@downcity/agent 1.1.73 → 1.1.79
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/README.md +26 -28
- package/bin/agent/{Agent.d.ts → local/Agent.d.ts} +8 -36
- package/bin/agent/local/Agent.d.ts.map +1 -0
- package/bin/agent/{Agent.js → local/Agent.js} +45 -200
- package/bin/agent/local/Agent.js.map +1 -0
- package/bin/agent/local/AgentInstructions.d.ts +22 -0
- package/bin/agent/local/AgentInstructions.d.ts.map +1 -0
- package/bin/agent/local/AgentInstructions.js +57 -0
- package/bin/agent/local/AgentInstructions.js.map +1 -0
- package/bin/agent/local/AgentPluginFactory.d.ts +29 -0
- package/bin/agent/local/AgentPluginFactory.d.ts.map +1 -0
- package/bin/agent/local/AgentPluginFactory.js +53 -0
- package/bin/agent/local/AgentPluginFactory.js.map +1 -0
- package/bin/{runtime/host/AgentHostRuntime.d.ts → agent/local/AgentRuntimeAssembly.d.ts} +2 -2
- package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -0
- package/bin/{runtime/host/AgentHostRuntime.js → agent/local/AgentRuntimeAssembly.js} +2 -2
- package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -0
- package/bin/agent/local/AgentRuntimeFactory.d.ts +72 -0
- package/bin/agent/local/AgentRuntimeFactory.d.ts.map +1 -0
- package/bin/agent/local/AgentRuntimeFactory.js +94 -0
- package/bin/agent/local/AgentRuntimeFactory.js.map +1 -0
- package/bin/{runtime/host → agent/local}/ProjectSetup.d.ts +1 -1
- package/bin/agent/local/ProjectSetup.d.ts.map +1 -0
- package/bin/{runtime/host → agent/local}/ProjectSetup.js +1 -1
- package/bin/agent/local/ProjectSetup.js.map +1 -0
- package/bin/agent/{RemoteAgent.d.ts → remote/RemoteAgent.d.ts} +3 -3
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -0
- package/bin/agent/remote/RemoteAgent.js +58 -0
- package/bin/agent/remote/RemoteAgent.js.map +1 -0
- package/bin/agent/remote/RemoteSession.d.ts +62 -0
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -0
- package/bin/agent/remote/RemoteSession.js +225 -0
- package/bin/agent/remote/RemoteSession.js.map +1 -0
- package/bin/agent/remote/RemoteTransport.d.ts +52 -0
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -0
- package/bin/agent/remote/RemoteTransport.js +9 -0
- package/bin/agent/remote/RemoteTransport.js.map +1 -0
- package/bin/agent/remote/TransportFactory.d.ts +13 -0
- package/bin/agent/remote/TransportFactory.d.ts.map +1 -0
- package/bin/agent/remote/TransportFactory.js +22 -0
- package/bin/agent/remote/TransportFactory.js.map +1 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +35 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +259 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +34 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +66 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -0
- package/bin/config/AgentInitializer.d.ts +1 -1
- package/bin/config/AgentInitializer.js +1 -1
- package/bin/executor/Executor.d.ts +4 -0
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +52 -35
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.js +2 -2
- package/bin/executor/composer/history/SessionHistoryWriter.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/AssistantResultPersistence.d.ts +3 -3
- package/bin/executor/messages/AssistantResultPersistence.d.ts.map +1 -1
- package/bin/executor/messages/AssistantResultPersistence.js +2 -6
- package/bin/executor/messages/AssistantResultPersistence.js.map +1 -1
- package/bin/executor/messages/SessionStepEventMapper.d.ts +7 -8
- package/bin/executor/messages/SessionStepEventMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionStepEventMapper.js +55 -86
- package/bin/executor/messages/SessionStepEventMapper.js.map +1 -1
- package/bin/executor/messages/UserVisibleText.d.ts +2 -10
- package/bin/executor/messages/UserVisibleText.d.ts.map +1 -1
- package/bin/executor/messages/UserVisibleText.js +3 -16
- package/bin/executor/messages/UserVisibleText.js.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +12 -0
- package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +12 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +145 -8
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts +1 -10
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts.map +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +1 -39
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/executor/types/SessionHistoryPaths.d.ts +4 -0
- package/bin/executor/types/SessionHistoryPaths.d.ts.map +1 -1
- package/bin/index.d.ts +5 -5
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +3 -3
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
- package/bin/plugin/core/PluginCommandRequest.js +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +1 -1
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/core/ProjectConfigStore.d.ts +3 -2
- package/bin/plugin/core/ProjectConfigStore.d.ts.map +1 -1
- package/bin/plugin/core/ProjectConfigStore.js +3 -4
- package/bin/plugin/core/ProjectConfigStore.js.map +1 -1
- package/bin/plugin/types/Plugin.d.ts +10 -842
- package/bin/plugin/types/Plugin.d.ts.map +1 -1
- package/bin/plugin/types/Plugin.js +3 -4
- package/bin/plugin/types/Plugin.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +1 -1
- package/bin/plugin/types/PluginApi.js +1 -1
- package/bin/plugin/types/PluginState.d.ts +1 -1
- package/bin/plugin/types/PluginState.d.ts.map +1 -1
- package/bin/rpc/Client.d.ts +2 -99
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +0 -46
- package/bin/rpc/Client.js.map +1 -1
- package/bin/rpc/Server.d.ts +5 -21
- package/bin/rpc/Server.d.ts.map +1 -1
- package/bin/rpc/Server.js +30 -315
- package/bin/rpc/Server.js.map +1 -1
- package/bin/rpc/server/InternalHandlers.d.ts +21 -0
- package/bin/rpc/server/InternalHandlers.d.ts.map +1 -0
- package/bin/rpc/server/InternalHandlers.js +190 -0
- package/bin/rpc/server/InternalHandlers.js.map +1 -0
- package/bin/rpc/server/RequestDispatcher.d.ts +27 -0
- package/bin/rpc/server/RequestDispatcher.d.ts.map +1 -0
- package/bin/rpc/server/RequestDispatcher.js +38 -0
- package/bin/rpc/server/RequestDispatcher.js.map +1 -0
- package/bin/rpc/server/SdkSessionHandlers.d.ts +25 -0
- package/bin/rpc/server/SdkSessionHandlers.d.ts.map +1 -0
- package/bin/rpc/server/SdkSessionHandlers.js +86 -0
- package/bin/rpc/server/SdkSessionHandlers.js.map +1 -0
- package/bin/rpc/server/ServerTypes.d.ts +59 -0
- package/bin/rpc/server/ServerTypes.d.ts.map +1 -0
- package/bin/rpc/server/ServerTypes.js +9 -0
- package/bin/rpc/server/ServerTypes.js.map +1 -0
- package/bin/{runtime/sandbox → sandbox}/MacOsSeatbeltSandbox.d.ts +1 -1
- package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +1 -0
- package/bin/sandbox/MacOsSeatbeltSandbox.js.map +1 -0
- package/bin/{runtime/sandbox → sandbox}/SandboxConfigResolver.d.ts +2 -2
- package/bin/sandbox/SandboxConfigResolver.d.ts.map +1 -0
- package/bin/sandbox/SandboxConfigResolver.js.map +1 -0
- package/bin/{runtime/sandbox → sandbox}/SandboxRunner.d.ts +2 -2
- package/bin/sandbox/SandboxRunner.d.ts.map +1 -0
- package/bin/{runtime/sandbox → sandbox}/SandboxRunner.js +2 -2
- package/bin/sandbox/SandboxRunner.js.map +1 -0
- package/bin/sandbox/types/Sandbox.d.ts.map +1 -0
- package/bin/sandbox/types/Sandbox.js.map +1 -0
- package/bin/{runtime/sandbox → sandbox}/types/SandboxRuntime.d.ts +2 -2
- package/bin/sandbox/types/SandboxRuntime.d.ts.map +1 -0
- package/bin/sandbox/types/SandboxRuntime.js.map +1 -0
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +2 -1
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +1 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +28 -13
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +1 -1
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +1 -1
- package/bin/session/index.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +9 -0
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +11 -0
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +134 -0
- package/bin/types/agent/AgentOptions.d.ts.map +1 -0
- package/bin/types/agent/AgentOptions.js +9 -0
- package/bin/types/agent/AgentOptions.js.map +1 -0
- package/bin/types/{runtime/host/AgentHost.d.ts → agent/AgentRuntimeAssembly.d.ts} +4 -4
- package/bin/types/agent/AgentRuntimeAssembly.d.ts.map +1 -0
- package/bin/types/{runtime/host/AgentHost.js → agent/AgentRuntimeAssembly.js} +3 -3
- package/bin/types/agent/AgentRuntimeAssembly.js.map +1 -0
- package/bin/types/agent/AgentTypes.d.ts +8 -613
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/AgentTypes.js +4 -4
- package/bin/types/agent/RemoteAgentOptions.d.ts +28 -0
- package/bin/types/agent/RemoteAgentOptions.d.ts.map +1 -0
- package/bin/types/agent/RemoteAgentOptions.js +9 -0
- package/bin/types/agent/RemoteAgentOptions.js.map +1 -0
- package/bin/types/agent/SessionActor.d.ts +60 -0
- package/bin/types/agent/SessionActor.d.ts.map +1 -0
- package/bin/types/agent/SessionActor.js +9 -0
- package/bin/types/agent/SessionActor.js.map +1 -0
- package/bin/types/agent/SessionTypes.d.ts +312 -0
- package/bin/types/agent/SessionTypes.d.ts.map +1 -0
- package/bin/types/agent/SessionTypes.js +9 -0
- package/bin/types/agent/SessionTypes.js.map +1 -0
- package/bin/types/config/DowncityConfig.d.ts +1 -1
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/{runtime/host → platform}/Store.d.ts +1 -1
- package/bin/types/platform/Store.d.ts.map +1 -0
- package/bin/types/{runtime/host → platform}/Store.js +1 -1
- package/bin/types/platform/Store.js.map +1 -0
- package/bin/types/plugin/PluginAction.d.ts +119 -0
- package/bin/types/plugin/PluginAction.d.ts.map +1 -0
- package/bin/types/plugin/PluginAction.js +9 -0
- package/bin/types/plugin/PluginAction.js.map +1 -0
- package/bin/types/plugin/PluginCommand.d.ts +80 -0
- package/bin/types/plugin/PluginCommand.d.ts.map +1 -0
- package/bin/types/plugin/PluginCommand.js +9 -0
- package/bin/types/plugin/PluginCommand.js.map +1 -0
- package/bin/types/plugin/PluginDefinition.d.ts +57 -0
- package/bin/types/plugin/PluginDefinition.d.ts.map +1 -0
- package/bin/types/plugin/PluginDefinition.js +9 -0
- package/bin/types/plugin/PluginDefinition.js.map +1 -0
- package/bin/types/plugin/PluginHttp.d.ts +34 -0
- package/bin/types/plugin/PluginHttp.d.ts.map +1 -0
- package/bin/types/plugin/PluginHttp.js +9 -0
- package/bin/types/plugin/PluginHttp.js.map +1 -0
- package/bin/types/plugin/PluginRuntime.d.ts +148 -0
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -0
- package/bin/types/plugin/PluginRuntime.js +9 -0
- package/bin/types/plugin/PluginRuntime.js.map +1 -0
- package/bin/types/plugin/PluginSetup.d.ts +133 -0
- package/bin/types/plugin/PluginSetup.d.ts.map +1 -0
- package/bin/types/plugin/PluginSetup.js +9 -0
- package/bin/types/plugin/PluginSetup.js.map +1 -0
- package/bin/types/plugin/PluginState.d.ts +69 -0
- package/bin/types/plugin/PluginState.d.ts.map +1 -0
- package/bin/types/plugin/PluginState.js +9 -0
- package/bin/types/plugin/PluginState.js.map +1 -0
- package/bin/types/rpc/RpcProtocol.d.ts +323 -0
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -0
- package/bin/types/rpc/RpcProtocol.js +10 -0
- package/bin/types/rpc/RpcProtocol.js.map +1 -0
- package/bin/types/runtime/agent/AgentContext.d.ts +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentRuntime.d.ts +1 -1
- package/bin/types/runtime/agent/AgentRuntime.d.ts.map +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +7 -7
- package/bin/types/runtime/platform/PlatformGateway.d.ts +1 -1
- package/bin/types/runtime/platform/PlatformGateway.js +1 -1
- package/package.json +2 -2
- package/scripts/session-history-inflight.test.mjs +146 -0
- package/src/agent/{Agent.ts → local/Agent.ts} +50 -228
- package/src/agent/local/AgentInstructions.ts +68 -0
- package/src/agent/local/AgentPluginFactory.ts +83 -0
- package/src/{runtime/host/AgentHostRuntime.ts → agent/local/AgentRuntimeAssembly.ts} +2 -2
- package/src/agent/local/AgentRuntimeFactory.ts +173 -0
- package/src/{runtime/host → agent/local}/ProjectSetup.ts +1 -1
- package/src/agent/remote/RemoteAgent.ts +76 -0
- package/src/agent/remote/RemoteSession.ts +287 -0
- package/src/agent/remote/RemoteTransport.ts +71 -0
- package/src/agent/remote/TransportFactory.ts +29 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +347 -0
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +107 -0
- package/src/config/AgentInitializer.ts +1 -1
- package/src/executor/Executor.ts +56 -37
- package/src/executor/composer/history/SessionHistoryWriter.ts +2 -2
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -1
- package/src/executor/messages/AssistantResultPersistence.ts +4 -12
- package/src/executor/messages/SessionStepEventMapper.ts +59 -101
- package/src/executor/messages/UserVisibleText.ts +3 -18
- package/src/executor/store/history/SessionHistoryStore.ts +15 -0
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +164 -11
- package/src/executor/tools/shell/ShellToolFormatting.ts +1 -50
- package/src/executor/types/SessionHistoryPaths.ts +5 -0
- package/src/index.ts +5 -5
- package/src/plugin/core/PluginCommandRequest.ts +1 -1
- package/src/plugin/core/PluginLocalExecution.ts +1 -1
- package/src/plugin/core/ProjectConfigStore.ts +4 -4
- package/src/plugin/types/Plugin.ts +54 -913
- package/src/plugin/types/PluginApi.ts +1 -1
- package/src/plugin/types/PluginState.ts +1 -1
- package/src/rpc/Client.ts +16 -322
- package/src/rpc/Server.ts +39 -565
- package/src/rpc/server/InternalHandlers.ts +230 -0
- package/src/rpc/server/RequestDispatcher.ts +67 -0
- package/src/rpc/server/SdkSessionHandlers.ts +106 -0
- package/src/rpc/server/ServerTypes.ts +65 -0
- package/src/{runtime/sandbox → sandbox}/MacOsSeatbeltSandbox.ts +1 -1
- package/src/{runtime/sandbox → sandbox}/SandboxConfigResolver.ts +1 -1
- package/src/{runtime/sandbox → sandbox}/SandboxRunner.ts +3 -3
- package/src/{runtime/sandbox → sandbox}/types/SandboxRuntime.ts +2 -2
- package/src/session/Session.ts +6 -0
- package/src/session/browse/Browse.ts +29 -10
- package/src/session/index.ts +1 -0
- package/src/session/storage/Paths.ts +19 -0
- package/src/types/agent/AgentOptions.ts +147 -0
- package/src/types/{runtime/host/AgentHost.ts → agent/AgentRuntimeAssembly.ts} +2 -2
- package/src/types/agent/AgentTypes.ts +37 -709
- package/src/types/agent/RemoteAgentOptions.ts +29 -0
- package/src/types/agent/SessionActor.ts +88 -0
- package/src/types/agent/SessionTypes.ts +334 -0
- package/src/types/config/DowncityConfig.ts +1 -1
- package/src/types/{runtime/host → platform}/Store.ts +1 -1
- package/src/types/plugin/PluginAction.ts +133 -0
- package/src/types/plugin/PluginCommand.ts +89 -0
- package/src/types/plugin/PluginDefinition.ts +74 -0
- package/src/types/plugin/PluginHttp.ts +36 -0
- package/src/types/plugin/PluginRuntime.ts +169 -0
- package/src/types/plugin/PluginSetup.ts +138 -0
- package/src/types/plugin/PluginState.ts +82 -0
- package/src/types/rpc/RpcProtocol.ts +361 -0
- package/src/types/runtime/agent/AgentContext.ts +1 -1
- package/src/types/runtime/agent/AgentRuntime.ts +1 -1
- package/src/types/runtime/platform/Platform.ts +7 -7
- package/src/types/runtime/platform/PlatformGateway.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/Agent.d.ts.map +0 -1
- package/bin/agent/Agent.js.map +0 -1
- package/bin/agent/RemoteAgent.d.ts.map +0 -1
- package/bin/agent/RemoteAgent.js +0 -585
- package/bin/agent/RemoteAgent.js.map +0 -1
- package/bin/runtime/auth/AuthEnv.d.ts +0 -36
- package/bin/runtime/auth/AuthEnv.d.ts.map +0 -1
- package/bin/runtime/auth/AuthEnv.js +0 -54
- package/bin/runtime/auth/AuthEnv.js.map +0 -1
- package/bin/runtime/auth/CliAuthStateStore.d.ts +0 -29
- package/bin/runtime/auth/CliAuthStateStore.d.ts.map +0 -1
- package/bin/runtime/auth/CliAuthStateStore.js +0 -26
- package/bin/runtime/auth/CliAuthStateStore.js.map +0 -1
- package/bin/runtime/control/AuthControlService.d.ts +0 -34
- package/bin/runtime/control/AuthControlService.d.ts.map +0 -1
- package/bin/runtime/control/AuthControlService.js +0 -129
- package/bin/runtime/control/AuthControlService.js.map +0 -1
- package/bin/runtime/control/CommonHelpers.d.ts +0 -36
- package/bin/runtime/control/CommonHelpers.d.ts.map +0 -1
- package/bin/runtime/control/CommonHelpers.js +0 -63
- package/bin/runtime/control/CommonHelpers.js.map +0 -1
- package/bin/runtime/control/ExecuteBySession.d.ts +0 -30
- package/bin/runtime/control/ExecuteBySession.d.ts.map +0 -1
- package/bin/runtime/control/ExecuteBySession.js +0 -41
- package/bin/runtime/control/ExecuteBySession.js.map +0 -1
- package/bin/runtime/control/ExecuteInput.d.ts +0 -18
- package/bin/runtime/control/ExecuteInput.d.ts.map +0 -1
- package/bin/runtime/control/ExecuteInput.js +0 -201
- package/bin/runtime/control/ExecuteInput.js.map +0 -1
- package/bin/runtime/control/Helpers.d.ts +0 -13
- package/bin/runtime/control/Helpers.d.ts.map +0 -1
- package/bin/runtime/control/Helpers.js +0 -13
- package/bin/runtime/control/Helpers.js.map +0 -1
- package/bin/runtime/control/MessageTimeline.d.ts +0 -22
- package/bin/runtime/control/MessageTimeline.d.ts.map +0 -1
- package/bin/runtime/control/MessageTimeline.js +0 -226
- package/bin/runtime/control/MessageTimeline.js.map +0 -1
- package/bin/runtime/control/SessionSummaryStore.d.ts +0 -20
- package/bin/runtime/control/SessionSummaryStore.d.ts.map +0 -1
- package/bin/runtime/control/SessionSummaryStore.js +0 -50
- package/bin/runtime/control/SessionSummaryStore.js.map +0 -1
- package/bin/runtime/control/TaskStore.d.ts +0 -33
- package/bin/runtime/control/TaskStore.d.ts.map +0 -1
- package/bin/runtime/control/TaskStore.js +0 -175
- package/bin/runtime/control/TaskStore.js.map +0 -1
- package/bin/runtime/control/types/AuthControl.d.ts +0 -30
- package/bin/runtime/control/types/AuthControl.d.ts.map +0 -1
- package/bin/runtime/control/types/AuthControl.js +0 -9
- package/bin/runtime/control/types/AuthControl.js.map +0 -1
- package/bin/runtime/control/types/ControlSessionExecute.d.ts +0 -85
- package/bin/runtime/control/types/ControlSessionExecute.d.ts.map +0 -1
- package/bin/runtime/control/types/ControlSessionExecute.js +0 -9
- package/bin/runtime/control/types/ControlSessionExecute.js.map +0 -1
- package/bin/runtime/control/types/ControlViewData.d.ts +0 -320
- package/bin/runtime/control/types/ControlViewData.d.ts.map +0 -1
- package/bin/runtime/control/types/ControlViewData.js +0 -9
- package/bin/runtime/control/types/ControlViewData.js.map +0 -1
- package/bin/runtime/host/AgentHostRuntime.d.ts.map +0 -1
- package/bin/runtime/host/AgentHostRuntime.js.map +0 -1
- package/bin/runtime/host/ProjectSetup.d.ts.map +0 -1
- package/bin/runtime/host/ProjectSetup.js.map +0 -1
- package/bin/runtime/sandbox/MacOsSeatbeltSandbox.d.ts.map +0 -1
- package/bin/runtime/sandbox/MacOsSeatbeltSandbox.js.map +0 -1
- package/bin/runtime/sandbox/SandboxConfigResolver.d.ts.map +0 -1
- package/bin/runtime/sandbox/SandboxConfigResolver.js.map +0 -1
- package/bin/runtime/sandbox/SandboxRunner.d.ts.map +0 -1
- package/bin/runtime/sandbox/SandboxRunner.js.map +0 -1
- package/bin/runtime/sandbox/types/Sandbox.d.ts.map +0 -1
- package/bin/runtime/sandbox/types/Sandbox.js.map +0 -1
- package/bin/runtime/sandbox/types/SandboxRuntime.d.ts.map +0 -1
- package/bin/runtime/sandbox/types/SandboxRuntime.js.map +0 -1
- package/bin/types/runtime/host/AgentHost.d.ts.map +0 -1
- package/bin/types/runtime/host/AgentHost.js.map +0 -1
- package/bin/types/runtime/host/Store.d.ts.map +0 -1
- package/bin/types/runtime/host/Store.js.map +0 -1
- package/src/agent/RemoteAgent.ts +0 -834
- package/src/runtime/auth/AuthEnv.ts +0 -62
- package/src/runtime/auth/CliAuthStateStore.ts +0 -46
- package/src/runtime/control/AuthControlService.ts +0 -169
- package/src/runtime/control/CommonHelpers.ts +0 -69
- package/src/runtime/control/ExecuteBySession.ts +0 -52
- package/src/runtime/control/ExecuteInput.ts +0 -236
- package/src/runtime/control/Helpers.ts +0 -22
- package/src/runtime/control/MessageTimeline.ts +0 -269
- package/src/runtime/control/SessionSummaryStore.ts +0 -72
- package/src/runtime/control/TaskStore.ts +0 -242
- package/src/runtime/control/types/AuthControl.ts +0 -34
- package/src/runtime/control/types/ControlSessionExecute.ts +0 -99
- package/src/runtime/control/types/ControlViewData.ts +0 -392
- /package/bin/{runtime/sandbox → sandbox}/MacOsSeatbeltSandbox.js +0 -0
- /package/bin/{runtime/sandbox → sandbox}/SandboxConfigResolver.js +0 -0
- /package/bin/{runtime/sandbox → sandbox}/types/Sandbox.d.ts +0 -0
- /package/bin/{runtime/sandbox → sandbox}/types/Sandbox.js +0 -0
- /package/bin/{runtime/sandbox → sandbox}/types/SandboxRuntime.js +0 -0
- /package/src/{runtime/sandbox → sandbox}/types/Sandbox.ts +0 -0
|
@@ -4,14 +4,11 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 负责收敛“写完整 assistant message / 写 fallback 文本 / 完全跳过”三种分支。
|
|
6
6
|
* - 避免 SDK、HTTP execute、control execute、chat queue 各自复制一套判断。
|
|
7
|
-
* -
|
|
7
|
+
* - 运行中 step/tool 的持久化由 inflight 快照承担;run 结束时只关心最终 assistant 如何收口。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
|
|
11
|
-
import {
|
|
12
|
-
hasPersistedAssistantSteps,
|
|
13
|
-
resolveAssistantMessageForPersistence,
|
|
14
|
-
} from "@/executor/messages/UserVisibleText.js";
|
|
11
|
+
import { resolveAssistantMessageForPersistence } from "@/executor/messages/UserVisibleText.js";
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* assistant 写入端口。
|
|
@@ -48,8 +45,8 @@ export interface PersistAssistantResultParams {
|
|
|
48
45
|
* 可选兜底文本。
|
|
49
46
|
*
|
|
50
47
|
* 关键点(中文)
|
|
51
|
-
* - 仅在没有完整 assistant message
|
|
52
|
-
* -
|
|
48
|
+
* - 仅在没有完整 assistant message 时才允许写入。
|
|
49
|
+
* - inflight 快照的正式收口由 history store 负责,这里不再处理旧的 step 独立落盘分支。
|
|
53
50
|
*/
|
|
54
51
|
fallbackText?: string;
|
|
55
52
|
}
|
|
@@ -83,11 +80,6 @@ export function buildAssistantResultPersistencePayload(
|
|
|
83
80
|
};
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
// 关键点(中文):step 已经单独落盘时,最终 merged assistant 必须完全跳过。
|
|
87
|
-
if (hasPersistedAssistantSteps(params.assistantMessage)) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
83
|
const fallbackText = normalizeFallbackText(params.fallbackText);
|
|
92
84
|
if (!fallbackText) return null;
|
|
93
85
|
return {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SessionStepEventMapper:把单个 step
|
|
2
|
+
* SessionStepEventMapper:把单个 step 结果转成 assistant parts。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
5
|
+
* - 运行过程仍然要持久化,但收口到同一条 assistant UIMessage。
|
|
6
|
+
* - 工具结果使用 AI SDK v6 UI tool part 格式,和官方 UIMessage 语义保持一致。
|
|
7
|
+
* - 每个 step 前插入 `step-start`,便于在 UI 中保留多 step 边界。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { generateId } from "@/utils/Id.js";
|
|
11
|
-
import type { JsonObject } from "@/types/common/Json.js";
|
|
12
10
|
import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
|
|
13
11
|
|
|
14
12
|
type UnknownRecord = Record<string, unknown>;
|
|
@@ -64,6 +62,21 @@ function resolveToolResultPayload(value: unknown): unknown {
|
|
|
64
62
|
return undefined;
|
|
65
63
|
}
|
|
66
64
|
|
|
65
|
+
function resolveToolResultErrorText(value: unknown): string | undefined {
|
|
66
|
+
const record = toRecord(value);
|
|
67
|
+
if (!record) return undefined;
|
|
68
|
+
if (typeof record.errorText === "string" && record.errorText.trim()) {
|
|
69
|
+
return record.errorText.trim();
|
|
70
|
+
}
|
|
71
|
+
if (typeof record.error === "string" && record.error.trim()) {
|
|
72
|
+
return record.error.trim();
|
|
73
|
+
}
|
|
74
|
+
if (record.error instanceof Error && record.error.message.trim()) {
|
|
75
|
+
return record.error.message.trim();
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
function mapToolResultsByCallId(toolResults: unknown[]): Map<string, unknown> {
|
|
68
81
|
const out = new Map<string, unknown>();
|
|
69
82
|
for (const toolResult of toolResults) {
|
|
@@ -91,53 +104,16 @@ function toDataPartType(type: string): string {
|
|
|
91
104
|
return `data-acp-${type.replace(/_/g, "-")}`;
|
|
92
105
|
}
|
|
93
106
|
|
|
94
|
-
function buildMetadata(params: {
|
|
95
|
-
sessionId: string;
|
|
96
|
-
ts: number;
|
|
97
|
-
extra?: JsonObject;
|
|
98
|
-
}): SessionMessageV1["metadata"] {
|
|
99
|
-
return {
|
|
100
|
-
v: 1,
|
|
101
|
-
ts: params.ts,
|
|
102
|
-
sessionId: params.sessionId,
|
|
103
|
-
source: "egress",
|
|
104
|
-
kind: "normal",
|
|
105
|
-
...(params.extra ? { extra: params.extra } : {}),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function buildAssistantStepMessage(params: {
|
|
110
|
-
sessionId: string;
|
|
111
|
-
ts: number;
|
|
112
|
-
part: Record<string, unknown>;
|
|
113
|
-
extra: JsonObject;
|
|
114
|
-
}): SessionMessageV1 {
|
|
115
|
-
return {
|
|
116
|
-
id: `a:${params.sessionId}:${generateId()}`,
|
|
117
|
-
role: "assistant",
|
|
118
|
-
metadata: buildMetadata({
|
|
119
|
-
sessionId: params.sessionId,
|
|
120
|
-
ts: params.ts,
|
|
121
|
-
extra: params.extra,
|
|
122
|
-
}),
|
|
123
|
-
parts: [params.part as SessionMessageV1["parts"][number]],
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
107
|
/**
|
|
128
|
-
* 从 stepResult
|
|
108
|
+
* 从 stepResult 提取按顺序写入同一条 assistant message 的 parts。
|
|
129
109
|
*/
|
|
130
|
-
export function
|
|
131
|
-
sessionId: string;
|
|
110
|
+
export function buildSessionStepParts(params: {
|
|
132
111
|
stepIndex: number;
|
|
133
112
|
stepResult?: unknown;
|
|
134
113
|
text: string;
|
|
135
114
|
visibility?: "visible" | "internal";
|
|
136
|
-
}): SessionMessageV1[] {
|
|
137
|
-
const
|
|
138
|
-
if (!sessionId) return [];
|
|
139
|
-
|
|
140
|
-
const out: SessionMessageV1[] = [];
|
|
115
|
+
}): SessionMessageV1["parts"] {
|
|
116
|
+
const out: SessionMessageV1["parts"] = [];
|
|
141
117
|
const stepRecord = toRecord(params.stepResult) || {};
|
|
142
118
|
const toolCalls = Array.isArray(stepRecord.toolCalls) ? stepRecord.toolCalls : [];
|
|
143
119
|
const toolResults = Array.isArray(stepRecord.toolResults)
|
|
@@ -147,34 +123,29 @@ export function buildSessionStepEventMessages(params: {
|
|
|
147
123
|
const acpEvents = Array.isArray(stepRecord.acpEvents)
|
|
148
124
|
? stepRecord.acpEvents
|
|
149
125
|
: [];
|
|
150
|
-
const baseTs = Date.now();
|
|
151
|
-
let sequence = 0;
|
|
152
126
|
|
|
153
127
|
const text = String(params.text || "").trim();
|
|
128
|
+
const has_structured_output =
|
|
129
|
+
Boolean(text) || toolCalls.length > 0 || acpEvents.length > 0;
|
|
130
|
+
if (!has_structured_output) return [];
|
|
131
|
+
|
|
132
|
+
out.push({ type: "step-start" });
|
|
133
|
+
|
|
154
134
|
if (text) {
|
|
155
135
|
const isInternal = params.visibility === "internal";
|
|
156
136
|
out.push(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
text,
|
|
169
|
-
},
|
|
170
|
-
extra: {
|
|
171
|
-
internal: isInternal ? "assistant_step_reasoning" : "assistant_step_text",
|
|
172
|
-
stepIndex: params.stepIndex,
|
|
173
|
-
persistedBy: "session_store_run",
|
|
174
|
-
},
|
|
175
|
-
}),
|
|
137
|
+
isInternal
|
|
138
|
+
? {
|
|
139
|
+
type: "reasoning",
|
|
140
|
+
text,
|
|
141
|
+
state: "done",
|
|
142
|
+
}
|
|
143
|
+
: {
|
|
144
|
+
type: "text",
|
|
145
|
+
text,
|
|
146
|
+
state: "done",
|
|
147
|
+
},
|
|
176
148
|
);
|
|
177
|
-
sequence += 1;
|
|
178
149
|
}
|
|
179
150
|
|
|
180
151
|
for (let index = 0; index < toolCalls.length; index += 1) {
|
|
@@ -185,25 +156,23 @@ export function buildSessionStepEventMessages(params: {
|
|
|
185
156
|
const toolResult = toolCallId ? toolResultsByCallId.get(toolCallId) : undefined;
|
|
186
157
|
if (!toolResult) continue;
|
|
187
158
|
const output = resolveToolResultPayload(toolResult);
|
|
159
|
+
const errorText = resolveToolResultErrorText(toolResult);
|
|
188
160
|
out.push(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
},
|
|
204
|
-
}),
|
|
161
|
+
{
|
|
162
|
+
type: `tool-${toolName}`,
|
|
163
|
+
...(toolCallId ? { toolCallId } : {}),
|
|
164
|
+
...(input !== undefined ? { input } : {}),
|
|
165
|
+
...(errorText
|
|
166
|
+
? {
|
|
167
|
+
state: "output-error",
|
|
168
|
+
errorText,
|
|
169
|
+
}
|
|
170
|
+
: {
|
|
171
|
+
state: "output-available",
|
|
172
|
+
output,
|
|
173
|
+
}),
|
|
174
|
+
} as SessionMessageV1["parts"][number],
|
|
205
175
|
);
|
|
206
|
-
sequence += 1;
|
|
207
176
|
}
|
|
208
177
|
|
|
209
178
|
for (let index = 0; index < acpEvents.length; index += 1) {
|
|
@@ -211,22 +180,11 @@ export function buildSessionStepEventMessages(params: {
|
|
|
211
180
|
const type = resolveAcpEventType(acpEvent);
|
|
212
181
|
if (!type) continue;
|
|
213
182
|
out.push(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
type: toDataPartType(type),
|
|
219
|
-
data: resolveAcpEventData(acpEvent),
|
|
220
|
-
},
|
|
221
|
-
extra: {
|
|
222
|
-
internal: "assistant_step_acp_event",
|
|
223
|
-
stepIndex: params.stepIndex,
|
|
224
|
-
acpEventType: type,
|
|
225
|
-
eventIndex: index + 1,
|
|
226
|
-
},
|
|
227
|
-
}),
|
|
183
|
+
{
|
|
184
|
+
type: toDataPartType(type),
|
|
185
|
+
data: resolveAcpEventData(acpEvent),
|
|
186
|
+
} as SessionMessageV1["parts"][number],
|
|
228
187
|
);
|
|
229
|
-
sequence += 1;
|
|
230
188
|
}
|
|
231
189
|
|
|
232
190
|
return out;
|
|
@@ -17,29 +17,14 @@ import {
|
|
|
17
17
|
* 生成真正应该落盘到 session 的 assistant message。
|
|
18
18
|
*
|
|
19
19
|
* 关键点(中文)
|
|
20
|
-
* -
|
|
21
|
-
* -
|
|
20
|
+
* - session 正式历史应尽量保留 AI SDK 最终 assistant UIMessage。
|
|
21
|
+
* - 运行中 step/tool 的中断恢复由 inflight 快照承担,不再通过跳过最终 message 收口。
|
|
22
22
|
*/
|
|
23
23
|
export function resolveAssistantMessageForPersistence(
|
|
24
24
|
message: SessionMessageV1 | null | undefined,
|
|
25
25
|
): SessionMessageV1 | null {
|
|
26
26
|
if (!message || typeof message !== "object") return null;
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 判断 assistant message 是否声明“本轮 step 消息已单独持久化”。
|
|
32
|
-
*
|
|
33
|
-
* 关键点(中文)
|
|
34
|
-
* - 该标记只用于避免在 run 结束时把最终 merged assistant 再重复写入 context。
|
|
35
|
-
* - 不影响 channel 发送;只影响 context messages 的最终 append 策略。
|
|
36
|
-
*/
|
|
37
|
-
export function hasPersistedAssistantSteps(
|
|
38
|
-
message: SessionMessageV1 | null | undefined,
|
|
39
|
-
): boolean {
|
|
40
|
-
const extra = message?.metadata?.extra;
|
|
41
|
-
if (!extra || typeof extra !== "object" || Array.isArray(extra)) return false;
|
|
42
|
-
return extra.assistantStepMessagesPersisted === true;
|
|
27
|
+
return message;
|
|
43
28
|
}
|
|
44
29
|
|
|
45
30
|
/**
|
|
@@ -63,6 +63,21 @@ export interface SessionHistoryStore {
|
|
|
63
63
|
*/
|
|
64
64
|
append(message: SessionMessageV1): Promise<void>;
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* 读取当前运行中的 assistant 快照。
|
|
68
|
+
*/
|
|
69
|
+
readInflight(): Promise<SessionMessageV1 | null>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 写入当前运行中的 assistant 快照。
|
|
73
|
+
*/
|
|
74
|
+
writeInflight(message: SessionMessageV1): Promise<void>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 用最终 assistant 收口 inflight 快照。
|
|
78
|
+
*/
|
|
79
|
+
finalizeInflight(message?: SessionMessageV1 | null): Promise<void>;
|
|
80
|
+
|
|
66
81
|
/**
|
|
67
82
|
* 读取完整消息历史。
|
|
68
83
|
*/
|
|
@@ -106,6 +106,7 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
106
106
|
private readonly overrideMessagesFilePath?: string;
|
|
107
107
|
private readonly overrideMetaFilePath?: string;
|
|
108
108
|
private readonly overrideArchiveDirPath?: string;
|
|
109
|
+
private readonly overrideInflightFilePath?: string;
|
|
109
110
|
|
|
110
111
|
constructor(options: JsonlSessionHistoryStoreOptions) {
|
|
111
112
|
const rootPath = String(options.rootPath || "").trim();
|
|
@@ -135,6 +136,9 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
135
136
|
this.overrideArchiveDirPath = this.readOptionalPath(
|
|
136
137
|
options.paths?.archiveDirPath,
|
|
137
138
|
);
|
|
139
|
+
this.overrideInflightFilePath = this.readOptionalPath(
|
|
140
|
+
options.paths?.inflightFilePath,
|
|
141
|
+
);
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
private readOptionalPath(value: string | undefined): string | undefined {
|
|
@@ -183,6 +187,14 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
183
187
|
return path.join(this.getMessagesDirPath(), "archive");
|
|
184
188
|
}
|
|
185
189
|
|
|
190
|
+
private getInflightFilePath(): string {
|
|
191
|
+
if (this.overrideInflightFilePath) return this.overrideInflightFilePath;
|
|
192
|
+
if (this.overrideMessagesDirPath) {
|
|
193
|
+
return path.join(this.overrideMessagesDirPath, "inflight.json");
|
|
194
|
+
}
|
|
195
|
+
return path.join(this.getMessagesDirPath(), "inflight.json");
|
|
196
|
+
}
|
|
197
|
+
|
|
186
198
|
private getLockFilePath(): string {
|
|
187
199
|
return path.join(this.getMessagesDirPath(), ".session.lock");
|
|
188
200
|
}
|
|
@@ -199,6 +211,75 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
199
211
|
return value || undefined;
|
|
200
212
|
}
|
|
201
213
|
|
|
214
|
+
private normalizePersistedMessage(
|
|
215
|
+
input: unknown,
|
|
216
|
+
): SessionMessageV1 | null {
|
|
217
|
+
if (!input || typeof input !== "object") return null;
|
|
218
|
+
const candidate = input as Partial<SessionMessageV1>;
|
|
219
|
+
const role = String(candidate.role || "");
|
|
220
|
+
if (role !== "user" && role !== "assistant") return null;
|
|
221
|
+
if (!Array.isArray(candidate.parts)) return null;
|
|
222
|
+
return candidate as SessionMessageV1;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private hasStructuredAssistantParts(message: SessionMessageV1 | null): boolean {
|
|
226
|
+
if (!message || message.role !== "assistant" || !Array.isArray(message.parts)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
return message.parts.some((part) => {
|
|
230
|
+
if (!part || typeof part !== "object") return false;
|
|
231
|
+
const type = typeof part.type === "string" ? part.type.trim() : "";
|
|
232
|
+
return Boolean(type) && type !== "text";
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private mergeInflightWithFinal(
|
|
237
|
+
inflight: SessionMessageV1,
|
|
238
|
+
finalMessage: SessionMessageV1,
|
|
239
|
+
): SessionMessageV1 {
|
|
240
|
+
const final_parts = Array.isArray(finalMessage.parts)
|
|
241
|
+
? finalMessage.parts.filter((part) => part && typeof part === "object")
|
|
242
|
+
: [];
|
|
243
|
+
if (this.hasStructuredAssistantParts(finalMessage)) {
|
|
244
|
+
return finalMessage;
|
|
245
|
+
}
|
|
246
|
+
if (final_parts.length === 0) return inflight;
|
|
247
|
+
|
|
248
|
+
const inflight_parts = Array.isArray(inflight.parts)
|
|
249
|
+
? inflight.parts
|
|
250
|
+
: [];
|
|
251
|
+
const last_inflight_part =
|
|
252
|
+
inflight_parts.length > 0 ? inflight_parts[inflight_parts.length - 1] : undefined;
|
|
253
|
+
const last_inflight_text =
|
|
254
|
+
last_inflight_part &&
|
|
255
|
+
typeof last_inflight_part === "object" &&
|
|
256
|
+
last_inflight_part.type === "text" &&
|
|
257
|
+
typeof last_inflight_part.text === "string"
|
|
258
|
+
? last_inflight_part.text.trim()
|
|
259
|
+
: "";
|
|
260
|
+
const append_parts = final_parts.filter((part, index) => {
|
|
261
|
+
if (index > 0) return true;
|
|
262
|
+
if (!part || typeof part !== "object" || part.type !== "text") return true;
|
|
263
|
+
const next_text = typeof part.text === "string" ? part.text.trim() : "";
|
|
264
|
+
if (!next_text) return false;
|
|
265
|
+
return next_text !== last_inflight_text;
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
...inflight,
|
|
270
|
+
id: finalMessage.id,
|
|
271
|
+
metadata: {
|
|
272
|
+
...(inflight.metadata || {
|
|
273
|
+
v: 1 as const,
|
|
274
|
+
ts: Date.now(),
|
|
275
|
+
sessionId: this.sessionId,
|
|
276
|
+
}),
|
|
277
|
+
...(finalMessage.metadata || {}),
|
|
278
|
+
},
|
|
279
|
+
parts: [...inflight_parts, ...append_parts],
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
202
283
|
private async readMetaUnsafe(): Promise<SessionHistoryMetaV1> {
|
|
203
284
|
const file = this.getMetaFilePath();
|
|
204
285
|
try {
|
|
@@ -261,6 +342,40 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
261
342
|
await fs.writeJson(this.getMetaFilePath(), normalized, { spaces: 2 });
|
|
262
343
|
}
|
|
263
344
|
|
|
345
|
+
private async readInflightUnsafe(): Promise<SessionMessageV1 | null> {
|
|
346
|
+
const file = this.getInflightFilePath();
|
|
347
|
+
try {
|
|
348
|
+
const raw = await fs.readJson(file);
|
|
349
|
+
return this.normalizePersistedMessage(raw);
|
|
350
|
+
} catch {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
private async writeInflightUnsafe(message: SessionMessageV1): Promise<void> {
|
|
356
|
+
const normalized = this.normalizePersistedMessage(message);
|
|
357
|
+
if (!normalized || normalized.role !== "assistant") {
|
|
358
|
+
throw new Error("inflight assistant must be an assistant UIMessage");
|
|
359
|
+
}
|
|
360
|
+
const file = this.getInflightFilePath();
|
|
361
|
+
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
362
|
+
await fs.ensureDir(path.dirname(file));
|
|
363
|
+
await fs.writeJson(temp, normalized, { spaces: 2 });
|
|
364
|
+
await fs.move(temp, file, { overwrite: true });
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private async removeInflightUnsafe(): Promise<void> {
|
|
368
|
+
await fs.remove(this.getInflightFilePath());
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private async appendMessageUnsafe(message: SessionMessageV1): Promise<void> {
|
|
372
|
+
await fs.appendFile(
|
|
373
|
+
this.getMessagesFilePath(),
|
|
374
|
+
JSON.stringify(message) + "\n",
|
|
375
|
+
"utf8",
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
264
379
|
private async withWriteLock<T>(fn: () => Promise<T>): Promise<T> {
|
|
265
380
|
await this.ensureLayout();
|
|
266
381
|
const lockPath = this.getLockFilePath();
|
|
@@ -361,11 +476,48 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
361
476
|
|
|
362
477
|
async append(message: SessionMessageV1): Promise<void> {
|
|
363
478
|
await this.withWriteLock(async () => {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
)
|
|
479
|
+
const normalized = this.normalizePersistedMessage(message);
|
|
480
|
+
if (!normalized) return;
|
|
481
|
+
|
|
482
|
+
// 关键点(中文):若上一次 assistant 在运行中中断,新的 user 到来前先把残留快照收口到正式历史,
|
|
483
|
+
// 避免 `list()` 时旧 inflight 跑到新 user 后面,打乱时序。
|
|
484
|
+
if (normalized.role === "user") {
|
|
485
|
+
const current_inflight = await this.readInflightUnsafe();
|
|
486
|
+
if (current_inflight) {
|
|
487
|
+
await this.appendMessageUnsafe(current_inflight);
|
|
488
|
+
await this.removeInflightUnsafe();
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
await this.appendMessageUnsafe(normalized);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
async readInflight(): Promise<SessionMessageV1 | null> {
|
|
497
|
+
await this.ensureLayout();
|
|
498
|
+
return this.readInflightUnsafe();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
async writeInflight(message: SessionMessageV1): Promise<void> {
|
|
502
|
+
await this.withWriteLock(async () => {
|
|
503
|
+
await this.writeInflightUnsafe(message);
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async finalizeInflight(message?: SessionMessageV1 | null): Promise<void> {
|
|
508
|
+
await this.withWriteLock(async () => {
|
|
509
|
+
const current_inflight = await this.readInflightUnsafe();
|
|
510
|
+
const normalized_message = this.normalizePersistedMessage(message);
|
|
511
|
+
const final_message =
|
|
512
|
+
current_inflight && normalized_message
|
|
513
|
+
? this.mergeInflightWithFinal(current_inflight, normalized_message)
|
|
514
|
+
: normalized_message || current_inflight;
|
|
515
|
+
if (final_message) {
|
|
516
|
+
await this.appendMessageUnsafe(final_message);
|
|
517
|
+
}
|
|
518
|
+
if (current_inflight) {
|
|
519
|
+
await this.removeInflightUnsafe();
|
|
520
|
+
}
|
|
369
521
|
});
|
|
370
522
|
}
|
|
371
523
|
|
|
@@ -377,16 +529,17 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
|
|
|
377
529
|
const out: SessionMessageV1[] = [];
|
|
378
530
|
for (const line of lines) {
|
|
379
531
|
try {
|
|
380
|
-
const obj = JSON.parse(line)
|
|
381
|
-
if (!obj
|
|
382
|
-
|
|
383
|
-
if (role !== "user" && role !== "assistant") continue;
|
|
384
|
-
if (!Array.isArray(obj.parts)) continue;
|
|
385
|
-
out.push(obj as SessionMessageV1);
|
|
532
|
+
const obj = this.normalizePersistedMessage(JSON.parse(line));
|
|
533
|
+
if (!obj) continue;
|
|
534
|
+
out.push(obj);
|
|
386
535
|
} catch {
|
|
387
536
|
// ignore invalid lines
|
|
388
537
|
}
|
|
389
538
|
}
|
|
539
|
+
const current_inflight = await this.readInflightUnsafe();
|
|
540
|
+
if (current_inflight) {
|
|
541
|
+
out.push(current_inflight);
|
|
542
|
+
}
|
|
390
543
|
return out;
|
|
391
544
|
}
|
|
392
545
|
|
|
@@ -3,35 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - shell 会话生命周期已经统一收敛到 shell plugin runtime。
|
|
6
|
-
* - 这里仅保留当前仍被 tool
|
|
6
|
+
* - 这里仅保留当前仍被 tool 与测试复用的最小能力:命令安全校验。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { stripInvocationAuthEnv } from "@/runtime/auth/AuthEnv.js";
|
|
10
|
-
import { getSessionRunScope } from "@executor/SessionRunScope.js";
|
|
11
|
-
|
|
12
|
-
function setEnvString(
|
|
13
|
-
env: NodeJS.ProcessEnv,
|
|
14
|
-
key: string,
|
|
15
|
-
value: string | undefined,
|
|
16
|
-
): void {
|
|
17
|
-
if (typeof value !== "string") return;
|
|
18
|
-
const trimmed = value.trim();
|
|
19
|
-
if (!trimmed) return;
|
|
20
|
-
env[key] = trimmed;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function applyEnvMap(
|
|
24
|
-
env: NodeJS.ProcessEnv,
|
|
25
|
-
entries?: Record<string, string>,
|
|
26
|
-
): void {
|
|
27
|
-
if (!entries) return;
|
|
28
|
-
for (const [rawKey, rawValue] of Object.entries(entries)) {
|
|
29
|
-
const key = String(rawKey || "").trim();
|
|
30
|
-
if (!key) continue;
|
|
31
|
-
setEnvString(env, key, rawValue);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
9
|
/**
|
|
36
10
|
* 对 `town chat send` 命令做前置安全校验。
|
|
37
11
|
*
|
|
@@ -58,26 +32,3 @@ export function validateChatSendCommand(cmd: string): string | null {
|
|
|
58
32
|
"If your message is multi-line, use `town chat send --stdin` (with heredoc/pipe), `--text-file`, or explicit `--text`.",
|
|
59
33
|
].join(" ");
|
|
60
34
|
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 构建 shell 子进程环境变量。
|
|
64
|
-
*
|
|
65
|
-
* 关键点(中文)
|
|
66
|
-
* - 当前仍用于 shell tool / shell runtime 与相关测试。
|
|
67
|
-
* - 优先级:显式注入 > 当前请求上下文变量 > 宿主进程环境。
|
|
68
|
-
* - 默认剥离 Bearer Token,避免通用 shell 隐式走本地 HTTP。
|
|
69
|
-
*/
|
|
70
|
-
export function buildShellContextEnv(
|
|
71
|
-
injected?: Record<string, string>,
|
|
72
|
-
): NodeJS.ProcessEnv {
|
|
73
|
-
const env: NodeJS.ProcessEnv = { ...process.env };
|
|
74
|
-
const contextCtx = getSessionRunScope();
|
|
75
|
-
|
|
76
|
-
applyEnvMap(env, injected);
|
|
77
|
-
setEnvString(env, "DC_SESSION_ID", contextCtx?.sessionId);
|
|
78
|
-
setEnvString(env, "DC_CITY_HOST", process.env.DC_CITY_HOST);
|
|
79
|
-
setEnvString(env, "DC_CITY_PORT", process.env.DC_CITY_PORT);
|
|
80
|
-
stripInvocationAuthEnv(env);
|
|
81
|
-
|
|
82
|
-
return env;
|
|
83
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
// Agent 入口
|
|
11
|
-
export { Agent } from "./agent/Agent.js";
|
|
12
|
-
export { RemoteAgent } from "./agent/RemoteAgent.js";
|
|
11
|
+
export { Agent } from "./agent/local/Agent.js";
|
|
12
|
+
export { RemoteAgent } from "./agent/remote/RemoteAgent.js";
|
|
13
13
|
export {
|
|
14
14
|
inferAgentModelLabel,
|
|
15
15
|
normalizeAgentModel,
|
|
@@ -134,7 +134,7 @@ export {
|
|
|
134
134
|
export { loadDowncityConfig } from "./config/Config.js";
|
|
135
135
|
export {
|
|
136
136
|
ensureRuntimeProjectReady,
|
|
137
|
-
} from "./
|
|
137
|
+
} from "./agent/local/ProjectSetup.js";
|
|
138
138
|
export { assertProjectExecutionTarget } from "./config/ExecutionBinding.js";
|
|
139
139
|
|
|
140
140
|
// 日志
|
|
@@ -144,7 +144,7 @@ export { getLogger, logger, type Logger } from "./utils/logger/Logger.js";
|
|
|
144
144
|
export type {
|
|
145
145
|
AgentPathRuntime,
|
|
146
146
|
AgentPluginConfigRuntime,
|
|
147
|
-
} from "./types/
|
|
147
|
+
} from "./types/agent/AgentRuntimeAssembly.js";
|
|
148
148
|
|
|
149
149
|
// 项目协议类型
|
|
150
150
|
export type {
|
|
@@ -273,7 +273,7 @@ export type {
|
|
|
273
273
|
UpsertChannelAccountInput,
|
|
274
274
|
UpsertEnvEntryInput,
|
|
275
275
|
UpsertGlobalEnvEntryInput,
|
|
276
|
-
} from "./types/
|
|
276
|
+
} from "./types/platform/Store.js";
|
|
277
277
|
|
|
278
278
|
// HTTP auth 协议类型
|
|
279
279
|
export {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* PluginCommandRequest:统一 plugin runtime command 请求解析模块。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
5
|
+
* - 统一收口 Town gateway command 入口的请求体解析。
|
|
6
6
|
* - plugin runtime 远程调用统一走 runtime command 协议,不再让 action 自带 HTTP route。
|
|
7
7
|
* - ActionSchedule 参数(`schedule` / `delay` / `time`)也在这里一次性归一化。
|
|
8
8
|
*/
|
|
@@ -15,7 +15,7 @@ import { findPluginByName } from "@/plugin/core/PluginCatalog.js";
|
|
|
15
15
|
import {
|
|
16
16
|
createAgentPathRuntime,
|
|
17
17
|
createAgentPluginConfigRuntime,
|
|
18
|
-
} from "@/
|
|
18
|
+
} from "@/agent/local/AgentRuntimeAssembly.js";
|
|
19
19
|
import type { JsonValue } from "@/types/common/Json.js";
|
|
20
20
|
import type {
|
|
21
21
|
Plugin,
|