@downcity/agent 1.1.217 → 1.1.224
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/bin/agent/local/Agent.d.ts +1 -34
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +1 -44
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +35 -2
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentSessions.d.ts +6 -0
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessions.js +43 -4
- package/bin/agent/local/services/AgentSessions.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +1 -35
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +1 -37
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +26 -41
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +75 -107
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +15 -27
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +10 -21
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +24 -46
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +10 -20
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +10 -16
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +2 -2
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/types/SessionHistoryPaths.d.ts +1 -1
- package/bin/executor/types/SessionRecords.d.ts +2 -0
- package/bin/executor/types/SessionRecords.d.ts.map +1 -1
- package/bin/executor/types/SessionRecords.js.map +1 -1
- package/bin/index.d.ts +6 -3
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -0
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +12 -34
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +31 -70
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +22 -4
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +95 -21
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +49 -18
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts +51 -0
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -0
- package/bin/session/recorder/JsonlSessionMessageStore.js +231 -0
- package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -0
- package/bin/session/recorder/SessionMessageCodec.d.ts +20 -0
- package/bin/session/recorder/SessionMessageCodec.d.ts.map +1 -0
- package/bin/session/recorder/SessionMessageCodec.js +257 -0
- package/bin/session/recorder/SessionMessageCodec.js.map +1 -0
- package/bin/session/recorder/SessionRecorder.d.ts +186 -0
- package/bin/session/recorder/SessionRecorder.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorder.js +655 -0
- package/bin/session/recorder/SessionRecorder.js.map +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.d.ts +18 -0
- package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorderCompaction.js +142 -0
- package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +66 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.js +195 -0
- package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -0
- package/bin/session/runtime/SessionEventHub.d.ts +12 -5
- package/bin/session/runtime/SessionEventHub.d.ts.map +1 -1
- package/bin/session/runtime/SessionEventHub.js +11 -6
- package/bin/session/runtime/SessionEventHub.js.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +9 -15
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +48 -30
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +9 -5
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +138 -74
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +6 -7
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +84 -60
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +8 -3
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +10 -5
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +1 -1
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +2 -2
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts +6 -0
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/Persistence.js +7 -0
- package/bin/session/storage/Persistence.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +3 -3
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +2 -2
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +15 -5
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +48 -61
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +5 -4
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/session/SessionApproval.d.ts +97 -0
- package/bin/types/session/SessionApproval.d.ts.map +1 -0
- package/bin/types/session/SessionApproval.js +7 -0
- package/bin/types/session/SessionApproval.js.map +1 -0
- package/bin/types/session/SessionMessage.d.ts +223 -0
- package/bin/types/session/SessionMessage.d.ts.map +1 -0
- package/bin/types/session/SessionMessage.js +8 -0
- package/bin/types/session/SessionMessage.js.map +1 -0
- package/bin/types/session/SessionMutation.d.ts +116 -0
- package/bin/types/session/SessionMutation.d.ts.map +1 -0
- package/bin/types/session/SessionMutation.js +19 -0
- package/bin/types/session/SessionMutation.js.map +1 -0
- package/bin/types/session/SessionOptions.d.ts +9 -0
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/package.json +3 -3
- package/scripts/agent-env.test.mjs +4 -4
- package/scripts/remote-session-reconnect.test.mjs +7 -3
- package/scripts/session-action-message.test.mjs +98 -27
- package/scripts/session-history-inflight.test.mjs +2 -2
- package/scripts/session-list-title.test.mjs +6 -19
- package/scripts/session-prompt-runtime.test.mjs +7 -19
- package/scripts/session-recorder.test.mjs +199 -0
- package/scripts/session-title-event.test.mjs +10 -18
- package/src/agent/local/Agent.ts +1 -55
- package/src/agent/local/services/AgentAssemblyService.ts +39 -3
- package/src/agent/local/services/AgentSessions.ts +48 -3
- package/src/agent/remote/RemoteAgent.ts +1 -54
- package/src/agent/remote/RemoteSession.ts +106 -136
- package/src/agent/remote/RemoteTransport.ts +30 -30
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +52 -77
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +30 -34
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +2 -2
- package/src/executor/types/SessionHistoryPaths.ts +1 -1
- package/src/executor/types/SessionRecords.ts +2 -0
- package/src/index.ts +36 -10
- package/src/rpc/Client.ts +58 -95
- package/src/session/Session.ts +128 -37
- package/src/session/browse/Browse.ts +51 -22
- package/src/session/recorder/JsonlSessionMessageStore.ts +246 -0
- package/src/session/recorder/SessionMessageCodec.ts +284 -0
- package/src/session/recorder/SessionRecorder.ts +871 -0
- package/src/session/recorder/SessionRecorderCompaction.ts +188 -0
- package/src/session/recorder/SessionRecorderHistoryStore.ts +276 -0
- package/src/session/runtime/SessionEventHub.ts +25 -12
- package/src/session/runtime/SessionPromptRuntime.ts +60 -43
- package/src/session/services/SessionStateService.ts +159 -86
- package/src/session/services/SessionTurnService.ts +91 -73
- package/src/session/services/SessionViewService.ts +25 -13
- package/src/session/storage/Paths.ts +2 -2
- package/src/session/storage/Persistence.ts +13 -0
- package/src/session/storage/RuntimeSessionPort.ts +8 -9
- package/src/types/agent/SessionActor.ts +31 -8
- package/src/types/rpc/RpcProtocol.ts +44 -67
- package/src/types/runtime/agent/AgentContext.ts +9 -7
- package/src/types/session/SessionApproval.ts +108 -0
- package/src/types/session/SessionMessage.ts +253 -0
- package/src/types/session/SessionMutation.ts +141 -0
- package/src/types/session/SessionOptions.ts +25 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/session/SessionEventMapper.d.ts +0 -32
- package/bin/session/SessionEventMapper.d.ts.map +0 -1
- package/bin/session/SessionEventMapper.js +0 -131
- package/bin/session/SessionEventMapper.js.map +0 -1
- package/bin/types/sdk/AgentSessionEvent.d.ts +0 -302
- package/bin/types/sdk/AgentSessionEvent.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionEvent.js +0 -9
- package/bin/types/sdk/AgentSessionEvent.js.map +0 -1
- package/bin/types/sdk/InternalUiChunkEvent.d.ts +0 -100
- package/bin/types/sdk/InternalUiChunkEvent.d.ts.map +0 -1
- package/bin/types/sdk/InternalUiChunkEvent.js +0 -9
- package/bin/types/sdk/InternalUiChunkEvent.js.map +0 -1
- package/scripts/session-history-archive.test.mjs +0 -188
- package/src/session/SessionEventMapper.ts +0 -148
- package/src/types/sdk/AgentSessionEvent.ts +0 -370
- package/src/types/sdk/InternalUiChunkEvent.ts +0 -108
|
@@ -15,18 +15,20 @@ import type {
|
|
|
15
15
|
AgentArchiveSessionsResult,
|
|
16
16
|
AgentCleanArchiveResult,
|
|
17
17
|
AgentSessionForkInput,
|
|
18
|
-
AgentSessionRecordsInput,
|
|
19
|
-
AgentSessionRecordsPage,
|
|
20
18
|
AgentSessionInfo,
|
|
21
19
|
AgentSessionSummaryPage,
|
|
22
20
|
AgentSessionSystemSnapshot,
|
|
23
21
|
AgentSessionSetInput,
|
|
24
22
|
} from "@/types/agent/SessionTypes.js";
|
|
23
|
+
import type {
|
|
24
|
+
ListSessionMessagesInput,
|
|
25
|
+
SessionMessagePage,
|
|
26
|
+
} from "@/types/session/SessionMessage.js";
|
|
25
27
|
import type {
|
|
26
28
|
RemoteAgentPluginActionInput,
|
|
27
29
|
RemoteAgentPluginActionResult,
|
|
28
30
|
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
29
|
-
import type {
|
|
31
|
+
import type { SessionMutation } from "@/types/session/SessionMutation.js";
|
|
30
32
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
31
33
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
32
34
|
import type {
|
|
@@ -34,13 +36,12 @@ import type {
|
|
|
34
36
|
TransportSubscription,
|
|
35
37
|
} from "@/agent/remote/RemoteTransport.js";
|
|
36
38
|
import type {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} from "@downcity/shell";
|
|
39
|
+
ResolveSessionApprovalInput,
|
|
40
|
+
SessionApproval,
|
|
41
|
+
SessionApprovalModeSnapshot,
|
|
42
|
+
SessionApprovalResult,
|
|
43
|
+
SetSessionApprovalModeInput,
|
|
44
|
+
} from "@/types/session/SessionApproval.js";
|
|
44
45
|
|
|
45
46
|
type SdkEventsReadyFrame = {
|
|
46
47
|
/** SDK HTTP events 连接内部 ready 标记。 */
|
|
@@ -168,7 +169,7 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
168
169
|
async subscribe(params: {
|
|
169
170
|
session_id: string;
|
|
170
171
|
on_ready: () => void;
|
|
171
|
-
on_event: (event:
|
|
172
|
+
on_event: (event: SessionMutation) => void;
|
|
172
173
|
on_close: (error?: unknown) => void;
|
|
173
174
|
}): Promise<TransportSubscription> {
|
|
174
175
|
const abort_controller = new AbortController();
|
|
@@ -213,32 +214,36 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
213
214
|
};
|
|
214
215
|
}
|
|
215
216
|
|
|
216
|
-
async
|
|
217
|
+
async messages(
|
|
217
218
|
session_id: string,
|
|
218
|
-
input?:
|
|
219
|
-
): Promise<
|
|
219
|
+
input?: ListSessionMessagesInput,
|
|
220
|
+
): Promise<SessionMessagePage> {
|
|
220
221
|
const query = new URLSearchParams();
|
|
221
222
|
if (input?.limit !== undefined) query.set("limit", String(input.limit));
|
|
222
223
|
if (input?.cursor) query.set("cursor", input.cursor);
|
|
223
|
-
if (input?.
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
if (input?.before_sequence !== undefined) {
|
|
225
|
+
query.set("before_sequence", String(input.before_sequence));
|
|
226
|
+
}
|
|
227
|
+
if (input?.include_internal) query.set("include_internal", "true");
|
|
228
|
+
if (input?.through_sequence !== undefined) {
|
|
229
|
+
query.set("through_sequence", String(input.through_sequence));
|
|
230
|
+
}
|
|
226
231
|
const payload = await read_http_json<{
|
|
227
232
|
success?: boolean;
|
|
228
233
|
error?: string;
|
|
229
|
-
|
|
234
|
+
messages?: SessionMessagePage;
|
|
230
235
|
}>(
|
|
231
|
-
`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/
|
|
236
|
+
`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/messages${
|
|
232
237
|
query.size > 0 ? `?${query.toString()}` : ""
|
|
233
238
|
}`,
|
|
234
239
|
{
|
|
235
240
|
headers: this.headers(),
|
|
236
241
|
},
|
|
237
242
|
);
|
|
238
|
-
if (!payload.success || !payload.
|
|
239
|
-
throw new Error(String(payload.error || "Remote session
|
|
243
|
+
if (!payload.success || !payload.messages || !Array.isArray(payload.messages.items)) {
|
|
244
|
+
throw new Error(String(payload.error || "Remote session messages failed"));
|
|
240
245
|
}
|
|
241
|
-
return payload.
|
|
246
|
+
return payload.messages;
|
|
242
247
|
}
|
|
243
248
|
|
|
244
249
|
async system(session_id: string): Promise<AgentSessionSystemSnapshot> {
|
|
@@ -401,12 +406,12 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
401
406
|
return payload;
|
|
402
407
|
}
|
|
403
408
|
|
|
404
|
-
async approvals(): Promise<
|
|
409
|
+
async approvals(session_id: string): Promise<SessionApproval[]> {
|
|
405
410
|
const payload = await read_http_json<{
|
|
406
411
|
success?: boolean;
|
|
407
412
|
error?: string;
|
|
408
|
-
approvals?:
|
|
409
|
-
}>(`${this.base_url}/api/
|
|
413
|
+
approvals?: SessionApproval[];
|
|
414
|
+
}>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approvals`, {
|
|
410
415
|
headers: this.headers(),
|
|
411
416
|
});
|
|
412
417
|
if (!payload.success || !Array.isArray(payload.approvals)) {
|
|
@@ -415,28 +420,13 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
415
420
|
return payload.approvals;
|
|
416
421
|
}
|
|
417
422
|
|
|
418
|
-
async
|
|
419
|
-
const payload = await read_http_json<{
|
|
420
|
-
success?: boolean;
|
|
421
|
-
error?: string;
|
|
422
|
-
modes?: ShellApprovalModeOption[];
|
|
423
|
-
}>(`${this.base_url}/api/shell/approval-modes`, {
|
|
424
|
-
headers: this.headers(),
|
|
425
|
-
});
|
|
426
|
-
if (!payload.success || !Array.isArray(payload.modes)) {
|
|
427
|
-
throw new Error(String(payload.error || "Remote shell approval modes failed"));
|
|
428
|
-
}
|
|
429
|
-
return payload.modes;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
|
|
433
|
-
const session_id = String(input.session_id || "").trim();
|
|
423
|
+
async approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
|
|
434
424
|
const payload = await read_http_json<{
|
|
435
425
|
success?: boolean;
|
|
436
426
|
error?: string;
|
|
437
427
|
session_id?: string;
|
|
438
|
-
mode?:
|
|
439
|
-
}>(`${this.base_url}/api/
|
|
428
|
+
mode?: SessionApprovalModeSnapshot["mode"];
|
|
429
|
+
}>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval-mode`, {
|
|
440
430
|
headers: this.headers(),
|
|
441
431
|
});
|
|
442
432
|
if (!payload.success || !payload.session_id || !payload.mode) {
|
|
@@ -448,18 +438,19 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
448
438
|
};
|
|
449
439
|
}
|
|
450
440
|
|
|
451
|
-
async set_approval_mode(
|
|
452
|
-
session_id: string
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const payload = await read_http_json<
|
|
441
|
+
async set_approval_mode(
|
|
442
|
+
session_id: string,
|
|
443
|
+
input: SetSessionApprovalModeInput,
|
|
444
|
+
): Promise<SessionApprovalModeSnapshot> {
|
|
445
|
+
const payload = await read_http_json<SessionApprovalModeSnapshot & {
|
|
446
|
+
success?: boolean;
|
|
456
447
|
error?: string;
|
|
457
|
-
}>(`${this.base_url}/api/
|
|
448
|
+
}>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval-mode`, {
|
|
458
449
|
method: "POST",
|
|
459
450
|
headers: this.headers({
|
|
460
451
|
"Content-Type": "application/json",
|
|
461
452
|
}),
|
|
462
|
-
body: JSON.stringify(input),
|
|
453
|
+
body: JSON.stringify({ mode: input.mode }),
|
|
463
454
|
});
|
|
464
455
|
if (payload.success !== true) {
|
|
465
456
|
throw new Error(String(payload.error || "Remote shell approval mode update failed"));
|
|
@@ -467,29 +458,21 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
467
458
|
return payload;
|
|
468
459
|
}
|
|
469
460
|
|
|
470
|
-
async
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return await this.run_shell_decision("deny", input.approval_id);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
private async run_shell_decision(
|
|
479
|
-
action: "approve" | "deny",
|
|
480
|
-
approval_id: string,
|
|
481
|
-
): Promise<ShellApprovalDecisionResult> {
|
|
482
|
-
const payload = await read_http_json<ShellApprovalDecisionResult & {
|
|
461
|
+
async resolve_approval(
|
|
462
|
+
session_id: string,
|
|
463
|
+
input: ResolveSessionApprovalInput,
|
|
464
|
+
): Promise<SessionApprovalResult> {
|
|
465
|
+
const payload = await read_http_json<SessionApprovalResult & {
|
|
483
466
|
error?: string;
|
|
484
|
-
}>(`${this.base_url}/api/
|
|
467
|
+
}>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval`, {
|
|
485
468
|
method: "POST",
|
|
486
469
|
headers: this.headers({
|
|
487
470
|
"Content-Type": "application/json",
|
|
488
471
|
}),
|
|
489
|
-
body: JSON.stringify(
|
|
472
|
+
body: JSON.stringify(input),
|
|
490
473
|
});
|
|
491
474
|
if (typeof payload.success !== "boolean") {
|
|
492
|
-
throw new Error(String(payload.error ||
|
|
475
|
+
throw new Error(String(payload.error || "Remote session approval failed"));
|
|
493
476
|
}
|
|
494
477
|
return payload;
|
|
495
478
|
}
|
|
@@ -523,7 +506,7 @@ async function consume_http_event_stream(params: {
|
|
|
523
506
|
abort_controller: AbortController;
|
|
524
507
|
on_ready: () => void;
|
|
525
508
|
on_ready_error: (error: unknown) => void;
|
|
526
|
-
on_event: (event:
|
|
509
|
+
on_event: (event: SessionMutation) => void;
|
|
527
510
|
}): Promise<unknown | undefined> {
|
|
528
511
|
const decoder = new TextDecoder();
|
|
529
512
|
const reader = params.body.getReader();
|
|
@@ -546,7 +529,7 @@ async function consume_http_event_stream(params: {
|
|
|
546
529
|
ready_resolved = true;
|
|
547
530
|
params.on_ready();
|
|
548
531
|
} else {
|
|
549
|
-
params.on_event(value as
|
|
532
|
+
params.on_event(value as SessionMutation);
|
|
550
533
|
}
|
|
551
534
|
}
|
|
552
535
|
newline_index = buffered.indexOf("\n");
|
|
@@ -560,7 +543,7 @@ async function consume_http_event_stream(params: {
|
|
|
560
543
|
ready_resolved = true;
|
|
561
544
|
params.on_ready();
|
|
562
545
|
} else {
|
|
563
|
-
params.on_event(value as
|
|
546
|
+
params.on_event(value as SessionMutation);
|
|
564
547
|
}
|
|
565
548
|
}
|
|
566
549
|
|
|
@@ -570,10 +553,6 @@ async function consume_http_event_stream(params: {
|
|
|
570
553
|
params.on_ready_error(error);
|
|
571
554
|
throw error;
|
|
572
555
|
}
|
|
573
|
-
params.on_event({
|
|
574
|
-
type: "error",
|
|
575
|
-
message: "Remote session events connection closed",
|
|
576
|
-
});
|
|
577
556
|
}
|
|
578
557
|
} catch (error) {
|
|
579
558
|
close_error = error;
|
|
@@ -581,10 +560,6 @@ async function consume_http_event_stream(params: {
|
|
|
581
560
|
if (!ready_resolved) {
|
|
582
561
|
params.on_ready_error(error);
|
|
583
562
|
}
|
|
584
|
-
params.on_event({
|
|
585
|
-
type: "error",
|
|
586
|
-
message: error instanceof Error ? error.message : String(error),
|
|
587
|
-
});
|
|
588
563
|
}
|
|
589
564
|
} finally {
|
|
590
565
|
try {
|
|
@@ -15,18 +15,20 @@ import type {
|
|
|
15
15
|
AgentArchiveSessionsResult,
|
|
16
16
|
AgentCleanArchiveResult,
|
|
17
17
|
AgentSessionForkInput,
|
|
18
|
-
AgentSessionRecordsInput,
|
|
19
|
-
AgentSessionRecordsPage,
|
|
20
18
|
AgentSessionInfo,
|
|
21
19
|
AgentSessionSummaryPage,
|
|
22
20
|
AgentSessionSystemSnapshot,
|
|
23
21
|
AgentSessionSetInput,
|
|
24
22
|
} from "@/types/agent/SessionTypes.js";
|
|
23
|
+
import type {
|
|
24
|
+
ListSessionMessagesInput,
|
|
25
|
+
SessionMessagePage,
|
|
26
|
+
} from "@/types/session/SessionMessage.js";
|
|
25
27
|
import type {
|
|
26
28
|
RemoteAgentPluginActionInput,
|
|
27
29
|
RemoteAgentPluginActionResult,
|
|
28
30
|
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
29
|
-
import type {
|
|
31
|
+
import type { SessionMutation } from "@/types/session/SessionMutation.js";
|
|
30
32
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
31
33
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
32
34
|
import { RpcClient, parse_rpc_url } from "@/rpc/Client.js";
|
|
@@ -35,13 +37,12 @@ import type {
|
|
|
35
37
|
TransportSubscription,
|
|
36
38
|
} from "@/agent/remote/RemoteTransport.js";
|
|
37
39
|
import type {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} from "@downcity/shell";
|
|
40
|
+
ResolveSessionApprovalInput,
|
|
41
|
+
SessionApproval,
|
|
42
|
+
SessionApprovalModeSnapshot,
|
|
43
|
+
SessionApprovalResult,
|
|
44
|
+
SetSessionApprovalModeInput,
|
|
45
|
+
} from "@/types/session/SessionApproval.js";
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* 本机 RPC transport。
|
|
@@ -85,7 +86,7 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
85
86
|
async subscribe(params: {
|
|
86
87
|
session_id: string;
|
|
87
88
|
on_ready: () => void;
|
|
88
|
-
on_event: (event:
|
|
89
|
+
on_event: (event: SessionMutation) => void;
|
|
89
90
|
on_close: (error?: unknown) => void;
|
|
90
91
|
}): Promise<TransportSubscription> {
|
|
91
92
|
const subscription = await this.client.subscribe_session({
|
|
@@ -101,11 +102,11 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
async
|
|
105
|
+
async messages(
|
|
105
106
|
session_id: string,
|
|
106
|
-
input?:
|
|
107
|
-
): Promise<
|
|
108
|
-
return await this.client.
|
|
107
|
+
input?: ListSessionMessagesInput,
|
|
108
|
+
): Promise<SessionMessagePage> {
|
|
109
|
+
return await this.client.get_session_messages({
|
|
109
110
|
session_id,
|
|
110
111
|
input,
|
|
111
112
|
});
|
|
@@ -159,31 +160,26 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
159
160
|
});
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
async approvals(): Promise<
|
|
163
|
-
return await this.client.
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async approval_modes(): Promise<ShellApprovalModeOption[]> {
|
|
167
|
-
return await this.client.list_shell_approval_modes();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
|
|
171
|
-
return await this.client.get_shell_approval_mode(input.session_id);
|
|
163
|
+
async approvals(session_id: string): Promise<SessionApproval[]> {
|
|
164
|
+
return await this.client.get_session_approvals(session_id);
|
|
172
165
|
}
|
|
173
166
|
|
|
174
|
-
async
|
|
175
|
-
session_id
|
|
176
|
-
mode: ShellApprovalMode;
|
|
177
|
-
}): Promise<ShellApprovalModeUpdateResult> {
|
|
178
|
-
return await this.client.set_shell_approval_mode(input);
|
|
167
|
+
async approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
|
|
168
|
+
return await this.client.get_session_approval_mode(session_id);
|
|
179
169
|
}
|
|
180
170
|
|
|
181
|
-
async
|
|
182
|
-
|
|
171
|
+
async set_approval_mode(
|
|
172
|
+
session_id: string,
|
|
173
|
+
input: SetSessionApprovalModeInput,
|
|
174
|
+
): Promise<SessionApprovalModeSnapshot> {
|
|
175
|
+
return await this.client.set_session_approval_mode(session_id, input);
|
|
183
176
|
}
|
|
184
177
|
|
|
185
|
-
async
|
|
186
|
-
|
|
178
|
+
async resolve_approval(
|
|
179
|
+
session_id: string,
|
|
180
|
+
input: ResolveSessionApprovalInput,
|
|
181
|
+
): Promise<SessionApprovalResult> {
|
|
182
|
+
return await this.client.resolve_session_approval(session_id, input);
|
|
187
183
|
}
|
|
188
184
|
|
|
189
185
|
async close(): Promise<void> {
|
|
@@ -197,9 +197,9 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
197
197
|
private getInflightFilePath(): string {
|
|
198
198
|
if (this.overrideInflightFilePath) return this.overrideInflightFilePath;
|
|
199
199
|
if (this.overrideMessagesDirPath) {
|
|
200
|
-
return path.join(this.overrideMessagesDirPath, "
|
|
200
|
+
return path.join(this.overrideMessagesDirPath, "assistant_message.json");
|
|
201
201
|
}
|
|
202
|
-
return path.join(this.getMessagesDirPath(), "
|
|
202
|
+
return path.join(this.getMessagesDirPath(), "assistant_message.json");
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
private getLockFilePath(): string {
|
package/src/index.ts
CHANGED
|
@@ -27,9 +27,6 @@ export type {
|
|
|
27
27
|
AgentListSessionsInput,
|
|
28
28
|
AgentSessionConfigSnapshot,
|
|
29
29
|
AgentSessionForkInput,
|
|
30
|
-
AgentSessionRecordsInput,
|
|
31
|
-
AgentSessionRecordsPage,
|
|
32
|
-
AgentSessionRecordsView,
|
|
33
30
|
AgentSessionInfo,
|
|
34
31
|
AgentSessionSetInput,
|
|
35
32
|
AgentSessionSummary,
|
|
@@ -38,8 +35,42 @@ export type {
|
|
|
38
35
|
AgentSessionSystemBlockSource,
|
|
39
36
|
AgentSessionSystemSessionInfo,
|
|
40
37
|
AgentSessionSystemSnapshot,
|
|
41
|
-
AgentSessionTimelineEvent,
|
|
42
38
|
} from "./types/agent/SessionTypes.js";
|
|
39
|
+
export type {
|
|
40
|
+
ListSessionMessagesInput,
|
|
41
|
+
SessionActionMessage,
|
|
42
|
+
SessionAssistantMessage,
|
|
43
|
+
SessionAssistantMessagePart,
|
|
44
|
+
SessionAssistantToolPart,
|
|
45
|
+
SessionErrorMessage,
|
|
46
|
+
SessionMessage,
|
|
47
|
+
SessionMessagePage,
|
|
48
|
+
SessionUserMessage,
|
|
49
|
+
SessionUserMessagePart,
|
|
50
|
+
} from "./types/session/SessionMessage.js";
|
|
51
|
+
export {
|
|
52
|
+
is_session_mutation,
|
|
53
|
+
} from "./types/session/SessionMutation.js";
|
|
54
|
+
export type {
|
|
55
|
+
SessionDeltaMutation,
|
|
56
|
+
SessionMessageMutation,
|
|
57
|
+
SessionMutation,
|
|
58
|
+
SessionMutationReply,
|
|
59
|
+
SessionMutationSubscriber,
|
|
60
|
+
SessionMutationUnsubscribe,
|
|
61
|
+
SessionPartMutation,
|
|
62
|
+
SessionStateMutation,
|
|
63
|
+
SessionTurnMutation,
|
|
64
|
+
} from "./types/session/SessionMutation.js";
|
|
65
|
+
export type {
|
|
66
|
+
ResolveSessionApprovalInput,
|
|
67
|
+
SessionApproval,
|
|
68
|
+
SessionApprovalDecision,
|
|
69
|
+
SessionApprovalMode,
|
|
70
|
+
SessionApprovalModeSnapshot,
|
|
71
|
+
SessionApprovalResult,
|
|
72
|
+
SetSessionApprovalModeInput,
|
|
73
|
+
} from "./types/session/SessionApproval.js";
|
|
43
74
|
export type {
|
|
44
75
|
AgentOptions,
|
|
45
76
|
AgentSessionConstructor,
|
|
@@ -56,18 +87,13 @@ export type {
|
|
|
56
87
|
RemoteAgentPluginActionInput,
|
|
57
88
|
RemoteAgentPluginActionResult,
|
|
58
89
|
} from "./types/agent/RemoteAgentPluginAction.js";
|
|
59
|
-
export type {
|
|
60
|
-
AgentSessionEvent,
|
|
61
|
-
AgentSessionSubscriber,
|
|
62
|
-
AgentSessionUnsubscribe,
|
|
63
|
-
} from "./types/sdk/AgentSessionEvent.js";
|
|
64
90
|
export type {
|
|
65
91
|
AgentSessionActionCallback,
|
|
66
92
|
AgentSessionActionEvent,
|
|
67
93
|
AgentSessionActionRecord,
|
|
68
94
|
AgentSessionActionState,
|
|
69
95
|
} from "./types/sdk/AgentSessionAction.js";
|
|
70
|
-
export type { AgentSessionPromptInput
|
|
96
|
+
export type { AgentSessionPromptInput } from "./types/sdk/AgentSessionPrompt.js";
|
|
71
97
|
export type { AgentSessionStopResult } from "./types/sdk/AgentSessionStop.js";
|
|
72
98
|
export type {
|
|
73
99
|
AgentSessionTurnHandle,
|