@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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type CliExecutableSpec } from './cli-executable.js';
|
|
2
|
+
import type { ModelAdapter, ModelResponse, ToolSchema } from './types.js';
|
|
3
|
+
export declare const GOOGLE_BASE_URL = "https://antigravity.google";
|
|
4
|
+
export declare const GOOGLE_EXECUTABLE: CliExecutableSpec;
|
|
5
|
+
export declare function googleEnvironment(source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
6
|
+
export interface GoogleRunOptions {
|
|
7
|
+
input?: string;
|
|
8
|
+
captureStderr?: boolean;
|
|
9
|
+
acceptedExitCodes?: number[];
|
|
10
|
+
}
|
|
11
|
+
export type GoogleRun = (args: string[], signal: AbortSignal, options?: GoogleRunOptions) => Promise<{
|
|
12
|
+
stdout: string;
|
|
13
|
+
stderr: string;
|
|
14
|
+
}>;
|
|
15
|
+
export interface GoogleDependencies {
|
|
16
|
+
run?: GoogleRun;
|
|
17
|
+
}
|
|
18
|
+
export declare const runGoogleProcess: GoogleRun;
|
|
19
|
+
export declare function parseGoogleModels(output: string): {
|
|
20
|
+
signedIn: boolean;
|
|
21
|
+
models: string[];
|
|
22
|
+
};
|
|
23
|
+
export declare function readGoogleCatalog(signal: AbortSignal, dependencies?: GoogleDependencies): Promise<{
|
|
24
|
+
signedIn: boolean;
|
|
25
|
+
models: string[];
|
|
26
|
+
}>;
|
|
27
|
+
export declare function parseGoogleResponse(output: string, tools?: readonly Pick<ToolSchema, 'name'>[]): ModelResponse;
|
|
28
|
+
export declare function parseGoogleText(output: string): ModelResponse;
|
|
29
|
+
export declare function createGoogleAdapter(_config: {
|
|
30
|
+
model: string;
|
|
31
|
+
}, dependencies?: GoogleDependencies): ModelAdapter;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { resolveCliExecutable } from './cli-executable.js';
|
|
3
|
+
import { runBoundedCli } from './cli-process.js';
|
|
4
|
+
import { allowanceInstruction, boundTextStep, parseStructuredStep, STRUCTURED_STEP_PROMPT, STRUCTURED_STEP_SCHEMA, structuredStepPrompt, TEXT_STEP_PROMPT } from './structured-step.js';
|
|
5
|
+
export const GOOGLE_BASE_URL = 'https://antigravity.google';
|
|
6
|
+
export const GOOGLE_EXECUTABLE = {
|
|
7
|
+
names: ['agy'], overrideEnv: 'ANDORRA_AGY_PATH', homeDirectories: [join('AppData', 'Local', 'agy', 'bin'), join('.local', 'bin')],
|
|
8
|
+
installMessage: 'Install the Antigravity CLI (agy) from antigravity.google, sign in with Google, then retry the Google provider.',
|
|
9
|
+
};
|
|
10
|
+
const SIGN_IN_MESSAGE = 'Sign in with Google in the Antigravity CLI (agy) on this machine, then retry the Google provider.';
|
|
11
|
+
const REQUEST_TIMEOUT_MS = 10 * 60_000;
|
|
12
|
+
const CATALOG_TIMEOUT_MS = 30_000;
|
|
13
|
+
// Strict permissions make the CLI ask before every one of its own tools, and a headless run cannot
|
|
14
|
+
// answer, so each is denied: the CLI serves as a model and Andorra runs the tools.
|
|
15
|
+
const STEP_SETTINGS = JSON.stringify({ toolPermission: 'strict', disableSlashCommands: true, allowNonWorkspaceAccess: false });
|
|
16
|
+
export function googleEnvironment(source = process.env) {
|
|
17
|
+
const env = Object.fromEntries(Object.entries(source).filter(([key]) => !/^(?:GEMINI_API_KEY$|GOOGLE_API_KEY$|GOOGLE_GENAI_|NODE_OPTIONS$)/i.test(key)));
|
|
18
|
+
return { ...env, NO_COLOR: '1' };
|
|
19
|
+
}
|
|
20
|
+
export const runGoogleProcess = async (args, signal, options = {}) => {
|
|
21
|
+
const executable = await resolveCliExecutable(GOOGLE_EXECUTABLE);
|
|
22
|
+
return runBoundedCli(executable, () => args, signal, { env: googleEnvironment(), label: 'Antigravity CLI', ...options });
|
|
23
|
+
};
|
|
24
|
+
/** The CLI also lists models from other vendors; only Google's own are offered here. */
|
|
25
|
+
const GOOGLE_MODEL = /^gemini-[\w.-]{1,200}$/;
|
|
26
|
+
export function parseGoogleModels(output) {
|
|
27
|
+
const plain = output.replace(/\u001b\[[0-9;]*m/g, '');
|
|
28
|
+
if (/\b(?:please sign in|authentication required|not (?:authenticated|signed in|logged in))\b/i.test(plain))
|
|
29
|
+
return { signedIn: false, models: [] };
|
|
30
|
+
const models = [];
|
|
31
|
+
let listed = 0;
|
|
32
|
+
for (const line of plain.split(/\r?\n/)) {
|
|
33
|
+
const id = line.match(/^([\w.-]+)\t/)?.[1];
|
|
34
|
+
if (!id)
|
|
35
|
+
continue;
|
|
36
|
+
listed += 1;
|
|
37
|
+
if (GOOGLE_MODEL.test(id) && !models.includes(id) && models.length < 1000)
|
|
38
|
+
models.push(id);
|
|
39
|
+
}
|
|
40
|
+
return { signedIn: listed > 0, models };
|
|
41
|
+
}
|
|
42
|
+
export async function readGoogleCatalog(signal, dependencies = {}) {
|
|
43
|
+
const run = dependencies.run ?? runGoogleProcess;
|
|
44
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(CATALOG_TIMEOUT_MS)]);
|
|
45
|
+
const { stdout, stderr } = await run(['models'], bounded, { captureStderr: true, acceptedExitCodes: [0, 1] });
|
|
46
|
+
return parseGoogleModels(`${stdout}\n${stderr}`);
|
|
47
|
+
}
|
|
48
|
+
function frames(text) {
|
|
49
|
+
return text.split(/\r?\n/).filter(line => line.trim().startsWith('{')).map(line => {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(line);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error('Antigravity CLI returned malformed JSON');
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function googleUsage(usage) {
|
|
59
|
+
if (!usage || typeof usage !== 'object')
|
|
60
|
+
return undefined;
|
|
61
|
+
const token = (name) => Number.isSafeInteger(usage[name]) && usage[name] >= 0 ? usage[name] : undefined;
|
|
62
|
+
const input = token('input_tokens');
|
|
63
|
+
const output = token('output_tokens');
|
|
64
|
+
const read = token('cache_read_tokens');
|
|
65
|
+
if (!input && !output && !read)
|
|
66
|
+
return { requests: 1 };
|
|
67
|
+
return { requests: 1,
|
|
68
|
+
...(input === undefined ? {} : { inputTokens: input + (read ?? 0) }),
|
|
69
|
+
...(output === undefined ? {} : { outputTokens: output }),
|
|
70
|
+
...(read === undefined ? {} : { cacheRead: read }) };
|
|
71
|
+
}
|
|
72
|
+
function failure(message) {
|
|
73
|
+
if (typeof message === 'string' && /\bauthenticat|\bsign in\b|\blog in\b/i.test(message))
|
|
74
|
+
return new Error(SIGN_IN_MESSAGE);
|
|
75
|
+
return new Error('Google inference failed. Check the Antigravity CLI sign-in, model access, and plan limits.');
|
|
76
|
+
}
|
|
77
|
+
function singleResult(output, attempted) {
|
|
78
|
+
const events = frames(output);
|
|
79
|
+
for (const event of events) {
|
|
80
|
+
const step = event?.event === 'step_update' ? event.step_update : undefined;
|
|
81
|
+
if (step && (step.step_type === 'tool' || step.tool_name !== undefined || step.tool_info !== undefined || step.subagent_info !== undefined))
|
|
82
|
+
throw new Error(attempted);
|
|
83
|
+
}
|
|
84
|
+
const results = events.filter(event => event?.event === 'result').map(event => event.result);
|
|
85
|
+
if (results.length !== 1 || !results[0] || typeof results[0] !== 'object')
|
|
86
|
+
throw new Error('Google did not return exactly one model result');
|
|
87
|
+
const result = results[0];
|
|
88
|
+
if (result.status !== 'SUCCESS')
|
|
89
|
+
throw failure(result.error);
|
|
90
|
+
if (Array.isArray(result.denied_actions) && result.denied_actions.length)
|
|
91
|
+
throw new Error(attempted);
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
export function parseGoogleResponse(output, tools = []) {
|
|
95
|
+
const result = singleResult(output, 'Google attempted a native tool');
|
|
96
|
+
let structured = result.structured_output;
|
|
97
|
+
if (structured === undefined && typeof result.response === 'string') {
|
|
98
|
+
try {
|
|
99
|
+
structured = JSON.parse(result.response);
|
|
100
|
+
}
|
|
101
|
+
catch { }
|
|
102
|
+
}
|
|
103
|
+
if (structured === undefined)
|
|
104
|
+
throw new Error('Google did not return a complete Andorra model step');
|
|
105
|
+
const response = parseStructuredStep(structured, tools, 'Google');
|
|
106
|
+
const usage = googleUsage(result.usage);
|
|
107
|
+
if (usage)
|
|
108
|
+
response.usage = usage;
|
|
109
|
+
return response;
|
|
110
|
+
}
|
|
111
|
+
export function parseGoogleText(output) {
|
|
112
|
+
const result = singleResult(output, 'Google attempted a tool during text generation');
|
|
113
|
+
const usage = googleUsage(result.usage);
|
|
114
|
+
return { text: typeof result.response === 'string' ? result.response.replace(/\r?\n$/, '') : '', toolCalls: [], ...(usage ? { usage } : {}) };
|
|
115
|
+
}
|
|
116
|
+
export function createGoogleAdapter(_config, dependencies = {}) {
|
|
117
|
+
const run = dependencies.run ?? runGoogleProcess;
|
|
118
|
+
return {
|
|
119
|
+
async listModels(signal) {
|
|
120
|
+
const catalog = await readGoogleCatalog(signal, dependencies);
|
|
121
|
+
if (!catalog.signedIn)
|
|
122
|
+
throw new Error(SIGN_IN_MESSAGE);
|
|
123
|
+
return catalog.models;
|
|
124
|
+
},
|
|
125
|
+
async generate(request) {
|
|
126
|
+
request.signal.throwIfAborted();
|
|
127
|
+
if (!GOOGLE_MODEL.test(request.model))
|
|
128
|
+
throw new Error('The Google provider runs Gemini models only. Choose a Gemini model.');
|
|
129
|
+
const auxiliary = request.maxTokens !== undefined;
|
|
130
|
+
if (auxiliary && (!Number.isSafeInteger(request.maxTokens) || request.maxTokens < 1))
|
|
131
|
+
throw new Error('Invalid auxiliary output allowance.');
|
|
132
|
+
if (auxiliary && request.tools.length)
|
|
133
|
+
throw new Error('Google cannot apply an auxiliary output allowance to tool-bearing requests.');
|
|
134
|
+
const signal = AbortSignal.any([request.signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]);
|
|
135
|
+
const imageCount = request.messages.reduce((total, message) => total + (message.images?.length ?? 0), 0);
|
|
136
|
+
// The CLI has no system-prompt override, so the model-component instructions travel in the prompt.
|
|
137
|
+
const prompt = JSON.stringify({
|
|
138
|
+
instructions: auxiliary ? `${TEXT_STEP_PROMPT} ${allowanceInstruction(request.maxTokens)}` : STRUCTURED_STEP_PROMPT,
|
|
139
|
+
...JSON.parse(structuredStepPrompt(request)),
|
|
140
|
+
...(imageCount ? { omittedImages: `This provider cannot forward images; ${imageCount} image${imageCount === 1 ? ' was' : 's were'} omitted from the conversation.` } : {})
|
|
141
|
+
});
|
|
142
|
+
request.onRequest?.();
|
|
143
|
+
const { stdout } = await run(['--input-format', 'stream-json', '--output-format', 'stream-json', '--model', request.model,
|
|
144
|
+
'--settings', STEP_SETTINGS, '--disable-slash-commands',
|
|
145
|
+
...(auxiliary ? [] : ['--json-schema', JSON.stringify(STRUCTURED_STEP_SCHEMA)])], signal, { input: `${JSON.stringify({ event: 'user', message: { content: prompt } })}\n`, acceptedExitCodes: [0, 1] });
|
|
146
|
+
signal.throwIfAborted();
|
|
147
|
+
if (!auxiliary)
|
|
148
|
+
return parseGoogleResponse(stdout, request.tools);
|
|
149
|
+
const text = parseGoogleText(stdout);
|
|
150
|
+
return boundTextStep(text, request.maxTokens, text.usage?.outputTokens);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -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[];
|
package/dist/src/graph-health.js
CHANGED
|
@@ -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.cause && /^[A-Z][A-Z0-9_]{0,63}$/.test(retry.cause) ? `${retry.reason} (${retry.cause})` : 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
|
-
|
|
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
|
-
|
|
203
|
-
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { mkdir } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
@@ -7,6 +7,7 @@ import { createInterface } from 'node:readline';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { stopAutomationWorker } from './automation-worker-shutdown.js';
|
|
9
9
|
import { configDirectory } from './config.js';
|
|
10
|
+
import { announceGraphVisibilityChange } from './graph-visibility.js';
|
|
10
11
|
import { GRAPH_MANAGER_GRAPH_ID } from './graphs.js';
|
|
11
12
|
import { clipText } from './text.js';
|
|
12
13
|
import { describeTool } from './transcript.js';
|
|
@@ -18,7 +19,39 @@ const UPDATE_MESSAGE = 'Update Andorra Code to use Graph Manager.';
|
|
|
18
19
|
const TOO_LARGE_MESSAGE = 'This graph is too large to send to Graph Manager.';
|
|
19
20
|
const TOOL_LINE_MAX = 120;
|
|
20
21
|
const DRAFTS_MAX = 64;
|
|
22
|
+
const LIVE_EDITS_MAX = 500;
|
|
21
23
|
const BUNDLED_GRAPH_ID = 'default';
|
|
24
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
25
|
+
const clone = (value) => JSON.parse(JSON.stringify(value));
|
|
26
|
+
/** `current` with the named fields, and those that changed between `before` and `after`, taken from `after`. */
|
|
27
|
+
function overlay(current, before, after, named) {
|
|
28
|
+
const out = clone(current);
|
|
29
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after), ...named])) {
|
|
30
|
+
if (!named.includes(key) && same(before[key], after[key]))
|
|
31
|
+
continue;
|
|
32
|
+
if (Object.hasOwn(after, key))
|
|
33
|
+
out[key] = clone(after[key]);
|
|
34
|
+
else
|
|
35
|
+
delete out[key];
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function draftState(output) {
|
|
40
|
+
try {
|
|
41
|
+
const graph = record(record(record(JSON.parse(String(output ?? ''))).data).graph);
|
|
42
|
+
const nodes = record(graph.nodes);
|
|
43
|
+
if (graph.nodes !== nodes || !Array.isArray(graph.edges))
|
|
44
|
+
return undefined;
|
|
45
|
+
const edges = new Map();
|
|
46
|
+
for (const edge of graph.edges)
|
|
47
|
+
if (typeof record(edge).id === 'string')
|
|
48
|
+
edges.set(record(edge).id, clone(record(edge)));
|
|
49
|
+
return { nodes: clone(nodes), edges };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
22
55
|
const DRAFT_EDIT_ACTIONS = new Set(['andorra_graph_node_upsert', 'andorra_graph_node_patch', 'andorra_graph_node_remove', 'andorra_graph_edge_upsert', 'andorra_graph_edge_remove', 'andorra_graph_patch']);
|
|
23
56
|
export function draftEdit(action, args, output) {
|
|
24
57
|
let reply = {};
|
|
@@ -134,7 +167,7 @@ export function managerTask(turn) {
|
|
|
134
167
|
`You are helping in Graph Studio. Open graph: "${graphName(turn.graph)}", id ${graphId(turn.graph)} (${saved}).`,
|
|
135
168
|
graphId(turn.graph) === BUNDLED_GRAPH_ID
|
|
136
169
|
? `The open graph is the bundled preset, which cannot be changed: nothing can be saved under the id "${BUNDLED_GRAPH_ID}". The canvas below is what the user sees now. Do not edit this graph; create a new graph with a new id and its own name (mode "create"), based on the canvas, and make your changes there.`
|
|
137
|
-
: 'The canvas below is what the user sees now, including edits not yet saved. Work from it
|
|
170
|
+
: 'The canvas below is what the user sees now, including edits not yet saved. Work from it: open a draft of this same graph id (mode "create" when it is not saved yet, "edit" otherwise) and make the changes there, upserting from the canvas anything the draft lacks. Each draft edit shows on the canvas at once as an unsaved change. Do not publish this graph: the user reviews your changes and saves them from the editor, and a publish of it is declined.',
|
|
138
171
|
`Selected model: ${turn.provider}/${turn.model}. Use it for new agent nodes unless the user asks otherwise.`,
|
|
139
172
|
'',
|
|
140
173
|
'Canvas:',
|
|
@@ -176,6 +209,13 @@ export class GraphManagerChat {
|
|
|
176
209
|
idleWaiters = [];
|
|
177
210
|
now;
|
|
178
211
|
toolRows = 0;
|
|
212
|
+
liveEdits = [];
|
|
213
|
+
editSeq = 0;
|
|
214
|
+
/** Names this chat's edit numbering, so a panel never compares numbers from two conversations. */
|
|
215
|
+
editStream = randomUUID();
|
|
216
|
+
/** The open graph as the panel holds it: the canvas sent with the last message plus the edits since. */
|
|
217
|
+
canvas;
|
|
218
|
+
draftStates = new Map();
|
|
179
219
|
constructor(options) {
|
|
180
220
|
this.options = options;
|
|
181
221
|
this.directory = resolve(options.directory);
|
|
@@ -186,7 +226,7 @@ export class GraphManagerChat {
|
|
|
186
226
|
subscribe(listener) {
|
|
187
227
|
this.listeners.add(listener);
|
|
188
228
|
this.armIdleStop();
|
|
189
|
-
this.deliverTo(listener, { type: 'snapshot', events: [...this.transcript], state: this.state });
|
|
229
|
+
this.deliverTo(listener, { type: 'snapshot', events: [...this.transcript], state: this.state, edits: [...this.liveEdits], stream: this.editStream });
|
|
190
230
|
return () => { this.listeners.delete(listener); this.armIdleStop(); };
|
|
191
231
|
}
|
|
192
232
|
send(turn) {
|
|
@@ -235,6 +275,9 @@ export class GraphManagerChat {
|
|
|
235
275
|
this.graphCalls.clear();
|
|
236
276
|
this.drafts.clear();
|
|
237
277
|
this.otherRevisions.clear();
|
|
278
|
+
this.liveEdits = [];
|
|
279
|
+
this.draftStates.clear();
|
|
280
|
+
this.canvas = undefined;
|
|
238
281
|
this.openGraphId = undefined;
|
|
239
282
|
this.lastRevision = 0;
|
|
240
283
|
const snapshot = { type: 'snapshot', events: [], state: this.state };
|
|
@@ -273,6 +316,10 @@ export class GraphManagerChat {
|
|
|
273
316
|
const known = turn.saved ? turn.revision ?? 0 : 0;
|
|
274
317
|
this.lastRevision = id === this.openGraphId ? Math.max(this.lastRevision, known) : known;
|
|
275
318
|
this.openGraphId = id;
|
|
319
|
+
const nodes = record(turn.graph.nodes);
|
|
320
|
+
this.canvas = turn.graph.nodes === nodes && Array.isArray(turn.graph.edges)
|
|
321
|
+
? { nodes: clone(nodes), edges: clone(turn.graph.edges), fields: clone(turn.graph) }
|
|
322
|
+
: undefined;
|
|
276
323
|
this.lastModel = { provider: turn.provider, model: turn.model };
|
|
277
324
|
const task = managerTask(turn);
|
|
278
325
|
if (task.length > MANAGER_TASK_MAX_CHARS) {
|
|
@@ -533,11 +580,21 @@ export class GraphManagerChat {
|
|
|
533
580
|
await stopAutomationWorker(engine.child, engine.closed);
|
|
534
581
|
}
|
|
535
582
|
onEngineEvent(event, data) {
|
|
536
|
-
|
|
583
|
+
// The manager runs in its own engine process, so a change it makes to the account's graphs (project visibility
|
|
584
|
+
// included) is announced only there. Pass it on, so the engine hosting this editor tells its clients to reload.
|
|
585
|
+
if (event === 'graphs.changed')
|
|
586
|
+
announceGraphVisibilityChange();
|
|
587
|
+
else if (event === 'run.started' && typeof data.runId === 'string' && this.state === 'starting')
|
|
537
588
|
this.runId = data.runId;
|
|
538
589
|
else if (event === 'run.event')
|
|
539
590
|
this.onRunEvent(record(data.event));
|
|
540
591
|
else if (event === 'run.approval' && typeof data.id === 'string') {
|
|
592
|
+
if (this.publishesOpenGraph(data)) {
|
|
593
|
+
// In the editor Graph Manager's edits stay on the canvas unsaved; the user saves them.
|
|
594
|
+
if (this.engine)
|
|
595
|
+
void this.request(this.engine, 'run.approve', { id: data.id, approved: false }).catch(() => { });
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
541
598
|
this.prompts.add(data.id);
|
|
542
599
|
this.emit({ type: 'approval', id: data.id, text: this.describe(String(data.name), data.arguments) });
|
|
543
600
|
}
|
|
@@ -617,15 +674,117 @@ export class GraphManagerChat {
|
|
|
617
674
|
this.drafts.set(draft, call.begins);
|
|
618
675
|
if (this.drafts.size > DRAFTS_MAX)
|
|
619
676
|
this.drafts.delete(this.drafts.keys().next().value);
|
|
677
|
+
const known = draftState(data.output);
|
|
678
|
+
this.draftStates.delete(draft);
|
|
679
|
+
if (known)
|
|
680
|
+
this.draftStates.set(draft, known);
|
|
681
|
+
if (this.draftStates.size > DRAFTS_MAX)
|
|
682
|
+
this.draftStates.delete(this.draftStates.keys().next().value);
|
|
620
683
|
}
|
|
621
684
|
if (call?.edits) {
|
|
622
|
-
const edit = draftEdit(call.edits.action, call.edits.args, data.output);
|
|
685
|
+
const edit = draftEdit(call.edits.action, call.edits.args, data.output) ?? this.editFromArguments(call.edits.action, call.edits.args);
|
|
623
686
|
if (edit)
|
|
624
|
-
this.
|
|
687
|
+
this.liveEdit(call.edits.graphId, call.edits.action, call.edits.args, edit);
|
|
625
688
|
}
|
|
626
689
|
this.checkRevision(call?.publishes ?? call?.removes);
|
|
627
690
|
}
|
|
628
691
|
}
|
|
692
|
+
publishesOpenGraph(data) {
|
|
693
|
+
if (data.name !== 'graphs' || !this.openGraphId || this.openGraphId === BUNDLED_GRAPH_ID)
|
|
694
|
+
return false;
|
|
695
|
+
const args = toolArguments(data.arguments);
|
|
696
|
+
if (args.action !== 'andorra_graph_publish')
|
|
697
|
+
return false;
|
|
698
|
+
const draftId = record(args.args).draftId;
|
|
699
|
+
return typeof draftId === 'string' && this.drafts.get(draftId)?.id === this.openGraphId;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* The engine clips a tool's output at 24,000 characters, so the reply to a call that set a long prompt
|
|
703
|
+
* is not readable JSON. The call succeeded, so its own arguments say what the draft now holds: an
|
|
704
|
+
* upsert's whole node or connection, or a patch over the draft's (or else the canvas's) copy of the step.
|
|
705
|
+
*/
|
|
706
|
+
editFromArguments(action, args) {
|
|
707
|
+
const node = record(args.node), edge = record(args.edge), patch = record(args.patch);
|
|
708
|
+
if (action === 'andorra_graph_node_upsert')
|
|
709
|
+
return typeof node.id === 'string' && node.id ? { kind: 'node', node: clone(node) } : undefined;
|
|
710
|
+
if (action === 'andorra_graph_edge_upsert')
|
|
711
|
+
return typeof edge.id === 'string' && typeof edge.source === 'string' && typeof edge.target === 'string' ? { kind: 'edge', edge: clone(edge) } : undefined;
|
|
712
|
+
if (action !== 'andorra_graph_node_patch' || typeof args.nodeId !== 'string' || !Object.keys(patch).length)
|
|
713
|
+
return undefined;
|
|
714
|
+
const draftId = typeof args.draftId === 'string' ? args.draftId : '';
|
|
715
|
+
const base = this.draftStates.get(draftId)?.nodes[args.nodeId] ?? this.canvas?.nodes[args.nodeId];
|
|
716
|
+
return base ? { kind: 'node', node: { ...clone(base), ...clone(patch), id: args.nodeId } } : undefined;
|
|
717
|
+
}
|
|
718
|
+
liveEdit(graphId, action, args, edit) {
|
|
719
|
+
const patched = action === 'andorra_graph_node_patch' ? Object.keys(record(args.patch)) : undefined;
|
|
720
|
+
const shown = graphId === this.openGraphId ? this.reconcile(typeof args.draftId === 'string' ? args.draftId : '', edit, patched) : edit;
|
|
721
|
+
if (!shown)
|
|
722
|
+
return;
|
|
723
|
+
const entry = { seq: ++this.editSeq, graphId, edit: shown, stream: this.editStream };
|
|
724
|
+
this.liveEdits.push(entry);
|
|
725
|
+
if (this.liveEdits.length > LIVE_EDITS_MAX)
|
|
726
|
+
this.liveEdits.splice(0, this.liveEdits.length - LIVE_EDITS_MAX);
|
|
727
|
+
this.broadcast({ type: 'graph.edit', ...entry });
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* A draft opened in edit mode starts from the latest saved revision, which lacks the unsaved changes on
|
|
731
|
+
* the canvas. A patched node from that draft would put stale fields back, so a patch of a step the
|
|
732
|
+
* canvas holds carries only the fields it names, plus any the backend changed with them. An upsert
|
|
733
|
+
* states the whole step or connection, so it is shown as given.
|
|
734
|
+
*/
|
|
735
|
+
reconcile(draftId, edit, patched) {
|
|
736
|
+
const draft = this.draftStates.get(draftId), canvas = this.canvas;
|
|
737
|
+
if (edit.kind === 'node') {
|
|
738
|
+
const id = String(edit.node.id);
|
|
739
|
+
const before = draft?.nodes[id], current = canvas?.nodes[id];
|
|
740
|
+
if (draft)
|
|
741
|
+
draft.nodes[id] = clone(edit.node);
|
|
742
|
+
let node = edit.node;
|
|
743
|
+
if (patched) {
|
|
744
|
+
// The draft still had a step the canvas no longer has: it was removed after the draft opened.
|
|
745
|
+
if (canvas && !current)
|
|
746
|
+
return undefined;
|
|
747
|
+
if (current)
|
|
748
|
+
node = overlay(current, before ?? edit.node, edit.node, patched);
|
|
749
|
+
}
|
|
750
|
+
if (canvas)
|
|
751
|
+
canvas.nodes[id] = clone(node);
|
|
752
|
+
return { kind: 'node', node };
|
|
753
|
+
}
|
|
754
|
+
if (edit.kind === 'edge') {
|
|
755
|
+
const id = String(edit.edge.id);
|
|
756
|
+
draft?.edges.set(id, clone(edit.edge));
|
|
757
|
+
if (canvas) {
|
|
758
|
+
const index = canvas.edges.findIndex(item => record(item).id === id);
|
|
759
|
+
if (index >= 0)
|
|
760
|
+
canvas.edges[index] = clone(edit.edge);
|
|
761
|
+
else
|
|
762
|
+
canvas.edges.push(clone(edit.edge));
|
|
763
|
+
}
|
|
764
|
+
return edit;
|
|
765
|
+
}
|
|
766
|
+
if (edit.kind === 'node.remove') {
|
|
767
|
+
const touches = (item) => item.source === edit.nodeId || item.target === edit.nodeId;
|
|
768
|
+
if (draft) {
|
|
769
|
+
delete draft.nodes[edit.nodeId];
|
|
770
|
+
for (const [key, item] of draft.edges)
|
|
771
|
+
if (touches(item))
|
|
772
|
+
draft.edges.delete(key);
|
|
773
|
+
}
|
|
774
|
+
if (canvas) {
|
|
775
|
+
delete canvas.nodes[edit.nodeId];
|
|
776
|
+
canvas.edges = canvas.edges.filter(item => !touches(item));
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
else if (edit.kind === 'edge.remove') {
|
|
780
|
+
draft?.edges.delete(edit.edgeId);
|
|
781
|
+
if (canvas)
|
|
782
|
+
canvas.edges = canvas.edges.filter(item => record(item).id !== edit.edgeId);
|
|
783
|
+
}
|
|
784
|
+
else if (canvas)
|
|
785
|
+
Object.assign(canvas.fields, clone(edit.patch));
|
|
786
|
+
return edit;
|
|
787
|
+
}
|
|
629
788
|
settleTool(toolCallId, status, reason) {
|
|
630
789
|
if (typeof toolCallId !== 'string' || !toolCallId)
|
|
631
790
|
return;
|