@downcity/agent 1.1.207 → 1.1.210
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 -3
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +0 -3
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/AgentInstructions.d.ts +2 -1
- package/bin/agent/local/AgentInstructions.d.ts.map +1 -1
- package/bin/agent/local/AgentInstructions.js +10 -10
- package/bin/agent/local/AgentInstructions.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +3 -8
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +0 -1
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentSessions.d.ts +5 -7
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessions.js +2 -3
- package/bin/agent/local/services/AgentSessions.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +3 -1
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +10 -1
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +18 -0
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +5 -1
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +4 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +7 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +4 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +1 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/Executor.d.ts +0 -16
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +0 -16
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +1 -3
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +1 -5
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts +0 -10
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.js +31 -61
- package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
- package/bin/executor/composer/system/default/StaticPromptCatalog.d.ts +4 -0
- package/bin/executor/composer/system/default/StaticPromptCatalog.d.ts.map +1 -1
- package/bin/executor/composer/system/default/StaticPromptCatalog.js +4 -0
- package/bin/executor/composer/system/default/StaticPromptCatalog.js.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts +1 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +2 -7
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts +0 -4
- package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js +0 -5
- package/bin/executor/composer/system/default/SystemPromptAssets.js.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/executor/messages/AssistantFileResource.d.ts.map +1 -1
- package/bin/executor/messages/AssistantFileResource.js +58 -15
- package/bin/executor/messages/AssistantFileResource.js.map +1 -1
- package/bin/executor/services/ExecutorInflightService.d.ts +0 -5
- package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -1
- package/bin/executor/services/ExecutorInflightService.js +0 -6
- package/bin/executor/services/ExecutorInflightService.js.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +4 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +115 -3
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +6 -0
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/index.d.ts +38 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +14 -1
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/ActionScheduleExecutor.js +1 -1
- package/bin/plugin/core/ActionScheduleExecutor.js.map +1 -1
- package/bin/plugin/core/BasePlugin.d.ts +7 -9
- package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.js +1 -14
- package/bin/plugin/core/BasePlugin.js.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +1 -1
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionFactory.d.ts +1 -5
- package/bin/plugin/core/PluginActionFactory.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionFactory.js +0 -3
- package/bin/plugin/core/PluginActionFactory.js.map +1 -1
- package/bin/plugin/core/PluginActionRunner.d.ts +6 -4
- package/bin/plugin/core/PluginActionRunner.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionRunner.js +2 -2
- package/bin/plugin/core/PluginActionRunner.js.map +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts +2 -1
- package/bin/plugin/core/PluginCatalog.d.ts.map +1 -1
- package/bin/plugin/core/PluginCatalog.js.map +1 -1
- package/bin/plugin/core/PluginCommand.d.ts +1 -1
- package/bin/plugin/core/PluginCommand.d.ts.map +1 -1
- package/bin/plugin/core/PluginCommand.js.map +1 -1
- package/bin/plugin/core/PluginHttpRoutes.d.ts +1 -1
- package/bin/plugin/core/PluginHttpRoutes.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts +4 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +0 -1
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +4 -2
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +7 -6
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +7 -27
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/plugin/core/PluginStateController.js +5 -39
- package/bin/plugin/core/PluginStateController.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +3 -79
- package/bin/plugin/types/PluginApi.d.ts.map +1 -1
- package/bin/rpc/Client.d.ts +11 -6
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +2 -0
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +2 -5
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +3 -16
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionSystemBuilder.d.ts +1 -1
- package/bin/session/SessionSystemBuilder.d.ts.map +1 -1
- package/bin/session/browse/Browse.d.ts +4 -6
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +71 -71
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/preview/SessionMessagePreview.d.ts +13 -0
- package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -0
- package/bin/session/preview/SessionMessagePreview.js +61 -0
- package/bin/session/preview/SessionMessagePreview.js.map +1 -0
- package/bin/session/services/SessionStateService.d.ts +1 -1
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +2 -2
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +2 -1
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +4 -1
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +23 -0
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts +1 -1
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +0 -12
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +0 -8
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/plugin/PluginAction.d.ts +0 -10
- package/bin/types/plugin/PluginAction.d.ts.map +1 -1
- package/bin/types/plugin/PluginCommand.d.ts +2 -3
- package/bin/types/plugin/PluginCommand.d.ts.map +1 -1
- package/bin/types/plugin/PluginControl.d.ts +74 -0
- package/bin/types/plugin/PluginControl.d.ts.map +1 -0
- package/bin/types/plugin/PluginControl.js +9 -0
- package/bin/types/plugin/PluginControl.js.map +1 -0
- package/bin/types/plugin/PluginDefinition.d.ts +1 -1
- package/bin/types/plugin/PluginDefinition.d.ts.map +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +1 -3
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.d.ts +3 -16
- package/bin/types/plugin/PluginState.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +3 -3
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +1 -9
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/session/SessionLocalState.d.ts +1 -1
- package/bin/types/session/SessionLocalState.d.ts.map +1 -1
- package/package.json +4 -7
- package/scripts/agent-ready.test.mjs +38 -0
- package/scripts/assistant-file-resource.test.mjs +39 -0
- package/scripts/city-model-tool-loop.test.mjs +18 -30
- package/scripts/image-plugin-job.test.mjs +13 -13
- package/scripts/plugin-tool-bridge.test.mjs +2 -3
- package/scripts/remote-session-reconnect.test.mjs +67 -0
- package/scripts/session-history-writer-error.test.mjs +57 -0
- package/scripts/session-list-title.test.mjs +114 -23
- package/scripts/session-system-blocks.test.mjs +73 -0
- package/src/agent/local/Agent.ts +4 -10
- package/src/agent/local/AgentInstructions.ts +11 -11
- package/src/agent/local/services/AgentAssemblyService.ts +3 -9
- package/src/agent/local/services/AgentSessions.ts +8 -15
- package/src/agent/remote/RemoteAgent.ts +5 -4
- package/src/agent/remote/RemoteSession.ts +21 -2
- package/src/agent/remote/RemoteTransport.ts +6 -2
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +13 -3
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +6 -2
- package/src/executor/Executor.ts +0 -23
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +2 -8
- package/src/executor/composer/history/SessionHistoryWriter.ts +33 -64
- package/src/executor/composer/system/default/StaticPromptCatalog.ts +4 -0
- package/src/executor/composer/system/default/SystemDomain.ts +1 -9
- package/src/executor/composer/system/default/SystemPromptAssets.ts +0 -6
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +37 -15
- package/src/executor/messages/AssistantFileResource.ts +61 -17
- package/src/executor/services/ExecutorInflightService.ts +0 -10
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +130 -4
- package/src/executor/types/SessionHistoryMeta.ts +6 -0
- package/src/index.ts +100 -29
- package/src/plugin/core/ActionScheduleExecutor.ts +1 -1
- package/src/plugin/core/BasePlugin.ts +8 -22
- package/src/plugin/core/HookRegistry.ts +1 -1
- package/src/plugin/core/PluginActionFactory.ts +1 -8
- package/src/plugin/core/PluginActionRunner.ts +8 -11
- package/src/plugin/core/PluginCatalog.ts +2 -5
- package/src/plugin/core/PluginCommand.ts +2 -1
- package/src/plugin/core/PluginHttpRoutes.ts +1 -1
- package/src/plugin/core/PluginLocalExecution.ts +4 -7
- package/src/plugin/core/PluginRegistry.ts +10 -10
- package/src/plugin/core/PluginStateController.ts +12 -60
- package/src/plugin/types/PluginApi.ts +6 -81
- package/src/rpc/Client.ts +22 -16
- package/src/session/Session.ts +5 -21
- package/src/session/SessionSystemBuilder.ts +1 -1
- package/src/session/browse/Browse.ts +103 -84
- package/src/session/preview/SessionMessagePreview.ts +75 -0
- package/src/session/services/SessionStateService.ts +3 -4
- package/src/session/services/SessionViewService.ts +6 -6
- package/src/session/storage/Metadata.ts +26 -0
- package/src/session/storage/Persistence.ts +1 -1
- package/src/session/storage/RuntimeSessionPort.ts +0 -20
- package/src/types/plugin/PluginAction.ts +0 -10
- package/src/types/plugin/PluginCommand.ts +2 -3
- package/src/types/plugin/PluginControl.ts +80 -0
- package/src/types/plugin/PluginDefinition.ts +1 -1
- package/src/types/plugin/PluginRuntime.ts +1 -3
- package/src/types/plugin/PluginState.ts +3 -20
- package/src/types/rpc/RpcProtocol.ts +4 -4
- package/src/types/runtime/agent/AgentContext.ts +1 -9
- package/src/types/session/SessionLocalState.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/config/DowncitySchema.d.ts +0 -20
- package/bin/config/DowncitySchema.d.ts.map +0 -1
- package/bin/config/DowncitySchema.js +0 -160
- package/bin/config/DowncitySchema.js.map +0 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts +0 -7
- package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts.map +0 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.js +0 -8
- package/bin/executor/composer/system/default/assets/plugin.prompt.js.map +0 -1
- package/bin/plugin/core/Activation.d.ts +0 -18
- package/bin/plugin/core/Activation.d.ts.map +0 -1
- package/bin/plugin/core/Activation.js +0 -21
- package/bin/plugin/core/Activation.js.map +0 -1
- package/bin/plugin/core/Manager.d.ts +0 -7
- package/bin/plugin/core/Manager.d.ts.map +0 -1
- package/bin/plugin/core/Manager.js +0 -6
- package/bin/plugin/core/Manager.js.map +0 -1
- package/bin/plugin/types/Plugin.d.ts +0 -15
- package/bin/plugin/types/Plugin.d.ts.map +0 -1
- package/bin/plugin/types/Plugin.js +0 -9
- package/bin/plugin/types/Plugin.js.map +0 -1
- package/bin/plugin/types/PluginLifecycle.d.ts +0 -34
- package/bin/plugin/types/PluginLifecycle.d.ts.map +0 -1
- package/bin/plugin/types/PluginLifecycle.js +0 -9
- package/bin/plugin/types/PluginLifecycle.js.map +0 -1
- package/bin/plugin/types/PluginState.d.ts +0 -5
- package/bin/plugin/types/PluginState.d.ts.map +0 -1
- package/bin/plugin/types/PluginState.js +0 -5
- package/bin/plugin/types/PluginState.js.map +0 -1
- package/bin/plugin/types/Plugins.d.ts +0 -61
- package/bin/plugin/types/Plugins.d.ts.map +0 -1
- package/bin/plugin/types/Plugins.js +0 -5
- package/bin/plugin/types/Plugins.js.map +0 -1
- package/bin/session/index.d.ts +0 -15
- package/bin/session/index.d.ts.map +0 -1
- package/bin/session/index.js +0 -15
- package/bin/session/index.js.map +0 -1
- package/bin/types/agent/AgentTypes.d.ts +0 -18
- package/bin/types/agent/AgentTypes.d.ts.map +0 -1
- package/bin/types/agent/AgentTypes.js +0 -10
- package/bin/types/agent/AgentTypes.js.map +0 -1
- package/bin/utils/logger/Format.d.ts +0 -11
- package/bin/utils/logger/Format.d.ts.map +0 -1
- package/bin/utils/logger/Format.js +0 -10
- package/bin/utils/logger/Format.js.map +0 -1
- package/src/config/DowncitySchema.ts +0 -175
- package/src/executor/composer/system/default/assets/plugin.prompt.ts +0 -9
- package/src/executor/composer/system/default/assets/plugin.prompt.ts.txt +0 -20
- package/src/plugin/core/Activation.ts +0 -26
- package/src/plugin/core/Manager.ts +0 -17
- package/src/plugin/types/Plugin.ts +0 -63
- package/src/plugin/types/PluginLifecycle.ts +0 -35
- package/src/plugin/types/PluginState.ts +0 -12
- package/src/plugin/types/Plugins.ts +0 -67
- package/src/session/index.ts +0 -57
- package/src/types/agent/AgentTypes.ts +0 -58
- package/src/utils/logger/Format.ts +0 -15
package/src/agent/local/Agent.ts
CHANGED
|
@@ -10,12 +10,10 @@
|
|
|
10
10
|
import type { Tool } from "ai";
|
|
11
11
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
12
12
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
13
|
-
import type { AgentPlugins } from "@/plugin/
|
|
14
|
-
import type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
AgentSessions as AgentSessionsApi,
|
|
18
|
-
} from "@/types/agent/AgentTypes.js";
|
|
13
|
+
import type { AgentPlugins } from "@/types/plugin/PluginRuntime.js";
|
|
14
|
+
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
15
|
+
import type { AgentOptions } from "@/types/agent/AgentOptions.js";
|
|
16
|
+
import type { AgentSessions as AgentSessionsApi } from "@/types/agent/SessionActor.js";
|
|
19
17
|
import type {
|
|
20
18
|
ShellApprovalMode,
|
|
21
19
|
ShellApprovalDecisionResult,
|
|
@@ -25,7 +23,6 @@ import type {
|
|
|
25
23
|
ShellApprovalView,
|
|
26
24
|
Shell,
|
|
27
25
|
} from "@downcity/shell";
|
|
28
|
-
import { PluginRegistry } from "@/plugin/core/PluginRegistry.js";
|
|
29
26
|
import { Logger } from "@/utils/logger/Logger.js";
|
|
30
27
|
import { normalizeInstructionInput } from "@/agent/local/AgentInstructions.js";
|
|
31
28
|
import {
|
|
@@ -47,7 +44,6 @@ export class Agent {
|
|
|
47
44
|
|
|
48
45
|
private readonly logger: Logger;
|
|
49
46
|
private readonly agentContext: AgentContext;
|
|
50
|
-
private readonly pluginRegistry: PluginRegistry;
|
|
51
47
|
private readonly config: DowncityConfig;
|
|
52
48
|
private readonly env: Record<string, string>;
|
|
53
49
|
private readonly defaultModel?: AgentModel;
|
|
@@ -84,7 +80,6 @@ export class Agent {
|
|
|
84
80
|
this.plugins = assembly.plugins;
|
|
85
81
|
this.logger = assembly.logger;
|
|
86
82
|
this.agentContext = assembly.agent_context;
|
|
87
|
-
this.pluginRegistry = assembly.plugin_registry;
|
|
88
83
|
this.config = assembly.config;
|
|
89
84
|
this.env = assembly.env;
|
|
90
85
|
this.instruction = assembly.instruction;
|
|
@@ -262,7 +257,6 @@ export class Agent {
|
|
|
262
257
|
logger: this.logger || assembly.logger,
|
|
263
258
|
get_agent_context: () => this.agentContext ?? assembly.agent_context,
|
|
264
259
|
get_instruction: () => this.instruction,
|
|
265
|
-
plugin_instances: assembly.plugin_instances,
|
|
266
260
|
ensure_agent_ready: async () => {
|
|
267
261
|
await this.backgroundService.ready();
|
|
268
262
|
},
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 这里只处理静态 instruction 与默认 core prompt。
|
|
6
|
+
* - instruction 永远在 core 前面;core 不会被调用方 instruction 替代。
|
|
6
7
|
* - 不读取 session、plugin 或 runtime 状态,保持为纯函数。
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
10
|
-
import type { AgentSessionSystemBlock } from "@/types/agent/
|
|
11
|
+
import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
|
|
11
12
|
import { DEFAULT_SHIP_PROMPTS } from "@executor/composer/system/default/SystemDomain.js";
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -51,18 +52,17 @@ export function createInstructionSystemBlocks(
|
|
|
51
52
|
instruction: string[],
|
|
52
53
|
project_root: string,
|
|
53
54
|
): AgentSessionSystemBlock[] {
|
|
54
|
-
|
|
55
|
-
return [
|
|
56
|
-
{
|
|
57
|
-
source: "core",
|
|
58
|
-
name: "default",
|
|
59
|
-
content: createCoreInstructionContent(project_root),
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
return instruction.map((content, index) => ({
|
|
55
|
+
const instruction_blocks = instruction.map((content, index) => ({
|
|
64
56
|
source: "instruction" as const,
|
|
65
57
|
name: instruction.length === 1 ? "agent" : `agent:${index + 1}`,
|
|
66
58
|
content,
|
|
67
59
|
}));
|
|
60
|
+
return [
|
|
61
|
+
...instruction_blocks,
|
|
62
|
+
{
|
|
63
|
+
source: "core",
|
|
64
|
+
name: "default",
|
|
65
|
+
content: createCoreInstructionContent(project_root),
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
68
|
}
|
|
@@ -11,8 +11,8 @@ import type { LanguageModel, Tool } from "ai";
|
|
|
11
11
|
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
12
12
|
import { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
13
13
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
14
|
-
import type { AgentPlugins } from "@/plugin/
|
|
15
|
-
import type { AgentOptions } from "@/types/agent/
|
|
14
|
+
import type { AgentPlugins } from "@/types/plugin/PluginRuntime.js";
|
|
15
|
+
import type { AgentOptions } from "@/types/agent/AgentOptions.js";
|
|
16
16
|
import { Logger } from "@/utils/logger/Logger.js";
|
|
17
17
|
import { loadDowncityConfig, resolveAgentEnv } from "@/config/Config.js";
|
|
18
18
|
import { PluginRegistry } from "@/plugin/core/PluginRegistry.js";
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
import {
|
|
31
31
|
createPluginTools,
|
|
32
32
|
} from "@executor/tools/plugin/PluginToolDefinition.js";
|
|
33
|
-
import type { AgentManagedSession } from "@/types/
|
|
33
|
+
import type { AgentManagedSession } from "@/types/session/SessionOptions.js";
|
|
34
34
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
35
35
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
36
36
|
|
|
@@ -102,11 +102,6 @@ export interface AgentAssemblyResult {
|
|
|
102
102
|
*/
|
|
103
103
|
plugin_instances: Map<string, Plugin>;
|
|
104
104
|
|
|
105
|
-
/**
|
|
106
|
-
* 当前 plugin 注册表。
|
|
107
|
-
*/
|
|
108
|
-
plugin_registry: PluginRegistry;
|
|
109
|
-
|
|
110
105
|
/**
|
|
111
106
|
* 当前 agent plugin 调用面。
|
|
112
107
|
*/
|
|
@@ -238,7 +233,6 @@ export class AgentAssemblyService {
|
|
|
238
233
|
instruction,
|
|
239
234
|
config,
|
|
240
235
|
plugin_instances,
|
|
241
|
-
plugin_registry,
|
|
242
236
|
plugins,
|
|
243
237
|
agent_context: agent_context!,
|
|
244
238
|
...(shell ? { shell } : {}),
|
|
@@ -19,25 +19,25 @@ import type {
|
|
|
19
19
|
AgentArchiveSessionsResult,
|
|
20
20
|
AgentCleanArchiveResult,
|
|
21
21
|
AgentListSessionsInput,
|
|
22
|
-
AgentManagedSession,
|
|
23
|
-
AgentModel,
|
|
24
|
-
AgentSession,
|
|
25
|
-
AgentSessions as AgentSessionsApi,
|
|
26
|
-
AgentSessionConstructor,
|
|
27
22
|
AgentSessionSummaryPage,
|
|
28
23
|
AgentSessionSystemBlock,
|
|
29
|
-
} from "@/types/agent/
|
|
24
|
+
} from "@/types/agent/SessionTypes.js";
|
|
25
|
+
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
26
|
+
import type { AgentSessionConstructor } from "@/types/agent/AgentOptions.js";
|
|
27
|
+
import type { AgentSession, AgentSessions as AgentSessionsApi } from "@/types/agent/SessionActor.js";
|
|
28
|
+
import type { AgentManagedSession } from "@/types/session/SessionOptions.js";
|
|
30
29
|
import { Session } from "@/session/Session.js";
|
|
31
30
|
import {
|
|
32
31
|
getSdkAgentArchivedSessionDirPath,
|
|
33
32
|
getSdkAgentArchivedSessionsDirPath,
|
|
34
33
|
getSdkAgentSessionDirPath,
|
|
34
|
+
} from "@/session/storage/Paths.js";
|
|
35
|
+
import {
|
|
35
36
|
listArchivedAgentSessionSummaryPage,
|
|
36
37
|
listAgentSessionSummaryPage,
|
|
37
|
-
} from "@/session/
|
|
38
|
+
} from "@/session/browse/Browse.js";
|
|
38
39
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
39
40
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
40
|
-
import type { Plugin } from "@/types/plugin/PluginDefinition.js";
|
|
41
41
|
import { createInstructionSystemBlocks } from "@/agent/local/AgentInstructions.js";
|
|
42
42
|
|
|
43
43
|
function decodeMaybe(input: string): string {
|
|
@@ -82,11 +82,6 @@ type AgentSessionsOptions = {
|
|
|
82
82
|
*/
|
|
83
83
|
get_instruction: () => string[];
|
|
84
84
|
|
|
85
|
-
/**
|
|
86
|
-
* 当前 plugin 实例集合。
|
|
87
|
-
*/
|
|
88
|
-
plugin_instances: Map<string, Plugin>;
|
|
89
|
-
|
|
90
85
|
/**
|
|
91
86
|
* 等待当前 Agent 后台能力启动完成。
|
|
92
87
|
*/
|
|
@@ -113,7 +108,6 @@ export class AgentSessions implements AgentSessionsApi<AgentSession> {
|
|
|
113
108
|
private readonly logger: Logger;
|
|
114
109
|
private readonly get_agent_context: AgentSessionsOptions["get_agent_context"];
|
|
115
110
|
private readonly get_instruction: AgentSessionsOptions["get_instruction"];
|
|
116
|
-
private readonly plugin_instances: Map<string, Plugin>;
|
|
117
111
|
private readonly ensure_agent_ready: AgentSessionsOptions["ensure_agent_ready"];
|
|
118
112
|
private readonly default_model?: AgentModel;
|
|
119
113
|
private readonly SessionClass: AgentSessionConstructor;
|
|
@@ -127,7 +121,6 @@ export class AgentSessions implements AgentSessionsApi<AgentSession> {
|
|
|
127
121
|
this.logger = options.logger;
|
|
128
122
|
this.get_agent_context = options.get_agent_context;
|
|
129
123
|
this.get_instruction = options.get_instruction;
|
|
130
|
-
this.plugin_instances = options.plugin_instances;
|
|
131
124
|
this.ensure_agent_ready = options.ensure_agent_ready;
|
|
132
125
|
this.default_model = options.default_model;
|
|
133
126
|
this.SessionClass = options.SessionClass || Session;
|
|
@@ -16,12 +16,13 @@ import type {
|
|
|
16
16
|
AgentCreateSessionInput,
|
|
17
17
|
AgentListSessionsInput,
|
|
18
18
|
AgentSessionSummaryPage,
|
|
19
|
-
|
|
19
|
+
} from "@/types/agent/SessionTypes.js";
|
|
20
|
+
import type { AgentSessions, RemoteAgentSession } from "@/types/agent/SessionActor.js";
|
|
21
|
+
import type { RemoteAgentOptions } from "@/types/agent/RemoteAgentOptions.js";
|
|
22
|
+
import type {
|
|
20
23
|
RemoteAgentPluginActionInput,
|
|
21
24
|
RemoteAgentPluginActionResult,
|
|
22
|
-
|
|
23
|
-
RemoteAgentSession,
|
|
24
|
-
} from "@/types/agent/AgentTypes.js";
|
|
25
|
+
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
25
26
|
import type {
|
|
26
27
|
ShellApprovalMode,
|
|
27
28
|
ShellApprovalDecisionResult,
|
|
@@ -14,8 +14,8 @@ import type {
|
|
|
14
14
|
AgentSessionInfo,
|
|
15
15
|
AgentSessionSetInput,
|
|
16
16
|
AgentSessionSystemSnapshot,
|
|
17
|
-
|
|
18
|
-
} from "@/types/agent/
|
|
17
|
+
} from "@/types/agent/SessionTypes.js";
|
|
18
|
+
import type { RemoteAgentSession } from "@/types/agent/SessionActor.js";
|
|
19
19
|
import { isAgentSessionPromptInputEmpty } from "@/types/sdk/AgentSessionPrompt.js";
|
|
20
20
|
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
21
21
|
import type {
|
|
@@ -171,6 +171,9 @@ export class RemoteSession implements RemoteAgentSession {
|
|
|
171
171
|
on_event: (event) => {
|
|
172
172
|
this.handle_event(event);
|
|
173
173
|
},
|
|
174
|
+
on_close: (error) => {
|
|
175
|
+
this.handle_event_pump_closed(error);
|
|
176
|
+
},
|
|
174
177
|
});
|
|
175
178
|
this.event_pump_running = true;
|
|
176
179
|
if (!resolved_ready) {
|
|
@@ -211,6 +214,22 @@ export class RemoteSession implements RemoteAgentSession {
|
|
|
211
214
|
this.event_hub.publish(event);
|
|
212
215
|
}
|
|
213
216
|
|
|
217
|
+
/**
|
|
218
|
+
* 收口底层事件连接断开后的运行态。
|
|
219
|
+
*
|
|
220
|
+
* 关键点(中文)
|
|
221
|
+
* - 连接已经结束时必须清除 running 标记,后续 prompt 才会重新订阅。
|
|
222
|
+
* - 当前未完成 turn 立即失败,避免调用侧永久等待 finished。
|
|
223
|
+
*/
|
|
224
|
+
private handle_event_pump_closed(error?: unknown): void {
|
|
225
|
+
this.event_subscription = null;
|
|
226
|
+
this.event_pump_running = false;
|
|
227
|
+
const message = error instanceof Error
|
|
228
|
+
? error.message
|
|
229
|
+
: String(error || "Remote session events connection closed");
|
|
230
|
+
this.fail_pending_turns(message);
|
|
231
|
+
}
|
|
232
|
+
|
|
214
233
|
private ensure_turn_lifecycle(turn_id: string): RemoteTurnLifecycle {
|
|
215
234
|
const cached = this.turns_by_id.get(turn_id);
|
|
216
235
|
if (cached) return cached;
|
|
@@ -20,12 +20,14 @@ import type {
|
|
|
20
20
|
AgentSessionInfo,
|
|
21
21
|
AgentSessionSummaryPage,
|
|
22
22
|
AgentSessionSystemSnapshot,
|
|
23
|
-
|
|
23
|
+
} from "@/types/agent/SessionTypes.js";
|
|
24
|
+
import type {
|
|
24
25
|
RemoteAgentPluginActionInput,
|
|
25
26
|
RemoteAgentPluginActionResult,
|
|
26
|
-
} from "@/types/agent/
|
|
27
|
+
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
27
28
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
28
29
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
30
|
+
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
29
31
|
import type {
|
|
30
32
|
ShellApprovalMode,
|
|
31
33
|
ShellApprovalDecisionResult,
|
|
@@ -61,6 +63,8 @@ export type RemoteSessionTransport = {
|
|
|
61
63
|
session_id: string;
|
|
62
64
|
on_ready: () => void;
|
|
63
65
|
on_event: (event: AgentSessionEvent) => void;
|
|
66
|
+
/** 底层事件连接结束后的通知;主动关闭不触发。 */
|
|
67
|
+
on_close: (error?: unknown) => void;
|
|
64
68
|
}): Promise<TransportSubscription>;
|
|
65
69
|
/** 读取 history。 */
|
|
66
70
|
records(
|
|
@@ -20,12 +20,14 @@ import type {
|
|
|
20
20
|
AgentSessionInfo,
|
|
21
21
|
AgentSessionSummaryPage,
|
|
22
22
|
AgentSessionSystemSnapshot,
|
|
23
|
-
|
|
23
|
+
} from "@/types/agent/SessionTypes.js";
|
|
24
|
+
import type {
|
|
24
25
|
RemoteAgentPluginActionInput,
|
|
25
26
|
RemoteAgentPluginActionResult,
|
|
26
|
-
} from "@/types/agent/
|
|
27
|
+
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
27
28
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
28
29
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
30
|
+
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
29
31
|
import type {
|
|
30
32
|
RemoteAgentTransport,
|
|
31
33
|
TransportSubscription,
|
|
@@ -145,6 +147,7 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
145
147
|
session_id: string;
|
|
146
148
|
on_ready: () => void;
|
|
147
149
|
on_event: (event: AgentSessionEvent) => void;
|
|
150
|
+
on_close: (error?: unknown) => void;
|
|
148
151
|
}): Promise<TransportSubscription> {
|
|
149
152
|
const abort_controller = new AbortController();
|
|
150
153
|
let resolve_ready!: () => void;
|
|
@@ -175,6 +178,10 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
175
178
|
reject_ready(error);
|
|
176
179
|
},
|
|
177
180
|
on_event: params.on_event,
|
|
181
|
+
}).then((error) => {
|
|
182
|
+
if (!abort_controller.signal.aborted) {
|
|
183
|
+
params.on_close(error);
|
|
184
|
+
}
|
|
178
185
|
});
|
|
179
186
|
await ready_promise;
|
|
180
187
|
return {
|
|
@@ -495,11 +502,12 @@ async function consume_http_event_stream(params: {
|
|
|
495
502
|
on_ready: () => void;
|
|
496
503
|
on_ready_error: (error: unknown) => void;
|
|
497
504
|
on_event: (event: AgentSessionEvent) => void;
|
|
498
|
-
}): Promise<
|
|
505
|
+
}): Promise<unknown | undefined> {
|
|
499
506
|
const decoder = new TextDecoder();
|
|
500
507
|
const reader = params.body.getReader();
|
|
501
508
|
let buffered = "";
|
|
502
509
|
let ready_resolved = false;
|
|
510
|
+
let close_error: unknown;
|
|
503
511
|
|
|
504
512
|
try {
|
|
505
513
|
while (true) {
|
|
@@ -546,6 +554,7 @@ async function consume_http_event_stream(params: {
|
|
|
546
554
|
});
|
|
547
555
|
}
|
|
548
556
|
} catch (error) {
|
|
557
|
+
close_error = error;
|
|
549
558
|
if (!params.abort_controller.signal.aborted) {
|
|
550
559
|
if (!ready_resolved) {
|
|
551
560
|
params.on_ready_error(error);
|
|
@@ -562,6 +571,7 @@ async function consume_http_event_stream(params: {
|
|
|
562
571
|
// ignore
|
|
563
572
|
}
|
|
564
573
|
}
|
|
574
|
+
return close_error;
|
|
565
575
|
}
|
|
566
576
|
|
|
567
577
|
function extract_error_message(payload: unknown): string {
|
|
@@ -20,12 +20,14 @@ import type {
|
|
|
20
20
|
AgentSessionInfo,
|
|
21
21
|
AgentSessionSummaryPage,
|
|
22
22
|
AgentSessionSystemSnapshot,
|
|
23
|
-
|
|
23
|
+
} from "@/types/agent/SessionTypes.js";
|
|
24
|
+
import type {
|
|
24
25
|
RemoteAgentPluginActionInput,
|
|
25
26
|
RemoteAgentPluginActionResult,
|
|
26
|
-
} from "@/types/agent/
|
|
27
|
+
} from "@/types/agent/RemoteAgentPluginAction.js";
|
|
27
28
|
import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
|
|
28
29
|
import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
|
|
30
|
+
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
29
31
|
import { RpcClient, parse_rpc_url } from "@/rpc/Client.js";
|
|
30
32
|
import type {
|
|
31
33
|
RemoteAgentTransport,
|
|
@@ -76,11 +78,13 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
|
|
|
76
78
|
session_id: string;
|
|
77
79
|
on_ready: () => void;
|
|
78
80
|
on_event: (event: AgentSessionEvent) => void;
|
|
81
|
+
on_close: (error?: unknown) => void;
|
|
79
82
|
}): Promise<TransportSubscription> {
|
|
80
83
|
const subscription = await this.client.subscribe_session({
|
|
81
84
|
session_id: params.session_id,
|
|
82
85
|
on_ready: params.on_ready,
|
|
83
86
|
on_event: params.on_event,
|
|
87
|
+
on_close: params.on_close,
|
|
84
88
|
});
|
|
85
89
|
return {
|
|
86
90
|
close: async () => {
|
package/src/executor/Executor.ts
CHANGED
|
@@ -86,10 +86,6 @@ type ExecutorOptions = {
|
|
|
86
86
|
*/
|
|
87
87
|
contextComposer?: SessionContextComposer;
|
|
88
88
|
|
|
89
|
-
/**
|
|
90
|
-
* session 更新后的异步回调。
|
|
91
|
-
*/
|
|
92
|
-
runAfterSessionUpdated?: (sessionId: string) => Promise<void>;
|
|
93
89
|
};
|
|
94
90
|
|
|
95
91
|
/**
|
|
@@ -139,13 +135,10 @@ export class Executor implements SessionExecutor {
|
|
|
139
135
|
this.historyWriter = new SessionHistoryWriter({
|
|
140
136
|
sessionId,
|
|
141
137
|
getHistoryStore: () => this.getHistoryStore(),
|
|
142
|
-
runAfterSessionUpdated: options.runAfterSessionUpdated,
|
|
143
138
|
});
|
|
144
139
|
this.inflight_service = new ExecutorInflightService({
|
|
145
140
|
session_id: this.sessionId,
|
|
146
141
|
history_store: this.historyStore,
|
|
147
|
-
run_after_session_updated_async: async () =>
|
|
148
|
-
await this.afterSessionUpdatedAsync(),
|
|
149
142
|
});
|
|
150
143
|
this.recovery_policy = new ExecutorRecoveryPolicy({
|
|
151
144
|
compaction_composer: this.compactionComposer,
|
|
@@ -196,22 +189,6 @@ export class Executor implements SessionExecutor {
|
|
|
196
189
|
return this;
|
|
197
190
|
}
|
|
198
191
|
|
|
199
|
-
/**
|
|
200
|
-
* 清理当前 session 的执行器运行态。
|
|
201
|
-
*
|
|
202
|
-
* 关键点(中文)
|
|
203
|
-
* - 当前 Executor 不缓存模型实例,模型每轮 run 都从 `getModel()` 读取。
|
|
204
|
-
* - history 是事实源,不应随着执行态一起丢失。
|
|
205
|
-
*/
|
|
206
|
-
clearExecutor(): void {}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* 触发 session 更新后的异步回调。
|
|
210
|
-
*/
|
|
211
|
-
async afterSessionUpdatedAsync(): Promise<void> {
|
|
212
|
-
await this.historyWriter.afterSessionUpdatedAsync();
|
|
213
|
-
}
|
|
214
|
-
|
|
215
192
|
/**
|
|
216
193
|
* 追加一条 user 消息。
|
|
217
194
|
*/
|
|
@@ -26,7 +26,6 @@ import type {
|
|
|
26
26
|
import {
|
|
27
27
|
is_session_message_record,
|
|
28
28
|
} from "@/executor/types/SessionRecords.js";
|
|
29
|
-
import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
|
|
30
29
|
import {
|
|
31
30
|
append_session_compaction_file_operations,
|
|
32
31
|
build_initial_session_compaction_prompt,
|
|
@@ -57,8 +56,7 @@ type SessionCompactDeps = {
|
|
|
57
56
|
}) => SessionRecordV1;
|
|
58
57
|
getArchiveDirPath: () => string;
|
|
59
58
|
getMessagesFilePath: () => string;
|
|
60
|
-
|
|
61
|
-
writeMetaUnsafe: (next: SessionHistoryMetaV1) => Promise<void>;
|
|
59
|
+
writeHistorySummaryUnsafe: (records: SessionRecordV1[]) => Promise<void>;
|
|
62
60
|
};
|
|
63
61
|
|
|
64
62
|
/**
|
|
@@ -259,11 +257,7 @@ export async function compactSessionMessagesIfNeeded(
|
|
|
259
257
|
await fs.writeFile(tmp, next.map((m) => JSON.stringify(m)).join("\n") + "\n", "utf8");
|
|
260
258
|
await fs.move(tmp, messagesPath, { overwrite: true });
|
|
261
259
|
|
|
262
|
-
|
|
263
|
-
await deps.writeMetaUnsafe({
|
|
264
|
-
...prevMeta,
|
|
265
|
-
updatedAt: Date.now(),
|
|
266
|
-
});
|
|
260
|
+
await deps.writeHistorySummaryUnsafe(next);
|
|
267
261
|
});
|
|
268
262
|
|
|
269
263
|
if (action_started) {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 只负责当前 session 的 user / assistant 消息补写。
|
|
6
6
|
* - 只依赖当前 session 的 history Store,不感知其他 session。
|
|
7
|
-
* - 会话更新后的通知也收在这里,避免把写入细节散到 Session 主类里。
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import type { JsonObject } from "@/types/common/Json.js";
|
|
@@ -25,10 +24,6 @@ type SessionHistoryWriterOptions = {
|
|
|
25
24
|
*/
|
|
26
25
|
getHistoryStore: () => SessionHistoryStore;
|
|
27
26
|
|
|
28
|
-
/**
|
|
29
|
-
* session 更新后的异步回调。
|
|
30
|
-
*/
|
|
31
|
-
runAfterSessionUpdated?: (sessionId: string) => Promise<void>;
|
|
32
27
|
};
|
|
33
28
|
|
|
34
29
|
/**
|
|
@@ -37,29 +32,15 @@ type SessionHistoryWriterOptions = {
|
|
|
37
32
|
export class SessionHistoryWriter {
|
|
38
33
|
private readonly sessionId: string;
|
|
39
34
|
private readonly getHistoryStore: SessionHistoryWriterOptions["getHistoryStore"];
|
|
40
|
-
private readonly runAfterSessionUpdated?: SessionHistoryWriterOptions["runAfterSessionUpdated"];
|
|
41
35
|
|
|
42
36
|
constructor(options: SessionHistoryWriterOptions) {
|
|
43
37
|
this.sessionId = String(options.sessionId || "").trim();
|
|
44
38
|
this.getHistoryStore = options.getHistoryStore;
|
|
45
|
-
this.runAfterSessionUpdated = options.runAfterSessionUpdated;
|
|
46
39
|
if (!this.sessionId) {
|
|
47
40
|
throw new Error("SessionHistoryWriter requires a non-empty sessionId");
|
|
48
41
|
}
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
/**
|
|
52
|
-
* 触发 session 更新后的异步回调。
|
|
53
|
-
*/
|
|
54
|
-
async afterSessionUpdatedAsync(): Promise<void> {
|
|
55
|
-
if (!this.runAfterSessionUpdated) return;
|
|
56
|
-
try {
|
|
57
|
-
await this.runAfterSessionUpdated(this.sessionId);
|
|
58
|
-
} catch {
|
|
59
|
-
// ignore
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
44
|
/**
|
|
64
45
|
* 追加一条 user 消息。
|
|
65
46
|
*/
|
|
@@ -68,29 +49,23 @@ export class SessionHistoryWriter {
|
|
|
68
49
|
text?: string;
|
|
69
50
|
extra?: JsonObject;
|
|
70
51
|
}): Promise<void> {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
52
|
+
const historyStore = this.getHistoryStore();
|
|
53
|
+
if (params.message && typeof params.message === "object") {
|
|
54
|
+
await historyStore.write_record(params.message);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
78
57
|
|
|
79
|
-
|
|
80
|
-
|
|
58
|
+
const fallbackText = String(params.text || "").trim();
|
|
59
|
+
if (!fallbackText) return;
|
|
81
60
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
void this.afterSessionUpdatedAsync();
|
|
91
|
-
} catch {
|
|
92
|
-
// ignore
|
|
93
|
-
}
|
|
61
|
+
const message = historyStore.userText({
|
|
62
|
+
text: fallbackText,
|
|
63
|
+
metadata: {
|
|
64
|
+
sessionId: this.sessionId,
|
|
65
|
+
extra: params.extra,
|
|
66
|
+
} as Omit<SessionMetadataV1, "v" | "ts">,
|
|
67
|
+
});
|
|
68
|
+
await historyStore.write_record(message);
|
|
94
69
|
}
|
|
95
70
|
|
|
96
71
|
/**
|
|
@@ -101,31 +76,25 @@ export class SessionHistoryWriter {
|
|
|
101
76
|
fallbackText?: string;
|
|
102
77
|
extra?: JsonObject;
|
|
103
78
|
}): Promise<void> {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
79
|
+
const historyStore = this.getHistoryStore();
|
|
80
|
+
if (params.message && typeof params.message === "object") {
|
|
81
|
+
await historyStore.finalize_inflight(params.message);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
111
84
|
|
|
112
|
-
|
|
113
|
-
|
|
85
|
+
const fallbackText = String(params.fallbackText || "").trim();
|
|
86
|
+
if (!fallbackText) return;
|
|
114
87
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
void this.afterSessionUpdatedAsync();
|
|
127
|
-
} catch {
|
|
128
|
-
// ignore
|
|
129
|
-
}
|
|
88
|
+
await historyStore.finalize_inflight(
|
|
89
|
+
historyStore.assistantText({
|
|
90
|
+
text: fallbackText,
|
|
91
|
+
metadata: {
|
|
92
|
+
sessionId: this.sessionId,
|
|
93
|
+
extra: params.extra,
|
|
94
|
+
},
|
|
95
|
+
kind: "normal",
|
|
96
|
+
source: "egress",
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
130
99
|
}
|
|
131
100
|
}
|
|
@@ -117,6 +117,10 @@ function systemsEqual(a: string[], b: string[]): boolean {
|
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* 构建静态系统提示列表。
|
|
120
|
+
*
|
|
121
|
+
* 关键点(中文)
|
|
122
|
+
* - PROFILE/SOUL 这类项目指令在前,Downcity core 在后。
|
|
123
|
+
* - 该顺序对应 SDK session 中 instruction -> core 的稳定分层。
|
|
120
124
|
*/
|
|
121
125
|
export function buildStaticSystemPrompts(staticProfiles: string[]): string[] {
|
|
122
126
|
return [...staticProfiles, DEFAULT_SHIP_PROMPTS].filter(Boolean);
|
|
@@ -12,7 +12,6 @@ import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
|
12
12
|
import { buildRuntimeClockSystemPrompt } from "@executor/composer/system/default/variables/VariableReplacer.js";
|
|
13
13
|
import {
|
|
14
14
|
CORE_SYSTEM_PROMPT,
|
|
15
|
-
PLUGIN_SYSTEM_PROMPT,
|
|
16
15
|
TASK_SYSTEM_PROMPT,
|
|
17
16
|
} from "@executor/composer/system/default/SystemPromptAssets.js";
|
|
18
17
|
|
|
@@ -27,8 +26,6 @@ function normalizeSystemText(input: string | null | undefined): string {
|
|
|
27
26
|
*/
|
|
28
27
|
export const DEFAULT_SHIP_PROMPTS = CORE_SYSTEM_PROMPT;
|
|
29
28
|
|
|
30
|
-
const MAIN_PLUGIN_PROMPT = PLUGIN_SYSTEM_PROMPT;
|
|
31
|
-
|
|
32
29
|
/**
|
|
33
30
|
* 构建一次运行的运行时 system prompt。
|
|
34
31
|
*
|
|
@@ -146,7 +143,7 @@ export function resolveSystemContextProfile(
|
|
|
146
143
|
* 收集受 agent 托管的 plugin system 文本。
|
|
147
144
|
*
|
|
148
145
|
* 关键点(中文)
|
|
149
|
-
* -
|
|
146
|
+
* - core prompt 已包含 plugin 系统总规则;这里仅收集各 plugin 自己的 system prompt。
|
|
150
147
|
* - 单个加载失败走 fail-open,不阻断主链路。
|
|
151
148
|
*/
|
|
152
149
|
export async function loadManagedPluginSystemPrompts(input: {
|
|
@@ -161,11 +158,6 @@ export async function loadManagedPluginSystemPrompts(input: {
|
|
|
161
158
|
disabledPluginNames: string[];
|
|
162
159
|
}): Promise<string[]> {
|
|
163
160
|
const out: string[] = [];
|
|
164
|
-
const mainPluginPrompt = normalizeSystemText(MAIN_PLUGIN_PROMPT);
|
|
165
|
-
if (mainPluginPrompt) {
|
|
166
|
-
out.push(mainPluginPrompt);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
161
|
const disabledPluginNames = new Set(
|
|
170
162
|
input.disabledPluginNames
|
|
171
163
|
.map((item) => String(item || "").trim())
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import coreSystemPromptText from "@executor/composer/system/default/assets/core.prompt.js";
|
|
10
|
-
import pluginSystemPromptText from "@executor/composer/system/default/assets/plugin.prompt.js";
|
|
11
10
|
import taskSystemPromptText from "@executor/composer/system/default/assets/task.prompt.js";
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -15,11 +14,6 @@ import taskSystemPromptText from "@executor/composer/system/default/assets/task.
|
|
|
15
14
|
*/
|
|
16
15
|
export const CORE_SYSTEM_PROMPT = coreSystemPromptText.trim();
|
|
17
16
|
|
|
18
|
-
/**
|
|
19
|
-
* plugin 层稳定 system prompt。
|
|
20
|
-
*/
|
|
21
|
-
export const PLUGIN_SYSTEM_PROMPT = pluginSystemPromptText.trim();
|
|
22
|
-
|
|
23
17
|
/**
|
|
24
18
|
* task 模式专用 system prompt。
|
|
25
19
|
*/
|