@downcity/agent 1.1.199 → 1.1.202
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 +3 -7
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +14 -19
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/{AgentSessionManager.d.ts → AgentSessions.d.ts} +12 -17
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -0
- package/bin/agent/local/services/{AgentSessionManager.js → AgentSessions.js} +11 -26
- package/bin/agent/local/services/AgentSessions.js.map +1 -0
- package/bin/agent/remote/RemoteAgent.d.ts +2 -9
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +40 -22
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +5 -5
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +5 -3
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +2 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +2 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +5 -5
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +2 -2
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +2 -2
- package/bin/executor/Executor.d.ts +7 -7
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +41 -33
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/SessionRunScope.d.ts +1 -1
- package/bin/executor/SessionRunScope.d.ts.map +1 -1
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts +5 -5
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +4 -5
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +73 -40
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts +27 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts.map +1 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js +181 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js.map +1 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +45 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +1 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +144 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +1 -0
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +3 -3
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +1 -1
- package/bin/executor/composer/context/SessionContextComposer.d.ts +3 -3
- package/bin/executor/composer/context/SessionContextComposer.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryComposer.d.ts +2 -2
- package/bin/executor/composer/history/SessionHistoryComposer.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts +5 -5
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.js +6 -6
- package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts +2 -2
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts.map +1 -1
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js +5 -4
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +5 -5
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts +4 -4
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +3 -3
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +1 -1
- package/bin/executor/messages/AssistantResultPersistence.d.ts +5 -5
- package/bin/executor/messages/AssistantResultPersistence.d.ts.map +1 -1
- package/bin/executor/messages/AssistantResultPersistence.js +1 -1
- package/bin/executor/messages/AssistantResultPersistence.js.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts +3 -3
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
- package/bin/executor/messages/SessionMessageCodec.d.ts +4 -4
- package/bin/executor/messages/SessionMessageCodec.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageCodec.js +5 -5
- package/bin/executor/messages/SessionMessageCodec.js.map +1 -1
- package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
- package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageLog.js.map +1 -1
- package/bin/executor/messages/SessionStepEventMapper.d.ts +2 -2
- package/bin/executor/messages/SessionStepEventMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionStepEventMapper.js.map +1 -1
- package/bin/executor/messages/UserVisibleText.d.ts +3 -3
- package/bin/executor/messages/UserVisibleText.d.ts.map +1 -1
- package/bin/executor/messages/UserVisibleText.js +3 -3
- package/bin/executor/messages/UserVisibleText.js.map +1 -1
- package/bin/executor/services/ExecutorInflightService.d.ts +2 -2
- package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -1
- package/bin/executor/services/ExecutorInflightService.js +11 -7
- package/bin/executor/services/ExecutorInflightService.js.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +30 -27
- package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.js +3 -3
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +21 -20
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +114 -72
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts +1 -7
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolSchemas.d.ts +4 -6
- package/bin/executor/tools/plugin/PluginToolSchemas.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolSchemas.js +24 -10
- package/bin/executor/tools/plugin/PluginToolSchemas.js.map +1 -1
- package/bin/executor/types/SessionRecords.d.ts +162 -0
- package/bin/executor/types/SessionRecords.d.ts.map +1 -0
- package/bin/executor/types/SessionRecords.js +52 -0
- package/bin/executor/types/SessionRecords.js.map +1 -0
- package/bin/executor/types/SessionRun.d.ts +3 -3
- package/bin/executor/types/SessionRun.d.ts.map +1 -1
- package/bin/index.d.ts +2 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +5 -5
- package/bin/rpc/Client.js +4 -4
- package/bin/session/Session.d.ts +6 -6
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +8 -8
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +2 -2
- package/bin/session/SessionTitle.d.ts.map +1 -1
- package/bin/session/SessionTitle.js +5 -0
- package/bin/session/SessionTitle.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +12 -12
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +37 -34
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +1 -1
- package/bin/session/index.js +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +3 -3
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +11 -12
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +43 -69
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.js +3 -3
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +4 -4
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +26 -36
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts +4 -4
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +2 -2
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +4 -4
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +2 -2
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +11 -11
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +22 -22
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +7 -7
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +6 -6
- package/bin/types/runtime/agent/AgentContext.d.ts +7 -7
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.d.ts +26 -0
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -0
- package/bin/types/sdk/AgentSessionAction.js +10 -0
- package/bin/types/sdk/AgentSessionAction.js.map +1 -0
- package/bin/types/sdk/AgentSessionEvent.d.ts +2 -2
- package/bin/types/sdk/AgentSessionEvent.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionTurn.d.ts +2 -2
- package/bin/types/sdk/AgentSessionTurn.d.ts.map +1 -1
- package/package.json +3 -3
- package/scripts/agent-ready.test.mjs +1 -1
- package/scripts/city-model-tool-loop.test.mjs +36 -4
- package/scripts/plugin-tool-bridge.test.mjs +13 -0
- package/scripts/session-action-message.test.mjs +199 -0
- package/scripts/session-compaction-prompts.test.mjs +97 -0
- package/scripts/session-history-archive.test.mjs +8 -8
- package/scripts/session-history-inflight.test.mjs +10 -10
- package/scripts/session-list-title.test.mjs +9 -9
- package/scripts/session-title-event.test.mjs +12 -10
- package/src/agent/local/Agent.ts +16 -22
- package/src/agent/local/services/{AgentSessionManager.ts → AgentSessions.ts} +16 -32
- package/src/agent/remote/RemoteAgent.ts +58 -23
- package/src/agent/remote/RemoteSession.ts +10 -8
- package/src/agent/remote/RemoteTransport.ts +5 -5
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +10 -10
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +6 -6
- package/src/executor/Executor.ts +51 -41
- package/src/executor/SessionRunScope.ts +1 -1
- package/src/executor/composer/compaction/SessionCompactionComposer.ts +5 -5
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +1 -1
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +91 -52
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.ts +197 -0
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +162 -0
- package/src/executor/composer/context/LocalSessionContextComposer.ts +5 -5
- package/src/executor/composer/context/SessionContextComposer.ts +5 -5
- package/src/executor/composer/history/SessionHistoryComposer.ts +2 -2
- package/src/executor/composer/history/SessionHistoryWriter.ts +10 -10
- package/src/executor/composer/history/jsonl/JsonlSessionHistoryComposer.ts +13 -10
- package/src/executor/core-engine/CoreEngineMessageState.ts +8 -8
- package/src/executor/core-engine/CoreEngineRunner.ts +7 -7
- package/src/executor/core-engine/CoreEngineSignals.ts +7 -7
- package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +5 -5
- package/src/executor/messages/AssistantResultPersistence.ts +8 -8
- package/src/executor/messages/SessionAttachmentMapper.ts +11 -11
- package/src/executor/messages/SessionMessageCodec.ts +10 -10
- package/src/executor/messages/SessionMessageLog.ts +3 -3
- package/src/executor/messages/SessionStepEventMapper.ts +5 -5
- package/src/executor/messages/UserVisibleText.ts +9 -9
- package/src/executor/services/ExecutorInflightService.ts +13 -9
- package/src/executor/store/history/SessionHistoryStore.ts +32 -28
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +146 -95
- package/src/executor/tools/plugin/PluginToolSchemas.ts +24 -10
- package/src/executor/types/SessionRecords.ts +217 -0
- package/src/executor/types/SessionRun.ts +5 -5
- package/src/index.ts +9 -10
- package/src/rpc/Client.ts +9 -9
- package/src/session/Session.ts +10 -10
- package/src/session/SessionTitle.ts +7 -4
- package/src/session/browse/Browse.ts +66 -58
- package/src/session/index.ts +1 -1
- package/src/session/runtime/SessionPromptRuntime.ts +6 -6
- package/src/session/services/SessionStateService.ts +61 -86
- package/src/session/services/SessionTurnService.ts +7 -7
- package/src/session/services/SessionViewService.ts +35 -45
- package/src/session/storage/Persistence.ts +6 -6
- package/src/session/storage/RuntimeSessionPort.ts +6 -6
- package/src/types/agent/AgentTypes.ts +4 -4
- package/src/types/agent/SessionActor.ts +12 -12
- package/src/types/agent/SessionTypes.ts +22 -22
- package/src/types/executor/SessionRunContext.ts +12 -12
- package/src/types/rpc/RpcProtocol.ts +6 -6
- package/src/types/runtime/agent/AgentContext.ts +8 -8
- package/src/types/sdk/AgentSessionAction.ts +35 -0
- package/src/types/sdk/AgentSessionEvent.ts +2 -2
- package/src/types/sdk/AgentSessionTurn.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +0 -1
- package/bin/agent/local/services/AgentSessionManager.js.map +0 -1
- package/bin/executor/types/SessionMessages.d.ts +0 -118
- package/bin/executor/types/SessionMessages.d.ts.map +0 -1
- package/bin/executor/types/SessionMessages.js +0 -28
- package/bin/executor/types/SessionMessages.js.map +0 -1
- package/bin/types/sdk/AgentSessionOperation.d.ts +0 -99
- package/bin/types/sdk/AgentSessionOperation.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionOperation.js +0 -10
- package/bin/types/sdk/AgentSessionOperation.js.map +0 -1
- package/scripts/session-operation-message.test.mjs +0 -197
- package/src/executor/types/SessionMessages.ts +0 -148
- package/src/types/sdk/AgentSessionOperation.ts +0 -125
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
|
-
import type { SessionUserMessageV1 } from "@/executor/types/
|
|
11
|
+
import type { SessionUserMessageV1 } from "@/executor/types/SessionRecords.js";
|
|
12
12
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "@/executor/types/
|
|
13
|
+
SessionRecordV1,
|
|
14
|
+
SessionMessageRecordV1,
|
|
15
|
+
} from "@/executor/types/SessionRecords.js";
|
|
16
16
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
17
17
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
18
18
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
@@ -109,7 +109,7 @@ export interface SessionPromptRuntimeOptions {
|
|
|
109
109
|
}) => Promise<{
|
|
110
110
|
text: string;
|
|
111
111
|
success: boolean;
|
|
112
|
-
assistantMessage?:
|
|
112
|
+
assistantMessage?: SessionMessageRecordV1 | null;
|
|
113
113
|
error?: string;
|
|
114
114
|
}>;
|
|
115
115
|
|
|
@@ -349,7 +349,7 @@ export class SessionPromptRuntime {
|
|
|
349
349
|
function buildPromptRuntimeErrorAssistantMessage(input: {
|
|
350
350
|
sessionId: string;
|
|
351
351
|
message: string;
|
|
352
|
-
}):
|
|
352
|
+
}): SessionMessageRecordV1 {
|
|
353
353
|
return {
|
|
354
354
|
id: `a:${input.sessionId}:${Date.now()}:${nanoid(6)}`,
|
|
355
355
|
role: "assistant",
|
|
@@ -30,16 +30,15 @@ import type {
|
|
|
30
30
|
import type {
|
|
31
31
|
AgentSessionEvent,
|
|
32
32
|
} from "@/types/sdk/AgentSessionEvent.js";
|
|
33
|
-
import type {
|
|
34
|
-
AgentSessionOperationEvent,
|
|
35
|
-
AgentSessionOperationRecord,
|
|
36
|
-
} from "@/types/sdk/AgentSessionOperation.js";
|
|
37
33
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
38
34
|
import type {
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
SessionActionRecordInputV1,
|
|
36
|
+
SessionActionRecordV1,
|
|
37
|
+
SessionRecordV1,
|
|
38
|
+
SessionMessageRecordV1,
|
|
41
39
|
SessionUserMessageV1,
|
|
42
|
-
} from "@/executor/types/
|
|
40
|
+
} from "@/executor/types/SessionRecords.js";
|
|
41
|
+
import { to_session_action_record } from "@/executor/types/SessionRecords.js";
|
|
43
42
|
import type { SessionLocalState } from "@/types/session/SessionLocalState.js";
|
|
44
43
|
import { generateId } from "@/utils/Id.js";
|
|
45
44
|
|
|
@@ -87,17 +86,16 @@ type SessionStateServiceOptions = {
|
|
|
87
86
|
|
|
88
87
|
type SessionSetOptions = {
|
|
89
88
|
/**
|
|
90
|
-
* 是否写入并发布 model-switching
|
|
89
|
+
* 是否写入并发布 model-switching action。
|
|
91
90
|
*
|
|
92
91
|
* 说明(中文)
|
|
93
92
|
* - 公开 `session.set()` 应保持默认开启。
|
|
94
93
|
* - fork 内部复制模型配置时关闭,避免污染 forked session 历史。
|
|
95
94
|
*/
|
|
96
|
-
|
|
95
|
+
emit_action?: boolean;
|
|
97
96
|
};
|
|
98
97
|
|
|
99
|
-
type
|
|
100
|
-
Partial<Pick<AgentSessionOperationRecord, "operationId">>;
|
|
98
|
+
type EmitActionInput = SessionActionRecordInputV1 | SessionActionRecordV1;
|
|
101
99
|
|
|
102
100
|
/**
|
|
103
101
|
* 本地 Session 状态与持久化服务。
|
|
@@ -223,23 +221,21 @@ export class SessionStateService {
|
|
|
223
221
|
* 写入当前 session 配置。
|
|
224
222
|
*/
|
|
225
223
|
async set(input: AgentSessionSetInput, options?: SessionSetOptions): Promise<void> {
|
|
226
|
-
const
|
|
224
|
+
const should_emit_action = options?.emit_action !== false;
|
|
227
225
|
const previous_model_label = this.state.sessionConfig.modelLabel;
|
|
228
226
|
const next_model_label = input.model
|
|
229
227
|
? inferAgentModelLabel(input.model)
|
|
230
228
|
: undefined;
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
if (input.model &&
|
|
234
|
-
await this.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
...(next_model_label ? { modelLabel: next_model_label } : {}),
|
|
242
|
-
},
|
|
229
|
+
const action_id = `model-switching:${this.session_id}:${Date.now()}:${generateId()}`;
|
|
230
|
+
|
|
231
|
+
if (input.model && should_emit_action) {
|
|
232
|
+
await this.emit_action_event({
|
|
233
|
+
id: action_id,
|
|
234
|
+
title: "Switching session model",
|
|
235
|
+
description: next_model_label
|
|
236
|
+
? `Switching to ${next_model_label}.`
|
|
237
|
+
: undefined,
|
|
238
|
+
state: "running",
|
|
243
239
|
});
|
|
244
240
|
}
|
|
245
241
|
|
|
@@ -256,30 +252,25 @@ export class SessionStateService {
|
|
|
256
252
|
model: this.state.sessionConfig.model,
|
|
257
253
|
});
|
|
258
254
|
} catch (error) {
|
|
259
|
-
if (input.model &&
|
|
260
|
-
await this.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
error: error instanceof Error ? error.message : String(error),
|
|
255
|
+
if (input.model && should_emit_action) {
|
|
256
|
+
await this.emit_action_event({
|
|
257
|
+
id: action_id,
|
|
258
|
+
title: "Session model switch failed",
|
|
259
|
+
description: error instanceof Error ? error.message : String(error),
|
|
260
|
+
state: "failed",
|
|
266
261
|
});
|
|
267
262
|
}
|
|
268
263
|
throw error;
|
|
269
264
|
}
|
|
270
265
|
|
|
271
|
-
if (input.model &&
|
|
272
|
-
await this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
...(this.state.sessionConfig.modelLabel
|
|
280
|
-
? { modelLabel: this.state.sessionConfig.modelLabel }
|
|
281
|
-
: {}),
|
|
282
|
-
},
|
|
266
|
+
if (input.model && should_emit_action) {
|
|
267
|
+
await this.emit_action_event({
|
|
268
|
+
id: action_id,
|
|
269
|
+
title: "Session model switched",
|
|
270
|
+
description: this.state.sessionConfig.modelLabel
|
|
271
|
+
? `Using ${this.state.sessionConfig.modelLabel}.`
|
|
272
|
+
: undefined,
|
|
273
|
+
state: "completed",
|
|
283
274
|
});
|
|
284
275
|
}
|
|
285
276
|
}
|
|
@@ -288,10 +279,10 @@ export class SessionStateService {
|
|
|
288
279
|
* 追加一条 user 消息并刷新标题与 metadata。
|
|
289
280
|
*/
|
|
290
281
|
async append_user_message(params: {
|
|
291
|
-
message?:
|
|
282
|
+
message?: SessionRecordV1 | null;
|
|
292
283
|
text?: string;
|
|
293
284
|
}): Promise<void> {
|
|
294
|
-
await this.executor.
|
|
285
|
+
await this.executor.append_user_message(params);
|
|
295
286
|
await this.ensure_title_from_history({ generate: true });
|
|
296
287
|
await this.touch_metadata();
|
|
297
288
|
}
|
|
@@ -300,10 +291,10 @@ export class SessionStateService {
|
|
|
300
291
|
* 追加一条 assistant 消息并刷新 metadata。
|
|
301
292
|
*/
|
|
302
293
|
async append_assistant_message(params: {
|
|
303
|
-
message?:
|
|
294
|
+
message?: SessionRecordV1 | null;
|
|
304
295
|
fallbackText?: string;
|
|
305
296
|
}): Promise<void> {
|
|
306
|
-
await this.executor.
|
|
297
|
+
await this.executor.append_assistant_message(params);
|
|
307
298
|
await this.touch_metadata();
|
|
308
299
|
}
|
|
309
300
|
|
|
@@ -328,7 +319,7 @@ export class SessionStateService {
|
|
|
328
319
|
*/
|
|
329
320
|
generate?: boolean;
|
|
330
321
|
}): Promise<void> {
|
|
331
|
-
const messages = await this.history_store.
|
|
322
|
+
const messages = await this.history_store.list_records();
|
|
332
323
|
const before_metadata = await readSessionMetadata({
|
|
333
324
|
projectRoot: this.project_root,
|
|
334
325
|
agentId: this.agent_id,
|
|
@@ -356,7 +347,7 @@ export class SessionStateService {
|
|
|
356
347
|
* 持久化最终 assistant 结果。
|
|
357
348
|
*/
|
|
358
349
|
async persist_assistant_result(
|
|
359
|
-
assistant_message?:
|
|
350
|
+
assistant_message?: SessionMessageRecordV1 | null,
|
|
360
351
|
): Promise<void> {
|
|
361
352
|
await persistSdkAssistantResult({
|
|
362
353
|
projectRoot: this.project_root,
|
|
@@ -369,49 +360,33 @@ export class SessionStateService {
|
|
|
369
360
|
}
|
|
370
361
|
|
|
371
362
|
/**
|
|
372
|
-
* 持久化一条
|
|
363
|
+
* 持久化一条 action record。
|
|
373
364
|
*/
|
|
374
|
-
async
|
|
375
|
-
event:
|
|
365
|
+
async persist_action_event(
|
|
366
|
+
event: SessionActionRecordV1,
|
|
376
367
|
): Promise<void> {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
operation: {
|
|
380
|
-
operationId: event.operationId,
|
|
381
|
-
name: event.name,
|
|
382
|
-
status: event.status,
|
|
383
|
-
...(event.turnId ? { turnId: event.turnId } : {}),
|
|
384
|
-
...(event.label ? { label: event.label } : {}),
|
|
385
|
-
...(event.reason ? { reason: event.reason } : {}),
|
|
386
|
-
...(typeof event.progress === "number" ? { progress: event.progress } : {}),
|
|
387
|
-
...(event.result !== undefined ? { result: event.result } : {}),
|
|
388
|
-
...(event.error ? { error: event.error } : {}),
|
|
389
|
-
},
|
|
390
|
-
metadata: {
|
|
391
|
-
sessionId: this.session_id,
|
|
392
|
-
},
|
|
393
|
-
});
|
|
394
|
-
await this.history_store.append(message);
|
|
368
|
+
const message = to_session_action_record(event, this.session_id);
|
|
369
|
+
await this.history_store.write_record(message);
|
|
395
370
|
await this.touch_metadata();
|
|
396
371
|
}
|
|
397
372
|
|
|
398
373
|
/**
|
|
399
|
-
* 写入并发布一条
|
|
374
|
+
* 写入并发布一条 action。
|
|
400
375
|
*/
|
|
401
|
-
async
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
376
|
+
async emit_action_event(input: EmitActionInput): Promise<void> {
|
|
377
|
+
const event = to_session_action_record(
|
|
378
|
+
{
|
|
379
|
+
...input,
|
|
380
|
+
id:
|
|
381
|
+
String(input.id || "").trim() ||
|
|
382
|
+
`action:${this.session_id}:${Date.now()}:${generateId()}`,
|
|
383
|
+
},
|
|
384
|
+
this.session_id,
|
|
385
|
+
);
|
|
411
386
|
try {
|
|
412
|
-
await this.
|
|
387
|
+
await this.persist_action_event(event);
|
|
413
388
|
} catch {
|
|
414
|
-
//
|
|
389
|
+
// action 持久化失败不应阻断宿主操作。
|
|
415
390
|
}
|
|
416
391
|
this.publish_event(event);
|
|
417
392
|
}
|
|
@@ -430,7 +405,7 @@ export class SessionStateService {
|
|
|
430
405
|
sessionId: this.session_id,
|
|
431
406
|
},
|
|
432
407
|
}) as SessionUserMessageV1;
|
|
433
|
-
await this.executor.
|
|
408
|
+
await this.executor.append_user_message({
|
|
434
409
|
message,
|
|
435
410
|
});
|
|
436
411
|
await this.ensure_title_from_history({ generate: true });
|
|
@@ -455,7 +430,7 @@ export class SessionStateService {
|
|
|
455
430
|
kind: "normal",
|
|
456
431
|
},
|
|
457
432
|
};
|
|
458
|
-
await this.executor.
|
|
433
|
+
await this.executor.append_user_message({
|
|
459
434
|
message,
|
|
460
435
|
});
|
|
461
436
|
await this.ensure_title_from_history({ generate: true });
|
|
@@ -474,7 +449,7 @@ export class SessionStateService {
|
|
|
474
449
|
: [];
|
|
475
450
|
if (normalized_messages.length <= 0) return;
|
|
476
451
|
for (const message of normalized_messages) {
|
|
477
|
-
await this.executor.
|
|
452
|
+
await this.executor.append_user_message({
|
|
478
453
|
message,
|
|
479
454
|
});
|
|
480
455
|
}
|
|
@@ -19,10 +19,10 @@ import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js"
|
|
|
19
19
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
20
20
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
21
21
|
import type {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
SessionRecordV1,
|
|
23
|
+
SessionMessageRecordV1,
|
|
24
24
|
SessionUserMessageV1,
|
|
25
|
-
} from "@/executor/types/
|
|
25
|
+
} from "@/executor/types/SessionRecords.js";
|
|
26
26
|
import { mapAgentEventToSessionEvent, mapUiMessageChunkToAgentEvent } from "@/session/SessionEventMapper.js";
|
|
27
27
|
import { SessionEventHub } from "@/session/runtime/SessionEventHub.js";
|
|
28
28
|
import { SessionPromptRuntime } from "@/session/runtime/SessionPromptRuntime.js";
|
|
@@ -145,7 +145,7 @@ export class SessionTurnService {
|
|
|
145
145
|
}): Promise<{
|
|
146
146
|
text: string;
|
|
147
147
|
success: boolean;
|
|
148
|
-
assistantMessage?:
|
|
148
|
+
assistantMessage?: SessionMessageRecordV1 | null;
|
|
149
149
|
error?: string;
|
|
150
150
|
}> {
|
|
151
151
|
const tool_name_by_call_id = new Map<string, string>();
|
|
@@ -199,11 +199,11 @@ export class SessionTurnService {
|
|
|
199
199
|
this.publish_event(session_event);
|
|
200
200
|
}
|
|
201
201
|
},
|
|
202
|
-
|
|
202
|
+
onActionCallback: async (event) => {
|
|
203
203
|
try {
|
|
204
|
-
await this.state_service.
|
|
204
|
+
await this.state_service.persist_action_event(event);
|
|
205
205
|
} catch {
|
|
206
|
-
//
|
|
206
|
+
// action 持久化失败不应阻断当前 turn。
|
|
207
207
|
}
|
|
208
208
|
this.publish_event(event);
|
|
209
209
|
},
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* SessionViewService:本地 Session 查询与派生视图服务。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - 统一管理 info/
|
|
5
|
+
* - 统一管理 info/records/system/fork 这类读取型能力。
|
|
6
6
|
* - 该服务只负责拼装查询结果,不负责编排 prompt turn。
|
|
7
7
|
* - 需要写入持久化状态的地方仍委托给 SessionStateService。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
buildSessionRecordsPage,
|
|
13
13
|
buildSessionInfo,
|
|
14
14
|
getSdkAgentSessionArchiveFilePath,
|
|
15
15
|
ensureSessionTitle,
|
|
@@ -21,14 +21,14 @@ import type { JsonlSessionHistoryStore } from "@/executor/store/history/jsonl/Js
|
|
|
21
21
|
import type { SessionSystemComposer } from "@/executor/composer/system/SessionSystemComposer.js";
|
|
22
22
|
import type {
|
|
23
23
|
AgentSessionForkInput,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
AgentSessionRecordsInput,
|
|
25
|
+
AgentSessionRecordsPage,
|
|
26
26
|
AgentSessionInfo,
|
|
27
27
|
AgentSession,
|
|
28
28
|
AgentSessionSystemBlock,
|
|
29
29
|
AgentSessionSystemSnapshot,
|
|
30
30
|
} from "@/types/agent/AgentTypes.js";
|
|
31
|
-
import type {
|
|
31
|
+
import type { SessionRecordV1 } from "@/executor/types/SessionRecords.js";
|
|
32
32
|
import { SessionStateService } from "@/session/services/SessionStateService.js";
|
|
33
33
|
import type { SessionRunContext } from "@/types/executor/SessionRunContext.js";
|
|
34
34
|
|
|
@@ -138,7 +138,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
138
138
|
agentId: this.agent_id,
|
|
139
139
|
sessionId: this.session_id,
|
|
140
140
|
}),
|
|
141
|
-
this.history_store.
|
|
141
|
+
this.history_store.list_records(),
|
|
142
142
|
]);
|
|
143
143
|
return await this.build_info({
|
|
144
144
|
metadata,
|
|
@@ -155,7 +155,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
155
155
|
/**
|
|
156
156
|
* 当前 session 消息列表。
|
|
157
157
|
*/
|
|
158
|
-
messages:
|
|
158
|
+
messages: SessionRecordV1[];
|
|
159
159
|
}): Promise<AgentSessionInfo> {
|
|
160
160
|
const metadata_with_title = input.metadata.title
|
|
161
161
|
? input.metadata
|
|
@@ -176,11 +176,11 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
* 读取当前 session
|
|
179
|
+
* 读取当前 session records 分页。
|
|
180
180
|
*/
|
|
181
|
-
async
|
|
182
|
-
input?:
|
|
183
|
-
): Promise<
|
|
181
|
+
async records(
|
|
182
|
+
input?: AgentSessionRecordsInput,
|
|
183
|
+
): Promise<AgentSessionRecordsPage> {
|
|
184
184
|
const archive_id = String(input?.archive_id || "").trim();
|
|
185
185
|
const [metadata, current_messages] = await Promise.all([
|
|
186
186
|
readSessionMetadata({
|
|
@@ -188,7 +188,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
188
188
|
agentId: this.agent_id,
|
|
189
189
|
sessionId: this.session_id,
|
|
190
190
|
}),
|
|
191
|
-
this.history_store.
|
|
191
|
+
this.history_store.list_records(),
|
|
192
192
|
]);
|
|
193
193
|
const page_messages = archive_id
|
|
194
194
|
? await loadSessionArchiveMessagesFromPath(
|
|
@@ -204,7 +204,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
204
204
|
metadata,
|
|
205
205
|
messages: current_messages,
|
|
206
206
|
});
|
|
207
|
-
return
|
|
207
|
+
return buildSessionRecordsPage({
|
|
208
208
|
session,
|
|
209
209
|
messages: page_messages,
|
|
210
210
|
input,
|
|
@@ -273,22 +273,18 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
273
273
|
typeof input === "string"
|
|
274
274
|
? String(input || "").trim() || undefined
|
|
275
275
|
: String(input?.messageId || "").trim() || undefined;
|
|
276
|
-
const messages = await this.history_store.
|
|
276
|
+
const messages = await this.history_store.list_records();
|
|
277
277
|
const fork_messages =
|
|
278
278
|
!message_id
|
|
279
279
|
? messages
|
|
280
280
|
: this.resolve_fork_messages(messages, message_id);
|
|
281
|
-
const
|
|
281
|
+
const action_id = `history-forking:${this.session_id}:${Date.now()}:${nanoid(8)}`;
|
|
282
282
|
|
|
283
|
-
await this.state_service.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
result: {
|
|
289
|
-
messageCount: fork_messages.length,
|
|
290
|
-
...(message_id ? { messageId: message_id } : {}),
|
|
291
|
-
},
|
|
283
|
+
await this.state_service.emit_action_event({
|
|
284
|
+
id: action_id,
|
|
285
|
+
title: "Forking session records",
|
|
286
|
+
description: `Preparing ${String(fork_messages.length)} messages for the new session.`,
|
|
287
|
+
state: "running",
|
|
292
288
|
});
|
|
293
289
|
|
|
294
290
|
try {
|
|
@@ -302,38 +298,32 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
302
298
|
{
|
|
303
299
|
model: session_config.model,
|
|
304
300
|
},
|
|
305
|
-
{
|
|
301
|
+
{ emit_action: false },
|
|
306
302
|
);
|
|
307
303
|
}
|
|
308
304
|
await this.append_fork_messages(forked_bundle, fork_messages);
|
|
309
|
-
await this.state_service.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
result: {
|
|
315
|
-
forkedSessionId: String((forked as { id?: unknown }).id || ""),
|
|
316
|
-
messageCount: fork_messages.length,
|
|
317
|
-
...(message_id ? { messageId: message_id } : {}),
|
|
318
|
-
},
|
|
305
|
+
await this.state_service.emit_action_event({
|
|
306
|
+
id: action_id,
|
|
307
|
+
title: "Session records forked",
|
|
308
|
+
description: `Created ${String((forked as { id?: unknown }).id || "")} with ${String(fork_messages.length)} messages.`,
|
|
309
|
+
state: "completed",
|
|
319
310
|
});
|
|
320
311
|
return forked;
|
|
321
312
|
} catch (error) {
|
|
322
|
-
await this.state_service.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
error: error instanceof Error ? error.message : String(error),
|
|
313
|
+
await this.state_service.emit_action_event({
|
|
314
|
+
id: action_id,
|
|
315
|
+
title: "Session records fork failed",
|
|
316
|
+
description: error instanceof Error ? error.message : String(error),
|
|
317
|
+
state: "failed",
|
|
328
318
|
});
|
|
329
319
|
throw error;
|
|
330
320
|
}
|
|
331
321
|
}
|
|
332
322
|
|
|
333
323
|
private resolve_fork_messages(
|
|
334
|
-
messages:
|
|
324
|
+
messages: SessionRecordV1[],
|
|
335
325
|
message_id: string,
|
|
336
|
-
):
|
|
326
|
+
): SessionRecordV1[] {
|
|
337
327
|
const target_index = messages.findIndex(
|
|
338
328
|
(message) => String(message.id || "").trim() === message_id,
|
|
339
329
|
);
|
|
@@ -350,9 +340,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
350
340
|
history_store: JsonlSessionHistoryStore;
|
|
351
341
|
state_service: SessionStateService;
|
|
352
342
|
},
|
|
353
|
-
messages:
|
|
343
|
+
messages: SessionRecordV1[],
|
|
354
344
|
): Promise<void> {
|
|
355
|
-
await forked_bundle.history_store.
|
|
345
|
+
await forked_bundle.history_store.write_records(messages);
|
|
356
346
|
}
|
|
357
347
|
|
|
358
348
|
private stringify_system_content(content: unknown): string {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
import { extractTextFromUiMessage } from "@/executor/messages/UIMessageTransformer.js";
|
|
10
10
|
import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
|
|
11
11
|
import type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "@/executor/types/
|
|
12
|
+
SessionRecordV1,
|
|
13
|
+
SessionMessageRecordV1,
|
|
14
|
+
} from "@/executor/types/SessionRecords.js";
|
|
15
15
|
import { persistAssistantResult } from "@/executor/messages/AssistantResultPersistence.js";
|
|
16
16
|
import type { AgentSessionConfigSnapshot } from "@/types/agent/AgentTypes.js";
|
|
17
17
|
import {
|
|
@@ -50,11 +50,11 @@ export interface PersistSdkAssistantResultParams
|
|
|
50
50
|
* 追加 assistant 消息的底层执行编排器。
|
|
51
51
|
*/
|
|
52
52
|
executor: {
|
|
53
|
-
|
|
53
|
+
append_assistant_message(params: {
|
|
54
54
|
/**
|
|
55
55
|
* 已构造好的完整消息。
|
|
56
56
|
*/
|
|
57
|
-
message?:
|
|
57
|
+
message?: SessionRecordV1 | null;
|
|
58
58
|
/**
|
|
59
59
|
* 兜底文本内容。
|
|
60
60
|
*/
|
|
@@ -68,7 +68,7 @@ export interface PersistSdkAssistantResultParams
|
|
|
68
68
|
* - stop/abort 且没有 assistant 内容时允许为空。
|
|
69
69
|
* - 为空时仅刷新 metadata,不写入伪造 assistant 正文。
|
|
70
70
|
*/
|
|
71
|
-
assistantMessage?:
|
|
71
|
+
assistantMessage?: SessionMessageRecordV1 | null;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
@@ -58,11 +58,11 @@ export interface CreateRuntimeSessionPortParams {
|
|
|
58
58
|
/**
|
|
59
59
|
* 追加 user 消息到底层历史。
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
append_user_message: SessionPort["append_user_message"];
|
|
62
62
|
/**
|
|
63
63
|
* 追加 assistant 消息到底层历史。
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
append_assistant_message: SessionPort["append_assistant_message"];
|
|
66
66
|
/**
|
|
67
67
|
* 返回当前 session 是否正在执行。
|
|
68
68
|
*/
|
|
@@ -111,12 +111,12 @@ export function createRuntimeSessionPort(
|
|
|
111
111
|
afterSessionUpdatedAsync: async () => {
|
|
112
112
|
await params.afterSessionUpdatedAsync();
|
|
113
113
|
},
|
|
114
|
-
|
|
115
|
-
await params.
|
|
114
|
+
append_user_message: async (messageParams) => {
|
|
115
|
+
await params.append_user_message(messageParams);
|
|
116
116
|
await params.touchMetadata();
|
|
117
117
|
},
|
|
118
|
-
|
|
119
|
-
await params.
|
|
118
|
+
append_assistant_message: async (messageParams) => {
|
|
119
|
+
await params.append_assistant_message(messageParams);
|
|
120
120
|
await params.touchMetadata();
|
|
121
121
|
},
|
|
122
122
|
isExecuting: () => params.isExecuting(),
|
|
@@ -36,9 +36,9 @@ export type {
|
|
|
36
36
|
AgentListSessionsInput,
|
|
37
37
|
AgentSessionConfigSnapshot,
|
|
38
38
|
AgentSessionForkInput,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
AgentSessionRecordsInput,
|
|
40
|
+
AgentSessionRecordsPage,
|
|
41
|
+
AgentSessionRecordsView,
|
|
42
42
|
AgentSessionInfo,
|
|
43
43
|
AgentSessionSetInput,
|
|
44
44
|
AgentSessionSummary,
|
|
@@ -53,6 +53,6 @@ export type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
|
53
53
|
export type {
|
|
54
54
|
AgentSession,
|
|
55
55
|
AgentSessionActor,
|
|
56
|
-
|
|
56
|
+
AgentSessions,
|
|
57
57
|
RemoteAgentSession,
|
|
58
58
|
} from "@/types/agent/SessionActor.js";
|
|
@@ -16,8 +16,8 @@ import type {
|
|
|
16
16
|
AgentListSessionsInput,
|
|
17
17
|
AgentSessionConfigSnapshot,
|
|
18
18
|
AgentSessionForkInput,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
AgentSessionRecordsInput,
|
|
20
|
+
AgentSessionRecordsPage,
|
|
21
21
|
AgentSessionInfo,
|
|
22
22
|
AgentSessionSetInput,
|
|
23
23
|
AgentSessionSummaryPage,
|
|
@@ -32,23 +32,23 @@ import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
|
32
32
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* SDK Session
|
|
35
|
+
* SDK Session 集合入口。
|
|
36
36
|
*/
|
|
37
|
-
export interface
|
|
37
|
+
export interface AgentSessions<TSession extends AgentSessionActor = AgentSession> {
|
|
38
38
|
/** 新建一个 session。 */
|
|
39
|
-
|
|
39
|
+
create(input?: AgentCreateSessionInput): Promise<TSession>;
|
|
40
40
|
|
|
41
41
|
/** 获取一个已存在的 session。 */
|
|
42
|
-
|
|
42
|
+
get(session_id: string): Promise<TSession>;
|
|
43
43
|
|
|
44
44
|
/** 列出当前 agent 的 session 摘要页。 */
|
|
45
|
-
|
|
45
|
+
list(input?: AgentListSessionsInput): Promise<AgentSessionSummaryPage>;
|
|
46
46
|
|
|
47
47
|
/** 归档单个 session。 */
|
|
48
|
-
|
|
48
|
+
archive(input: AgentArchiveSessionInput): Promise<AgentArchiveSessionResult>;
|
|
49
49
|
|
|
50
50
|
/** 列出已归档的 session 摘要页。 */
|
|
51
|
-
|
|
51
|
+
archived(input?: AgentArchiveSessionsInput): Promise<AgentArchiveSessionsResult>;
|
|
52
52
|
|
|
53
53
|
/** 永久清空已归档 session。 */
|
|
54
54
|
clean_archive(): Promise<AgentCleanArchiveResult>;
|
|
@@ -62,7 +62,7 @@ export interface AgentSessionActor {
|
|
|
62
62
|
readonly id: string;
|
|
63
63
|
|
|
64
64
|
/** 读取当前 session 详情。 */
|
|
65
|
-
|
|
65
|
+
get_info(): Promise<AgentSessionInfo>;
|
|
66
66
|
|
|
67
67
|
/** 追加一条新的 prompt。 */
|
|
68
68
|
prompt(input: AgentSessionPromptInput): Promise<AgentSessionTurnHandle>;
|
|
@@ -73,8 +73,8 @@ export interface AgentSessionActor {
|
|
|
73
73
|
/** 订阅当前 session 的未来事件。 */
|
|
74
74
|
subscribe(subscriber: AgentSessionSubscriber): AgentSessionUnsubscribe;
|
|
75
75
|
|
|
76
|
-
/** 读取当前 session
|
|
77
|
-
|
|
76
|
+
/** 读取当前 session records 分页。 */
|
|
77
|
+
records(input?: AgentSessionRecordsInput): Promise<AgentSessionRecordsPage>;
|
|
78
78
|
|
|
79
79
|
/** 读取当前 session 生效的 system 快照。 */
|
|
80
80
|
system(): Promise<AgentSessionSystemSnapshot>;
|