@andorra-labs/code 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/acp-agent.d.ts +54 -0
- package/dist/src/acp-agent.js +991 -0
- package/dist/src/agent-definitions.js +29 -6
- package/dist/src/agent-execution.js +8 -2
- package/dist/src/agent-mcp-catalog.js +2 -0
- package/dist/src/agent-mcp.d.ts +3 -1
- package/dist/src/agent-mcp.js +97 -11
- package/dist/src/andorra/entry.js +21 -3
- package/dist/src/andorra/hosted.d.ts +3 -0
- package/dist/src/andorra/hosted.js +5 -1
- package/dist/src/andorra/notices.d.ts +10 -1
- package/dist/src/andorra/notices.js +25 -2
- package/dist/src/andorra/terminal.d.ts +2 -0
- package/dist/src/andorra/terminal.js +2 -2
- package/dist/src/app-server/protocol.d.ts +9 -2
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server/workspace.d.ts +1 -0
- package/dist/src/app-server/workspace.js +141 -10
- package/dist/src/app-server.d.ts +115 -0
- package/dist/src/app-server.js +980 -63
- package/dist/src/auth/AuthManager.js +4 -4
- package/dist/src/auth/deployment.js +2 -2
- package/dist/src/browser-bridge.d.ts +1 -0
- package/dist/src/browser-bridge.js +5 -2
- package/dist/src/browser-external-app.d.ts +27 -0
- package/dist/src/browser-external-app.js +60 -0
- package/dist/src/browser-panel-tool.d.ts +6 -0
- package/dist/src/browser-panel-tool.js +36 -0
- package/dist/src/browser-runner.js +1 -0
- package/dist/src/browser-server.d.ts +5 -0
- package/dist/src/browser-server.js +27 -3
- package/dist/src/browser-ui/style.css +3 -3
- package/dist/src/browser-ui/tokens.css +27 -16
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +60 -2
- package/dist/src/bug-report.d.ts +81 -0
- package/dist/src/bug-report.js +235 -0
- package/dist/src/claude-provider.d.ts +2 -1
- package/dist/src/claude-provider.js +13 -9
- package/dist/src/cli-sign-in.d.ts +3 -1
- package/dist/src/cli-sign-in.js +4 -1
- package/dist/src/cli.js +184 -40
- package/dist/src/codex-errors.js +4 -1
- package/dist/src/coding-tools.js +7 -7
- package/dist/src/command-screens.d.ts +9 -2
- package/dist/src/command-screens.js +166 -97
- package/dist/src/commands.d.ts +3 -2
- package/dist/src/commands.js +1 -0
- package/dist/src/compaction-phrases.d.ts +4 -0
- package/dist/src/compaction-phrases.js +20 -0
- package/dist/src/completion-gates.d.ts +22 -0
- package/dist/src/completion-gates.js +11 -0
- package/dist/src/config.d.ts +5 -0
- package/dist/src/config.js +48 -0
- package/dist/src/context-compaction.js +2 -1
- package/dist/src/decision/DecisionManager.js +3 -2
- package/dist/src/decision/requestPhrases.d.ts +4 -0
- package/dist/src/decision/requestPhrases.js +23 -0
- package/dist/src/github-inbox.d.ts +55 -0
- package/dist/src/github-inbox.js +153 -0
- package/dist/src/google-provider.d.ts +31 -0
- package/dist/src/google-provider.js +153 -0
- package/dist/src/graph-health.js +8 -4
- package/dist/src/graph-manager-chat.js +6 -1
- package/dist/src/graph-provider-portability.js +32 -10
- package/dist/src/graph-quota.d.ts +29 -2
- package/dist/src/graph-quota.js +68 -10
- package/dist/src/graph-runner.js +24 -7
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +9 -7
- package/dist/src/graph-sync.d.ts +1 -0
- package/dist/src/graph-sync.js +93 -34
- package/dist/src/graph-tool.d.ts +2 -0
- package/dist/src/graph-tool.js +2 -2
- package/dist/src/graph-ui/app.js +177 -41
- package/dist/src/graph-ui/controls.css +1 -0
- package/dist/src/graph-ui/edge-router.js +121 -53
- package/dist/src/graph-ui/embed.js +2 -2
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +1 -1
- package/dist/src/graph-ui/manager.css +1 -1
- package/dist/src/graph-ui/manager.js +2 -2
- package/dist/src/graph-ui/sidebar.js +30 -0
- package/dist/src/graph-ui/studio-canvas.js +26 -13
- package/dist/src/graph-ui/studio.css +15 -7
- package/dist/src/graph-ui/studio.js +11 -4
- package/dist/src/graph-ui/style.css +77 -45
- package/dist/src/graph-ui/theme.js +3 -36
- package/dist/src/graph-ui/tokens.css +27 -19
- package/dist/src/graph-visibility.d.ts +31 -0
- package/dist/src/graph-visibility.js +102 -0
- package/dist/src/graphs.js +4 -3
- package/dist/src/live-model.d.ts +24 -0
- package/dist/src/live-model.js +37 -0
- package/dist/src/managed-sign-in.d.ts +1 -0
- package/dist/src/managed-sign-in.js +13 -0
- package/dist/src/membership-errors.d.ts +2 -0
- package/dist/src/membership-errors.js +5 -1
- package/dist/src/membership.d.ts +23 -1
- package/dist/src/membership.js +48 -6
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +1 -1
- package/dist/src/model-metadata.js +12 -3
- package/dist/src/paged-transcript.d.ts +2 -0
- package/dist/src/paged-transcript.js +16 -0
- package/dist/src/plan-pass.d.ts +59 -0
- package/dist/src/plan-pass.js +165 -0
- package/dist/src/provider-connection.js +17 -0
- package/dist/src/provider-engine.d.ts +5 -0
- package/dist/src/provider-engine.js +6 -3
- package/dist/src/provider-import.js +3 -1
- package/dist/src/provider-settings.js +14 -2
- package/dist/src/providers.d.ts +33 -2
- package/dist/src/providers.js +101 -28
- package/dist/src/pull-request-checks.d.ts +26 -0
- package/dist/src/pull-request-checks.js +56 -0
- package/dist/src/pull-request-conversation.d.ts +134 -0
- package/dist/src/pull-request-conversation.js +221 -0
- package/dist/src/pull-request-create.d.ts +175 -0
- package/dist/src/pull-request-create.js +392 -0
- package/dist/src/pull-request-details.d.ts +242 -0
- package/dist/src/pull-request-details.js +614 -0
- package/dist/src/pull-request-edit.d.ts +23 -0
- package/dist/src/pull-request-edit.js +91 -0
- package/dist/src/pull-request-logs.d.ts +76 -0
- package/dist/src/pull-request-logs.js +172 -0
- package/dist/src/pull-request-merge.d.ts +112 -0
- package/dist/src/pull-request-merge.js +258 -0
- package/dist/src/pull-request-review.d.ts +137 -0
- package/dist/src/pull-request-review.js +401 -0
- package/dist/src/pull-requests.d.ts +43 -2
- package/dist/src/pull-requests.js +112 -21
- package/dist/src/react-runtime.js +58 -9
- package/dist/src/read-document-tool.d.ts +2 -0
- package/dist/src/read-document-tool.js +6 -6
- package/dist/src/remote/engine-pool.js +42 -6
- package/dist/src/run-control.d.ts +10 -0
- package/dist/src/run-control.js +24 -0
- package/dist/src/run-progress.d.ts +10 -0
- package/dist/src/run-progress.js +122 -0
- package/dist/src/run-records.d.ts +2 -2
- package/dist/src/runtime-environment.d.ts +1 -0
- package/dist/src/runtime-environment.js +13 -0
- package/dist/src/runtime.d.ts +5 -1
- package/dist/src/runtime.js +14 -2
- package/dist/src/save-lock.js +14 -7
- package/dist/src/session-title.d.ts +3 -0
- package/dist/src/session-title.js +5 -2
- package/dist/src/sign-in-detection.d.ts +1 -1
- package/dist/src/sign-in-detection.js +10 -3
- package/dist/src/sign-in-offer.js +1 -1
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/bug-report/SKILL.md +80 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +9 -1
- package/dist/src/skills/bundled/graph-manager/errors.md +1 -0
- package/dist/src/skills/bundled/provenance.json +7 -2
- package/dist/src/skills/runtime-skills.js +1 -0
- package/dist/src/subagent-run.js +1 -0
- package/dist/src/telemetry/capture-core.d.ts +17 -0
- package/dist/src/telemetry/capture-core.js +59 -1
- package/dist/src/telemetry/classify.d.ts +3 -1
- package/dist/src/telemetry/classify.js +37 -0
- package/dist/src/telemetry/emitter.d.ts +2 -0
- package/dist/src/telemetry/emitter.js +42 -5
- package/dist/src/telemetry/schema.d.ts +22 -0
- package/dist/src/telemetry/schema.js +68 -1
- package/dist/src/telemetry/surface.d.ts +1 -0
- package/dist/src/telemetry/uploader.d.ts +12 -1
- package/dist/src/telemetry/uploader.js +30 -2
- package/dist/src/terminal-links.d.ts +16 -0
- package/dist/src/terminal-links.js +113 -0
- package/dist/src/terminal-ui.d.ts +8 -1
- package/dist/src/terminal-ui.js +40 -14
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/trajectory.js +6 -1
- package/dist/src/transcript.d.ts +2 -0
- package/dist/src/transcript.js +10 -3
- package/dist/src/types.d.ts +9 -0
- package/dist/src/usage-analytics.js +18 -10
- package/package.json +2 -1
|
@@ -2,6 +2,7 @@ import { CliSignIn, type ManagedSignInState } from './cli-sign-in.js';
|
|
|
2
2
|
import { type OpenCodeServerLike, type OpenCodeSignInOption } from './opencode-cli-provider.js';
|
|
3
3
|
export declare function claudeSignIn(): CliSignIn;
|
|
4
4
|
export declare function grokSignIn(): CliSignIn;
|
|
5
|
+
export declare function googleSignIn(): CliSignIn;
|
|
5
6
|
export interface OpenCodeSignInState extends ManagedSignInState {
|
|
6
7
|
connected?: {
|
|
7
8
|
id: string;
|
|
@@ -2,6 +2,7 @@ import { resolveCliExecutable } from './cli-executable.js';
|
|
|
2
2
|
import { CliSignIn } from './cli-sign-in.js';
|
|
3
3
|
import { claudeEnvironment, readClaudeSignIn } from './claude-provider.js';
|
|
4
4
|
import { resolveClaudeExecutable } from './claude-executable.js';
|
|
5
|
+
import { GOOGLE_EXECUTABLE, googleEnvironment, readGoogleCatalog } from './google-provider.js';
|
|
5
6
|
import { GROK_EXECUTABLE, grokEnvironment, readGrokCatalog } from './grok-provider.js';
|
|
6
7
|
import { authorizeOpenCode, completeOpenCode, listOpenCodeSignIns, readOpenCodeCatalog, sharedOpenCodeServer, signOutOpenCode, } from './opencode-cli-provider.js';
|
|
7
8
|
export function claudeSignIn() {
|
|
@@ -28,6 +29,18 @@ export function grokSignIn() {
|
|
|
28
29
|
deviceCode: true,
|
|
29
30
|
});
|
|
30
31
|
}
|
|
32
|
+
export function googleSignIn() {
|
|
33
|
+
return new CliSignIn({
|
|
34
|
+
product: 'Google',
|
|
35
|
+
resolveExecutable: () => resolveCliExecutable(GOOGLE_EXECUTABLE),
|
|
36
|
+
env: () => googleEnvironment(),
|
|
37
|
+
loginArgs: ['acp', '--login'],
|
|
38
|
+
signOutHint: 'The Antigravity CLI signs out only from inside it: run agy in a terminal, type /logout, then refresh here.',
|
|
39
|
+
status: signal => readGoogleCatalog(signal),
|
|
40
|
+
pageHosts: ['accounts.google.com'],
|
|
41
|
+
acceptsCode: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
31
44
|
export class OpenCodeSignIn {
|
|
32
45
|
server;
|
|
33
46
|
attempt;
|
|
@@ -5,6 +5,8 @@ export interface MembershipVerdict {
|
|
|
5
5
|
subject?: string;
|
|
6
6
|
}
|
|
7
7
|
export declare class PaidMembershipRequiredError extends Error {
|
|
8
|
+
/** The membership could not be checked (timeout, 5xx, 429, network). Says nothing about the account's plan. */
|
|
9
|
+
unavailable: boolean;
|
|
8
10
|
constructor(message?: string);
|
|
9
11
|
static for(access: MembershipVerdict): PaidMembershipRequiredError;
|
|
10
12
|
}
|
|
@@ -5,11 +5,15 @@ const REASONS = {
|
|
|
5
5
|
network: 'the account service could not be reached',
|
|
6
6
|
};
|
|
7
7
|
export class PaidMembershipRequiredError extends Error {
|
|
8
|
+
/** The membership could not be checked (timeout, 5xx, 429, network). Says nothing about the account's plan. */
|
|
9
|
+
unavailable = false;
|
|
8
10
|
constructor(message = `Paid membership is required for ${FEATURES}. Use /login to sign in. If already signed in, check your membership or connection.`) { super(message); }
|
|
9
11
|
static for(access) {
|
|
10
12
|
if (access.unavailable) {
|
|
11
13
|
const reason = access.failureReason ? `: ${REASONS[access.failureReason]}` : ' right now';
|
|
12
|
-
|
|
14
|
+
const error = new PaidMembershipRequiredError(`Your Andorra membership could not be checked${reason}. This does not mean you were signed out; check your connection and retry.`);
|
|
15
|
+
error.unavailable = true;
|
|
16
|
+
return error;
|
|
13
17
|
}
|
|
14
18
|
if (!access.subject)
|
|
15
19
|
return new PaidMembershipRequiredError(`You are signed out of your Andorra account; ${FEATURES} need a signed-in account. Use /login to sign in again.`);
|
package/dist/src/membership.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Graph } from './graphs.js';
|
|
2
|
+
import { readOfflinePlan } from './plan-pass.js';
|
|
2
3
|
import type { TelemetryPlan } from './telemetry/schema.js';
|
|
3
4
|
export declare const SOFTWARE_ENGINEER_HARNESS: Graph;
|
|
4
5
|
export declare const RETIRED_ANDORRA_SELECTION = ":andorra";
|
|
@@ -11,6 +12,7 @@ export interface Membership {
|
|
|
11
12
|
paid: boolean;
|
|
12
13
|
unavailable?: boolean;
|
|
13
14
|
failureReason?: MembershipFailureReason;
|
|
15
|
+
failureDetail?: string;
|
|
14
16
|
subject?: string;
|
|
15
17
|
email?: string;
|
|
16
18
|
tier?: MembershipTier;
|
|
@@ -30,9 +32,13 @@ export interface Membership {
|
|
|
30
32
|
windowDecisionResetsAt?: string;
|
|
31
33
|
/** Uncapped Paid account: no daily, window or global cap applies. The service answers `unlimited: true` and omits every allowance field. */
|
|
32
34
|
unlimited?: boolean;
|
|
35
|
+
/** The plan comes from a stored, signed pass because the account service could not be reached. */
|
|
36
|
+
offline?: true;
|
|
33
37
|
billingUrl?: string;
|
|
34
38
|
}
|
|
35
39
|
export declare function membershipPlanLabel(tier: MembershipTier | undefined, paid: boolean): string;
|
|
40
|
+
/** Which step of the lookup failed and the first concrete error code under it, e.g. "sign-in token: ECONNRESET". */
|
|
41
|
+
export declare function transportFailureDetail(error: unknown, step: 'sign-in token' | 'account check'): string;
|
|
36
42
|
export declare function safeAccountEmail(value: unknown): string | undefined;
|
|
37
43
|
export { PaidMembershipRequiredError } from './membership-errors.js';
|
|
38
44
|
export interface PlanConfirmation {
|
|
@@ -45,13 +51,29 @@ export interface MembershipDependencies {
|
|
|
45
51
|
apiBaseUrl(): string;
|
|
46
52
|
fetch: typeof globalThis.fetch;
|
|
47
53
|
recordPlan?: (answer: PlanConfirmation, home?: string) => Promise<void>;
|
|
54
|
+
/** Keeps the signed pass an answer carried, for use while the service is unreachable. */
|
|
55
|
+
storePass?: (pass: unknown, subject: string, home: string, serverTime: number | undefined, plan: {
|
|
56
|
+
paid: boolean;
|
|
57
|
+
tier?: string;
|
|
58
|
+
}) => Promise<unknown>;
|
|
48
59
|
}
|
|
49
60
|
export declare function createMembershipClient(deps: MembershipDependencies): (signal?: AbortSignal, home?: string) => Promise<Membership>;
|
|
50
61
|
export declare const getMembership: (signal?: AbortSignal, home?: string) => Promise<Membership>;
|
|
62
|
+
/**
|
|
63
|
+
* The plan check for custom graphs. It is `getMembership`, except that when the account service
|
|
64
|
+
* cannot be reached a stored pass for the signed-in account stands in for the answer until the pass
|
|
65
|
+
* lapses. Hosted services still need the network; this only decides which graphs may be used.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createGraphMembership(deps: {
|
|
68
|
+
membership: (signal?: AbortSignal, home?: string) => Promise<Membership>;
|
|
69
|
+
subject: () => Promise<string | undefined>;
|
|
70
|
+
readPlan?: typeof readOfflinePlan;
|
|
71
|
+
}): (signal?: AbortSignal, home?: string) => Promise<Membership>;
|
|
72
|
+
export declare const getGraphMembership: (signal?: AbortSignal, home?: string) => Promise<Membership>;
|
|
51
73
|
export declare function requirePaidMembership(signal?: AbortSignal): Promise<void>;
|
|
52
74
|
export declare function requireGraphMembership(signal?: AbortSignal): Promise<void>;
|
|
53
75
|
export declare function readGraphMembership(signal?: AbortSignal): Promise<Membership>;
|
|
54
|
-
export declare function loadAccessibleGraph(id?: string, signal?: AbortSignal, membership?: (signal?: AbortSignal
|
|
76
|
+
export declare function loadAccessibleGraph(id?: string, signal?: AbortSignal, membership?: (signal?: AbortSignal) => Promise<Membership>, options?: {
|
|
55
77
|
bindProviders?: boolean;
|
|
56
78
|
allowDeleted?: boolean;
|
|
57
79
|
allowRetired?: boolean;
|
package/dist/src/membership.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { DEFAULT_AGENT_GRAPH } from './default-graph.js';
|
|
2
2
|
import { DEFAULT_HARNESS, GRAPH_MANAGER_GRAPH_ID, GRAPH_MANAGER_HARNESS, GraphDeletedError, isDeletedGraph, loadGraph } from './graphs.js';
|
|
3
|
-
import { AUTH_REFRESH_BUDGET_MS, AuthError, getAccessToken, getAuthConfiguration } from './auth/index.js';
|
|
3
|
+
import { AUTH_REFRESH_BUDGET_MS, AuthError, getAccessToken, getAuthConfiguration, getAuthStatus } from './auth/index.js';
|
|
4
|
+
import { readOfflinePlan, storePlanPass } from './plan-pass.js';
|
|
4
5
|
import { graphStorageDirectory } from './graph-account.js';
|
|
5
6
|
import { configDirectory, loadConfig } from './config.js';
|
|
6
7
|
import { analyticsPlanFromMembership, resolveAnalyticsConfig } from './analytics.js';
|
|
7
8
|
import { recordConfirmedPlan } from './telemetry/state.js';
|
|
8
9
|
import { telemetryDirectory } from './telemetry/identity.js';
|
|
9
10
|
import { bindPortableGraphProviders } from './graph-provider-portability.js';
|
|
10
|
-
import { loadFreeTierGraph } from './graph-quota.js';
|
|
11
|
+
import { loadFreeTierGraph, notePremiumGraphAccount } from './graph-quota.js';
|
|
11
12
|
export const SOFTWARE_ENGINEER_HARNESS = {
|
|
12
13
|
schemaVersion: 2, id: 'software-engineer', name: DEFAULT_AGENT_GRAPH.name, revision: 1, entry: DEFAULT_AGENT_GRAPH.entry,
|
|
13
14
|
nodes: structuredClone(DEFAULT_AGENT_GRAPH.nodes), edges: structuredClone(DEFAULT_AGENT_GRAPH.edges),
|
|
@@ -74,6 +75,21 @@ function transportFailureReason(error) {
|
|
|
74
75
|
}
|
|
75
76
|
return network ? 'network' : undefined;
|
|
76
77
|
}
|
|
78
|
+
/** Which step of the lookup failed and the first concrete error code under it, e.g. "sign-in token: ECONNRESET". */
|
|
79
|
+
export function transportFailureDetail(error, step) {
|
|
80
|
+
let current = error;
|
|
81
|
+
for (let depth = 0; depth < 8 && current && typeof current === 'object'; depth++) {
|
|
82
|
+
const failure = current;
|
|
83
|
+
if (typeof failure.code === 'string' && /^[A-Z][A-Z0-9_]{1,63}$/.test(failure.code))
|
|
84
|
+
return `${step}: ${failure.code}`;
|
|
85
|
+
if (failure.name === 'TimeoutError')
|
|
86
|
+
return `${step}: timeout`;
|
|
87
|
+
if (current instanceof AuthError && failure.code !== 'network')
|
|
88
|
+
return `${step}: ${current.code}`;
|
|
89
|
+
current = failure.cause;
|
|
90
|
+
}
|
|
91
|
+
return step;
|
|
92
|
+
}
|
|
77
93
|
export function safeAccountEmail(value) {
|
|
78
94
|
return typeof value === 'string' && value.length <= 254
|
|
79
95
|
&& /^[^\s@\p{Cc}\p{Cf}\p{Cs}]+@[^\s@\p{Cc}\p{Cf}\p{Cs}]+$/u.test(value) ? value : undefined;
|
|
@@ -104,7 +120,7 @@ export function createMembershipClient(deps) {
|
|
|
104
120
|
}).catch(error => { throw Object.assign(new Error('Membership connection unavailable'), { cause: error, membershipNetworkFailure: true }); });
|
|
105
121
|
if (!response.ok) {
|
|
106
122
|
await response.body?.cancel();
|
|
107
|
-
return { paid: false, ...(response.status >= 500 || response.status === 429 ? { unavailable: true } : {}) };
|
|
123
|
+
return { paid: false, ...(response.status >= 500 || response.status === 429 ? { unavailable: true, failureDetail: `account check: HTTP ${response.status}` } : {}) };
|
|
108
124
|
}
|
|
109
125
|
const reader = response.body?.getReader();
|
|
110
126
|
if (!reader)
|
|
@@ -143,6 +159,8 @@ export function createMembershipClient(deps) {
|
|
|
143
159
|
? result.tier : undefined;
|
|
144
160
|
const observedAt = new Date().toISOString();
|
|
145
161
|
await (deps.recordPlan ?? recordPlanConfirmation)({ subject: result.subject, tier: analyticsPlanFromMembership(tier, result.paid), observedAt }, home).catch(() => { });
|
|
162
|
+
const served = Date.parse(response.headers?.get?.('date') ?? '');
|
|
163
|
+
await (deps.storePass ?? ((pass, subject, directory, serverTime, plan) => storePlanPass(pass, subject, directory, { serverTime, plan })))(result.pass, result.subject, home ?? configDirectory(), Number.isFinite(served) ? served : undefined, { paid: result.paid, ...(tier ? { tier } : {}) }).catch(() => { });
|
|
146
164
|
const windowed = windowFields(result);
|
|
147
165
|
const unlimited = typeof result.unlimited === 'boolean' ? result.unlimited : undefined;
|
|
148
166
|
const lifetime = Number.isSafeInteger(result.decisionsSinceRollout) && result.decisionsSinceRollout >= 0
|
|
@@ -161,8 +179,10 @@ export function createMembershipClient(deps) {
|
|
|
161
179
|
const failureReason = transportFailureReason(error);
|
|
162
180
|
const refused = error instanceof AuthError && (error.code === 'login_required' || error.code === 'invalid_token');
|
|
163
181
|
const unavailable = !refused && (bounded === undefined || bounded.aborted || failureReason !== undefined);
|
|
182
|
+
const failureDetail = unavailable ? transportFailureDetail(error, bounded ? 'account check' : 'sign-in token') : undefined;
|
|
164
183
|
return { paid: false, ...(unavailable ? { unavailable: true } : {}),
|
|
165
|
-
...(unavailable && !bounded?.aborted && failureReason ? { failureReason } : {})
|
|
184
|
+
...(unavailable && !bounded?.aborted && failureReason ? { failureReason } : {}),
|
|
185
|
+
...(failureDetail ? { failureDetail } : {}) };
|
|
166
186
|
}
|
|
167
187
|
};
|
|
168
188
|
}
|
|
@@ -170,6 +190,26 @@ export const getMembership = createMembershipClient({
|
|
|
170
190
|
accessToken: getAccessToken, apiBaseUrl: () => getAuthConfiguration().apiBaseUrl,
|
|
171
191
|
fetch: (...args) => globalThis.fetch(...args),
|
|
172
192
|
});
|
|
193
|
+
/**
|
|
194
|
+
* The plan check for custom graphs. It is `getMembership`, except that when the account service
|
|
195
|
+
* cannot be reached a stored pass for the signed-in account stands in for the answer until the pass
|
|
196
|
+
* lapses. Hosted services still need the network; this only decides which graphs may be used.
|
|
197
|
+
*/
|
|
198
|
+
export function createGraphMembership(deps) {
|
|
199
|
+
return async (signal, home) => {
|
|
200
|
+
const access = await deps.membership(signal, home);
|
|
201
|
+
if (!access.unavailable)
|
|
202
|
+
return access;
|
|
203
|
+
signal?.throwIfAborted();
|
|
204
|
+
const subject = await deps.subject().catch(() => undefined);
|
|
205
|
+
const plan = await (deps.readPlan ?? readOfflinePlan)(subject, home ?? configDirectory()).catch(() => undefined);
|
|
206
|
+
return plan ? { paid: plan.paid, tier: plan.tier, subject: plan.subject, offline: true } : access;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export const getGraphMembership = createGraphMembership({
|
|
210
|
+
membership: (signal, home) => getMembership(signal, home),
|
|
211
|
+
subject: async () => (await getAuthStatus()).subject,
|
|
212
|
+
});
|
|
173
213
|
export async function requirePaidMembership(signal) {
|
|
174
214
|
const access = await getMembership(signal);
|
|
175
215
|
if (!access.paid)
|
|
@@ -179,12 +219,12 @@ export async function requireGraphMembership(signal) {
|
|
|
179
219
|
await readGraphMembership(signal);
|
|
180
220
|
}
|
|
181
221
|
export async function readGraphMembership(signal) {
|
|
182
|
-
const access = await
|
|
222
|
+
const access = await getGraphMembership(signal);
|
|
183
223
|
if (!access.paid && !access.subject)
|
|
184
224
|
throw PaidMembershipRequiredError.for(access);
|
|
185
225
|
return access;
|
|
186
226
|
}
|
|
187
|
-
export async function loadAccessibleGraph(id = 'default', signal, membership =
|
|
227
|
+
export async function loadAccessibleGraph(id = 'default', signal, membership = getGraphMembership, options = {}) {
|
|
188
228
|
signal?.throwIfAborted();
|
|
189
229
|
if (id === RETIRED_ANDORRA_SELECTION && options.allowRetired) {
|
|
190
230
|
const access = await membership(signal);
|
|
@@ -206,6 +246,8 @@ export async function loadAccessibleGraph(id = 'default', signal, membership = g
|
|
|
206
246
|
if (!/^[A-Za-z0-9-]{1,128}$/.test(access.subject))
|
|
207
247
|
throw new PaidMembershipRequiredError();
|
|
208
248
|
const directory = await graphStorageDirectory(undefined, access.subject);
|
|
249
|
+
if (access.paid)
|
|
250
|
+
await notePremiumGraphAccount(directory);
|
|
209
251
|
const graph = access.paid ? await loadGraph(id, undefined, directory) : await loadFreeTierGraph(id, directory);
|
|
210
252
|
if (!options.allowDeleted && isDeletedGraph(graph))
|
|
211
253
|
throw new GraphDeletedError(graph.name);
|
|
@@ -4,7 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
export const MODEL_HEALTH_TTL_MS = 10 * 60_000;
|
|
5
5
|
const REFRESH_INTERVAL_MS = 60_000;
|
|
6
6
|
const FILE = 'model-health.json';
|
|
7
|
-
const DESCRIPTIVE_FIELDS = new Set(['model', 'models', 'modelContextWindows', 'modelNames', 'contextWindow', 'reasoningEffort']);
|
|
7
|
+
const DESCRIPTIVE_FIELDS = new Set(['model', 'models', 'modelContextWindows', 'modelNames', 'modelParameters', 'freeModels', 'contextWindow', 'reasoningEffort']);
|
|
8
8
|
export function modelHealthKey(provider, model) {
|
|
9
9
|
const reach = Object.fromEntries(Object.entries(provider)
|
|
10
10
|
.filter(([name]) => !DESCRIPTIVE_FIELDS.has(name))
|
|
@@ -4,7 +4,7 @@ export interface ModelMetadata {
|
|
|
4
4
|
contextWindow?: number;
|
|
5
5
|
}
|
|
6
6
|
export declare function resolveModelContext(provider: ProviderConfig, model: string | undefined, signal: AbortSignal): Promise<ProviderConfig>;
|
|
7
|
-
export declare function configuredModelSnapshot(provider: ProviderConfig,
|
|
7
|
+
export declare function configuredModelSnapshot(provider: ProviderConfig, requested: string | undefined): ProviderConfig;
|
|
8
8
|
export declare function withEvaluationReasoningEffort(snapshot: ProviderConfig, effort: string | undefined): ProviderConfig;
|
|
9
9
|
export declare function refreshModelContext(provider: ProviderConfig, signal: AbortSignal): Promise<ProviderConfig>;
|
|
10
10
|
/** What the provider lists, with Andorra-known Claude windows filled in where the listing gives none. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { configuredContextWindow, deadlinePhrase, MODEL_LISTING_TIMEOUT_MS } from './providers.js';
|
|
1
|
+
import { configuredContextWindow, deadlinePhrase, MODEL_LISTING_TIMEOUT_MS, providerModelId } from './providers.js';
|
|
2
2
|
import { providerAuthHeaders } from './anthropic-credentials.js';
|
|
3
3
|
import { validateConfig } from './config.js';
|
|
4
4
|
import { readOpenCodeModels } from './opencode-catalog.js';
|
|
@@ -6,6 +6,7 @@ import { readCodexCatalog } from './codex-provider.js';
|
|
|
6
6
|
import { codexConnectFor } from './codex-rpc.js';
|
|
7
7
|
import { readClaudeCatalog } from './claude-provider.js';
|
|
8
8
|
import { knownClaudeContextWindow } from './model-context-windows.js';
|
|
9
|
+
import { readGoogleCatalog } from './google-provider.js';
|
|
9
10
|
import { readGrokCatalog } from './grok-provider.js';
|
|
10
11
|
import { readOpenCodeCatalog } from './opencode-cli-provider.js';
|
|
11
12
|
import { ANDORRA_SIGN_IN_MESSAGE, ANDORRA_UNAVAILABLE_MESSAGE } from './andorra/endpoint.js';
|
|
@@ -13,7 +14,9 @@ import { createHostedClient } from './andorra/hosted.js';
|
|
|
13
14
|
export async function resolveModelContext(provider, model, signal) {
|
|
14
15
|
return refreshModelContext(configuredModelSnapshot(provider, model), signal);
|
|
15
16
|
}
|
|
16
|
-
export function configuredModelSnapshot(provider,
|
|
17
|
+
export function configuredModelSnapshot(provider, requested) {
|
|
18
|
+
// A model the provider lists in another case is requested in the provider's own spelling.
|
|
19
|
+
const model = requested === undefined ? undefined : providerModelId(provider, requested) ?? requested;
|
|
17
20
|
const snapshot = { ...provider };
|
|
18
21
|
if (model !== undefined && model !== snapshot.model) {
|
|
19
22
|
snapshot.model = model;
|
|
@@ -45,7 +48,7 @@ export async function refreshModelContext(provider, signal) {
|
|
|
45
48
|
return snapshot;
|
|
46
49
|
}
|
|
47
50
|
// Andorra entries carry the router's windows already (saved from GET /v1/hosted).
|
|
48
|
-
if (snapshot.type === 'codex' || snapshot.type === 'grok' || snapshot.type === 'andorra')
|
|
51
|
+
if (snapshot.type === 'codex' || snapshot.type === 'grok' || snapshot.type === 'google' || snapshot.type === 'andorra')
|
|
49
52
|
return snapshot;
|
|
50
53
|
try {
|
|
51
54
|
// The raw listing: a catalog default must not displace a window the user saved.
|
|
@@ -113,6 +116,12 @@ async function listModelMetadata(provider, signal) {
|
|
|
113
116
|
throw new Error('Sign in to Grok on this machine before listing its models.');
|
|
114
117
|
return catalog.models.map(id => ({ id }));
|
|
115
118
|
}
|
|
119
|
+
if (provider.type === 'google') {
|
|
120
|
+
const catalog = await readGoogleCatalog(signal);
|
|
121
|
+
if (!catalog.signedIn)
|
|
122
|
+
throw new Error('Sign in with Google in the Antigravity CLI on this machine before listing its models.');
|
|
123
|
+
return catalog.models.map(id => ({ id }));
|
|
124
|
+
}
|
|
116
125
|
if (provider.type === 'opencode')
|
|
117
126
|
return (await readOpenCodeCatalog(signal)).models.map(model => ({ id: model.id, ...(model.contextWindow ? { contextWindow: model.contextWindow } : {}) }));
|
|
118
127
|
if (provider.type === 'opencode-go')
|
|
@@ -26,6 +26,8 @@ export declare class PagedTranscript<T extends Body, R> {
|
|
|
26
26
|
omitted: boolean;
|
|
27
27
|
};
|
|
28
28
|
append(value: T): void;
|
|
29
|
+
/** Puts `value` where the newest entry is, for a line that reports progress by rewriting itself. */
|
|
30
|
+
replaceLast(value: T): void;
|
|
29
31
|
private size;
|
|
30
32
|
private remember;
|
|
31
33
|
private materialize;
|
|
@@ -68,6 +68,22 @@ export class PagedTranscript {
|
|
|
68
68
|
this.omitted = true;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/** Puts `value` where the newest entry is, for a line that reports progress by rewriting itself. */
|
|
72
|
+
replaceLast(value) {
|
|
73
|
+
if (this.closed)
|
|
74
|
+
return;
|
|
75
|
+
const last = this.entries.pop();
|
|
76
|
+
if (last) {
|
|
77
|
+
const cached = this.cache.get(last);
|
|
78
|
+
if (cached) {
|
|
79
|
+
this.cachedChars -= this.size(cached);
|
|
80
|
+
this.cache.delete(last);
|
|
81
|
+
}
|
|
82
|
+
if (!last.fallback)
|
|
83
|
+
this.offset = last.offset;
|
|
84
|
+
}
|
|
85
|
+
this.append(value);
|
|
86
|
+
}
|
|
71
87
|
size(body) { return body.text.length + (body.detail?.length ?? 0); }
|
|
72
88
|
remember(entry, body) {
|
|
73
89
|
const old = this.cache.get(entry);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The offline plan pass.
|
|
3
|
+
*
|
|
4
|
+
* When the account service answers a plan check it also returns a pass: the account, its plan, when
|
|
5
|
+
* the pass was issued and when it lapses, signed with a key whose private half stays in the
|
|
6
|
+
* service's key store. This module checks that signature with the public half, so a pass whose
|
|
7
|
+
* dates were edited on disk is rejected, and lets a valid pass stand in for the plan check while the
|
|
8
|
+
* service cannot be reached.
|
|
9
|
+
*
|
|
10
|
+
* The clock is not trusted. Beside the pass the file keeps the latest time this machine has seen,
|
|
11
|
+
* which only moves forward, and a system clock earlier than that is treated as tampering. A machine
|
|
12
|
+
* its owner controls can still restore both the pass and that record from a copy; this stops an
|
|
13
|
+
* edited date and a moved clock, not a restored backup.
|
|
14
|
+
*/
|
|
15
|
+
/** Public keys that sign passes, as base64 DER (SubjectPublicKeyInfo), newest first. Empty until the key exists. */
|
|
16
|
+
export declare const PLAN_PASS_KEYS: readonly string[];
|
|
17
|
+
export type PlanPassTier = 'free' | 'legacy' | 'paid';
|
|
18
|
+
export interface PlanPass {
|
|
19
|
+
subject: string;
|
|
20
|
+
tier: PlanPassTier;
|
|
21
|
+
paid: boolean;
|
|
22
|
+
issuedAt: number;
|
|
23
|
+
expiresAt: number;
|
|
24
|
+
}
|
|
25
|
+
export interface OfflinePlan extends PlanPass {
|
|
26
|
+
offline: true;
|
|
27
|
+
}
|
|
28
|
+
/** The claims of a pass one of `keys` signed, in milliseconds, or undefined for anything else. */
|
|
29
|
+
export declare function verifyPlanPass(token: unknown, keys?: readonly string[]): PlanPass | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Keeps the pass an online plan check returned. `serverTime` is the service's own clock from that
|
|
32
|
+
* answer; it replaces the latest time seen, so a machine whose clock once ran ahead recovers the
|
|
33
|
+
* next time it is online. A pass that does not verify, names another account, or disagrees with
|
|
34
|
+
* the `plan` the service just answered is not kept.
|
|
35
|
+
*
|
|
36
|
+
* When the answer brings no pass worth keeping, a pass already stored survives only if it still
|
|
37
|
+
* says what the service just said. A downgrade the service confirmed therefore ends the old pass at
|
|
38
|
+
* once, even when the service could not sign a new one.
|
|
39
|
+
*/
|
|
40
|
+
export declare function storePlanPass(token: unknown, subject: string, home: string, options?: {
|
|
41
|
+
serverTime?: number;
|
|
42
|
+
now?: number;
|
|
43
|
+
keys?: readonly string[];
|
|
44
|
+
plan?: {
|
|
45
|
+
paid: boolean;
|
|
46
|
+
tier?: string;
|
|
47
|
+
};
|
|
48
|
+
}): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* The plan a stored pass grants `subject` right now, while the service cannot be reached.
|
|
51
|
+
*
|
|
52
|
+
* Nothing is granted when the pass does not verify, names another account, has lapsed, when the
|
|
53
|
+
* record of the latest time seen is missing, or when the system clock is behind that record. Each
|
|
54
|
+
* use moves the record forward, so time spent offline is not handed back by turning the clock back.
|
|
55
|
+
*/
|
|
56
|
+
export declare function readOfflinePlan(subject: string | undefined, home: string, options?: {
|
|
57
|
+
now?: number;
|
|
58
|
+
keys?: readonly string[];
|
|
59
|
+
}): Promise<OfflinePlan | undefined>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { createPublicKey, randomBytes, verify } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
/**
|
|
5
|
+
* The offline plan pass.
|
|
6
|
+
*
|
|
7
|
+
* When the account service answers a plan check it also returns a pass: the account, its plan, when
|
|
8
|
+
* the pass was issued and when it lapses, signed with a key whose private half stays in the
|
|
9
|
+
* service's key store. This module checks that signature with the public half, so a pass whose
|
|
10
|
+
* dates were edited on disk is rejected, and lets a valid pass stand in for the plan check while the
|
|
11
|
+
* service cannot be reached.
|
|
12
|
+
*
|
|
13
|
+
* The clock is not trusted. Beside the pass the file keeps the latest time this machine has seen,
|
|
14
|
+
* which only moves forward, and a system clock earlier than that is treated as tampering. A machine
|
|
15
|
+
* its owner controls can still restore both the pass and that record from a copy; this stops an
|
|
16
|
+
* edited date and a moved clock, not a restored backup.
|
|
17
|
+
*/
|
|
18
|
+
/** Public keys that sign passes, as base64 DER (SubjectPublicKeyInfo), newest first. Empty until the key exists. */
|
|
19
|
+
export const PLAN_PASS_KEYS = [];
|
|
20
|
+
/** A pass never grants more than this, whatever it says: the service caps a pass at 31 days. */
|
|
21
|
+
const MAX_LIFETIME_MS = 32 * 86_400_000;
|
|
22
|
+
/** How far behind the latest time seen the system clock may be: ordinary drift and time-zone fixes. */
|
|
23
|
+
const CLOCK_SLACK_MS = 5 * 60_000;
|
|
24
|
+
const FILE = 'plan-pass.json';
|
|
25
|
+
function importKeys(keys) {
|
|
26
|
+
const imported = [];
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
try {
|
|
29
|
+
imported.push(createPublicKey({ key: Buffer.from(key, 'base64'), format: 'der', type: 'spki' }));
|
|
30
|
+
}
|
|
31
|
+
catch { /* an unusable key signs nothing */ }
|
|
32
|
+
}
|
|
33
|
+
return imported;
|
|
34
|
+
}
|
|
35
|
+
/** The claims of a pass one of `keys` signed, in milliseconds, or undefined for anything else. */
|
|
36
|
+
export function verifyPlanPass(token, keys = PLAN_PASS_KEYS) {
|
|
37
|
+
if (typeof token !== 'string' || token.length > 4096)
|
|
38
|
+
return undefined;
|
|
39
|
+
const parts = token.split('.');
|
|
40
|
+
if (parts.length !== 2 || !parts.every(part => /^[A-Za-z0-9_-]+$/.test(part)))
|
|
41
|
+
return undefined;
|
|
42
|
+
const signature = Buffer.from(parts[1], 'base64url');
|
|
43
|
+
if (!importKeys(keys).some(key => { try {
|
|
44
|
+
return verify('sha256', Buffer.from(parts[0], 'ascii'), key, signature);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
} }))
|
|
49
|
+
return undefined;
|
|
50
|
+
let claims;
|
|
51
|
+
try {
|
|
52
|
+
claims = JSON.parse(Buffer.from(parts[0], 'base64url').toString('utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
if (!claims || typeof claims !== 'object' || Array.isArray(claims))
|
|
58
|
+
return undefined;
|
|
59
|
+
const { v, sub, tier, paid, iat, exp } = claims;
|
|
60
|
+
if (v !== 1 || typeof sub !== 'string' || !/^[A-Za-z0-9-]{1,128}$/.test(sub))
|
|
61
|
+
return undefined;
|
|
62
|
+
if (tier !== 'free' && tier !== 'legacy' && tier !== 'paid')
|
|
63
|
+
return undefined;
|
|
64
|
+
if (paid !== (tier !== 'free'))
|
|
65
|
+
return undefined;
|
|
66
|
+
if (!Number.isSafeInteger(iat) || !Number.isSafeInteger(exp) || iat <= 0 || exp <= iat)
|
|
67
|
+
return undefined;
|
|
68
|
+
const issuedAt = iat * 1000, expiresAt = exp * 1000;
|
|
69
|
+
if (expiresAt - issuedAt > MAX_LIFETIME_MS)
|
|
70
|
+
return undefined;
|
|
71
|
+
return { subject: sub, tier, paid, issuedAt, expiresAt };
|
|
72
|
+
}
|
|
73
|
+
async function readStored(home) {
|
|
74
|
+
try {
|
|
75
|
+
const value = JSON.parse(await readFile(join(home, FILE), 'utf8'));
|
|
76
|
+
if (!value || typeof value !== 'object')
|
|
77
|
+
return undefined;
|
|
78
|
+
const { pass, lastSeen } = value;
|
|
79
|
+
return typeof pass === 'string' && Number.isSafeInteger(lastSeen) && lastSeen > 0 ? { pass, lastSeen: lastSeen } : undefined;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function writeStored(home, stored) {
|
|
86
|
+
await mkdir(home, { recursive: true });
|
|
87
|
+
// Each write stages its own file: two plan checks finishing together must not share one.
|
|
88
|
+
const path = join(home, FILE), staged = `${path}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`;
|
|
89
|
+
try {
|
|
90
|
+
await writeFile(staged, JSON.stringify(stored), { mode: 0o600 });
|
|
91
|
+
await rename(staged, path);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
await unlink(staged).catch(() => { });
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** One read-and-update of a home's record at a time in this process, so none works from a stale copy. */
|
|
99
|
+
const queues = new Map();
|
|
100
|
+
function serial(home, task) {
|
|
101
|
+
const run = (queues.get(home) ?? Promise.resolve()).then(task, task);
|
|
102
|
+
const settled = run.catch(() => { });
|
|
103
|
+
queues.set(home, settled);
|
|
104
|
+
void settled.then(() => { if (queues.get(home) === settled)
|
|
105
|
+
queues.delete(home); });
|
|
106
|
+
return run;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Keeps the pass an online plan check returned. `serverTime` is the service's own clock from that
|
|
110
|
+
* answer; it replaces the latest time seen, so a machine whose clock once ran ahead recovers the
|
|
111
|
+
* next time it is online. A pass that does not verify, names another account, or disagrees with
|
|
112
|
+
* the `plan` the service just answered is not kept.
|
|
113
|
+
*
|
|
114
|
+
* When the answer brings no pass worth keeping, a pass already stored survives only if it still
|
|
115
|
+
* says what the service just said. A downgrade the service confirmed therefore ends the old pass at
|
|
116
|
+
* once, even when the service could not sign a new one.
|
|
117
|
+
*/
|
|
118
|
+
export function storePlanPass(token, subject, home, options = {}) {
|
|
119
|
+
const agrees = (pass) => pass !== undefined && pass.subject === subject
|
|
120
|
+
&& (options.plan === undefined || (pass.paid === options.plan.paid && (options.plan.tier === undefined || pass.tier === options.plan.tier)));
|
|
121
|
+
return serial(home, async () => {
|
|
122
|
+
const pass = verifyPlanPass(token, options.keys);
|
|
123
|
+
if (!agrees(pass)) {
|
|
124
|
+
const stored = await readStored(home);
|
|
125
|
+
if (stored && !agrees(verifyPlanPass(stored.pass, options.keys)))
|
|
126
|
+
await unlink(join(home, FILE)).catch(() => { });
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const now = options.now ?? Date.now();
|
|
130
|
+
const serverTime = options.serverTime !== undefined && Number.isFinite(options.serverTime) ? options.serverTime : undefined;
|
|
131
|
+
await writeStored(home, { pass: token, lastSeen: Math.max(serverTime ?? now, pass.issuedAt) });
|
|
132
|
+
return true;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The plan a stored pass grants `subject` right now, while the service cannot be reached.
|
|
137
|
+
*
|
|
138
|
+
* Nothing is granted when the pass does not verify, names another account, has lapsed, when the
|
|
139
|
+
* record of the latest time seen is missing, or when the system clock is behind that record. Each
|
|
140
|
+
* use moves the record forward, so time spent offline is not handed back by turning the clock back.
|
|
141
|
+
*/
|
|
142
|
+
export function readOfflinePlan(subject, home, options = {}) {
|
|
143
|
+
return serial(home, () => readOfflinePlanNow(subject, home, options));
|
|
144
|
+
}
|
|
145
|
+
async function readOfflinePlanNow(subject, home, options) {
|
|
146
|
+
if (!subject)
|
|
147
|
+
return undefined;
|
|
148
|
+
const stored = await readStored(home);
|
|
149
|
+
if (!stored)
|
|
150
|
+
return undefined;
|
|
151
|
+
const pass = verifyPlanPass(stored.pass, options.keys);
|
|
152
|
+
if (!pass || pass.subject !== subject)
|
|
153
|
+
return undefined;
|
|
154
|
+
const now = options.now ?? Date.now();
|
|
155
|
+
const floor = Math.max(stored.lastSeen, pass.issuedAt);
|
|
156
|
+
if (now < floor - CLOCK_SLACK_MS)
|
|
157
|
+
return undefined;
|
|
158
|
+
const current = Math.max(now, floor);
|
|
159
|
+
// Recorded before the expiry is judged: a pass seen lapsed stays lapsed when the clock is moved back.
|
|
160
|
+
if (current > stored.lastSeen)
|
|
161
|
+
await writeStored(home, { pass: stored.pass, lastSeen: current }).catch(() => { });
|
|
162
|
+
if (current >= pass.expiresAt)
|
|
163
|
+
return undefined;
|
|
164
|
+
return { ...pass, offline: true };
|
|
165
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readCodexCatalog } from './codex-provider.js';
|
|
2
2
|
import { codexConnectFor } from './codex-rpc.js';
|
|
3
3
|
import { readClaudeCatalog } from './claude-provider.js';
|
|
4
|
+
import { readGoogleCatalog } from './google-provider.js';
|
|
4
5
|
import { readGrokCatalog } from './grok-provider.js';
|
|
5
6
|
import { readOpenCodeCatalog } from './opencode-cli-provider.js';
|
|
6
7
|
import { CliUnavailableError } from './cli-executable.js';
|
|
@@ -61,6 +62,22 @@ export async function testProviderConnection(provider, signal, deps = {}) {
|
|
|
61
62
|
return failed(bounded.aborted ? 'The Grok sign-in check timed out.' : 'Grok sign-in or model discovery is unavailable.');
|
|
62
63
|
}
|
|
63
64
|
}
|
|
65
|
+
if (provider.type === 'google') {
|
|
66
|
+
try {
|
|
67
|
+
const catalog = await readGoogleCatalog(bounded);
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
if (!catalog.signedIn)
|
|
70
|
+
return failed('Sign in with Google in the Antigravity CLI on this machine before using this provider.');
|
|
71
|
+
return { ok: true, latencyMs: Date.now() - startedAt, modelCount: catalog.models.length,
|
|
72
|
+
...(provider.model.trim() ? { modelAvailable: catalog.models.includes(provider.model) } : {}) };
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
signal.throwIfAborted();
|
|
76
|
+
if (error instanceof CliUnavailableError)
|
|
77
|
+
return failed(error.message);
|
|
78
|
+
return failed(bounded.aborted ? 'The Google sign-in check timed out.' : 'Google sign-in or model discovery is unavailable.');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
64
81
|
if (provider.type === 'opencode') {
|
|
65
82
|
try {
|
|
66
83
|
const catalog = await readOpenCodeCatalog(bounded);
|
|
@@ -7,6 +7,11 @@ export interface EngineTransport {
|
|
|
7
7
|
anthropic: boolean;
|
|
8
8
|
contextWindow: number;
|
|
9
9
|
reasoningEffort?: string;
|
|
10
|
+
/**
|
|
11
|
+
* What an earlier assistant message carries as `reasoning_content` when none was kept for it (a turn replayed
|
|
12
|
+
* from a session, a summary, a model change). Set for endpoints that reject the request otherwise.
|
|
13
|
+
*/
|
|
14
|
+
missingReasoning?: string;
|
|
10
15
|
send(body: Record<string, unknown>): Promise<Response>;
|
|
11
16
|
parseWhole(response: Response): Promise<ModelResponse>;
|
|
12
17
|
streamValidator?(): {
|
|
@@ -228,13 +228,16 @@ export async function generateEngineResponse(request, host) {
|
|
|
228
228
|
const status = error.status;
|
|
229
229
|
if (status !== 400 && status !== 422)
|
|
230
230
|
throw error;
|
|
231
|
+
const recovered = () => request.onRecoveredError?.(`http_${status}`);
|
|
231
232
|
if (body.tool_choice !== undefined) {
|
|
232
233
|
const { tool_choice: _choice, ...unforced } = body;
|
|
234
|
+
recovered();
|
|
233
235
|
return sendWithFallbacks(unforced);
|
|
234
236
|
}
|
|
235
237
|
if (host.streamingDisabled?.())
|
|
236
238
|
throw error;
|
|
237
239
|
const { stream_options: _options, ...plain } = body;
|
|
240
|
+
recovered();
|
|
238
241
|
return host.send({ ...plain, stream: false });
|
|
239
242
|
}
|
|
240
243
|
};
|
|
@@ -366,10 +369,10 @@ export async function generateEngineResponse(request, host) {
|
|
|
366
369
|
delete body.store;
|
|
367
370
|
if (host.reasoningEffort !== undefined)
|
|
368
371
|
body.reasoning_effort = host.reasoningEffort;
|
|
369
|
-
if (
|
|
372
|
+
if (host.missingReasoning !== undefined) {
|
|
370
373
|
for (const message of body.messages) {
|
|
371
|
-
if (message.role === 'assistant' && message.reasoning_content === undefined)
|
|
372
|
-
message.reasoning_content =
|
|
374
|
+
if (message.role === 'assistant' && (message.reasoning_content === undefined || message.reasoning_content === ''))
|
|
375
|
+
message.reasoning_content = host.missingReasoning;
|
|
373
376
|
}
|
|
374
377
|
}
|
|
375
378
|
}
|