@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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - Client 与 Server 共享同一份 request/frame 类型,避免协议两边漂移。
|
|
7
7
|
* - 字段名保持现有协议格式,兼容已发布的 downcity 托管 runtime 调用。
|
|
8
8
|
*/
|
|
9
|
-
import type { AgentCreateSessionInput, AgentListSessionsInput, AgentArchiveSessionsInput,
|
|
9
|
+
import type { AgentCreateSessionInput, AgentListSessionsInput, AgentArchiveSessionsInput, AgentSessionRecordsInput, AgentSessionSystemSnapshot } from "../../types/agent/AgentTypes.js";
|
|
10
10
|
import type { AgentSessionEvent } from "../../types/sdk/AgentSessionEvent.js";
|
|
11
11
|
import type { AgentSessionPromptInput } from "../../types/sdk/AgentSessionPrompt.js";
|
|
12
12
|
import type { JsonValue } from "../../types/common/Json.js";
|
|
@@ -90,14 +90,14 @@ export type RpcRequest = {
|
|
|
90
90
|
} | {
|
|
91
91
|
/** 请求 id,用于匹配响应。 */
|
|
92
92
|
id: string;
|
|
93
|
-
/** 读取 session
|
|
94
|
-
method: "sdk.sessions.
|
|
95
|
-
/**
|
|
93
|
+
/** 读取 session records。 */
|
|
94
|
+
method: "sdk.sessions.records";
|
|
95
|
+
/** records 查询参数。 */
|
|
96
96
|
params: {
|
|
97
97
|
/** 目标 session id。 */
|
|
98
98
|
sessionId: string;
|
|
99
|
-
/**
|
|
100
|
-
input?:
|
|
99
|
+
/** records 分页与视图参数。 */
|
|
100
|
+
input?: AgentSessionRecordsInput;
|
|
101
101
|
};
|
|
102
102
|
} | {
|
|
103
103
|
/** 请求 id,用于匹配响应。 */
|
|
@@ -13,7 +13,7 @@ import type { DowncityConfig } from "../../../types/config/DowncityConfig.js";
|
|
|
13
13
|
import type { JsonValue } from "../../../types/common/Json.js";
|
|
14
14
|
import type { AgentPlugins } from "../../../plugin/types/Plugin.js";
|
|
15
15
|
import type { Plugin } from "../../../types/plugin/PluginDefinition.js";
|
|
16
|
-
import type { SessionMetadataV1,
|
|
16
|
+
import type { SessionMetadataV1, SessionRecordV1 } from "../../../executor/types/SessionRecords.js";
|
|
17
17
|
import type { SessionRunInput, SessionRunResult } from "../../../executor/types/SessionRun.js";
|
|
18
18
|
import type { SessionHistoryStore } from "../../../executor/store/history/SessionHistoryStore.js";
|
|
19
19
|
import type { AgentSessionPromptInput } from "../../../types/sdk/AgentSessionPrompt.js";
|
|
@@ -113,7 +113,7 @@ export interface SessionPort {
|
|
|
113
113
|
*
|
|
114
114
|
* 关键点(中文)
|
|
115
115
|
* - 只广播订阅之后产生的事件。
|
|
116
|
-
* -
|
|
116
|
+
* - session records 仍通过 `getHistoryStore()` / SDK `records()` 读取。
|
|
117
117
|
*/
|
|
118
118
|
subscribe(subscriber: AgentSessionSubscriber): AgentSessionUnsubscribe;
|
|
119
119
|
/**
|
|
@@ -121,7 +121,7 @@ export interface SessionPort {
|
|
|
121
121
|
*
|
|
122
122
|
* 关键点(中文)
|
|
123
123
|
* - plugin runtime 用它把审批、外部进度等非模型 chunk 事件推送给订阅方。
|
|
124
|
-
* - 历史消息持久化仍由
|
|
124
|
+
* - 历史消息持久化仍由 append_user_message / append_assistant_message 负责。
|
|
125
125
|
*/
|
|
126
126
|
publishEvent(event: AgentSessionEvent): void;
|
|
127
127
|
/**
|
|
@@ -135,11 +135,11 @@ export interface SessionPort {
|
|
|
135
135
|
/**
|
|
136
136
|
* 追加一条 user 消息。
|
|
137
137
|
*/
|
|
138
|
-
|
|
138
|
+
append_user_message(params: {
|
|
139
139
|
/**
|
|
140
140
|
* 已构造好的完整消息。
|
|
141
141
|
*/
|
|
142
|
-
message?:
|
|
142
|
+
message?: SessionRecordV1 | null;
|
|
143
143
|
/**
|
|
144
144
|
* 兜底文本内容。
|
|
145
145
|
*/
|
|
@@ -152,11 +152,11 @@ export interface SessionPort {
|
|
|
152
152
|
/**
|
|
153
153
|
* 追加一条 assistant 消息。
|
|
154
154
|
*/
|
|
155
|
-
|
|
155
|
+
append_assistant_message(params: {
|
|
156
156
|
/**
|
|
157
157
|
* 已构造好的完整消息。
|
|
158
158
|
*/
|
|
159
|
-
message?:
|
|
159
|
+
message?: SessionRecordV1 | null;
|
|
160
160
|
/**
|
|
161
161
|
* 兜底文本内容。
|
|
162
162
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContext.d.ts","sourceRoot":"","sources":["../../../../src/types/runtime/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EACV,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"AgentContext.d.ts","sourceRoot":"","sources":["../../../../src/types/runtime/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;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IACjC,8BAA8B;IAC9B,QAAQ,CAAC,YAAY,EAAE,wBAAwB,CAAC;IAChD,0BAA0B;IAC1B,QAAQ,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,oBAAoB;IACpB,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,mBAAmB;IACnB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;gBAEtB,OAAO,EAAE,mBAAmB;IAiBxC;;;;;;OAMG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW;IAI1C;;OAEG;IACH,uBAAuB,IAAI,MAAM,EAAE;IAInC;;OAEG;IACH,wBAAwB,IAAI,MAAM;IAIlC;;;;;;OAMG;YACW,oBAAoB;CAmBnC;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CACtC,CAAC"}
|
|
@@ -1,65 +1,24 @@
|
|
|
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
|
+
import type { SessionActionRecordV1, SessionActionStateV1 } from "../../executor/types/SessionRecords.js";
|
|
9
10
|
/**
|
|
10
11
|
* Session action 当前状态。
|
|
11
12
|
*/
|
|
12
|
-
export type AgentSessionActionState =
|
|
13
|
+
export type AgentSessionActionState = SessionActionStateV1;
|
|
13
14
|
/**
|
|
14
15
|
* Session action 记录。
|
|
15
16
|
*/
|
|
16
|
-
export
|
|
17
|
-
/**
|
|
18
|
-
* 同一个 action 生命周期内稳定复用的 ID。
|
|
19
|
-
*
|
|
20
|
-
* 说明(中文)
|
|
21
|
-
* - 这是 history item envelope 字段,用于把同一个动作更新为一条记录。
|
|
22
|
-
* - 前端展示语义只依赖 `type/title/description/state`。
|
|
23
|
-
*/
|
|
24
|
-
id: string;
|
|
25
|
-
/**
|
|
26
|
-
* 当前 action 标题。
|
|
27
|
-
*/
|
|
28
|
-
title: string;
|
|
29
|
-
/**
|
|
30
|
-
* 当前 action 描述。
|
|
31
|
-
*/
|
|
32
|
-
description?: string;
|
|
33
|
-
/**
|
|
34
|
-
* 当前 action 状态。
|
|
35
|
-
*/
|
|
36
|
-
state: AgentSessionActionState;
|
|
37
|
-
/**
|
|
38
|
-
* 当前 action 关联的 turn 标识。
|
|
39
|
-
*/
|
|
40
|
-
turnId?: string;
|
|
41
|
-
/**
|
|
42
|
-
* 是否建议前端展示。
|
|
43
|
-
*
|
|
44
|
-
* 说明(中文)
|
|
45
|
-
* - 默认视为 `true`。
|
|
46
|
-
* - 调试或审计类辅助事件可显式写入 `false`。
|
|
47
|
-
*/
|
|
48
|
-
visible?: boolean;
|
|
49
|
-
}
|
|
17
|
+
export type AgentSessionActionRecord = SessionActionRecordV1;
|
|
50
18
|
/**
|
|
51
19
|
* Session action 订阅事件。
|
|
52
20
|
*/
|
|
53
|
-
export
|
|
54
|
-
/**
|
|
55
|
-
* 当前事件类型。
|
|
56
|
-
*/
|
|
57
|
-
type: "action";
|
|
58
|
-
/**
|
|
59
|
-
* 当前 session 唯一标识。
|
|
60
|
-
*/
|
|
61
|
-
sessionId: string;
|
|
62
|
-
}
|
|
21
|
+
export type AgentSessionActionEvent = SessionActionRecordV1;
|
|
63
22
|
/**
|
|
64
23
|
* Session action 发布回调。
|
|
65
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentSessionAction.d.ts","sourceRoot":"","sources":["../../../src/types/sdk/AgentSessionAction.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH
|
|
1
|
+
{"version":3,"file":"AgentSessionAction.d.ts","sourceRoot":"","sources":["../../../src/types/sdk/AgentSessionAction.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,oCAAoC,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,CACvC,MAAM,EAAE,uBAAuB,KAC5B,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
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
|
export {};
|
|
10
10
|
//# sourceMappingURL=AgentSessionAction.js.map
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - 同一个 turn 可以吸收多条 prompt,因此多个 prompt 可能返回相同 `id` 的 turn handle。
|
|
7
7
|
* - 增量过程继续通过 `session.subscribe()` 观察;turn handle 只负责等待最终完成结果。
|
|
8
8
|
*/
|
|
9
|
-
import type {
|
|
9
|
+
import type { SessionMessageRecordV1 } from "../../executor/types/SessionRecords.js";
|
|
10
10
|
/**
|
|
11
11
|
* 单个 Session turn 的最终结果。
|
|
12
12
|
*/
|
|
@@ -30,7 +30,7 @@ export interface AgentSessionTurnResult {
|
|
|
30
30
|
* - `turn.finished` 返回的结果以这条消息作为最终事实源。
|
|
31
31
|
* - transport / runtime service 若需要读取最终结构化输出,应优先消费这里。
|
|
32
32
|
*/
|
|
33
|
-
assistantMessage?:
|
|
33
|
+
assistantMessage?: SessionMessageRecordV1;
|
|
34
34
|
/**
|
|
35
35
|
* 当前 turn 失败时的错误文本。
|
|
36
36
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentSessionTurn.d.ts","sourceRoot":"","sources":["../../../src/types/sdk/AgentSessionTurn.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"AgentSessionTurn.d.ts","sourceRoot":"","sources":["../../../src/types/sdk/AgentSessionTurn.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAE1C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;OAMG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;;;;OAMG;IACH,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAEtC;;;;;;OAMG;IACH,QAAQ,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAC3C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@downcity/agent",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.202",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Downcity Agent 运行时 — 单 Agent 执行壳与本机 RPC 能力",
|
|
6
6
|
"main": "./bin/index.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@ai-sdk/openai-compatible": "^2.0.48",
|
|
20
|
-
"@downcity/shell": "^0.1.
|
|
21
|
-
"@downcity/type": "0.1.
|
|
20
|
+
"@downcity/shell": "^0.1.71",
|
|
21
|
+
"@downcity/type": "0.1.104",
|
|
22
22
|
"ai": "^6.0.193",
|
|
23
23
|
"commander": "^15.0.0",
|
|
24
24
|
"dotenv": "^17.4.2",
|
|
@@ -144,7 +144,7 @@ test("session.prompt waits for agent background ready before model execution", a
|
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
try {
|
|
147
|
-
const session = await agent.
|
|
147
|
+
const session = await agent.sessions.create({
|
|
148
148
|
sessionId: "ready_session",
|
|
149
149
|
});
|
|
150
150
|
const prompt_promise = session.prompt({
|
|
@@ -14,6 +14,7 @@ import os from "node:os";
|
|
|
14
14
|
import path from "node:path";
|
|
15
15
|
import fs from "node:fs/promises";
|
|
16
16
|
import { Agent } from "../bin/index.js";
|
|
17
|
+
import { createAction, createPlugin } from "../bin/plugin/core/PluginActionFactory.js";
|
|
17
18
|
import { City } from "../../city/bin/index.js";
|
|
18
19
|
import { tool } from "ai";
|
|
19
20
|
import { z } from "zod";
|
|
@@ -224,12 +225,13 @@ test("CityModel uses direct LanguageModel path and sends tool result back", asyn
|
|
|
224
225
|
|
|
225
226
|
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
226
227
|
|
|
228
|
+
let agent;
|
|
227
229
|
try {
|
|
228
230
|
const address = server.address();
|
|
229
231
|
assert.ok(address && typeof address === "object");
|
|
230
232
|
const city = new City({
|
|
231
233
|
role: "user",
|
|
232
|
-
|
|
234
|
+
federation_url: `http://127.0.0.1:${String(address.port)}`,
|
|
233
235
|
city_id: "city_demo",
|
|
234
236
|
user_token: "ub_test",
|
|
235
237
|
});
|
|
@@ -240,9 +242,25 @@ test("CityModel uses direct LanguageModel path and sends tool result back", asyn
|
|
|
240
242
|
const agent_path = await fs.mkdtemp(
|
|
241
243
|
path.join(os.tmpdir(), "downcity-agent-city-model-tool-loop-"),
|
|
242
244
|
);
|
|
243
|
-
const
|
|
245
|
+
const skill_plugin = createPlugin({
|
|
246
|
+
name: "skill",
|
|
247
|
+
title: "Skill",
|
|
248
|
+
description: "Test skill plugin",
|
|
249
|
+
actions: {
|
|
250
|
+
lookup: createAction({
|
|
251
|
+
description: "Lookup a skill",
|
|
252
|
+
execute: async ({ input }) => ({
|
|
253
|
+
success: true,
|
|
254
|
+
data: { name: input.name },
|
|
255
|
+
message: "loaded",
|
|
256
|
+
}),
|
|
257
|
+
}),
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
agent = new Agent({
|
|
244
261
|
id: "tool_loop_agent",
|
|
245
262
|
path: agent_path,
|
|
263
|
+
plugins: [skill_plugin],
|
|
246
264
|
tools: {
|
|
247
265
|
ping: tool({
|
|
248
266
|
description: "ping tool",
|
|
@@ -257,7 +275,7 @@ test("CityModel uses direct LanguageModel path and sends tool result back", asyn
|
|
|
257
275
|
},
|
|
258
276
|
});
|
|
259
277
|
|
|
260
|
-
const session = await agent.
|
|
278
|
+
const session = await agent.sessions.create();
|
|
261
279
|
await session.set({ model });
|
|
262
280
|
const turn = await session.prompt({ query: "please use the ping tool" });
|
|
263
281
|
const result = await turn.finished;
|
|
@@ -266,8 +284,19 @@ test("CityModel uses direct LanguageModel path and sends tool result back", asyn
|
|
|
266
284
|
assert.equal(tool_executed, true);
|
|
267
285
|
assert.equal(stream_requests, 0);
|
|
268
286
|
assert.equal(agent_requests.length, 2);
|
|
269
|
-
assert.equal(requests.every((request) => request?.city_id === "city_demo"), true);
|
|
270
287
|
assert.equal(agent_requests[0]?.model, "mock-model");
|
|
288
|
+
const plugin_call_tool = agent_requests[0]?.tools?.find(
|
|
289
|
+
(item) => item?.type === "function" && item?.function?.name === "plugin_call",
|
|
290
|
+
);
|
|
291
|
+
assert.ok(plugin_call_tool);
|
|
292
|
+
const plugin_call_parameters = plugin_call_tool.function.parameters;
|
|
293
|
+
assert.equal(plugin_call_parameters.type, "object");
|
|
294
|
+
assert.deepEqual(plugin_call_parameters.required, ["plugin", "action"]);
|
|
295
|
+
assert.equal(plugin_call_parameters.additionalProperties, false);
|
|
296
|
+
assert.equal(
|
|
297
|
+
plugin_call_parameters.properties.payload.additionalProperties,
|
|
298
|
+
true,
|
|
299
|
+
);
|
|
271
300
|
|
|
272
301
|
const second_request_messages = Array.isArray(agent_requests[1]?.messages)
|
|
273
302
|
? agent_requests[1].messages
|
|
@@ -278,6 +307,9 @@ test("CityModel uses direct LanguageModel path and sends tool result back", asyn
|
|
|
278
307
|
assert.match(serialized_second_messages, /echoed/);
|
|
279
308
|
assert.match(serialized_second_messages, /hello/);
|
|
280
309
|
} finally {
|
|
310
|
+
if (agent) {
|
|
311
|
+
await agent.dispose();
|
|
312
|
+
}
|
|
281
313
|
await new Promise((resolve, reject) => {
|
|
282
314
|
server.close((error) => {
|
|
283
315
|
if (error) {
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
invokePluginReadTool,
|
|
18
18
|
} from "../bin/executor/tools/plugin/PluginToolBridge.js";
|
|
19
19
|
import { createPluginTools } from "../bin/executor/tools/plugin/PluginToolDefinition.js";
|
|
20
|
+
import { plugin_call_input_schema } from "../bin/executor/tools/plugin/PluginToolSchemas.js";
|
|
20
21
|
import { withSessionRunScope } from "../bin/executor/SessionRunScope.js";
|
|
21
22
|
import { createAction, createPlugin } from "../bin/plugin/core/PluginActionFactory.js";
|
|
22
23
|
import { createAgentPluginRegistry } from "../bin/agent/local/AgentPluginFactory.js";
|
|
@@ -32,6 +33,18 @@ function create_run_context(project_root) {
|
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
test("plugin_call payload schema allows arbitrary object properties", async () => {
|
|
37
|
+
const plugin_call_schema = await plugin_call_input_schema.jsonSchema;
|
|
38
|
+
const payload_schema = plugin_call_schema.properties.payload;
|
|
39
|
+
|
|
40
|
+
assert.equal(plugin_call_schema.type, "object");
|
|
41
|
+
assert.deepEqual(plugin_call_schema.required, ["plugin", "action"]);
|
|
42
|
+
assert.equal(plugin_call_schema.additionalProperties, false);
|
|
43
|
+
assert.equal(payload_schema.type, "object");
|
|
44
|
+
assert.equal(payload_schema.additionalProperties, true);
|
|
45
|
+
assert.deepEqual(payload_schema.default, {});
|
|
46
|
+
});
|
|
47
|
+
|
|
35
48
|
test("invokePluginCallTool returns absolute paths for materialized file parts", async () => {
|
|
36
49
|
const project_root = await fs.mkdtemp(
|
|
37
50
|
path.join(os.tmpdir(), "downcity-agent-plugin-tool-files-"),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file 验证 action
|
|
2
|
+
* @file 验证 action record 的持久化、模型输入过滤与 timeline 投影。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - action
|
|
5
|
+
* - action record 会作为 `type=action` item 写入 JSONL。
|
|
6
6
|
* - 同一个 action id 会被更新为一条历史记录,不拆成 running/completed 多条。
|
|
7
|
-
* - history composer 组装 LLM 输入时必须过滤 action
|
|
7
|
+
* - history composer 组装 LLM 输入时必须过滤 action record。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import test from "node:test";
|
|
@@ -18,7 +18,7 @@ import { JsonlSessionHistoryComposer } from "../bin/executor/composer/history/js
|
|
|
18
18
|
import { toSessionTimelineEvents } from "../bin/session/browse/Browse.js";
|
|
19
19
|
import { Agent } from "../bin/index.js";
|
|
20
20
|
|
|
21
|
-
test("action
|
|
21
|
+
test("action record is upserted but filtered from LLM history", async () => {
|
|
22
22
|
const root_path = await fs.mkdtemp(
|
|
23
23
|
path.join(os.tmpdir(), "downcity-agent-action-message-"),
|
|
24
24
|
);
|
|
@@ -30,29 +30,29 @@ test("action message is upserted but filtered from LLM history", async () => {
|
|
|
30
30
|
});
|
|
31
31
|
const composer = new JsonlSessionHistoryComposer({ store });
|
|
32
32
|
|
|
33
|
-
await store.
|
|
33
|
+
await store.write_record(
|
|
34
34
|
store.userText({
|
|
35
35
|
text: "hello",
|
|
36
36
|
metadata: { sessionId: session_id },
|
|
37
37
|
id: "u:1",
|
|
38
38
|
}),
|
|
39
39
|
);
|
|
40
|
-
await store.
|
|
40
|
+
await store.write_record(
|
|
41
41
|
store.action({
|
|
42
42
|
action: {
|
|
43
43
|
id: "action:1",
|
|
44
|
-
title: "Compacting session
|
|
44
|
+
title: "Compacting session records",
|
|
45
45
|
state: "running",
|
|
46
46
|
turnId: "turn-1",
|
|
47
47
|
},
|
|
48
48
|
metadata: { sessionId: session_id },
|
|
49
49
|
}),
|
|
50
50
|
);
|
|
51
|
-
await store.
|
|
51
|
+
await store.write_record(
|
|
52
52
|
store.action({
|
|
53
53
|
action: {
|
|
54
54
|
id: "action:1",
|
|
55
|
-
title: "Session
|
|
55
|
+
title: "Session records compacted",
|
|
56
56
|
description: "Compacted earlier messages.",
|
|
57
57
|
state: "completed",
|
|
58
58
|
turnId: "turn-1",
|
|
@@ -60,7 +60,7 @@ test("action message is upserted but filtered from LLM history", async () => {
|
|
|
60
60
|
metadata: { sessionId: session_id },
|
|
61
61
|
}),
|
|
62
62
|
);
|
|
63
|
-
await store.
|
|
63
|
+
await store.write_record(
|
|
64
64
|
store.assistantText({
|
|
65
65
|
text: "world",
|
|
66
66
|
metadata: { sessionId: session_id },
|
|
@@ -68,10 +68,10 @@ test("action message is upserted but filtered from LLM history", async () => {
|
|
|
68
68
|
}),
|
|
69
69
|
);
|
|
70
70
|
|
|
71
|
-
const persisted_messages = await store.
|
|
71
|
+
const persisted_messages = await store.list_records();
|
|
72
72
|
assert.equal(persisted_messages.length, 3);
|
|
73
73
|
assert.equal(persisted_messages[1].type, "action");
|
|
74
|
-
assert.equal(persisted_messages[1].title, "Session
|
|
74
|
+
assert.equal(persisted_messages[1].title, "Session records compacted");
|
|
75
75
|
assert.equal(persisted_messages[1].description, "Compacted earlier messages.");
|
|
76
76
|
assert.equal(persisted_messages[1].state, "completed");
|
|
77
77
|
|
|
@@ -90,12 +90,12 @@ test("action message is upserted but filtered from LLM history", async () => {
|
|
|
90
90
|
const timeline_events = toSessionTimelineEvents(persisted_messages[1]);
|
|
91
91
|
assert.equal(timeline_events.length, 1);
|
|
92
92
|
assert.equal(timeline_events[0].role, "action");
|
|
93
|
-
assert.equal(timeline_events[0].actionTitle, "Session
|
|
93
|
+
assert.equal(timeline_events[0].actionTitle, "Session records compacted");
|
|
94
94
|
assert.equal(timeline_events[0].actionDescription, "Compacted earlier messages.");
|
|
95
95
|
assert.equal(timeline_events[0].actionState, "completed");
|
|
96
96
|
assert.equal(
|
|
97
97
|
timeline_events[0].text,
|
|
98
|
-
"Session
|
|
98
|
+
"Session records compacted\nCompacted earlier messages.",
|
|
99
99
|
);
|
|
100
100
|
});
|
|
101
101
|
|
|
@@ -108,7 +108,7 @@ test("session.set persists and publishes model-switching actions", async () => {
|
|
|
108
108
|
path: agent_path,
|
|
109
109
|
});
|
|
110
110
|
try {
|
|
111
|
-
const session = await agent.
|
|
111
|
+
const session = await agent.sessions.create({
|
|
112
112
|
sessionId: "model_switching_session",
|
|
113
113
|
});
|
|
114
114
|
const events = [];
|
|
@@ -130,8 +130,8 @@ test("session.set persists and publishes model-switching actions", async () => {
|
|
|
130
130
|
);
|
|
131
131
|
assert.equal(new Set(events.map((event) => event.id)).size, 1);
|
|
132
132
|
|
|
133
|
-
const
|
|
134
|
-
const action_events =
|
|
133
|
+
const records = await session.records({ view: "timeline" });
|
|
134
|
+
const action_events = records.items.filter(
|
|
135
135
|
(item) => item.role === "action",
|
|
136
136
|
);
|
|
137
137
|
assert.deepEqual(
|
|
@@ -152,7 +152,7 @@ test("session.fork persists and publishes history-forking actions on source sess
|
|
|
152
152
|
path: agent_path,
|
|
153
153
|
});
|
|
154
154
|
try {
|
|
155
|
-
const session = await agent.
|
|
155
|
+
const session = await agent.sessions.create({
|
|
156
156
|
sessionId: "history_forking_session",
|
|
157
157
|
});
|
|
158
158
|
await session.set({
|
|
@@ -161,7 +161,7 @@ test("session.fork persists and publishes history-forking actions on source sess
|
|
|
161
161
|
provider: "test",
|
|
162
162
|
},
|
|
163
163
|
});
|
|
164
|
-
await session.
|
|
164
|
+
await session.append_user_message({ text: "source message" });
|
|
165
165
|
|
|
166
166
|
const events = [];
|
|
167
167
|
const unsubscribe = session.subscribe((event) => {
|
|
@@ -174,22 +174,22 @@ test("session.fork persists and publishes history-forking actions on source sess
|
|
|
174
174
|
|
|
175
175
|
assert.deepEqual(
|
|
176
176
|
events.map((event) => `${event.title}:${event.state}`),
|
|
177
|
-
["Forking session
|
|
177
|
+
["Forking session records:running", "Session records forked:completed"],
|
|
178
178
|
);
|
|
179
179
|
assert.equal(new Set(events.map((event) => event.id)).size, 1);
|
|
180
180
|
assert.notEqual(forked.id, session.id);
|
|
181
181
|
|
|
182
|
-
const
|
|
183
|
-
const source_fork_actions =
|
|
184
|
-
(item) => item.role === "action" && item.actionTitle === "Session
|
|
182
|
+
const source_records = await session.records({ view: "timeline" });
|
|
183
|
+
const source_fork_actions = source_records.items.filter(
|
|
184
|
+
(item) => item.role === "action" && item.actionTitle === "Session records forked",
|
|
185
185
|
);
|
|
186
186
|
assert.deepEqual(
|
|
187
187
|
source_fork_actions.map((event) => event.actionState),
|
|
188
188
|
["completed"],
|
|
189
189
|
);
|
|
190
190
|
|
|
191
|
-
const
|
|
192
|
-
const forked_model_actions =
|
|
191
|
+
const forked_records = await forked.records({ view: "timeline" });
|
|
192
|
+
const forked_model_actions = forked_records.items.filter(
|
|
193
193
|
(item) => item.role === "action" && item.actionTitle === "Session model switched",
|
|
194
194
|
);
|
|
195
195
|
assert.equal(forked_model_actions.length, 1);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file 验证 session compact prompt 与文件操作 XML 记录。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - compact prompt 必须保持结构化摘要格式稳定。
|
|
6
|
+
* - 迭代更新 prompt 需要携带 previous-summary 标签。
|
|
7
|
+
* - 文件操作 XML 由本地解析追加,不依赖模型复述工具日志。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import test from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
SESSION_COMPACTION_SYSTEM_PROMPT,
|
|
15
|
+
append_session_compaction_file_operations,
|
|
16
|
+
build_initial_session_compaction_prompt,
|
|
17
|
+
build_turn_prefix_session_compaction_prompt,
|
|
18
|
+
build_update_session_compaction_prompt,
|
|
19
|
+
} from "../bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js";
|
|
20
|
+
import {
|
|
21
|
+
collect_session_compaction_file_operations,
|
|
22
|
+
format_session_compaction_file_operations,
|
|
23
|
+
} from "../bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js";
|
|
24
|
+
|
|
25
|
+
test("session compaction prompts preserve structured formats", () => {
|
|
26
|
+
assert.match(
|
|
27
|
+
SESSION_COMPACTION_SYSTEM_PROMPT,
|
|
28
|
+
/Do NOT continue the conversation/,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const initial_prompt = build_initial_session_compaction_prompt({
|
|
32
|
+
conversation_text: "user: 请修改 packages/agent/src/foo.ts",
|
|
33
|
+
});
|
|
34
|
+
assert.match(initial_prompt, /## Goal/);
|
|
35
|
+
assert.match(initial_prompt, /## Constraints & Preferences/);
|
|
36
|
+
assert.match(initial_prompt, /## Critical Context/);
|
|
37
|
+
assert.match(
|
|
38
|
+
initial_prompt,
|
|
39
|
+
/Keep each section concise\. Preserve exact file paths/,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const update_prompt = build_update_session_compaction_prompt({
|
|
43
|
+
previous_summary: "## Goal\n旧目标",
|
|
44
|
+
new_conversation_text: "assistant: 已完成一部分",
|
|
45
|
+
});
|
|
46
|
+
assert.match(update_prompt, /<previous-summary>\n## Goal\n旧目标\n<\/previous-summary>/);
|
|
47
|
+
assert.match(update_prompt, /PRESERVE all existing information/);
|
|
48
|
+
assert.match(update_prompt, /## Next Steps/);
|
|
49
|
+
|
|
50
|
+
const prefix_prompt = build_turn_prefix_session_compaction_prompt({
|
|
51
|
+
prefix_text: "user: 这个 turn 太长",
|
|
52
|
+
});
|
|
53
|
+
assert.match(prefix_prompt, /## Original Request/);
|
|
54
|
+
assert.match(prefix_prompt, /## Context for Suffix/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("session compaction file operations are appended as xml", () => {
|
|
58
|
+
const messages = [
|
|
59
|
+
{
|
|
60
|
+
id: "a:1",
|
|
61
|
+
role: "assistant",
|
|
62
|
+
parts: [
|
|
63
|
+
{
|
|
64
|
+
type: "tool-exec_command",
|
|
65
|
+
input: {
|
|
66
|
+
cmd: "sed -n '1,40p' packages/agent/src/foo.ts && rg -n compact packages/agent/src",
|
|
67
|
+
},
|
|
68
|
+
output: [
|
|
69
|
+
"*** Update File: packages/agent/src/bar.ts",
|
|
70
|
+
" M packages/agent/src/baz.ts",
|
|
71
|
+
].join("\n"),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const operations = collect_session_compaction_file_operations(messages);
|
|
78
|
+
assert.deepEqual(operations.read_files, [
|
|
79
|
+
"packages/agent/src",
|
|
80
|
+
"packages/agent/src/foo.ts",
|
|
81
|
+
]);
|
|
82
|
+
assert.deepEqual(operations.modified_files, [
|
|
83
|
+
"packages/agent/src/bar.ts",
|
|
84
|
+
"packages/agent/src/baz.ts",
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
const xml = format_session_compaction_file_operations(messages);
|
|
88
|
+
assert.match(xml, /<read-files>\npackages\/agent\/src/);
|
|
89
|
+
assert.match(xml, /<modified-files>\npackages\/agent\/src\/bar\.ts/);
|
|
90
|
+
|
|
91
|
+
const summary = append_session_compaction_file_operations({
|
|
92
|
+
summary: "## Goal\n完成 compact",
|
|
93
|
+
file_operations_xml: xml,
|
|
94
|
+
});
|
|
95
|
+
assert.match(summary, /## Goal\n完成 compact\n\n<read-files>/);
|
|
96
|
+
assert.match(summary, /<\/modified-files>$/);
|
|
97
|
+
});
|