@andorra-labs/code 0.1.13 → 0.1.14

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.
Files changed (105) hide show
  1. package/dist/src/account-presentation.js +4 -1
  2. package/dist/src/agent-execution.js +300 -140
  3. package/dist/src/agent-mcp.js +2 -2
  4. package/dist/src/andorra/endpoint.d.ts +7 -0
  5. package/dist/src/andorra/endpoint.js +46 -0
  6. package/dist/src/andorra/entry.d.ts +21 -0
  7. package/dist/src/andorra/entry.js +100 -0
  8. package/dist/src/andorra/errors.d.ts +2 -0
  9. package/dist/src/andorra/errors.js +39 -0
  10. package/dist/src/andorra/hosted.d.ts +52 -0
  11. package/dist/src/andorra/hosted.js +126 -0
  12. package/dist/src/andorra/monitor.d.ts +151 -0
  13. package/dist/src/andorra/monitor.js +393 -0
  14. package/dist/src/andorra/notices.d.ts +7 -0
  15. package/dist/src/andorra/notices.js +15 -0
  16. package/dist/src/andorra/opt-in.d.ts +58 -0
  17. package/dist/src/andorra/opt-in.js +112 -0
  18. package/dist/src/andorra/request-watch.d.ts +6 -0
  19. package/dist/src/andorra/request-watch.js +10 -0
  20. package/dist/src/andorra/state.d.ts +86 -0
  21. package/dist/src/andorra/state.js +238 -0
  22. package/dist/src/andorra/terminal.d.ts +68 -0
  23. package/dist/src/andorra/terminal.js +125 -0
  24. package/dist/src/andorra/usage-format.d.ts +9 -0
  25. package/dist/src/andorra/usage-format.js +19 -0
  26. package/dist/src/anthropic-credentials.js +9 -1
  27. package/dist/src/app-server/protocol.d.ts +6 -2
  28. package/dist/src/app-server/protocol.js +1 -1
  29. package/dist/src/app-server.d.ts +27 -0
  30. package/dist/src/app-server.js +292 -85
  31. package/dist/src/auth/AuthManager.d.ts +9 -0
  32. package/dist/src/auth/AuthManager.js +161 -21
  33. package/dist/src/auth/deployment.d.ts +1 -0
  34. package/dist/src/auth/deployment.js +1 -0
  35. package/dist/src/auth/index.d.ts +1 -1
  36. package/dist/src/auth/index.js +1 -1
  37. package/dist/src/auth/store.d.ts +26 -0
  38. package/dist/src/auth/store.js +34 -1
  39. package/dist/src/browser-runner.js +1 -1
  40. package/dist/src/browser-stealth.d.ts +19 -1
  41. package/dist/src/browser-stealth.js +23 -3
  42. package/dist/src/browser-ui/tokens.css +4 -4
  43. package/dist/src/browser-view.d.ts +65 -0
  44. package/dist/src/browser-view.js +229 -16
  45. package/dist/src/cli.js +43 -26
  46. package/dist/src/command-screens.d.ts +17 -1
  47. package/dist/src/command-screens.js +192 -21
  48. package/dist/src/commands.d.ts +7 -1
  49. package/dist/src/commands.js +78 -27
  50. package/dist/src/config.d.ts +6 -1
  51. package/dist/src/config.js +86 -3
  52. package/dist/src/dashboard-view.d.ts +2 -0
  53. package/dist/src/dashboard-view.js +11 -2
  54. package/dist/src/decision/PreparedSteps.js +1 -1
  55. package/dist/src/decision/applyToolMenu.js +1 -1
  56. package/dist/src/decision/toolFamilies.js +1 -1
  57. package/dist/src/decision/types.d.ts +1 -0
  58. package/dist/src/graph-health.d.ts +11 -0
  59. package/dist/src/graph-health.js +36 -4
  60. package/dist/src/graph-manager-chat.d.ts +33 -0
  61. package/dist/src/graph-manager-chat.js +159 -5
  62. package/dist/src/graph-runner.js +27 -0
  63. package/dist/src/graph-selection.js +2 -1
  64. package/dist/src/graph-ui/app.js +25 -2
  65. package/dist/src/graph-ui/manager.js +40 -5
  66. package/dist/src/graph-ui/style.css +5 -2
  67. package/dist/src/graph-ui/tokens.css +4 -4
  68. package/dist/src/graphs.js +1 -3
  69. package/dist/src/hardened-runtime.js +1 -1
  70. package/dist/src/membership-errors.js +1 -1
  71. package/dist/src/membership.d.ts +10 -2
  72. package/dist/src/membership.js +20 -6
  73. package/dist/src/model-context-windows.d.ts +2 -0
  74. package/dist/src/model-context-windows.js +24 -0
  75. package/dist/src/model-health-cache.js +1 -1
  76. package/dist/src/model-metadata.d.ts +1 -0
  77. package/dist/src/model-metadata.js +40 -3
  78. package/dist/src/palette.d.ts +1 -0
  79. package/dist/src/palette.js +1 -1
  80. package/dist/src/permissions.js +17 -4
  81. package/dist/src/provider-connection.js +15 -0
  82. package/dist/src/provider-settings.d.ts +16 -1
  83. package/dist/src/provider-settings.js +36 -20
  84. package/dist/src/providers.d.ts +14 -2
  85. package/dist/src/providers.js +69 -11
  86. package/dist/src/react-runtime.js +12 -7
  87. package/dist/src/remote/engine-pool.js +5 -4
  88. package/dist/src/run-control.d.ts +2 -2
  89. package/dist/src/run-control.js +9 -6
  90. package/dist/src/runtime.d.ts +2 -0
  91. package/dist/src/runtime.js +2 -1
  92. package/dist/src/sessions.d.ts +1 -0
  93. package/dist/src/sessions.js +4 -2
  94. package/dist/src/skills/bundled/graph-manager/errors.md +1 -1
  95. package/dist/src/skills/bundled/provenance.json +738 -738
  96. package/dist/src/subagent-run.d.ts +2 -0
  97. package/dist/src/subagent-run.js +14 -3
  98. package/dist/src/telemetry/schema.d.ts +1 -1
  99. package/dist/src/telemetry/schema.js +2 -2
  100. package/dist/src/terminal-ui.d.ts +21 -0
  101. package/dist/src/terminal-ui.js +73 -10
  102. package/dist/src/transcript.js +3 -0
  103. package/dist/src/types.d.ts +3 -0
  104. package/dist/src/workspace-instructions.js +1 -1
  105. package/package.json +12 -1
