@downcity/agent 1.1.337 → 1.1.399
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 +31 -15
- package/bin/agent/Agent.d.ts +42 -91
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +115 -200
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentModel.d.ts +8 -8
- package/bin/agent/AgentModel.d.ts.map +1 -1
- package/bin/agent/AgentModel.js +5 -5
- package/bin/agent/AgentModel.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +42 -28
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +80 -44
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/agent/WorkspaceEntry.d.ts +82 -0
- package/bin/agent/WorkspaceEntry.d.ts.map +1 -0
- package/bin/agent/WorkspaceEntry.js +246 -0
- package/bin/agent/WorkspaceEntry.js.map +1 -0
- package/bin/agent/index.d.ts +5 -0
- package/bin/agent/index.d.ts.map +1 -0
- package/bin/agent/index.js +5 -0
- package/bin/agent/index.js.map +1 -0
- package/bin/city/host/CityHostRegistry.d.ts +44 -0
- package/bin/city/host/CityHostRegistry.d.ts.map +1 -0
- package/bin/city/host/CityHostRegistry.js +225 -0
- package/bin/city/host/CityHostRegistry.js.map +1 -0
- package/bin/city/index.d.ts +22 -0
- package/bin/city/index.d.ts.map +1 -0
- package/bin/city/index.js +10 -0
- package/bin/city/index.js.map +1 -0
- package/bin/city/runtime/City.d.ts +99 -0
- package/bin/city/runtime/City.d.ts.map +1 -0
- package/bin/city/runtime/City.js +376 -0
- package/bin/city/runtime/City.js.map +1 -0
- package/bin/city/transport/SerializedTransport.d.ts +30 -0
- package/bin/city/transport/SerializedTransport.d.ts.map +1 -0
- package/bin/city/transport/SerializedTransport.js +57 -0
- package/bin/city/transport/SerializedTransport.js.map +1 -0
- package/bin/city/transport/http/AgentHTTP.d.ts +66 -0
- package/bin/city/transport/http/AgentHTTP.d.ts.map +1 -0
- package/bin/city/transport/http/AgentHTTP.js +142 -0
- package/bin/city/transport/http/AgentHTTP.js.map +1 -0
- package/bin/city/transport/http/CityHTTP.d.ts +44 -0
- package/bin/city/transport/http/CityHTTP.d.ts.map +1 -0
- package/bin/city/transport/http/CityHTTP.js +171 -0
- package/bin/city/transport/http/CityHTTP.js.map +1 -0
- package/bin/city/transport/http/NodeHttpAdapter.d.ts +27 -0
- package/bin/city/transport/http/NodeHttpAdapter.d.ts.map +1 -0
- package/bin/city/transport/http/NodeHttpAdapter.js +57 -0
- package/bin/city/transport/http/NodeHttpAdapter.js.map +1 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.d.ts +15 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.d.ts.map +1 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.js +38 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.js.map +1 -0
- package/bin/city/transport/http/routes/SessionRoutes.d.ts +17 -0
- package/bin/city/transport/http/routes/SessionRoutes.d.ts.map +1 -0
- package/bin/city/transport/http/routes/SessionRoutes.js +417 -0
- package/bin/city/transport/http/routes/SessionRoutes.js.map +1 -0
- package/bin/city/transport/rpc/AgentRPC.d.ts +47 -0
- package/bin/city/transport/rpc/AgentRPC.d.ts.map +1 -0
- package/bin/city/transport/rpc/AgentRPC.js +89 -0
- package/bin/city/transport/rpc/AgentRPC.js.map +1 -0
- package/bin/city/transport/rpc/CityRPC.d.ts +26 -0
- package/bin/city/transport/rpc/CityRPC.d.ts.map +1 -0
- package/bin/city/transport/rpc/CityRPC.js +110 -0
- package/bin/city/transport/rpc/CityRPC.js.map +1 -0
- package/bin/city/transport/rpc/RpcServer.d.ts +30 -0
- package/bin/city/transport/rpc/RpcServer.d.ts.map +1 -0
- package/bin/city/transport/rpc/RpcServer.js +125 -0
- package/bin/city/transport/rpc/RpcServer.js.map +1 -0
- package/bin/city/transport/rpc/server/InternalHandlers.d.ts +22 -0
- package/bin/city/transport/rpc/server/InternalHandlers.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/InternalHandlers.js +196 -0
- package/bin/city/transport/rpc/server/InternalHandlers.js.map +1 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.d.ts +27 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.js +38 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.js.map +1 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.d.ts +25 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.js +146 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.js.map +1 -0
- package/bin/city/transport/rpc/server/ServerTypes.d.ts +94 -0
- package/bin/city/transport/rpc/server/ServerTypes.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/ServerTypes.js +9 -0
- package/bin/city/transport/rpc/server/ServerTypes.js.map +1 -0
- package/bin/city/transport/session/RemoteSessionConfig.d.ts +15 -0
- package/bin/city/transport/session/RemoteSessionConfig.d.ts.map +1 -0
- package/bin/city/transport/session/RemoteSessionConfig.js +23 -0
- package/bin/city/transport/session/RemoteSessionConfig.js.map +1 -0
- package/bin/city/transport/types/AgentHttpBinding.d.ts +24 -0
- package/bin/city/transport/types/AgentHttpBinding.d.ts.map +1 -0
- package/bin/city/transport/types/AgentHttpBinding.js +5 -0
- package/bin/city/transport/types/AgentHttpBinding.js.map +1 -0
- package/bin/city/transport/types/AgentHttpRuntime.d.ts +12 -0
- package/bin/city/transport/types/AgentHttpRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/AgentHttpRuntime.js +7 -0
- package/bin/city/transport/types/AgentHttpRuntime.js.map +1 -0
- package/bin/city/transport/types/AgentRpcBinding.d.ts +27 -0
- package/bin/city/transport/types/AgentRpcBinding.d.ts.map +1 -0
- package/bin/city/transport/types/AgentRpcBinding.js +8 -0
- package/bin/city/transport/types/AgentRpcBinding.js.map +1 -0
- package/bin/city/transport/types/AgentRpcRuntime.d.ts +18 -0
- package/bin/city/transport/types/AgentRpcRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/AgentRpcRuntime.js +7 -0
- package/bin/city/transport/types/AgentRpcRuntime.js.map +1 -0
- package/bin/city/transport/types/AgentSessionModelResolver.d.ts +11 -0
- package/bin/city/transport/types/AgentSessionModelResolver.d.ts.map +1 -0
- package/bin/city/transport/types/AgentSessionModelResolver.js +7 -0
- package/bin/city/transport/types/AgentSessionModelResolver.js.map +1 -0
- package/bin/city/transport/types/CityHttpRuntime.d.ts +36 -0
- package/bin/city/transport/types/CityHttpRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/CityHttpRuntime.js +8 -0
- package/bin/city/transport/types/CityHttpRuntime.js.map +1 -0
- package/bin/city/transport/types/CityRpcRuntime.d.ts +17 -0
- package/bin/city/transport/types/CityRpcRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/CityRpcRuntime.js +8 -0
- package/bin/city/transport/types/CityRpcRuntime.js.map +1 -0
- package/bin/city/transport/types/RpcProtocol.d.ts +24 -0
- package/bin/city/transport/types/RpcProtocol.d.ts.map +1 -0
- package/bin/city/transport/types/RpcProtocol.js +9 -0
- package/bin/city/transport/types/RpcProtocol.js.map +1 -0
- package/bin/city/types/City.d.ts +84 -0
- package/bin/city/types/City.d.ts.map +1 -0
- package/bin/city/types/City.js +7 -0
- package/bin/city/types/City.js.map +1 -0
- package/bin/city/types/PluginHostContext.d.ts +31 -0
- package/bin/city/types/PluginHostContext.d.ts.map +1 -0
- package/bin/city/types/PluginHostContext.js +11 -0
- package/bin/city/types/PluginHostContext.js.map +1 -0
- package/bin/city/types/SerializedTransport.d.ts +16 -0
- package/bin/city/types/SerializedTransport.d.ts.map +1 -0
- package/bin/city/types/SerializedTransport.js +3 -0
- package/bin/city/types/SerializedTransport.js.map +1 -0
- package/bin/executor/Executor.d.ts +4 -4
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +90 -34
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/SessionSystemComposer.d.ts +2 -2
- package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +1 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +3 -3
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +1 -1
- package/bin/executor/composer/system/default/PromptRenderer.d.ts +3 -3
- package/bin/executor/composer/system/default/PromptRenderer.d.ts.map +1 -1
- package/bin/executor/composer/system/default/PromptRenderer.js +1 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts +3 -3
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +3 -3
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js +2 -2
- 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/composer/system/default/variables/GeoContext.d.ts +1 -1
- package/bin/executor/composer/system/default/variables/VariableReplacer.js +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +6 -23
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js +112 -344
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineError.d.ts +1 -1
- package/bin/executor/core-engine/CoreEngineError.js +1 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +2 -3
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.js +1 -15
- package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +16 -39
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js +25 -60
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +10 -6
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +146 -234
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts +20 -58
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js +84 -304
- package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts +6 -37
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.js +12 -243
- package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
- package/bin/executor/messages/SessionMessageLog.d.ts +7 -14
- package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageLog.js +11 -26
- package/bin/executor/messages/SessionMessageLog.js.map +1 -1
- package/bin/executor/messages/SessionModelMessages.d.ts +14 -0
- package/bin/executor/messages/SessionModelMessages.d.ts.map +1 -0
- package/bin/executor/messages/SessionModelMessages.js +187 -0
- package/bin/executor/messages/SessionModelMessages.js.map +1 -0
- package/bin/executor/model/ModelGenerate.d.ts +22 -0
- package/bin/executor/model/ModelGenerate.d.ts.map +1 -0
- package/bin/executor/model/ModelGenerate.js +54 -0
- package/bin/executor/model/ModelGenerate.js.map +1 -0
- package/bin/executor/model/ModelStepRunner.d.ts +70 -0
- package/bin/executor/model/ModelStepRunner.d.ts.map +1 -0
- package/bin/executor/model/ModelStepRunner.js +284 -0
- package/bin/executor/model/ModelStepRunner.js.map +1 -0
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +4 -4
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +7 -2
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/executor/types/SessionLoop.d.ts +1 -21
- package/bin/executor/types/SessionLoop.d.ts.map +1 -1
- package/bin/executor/types/SessionPrompts.d.ts +8 -7
- package/bin/executor/types/SessionPrompts.d.ts.map +1 -1
- package/bin/executor/types/SessionPrompts.js +1 -2
- package/bin/executor/types/SessionPrompts.js.map +1 -1
- package/bin/group/Group.d.ts +20 -0
- package/bin/group/Group.d.ts.map +1 -0
- package/bin/group/Group.js +42 -0
- package/bin/group/Group.js.map +1 -0
- package/bin/group/GroupSession.d.ts +103 -0
- package/bin/group/GroupSession.d.ts.map +1 -0
- package/bin/group/GroupSession.js +666 -0
- package/bin/group/GroupSession.js.map +1 -0
- package/bin/group/GroupSessions.d.ts +21 -0
- package/bin/group/GroupSessions.d.ts.map +1 -0
- package/bin/group/GroupSessions.js +89 -0
- package/bin/group/GroupSessions.js.map +1 -0
- package/bin/group/index.d.ts +9 -0
- package/bin/group/index.d.ts.map +1 -0
- package/bin/group/index.js +6 -0
- package/bin/group/index.js.map +1 -0
- package/bin/index.d.ts +29 -21
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +7 -9
- package/bin/index.js.map +1 -1
- package/bin/internal/AgentRuntime.d.ts +43 -0
- package/bin/internal/AgentRuntime.d.ts.map +1 -0
- package/bin/internal/AgentRuntime.js +179 -0
- package/bin/internal/AgentRuntime.js.map +1 -0
- package/bin/internal/GroupRuntime.d.ts +17 -0
- package/bin/internal/GroupRuntime.d.ts.map +1 -0
- package/bin/internal/GroupRuntime.js +66 -0
- package/bin/internal/GroupRuntime.js.map +1 -0
- package/bin/internal/index.d.ts +8 -0
- package/bin/internal/index.d.ts.map +1 -0
- package/bin/internal/index.js +8 -0
- package/bin/internal/index.js.map +1 -0
- package/bin/plugin/core/ActionScheduleExecutor.d.ts +3 -2
- package/bin/plugin/core/ActionScheduleExecutor.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleExecutor.js +14 -3
- package/bin/plugin/core/ActionScheduleExecutor.js.map +1 -1
- package/bin/plugin/core/ActionScheduleRuntime.d.ts +3 -1
- package/bin/plugin/core/ActionScheduleRuntime.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleRuntime.js +9 -8
- package/bin/plugin/core/ActionScheduleRuntime.js.map +1 -1
- package/bin/plugin/core/ActionScheduleStore.d.ts +7 -3
- package/bin/plugin/core/ActionScheduleStore.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleStore.js +32 -9
- package/bin/plugin/core/ActionScheduleStore.js.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +4 -6
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/HookRegistry.js +8 -14
- package/bin/plugin/core/HookRegistry.js.map +1 -1
- package/bin/plugin/core/PluginActionExecution.d.ts +33 -0
- package/bin/plugin/core/PluginActionExecution.d.ts.map +1 -0
- package/bin/plugin/core/PluginActionExecution.js +168 -0
- package/bin/plugin/core/PluginActionExecution.js.map +1 -0
- 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 +3 -0
- package/bin/plugin/core/PluginActionFactory.js.map +1 -1
- package/bin/plugin/core/PluginContext.d.ts +14 -4
- package/bin/plugin/core/PluginContext.d.ts.map +1 -1
- package/bin/plugin/core/PluginContext.js +11 -2
- package/bin/plugin/core/PluginContext.js.map +1 -1
- package/bin/plugin/core/PluginHttpRoutes.d.ts +1 -1
- package/bin/plugin/core/PluginHttpRoutes.d.ts.map +1 -1
- package/bin/plugin/core/PluginHttpRoutes.js +1 -1
- package/bin/plugin/core/PluginHttpRoutes.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +41 -26
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +125 -107
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/tool/PluginToolRuntime.d.ts.map +1 -1
- package/bin/plugin/tool/PluginToolRuntime.js +4 -1
- package/bin/plugin/tool/PluginToolRuntime.js.map +1 -1
- package/bin/plugin/tool/PluginToolSchemas.d.ts +22 -2
- package/bin/plugin/tool/PluginToolSchemas.d.ts.map +1 -1
- package/bin/plugin/tool/PluginToolSchemas.js +3 -4
- package/bin/plugin/tool/PluginToolSchemas.js.map +1 -1
- package/bin/plugin/tool/PluginTools.d.ts +5 -8
- package/bin/plugin/tool/PluginTools.d.ts.map +1 -1
- package/bin/plugin/tool/PluginTools.js +9 -8
- package/bin/plugin/tool/PluginTools.js.map +1 -1
- package/bin/plugin/types/ActionSchedule.d.ts +6 -0
- package/bin/plugin/types/ActionSchedule.d.ts.map +1 -1
- package/bin/remote/RemoteAgent.js +2 -2
- package/bin/remote/RemoteSession.d.ts +1 -1
- package/bin/remote/TransportFactory.d.ts +1 -1
- package/bin/remote/TransportFactory.js +2 -2
- package/bin/remote/transports/HttpRemoteAgentTransport.d.ts +1 -1
- package/bin/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/remote/transports/HttpRemoteAgentTransport.js +3 -3
- package/bin/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/remote/transports/RpcClient.d.ts +1 -0
- package/bin/remote/transports/RpcClient.d.ts.map +1 -1
- package/bin/remote/transports/RpcClient.js +16 -0
- package/bin/remote/transports/RpcClient.js.map +1 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.d.ts +1 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.js +2 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/session/DefaultSessionComposer.js +4 -4
- package/bin/session/DefaultSessionComposer.js.map +1 -1
- package/bin/session/Session.d.ts +9 -3
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +85 -55
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionLoop.d.ts.map +1 -1
- package/bin/session/SessionLoop.js +23 -25
- package/bin/session/SessionLoop.js.map +1 -1
- package/bin/session/SessionMessages.d.ts +9 -11
- package/bin/session/SessionMessages.d.ts.map +1 -1
- package/bin/session/SessionMessages.js +56 -104
- package/bin/session/SessionMessages.js.map +1 -1
- package/bin/session/SessionQueue.d.ts +1 -1
- package/bin/session/SessionState.d.ts +3 -0
- package/bin/session/SessionState.d.ts.map +1 -1
- package/bin/session/SessionState.js +42 -12
- package/bin/session/SessionState.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +6 -6
- package/bin/session/SessionTitle.d.ts.map +1 -1
- package/bin/session/SessionTitle.js +11 -39
- package/bin/session/SessionTitle.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +6 -4
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +25 -43
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/control/SessionInteractions.d.ts +2 -2
- package/bin/session/control/SessionInteractions.d.ts.map +1 -1
- package/bin/session/control/SessionInteractions.js +68 -32
- package/bin/session/control/SessionInteractions.js.map +1 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts +20 -17
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +1 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js +35 -35
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +1 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +2 -2
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +1 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js +20 -8
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +1 -1
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts +42 -48
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionAssistantMessageWriter.js +225 -543
- package/bin/session/messages/SessionAssistantMessageWriter.js.map +1 -1
- package/bin/session/messages/SessionJsonValue.d.ts +0 -10
- package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
- package/bin/session/messages/SessionJsonValue.js +0 -23
- package/bin/session/messages/SessionJsonValue.js.map +1 -1
- package/bin/session/messages/SessionMessageCompaction.d.ts +7 -3
- package/bin/session/messages/SessionMessageCompaction.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageCompaction.js +69 -91
- package/bin/session/messages/SessionMessageCompaction.js.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +22 -21
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +1 -1
- package/bin/session/messages/SessionMessageText.d.ts +25 -0
- package/bin/session/messages/SessionMessageText.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageText.js +52 -0
- package/bin/session/messages/SessionMessageText.js.map +1 -0
- package/bin/session/preview/SessionMessagePreview.d.ts +3 -3
- package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/preview/SessionMessagePreview.js +10 -30
- package/bin/session/preview/SessionMessagePreview.js.map +1 -1
- package/bin/session/runtime/SessionTurnContext.d.ts.map +1 -1
- package/bin/session/runtime/SessionTurnContext.js +4 -2
- package/bin/session/runtime/SessionTurnContext.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +5 -3
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +26 -7
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.d.ts +2 -16
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +21 -17
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/action/ActionResult.d.ts +15 -10
- package/bin/types/action/ActionResult.d.ts.map +1 -1
- package/bin/types/action/ActionResult.js +2 -2
- package/bin/types/action/ActionResult.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +7 -14
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentSessionCollection.d.ts +42 -0
- package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -0
- package/bin/types/agent/AgentSessionCollection.js +7 -0
- package/bin/types/agent/AgentSessionCollection.js.map +1 -0
- package/bin/types/agent/AgentStorage.d.ts +18 -0
- package/bin/types/agent/AgentStorage.d.ts.map +1 -0
- package/bin/types/agent/AgentStorage.js +8 -0
- package/bin/types/agent/AgentStorage.js.map +1 -0
- package/bin/types/agent/RemoteAgentOptions.d.ts +1 -1
- package/bin/types/agent/RemoteAgentPluginAction.d.ts +2 -2
- package/bin/types/agent/SessionActor.d.ts +15 -8
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +39 -12
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/agent/WorkspaceEntryOptions.d.ts +16 -0
- package/bin/types/agent/WorkspaceEntryOptions.d.ts.map +1 -0
- package/bin/types/agent/WorkspaceEntryOptions.js +8 -0
- package/bin/types/agent/WorkspaceEntryOptions.js.map +1 -0
- package/bin/types/executor/SessionAssistantOutput.d.ts +19 -17
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +1 -1
- package/bin/types/executor/SessionAssistantOutput.js +2 -3
- package/bin/types/executor/SessionAssistantOutput.js.map +1 -1
- package/bin/types/executor/SessionToolExecutionContext.d.ts +8 -5
- package/bin/types/executor/SessionToolExecutionContext.d.ts.map +1 -1
- package/bin/types/executor/SessionToolExecutionContext.js +1 -1
- package/bin/types/executor/SessionTurnContext.d.ts +16 -16
- package/bin/types/executor/SessionTurnContext.d.ts.map +1 -1
- package/bin/types/group/DispatchStrategy.d.ts +62 -0
- package/bin/types/group/DispatchStrategy.d.ts.map +1 -0
- package/bin/types/group/DispatchStrategy.js +93 -0
- package/bin/types/group/DispatchStrategy.js.map +1 -0
- package/bin/types/group/Group.d.ts +61 -0
- package/bin/types/group/Group.d.ts.map +1 -0
- package/bin/types/group/Group.js +3 -0
- package/bin/types/group/Group.js.map +1 -0
- package/bin/types/group/GroupSession.d.ts +149 -0
- package/bin/types/group/GroupSession.d.ts.map +1 -0
- package/bin/types/group/GroupSession.js +3 -0
- package/bin/types/group/GroupSession.js.map +1 -0
- package/bin/types/group/GroupSessionStore.d.ts +77 -0
- package/bin/types/group/GroupSessionStore.d.ts.map +1 -0
- package/bin/types/group/GroupSessionStore.js +3 -0
- package/bin/types/group/GroupSessionStore.js.map +1 -0
- package/bin/types/plugin/AgentPluginContext.d.ts +25 -0
- package/bin/types/plugin/AgentPluginContext.d.ts.map +1 -0
- package/bin/types/plugin/AgentPluginContext.js +10 -0
- package/bin/types/plugin/AgentPluginContext.js.map +1 -0
- package/bin/types/plugin/PluginAction.d.ts +10 -8
- package/bin/types/plugin/PluginAction.d.ts.map +1 -1
- package/bin/types/plugin/PluginActionExecution.d.ts +31 -0
- package/bin/types/plugin/PluginActionExecution.d.ts.map +1 -0
- package/bin/types/plugin/PluginActionExecution.js +10 -0
- package/bin/types/plugin/PluginActionExecution.js.map +1 -0
- package/bin/types/plugin/PluginCommand.d.ts +5 -5
- package/bin/types/plugin/PluginCommand.d.ts.map +1 -1
- package/bin/types/plugin/PluginContext.d.ts +19 -8
- package/bin/types/plugin/PluginContext.d.ts.map +1 -1
- package/bin/types/plugin/PluginContext.js +1 -1
- package/bin/types/plugin/PluginDefinition.d.ts +6 -6
- package/bin/types/plugin/PluginExecutionContext.d.ts +4 -10
- package/bin/types/plugin/PluginExecutionContext.d.ts.map +1 -1
- package/bin/types/plugin/PluginExecutionContext.js +3 -5
- package/bin/types/plugin/PluginExecutionContext.js.map +1 -1
- package/bin/types/plugin/PluginHttp.d.ts +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +13 -8
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginServices.d.ts +10 -0
- package/bin/types/plugin/PluginServices.d.ts.map +1 -0
- package/bin/types/plugin/PluginServices.js +3 -0
- package/bin/types/plugin/PluginServices.js.map +1 -0
- package/bin/types/plugin/PluginState.d.ts +3 -3
- package/bin/types/plugin/PluginState.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.js +1 -1
- package/bin/types/plugin/PluginTool.d.ts +6 -4
- package/bin/types/plugin/PluginTool.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +30 -8
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.d.ts +6 -7
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.js +2 -3
- package/bin/types/sdk/AgentSessionAction.js.map +1 -1
- package/bin/types/sdk/AgentSessionPrompt.d.ts +7 -7
- package/bin/types/sdk/AgentSessionPrompt.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionPrompt.js +1 -4
- package/bin/types/sdk/AgentSessionPrompt.js.map +1 -1
- package/bin/types/session/SessionAction.d.ts +39 -0
- package/bin/types/session/SessionAction.d.ts.map +1 -0
- package/bin/types/session/SessionAction.js +8 -0
- package/bin/types/session/SessionAction.js.map +1 -0
- package/bin/types/session/SessionComposer.d.ts +10 -11
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionContent.d.ts +41 -0
- package/bin/types/session/SessionContent.d.ts.map +1 -0
- package/bin/types/session/SessionContent.js +8 -0
- package/bin/types/session/SessionContent.js.map +1 -0
- package/bin/types/session/SessionExecution.d.ts +9 -68
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionInteraction.d.ts +92 -58
- package/bin/types/session/SessionInteraction.d.ts.map +1 -1
- package/bin/types/session/SessionInteraction.js +11 -4
- package/bin/types/session/SessionInteraction.js.map +1 -1
- package/bin/types/session/SessionInteractions.d.ts +1 -1
- package/bin/types/session/SessionLocalState.d.ts +2 -2
- package/bin/types/session/SessionLoop.d.ts +5 -5
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessage.d.ts +27 -87
- package/bin/types/session/SessionMessage.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +14 -14
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionMutation.d.ts +17 -4
- 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 +14 -9
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionOrigin.d.ts +19 -0
- package/bin/types/session/SessionOrigin.d.ts.map +1 -0
- package/bin/types/session/SessionOrigin.js +8 -0
- package/bin/types/session/SessionOrigin.js.map +1 -0
- package/bin/types/session/SessionPort.d.ts +16 -20
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionSegment.d.ts +1 -1
- package/bin/types/session/SessionState.d.ts +9 -6
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +1 -1
- package/bin/types/session/SessionTool.d.ts +12 -1
- package/bin/types/session/SessionTool.d.ts.map +1 -1
- package/bin/types/store/LocalStore.d.ts +19 -11
- package/bin/types/store/LocalStore.d.ts.map +1 -1
- package/bin/types/store/LocalStore.js +2 -2
- package/bin/types/store/SessionAttachmentStore.d.ts +4 -4
- package/bin/types/store/SessionAttachmentStore.js +3 -3
- package/bin/types/store/SessionDataStore.d.ts +85 -0
- package/bin/types/store/SessionDataStore.d.ts.map +1 -0
- package/bin/types/store/SessionDataStore.js +9 -0
- package/bin/types/store/SessionDataStore.js.map +1 -0
- package/bin/types/store/SessionStore.d.ts +24 -78
- package/bin/types/store/SessionStore.d.ts.map +1 -1
- package/bin/types/store/SessionStore.js +3 -3
- package/bin/types/tools/ToolActionExecutionContext.d.ts +30 -0
- package/bin/types/tools/ToolActionExecutionContext.d.ts.map +1 -0
- package/bin/types/tools/ToolActionExecutionContext.js +8 -0
- package/bin/types/tools/ToolActionExecutionContext.js.map +1 -0
- package/bin/types/tools/ask/AskQuestionsTool.d.ts +1 -1
- package/bin/utils/logger/Logger.d.ts +21 -9
- package/bin/utils/logger/Logger.d.ts.map +1 -1
- package/bin/utils/logger/Logger.js +18 -9
- package/bin/utils/logger/Logger.js.map +1 -1
- package/bin/workspace/WorkspacePaths.d.ts +3 -54
- package/bin/workspace/WorkspacePaths.d.ts.map +1 -1
- package/bin/workspace/WorkspacePaths.js +7 -74
- package/bin/workspace/WorkspacePaths.js.map +1 -1
- package/bin/workspace/store/JsonlSessionMessageStore.d.ts +1 -1
- package/bin/workspace/store/JsonlSessionMessageStore.d.ts.map +1 -1
- package/bin/workspace/store/LocalGroupSessionDataStore.d.ts +46 -0
- package/bin/workspace/store/LocalGroupSessionDataStore.d.ts.map +1 -0
- package/bin/workspace/store/LocalGroupSessionDataStore.js +197 -0
- package/bin/workspace/store/LocalGroupSessionDataStore.js.map +1 -0
- package/bin/workspace/store/LocalGroupSessionStore.d.ts +22 -0
- package/bin/workspace/store/LocalGroupSessionStore.d.ts.map +1 -0
- package/bin/workspace/store/LocalGroupSessionStore.js +75 -0
- package/bin/workspace/store/LocalGroupSessionStore.js.map +1 -0
- package/bin/workspace/store/LocalSessionAttachmentStore.d.ts +2 -2
- package/bin/workspace/store/LocalSessionAttachmentStore.d.ts.map +1 -1
- package/bin/workspace/store/LocalSessionAttachmentStore.js +2 -2
- package/bin/workspace/store/LocalSessionAttachmentStore.js.map +1 -1
- package/bin/workspace/store/LocalSessionDataStore.d.ts +45 -0
- package/bin/workspace/store/LocalSessionDataStore.d.ts.map +1 -0
- package/bin/workspace/store/LocalSessionDataStore.js +100 -0
- package/bin/workspace/store/LocalSessionDataStore.js.map +1 -0
- package/bin/workspace/store/LocalSessionStore.d.ts +38 -28
- package/bin/workspace/store/LocalSessionStore.d.ts.map +1 -1
- package/bin/workspace/store/LocalSessionStore.js +151 -51
- package/bin/workspace/store/LocalSessionStore.js.map +1 -1
- package/bin/workspace/store/LocalStorePaths.d.ts +31 -83
- package/bin/workspace/store/LocalStorePaths.d.ts.map +1 -1
- package/bin/workspace/store/LocalStorePaths.js +43 -101
- package/bin/workspace/store/LocalStorePaths.js.map +1 -1
- package/bin/workspace/store/SessionMessageStoreFactory.d.ts +1 -1
- package/bin/workspace/store/SessionMessageStoreFactory.d.ts.map +1 -1
- package/bin/workspace/store/SessionMessageStoreFactory.js +1 -1
- package/city-test/agent-http.test.mjs +326 -0
- package/city-test/city-container.test.mjs +156 -0
- package/city-test/city-host-registry.test.mjs +68 -0
- package/city-test/city-transport.test.mjs +282 -0
- package/city-test/group.test.mjs +739 -0
- package/city-test/session-model.test.mjs +169 -0
- package/city-test/transport-lifecycle.test.mjs +164 -0
- package/package.json +30 -17
- package/scripts/ModelClientMock.mjs +165 -0
- package/scripts/action-schedule-store.test.mjs +81 -11
- package/scripts/agent-compiler.mjs +10 -6
- package/scripts/agent-env-shell-sandbox.test.mjs +10 -10
- package/scripts/agent-env.test.mjs +6 -8
- package/scripts/agent-multi-workspace.test.mjs +213 -0
- package/scripts/agent-ready.test.mjs +71 -16
- package/scripts/agent-session-maintenance.test.mjs +15 -28
- package/scripts/agent-store.test.mjs +121 -22
- package/scripts/city-model-tool-loop.test.mjs +66 -195
- package/scripts/core-engine-context-compaction.test.mjs +65 -113
- package/scripts/core-engine-model-stream.test.mjs +87 -0
- package/scripts/executor-failure-result.test.mjs +13 -29
- package/scripts/file-tools.test.mjs +6 -6
- package/scripts/image-plugin-job.test.mjs +77 -40
- package/scripts/logger-isolation.test.mjs +2 -2
- package/scripts/multi-agent-plugin-isolation.test.mjs +11 -9
- package/scripts/plugin-tools.test.mjs +153 -18
- package/scripts/public-api-naming.test.mjs +0 -1
- package/scripts/rewrite-build-aliases.mjs +49 -0
- package/scripts/rpc-url-routing.test.mjs +29 -0
- package/scripts/search-tools.test.mjs +4 -4
- package/scripts/session-ask-question.test.mjs +23 -21
- package/scripts/session-attachments.test.mjs +11 -9
- package/scripts/session-compact-handle.test.mjs +6 -5
- package/scripts/session-composer.test.mjs +61 -18
- package/scripts/session-config-turn-boundary.test.mjs +132 -92
- package/scripts/session-dynamic-interaction.test.mjs +75 -0
- package/scripts/session-fork.test.mjs +35 -0
- package/scripts/session-list-title.test.mjs +14 -56
- package/scripts/session-messages.test.mjs +306 -1681
- package/scripts/session-shell-approval.test.mjs +16 -13
- package/scripts/session-system-blocks.test.mjs +1 -1
- package/scripts/session-title-event.test.mjs +38 -24
- package/scripts/session-tool-approval.test.mjs +17 -15
- package/scripts/session-turn-context.test.mjs +31 -28
- package/scripts/session-turn-failure.test.mjs +112 -110
- package/scripts/verify-build-aliases.mjs +32 -0
- package/scripts/workspace.test.mjs +146 -32
- package/src/agent/Agent.ts +138 -238
- package/src/agent/AgentModel.ts +9 -9
- package/src/agent/AgentSessions.ts +116 -65
- package/src/agent/WorkspaceEntry.ts +309 -0
- package/src/agent/index.ts +4 -0
- package/src/city/host/CityHostRegistry.ts +260 -0
- package/src/city/index.ts +49 -0
- package/src/city/runtime/City.ts +425 -0
- package/src/city/transport/SerializedTransport.ts +65 -0
- package/src/city/transport/http/AgentHTTP.ts +176 -0
- package/src/city/transport/http/CityHTTP.ts +196 -0
- package/src/city/transport/http/NodeHttpAdapter.ts +75 -0
- package/src/city/transport/http/routes/RuntimeRoutes.ts +51 -0
- package/src/city/transport/http/routes/SessionRoutes.ts +497 -0
- package/src/city/transport/rpc/AgentRPC.ts +111 -0
- package/src/city/transport/rpc/CityRPC.ts +138 -0
- package/src/city/transport/rpc/RpcServer.ts +158 -0
- package/src/city/transport/rpc/server/InternalHandlers.ts +223 -0
- package/src/city/transport/rpc/server/RequestDispatcher.ts +67 -0
- package/src/city/transport/rpc/server/SdkSessionHandlers.ts +166 -0
- package/src/city/transport/rpc/server/ServerTypes.ts +103 -0
- package/src/city/transport/session/RemoteSessionConfig.ts +34 -0
- package/src/city/transport/types/AgentHttpBinding.ts +25 -0
- package/src/city/transport/types/AgentHttpRuntime.ts +13 -0
- package/src/city/transport/types/AgentRpcBinding.ts +28 -0
- package/src/city/transport/types/AgentRpcRuntime.ts +20 -0
- package/src/city/transport/types/AgentSessionModelResolver.ts +13 -0
- package/src/city/transport/types/CityHttpRuntime.ts +45 -0
- package/src/city/transport/types/CityRpcRuntime.ts +27 -0
- package/src/city/transport/types/RpcProtocol.ts +32 -0
- package/src/city/types/City.ts +99 -0
- package/src/city/types/PluginHostContext.ts +40 -0
- package/src/city/types/SerializedTransport.ts +19 -0
- package/src/executor/Executor.ts +101 -43
- package/src/executor/README.md +11 -8
- package/src/executor/composer/system/SessionSystemComposer.ts +2 -2
- package/src/executor/composer/system/default/PromptRenderer.ts +2 -2
- package/src/executor/composer/system/default/SystemDomain.ts +5 -5
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +4 -12
- package/src/executor/core-engine/CoreEngineContextCompaction.ts +113 -427
- package/src/executor/core-engine/CoreEngineError.ts +1 -1
- package/src/executor/core-engine/CoreEngineLoopDecision.ts +1 -18
- package/src/executor/core-engine/CoreEngineMessageState.ts +32 -101
- package/src/executor/core-engine/CoreEngineRunner.ts +179 -281
- package/src/executor/core-engine/CoreEngineSignals.ts +98 -346
- package/src/executor/messages/SessionAttachmentMapper.ts +15 -273
- package/src/executor/messages/SessionMessageLog.ts +12 -25
- package/src/executor/messages/SessionModelMessages.ts +223 -0
- package/src/executor/model/ModelGenerate.ts +71 -0
- package/src/executor/model/ModelStepRunner.ts +381 -0
- package/src/executor/services/ExecutorRecoveryPolicy.ts +4 -4
- package/src/executor/types/SessionHistoryMeta.ts +8 -2
- package/src/executor/types/SessionLoop.ts +0 -26
- package/src/executor/types/SessionPrompts.ts +8 -8
- package/src/group/Group.ts +45 -0
- package/src/group/GroupSession.ts +728 -0
- package/src/group/GroupSessions.ts +104 -0
- package/src/group/index.ts +29 -0
- package/src/index.ts +110 -60
- package/src/internal/AgentRuntime.ts +229 -0
- package/src/internal/GroupRuntime.ts +89 -0
- package/src/internal/index.ts +33 -0
- package/src/plugin/core/ActionScheduleExecutor.ts +17 -5
- package/src/plugin/core/ActionScheduleRuntime.ts +16 -6
- package/src/plugin/core/ActionScheduleStore.ts +43 -12
- package/src/plugin/core/HookRegistry.ts +24 -14
- package/src/plugin/core/PluginActionExecution.ts +230 -0
- package/src/plugin/core/PluginActionFactory.ts +9 -3
- package/src/plugin/core/PluginContext.ts +25 -6
- package/src/plugin/core/PluginHttpRoutes.ts +2 -2
- package/src/plugin/core/PluginRegistry.ts +193 -107
- package/src/plugin/tool/PluginToolRuntime.ts +4 -1
- package/src/plugin/tool/PluginToolSchemas.ts +3 -4
- package/src/plugin/tool/PluginTools.ts +12 -8
- package/src/plugin/types/ActionSchedule.ts +6 -0
- package/src/remote/transports/HttpRemoteAgentTransport.ts +3 -3
- package/src/remote/transports/RpcClient.ts +17 -0
- package/src/remote/transports/RpcRemoteAgentTransport.ts +1 -0
- package/src/session/DefaultSessionComposer.ts +3 -3
- package/src/session/Session.ts +79 -43
- package/src/session/SessionLoop.ts +27 -34
- package/src/session/SessionMessages.ts +63 -121
- package/src/session/SessionState.ts +46 -21
- package/src/session/SessionTitle.ts +23 -40
- package/src/session/browse/Browse.ts +35 -63
- package/src/session/control/SessionInteractions.ts +72 -51
- package/src/session/execution/SessionAssistantOutputAdapter.ts +44 -45
- package/src/session/execution/tools/SessionShellApprovalAdapter.ts +20 -9
- package/src/session/messages/SessionAssistantMessageWriter.ts +259 -637
- package/src/session/messages/SessionJsonValue.ts +0 -23
- package/src/session/messages/SessionMessageCompaction.ts +78 -103
- package/src/session/messages/SessionMessageInteractionWriter.ts +22 -22
- package/src/session/messages/SessionMessageText.ts +73 -0
- package/src/session/preview/SessionMessagePreview.ts +15 -45
- package/src/session/runtime/SessionTurnContext.ts +11 -9
- package/src/session/storage/Metadata.ts +38 -9
- package/src/tools/ask/AskQuestionsTool.ts +28 -17
- package/src/types/action/ActionResult.ts +20 -11
- package/src/types/agent/AgentOptions.ts +6 -13
- package/src/types/agent/AgentSessionCollection.ts +61 -0
- package/src/types/agent/AgentStorage.ts +19 -0
- package/src/types/agent/RemoteAgentOptions.ts +1 -1
- package/src/types/agent/SessionActor.ts +9 -0
- package/src/types/agent/SessionTypes.ts +41 -12
- package/src/types/agent/WorkspaceEntryOptions.ts +18 -0
- package/src/types/executor/SessionAssistantOutput.ts +22 -17
- package/src/types/executor/SessionToolExecutionContext.ts +9 -4
- package/src/types/executor/SessionTurnContext.ts +11 -11
- package/src/types/group/DispatchStrategy.ts +165 -0
- package/src/types/group/Group.ts +64 -0
- package/src/types/group/GroupSession.ts +154 -0
- package/src/types/group/GroupSessionStore.ts +82 -0
- package/src/types/plugin/AgentPluginContext.ts +30 -0
- package/src/types/plugin/PluginAction.ts +7 -5
- package/src/types/plugin/PluginActionExecution.ts +36 -0
- package/src/types/plugin/PluginCommand.ts +5 -5
- package/src/types/plugin/PluginContext.ts +23 -7
- package/src/types/plugin/PluginExecutionContext.ts +6 -11
- package/src/types/plugin/PluginRuntime.ts +5 -0
- package/src/types/plugin/PluginServices.ts +11 -0
- package/src/types/plugin/PluginState.ts +2 -2
- package/src/types/plugin/PluginTool.ts +4 -1
- package/src/types/rpc/RpcProtocol.ts +24 -2
- package/src/types/sdk/AgentSessionAction.ts +8 -9
- package/src/types/sdk/AgentSessionPrompt.ts +8 -11
- package/src/types/session/SessionAction.ts +41 -0
- package/src/types/session/SessionComposer.ts +8 -13
- package/src/types/session/SessionContent.ts +52 -0
- package/src/types/session/SessionExecution.ts +9 -88
- package/src/types/session/SessionInteraction.ts +106 -73
- package/src/types/session/SessionLoop.ts +1 -1
- package/src/types/session/SessionMessage.ts +27 -94
- package/src/types/session/SessionMessages.ts +12 -9
- package/src/types/session/SessionMutation.ts +17 -2
- package/src/types/session/SessionOptions.ts +11 -4
- package/src/types/session/SessionOrigin.ts +21 -0
- package/src/types/session/SessionPort.ts +12 -20
- package/src/types/session/SessionState.ts +7 -4
- package/src/types/session/SessionTool.ts +12 -0
- package/src/types/store/LocalStore.ts +19 -11
- package/src/types/store/SessionAttachmentStore.ts +4 -4
- package/src/types/store/SessionDataStore.ts +109 -0
- package/src/types/store/SessionStore.ts +37 -94
- package/src/types/tools/ToolActionExecutionContext.ts +32 -0
- package/src/utils/logger/Logger.ts +33 -12
- package/src/workspace/WorkspacePaths.ts +7 -82
- package/src/workspace/store/JsonlSessionMessageStore.ts +2 -2
- package/src/workspace/store/LocalGroupSessionDataStore.ts +232 -0
- package/src/workspace/store/LocalGroupSessionStore.ts +90 -0
- package/src/workspace/store/LocalSessionAttachmentStore.ts +3 -3
- package/src/workspace/store/LocalSessionDataStore.ts +169 -0
- package/src/workspace/store/LocalSessionStore.ts +202 -86
- package/src/workspace/store/LocalStorePaths.ts +65 -147
- package/src/workspace/store/SessionMessageStoreFactory.ts +1 -1
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -183
- package/bin/agent/AgentState.d.ts +0 -45
- package/bin/agent/AgentState.d.ts.map +0 -1
- package/bin/agent/AgentState.js +0 -74
- package/bin/agent/AgentState.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +0 -48
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js +0 -92
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +0 -1
- package/bin/executor/messages/SessionMessageCodec.d.ts +0 -29
- package/bin/executor/messages/SessionMessageCodec.d.ts.map +0 -1
- package/bin/executor/messages/SessionMessageCodec.js +0 -75
- package/bin/executor/messages/SessionMessageCodec.js.map +0 -1
- package/bin/executor/messages/SessionStepEventMapper.d.ts +0 -19
- package/bin/executor/messages/SessionStepEventMapper.d.ts.map +0 -1
- package/bin/executor/messages/SessionStepEventMapper.js +0 -177
- package/bin/executor/messages/SessionStepEventMapper.js.map +0 -1
- package/bin/executor/messages/UIMessageTransformer.d.ts +0 -29
- package/bin/executor/messages/UIMessageTransformer.d.ts.map +0 -1
- package/bin/executor/messages/UIMessageTransformer.js +0 -114
- package/bin/executor/messages/UIMessageTransformer.js.map +0 -1
- package/bin/executor/messages/UserVisibleText.d.ts +0 -26
- package/bin/executor/messages/UserVisibleText.d.ts.map +0 -1
- package/bin/executor/messages/UserVisibleText.js +0 -65
- package/bin/executor/messages/UserVisibleText.js.map +0 -1
- package/bin/executor/types/SessionRecords.d.ts +0 -162
- package/bin/executor/types/SessionRecords.d.ts.map +0 -1
- package/bin/executor/types/SessionRecords.js +0 -51
- package/bin/executor/types/SessionRecords.js.map +0 -1
- package/bin/plugin/core/PluginActionRunner.d.ts +0 -24
- package/bin/plugin/core/PluginActionRunner.d.ts.map +0 -1
- package/bin/plugin/core/PluginActionRunner.js +0 -19
- package/bin/plugin/core/PluginActionRunner.js.map +0 -1
- package/bin/session/messages/SessionMessageCodec.d.ts +0 -23
- package/bin/session/messages/SessionMessageCodec.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageCodec.js +0 -455
- package/bin/session/messages/SessionMessageCodec.js.map +0 -1
- package/bin/types/agent/AgentState.d.ts +0 -19
- package/bin/types/agent/AgentState.d.ts.map +0 -1
- package/bin/types/agent/AgentState.js +0 -9
- package/bin/types/agent/AgentState.js.map +0 -1
- package/bin/types/store/AgentStore.d.ts +0 -31
- package/bin/types/store/AgentStore.d.ts.map +0 -1
- package/bin/types/store/AgentStore.js +0 -9
- package/bin/types/store/AgentStore.js.map +0 -1
- package/bin/types/workspace/FileSystem.d.ts +0 -55
- package/bin/types/workspace/FileSystem.d.ts.map +0 -1
- package/bin/types/workspace/FileSystem.js +0 -9
- package/bin/types/workspace/FileSystem.js.map +0 -1
- package/bin/types/workspace/FileTool.d.ts +0 -181
- package/bin/types/workspace/FileTool.d.ts.map +0 -1
- package/bin/types/workspace/FileTool.js +0 -10
- package/bin/types/workspace/FileTool.js.map +0 -1
- package/bin/types/workspace/SearchTool.d.ts +0 -131
- package/bin/types/workspace/SearchTool.d.ts.map +0 -1
- package/bin/types/workspace/SearchTool.js +0 -10
- package/bin/types/workspace/SearchTool.js.map +0 -1
- package/bin/types/workspace/Workspace.d.ts +0 -24
- package/bin/types/workspace/Workspace.d.ts.map +0 -1
- package/bin/types/workspace/Workspace.js +0 -9
- package/bin/types/workspace/Workspace.js.map +0 -1
- package/bin/types/workspace/WorkspaceEnv.d.ts +0 -16
- package/bin/types/workspace/WorkspaceEnv.d.ts.map +0 -1
- package/bin/types/workspace/WorkspaceEnv.js +0 -9
- package/bin/types/workspace/WorkspaceEnv.js.map +0 -1
- package/bin/types/workspace/WorkspaceTools.d.ts +0 -20
- package/bin/types/workspace/WorkspaceTools.d.ts.map +0 -1
- package/bin/types/workspace/WorkspaceTools.js +0 -9
- package/bin/types/workspace/WorkspaceTools.js.map +0 -1
- package/bin/utils/cli/CliOutput.d.ts +0 -14
- package/bin/utils/cli/CliOutput.d.ts.map +0 -1
- package/bin/utils/cli/CliOutput.js +0 -98
- package/bin/utils/cli/CliOutput.js.map +0 -1
- package/bin/utils/cli/PrettyStatus.d.ts +0 -25
- package/bin/utils/cli/PrettyStatus.d.ts.map +0 -1
- package/bin/utils/cli/PrettyStatus.js +0 -77
- package/bin/utils/cli/PrettyStatus.js.map +0 -1
- package/bin/utils/logger/FormatRequest.d.ts +0 -29
- package/bin/utils/logger/FormatRequest.d.ts.map +0 -1
- package/bin/utils/logger/FormatRequest.js +0 -309
- package/bin/utils/logger/FormatRequest.js.map +0 -1
- package/bin/utils/logger/FormatResponse.d.ts +0 -46
- package/bin/utils/logger/FormatResponse.d.ts.map +0 -1
- package/bin/utils/logger/FormatResponse.js +0 -186
- package/bin/utils/logger/FormatResponse.js.map +0 -1
- package/bin/utils/logger/FormatShared.d.ts +0 -33
- package/bin/utils/logger/FormatShared.d.ts.map +0 -1
- package/bin/utils/logger/FormatShared.js +0 -215
- package/bin/utils/logger/FormatShared.js.map +0 -1
- package/bin/utils/object/DeepMerge.d.ts +0 -18
- package/bin/utils/object/DeepMerge.d.ts.map +0 -1
- package/bin/utils/object/DeepMerge.js +0 -37
- package/bin/utils/object/DeepMerge.js.map +0 -1
- package/bin/utils/object/ObjectGuards.d.ts +0 -17
- package/bin/utils/object/ObjectGuards.d.ts.map +0 -1
- package/bin/utils/object/ObjectGuards.js +0 -19
- package/bin/utils/object/ObjectGuards.js.map +0 -1
- package/bin/utils/path/AncestorFiles.d.ts +0 -17
- package/bin/utils/path/AncestorFiles.d.ts.map +0 -1
- package/bin/utils/path/AncestorFiles.js +0 -36
- package/bin/utils/path/AncestorFiles.js.map +0 -1
- package/bin/utils/storage/index.d.ts +0 -4
- package/bin/utils/storage/index.d.ts.map +0 -1
- package/bin/utils/storage/index.js +0 -17
- package/bin/utils/storage/index.js.map +0 -1
- package/bin/utils/string/EscapeRegExp.d.ts +0 -17
- package/bin/utils/string/EscapeRegExp.d.ts.map +0 -1
- package/bin/utils/string/EscapeRegExp.js +0 -19
- package/bin/utils/string/EscapeRegExp.js.map +0 -1
- package/bin/workspace/LocalFileSystem.d.ts +0 -44
- package/bin/workspace/LocalFileSystem.d.ts.map +0 -1
- package/bin/workspace/LocalFileSystem.js +0 -153
- package/bin/workspace/LocalFileSystem.js.map +0 -1
- package/bin/workspace/Workspace.d.ts +0 -53
- package/bin/workspace/Workspace.d.ts.map +0 -1
- package/bin/workspace/Workspace.js +0 -151
- package/bin/workspace/Workspace.js.map +0 -1
- package/bin/workspace/WorkspaceBase.d.ts +0 -41
- package/bin/workspace/WorkspaceBase.d.ts.map +0 -1
- package/bin/workspace/WorkspaceBase.js +0 -19
- package/bin/workspace/WorkspaceBase.js.map +0 -1
- package/bin/workspace/WorkspaceEnv.d.ts +0 -19
- package/bin/workspace/WorkspaceEnv.d.ts.map +0 -1
- package/bin/workspace/WorkspaceEnv.js +0 -50
- package/bin/workspace/WorkspaceEnv.js.map +0 -1
- package/bin/workspace/file/FileActionRuntime.d.ts +0 -14
- package/bin/workspace/file/FileActionRuntime.d.ts.map +0 -1
- package/bin/workspace/file/FileActionRuntime.js +0 -386
- package/bin/workspace/file/FileActionRuntime.js.map +0 -1
- package/bin/workspace/file/FileAtomicWriter.d.ts +0 -20
- package/bin/workspace/file/FileAtomicWriter.d.ts.map +0 -1
- package/bin/workspace/file/FileAtomicWriter.js +0 -50
- package/bin/workspace/file/FileAtomicWriter.js.map +0 -1
- package/bin/workspace/file/FileEncoding.d.ts +0 -34
- package/bin/workspace/file/FileEncoding.d.ts.map +0 -1
- package/bin/workspace/file/FileEncoding.js +0 -152
- package/bin/workspace/file/FileEncoding.js.map +0 -1
- package/bin/workspace/file/FilePathPolicy.d.ts +0 -26
- package/bin/workspace/file/FilePathPolicy.d.ts.map +0 -1
- package/bin/workspace/file/FilePathPolicy.js +0 -134
- package/bin/workspace/file/FilePathPolicy.js.map +0 -1
- package/bin/workspace/file/FileToolError.d.ts +0 -30
- package/bin/workspace/file/FileToolError.d.ts.map +0 -1
- package/bin/workspace/file/FileToolError.js +0 -78
- package/bin/workspace/file/FileToolError.js.map +0 -1
- package/bin/workspace/search/SearchActionRuntime.d.ts +0 -14
- package/bin/workspace/search/SearchActionRuntime.d.ts.map +0 -1
- package/bin/workspace/search/SearchActionRuntime.js +0 -359
- package/bin/workspace/search/SearchActionRuntime.js.map +0 -1
- package/bin/workspace/search/SearchToolError.d.ts +0 -26
- package/bin/workspace/search/SearchToolError.d.ts.map +0 -1
- package/bin/workspace/search/SearchToolError.js +0 -76
- package/bin/workspace/search/SearchToolError.js.map +0 -1
- package/bin/workspace/store/LocalAgentStore.d.ts +0 -43
- package/bin/workspace/store/LocalAgentStore.d.ts.map +0 -1
- package/bin/workspace/store/LocalAgentStore.js +0 -135
- package/bin/workspace/store/LocalAgentStore.js.map +0 -1
- package/bin/workspace/tool/FileToolSchemas.d.ts +0 -35
- package/bin/workspace/tool/FileToolSchemas.d.ts.map +0 -1
- package/bin/workspace/tool/FileToolSchemas.js +0 -73
- package/bin/workspace/tool/FileToolSchemas.js.map +0 -1
- package/bin/workspace/tool/FileTools.d.ts +0 -11
- package/bin/workspace/tool/FileTools.d.ts.map +0 -1
- package/bin/workspace/tool/FileTools.js +0 -61
- package/bin/workspace/tool/FileTools.js.map +0 -1
- package/bin/workspace/tool/SearchToolSchemas.d.ts +0 -24
- package/bin/workspace/tool/SearchToolSchemas.d.ts.map +0 -1
- package/bin/workspace/tool/SearchToolSchemas.js +0 -60
- package/bin/workspace/tool/SearchToolSchemas.js.map +0 -1
- package/bin/workspace/tool/SearchTools.d.ts +0 -11
- package/bin/workspace/tool/SearchTools.d.ts.map +0 -1
- package/bin/workspace/tool/SearchTools.js +0 -38
- package/bin/workspace/tool/SearchTools.js.map +0 -1
- package/bin/workspace/tool/WorkspaceTools.d.ts +0 -11
- package/bin/workspace/tool/WorkspaceTools.d.ts.map +0 -1
- package/bin/workspace/tool/WorkspaceTools.js +0 -22
- package/bin/workspace/tool/WorkspaceTools.js.map +0 -1
- package/scripts/core-engine-ui-stream-collector.test.mjs +0 -38
- package/scripts/openai-responses-continuation.test.mjs +0 -78
- package/src/agent/AgentState.ts +0 -96
- package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +0 -136
- package/src/executor/messages/SessionMessageCodec.ts +0 -106
- package/src/executor/messages/SessionStepEventMapper.ts +0 -191
- package/src/executor/messages/UIMessageTransformer.ts +0 -152
- package/src/executor/messages/UserVisibleText.ts +0 -75
- package/src/executor/types/SessionRecords.ts +0 -217
- package/src/plugin/core/PluginActionRunner.ts +0 -36
- package/src/session/messages/SessionMessageCodec.ts +0 -495
- package/src/types/agent/AgentState.ts +0 -22
- package/src/types/store/AgentStore.ts +0 -52
- package/src/types/workspace/FileSystem.ts +0 -76
- package/src/types/workspace/FileTool.ts +0 -225
- package/src/types/workspace/SearchTool.ts +0 -156
- package/src/types/workspace/Workspace.ts +0 -27
- package/src/types/workspace/WorkspaceEnv.ts +0 -19
- package/src/types/workspace/WorkspaceTools.ts +0 -23
- package/src/utils/cli/CliOutput.ts +0 -128
- package/src/utils/cli/PrettyStatus.ts +0 -94
- package/src/utils/logger/FormatRequest.ts +0 -455
- package/src/utils/logger/FormatResponse.ts +0 -265
- package/src/utils/logger/FormatShared.ts +0 -258
- package/src/utils/object/DeepMerge.ts +0 -40
- package/src/utils/object/ObjectGuards.ts +0 -19
- package/src/utils/path/AncestorFiles.ts +0 -40
- package/src/utils/storage/index.ts +0 -19
- package/src/utils/string/EscapeRegExp.ts +0 -19
- package/src/workspace/LocalFileSystem.ts +0 -209
- package/src/workspace/Workspace.ts +0 -178
- package/src/workspace/WorkspaceBase.ts +0 -62
- package/src/workspace/WorkspaceEnv.ts +0 -54
- package/src/workspace/file/FileActionRuntime.ts +0 -433
- package/src/workspace/file/FileAtomicWriter.ts +0 -61
- package/src/workspace/file/FileEncoding.ts +0 -175
- package/src/workspace/file/FilePathPolicy.ts +0 -162
- package/src/workspace/file/FileToolError.ts +0 -99
- package/src/workspace/search/SearchActionRuntime.ts +0 -438
- package/src/workspace/search/SearchToolError.ts +0 -94
- package/src/workspace/store/LocalAgentStore.ts +0 -191
- package/src/workspace/tool/FileToolSchemas.ts +0 -77
- package/src/workspace/tool/FileTools.ts +0 -91
- package/src/workspace/tool/SearchToolSchemas.ts +0 -62
- package/src/workspace/tool/SearchTools.ts +0 -61
- package/src/workspace/tool/WorkspaceTools.ts +0 -31
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* City:Workspace、Embassy 与统一 transport 的资源容器。
|
|
3
|
+
*
|
|
4
|
+
* City 不创建 Agent、Session 或 Plugin。应用创建 Agent 后通过
|
|
5
|
+
* `city.agents.add(agent)` 加入当前容器;City 管理 Agent 集合、Workspace/Embassy
|
|
6
|
+
* 资源与统一 transport。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Agent } from "@/agent/Agent.js";
|
|
10
|
+
import { Group } from "@/group/Group.js";
|
|
11
|
+
import {
|
|
12
|
+
attach_agent_city,
|
|
13
|
+
attach_agent_storage,
|
|
14
|
+
attach_group_storage,
|
|
15
|
+
detach_group_storage,
|
|
16
|
+
create_workspace_entry,
|
|
17
|
+
detach_agent_city,
|
|
18
|
+
get_workspace_entry,
|
|
19
|
+
} from "@/internal/index.js";
|
|
20
|
+
import type { WorkspaceEntry } from "@/agent/WorkspaceEntry.js";
|
|
21
|
+
import type { WorkspaceBase } from "@downcity/workspace";
|
|
22
|
+
import type { StorageProvider } from "@downcity/workspace";
|
|
23
|
+
import { MemoryStorageProvider } from "@downcity/workspace";
|
|
24
|
+
import { CityHTTP } from "@/city/transport/http/CityHTTP.js";
|
|
25
|
+
import { CityRPC } from "@/city/transport/rpc/CityRPC.js";
|
|
26
|
+
import type {
|
|
27
|
+
CityAgents,
|
|
28
|
+
CityGroups,
|
|
29
|
+
CityListenOptions,
|
|
30
|
+
CityOptions,
|
|
31
|
+
CityRuntimeOptions,
|
|
32
|
+
CityWorkspaces,
|
|
33
|
+
} from "@/city/types/City.js";
|
|
34
|
+
|
|
35
|
+
/** Agent 实例索引与 transport 宿主。 */
|
|
36
|
+
export class City {
|
|
37
|
+
/** City 持有的底层 Storage;默认是进程内存储。 */
|
|
38
|
+
readonly storage: StorageProvider;
|
|
39
|
+
/** 当前 City 引用的 Agent,按稳定 ID 索引。 */
|
|
40
|
+
private readonly agents_by_id = new Map<string, Agent>();
|
|
41
|
+
|
|
42
|
+
/** 当前 City 引用的 Group,按稳定 ID 索引。 */
|
|
43
|
+
private readonly groups_by_id = new Map<string, Group>();
|
|
44
|
+
|
|
45
|
+
/** City 面向应用的 Agent 集合入口。 */
|
|
46
|
+
readonly agents: CityAgents;
|
|
47
|
+
|
|
48
|
+
/** City 面向宿主的 Group 集合入口。 */
|
|
49
|
+
readonly groups: CityGroups;
|
|
50
|
+
|
|
51
|
+
/** City 面向宿主的 Workspace 集合入口。 */
|
|
52
|
+
readonly workspaces: CityWorkspaces;
|
|
53
|
+
|
|
54
|
+
/** City 持有的 Workspace 资源,按稳定 ID 索引。 */
|
|
55
|
+
private readonly workspaces_by_id = new Map<string, WorkspaceBase>();
|
|
56
|
+
|
|
57
|
+
/** City 绑定的 Embassy 服务入口。 */
|
|
58
|
+
readonly embassy?: CityOptions["embassy"];
|
|
59
|
+
|
|
60
|
+
/** 正在解除注册的 Agent;对查询立即不可见,失败后恢复可见。 */
|
|
61
|
+
private readonly removing_agent_ids = new Set<string>();
|
|
62
|
+
|
|
63
|
+
/** 每个 Agent 当前唯一的解除注册流程。 */
|
|
64
|
+
private readonly removal_promises = new Map<string, Promise<Agent | null>>();
|
|
65
|
+
|
|
66
|
+
/** 宿主提供的按需 Workspace 创建能力。 */
|
|
67
|
+
private readonly resolve_workspace?: CityRuntimeOptions["resolve_workspace"];
|
|
68
|
+
|
|
69
|
+
/** 相同 Agent/Workspace 目标当前唯一的进入流程。 */
|
|
70
|
+
private readonly workspace_entry_promises = new Map<string, Promise<WorkspaceEntry>>();
|
|
71
|
+
|
|
72
|
+
/** 当前 City 唯一的 HTTP transport。 */
|
|
73
|
+
private readonly http_transport: CityHTTP;
|
|
74
|
+
|
|
75
|
+
/** 当前 City 唯一的 RPC transport。 */
|
|
76
|
+
private readonly rpc_transport: CityRPC;
|
|
77
|
+
|
|
78
|
+
/** City transport 组合操作的唯一串行链。 */
|
|
79
|
+
private transport_operation_chain: Promise<void> = Promise.resolve();
|
|
80
|
+
|
|
81
|
+
/** City 自身的生命周期状态。 */
|
|
82
|
+
private city_status: "active" | "closing" | "closed" = "active";
|
|
83
|
+
|
|
84
|
+
/** City 关闭流程;并发调用共享同一个 Promise。 */
|
|
85
|
+
private close_promise?: Promise<void>;
|
|
86
|
+
|
|
87
|
+
constructor(options: CityOptions = {}) {
|
|
88
|
+
this.storage = options.storage || new MemoryStorageProvider();
|
|
89
|
+
this.embassy = options.embassy;
|
|
90
|
+
for (const workspace of options.workspaces ?? []) {
|
|
91
|
+
const workspace_id = String(workspace?.id || "").trim();
|
|
92
|
+
if (!workspace_id) throw new Error("City requires Workspace with a stable id");
|
|
93
|
+
if (this.workspaces_by_id.has(workspace_id)) {
|
|
94
|
+
throw new Error(`Workspace already exists in City: ${workspace_id}`);
|
|
95
|
+
}
|
|
96
|
+
this.bind_workspace_shell(workspace);
|
|
97
|
+
this.workspaces_by_id.set(workspace_id, workspace);
|
|
98
|
+
}
|
|
99
|
+
const runtime_options = options.runtime ?? {};
|
|
100
|
+
this.resolve_workspace = runtime_options.resolve_workspace;
|
|
101
|
+
this.http_transport = new CityHTTP(this, runtime_options.http);
|
|
102
|
+
this.rpc_transport = new CityRPC(this, runtime_options.rpc);
|
|
103
|
+
this.agents = Object.freeze({
|
|
104
|
+
add: (agent) => this.add_agent(agent),
|
|
105
|
+
get: (agent_id) => this.get_agent(agent_id),
|
|
106
|
+
list: () => this.list_agents(),
|
|
107
|
+
remove: async (agent_id) => await this.remove_agent(agent_id),
|
|
108
|
+
});
|
|
109
|
+
this.groups = Object.freeze({
|
|
110
|
+
add: (group: Group) => this.add_group(group),
|
|
111
|
+
get: (group_id: string) => this.get_group(group_id),
|
|
112
|
+
list: () => this.list_groups(),
|
|
113
|
+
remove: async (group_id: string) => await this.remove_group(group_id),
|
|
114
|
+
});
|
|
115
|
+
this.workspaces = Object.freeze({
|
|
116
|
+
add: (workspace) => this.add_workspace(workspace),
|
|
117
|
+
get: (workspace_id) => this.get_workspace(workspace_id),
|
|
118
|
+
list: () => this.list_workspaces(),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 按稳定 ID 获取 City 管理的 Group。 */
|
|
123
|
+
private get_group(group_id_input: string): Group | null {
|
|
124
|
+
return this.groups_by_id.get(String(group_id_input || "").trim()) ?? null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 返回 City 管理的 Group 稳定快照。 */
|
|
128
|
+
private list_groups(): readonly Group[] {
|
|
129
|
+
return [...this.groups_by_id.values()];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 将已创建 Group 加入 City,并校验成员属于当前 City。 */
|
|
133
|
+
private add_group(group: Group): Group {
|
|
134
|
+
this.assert_active();
|
|
135
|
+
if (!group?.id) throw new Error("City requires a Group with a stable ID");
|
|
136
|
+
const existing = this.groups_by_id.get(group.id);
|
|
137
|
+
if (existing && existing !== group) throw new Error(`Group already exists in City: ${group.id}`);
|
|
138
|
+
if (existing) return existing;
|
|
139
|
+
for (const member of group.members) {
|
|
140
|
+
if (this.agents_by_id.get(member.id) !== member) {
|
|
141
|
+
throw new Error(`Group member is not registered in City: ${member.id}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
attach_group_storage(group, this.storage, this);
|
|
145
|
+
this.groups_by_id.set(group.id, group);
|
|
146
|
+
return group;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 释放并移除一个 Group。 */
|
|
150
|
+
private async remove_group(group_id_input: string): Promise<Group | null> {
|
|
151
|
+
const group_id = String(group_id_input || "").trim();
|
|
152
|
+
const group = this.groups_by_id.get(group_id) ?? null;
|
|
153
|
+
if (!group) return null;
|
|
154
|
+
await group.dispose();
|
|
155
|
+
await detach_group_storage(group, this);
|
|
156
|
+
this.groups_by_id.delete(group_id);
|
|
157
|
+
return group;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 返回 City 持有的 Workspace;不存在时返回 null。 */
|
|
161
|
+
/** 内部 AgentCity 协议;用户应使用 `city.workspaces.get()`。 */
|
|
162
|
+
get_workspace(workspace_id_input: string): WorkspaceBase | null {
|
|
163
|
+
const workspace_id = String(workspace_id_input || "").trim();
|
|
164
|
+
return this.workspaces_by_id.get(workspace_id) ?? null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 返回 City 持有的 Workspace 稳定快照。 */
|
|
168
|
+
private list_workspaces(): readonly WorkspaceBase[] {
|
|
169
|
+
return [...this.workspaces_by_id.values()];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** 返回当前 City 已注册 Agent 的稳定快照。 */
|
|
173
|
+
private list_agents(): readonly Agent[] {
|
|
174
|
+
return [...this.agents_by_id.entries()]
|
|
175
|
+
.filter(([agent_id]) => !this.removing_agent_ids.has(agent_id))
|
|
176
|
+
.map(([, agent]) => agent);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 按稳定 ID 返回可直接使用的 Agent;不存在时返回 null。 */
|
|
180
|
+
private get_agent(agent_id_input: string): Agent | null {
|
|
181
|
+
const agent_id = String(agent_id_input || "").trim();
|
|
182
|
+
if (this.removing_agent_ids.has(agent_id)) return null;
|
|
183
|
+
return this.agents_by_id.get(agent_id) ?? null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** 按稳定 ID 返回内部 transport 所需 Agent;不存在时抛出明确错误。 */
|
|
187
|
+
private require_agent(agent_id_input: string): Agent {
|
|
188
|
+
const agent_id = String(agent_id_input || "").trim();
|
|
189
|
+
const agent = this.get_agent(agent_id);
|
|
190
|
+
if (!agent) throw new Error(`Agent not found in City: ${agent_id}`);
|
|
191
|
+
return agent;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 按 Agent ID 与 Workspace ID 返回 transport 所需的明确执行作用域。 */
|
|
195
|
+
require_workspace(agent_id_input: string, workspace_id_input: string): WorkspaceEntry {
|
|
196
|
+
const agent = this.require_agent(agent_id_input);
|
|
197
|
+
const workspace_id = String(workspace_id_input || "").trim();
|
|
198
|
+
if (!workspace_id) throw new Error("City request requires workspace_id");
|
|
199
|
+
const entry = get_workspace_entry(agent, workspace_id);
|
|
200
|
+
if (!entry) {
|
|
201
|
+
throw new Error(`Agent "${agent.id}" has not entered Workspace: ${workspace_id}`);
|
|
202
|
+
}
|
|
203
|
+
return entry;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** 按需解析并进入 Workspace;相同目标的并发请求共享一次创建流程。 */
|
|
207
|
+
async enter_workspace(
|
|
208
|
+
agent_id_input: string,
|
|
209
|
+
workspace_id_input: string,
|
|
210
|
+
): Promise<WorkspaceEntry> {
|
|
211
|
+
const agent = this.require_agent(agent_id_input);
|
|
212
|
+
const workspace_id = String(workspace_id_input || "").trim();
|
|
213
|
+
if (!workspace_id) throw new Error("City request requires workspace_id");
|
|
214
|
+
const existing = get_workspace_entry(agent, workspace_id);
|
|
215
|
+
if (existing) return existing;
|
|
216
|
+
const city_workspace = this.get_workspace(workspace_id);
|
|
217
|
+
if (city_workspace) return create_workspace_entry(agent, city_workspace);
|
|
218
|
+
if (!this.resolve_workspace) {
|
|
219
|
+
throw new Error(`Agent "${agent.id}" has not entered Workspace: ${workspace_id}`);
|
|
220
|
+
}
|
|
221
|
+
const target_key = `${agent.id}/${workspace_id}`;
|
|
222
|
+
const current = this.workspace_entry_promises.get(target_key);
|
|
223
|
+
if (current) return await current;
|
|
224
|
+
const entry_promise = (async () => {
|
|
225
|
+
const workspace = await this.resolve_workspace!(agent, workspace_id);
|
|
226
|
+
if (workspace.id !== workspace_id) {
|
|
227
|
+
await workspace.dispose().catch(() => undefined);
|
|
228
|
+
throw new Error(
|
|
229
|
+
`Resolved Workspace ID mismatch: expected ${workspace_id}, received ${workspace.id}`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
this.add_workspace(workspace);
|
|
233
|
+
return create_workspace_entry(agent, workspace);
|
|
234
|
+
})();
|
|
235
|
+
this.workspace_entry_promises.set(target_key, entry_promise);
|
|
236
|
+
try {
|
|
237
|
+
return await entry_promise;
|
|
238
|
+
} finally {
|
|
239
|
+
if (this.workspace_entry_promises.get(target_key) === entry_promise) {
|
|
240
|
+
this.workspace_entry_promises.delete(target_key);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** 停止、释放并从 City 移除指定 Agent。 */
|
|
246
|
+
private async remove_agent(agent_id_input: string): Promise<Agent | null> {
|
|
247
|
+
const agent_id = String(agent_id_input || "").trim();
|
|
248
|
+
const existing_removal = this.removal_promises.get(agent_id);
|
|
249
|
+
if (existing_removal) return await existing_removal;
|
|
250
|
+
const agent = this.agents_by_id.get(agent_id) ?? null;
|
|
251
|
+
if (!agent) return null;
|
|
252
|
+
this.removing_agent_ids.add(agent_id);
|
|
253
|
+
const removal = (async () => {
|
|
254
|
+
try {
|
|
255
|
+
await this.http_transport.detach_agent(agent_id);
|
|
256
|
+
const dependent_groups = [...this.groups_by_id.values()]
|
|
257
|
+
.filter((group) => group.members.some((member) => member === agent));
|
|
258
|
+
await Promise.allSettled(dependent_groups.map(async (group) => {
|
|
259
|
+
await group.dispose();
|
|
260
|
+
this.groups_by_id.delete(group.id);
|
|
261
|
+
}));
|
|
262
|
+
await agent.dispose();
|
|
263
|
+
this.release_agent(agent);
|
|
264
|
+
return agent;
|
|
265
|
+
} finally {
|
|
266
|
+
this.removing_agent_ids.delete(agent_id);
|
|
267
|
+
}
|
|
268
|
+
})();
|
|
269
|
+
this.removal_promises.set(agent_id, removal);
|
|
270
|
+
try {
|
|
271
|
+
return await removal;
|
|
272
|
+
} finally {
|
|
273
|
+
if (this.removal_promises.get(agent_id) === removal) {
|
|
274
|
+
this.removal_promises.delete(agent_id);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** 启动 City 唯一的 HTTP/RPC transport。 */
|
|
280
|
+
async http(options: Parameters<CityHTTP["listen"]>[0]): Promise<CityHTTP> {
|
|
281
|
+
this.assert_active();
|
|
282
|
+
await this.enqueue_transport_operation(async () => {
|
|
283
|
+
await this.http_transport.listen(options);
|
|
284
|
+
});
|
|
285
|
+
return this.http_transport;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** 启动 City 唯一的 RPC transport。 */
|
|
289
|
+
async rpc(options?: Parameters<CityRPC["listen"]>[0]): Promise<CityRPC> {
|
|
290
|
+
this.assert_active();
|
|
291
|
+
await this.enqueue_transport_operation(async () => {
|
|
292
|
+
await this.rpc_transport.listen(options);
|
|
293
|
+
});
|
|
294
|
+
return this.rpc_transport;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** 启动 City 唯一的 HTTP/RPC transport。 */
|
|
298
|
+
async listen(options: CityListenOptions): Promise<void> {
|
|
299
|
+
this.assert_active();
|
|
300
|
+
await this.enqueue_transport_operation(async () => {
|
|
301
|
+
const started: Array<() => Promise<void>> = [];
|
|
302
|
+
try {
|
|
303
|
+
if (options.rpc) {
|
|
304
|
+
const was_listening = Boolean(this.rpc_transport.binding());
|
|
305
|
+
await this.rpc_transport.listen(options.rpc);
|
|
306
|
+
if (!was_listening) started.push(async () => await this.rpc_transport.close());
|
|
307
|
+
}
|
|
308
|
+
if (options.http) {
|
|
309
|
+
const was_listening = Boolean(this.http_transport.binding());
|
|
310
|
+
await this.http_transport.listen(options.http);
|
|
311
|
+
if (!was_listening) started.push(async () => await this.http_transport.close());
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
await Promise.allSettled(started.reverse().map(async (close) => await close()));
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** 幂等关闭 transport,并按依赖顺序释放绑定 Agent 与 City Workspace。 */
|
|
321
|
+
async close(): Promise<void> {
|
|
322
|
+
if (this.city_status === "closed") return;
|
|
323
|
+
if (!this.close_promise) {
|
|
324
|
+
const close_operation = this.enqueue_transport_operation(async () => {
|
|
325
|
+
this.city_status = "closing";
|
|
326
|
+
const results: PromiseSettledResult<unknown>[] = [];
|
|
327
|
+
results.push(...await Promise.allSettled([
|
|
328
|
+
this.http_transport.close(),
|
|
329
|
+
this.rpc_transport.close(),
|
|
330
|
+
]));
|
|
331
|
+
results.push(...await Promise.allSettled(
|
|
332
|
+
[...this.groups_by_id.values()].map(async (group) => {
|
|
333
|
+
await group.dispose();
|
|
334
|
+
await detach_group_storage(group, this);
|
|
335
|
+
}),
|
|
336
|
+
));
|
|
337
|
+
results.push(...await Promise.allSettled(this.agents.list().map(async (agent) => await agent.dispose())));
|
|
338
|
+
results.push(...await Promise.allSettled(
|
|
339
|
+
[...this.workspaces_by_id.values()].map(async (workspace) => await workspace.dispose()),
|
|
340
|
+
));
|
|
341
|
+
results.push(...await Promise.allSettled([
|
|
342
|
+
this.storage.dispose?.() ?? Promise.resolve(),
|
|
343
|
+
]));
|
|
344
|
+
const errors = results.flatMap((result) =>
|
|
345
|
+
result.status === "rejected" ? [result.reason] : [],
|
|
346
|
+
);
|
|
347
|
+
if (errors.length > 0) {
|
|
348
|
+
this.city_status = "active";
|
|
349
|
+
throw new AggregateError(errors, "City transport close failed");
|
|
350
|
+
}
|
|
351
|
+
this.agents_by_id.clear();
|
|
352
|
+
this.groups_by_id.clear();
|
|
353
|
+
this.workspaces_by_id.clear();
|
|
354
|
+
this.city_status = "closed";
|
|
355
|
+
});
|
|
356
|
+
this.close_promise = close_operation.catch((error) => {
|
|
357
|
+
this.close_promise = undefined;
|
|
358
|
+
throw error;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
await this.close_promise;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** 将已创建 Agent 加入集合并建立唯一 City 绑定。 */
|
|
365
|
+
private add_agent(agent: Agent): Agent {
|
|
366
|
+
this.assert_active();
|
|
367
|
+
if (!agent?.id) throw new Error("City requires an Agent with a stable ID");
|
|
368
|
+
if (this.agents_by_id.has(agent.id) || this.removing_agent_ids.has(agent.id)) {
|
|
369
|
+
throw new Error(`Agent already exists in City: ${agent.id}`);
|
|
370
|
+
}
|
|
371
|
+
attach_agent_city(agent, this);
|
|
372
|
+
attach_agent_storage(agent, this.storage);
|
|
373
|
+
this.agents_by_id.set(agent.id, agent);
|
|
374
|
+
return agent;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** Agent 自行释放时清除 City 运行时引用。 */
|
|
378
|
+
release_agent(agent: { readonly id: string }): void {
|
|
379
|
+
const current = this.agents_by_id.get(agent.id);
|
|
380
|
+
if (!current || current !== agent) return;
|
|
381
|
+
detach_agent_city(current, this);
|
|
382
|
+
this.agents_by_id.delete(agent.id);
|
|
383
|
+
void this.http_transport.detach_agent(agent.id).catch(() => undefined);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** 把宿主按需解析出的 Workspace 纳入 City 资源索引。 */
|
|
387
|
+
private add_workspace(workspace: WorkspaceBase): WorkspaceBase {
|
|
388
|
+
this.assert_active();
|
|
389
|
+
const workspace_id = String(workspace?.id || "").trim();
|
|
390
|
+
if (!workspace_id) throw new Error("City requires Workspace with a stable id");
|
|
391
|
+
const existing = this.workspaces_by_id.get(workspace_id);
|
|
392
|
+
if (existing && existing !== workspace) {
|
|
393
|
+
throw new Error(`Workspace already exists in City: ${workspace_id}`);
|
|
394
|
+
}
|
|
395
|
+
if (existing) return existing;
|
|
396
|
+
this.bind_workspace_shell(workspace);
|
|
397
|
+
this.workspaces_by_id.set(workspace_id, workspace);
|
|
398
|
+
return workspace;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** 将 City 的底层 Storage 绑定到 Workspace 的 Shell 运行目录。 */
|
|
402
|
+
private bind_workspace_shell(workspace: WorkspaceBase): void {
|
|
403
|
+
workspace.shell?.bind({
|
|
404
|
+
root_path: workspace.path,
|
|
405
|
+
data_path: this.storage.open_scope(["workspaces", workspace.id, "shell"]).root_path,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** 拒绝在 City 关闭后继续注入运行时资源。 */
|
|
410
|
+
private assert_active(): void {
|
|
411
|
+
if (this.city_status !== "active") {
|
|
412
|
+
throw new Error(`City is ${this.city_status}`);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** 串行执行一次 City transport 组合操作。 */
|
|
417
|
+
private enqueue_transport_operation(operation: () => Promise<void>): Promise<void> {
|
|
418
|
+
const result = this.transport_operation_chain.then(operation);
|
|
419
|
+
this.transport_operation_chain = result.then(
|
|
420
|
+
() => undefined,
|
|
421
|
+
() => undefined,
|
|
422
|
+
);
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 串行 transport 生命周期。
|
|
3
|
+
*
|
|
4
|
+
* 该对象是 HTTP/RPC Server 状态的唯一拥有者。listen 与 close 按调用顺序执行,
|
|
5
|
+
* 因此启动过程中收到 close 时,会先完成启动再立即释放,不会留下失联端口。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { SerializedTransportOptions } from "@/city/types/SerializedTransport.js";
|
|
9
|
+
|
|
10
|
+
/** 管理一个可重复监听和关闭的底层 transport。 */
|
|
11
|
+
export class SerializedTransport<TOptions, TResource, TBinding> {
|
|
12
|
+
/** transport 操作的唯一串行链。 */
|
|
13
|
+
private operation_chain: Promise<void> = Promise.resolve();
|
|
14
|
+
|
|
15
|
+
/** 当前已经成功启动的底层资源。 */
|
|
16
|
+
private current_resource: TResource | null = null;
|
|
17
|
+
|
|
18
|
+
/** 当前监听地址;未监听时为空。 */
|
|
19
|
+
private current_binding: TBinding | null = null;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
/** 创建和释放底层资源的实现。 */
|
|
23
|
+
private readonly options: SerializedTransportOptions<TOptions, TResource, TBinding>,
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
/** 按调用顺序启动 transport;已监听时返回现有 binding。 */
|
|
27
|
+
async listen(options: TOptions): Promise<TBinding> {
|
|
28
|
+
return await this.enqueue(async () => {
|
|
29
|
+
if (this.current_binding) return this.current_binding;
|
|
30
|
+
const started = await this.options.start(options);
|
|
31
|
+
this.current_resource = started.resource;
|
|
32
|
+
this.current_binding = started.binding;
|
|
33
|
+
return started.binding;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 按调用顺序关闭 transport;没有监听时直接完成。 */
|
|
38
|
+
async close(): Promise<void> {
|
|
39
|
+
await this.enqueue(async () => {
|
|
40
|
+
const resource = this.current_resource;
|
|
41
|
+
if (!resource) return;
|
|
42
|
+
await this.options.stop(resource);
|
|
43
|
+
// 释放成功后才提交 stopped 状态;失败时保留句柄,允许调用方重试收口。
|
|
44
|
+
if (this.current_resource === resource) {
|
|
45
|
+
this.current_resource = null;
|
|
46
|
+
this.current_binding = null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 返回当前已完成监听的 binding 快照。 */
|
|
52
|
+
binding(): TBinding | null {
|
|
53
|
+
return this.current_binding;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 将一次状态变化接到唯一操作链,并保证失败后后续操作仍可继续。 */
|
|
57
|
+
private enqueue<TResult>(operation: () => Promise<TResult>): Promise<TResult> {
|
|
58
|
+
const result = this.operation_chain.then(operation);
|
|
59
|
+
this.operation_chain = result.then(
|
|
60
|
+
() => undefined,
|
|
61
|
+
() => undefined,
|
|
62
|
+
);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentHTTP:把本地 Agent 暴露为最小 SDK HTTP 面的对外类。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 仅承载 RemoteAgent 对应的 SDK transport(`/api/sdk/sessions/*`)。
|
|
6
|
+
* - `router()` 返回一个 `Hono` 子路由,调用方 `app.route("/", agent_http.router())` 即可挂载。
|
|
7
|
+
* - `server()` 返回一个独立 HTTP server 句柄,按需自启、自停。
|
|
8
|
+
* - 同一个实例多次取 router/server 都返回缓存对象,避免重复注册。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import http from "node:http";
|
|
12
|
+
import { Hono } from "hono";
|
|
13
|
+
import { create_workspace_entry } from "@/internal/index.js";
|
|
14
|
+
import type { Agent } from "@/agent/Agent.js";
|
|
15
|
+
import type { AgentSessionCollection } from "@/types/agent/AgentSessionCollection.js";
|
|
16
|
+
import type { WorkspaceBase } from "@downcity/workspace";
|
|
17
|
+
import type { AgentPlugins } from "@/types/plugin/PluginRuntime.js";
|
|
18
|
+
import { register_sdk_session_routes } from "@/city/transport/http/routes/SessionRoutes.js";
|
|
19
|
+
import { register_runtime_routes } from "@/city/transport/http/routes/RuntimeRoutes.js";
|
|
20
|
+
import { create_node_http_server } from "@/city/transport/http/NodeHttpAdapter.js";
|
|
21
|
+
import { SerializedTransport } from "@/city/transport/SerializedTransport.js";
|
|
22
|
+
import type {
|
|
23
|
+
AgentHttpBinding,
|
|
24
|
+
AgentHttpListenOptions,
|
|
25
|
+
} from "@/city/transport/types/AgentHttpBinding.js";
|
|
26
|
+
import type { AgentHttpRuntimeOptions } from "@/city/transport/types/AgentHttpRuntime.js";
|
|
27
|
+
|
|
28
|
+
const DEFAULT_HTTP_HOST = "127.0.0.1";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* AgentHTTP server 句柄。
|
|
32
|
+
*/
|
|
33
|
+
export interface AgentHttpServerHandle {
|
|
34
|
+
/** 监听 HTTP 端口。 */
|
|
35
|
+
listen(options: AgentHttpListenOptions): Promise<AgentHttpBinding>;
|
|
36
|
+
/** 关闭当前 HTTP server。 */
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
/** 当前监听绑定信息,未 listen 时为 `null`。 */
|
|
39
|
+
binding(): AgentHttpBinding | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 把一个 `WorkspaceEntry` 暴露为最小 SDK HTTP 面。
|
|
44
|
+
*/
|
|
45
|
+
export class AgentHTTP {
|
|
46
|
+
private readonly agent: Agent;
|
|
47
|
+
private readonly workspace?: WorkspaceBase;
|
|
48
|
+
private readonly plugins: AgentPlugins;
|
|
49
|
+
private readonly session_collection: AgentSessionCollection;
|
|
50
|
+
private readonly runtime_options: AgentHttpRuntimeOptions;
|
|
51
|
+
private cached_router: Hono | null = null;
|
|
52
|
+
private cached_server: AgentHttpServerHandle | null = null;
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
agent_or_workspace: Agent | { agent: Agent; workspace: WorkspaceBase; plugins: AgentPlugins },
|
|
56
|
+
workspace_or_options?: WorkspaceBase | AgentHttpRuntimeOptions,
|
|
57
|
+
runtime_options: AgentHttpRuntimeOptions = {},
|
|
58
|
+
) {
|
|
59
|
+
if (workspace_or_options && "id" in workspace_or_options && "path" in workspace_or_options) {
|
|
60
|
+
const agent = "agent" in agent_or_workspace ? agent_or_workspace.agent : agent_or_workspace;
|
|
61
|
+
this.agent = agent;
|
|
62
|
+
this.workspace = workspace_or_options;
|
|
63
|
+
this.plugins = "agent" in agent_or_workspace
|
|
64
|
+
? agent_or_workspace.plugins
|
|
65
|
+
: create_workspace_entry(agent, workspace_or_options).plugins;
|
|
66
|
+
this.session_collection = create_workspace_entry(agent, workspace_or_options).sessions;
|
|
67
|
+
this.runtime_options = runtime_options;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const entry = agent_or_workspace as { agent?: Agent; workspace?: WorkspaceBase; plugins?: AgentPlugins };
|
|
71
|
+
this.agent = entry.agent || agent_or_workspace as Agent;
|
|
72
|
+
this.workspace = entry.workspace;
|
|
73
|
+
this.plugins = entry.plugins || this.agent.plugins as unknown as AgentPlugins;
|
|
74
|
+
this.session_collection = this.workspace
|
|
75
|
+
? create_workspace_entry(this.agent, this.workspace).sessions
|
|
76
|
+
: this.agent.sessions;
|
|
77
|
+
this.runtime_options = (workspace_or_options as AgentHttpRuntimeOptions | undefined) ?? {};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 返回一个挂载到外部 hono server 用的子路由。
|
|
82
|
+
*
|
|
83
|
+
* 说明(中文)
|
|
84
|
+
* - 多次调用返回同一个 hono 实例,避免重复注册。
|
|
85
|
+
* - 不在这里附加 CORS / logger,由调用方按需在自己的入口 hono 上挂中间件。
|
|
86
|
+
*/
|
|
87
|
+
router(): Hono {
|
|
88
|
+
if (this.cached_router) return this.cached_router;
|
|
89
|
+
const router = new Hono();
|
|
90
|
+
register_sdk_session_routes(router, this.session_collection, this.workspace, {
|
|
91
|
+
resolve_session_model: this.runtime_options.resolve_session_model,
|
|
92
|
+
});
|
|
93
|
+
register_runtime_routes(router, this.plugins);
|
|
94
|
+
this.cached_router = router;
|
|
95
|
+
return router;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 返回独立 HTTP server 句柄。
|
|
100
|
+
*/
|
|
101
|
+
server(): AgentHttpServerHandle {
|
|
102
|
+
if (this.cached_server) return this.cached_server;
|
|
103
|
+
const handle = create_agent_http_server_handle(this.router());
|
|
104
|
+
this.cached_server = handle;
|
|
105
|
+
return handle;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 关闭通过本实例 `server()` 启动的 HTTP server。
|
|
110
|
+
*
|
|
111
|
+
* 说明(中文)
|
|
112
|
+
* - 仅作用于 `server()` 创建的独立 HTTP server。
|
|
113
|
+
* - `router()` 挂到外部 hono 的场景由调用方自己管理生命周期。
|
|
114
|
+
*/
|
|
115
|
+
async close(): Promise<void> {
|
|
116
|
+
const handle = this.cached_server;
|
|
117
|
+
if (!handle) return;
|
|
118
|
+
await handle.close();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 为已装配完成的 Hono Router 创建独立 Node HTTP Server 句柄。 */
|
|
123
|
+
export function create_agent_http_server_handle(app: Hono): AgentHttpServerHandle {
|
|
124
|
+
const lifecycle = new SerializedTransport<
|
|
125
|
+
AgentHttpListenOptions,
|
|
126
|
+
http.Server,
|
|
127
|
+
AgentHttpBinding
|
|
128
|
+
>({
|
|
129
|
+
start: async (options) => {
|
|
130
|
+
const host = String(options.host || DEFAULT_HTTP_HOST).trim() || DEFAULT_HTTP_HOST;
|
|
131
|
+
const port = options.port;
|
|
132
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
133
|
+
throw new Error("AgentHTTP server requires a valid TCP port");
|
|
134
|
+
}
|
|
135
|
+
const server = create_node_http_server({ app, host, port });
|
|
136
|
+
await new Promise<void>((resolve, reject) => {
|
|
137
|
+
const on_error = (error: Error): void => {
|
|
138
|
+
server.off("error", on_error);
|
|
139
|
+
// listen 失败时该 Server 不会进入生命周期对象,立即清理监听器和句柄。
|
|
140
|
+
try {
|
|
141
|
+
server.close();
|
|
142
|
+
} catch {
|
|
143
|
+
// 未进入监听态时 close 可能抛出 ERR_SERVER_NOT_RUNNING,可安全忽略。
|
|
144
|
+
}
|
|
145
|
+
reject(error);
|
|
146
|
+
};
|
|
147
|
+
server.once("error", on_error);
|
|
148
|
+
server.listen(port, host, () => {
|
|
149
|
+
server.off("error", on_error);
|
|
150
|
+
resolve();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
resource: server,
|
|
155
|
+
binding: { url: `http://${host}:${port}`, host, port },
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
stop: async (server) => {
|
|
159
|
+
await new Promise<void>((resolve, reject) => {
|
|
160
|
+
server.close((error) => error ? reject(error) : resolve());
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
async listen(options: AgentHttpListenOptions): Promise<AgentHttpBinding> {
|
|
167
|
+
return await lifecycle.listen(options);
|
|
168
|
+
},
|
|
169
|
+
async close(): Promise<void> {
|
|
170
|
+
await lifecycle.close();
|
|
171
|
+
},
|
|
172
|
+
binding(): AgentHttpBinding | null {
|
|
173
|
+
return lifecycle.binding();
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|