@downcity/agent 1.1.200 → 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 +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 +15 -31
- 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 +25 -25
- 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 +29 -44
- 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
package/src/session/Session.ts
CHANGED
|
@@ -15,8 +15,8 @@ import type {
|
|
|
15
15
|
AgentSession,
|
|
16
16
|
AgentSessionConfigSnapshot,
|
|
17
17
|
AgentSessionForkInput,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
AgentSessionRecordsInput,
|
|
19
|
+
AgentSessionRecordsPage,
|
|
20
20
|
AgentSessionInfo,
|
|
21
21
|
AgentSessionSetInput,
|
|
22
22
|
AgentSessionSystemBlock,
|
|
@@ -207,7 +207,7 @@ export class Session implements AgentSession {
|
|
|
207
207
|
/**
|
|
208
208
|
* 追加一条 user 文本消息。
|
|
209
209
|
*/
|
|
210
|
-
async
|
|
210
|
+
async append_user_message(input: {
|
|
211
211
|
text: string;
|
|
212
212
|
}): Promise<void> {
|
|
213
213
|
await this.stateService.append_user_message({
|
|
@@ -218,7 +218,7 @@ export class Session implements AgentSession {
|
|
|
218
218
|
/**
|
|
219
219
|
* 追加一条 assistant 文本消息。
|
|
220
220
|
*/
|
|
221
|
-
async
|
|
221
|
+
async append_assistant_message(input: {
|
|
222
222
|
text: string;
|
|
223
223
|
}): Promise<void> {
|
|
224
224
|
await this.stateService.append_assistant_message({
|
|
@@ -229,15 +229,15 @@ export class Session implements AgentSession {
|
|
|
229
229
|
/**
|
|
230
230
|
* 读取当前 session 详情。
|
|
231
231
|
*/
|
|
232
|
-
async
|
|
232
|
+
async get_info(): Promise<AgentSessionInfo> {
|
|
233
233
|
return await this.viewService.get_info();
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
/**
|
|
237
|
-
* 读取当前 session
|
|
237
|
+
* 读取当前 session records 分页。
|
|
238
238
|
*/
|
|
239
|
-
async
|
|
240
|
-
return await this.viewService.
|
|
239
|
+
async records(input?: AgentSessionRecordsInput): Promise<AgentSessionRecordsPage> {
|
|
240
|
+
return await this.viewService.records(input);
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
/**
|
|
@@ -288,10 +288,10 @@ export class Session implements AgentSession {
|
|
|
288
288
|
afterSessionUpdatedAsync: async () => {
|
|
289
289
|
await this.executor.afterSessionUpdatedAsync();
|
|
290
290
|
},
|
|
291
|
-
|
|
291
|
+
append_user_message: async (message_params) => {
|
|
292
292
|
await this.stateService.append_user_message(message_params);
|
|
293
293
|
},
|
|
294
|
-
|
|
294
|
+
append_assistant_message: async (message_params) => {
|
|
295
295
|
await this.stateService.append_assistant_message(message_params);
|
|
296
296
|
},
|
|
297
297
|
isExecuting: () => this.isExecuting(),
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import { generateText, type LanguageModel } from "ai";
|
|
11
11
|
import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
|
|
12
|
-
import type {
|
|
13
|
-
import {
|
|
12
|
+
import type { SessionRecordV1 } from "@/executor/types/SessionRecords.js";
|
|
13
|
+
import { is_session_message_record } from "@/executor/types/SessionRecords.js";
|
|
14
14
|
import {
|
|
15
15
|
normalizeSessionTitle,
|
|
16
16
|
readSessionMetadata,
|
|
@@ -41,7 +41,7 @@ export interface EnsureSessionTitleParams {
|
|
|
41
41
|
/**
|
|
42
42
|
* 当前 session 已落盘消息。
|
|
43
43
|
*/
|
|
44
|
-
messages:
|
|
44
|
+
messages: SessionRecordV1[];
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* 可选模型实例;传入时会尝试生成更短标题。
|
|
@@ -61,8 +61,8 @@ function truncateTitle(input: string, maxChars: number): string {
|
|
|
61
61
|
return title.slice(0, maxChars).trimEnd();
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
function extractTextFromMessage(message:
|
|
65
|
-
if (!
|
|
64
|
+
function extractTextFromMessage(message: SessionRecordV1): string {
|
|
65
|
+
if (!is_session_message_record(message)) return "";
|
|
66
66
|
if (!Array.isArray(message.parts)) return "";
|
|
67
67
|
const texts: string[] = [];
|
|
68
68
|
for (const part of message.parts) {
|
|
@@ -76,9 +76,9 @@ function extractTextFromMessage(message: SessionMessageV1): string {
|
|
|
76
76
|
return texts.join("\n").trim();
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function resolveFirstUserText(messages:
|
|
79
|
+
function resolveFirstUserText(messages: SessionRecordV1[]): string {
|
|
80
80
|
for (const message of messages) {
|
|
81
|
-
if (!
|
|
81
|
+
if (!is_session_message_record(message)) continue;
|
|
82
82
|
if (message.role !== "user") continue;
|
|
83
83
|
const text = extractTextFromMessage(message);
|
|
84
84
|
if (text) return text;
|
|
@@ -17,24 +17,24 @@ import {
|
|
|
17
17
|
} from "ai";
|
|
18
18
|
import type {
|
|
19
19
|
AgentListSessionsInput,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
AgentSessionRecordsInput,
|
|
21
|
+
AgentSessionRecordsPage,
|
|
22
|
+
AgentSessionRecordsView,
|
|
23
23
|
AgentSessionInfo,
|
|
24
24
|
AgentSessionSummary,
|
|
25
25
|
AgentSessionSummaryPage,
|
|
26
26
|
AgentSessionTimelineEvent,
|
|
27
27
|
} from "@/types/agent/AgentTypes.js";
|
|
28
28
|
import type {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
SessionActionRecordV1,
|
|
30
|
+
SessionRecordV1,
|
|
31
31
|
SessionMetadataV1,
|
|
32
|
-
|
|
33
|
-
} from "@/executor/types/
|
|
32
|
+
SessionMessageRecordV1,
|
|
33
|
+
} from "@/executor/types/SessionRecords.js";
|
|
34
34
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from "@/executor/types/
|
|
35
|
+
is_session_action_record,
|
|
36
|
+
is_session_message_record,
|
|
37
|
+
} from "@/executor/types/SessionRecords.js";
|
|
38
38
|
import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
|
|
39
39
|
import { pickLastSuccessfulChatSendText } from "@/executor/messages/UserVisibleText.js";
|
|
40
40
|
import { getSdkAgentSessionMessagesPath } from "@/session/storage/Paths.js";
|
|
@@ -81,7 +81,7 @@ type SessionBrowseBaseInput = {
|
|
|
81
81
|
/**
|
|
82
82
|
* 当前 session 已读取到的完整消息。
|
|
83
83
|
*/
|
|
84
|
-
messages:
|
|
84
|
+
messages: SessionRecordV1[];
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* 当前 session 是否正在执行。
|
|
@@ -177,7 +177,7 @@ function extractMessageText(parts: unknown): string {
|
|
|
177
177
|
return texts.join("\n").trim();
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
function extractAssistantToolSummary(message:
|
|
180
|
+
function extractAssistantToolSummary(message: SessionMessageRecordV1): string {
|
|
181
181
|
if (!Array.isArray(message.parts)) return "";
|
|
182
182
|
const toolNames = new Set<string>();
|
|
183
183
|
for (const part of message.parts as AnyUiPart[]) {
|
|
@@ -193,13 +193,13 @@ function extractAssistantToolSummary(message: SessionModelMessageV1): string {
|
|
|
193
193
|
/**
|
|
194
194
|
* 解析单条 session 消息的用户可见预览文本。
|
|
195
195
|
*/
|
|
196
|
-
export function resolveSessionMessagePreview(message:
|
|
197
|
-
if (
|
|
196
|
+
export function resolveSessionMessagePreview(message: SessionRecordV1): string {
|
|
197
|
+
if (is_session_action_record(message)) {
|
|
198
198
|
return message.description
|
|
199
199
|
? `${message.title}\n${message.description}`
|
|
200
200
|
: message.title;
|
|
201
201
|
}
|
|
202
|
-
if (!
|
|
202
|
+
if (!is_session_message_record(message)) return "";
|
|
203
203
|
const plainText = extractMessageText(message.parts);
|
|
204
204
|
if (plainText) return plainText;
|
|
205
205
|
if (message.role !== "assistant") return "";
|
|
@@ -237,7 +237,7 @@ function extractToolResultOutput(part: ToolPartCompatShape): unknown {
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
function toTimelineEvent(params: {
|
|
240
|
-
message:
|
|
240
|
+
message: SessionMessageRecordV1;
|
|
241
241
|
role: AgentSessionTimelineEvent["role"];
|
|
242
242
|
text: string;
|
|
243
243
|
sequence: number;
|
|
@@ -256,7 +256,7 @@ function toTimelineEvent(params: {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
function toActionTimelineEvent(
|
|
259
|
-
message:
|
|
259
|
+
message: SessionActionRecordV1,
|
|
260
260
|
): AgentSessionTimelineEvent {
|
|
261
261
|
const metadata = message.metadata || null;
|
|
262
262
|
return {
|
|
@@ -274,13 +274,13 @@ function toActionTimelineEvent(
|
|
|
274
274
|
* 把单条 session message 展平成时间线事件。
|
|
275
275
|
*/
|
|
276
276
|
export function toSessionTimelineEvents(
|
|
277
|
-
message:
|
|
277
|
+
message: SessionRecordV1,
|
|
278
278
|
): AgentSessionTimelineEvent[] {
|
|
279
|
-
if (
|
|
279
|
+
if (is_session_action_record(message)) {
|
|
280
280
|
return [toActionTimelineEvent(message)];
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
-
if (!
|
|
283
|
+
if (!is_session_message_record(message)) return [];
|
|
284
284
|
if (message.role !== "assistant") {
|
|
285
285
|
return [
|
|
286
286
|
toTimelineEvent({
|
|
@@ -366,14 +366,14 @@ export function toSessionTimelineEvents(
|
|
|
366
366
|
*/
|
|
367
367
|
export async function loadSessionMessagesFromPath(
|
|
368
368
|
filePath: string,
|
|
369
|
-
): Promise<
|
|
370
|
-
const messages:
|
|
369
|
+
): Promise<SessionRecordV1[]> {
|
|
370
|
+
const messages: SessionRecordV1[] = [];
|
|
371
371
|
if (await fs.pathExists(filePath)) {
|
|
372
372
|
const raw = await fs.readFile(filePath, "utf-8");
|
|
373
373
|
const lines = raw.split("\n").filter(Boolean);
|
|
374
374
|
for (const line of lines) {
|
|
375
375
|
try {
|
|
376
|
-
const parsed = JSON.parse(line) as
|
|
376
|
+
const parsed = JSON.parse(line) as SessionRecordV1;
|
|
377
377
|
if (!parsed || typeof parsed !== "object") continue;
|
|
378
378
|
const candidate = parsed as { type?: unknown; role?: unknown };
|
|
379
379
|
if (
|
|
@@ -393,9 +393,9 @@ export async function loadSessionMessagesFromPath(
|
|
|
393
393
|
const inflight_path = filePath.replace(/messages\.jsonl$/, "inflight.json");
|
|
394
394
|
if (await fs.pathExists(inflight_path)) {
|
|
395
395
|
try {
|
|
396
|
-
const parsed = (await fs.readJson(inflight_path)) as
|
|
396
|
+
const parsed = (await fs.readJson(inflight_path)) as SessionRecordV1;
|
|
397
397
|
if (
|
|
398
|
-
|
|
398
|
+
is_session_message_record(parsed) &&
|
|
399
399
|
parsed.role === "assistant" &&
|
|
400
400
|
Array.isArray(parsed.parts)
|
|
401
401
|
) {
|
|
@@ -418,11 +418,11 @@ export async function loadSessionMessagesFromPath(
|
|
|
418
418
|
*/
|
|
419
419
|
export async function loadSessionArchiveMessagesFromPath(
|
|
420
420
|
filePath: string,
|
|
421
|
-
): Promise<
|
|
421
|
+
): Promise<SessionRecordV1[]> {
|
|
422
422
|
try {
|
|
423
423
|
const raw = (await fs.readJson(filePath)) as SessionArchiveFileV1 | null;
|
|
424
424
|
const items = Array.isArray(raw?.messages) ? raw.messages : [];
|
|
425
|
-
return items.filter((item): item is
|
|
425
|
+
return items.filter((item): item is SessionRecordV1 => {
|
|
426
426
|
if (!item || typeof item !== "object") return false;
|
|
427
427
|
const candidate = item as { type?: unknown; role?: unknown; parts?: unknown };
|
|
428
428
|
return (
|
|
@@ -439,13 +439,13 @@ export async function loadSessionArchiveMessagesFromPath(
|
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
function isCompactSummaryMessage(message:
|
|
443
|
-
if (!
|
|
442
|
+
function isCompactSummaryMessage(message: SessionRecordV1): boolean {
|
|
443
|
+
if (!is_session_message_record(message)) return false;
|
|
444
444
|
const metadata = (message.metadata || null) as SessionMetadataV1 | null;
|
|
445
445
|
return metadata?.source === "compact" || metadata?.kind === "summary";
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
-
function resolvePreviousArchiveId(messages:
|
|
448
|
+
function resolvePreviousArchiveId(messages: SessionRecordV1[]): string | undefined {
|
|
449
449
|
for (const message of messages) {
|
|
450
450
|
if (!isCompactSummaryMessage(message)) continue;
|
|
451
451
|
const metadata = (message.metadata || null) as SessionMetadataV1 | null;
|
|
@@ -456,8 +456,8 @@ function resolvePreviousArchiveId(messages: SessionMessageV1[]): string | undefi
|
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
function filterUserVisibleHistoryMessages(
|
|
459
|
-
messages:
|
|
460
|
-
):
|
|
459
|
+
messages: SessionRecordV1[],
|
|
460
|
+
): SessionRecordV1[] {
|
|
461
461
|
return messages.filter((message) => !isCompactSummaryMessage(message));
|
|
462
462
|
}
|
|
463
463
|
|
|
@@ -500,14 +500,14 @@ export function buildSessionInfo(
|
|
|
500
500
|
}
|
|
501
501
|
|
|
502
502
|
/**
|
|
503
|
-
* 基于完整消息列表构建 session
|
|
503
|
+
* 基于完整消息列表构建 session records 分页结果。
|
|
504
504
|
*/
|
|
505
|
-
export function
|
|
505
|
+
export function buildSessionRecordsPage(params: {
|
|
506
506
|
session: AgentSessionInfo;
|
|
507
|
-
messages:
|
|
508
|
-
input?:
|
|
509
|
-
}):
|
|
510
|
-
const view:
|
|
507
|
+
messages: SessionRecordV1[];
|
|
508
|
+
input?: AgentSessionRecordsInput;
|
|
509
|
+
}): AgentSessionRecordsPage {
|
|
510
|
+
const view: AgentSessionRecordsView = params.input?.view || "message";
|
|
511
511
|
const order = params.input?.order || "asc";
|
|
512
512
|
const limit = normalizeLimit(params.input?.limit, 50, 500);
|
|
513
513
|
const cursor = normalizeCursor(params.input?.cursor);
|
package/src/session/index.ts
CHANGED
|
@@ -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
|
-
AgentSessionActionEvent,
|
|
35
|
-
AgentSessionActionRecord,
|
|
36
|
-
} from "@/types/sdk/AgentSessionAction.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
|
|
|
@@ -96,8 +95,7 @@ type SessionSetOptions = {
|
|
|
96
95
|
emit_action?: boolean;
|
|
97
96
|
};
|
|
98
97
|
|
|
99
|
-
type EmitActionInput =
|
|
100
|
-
Partial<Pick<AgentSessionActionRecord, "id">>;
|
|
98
|
+
type EmitActionInput = SessionActionRecordInputV1 | SessionActionRecordV1;
|
|
101
99
|
|
|
102
100
|
/**
|
|
103
101
|
* 本地 Session 状态与持久化服务。
|
|
@@ -281,10 +279,10 @@ export class SessionStateService {
|
|
|
281
279
|
* 追加一条 user 消息并刷新标题与 metadata。
|
|
282
280
|
*/
|
|
283
281
|
async append_user_message(params: {
|
|
284
|
-
message?:
|
|
282
|
+
message?: SessionRecordV1 | null;
|
|
285
283
|
text?: string;
|
|
286
284
|
}): Promise<void> {
|
|
287
|
-
await this.executor.
|
|
285
|
+
await this.executor.append_user_message(params);
|
|
288
286
|
await this.ensure_title_from_history({ generate: true });
|
|
289
287
|
await this.touch_metadata();
|
|
290
288
|
}
|
|
@@ -293,10 +291,10 @@ export class SessionStateService {
|
|
|
293
291
|
* 追加一条 assistant 消息并刷新 metadata。
|
|
294
292
|
*/
|
|
295
293
|
async append_assistant_message(params: {
|
|
296
|
-
message?:
|
|
294
|
+
message?: SessionRecordV1 | null;
|
|
297
295
|
fallbackText?: string;
|
|
298
296
|
}): Promise<void> {
|
|
299
|
-
await this.executor.
|
|
297
|
+
await this.executor.append_assistant_message(params);
|
|
300
298
|
await this.touch_metadata();
|
|
301
299
|
}
|
|
302
300
|
|
|
@@ -321,7 +319,7 @@ export class SessionStateService {
|
|
|
321
319
|
*/
|
|
322
320
|
generate?: boolean;
|
|
323
321
|
}): Promise<void> {
|
|
324
|
-
const messages = await this.history_store.
|
|
322
|
+
const messages = await this.history_store.list_records();
|
|
325
323
|
const before_metadata = await readSessionMetadata({
|
|
326
324
|
projectRoot: this.project_root,
|
|
327
325
|
agentId: this.agent_id,
|
|
@@ -349,7 +347,7 @@ export class SessionStateService {
|
|
|
349
347
|
* 持久化最终 assistant 结果。
|
|
350
348
|
*/
|
|
351
349
|
async persist_assistant_result(
|
|
352
|
-
assistant_message?:
|
|
350
|
+
assistant_message?: SessionMessageRecordV1 | null,
|
|
353
351
|
): Promise<void> {
|
|
354
352
|
await persistSdkAssistantResult({
|
|
355
353
|
projectRoot: this.project_root,
|
|
@@ -362,24 +360,13 @@ export class SessionStateService {
|
|
|
362
360
|
}
|
|
363
361
|
|
|
364
362
|
/**
|
|
365
|
-
* 持久化一条 action
|
|
363
|
+
* 持久化一条 action record。
|
|
366
364
|
*/
|
|
367
365
|
async persist_action_event(
|
|
368
|
-
event:
|
|
366
|
+
event: SessionActionRecordV1,
|
|
369
367
|
): Promise<void> {
|
|
370
|
-
const message = this.
|
|
371
|
-
|
|
372
|
-
id: event.id,
|
|
373
|
-
title: event.title,
|
|
374
|
-
state: event.state,
|
|
375
|
-
...(event.description ? { description: event.description } : {}),
|
|
376
|
-
...(event.turnId ? { turnId: event.turnId } : {}),
|
|
377
|
-
},
|
|
378
|
-
metadata: {
|
|
379
|
-
sessionId: this.session_id,
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
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);
|
|
383
370
|
await this.touch_metadata();
|
|
384
371
|
}
|
|
385
372
|
|
|
@@ -387,17 +374,15 @@ export class SessionStateService {
|
|
|
387
374
|
* 写入并发布一条 action。
|
|
388
375
|
*/
|
|
389
376
|
async emit_action_event(input: EmitActionInput): Promise<void> {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
id: action_id,
|
|
400
|
-
};
|
|
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
|
+
);
|
|
401
386
|
try {
|
|
402
387
|
await this.persist_action_event(event);
|
|
403
388
|
} catch {
|
|
@@ -420,7 +405,7 @@ export class SessionStateService {
|
|
|
420
405
|
sessionId: this.session_id,
|
|
421
406
|
},
|
|
422
407
|
}) as SessionUserMessageV1;
|
|
423
|
-
await this.executor.
|
|
408
|
+
await this.executor.append_user_message({
|
|
424
409
|
message,
|
|
425
410
|
});
|
|
426
411
|
await this.ensure_title_from_history({ generate: true });
|
|
@@ -445,7 +430,7 @@ export class SessionStateService {
|
|
|
445
430
|
kind: "normal",
|
|
446
431
|
},
|
|
447
432
|
};
|
|
448
|
-
await this.executor.
|
|
433
|
+
await this.executor.append_user_message({
|
|
449
434
|
message,
|
|
450
435
|
});
|
|
451
436
|
await this.ensure_title_from_history({ generate: true });
|
|
@@ -464,7 +449,7 @@ export class SessionStateService {
|
|
|
464
449
|
: [];
|
|
465
450
|
if (normalized_messages.length <= 0) return;
|
|
466
451
|
for (const message of normalized_messages) {
|
|
467
|
-
await this.executor.
|
|
452
|
+
await this.executor.append_user_message({
|
|
468
453
|
message,
|
|
469
454
|
});
|
|
470
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>();
|
|
@@ -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 {
|