@@ -117,11 +117,16 @@ export declare function validateMemoryConfig(memory: unknown): void;
117
117
  export declare function resolveMemoryConfig(config: Config, env?: NodeJS.ProcessEnv, warn?: (message: string) => void): MemoryConfig;
118
118
  export declare function loadConfig(directory?: string): Promise<Config>;
119
119
  export declare function loadSavedAnalytics(directory?: string): Promise<AnalyticsConfig | undefined>;
120
+ /** Saves a whole config. When an Andorra entry the user removed is dropped (see above), `config` itself is updated to match what was saved. */
120
121
  export declare function saveConfig(config: Config, directory?: string): Promise<void>;
121
122
  export declare class ConfigConflictError extends Error {
122
123
  constructor();
123
124
  }
124
- export declare function changeConfigFile(directory: string, change: (current: Config) => Config, attempts?: number): Promise<Config>;
125
+ /**
126
+ * `prepare`, when given, runs once inside the cross-process config lock before the config is read, and its
127
+ * result is handed to `change`: for a change that depends on other saved state, which must be read under the lock.
128
+ */
129
+ export declare function changeConfigFile<T = undefined>(directory: string, change: (current: Config, prepared: T) => Config, attempts?: number, prepare?: () => Promise<T>): Promise<Config>;
125
130
  export declare function validateCodeIntelConfig(codeIntel: unknown): void;
126
131
  export declare function resolveCodeIntelConfig(config: Config): Required<Pick<CodeIntelConfig, 'enabled'>> & CodeIntelConfig;
127
132
  export declare function validateRemoteConfig(remote: unknown): void;
@@ -4,8 +4,11 @@ import { homedir } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
5
5
  import { randomUUID } from 'node:crypto';
6
6
  import { isIP } from 'node:net';
7
+ import { cleanModelName, fallbackProviderId } from './andorra/entry.js';
8
+ import { readHostedState } from './andorra/state.js';
7
9
  import { assertProviderCredentials, assertRequestTimeout, assertStreamIdleTimeout, MAX_CODEX_ACCOUNT_KEY_LENGTH, MAX_PROVIDER_NAME_LENGTH, PROVIDER_TYPES, REASONING_EFFORTS } from './providers.js';
8
10
  import { GROK_BASE_URL } from './grok-provider.js';
11
+ import { ANDORRA_PROVIDER_BASE_URL } from './andorra/endpoint.js';
9
12
  import { OPENCODE_BASE_URL } from './opencode-cli-provider.js';
