@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
|
@@ -5,7 +5,7 @@ import { RemotePeerError } from './remote/errors.js';
|
|
|
5
5
|
export const PEER_PROVIDER_EXPORT_CAPABILITY = 'remote.providers.export';
|
|
6
6
|
const PEER_IMPORT_DEADLINE_MS = 60_000;
|
|
7
7
|
const MAX_EXPORTED_PROVIDERS = 100;
|
|
8
|
-
const IMPORT_PROVIDER_TYPES = new Set(['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode']);
|
|
8
|
+
const IMPORT_PROVIDER_TYPES = new Set(['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode', 'google']);
|
|
9
9
|
function message(error) { return error instanceof Error ? error.message : String(error); }
|
|
10
10
|
export function normalizeExportedProvider(value) {
|
|
11
11
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
@@ -169,6 +169,8 @@ function credentialNote(provider) {
|
|
|
169
169
|
return 'Claude Code sign-in does not transfer; sign in on this machine after importing';
|
|
170
170
|
if (provider.type === 'grok')
|
|
171
171
|
return 'Grok sign-in does not transfer; sign in on this machine after importing';
|
|
172
|
+
if (provider.type === 'google')
|
|
173
|
+
return 'Google sign-in does not transfer; sign in on this machine after importing';
|
|
172
174
|
if (provider.type === 'opencode')
|
|
173
175
|
return 'OpenCode sign-ins do not transfer; connect its providers on this machine after importing';
|
|
174
176
|
if (provider.apiKey)
|
|
@@ -6,6 +6,7 @@ import { codexAccountHome } from './codex-rpc.js';
|
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
8
|
import { ANTHROPIC_CONSOLE_BASE_URL, anthropicAccountHome } from './anthropic-credentials.js';
|
|
9
|
+
import { GOOGLE_BASE_URL } from './google-provider.js';
|
|
9
10
|
import { GROK_BASE_URL } from './grok-provider.js';
|
|
10
11
|
import { OPENCODE_BASE_URL } from './opencode-cli-provider.js';
|
|
11
12
|
const defaultConsoleAuth = async () => new (await import('./anthropic-console-auth.js')).AnthropicConsoleAuth();
|
|
@@ -56,6 +57,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
56
57
|
{ id: 'openai', label: 'OpenAI' }, { id: 'anthropic', label: 'Anthropic' },
|
|
57
58
|
{ id: 'local', label: 'Local server' }, { id: 'codex', label: 'ChatGPT / Codex' },
|
|
58
59
|
{ id: 'claude', label: 'Claude subscription' }, { id: 'grok', label: 'Grok subscription (Grok CLI)' },
|
|
60
|
+
{ id: 'google', label: 'Google sign-in (Antigravity CLI)' },
|
|
59
61
|
{ id: 'opencode', label: 'OpenCode (CLI sign-in)' }, { id: 'opencode-go', label: 'OpenCode Go' },
|
|
60
62
|
{ id: 'custom', label: 'Custom provider' },
|
|
61
63
|
];
|
|
@@ -80,6 +82,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
80
82
|
codex: { type: 'codex', baseUrl: 'https://chatgpt.com/backend-api/codex', model: '' },
|
|
81
83
|
claude: { type: 'claude', baseUrl: 'https://api.anthropic.com', model: '' },
|
|
82
84
|
grok: { type: 'grok', baseUrl: GROK_BASE_URL, model: '' },
|
|
85
|
+
google: { type: 'google', baseUrl: GOOGLE_BASE_URL, model: '' },
|
|
83
86
|
opencode: { type: 'opencode', baseUrl: OPENCODE_BASE_URL, model: '' },
|
|
84
87
|
'opencode-go': { type: 'opencode-go', baseUrl: 'https://opencode.ai/inference/go', model: '' },
|
|
85
88
|
custom: { type: 'openai-compatible', baseUrl: 'https://api.openai.com/v1', model: '' },
|
|
@@ -130,7 +133,8 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
130
133
|
const isClaude = provider.type === 'claude';
|
|
131
134
|
const isGrok = provider.type === 'grok';
|
|
132
135
|
const isOpenCode = provider.type === 'opencode';
|
|
133
|
-
const
|
|
136
|
+
const isGoogle = provider.type === 'google';
|
|
137
|
+
const managed = isCodex || isClaude || isGrok || isOpenCode || isGoogle;
|
|
134
138
|
// Andorra's entry has a fixed endpoint, no key and a model list the service keeps current.
|
|
135
139
|
const isAndorra = provider.type === 'andorra';
|
|
136
140
|
const isConsole = provider.type === 'anthropic' && provider.anthropicAuth === 'console';
|
|
@@ -147,7 +151,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
147
151
|
{ id: 'apiKey', label: `API key: ${provider.apiKey ? 'saved (hidden)' : 'not saved'}` },
|
|
148
152
|
{ id: 'apiKeyEnv', label: `Environment fallback: ${provider.apiKeyEnv ?? 'none'}` },
|
|
149
153
|
...(provider.apiKey || provider.apiKeyEnv ? [{ id: 'clearAuth', label: 'Remove authentication' }] : []),
|
|
150
|
-
] : [{ id: 'login', label: isClaude ? 'Check Claude Code sign-in' : isGrok ? 'Check Grok sign-in' : isOpenCode ? 'Check OpenCode connection' : 'Sign in with ChatGPT / Codex' }]),
|
|
154
|
+
] : [{ id: 'login', label: isClaude ? 'Check Claude Code sign-in' : isGrok ? 'Check Grok sign-in' : isGoogle ? 'Check Google sign-in' : isOpenCode ? 'Check OpenCode connection' : 'Sign in with ChatGPT / Codex' }]),
|
|
151
155
|
{ id: 'name', label: `Display name: ${provider.name || 'not set'}` },
|
|
152
156
|
{ id: 'model', label: `Active model: ${provider.model ? modelDisplayName(provider, provider.model) : 'not set'}` },
|
|
153
157
|
...(isAndorra ? [] : [{ id: 'models', label: `Models: ${providerModels(provider).length || 'none'} configured` }]),
|
|
@@ -241,6 +245,8 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
241
245
|
return (await (await import('./claude-provider.js')).readClaudeCatalog(loadSignal)).models.map(id => ({ id }));
|
|
242
246
|
if (isGrok)
|
|
243
247
|
return (await (await import('./grok-provider.js')).readGrokCatalog(loadSignal)).models.map(id => ({ id }));
|
|
248
|
+
if (isGoogle)
|
|
249
|
+
return (await (await import('./google-provider.js')).readGoogleCatalog(loadSignal)).models.map(id => ({ id }));
|
|
244
250
|
if (isOpenCode)
|
|
245
251
|
return (await (await import('./opencode-cli-provider.js')).readOpenCodeCatalog(loadSignal)).models.map(model => ({ id: model.id }));
|
|
246
252
|
return (await discover(candidate, loadSignal) ?? []).map(id => ({ id }));
|
|
@@ -436,6 +442,12 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
436
442
|
throw new Error('Run grok login on this machine, then retry.');
|
|
437
443
|
return catalog.models.map(id => ({ id }));
|
|
438
444
|
}
|
|
445
|
+
if (isGoogle) {
|
|
446
|
+
const catalog = await (await import('./google-provider.js')).readGoogleCatalog(loadSignal);
|
|
447
|
+
if (!catalog.signedIn)
|
|
448
|
+
throw new Error('Run agy acp --login on this machine, then retry.');
|
|
449
|
+
return catalog.models.map(id => ({ id }));
|
|
450
|
+
}
|
|
439
451
|
if (isOpenCode) {
|
|
440
452
|
const catalog = await (await import('./opencode-cli-provider.js')).readOpenCodeCatalog(loadSignal);
|
|
441
453
|
if (!catalog.models.length)
|
package/dist/src/providers.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { ModelAdapter } from './types.js';
|
|
2
2
|
export declare const REASONING_EFFORTS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
3
|
+
/** Provider types whose requests carry a thinking-effort override. */
|
|
4
|
+
export declare const REASONING_EFFORT_PROVIDER_TYPES: readonly ["openai-compatible", "opencode-go", "anthropic"];
|
|
5
|
+
export declare function supportsReasoningEffort(type: string): boolean;
|
|
3
6
|
export type ReasoningEffort = typeof REASONING_EFFORTS[number];
|
|
4
|
-
export declare const PROVIDER_TYPES: readonly ["openai-compatible", "anthropic", "codex", "claude", "opencode-go", "grok", "opencode", "andorra"];
|
|
7
|
+
export declare const PROVIDER_TYPES: readonly ["openai-compatible", "anthropic", "codex", "claude", "opencode-go", "grok", "opencode", "google", "andorra"];
|
|
5
8
|
export type ProviderType = typeof PROVIDER_TYPES[number];
|
|
6
|
-
export declare const SIGN_IN_PROVIDER_TYPES: readonly ["codex", "claude", "grok", "opencode"];
|
|
9
|
+
export declare const SIGN_IN_PROVIDER_TYPES: readonly ["codex", "claude", "grok", "opencode", "google"];
|
|
7
10
|
export declare function isSignInProviderType(type: unknown): type is typeof SIGN_IN_PROVIDER_TYPES[number];
|
|
8
11
|
export declare const DEFAULT_REQUEST_TIMEOUT_MS: number;
|
|
9
12
|
export declare const MAX_REQUEST_TIMEOUT_MS = 86400000;
|
|
@@ -22,6 +25,10 @@ export interface ProviderConfig {
|
|
|
22
25
|
modelContextWindows?: Record<string, number>;
|
|
23
26
|
/** Andorra only: the router's display name for each model id. Shown to people; never used to look a model up. */
|
|
24
27
|
modelNames?: Record<string, string>;
|
|
28
|
+
/** Andorra only: the size the router states for a model id, in billions of parameters. Shown to people. */
|
|
29
|
+
modelParameters?: Record<string, number>;
|
|
30
|
+
/** Andorra only: the model ids the router serves free of the weekly allowance. Shown to people as a badge. */
|
|
31
|
+
freeModels?: string[];
|
|
25
32
|
contextWindow?: number;
|
|
26
33
|
reasoningEffort?: ReasoningEffort;
|
|
27
34
|
requestTimeoutMs?: number;
|
|
@@ -32,6 +39,11 @@ export interface ProviderConfig {
|
|
|
32
39
|
name?: string;
|
|
33
40
|
}
|
|
34
41
|
export declare function providerLabel(provider: Pick<ProviderConfig, 'id' | 'type' | 'codexEmail' | 'name'>, providers: readonly Pick<ProviderConfig, 'type'>[]): string;
|
|
42
|
+
/** The bounds of a hosted model's size in billions of parameters; the router and the admin page use the same ones. */
|
|
43
|
+
export declare const MIN_MODEL_PARAMETERS_BILLIONS = 0.001;
|
|
44
|
+
export declare const MAX_MODEL_PARAMETERS_BILLIONS = 100000;
|
|
45
|
+
/** Whether `value` is a size a hosted model may state: a finite number of billions of parameters in range. */
|
|
46
|
+
export declare function isModelParameters(value: unknown): value is number;
|
|
35
47
|
/** What a person reads for `model`: an Andorra entry's stored display name, otherwise the id itself. */
|
|
36
48
|
export declare function modelDisplayName(provider: Pick<ProviderConfig, 'type' | 'modelNames'> | undefined, model: string): string;
|
|
37
49
|
/** The model id an exact display name (any case) names on an Andorra entry; undefined for an id, another provider, or a name two models share. */
|
|
@@ -45,6 +57,14 @@ export declare function freeCodexAccountSlot(base: string, providers: readonly P
|
|
|
45
57
|
export declare function freeDraftCodexAccountSlot(base: string, draft: readonly Pick<ProviderConfig, 'id' | 'codexAccount'>[], saved: readonly Pick<ProviderConfig, 'id' | 'codexAccount'>[]): string;
|
|
46
58
|
export declare function allocateCodexAccountSlots(stored: readonly ProviderConfig[], next: readonly ProviderConfig[]): ProviderConfig[];
|
|
47
59
|
export declare function providerModels(provider: Pick<ProviderConfig, 'model' | 'models'>): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Provider and model ids are matched without regard to case, so a graph saved on a machine whose provider is "GX10"
|
|
62
|
+
* runs on a machine that calls the same provider "gx10". An exact match always wins; otherwise the one entry whose id
|
|
63
|
+
* differs only in case is taken, and none when several do. Callers use the returned entry's own spelling from then on.
|
|
64
|
+
*/
|
|
65
|
+
export declare function findProviderById<P extends Pick<ProviderConfig, 'id'>>(providers: readonly P[], id: string | undefined): P | undefined;
|
|
66
|
+
/** The provider's own spelling of `model`, matched as findProviderById matches ids; undefined when it does not offer it. */
|
|
67
|
+
export declare function providerModelId(provider: Pick<ProviderConfig, 'model' | 'models'>, model: string): string | undefined;
|
|
48
68
|
export declare function configuredContextWindow(provider: Pick<ProviderConfig, 'model' | 'modelContextWindows'>, model: string | undefined): number | undefined;
|
|
49
69
|
export declare function applyModelContextWindow(provider: ProviderConfig, model: string): void;
|
|
50
70
|
export declare function providerSecrets(providers: ProviderConfig[], env?: NodeJS.ProcessEnv): string[];
|
|
@@ -55,8 +75,19 @@ export declare function defaultProviders(): ProviderConfig[];
|
|
|
55
75
|
export declare const MALFORMED_RESPONSE_RETRIES = 5;
|
|
56
76
|
export declare class ProviderRequestError extends Error {
|
|
57
77
|
readonly contextOverflow: boolean;
|
|
78
|
+
/** The system error code behind a connection that could not be made; recorded with the failure, never part of the message. */
|
|
79
|
+
connectionCause?: string;
|
|
80
|
+
/** What kind of failure this was, for telemetry (`provider_timeout`, `http_429`); never shown and never part of the message. */
|
|
81
|
+
telemetryCode?: string;
|
|
58
82
|
constructor(message: string, contextOverflow?: boolean);
|
|
59
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* The telemetry error code for an error that ended a run: a provider failure's code, a record-only
|
|
86
|
+
* `telemetryCode` another adapter attached (Claude's exhausted malformed steps), or `runtime_error`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function runFailureCode(error: unknown): string;
|
|
89
|
+
/** The telemetry error code for a failed provider request: an OS code, a named kind, or `http_<status>`. */
|
|
90
|
+
export declare function providerFailureCode(error: unknown): string;
|
|
60
91
|
export declare const BLANK_TOOL_CALL_LIMIT = 4096;
|
|
61
92
|
export declare function createBlankToolCallGuard(limit?: number): {
|
|
62
93
|
fragment(text: string): void;
|
package/dist/src/providers.js
CHANGED
|
@@ -3,6 +3,7 @@ import { COMPLETION_TOOL } from './completion.js';
|
|
|
3
3
|
import { createCodexAdapter } from './codex-provider.js';
|
|
4
4
|
import { createClaudeAdapter } from './claude-provider.js';
|
|
5
5
|
import { createOpenCodeAdapter } from './opencode-provider.js';
|
|
6
|
+
import { createGoogleAdapter } from './google-provider.js';
|
|
6
7
|
import { createGrokAdapter } from './grok-provider.js';
|
|
7
8
|
import { createOpenCodeCliAdapter } from './opencode-cli-provider.js';
|
|
8
9
|
import { providerAuthHeaders } from './anthropic-credentials.js';
|
|
@@ -11,12 +12,17 @@ import { andorraRefusal } from './andorra/errors.js';
|
|
|
11
12
|
import { generateEngineResponse, isEngineContextOverflow } from './provider-engine.js';
|
|
12
13
|
import { estimateStreamedTokens } from './token-rate.js';
|
|
13
14
|
export const REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
14
|
-
|
|
15
|
-
export const
|
|
15
|
+
/** Provider types whose requests carry a thinking-effort override. */
|
|
16
|
+
export const REASONING_EFFORT_PROVIDER_TYPES = ['openai-compatible', 'opencode-go', 'anthropic'];
|
|
17
|
+
export function supportsReasoningEffort(type) {
|
|
18
|
+
return REASONING_EFFORT_PROVIDER_TYPES.includes(type);
|
|
19
|
+
}
|
|
20
|
+
export const PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode', 'google', 'andorra'];
|
|
21
|
+
export const SIGN_IN_PROVIDER_TYPES = ['codex', 'claude', 'grok', 'opencode', 'google'];
|
|
16
22
|
export function isSignInProviderType(type) {
|
|
17
23
|
return SIGN_IN_PROVIDER_TYPES.includes(type);
|
|
18
24
|
}
|
|
19
|
-
const SIGN_IN_PRODUCT = { codex: 'Codex', claude: 'Claude', grok: 'Grok', opencode: 'OpenCode' };
|
|
25
|
+
const SIGN_IN_PRODUCT = { codex: 'Codex', claude: 'Claude', grok: 'Grok', opencode: 'OpenCode', google: 'Google' };
|
|
20
26
|
export const DEFAULT_REQUEST_TIMEOUT_MS = 10 * 60_000;
|
|
21
27
|
export const MAX_REQUEST_TIMEOUT_MS = 86_400_000;
|
|
22
28
|
export function assertRequestTimeout(provider) {
|
|
@@ -56,6 +62,13 @@ export function providerLabel(provider, providers) {
|
|
|
56
62
|
const local = provider.codexEmail?.split('@')[0] || provider.id;
|
|
57
63
|
return `codex - ${local.length > 32 ? `${local.slice(0, 31)}…` : local}`;
|
|
58
64
|
}
|
|
65
|
+
/** The bounds of a hosted model's size in billions of parameters; the router and the admin page use the same ones. */
|
|
66
|
+
export const MIN_MODEL_PARAMETERS_BILLIONS = 0.001;
|
|
67
|
+
export const MAX_MODEL_PARAMETERS_BILLIONS = 100_000;
|
|
68
|
+
/** Whether `value` is a size a hosted model may state: a finite number of billions of parameters in range. */
|
|
69
|
+
export function isModelParameters(value) {
|
|
70
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= MIN_MODEL_PARAMETERS_BILLIONS && value <= MAX_MODEL_PARAMETERS_BILLIONS;
|
|
71
|
+
}
|
|
59
72
|
/** What a person reads for `model`: an Andorra entry's stored display name, otherwise the id itself. */
|
|
60
73
|
export function modelDisplayName(provider, model) {
|
|
61
74
|
const names = provider?.type === 'andorra' ? provider.modelNames : undefined;
|
|
@@ -115,6 +128,30 @@ export function providerModels(provider) {
|
|
|
115
128
|
return provider.models.filter(model => model.trim());
|
|
116
129
|
return provider.model.trim() ? [provider.model] : [];
|
|
117
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Provider and model ids are matched without regard to case, so a graph saved on a machine whose provider is "GX10"
|
|
133
|
+
* runs on a machine that calls the same provider "gx10". An exact match always wins; otherwise the one entry whose id
|
|
134
|
+
* differs only in case is taken, and none when several do. Callers use the returned entry's own spelling from then on.
|
|
135
|
+
*/
|
|
136
|
+
export function findProviderById(providers, id) {
|
|
137
|
+
if (id === undefined)
|
|
138
|
+
return undefined;
|
|
139
|
+
const exact = providers.find(provider => provider.id === id);
|
|
140
|
+
if (exact !== undefined)
|
|
141
|
+
return exact;
|
|
142
|
+
const folded = id.toLowerCase();
|
|
143
|
+
const matches = providers.filter(provider => typeof provider.id === 'string' && provider.id.toLowerCase() === folded);
|
|
144
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
145
|
+
}
|
|
146
|
+
/** The provider's own spelling of `model`, matched as findProviderById matches ids; undefined when it does not offer it. */
|
|
147
|
+
export function providerModelId(provider, model) {
|
|
148
|
+
const offered = [provider.model, ...(provider.models ?? [])].filter(item => typeof item === 'string' && item.trim());
|
|
149
|
+
if (offered.includes(model))
|
|
150
|
+
return model;
|
|
151
|
+
const folded = model.toLowerCase();
|
|
152
|
+
const matches = [...new Set(offered.filter(item => item.toLowerCase() === folded))];
|
|
153
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
154
|
+
}
|
|
118
155
|
export function configuredContextWindow(provider, model) {
|
|
119
156
|
const id = model ?? provider.model;
|
|
120
157
|
if (!provider.modelContextWindows || !Object.hasOwn(provider.modelContextWindows, id))
|
|
@@ -152,7 +189,7 @@ export function assertProviderCredentials(provider) {
|
|
|
152
189
|
if (provider.type === 'claude' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
153
190
|
throw new Error('Claude providers use Claude Code sign-in; API key overrides are not supported.');
|
|
154
191
|
}
|
|
155
|
-
if ((provider.type === 'grok' || provider.type === 'opencode') && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
192
|
+
if ((provider.type === 'grok' || provider.type === 'opencode' || provider.type === 'google') && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
156
193
|
throw new Error(`${SIGN_IN_PRODUCT[provider.type]} providers use their CLI sign-in; API key overrides are not supported.`);
|
|
157
194
|
}
|
|
158
195
|
if (provider.type === 'andorra' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
@@ -185,23 +222,54 @@ export function defaultProviders() {
|
|
|
185
222
|
{ id: 'local', type: 'openai-compatible', baseUrl: 'http://127.0.0.1:1234/v1', model: 'local-model' },
|
|
186
223
|
];
|
|
187
224
|
}
|
|
188
|
-
|
|
189
|
-
const REQUEST_RETRY_DELAYS_MS = [
|
|
225
|
+
// A transport fault is retried seven times: twice 5 seconds apart, three times 15 seconds apart, then twice a minute apart.
|
|
226
|
+
const REQUEST_RETRY_DELAYS_MS = [5_000, 5_000, 15_000, 15_000, 15_000, 60_000, 60_000];
|
|
227
|
+
const MAX_REQUEST_RETRIES = REQUEST_RETRY_DELAYS_MS.length;
|
|
190
228
|
const MALFORMED_STREAM_RETRY_DELAYS_MS = [1_000, 3_000, 10_000];
|
|
229
|
+
const MALFORMED_STREAM_RETRIES = MALFORMED_STREAM_RETRY_DELAYS_MS.length;
|
|
191
230
|
// A malformed response is usually the model's own slip (tool-call arguments that are not valid JSON), so asking
|
|
192
231
|
// again gets a fresh sample. It needs no long backoff and is retried quietly, more often than a transport fault.
|
|
193
232
|
export const MALFORMED_RESPONSE_RETRIES = 5;
|
|
194
233
|
const MALFORMED_RESPONSE_RETRY_DELAYS_MS = [250, 250, 500, 1_000, 2_000];
|
|
195
234
|
const MALFORMED_RESPONSE_MESSAGE = 'Provider returned a malformed response.';
|
|
196
|
-
|
|
235
|
+
// The longest Retry-After a provider may ask for; it is not tied to the backoff above.
|
|
236
|
+
const MAX_AUTOMATIC_RETRY_AFTER_MS = 120_000;
|
|
197
237
|
export class ProviderRequestError extends Error {
|
|
198
238
|
contextOverflow;
|
|
239
|
+
/** The system error code behind a connection that could not be made; recorded with the failure, never part of the message. */
|
|
240
|
+
connectionCause;
|
|
241
|
+
/** What kind of failure this was, for telemetry (`provider_timeout`, `http_429`); never shown and never part of the message. */
|
|
242
|
+
telemetryCode;
|
|
199
243
|
constructor(message, contextOverflow = false) {
|
|
200
244
|
super(message);
|
|
201
245
|
this.contextOverflow = contextOverflow;
|
|
202
246
|
this.name = 'Error';
|
|
203
247
|
}
|
|
204
248
|
}
|
|
249
|
+
function coded(error, code) { error.telemetryCode = code; return error; }
|
|
250
|
+
/**
|
|
251
|
+
* The telemetry error code for an error that ended a run: a provider failure's code, a record-only
|
|
252
|
+
* `telemetryCode` another adapter attached (Claude's exhausted malformed steps), or `runtime_error`.
|
|
253
|
+
*/
|
|
254
|
+
export function runFailureCode(error) {
|
|
255
|
+
if (error instanceof ProviderRequestError)
|
|
256
|
+
return providerFailureCode(error);
|
|
257
|
+
const code = error?.telemetryCode;
|
|
258
|
+
return typeof code === 'string' && code ? code : 'runtime_error';
|
|
259
|
+
}
|
|
260
|
+
/** The telemetry error code for a failed provider request: an OS code, a named kind, or `http_<status>`. */
|
|
261
|
+
export function providerFailureCode(error) {
|
|
262
|
+
if (!(error instanceof ProviderRequestError))
|
|
263
|
+
return 'provider_error';
|
|
264
|
+
if (error.connectionCause)
|
|
265
|
+
return error.connectionCause;
|
|
266
|
+
if (error.telemetryCode)
|
|
267
|
+
return error.telemetryCode;
|
|
268
|
+
if (error.contextOverflow)
|
|
269
|
+
return 'context_overflow';
|
|
270
|
+
const status = error.status;
|
|
271
|
+
return typeof status === 'number' && Number.isInteger(status) && status >= 100 && status <= 599 ? `http_${status}` : 'provider_error';
|
|
272
|
+
}
|
|
205
273
|
class RetryableProviderError extends ProviderRequestError {
|
|
206
274
|
retryAfterMs;
|
|
207
275
|
retryDelaysMs;
|
|
@@ -217,13 +285,13 @@ class RetryableProviderError extends ProviderRequestError {
|
|
|
217
285
|
}
|
|
218
286
|
}
|
|
219
287
|
class MalformedResponseProviderError extends RetryableProviderError {
|
|
220
|
-
constructor() { super(MALFORMED_RESPONSE_MESSAGE, 0, MALFORMED_RESPONSE_RETRY_DELAYS_MS, MALFORMED_RESPONSE_RETRIES, true); }
|
|
288
|
+
constructor() { super(MALFORMED_RESPONSE_MESSAGE, 0, MALFORMED_RESPONSE_RETRY_DELAYS_MS, MALFORMED_RESPONSE_RETRIES, true); this.telemetryCode = 'malformed_response'; }
|
|
221
289
|
}
|
|
222
290
|
class MalformedStreamProviderError extends MalformedResponseProviderError {
|
|
223
291
|
}
|
|
224
292
|
export const BLANK_TOOL_CALL_LIMIT = 4096;
|
|
225
293
|
class BlankToolCallProviderError extends RetryableProviderError {
|
|
226
|
-
constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS); }
|
|
294
|
+
constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS, MALFORMED_STREAM_RETRIES); this.telemetryCode = 'blank_tool_call'; }
|
|
227
295
|
}
|
|
228
296
|
export function createBlankToolCallGuard(limit = BLANK_TOOL_CALL_LIMIT) {
|
|
229
297
|
let blank = 0;
|
|
@@ -284,7 +352,7 @@ async function boundedJson(response) {
|
|
|
284
352
|
let bytes = 0;
|
|
285
353
|
try {
|
|
286
354
|
while (true) {
|
|
287
|
-
const chunk = await reader.read().catch(() => { throw new RetryableProviderError('Provider connection failed while reading its response.'); });
|
|
355
|
+
const chunk = await reader.read().catch(() => { throw coded(new RetryableProviderError('Provider connection failed while reading its response.'), 'stream_interrupted'); });
|
|
288
356
|
if (chunk.done)
|
|
289
357
|
break;
|
|
290
358
|
if (chunk.value.byteLength > buffer.length - bytes) {
|
|
@@ -686,7 +754,7 @@ function createAnthropicStreamAccumulator(now = Date.now) {
|
|
|
686
754
|
},
|
|
687
755
|
finish(requests, completionAdvertised) {
|
|
688
756
|
if (!started || !stopped || !finishReason)
|
|
689
|
-
throw new RetryableProviderError('Provider closed the stream before the response completed.');
|
|
757
|
+
throw coded(new RetryableProviderError('Provider closed the stream before the response completed.'), 'stream_interrupted');
|
|
690
758
|
const ordered = [...blocks.entries()].sort(([a], [b]) => a - b).map(([, block]) => block);
|
|
691
759
|
const text = ordered.filter(block => block.type === 'text').map(block => block.text).join('\n');
|
|
692
760
|
const measured = decodeWindow();
|
|
@@ -717,6 +785,8 @@ export function createAdapter(config, options = {}) {
|
|
|
717
785
|
return createClaudeAdapter(config);
|
|
718
786
|
if (config.type === 'grok')
|
|
719
787
|
return createGrokAdapter(config);
|
|
788
|
+
if (config.type === 'google')
|
|
789
|
+
return createGoogleAdapter(config);
|
|
720
790
|
if (config.type === 'opencode')
|
|
721
791
|
return createOpenCodeCliAdapter(config);
|
|
722
792
|
if (config.type === 'opencode-go')
|
|
@@ -753,7 +823,7 @@ export function createAdapter(config, options = {}) {
|
|
|
753
823
|
if (signal.aborted)
|
|
754
824
|
cancelled();
|
|
755
825
|
if (authDeadline?.aborted)
|
|
756
|
-
throw new RetryableProviderError('Provider request timed out.');
|
|
826
|
+
throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
|
|
757
827
|
throw error;
|
|
758
828
|
}
|
|
759
829
|
const headers = { 'content-type': 'application/json', ...sessionHeader, ...credential };
|
|
@@ -783,19 +853,18 @@ export function createAdapter(config, options = {}) {
|
|
|
783
853
|
if (signal.aborted)
|
|
784
854
|
throw new Error('Provider request cancelled.');
|
|
785
855
|
if (deadline?.aborted)
|
|
786
|
-
throw new RetryableProviderError('Provider request timed out.');
|
|
856
|
+
throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
|
|
787
857
|
// A connection that could not be made is not one of the router's refusals: it gets the usual bounded
|
|
788
858
|
// retries, and the plain sentence (no address, no error code) while retrying and when they run out.
|
|
789
859
|
if (andorra) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
throw
|
|
860
|
+
const failure = permanentConnectionFailure(error) ? new ProviderRequestError(ANDORRA_UNAVAILABLE_MESSAGE) : new RetryableProviderError(ANDORRA_UNAVAILABLE_MESSAGE);
|
|
861
|
+
failure.connectionCause = connectionFailureDetail(error);
|
|
862
|
+
throw coded(failure, 'connection_failed');
|
|
793
863
|
}
|
|
794
864
|
const cause = connectionFailureDetail(error);
|
|
795
865
|
const message = `Provider connection failed${cause ? ` (${cause})` : ''}. Check its URL and network connection.`;
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
throw new RetryableProviderError(message);
|
|
866
|
+
const failure = permanentConnectionFailure(error) ? new ProviderRequestError(message) : new RetryableProviderError(message);
|
|
867
|
+
throw coded(failure, cause ?? 'connection_failed');
|
|
799
868
|
}
|
|
800
869
|
if (response.status === 401 && config.anthropicAuth === 'console' && !forceRefresh) {
|
|
801
870
|
dispose();
|
|
@@ -816,12 +885,12 @@ export function createAdapter(config, options = {}) {
|
|
|
816
885
|
// The router's own refusals are sent once and shown as written here, never retried.
|
|
817
886
|
const refusal = andorra ? andorraRefusal(response.status, errorData, response.headers.get('retry-after')) : undefined;
|
|
818
887
|
if (refusal)
|
|
819
|
-
throw new ProviderRequestError(refusal);
|
|
888
|
+
throw coded(new ProviderRequestError(refusal), `http_${response.status}`);
|
|
820
889
|
const detail = providerErrorDetail(errorData);
|
|
821
890
|
const shown = detail === undefined ? undefined : redactCredential(detail, key);
|
|
822
891
|
const message = `Provider request failed (HTTP ${response.status})${shown ? `: ${shown}` : ''}. Check credentials, model, and provider availability.`;
|
|
823
892
|
if ([408, 409, 429, 500, 502, 503, 504, 529].includes(response.status)) {
|
|
824
|
-
throw new RetryableProviderError(message, retryAfter(response.headers.get('retry-after')));
|
|
893
|
+
throw coded(new RetryableProviderError(message, retryAfter(response.headers.get('retry-after'))), `http_${response.status}`);
|
|
825
894
|
}
|
|
826
895
|
throw new HttpProviderError(message, response.status);
|
|
827
896
|
}
|
|
@@ -909,7 +978,7 @@ export function createAdapter(config, options = {}) {
|
|
|
909
978
|
if (signal.aborted)
|
|
910
979
|
throw new Error('Provider request cancelled.');
|
|
911
980
|
if (deadline?.aborted)
|
|
912
|
-
throw new RetryableProviderError('Provider request timed out.');
|
|
981
|
+
throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
|
|
913
982
|
if (error instanceof ResponseTooLargeError || error instanceof RetryableProviderError)
|
|
914
983
|
throw error;
|
|
915
984
|
return malformed();
|
|
@@ -931,12 +1000,13 @@ export function createAdapter(config, options = {}) {
|
|
|
931
1000
|
if (retry >= error.maxRetries)
|
|
932
1001
|
throw error;
|
|
933
1002
|
if (error.retryAfterMs > MAX_AUTOMATIC_RETRY_AFTER_MS)
|
|
934
|
-
throw new ProviderRequestError(`${error.message} Retry-After exceeds the 120-second automatic retry limit.`);
|
|
1003
|
+
throw coded(new ProviderRequestError(`${error.message} Retry-After exceeds the 120-second automatic retry limit.`), providerFailureCode(error));
|
|
935
1004
|
const delayMs = Math.max(error.retryDelaysMs[retry] ?? error.retryDelaysMs.at(-1) ?? 0, error.retryAfterMs);
|
|
936
1005
|
const reason = error instanceof MalformedStreamProviderError
|
|
937
1006
|
? 'Provider returned a malformed streamed response; retrying without streaming.'
|
|
938
1007
|
: error.message;
|
|
939
|
-
await onRetry?.({ retry: retry + 1, maxRetries: error.maxRetries, delayMs, reason, ...(error.quiet ? { quiet: true } : {})
|
|
1008
|
+
await onRetry?.({ retry: retry + 1, maxRetries: error.maxRetries, delayMs, reason, code: providerFailureCode(error), ...(error.quiet ? { quiet: true } : {}),
|
|
1009
|
+
...(error.connectionCause ? { cause: error.connectionCause } : {}) });
|
|
940
1010
|
try {
|
|
941
1011
|
await delay(delayMs, undefined, { signal });
|
|
942
1012
|
}
|
|
@@ -961,6 +1031,9 @@ export function createAdapter(config, options = {}) {
|
|
|
961
1031
|
providerId: config.id, baseUrl: base.href.replace(/\/$/, ''), anthropic,
|
|
962
1032
|
contextWindow: model === config.model ? config.contextWindow ?? 128_000 : 128_000,
|
|
963
1033
|
reasoningEffort: model === config.model ? config.reasoningEffort : undefined,
|
|
1034
|
+
// DeepSeek takes an empty string. Andorra's router rejects an empty one like an absent one (HTTP 400,
|
|
1035
|
+
// "Missing required parameter: 'messages[n].reasoning_content'") and takes a single space.
|
|
1036
|
+
...(andorra ? { missingReasoning: ' ' } : base.origin === 'https://api.deepseek.com' ? { missingReasoning: '' } : {}),
|
|
964
1037
|
async send(body) {
|
|
965
1038
|
deadline = undefined;
|
|
966
1039
|
dispose?.();
|
|
@@ -985,7 +1058,7 @@ export function createAdapter(config, options = {}) {
|
|
|
985
1058
|
if (signal.aborted)
|
|
986
1059
|
cancelled();
|
|
987
1060
|
if (deadline?.aborted)
|
|
988
|
-
throw new RetryableProviderError('Provider request timed out.');
|
|
1061
|
+
throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
|
|
989
1062
|
if (error instanceof ResponseTooLargeError || error instanceof RetryableProviderError)
|
|
990
1063
|
throw error;
|
|
991
1064
|
return malformed();
|
|
@@ -1027,7 +1100,7 @@ export function createAdapter(config, options = {}) {
|
|
|
1027
1100
|
...(thinking.length ? { providerContinuation: { api: 'anthropic-messages', provider: config.id, model, thinking } } : {}) };
|
|
1028
1101
|
},
|
|
1029
1102
|
checkCalls: calls => checkCalls(calls, advertised),
|
|
1030
|
-
streamReadError: () => new RetryableProviderError('Provider connection failed while reading its response.'),
|
|
1103
|
+
streamReadError: () => coded(new RetryableProviderError('Provider connection failed while reading its response.'), 'stream_interrupted'),
|
|
1031
1104
|
streamMalformedError: () => new MalformedStreamProviderError(),
|
|
1032
1105
|
streamingDisabled: () => currentRequestNonStreaming,
|
|
1033
1106
|
...(anthropic ? { streamValidator() {
|
|
@@ -1037,7 +1110,7 @@ export function createAdapter(config, options = {}) {
|
|
|
1037
1110
|
const validator = createStreamAccumulator(() => { });
|
|
1038
1111
|
return { event: validator.event, finish() {
|
|
1039
1112
|
if (!validator.completed)
|
|
1040
|
-
throw new RetryableProviderError('Provider closed the stream before the response completed.');
|
|
1113
|
+
throw coded(new RetryableProviderError('Provider closed the stream before the response completed.'), 'stream_interrupted');
|
|
1041
1114
|
return validator.finish(requests, advertised);
|
|
1042
1115
|
} };
|
|
1043
1116
|
} }),
|
|
@@ -1045,7 +1118,7 @@ export function createAdapter(config, options = {}) {
|
|
|
1045
1118
|
if (signal.aborted)
|
|
1046
1119
|
cancelled();
|
|
1047
1120
|
if (deadline?.aborted)
|
|
1048
|
-
throw new RetryableProviderError('Provider request timed out.');
|
|
1121
|
+
throw coded(new RetryableProviderError('Provider request timed out.'), 'provider_timeout');
|
|
1049
1122
|
if (error instanceof Error && !(error instanceof RetryableProviderError) && error.message === MALFORMED_RESPONSE_MESSAGE)
|
|
1050
1123
|
throw new MalformedResponseProviderError();
|
|
1051
1124
|
throw error;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type PullRequestCheckState = 'passed' | 'failed' | 'pending' | 'skipped' | 'neutral' | 'cancelled';
|
|
2
|
+
export interface PullRequestCheck {
|
|
3
|
+
name: string;
|
|
4
|
+
workflow?: string;
|
|
5
|
+
state: PullRequestCheckState;
|
|
6
|
+
url?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
startedAt?: string;
|
|
9
|
+
completedAt?: string;
|
|
10
|
+
}
|
|
11
|
+
/** The checks on the head commit, rolled up: failed if any failed, pending if any is still running, passed otherwise. */
|
|
12
|
+
export interface PullRequestChecksRollup {
|
|
13
|
+
state: 'passed' | 'failed' | 'pending';
|
|
14
|
+
total: number;
|
|
15
|
+
passed: number;
|
|
16
|
+
failed: number;
|
|
17
|
+
pending: number;
|
|
18
|
+
}
|
|
19
|
+
/** One CheckRun or StatusContext from `statusCheckRollup`, in the tab's words. */
|
|
20
|
+
export declare function parseCheck(value: unknown): PullRequestCheck | undefined;
|
|
21
|
+
/** Cancelled, skipped and neutral checks neither pass nor fail the rollup; with nothing else there is no rollup. */
|
|
22
|
+
export declare function checksRollup(checks: readonly Pick<PullRequestCheck, 'state'>[]): PullRequestChecksRollup | undefined;
|
|
23
|
+
export declare function sameChecksRollup(a: PullRequestChecksRollup | undefined, b: PullRequestChecksRollup | undefined): boolean;
|
|
24
|
+
export declare function isChecksRollup(value: unknown): value is PullRequestChecksRollup;
|
|
25
|
+
/** Every check's rollup from a raw `statusCheckRollup` list. */
|
|
26
|
+
export declare function rollupOf(raw: unknown): PullRequestChecksRollup | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The checks on a pull request's head commit, as GitHub's `statusCheckRollup` reports them, in the
|
|
2
|
+
// desktop's words. Both the PR watcher (for the sidebar's failing-checks mark) and the PR tab read them.
|
|
3
|
+
const text = (value) => typeof value === 'string' && value !== '' ? value : undefined;
|
|
4
|
+
const record = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
5
|
+
// GitHub reports a check that has not finished with the zero time.
|
|
6
|
+
const stamp = (value) => { const at = text(value); return at === undefined || at.startsWith('0001-01-01') ? undefined : at; };
|
|
7
|
+
/** One CheckRun or StatusContext from `statusCheckRollup`, in the tab's words. */
|
|
8
|
+
export function parseCheck(value) {
|
|
9
|
+
const node = record(value);
|
|
10
|
+
if (node.__typename === 'StatusContext' || (node.context !== undefined && node.name === undefined)) {
|
|
11
|
+
const name = text(node.context);
|
|
12
|
+
if (name === undefined)
|
|
13
|
+
return undefined;
|
|
14
|
+
const state = node.state === 'SUCCESS' ? 'passed' : node.state === 'FAILURE' || node.state === 'ERROR' ? 'failed' : 'pending';
|
|
15
|
+
return { name, state, ...defined({ url: text(node.targetUrl), description: text(node.description), startedAt: stamp(node.startedAt) ?? stamp(node.createdAt) }) };
|
|
16
|
+
}
|
|
17
|
+
const name = text(node.name);
|
|
18
|
+
if (name === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
const conclusion = typeof node.conclusion === 'string' ? node.conclusion : '';
|
|
21
|
+
const state = node.status !== 'COMPLETED' ? 'pending'
|
|
22
|
+
: conclusion === 'SUCCESS' ? 'passed'
|
|
23
|
+
: conclusion === 'SKIPPED' ? 'skipped'
|
|
24
|
+
: conclusion === 'NEUTRAL' ? 'neutral'
|
|
25
|
+
: conclusion === 'CANCELLED' ? 'cancelled'
|
|
26
|
+
: conclusion === '' ? 'pending' : 'failed';
|
|
27
|
+
return { name, state, ...defined({ workflow: text(node.workflowName), url: text(node.detailsUrl), startedAt: stamp(node.startedAt), completedAt: stamp(node.completedAt) }) };
|
|
28
|
+
}
|
|
29
|
+
/** Cancelled, skipped and neutral checks neither pass nor fail the rollup; with nothing else there is no rollup. */
|
|
30
|
+
export function checksRollup(checks) {
|
|
31
|
+
const passed = checks.filter(check => check.state === 'passed').length;
|
|
32
|
+
const failed = checks.filter(check => check.state === 'failed').length;
|
|
33
|
+
const pending = checks.filter(check => check.state === 'pending').length;
|
|
34
|
+
if (passed + failed + pending === 0)
|
|
35
|
+
return undefined;
|
|
36
|
+
return { state: failed > 0 ? 'failed' : pending > 0 ? 'pending' : 'passed', total: checks.length, passed, failed, pending };
|
|
37
|
+
}
|
|
38
|
+
export function sameChecksRollup(a, b) {
|
|
39
|
+
return a === b || (a !== undefined && b !== undefined && a.state === b.state && a.total === b.total && a.passed === b.passed && a.failed === b.failed && a.pending === b.pending);
|
|
40
|
+
}
|
|
41
|
+
export function isChecksRollup(value) {
|
|
42
|
+
const rollup = record(value);
|
|
43
|
+
return (rollup.state === 'passed' || rollup.state === 'failed' || rollup.state === 'pending')
|
|
44
|
+
&& [rollup.total, rollup.passed, rollup.failed, rollup.pending].every(entry => typeof entry === 'number' && Number.isSafeInteger(entry) && entry >= 0);
|
|
45
|
+
}
|
|
46
|
+
/** Every check's rollup from a raw `statusCheckRollup` list. */
|
|
47
|
+
export function rollupOf(raw) {
|
|
48
|
+
return Array.isArray(raw) ? checksRollup(raw.map(parseCheck).filter((check) => check !== undefined)) : undefined;
|
|
49
|
+
}
|
|
50
|
+
function defined(values) {
|
|
51
|
+
const kept = {};
|
|
52
|
+
for (const [key, value] of Object.entries(values))
|
|
53
|
+
if (value !== undefined)
|
|
54
|
+
kept[key] = value;
|
|
55
|
+
return kept;
|
|
56
|
+
}
|