@andorra-labs/code 0.1.8 → 0.1.10
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/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/src/account-presentation.d.ts +11 -0
- package/dist/src/account-presentation.js +29 -2
- package/dist/src/agent-execution.js +57 -4
- package/dist/src/agent-mcp.d.ts +12 -0
- package/dist/src/agent-mcp.js +81 -2
- package/dist/src/app-server/protocol.d.ts +120 -1
- package/dist/src/app-server/protocol.js +8 -1
- package/dist/src/app-server/reasoning.d.ts +0 -8
- package/dist/src/app-server/reasoning.js +15 -28
- package/dist/src/app-server.d.ts +32 -0
- package/dist/src/app-server.js +214 -21
- package/dist/src/auth/AuthManager.d.ts +15 -0
- package/dist/src/auth/AuthManager.js +66 -7
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +17 -1
- package/dist/src/auth/store.js +25 -2
- package/dist/src/browser-runner.js +1 -2
- package/dist/src/browser-server.js +10 -2
- package/dist/src/browser-session.js +6 -2
- package/dist/src/browser-stealth.d.ts +29 -0
- package/dist/src/browser-stealth.js +166 -0
- package/dist/src/browser-ui/app.js +123 -28
- package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
- package/dist/src/browser-ui/index.html +8 -8
- package/dist/src/browser-ui/style.css +199 -171
- package/dist/src/browser-ui/tokens.css +198 -0
- package/dist/src/browser-view.d.ts +57 -9
- package/dist/src/browser-view.js +187 -36
- package/dist/src/cli.js +31 -9
- package/dist/src/coding-tools.js +9 -5
- package/dist/src/command-screens.js +4 -4
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +3 -2
- package/dist/src/completion-gates.d.ts +35 -0
- package/dist/src/completion-gates.js +25 -0
- package/dist/src/completion.d.ts +7 -1
- package/dist/src/completion.js +37 -4
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +2 -2
- package/dist/src/context-budget.d.ts +11 -0
- package/dist/src/context-budget.js +13 -0
- package/dist/src/decision/DecisionEngine.d.ts +5 -1
- package/dist/src/decision/DecisionManager.d.ts +1 -0
- package/dist/src/decision/DecisionManager.js +14 -3
- package/dist/src/decision/FactContinuations.d.ts +6 -0
- package/dist/src/decision/FactContinuations.js +9 -1
- package/dist/src/decision/FactServiceGate.js +1 -1
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/hostedSkills.d.ts +37 -0
- package/dist/src/decision/hostedSkills.js +64 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
- package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
- package/dist/src/default-graph.d.ts +11 -0
- package/dist/src/default-graph.js +20 -0
- package/dist/src/duration.d.ts +13 -2
- package/dist/src/duration.js +27 -3
- package/dist/src/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- package/dist/src/graph-manager-chat.d.ts +302 -0
- package/dist/src/graph-manager-chat.js +940 -0
- package/dist/src/graph-runner.js +6 -0
- package/dist/src/graph-server.d.ts +9 -0
- package/dist/src/graph-server.js +171 -20
- package/dist/src/graph-studio-features.js +2 -2
- package/dist/src/graph-sync.js +5 -2
- package/dist/src/graph-ui/app.js +369 -183
- package/dist/src/graph-ui/controls.css +55 -32
- package/dist/src/graph-ui/controls.js +85 -9
- package/dist/src/graph-ui/edge-router.js +114 -13
- package/dist/src/graph-ui/embed.js +32 -17
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +4 -4
- package/dist/src/graph-ui/library.css +4 -10
- package/dist/src/graph-ui/manager-markdown.js +155 -0
- package/dist/src/graph-ui/manager-state.js +191 -0
- package/dist/src/graph-ui/manager.css +161 -0
- package/dist/src/graph-ui/manager.js +700 -0
- package/dist/src/graph-ui/skill-picker.js +6 -6
- package/dist/src/graph-ui/studio-canvas.js +17 -15
- package/dist/src/graph-ui/studio.css +24 -23
- package/dist/src/graph-ui/studio.js +69 -48
- package/dist/src/graph-ui/style.css +128 -93
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +217 -151
- package/dist/src/graphs.d.ts +76 -2
- package/dist/src/graphs.js +172 -9
- package/dist/src/hardened-runtime.js +8 -2
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- package/dist/src/membership-errors.d.ts +14 -0
- package/dist/src/membership-errors.js +24 -1
- package/dist/src/membership.d.ts +20 -0
- package/dist/src/membership.js +45 -16
- package/dist/src/palette.d.ts +25 -8
- package/dist/src/palette.js +26 -8
- package/dist/src/provider-engine.d.ts +4 -4
- package/dist/src/provider-engine.js +39 -22
- package/dist/src/provider-keys.d.ts +5 -1
- package/dist/src/provider-keys.js +7 -3
- package/dist/src/provider-settings.d.ts +4 -1
- package/dist/src/provider-settings.js +46 -5
- package/dist/src/providers.d.ts +24 -0
- package/dist/src/providers.js +47 -2
- package/dist/src/qa/guidance.d.ts +26 -0
- package/dist/src/qa/guidance.js +46 -0
- package/dist/src/qa/index.d.ts +1 -8
- package/dist/src/qa/index.js +1 -16
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
- package/dist/src/qa/runtime/ProcessManager.js +69 -13
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.d.ts +11 -0
- package/dist/src/react-runtime.js +203 -53
- package/dist/src/remote/engine-pool.js +21 -6
- package/dist/src/run-progress.d.ts +6 -0
- package/dist/src/run-progress.js +7 -0
- package/dist/src/runtime.d.ts +8 -0
- package/dist/src/screen-selection.d.ts +38 -0
- package/dist/src/screen-selection.js +103 -0
- package/dist/src/session-changes.d.ts +117 -0
- package/dist/src/session-changes.js +796 -0
- package/dist/src/session-skills.d.ts +75 -0
- package/dist/src/session-skills.js +151 -0
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +6 -12
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +8 -0
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
- package/dist/src/stall-recovery.d.ts +33 -0
- package/dist/src/stall-recovery.js +83 -0
- package/dist/src/subagent-run.js +1 -2
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +66 -22
- package/dist/src/terminal-ui.js +327 -92
- package/dist/src/tool-diff-stats.d.ts +9 -0
- package/dist/src/tool-diff-stats.js +20 -0
- package/dist/src/tool-names.d.ts +1 -1
- package/dist/src/tool-result-filter.js +1 -1
- package/dist/src/tools.js +26 -2
- package/dist/src/transcript.d.ts +11 -0
- package/dist/src/transcript.js +23 -3
- package/dist/src/types.d.ts +24 -4
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +55 -15
- package/docs/concepts/README.md +1 -1
- package/docs/concepts/limits.md +9 -0
- package/docs/guides/desktop-app.md +1 -1
- package/docs/guides/graph-builder.md +16 -1
- package/docs/guides/tui.md +9 -9
- package/docs/reference/slash-commands.md +2 -1
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
- package/package.json +1 -1
- package/tests/chat-side-panel-test-plan.md +1 -1
- package/dist/src/qa/api/http-runner.d.ts +0 -3
- package/dist/src/qa/api/http-runner.js +0 -47
- package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
- package/dist/src/qa/git/ChangeDetector.js +0 -177
- package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
- package/dist/src/qa/git/DiffReviewer.js +0 -115
- package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
- package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
- package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
- package/dist/src/qa/orchestrator/MergeGate.js +0 -40
- package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
- package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
- package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
- package/dist/src/qa/runners/CommandRunner.js +0 -96
- package/dist/src/qa/runners/TestRunner.d.ts +0 -21
- package/dist/src/qa/runners/TestRunner.js +0 -66
- package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
- package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
- package/dist/src/qa/runtime-detect.d.ts +0 -10
- package/dist/src/qa/runtime-detect.js +0 -72
- package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
- package/dist/src/qa/security/DependencyScanner.js +0 -167
- package/dist/src/qa/security/SecretScanner.d.ts +0 -3
- package/dist/src/qa/security/SecretScanner.js +0 -55
package/dist/src/graph-runner.js
CHANGED
|
@@ -241,6 +241,12 @@ export async function runGraph(graph, options) {
|
|
|
241
241
|
// Skill activation is run-wide and independent of conversation reuse or provider identity.
|
|
242
242
|
// Journal replay restores it before any resumed frontier node starts.
|
|
243
243
|
const activeSkills = new Set(options.resumeFrom?.progress.activeSkills ?? []);
|
|
244
|
+
// A run-level skill the stopped attempt inherited is decided again by this caller: the user may have
|
|
245
|
+
// paused, removed or replaced the session's skill since the stop. Skills a node loaded stay restored.
|
|
246
|
+
for (const skillId of options.resumeFrom?.progress.runSkills ?? []) {
|
|
247
|
+
if (!(options.inheritedSkills ?? []).includes(skillId))
|
|
248
|
+
activeSkills.delete(skillId);
|
|
249
|
+
}
|
|
244
250
|
const queue = [{ nodeId: pinned.entry, generation: 0, path: [], inputs: {}, predecessors: {} }];
|
|
245
251
|
const visits = new Map();
|
|
246
252
|
const executed = new Set();
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { type Config } from './config.js';
|
|
2
2
|
import { type Membership } from './membership.js';
|
|
3
3
|
import { GraphSync } from './graph-sync.js';
|
|
4
|
+
import { GraphManagerChat, type ManagerGraphRevision } from './graph-manager-chat.js';
|
|
5
|
+
/** What the Graph Manager routes need of the chat; a test supplies a stand-in for the engine-backed one. */
|
|
6
|
+
/**
|
|
7
|
+
* What the Graph Manager chat reads after each `graphs` call: the graph's latest stored revision, and
|
|
8
|
+
* whether it is the one a deletion publishes. Undefined for a graph with nothing stored.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readManagerGraphRevision(id: string, graphDirectory: string): Promise<ManagerGraphRevision | undefined>;
|
|
11
|
+
export type GraphManagerChatSession = Pick<GraphManagerChat, 'subscribe' | 'send' | 'approve' | 'answer' | 'cancel' | 'reset' | 'close'>;
|
|
4
12
|
export declare function createGraphSessionCheck(subject: string | undefined, status?: (signal?: AbortSignal) => Promise<import("./auth/types.js").AuthStatus>, membership?: (signal?: AbortSignal, home?: string) => Promise<Membership>): () => Promise<void>;
|
|
5
13
|
export declare function requireGraphProviders(directory?: string): Promise<Config>;
|
|
6
14
|
export declare function startGraphServer(directory?: string, checkMembership?: () => Promise<unknown>, options?: {
|
|
7
15
|
membership?: () => Promise<Membership>;
|
|
8
16
|
sync?: GraphSync;
|
|
17
|
+
managerChat?: (directory: string) => GraphManagerChatSession;
|
|
9
18
|
}): Promise<{
|
|
10
19
|
url: string;
|
|
11
20
|
origin: string;
|
package/dist/src/graph-server.js
CHANGED
|
@@ -6,7 +6,7 @@ import { execFile } from 'node:child_process';
|
|
|
6
6
|
import { changeConfigFile, configDirectory, loadConfig, validateConfig } from './config.js';
|
|
7
7
|
import { stampGraphProviderProfiles } from './graph-provider-portability.js';
|
|
8
8
|
import { resetDeletedGraphSelection } from './graph-selection.js';
|
|
9
|
-
import { listGraphs, loadGraph, saveGraph, validateGraph, migrateGraphForEditor, deleteGraph, withoutDeletedGraphs } from './graphs.js';
|
|
9
|
+
import { listGraphs, loadGraph, saveGraph, validateGraph, migrateGraphForEditor, deleteGraph, isDeletedGraph, withoutDeletedGraphs, GRAPH_MANAGER_GRAPH_ID, reservedGraphId } from './graphs.js';
|
|
10
10
|
import { createTools } from './tools.js';
|
|
11
11
|
import { AutomationStore } from './automations.js';
|
|
12
12
|
import { deleteAgentDefinition, exportAgentDefinition, importAgentDefinition, listAgentDefinitions, readAgentDefinition, saveAgentDefinition, validateAgentDefinition } from './agent-definitions.js';
|
|
@@ -21,6 +21,36 @@ import { graphStorageDirectory } from './graph-account.js';
|
|
|
21
21
|
import { GraphSync } from './graph-sync.js';
|
|
22
22
|
import { editorSkillCatalog } from './skills/invocable-skills.js';
|
|
23
23
|
import { graphRevisionHistory, previewGraphRoutes, studioRuns, studioRunEvents } from './graph-studio-features.js';
|
|
24
|
+
import { GraphManagerChat } from './graph-manager-chat.js';
|
|
25
|
+
/** What the Graph Manager routes need of the chat; a test supplies a stand-in for the engine-backed one. */
|
|
26
|
+
/**
|
|
27
|
+
* What the Graph Manager chat reads after each `graphs` call: the graph's latest stored revision, and
|
|
28
|
+
* whether it is the one a deletion publishes. Undefined for a graph with nothing stored.
|
|
29
|
+
*/
|
|
30
|
+
export function readManagerGraphRevision(id, graphDirectory) {
|
|
31
|
+
return loadGraph(id, undefined, graphDirectory).then(graph => ({ revision: graph.revision, deleted: isDeletedGraph(graph) }), () => undefined);
|
|
32
|
+
}
|
|
33
|
+
/** The largest request body the editor accepts for a graph, whether it is being saved or sent to Graph Manager. */
|
|
34
|
+
const GRAPH_BODY_LIMIT = 512 * 1024;
|
|
35
|
+
const MANAGER_TOO_LARGE = 'This workflow is too large to send to Workflow Manager.';
|
|
36
|
+
const MANAGER_PING_MS = 15_000;
|
|
37
|
+
/**
|
|
38
|
+
* Reads a request body of at most `limit` bytes; undefined when it is larger. An oversized body is
|
|
39
|
+
* read to its end without being kept: leaving the loop early would destroy the request, and the
|
|
40
|
+
* connection with it, before the refusal could be delivered.
|
|
41
|
+
*/
|
|
42
|
+
async function readBody(req, limit) {
|
|
43
|
+
let size = 0;
|
|
44
|
+
let chunks = [];
|
|
45
|
+
for await (const chunk of req) {
|
|
46
|
+
size += chunk.length;
|
|
47
|
+
if (size > limit)
|
|
48
|
+
chunks = undefined;
|
|
49
|
+
chunks?.push(Buffer.from(chunk));
|
|
50
|
+
}
|
|
51
|
+
return chunks && Buffer.concat(chunks);
|
|
52
|
+
}
|
|
53
|
+
const filled = (value) => typeof value === 'string' && value.trim() !== '';
|
|
24
54
|
const setupMessage = 'No providers configured. Run `andorra` and open `/providers` first, then retry `andorra graph`.';
|
|
25
55
|
export function createGraphSessionCheck(subject, status = getAuthStatus, membership = getMembership) {
|
|
26
56
|
let revoked = false;
|
|
@@ -100,6 +130,22 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
100
130
|
};
|
|
101
131
|
await freeTier();
|
|
102
132
|
const token = randomBytes(32).toString('hex');
|
|
133
|
+
// The Graph Manager chat owns a child engine, so it exists only once a panel asks for it. Revisions
|
|
134
|
+
// 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({
|
|
136
|
+
directory: home,
|
|
137
|
+
readRevision: id => readManagerGraphRevision(id, graphDirectory),
|
|
138
|
+
}));
|
|
139
|
+
let manager;
|
|
140
|
+
let closing = false;
|
|
141
|
+
const managerChat = () => {
|
|
142
|
+
// A request that outlives close() must not start an engine nothing would stop.
|
|
143
|
+
if (closing)
|
|
144
|
+
throw new Error('The editor is closing.');
|
|
145
|
+
return manager ??= createManagerChat(directory);
|
|
146
|
+
};
|
|
147
|
+
/** Ends each open Graph Manager stream, so closing the server never waits on one. */
|
|
148
|
+
const managerStreams = new Set();
|
|
103
149
|
let origin = '';
|
|
104
150
|
const assets = {
|
|
105
151
|
'/': ['index.html', 'text/html; charset=utf-8'],
|
|
@@ -111,6 +157,10 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
111
157
|
'/embed.js': ['embed.js', 'text/javascript; charset=utf-8'],
|
|
112
158
|
'/sidebar.js': ['sidebar.js', 'text/javascript; charset=utf-8'],
|
|
113
159
|
'/drafts.js': ['drafts.js', 'text/javascript; charset=utf-8'],
|
|
160
|
+
'/manager-markdown.js': ['manager-markdown.js', 'text/javascript; charset=utf-8'],
|
|
161
|
+
'/manager-state.js': ['manager-state.js', 'text/javascript; charset=utf-8'],
|
|
162
|
+
'/manager.js': ['manager.js', 'text/javascript; charset=utf-8'],
|
|
163
|
+
'/manager.css': ['manager.css', 'text/css; charset=utf-8'],
|
|
114
164
|
'/edge-router.js': ['edge-router.js', 'text/javascript; charset=utf-8'],
|
|
115
165
|
'/icons.js': ['icons.js', 'text/javascript; charset=utf-8'],
|
|
116
166
|
'/controls.js': ['controls.js', 'text/javascript; charset=utf-8'],
|
|
@@ -168,9 +218,9 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
168
218
|
if (path.startsWith('/api/')) {
|
|
169
219
|
const expected = Buffer.from(`Bearer ${token}`);
|
|
170
220
|
const authorized = (value) => { const supplied = Buffer.from(value); return supplied.length === expected.length && timingSafeEqual(supplied, expected); };
|
|
171
|
-
// EventSource cannot send an Authorization header, so the
|
|
172
|
-
//
|
|
173
|
-
const streamQuery = path === '/api/activity/stream' ? `Bearer ${new URL(req.url, origin).searchParams.get('token') ?? ''}` : undefined;
|
|
221
|
+
// EventSource cannot send an Authorization header, so the two event streams alone also
|
|
222
|
+
// accept the session token in the query string.
|
|
223
|
+
const streamQuery = path === '/api/activity/stream' || path === '/api/manager/stream' ? `Bearer ${new URL(req.url, origin).searchParams.get('token') ?? ''}` : undefined;
|
|
174
224
|
if (!authorized(req.headers.authorization ?? '') && !(streamQuery !== undefined && authorized(streamQuery))) {
|
|
175
225
|
reply(res, 401, { error: 'Reopen the editor using andorra graph.' });
|
|
176
226
|
return;
|
|
@@ -239,6 +289,93 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
239
289
|
await push();
|
|
240
290
|
return;
|
|
241
291
|
}
|
|
292
|
+
if (req.method === 'GET' && path === '/api/manager/stream') {
|
|
293
|
+
const chat = managerChat();
|
|
294
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
295
|
+
res.flushHeaders?.();
|
|
296
|
+
let open = true;
|
|
297
|
+
let unsubscribe = () => { };
|
|
298
|
+
const finish = () => {
|
|
299
|
+
if (!open)
|
|
300
|
+
return;
|
|
301
|
+
open = false;
|
|
302
|
+
clearInterval(timer);
|
|
303
|
+
managerStreams.delete(end);
|
|
304
|
+
unsubscribe();
|
|
305
|
+
};
|
|
306
|
+
const end = () => { finish(); try {
|
|
307
|
+
res.end();
|
|
308
|
+
}
|
|
309
|
+
catch { /* The socket is already gone. */ } };
|
|
310
|
+
const timer = setInterval(() => {
|
|
311
|
+
// Logout or a membership downgrade revokes an open stream like any other editor request.
|
|
312
|
+
void (async () => { if (sync?.accessDenied)
|
|
313
|
+
throw new PaidMembershipRequiredError(); await checkSession(); })()
|
|
314
|
+
.then(() => { if (open && !res.destroyed)
|
|
315
|
+
res.write(': ping\n\n'); }, end);
|
|
316
|
+
}, MANAGER_PING_MS);
|
|
317
|
+
managerStreams.add(end);
|
|
318
|
+
req.on('close', finish);
|
|
319
|
+
res.on('close', finish);
|
|
320
|
+
// The chat hands over the conversation so far as a snapshot before anything else.
|
|
321
|
+
unsubscribe = chat.subscribe(event => { if (open && !res.destroyed)
|
|
322
|
+
res.write(`data: ${JSON.stringify(event)}\n\n`); });
|
|
323
|
+
if (!open)
|
|
324
|
+
unsubscribe();
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (req.method === 'POST' && path.startsWith('/api/manager/')) {
|
|
328
|
+
const action = path.slice('/api/manager/'.length);
|
|
329
|
+
// The chat reports what goes wrong on the engine's side as an `error` event on the stream,
|
|
330
|
+
// and a message can take as long as an engine start, so no route waits for its outcome.
|
|
331
|
+
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') {
|
|
341
|
+
if (!req.headers['content-type']?.startsWith('application/json')) {
|
|
342
|
+
reply(res, 415, { error: 'Expected application/json' });
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const body = await readBody(req, GRAPH_BODY_LIMIT);
|
|
346
|
+
if (!body) {
|
|
347
|
+
reply(res, 413, { error: MANAGER_TOO_LARGE });
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const parsed = JSON.parse(body.toString('utf8'));
|
|
351
|
+
const value = parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
352
|
+
if (action === 'approve') {
|
|
353
|
+
if (!filled(value.id) || typeof value.approved !== 'boolean')
|
|
354
|
+
throw new Error('An approval needs its id and a decision.');
|
|
355
|
+
accepted(managerChat().approve(value.id, value.approved));
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (action === 'answer') {
|
|
359
|
+
if (!filled(value.id) || typeof value.value !== 'string')
|
|
360
|
+
throw new Error('An answer needs the question id and a value.');
|
|
361
|
+
accepted(managerChat().answer(value.id, value.value));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const graph = value.graph;
|
|
365
|
+
if (!filled(value.provider) || !filled(value.model))
|
|
366
|
+
throw new Error('Choose a model for Workflow Manager.');
|
|
367
|
+
if (!filled(value.text))
|
|
368
|
+
throw new Error('Write a message for Workflow Manager.');
|
|
369
|
+
if (graph === null || typeof graph !== 'object' || Array.isArray(graph) || typeof graph.id !== 'string' || typeof graph.name !== 'string')
|
|
370
|
+
throw new Error('A message to Workflow Manager needs the open workflow.');
|
|
371
|
+
accepted(managerChat().send({
|
|
372
|
+
provider: value.provider, model: value.model, text: value.text,
|
|
373
|
+
graph: graph, saved: value.saved === true,
|
|
374
|
+
...(typeof value.revision === 'number' && Number.isInteger(value.revision) && value.revision >= 0 ? { revision: value.revision } : {}),
|
|
375
|
+
}));
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
242
379
|
const config = await editorConfig(directory);
|
|
243
380
|
if (req.method === 'GET' && path === '/api/sync') {
|
|
244
381
|
reply(res, 200, sync?.status ?? { state: 'pending', detail: 'Saved locally' });
|
|
@@ -328,7 +465,7 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
328
465
|
const graphs = [];
|
|
329
466
|
const graphMigrationErrors = [];
|
|
330
467
|
const savedGraphs = await listGraphs(graphDirectory, (id, error) => {
|
|
331
|
-
graphMigrationErrors.push({ id, name: id, error: error instanceof Error ? error.message : '
|
|
468
|
+
graphMigrationErrors.push({ id, name: id, error: error instanceof Error ? error.message : 'Workflow load failed' });
|
|
332
469
|
});
|
|
333
470
|
const free = await freeTier();
|
|
334
471
|
// Deleted graphs stay out of the editor; restoring one goes through the graph MCP server.
|
|
@@ -383,7 +520,11 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
383
520
|
// The preset is bundled with the CLI: it has no storage to remove, and hiding it would
|
|
384
521
|
// only last until the next launch.
|
|
385
522
|
if (id === 'default') {
|
|
386
|
-
reply(res, 400, { error: 'The bundled default
|
|
523
|
+
reply(res, 400, { error: 'The bundled default workflow cannot be deleted.' });
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (id === GRAPH_MANAGER_GRAPH_ID) {
|
|
527
|
+
reply(res, 400, { error: reservedGraphId(id).message });
|
|
387
528
|
return;
|
|
388
529
|
}
|
|
389
530
|
// forgetGraph schedules the post-delete sync pass itself; scheduling another here
|
|
@@ -407,17 +548,12 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
407
548
|
reply(res, 415, { error: 'Expected application/json' });
|
|
408
549
|
return;
|
|
409
550
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
if (size > 512 * 1024) {
|
|
415
|
-
reply(res, 413, { error: 'Graph exceeds 512 KiB' });
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
chunks.push(Buffer.from(chunk));
|
|
551
|
+
const body = await readBody(req, GRAPH_BODY_LIMIT);
|
|
552
|
+
if (!body) {
|
|
553
|
+
reply(res, 413, { error: 'Workflow exceeds 512 KiB' });
|
|
554
|
+
return;
|
|
419
555
|
}
|
|
420
|
-
const value = JSON.parse(
|
|
556
|
+
const value = JSON.parse(body.toString('utf8'));
|
|
421
557
|
// The deletion marker is set only through the graph MCP server's delete tool, which confirms
|
|
422
558
|
// with the person and checks automations first; an ordinary save may not carry it.
|
|
423
559
|
if (path === '/api/graphs' && value && typeof value === 'object' && value.metadata && typeof value.metadata === 'object' && Object.hasOwn(value.metadata, 'deletedAt')) {
|
|
@@ -468,8 +604,8 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
468
604
|
}
|
|
469
605
|
// Stamping can add profile entries after the streamed body already passed the limit.
|
|
470
606
|
const stamped = stampGraphProviderProfiles(graph, config);
|
|
471
|
-
if (Buffer.byteLength(JSON.stringify(stamped)) >
|
|
472
|
-
reply(res, 413, { error: '
|
|
607
|
+
if (Buffer.byteLength(JSON.stringify(stamped)) > GRAPH_BODY_LIMIT) {
|
|
608
|
+
reply(res, 413, { error: 'Workflow exceeds 512 KiB' });
|
|
473
609
|
return;
|
|
474
610
|
}
|
|
475
611
|
const expected = graph.revision === 0 ? null : graph.revision;
|
|
@@ -509,7 +645,19 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
509
645
|
if (!address || typeof address === 'string')
|
|
510
646
|
throw new Error('Unable to bind graph server');
|
|
511
647
|
origin = `http://127.0.0.1:${address.port}`;
|
|
512
|
-
return { url: `${origin}/#token=${token}`, origin, token, close: async () => {
|
|
648
|
+
return { url: `${origin}/#token=${token}`, origin, token, close: async () => {
|
|
649
|
+
closing = true;
|
|
650
|
+
for (const end of [...managerStreams])
|
|
651
|
+
end();
|
|
652
|
+
// The server goes down even when the chat's engine does not stop cleanly.
|
|
653
|
+
try {
|
|
654
|
+
await manager?.close();
|
|
655
|
+
}
|
|
656
|
+
finally {
|
|
657
|
+
await sync?.close();
|
|
658
|
+
await new Promise((resolve, reject) => { server.closeAllConnections(); server.close(error => error ? reject(error) : resolve()); });
|
|
659
|
+
}
|
|
660
|
+
} };
|
|
513
661
|
}
|
|
514
662
|
/**
|
|
515
663
|
* Reset the configured selection only after the deletion succeeds. Otherwise a graph-lock
|
|
@@ -517,11 +665,14 @@ export async function startGraphServer(directory = configDirectory(), checkMembe
|
|
|
517
665
|
* between removal and reset is handled by the CLI's missing-selection fallback.
|
|
518
666
|
*/
|
|
519
667
|
export async function deleteGraphWithTombstone(id, graphDirectory, directory, subject, sync) {
|
|
668
|
+
// The signed-in path never reaches deleteGraph, so the built-in graph is refused here for both.
|
|
669
|
+
if (id === GRAPH_MANAGER_GRAPH_ID)
|
|
670
|
+
throw reservedGraphId(id);
|
|
520
671
|
// An automation would fail at its next run; the user decides what it runs instead. The graph
|
|
521
672
|
// MCP server's delete tool applies the same check, so the editor cannot bypass it.
|
|
522
673
|
const users = (await new AutomationStore(directory).list()).filter(job => job.execution?.graph === id);
|
|
523
674
|
if (users.length)
|
|
524
|
-
throw new Error('
|
|
675
|
+
throw new Error('Workflow ' + id + ' is run by automation'
|
|
525
676
|
+ (users.length === 1 ? ' ' : 's ') + users.map(job => '"' + job.name + '"').join(', ')
|
|
526
677
|
+ '. Change or remove ' + (users.length === 1 ? 'it' : 'them') + ' first.');
|
|
527
678
|
if (sync) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readdir, readFile, open, stat } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_GRAPH, loadGraph } from './graphs.js';
|
|
4
4
|
import { runRecordsDirectory, runRecordPath } from './run-records.js';
|
|
5
5
|
/** A conservative connectivity walkthrough, not a substitute for a real Agent/Join/Loop run. */
|
|
6
6
|
export function previewGraphRoutes(graph, choices = {}) {
|
|
@@ -120,7 +120,7 @@ export async function graphRevisionHistory(id, directory) {
|
|
|
120
120
|
safeId(id);
|
|
121
121
|
let revisions;
|
|
122
122
|
if (id === 'default')
|
|
123
|
-
revisions = Array.from({ length:
|
|
123
|
+
revisions = Array.from({ length: DEFAULT_GRAPH.revision }, (_, index) => DEFAULT_GRAPH.revision - index);
|
|
124
124
|
else {
|
|
125
125
|
// A new/imported draft has no saved revision directory yet.
|
|
126
126
|
let filenames;
|
package/dist/src/graph-sync.js
CHANGED
|
@@ -4,7 +4,7 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
4
4
|
import { join, relative } from 'node:path';
|
|
5
5
|
import { AUTH_REFRESH_BUDGET_MS, getAccessToken, getAuthConfiguration, getAuthStatus } from './auth/index.js';
|
|
6
6
|
import { decodeJwt } from 'jose';
|
|
7
|
-
import { GraphConflictError, restoreGraphRevision, validateGraph } from './graphs.js';
|
|
7
|
+
import { GRAPH_MANAGER_GRAPH_ID, GraphConflictError, reservedGraphId, restoreGraphRevision, validateGraph } from './graphs.js';
|
|
8
8
|
import { acquireSaveLock, removeLockedFolder, SaveLockBusyError } from './save-lock.js';
|
|
9
9
|
import { readGraphQuota } from './graph-quota.js';
|
|
10
10
|
const MAX_BYTES = 600 * 1024;
|
|
@@ -367,6 +367,9 @@ export class GraphSync {
|
|
|
367
367
|
async forgetGraph(id) {
|
|
368
368
|
if (!safeId(id) || id === 'default')
|
|
369
369
|
throw new Error('Invalid graph id');
|
|
370
|
+
// Built in: there is no stored graph to remove, and a tombstone would outlive a delete that removed nothing.
|
|
371
|
+
if (id === GRAPH_MANAGER_GRAPH_ID)
|
|
372
|
+
throw reservedGraphId(id);
|
|
370
373
|
await mkdir(this.folder, { recursive: true });
|
|
371
374
|
const folder = join(this.directory, 'graphs', id);
|
|
372
375
|
let release;
|
|
@@ -458,7 +461,7 @@ export class GraphSync {
|
|
|
458
461
|
* the replacement's latest pointer.
|
|
459
462
|
*/
|
|
460
463
|
async reviveGraph(id) {
|
|
461
|
-
if (!safeId(id) || id === 'default')
|
|
464
|
+
if (!safeId(id) || id === 'default' || id === GRAPH_MANAGER_GRAPH_ID)
|
|
462
465
|
return;
|
|
463
466
|
// A slow draft prune can hold the account lock past the normal two-second budget.
|
|
464
467
|
// A successful save must not return while its tombstone remains: keep retrying the
|