@andorra-labs/code 0.1.11 → 0.1.12
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/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/agent-execution.js +15 -3
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +8 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +15 -0
- package/dist/src/app-server.js +89 -10
- package/dist/src/browser-panel-tool.d.ts +24 -3
- package/dist/src/browser-panel-tool.js +80 -6
- package/dist/src/browser-runner.js +3 -1
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +38 -2
- package/dist/src/claude-provider.js +15 -2
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.js +175 -43
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
- package/dist/src/codex-provider.js +6 -3
- package/dist/src/coding-tools.d.ts +2 -1
- package/dist/src/coding-tools.js +39 -31
- package/dist/src/completion.d.ts +43 -1
- package/dist/src/completion.js +145 -4
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/delegation-changes.js +19 -2
- package/dist/src/diff-preview.d.ts +1 -0
- package/dist/src/diff-preview.js +12 -3
- package/dist/src/engine-streams.d.ts +22 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.js +17 -6
- package/dist/src/file-read-key.d.ts +8 -0
- package/dist/src/file-read-key.js +12 -0
- package/dist/src/graph-editor-session.js +2 -1
- package/dist/src/graph-health.d.ts +21 -0
- package/dist/src/graph-health.js +46 -0
- package/dist/src/graph-manager-chat.d.ts +52 -3
- package/dist/src/graph-manager-chat.js +50 -5
- package/dist/src/graph-runner.js +23 -3
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +39 -18
- package/dist/src/graph-ui/app.js +100 -30
- package/dist/src/graph-ui/controls.css +52 -0
- package/dist/src/graph-ui/icons.js +3 -0
- package/dist/src/graph-ui/index.html +2 -2
- package/dist/src/graph-ui/manager-state.js +141 -3
- package/dist/src/graph-ui/manager.css +2 -2
- package/dist/src/graph-ui/manager.js +328 -66
- package/dist/src/graph-ui/model-picker.js +279 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graphs.d.ts +2 -0
- package/dist/src/graphs.js +7 -7
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- package/dist/src/memory/ProjectMemory.d.ts +77 -0
- package/dist/src/memory/ProjectMemory.js +310 -0
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/opencode-provider.js +5 -6
- package/dist/src/package-name.d.ts +3 -0
- package/dist/src/package-name.js +3 -0
- package/dist/src/provider-engine.js +2 -2
- package/dist/src/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +16 -8
- package/dist/src/remote/cert.d.ts +1 -1
- package/dist/src/remote/cert.js +2 -7
- package/dist/src/remote/client.js +1 -1
- package/dist/src/remote/pem.d.ts +6 -0
- package/dist/src/remote/pem.js +11 -0
- package/dist/src/run-records.js +49 -10
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- package/dist/src/sign-in-detection.d.ts +82 -0
- package/dist/src/sign-in-detection.js +197 -0
- package/dist/src/sign-in-offer.d.ts +35 -0
- package/dist/src/sign-in-offer.js +116 -0
- package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
- package/dist/src/skills/bundled/provenance.json +1 -1
- package/dist/src/skills/runtime-skills.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +13 -0
- package/dist/src/stray-files.d.ts +14 -0
- package/dist/src/stray-files.js +81 -0
- package/dist/src/subagent-run.js +6 -1
- package/dist/src/terminal-ui.d.ts +1 -1
- package/dist/src/terminal-ui.js +9 -3
- package/dist/src/tool-activity.js +1 -1
- package/dist/src/tool-schema-compatibility.d.ts +7 -2
- package/dist/src/tool-schema-compatibility.js +8 -4
- package/dist/src/transcript.d.ts +5 -0
- package/dist/src/transcript.js +11 -3
- package/dist/src/types.d.ts +2 -0
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +125 -0
- package/dist/src/update-check.js +1 -1
- package/dist/src/update.d.ts +11 -1
- package/dist/src/update.js +27 -5
- package/dist/src/workspace-git-metadata.d.ts +15 -0
- package/dist/src/workspace-git-metadata.js +50 -1
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { startGraphServer } from './graph-server.js';
|
|
4
3
|
import { requireGraphMembership } from './membership.js';
|
|
4
|
+
// The editor server pulls in the automation scheduler and graph sync; it loads when first opened.
|
|
5
|
+
const startGraphServer = async () => (await import('./graph-server.js')).startGraphServer();
|
|
5
6
|
function openBrowser(url, signal) {
|
|
6
7
|
const command = process.platform === 'win32' ? 'rundll32.exe' : process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
7
8
|
const args = process.platform === 'win32' ? ['url.dll,FileProtocolHandler', url] : [url];
|
|
@@ -83,6 +83,27 @@ export interface GraphResumeScope {
|
|
|
83
83
|
export declare function resumeModelNodes(graph: Graph, resume?: GraphResumeScope): string[] | undefined;
|
|
84
84
|
/** Probe inference itself, rather than trusting a provider's possibly stale model listing. */
|
|
85
85
|
export declare function checkGraphModelHealth(graph: Graph, config: Config, signal: AbortSignal, dependencies?: GraphModelHealthDependencies): Promise<GraphModelHealthResult>;
|
|
86
|
+
/** What the Default graph's selection check needs: the session pair, a shared answer cache, and a bound. */
|
|
87
|
+
export interface SessionModelCheckDependencies {
|
|
88
|
+
createAdapter?: (provider: ProviderConfig) => ModelAdapter;
|
|
89
|
+
verified?: GraphModelHealthDependencies['verified'];
|
|
90
|
+
/** Bound for the model listing, and for the reply probe a provider without a listing falls back to. */
|
|
91
|
+
timeoutMs?: number;
|
|
92
|
+
/** The label the failure names the nodes by. */
|
|
93
|
+
nodes?: string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether the session's own provider still offers its model — the check selecting Default needs.
|
|
97
|
+
*
|
|
98
|
+
* Default is one agent that runs the session pair and nothing else, so checking it as a graph
|
|
99
|
+
* asks that one model for a reply: a whole inference turn (seconds on a hosted model, a full
|
|
100
|
+
* thread on Codex) before the selection settles. This asks the provider's model listing instead,
|
|
101
|
+
* which answers in a fraction of that, and passes at once when the pair answered a probe recently.
|
|
102
|
+
* The run's own preflight still probes inference before any work starts, so a model the listing
|
|
103
|
+
* names but that cannot answer is still refused where it matters. A provider without a listing,
|
|
104
|
+
* or whose listing fails, is probed for a reply as before.
|
|
105
|
+
*/
|
|
106
|
+
export declare function checkSessionModelHealth(config: Config, signal: AbortSignal, dependencies?: SessionModelCheckDependencies): Promise<GraphModelHealthResult>;
|
|
86
107
|
export declare function formatGraphHealthFailure(result: GraphModelHealthResult, remediation?: string): string;
|
|
87
108
|
/**
|
|
88
109
|
* The health failures that must stop work before it starts.
|
package/dist/src/graph-health.js
CHANGED
|
@@ -224,6 +224,52 @@ export async function checkGraphModelHealth(graph, config, signal, dependencies
|
|
|
224
224
|
const unavailable = failures.filter((failure) => failure !== undefined);
|
|
225
225
|
return { healthy: unavailable.length === 0, failures: unavailable };
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Whether the session's own provider still offers its model — the check selecting Default needs.
|
|
229
|
+
*
|
|
230
|
+
* Default is one agent that runs the session pair and nothing else, so checking it as a graph
|
|
231
|
+
* asks that one model for a reply: a whole inference turn (seconds on a hosted model, a full
|
|
232
|
+
* thread on Codex) before the selection settles. This asks the provider's model listing instead,
|
|
233
|
+
* which answers in a fraction of that, and passes at once when the pair answered a probe recently.
|
|
234
|
+
* The run's own preflight still probes inference before any work starts, so a model the listing
|
|
235
|
+
* names but that cannot answer is still refused where it matters. A provider without a listing,
|
|
236
|
+
* or whose listing fails, is probed for a reply as before.
|
|
237
|
+
*/
|
|
238
|
+
export async function checkSessionModelHealth(config, signal, dependencies = {}) {
|
|
239
|
+
signal.throwIfAborted();
|
|
240
|
+
const nodes = dependencies.nodes ?? ['Andorra Agent'];
|
|
241
|
+
const provider = config.providers.find(p => p.id === config.provider);
|
|
242
|
+
const model = provider?.model ?? '(default model)';
|
|
243
|
+
if (!provider)
|
|
244
|
+
return { healthy: false, failures: [{ provider: config.provider, model, nodes, reason: 'Provider is not configured.' }] };
|
|
245
|
+
if (dependencies.verified?.has(provider, model))
|
|
246
|
+
return { healthy: true, failures: [] };
|
|
247
|
+
const timeoutMs = dependencies.timeoutMs ?? 30_000;
|
|
248
|
+
const adapter = (dependencies.createAdapter ?? createAdapter)(provider);
|
|
249
|
+
if (adapter.listModels) {
|
|
250
|
+
let models;
|
|
251
|
+
try {
|
|
252
|
+
models = await adapter.listModels(AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]));
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
signal.throwIfAborted();
|
|
256
|
+
}
|
|
257
|
+
if (models !== undefined && models.length > 0) {
|
|
258
|
+
return models.includes(model) ? { healthy: true, failures: [] } : { healthy: false, failures: [{
|
|
259
|
+
provider: provider.id, model, nodes, providerError: true,
|
|
260
|
+
reason: 'The provider does not offer this model. Choose another one with /model.',
|
|
261
|
+
}] };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const reply = { provider: provider.id, model, nodes };
|
|
265
|
+
const probeGraph = { schemaVersion: 3, id: 'session-model', name: 'Session model', revision: 1, entry: 'agent',
|
|
266
|
+
nodes: { agent: { id: 'agent', name: nodes[0], type: 'agent' } }, edges: [] };
|
|
267
|
+
const result = await checkGraphModelHealth(probeGraph, config, signal, {
|
|
268
|
+
timeoutMs, ...(dependencies.createAdapter ? { createAdapter: dependencies.createAdapter } : {}),
|
|
269
|
+
...(dependencies.verified ? { verified: dependencies.verified } : {}),
|
|
270
|
+
});
|
|
271
|
+
return { healthy: result.healthy, failures: result.failures.map(failure => ({ ...failure, ...reply })) };
|
|
272
|
+
}
|
|
227
273
|
export function formatGraphHealthFailure(result, remediation = 'Open /graph > Edit Graphs, fix the model selections, then reload the graph to check again.') {
|
|
228
274
|
if (result.healthy)
|
|
229
275
|
return '';
|
|
@@ -79,9 +79,12 @@ export type ManagerEvent = {
|
|
|
79
79
|
} | {
|
|
80
80
|
type: 'state';
|
|
81
81
|
state: ManagerState;
|
|
82
|
-
}
|
|
82
|
+
}
|
|
83
|
+
/** `warning` marks a report that refused nothing: the message it follows was delivered. */
|
|
84
|
+
| {
|
|
83
85
|
type: 'error';
|
|
84
86
|
message: string;
|
|
87
|
+
warning?: true;
|
|
85
88
|
} | {
|
|
86
89
|
type: 'graph.saved';
|
|
87
90
|
graphId: string;
|
|
@@ -92,6 +95,36 @@ export type ManagerEvent = {
|
|
|
92
95
|
| {
|
|
93
96
|
type: 'graph.deleted';
|
|
94
97
|
graphId: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* One change the agent made to its draft of a graph, for the canvas to show as it happens. It is
|
|
101
|
+
* not a save: the draft is saved only by a publish, which asks the user first. Sent live and never
|
|
102
|
+
* kept in the transcript, so a panel that connects later is not handed edits to apply twice.
|
|
103
|
+
*/
|
|
104
|
+
| {
|
|
105
|
+
type: 'graph.edit';
|
|
106
|
+
graphId: string;
|
|
107
|
+
edit: ManagerGraphEdit;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* A draft change in the canvas's own terms: a node or connection set to what the draft now holds
|
|
111
|
+
* (placement and generated ids included), one removed, or graph fields replaced.
|
|
112
|
+
*/
|
|
113
|
+
export type ManagerGraphEdit = {
|
|
114
|
+
kind: 'node';
|
|
115
|
+
node: Record<string, unknown>;
|
|
116
|
+
} | {
|
|
117
|
+
kind: 'node.remove';
|
|
118
|
+
nodeId: string;
|
|
119
|
+
} | {
|
|
120
|
+
kind: 'edge';
|
|
121
|
+
edge: Record<string, unknown>;
|
|
122
|
+
} | {
|
|
123
|
+
kind: 'edge.remove';
|
|
124
|
+
edgeId: string;
|
|
125
|
+
} | {
|
|
126
|
+
kind: 'graph';
|
|
127
|
+
patch: Record<string, unknown>;
|
|
95
128
|
};
|
|
96
129
|
/** A graph's latest stored revision. Deleting a graph publishes one more, marked `metadata.deletedAt`. */
|
|
97
130
|
export interface ManagerGraphRevision {
|
|
@@ -112,6 +145,8 @@ export interface EngineChild {
|
|
|
112
145
|
export interface GraphManagerChatOptions {
|
|
113
146
|
/** The config directory (ANDORRACODE_HOME) the engine runs against. */
|
|
114
147
|
directory: string;
|
|
148
|
+
/** The empty folder the engine starts in. Default `managerWorkspace(directory)`. */
|
|
149
|
+
workspace?: string;
|
|
115
150
|
/** Starts the engine in `cwd`. The default spawns this build's `app-server --stdio`. */
|
|
116
151
|
spawnEngine?: (cwd: string) => EngineChild;
|
|
117
152
|
/** The latest stored revision of a graph and whether it is a deletion, or undefined when it has none. */
|
|
@@ -123,6 +158,12 @@ export interface GraphManagerChatOptions {
|
|
|
123
158
|
}
|
|
124
159
|
/** Mirrors `MAX_TASK_CHARS` in `app-server.ts`: the engine refuses a longer `run.start` task or `run.steer` text. */
|
|
125
160
|
export declare const MANAGER_TASK_MAX_CHARS = 100000;
|
|
161
|
+
/**
|
|
162
|
+
* The change a successful draft call made, read from its reply where the backend decided something
|
|
163
|
+
* (a new card's placement, a connection's generated id) and from its arguments otherwise. Undefined
|
|
164
|
+
* when the reply cannot be read, so the canvas is never shown a guess.
|
|
165
|
+
*/
|
|
166
|
+
export declare function draftEdit(action: string, args: Record<string, unknown>, output: unknown): ManagerGraphEdit | undefined;
|
|
126
167
|
/**
|
|
127
168
|
* One line saying what a tool call or an approval is about, for the tools Graph Manager works with:
|
|
128
169
|
* the `graphs` action and the graph it names, the skill being read, the server being connected.
|
|
@@ -157,6 +198,13 @@ export declare function managerToolParts(name: string, value: unknown, openGraph
|
|
|
157
198
|
* the scope the parent reads.
|
|
158
199
|
*/
|
|
159
200
|
export declare function managerEngineEnvironment(directory: string, environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
201
|
+
/**
|
|
202
|
+
* The empty folder Graph Manager's engine runs in: one per config home, outside it. The config home
|
|
203
|
+
* is protected runtime metadata, so a workspace inside it made every read the agent tried (a Grep, a
|
|
204
|
+
* Glob) ask the user for approval. Outside it, reads run freely in an empty folder and the only
|
|
205
|
+
* prompts left are the ones that change something: publishing, deleting or restoring a graph.
|
|
206
|
+
*/
|
|
207
|
+
export declare function managerWorkspace(directory: string): string;
|
|
160
208
|
/**
|
|
161
209
|
* What the agent is given with every message: which graph is open, the canvas as the user sees it
|
|
162
210
|
* now (unsaved edits included), the model the panel has selected, and the user's own words.
|
|
@@ -167,8 +215,9 @@ export declare function managerTask(turn: ManagerTurn): string;
|
|
|
167
215
|
*
|
|
168
216
|
* The engine that hosts Graph Studio may be busy with the user's task and runs one task at a time,
|
|
169
217
|
* so the chat spawns a dedicated `app-server --stdio` child in an empty workspace and speaks the
|
|
170
|
-
* same line protocol the automation runner does.
|
|
171
|
-
*
|
|
218
|
+
* same line protocol the automation runner does. The graph server keeps one chat per graph, and every
|
|
219
|
+
* panel open on that graph shares it: each subscriber is caught up with a snapshot and then receives
|
|
220
|
+
* the stream.
|
|
172
221
|
*
|
|
173
222
|
* Failures on the engine's side are reported as `error` events rather than rejections, because the
|
|
174
223
|
* message that failed is already on every panel's transcript and the stream is where panels listen.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
3
5
|
import { isAbsolute, join, resolve } from 'node:path';
|
|
4
6
|
import { createInterface } from 'node:readline';
|
|
5
7
|
import { fileURLToPath } from 'node:url';
|
|
@@ -23,6 +25,32 @@ const TOOL_LINE_MAX = 120;
|
|
|
23
25
|
const DRAFTS_MAX = 64;
|
|
24
26
|
/** The bundled preset every installation has. Nothing can be saved under its id. */
|
|
25
27
|
const BUNDLED_GRAPH_ID = 'default';
|
|
28
|
+
/** The draft actions that change what the canvas shows. */
|
|
29
|
+
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']);
|
|
30
|
+
/**
|
|
31
|
+
* The change a successful draft call made, read from its reply where the backend decided something
|
|
32
|
+
* (a new card's placement, a connection's generated id) and from its arguments otherwise. Undefined
|
|
33
|
+
* when the reply cannot be read, so the canvas is never shown a guess.
|
|
34
|
+
*/
|
|
35
|
+
export function draftEdit(action, args, output) {
|
|
36
|
+
let reply = {};
|
|
37
|
+
try {
|
|
38
|
+
reply = record(record(JSON.parse(String(output ?? ''))).data);
|
|
39
|
+
}
|
|
40
|
+
catch { /* A clipped reply has nothing to read. */ }
|
|
41
|
+
const node = record(reply.node), edge = record(reply.edge), patch = record(args.patch);
|
|
42
|
+
if (action === 'andorra_graph_node_upsert' || action === 'andorra_graph_node_patch')
|
|
43
|
+
return typeof node.id === 'string' ? { kind: 'node', node } : undefined;
|
|
44
|
+
if (action === 'andorra_graph_edge_upsert')
|
|
45
|
+
return typeof edge.id === 'string' && typeof edge.source === 'string' && typeof edge.target === 'string' ? { kind: 'edge', edge } : undefined;
|
|
46
|
+
if (action === 'andorra_graph_node_remove')
|
|
47
|
+
return typeof args.nodeId === 'string' && args.nodeId ? { kind: 'node.remove', nodeId: args.nodeId } : undefined;
|
|
48
|
+
if (action === 'andorra_graph_edge_remove')
|
|
49
|
+
return typeof args.edgeId === 'string' && args.edgeId ? { kind: 'edge.remove', edgeId: args.edgeId } : undefined;
|
|
50
|
+
if (action === 'andorra_graph_patch')
|
|
51
|
+
return Object.keys(patch).length ? { kind: 'graph', patch } : undefined;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
26
54
|
/** The engine went away, deliberately or not; whoever stopped it has already said what there is to say. */
|
|
27
55
|
class EngineStopped extends Error {
|
|
28
56
|
}
|
|
@@ -142,6 +170,15 @@ export function managerEngineEnvironment(directory, environment = process.env) {
|
|
|
142
170
|
return worker;
|
|
143
171
|
return { ...worker, ANDORRACODE_HOME: resolve(directory) };
|
|
144
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* The empty folder Graph Manager's engine runs in: one per config home, outside it. The config home
|
|
175
|
+
* is protected runtime metadata, so a workspace inside it made every read the agent tried (a Grep, a
|
|
176
|
+
* Glob) ask the user for approval. Outside it, reads run freely in an empty folder and the only
|
|
177
|
+
* prompts left are the ones that change something: publishing, deleting or restoring a graph.
|
|
178
|
+
*/
|
|
179
|
+
export function managerWorkspace(directory) {
|
|
180
|
+
return join(tmpdir(), 'andorra-graph-manager', createHash('sha256').update(resolve(directory)).digest('hex').slice(0, 16));
|
|
181
|
+
}
|
|
145
182
|
/**
|
|
146
183
|
* What the agent is given with every message: which graph is open, the canvas as the user sees it
|
|
147
184
|
* now (unsaved edits included), the model the panel has selected, and the user's own words.
|
|
@@ -170,8 +207,9 @@ export function managerTask(turn) {
|
|
|
170
207
|
*
|
|
171
208
|
* The engine that hosts Graph Studio may be busy with the user's task and runs one task at a time,
|
|
172
209
|
* so the chat spawns a dedicated `app-server --stdio` child in an empty workspace and speaks the
|
|
173
|
-
* same line protocol the automation runner does.
|
|
174
|
-
*
|
|
210
|
+
* same line protocol the automation runner does. The graph server keeps one chat per graph, and every
|
|
211
|
+
* panel open on that graph shares it: each subscriber is caught up with a snapshot and then receives
|
|
212
|
+
* the stream.
|
|
175
213
|
*
|
|
176
214
|
* Failures on the engine's side are reported as `error` events rather than rejections, because the
|
|
177
215
|
* message that failed is already on every panel's transcript and the stream is where panels listen.
|
|
@@ -224,7 +262,7 @@ export class GraphManagerChat {
|
|
|
224
262
|
this.options = options;
|
|
225
263
|
// Resolved now: the engine is started in another working directory.
|
|
226
264
|
this.directory = resolve(options.directory);
|
|
227
|
-
this.workspace =
|
|
265
|
+
this.workspace = resolve(options.workspace ?? managerWorkspace(this.directory));
|
|
228
266
|
this.idleMs = options.idleMs ?? 600_000;
|
|
229
267
|
this.now = options.now ?? Date.now;
|
|
230
268
|
}
|
|
@@ -349,7 +387,7 @@ export class GraphManagerChat {
|
|
|
349
387
|
try {
|
|
350
388
|
await this.request(engine, 'run.steer', { runId, sessionId: this.sessionId, text: task });
|
|
351
389
|
if (keptModel !== undefined)
|
|
352
|
-
this.emit({ type: 'error', message: `Graph Manager could not switch to ${turn.provider}/${turn.model}, so this run keeps its model: ${keptModel.reason}
|
|
390
|
+
this.emit({ type: 'error', message: `Graph Manager could not switch to ${turn.provider}/${turn.model}, so this run keeps its model: ${keptModel.reason}`, warning: true });
|
|
353
391
|
return;
|
|
354
392
|
}
|
|
355
393
|
catch (error) {
|
|
@@ -698,7 +736,9 @@ export class GraphManagerChat {
|
|
|
698
736
|
const begins = args.action === 'andorra_graph_begin' && typeof input.id === 'string' ? { id: input.id, ...(name ? { name } : {}) } : undefined;
|
|
699
737
|
const publishes = args.action === 'andorra_graph_publish' && typeof input.draftId === 'string' ? this.drafts.get(input.draftId) : undefined;
|
|
700
738
|
const removes = (args.action === 'andorra_graph_delete' || args.action === 'andorra_graph_restore') && typeof input.id === 'string' ? { id: input.id } : undefined;
|
|
701
|
-
|
|
739
|
+
const edited = DRAFT_EDIT_ACTIONS.has(String(args.action)) && typeof input.draftId === 'string' ? this.drafts.get(input.draftId) : undefined;
|
|
740
|
+
const edits = edited ? { graphId: edited.id, action: String(args.action), args: input } : undefined;
|
|
741
|
+
this.graphCalls.set(data.toolCallId, { line, ...(begins ? { begins } : {}), ...(publishes ? { publishes } : {}), ...(removes ? { removes } : {}), ...(edits ? { edits } : {}) });
|
|
702
742
|
}
|
|
703
743
|
}
|
|
704
744
|
else if (event.type === 'node.tool.failed') {
|
|
@@ -720,6 +760,11 @@ export class GraphManagerChat {
|
|
|
720
760
|
if (this.drafts.size > DRAFTS_MAX)
|
|
721
761
|
this.drafts.delete(this.drafts.keys().next().value);
|
|
722
762
|
}
|
|
763
|
+
if (call?.edits) {
|
|
764
|
+
const edit = draftEdit(call.edits.action, call.edits.args, data.output);
|
|
765
|
+
if (edit)
|
|
766
|
+
this.broadcast({ type: 'graph.edit', graphId: call.edits.graphId, edit });
|
|
767
|
+
}
|
|
723
768
|
this.checkRevision(call?.publishes ?? call?.removes);
|
|
724
769
|
}
|
|
725
770
|
}
|
package/dist/src/graph-runner.js
CHANGED
|
@@ -199,6 +199,23 @@ export async function runGraph(graph, options) {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
const budget = createRuntimeBudget(options.context.signal, limits.wallTimeMs, options.context.runControl);
|
|
202
|
+
// A node is handed only the run's remaining time, so its own wall bound is a slice of the run's.
|
|
203
|
+
// When the run's clock is what ran out, the stop names the run's limit: a node that started with a
|
|
204
|
+
// minute left otherwise reports a two-hour run as having "run out of time after about 1 minute".
|
|
205
|
+
// Ownership is decided from what the node was handed when it STARTED, not from the bound its last
|
|
206
|
+
// inner invocation reports: the slice and the run's clock share one deadline, so either timer can
|
|
207
|
+
// be the one that notices, and a node with loop or copy modifiers hands each later pass only the
|
|
208
|
+
// time it has left, so its final slice is smaller than its own limit even when that limit expired.
|
|
209
|
+
const handedWallMs = new Map();
|
|
210
|
+
const runClockBounds = (bounds, reason, nodeId) => {
|
|
211
|
+
if (reason !== 'wallTimeMs')
|
|
212
|
+
return bounds;
|
|
213
|
+
const own = pinned.nodes[nodeId]?.limits?.wallTimeMs || undefined;
|
|
214
|
+
const handed = handedWallMs.get(nodeId);
|
|
215
|
+
if (own !== undefined && (handed === undefined || own <= handed))
|
|
216
|
+
return { ...bounds, wallTimeMs: own };
|
|
217
|
+
return limits.wallTimeMs ? { ...bounds, wallTimeMs: limits.wallTimeMs } : bounds;
|
|
218
|
+
};
|
|
202
219
|
const signal = budget.signal;
|
|
203
220
|
const confirmedClarifications = [];
|
|
204
221
|
// Bind before queueing: the queue must serialize the budget-aware `approve`, or a wait
|
|
@@ -710,6 +727,7 @@ export async function runGraph(graph, options) {
|
|
|
710
727
|
const narrow = (run, remaining) => remaining === undefined ? run : run === undefined ? remaining : Math.min(run, remaining);
|
|
711
728
|
maxToolCalls = narrow(maxToolCalls, continuation?.state.remainingToolCalls);
|
|
712
729
|
wallTimeMs = narrow(wallTimeMs, continuation?.state.remainingWallTimeMs);
|
|
730
|
+
handedWallMs.set(nodeId, wallTimeMs);
|
|
713
731
|
if (wallTimeMs !== undefined && wallTimeMs <= 0)
|
|
714
732
|
return { id: result.id, graph: pinned, provider: result.provider, model: result.model, status: 'exhausted', reason: 'wallTimeMs', toolCalls: 0, usage: { inputTokens: 0, outputTokens: 0, requests: 0 } };
|
|
715
733
|
const branchTodos = new TodoStore();
|
|
@@ -741,7 +759,9 @@ export async function runGraph(graph, options) {
|
|
|
741
759
|
? await readWhileRunning(operationSignal => runMemory.retrieve({ task: memoryTask, nodeId, runId: result.id, signal: operationSignal }))
|
|
742
760
|
: undefined;
|
|
743
761
|
const invocationTools = runMemory ? [...options.tools, memorySearchTool(runMemory, result.id)] : options.tools;
|
|
744
|
-
const
|
|
762
|
+
const projectMemory = options.projectMemory && node.contextPolicy?.projectMemory !== false
|
|
763
|
+
? await readWhileRunning(() => options.projectMemory.context()) : undefined;
|
|
764
|
+
const invocationTask = [options.task, memory?.block, options.commandMemory?.context(), projectMemory].filter(Boolean).join('\n\n');
|
|
745
765
|
const instrument = (provider, resolved) => ({
|
|
746
766
|
...resolved, adapter: dashboardAdapter(resolved.adapter, provider, event => options.onEvent?.(event), { runId: result.id, nodeId, nodeName: node.name, nodeType: node.type }),
|
|
747
767
|
});
|
|
@@ -1005,7 +1025,7 @@ export async function runGraph(graph, options) {
|
|
|
1005
1025
|
result.reason = failed.reason ?? failed.status;
|
|
1006
1026
|
// Report the failing branch's effective bounds, which a node limit can tighten.
|
|
1007
1027
|
if (failed.limits)
|
|
1008
|
-
result.limits = failed.limits;
|
|
1028
|
+
result.limits = runClockBounds(failed.limits, result.reason, failedActivation.nodeId);
|
|
1009
1029
|
break;
|
|
1010
1030
|
}
|
|
1011
1031
|
}
|
|
@@ -1071,7 +1091,7 @@ export async function runGraph(graph, options) {
|
|
|
1071
1091
|
result.reason = cancelled ? 'cancelled' : budget.expired() ? 'wallTimeMs' : outcome.reason ?? outcome.status;
|
|
1072
1092
|
// Report the node's effective bounds, which a node limit can tighten.
|
|
1073
1093
|
if (outcome.limits)
|
|
1074
|
-
result.limits = outcome.limits;
|
|
1094
|
+
result.limits = runClockBounds(outcome.limits, result.reason, nodeId);
|
|
1075
1095
|
break;
|
|
1076
1096
|
}
|
|
1077
1097
|
if (!outcome.completion)
|
|
@@ -14,7 +14,7 @@ export declare function requireGraphProviders(directory?: string): Promise<Confi
|
|
|
14
14
|
export declare function startGraphServer(directory?: string, checkMembership?: () => Promise<unknown>, options?: {
|
|
15
15
|
membership?: () => Promise<Membership>;
|
|
16
16
|
sync?: GraphSync;
|
|
17
|
-
managerChat?: (directory: string) => GraphManagerChatSession;
|
|
17
|
+
managerChat?: (directory: string, graphId: string) => GraphManagerChatSession;
|
|
18
18
|
}): Promise<{
|
|
19
19
|
url: string;
|
|
20
20
|
origin: string;
|
package/dist/src/graph-server.js
CHANGED
|
@@ -30,8 +30,13 @@ import { GraphManagerChat } from './graph-manager-chat.js';
|
|
|
30
30
|
export function readManagerGraphRevision(id, graphDirectory) {
|
|
31
31
|
return loadGraph(id, undefined, graphDirectory).then(graph => ({ revision: graph.revision, deleted: isDeletedGraph(graph) }), () => undefined);
|
|
32
32
|
}
|
|
33
|
+
/** The ids a graph can have in the editor; a Graph Manager conversation is named by one. */
|
|
34
|
+
const MANAGER_GRAPH_ID = /^[\w-]{1,120}$/;
|
|
33
35
|
/** The largest request body the editor accepts for a graph, whether it is being saved or sent to Graph Manager. */
|
|
34
36
|
const GRAPH_BODY_LIMIT = 512 * 1024;
|
|
37
|
+
// The vendor marks the editor's model picker can draw (model-picker.js `logoFor`): the desktop's
|
|
38
|
+
// glyph files (desktop/src/assets/providers/glyphs), which build-assets.mjs copies beside the editor.
|
|
39
|
+
const PROVIDER_GLYPHS = ['alibaba-cloud', 'anthropic', 'aws-bedrock', 'claude', 'deepseek', 'fireworks', 'kimi', 'minimax', 'openai', 'opencode', 'openrouter', 'xai', 'xiaomi-mimo', 'zai'];
|
|
35
40
|
const MANAGER_TOO_LARGE = 'This graph is too large to send to Graph Manager.';
|
|
36
41
|
const MANAGER_PING_MS = 15_000;
|
|
37
42
|
/**
|
|
@@ -132,17 +137,26 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
132
137
|
const token = randomBytes(32).toString('hex');
|
|
133
138
|
// The Graph Manager chat owns a child engine, so it exists only once a panel asks for it. Revisions
|
|
134
139
|
// are read from the folder this account's graphs are saved in, which is where the agent's saves land.
|
|
135
|
-
const createManagerChat = options.managerChat ?? ((home) => new GraphManagerChat({
|
|
140
|
+
const createManagerChat = options.managerChat ?? ((home, _graphId) => new GraphManagerChat({
|
|
136
141
|
directory: home,
|
|
137
142
|
readRevision: id => readManagerGraphRevision(id, graphDirectory),
|
|
138
143
|
}));
|
|
139
|
-
|
|
144
|
+
// Each graph has a conversation of its own, so one graph's requests and edits never reach the
|
|
145
|
+
// agent working on another. A chat's engine stops on its own once nobody is listening to it.
|
|
146
|
+
const managers = new Map();
|
|
140
147
|
let closing = false;
|
|
141
|
-
const managerChat = () => {
|
|
148
|
+
const managerChat = (graph) => {
|
|
142
149
|
// A request that outlives close() must not start an engine nothing would stop.
|
|
143
150
|
if (closing)
|
|
144
151
|
throw new Error('The editor is closing.');
|
|
145
|
-
|
|
152
|
+
if (typeof graph !== 'string' || !MANAGER_GRAPH_ID.test(graph))
|
|
153
|
+
throw new Error('Graph Manager needs the id of the open graph.');
|
|
154
|
+
let chat = managers.get(graph);
|
|
155
|
+
if (!chat) {
|
|
156
|
+
chat = createManagerChat(directory, graph);
|
|
157
|
+
managers.set(graph, chat);
|
|
158
|
+
}
|
|
159
|
+
return chat;
|
|
146
160
|
};
|
|
147
161
|
/** Ends each open Graph Manager stream, so closing the server never waits on one. */
|
|
148
162
|
const managerStreams = new Set();
|
|
@@ -165,6 +179,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
165
179
|
'/icons.js': ['icons.js', 'text/javascript; charset=utf-8'],
|
|
166
180
|
'/controls.js': ['controls.js', 'text/javascript; charset=utf-8'],
|
|
167
181
|
'/skill-picker.js': ['skill-picker.js', 'text/javascript; charset=utf-8'],
|
|
182
|
+
'/model-picker.js': ['model-picker.js', 'text/javascript; charset=utf-8'],
|
|
168
183
|
'/controls.css': ['controls.css', 'text/css; charset=utf-8'],
|
|
169
184
|
'/style.css': ['style.css', 'text/css; charset=utf-8'],
|
|
170
185
|
'/library.css': ['library.css', 'text/css; charset=utf-8'],
|
|
@@ -177,6 +192,10 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
177
192
|
'/fonts/geist-mono-latin-400-normal.woff2': ['fonts/geist-mono-latin-400-normal.woff2', 'font/woff2'],
|
|
178
193
|
'/andorra-logo.png': ['andorra-logo.png', 'image/png'],
|
|
179
194
|
};
|
|
195
|
+
// The provider marks the model picker draws: the desktop's own glyphs, copied beside the editor
|
|
196
|
+
// by build-assets.mjs.
|
|
197
|
+
for (const logo of PROVIDER_GLYPHS)
|
|
198
|
+
assets[`/provider-glyphs/${logo}.png`] = [`provider-glyphs/${logo}.png`, 'image/png'];
|
|
180
199
|
const reply = (res, status, value) => {
|
|
181
200
|
res.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
182
201
|
res.end(JSON.stringify(value));
|
|
@@ -290,7 +309,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
290
309
|
return;
|
|
291
310
|
}
|
|
292
311
|
if (req.method === 'GET' && path === '/api/manager/stream') {
|
|
293
|
-
const chat = managerChat();
|
|
312
|
+
const chat = managerChat(new URL(req.url, origin).searchParams.get('graph'));
|
|
294
313
|
res.writeHead(200, { 'Content-Type': 'text/event-stream; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
295
314
|
res.flushHeaders?.();
|
|
296
315
|
let open = true;
|
|
@@ -329,15 +348,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
329
348
|
// The chat reports what goes wrong on the engine's side as an `error` event on the stream,
|
|
330
349
|
// and a message can take as long as an engine start, so no route waits for its outcome.
|
|
331
350
|
const accepted = (work) => { void work.catch(() => { }); reply(res, 200, { ok: true }); };
|
|
332
|
-
if (action === 'cancel') {
|
|
333
|
-
accepted(managerChat().cancel());
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
if (action === 'reset') {
|
|
337
|
-
accepted(managerChat().reset());
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
if (action === 'message' || action === 'approve' || action === 'answer') {
|
|
351
|
+
if (action === 'cancel' || action === 'reset' || action === 'message' || action === 'approve' || action === 'answer') {
|
|
341
352
|
if (!req.headers['content-type']?.startsWith('application/json')) {
|
|
342
353
|
reply(res, 415, { error: 'Expected application/json' });
|
|
343
354
|
return;
|
|
@@ -349,16 +360,26 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
349
360
|
}
|
|
350
361
|
const parsed = JSON.parse(body.toString('utf8'));
|
|
351
362
|
const value = parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
363
|
+
// Every request names the graph whose conversation it belongs to; a message names it by its canvas.
|
|
364
|
+
const graphId = action === 'message' ? value.graph?.id : value.graphId;
|
|
365
|
+
if (action === 'cancel') {
|
|
366
|
+
accepted(managerChat(graphId).cancel());
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (action === 'reset') {
|
|
370
|
+
accepted(managerChat(graphId).reset());
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
352
373
|
if (action === 'approve') {
|
|
353
374
|
if (!filled(value.id) || typeof value.approved !== 'boolean')
|
|
354
375
|
throw new Error('An approval needs its id and a decision.');
|
|
355
|
-
accepted(managerChat().approve(value.id, value.approved));
|
|
376
|
+
accepted(managerChat(graphId).approve(value.id, value.approved));
|
|
356
377
|
return;
|
|
357
378
|
}
|
|
358
379
|
if (action === 'answer') {
|
|
359
380
|
if (!filled(value.id) || typeof value.value !== 'string')
|
|
360
381
|
throw new Error('An answer needs the question id and a value.');
|
|
361
|
-
accepted(managerChat().answer(value.id, value.value));
|
|
382
|
+
accepted(managerChat(graphId).answer(value.id, value.value));
|
|
362
383
|
return;
|
|
363
384
|
}
|
|
364
385
|
const graph = value.graph;
|
|
@@ -368,7 +389,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
368
389
|
throw new Error('Write a message for Graph Manager.');
|
|
369
390
|
if (graph === null || typeof graph !== 'object' || Array.isArray(graph) || typeof graph.id !== 'string' || typeof graph.name !== 'string')
|
|
370
391
|
throw new Error('A message to Graph Manager needs the open graph.');
|
|
371
|
-
accepted(managerChat().send({
|
|
392
|
+
accepted(managerChat(graphId).send({
|
|
372
393
|
provider: value.provider, model: value.model, text: value.text,
|
|
373
394
|
graph: graph, saved: value.saved === true,
|
|
374
395
|
...(typeof value.revision === 'number' && Number.isInteger(value.revision) && value.revision >= 0 ? { revision: value.revision } : {}),
|
|
@@ -651,7 +672,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
651
672
|
end();
|
|
652
673
|
// The server goes down even when the chat's engine does not stop cleanly.
|
|
653
674
|
try {
|
|
654
|
-
await
|
|
675
|
+
await Promise.all([...managers.values()].map(chat => chat.close()));
|
|
655
676
|
}
|
|
656
677
|
finally {
|
|
657
678
|
await sync?.close();
|