@kabmo-labs/kabmo 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +440 -436
- package/dist/client/static/js/{index-ga8cbpt4.js → index-95b3n20k.js} +945 -945
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/session-actions-menu/index.tsx +38 -12
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
- package/src/client/components/common/session-row/index.tsx +24 -25
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +64 -68
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -13
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +59 -57
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +57 -61
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +28 -39
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +10 -21
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/hooks/chat/composer/items.test.ts +19 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +4 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -0
- package/src/client/hooks/chat/timeline/send.ts +17 -103
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
- package/src/client/hooks/models/use-harness-update.test.ts +137 -44
- package/src/client/hooks/models/use-harness-update.ts +133 -85
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/server/lib/db/schema.ts +1 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +31 -21
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
- package/src/server/lib/harness/acp/session-handshake.ts +83 -6
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +48 -6
- package/src/server/lib/harness/acp/session-turns.ts +8 -3
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +19 -1
- package/src/server/lib/harness/acp/session.ts +60 -60
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +102 -0
- package/src/server/lib/harness/acp/turn.ts +81 -6
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +46 -6
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +21 -9
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/update-job-store.test.ts +37 -12
- package/src/server/lib/harness/update-job-store.ts +22 -16
- package/src/server/lib/harness/update-job.server.ts +66 -175
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.ts +8 -3
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +14 -9
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
- package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
- package/src/server/lib/sessions/fork.server.test.ts +68 -0
- package/src/server/lib/sessions/fork.server.ts +31 -6
- package/src/server/lib/sessions/spawn.server.test.ts +41 -0
- package/src/server/lib/sessions/spawn.server.ts +27 -2
- package/src/server/routes/agent/harness-command.ts +6 -5
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/update-status.ts +18 -12
- package/src/server/routes/harness/update.test.ts +53 -16
- package/src/server/routes/harness/update.ts +13 -8
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/fork.ts +19 -4
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +19 -0
- package/src/server/routes/sessions/spawn.ts +16 -13
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +53 -6
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/types/harness-update.ts +24 -0
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/harness-table.test-util.ts +25 -9
- package/dist/client/static/js/index-bc9aa4mx.css +0 -1
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
- package/src/client/hooks/workspace/child-expansion.ts +0 -33
|
@@ -31,10 +31,13 @@ import { PendingCalls } from '@/server/lib/harness/acp/calls';
|
|
|
31
31
|
import { killProcessTree } from '@/server/lib/lifecycle/kill-tree';
|
|
32
32
|
import { stripKabmoHostEnv, withToolchainPath } from '@kabmo-labs/kabmo-sdk';
|
|
33
33
|
import * as verbs from '@/server/lib/harness/acp/verbs';
|
|
34
|
+
import { initializeAcpAgent } from '@/server/lib/harness/acp/client-initialize';
|
|
35
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
34
36
|
import type {
|
|
35
37
|
AcpId,
|
|
36
38
|
AcpInitializeResult,
|
|
37
39
|
AcpNotification,
|
|
40
|
+
AcpProtocolVersion,
|
|
38
41
|
AcpRequest,
|
|
39
42
|
AcpResponse,
|
|
40
43
|
} from '@/server/lib/harness/acp/protocol';
|
|
@@ -46,7 +49,11 @@ export type AcpClientRequestHandler = (
|
|
|
46
49
|
id: AcpId,
|
|
47
50
|
method: string,
|
|
48
51
|
params: Record<string, unknown>,
|
|
49
|
-
) => Promise<
|
|
52
|
+
) => Promise<
|
|
53
|
+
| { answered: true; result: unknown }
|
|
54
|
+
| { answered: false; message: string; code?: number }
|
|
55
|
+
| { answered: false; deferred: true }
|
|
56
|
+
>;
|
|
50
57
|
|
|
51
58
|
export interface AcpClientOptions {
|
|
52
59
|
command: string[];
|
|
@@ -75,6 +82,9 @@ export class AcpProcess {
|
|
|
75
82
|
private exited = false;
|
|
76
83
|
private stderrTail = '';
|
|
77
84
|
private writeQueue: Promise<void> = Promise.resolve();
|
|
85
|
+
/** The negotiated ACP major. 1 until `initialize` answers; every verb that
|
|
86
|
+
* changed shape between versions reads it. */
|
|
87
|
+
protocolVersion: AcpProtocolVersion = 1;
|
|
78
88
|
/** Set once `initialize` answers, so a request sent earlier fails loudly
|
|
79
89
|
* instead of racing the handshake. */
|
|
80
90
|
private initialized = false;
|
|
@@ -131,20 +141,10 @@ export class AcpProcess {
|
|
|
131
141
|
return this.child.pid ?? undefined;
|
|
132
142
|
}
|
|
133
143
|
|
|
134
|
-
/** `initialize
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
async initialize(capabilities: Record<string, unknown> = {}, timeoutMs = 60_000): Promise<AcpInitializeResult> {
|
|
139
|
-
const result = await this.request<AcpInitializeResult>(
|
|
140
|
-
'initialize',
|
|
141
|
-
{
|
|
142
|
-
protocolVersion: 1,
|
|
143
|
-
clientCapabilities: capabilities,
|
|
144
|
-
clientInfo: { name: 'kabmo', title: 'Kabmo', version: '0.1' },
|
|
145
|
-
},
|
|
146
|
-
timeoutMs,
|
|
147
|
-
);
|
|
144
|
+
/** `initialize`; the client advertises exactly what it can serve. */
|
|
145
|
+
async initialize(capabilities?: Record<string, unknown>, timeoutMs = 60_000): Promise<AcpInitializeResult> {
|
|
146
|
+
const result = await initializeAcpAgent(this.call, capabilities, timeoutMs);
|
|
147
|
+
this.protocolVersion = result.protocolVersion === 2 ? 2 : 1;
|
|
148
148
|
this.initialized = true;
|
|
149
149
|
return result;
|
|
150
150
|
}
|
|
@@ -158,7 +158,7 @@ export class AcpProcess {
|
|
|
158
158
|
// wire shape. Callers keep using `proc.newSession(...)`.
|
|
159
159
|
|
|
160
160
|
newSession(cwd: string, timeoutMs?: number) {
|
|
161
|
-
return verbs.newSession(this.call, cwd, timeoutMs);
|
|
161
|
+
return verbs.newSession(this.call, cwd, timeoutMs, this.protocolVersion);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
loadSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
@@ -166,7 +166,7 @@ export class AcpProcess {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
resumeSession(sessionId: string, cwd: string, timeoutMs?: number) {
|
|
169
|
-
return verbs.resumeSession(this.call, sessionId, cwd, timeoutMs);
|
|
169
|
+
return verbs.resumeSession(this.call, sessionId, cwd, timeoutMs, this.protocolVersion);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
forkSession(sessionId: string, cwd: string, timeoutMs?: number, target?: Record<string, unknown>) {
|
|
@@ -192,7 +192,7 @@ export class AcpProcess {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
setConfigOption(sessionId: string, configId: string, value: string | boolean, timeoutMs?: number) {
|
|
195
|
-
return verbs.setConfigOption(this.call, sessionId, configId, value, timeoutMs);
|
|
195
|
+
return verbs.setConfigOption(this.call, sessionId, configId, value, timeoutMs, this.protocolVersion);
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
steer(sessionId: string, blocks: unknown[], queue?: 'steering' | 'followUp', timeoutMs?: number) {
|
|
@@ -203,6 +203,14 @@ export class AcpProcess {
|
|
|
203
203
|
return verbs.closeSession(this.call, sessionId, timeoutMs);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
setMode(sessionId: string, modeId: string, timeoutMs?: number) {
|
|
207
|
+
return verbs.setMode(this.call, sessionId, modeId, timeoutMs);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
deleteSession(sessionId: string, timeoutMs?: number) {
|
|
211
|
+
return verbs.deleteSession(this.call, sessionId, timeoutMs);
|
|
212
|
+
}
|
|
213
|
+
|
|
206
214
|
/** The invoke seam `verbs.ts` binds to. Arrow so it survives being passed. */
|
|
207
215
|
readonly call = <T,>(method: string, params: unknown, timeoutMs: number): Promise<T> =>
|
|
208
216
|
this.request<T>(method, params, timeoutMs);
|
|
@@ -212,7 +220,7 @@ export class AcpProcess {
|
|
|
212
220
|
this.write({ jsonrpc: '2.0', id, result });
|
|
213
221
|
}
|
|
214
222
|
|
|
215
|
-
respondError(id: AcpId, message: string, code =
|
|
223
|
+
respondError(id: AcpId, message: string, code: number = ACP_ERROR.internal): void {
|
|
216
224
|
this.write({ jsonrpc: '2.0', id, error: { code, message } });
|
|
217
225
|
}
|
|
218
226
|
|
|
@@ -329,8 +337,10 @@ export class AcpProcess {
|
|
|
329
337
|
// the same request twice.
|
|
330
338
|
if (handled && 'deferred' in handled) return;
|
|
331
339
|
// A refusal is REQUIRED, not optional: an unanswered agent→client call
|
|
332
|
-
// parks the turn forever (the agent's dispatcher waits on it).
|
|
333
|
-
|
|
340
|
+
// parks the turn forever (the agent's dispatcher waits on it). The code
|
|
341
|
+
// travels with it so the agent can distinguish "not implemented" from
|
|
342
|
+
// "that file is gone" and fall back accordingly.
|
|
343
|
+
this.respondError(id, handled?.message ?? `Kabmo does not implement ${method}`, handled?.code);
|
|
334
344
|
} catch (error) {
|
|
335
345
|
this.respondError(id, error instanceof Error ? error.message : String(error));
|
|
336
346
|
}
|
|
@@ -23,12 +23,12 @@ const option = (id: string, category: string, values: string[]): AcpConfigOption
|
|
|
23
23
|
options: values.map((value) => ({ value })),
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
function host(): AcpCommandHost & { writes: [string, string | boolean][];
|
|
26
|
+
function host(): AcpCommandHost & { writes: [string, string | boolean][]; accessModes: string[] } {
|
|
27
27
|
const writes: [string, string | boolean][] = [];
|
|
28
|
-
const
|
|
28
|
+
const accessModes: string[] = [];
|
|
29
29
|
return {
|
|
30
30
|
writes,
|
|
31
|
-
|
|
31
|
+
accessModes,
|
|
32
32
|
harness: 'claude',
|
|
33
33
|
sessionId: 's1',
|
|
34
34
|
capabilities: {
|
|
@@ -48,7 +48,7 @@ function host(): AcpCommandHost & { writes: [string, string | boolean][]; modes:
|
|
|
48
48
|
steer: async () => ({}),
|
|
49
49
|
cancelTurn: () => {},
|
|
50
50
|
setAccessMode: (mode) => {
|
|
51
|
-
|
|
51
|
+
accessModes.push(mode);
|
|
52
52
|
},
|
|
53
53
|
setConfig: async (id, value) => {
|
|
54
54
|
writes.push([id, value]);
|
|
@@ -82,7 +82,7 @@ describe('ACP dispatchCommand', () => {
|
|
|
82
82
|
test('the access tier is adopted before the command runs', async () => {
|
|
83
83
|
const stub = host();
|
|
84
84
|
await dispatchCommand(stub, { type: 'get_state', accessMode: 'yolo' });
|
|
85
|
-
expect(stub.
|
|
85
|
+
expect(stub.accessModes).toEqual(['yolo']);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
test('get_commands answers the agent’s own list', async () => {
|
|
@@ -24,7 +24,7 @@ import { configOption, promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
|
24
24
|
import { acpOptionValues } from '@/server/lib/harness/acp/protocol';
|
|
25
25
|
import { notePromptTitle } from '@/server/lib/harness/session-title.server';
|
|
26
26
|
import { isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
27
|
-
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
27
|
+
import type { AcpConfigOption, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
28
28
|
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
29
29
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
30
30
|
|
|
@@ -35,6 +35,10 @@ export interface AcpCommandHost {
|
|
|
35
35
|
readonly sessionId: string;
|
|
36
36
|
readonly capabilities: HarnessCapabilities;
|
|
37
37
|
readonly configOptions: AcpConfigOption[];
|
|
38
|
+
/** The older Session Modes API, when the agent publishes no selector. */
|
|
39
|
+
readonly modes?: AcpSessionModeState | null;
|
|
40
|
+
/** `session/set_mode`; present only when the session can speak it. */
|
|
41
|
+
setMode?(modeId: string): Promise<unknown>;
|
|
38
42
|
/** Dispatch one turn. Returns the ACK (`{agentInvoked:true}`), never the
|
|
39
43
|
* turn: the route's answer means "accepted", and the turn's end arrives as
|
|
40
44
|
* the session's `agent_end` frame. */
|
|
@@ -137,7 +141,15 @@ export interface AcpCommandHost {
|
|
|
137
141
|
case 'set_mode': {
|
|
138
142
|
const mode = String(command.mode ?? '');
|
|
139
143
|
const selector = configOption(host.configOptions, 'mode');
|
|
140
|
-
if (!selector)
|
|
144
|
+
if (!selector) {
|
|
145
|
+
// The older Session Modes API. An agent that publishes `modes` and no
|
|
146
|
+
// `mode` selector can still move; inventing a selector write would
|
|
147
|
+
// call a method it did not advertise.
|
|
148
|
+
if (host.modes?.availableModes.some((entry) => entry.id === mode) && host.setMode) {
|
|
149
|
+
return host.setMode(mode);
|
|
150
|
+
}
|
|
151
|
+
throw new Error(`This harness exposes no mode selector (${host.harness})`);
|
|
152
|
+
}
|
|
141
153
|
return host.setConfig(selector.id, mode);
|
|
142
154
|
}
|
|
143
155
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The timeline fields ACP frames did not carry: a message stamp at first
|
|
8
|
+
* chunk, and the turn's measured duration at close. Without them the assistant
|
|
9
|
+
* footer had no date or response time for any ACP harness.
|
|
10
|
+
*
|
|
11
|
+
* Split from `frames.test.ts` to stay under the file ceiling.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
|
|
16
|
+
import { toChatMessage } from '@/shared/lib/omp/session/mapper';
|
|
17
|
+
|
|
18
|
+
const textChunk = (text: string, messageId = 'm1') => ({
|
|
19
|
+
sessionUpdate: 'agent_message_chunk',
|
|
20
|
+
content: { type: 'text', text },
|
|
21
|
+
messageId,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** The frame's message as a record, for assertions on fields the event type
|
|
25
|
+
* widens to `unknown`. The mapper built it, so the shape is ours. */
|
|
26
|
+
const messageOf = (frame: unknown): Record<string, unknown> | null => {
|
|
27
|
+
if (!frame || typeof frame !== 'object' || !('message' in frame)) return null;
|
|
28
|
+
const message = frame.message;
|
|
29
|
+
return message && typeof message === 'object' ? message as Record<string, unknown> : null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('acp frame mapper — message timing', () => {
|
|
33
|
+
test('stamps the message start once, not every chunk', () => {
|
|
34
|
+
const mapper = new AcpFrameMapper();
|
|
35
|
+
const first = messageOf(mapper.mapUpdate(textChunk('hello '))[0]);
|
|
36
|
+
const second = messageOf(mapper.mapUpdate(textChunk('world'))[0]);
|
|
37
|
+
expect(typeof first?.timestamp).toBe('number');
|
|
38
|
+
expect(second?.timestamp).toBe(first?.timestamp);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('the closed message carries a duration measured from the turn start', () => {
|
|
42
|
+
const mapper = new AcpFrameMapper();
|
|
43
|
+
mapper.reset(1_000);
|
|
44
|
+
mapper.mapUpdate(textChunk('done'));
|
|
45
|
+
const message = messageOf(mapper.closeMessage()[0]);
|
|
46
|
+
const { timestamp, completedAt, duration } = message ?? {};
|
|
47
|
+
if (typeof timestamp !== 'number' || typeof completedAt !== 'number' || typeof duration !== 'number') {
|
|
48
|
+
throw new Error('message_end is missing its timing fields');
|
|
49
|
+
}
|
|
50
|
+
expect(timestamp).toBeGreaterThanOrEqual(1_000);
|
|
51
|
+
expect(completedAt).toBeGreaterThanOrEqual(timestamp);
|
|
52
|
+
expect(duration).toBe(completedAt - 1_000);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('the client mapper turns those fields into the footer stamp and duration', () => {
|
|
56
|
+
const mapper = new AcpFrameMapper();
|
|
57
|
+
mapper.reset(1_000);
|
|
58
|
+
mapper.mapUpdate(textChunk('done'));
|
|
59
|
+
const message = messageOf(mapper.closeMessage()[0]);
|
|
60
|
+
if (!message) throw new Error('message_end carried no message');
|
|
61
|
+
const converted = toChatMessage(message, false);
|
|
62
|
+
expect(converted?.date).toStartWith('Today,');
|
|
63
|
+
expect(converted?.timestamp).toMatch(/^\d{1,2}:\d{2}\s(AM|PM)$/);
|
|
64
|
+
const duration = message.duration;
|
|
65
|
+
if (typeof duration !== 'number') throw new Error('message_end carried no duration');
|
|
66
|
+
expect(converted?.durationMs).toBe(duration);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* v2 frame semantics: whole-message upserts, one tool-call upsert, streaming
|
|
8
|
+
* tool content, keyed plans, and the two extra final statuses.
|
|
9
|
+
*
|
|
10
|
+
* Split from `frames.test.ts` to stay under the file ceiling.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, test } from 'bun:test';
|
|
14
|
+
import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
|
|
15
|
+
|
|
16
|
+
describe('acp v2 updates', () => {
|
|
17
|
+
test('a whole agent_message replaces content and a chunk appends to it', () => {
|
|
18
|
+
const mapper = new AcpFrameMapper();
|
|
19
|
+
const whole = mapper.mapUpdate({
|
|
20
|
+
sessionUpdate: 'agent_message',
|
|
21
|
+
messageId: 'm1',
|
|
22
|
+
content: [{ type: 'text', text: 'hello' }],
|
|
23
|
+
});
|
|
24
|
+
expect(whole.at(-1)).toMatchObject({
|
|
25
|
+
type: 'message_update',
|
|
26
|
+
message: { content: [{ type: 'text', text: 'hello' }] },
|
|
27
|
+
});
|
|
28
|
+
const chunk = mapper.mapUpdate({
|
|
29
|
+
sessionUpdate: 'agent_message_chunk',
|
|
30
|
+
messageId: 'm1',
|
|
31
|
+
content: { type: 'text', text: ' world' },
|
|
32
|
+
});
|
|
33
|
+
expect(chunk.at(-1)).toMatchObject({
|
|
34
|
+
type: 'message_update',
|
|
35
|
+
message: { content: [{ type: 'text', text: 'hello world' }] },
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('a later whole message replaces the text it streamed before', () => {
|
|
40
|
+
const mapper = new AcpFrameMapper();
|
|
41
|
+
mapper.mapUpdate({ sessionUpdate: 'agent_message', messageId: 'm1', content: [{ type: 'text', text: 'old' }] });
|
|
42
|
+
const replaced = mapper.mapUpdate({
|
|
43
|
+
sessionUpdate: 'agent_message',
|
|
44
|
+
messageId: 'm1',
|
|
45
|
+
content: [{ type: 'text', text: 'new' }],
|
|
46
|
+
});
|
|
47
|
+
expect(replaced.at(-1)).toMatchObject({ message: { content: [{ type: 'text', text: 'new' }] } });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('a first tool_call_update creates the call and content chunks reach its result', () => {
|
|
51
|
+
const mapper = new AcpFrameMapper();
|
|
52
|
+
const start = mapper.mapUpdate({
|
|
53
|
+
sessionUpdate: 'tool_call_update',
|
|
54
|
+
toolCallId: 't1',
|
|
55
|
+
title: 'Run tests',
|
|
56
|
+
name: 'bash',
|
|
57
|
+
kind: 'execute',
|
|
58
|
+
status: 'in_progress',
|
|
59
|
+
});
|
|
60
|
+
expect(start.some((event) => event.type === 'tool_execution_start')).toBe(true);
|
|
61
|
+
mapper.mapUpdate({
|
|
62
|
+
sessionUpdate: 'tool_call_content_chunk',
|
|
63
|
+
toolCallId: 't1',
|
|
64
|
+
content: { type: 'content', content: { type: 'text', text: 'out' } },
|
|
65
|
+
});
|
|
66
|
+
const end = mapper.mapUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 't1', status: 'completed' });
|
|
67
|
+
expect(end[0]).toMatchObject({ type: 'tool_execution_end', output: 'out', isError: false });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('cancelled is a final tool status and paused is not', () => {
|
|
71
|
+
const mapper = new AcpFrameMapper();
|
|
72
|
+
mapper.mapUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 'p1', status: 'paused' });
|
|
73
|
+
expect(mapper.openCalls()).toEqual(['p1']);
|
|
74
|
+
const cancelled = mapper.mapUpdate({ sessionUpdate: 'tool_call_update', toolCallId: 'p1', status: 'cancelled' });
|
|
75
|
+
expect(cancelled[0]).toMatchObject({ type: 'tool_execution_end', isError: true });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('plan_update feeds the entries the Todos panel reads', () => {
|
|
79
|
+
const frames = new AcpFrameMapper().mapUpdate({
|
|
80
|
+
sessionUpdate: 'plan_update',
|
|
81
|
+
plan: { type: 'items', planId: 'p1', entries: [{ content: 'step', status: 'pending' }] },
|
|
82
|
+
});
|
|
83
|
+
expect(frames[0]).toMatchObject({ type: 'plan_updated', entries: [{ content: 'step' }] });
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -33,55 +33,42 @@
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
acpToolDetails,
|
|
40
|
-
acpToolOutput,
|
|
41
|
-
acpToolTarget,
|
|
42
|
-
isKnownToolName,
|
|
43
|
-
toolTypeFor,
|
|
44
|
-
} from '@/server/lib/harness/acp/mapper';
|
|
45
|
-
import type { AcpToolKind, AcpToolStatus } from '@/server/lib/harness/acp/protocol';
|
|
36
|
+
import { acpContentText } from '@/server/lib/harness/acp/mapper';
|
|
37
|
+
import { planEntries } from '@/server/lib/harness/acp/v2';
|
|
38
|
+
import { AcpToolCalls, type ToolCallBlock } from '@/server/lib/harness/acp/tool-calls';
|
|
46
39
|
|
|
47
40
|
/** One block of the accumulated assistant message, in `parseMessageBlocks` shape. */
|
|
48
41
|
type MessageBlock =
|
|
49
42
|
| { type: 'text'; text: string }
|
|
50
43
|
| { type: 'thinking'; thinking: string }
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
interface OpenTool {
|
|
54
|
-
id: string;
|
|
55
|
-
name: string;
|
|
56
|
-
kind?: AcpToolKind;
|
|
57
|
-
title?: string;
|
|
58
|
-
status: AcpToolStatus;
|
|
59
|
-
rawOutput?: unknown;
|
|
60
|
-
/** `tool_call(Update).content` — where some agents put the diff/output. */
|
|
61
|
-
content?: unknown;
|
|
62
|
-
locations?: unknown;
|
|
63
|
-
startedAt: number;
|
|
64
|
-
}
|
|
44
|
+
| ToolCallBlock;
|
|
65
45
|
|
|
66
46
|
/** Per-session accumulator; one instance per live ACP session. */
|
|
67
47
|
export class AcpFrameMapper {
|
|
68
48
|
private blocks: MessageBlock[] = [];
|
|
69
49
|
private messageId: string | null = null;
|
|
70
|
-
|
|
50
|
+
/** When the turn was dispatched, the base for its duration. */
|
|
51
|
+
private turnStartedAt: number | null = null;
|
|
52
|
+
/** When the open message's first frame arrived, its timeline stamp. */
|
|
53
|
+
private openedAt: number | null = null;
|
|
54
|
+
private readonly tools = new AcpToolCalls({
|
|
55
|
+
pushBlock: (block) => this.blocks.push(block),
|
|
56
|
+
snapshot: () => this.snapshot(),
|
|
57
|
+
});
|
|
71
58
|
|
|
72
|
-
/** Forget per-turn state (an aborted run, a fresh load). */
|
|
73
|
-
reset(): void {
|
|
59
|
+
/** Forget per-turn state (an aborted run, a fresh load) and start its clock. */
|
|
60
|
+
reset(startedAt: number = Date.now()): void {
|
|
74
61
|
this.blocks = [];
|
|
75
62
|
this.messageId = null;
|
|
76
|
-
this.
|
|
63
|
+
this.openedAt = null;
|
|
64
|
+
this.turnStartedAt = startedAt;
|
|
65
|
+
this.tools.reset();
|
|
77
66
|
}
|
|
78
67
|
|
|
79
68
|
/** Tool calls still running — the driver closes them if the agent exits
|
|
80
69
|
* mid-turn, so no card is left spinning forever. */
|
|
81
70
|
openCalls(): string[] {
|
|
82
|
-
return
|
|
83
|
-
.filter((call) => call.status === 'pending' || call.status === 'in_progress')
|
|
84
|
-
.map((call) => call.id);
|
|
71
|
+
return this.tools.openCalls();
|
|
85
72
|
}
|
|
86
73
|
|
|
87
74
|
/**
|
|
@@ -97,14 +84,29 @@ export class AcpFrameMapper {
|
|
|
97
84
|
return this.appendChunk(update, 'text');
|
|
98
85
|
case 'agent_thought_chunk':
|
|
99
86
|
return this.appendChunk(update, 'thinking');
|
|
87
|
+
// v2 whole-message upserts: replace that message's content, keep tool blocks.
|
|
88
|
+
case 'agent_message':
|
|
89
|
+
return this.upsertMessage(update, 'text');
|
|
90
|
+
case 'agent_thought':
|
|
91
|
+
return this.upsertMessage(update, 'thinking');
|
|
92
|
+
case 'user_message':
|
|
100
93
|
case 'user_message_chunk':
|
|
101
94
|
// Live user chunks only arrive on replay/steering; the composer already
|
|
102
95
|
// drew the optimistic bubble, so this is a receipt, not a new row.
|
|
103
96
|
return [];
|
|
104
97
|
case 'tool_call':
|
|
105
|
-
return this.
|
|
98
|
+
return this.tools.open(update);
|
|
106
99
|
case 'tool_call_update':
|
|
107
|
-
return this.
|
|
100
|
+
return this.tools.patch(update);
|
|
101
|
+
case 'tool_call_content_chunk':
|
|
102
|
+
return this.tools.appendContent(update);
|
|
103
|
+
// v2's turn boundary is handled by `AcpTurns.onStateUpdate`, not mapped.
|
|
104
|
+
case 'state_update':
|
|
105
|
+
case 'terminal_update':
|
|
106
|
+
case 'terminal_output_chunk':
|
|
107
|
+
case 'compaction_update':
|
|
108
|
+
case 'compaction_summary_chunk':
|
|
109
|
+
return [];
|
|
108
110
|
case 'usage_update':
|
|
109
111
|
return this.usage(update);
|
|
110
112
|
case 'available_commands_update':
|
|
@@ -123,6 +125,9 @@ export class AcpFrameMapper {
|
|
|
123
125
|
// The spec defines it; no measured agent sends it. Forwarded so a future
|
|
124
126
|
// adapter lights the panel with no change here.
|
|
125
127
|
return [{ type: 'plan_updated', entries: update.entries ?? [] }];
|
|
128
|
+
case 'plan_update':
|
|
129
|
+
// v2 keyed plans; Kabmo's Todos panel renders one list.
|
|
130
|
+
return [{ type: 'plan_updated', entries: planEntries(update) }];
|
|
126
131
|
case 'notice':
|
|
127
132
|
return [{
|
|
128
133
|
type: 'notice',
|
|
@@ -140,9 +145,16 @@ export class AcpFrameMapper {
|
|
|
140
145
|
/** Close the open assistant row (turn end, abort, disconnect). */
|
|
141
146
|
closeMessage(): AgentEvent[] {
|
|
142
147
|
if (!this.messageId && this.blocks.length === 0) return [];
|
|
148
|
+
const completedAt = Date.now();
|
|
143
149
|
const message = this.snapshot();
|
|
150
|
+
const startedAt = this.turnStartedAt ?? this.openedAt;
|
|
151
|
+
if (startedAt !== null) {
|
|
152
|
+
message.completedAt = completedAt;
|
|
153
|
+
message.duration = Math.max(0, completedAt - startedAt);
|
|
154
|
+
}
|
|
144
155
|
this.blocks = [];
|
|
145
156
|
this.messageId = null;
|
|
157
|
+
this.openedAt = null;
|
|
146
158
|
return [{ type: 'message_end', message }];
|
|
147
159
|
}
|
|
148
160
|
|
|
@@ -158,9 +170,11 @@ export class AcpFrameMapper {
|
|
|
158
170
|
*/
|
|
159
171
|
private snapshot(): Record<string, unknown> {
|
|
160
172
|
const id = this.messageId ??= `acp-${crypto.randomUUID()}`;
|
|
173
|
+
const timestamp = this.openedAt ??= Date.now();
|
|
161
174
|
return {
|
|
162
175
|
role: 'assistant',
|
|
163
176
|
id,
|
|
177
|
+
timestamp,
|
|
164
178
|
content: this.blocks.map((block) => ({ ...block })),
|
|
165
179
|
};
|
|
166
180
|
}
|
|
@@ -194,134 +208,33 @@ export class AcpFrameMapper {
|
|
|
194
208
|
return frames;
|
|
195
209
|
}
|
|
196
210
|
|
|
197
|
-
private openTool(update: Record<string, unknown>): AgentEvent[] {
|
|
198
|
-
const toolCallId = typeof update.toolCallId === 'string' ? update.toolCallId : '';
|
|
199
|
-
if (!toolCallId) return [];
|
|
200
|
-
const name = typeof update.name === 'string' && update.name
|
|
201
|
-
? update.name
|
|
202
|
-
: typeof update.title === 'string' && update.title
|
|
203
|
-
? update.title
|
|
204
|
-
: 'tool';
|
|
205
|
-
const kind = typeof update.kind === 'string' ? (update.kind as AcpToolKind) : undefined;
|
|
206
|
-
const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : 'pending';
|
|
207
|
-
// A specific kind is authoritative. `other`/absent is only an explicit type
|
|
208
|
-
// when the name is one the renderers know; otherwise the shared parser's
|
|
209
|
-
// own inference from the name is better informed than a forced `read`.
|
|
210
|
-
const toolType = kind !== undefined && kind !== 'other'
|
|
211
|
-
? toolTypeFor(kind, name)
|
|
212
|
-
: isKnownToolName(name) ? toolTypeFor(kind, name) : undefined;
|
|
213
|
-
const rawInput = update.rawInput;
|
|
214
|
-
const args = rawInput && typeof rawInput === 'object' && !Array.isArray(rawInput)
|
|
215
|
-
? Object.fromEntries(Object.entries(rawInput))
|
|
216
|
-
: undefined;
|
|
217
|
-
|
|
218
|
-
// The card is drawn from the message block, so opening a call means adding
|
|
219
|
-
// the block and re-emitting the message — not emitting a separate card row.
|
|
220
|
-
// `toolType` travels with the block: the shared parser's name inference
|
|
221
|
-
// cannot know that ACP `kind:"execute"` means bash when the name is `Shell`.
|
|
222
|
-
this.blocks.push({
|
|
223
|
-
type: 'toolCall',
|
|
224
|
-
id: toolCallId,
|
|
225
|
-
name,
|
|
226
|
-
...(args ? { arguments: args } : {}),
|
|
227
|
-
...(kind ? { toolKind: kind } : {}),
|
|
228
|
-
...(toolType ? { toolType } : {}),
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
const frames: AgentEvent[] = [
|
|
232
|
-
{ type: 'message_update', message: this.snapshot(), assistantMessageEvent: { type: 'toolcall_start' } },
|
|
233
|
-
{
|
|
234
|
-
type: 'tool_execution_start',
|
|
235
|
-
toolCallId,
|
|
236
|
-
toolName: name,
|
|
237
|
-
...(toolType ? { toolType } : {}),
|
|
238
|
-
...(args ? { args } : {}),
|
|
239
|
-
...(typeof update.title === 'string' ? { intent: update.title } : {}),
|
|
240
|
-
...(acpToolTarget(update.locations, rawInput) ? { target: acpToolTarget(update.locations, rawInput) } : {}),
|
|
241
|
-
},
|
|
242
|
-
];
|
|
243
|
-
|
|
244
|
-
// Some agents announce a call ONLY once it is finished (`tool_call` with
|
|
245
|
-
// `status:"completed"` and no later update). Leaving it in the open map
|
|
246
|
-
// meant the turn's cleanup closed it as an ERROR, overwriting a success.
|
|
247
|
-
if (status === 'completed' || status === 'failed') {
|
|
248
|
-
frames.push({
|
|
249
|
-
type: 'tool_execution_end',
|
|
250
|
-
toolCallId,
|
|
251
|
-
toolName: name,
|
|
252
|
-
result: update.rawOutput ?? (update.content === undefined ? undefined : { content: update.content }),
|
|
253
|
-
isError: status === 'failed',
|
|
254
|
-
details: acpToolDetails(update.rawOutput) ?? acpContentDetails(update.content),
|
|
255
|
-
output: acpToolOutput(update.rawOutput) || acpContentText(update.content),
|
|
256
|
-
});
|
|
257
|
-
} else {
|
|
258
|
-
this.open.set(toolCallId, {
|
|
259
|
-
id: toolCallId,
|
|
260
|
-
name,
|
|
261
|
-
kind,
|
|
262
|
-
title: typeof update.title === 'string' ? update.title : undefined,
|
|
263
|
-
status,
|
|
264
|
-
rawOutput: update.rawOutput,
|
|
265
|
-
content: update.content,
|
|
266
|
-
locations: update.locations,
|
|
267
|
-
startedAt: Date.now(),
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
return frames;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
211
|
/**
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
212
|
+
* v2 whole-message upsert: replace that message's blocks of one kind.
|
|
213
|
+
*
|
|
214
|
+
* Tool-call blocks are entities of their own in v2; they stay in place, and
|
|
215
|
+
* the text/thinking content for the message is replaced wholesale.
|
|
278
216
|
*/
|
|
279
|
-
private
|
|
280
|
-
const
|
|
281
|
-
if (!
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
if (typeof update.title === 'string') existing.title = update.title;
|
|
291
|
-
const status = typeof update.status === 'string' ? (update.status as AcpToolStatus) : existing.status;
|
|
292
|
-
existing.status = status;
|
|
293
|
-
|
|
294
|
-
// Some agents report the result as `content` blocks instead of `rawOutput`;
|
|
295
|
-
// the diff block only becomes visible through the details bridge.
|
|
296
|
-
const result = existing.rawOutput ?? (existing.content === undefined ? undefined : { content: existing.content });
|
|
297
|
-
const output = acpToolOutput(existing.rawOutput) || acpContentText(existing.content);
|
|
298
|
-
const details = acpToolDetails(existing.rawOutput) ?? acpContentDetails(existing.content);
|
|
299
|
-
|
|
300
|
-
if (status === 'completed' || status === 'failed') {
|
|
301
|
-
const failed = status === 'failed';
|
|
302
|
-
this.open.delete(toolCallId);
|
|
303
|
-
return [{
|
|
304
|
-
type: 'tool_execution_end',
|
|
305
|
-
toolCallId,
|
|
306
|
-
toolName: existing.name,
|
|
307
|
-
result,
|
|
308
|
-
isError: failed,
|
|
309
|
-
details,
|
|
310
|
-
durationMs: Math.max(0, Date.now() - existing.startedAt),
|
|
311
|
-
output,
|
|
312
|
-
}];
|
|
217
|
+
private upsertMessage(update: Record<string, unknown>, kind: 'text' | 'thinking'): AgentEvent[] {
|
|
218
|
+
const messageId = typeof update.messageId === 'string' ? update.messageId : '';
|
|
219
|
+
if (!messageId || !('content' in update)) return [];
|
|
220
|
+
const frames: AgentEvent[] = [];
|
|
221
|
+
if (this.messageId && this.messageId !== messageId) frames.push(...this.closeMessage());
|
|
222
|
+
this.messageId = messageId;
|
|
223
|
+
const raw = update.content;
|
|
224
|
+
const text = raw === null || (Array.isArray(raw) && raw.length === 0) ? '' : acpContentText(raw);
|
|
225
|
+
this.blocks = this.blocks.filter((block) => block.type !== kind);
|
|
226
|
+
if (text) {
|
|
227
|
+
this.blocks.push(kind === 'text' ? { type: 'text', text } : { type: 'thinking', thinking: text });
|
|
313
228
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
output,
|
|
324
|
-
}];
|
|
229
|
+
frames.push({
|
|
230
|
+
type: 'message_update',
|
|
231
|
+
message: this.snapshot(),
|
|
232
|
+
assistantMessageEvent: {
|
|
233
|
+
type: kind === 'text' ? 'text_delta' : 'thinking_delta',
|
|
234
|
+
delta: text,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
return frames;
|
|
325
238
|
}
|
|
326
239
|
|
|
327
240
|
private usage(update: Record<string, unknown>): AgentEvent[] {
|