10
13
  import { validateAnalyticsConfig } from './analytics.js';
11
14
  import { isPermissionMode } from './permissions.js';
@@ -119,6 +122,31 @@ function privateHttpHost(host) {
119
122
  }
120
123
  return isIP(address) === 6 && (/^f[cd]/.test(address) || /^fe[89ab]/.test(address));
121
124
  }
125
+ /**
126
+ * Brings a saved Andorra entry in line with this build instead of refusing it, so a config saved by another
127
+ * build always loads: the address is informational (requests never use it) and becomes today's, and the display
128
+ * names are cleaned by today's rule, dropping any that cannot be shown.
129
+ */
130
+ function normaliseAndorraEntry(provider) {
131
+ provider.baseUrl = ANDORRA_PROVIDER_BASE_URL;
132
+ if (provider.modelNames === undefined)
133
+ return;
134
+ const saved = provider.modelNames;
135
+ const names = {};
136
+ if (saved && typeof saved === 'object' && !Array.isArray(saved)) {
137
+ for (const [model, name] of Object.entries(saved)) {
138
+ if (!model.trim() || model.length > 500 || ['__proto__', 'constructor', 'prototype'].includes(model) || typeof name !== 'string')
139
+ continue;
140
+ const cleaned = cleanModelName(name);
141
+ if (cleaned !== undefined)
142
+ names[model] = cleaned;
143
+ }
144
+ }
145
+ if (Object.keys(names).length > 0)
146
+ provider.modelNames = names;
147
+ else
148
+ delete provider.modelNames;
149
+ }
122
150
  export function validateConfig(value) {
123
151
  const c = value;
124
152
  if (!c || c.version !== 1 || typeof c.provider !== 'string' || !Array.isArray(c.providers)) {
@@ -200,7 +228,10 @@ export function validateConfig(value) {
200
228
  return c;
201
229
  }
202
230
  const ids = new Set();
231
+ let andorraSeen = false;
203
232
  for (const p of c.providers) {
233
+ if (p && typeof p === 'object' && p.type === 'andorra')
234
+ normaliseAndorraEntry(p);
204
235
  if (!p || typeof p.id !== 'string' || !/^[\w-]+$/.test(p.id) || ids.has(p.id)
205
236
  || !PROVIDER_TYPES.includes(p.type)
206
237
  || typeof p.model !== 'string' || !p.model.trim() || p.model.length > 500 || typeof p.baseUrl !== 'string'
@@ -233,6 +264,13 @@ export function validateConfig(value) {
233
264
  }
234
265
  }
235
266
  }
267
+ if (p.modelNames !== undefined) {
268
+ const names = p.modelNames;
269
+ // An Andorra entry's names were normalised above; on any other provider the key has no meaning.
270
+ if (p.type !== 'andorra' || !names || typeof names !== 'object' || Array.isArray(names)) {
271
+ throw new Error('Provider modelNames is an Andorra-only map of model ids to one-line display names of up to 80 characters');
272
+ }
273
+ }
236
274
  if (p.reasoningEffort !== undefined && (!['openai-compatible', 'opencode-go', 'anthropic'].includes(p.type) || !REASONING_EFFORTS.includes(p.reasoningEffort))) {
237
275
  throw new Error('Invalid reasoningEffort: use an OpenAI-compatible, OpenCode Go or Anthropic provider and none, minimal, low, medium, high, xhigh, or max');
238
276
  }
@@ -264,6 +302,11 @@ export function validateConfig(value) {
264
302
  if (p.type === 'opencode' && p.baseUrl !== OPENCODE_BASE_URL) {
265
303
  throw new Error('OpenCode providers use the installed OpenCode CLI; custom endpoints are not supported');
266
304
  }
305
+ if (p.type === 'andorra') {
306
+ if (andorraSeen)
307
+ throw new Error('Only one Andorra provider can be configured');
308
+ andorraSeen = true;
309
+ }
267
310
  if (p.type === 'opencode' && [p.model, ...(p.models ?? [])].some(model => !/^[^/\s]+\/\S/.test(model))) {
268
311
  throw new Error('OpenCode models are named provider/model, for example opencode/big-pickle');
269
312
  }
@@ -615,19 +658,59 @@ async function withConfigLock(directory, run) {
615
658
  }
616
659
  }
617
660
  }
661
+ /**
662
+ * Called by every config write, inside the save lock, on the config about to be written: when the user removed the
663
+ * Andorra provider (the decision in `andorra-hosted.json` says `removed`) an Andorra entry in it is dropped, with
664
+ * the selection moved off it and a pair that named it cleared. The decision is read here, under the lock the
665
+ * removal's own save takes, so a writer holding a copy of the config from before the removal (the terminal app
666
+ * saves the config it has in memory) cannot bring the entry back, and an entry left behind by an interrupted
667
+ * removal goes with the next save. The state file is only read here, never updated (see the lock rule in
668
+ * `src/andorra/state.ts`). A state that cannot be read leaves the config as it is.
669
+ */
670
+ async function withoutRemovedAndorra(config, directory) {
671
+ const entry = config.providers.find(provider => provider.type === 'andorra');
672
+ if (entry === undefined)
673
+ return config;
674
+ let decision;
675
+ try {
676
+ decision = (await readHostedState(directory)).entry;
677
+ }
678
+ catch {
679
+ return config;
680
+ }
681
+ if (decision !== 'removed')
682
+ return config;
683
+ const providers = config.providers.filter(provider => provider !== entry);
684
+ return reconcileSubagentPair({ ...config, providers, provider: config.provider === entry.id ? fallbackProviderId(providers) : config.provider });
685
+ }
686
+ /** Saves a whole config. When an Andorra entry the user removed is dropped (see above), `config` itself is updated to match what was saved. */
618
687
  export async function saveConfig(config, directory = configDirectory()) {
619
- await withConfigLock(directory, () => writeConfig(config, directory));
688
+ await withConfigLock(directory, async () => {
689
+ const saved = await withoutRemovedAndorra(config, directory);
690
+ if (saved !== config) {
691
+ config.providers = saved.providers;
692
+ config.provider = saved.provider;
693
+ if (saved.externalSubagent === undefined)
694
+ delete config.externalSubagent;
695
+ }
696
+ await writeConfig(config, directory);
697
+ });
620
698
  }
621
699
  export class ConfigConflictError extends Error {
622
700
  constructor() { super('The configuration changed while this change was being applied. Try again.'); this.name = 'ConfigConflictError'; }
623
701
  }
624
- export async function changeConfigFile(directory, change, attempts = 3) {
702
+ /**
703
+ * `prepare`, when given, runs once inside the cross-process config lock before the config is read, and its
704
+ * result is handed to `change`: for a change that depends on other saved state, which must be read under the lock.
705
+ */
706
+ export async function changeConfigFile(directory, change, attempts = 3, prepare) {
625
707
  const stored = join(directory, 'config.json');
626
708
  const read = async () => await readFile(stored, 'utf8').catch(() => undefined);
627
709
  return await withConfigLock(directory, async () => {
710
+ const prepared = (prepare === undefined ? undefined : await prepare());
628
711
  for (let attempt = 0; attempt < attempts; attempt++) {
629
712
  const before = await read();
630
- const next = change((await readStoredConfig(directory)).config);
713
+ const next = await withoutRemovedAndorra(change((await readStoredConfig(directory)).config, prepared), directory);
631
714
  if (await read() !== before)
632
715
  continue;
633
716
  await writeConfig(next, directory);
@@ -22,6 +22,8 @@ export interface DashboardView {
22
22
  model: string;
23
23
  graph?: Graph;
24
24
  providerModels?: Readonly<Record<string, string>>;
25
+ /** Provider id → model id → display name; a model without one shows its id. */
26
+ modelNames?: Readonly<Record<string, Readonly<Record<string, string>>>>;
25
27
  activeNodes: readonly string[];
26
28
  nodeModels: ReadonlyMap<string, string>;
27
29
  todos: readonly TodoItem[];
@@ -104,6 +104,11 @@ function beside(left, right, leftWidth, rightWidth) {
104
104
  segments: [...fitRow(left[index] ?? empty, leftWidth).segments, seg(' '), ...fitRow(right[index] ?? empty, rightWidth).segments],
105
105
  }));
106
106
  }
107
+ function named(view, provider, model) {
108
+ const own = view.modelNames && Object.hasOwn(view.modelNames, provider) ? view.modelNames[provider] : undefined;
109
+ const name = own && Object.hasOwn(own, model) ? own[model] : undefined;
110
+ return typeof name === 'string' && name ? name : model;
111
+ }
107
112
  function graphRows(view) {
108
113
  const graph = view.graph;
109
114
  if (!graph)
@@ -127,7 +132,11 @@ function graphRows(view) {
127
132
  }
128
133
  const current = active.has(id);
129
134
  const model = view.nodeModels.get(id) ?? (node.type === 'agent'
130
- ? `${node.provider ?? view.provider}/${node.model ?? (node.provider && node.provider !== view.provider ? view.providerModels?.[node.provider] ?? 'Unavailable' : view.model)}` : node.type);
135
+ ? (() => {
136
+ const provider = node.provider ?? view.provider;
137
+ const model = node.model ?? (node.provider && node.provider !== view.provider ? view.providerModels?.[node.provider] : view.model);
138
+ return `${provider}/${model === undefined ? 'Unavailable' : named(view, provider, model)}`;
139
+ })() : node.type);
131
140
  rows.push(row(seg(current ? '● ' : '○ ', current ? focus : FAINT), seg(node.name, current ? WHITE : GRAY)));
132
141
  rows.push(row(seg(` ${model}`, FAINT)));
133
142
  }
@@ -150,7 +159,7 @@ export function dashboardRows(view, width, height) {
150
159
  const value = (reading) => seg(reading, DIM);
151
160
  const count = (reading) => reading === undefined ? unavailable : value(number.format(reading));
152
161
  const speed = model?.tokensPerSecond !== undefined ? value(`${model.tokensPerSecond.toFixed(1)} tok/s`) : unavailable;
153
- const identity = model ? row(seg(`${model.provider}/${model.model}`, WHITE)) : row(seg(`${view.provider}/${view.model}`, WHITE), seg(' · no requests', FAINT));
162
+ const identity = model ? row(seg(`${model.provider}/${named(view, model.provider, model.model)}`, WHITE)) : row(seg(`${view.provider}/${named(view, view.provider, view.model)}`, WHITE), seg(' · no requests', FAINT));
154
163
  const tokenHint = `${selected + 1}/${models} · Ctrl+N`;
155
164
  const tokenCard = (cardWidth) => card('Session tokens', tokenHint, [
156
165
  identity,
@@ -5,7 +5,7 @@ export const PREPARE_STEPS = 'prepare_steps';
5
5
  export const PREPARED_TRIGGERS = ['success', 'failure', 'always'];
6
6
  const kinds = ['investigate', 'retry', 'change_strategy', 'verify', 'complete'];
7
7
  const triggerKinds = new Set(['investigate', 'verify']);
8
- const forbidden = new Set([PREPARE_STEPS, 'complete_agent', 'update_todos', 'ask_user', 'spawn_subagent', 'accept_change', 'discard_change', 'remove_untracked_file']);
8
+ const forbidden = new Set([PREPARE_STEPS, 'complete_agent', 'update_todos', 'ask_user', 'spawn_subagent', 'wait_subagent', 'message_subagent', 'cancel_subagent', 'accept_change', 'discard_change', 'remove_untracked_file']);
9
9
  const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
10
10
  export function boundedDecisionText(text, bytes) {
11
11
  const value = redactSecrets(text).text;
@@ -17,7 +17,7 @@ export async function applyToolMenu(options) {
17
17
  const signal = pause ? AbortSignal.any([options.context.signal, pause]) : options.context.signal;
18
18
  const previous = options.resumeMessages ?? options.previousConversation?.messages ?? [];
19
19
  const historical = [...new Set([...previous.flatMap(message => (message.toolCalls ?? []).map(call => call.name)), ...(options.efficiency?.toolMenuRouting?.pinnedTools ?? [])])];
20
- const identity = { runId: options.runId ?? randomUUID(), nodeId: options.nodeId ?? 'engineer', invocationId: randomUUID() };
20
+ const identity = { runId: options.runId ?? randomUUID(), nodeId: options.nodeId ?? 'engineer', invocationId: randomUUID(), ...(options.subagentId ? { subagentId: options.subagentId } : {}) };
21
21
  const emit = async (data) => {
22
22
  try {
23
23
  await options.onEvent?.({ type: 'efficiency.tool_menu', time: new Date().toISOString(), data: { ...identity, mode, ...data } });
@@ -1,6 +1,6 @@
1
1
  import { DecisionPolicy } from './DecisionPolicy.js';
2
2
  import { hasFactGuidance } from './guidancePolicy.js';
3
- const families = { Read: 'filesystem-read', Glob: 'code-search', Grep: 'code-search', Write: 'filesystem-write', Edit: 'filesystem-write', Bash: 'shell', PowerShell: 'shell', NativeExec: 'shell', AsyncProcess: 'shell', PowerShellFast: 'shell', ShellMetrics: 'shell', read: 'filesystem-read', ls: 'filesystem-read', find: 'code-search', grep: 'code-search', write: 'filesystem-write', edit: 'filesystem-write', powershell: 'shell', bash: 'shell', read_file: 'filesystem-read', list_files: 'filesystem-read', write_file: 'filesystem-write', edit_file: 'filesystem-write', apply_patch: 'filesystem-write', search_files: 'code-search', repo_explore: 'codegraph', git_read: 'git', pull_request: 'git', shell: 'shell', memory_search: 'memory', spawn_subagent: 'subagents', read_artifact: 'artifact', write_artifact: 'artifact' };
3
+ const families = { Read: 'filesystem-read', Glob: 'code-search', Grep: 'code-search', Write: 'filesystem-write', Edit: 'filesystem-write', Bash: 'shell', PowerShell: 'shell', NativeExec: 'shell', AsyncProcess: 'shell', PowerShellFast: 'shell', ShellMetrics: 'shell', read: 'filesystem-read', ls: 'filesystem-read', find: 'code-search', grep: 'code-search', write: 'filesystem-write', edit: 'filesystem-write', powershell: 'shell', bash: 'shell', read_file: 'filesystem-read', list_files: 'filesystem-read', write_file: 'filesystem-write', edit_file: 'filesystem-write', apply_patch: 'filesystem-write', search_files: 'code-search', repo_explore: 'codegraph', git_read: 'git', pull_request: 'git', shell: 'shell', memory_search: 'memory', spawn_subagent: 'subagents', wait_subagent: 'subagents', message_subagent: 'subagents', cancel_subagent: 'subagents', read_artifact: 'artifact', write_artifact: 'artifact' };
4
4
  const protectedTools = new Set(['complete_agent', 'complete', 'complete_task', 'submit_completion', 'update_todos', 'ask_user', 'load_project_skill', 'restore_tools', 'prepare_steps', 'prepare_finish']);
5
5
  export function toolFamily(tool) { return tool.family ?? families[tool.name]; }
6
6
  export function toolFamilies(tools) { return [...new Set(tools.map(toolFamily).filter((family) => family !== undefined))]; }
@@ -90,4 +90,5 @@ export interface DecisionIdentity {
90
90
  runId: string;
91
91
  nodeId: string;
92
92
  invocationId: string;
93
+ subagentId?: string;
93
94
  }
@@ -2,6 +2,7 @@ import type { Config } from './config.js';
2
2
  import type { Graph } from './graphs.js';
3
3
  import { type ProviderConfig } from './providers.js';
4
4
  import type { ModelAdapter, Usage } from './types.js';
5
+ import type { AndorraAvailability } from './andorra/state.js';
5
6
  export interface GraphModelHealthFailure {
6
7
  provider: string;
7
8
  model: string;
@@ -9,6 +10,8 @@ export interface GraphModelHealthFailure {
9
10
  reason: string;
10
11
  providerError?: boolean;
11
12
  timedOut?: boolean;
13
+ /** The reason is a whole sentence for the user (an Andorra refusal): shown as it is, with no advice to edit the graph. */
14
+ plain?: boolean;
12
15
  }
13
16
  export interface GraphModelHealthResult {
14
17
  healthy: boolean;
@@ -32,6 +35,8 @@ export interface GraphModelHealthDependencies {
32
35
  has(provider: ProviderConfig, model: string): boolean;
33
36
  add(provider: ProviderConfig, model: string): void;
34
37
  };
38
+ /** What the client's Andorra monitor knows from a check that answered; undefined when it does not know yet. */
39
+ andorra?: () => AndorraAvailability | undefined | Promise<AndorraAvailability | undefined>;
35
40
  }
36
41
  export interface GraphResumeScope {
37
42
  nodeResults?: Record<string, unknown>;
@@ -50,7 +55,13 @@ export interface SessionModelCheckDependencies {
50
55
  verified?: GraphModelHealthDependencies['verified'];
51
56
  timeoutMs?: number;
52
57
  nodes?: string[];
58
+ andorra?: GraphModelHealthDependencies['andorra'];
53
59
  }
54
60
  export declare function checkSessionModelHealth(config: Config, signal: AbortSignal, dependencies?: SessionModelCheckDependencies): Promise<GraphModelHealthResult>;
55
61
  export declare function formatGraphHealthFailure(result: GraphModelHealthResult, remediation?: string): string;
62
+ /**
63
+ * When every failure is a plain sentence (Andorra refused: unavailable, sign in, allowance, busy), those
64
+ * sentences alone; undefined otherwise. Nothing in the graph is wrong then, so nothing says to fix it.
65
+ */
66
+ export declare function plainHealthFailure(failures: readonly GraphModelHealthFailure[]): string | undefined;
56
67
  export declare function blockingHealthFailures(result: GraphModelHealthResult, continuation: boolean): GraphModelHealthFailure[];
@@ -1,4 +1,5 @@
1
1
  import { configuredContextWindow, createAdapter } from './providers.js';
2
+ import { ANDORRA_UNAVAILABLE_MESSAGE } from './andorra/endpoint.js';
2
3
  export function resumeModelNodes(graph, resume) {
3
4
  if (resume === undefined)
4
5
  return undefined;
@@ -110,6 +111,15 @@ export async function checkGraphModelHealth(graph, config, signal, dependencies
110
111
  failures[index] = { ...reference, reason: 'Provider is not configured.' };
111
112
  continue;
112
113
  }
114
+ if (provider.type === 'andorra') {
115
+ // The client has the router's fresh answer (or asks it once now): no model request is sent to learn it again.
116
+ const known = await Promise.resolve(dependencies.andorra?.()).catch(() => undefined);
117
+ signal.throwIfAborted();
118
+ if (known && !known.available) {
119
+ failures[index] = { ...reference, providerError: true, plain: true, reason: known.message };
120
+ continue;
121
+ }
122
+ }
113
123
  if (dependencies.verified?.has(provider, reference.model)) {
114
124
  answered[index] = true;
115
125
  continue;
@@ -144,6 +154,10 @@ export async function checkGraphModelHealth(graph, config, signal, dependencies
144
154
  requests += 1;
145
155
  dependencies.onUsage?.({ requests: 1 }, reference);
146
156
  },
157
+ // The probe of an Andorra model makes one attempt. The adapter's retry schedule (up to minutes, for a
158
+ // router that cannot be reached) belongs to a conversation, where each retry is shown; here it would
159
+ // only be a silent wait, so the first retry it announces ends the probe with that retry's reason.
160
+ ...(provider.type === 'andorra' ? { onRetry: (retry) => { throw new Error(retry.reason); } } : {}),
147
161
  });
148
162
  }), aborted]);
149
163
  signal.throwIfAborted();
@@ -160,9 +174,13 @@ export async function checkGraphModelHealth(graph, config, signal, dependencies
160
174
  }, reference);
161
175
  }
162
176
  }
163
- catch {
177
+ catch (error) {
164
178
  signal.throwIfAborted();
165
- failures[index] = { ...reference, providerError: true, ...(timedOut ? { timedOut: true } : {}), reason: timedOut ? 'Model health check timed out.' : 'Model request failed. Check model availability and provider credentials.' };
179
+ // Andorra's adapter words its own failures (unavailable, sign in, allowance, busy): that sentence is the reason.
180
+ // A probe of Andorra that ran out of time was still trying to reach the router: that reads as unavailable.
181
+ const said = provider.type !== 'andorra' ? undefined : timedOut ? ANDORRA_UNAVAILABLE_MESSAGE : error instanceof Error && error.message.trim() ? error.message : undefined;
182
+ failures[index] = said !== undefined ? { ...reference, providerError: true, ...(timedOut ? { timedOut: true } : {}), plain: true, reason: said }
183
+ : { ...reference, providerError: true, ...(timedOut ? { timedOut: true } : {}), reason: timedOut ? 'Model health check timed out.' : 'Model request failed. Check model availability and provider credentials.' };
166
184
  }
167
185
  finally {
168
186
  clearTimeout(timer);
@@ -199,8 +217,9 @@ export async function checkSessionModelHealth(config, signal, dependencies = {})
199
217
  if (dependencies.verified?.has(provider, model))
200
218
  return { healthy: true, failures: [] };
201
219
  const timeoutMs = dependencies.timeoutMs ?? 30_000;
202
- const adapter = (dependencies.createAdapter ?? createAdapter)(provider);
203
- if (adapter.listModels) {
220
+ // Andorra is asked once, by the probe: its refusals are sentences a model listing would not carry.
221
+ const adapter = provider.type === 'andorra' ? undefined : (dependencies.createAdapter ?? createAdapter)(provider);
222
+ if (adapter?.listModels) {
204
223
  let models;
205
224
  try {
206
225
  models = await adapter.listModels(AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]));
@@ -221,17 +240,30 @@ export async function checkSessionModelHealth(config, signal, dependencies = {})
221
240
  const result = await checkGraphModelHealth(probeGraph, config, signal, {
222
241
  timeoutMs, ...(dependencies.createAdapter ? { createAdapter: dependencies.createAdapter } : {}),
223
242
  ...(dependencies.verified ? { verified: dependencies.verified } : {}),
243
+ ...(dependencies.andorra ? { andorra: dependencies.andorra } : {}),
224
244
  });
225
245
  return { healthy: result.healthy, failures: result.failures.map(failure => ({ ...failure, ...reply })) };
226
246
  }
227
247
  export function formatGraphHealthFailure(result, remediation = 'Open /graph > Edit Graphs, fix the model selections, then reload the graph to check again.') {
228
248
  if (result.healthy)
229
249
  return '';
250
+ const plain = plainHealthFailure(result.failures);
251
+ if (plain !== undefined)
252
+ return plain;
230
253
  return ['Graph model health check failed. These models are unavailable:',
231
254
  ...result.failures.map(failure => `- ${failure.provider}/${failure.model}: ${failure.reason} Nodes: ${failure.nodes.join(', ')}`),
232
255
  `Tasks are blocked because these unavailable models will cause errors downstream. ${remediation}`,
233
256
  ].join('\n');
234
257
  }
258
+ /**
259
+ * When every failure is a plain sentence (Andorra refused: unavailable, sign in, allowance, busy), those
260
+ * sentences alone; undefined otherwise. Nothing in the graph is wrong then, so nothing says to fix it.
261
+ */
262
+ export function plainHealthFailure(failures) {
263
+ if (failures.length === 0 || !failures.every(failure => failure.plain === true))
264
+ return undefined;
265
+ return [...new Set(failures.map(failure => failure.reason))].join('\n');
266
+ }
235
267
  export function blockingHealthFailures(result, continuation) {
236
268
  return continuation ? result.failures.filter(failure => failure.timedOut !== true) : result.failures;
237
269
  }
@@ -13,6 +13,8 @@ export type ManagerEvent = {
13
13
  type: 'snapshot';
14
14
  events: ManagerEvent[];
15
15
  state: ManagerState;
16
+ edits?: ManagerLiveEdit[];
17
+ stream?: string;
16
18
  } | {
17
19
  type: 'user';
18
20
  text: string;
@@ -81,7 +83,16 @@ export type ManagerEvent = {
81
83
  type: 'graph.edit';
82
84
  graphId: string;
83
85
  edit: ManagerGraphEdit;
86
+ seq?: number;
87
+ stream?: string;
84
88
  };
89
+ /** A live draft edit, numbered so a panel that reconnects can apply the ones it missed. */
90
+ export interface ManagerLiveEdit {
91
+ seq: number;
92
+ graphId: string;
93
+ edit: ManagerGraphEdit;
94
+ stream: string;
95
+ }
85
96
  export type ManagerGraphEdit = {
86
97
  kind: 'node';
87
98
  node: Record<string, unknown>;
@@ -160,6 +171,13 @@ export declare class GraphManagerChat {
160
171
  private idleWaiters;
161
172
  private readonly now;
162
173
  private toolRows;
174
+ private liveEdits;
175
+ private editSeq;
176
+ /** Names this chat's edit numbering, so a panel never compares numbers from two conversations. */
177
+ private readonly editStream;
178
+ /** The open graph as the panel holds it: the canvas sent with the last message plus the edits since. */
179
+ private canvas;
180
+ private readonly draftStates;
163
181
  constructor(options: GraphManagerChatOptions);
164
182
  subscribe(listener: (event: ManagerEvent) => void): () => void;
165
183
  send(turn: ManagerTurn): Promise<void>;
@@ -181,6 +199,21 @@ export declare class GraphManagerChat {
181
199
  private stopEngine;
182
200
  private onEngineEvent;
183
201
  private onRunEvent;
202
+ private publishesOpenGraph;
203
+ /**
204
+ * The engine clips a tool's output at 24,000 characters, so the reply to a call that set a long prompt
205
+ * is not readable JSON. The call succeeded, so its own arguments say what the draft now holds: an
206
+ * upsert's whole node or connection, or a patch over the draft's (or else the canvas's) copy of the step.
207
+ */
208
+ private editFromArguments;
209
+ private liveEdit;
210
+ /**
211
+ * A draft opened in edit mode starts from the latest saved revision, which lacks the unsaved changes on
212
+ * the canvas. A patched node from that draft would put stale fields back, so a patch of a step the
213
+ * canvas holds carries only the fields it names, plus any the backend changed with them. An upsert
214
+ * states the whole step or connection, so it is shown as given.
215
+ */
216
+ private reconcile;
184
217
  private settleTool;
185
218
  private onReasoning;
186
219
  private settleOpenRows;