@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 47 lines 1.5 KB
Raw
1 import {
2 AuthDiagnosticsReadScope,
3 sessionGrantsScope,
4 type SessionGrantInput,
5 } from "@t3tools/contracts";
6
7 import type { EnvironmentConnectionPhase } from "../connection/presentation.ts";
8 import { mFallback, msg } from "gt-i18n";
9 import type { MFunctionType } from "gt-i18n/types";
10
11 export function resolveUsageAccess(
12 input: {
13 readonly connectionPhase: EnvironmentConnectionPhase;
14 readonly session: SessionGrantInput | null;
15 readonly hasSessionError: boolean;
16 },
17 resolve: MFunctionType = mFallback,
18 ) {
19 if (input.hasSessionError) {
20 return {
21 canReadDiagnostics: false,
22 isPending: false,
23 error: resolve(msg("Could not check this connection's access to diagnostics and usage.")),
24 };
25 }
26 if (input.session === null) {
27 // An unprepared offline connection cannot finish its session check. Keep
28 // it out of pending totals until the connection starts another attempt.
29 const isPending =
30 input.connectionPhase === "connected" ||
31 input.connectionPhase === "connecting" ||
32 input.connectionPhase === "reconnecting";
33 return {
34 canReadDiagnostics: false,
35 isPending,
36 error: isPending ? null : resolve(msg("This environment is not connected.")),
37 };
38 }
39 const canReadDiagnostics = sessionGrantsScope(input.session, AuthDiagnosticsReadScope);
40 return {
41 canReadDiagnostics,
42 isPending: false,
43 error: canReadDiagnostics
44 ? null
45 : resolve(msg("This connection does not have access to diagnostics and usage.")),
46 };
47 }