@andorra-labs/code 0.1.10 → 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 +31 -205
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/dist/src/agent-execution.js +50 -2
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +9 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +49 -1
- package/dist/src/app-server.js +353 -64
- package/dist/src/automation-service.js +1 -1
- 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-session.d.ts +8 -0
- package/dist/src/browser-session.js +27 -1
- package/dist/src/browser-ui/app.js +237 -15
- package/dist/src/browser-ui/index.html +5 -5
- package/dist/src/browser-ui/style.css +110 -65
- package/dist/src/browser-ui/tokens.css +27 -26
- 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 +26 -1
- package/dist/src/coding-tools.js +104 -33
- package/dist/src/command-screens.js +1 -1
- package/dist/src/commands.js +1 -1
- package/dist/src/completion-gates.d.ts +42 -7
- package/dist/src/completion-gates.js +55 -9
- package/dist/src/completion.d.ts +51 -1
- package/dist/src/completion.js +164 -5
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/dashboard-view.js +2 -2
- package/dist/src/deadline.js +4 -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 +62 -17
- package/dist/src/graph-runner.js +62 -5
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +48 -27
- package/dist/src/graph-sync.d.ts +8 -0
- package/dist/src/graph-sync.js +54 -3
- package/dist/src/graph-tool.js +1 -1
- package/dist/src/graph-ui/app.js +362 -123
- package/dist/src/graph-ui/controls.css +95 -22
- package/dist/src/graph-ui/controls.js +31 -1
- package/dist/src/graph-ui/embed.js +62 -13
- package/dist/src/graph-ui/icons.js +7 -0
- package/dist/src/graph-ui/index.html +4 -4
- package/dist/src/graph-ui/manager-state.js +143 -5
- package/dist/src/graph-ui/manager.css +21 -20
- package/dist/src/graph-ui/manager.js +337 -75
- 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/graph-ui/skill-picker.js +1 -1
- package/dist/src/graph-ui/studio-canvas.js +8 -8
- package/dist/src/graph-ui/studio.css +18 -15
- package/dist/src/graph-ui/studio.js +92 -35
- package/dist/src/graph-ui/style.css +122 -79
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +33 -29
- package/dist/src/graphs.d.ts +5 -2
- package/dist/src/graphs.js +10 -9
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- package/dist/src/membership-errors.d.ts +7 -1
- package/dist/src/membership-errors.js +9 -3
- 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/pull-requests.d.ts +42 -6
- package/dist/src/pull-requests.js +11 -3
- package/dist/src/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +137 -22
- package/dist/src/read-document-doc.d.ts +20 -0
- package/dist/src/read-document-doc.js +524 -0
- package/dist/src/read-document-docx.d.ts +21 -0
- package/dist/src/read-document-docx.js +584 -0
- package/dist/src/read-document-text.d.ts +29 -0
- package/dist/src/read-document-text.js +67 -0
- package/dist/src/read-document-tool.d.ts +48 -0
- package/dist/src/read-document-tool.js +162 -0
- package/dist/src/read-document.d.ts +78 -0
- package/dist/src/read-document.js +353 -0
- package/dist/src/read-image.d.ts +29 -2
- package/dist/src/read-image.js +42 -17
- 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 +21 -0
- package/dist/src/runtime.js +10 -1
- package/dist/src/session-changes.d.ts +6 -1
- package/dist/src/session-changes.js +13 -5
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- package/dist/src/side-panel.d.ts +6 -1
- package/dist/src/side-panel.js +12 -10
- 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/create-skill/SKILL.md +1 -1
- package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +59 -7
- package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
- package/dist/src/skills/bundled/provenance.json +4 -4
- package/dist/src/skills/runtime-skills.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +16 -3
- package/dist/src/stall-recovery.d.ts +6 -2
- package/dist/src/stall-recovery.js +7 -2
- 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 +11 -5
- package/dist/src/time-limit.d.ts +53 -0
- package/dist/src/time-limit.js +79 -0
- 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/tools.js +92 -7
- package/dist/src/transcript.d.ts +5 -0
- package/dist/src/transcript.js +12 -4
- package/dist/src/types.d.ts +8 -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/usage-analytics.d.ts +3 -1
- package/dist/src/usage-analytics.js +16 -2
- 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 +6 -26
- package/docs/README.md +0 -36
- package/docs/agents/README.md +0 -62
- package/docs/agents/install-for-agents.md +0 -56
- package/docs/agents/mcp-server.md +0 -212
- package/docs/agents/subagent-mode.md +0 -149
- package/docs/concepts/README.md +0 -47
- package/docs/concepts/jev-actionable-routing.md +0 -113
- package/docs/concepts/jev-decision-thresholds.md +0 -412
- package/docs/concepts/jev-efficiency.md +0 -217
- package/docs/concepts/jev-eval-2026-11-01.md +0 -78
- package/docs/concepts/limits.md +0 -52
- package/docs/concepts/memory.md +0 -10
- package/docs/concepts/security.md +0 -50
- package/docs/concepts/workspace-instructions.md +0 -29
- package/docs/getting-started/README.md +0 -82
- package/docs/getting-started/accounts.md +0 -78
- package/docs/getting-started/configure-providers.md +0 -132
- package/docs/guides/README.md +0 -13
- package/docs/guides/browser.md +0 -39
- package/docs/guides/desktop-app.md +0 -414
- package/docs/guides/extensions.md +0 -102
- package/docs/guides/graph-builder.md +0 -116
- package/docs/guides/headless.md +0 -46
- package/docs/guides/tui.md +0 -75
- package/docs/guides/update.md +0 -70
- package/docs/guides/web-search.md +0 -51
- package/docs/guides/windows-code-signing.md +0 -319
- package/docs/llms.txt +0 -45
- package/docs/reference/README.md +0 -7
- package/docs/reference/cli.md +0 -76
- package/docs/reference/config.md +0 -91
- package/docs/reference/slash-commands.md +0 -59
- package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
- package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
- package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
- package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
- package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
- package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
- package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
- package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
- package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
- package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
- package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
- package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
- package/scripts/jev-efficiency-eval.mjs +0 -187
- package/scripts/jev-efficiency-live.mjs +0 -193
- package/scripts/zcode-engine-replay.mjs +0 -223
- package/tests/agent-centric-mcp-test-plan.md +0 -208
- package/tests/analytics-settings-test-plan.md +0 -165
- package/tests/browser-cli-smoke.mjs +0 -276
- package/tests/browser-test-plan.md +0 -280
- package/tests/chat-side-panel-test-plan.md +0 -309
- package/tests/decision-engine-test-plan.md +0 -163
- package/tests/default-active-jev-test-plan.md +0 -85
- package/tests/harness-extensions-test-plan.md +0 -113
- package/tests/jev-all-decisions-test-plan.md +0 -156
- package/tests/jev-efficiency/criteria.json +0 -158
- package/tests/jev-efficiency/workloads.mjs +0 -242
- package/tests/jev-efficiency-test-plan.md +0 -198
- package/tests/permissions-sandbox-probe.mjs +0 -74
- package/tests/permissions-test-plan.md +0 -191
- package/tests/product-telemetry-test-plan.md +0 -536
- package/tests/thinking-stream-preview-test-plan.md +0 -136
- package/tests/zcode-react-engine-test-plan.md +0 -396
|
@@ -6,7 +6,7 @@ globalThis.AndorraManager = (() => {
|
|
|
6
6
|
const byId = id => document.getElementById(id);
|
|
7
7
|
const button = byId('graph-manager'), tip = byId('manager-tip'), panel = byId('manager-panel');
|
|
8
8
|
if (!logic || !button || !tip || !panel) return undefined;
|
|
9
|
-
const
|
|
9
|
+
const modelsSlot = byId('manager-models');
|
|
10
10
|
const notices = byId('manager-notices'), log = byId('manager-transcript'), input = byId('manager-input');
|
|
11
11
|
const sendButton = byId('manager-send'), stopButton = byId('manager-stop'), runLabel = byId('manager-run-state');
|
|
12
12
|
|
|
@@ -23,9 +23,11 @@ globalThis.AndorraManager = (() => {
|
|
|
23
23
|
/** The engine's run state, read from `state` events and each snapshot; the transcript does not keep it. */
|
|
24
24
|
let runState = 'idle';
|
|
25
25
|
let source = null, retryTimer = null, retryMs = 1000, connected = false;
|
|
26
|
+
/** The graph whose conversation the stream follows. Each graph has its own; switching graphs switches it. */
|
|
27
|
+
let streamGraphId = null;
|
|
26
28
|
/** The canvas of the latest message the chat took, as JSON; what the agent's save is compared against. */
|
|
27
29
|
let sentCanvas = null;
|
|
28
|
-
/** The graph the conversation is about,
|
|
30
|
+
/** The graph the conversation is about: the open one, since every graph has its own conversation. */
|
|
29
31
|
let chatGraphId = null;
|
|
30
32
|
/** Messages posted and not yet echoed by the stream, oldest first: { text, canvas, graphId }. */
|
|
31
33
|
let posted = [];
|
|
@@ -33,6 +35,36 @@ globalThis.AndorraManager = (() => {
|
|
|
33
35
|
let beforeLastMessage = null;
|
|
34
36
|
/** A message sent into a working run changed the canvas: the agent's next save may predate it, so it is offered. */
|
|
35
37
|
let unsureCanvas = false;
|
|
38
|
+
/**
|
|
39
|
+
* What a live draft change is merged against, so edits the user made since win: the canvas of the
|
|
40
|
+
* latest message the chat accepted (JSON), updated by the agent's own version of each node it then
|
|
41
|
+
* changed and of each graph field it patched. A newly accepted message rebases all of it: what it
|
|
42
|
+
* carried is shared with the agent from then on, so the agent's next change of it is taken.
|
|
43
|
+
*/
|
|
44
|
+
let mergeCanvas = null;
|
|
45
|
+
/** The agent's latest version of each connection it set, as JSON, like `agentNodes`. */
|
|
46
|
+
const agentEdges = new Map();
|
|
47
|
+
/** The latest user message this panel has seen in its conversation, to tell a reconnect from a conversation that moved on. */
|
|
48
|
+
let latestUserSeen = null;
|
|
49
|
+
const agentNodes = new Map();
|
|
50
|
+
let agentFields = {};
|
|
51
|
+
function rebase(canvas) {
|
|
52
|
+
mergeCanvas = canvas;
|
|
53
|
+
agentNodes.clear(); agentEdges.clear(); agentFields = {};
|
|
54
|
+
}
|
|
55
|
+
/** The merge state before the latest accepted message, restored if the chat refuses that message. */
|
|
56
|
+
let mergeBeforeMessage = null;
|
|
57
|
+
function mergeState() {
|
|
58
|
+
return { mergeCanvas, nodes: new Map(agentNodes), edges: new Map(agentEdges), fields: { ...agentFields } };
|
|
59
|
+
}
|
|
60
|
+
function restoreMerge(saved) {
|
|
61
|
+
mergeCanvas = saved.mergeCanvas;
|
|
62
|
+
agentNodes.clear(); for (const [key, value] of saved.nodes) agentNodes.set(key, value);
|
|
63
|
+
agentEdges.clear(); for (const [key, value] of saved.edges) agentEdges.set(key, value);
|
|
64
|
+
agentFields = { ...saved.fields };
|
|
65
|
+
}
|
|
66
|
+
/** Draft changes that arrived while the user was typing in the editor, applied once they leave the field. */
|
|
67
|
+
let deferredEdits = [];
|
|
36
68
|
let shownGraphId = null;
|
|
37
69
|
let choice;
|
|
38
70
|
let providersSeen = '';
|
|
@@ -40,8 +72,6 @@ globalThis.AndorraManager = (() => {
|
|
|
40
72
|
let offeredRevision = null;
|
|
41
73
|
/** A graph the agent created beside the bundled preset, which it cannot change: { id, label }. Opened only on click. */
|
|
42
74
|
let createdOffer = null;
|
|
43
|
-
/** The graph the user moved to while a conversation about another one is open. */
|
|
44
|
-
let switchOffer = null;
|
|
45
75
|
let localError = '';
|
|
46
76
|
/** What this panel answered each approval with, to label the closed card. */
|
|
47
77
|
const decisions = new Map();
|
|
@@ -75,14 +105,28 @@ globalThis.AndorraManager = (() => {
|
|
|
75
105
|
if (graph.id !== shownGraphId) {
|
|
76
106
|
shownGraphId = graph.id;
|
|
77
107
|
hideTip();
|
|
78
|
-
|
|
79
|
-
createdOffer = null;
|
|
80
|
-
switchOffer = chatGraphId && chatGraphId !== graph.id && transcript.length ? graph.id : null;
|
|
81
|
-
renderNotices();
|
|
108
|
+
switchConversation(graph.id);
|
|
82
109
|
}
|
|
83
110
|
if (open) fillModels();
|
|
84
111
|
}
|
|
85
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Another graph is open: the panel leaves the last graph's conversation, which carries on without
|
|
115
|
+
* it, and follows this graph's own. Nothing of one graph's chat is shown beside another.
|
|
116
|
+
*/
|
|
117
|
+
function switchConversation(graphId) {
|
|
118
|
+
disconnect();
|
|
119
|
+
streamGraphId = graphId;
|
|
120
|
+
chatGraphId = graphId;
|
|
121
|
+
transcript = []; runState = 'idle';
|
|
122
|
+
posted = []; sentCanvas = null; beforeLastMessage = null; unsureCanvas = false;
|
|
123
|
+
offeredRevision = null; createdOffer = null; localError = '';
|
|
124
|
+
decisions.clear(); answering.clear(); openRows.clear();
|
|
125
|
+
rebase(null); latestUserSeen = null; mergeBeforeMessage = null; deferredEdits = [];
|
|
126
|
+
rendered = [];
|
|
127
|
+
if (open) { connect(); render(); }
|
|
128
|
+
}
|
|
129
|
+
|
|
86
130
|
function graphOpened(reason) {
|
|
87
131
|
heading();
|
|
88
132
|
if (!open && state.graph && logic.shouldShowTip(storage(), reason)) tip.hidden = false;
|
|
@@ -118,47 +162,44 @@ globalThis.AndorraManager = (() => {
|
|
|
118
162
|
const modelsOf = provider => [...new Set([provider.model, ...(provider.models || [])].filter(Boolean))];
|
|
119
163
|
const providerOf = id => state.providers.find(entry => entry.id === id);
|
|
120
164
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
165
|
+
const entryOf = provider => ({ id: provider.id, label: titleFor(provider), type: provider.type, baseUrl: provider.baseUrl });
|
|
166
|
+
// The chat's model picker: every configured provider's models grouped under its name. Graph
|
|
167
|
+
// Manager always runs a named pair, so there is no default row.
|
|
168
|
+
const picker = typeof modelPickerButton === 'function' ? modelPickerButton({
|
|
169
|
+
ariaLabel: 'Graph Manager model',
|
|
170
|
+
current: () => {
|
|
171
|
+
const provider = choice && providerOf(choice.provider);
|
|
172
|
+
return { model: choice?.model || 'No model available', provider: provider ? titleFor(provider) : '', entry: provider ? entryOf(provider) : undefined };
|
|
173
|
+
},
|
|
174
|
+
groups: () => state.providers.map(provider => ({ provider: entryOf(provider), models: modelsOf(provider).map(model => ({ model, note: '' })) })),
|
|
175
|
+
selected: () => choice,
|
|
176
|
+
pick: next => {
|
|
177
|
+
if (!providerOf(next.provider) || !next.model) return;
|
|
178
|
+
choice = { provider: next.provider, model: next.model };
|
|
179
|
+
logic.rememberModel(storage(), choice);
|
|
180
|
+
picker.redraw();
|
|
181
|
+
},
|
|
182
|
+
}) : null;
|
|
183
|
+
if (picker) { picker.id = 'manager-model-picker'; modelsSlot?.append(picker); }
|
|
184
|
+
|
|
185
|
+
/** Fills the picker from the editor's provider registry, keeping the choice while it is still offered. */
|
|
124
186
|
function fillModels() {
|
|
125
187
|
const signature = JSON.stringify(state.providers);
|
|
126
188
|
if (signature === providersSeen && choice) return;
|
|
127
189
|
providersSeen = signature;
|
|
128
190
|
const kept = choice && modelsOf(providerOf(choice.provider) || {}).includes(choice.model);
|
|
129
191
|
if (!kept) choice = logic.initialModel(storage(), state.graph, state.providers);
|
|
130
|
-
|
|
131
|
-
providerSelect.disabled = modelSelect.disabled = !choice;
|
|
132
|
-
if (choice) providerSelect.value = choice.provider;
|
|
133
|
-
fillModelOptions();
|
|
192
|
+
if (picker) { picker.disabled = !choice; picker.redraw(); globalThis.AndorraModelPicker?.refresh?.(picker); }
|
|
134
193
|
renderNotices();
|
|
135
194
|
}
|
|
136
|
-
function fillModelOptions() {
|
|
137
|
-
modelSelect.replaceChildren(...(choice ? modelsOf(providerOf(choice.provider) || {}) : []).map(model => option(model, model)));
|
|
138
|
-
if (choice) modelSelect.value = choice.model;
|
|
139
|
-
for (const select of [providerSelect, modelSelect]) globalThis.AndorraControls?.refreshSelect?.(select);
|
|
140
|
-
}
|
|
141
|
-
providerSelect.onchange = () => {
|
|
142
|
-
const provider = providerOf(providerSelect.value);
|
|
143
|
-
const model = provider && modelsOf(provider)[0];
|
|
144
|
-
if (!model) return;
|
|
145
|
-
choice = { provider: provider.id, model };
|
|
146
|
-
logic.rememberModel(storage(), choice);
|
|
147
|
-
fillModelOptions();
|
|
148
|
-
};
|
|
149
|
-
modelSelect.onchange = () => {
|
|
150
|
-
if (!choice || !modelSelect.value) return;
|
|
151
|
-
choice = { provider: choice.provider, model: modelSelect.value };
|
|
152
|
-
logic.rememberModel(storage(), choice);
|
|
153
|
-
};
|
|
154
195
|
|
|
155
196
|
// ------------------------------------------------------------------ Stream
|
|
156
197
|
|
|
157
198
|
function connect() {
|
|
158
|
-
if (source || !open || !token || typeof EventSource !== 'function') return;
|
|
199
|
+
if (source || !open || !token || !streamGraphId || typeof EventSource !== 'function') return;
|
|
159
200
|
clearTimeout(retryTimer);
|
|
160
201
|
// EventSource cannot send an Authorization header, so the stream takes the session token in its query.
|
|
161
|
-
const stream = source = new EventSource(`/api/manager/stream?token=${encodeURIComponent(token)}`);
|
|
202
|
+
const stream = source = new EventSource(`/api/manager/stream?token=${encodeURIComponent(token)}&graph=${encodeURIComponent(streamGraphId)}`);
|
|
162
203
|
stream.onopen = () => { if (source !== stream) return; connected = true; retryMs = 1000; renderRunState(); };
|
|
163
204
|
stream.onmessage = message => {
|
|
164
205
|
if (source !== stream) return;
|
|
@@ -195,11 +236,15 @@ globalThis.AndorraManager = (() => {
|
|
|
195
236
|
const latest = transcript.filter(entry => entry.type === 'user').pop();
|
|
196
237
|
const own = latest && posted.find(entry => entry.text === latest.text && entry.whileIdle);
|
|
197
238
|
sentCanvas = own ? own.canvas : null;
|
|
239
|
+
// The merge base outlives a reconnect (the panel closed and reopened) when no message came in
|
|
240
|
+
// meanwhile: what the agent and the user shared is still what they share. Otherwise only this
|
|
241
|
+
// panel's own latest message says what was shared; with none, nothing is known.
|
|
242
|
+
if (!latest) rebase(null);
|
|
243
|
+
else if (latest.text !== latestUserSeen) rebase(own ? own.canvas : null);
|
|
244
|
+
latestUserSeen = latest ? latest.text : null;
|
|
198
245
|
if (own) chatGraphId = own.graphId;
|
|
199
246
|
posted = []; beforeLastMessage = null; unsureCanvas = false;
|
|
200
|
-
if (!transcript.length) {
|
|
201
|
-
// A conversation found already under way (a reload, another window) is taken to be about the open graph.
|
|
202
|
-
else if (!chatGraphId) chatGraphId = state.graph?.id ?? null;
|
|
247
|
+
if (!transcript.length) { createdOffer = null; decisions.clear(); }
|
|
203
248
|
// A graph deleted while this panel was not listening leaves the list all the same, and
|
|
204
249
|
// nothing of it is offered: its latest revision is the deletion.
|
|
205
250
|
const deleted = logic.deletedGraphs(transcript);
|
|
@@ -214,19 +259,24 @@ globalThis.AndorraManager = (() => {
|
|
|
214
259
|
const created = transcript.map(entry => logic.createdGraph(state.graph?.id, entry)).filter(Boolean).pop();
|
|
215
260
|
if (created && !deleted.has(created.id)) createdOffer = created;
|
|
216
261
|
} else if (event.type === 'user') {
|
|
262
|
+
latestUserSeen = event.text;
|
|
217
263
|
accepted(event.text);
|
|
218
264
|
} else if (event.type === 'error') {
|
|
219
|
-
|
|
265
|
+
// A warning follows a message that was delivered; only a real error refuses one.
|
|
266
|
+
if (!event.warning) refused();
|
|
220
267
|
} else if (event.type === 'state') {
|
|
221
268
|
runState = event.state;
|
|
222
269
|
// The run is over: its message was read or no longer matters, and no save follows without a new one.
|
|
223
|
-
if (runState === 'idle') { beforeLastMessage = null; unsureCanvas = false; }
|
|
270
|
+
if (runState === 'idle') { beforeLastMessage = null; unsureCanvas = false; mergeBeforeMessage = null; }
|
|
224
271
|
} else if (event.type === 'resolved') {
|
|
225
272
|
answering.delete(event.id);
|
|
226
273
|
} else if (event.type === 'graph.saved') {
|
|
227
274
|
void graphSaved(event);
|
|
228
275
|
} else if (event.type === 'graph.deleted') {
|
|
229
276
|
graphDeleted(event);
|
|
277
|
+
} else if (event.type === 'graph.edit') {
|
|
278
|
+
liveEdit(event);
|
|
279
|
+
return;
|
|
230
280
|
}
|
|
231
281
|
render();
|
|
232
282
|
}
|
|
@@ -243,22 +293,30 @@ globalThis.AndorraManager = (() => {
|
|
|
243
293
|
// agent now works from a canvas this panel never saw, so nothing here is known to be what it
|
|
244
294
|
// has. A save that follows is offered, never loaded over what is on this canvas.
|
|
245
295
|
sentCanvas = null; beforeLastMessage = null;
|
|
296
|
+
rebase(null);
|
|
246
297
|
return;
|
|
247
298
|
}
|
|
248
299
|
const [message] = posted.splice(index, 1);
|
|
249
300
|
if (runState !== 'idle') {
|
|
301
|
+
// A steered message is read only at the run's next turn, and a draft change already under way
|
|
302
|
+
// can land before then, made without it. The merge base stays what the agent had, so what the
|
|
303
|
+
// user changed for this message stays theirs until a message sent while idle shares it.
|
|
250
304
|
// Nothing on the stream says whether a working run read this message before its next save.
|
|
251
305
|
if (message.canvas !== sentCanvas) unsureCanvas = true;
|
|
252
306
|
chatGraphId = message.graphId;
|
|
253
307
|
return;
|
|
254
308
|
}
|
|
255
309
|
beforeLastMessage = { sentCanvas, chatGraphId };
|
|
310
|
+
mergeBeforeMessage = mergeState();
|
|
311
|
+
rebase(message.canvas);
|
|
256
312
|
sentCanvas = message.canvas; chatGraphId = message.graphId;
|
|
257
313
|
}
|
|
258
314
|
/** The chat reported an error: a message still open to refusal is taken as refused, which only ever makes a save an offer. */
|
|
259
315
|
function refused() {
|
|
260
316
|
if (beforeLastMessage) ({ sentCanvas, chatGraphId } = beforeLastMessage);
|
|
261
|
-
|
|
317
|
+
// The refused message's canvas was never shared with the agent, so what was shared before it is the base again.
|
|
318
|
+
if (mergeBeforeMessage) restoreMerge(mergeBeforeMessage);
|
|
319
|
+
beforeLastMessage = null; unsureCanvas = false; mergeBeforeMessage = null;
|
|
262
320
|
}
|
|
263
321
|
|
|
264
322
|
/**
|
|
@@ -312,6 +370,160 @@ globalThis.AndorraManager = (() => {
|
|
|
312
370
|
offeredRevision = event.revision;
|
|
313
371
|
renderNotices();
|
|
314
372
|
}
|
|
373
|
+
/** The version of a node, or of the graph's fields, the agent and the user last shared, or undefined. */
|
|
374
|
+
/**
|
|
375
|
+
* `sharedNode` and `sharedEdge` answer with the version both last shared, `null` when the agent
|
|
376
|
+
* removed it (so a later re-add of the same id is the agent's, not a user deletion), or undefined
|
|
377
|
+
* when nothing is known.
|
|
378
|
+
*/
|
|
379
|
+
function sharedNode(id) {
|
|
380
|
+
if (agentNodes.has(id)) return JSON.parse(agentNodes.get(id));
|
|
381
|
+
try { return mergeCanvas ? JSON.parse(mergeCanvas).nodes?.[id] : undefined; } catch { return undefined; }
|
|
382
|
+
}
|
|
383
|
+
function sharedEdge(id) {
|
|
384
|
+
if (agentEdges.has(id)) return JSON.parse(agentEdges.get(id));
|
|
385
|
+
try { return mergeCanvas ? (JSON.parse(mergeCanvas).edges || []).find(edge => edge && edge.id === id) : undefined; } catch { return undefined; }
|
|
386
|
+
}
|
|
387
|
+
function sharedFields(keys) {
|
|
388
|
+
let sent = {};
|
|
389
|
+
try { sent = mergeCanvas ? JSON.parse(mergeCanvas) : {}; } catch { /* Nothing shared is known. */ }
|
|
390
|
+
return Object.fromEntries(keys.map(key => [key, Object.hasOwn(agentFields, key) ? JSON.parse(agentFields[key]) : sent[key]]));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* The agent changed its draft of the open graph: the canvas shows the change at once, as an unsaved
|
|
395
|
+
* edit the user can undo. Nothing is saved: the draft is saved only when the user approves its
|
|
396
|
+
* publish, and that save then opens over these edits.
|
|
397
|
+
*
|
|
398
|
+
* A change to a node or to graph fields is merged field by field: what the user changed since the
|
|
399
|
+
* agent last saw it stays the user's. When the canvas was the one the agent works from and nothing
|
|
400
|
+
* of the user's was kept, it still is after the edit, so the approved save loads without asking;
|
|
401
|
+
* otherwise that save is offered, never loaded over the user's edits.
|
|
402
|
+
*/
|
|
403
|
+
function liveEdit(event) {
|
|
404
|
+
if (!state.graph || event.graphId !== state.graph.id || !logic.soundEdit(event.edit)) return;
|
|
405
|
+
// A field being typed in holds objects of the graph and commits into them when it is left. The
|
|
406
|
+
// change waits until then and is applied with the inspector drawn afresh, so no control is left
|
|
407
|
+
// bound to an object the change replaced or moved.
|
|
408
|
+
if (typingInEditor()) {
|
|
409
|
+
deferredEdits.push(event);
|
|
410
|
+
status('Graph Manager changed the draft; it shows when you leave this field.');
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
applyLive(event);
|
|
414
|
+
}
|
|
415
|
+
function flushDeferred() {
|
|
416
|
+
if (!deferredEdits.length || typingInEditor()) return;
|
|
417
|
+
for (const event of deferredEdits.splice(0)) applyLive(event);
|
|
418
|
+
}
|
|
419
|
+
// `change` commits a field before focus leaves it; the deferred changes follow once it has.
|
|
420
|
+
document.addEventListener('focusout', () => { setTimeout(flushDeferred, 0); });
|
|
421
|
+
|
|
422
|
+
function applyLive(event) {
|
|
423
|
+
const graph = state.graph;
|
|
424
|
+
if (!graph || event.graphId !== graph.id) return;
|
|
425
|
+
let edit = event.edit, kept = [];
|
|
426
|
+
if (edit.kind === 'node' && !graph.nodes?.[edit.node.id] && sharedNode(edit.node.id)) {
|
|
427
|
+
// The card was shared with the agent and is gone from the canvas: the user deleted it, and the
|
|
428
|
+
// agent's change does not bring it back. A card the agent adds is one nothing shared before.
|
|
429
|
+
edit = null;
|
|
430
|
+
kept = ['node'];
|
|
431
|
+
} else if (edit.kind === 'edge' && !(graph.edges || []).some(item => item && item.id === edit.edge.id) && sharedEdge(edit.edge.id)) {
|
|
432
|
+
edit = null;
|
|
433
|
+
kept = ['edge'];
|
|
434
|
+
} else if (edit.kind === 'node' && graph.nodes?.[edit.node.id]) {
|
|
435
|
+
const base = sharedNode(edit.node.id);
|
|
436
|
+
if (!base) {
|
|
437
|
+
// Nothing says what the user and the agent last shared of this card, so a field that differs
|
|
438
|
+
// may be the user's own edit: the card stays as it is, and the approved save is offered.
|
|
439
|
+
edit = null;
|
|
440
|
+
kept = ['node'];
|
|
441
|
+
} else {
|
|
442
|
+
const result = logic.mergeFields(base, graph.nodes[edit.node.id], edit.node);
|
|
443
|
+
kept = result.kept;
|
|
444
|
+
edit = { kind: 'node', node: { ...result.merged, id: edit.node.id } };
|
|
445
|
+
}
|
|
446
|
+
} else if (edit.kind === 'edge' && (graph.edges || []).some(item => item && item.id === edit.edge.id)) {
|
|
447
|
+
const base = sharedEdge(edit.edge.id);
|
|
448
|
+
if (!base) {
|
|
449
|
+
edit = null;
|
|
450
|
+
kept = ['edge'];
|
|
451
|
+
} else {
|
|
452
|
+
const result = logic.mergeFields(base, graph.edges.find(item => item && item.id === edit.edge.id), edit.edge);
|
|
453
|
+
kept = result.kept;
|
|
454
|
+
edit = { kind: 'edge', edge: { ...result.merged, id: edit.edge.id } };
|
|
455
|
+
}
|
|
456
|
+
} else if (edit.kind === 'node.remove' && graph.nodes?.[edit.nodeId]) {
|
|
457
|
+
// A card the user changed, or connected anew, since the agent last saw it stays: removing it
|
|
458
|
+
// would take the user's work with it. The approved save is offered instead.
|
|
459
|
+
const id = edit.nodeId;
|
|
460
|
+
const base = sharedNode(id);
|
|
461
|
+
const sameEdge = item => { const shared = sharedEdge(item.id); return !!shared && JSON.stringify(shared) === JSON.stringify(item); };
|
|
462
|
+
if (!base || JSON.stringify(base) !== JSON.stringify(graph.nodes[id])
|
|
463
|
+
|| (graph.edges || []).some(item => item && (item.source === id || item.target === id) && !sameEdge(item))) {
|
|
464
|
+
edit = null;
|
|
465
|
+
kept = ['node'];
|
|
466
|
+
}
|
|
467
|
+
} else if (edit.kind === 'edge.remove' && (graph.edges || []).some(item => item && item.id === edit.edgeId)) {
|
|
468
|
+
const base = sharedEdge(edit.edgeId);
|
|
469
|
+
if (!base || JSON.stringify(base) !== JSON.stringify(graph.edges.find(item => item && item.id === edit.edgeId))) {
|
|
470
|
+
edit = null;
|
|
471
|
+
kept = ['edge'];
|
|
472
|
+
}
|
|
473
|
+
} else if (edit.kind === 'graph') {
|
|
474
|
+
const keys = Object.keys(edit.patch);
|
|
475
|
+
const current = Object.fromEntries(keys.map(key => [key, graph[key]]));
|
|
476
|
+
const result = logic.mergeFields(sharedFields(keys), current, edit.patch, keys);
|
|
477
|
+
kept = result.kept;
|
|
478
|
+
const patch = Object.fromEntries(keys.filter(key => result.merged[key] !== undefined).map(key => [key, result.merged[key]]));
|
|
479
|
+
edit = Object.keys(patch).length ? { kind: 'graph', patch } : null;
|
|
480
|
+
}
|
|
481
|
+
// The agent's own version is the base for its next change, whatever the canvas kept.
|
|
482
|
+
if (event.edit.kind === 'node') agentNodes.set(event.edit.node.id, JSON.stringify(event.edit.node));
|
|
483
|
+
if (event.edit.kind === 'node.remove') {
|
|
484
|
+
// The removal is remembered as such, with the connections it took in the agent's draft.
|
|
485
|
+
const id = event.edit.nodeId;
|
|
486
|
+
// The connections as the agent's draft has them now: the shared ones, with each it has since
|
|
487
|
+
// set, rerouted or removed laid over them. Only those still touching the card went with it.
|
|
488
|
+
const current = new Map();
|
|
489
|
+
try { for (const item of (mergeCanvas ? JSON.parse(mergeCanvas).edges || [] : [])) if (item && typeof item.id === 'string') current.set(item.id, item); } catch { /* Nothing shared is known. */ }
|
|
490
|
+
for (const [edgeId, json] of agentEdges) { const item = JSON.parse(json); if (item) current.set(edgeId, item); else current.delete(edgeId); }
|
|
491
|
+
for (const [edgeId, item] of current) if (item.source === id || item.target === id) agentEdges.set(edgeId, 'null');
|
|
492
|
+
agentNodes.set(id, 'null');
|
|
493
|
+
}
|
|
494
|
+
if (event.edit.kind === 'edge') agentEdges.set(event.edit.edge.id, JSON.stringify(event.edit.edge));
|
|
495
|
+
if (event.edit.kind === 'edge.remove') agentEdges.set(event.edit.edgeId, 'null');
|
|
496
|
+
if (event.edit.kind === 'graph') for (const [key, value] of Object.entries(event.edit.patch)) agentFields[key] = JSON.stringify(value);
|
|
497
|
+
if (!edit) {
|
|
498
|
+
if (kept.length) { sentCanvas = null; status('Graph Manager changed the draft; your own edits were kept. Approve its save, then load it to see its changes.'); }
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const trial = JSON.parse(JSON.stringify(graph));
|
|
502
|
+
if (!logic.applyEdit(trial, edit) || JSON.stringify(trial) === JSON.stringify(graph)) return;
|
|
503
|
+
const followed = JSON.stringify(graph) === sentCanvas && !kept.length;
|
|
504
|
+
try {
|
|
505
|
+
mutate(() => {
|
|
506
|
+
logic.applyEdit(state.graph, edit);
|
|
507
|
+
if (edit.kind === 'node.remove') {
|
|
508
|
+
state.selectedIds = state.selectedIds.filter(id => id !== edit.nodeId);
|
|
509
|
+
if (state.selected === edit.nodeId) state.selected = null;
|
|
510
|
+
}
|
|
511
|
+
if (edit.kind === 'edge.remove' && state.selectedEdge === edit.edgeId) state.selectedEdge = null;
|
|
512
|
+
}, true);
|
|
513
|
+
} catch {
|
|
514
|
+
// A change the editor cannot draw is taken back rather than left to break every redraw. The
|
|
515
|
+
// whole editor is redrawn (the window's `render`, not this panel's), so the canvas and the
|
|
516
|
+
// inspector are bound to the restored graph.
|
|
517
|
+
if (state.undo.length) {
|
|
518
|
+
state.graph = state.undo.pop();
|
|
519
|
+
try { refreshDirty(); globalThis.render(); } catch { /* The restored graph drew before this change. */ }
|
|
520
|
+
}
|
|
521
|
+
status('Graph Manager made a change the editor cannot show; it was left out.', true);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
if (followed) sentCanvas = JSON.stringify(state.graph);
|
|
525
|
+
status(kept.length ? 'Graph Manager changed the draft; your own edits were kept. Approve its save to keep its changes.' : 'Graph Manager changed the draft. Approve its save to keep it.');
|
|
526
|
+
}
|
|
315
527
|
/**
|
|
316
528
|
* The agent deleted a graph, which publishes a revision marked as deleted. It leaves the list. When
|
|
317
529
|
* it is the open graph that revision is never loaded or offered: the canvas stays as it is, still
|
|
@@ -325,16 +537,15 @@ globalThis.AndorraManager = (() => {
|
|
|
325
537
|
if (createdOffer?.id === event.graphId) createdOffer = null;
|
|
326
538
|
if (state.graph?.id !== event.graphId) return;
|
|
327
539
|
offeredRevision = null;
|
|
328
|
-
status('
|
|
540
|
+
status('Graph Manager deleted this graph.');
|
|
329
541
|
}
|
|
330
542
|
/** Opens the graph the agent created. Unsaved edits on the canvas are asked about first, as for any other graph. */
|
|
331
543
|
async function openCreated(offer) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (transcript.length) chatGraphId = offer.id;
|
|
335
|
-
if (!await openGraph(offer.id) || state.graph?.id !== offer.id) { chatGraphId = before; renderNotices(); return; }
|
|
544
|
+
// The new graph has a conversation of its own, which the panel follows once it is open.
|
|
545
|
+
if (!await openGraph(offer.id) || state.graph?.id !== offer.id) { renderNotices(); return; }
|
|
336
546
|
// The canvas is the agent's own save: a further save in the same run replaces it freely.
|
|
337
547
|
sentCanvas = JSON.stringify(state.graph);
|
|
548
|
+
rebase(sentCanvas);
|
|
338
549
|
beforeLastMessage = null; unsureCanvas = false;
|
|
339
550
|
createdOffer = null;
|
|
340
551
|
renderNotices();
|
|
@@ -344,9 +555,10 @@ globalThis.AndorraManager = (() => {
|
|
|
344
555
|
if (!await openGraph(id, { discard: true, ...(fetched ? { fetched } : {}) }) || state.graph?.id !== id) return false;
|
|
345
556
|
// The canvas is now the agent's own save: a further save in the same run replaces it as freely.
|
|
346
557
|
sentCanvas = JSON.stringify(state.graph);
|
|
558
|
+
rebase(sentCanvas);
|
|
347
559
|
beforeLastMessage = null; unsureCanvas = false;
|
|
348
560
|
offeredRevision = null;
|
|
349
|
-
status(`
|
|
561
|
+
status(`Graph Manager saved version ${state.graph.revision}`);
|
|
350
562
|
renderNotices();
|
|
351
563
|
return true;
|
|
352
564
|
}
|
|
@@ -362,7 +574,7 @@ globalThis.AndorraManager = (() => {
|
|
|
362
574
|
async function send() {
|
|
363
575
|
const text = input.value.trim();
|
|
364
576
|
if (!text || !state.graph) return;
|
|
365
|
-
if (!choice) { localError = 'Add a model provider to use
|
|
577
|
+
if (!choice) { localError = 'Add a model provider to use Graph Manager.'; renderNotices(); return; }
|
|
366
578
|
const revision = Number.isInteger(state.graph.revision) ? state.graph.revision : 0;
|
|
367
579
|
// The canvas is recorded with the message and becomes the comparison baseline only when the
|
|
368
580
|
// stream echoes that message; a refused request puts the words back and leaves the baseline alone.
|
|
@@ -370,7 +582,6 @@ globalThis.AndorraManager = (() => {
|
|
|
370
582
|
// A message sent while idle starts its own run; a snapshot may stand in for its echo.
|
|
371
583
|
message.whileIdle = runState === 'idle';
|
|
372
584
|
posted.push(message);
|
|
373
|
-
switchOffer = null;
|
|
374
585
|
input.value = '';
|
|
375
586
|
const sent = await post('/api/manager/message', { provider: choice.provider, model: choice.model, text, graph: JSON.parse(message.canvas), saved: revision > 0, revision });
|
|
376
587
|
if (sent) return;
|
|
@@ -389,8 +600,7 @@ globalThis.AndorraManager = (() => {
|
|
|
389
600
|
}
|
|
390
601
|
|
|
391
602
|
async function newChat() {
|
|
392
|
-
|
|
393
|
-
await post('/api/manager/reset');
|
|
603
|
+
await post('/api/manager/reset', { graphId: streamGraphId });
|
|
394
604
|
}
|
|
395
605
|
|
|
396
606
|
// ------------------------------------------------------------------ Drawing
|
|
@@ -487,17 +697,67 @@ globalThis.AndorraManager = (() => {
|
|
|
487
697
|
}
|
|
488
698
|
const workRow = entry => entry.type === 'thought' ? thoughtRow(entry) : toolRow(entry);
|
|
489
699
|
|
|
700
|
+
/**
|
|
701
|
+
* A streaming thought whose only change is more words: its preview and body take the new text
|
|
702
|
+
* where they are. Rebuilding the row instead (every ~80ms while a model thinks) swapped the
|
|
703
|
+
* element out between a press and its release, so the click that opens it never landed.
|
|
704
|
+
* False when anything else changed, and the row is drawn again.
|
|
705
|
+
*/
|
|
706
|
+
function patchThought(old, entry) {
|
|
707
|
+
if (old.entry.type !== 'thought' || entry.type !== 'thought' || old.entry.status !== 'thinking' || entry.status !== 'thinking'
|
|
708
|
+
|| old.entry.startedAt !== entry.startedAt || old.entry.truncated !== entry.truncated) return false;
|
|
709
|
+
const head = old.element.querySelector(':scope > .manager-fold-head');
|
|
710
|
+
const body = old.element.querySelector('.manager-activity-text');
|
|
711
|
+
if (!head || !body) return false;
|
|
712
|
+
const preview = lastLine(entry.text);
|
|
713
|
+
let tail = head.querySelector('.manager-preview-tail');
|
|
714
|
+
if (preview && !tail) {
|
|
715
|
+
tail = span(undefined, 'manager-activity-preview manager-preview-tail');
|
|
716
|
+
tail.append(span(preview));
|
|
717
|
+
head.insertBefore(tail, head.querySelector('[data-since]'));
|
|
718
|
+
} else if (tail) {
|
|
719
|
+
if (preview) tail.firstChild.textContent = preview; else tail.remove();
|
|
720
|
+
}
|
|
721
|
+
// An open thought keeps following its newest words only while the reader is at its end.
|
|
722
|
+
const following = body.scrollHeight - body.scrollTop - body.clientHeight < 24;
|
|
723
|
+
body.textContent = entry.text || 'Still thinking; nothing has streamed yet.';
|
|
724
|
+
if (following) body.scrollTop = body.scrollHeight;
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* The stretch that is still running, reconciled row by row against what it drew last time: a row
|
|
730
|
+
* whose entry is unchanged stays the same element, a streaming thought is patched in place, and
|
|
731
|
+
* only a row that really changed (a call settling) is drawn again. Keeping the elements is what
|
|
732
|
+
* lets a click on any row land while the stretch streams.
|
|
733
|
+
*/
|
|
734
|
+
function liveBlock(block, before) {
|
|
735
|
+
const container = before?.element ?? node('div', undefined, 'manager-work-live');
|
|
736
|
+
const rows = new Map();
|
|
737
|
+
let previous = null;
|
|
738
|
+
for (const entry of block.entries) {
|
|
739
|
+
const old = before?.rows?.get(entry.id);
|
|
740
|
+
let element;
|
|
741
|
+
if (old && (old.entry === entry || patchThought(old, entry))) element = old.element;
|
|
742
|
+
else {
|
|
743
|
+
element = workRow(entry);
|
|
744
|
+
if (old) old.element.replaceWith(element);
|
|
745
|
+
}
|
|
746
|
+
// A new row goes after the one before it; a kept row is not moved.
|
|
747
|
+
if (element.parentNode !== container) { if (previous) previous.after(element); else container.prepend(element); }
|
|
748
|
+
rows.set(entry.id, { entry, element });
|
|
749
|
+
previous = element;
|
|
750
|
+
}
|
|
751
|
+
for (const [id, old] of before?.rows ?? []) if (!rows.has(id)) old.element.remove();
|
|
752
|
+
return { element: container, rows };
|
|
753
|
+
}
|
|
754
|
+
|
|
490
755
|
/**
|
|
491
756
|
* A stretch of thinking and calls between messages. While it runs every row shows; once it
|
|
492
757
|
* settles it condenses to the one line the app's turn shows (`Thought for 8s, made 4 edits`), with
|
|
493
758
|
* its wall time at the edge, and opens back to the same rows.
|
|
494
759
|
*/
|
|
495
760
|
function workBlock(block) {
|
|
496
|
-
if (!block.settled) {
|
|
497
|
-
const live = node('div', undefined, 'manager-work-live');
|
|
498
|
-
live.append(...block.entries.map(workRow));
|
|
499
|
-
return live;
|
|
500
|
-
}
|
|
501
761
|
const failed = block.entries.filter(entry => entry.type === 'tool' && entry.status === 'failed').length;
|
|
502
762
|
const label = logic.workLabel(block.entries);
|
|
503
763
|
const duration = logic.workDuration(block.entries);
|
|
@@ -528,7 +788,7 @@ globalThis.AndorraManager = (() => {
|
|
|
528
788
|
}
|
|
529
789
|
if (entry.type === 'graph.deleted') {
|
|
530
790
|
const other = entry.graphId !== chatGraphId && entry.graphId !== state.graph?.id;
|
|
531
|
-
return node('div', other ? `Deleted ${entry.graphId}` : 'Deleted this
|
|
791
|
+
return node('div', other ? `Deleted ${entry.graphId}` : 'Deleted this graph', 'manager-row manager-saved');
|
|
532
792
|
}
|
|
533
793
|
if (entry.type === 'approval') return approvalCard(entry);
|
|
534
794
|
if (entry.type === 'question') return questionCard(entry);
|
|
@@ -554,17 +814,17 @@ globalThis.AndorraManager = (() => {
|
|
|
554
814
|
return item;
|
|
555
815
|
}
|
|
556
816
|
function approvalCard(entry) {
|
|
557
|
-
const item = card(entry, '
|
|
817
|
+
const item = card(entry, 'Graph Manager asks to', entry.text);
|
|
558
818
|
if (entry.answered) return closed(item, entry, 'Answered');
|
|
559
819
|
return actions(item, entry, [
|
|
560
|
-
control('Approve', () => settle(entry, '/api/manager/approve', { id: entry.id, approved: true }, 'Approved'), 'btn-small primary'),
|
|
561
|
-
control('Deny', () => settle(entry, '/api/manager/approve', { id: entry.id, approved: false }, 'Denied')),
|
|
820
|
+
control('Approve', () => settle(entry, '/api/manager/approve', { graphId: streamGraphId, id: entry.id, approved: true }, 'Approved'), 'btn-small primary'),
|
|
821
|
+
control('Deny', () => settle(entry, '/api/manager/approve', { graphId: streamGraphId, id: entry.id, approved: false }, 'Denied')),
|
|
562
822
|
]);
|
|
563
823
|
}
|
|
564
824
|
function questionCard(entry) {
|
|
565
|
-
const item = card(entry, '
|
|
825
|
+
const item = card(entry, 'Graph Manager asks', entry.question);
|
|
566
826
|
if (entry.answered) return closed(item, entry, 'Answered');
|
|
567
|
-
const answer = value => settle(entry, '/api/manager/answer', { id: entry.id, value }, `Answered: ${value}`);
|
|
827
|
+
const answer = value => settle(entry, '/api/manager/answer', { graphId: streamGraphId, id: entry.id, value }, `Answered: ${value}`);
|
|
568
828
|
if (Array.isArray(entry.choices) && entry.choices.length) {
|
|
569
829
|
return actions(item, entry, entry.choices.map(value => control(String(value), () => answer(String(value)))));
|
|
570
830
|
}
|
|
@@ -588,7 +848,7 @@ globalThis.AndorraManager = (() => {
|
|
|
588
848
|
const atEnd = log.scrollHeight - log.scrollTop - log.clientHeight < 40;
|
|
589
849
|
const next = [];
|
|
590
850
|
if (!transcript.length) {
|
|
591
|
-
log.replaceChildren(node('p', 'Ask
|
|
851
|
+
log.replaceChildren(node('p', 'Ask Graph Manager to build or change this graph. It sees the canvas as it is now, unsaved edits included. Its changes appear on the canvas as it makes them, and nothing is saved until you approve.', 'help manager-empty'));
|
|
592
852
|
rendered = [];
|
|
593
853
|
return;
|
|
594
854
|
}
|
|
@@ -596,11 +856,19 @@ globalThis.AndorraManager = (() => {
|
|
|
596
856
|
logic.blocks(transcript, runState !== 'idle').forEach((block, index) => {
|
|
597
857
|
const before = rendered[index], pending = block.kind === 'entry' && answering.has(block.entry.id);
|
|
598
858
|
if (sameBlock(before, block, pending)) { next.push(before); return; }
|
|
599
|
-
const
|
|
859
|
+
const live = block.kind === 'work' && !block.settled;
|
|
860
|
+
// The same running stretch as last time: its rows are reconciled in place, not redrawn.
|
|
861
|
+
if (live && before?.block.kind === 'work' && !before.block.settled && before.block.key === block.key && before.rows) {
|
|
862
|
+
const { rows } = liveBlock(block, before);
|
|
863
|
+
next.push({ block, pending, element: before.element, rows });
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
const drawn = live ? liveBlock(block) : { element: block.kind === 'work' ? workBlock(block) : row(block.entry) };
|
|
867
|
+
const element = drawn.element;
|
|
600
868
|
if (before?.element && element) before.element.replaceWith(element);
|
|
601
869
|
else { before?.element?.remove(); if (element) log.append(element); }
|
|
602
870
|
if (element) followThought(element);
|
|
603
|
-
next.push({ block, pending, element });
|
|
871
|
+
next.push({ block, pending, element, ...(drawn.rows ? { rows: drawn.rows } : {}) });
|
|
604
872
|
});
|
|
605
873
|
for (const stale of rendered.slice(next.length)) stale.element?.remove();
|
|
606
874
|
rendered = next;
|
|
@@ -628,23 +896,17 @@ globalThis.AndorraManager = (() => {
|
|
|
628
896
|
}
|
|
629
897
|
function renderNotices() {
|
|
630
898
|
const bars = [];
|
|
631
|
-
if (!state.providers.length) bars.push(notice('manager-warning', 'Add a model provider to use
|
|
632
|
-
if (switchOffer && state.graph?.id === switchOffer) {
|
|
633
|
-
bars.push(notice('manager-switch', `Start a new chat about ${state.graph.name || 'this workflow'}?`, [
|
|
634
|
-
control('New chat', () => { void newChat(); }, 'btn-small primary'),
|
|
635
|
-
control('Keep this chat', () => { switchOffer = null; renderNotices(); }),
|
|
636
|
-
]));
|
|
637
|
-
}
|
|
899
|
+
if (!state.providers.length) bars.push(notice('manager-warning', 'Add a model provider to use Graph Manager.', []));
|
|
638
900
|
if (offeredRevision !== null && state.graph) {
|
|
639
901
|
const id = state.graph.id;
|
|
640
|
-
bars.push(notice('manager-load', `
|
|
902
|
+
bars.push(notice('manager-load', `Graph Manager saved version ${offeredRevision}. Load it?`, [
|
|
641
903
|
control('Load', () => { void loadRevision(id); }, 'btn-small primary'),
|
|
642
904
|
control('Not now', () => { offeredRevision = null; renderNotices(); }),
|
|
643
905
|
]));
|
|
644
906
|
}
|
|
645
907
|
if (createdOffer && state.graph?.id === 'default') {
|
|
646
908
|
const offer = createdOffer;
|
|
647
|
-
bars.push(notice('manager-created', `
|
|
909
|
+
bars.push(notice('manager-created', `Graph Manager created ${offer.label}. Open it?`, [
|
|
648
910
|
control('Open', () => { void openCreated(offer); }, 'btn-small primary'),
|
|
649
911
|
control('Not now', () => { createdOffer = null; renderNotices(); }),
|
|
650
912
|
]));
|
|
@@ -669,7 +931,7 @@ globalThis.AndorraManager = (() => {
|
|
|
669
931
|
byId('manager-close').onclick = () => { setOpen(false); button.focus(); };
|
|
670
932
|
byId('manager-new-chat').onclick = () => { void newChat(); };
|
|
671
933
|
sendButton.onclick = () => { void send(); };
|
|
672
|
-
stopButton.onclick = () => { void post('/api/manager/cancel'); };
|
|
934
|
+
stopButton.onclick = () => { void post('/api/manager/cancel', { graphId: streamGraphId }); };
|
|
673
935
|
input.onkeydown = event => {
|
|
674
936
|
if (event.key !== 'Enter' || event.shiftKey || event.isComposing) return;
|
|
675
937
|
event.preventDefault();
|