@downcity/agent 1.1.200 → 1.1.203
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 +5 -5
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +22 -13
- 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 +3 -3
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.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 +56 -16
- 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 -5
- 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 +4 -4
- package/bin/executor/services/ExecutorInflightService.js.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +24 -21
- 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 +18 -19
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +33 -36
- 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/{SessionMessages.d.ts → SessionRecords.d.ts} +53 -28
- 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 +1 -1
- package/bin/index.d.ts.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 +3 -3
- 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 +9 -9
- 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 +7 -8
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +24 -34
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +4 -4
- package/bin/session/services/SessionViewService.js +12 -12
- 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 +12 -12
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +2 -2
- 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 +8 -49
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.js +4 -4
- 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 +71 -27
- 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 +30 -19
- package/src/executor/SessionRunScope.ts +1 -1
- package/src/executor/composer/compaction/SessionCompactionComposer.ts +3 -3
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +73 -29
- 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 -13
- 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 +7 -7
- package/src/executor/store/history/SessionHistoryStore.ts +26 -23
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +58 -62
- package/src/executor/tools/plugin/PluginToolSchemas.ts +24 -10
- package/src/executor/types/{SessionMessages.ts → SessionRecords.ts} +71 -40
- package/src/executor/types/SessionRun.ts +5 -5
- package/src/index.ts +4 -4
- package/src/rpc/Client.ts +9 -9
- package/src/session/Session.ts +10 -10
- package/src/session/SessionTitle.ts +7 -7
- package/src/session/browse/Browse.ts +38 -38
- package/src/session/index.ts +1 -1
- package/src/session/runtime/SessionPromptRuntime.ts +6 -6
- package/src/session/services/SessionStateService.ts +40 -47
- package/src/session/services/SessionTurnService.ts +4 -4
- package/src/session/services/SessionViewService.ts +21 -21
- 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 +12 -12
- package/src/types/executor/SessionRunContext.ts +2 -2
- package/src/types/rpc/RpcProtocol.ts +6 -6
- package/src/types/runtime/agent/AgentContext.ts +8 -8
- package/src/types/sdk/AgentSessionAction.ts +12 -56
- 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.map +0 -1
- package/bin/executor/types/SessionMessages.js +0 -46
- package/bin/executor/types/SessionMessages.js.map +0 -1
|
@@ -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,7 +273,7 @@ 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
|
|
@@ -282,7 +282,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
282
282
|
|
|
283
283
|
await this.state_service.emit_action_event({
|
|
284
284
|
id: action_id,
|
|
285
|
-
title: "Forking session
|
|
285
|
+
title: "Forking session records",
|
|
286
286
|
description: `Preparing ${String(fork_messages.length)} messages for the new session.`,
|
|
287
287
|
state: "running",
|
|
288
288
|
});
|
|
@@ -304,7 +304,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
304
304
|
await this.append_fork_messages(forked_bundle, fork_messages);
|
|
305
305
|
await this.state_service.emit_action_event({
|
|
306
306
|
id: action_id,
|
|
307
|
-
title: "Session
|
|
307
|
+
title: "Session records forked",
|
|
308
308
|
description: `Created ${String((forked as { id?: unknown }).id || "")} with ${String(fork_messages.length)} messages.`,
|
|
309
309
|
state: "completed",
|
|
310
310
|
});
|
|
@@ -312,7 +312,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
312
312
|
} catch (error) {
|
|
313
313
|
await this.state_service.emit_action_event({
|
|
314
314
|
id: action_id,
|
|
315
|
-
title: "Session
|
|
315
|
+
title: "Session records fork failed",
|
|
316
316
|
description: error instanceof Error ? error.message : String(error),
|
|
317
317
|
state: "failed",
|
|
318
318
|
});
|
|
@@ -321,9 +321,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
private resolve_fork_messages(
|
|
324
|
-
messages:
|
|
324
|
+
messages: SessionRecordV1[],
|
|
325
325
|
message_id: string,
|
|
326
|
-
):
|
|
326
|
+
): SessionRecordV1[] {
|
|
327
327
|
const target_index = messages.findIndex(
|
|
328
328
|
(message) => String(message.id || "").trim() === message_id,
|
|
329
329
|
);
|
|
@@ -340,9 +340,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
340
340
|
history_store: JsonlSessionHistoryStore;
|
|
341
341
|
state_service: SessionStateService;
|
|
342
342
|
},
|
|
343
|
-
messages:
|
|
343
|
+
messages: SessionRecordV1[],
|
|
344
344
|
): Promise<void> {
|
|
345
|
-
await forked_bundle.history_store.
|
|
345
|
+
await forked_bundle.history_store.write_records(messages);
|
|
346
346
|
}
|
|
347
347
|
|
|
348
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>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { LanguageModel } from "ai";
|
|
10
10
|
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
11
|
-
import type {
|
|
11
|
+
import type { SessionRecordV1 } from "@/executor/types/SessionRecords.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 新建 session 的输入参数。
|
|
@@ -83,9 +83,9 @@ export interface AgentSessionConfigSnapshot {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
* Session
|
|
86
|
+
* Session records视图类型。
|
|
87
87
|
*/
|
|
88
|
-
export type
|
|
88
|
+
export type AgentSessionRecordsView = "message" | "timeline";
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Session 时间线事件。
|
|
@@ -286,9 +286,9 @@ export interface AgentSessionSummaryPage {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
/**
|
|
289
|
-
* Session
|
|
289
|
+
* Session records 读取输入。
|
|
290
290
|
*/
|
|
291
|
-
export interface
|
|
291
|
+
export interface AgentSessionRecordsInput {
|
|
292
292
|
/** 当前页返回上限。 */
|
|
293
293
|
limit?: number;
|
|
294
294
|
/** 分页游标。 */
|
|
@@ -316,25 +316,25 @@ export interface AgentSessionHistoryInput {
|
|
|
316
316
|
* - `message`:原始 session 消息
|
|
317
317
|
* - `timeline`:适合直接渲染 UI 的平铺事件
|
|
318
318
|
*/
|
|
319
|
-
view?:
|
|
319
|
+
view?: AgentSessionRecordsView;
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
/**
|
|
323
|
-
* Session
|
|
323
|
+
* Session records 分页结果。
|
|
324
324
|
*/
|
|
325
|
-
export interface
|
|
325
|
+
export interface AgentSessionRecordsPage {
|
|
326
326
|
/** 当前读取所对应的 session 信息。 */
|
|
327
327
|
session: AgentSessionInfo;
|
|
328
328
|
/** 当前页实际返回视图。 */
|
|
329
|
-
view:
|
|
329
|
+
view: AgentSessionRecordsView;
|
|
330
330
|
/**
|
|
331
331
|
* 当前页数据列表。
|
|
332
332
|
*
|
|
333
333
|
* 说明(中文)
|
|
334
|
-
* - `view=message` 时返回 `
|
|
334
|
+
* - `view=message` 时返回 `SessionRecordV1[]`
|
|
335
335
|
* - `view=timeline` 时返回 `AgentSessionTimelineEvent[]`
|
|
336
336
|
*/
|
|
337
|
-
items:
|
|
337
|
+
items: SessionRecordV1[] | AgentSessionTimelineEvent[];
|
|
338
338
|
/**
|
|
339
339
|
* 过滤前后的总条数。
|
|
340
340
|
*
|
|
@@ -360,7 +360,7 @@ export interface AgentSessionHistoryPage {
|
|
|
360
360
|
*
|
|
361
361
|
* 关键点(中文)
|
|
362
362
|
* - compact summary 不会出现在 `items` 中。
|
|
363
|
-
* - 若当前层包含 compact summary,则这里暴露其 archive ID,供调用方继续 `session.
|
|
363
|
+
* - 若当前层包含 compact summary,则这里暴露其 archive ID,供调用方继续 `session.records({ archive_id })`。
|
|
364
364
|
*/
|
|
365
365
|
previous_archive_id?: string;
|
|
366
366
|
}
|
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
SessionAssistantStepCallback,
|
|
17
17
|
SessionUiMessageChunkCallback,
|
|
18
18
|
} from "@/executor/types/SessionRun.js";
|
|
19
|
-
import type { SessionUserMessageV1 } from "@/executor/types/
|
|
19
|
+
import type { SessionUserMessageV1 } from "@/executor/types/SessionRecords.js";
|
|
20
20
|
import type { FileUIPart } from "ai";
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -75,7 +75,7 @@ export interface SessionRunContext {
|
|
|
75
75
|
* action 发布回调。
|
|
76
76
|
*
|
|
77
77
|
* 关键点(中文)
|
|
78
|
-
* - 用于把 compaction 等辅助动作转成 session event 与 action
|
|
78
|
+
* - 用于把 compaction 等辅助动作转成 session event 与 action record。
|
|
79
79
|
* - action 不代表 assistant 正文,也不会进入 LLM 输入。
|
|
80
80
|
*/
|
|
81
81
|
onActionCallback?: AgentSessionActionCallback;
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
AgentArchiveSessionResult,
|
|
16
16
|
AgentArchiveSessionsResult,
|
|
17
17
|
AgentCleanArchiveResult,
|
|
18
|
-
|
|
18
|
+
AgentSessionRecordsInput,
|
|
19
19
|
AgentSessionStopResult,
|
|
20
20
|
AgentSessionSystemSnapshot,
|
|
21
21
|
} from "@/types/agent/AgentTypes.js";
|
|
@@ -112,14 +112,14 @@ export type RpcRequest =
|
|
|
112
112
|
| {
|
|
113
113
|
/** 请求 id,用于匹配响应。 */
|
|
114
114
|
id: string;
|
|
115
|
-
/** 读取 session
|
|
116
|
-
method: "sdk.sessions.
|
|
117
|
-
/**
|
|
115
|
+
/** 读取 session records。 */
|
|
116
|
+
method: "sdk.sessions.records";
|
|
117
|
+
/** records 查询参数。 */
|
|
118
118
|
params: {
|
|
119
119
|
/** 目标 session id。 */
|
|
120
120
|
sessionId: string;
|
|
121
|
-
/**
|
|
122
|
-
input?:
|
|
121
|
+
/** records 分页与视图参数。 */
|
|
122
|
+
input?: AgentSessionRecordsInput;
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
125
|
| {
|
|
@@ -19,8 +19,8 @@ import type { AgentPlugins } from "@/plugin/types/Plugin.js";
|
|
|
19
19
|
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
20
20
|
import type {
|
|
21
21
|
SessionMetadataV1,
|
|
22
|
-
|
|
23
|
-
} from "@/executor/types/
|
|
22
|
+
SessionRecordV1,
|
|
23
|
+
} from "@/executor/types/SessionRecords.js";
|
|
24
24
|
import type {
|
|
25
25
|
SessionRunInput,
|
|
26
26
|
SessionRunResult,
|
|
@@ -133,7 +133,7 @@ export interface SessionPort {
|
|
|
133
133
|
*
|
|
134
134
|
* 关键点(中文)
|
|
135
135
|
* - 只广播订阅之后产生的事件。
|
|
136
|
-
* -
|
|
136
|
+
* - session records 仍通过 `getHistoryStore()` / SDK `records()` 读取。
|
|
137
137
|
*/
|
|
138
138
|
subscribe(subscriber: AgentSessionSubscriber): AgentSessionUnsubscribe;
|
|
139
139
|
/**
|
|
@@ -141,7 +141,7 @@ export interface SessionPort {
|
|
|
141
141
|
*
|
|
142
142
|
* 关键点(中文)
|
|
143
143
|
* - plugin runtime 用它把审批、外部进度等非模型 chunk 事件推送给订阅方。
|
|
144
|
-
* - 历史消息持久化仍由
|
|
144
|
+
* - 历史消息持久化仍由 append_user_message / append_assistant_message 负责。
|
|
145
145
|
*/
|
|
146
146
|
publishEvent(event: AgentSessionEvent): void;
|
|
147
147
|
/**
|
|
@@ -155,11 +155,11 @@ export interface SessionPort {
|
|
|
155
155
|
/**
|
|
156
156
|
* 追加一条 user 消息。
|
|
157
157
|
*/
|
|
158
|
-
|
|
158
|
+
append_user_message(params: {
|
|
159
159
|
/**
|
|
160
160
|
* 已构造好的完整消息。
|
|
161
161
|
*/
|
|
162
|
-
message?:
|
|
162
|
+
message?: SessionRecordV1 | null;
|
|
163
163
|
/**
|
|
164
164
|
* 兜底文本内容。
|
|
165
165
|
*/
|
|
@@ -172,11 +172,11 @@ export interface SessionPort {
|
|
|
172
172
|
/**
|
|
173
173
|
* 追加一条 assistant 消息。
|
|
174
174
|
*/
|
|
175
|
-
|
|
175
|
+
append_assistant_message(params: {
|
|
176
176
|
/**
|
|
177
177
|
* 已构造好的完整消息。
|
|
178
178
|
*/
|
|
179
|
-
message?:
|
|
179
|
+
message?: SessionRecordV1 | null;
|
|
180
180
|
/**
|
|
181
181
|
* 兜底文本内容。
|
|
182
182
|
*/
|
|
@@ -1,75 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent Session action
|
|
2
|
+
* Agent Session action 公开类型。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - action
|
|
6
|
-
* -
|
|
7
|
-
* - action
|
|
5
|
+
* - action 是 session records 中的 `type: "action"` 记录。
|
|
6
|
+
* - 同一份结构同时用于 JSONL 持久化与 `session.subscribe()` 实时事件。
|
|
7
|
+
* - action 不进入 LLM 输入;组装模型消息前必须过滤。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import type {
|
|
11
|
+
SessionActionRecordV1,
|
|
12
|
+
SessionActionStateV1,
|
|
13
|
+
} from "@/executor/types/SessionRecords.js";
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Session action 当前状态。
|
|
12
17
|
*/
|
|
13
|
-
export type AgentSessionActionState =
|
|
18
|
+
export type AgentSessionActionState = SessionActionStateV1;
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Session action 记录。
|
|
17
22
|
*/
|
|
18
|
-
export
|
|
19
|
-
/**
|
|
20
|
-
* 同一个 action 生命周期内稳定复用的 ID。
|
|
21
|
-
*
|
|
22
|
-
* 说明(中文)
|
|
23
|
-
* - 这是 history item envelope 字段,用于把同一个动作更新为一条记录。
|
|
24
|
-
* - 前端展示语义只依赖 `type/title/description/state`。
|
|
25
|
-
*/
|
|
26
|
-
id: string;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 当前 action 标题。
|
|
30
|
-
*/
|
|
31
|
-
title: string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 当前 action 描述。
|
|
35
|
-
*/
|
|
36
|
-
description?: string;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 当前 action 状态。
|
|
40
|
-
*/
|
|
41
|
-
state: AgentSessionActionState;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 当前 action 关联的 turn 标识。
|
|
45
|
-
*/
|
|
46
|
-
turnId?: string;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 是否建议前端展示。
|
|
50
|
-
*
|
|
51
|
-
* 说明(中文)
|
|
52
|
-
* - 默认视为 `true`。
|
|
53
|
-
* - 调试或审计类辅助事件可显式写入 `false`。
|
|
54
|
-
*/
|
|
55
|
-
visible?: boolean;
|
|
56
|
-
}
|
|
23
|
+
export type AgentSessionActionRecord = SessionActionRecordV1;
|
|
57
24
|
|
|
58
25
|
/**
|
|
59
26
|
* Session action 订阅事件。
|
|
60
27
|
*/
|
|
61
|
-
export
|
|
62
|
-
extends Omit<AgentSessionActionRecord, "visible"> {
|
|
63
|
-
/**
|
|
64
|
-
* 当前事件类型。
|
|
65
|
-
*/
|
|
66
|
-
type: "action";
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 当前 session 唯一标识。
|
|
70
|
-
*/
|
|
71
|
-
sessionId: string;
|
|
72
|
-
}
|
|
28
|
+
export type AgentSessionActionEvent = SessionActionRecordV1;
|
|
73
29
|
|
|
74
30
|
/**
|
|
75
31
|
* Session action 发布回调。
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - 增量过程继续通过 `session.subscribe()` 观察;turn handle 只负责等待最终完成结果。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
10
|
+
import type { SessionMessageRecordV1 } from "@/executor/types/SessionRecords.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* 单个 Session turn 的最终结果。
|
|
@@ -35,7 +35,7 @@ export interface AgentSessionTurnResult {
|
|
|
35
35
|
* - `turn.finished` 返回的结果以这条消息作为最终事实源。
|
|
36
36
|
* - transport / runtime service 若需要读取最终结构化输出,应优先消费这里。
|
|
37
37
|
*/
|
|
38
|
-
assistantMessage?:
|
|
38
|
+
assistantMessage?: SessionMessageRecordV1;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* 当前 turn 失败时的错误文本。
|