@andorra-labs/code 0.1.13 → 0.1.15
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/account-presentation.js +4 -1
- package/dist/src/acp-agent.d.ts +54 -0
- package/dist/src/acp-agent.js +991 -0
- package/dist/src/agent-execution.js +304 -140
- package/dist/src/agent-mcp-catalog.js +2 -0
- package/dist/src/agent-mcp.d.ts +2 -0
- package/dist/src/agent-mcp.js +86 -4
- package/dist/src/andorra/endpoint.d.ts +7 -0
- package/dist/src/andorra/endpoint.js +46 -0
- package/dist/src/andorra/entry.d.ts +21 -0
- package/dist/src/andorra/entry.js +118 -0
- package/dist/src/andorra/errors.d.ts +2 -0
- package/dist/src/andorra/errors.js +39 -0
- package/dist/src/andorra/hosted.d.ts +55 -0
- package/dist/src/andorra/hosted.js +130 -0
- package/dist/src/andorra/monitor.d.ts +151 -0
- package/dist/src/andorra/monitor.js +393 -0
- package/dist/src/andorra/notices.d.ts +16 -0
- package/dist/src/andorra/notices.js +38 -0
- package/dist/src/andorra/opt-in.d.ts +58 -0
- package/dist/src/andorra/opt-in.js +112 -0
- package/dist/src/andorra/request-watch.d.ts +6 -0
- package/dist/src/andorra/request-watch.js +10 -0
- package/dist/src/andorra/state.d.ts +86 -0
- package/dist/src/andorra/state.js +238 -0
- package/dist/src/andorra/terminal.d.ts +70 -0
- package/dist/src/andorra/terminal.js +125 -0
- package/dist/src/andorra/usage-format.d.ts +9 -0
- package/dist/src/andorra/usage-format.js +19 -0
- package/dist/src/anthropic-credentials.js +9 -1
- package/dist/src/app-server/protocol.d.ts +10 -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 +35 -0
- package/dist/src/app-server.js +377 -124
- package/dist/src/auth/AuthManager.d.ts +9 -0
- package/dist/src/auth/AuthManager.js +164 -24
- package/dist/src/auth/deployment.d.ts +1 -0
- package/dist/src/auth/deployment.js +1 -0
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +26 -0
- package/dist/src/auth/store.js +34 -1
- 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 -1
- package/dist/src/browser-server.d.ts +5 -0
- package/dist/src/browser-server.js +27 -3
- package/dist/src/browser-stealth.d.ts +19 -1
- package/dist/src/browser-stealth.js +23 -3
- package/dist/src/browser-ui/tokens.css +4 -4
- package/dist/src/browser-view.d.ts +81 -0
- package/dist/src/browser-view.js +289 -18
- 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 +10 -8
- package/dist/src/cli-sign-in.d.ts +3 -1
- package/dist/src/cli-sign-in.js +4 -1
- package/dist/src/cli.js +205 -58
- package/dist/src/coding-tools.js +7 -7
- package/dist/src/command-screens.d.ts +26 -3
- package/dist/src/command-screens.js +323 -85
- package/dist/src/commands.d.ts +7 -1
- package/dist/src/commands.js +79 -27
- package/dist/src/completion-gates.d.ts +22 -0
- package/dist/src/completion-gates.js +11 -0
- package/dist/src/config.d.ts +11 -1
- package/dist/src/config.js +134 -3
- package/dist/src/dashboard-view.d.ts +2 -0
- package/dist/src/dashboard-view.js +11 -2
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/decision/applyToolMenu.js +1 -1
- package/dist/src/decision/toolFamilies.js +1 -1
- package/dist/src/decision/types.d.ts +1 -0
- package/dist/src/google-provider.d.ts +31 -0
- package/dist/src/google-provider.js +153 -0
- package/dist/src/graph-health.d.ts +11 -0
- package/dist/src/graph-health.js +36 -4
- package/dist/src/graph-manager-chat.d.ts +33 -0
- package/dist/src/graph-manager-chat.js +165 -6
- package/dist/src/graph-runner.js +27 -0
- package/dist/src/graph-selection.js +2 -1
- 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 +92 -10
- package/dist/src/graph-ui/edge-router.js +121 -53
- package/dist/src/graph-ui/manager.js +40 -5
- package/dist/src/graph-ui/style.css +5 -2
- package/dist/src/graph-ui/tokens.css +4 -4
- package/dist/src/graph-visibility.d.ts +31 -0
- package/dist/src/graph-visibility.js +102 -0
- package/dist/src/graphs.js +1 -3
- package/dist/src/hardened-runtime.js +1 -1
- 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 +6 -2
- package/dist/src/membership.d.ts +13 -2
- package/dist/src/membership.js +39 -8
- package/dist/src/model-context-windows.d.ts +2 -0
- package/dist/src/model-context-windows.js +24 -0
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +1 -0
- package/dist/src/model-metadata.js +47 -3
- package/dist/src/paged-transcript.d.ts +2 -0
- package/dist/src/paged-transcript.js +16 -0
- package/dist/src/palette.d.ts +1 -0
- package/dist/src/palette.js +1 -1
- package/dist/src/permissions.js +17 -4
- package/dist/src/provider-connection.js +32 -0
- package/dist/src/provider-engine.d.ts +5 -0
- package/dist/src/provider-engine.js +3 -3
- package/dist/src/provider-import.js +3 -1
- package/dist/src/provider-settings.d.ts +16 -1
- package/dist/src/provider-settings.js +50 -22
- package/dist/src/providers.d.ts +29 -3
- package/dist/src/providers.js +100 -18
- package/dist/src/react-runtime.js +33 -12
- 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 +31 -6
- package/dist/src/run-control.d.ts +2 -2
- package/dist/src/run-control.js +9 -6
- package/dist/src/runtime-environment.d.ts +1 -0
- package/dist/src/runtime-environment.js +13 -0
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/runtime.js +2 -1
- 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/sessions.d.ts +1 -0
- package/dist/src/sessions.js +4 -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 +2 -1
- package/dist/src/skills/bundled/provenance.json +743 -738
- package/dist/src/skills/runtime-skills.js +1 -0
- package/dist/src/subagent-run.d.ts +2 -0
- package/dist/src/subagent-run.js +14 -3
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +2 -2
- package/dist/src/telemetry/uploader.d.ts +7 -1
- package/dist/src/telemetry/uploader.js +11 -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 +29 -1
- package/dist/src/terminal-ui.js +113 -24
- 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 +5 -1
- package/dist/src/types.d.ts +5 -0
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +13 -1
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { validateConfig } from './config.js';
|
|
2
|
-
import {
|
|
2
|
+
import { fallbackProviderId } from './andorra/entry.js';
|
|
3
|
+
import { applyModelContextWindow, createAdapter, freeDraftCodexAccountSlot, modelDisplayName, providerModels, recordProviderModel, REASONING_EFFORTS } from './providers.js';
|
|
3
4
|
import { retireUnsavedCodexAccounts } from './codex-auth.js';
|
|
4
5
|
import { codexAccountHome } from './codex-rpc.js';
|
|
5
6
|
import { randomUUID } from 'node:crypto';
|
|
6
7
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
8
|
import { ANTHROPIC_CONSOLE_BASE_URL, anthropicAccountHome } from './anthropic-credentials.js';
|
|
9
|
+
import { GOOGLE_BASE_URL } from './google-provider.js';
|
|
8
10
|
import { GROK_BASE_URL } from './grok-provider.js';
|
|
9
11
|
import { OPENCODE_BASE_URL } from './opencode-cli-provider.js';
|
|
10
12
|
const defaultConsoleAuth = async () => new (await import('./anthropic-console-auth.js')).AnthropicConsoleAuth();
|
|
11
13
|
const defaultModelLister = async (provider, signal) => createAdapter(provider).listModels?.(signal);
|
|
12
|
-
|
|
14
|
+
const ANDORRA_PRESET = ':andorra';
|
|
15
|
+
export async function editProviderSettings(config, id, ui, signal, login = async (options) => (await import('./codex-auth.js')).loginCodex(options), retire = retireUnsavedCodexAccounts, consoleAuth = defaultConsoleAuth, discover = defaultModelLister, andorra) {
|
|
13
16
|
const abandon = {};
|
|
14
17
|
try {
|
|
15
|
-
return await editDraft(config, id, ui, signal, login, retire, consoleAuth, abandon, discover);
|
|
18
|
+
return await editDraft(config, id, ui, signal, login, retire, consoleAuth, abandon, discover, andorra);
|
|
16
19
|
}
|
|
17
20
|
catch (error) {
|
|
18
21
|
await abandon.discard?.().catch(() => { });
|
|
19
22
|
throw error;
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
|
-
async function editDraft(config, id, ui, signal, login, retire, consoleAuth, abandon, discover) {
|
|
25
|
+
async function editDraft(config, id, ui, signal, login, retire, consoleAuth, abandon, discover, andorra) {
|
|
23
26
|
if (!ui.question)
|
|
24
27
|
throw new Error('Provider settings require interactive input.');
|
|
25
28
|
const draft = structuredClone(config);
|
|
@@ -42,18 +45,31 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
42
45
|
const ask = async (label, secret = false) => (await ui.question(label, { title: label, signal, cancelOnEscape: true, history: false, secret })).trim();
|
|
43
46
|
const invalid = () => ui.showScreen('Invalid setting', ['That value is not valid. Your saved configuration has not changed.'], { signal });
|
|
44
47
|
if (!provider) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
const presetRows = () => {
|
|
49
|
+
// Andorra has nothing to fill in (no key, no address): choosing it adds it and returns to the list. Its row
|
|
50
|
+
// is there while it can be added, and comes or goes in place when a check answers while the list is open.
|
|
51
|
+
const offered = andorra?.description();
|
|
52
|
+
return [
|
|
53
|
+
...(offered ? [{ id: ANDORRA_PRESET, label: 'Andorra', description: offered }] : []),
|
|
54
|
+
{ id: 'deepseek', label: 'DeepSeek' }, { id: 'kimi', label: 'Kimi / Moonshot' },
|
|
55
|
+
{ id: 'kimi-coding', label: 'Kimi For Coding (Global)' }, { id: 'kimi-coding-cn', label: 'Kimi For Coding (China)' },
|
|
56
|
+
{ id: 'glm', label: 'GLM Coding Plan (Z.ai)' },
|
|
57
|
+
{ id: 'openai', label: 'OpenAI' }, { id: 'anthropic', label: 'Anthropic' },
|
|
58
|
+
{ id: 'local', label: 'Local server' }, { id: 'codex', label: 'ChatGPT / Codex' },
|
|
59
|
+
{ id: 'claude', label: 'Claude subscription' }, { id: 'grok', label: 'Grok subscription (Grok CLI)' },
|
|
60
|
+
{ id: 'google', label: 'Google sign-in (Antigravity CLI)' },
|
|
61
|
+
{ id: 'opencode', label: 'OpenCode (CLI sign-in)' }, { id: 'opencode-go', label: 'OpenCode Go' },
|
|
62
|
+
{ id: 'custom', label: 'Custom provider' },
|
|
63
|
+
];
|
|
64
|
+
};
|
|
65
|
+
const refresh = andorra?.refresh?.(presetRows);
|
|
66
|
+
const preset = await ui.select('Add provider', presetRows(), { signal, ...(refresh ? { refresh } : {}) });
|
|
55
67
|
if (!preset || signal.aborted)
|
|
56
68
|
return;
|
|
69
|
+
if (preset === ANDORRA_PRESET) {
|
|
70
|
+
await andorra?.add();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
57
73
|
const presets = {
|
|
58
74
|
deepseek: { type: 'openai-compatible', baseUrl: 'https://api.deepseek.com', model: '' },
|
|
59
75
|
kimi: { type: 'openai-compatible', baseUrl: 'https://api.moonshot.ai/v1', model: '' },
|
|
@@ -66,6 +82,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
66
82
|
codex: { type: 'codex', baseUrl: 'https://chatgpt.com/backend-api/codex', model: '' },
|
|
67
83
|
claude: { type: 'claude', baseUrl: 'https://api.anthropic.com', model: '' },
|
|
68
84
|
grok: { type: 'grok', baseUrl: GROK_BASE_URL, model: '' },
|
|
85
|
+
google: { type: 'google', baseUrl: GOOGLE_BASE_URL, model: '' },
|
|
69
86
|
opencode: { type: 'opencode', baseUrl: OPENCODE_BASE_URL, model: '' },
|
|
70
87
|
'opencode-go': { type: 'opencode-go', baseUrl: 'https://opencode.ai/inference/go', model: '' },
|
|
71
88
|
custom: { type: 'openai-compatible', baseUrl: 'https://api.openai.com/v1', model: '' },
|
|
@@ -116,13 +133,16 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
116
133
|
const isClaude = provider.type === 'claude';
|
|
117
134
|
const isGrok = provider.type === 'grok';
|
|
118
135
|
const isOpenCode = provider.type === 'opencode';
|
|
119
|
-
const
|
|
136
|
+
const isGoogle = provider.type === 'google';
|
|
137
|
+
const managed = isCodex || isClaude || isGrok || isOpenCode || isGoogle;
|
|
138
|
+
// Andorra's entry has a fixed endpoint, no key and a model list the service keeps current.
|
|
139
|
+
const isAndorra = provider.type === 'andorra';
|
|
120
140
|
const isConsole = provider.type === 'anthropic' && provider.anthropicAuth === 'console';
|
|
121
141
|
const field = await choose(`Providers > ${provider.id}`, [
|
|
122
142
|
...(isConsole ? [
|
|
123
143
|
{ id: 'anthropicAuth', label: 'Credential: Claude Console sign-in' },
|
|
124
144
|
{ id: 'consoleLogin', label: 'Sign in with Claude Console' },
|
|
125
|
-
] : !managed ? [
|
|
145
|
+
] : isAndorra ? [] : !managed ? [
|
|
126
146
|
...(provider.type === 'opencode-go' ? [] : [
|
|
127
147
|
{ id: 'type', label: `Protocol: ${provider.type}` },
|
|
128
148
|
{ id: 'baseUrl', label: `Endpoint: ${provider.baseUrl}` },
|
|
@@ -131,10 +151,10 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
131
151
|
{ id: 'apiKey', label: `API key: ${provider.apiKey ? 'saved (hidden)' : 'not saved'}` },
|
|
132
152
|
{ id: 'apiKeyEnv', label: `Environment fallback: ${provider.apiKeyEnv ?? 'none'}` },
|
|
133
153
|
...(provider.apiKey || provider.apiKeyEnv ? [{ id: 'clearAuth', label: 'Remove authentication' }] : []),
|
|
134
|
-
] : [{ 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' }]),
|
|
135
155
|
{ id: 'name', label: `Display name: ${provider.name || 'not set'}` },
|
|
136
|
-
{ id: 'model', label: `Active model: ${provider.model
|
|
137
|
-
{ id: 'models', label: `Models: ${providerModels(provider).length || 'none'} configured` },
|
|
156
|
+
{ id: 'model', label: `Active model: ${provider.model ? modelDisplayName(provider, provider.model) : 'not set'}` },
|
|
157
|
+
...(isAndorra ? [] : [{ id: 'models', label: `Models: ${providerModels(provider).length || 'none'} configured` }]),
|
|
138
158
|
{ id: 'discover', label: 'Browse available models' },
|
|
139
159
|
{ id: 'contextWindow', label: `Context window: ${provider.contextWindow ?? 'automatic'}` },
|
|
140
160
|
...(!managed ? [
|
|
@@ -162,7 +182,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
162
182
|
}
|
|
163
183
|
if (field === 'delete') {
|
|
164
184
|
const remaining = draft.providers.filter(item => item.id !== provider.id);
|
|
165
|
-
const next = draft.provider === provider.id ? remaining
|
|
185
|
+
const next = draft.provider === provider.id ? fallbackProviderId(remaining) : draft.provider;
|
|
166
186
|
const confirmed = await choose('Delete provider?', [{ id: 'cancel', label: 'Keep provider' }, { id: 'confirm', label: `Delete ${provider.id}${next ? `; active provider: ${next}` : '; no active provider'}` }], 'cancel');
|
|
167
187
|
if (confirmed !== 'confirm')
|
|
168
188
|
continue;
|
|
@@ -225,6 +245,8 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
225
245
|
return (await (await import('./claude-provider.js')).readClaudeCatalog(loadSignal)).models.map(id => ({ id }));
|
|
226
246
|
if (isGrok)
|
|
227
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 }));
|
|
228
250
|
if (isOpenCode)
|
|
229
251
|
return (await (await import('./opencode-cli-provider.js')).readOpenCodeCatalog(loadSignal)).models.map(model => ({ id: model.id }));
|
|
230
252
|
return (await discover(candidate, loadSignal) ?? []).map(id => ({ id }));
|
|
@@ -239,7 +261,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
239
261
|
unavailable = true;
|
|
240
262
|
}
|
|
241
263
|
const rows = new Map();
|
|
242
|
-
const row = (model, recommended) => ({ id: `:use:${model}`, label: `${model}${model === candidate.model ? ' · active' : ''}${recommended ? ' (recommended)' : ''}` });
|
|
264
|
+
const row = (model, recommended) => ({ id: `:use:${model}`, label: `${modelDisplayName(candidate, model)}${model === candidate.model ? ' · active' : ''}${recommended ? ' (recommended)' : ''}` });
|
|
243
265
|
for (const model of providerModels(candidate))
|
|
244
266
|
rows.set(model, row(model));
|
|
245
267
|
for (const model of listed)
|
|
@@ -420,6 +442,12 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
420
442
|
throw new Error('Run grok login on this machine, then retry.');
|
|
421
443
|
return catalog.models.map(id => ({ id }));
|
|
422
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
|
+
}
|
|
423
451
|
if (isOpenCode) {
|
|
424
452
|
const catalog = await (await import('./opencode-cli-provider.js')).readOpenCodeCatalog(loadSignal);
|
|
425
453
|
if (!catalog.models.length)
|
|
@@ -442,7 +470,7 @@ async function editDraft(config, id, ui, signal, login, retire, consoleAuth, aba
|
|
|
442
470
|
const preferred = models.find(model => model.id === candidate.model)?.id
|
|
443
471
|
?? models.find(model => model.isDefault)?.id ?? models[0].id;
|
|
444
472
|
const model = await choose('Choose model', [...new Map(models.map(model => [model.id, model])).values()]
|
|
445
|
-
.map(model => ({ id: model.id, label: `${model.id}${model.isDefault ? ' (recommended)' : ''}` })), preferred);
|
|
473
|
+
.map(model => ({ id: model.id, label: `${modelDisplayName(candidate, model.id)}${model.isDefault ? ' (recommended)' : ''}` })), preferred);
|
|
446
474
|
if (!model)
|
|
447
475
|
continue;
|
|
448
476
|
if (model !== candidate.model)
|
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"];
|
|
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;
|
|
@@ -20,6 +23,12 @@ export interface ProviderConfig {
|
|
|
20
23
|
model: string;
|
|
21
24
|
models?: string[];
|
|
22
25
|
modelContextWindows?: Record<string, number>;
|
|
26
|
+
/** Andorra only: the router's display name for each model id. Shown to people; never used to look a model up. */
|
|
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[];
|
|
23
32
|
contextWindow?: number;
|
|
24
33
|
reasoningEffort?: ReasoningEffort;
|
|
25
34
|
requestTimeoutMs?: number;
|
|
@@ -30,8 +39,20 @@ export interface ProviderConfig {
|
|
|
30
39
|
name?: string;
|
|
31
40
|
}
|
|
32
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;
|
|
47
|
+
/** What a person reads for `model`: an Andorra entry's stored display name, otherwise the id itself. */
|
|
48
|
+
export declare function modelDisplayName(provider: Pick<ProviderConfig, 'type' | 'modelNames'> | undefined, model: string): string;
|
|
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. */
|
|
50
|
+
export declare function modelIdForDisplayName(provider: Pick<ProviderConfig, 'type' | 'model' | 'models' | 'modelNames'>, text: string): string | undefined;
|
|
51
|
+
/** Provider id → model id → display name, for the providers that have names (Andorra). */
|
|
52
|
+
export declare function providerModelNames(providers: readonly Pick<ProviderConfig, 'id' | 'type' | 'modelNames'>[]): Record<string, Record<string, string>>;
|
|
33
53
|
export declare const MAX_CODEX_ACCOUNT_KEY_LENGTH = 100;
|
|
34
54
|
export declare const MAX_PROVIDER_NAME_LENGTH = 64;
|
|
55
|
+
export declare const MAX_MODEL_DISPLAY_NAME_LENGTH = 80;
|
|
35
56
|
export declare function freeCodexAccountSlot(base: string, providers: readonly Pick<ProviderConfig, 'id' | 'codexAccount'>[]): string;
|
|
36
57
|
export declare function freeDraftCodexAccountSlot(base: string, draft: readonly Pick<ProviderConfig, 'id' | 'codexAccount'>[], saved: readonly Pick<ProviderConfig, 'id' | 'codexAccount'>[]): string;
|
|
37
58
|
export declare function allocateCodexAccountSlots(stored: readonly ProviderConfig[], next: readonly ProviderConfig[]): ProviderConfig[];
|
|
@@ -43,8 +64,11 @@ export declare function recordProviderModel(provider: ProviderConfig, model: str
|
|
|
43
64
|
export declare function assertProviderCredentials(provider: Pick<ProviderConfig, 'type' | 'apiKey' | 'apiKeyEnv' | 'anthropicAuth'>): void;
|
|
44
65
|
export declare function resolveProviderApiKey(provider: Pick<ProviderConfig, 'type' | 'apiKey' | 'apiKeyEnv' | 'anthropicAuth'>): string | undefined;
|
|
45
66
|
export declare function defaultProviders(): ProviderConfig[];
|
|
67
|
+
export declare const MALFORMED_RESPONSE_RETRIES = 5;
|
|
46
68
|
export declare class ProviderRequestError extends Error {
|
|
47
69
|
readonly contextOverflow: boolean;
|
|
70
|
+
/** The system error code behind a connection that could not be made; recorded with the failure, never part of the message. */
|
|
71
|
+
connectionCause?: string;
|
|
48
72
|
constructor(message: string, contextOverflow?: boolean);
|
|
49
73
|
}
|
|
50
74
|
export declare const BLANK_TOOL_CALL_LIMIT = 4096;
|
|
@@ -56,4 +80,6 @@ export declare function createDecodeWindow(now?: () => number): {
|
|
|
56
80
|
stamp(text: string): void;
|
|
57
81
|
measure(): number | undefined;
|
|
58
82
|
};
|
|
59
|
-
export declare function createAdapter(config: ProviderConfig
|
|
83
|
+
export declare function createAdapter(config: ProviderConfig, options?: {
|
|
84
|
+
sessionId?: string;
|
|
85
|
+
}): ModelAdapter;
|
package/dist/src/providers.js
CHANGED
|
@@ -3,18 +3,26 @@ 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';
|
|
10
|
+
import { ANDORRA_UNAVAILABLE_MESSAGE, andorraBaseUrl } from './andorra/endpoint.js';
|
|
11
|
+
import { andorraRefusal } from './andorra/errors.js';
|
|
9
12
|
import { generateEngineResponse, isEngineContextOverflow } from './provider-engine.js';
|
|
10
13
|
import { estimateStreamedTokens } from './token-rate.js';
|
|
11
14
|
export const REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
12
|
-
|
|
13
|
-
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'];
|
|
14
22
|
export function isSignInProviderType(type) {
|
|
15
23
|
return SIGN_IN_PROVIDER_TYPES.includes(type);
|
|
16
24
|
}
|
|
17
|
-
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' };
|
|
18
26
|
export const DEFAULT_REQUEST_TIMEOUT_MS = 10 * 60_000;
|
|
19
27
|
export const MAX_REQUEST_TIMEOUT_MS = 86_400_000;
|
|
20
28
|
export function assertRequestTimeout(provider) {
|
|
@@ -54,8 +62,38 @@ export function providerLabel(provider, providers) {
|
|
|
54
62
|
const local = provider.codexEmail?.split('@')[0] || provider.id;
|
|
55
63
|
return `codex - ${local.length > 32 ? `${local.slice(0, 31)}…` : local}`;
|
|
56
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
|
+
}
|
|
72
|
+
/** What a person reads for `model`: an Andorra entry's stored display name, otherwise the id itself. */
|
|
73
|
+
export function modelDisplayName(provider, model) {
|
|
74
|
+
const names = provider?.type === 'andorra' ? provider.modelNames : undefined;
|
|
75
|
+
const name = names && Object.hasOwn(names, model) ? names[model] : undefined;
|
|
76
|
+
return typeof name === 'string' && name ? name : model;
|
|
77
|
+
}
|
|
78
|
+
/** 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. */
|
|
79
|
+
export function modelIdForDisplayName(provider, text) {
|
|
80
|
+
if (provider.type !== 'andorra' || !provider.modelNames)
|
|
81
|
+
return undefined;
|
|
82
|
+
const ids = providerModels(provider);
|
|
83
|
+
if (ids.includes(text))
|
|
84
|
+
return undefined;
|
|
85
|
+
const wanted = text.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
86
|
+
const matches = ids.filter(id => modelDisplayName(provider, id) !== id && modelDisplayName(provider, id).toLowerCase() === wanted);
|
|
87
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
88
|
+
}
|
|
89
|
+
/** Provider id → model id → display name, for the providers that have names (Andorra). */
|
|
90
|
+
export function providerModelNames(providers) {
|
|
91
|
+
return Object.fromEntries(providers.flatMap(provider => provider.type === 'andorra' && provider.modelNames && Object.keys(provider.modelNames).length
|
|
92
|
+
? [[provider.id, { ...provider.modelNames }]] : []));
|
|
93
|
+
}
|
|
57
94
|
export const MAX_CODEX_ACCOUNT_KEY_LENGTH = 100;
|
|
58
95
|
export const MAX_PROVIDER_NAME_LENGTH = 64;
|
|
96
|
+
export const MAX_MODEL_DISPLAY_NAME_LENGTH = 80;
|
|
59
97
|
export function freeCodexAccountSlot(base, providers) {
|
|
60
98
|
const taken = new Set(providers.flatMap(provider => provider.codexAccount === undefined ? [] : [provider.codexAccount.toLowerCase()]));
|
|
61
99
|
const key = (suffix) => `${base.slice(0, MAX_CODEX_ACCOUNT_KEY_LENGTH - suffix.length)}${suffix}`;
|
|
@@ -127,9 +165,12 @@ export function assertProviderCredentials(provider) {
|
|
|
127
165
|
if (provider.type === 'claude' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
128
166
|
throw new Error('Claude providers use Claude Code sign-in; API key overrides are not supported.');
|
|
129
167
|
}
|
|
130
|
-
if ((provider.type === 'grok' || provider.type === 'opencode') && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
168
|
+
if ((provider.type === 'grok' || provider.type === 'opencode' || provider.type === 'google') && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
131
169
|
throw new Error(`${SIGN_IN_PRODUCT[provider.type]} providers use their CLI sign-in; API key overrides are not supported.`);
|
|
132
170
|
}
|
|
171
|
+
if (provider.type === 'andorra' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
172
|
+
throw new Error('Andorra providers use your Andorra account sign-in; API keys are not supported.');
|
|
173
|
+
}
|
|
133
174
|
if (provider.apiKey !== undefined && (typeof provider.apiKey !== 'string' || !/^[\x21-\x7e]+$/.test(provider.apiKey))) {
|
|
134
175
|
throw new Error('API key must be nonempty and contain no whitespace or control characters.');
|
|
135
176
|
}
|
|
@@ -157,12 +198,22 @@ export function defaultProviders() {
|
|
|
157
198
|
{ id: 'local', type: 'openai-compatible', baseUrl: 'http://127.0.0.1:1234/v1', model: 'local-model' },
|
|
158
199
|
];
|
|
159
200
|
}
|
|
160
|
-
|
|
161
|
-
const REQUEST_RETRY_DELAYS_MS = [
|
|
201
|
+
// A transport fault is retried seven times: twice 5 seconds apart, three times 15 seconds apart, then twice a minute apart.
|
|
202
|
+
const REQUEST_RETRY_DELAYS_MS = [5_000, 5_000, 15_000, 15_000, 15_000, 60_000, 60_000];
|
|
203
|
+
const MAX_REQUEST_RETRIES = REQUEST_RETRY_DELAYS_MS.length;
|
|
162
204
|
const MALFORMED_STREAM_RETRY_DELAYS_MS = [1_000, 3_000, 10_000];
|
|
163
|
-
const
|
|
205
|
+
const MALFORMED_STREAM_RETRIES = MALFORMED_STREAM_RETRY_DELAYS_MS.length;
|
|
206
|
+
// A malformed response is usually the model's own slip (tool-call arguments that are not valid JSON), so asking
|
|
207
|
+
// again gets a fresh sample. It needs no long backoff and is retried quietly, more often than a transport fault.
|
|
208
|
+
export const MALFORMED_RESPONSE_RETRIES = 5;
|
|
209
|
+
const MALFORMED_RESPONSE_RETRY_DELAYS_MS = [250, 250, 500, 1_000, 2_000];
|
|
210
|
+
const MALFORMED_RESPONSE_MESSAGE = 'Provider returned a malformed response.';
|
|
211
|
+
// The longest Retry-After a provider may ask for; it is not tied to the backoff above.
|
|
212
|
+
const MAX_AUTOMATIC_RETRY_AFTER_MS = 120_000;
|
|
164
213
|
export class ProviderRequestError extends Error {
|
|
165
214
|
contextOverflow;
|
|
215
|
+
/** The system error code behind a connection that could not be made; recorded with the failure, never part of the message. */
|
|
216
|
+
connectionCause;
|
|
166
217
|
constructor(message, contextOverflow = false) {
|
|
167
218
|
super(message);
|
|
168
219
|
this.contextOverflow = contextOverflow;
|
|
@@ -172,19 +223,25 @@ export class ProviderRequestError extends Error {
|
|
|
172
223
|
class RetryableProviderError extends ProviderRequestError {
|
|
173
224
|
retryAfterMs;
|
|
174
225
|
retryDelaysMs;
|
|
175
|
-
|
|
226
|
+
maxRetries;
|
|
227
|
+
quiet;
|
|
228
|
+
constructor(message, retryAfterMs = 0, retryDelaysMs = REQUEST_RETRY_DELAYS_MS, maxRetries = MAX_REQUEST_RETRIES, quiet = false) {
|
|
176
229
|
super(message);
|
|
177
230
|
this.retryAfterMs = retryAfterMs;
|
|
178
231
|
this.retryDelaysMs = retryDelaysMs;
|
|
232
|
+
this.maxRetries = maxRetries;
|
|
233
|
+
this.quiet = quiet;
|
|
179
234
|
this.name = 'Error';
|
|
180
235
|
}
|
|
181
236
|
}
|
|
182
|
-
class
|
|
183
|
-
constructor() { super(
|
|
237
|
+
class MalformedResponseProviderError extends RetryableProviderError {
|
|
238
|
+
constructor() { super(MALFORMED_RESPONSE_MESSAGE, 0, MALFORMED_RESPONSE_RETRY_DELAYS_MS, MALFORMED_RESPONSE_RETRIES, true); }
|
|
239
|
+
}
|
|
240
|
+
class MalformedStreamProviderError extends MalformedResponseProviderError {
|
|
184
241
|
}
|
|
185
242
|
export const BLANK_TOOL_CALL_LIMIT = 4096;
|
|
186
243
|
class BlankToolCallProviderError extends RetryableProviderError {
|
|
187
|
-
constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS); }
|
|
244
|
+
constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS, MALFORMED_STREAM_RETRIES); }
|
|
188
245
|
}
|
|
189
246
|
export function createBlankToolCallGuard(limit = BLANK_TOOL_CALL_LIMIT) {
|
|
190
247
|
let blank = 0;
|
|
@@ -233,7 +290,7 @@ function connectionFailureDetail(error) {
|
|
|
233
290
|
return code && /^[A-Z][A-Z0-9_]*$/.test(code) ? code : undefined;
|
|
234
291
|
}
|
|
235
292
|
function cancelled() { throw new Error('Provider request cancelled.'); }
|
|
236
|
-
function malformed() { throw new Error(
|
|
293
|
+
function malformed() { throw new Error(MALFORMED_RESPONSE_MESSAGE); }
|
|
237
294
|
class ResponseTooLargeError extends Error {
|
|
238
295
|
constructor() { super('Provider response exceeds the 4 MiB limit.'); }
|
|
239
296
|
}
|
|
@@ -664,7 +721,9 @@ function createAnthropicStreamAccumulator(now = Date.now) {
|
|
|
664
721
|
},
|
|
665
722
|
};
|
|
666
723
|
}
|
|
667
|
-
|
|
724
|
+
/** The router reads `x-andorra-session` only in this form and ignores anything else, so nothing else is sent. */
|
|
725
|
+
const ANDORRA_SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
726
|
+
export function createAdapter(config, options = {}) {
|
|
668
727
|
if (config.reasoningEffort !== undefined && (!['openai-compatible', 'opencode-go', 'anthropic'].includes(config.type) || !REASONING_EFFORTS.includes(config.reasoningEffort)))
|
|
669
728
|
throw new Error('Reasoning effort overrides require an OpenAI-compatible, OpenCode Go or Anthropic provider and a supported effort value.');
|
|
670
729
|
assertRequestTimeout(config);
|
|
@@ -676,13 +735,17 @@ export function createAdapter(config) {
|
|
|
676
735
|
return createClaudeAdapter(config);
|
|
677
736
|
if (config.type === 'grok')
|
|
678
737
|
return createGrokAdapter(config);
|
|
738
|
+
if (config.type === 'google')
|
|
739
|
+
return createGoogleAdapter(config);
|
|
679
740
|
if (config.type === 'opencode')
|
|
680
741
|
return createOpenCodeCliAdapter(config);
|
|
681
742
|
if (config.type === 'opencode-go')
|
|
682
743
|
return createOpenCodeAdapter(config);
|
|
744
|
+
const andorra = config.type === 'andorra';
|
|
683
745
|
let base;
|
|
746
|
+
// An Andorra entry's saved URL is informational: requests always go to the router (or its loopback override).
|
|
684
747
|
try {
|
|
685
|
-
base = new URL(config.baseUrl);
|
|
748
|
+
base = new URL(andorra ? andorraBaseUrl() : config.baseUrl);
|
|
686
749
|
}
|
|
687
750
|
catch {
|
|
688
751
|
throw new Error('Provider base URL is invalid.');
|
|
@@ -690,8 +753,10 @@ export function createAdapter(config) {
|
|
|
690
753
|
if (!['https:', 'http:'].includes(base.protocol) || base.username || base.password || base.search || base.hash) {
|
|
691
754
|
throw new Error('Provider base URL must be HTTP(S) without credentials, query, or fragment.');
|
|
692
755
|
}
|
|
693
|
-
if (config.type !== 'openai-compatible' && config.type !== 'anthropic')
|
|
756
|
+
if (config.type !== 'openai-compatible' && config.type !== 'anthropic' && !andorra)
|
|
694
757
|
throw new Error('Unsupported provider type.');
|
|
758
|
+
const sessionHeader = andorra && options.sessionId !== undefined && ANDORRA_SESSION_ID.test(options.sessionId)
|
|
759
|
+
? { 'x-andorra-session': options.sessionId } : {};
|
|
695
760
|
const anthropic = config.type === 'anthropic';
|
|
696
761
|
const requestTimeoutMs = config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
697
762
|
const listingTimeoutMs = requestTimeoutMs > 0 ? Math.min(requestTimeoutMs, MODEL_LISTING_TIMEOUT_MS) : MODEL_LISTING_TIMEOUT_MS;
|
|
@@ -711,7 +776,7 @@ export function createAdapter(config) {
|
|
|
711
776
|
throw new RetryableProviderError('Provider request timed out.');
|
|
712
777
|
throw error;
|
|
713
778
|
}
|
|
714
|
-
const headers = { 'content-type': 'application/json', ...credential };
|
|
779
|
+
const headers = { 'content-type': 'application/json', ...sessionHeader, ...credential };
|
|
715
780
|
const key = headers['x-api-key'] ?? headers.authorization?.replace(/^Bearer /, '');
|
|
716
781
|
const idle = inference && timeoutMs > 0 ? new AbortController() : undefined;
|
|
717
782
|
let timer;
|
|
@@ -739,6 +804,13 @@ export function createAdapter(config) {
|
|
|
739
804
|
throw new Error('Provider request cancelled.');
|
|
740
805
|
if (deadline?.aborted)
|
|
741
806
|
throw new RetryableProviderError('Provider request timed out.');
|
|
807
|
+
// A connection that could not be made is not one of the router's refusals: it gets the usual bounded
|
|
808
|
+
// retries, and the plain sentence (no address, no error code) while retrying and when they run out.
|
|
809
|
+
if (andorra) {
|
|
810
|
+
const failure = permanentConnectionFailure(error) ? new ProviderRequestError(ANDORRA_UNAVAILABLE_MESSAGE) : new RetryableProviderError(ANDORRA_UNAVAILABLE_MESSAGE);
|
|
811
|
+
failure.connectionCause = connectionFailureDetail(error);
|
|
812
|
+
throw failure;
|
|
813
|
+
}
|
|
742
814
|
const cause = connectionFailureDetail(error);
|
|
743
815
|
const message = `Provider connection failed${cause ? ` (${cause})` : ''}. Check its URL and network connection.`;
|
|
744
816
|
if (permanentConnectionFailure(error))
|
|
@@ -761,6 +833,10 @@ export function createAdapter(config) {
|
|
|
761
833
|
throw new ProviderRequestError('Provider input exceeds the context window.', true);
|
|
762
834
|
}
|
|
763
835
|
await response.body?.cancel().catch(() => { });
|
|
836
|
+
// The router's own refusals are sent once and shown as written here, never retried.
|
|
837
|
+
const refusal = andorra ? andorraRefusal(response.status, errorData, response.headers.get('retry-after')) : undefined;
|
|
838
|
+
if (refusal)
|
|
839
|
+
throw new ProviderRequestError(refusal);
|
|
764
840
|
const detail = providerErrorDetail(errorData);
|
|
765
841
|
const shown = detail === undefined ? undefined : redactCredential(detail, key);
|
|
766
842
|
const message = `Provider request failed (HTTP ${response.status})${shown ? `: ${shown}` : ''}. Check credentials, model, and provider availability.`;
|
|
@@ -872,7 +948,7 @@ export function createAdapter(config) {
|
|
|
872
948
|
if (!(error instanceof RetryableProviderError))
|
|
873
949
|
throw error;
|
|
874
950
|
prepareRetry?.(error);
|
|
875
|
-
if (retry >=
|
|
951
|
+
if (retry >= error.maxRetries)
|
|
876
952
|
throw error;
|
|
877
953
|
if (error.retryAfterMs > MAX_AUTOMATIC_RETRY_AFTER_MS)
|
|
878
954
|
throw new ProviderRequestError(`${error.message} Retry-After exceeds the 120-second automatic retry limit.`);
|
|
@@ -880,7 +956,8 @@ export function createAdapter(config) {
|
|
|
880
956
|
const reason = error instanceof MalformedStreamProviderError
|
|
881
957
|
? 'Provider returned a malformed streamed response; retrying without streaming.'
|
|
882
958
|
: error.message;
|
|
883
|
-
await onRetry?.({ retry: retry + 1, maxRetries:
|
|
959
|
+
await onRetry?.({ retry: retry + 1, maxRetries: error.maxRetries, delayMs, reason, ...(error.quiet ? { quiet: true } : {}),
|
|
960
|
+
...(error.connectionCause ? { cause: error.connectionCause } : {}) });
|
|
884
961
|
try {
|
|
885
962
|
await delay(delayMs, undefined, { signal });
|
|
886
963
|
}
|
|
@@ -905,6 +982,9 @@ export function createAdapter(config) {
|
|
|
905
982
|
providerId: config.id, baseUrl: base.href.replace(/\/$/, ''), anthropic,
|
|
906
983
|
contextWindow: model === config.model ? config.contextWindow ?? 128_000 : 128_000,
|
|
907
984
|
reasoningEffort: model === config.model ? config.reasoningEffort : undefined,
|
|
985
|
+
// DeepSeek takes an empty string. Andorra's router rejects an empty one like an absent one (HTTP 400,
|
|
986
|
+
// "Missing required parameter: 'messages[n].reasoning_content'") and takes a single space.
|
|
987
|
+
...(andorra ? { missingReasoning: ' ' } : base.origin === 'https://api.deepseek.com' ? { missingReasoning: '' } : {}),
|
|
908
988
|
async send(body) {
|
|
909
989
|
deadline = undefined;
|
|
910
990
|
dispose?.();
|
|
@@ -990,6 +1070,8 @@ export function createAdapter(config) {
|
|
|
990
1070
|
cancelled();
|
|
991
1071
|
if (deadline?.aborted)
|
|
992
1072
|
throw new RetryableProviderError('Provider request timed out.');
|
|
1073
|
+
if (error instanceof Error && !(error instanceof RetryableProviderError) && error.message === MALFORMED_RESPONSE_MESSAGE)
|
|
1074
|
+
throw new MalformedResponseProviderError();
|
|
993
1075
|
throw error;
|
|
994
1076
|
}).finally(() => { dispose?.(); dispose = undefined; }), signal, onRetry, error => {
|
|
995
1077
|
if (error instanceof MalformedStreamProviderError) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runtimeEnvironmentNote } from './runtime-environment.js';
|
|
1
2
|
import { createGoalCompletionVerifier } from './goal-completion-verification.js';
|
|
2
3
|
import { goalSystemNote, withGoalSystemNote } from './session-goal.js';
|
|
3
4
|
import { validateExtendedToolSchema } from './tool-schema-compatibility.js';
|
|
@@ -10,7 +11,7 @@ import { andorraIsContextOverflow } from '../vendor/engine/runtime/ai/utils/over
|
|
|
10
11
|
import { toEngineResponse, engineModel } from './engine/protocol.js';
|
|
11
12
|
import { ProviderRequestError } from './providers.js';
|
|
12
13
|
import { COMPLETION_ALONE_ERROR, COMPLETION_TOOL, COMPLETION_GUIDANCE, FINAL_RESPONSE_GUIDANCE, OUTPUT_STOOD_IN_NOTE, RESPONSE_STRUCTURE_GUIDANCE, completionTool, completionResponse, parseCompletion, withoutTrailingEnvelope } from './completion.js';
|
|
13
|
-
import { MAX_GATE_ASKS, MAX_IDLE_UNFINISHED_ASKS, finalAnswerGate } from './completion-gates.js';
|
|
14
|
+
import { MAX_GATE_ASKS, MAX_IDLE_UNFINISHED_ASKS, finalAnswerGate, proseIsFinalAnswer } from './completion-gates.js';
|
|
14
15
|
import { TestEditGuard, testEditNudge } from './test-edit-guard.js';
|
|
15
16
|
import { HistoryCompactor, CompactionRecoveryError, pinnedContextChars, PINNED_CONTEXT_GUIDANCE, retireSupersededNodeScaffolding, clipOldPinnedMessages, isNodePrompt, recentHumanMessages } from './context-compaction.js';
|
|
16
17
|
import { createHash, randomUUID } from 'node:crypto';
|
|
@@ -72,6 +73,9 @@ function refusedRequest(error) {
|
|
|
72
73
|
}
|
|
73
74
|
const STEERED_OUTPUT_TAIL = 4_000;
|
|
74
75
|
const STEER_STOPPABLE = new Set(['Bash', 'PowerShell', 'PowerShellFast', 'NativeExec', 'bash', 'powershell', 'shell']);
|
|
76
|
+
// Calls that only wait on a subagent. A steer hands control back to the caller and leaves the subagent
|
|
77
|
+
// running, so they are never aborted the way a shell command is.
|
|
78
|
+
const SUBAGENT_WAITS = new Set(['spawn_subagent', 'wait_subagent']);
|
|
75
79
|
function steerStoppable(name, args) {
|
|
76
80
|
return STEER_STOPPABLE.has(name) || (name === 'AsyncProcess' && args.action === 'wait');
|
|
77
81
|
}
|
|
@@ -321,7 +325,8 @@ export class AndorraAgentEngine {
|
|
|
321
325
|
const recentFailures = [];
|
|
322
326
|
let decisionTask = options.decisionTask ?? options.task;
|
|
323
327
|
let taskChanged = Boolean(options.resumeMessages);
|
|
324
|
-
const messages = [{ role: 'system', content: ((options.graph || options.completionPolicy || options.subagentId ? '' : DEFAULT_AGENT_INSTRUCTIONS + '\n') + SYSTEM) +
|
|
328
|
+
const messages = [{ role: 'system', content: ((options.graph || options.completionPolicy || options.subagentId ? '' : DEFAULT_AGENT_INSTRUCTIONS + '\n') + SYSTEM) + `
|
|
329
|
+
${runtimeEnvironmentNote()}` + (options.systemPrompt ? `\nAgent instructions:\n${options.systemPrompt}` : '') + (options.instructions ? `\nWorkspace guidance:\n${options.instructions}` : '') }];
|
|
325
330
|
const completionGuidance = options.completionPolicy ? COMPLETION_GUIDANCE : COMPLETION_GUIDANCE.replace('Finish with complete_agent alone or final JSON.', 'When finished, return your answer in natural prose. Legacy complete_agent or final JSON is also accepted.');
|
|
326
331
|
messages[0].content += `\n${completionGuidance}`;
|
|
327
332
|
const declaredOutcomes = options.completionPolicy ? (options.completionPolicy.mode === 'single' ? [options.completionPolicy.outcome] : options.completionPolicy.outcomes) : [];
|
|
@@ -573,7 +578,7 @@ export class AndorraAgentEngine {
|
|
|
573
578
|
}
|
|
574
579
|
let answers = {};
|
|
575
580
|
if (requests.length) {
|
|
576
|
-
const identity = { runId: result.id, nodeId: options.nodeId ?? 'engineer', invocationId };
|
|
581
|
+
const identity = { runId: result.id, nodeId: options.nodeId ?? 'engineer', invocationId, ...(options.subagentId ? { subagentId: options.subagentId } : {}) };
|
|
577
582
|
const started = monotonicNow();
|
|
578
583
|
answers = Object.fromEntries(await Promise.all(requests.map(async (request) => [request.id, await manager.fact(request, identity, operationSignal, options.onEvent)])));
|
|
579
584
|
signal.throwIfAborted();
|
|
@@ -681,13 +686,13 @@ export class AndorraAgentEngine {
|
|
|
681
686
|
let finalized = [];
|
|
682
687
|
let batchSteer;
|
|
683
688
|
const watchBatchSteer = () => {
|
|
684
|
-
if (batchSteer || !control || !options.getSteeringMessages
|
|
689
|
+
if (batchSteer || !control || !options.getSteeringMessages)
|
|
685
690
|
return;
|
|
686
691
|
const watch = { arrived: false, cut: new AbortController(), stop: () => { } };
|
|
687
692
|
watch.stop = control.onSteer(() => {
|
|
688
693
|
watch.arrived = true;
|
|
689
694
|
watch.cut.abort(new Error('Stopped to read a new message from the user.'));
|
|
690
|
-
});
|
|
695
|
+
}, options.subagentId);
|
|
691
696
|
batchSteer = watch;
|
|
692
697
|
};
|
|
693
698
|
const endBatchSteer = () => { batchSteer?.stop(); batchSteer = undefined; };
|
|
@@ -922,8 +927,8 @@ export class AndorraAgentEngine {
|
|
|
922
927
|
const forced = !selectedStep && forceToolCall;
|
|
923
928
|
if (forced)
|
|
924
929
|
forceToolCall = false;
|
|
925
|
-
const stopSteerWatch = !selectedStep && control && options.getSteeringMessages
|
|
926
|
-
? control.onSteer(() => steerCut.abort(new Error('Interrupted to read a steering message.')))
|
|
930
|
+
const stopSteerWatch = !selectedStep && control && options.getSteeringMessages
|
|
931
|
+
? control.onSteer(() => steerCut.abort(new Error('Interrupted to read a steering message.')), options.subagentId)
|
|
927
932
|
: () => { };
|
|
928
933
|
try {
|
|
929
934
|
operationSignal.throwIfAborted();
|
|
@@ -1185,7 +1190,9 @@ export class AndorraAgentEngine {
|
|
|
1185
1190
|
testEditGuard.noteMutationStarting();
|
|
1186
1191
|
output = await tool.execute(args, {
|
|
1187
1192
|
...context,
|
|
1188
|
-
|
|
1193
|
+
toolCallId: entry.call.id, toolInvocationId: invocationId,
|
|
1194
|
+
steerSignal: SUBAGENT_WAITS.has(entry.call.name) ? batchSteer?.cut.signal : undefined,
|
|
1195
|
+
...(SUBAGENT_WAITS.has(entry.call.name) ? {} : {
|
|
1189
1196
|
signal: steerCut ? AbortSignal.any([operationSignal, steerCut]) : operationSignal,
|
|
1190
1197
|
userSignal: control ? AbortSignal.any([context.userSignal ?? signal, operationSignal]) : context.userSignal,
|
|
1191
1198
|
}),
|
|
@@ -1421,7 +1428,7 @@ export class AndorraAgentEngine {
|
|
|
1421
1428
|
truncated: item.truncated === true || Buffer.byteLength(redactForDecision(item.output)) > 2048,
|
|
1422
1429
|
summary: boundedDecisionText(item.output, 2048),
|
|
1423
1430
|
})) },
|
|
1424
|
-
}, { runId: result.id, nodeId: options.nodeId ?? 'engineer', invocationId }, operationSignal, options.onEvent);
|
|
1431
|
+
}, { runId: result.id, nodeId: options.nodeId ?? 'engineer', invocationId, ...(options.subagentId ? { subagentId: options.subagentId } : {}) }, operationSignal, options.onEvent);
|
|
1425
1432
|
if (!candidates.length) {
|
|
1426
1433
|
const tracked = round.then(batch => {
|
|
1427
1434
|
if (number <= postflightAnswered)
|
|
@@ -1526,13 +1533,27 @@ export class AndorraAgentEngine {
|
|
|
1526
1533
|
catch { }
|
|
1527
1534
|
}
|
|
1528
1535
|
const explicit = response.completionSource === 'complete_agent' || objectText && (!!options.completionPolicy || !!legacyCompletion);
|
|
1529
|
-
|
|
1536
|
+
const policy = options.completionPolicy;
|
|
1537
|
+
let proseCompletion;
|
|
1538
|
+
if (!explicit && policy?.mode === 'single' && proseIsFinalAnswer({
|
|
1539
|
+
text: response.text, stopReason: response.stopReason, endsRun: !!options.finalAnswerOutcomes?.includes(policy.outcome),
|
|
1540
|
+
hasOutputSchema: !!options.outputSchema, userPresent: tools.some(tool => tool.name === 'ask_user'),
|
|
1541
|
+
acted: result.toolCalls > 0 || todoCalls > 0 || !!options.resumeMessages, openTodos: todoStore.snapshot().filter(todo => todo.status !== 'completed').length,
|
|
1542
|
+
toolCallDropped: suspectedDroppedToolCall(response), carriesEnvelope: withoutTrailingEnvelope(response.text) !== response.text,
|
|
1543
|
+
})) {
|
|
1544
|
+
const summary = response.text.trim();
|
|
1545
|
+
const candidate = { summary, tests: [], outcome: policy.outcome, artifacts: [],
|
|
1546
|
+
output: { summary, tests: [], ...(options.canonicalTask !== undefined ? { originalTask: options.canonicalTask } : {}) } };
|
|
1547
|
+
if (!options.completionGuard?.(candidate))
|
|
1548
|
+
proseCompletion = candidate;
|
|
1549
|
+
}
|
|
1550
|
+
if (!explicit && !proseCompletion && options.completionPolicy && finishingRequest && finishHolds < 1) {
|
|
1530
1551
|
finishHolds++;
|
|
1531
1552
|
finishOnly = true;
|
|
1532
1553
|
await emit('efficiency.facts.action', { action: 'finish_only', reason: 'held' });
|
|
1533
1554
|
return { continue: true, context: FINISH_HELD_GUIDANCE };
|
|
1534
1555
|
}
|
|
1535
|
-
if (!explicit && options.completionPolicy) {
|
|
1556
|
+
if (!explicit && !proseCompletion && options.completionPolicy) {
|
|
1536
1557
|
const dropped = suspectedDroppedToolCall(response);
|
|
1537
1558
|
const shown = withoutTrailingEnvelope(response.text, SENT_BACK_ENVELOPE_NOTE);
|
|
1538
1559
|
if (shown.trim())
|
|
@@ -1634,7 +1655,7 @@ export class AndorraAgentEngine {
|
|
|
1634
1655
|
}
|
|
1635
1656
|
}
|
|
1636
1657
|
if (!explicit) {
|
|
1637
|
-
const completion = { summary: candidateText, tests: [] };
|
|
1658
|
+
const completion = proseCompletion ?? { summary: candidateText, tests: [] };
|
|
1638
1659
|
const rejected = options.completionGuard?.(completion);
|
|
1639
1660
|
if (rejected) {
|
|
1640
1661
|
completionRejectionEmitted = true;
|