@downcity/agent 1.1.237 → 1.1.258
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 +21 -20
- package/bin/agent/{local/Agent.d.ts → Agent.d.ts} +37 -27
- package/bin/agent/Agent.d.ts.map +1 -0
- package/bin/agent/Agent.js +211 -0
- package/bin/agent/Agent.js.map +1 -0
- package/bin/agent/AgentContext.d.ts +64 -0
- package/bin/agent/AgentContext.d.ts.map +1 -0
- package/bin/agent/AgentContext.js +53 -0
- package/bin/agent/AgentContext.js.map +1 -0
- package/bin/agent/{local/AgentInstructions.d.ts → AgentInstructions.d.ts} +1 -6
- package/bin/agent/AgentInstructions.d.ts.map +1 -0
- package/bin/agent/{local/AgentInstructions.js → AgentInstructions.js} +1 -10
- package/bin/agent/AgentInstructions.js.map +1 -0
- package/bin/{model/CityModelAdapter.d.ts → agent/AgentModel.d.ts} +3 -3
- package/bin/agent/AgentModel.d.ts.map +1 -0
- package/bin/{model/CityModelAdapter.js → agent/AgentModel.js} +11 -4
- package/bin/agent/AgentModel.js.map +1 -0
- package/bin/agent/{local/services/AgentSessions.d.ts → AgentSessions.d.ts} +30 -40
- package/bin/agent/AgentSessions.d.ts.map +1 -0
- package/bin/agent/{local/services/AgentSessions.js → AgentSessions.js} +62 -79
- package/bin/agent/AgentSessions.js.map +1 -0
- package/bin/agent/AgentState.d.ts +64 -0
- package/bin/agent/AgentState.d.ts.map +1 -0
- package/bin/agent/AgentState.js +118 -0
- package/bin/agent/AgentState.js.map +1 -0
- package/bin/config/Paths.d.ts +0 -43
- package/bin/config/Paths.d.ts.map +1 -1
- package/bin/config/Paths.js +0 -79
- package/bin/config/Paths.js.map +1 -1
- package/bin/config/ProjectSetup.d.ts.map +1 -0
- package/bin/{agent/local → config}/ProjectSetup.js +1 -1
- package/bin/config/ProjectSetup.js.map +1 -0
- package/bin/executor/Executor.d.ts +20 -86
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +109 -260
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +1 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts.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 +4 -1
- package/bin/executor/composer/system/default/SystemDomain.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/core-engine/CoreEngineRunner.d.ts +7 -13
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +81 -34
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +6 -12
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -1
- package/bin/executor/services/ExecutorRecoveryPolicy.js +20 -6
- package/bin/executor/services/ExecutorRecoveryPolicy.js.map +1 -1
- package/bin/executor/tools/file/ReadImageToolBridge.d.ts +21 -0
- package/bin/executor/tools/file/ReadImageToolBridge.d.ts.map +1 -0
- package/bin/executor/tools/file/ReadImageToolBridge.js +69 -0
- package/bin/executor/tools/file/ReadImageToolBridge.js.map +1 -0
- package/bin/executor/tools/plugin/PluginToolBridge.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolBridge.js +6 -5
- package/bin/executor/tools/plugin/PluginToolBridge.js.map +1 -1
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolDefinition.js +15 -2
- package/bin/executor/tools/plugin/PluginToolDefinition.js.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +0 -2
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/index.d.ts +17 -21
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +9 -11
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/ActionScheduleExecutor.d.ts +1 -1
- package/bin/plugin/core/ActionScheduleExecutor.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleRuntime.d.ts +1 -1
- package/bin/plugin/core/ActionScheduleRuntime.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.d.ts +4 -3
- package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.js.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +5 -8
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/HookRegistry.js +12 -12
- package/bin/plugin/core/HookRegistry.js.map +1 -1
- package/bin/plugin/core/PluginActionFactory.d.ts +6 -3
- package/bin/plugin/core/PluginActionFactory.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionFactory.js.map +1 -1
- package/bin/plugin/core/PluginActionRunner.d.ts +1 -1
- package/bin/plugin/core/PluginActionRunner.d.ts.map +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts +1 -1
- package/bin/plugin/core/PluginCatalog.d.ts.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 -5
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +4 -12
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +16 -12
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +43 -22
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +1 -1
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/{agent/remote → remote}/RemoteAgent.d.ts +4 -4
- package/bin/remote/RemoteAgent.d.ts.map +1 -0
- package/bin/{agent/remote → remote}/RemoteAgent.js +3 -3
- package/bin/remote/RemoteAgent.js.map +1 -0
- package/bin/{agent/remote → remote}/RemoteSession.d.ts +9 -11
- package/bin/remote/RemoteSession.d.ts.map +1 -0
- package/bin/{agent/remote → remote}/RemoteSession.js +3 -33
- package/bin/remote/RemoteSession.js.map +1 -0
- package/bin/{agent/remote → remote}/RemoteTransport.d.ts +7 -9
- package/bin/remote/RemoteTransport.d.ts.map +1 -0
- package/bin/remote/RemoteTransport.js.map +1 -0
- package/bin/{agent/remote → remote}/TransportFactory.d.ts +1 -1
- package/bin/remote/TransportFactory.d.ts.map +1 -0
- package/bin/{agent/remote → remote}/TransportFactory.js +2 -2
- package/bin/remote/TransportFactory.js.map +1 -0
- package/bin/{agent/remote → remote}/transports/HttpRemoteAgentTransport.d.ts +8 -9
- package/bin/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -0
- package/bin/{agent/remote → remote}/transports/HttpRemoteAgentTransport.js +0 -13
- package/bin/remote/transports/HttpRemoteAgentTransport.js.map +1 -0
- package/bin/{rpc/Client.d.ts → remote/transports/RpcClient.d.ts} +15 -22
- package/bin/remote/transports/RpcClient.d.ts.map +1 -0
- package/bin/{rpc/Client.js → remote/transports/RpcClient.js} +2 -13
- package/bin/remote/transports/RpcClient.js.map +1 -0
- package/bin/{agent/remote → remote}/transports/RpcRemoteAgentTransport.d.ts +8 -9
- package/bin/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -0
- package/bin/{agent/remote → remote}/transports/RpcRemoteAgentTransport.js +1 -4
- package/bin/remote/transports/RpcRemoteAgentTransport.js.map +1 -0
- package/bin/session/DefaultSessionComposer.d.ts +18 -0
- package/bin/session/DefaultSessionComposer.d.ts.map +1 -0
- package/bin/session/DefaultSessionComposer.js +62 -0
- package/bin/session/DefaultSessionComposer.js.map +1 -0
- package/bin/session/Session.d.ts +44 -33
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +440 -274
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionMessages.d.ts +117 -0
- package/bin/session/SessionMessages.d.ts.map +1 -0
- package/bin/session/{recorder/SessionRecorder.js → SessionMessages.js} +194 -284
- package/bin/session/SessionMessages.js.map +1 -0
- package/bin/session/SessionQueue.d.ts +34 -0
- package/bin/session/SessionQueue.d.ts.map +1 -0
- package/bin/session/SessionQueue.js +60 -0
- package/bin/session/SessionQueue.js.map +1 -0
- package/bin/session/SessionState.d.ts +70 -0
- package/bin/session/SessionState.d.ts.map +1 -0
- package/bin/session/SessionState.js +267 -0
- package/bin/session/SessionState.js.map +1 -0
- package/bin/session/SessionSystem.d.ts +15 -0
- package/bin/session/SessionSystem.d.ts.map +1 -0
- package/bin/session/SessionSystem.js +95 -0
- package/bin/session/SessionSystem.js.map +1 -0
- package/bin/session/SessionTurn.d.ts +84 -0
- package/bin/session/SessionTurn.d.ts.map +1 -0
- package/bin/session/SessionTurn.js +588 -0
- package/bin/session/SessionTurn.js.map +1 -0
- package/bin/session/approval/SessionApprovalBroker.d.ts +48 -0
- package/bin/session/approval/SessionApprovalBroker.d.ts.map +1 -0
- package/bin/session/approval/SessionApprovalBroker.js +126 -0
- package/bin/session/approval/SessionApprovalBroker.js.map +1 -0
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +1 -4
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/{recorder → messages}/JsonlSessionMessageStore.d.ts.map +1 -1
- package/bin/session/{recorder → messages}/JsonlSessionMessageStore.js.map +1 -1
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts +62 -0
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts.map +1 -0
- package/bin/session/messages/SessionAssistantMessageWriter.js +287 -0
- package/bin/session/messages/SessionAssistantMessageWriter.js.map +1 -0
- package/bin/session/messages/SessionJsonValue.d.ts +10 -0
- package/bin/session/messages/SessionJsonValue.d.ts.map +1 -0
- package/bin/session/messages/SessionJsonValue.js +23 -0
- package/bin/session/messages/SessionJsonValue.js.map +1 -0
- package/bin/session/{recorder → messages}/SessionMessageCodec.d.ts +4 -1
- package/bin/session/messages/SessionMessageCodec.d.ts.map +1 -0
- package/bin/session/{recorder → messages}/SessionMessageCodec.js +33 -19
- package/bin/session/messages/SessionMessageCodec.js.map +1 -0
- package/bin/session/messages/SessionMessageCompaction.d.ts +22 -0
- package/bin/session/messages/SessionMessageCompaction.d.ts.map +1 -0
- package/bin/session/{recorder/SessionRecorderCompaction.js → messages/SessionMessageCompaction.js} +19 -51
- package/bin/session/messages/SessionMessageCompaction.js.map +1 -0
- package/bin/session/runtime/SessionEventHub.d.ts +1 -8
- package/bin/session/runtime/SessionEventHub.d.ts.map +1 -1
- package/bin/session/runtime/SessionEventHub.js +1 -6
- package/bin/session/runtime/SessionEventHub.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +23 -5
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +32 -29
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +5 -10
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +2 -4
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +6 -35
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentState.d.ts +28 -0
- package/bin/types/agent/AgentState.d.ts.map +1 -0
- package/bin/types/agent/AgentState.js +9 -0
- package/bin/types/agent/AgentState.js.map +1 -0
- package/bin/types/agent/SessionActor.d.ts +0 -2
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +5 -18
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +8 -2
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.js +1 -1
- package/bin/types/executor/SessionToolExecutionContext.d.ts +20 -0
- package/bin/types/executor/SessionToolExecutionContext.d.ts.map +1 -0
- package/bin/types/executor/SessionToolExecutionContext.js +10 -0
- package/bin/types/executor/SessionToolExecutionContext.js.map +1 -0
- package/bin/types/plugin/PluginAction.d.ts +10 -1
- package/bin/types/plugin/PluginAction.d.ts.map +1 -1
- package/bin/types/plugin/PluginCommand.d.ts +3 -11
- package/bin/types/plugin/PluginCommand.d.ts.map +1 -1
- package/bin/types/plugin/PluginConfig.d.ts +12 -0
- package/bin/types/plugin/PluginConfig.d.ts.map +1 -0
- package/bin/types/plugin/PluginConfig.js +5 -0
- package/bin/types/plugin/PluginConfig.js.map +1 -0
- package/bin/types/plugin/PluginDefinition.d.ts +10 -3
- package/bin/types/plugin/PluginDefinition.d.ts.map +1 -1
- package/bin/types/plugin/PluginHttp.d.ts +1 -1
- package/bin/types/plugin/PluginHttp.d.ts.map +1 -1
- package/bin/types/plugin/PluginRunContext.d.ts +26 -0
- package/bin/types/plugin/PluginRunContext.d.ts.map +1 -0
- package/bin/types/plugin/PluginRunContext.js +10 -0
- package/bin/types/plugin/PluginRunContext.js.map +1 -0
- package/bin/types/plugin/PluginRuntime.d.ts +9 -3
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginToolRuntime.d.ts +11 -0
- package/bin/types/plugin/PluginToolRuntime.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +1 -13
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/session/SessionApproval.d.ts +4 -38
- package/bin/types/session/SessionApproval.d.ts.map +1 -1
- package/bin/types/session/SessionApprovalBroker.d.ts +17 -0
- package/bin/types/session/SessionApprovalBroker.d.ts.map +1 -0
- package/bin/types/session/SessionApprovalBroker.js +7 -0
- package/bin/types/session/SessionApprovalBroker.js.map +1 -0
- package/bin/types/session/SessionComposer.d.ts +99 -0
- package/bin/types/session/SessionComposer.d.ts.map +1 -0
- package/bin/types/session/SessionComposer.js +8 -0
- package/bin/types/session/SessionComposer.js.map +1 -0
- package/bin/types/session/SessionLocalState.d.ts +6 -6
- package/bin/types/session/SessionLocalState.d.ts.map +1 -1
- package/bin/types/session/SessionLocalState.js +1 -1
- package/bin/types/session/SessionMessage.d.ts +3 -2
- package/bin/types/session/SessionMessage.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +115 -0
- package/bin/types/session/SessionMessages.d.ts.map +1 -0
- package/bin/types/session/SessionMessages.js +7 -0
- package/bin/types/session/SessionMessages.js.map +1 -0
- package/bin/types/session/SessionMutation.d.ts +1 -10
- package/bin/types/session/SessionMutation.d.ts.map +1 -1
- package/bin/types/session/SessionMutation.js.map +1 -1
- package/bin/types/session/SessionOptions.d.ts +8 -23
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionPort.d.ts +72 -0
- package/bin/types/session/SessionPort.d.ts.map +1 -0
- package/bin/types/session/SessionPort.js +9 -0
- package/bin/types/session/SessionPort.js.map +1 -0
- package/bin/types/session/SessionQueue.d.ts +104 -0
- package/bin/types/session/SessionQueue.d.ts.map +1 -0
- package/bin/types/session/SessionQueue.js +7 -0
- package/bin/types/session/SessionQueue.js.map +1 -0
- package/bin/types/session/SessionState.d.ts +43 -0
- package/bin/types/session/SessionState.d.ts.map +1 -0
- package/bin/types/session/SessionState.js +7 -0
- package/bin/types/session/SessionState.js.map +1 -0
- package/bin/types/session/SessionSystem.d.ts +26 -0
- package/bin/types/session/SessionSystem.d.ts.map +1 -0
- package/bin/types/session/SessionSystem.js +7 -0
- package/bin/types/session/SessionSystem.js.map +1 -0
- package/bin/types/session/SessionTool.d.ts +23 -0
- package/bin/types/session/SessionTool.d.ts.map +1 -0
- package/bin/types/session/SessionTool.js +7 -0
- package/bin/types/session/SessionTool.js.map +1 -0
- package/bin/types/session/SessionTurn.d.ts +52 -0
- package/bin/types/session/SessionTurn.d.ts.map +1 -0
- package/bin/types/session/SessionTurn.js +7 -0
- package/bin/types/session/SessionTurn.js.map +1 -0
- package/package.json +3 -3
- package/scripts/agent-env.test.mjs +4 -18
- package/scripts/agent-ready.test.mjs +33 -2
- package/scripts/agent-session-maintenance.test.mjs +52 -0
- package/scripts/city-model-tool-loop.test.mjs +3 -4
- package/scripts/core-engine-context-compaction.test.mjs +5 -22
- package/scripts/image-plugin-job.test.mjs +4 -6
- package/scripts/plugin-tool-bridge.test.mjs +44 -36
- package/scripts/read-image-tool-bridge.test.mjs +71 -0
- package/scripts/remote-session-reconnect.test.mjs +1 -34
- package/scripts/session-compaction-prompts.test.mjs +1 -49
- package/scripts/session-composer.test.mjs +163 -0
- package/scripts/session-config-turn-boundary.test.mjs +2 -5
- package/scripts/session-list-title.test.mjs +3 -2
- package/scripts/session-messages-error.test.mjs +57 -0
- package/scripts/{session-recorder.test.mjs → session-messages.test.mjs} +131 -90
- package/scripts/session-queue.test.mjs +64 -0
- package/scripts/session-shell-approval.test.mjs +171 -0
- package/scripts/session-system-blocks.test.mjs +10 -10
- package/scripts/session-title-event.test.mjs +1 -0
- package/src/agent/Agent.ts +241 -0
- package/src/agent/AgentContext.ts +92 -0
- package/src/agent/{local/AgentInstructions.ts → AgentInstructions.ts} +0 -11
- package/src/{model/CityModelAdapter.ts → agent/AgentModel.ts} +10 -3
- package/src/agent/{local/services/AgentSessions.ts → AgentSessions.ts} +81 -110
- package/src/agent/AgentState.ts +151 -0
- package/src/config/Paths.ts +0 -91
- package/src/executor/Executor.ts +180 -386
- package/src/executor/README.md +29 -89
- package/src/executor/composer/system/default/DefaultSessionSystemComposer.ts +1 -1
- package/src/executor/composer/system/default/SystemDomain.ts +4 -2
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +15 -2
- package/src/executor/core-engine/CoreEngineRunner.ts +95 -54
- package/src/executor/services/ExecutorRecoveryPolicy.ts +24 -19
- package/src/executor/tools/file/ReadImageToolBridge.ts +79 -0
- package/src/executor/tools/plugin/PluginToolBridge.ts +6 -8
- package/src/executor/tools/plugin/PluginToolDefinition.ts +23 -3
- package/src/executor/types/SessionHistoryMeta.ts +0 -2
- package/src/index.ts +34 -53
- package/src/plugin/core/ActionScheduleExecutor.ts +1 -1
- package/src/plugin/core/ActionScheduleRuntime.ts +1 -1
- package/src/plugin/core/BasePlugin.ts +7 -3
- package/src/plugin/core/HookRegistry.ts +15 -18
- package/src/plugin/core/PluginActionFactory.ts +9 -3
- package/src/plugin/core/PluginActionRunner.ts +1 -1
- package/src/plugin/core/PluginCatalog.ts +1 -1
- package/src/plugin/core/PluginHttpRoutes.ts +1 -1
- package/src/plugin/core/PluginLocalExecution.ts +11 -24
- package/src/plugin/core/PluginRegistry.ts +55 -32
- package/src/plugin/core/PluginStateController.ts +1 -1
- package/src/{agent/remote → remote}/RemoteAgent.ts +4 -4
- package/src/{agent/remote → remote}/RemoteSession.ts +2 -35
- package/src/{agent/remote → remote}/RemoteTransport.ts +0 -3
- package/src/{agent/remote → remote}/TransportFactory.ts +3 -3
- package/src/{agent/remote → remote}/transports/HttpRemoteAgentTransport.ts +1 -23
- package/src/{rpc/Client.ts → remote/transports/RpcClient.ts} +1 -19
- package/src/{agent/remote → remote}/transports/RpcRemoteAgentTransport.ts +2 -10
- package/src/session/DefaultSessionComposer.ts +79 -0
- package/src/session/Session.ts +496 -332
- package/src/session/{recorder/SessionRecorder.ts → SessionMessages.ts} +254 -428
- package/src/session/SessionQueue.ts +86 -0
- package/src/session/SessionState.ts +322 -0
- package/src/session/SessionSystem.ts +117 -0
- package/src/session/SessionTurn.ts +684 -0
- package/src/session/approval/SessionApprovalBroker.ts +164 -0
- package/src/session/browse/Browse.ts +1 -4
- package/src/session/messages/SessionAssistantMessageWriter.ts +345 -0
- package/src/session/messages/SessionJsonValue.ts +25 -0
- package/src/session/{recorder → messages}/SessionMessageCodec.ts +38 -20
- package/src/session/{recorder/SessionRecorderCompaction.ts → messages/SessionMessageCompaction.ts} +30 -69
- package/src/session/runtime/SessionEventHub.ts +1 -14
- package/src/session/storage/Metadata.ts +60 -34
- package/src/session/storage/RuntimeSessionPort.ts +7 -14
- package/src/types/agent/AgentOptions.ts +6 -38
- package/src/types/agent/AgentState.ts +33 -0
- package/src/types/agent/SessionActor.ts +0 -3
- package/src/types/agent/SessionTypes.ts +5 -18
- package/src/types/executor/SessionRunContext.ts +10 -2
- package/src/types/executor/SessionToolExecutionContext.ts +21 -0
- package/src/types/plugin/PluginAction.ts +10 -1
- package/src/types/plugin/PluginCommand.ts +3 -14
- package/src/types/plugin/PluginConfig.ts +13 -0
- package/src/types/plugin/PluginDefinition.ts +13 -6
- package/src/types/plugin/PluginHttp.ts +1 -1
- package/src/types/plugin/PluginRunContext.ts +31 -0
- package/src/types/plugin/PluginRuntime.ts +13 -6
- package/src/types/plugin/PluginToolRuntime.ts +13 -1
- package/src/types/rpc/RpcProtocol.ts +0 -14
- package/src/types/session/SessionApproval.ts +4 -43
- package/src/types/session/SessionApprovalBroker.ts +18 -0
- package/src/types/session/SessionComposer.ts +114 -0
- package/src/types/session/SessionLocalState.ts +6 -6
- package/src/types/session/SessionMessage.ts +3 -2
- package/src/types/session/SessionMessages.ts +127 -0
- package/src/types/session/SessionMutation.ts +0 -11
- package/src/types/session/SessionOptions.ts +8 -40
- package/src/types/session/SessionPort.ts +97 -0
- package/src/types/session/SessionQueue.ts +122 -0
- package/src/types/session/SessionState.ts +47 -0
- package/src/types/session/SessionSystem.ts +27 -0
- package/src/types/session/SessionTool.ts +25 -0
- package/src/types/session/SessionTurn.ts +56 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/local/Agent.d.ts.map +0 -1
- package/bin/agent/local/Agent.js +0 -216
- package/bin/agent/local/Agent.js.map +0 -1
- package/bin/agent/local/AgentInstructions.d.ts.map +0 -1
- package/bin/agent/local/AgentInstructions.js.map +0 -1
- package/bin/agent/local/AgentPluginFactory.d.ts +0 -26
- package/bin/agent/local/AgentPluginFactory.d.ts.map +0 -1
- package/bin/agent/local/AgentPluginFactory.js +0 -33
- package/bin/agent/local/AgentPluginFactory.js.map +0 -1
- package/bin/agent/local/AgentRuntimeAssembly.d.ts +0 -10
- package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +0 -1
- package/bin/agent/local/AgentRuntimeAssembly.js +0 -43
- package/bin/agent/local/AgentRuntimeAssembly.js.map +0 -1
- package/bin/agent/local/ProjectSetup.d.ts.map +0 -1
- package/bin/agent/local/ProjectSetup.js.map +0 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +0 -105
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +0 -1
- package/bin/agent/local/services/AgentAssemblyService.js +0 -184
- package/bin/agent/local/services/AgentAssemblyService.js.map +0 -1
- package/bin/agent/local/services/AgentBackgroundService.d.ts +0 -55
- package/bin/agent/local/services/AgentBackgroundService.d.ts.map +0 -1
- package/bin/agent/local/services/AgentBackgroundService.js +0 -85
- package/bin/agent/local/services/AgentBackgroundService.js.map +0 -1
- package/bin/agent/local/services/AgentSessions.d.ts.map +0 -1
- package/bin/agent/local/services/AgentSessions.js.map +0 -1
- package/bin/agent/remote/RemoteAgent.d.ts.map +0 -1
- package/bin/agent/remote/RemoteAgent.js.map +0 -1
- package/bin/agent/remote/RemoteSession.d.ts.map +0 -1
- package/bin/agent/remote/RemoteSession.js.map +0 -1
- package/bin/agent/remote/RemoteTransport.d.ts.map +0 -1
- package/bin/agent/remote/RemoteTransport.js.map +0 -1
- package/bin/agent/remote/TransportFactory.d.ts.map +0 -1
- package/bin/agent/remote/TransportFactory.js.map +0 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +0 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +0 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +0 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +0 -1
- package/bin/executor/SessionRunScope.d.ts +0 -68
- package/bin/executor/SessionRunScope.d.ts.map +0 -1
- package/bin/executor/SessionRunScope.js +0 -96
- package/bin/executor/SessionRunScope.js.map +0 -1
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts +0 -74
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +0 -1
- package/bin/executor/composer/compaction/SessionCompactionComposer.js +0 -9
- package/bin/executor/composer/compaction/SessionCompactionComposer.js.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts +0 -27
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +0 -39
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +0 -44
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +0 -218
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts +0 -27
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts.map +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js +0 -181
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js.map +0 -1
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +0 -50
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +0 -1
- package/bin/executor/composer/context/LocalSessionContextComposer.js +0 -108
- package/bin/executor/composer/context/LocalSessionContextComposer.js.map +0 -1
- package/bin/executor/composer/context/SessionContextComposer.d.ts +0 -67
- package/bin/executor/composer/context/SessionContextComposer.d.ts.map +0 -1
- package/bin/executor/composer/context/SessionContextComposer.js +0 -9
- package/bin/executor/composer/context/SessionContextComposer.js.map +0 -1
- package/bin/executor/composer/history/SessionHistoryComposer.d.ts +0 -54
- package/bin/executor/composer/history/SessionHistoryComposer.d.ts.map +0 -1
- package/bin/executor/composer/history/SessionHistoryComposer.js +0 -10
- package/bin/executor/composer/history/SessionHistoryComposer.js.map +0 -1
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts +0 -46
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +0 -1
- package/bin/executor/composer/history/SessionHistoryWriter.js +0 -65
- package/bin/executor/composer/history/SessionHistoryWriter.js.map +0 -1
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts +0 -35
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts.map +0 -1
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js +0 -105
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js.map +0 -1
- package/bin/executor/messages/AssistantResultPersistence.d.ts +0 -66
- package/bin/executor/messages/AssistantResultPersistence.d.ts.map +0 -1
- package/bin/executor/messages/AssistantResultPersistence.js +0 -44
- package/bin/executor/messages/AssistantResultPersistence.js.map +0 -1
- package/bin/executor/services/ExecutorInflightService.d.ts +0 -34
- package/bin/executor/services/ExecutorInflightService.d.ts.map +0 -1
- package/bin/executor/services/ExecutorInflightService.js +0 -73
- package/bin/executor/services/ExecutorInflightService.js.map +0 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +0 -140
- package/bin/executor/store/history/SessionHistoryStore.d.ts.map +0 -1
- package/bin/executor/store/history/SessionHistoryStore.js +0 -10
- package/bin/executor/store/history/SessionHistoryStore.js.map +0 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +0 -116
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +0 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +0 -709
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +0 -1
- package/bin/executor/types/SessionHistoryPaths.d.ts +0 -34
- package/bin/executor/types/SessionHistoryPaths.d.ts.map +0 -1
- package/bin/executor/types/SessionHistoryPaths.js +0 -2
- package/bin/executor/types/SessionHistoryPaths.js.map +0 -1
- package/bin/model/CityModelAdapter.d.ts.map +0 -1
- package/bin/model/CityModelAdapter.js.map +0 -1
- package/bin/rpc/Client.d.ts.map +0 -1
- package/bin/rpc/Client.js.map +0 -1
- package/bin/session/SessionSystemBuilder.d.ts +0 -107
- package/bin/session/SessionSystemBuilder.d.ts.map +0 -1
- package/bin/session/SessionSystemBuilder.js +0 -148
- package/bin/session/SessionSystemBuilder.js.map +0 -1
- package/bin/session/recorder/SessionMessageCodec.d.ts.map +0 -1
- package/bin/session/recorder/SessionMessageCodec.js.map +0 -1
- package/bin/session/recorder/SessionRecorder.d.ts +0 -217
- package/bin/session/recorder/SessionRecorder.d.ts.map +0 -1
- package/bin/session/recorder/SessionRecorder.js.map +0 -1
- package/bin/session/recorder/SessionRecorderCompaction.d.ts +0 -18
- package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +0 -1
- package/bin/session/recorder/SessionRecorderCompaction.js.map +0 -1
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +0 -66
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +0 -1
- package/bin/session/recorder/SessionRecorderHistoryStore.js +0 -190
- package/bin/session/recorder/SessionRecorderHistoryStore.js.map +0 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +0 -112
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +0 -1
- package/bin/session/runtime/SessionPromptRuntime.js +0 -357
- package/bin/session/runtime/SessionPromptRuntime.js.map +0 -1
- package/bin/session/services/SessionStateService.d.ts +0 -187
- package/bin/session/services/SessionStateService.d.ts.map +0 -1
- package/bin/session/services/SessionStateService.js +0 -467
- package/bin/session/services/SessionStateService.js.map +0 -1
- package/bin/session/services/SessionTurnService.d.ts +0 -90
- package/bin/session/services/SessionTurnService.d.ts.map +0 -1
- package/bin/session/services/SessionTurnService.js +0 -293
- package/bin/session/services/SessionTurnService.js.map +0 -1
- package/bin/session/services/SessionViewService.d.ts +0 -114
- package/bin/session/services/SessionViewService.d.ts.map +0 -1
- package/bin/session/services/SessionViewService.js +0 -204
- package/bin/session/services/SessionViewService.js.map +0 -1
- package/bin/session/storage/Persistence.d.ts +0 -73
- package/bin/session/storage/Persistence.d.ts.map +0 -1
- package/bin/session/storage/Persistence.js +0 -63
- package/bin/session/storage/Persistence.js.map +0 -1
- package/bin/types/agent/AgentRuntimeAssembly.d.ts +0 -72
- package/bin/types/agent/AgentRuntimeAssembly.d.ts.map +0 -1
- package/bin/types/agent/AgentRuntimeAssembly.js +0 -10
- package/bin/types/agent/AgentRuntimeAssembly.js.map +0 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +0 -306
- package/bin/types/runtime/agent/AgentContext.d.ts.map +0 -1
- package/bin/types/runtime/agent/AgentContext.js +0 -128
- package/bin/types/runtime/agent/AgentContext.js.map +0 -1
- package/bin/types/session/SessionComposerOptions.d.ts +0 -90
- package/bin/types/session/SessionComposerOptions.d.ts.map +0 -1
- package/bin/types/session/SessionComposerOptions.js +0 -10
- package/bin/types/session/SessionComposerOptions.js.map +0 -1
- package/bin/types/session/SessionQueueCommand.d.ts +0 -68
- package/bin/types/session/SessionQueueCommand.d.ts.map +0 -1
- package/bin/types/session/SessionQueueCommand.js +0 -10
- package/bin/types/session/SessionQueueCommand.js.map +0 -1
- package/scripts/session-action-message.test.mjs +0 -410
- package/scripts/session-compaction-context-window.test.mjs +0 -96
- package/scripts/session-history-inflight.test.mjs +0 -146
- package/scripts/session-history-writer-error.test.mjs +0 -57
- package/scripts/session-prompt-runtime.test.mjs +0 -390
- package/src/agent/local/Agent.ts +0 -250
- package/src/agent/local/AgentPluginFactory.ts +0 -51
- package/src/agent/local/AgentRuntimeAssembly.ts +0 -65
- package/src/agent/local/services/AgentAssemblyService.ts +0 -307
- package/src/agent/local/services/AgentBackgroundService.ts +0 -115
- package/src/executor/SessionRunScope.ts +0 -122
- package/src/executor/composer/compaction/SessionCompactionComposer.ts +0 -84
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +0 -51
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +0 -294
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.ts +0 -197
- package/src/executor/composer/context/LocalSessionContextComposer.ts +0 -175
- package/src/executor/composer/context/SessionContextComposer.ts +0 -83
- package/src/executor/composer/history/SessionHistoryComposer.ts +0 -62
- package/src/executor/composer/history/SessionHistoryWriter.ts +0 -100
- package/src/executor/composer/history/jsonl/JsonlSessionHistoryComposer.ts +0 -133
- package/src/executor/messages/AssistantResultPersistence.ts +0 -106
- package/src/executor/services/ExecutorInflightService.ts +0 -95
- package/src/executor/store/history/SessionHistoryStore.ts +0 -172
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +0 -879
- package/src/executor/types/SessionHistoryPaths.ts +0 -38
- package/src/session/SessionSystemBuilder.ts +0 -262
- package/src/session/recorder/SessionRecorderHistoryStore.ts +0 -256
- package/src/session/runtime/SessionPromptRuntime.ts +0 -518
- package/src/session/services/SessionStateService.ts +0 -628
- package/src/session/services/SessionTurnService.ts +0 -368
- package/src/session/services/SessionViewService.ts +0 -335
- package/src/session/storage/Persistence.ts +0 -137
- package/src/types/agent/AgentRuntimeAssembly.ts +0 -74
- package/src/types/runtime/agent/AgentContext.ts +0 -387
- package/src/types/session/SessionComposerOptions.ts +0 -107
- package/src/types/session/SessionQueueCommand.ts +0 -78
- /package/bin/{agent/local → config}/ProjectSetup.d.ts +0 -0
- /package/bin/{agent/remote → remote}/RemoteTransport.js +0 -0
- /package/bin/session/{recorder → messages}/JsonlSessionMessageStore.d.ts +0 -0
- /package/bin/session/{recorder → messages}/JsonlSessionMessageStore.js +0 -0
- /package/src/{agent/local → config}/ProjectSetup.ts +0 -0
- /package/src/session/{recorder → messages}/JsonlSessionMessageStore.ts +0 -0
package/README.md
CHANGED
|
@@ -75,32 +75,31 @@ src/
|
|
|
75
75
|
|
|
76
76
|
- `src/agent/`
|
|
77
77
|
- SDK facade 层
|
|
78
|
-
- `
|
|
79
|
-
- `
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
- `Agent.ts` 负责本地 Agent 实例装配
|
|
79
|
+
- `AgentSessions.ts` 负责 Session 集合生命周期
|
|
80
|
+
|
|
81
|
+
- `src/session/`
|
|
82
|
+
- `Session.ts` 是公开 facade 与 Session 对象装配入口
|
|
83
|
+
- `SessionState.ts` 管理配置与 metadata
|
|
84
|
+
- `SessionTurn.ts` 管理输入队列和 Turn 生命周期
|
|
85
|
+
- `SessionMessages.ts` 是 canonical Message 唯一事实源
|
|
86
|
+
- `DefaultSessionComposer.ts` 负责 system/history/tools 与压缩计划定制
|
|
87
|
+
- `messages/` 放 JSONL Store、Assistant writer、Message codec 与 compaction
|
|
82
88
|
|
|
83
89
|
- `src/executor/`
|
|
84
90
|
- 内部执行内核
|
|
85
|
-
- `
|
|
86
|
-
-
|
|
87
|
-
- `Executor.prepareExecuteInput()` 串起四类 Composer,`Executor.runCoreEngine()` 负责进入模型 tool loop
|
|
88
|
-
- 负责 history、system、context、CoreEngine、增量输出与消息持久化
|
|
91
|
+
- `Executor` 只负责单轮 LLM/Tool Loop、Step 状态和上下文恢复
|
|
92
|
+
- 不持有 History Store,不负责 Message 或 metadata 持久化
|
|
89
93
|
|
|
90
94
|
- `src/plugin/`
|
|
91
95
|
- 插件框架与内建插件
|
|
92
96
|
- `core/` 负责注册、启用态、hook 调度、本地 action
|
|
93
|
-
- `builtins/` 放 `auth`、`chat`、`contact`、`memory`、`shell`、`skill`、`task`、`web`、`
|
|
97
|
+
- `builtins/` 放 `auth`、`chat`、`contact`、`memory`、`shell`、`skill`、`task`、`web`、`sound`、`workboard` 等内建插件
|
|
94
98
|
- `types/` 放插件公共协议类型
|
|
95
99
|
|
|
96
|
-
- `src/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
- `sandbox/` 放命令执行隔离与沙箱协议
|
|
100
|
-
- `control/` 放 runtime 控制面内部协议与处理器
|
|
101
|
-
- `src/rpc/` 放 Agent 本机 RPC runtime;HTTP gateway 由 downcity CLI 基于 RPC 转发提供
|
|
102
|
-
- 模型实例解析不在 `agent` 包内完成,而由宿主先创建 `LanguageModel`,再通过 `new Agent({ model })` 或 `session.set({ model })` 注入
|
|
103
|
-
- `model` 也可以接收 City City 返回的 `CityModel`,Agent 会在内部适配成 AI SDK `LanguageModel`
|
|
100
|
+
- `src/remote/transports/` 放 HTTP、RPC transport 及其内部客户端;RPC Server 与 HTTP gateway 由上游宿主管理
|
|
101
|
+
- Agent 与 Session 都持有宿主传入的 `AgentModel` 实例;`AgentModel` 可以是 AI SDK `LanguageModel` 或 City 返回的 `CityModel`
|
|
102
|
+
- Session 可通过 `session.set({ model })` 覆盖,执行时固定按 Session 模型、Agent 模型的顺序解析,并在 LLM 调用边界转换为 `LanguageModel`
|
|
104
103
|
|
|
105
104
|
- `src/types/`
|
|
106
105
|
- 跨模块、跨包共享协议类型
|
|
@@ -117,13 +116,15 @@ src/
|
|
|
117
116
|
`@downcity/agent` 的核心是一条单 Agent 执行链:
|
|
118
117
|
|
|
119
118
|
```text
|
|
120
|
-
入口协议 -> Agent facade ->
|
|
119
|
+
入口协议 -> Agent facade -> Session / Plugin -> Executor -> Runtime 子系统 -> History / Reply
|
|
121
120
|
```
|
|
122
121
|
|
|
123
122
|
其中:
|
|
124
123
|
|
|
125
|
-
- `agent
|
|
126
|
-
- `
|
|
124
|
+
- `agent` 承载本地 Agent 核心运行时,`remote` 承载独立的远程 SDK 客户端
|
|
125
|
+
- `config` 承载项目初始化等宿主集成能力,不进入 Agent 核心生命周期
|
|
126
|
+
- `Agent` facade 是实例级装配中心,也是 env、instruction、model、tools、plugins 与 sessions 的唯一状态所有者
|
|
127
|
+
- `AgentContext` 只向 Plugin 与宿主投影受限运行时能力,不保存完整项目 config 或第二份 Agent 状态
|
|
127
128
|
- `session / executor / plugin` 是三大核心分层
|
|
128
129
|
- `runtime` 是 control / sandbox / host 这类实现细节的统一容器
|
|
129
130
|
- `types / utils` 提供横向公共支撑
|
|
@@ -1,54 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Agent
|
|
2
|
+
* Agent:本地 Agent 核心入口与 facade。
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
5
|
* - 对外暴露 `Agent` 这一唯一的本地实例类。
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
6
|
+
* - Agent 直接持有自身状态与长期运行时对象,避免额外 Assembly 复制同一批字段。
|
|
7
|
+
* - Session 集合由 `AgentSessions` 管理;长期运行状态由 `AgentState` 管理。
|
|
8
8
|
*/
|
|
9
9
|
import type { Tool } from "ai";
|
|
10
|
-
import type {
|
|
11
|
-
import
|
|
12
|
-
import type {
|
|
13
|
-
import type { AgentOptions } from "../../types/agent/AgentOptions.js";
|
|
14
|
-
import type { AgentSessions as AgentSessionsApi } from "../../types/agent/SessionActor.js";
|
|
10
|
+
import type { AgentModel } from "../agent/AgentModel.js";
|
|
11
|
+
import { AgentContext } from "../agent/AgentContext.js";
|
|
12
|
+
import type { AgentOptions } from "../types/agent/AgentOptions.js";
|
|
15
13
|
import type { Shell } from "@downcity/shell";
|
|
16
|
-
import { Logger } from "
|
|
14
|
+
import { Logger } from "../utils/logger/Logger.js";
|
|
15
|
+
import { AgentSessions } from "../agent/AgentSessions.js";
|
|
16
|
+
import { PluginRegistry } from "../plugin/core/PluginRegistry.js";
|
|
17
17
|
/**
|
|
18
18
|
* SDK 本地 Agent。
|
|
19
19
|
*/
|
|
20
20
|
export declare class Agent {
|
|
21
|
+
/** 当前 Agent 的稳定标识,用于区分 Session 存储目录与运行时归属。 */
|
|
21
22
|
readonly id: string;
|
|
23
|
+
/** 当前 Agent 绑定的项目根目录绝对路径。 */
|
|
22
24
|
readonly path: string;
|
|
25
|
+
/** 当前 Agent 向所有 Session 提供的工具集合。 */
|
|
23
26
|
readonly tools: Record<string, Tool>;
|
|
24
|
-
|
|
25
|
-
readonly
|
|
27
|
+
/** 当前 Agent 已装配的 Plugin 调用与注册入口。 */
|
|
28
|
+
readonly plugins: PluginRegistry;
|
|
29
|
+
/** 当前 Agent 的本地 Session 创建、恢复、查询与归档入口。 */
|
|
30
|
+
readonly sessions: AgentSessions;
|
|
31
|
+
/**
|
|
32
|
+
* 当前 Agent 持有的默认运行时模型实例。
|
|
33
|
+
*
|
|
34
|
+
* 关键点(中文)
|
|
35
|
+
* - Agent 只持有调用方传入的实例,不负责模型选择、持久化或恢复。
|
|
36
|
+
* - Session 未设置自己的模型时,执行会回退使用该实例。
|
|
37
|
+
*/
|
|
38
|
+
readonly model?: AgentModel;
|
|
39
|
+
/** 当前 Agent 独享的运行日志器。 */
|
|
26
40
|
private readonly logger;
|
|
27
|
-
|
|
28
|
-
private readonly
|
|
41
|
+
/** 提供给 Plugin、Session 与宿主集成层共享的 Agent 执行上下文。 */
|
|
42
|
+
private readonly context;
|
|
43
|
+
/** 当前 Agent configured env 的可变共享对象。 */
|
|
29
44
|
private readonly env;
|
|
30
|
-
|
|
31
|
-
private readonly default_model_id?;
|
|
32
|
-
private readonly resolve_model?;
|
|
45
|
+
/** 调用方提供的自定义 Session 类;省略时使用 SDK 默认实现。 */
|
|
33
46
|
private readonly SessionClass;
|
|
34
|
-
|
|
47
|
+
/** 当前 Agent 的长期运行状态与生命周期。 */
|
|
48
|
+
private readonly state;
|
|
49
|
+
/** 当前 Agent 可选的内建 Shell 实例。 */
|
|
35
50
|
private readonly shell?;
|
|
36
|
-
|
|
51
|
+
/** 当前 Agent configured instruction 的可变有序集合。 */
|
|
37
52
|
private instruction;
|
|
38
53
|
constructor(options: AgentOptions);
|
|
39
54
|
/**
|
|
40
|
-
* 等待 Agent
|
|
55
|
+
* 等待 Agent 持有的长期运行时启动完成。
|
|
41
56
|
*
|
|
42
57
|
* 关键点(中文)
|
|
43
58
|
* - Agent 构造完成即开始启动 plugin lifecycle 与 ActionSchedule。
|
|
44
|
-
* -
|
|
59
|
+
* - 调用方在需要确认运行时就绪时使用,例如启动后立刻读取 plugin 状态。
|
|
45
60
|
*/
|
|
46
61
|
ready(): Promise<void>;
|
|
47
62
|
/**
|
|
48
|
-
* 释放当前 Agent
|
|
63
|
+
* 释放当前 Agent 持有的长期运行时对象。
|
|
49
64
|
*
|
|
50
65
|
* 关键点(中文)
|
|
51
|
-
* - 关闭 plugin lifecycle、ActionSchedule、shell
|
|
66
|
+
* - 关闭 plugin lifecycle、ActionSchedule、shell 等 Agent 自有资源。
|
|
52
67
|
* - 不负责任何 transport(RPC / HTTP);transport 由 `@downcity/server` 自行管理。
|
|
53
68
|
*/
|
|
54
69
|
dispose(): Promise<void>;
|
|
@@ -84,10 +99,6 @@ export declare class Agent {
|
|
|
84
99
|
* 原地应用一次 env patch,不触发重复广播。
|
|
85
100
|
*/
|
|
86
101
|
private apply_env_patch;
|
|
87
|
-
/**
|
|
88
|
-
* 返回当前项目根目录解析后的配置快照。
|
|
89
|
-
*/
|
|
90
|
-
getConfig(): DowncityConfig;
|
|
91
102
|
/**
|
|
92
103
|
* 返回当前 agent 绑定的统一日志器。
|
|
93
104
|
*/
|
|
@@ -100,6 +111,5 @@ export declare class Agent {
|
|
|
100
111
|
* 返回当前 agent 挂载的 Shell。
|
|
101
112
|
*/
|
|
102
113
|
getShell(): Shell | undefined;
|
|
103
|
-
private create_sessions;
|
|
104
114
|
}
|
|
105
115
|
//# sourceMappingURL=Agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Agent.d.ts","sourceRoot":"","sources":["../../src/agent/Agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,KAAK,EAAE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;OAMG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;;;OAMG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAM9C;;;;;;OAMG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIhC;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI;IAQ7D;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,IAAI;IAKhE;;OAEG;IACH,OAAO,CAAC,eAAe;IAevB;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,UAAU,IAAI,YAAY;IAI1B;;OAEG;IACH,QAAQ,IAAI,KAAK,GAAG,SAAS;CAG9B"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent:本地 Agent 核心入口与 facade。
|
|
3
|
+
*
|
|
4
|
+
* 职责说明(中文)
|
|
5
|
+
* - 对外暴露 `Agent` 这一唯一的本地实例类。
|
|
6
|
+
* - Agent 直接持有自身状态与长期运行时对象,避免额外 Assembly 复制同一批字段。
|
|
7
|
+
* - Session 集合由 `AgentSessions` 管理;长期运行状态由 `AgentState` 管理。
|
|
8
|
+
*/
|
|
9
|
+
import { AgentContext } from "../agent/AgentContext.js";
|
|
10
|
+
import { Logger } from "../utils/logger/Logger.js";
|
|
11
|
+
import { resolve_agent_env } from "../config/AgentEnv.js";
|
|
12
|
+
import { normalizeInstructionInput } from "../agent/AgentInstructions.js";
|
|
13
|
+
import { AgentSessions } from "../agent/AgentSessions.js";
|
|
14
|
+
import { AgentState } from "../agent/AgentState.js";
|
|
15
|
+
import { generateId } from "../utils/Id.js";
|
|
16
|
+
import { PluginRegistry } from "../plugin/core/PluginRegistry.js";
|
|
17
|
+
/**
|
|
18
|
+
* SDK 本地 Agent。
|
|
19
|
+
*/
|
|
20
|
+
export class Agent {
|
|
21
|
+
/** 当前 Agent 的稳定标识,用于区分 Session 存储目录与运行时归属。 */
|
|
22
|
+
id;
|
|
23
|
+
/** 当前 Agent 绑定的项目根目录绝对路径。 */
|
|
24
|
+
path;
|
|
25
|
+
/** 当前 Agent 向所有 Session 提供的工具集合。 */
|
|
26
|
+
tools;
|
|
27
|
+
/** 当前 Agent 已装配的 Plugin 调用与注册入口。 */
|
|
28
|
+
plugins;
|
|
29
|
+
/** 当前 Agent 的本地 Session 创建、恢复、查询与归档入口。 */
|
|
30
|
+
sessions;
|
|
31
|
+
/**
|
|
32
|
+
* 当前 Agent 持有的默认运行时模型实例。
|
|
33
|
+
*
|
|
34
|
+
* 关键点(中文)
|
|
35
|
+
* - Agent 只持有调用方传入的实例,不负责模型选择、持久化或恢复。
|
|
36
|
+
* - Session 未设置自己的模型时,执行会回退使用该实例。
|
|
37
|
+
*/
|
|
38
|
+
model;
|
|
39
|
+
/** 当前 Agent 独享的运行日志器。 */
|
|
40
|
+
logger;
|
|
41
|
+
/** 提供给 Plugin、Session 与宿主集成层共享的 Agent 执行上下文。 */
|
|
42
|
+
context;
|
|
43
|
+
/** 当前 Agent configured env 的可变共享对象。 */
|
|
44
|
+
env;
|
|
45
|
+
/** 调用方提供的自定义 Session 类;省略时使用 SDK 默认实现。 */
|
|
46
|
+
SessionClass;
|
|
47
|
+
/** 当前 Agent 的长期运行状态与生命周期。 */
|
|
48
|
+
state;
|
|
49
|
+
/** 当前 Agent 可选的内建 Shell 实例。 */
|
|
50
|
+
shell;
|
|
51
|
+
/** 当前 Agent configured instruction 的可变有序集合。 */
|
|
52
|
+
instruction;
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.id = String(options.id || "").trim();
|
|
55
|
+
this.path = String(options.path || "").trim();
|
|
56
|
+
if (!this.id)
|
|
57
|
+
throw new Error("Agent requires a non-empty id");
|
|
58
|
+
if (!this.path)
|
|
59
|
+
throw new Error("Agent requires a non-empty path");
|
|
60
|
+
this.SessionClass = options.Session;
|
|
61
|
+
this.model = options.model;
|
|
62
|
+
this.tools = options.tools && typeof options.tools === "object"
|
|
63
|
+
? { ...options.tools }
|
|
64
|
+
: {};
|
|
65
|
+
this.logger = new Logger();
|
|
66
|
+
this.logger.bindProjectRoot(this.path);
|
|
67
|
+
this.env = resolve_agent_env(this.path, options.env);
|
|
68
|
+
this.instruction = normalizeInstructionInput(options.instruction);
|
|
69
|
+
this.shell = options.shell;
|
|
70
|
+
this.plugins = new PluginRegistry(options.plugins || []);
|
|
71
|
+
if (this.shell) {
|
|
72
|
+
this.shell.configure({
|
|
73
|
+
root_path: this.path,
|
|
74
|
+
env: this.env,
|
|
75
|
+
agent_id: this.id,
|
|
76
|
+
logger: this.logger,
|
|
77
|
+
});
|
|
78
|
+
Object.assign(this.tools, this.shell.tools);
|
|
79
|
+
}
|
|
80
|
+
this.sessions = new AgentSessions({
|
|
81
|
+
agent_id: this.id,
|
|
82
|
+
project_root: this.path,
|
|
83
|
+
tools: this.tools,
|
|
84
|
+
logger: this.logger,
|
|
85
|
+
get_instruction: () => this.instruction,
|
|
86
|
+
get_agent_env: () => this.getEnv(),
|
|
87
|
+
get_agent_plugins: () => this.plugins.execution_view(),
|
|
88
|
+
ensure_agent_ready: async () => {
|
|
89
|
+
await this.ready();
|
|
90
|
+
},
|
|
91
|
+
get_agent_model: () => this.model,
|
|
92
|
+
SessionClass: this.SessionClass,
|
|
93
|
+
});
|
|
94
|
+
this.context = new AgentContext({
|
|
95
|
+
agent_id: this.id,
|
|
96
|
+
rootPath: this.path,
|
|
97
|
+
logger: this.logger,
|
|
98
|
+
get_env: () => this.env,
|
|
99
|
+
get_systems: () => this.instruction,
|
|
100
|
+
sessions: this.sessions,
|
|
101
|
+
plugins: this.plugins,
|
|
102
|
+
});
|
|
103
|
+
// 关键点(中文):装配完成后创建唯一状态对象,并立即启动长期运行时。
|
|
104
|
+
this.state = new AgentState({
|
|
105
|
+
context: this.context,
|
|
106
|
+
plugins: this.plugins,
|
|
107
|
+
sessions: this.sessions,
|
|
108
|
+
tools: this.tools,
|
|
109
|
+
shell: this.shell,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 等待 Agent 持有的长期运行时启动完成。
|
|
114
|
+
*
|
|
115
|
+
* 关键点(中文)
|
|
116
|
+
* - Agent 构造完成即开始启动 plugin lifecycle 与 ActionSchedule。
|
|
117
|
+
* - 调用方在需要确认运行时就绪时使用,例如启动后立刻读取 plugin 状态。
|
|
118
|
+
*/
|
|
119
|
+
async ready() {
|
|
120
|
+
await this.state.ready();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 释放当前 Agent 持有的长期运行时对象。
|
|
124
|
+
*
|
|
125
|
+
* 关键点(中文)
|
|
126
|
+
* - 关闭 plugin lifecycle、ActionSchedule、shell 等 Agent 自有资源。
|
|
127
|
+
* - 不负责任何 transport(RPC / HTTP);transport 由 `@downcity/server` 自行管理。
|
|
128
|
+
*/
|
|
129
|
+
async dispose() {
|
|
130
|
+
await this.state.dispose();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 更新当前 SDK Agent 的静态基础指令。
|
|
134
|
+
*/
|
|
135
|
+
setInstruction(input) {
|
|
136
|
+
const next_instruction = normalizeInstructionInput(input);
|
|
137
|
+
this.instruction.splice(0, this.instruction.length, ...next_instruction);
|
|
138
|
+
this.sessions.broadcast_instruction(this.instruction, generateId());
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 返回当前 agent env 的浅拷贝快照。
|
|
142
|
+
*
|
|
143
|
+
* 关键点(中文)
|
|
144
|
+
* - 返回的是拷贝,调用方修改它不会影响 agent 真实状态。
|
|
145
|
+
* - 想改 env 请使用 `setEnv` / `patchEnv`。
|
|
146
|
+
*/
|
|
147
|
+
getEnv() {
|
|
148
|
+
return { ...this.env };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 整体覆盖 agent env。
|
|
152
|
+
*
|
|
153
|
+
* 关键点(中文)
|
|
154
|
+
* - 直接清空当前共享 env 对象,再写入新值,保证 plugin / runtime / shell 看到的是同一引用。
|
|
155
|
+
* - 仅写入字符串值,`null` / `undefined` 表示删除该 key。
|
|
156
|
+
*/
|
|
157
|
+
setEnv(next) {
|
|
158
|
+
for (const key of Object.keys(this.env)) {
|
|
159
|
+
delete this.env[key];
|
|
160
|
+
}
|
|
161
|
+
this.apply_env_patch(next);
|
|
162
|
+
this.sessions.broadcast_env(this.env, generateId());
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 增量合并 agent env。
|
|
166
|
+
*
|
|
167
|
+
* 关键点(中文)
|
|
168
|
+
* - `null` / `undefined` 表示删除该 key;其他值会强制转字符串后写入。
|
|
169
|
+
* - configured env 原地更新;已有 Session 在下一 step 检查点提交 effective env。
|
|
170
|
+
*/
|
|
171
|
+
patchEnv(patch) {
|
|
172
|
+
this.apply_env_patch(patch);
|
|
173
|
+
this.sessions.broadcast_env(this.env, generateId());
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 原地应用一次 env patch,不触发重复广播。
|
|
177
|
+
*/
|
|
178
|
+
apply_env_patch(patch) {
|
|
179
|
+
if (!patch || typeof patch !== "object")
|
|
180
|
+
return;
|
|
181
|
+
for (const [raw_key, raw_value] of Object.entries(patch)) {
|
|
182
|
+
const key = String(raw_key || "").trim();
|
|
183
|
+
if (!key)
|
|
184
|
+
continue;
|
|
185
|
+
if (raw_value === null || raw_value === undefined) {
|
|
186
|
+
delete this.env[key];
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
this.env[key] = String(raw_value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 返回当前 agent 绑定的统一日志器。
|
|
194
|
+
*/
|
|
195
|
+
getLogger() {
|
|
196
|
+
return this.logger;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 返回当前 agent context。
|
|
200
|
+
*/
|
|
201
|
+
getContext() {
|
|
202
|
+
return this.context;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 返回当前 agent 挂载的 Shell。
|
|
206
|
+
*/
|
|
207
|
+
getShell() {
|
|
208
|
+
return this.shell;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=Agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Agent.js","sourceRoot":"","sources":["../../src/agent/Agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE;;GAEG;AACH,MAAM,OAAO,KAAK;IAChB,8CAA8C;IACrC,EAAE,CAAS;IAEpB,6BAA6B;IACpB,IAAI,CAAS;IAEtB,oCAAoC;IAC3B,KAAK,CAAuB;IAErC,oCAAoC;IAC3B,OAAO,CAAiB;IAEjC,0CAA0C;IACjC,QAAQ,CAAgB;IAEjC;;;;;;OAMG;IACM,KAAK,CAAc;IAE5B,yBAAyB;IACR,MAAM,CAAS;IAEhC,gDAAgD;IAC/B,OAAO,CAAe;IAEvC,uCAAuC;IACtB,GAAG,CA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责说明(中文)
|
|
5
|
+
* - 同一 Agent 实例全程共享同一个 Context。
|
|
6
|
+
* - 向 Plugin、Session 与宿主投影当前 Agent 的稳定运行时能力。
|
|
7
|
+
* - Context 不复制 Agent 状态,env 与 systems 始终从唯一状态源读取。
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentSessions } from "../agent/AgentSessions.js";
|
|
10
|
+
import type { AgentPlugins } from "../types/plugin/PluginRuntime.js";
|
|
11
|
+
import type { Logger } from "../utils/logger/Logger.js";
|
|
12
|
+
/**
|
|
13
|
+
* AgentContext 构造参数。
|
|
14
|
+
*/
|
|
15
|
+
interface AgentContextOptions {
|
|
16
|
+
/** 当前 Agent 稳定标识。 */
|
|
17
|
+
agent_id: string;
|
|
18
|
+
/** 当前项目根目录。 */
|
|
19
|
+
rootPath: string;
|
|
20
|
+
/** 当前 Agent 统一日志器。 */
|
|
21
|
+
logger: Logger;
|
|
22
|
+
/** 读取当前 Agent configured env。 */
|
|
23
|
+
get_env: () => Readonly<Record<string, string>>;
|
|
24
|
+
/** 读取当前 Agent configured systems。 */
|
|
25
|
+
get_systems: () => readonly string[];
|
|
26
|
+
/** 当前 Agent 直接持有的 Session 集合。 */
|
|
27
|
+
sessions: AgentSessions;
|
|
28
|
+
/** 当前 Agent 唯一的 Plugin 调用入口。 */
|
|
29
|
+
plugins: AgentPlugins;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 本地 Agent 的统一执行上下文。
|
|
33
|
+
*/
|
|
34
|
+
export declare class AgentContext {
|
|
35
|
+
/** 当前 Agent 稳定标识。 */
|
|
36
|
+
readonly agent_id: string;
|
|
37
|
+
/** 当前项目根目录。 */
|
|
38
|
+
readonly rootPath: string;
|
|
39
|
+
/** 当前 Agent 统一日志器。 */
|
|
40
|
+
readonly logger: Logger;
|
|
41
|
+
/** 当前 Agent configured env 读取器。 */
|
|
42
|
+
private readonly get_env;
|
|
43
|
+
/** 当前 Agent configured systems 读取器。 */
|
|
44
|
+
private readonly get_systems;
|
|
45
|
+
/** 当前 Agent 直接持有的 Session 集合。 */
|
|
46
|
+
readonly sessions: AgentSessions;
|
|
47
|
+
/** 当前 Agent 唯一的 Plugin 调用入口。 */
|
|
48
|
+
readonly plugins: AgentPlugins;
|
|
49
|
+
constructor(options: AgentContextOptions);
|
|
50
|
+
/**
|
|
51
|
+
* 读取 Agent 已配置的 env。
|
|
52
|
+
*
|
|
53
|
+
* 关键点(中文)
|
|
54
|
+
* - Session step 的 effective env 由 Plugin action 参数 `run_context.agentEnv` 显式提供。
|
|
55
|
+
* - 该 getter 不根据异步调用链隐式切换结果。
|
|
56
|
+
*/
|
|
57
|
+
get env(): Readonly<Record<string, string>>;
|
|
58
|
+
/**
|
|
59
|
+
* 读取 Agent 已配置的 instruction。
|
|
60
|
+
*/
|
|
61
|
+
get systems(): readonly string[];
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=AgentContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentContext.d.ts","sourceRoot":"","sources":["../../src/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;GAEG;AACH,UAAU,mBAAmB;IAC3B,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IAEjB,eAAe;IACf,QAAQ,EAAE,MAAM,CAAC;IAEjB,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IAEf,iCAAiC;IACjC,OAAO,EAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAEhD,qCAAqC;IACrC,WAAW,EAAE,MAAM,SAAS,MAAM,EAAE,CAAC;IAErC,iCAAiC;IACjC,QAAQ,EAAE,aAAa,CAAC;IAExB,gCAAgC;IAChC,OAAO,EAAE,YAAY,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,qBAAqB;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,eAAe;IACf,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,sBAAsB;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,mCAAmC;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IAEzD,uCAAuC;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqC;IAEjE,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IAEjC,gCAAgC;IAChC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;gBAEnB,OAAO,EAAE,mBAAmB;IAUxC;;;;;;OAMG;IACH,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAE1C;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,SAAS,MAAM,EAAE,CAE/B;CACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentContext:本地 Agent 的统一执行上下文。
|
|
3
|
+
*
|
|
4
|
+
* 职责说明(中文)
|
|
5
|
+
* - 同一 Agent 实例全程共享同一个 Context。
|
|
6
|
+
* - 向 Plugin、Session 与宿主投影当前 Agent 的稳定运行时能力。
|
|
7
|
+
* - Context 不复制 Agent 状态,env 与 systems 始终从唯一状态源读取。
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 本地 Agent 的统一执行上下文。
|
|
11
|
+
*/
|
|
12
|
+
export class AgentContext {
|
|
13
|
+
/** 当前 Agent 稳定标识。 */
|
|
14
|
+
agent_id;
|
|
15
|
+
/** 当前项目根目录。 */
|
|
16
|
+
rootPath;
|
|
17
|
+
/** 当前 Agent 统一日志器。 */
|
|
18
|
+
logger;
|
|
19
|
+
/** 当前 Agent configured env 读取器。 */
|
|
20
|
+
get_env;
|
|
21
|
+
/** 当前 Agent configured systems 读取器。 */
|
|
22
|
+
get_systems;
|
|
23
|
+
/** 当前 Agent 直接持有的 Session 集合。 */
|
|
24
|
+
sessions;
|
|
25
|
+
/** 当前 Agent 唯一的 Plugin 调用入口。 */
|
|
26
|
+
plugins;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.agent_id = options.agent_id;
|
|
29
|
+
this.rootPath = options.rootPath;
|
|
30
|
+
this.logger = options.logger;
|
|
31
|
+
this.get_env = options.get_env;
|
|
32
|
+
this.get_systems = options.get_systems;
|
|
33
|
+
this.sessions = options.sessions;
|
|
34
|
+
this.plugins = options.plugins;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 读取 Agent 已配置的 env。
|
|
38
|
+
*
|
|
39
|
+
* 关键点(中文)
|
|
40
|
+
* - Session step 的 effective env 由 Plugin action 参数 `run_context.agentEnv` 显式提供。
|
|
41
|
+
* - 该 getter 不根据异步调用链隐式切换结果。
|
|
42
|
+
*/
|
|
43
|
+
get env() {
|
|
44
|
+
return this.get_env();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 读取 Agent 已配置的 instruction。
|
|
48
|
+
*/
|
|
49
|
+
get systems() {
|
|
50
|
+
return this.get_systems();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=AgentContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentContext.js","sourceRoot":"","sources":["../../src/agent/AgentContext.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgCH;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB,qBAAqB;IACZ,QAAQ,CAAS;IAE1B,eAAe;IACN,QAAQ,CAAS;IAE1B,sBAAsB;IACb,MAAM,CAAS;IAExB,mCAAmC;IAClB,OAAO,CAAiC;IAEzD,uCAAuC;IACtB,WAAW,CAAqC;IAEjE,iCAAiC;IACxB,QAAQ,CAAgB;IAEjC,gCAAgC;IACvB,OAAO,CAAe;IAE/B,YAAY,OAA4B;QACtC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -6,12 +6,7 @@
|
|
|
6
6
|
* - instruction 永远在 core 前面;core 不会被调用方 instruction 替代。
|
|
7
7
|
* - 不读取 session、plugin 或 runtime 状态,保持为纯函数。
|
|
8
8
|
*/
|
|
9
|
-
import type {
|
|
10
|
-
import type { AgentSessionSystemBlock } from "../../types/agent/SessionTypes.js";
|
|
11
|
-
/**
|
|
12
|
-
* 创建 SDK 场景的最小 fallback 配置。
|
|
13
|
-
*/
|
|
14
|
-
export declare function createFallbackSdkConfig(agent_id: string): DowncityConfig;
|
|
9
|
+
import type { AgentSessionSystemBlock } from "../types/agent/SessionTypes.js";
|
|
15
10
|
/**
|
|
16
11
|
* 归一化调用方传入的静态 instruction。
|
|
17
12
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentInstructions.d.ts","sourceRoot":"","sources":["../../src/agent/AgentInstructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAG7E;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GACnC,MAAM,EAAE,CASV;AAUD;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,MAAM,EAAE,EACrB,YAAY,EAAE,MAAM,GACnB,uBAAuB,EAAE,CAc3B"}
|
|
@@ -6,16 +6,7 @@
|
|
|
6
6
|
* - instruction 永远在 core 前面;core 不会被调用方 instruction 替代。
|
|
7
7
|
* - 不读取 session、plugin 或 runtime 状态,保持为纯函数。
|
|
8
8
|
*/
|
|
9
|
-
import { DEFAULT_SHIP_PROMPTS } from "
|
|
10
|
-
/**
|
|
11
|
-
* 创建 SDK 场景的最小 fallback 配置。
|
|
12
|
-
*/
|
|
13
|
-
export function createFallbackSdkConfig(agent_id) {
|
|
14
|
-
return {
|
|
15
|
-
id: agent_id,
|
|
16
|
-
version: "0.0.0",
|
|
17
|
-
};
|
|
18
|
-
}
|
|
9
|
+
import { DEFAULT_SHIP_PROMPTS } from "../executor/composer/system/default/SystemDomain.js";
|
|
19
10
|
/**
|
|
20
11
|
* 归一化调用方传入的静态 instruction。
|
|
21
12
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentInstructions.js","sourceRoot":"","sources":["../../src/agent/AgentInstructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAEzF;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAoC;IAEpC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAChC,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ;YAC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|
5
|
-
* - Agent
|
|
5
|
+
* - Agent 与 Session 对外统一接收 AgentModel,executor 内部只处理 AI SDK LanguageModel。
|
|
6
6
|
* - CityModel 保留模型目录信息;运行时连接信息通过隐藏协议提供。
|
|
7
7
|
* - 这里直接创建 OpenAI-compatible LanguageModel,不再保留旧的 text/stream 反向适配。
|
|
8
8
|
* - 这里不依赖 @downcity/city,只依赖 @downcity/type 的共享协议。
|
|
@@ -27,4 +27,4 @@ export declare function read_agent_model_context_window(model: AgentModel | unde
|
|
|
27
27
|
* 从 Agent 模型输入推导展示标签。
|
|
28
28
|
*/
|
|
29
29
|
export declare function inferAgentModelLabel(model: AgentModel | undefined): string | undefined;
|
|
30
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=AgentModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentModel.d.ts","sourceRoot":"","sources":["../../src/agent/AgentModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAKxC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,SAAS,CAAC;AAenD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CASpE;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,UAAU,GAAG,SAAS,GAC5B,MAAM,GAAG,SAAS,CAMpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAqBtF"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AgentModel:Agent 与 Session 统一使用的运行时模型协议。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - Agent
|
|
5
|
+
* - Agent 与 Session 对外统一接收 AgentModel,executor 内部只处理 AI SDK LanguageModel。
|
|
6
6
|
* - CityModel 保留模型目录信息;运行时连接信息通过隐藏协议提供。
|
|
7
7
|
* - 这里直接创建 OpenAI-compatible LanguageModel,不再保留旧的 text/stream 反向适配。
|
|
8
8
|
* - 这里不依赖 @downcity/city,只依赖 @downcity/type 的共享协议。
|
|
9
9
|
*/
|
|
10
10
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
11
11
|
import { CITY_MODEL_INVOKER, isCityModel, } from "@downcity/type";
|
|
12
|
+
/** 已完成转换的 CityModel 与 LanguageModel 对应关系。 */
|
|
13
|
+
const normalized_models = new WeakMap();
|
|
12
14
|
/**
|
|
13
15
|
* 将 CityModel 的 hidden connection 转换为 AI SDK LanguageModel。
|
|
14
16
|
*/
|
|
@@ -26,7 +28,12 @@ function cityModelToLanguageModel(model) {
|
|
|
26
28
|
*/
|
|
27
29
|
export function normalizeAgentModel(model) {
|
|
28
30
|
if (isCityModel(model)) {
|
|
29
|
-
|
|
31
|
+
const cached = normalized_models.get(model);
|
|
32
|
+
if (cached)
|
|
33
|
+
return cached;
|
|
34
|
+
const normalized = cityModelToLanguageModel(model);
|
|
35
|
+
normalized_models.set(model, normalized);
|
|
36
|
+
return normalized;
|
|
30
37
|
}
|
|
31
38
|
return model;
|
|
32
39
|
}
|
|
@@ -71,4 +78,4 @@ export function inferAgentModelLabel(model) {
|
|
|
71
78
|
: "";
|
|
72
79
|
return constructorName || "configured-model";
|
|
73
80
|
}
|
|
74
|
-
//# sourceMappingURL=
|
|
81
|
+
//# sourceMappingURL=AgentModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentModel.js","sourceRoot":"","sources":["../../src/agent/AgentModel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAA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