@downcity/agent 1.1.13 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{runtime → core}/AgentContextTypes.d.ts +6 -6
- package/bin/core/AgentContextTypes.d.ts.map +1 -0
- package/bin/{runtime → core}/AgentContextTypes.js +2 -2
- package/bin/core/AgentContextTypes.js.map +1 -0
- package/bin/core/AgentCore.d.ts +87 -0
- package/bin/core/AgentCore.d.ts.map +1 -0
- package/bin/core/AgentCore.js +467 -0
- package/bin/core/AgentCore.js.map +1 -0
- package/bin/{runtime/AgentRuntimeTypes.d.ts → core/AgentCoreTypes.d.ts} +7 -7
- package/bin/core/AgentCoreTypes.d.ts.map +1 -0
- package/bin/core/AgentCoreTypes.js +10 -0
- package/bin/core/AgentCoreTypes.js.map +1 -0
- package/bin/host/runtime/PluginRuntime.d.ts +1 -1
- package/bin/host/runtime/PluginRuntime.d.ts.map +1 -1
- package/bin/index.d.ts +6 -8
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -5
- package/bin/index.js.map +1 -1
- package/bin/plugin/builtins/asr/InboundAugment.d.ts +1 -1
- package/bin/plugin/builtins/asr/InboundAugment.d.ts.map +1 -1
- package/bin/plugin/builtins/auth/runtime/AuthorizationConfig.d.ts +1 -1
- package/bin/plugin/builtins/auth/runtime/AuthorizationConfig.d.ts.map +1 -1
- package/bin/plugin/builtins/auth/runtime/AuthorizationStore.d.ts +1 -1
- package/bin/plugin/builtins/auth/runtime/AuthorizationStore.d.ts.map +1 -1
- package/bin/plugin/builtins/voice/InboundAugment.d.ts +1 -1
- package/bin/plugin/builtins/voice/InboundAugment.d.ts.map +1 -1
- package/bin/plugin/builtins/workboard/runtime/Collector.d.ts +1 -1
- package/bin/plugin/builtins/workboard/runtime/Collector.d.ts.map +1 -1
- package/bin/plugin/builtins/workboard/runtime/Collector.js +1 -1
- package/bin/plugin/builtins/workboard/runtime/Collector.js.map +1 -1
- package/bin/plugin/builtins/workboard/runtime/Normalizer.d.ts +1 -1
- package/bin/plugin/builtins/workboard/runtime/Normalizer.d.ts.map +1 -1
- package/bin/plugin/builtins/workboard/runtime/Store.d.ts +1 -1
- package/bin/plugin/builtins/workboard/runtime/Store.d.ts.map +1 -1
- package/bin/plugin/core/Activation.d.ts +2 -2
- package/bin/plugin/core/Activation.d.ts.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +1 -1
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/HttpRoutes.d.ts +1 -1
- package/bin/plugin/core/HttpRoutes.d.ts.map +1 -1
- package/bin/plugin/core/LocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/LocalExecution.js +18 -20
- package/bin/plugin/core/LocalExecution.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/types/Plugin.d.ts +1 -1
- package/bin/plugin/types/Plugin.d.ts.map +1 -1
- package/bin/sandbox/SandboxConfigResolver.d.ts +1 -1
- package/bin/sandbox/SandboxConfigResolver.d.ts.map +1 -1
- package/bin/sandbox/SandboxRunner.d.ts +1 -1
- package/bin/sandbox/SandboxRunner.d.ts.map +1 -1
- package/bin/sdk/Agent.d.ts +25 -23
- package/bin/sdk/Agent.d.ts.map +1 -1
- package/bin/sdk/Agent.js +86 -365
- package/bin/sdk/Agent.js.map +1 -1
- package/bin/sdk/AgentSdkTypes.d.ts +138 -0
- package/bin/sdk/AgentSdkTypes.d.ts.map +1 -1
- package/bin/sdk/HttpServer.d.ts +9 -19
- package/bin/sdk/HttpServer.d.ts.map +1 -1
- package/bin/sdk/HttpServer.js +26 -156
- package/bin/sdk/HttpServer.js.map +1 -1
- package/bin/sdk/RpcServer.d.ts +9 -10
- package/bin/sdk/RpcServer.d.ts.map +1 -1
- package/bin/sdk/RpcServer.js +22 -178
- package/bin/sdk/RpcServer.js.map +1 -1
- package/bin/sdk/Session.d.ts +2 -2
- package/bin/sdk/Session.d.ts.map +1 -1
- package/bin/sdk/Session.js +7 -1
- package/bin/sdk/Session.js.map +1 -1
- package/bin/sdk/SessionServicePort.d.ts +1 -1
- package/bin/sdk/SessionServicePort.d.ts.map +1 -1
- package/bin/server/http/Server.d.ts +10 -1
- package/bin/server/http/Server.d.ts.map +1 -1
- package/bin/server/http/Server.js +41 -15
- package/bin/server/http/Server.js.map +1 -1
- package/bin/server/http/control/AuthControlService.d.ts +1 -1
- package/bin/server/http/control/AuthControlService.d.ts.map +1 -1
- package/bin/server/http/control/ControlAuthorizationRoutes.d.ts +1 -1
- package/bin/server/http/control/ControlAuthorizationRoutes.d.ts.map +1 -1
- package/bin/server/http/control/ControlRouter.d.ts +18 -2
- package/bin/server/http/control/ControlRouter.d.ts.map +1 -1
- package/bin/server/http/control/ControlRouter.js +10 -8
- package/bin/server/http/control/ControlRouter.js.map +1 -1
- package/bin/server/http/control/ExecuteBySession.d.ts +2 -2
- package/bin/server/http/control/ExecuteBySession.d.ts.map +1 -1
- package/bin/server/http/control/OverviewRoutes.d.ts.map +1 -1
- package/bin/server/http/control/OverviewRoutes.js +6 -2
- package/bin/server/http/control/OverviewRoutes.js.map +1 -1
- package/bin/server/http/control/SessionSummaryStore.d.ts +1 -1
- package/bin/server/http/control/SessionSummaryStore.d.ts.map +1 -1
- package/bin/server/http/control/types/ControlRoutes.d.ts +2 -2
- package/bin/server/http/control/types/ControlRoutes.d.ts.map +1 -1
- package/bin/server/http/execute/execute.d.ts +13 -2
- package/bin/server/http/execute/execute.d.ts.map +1 -1
- package/bin/server/http/execute/execute.js +73 -71
- package/bin/server/http/execute/execute.js.map +1 -1
- package/bin/server/http/plugins/plugins.d.ts +13 -2
- package/bin/server/http/plugins/plugins.d.ts.map +1 -1
- package/bin/server/http/plugins/plugins.js +42 -40
- package/bin/server/http/plugins/plugins.js.map +1 -1
- package/bin/server/http/services/services.d.ts +12 -8
- package/bin/server/http/services/services.d.ts.map +1 -1
- package/bin/server/http/services/services.js +57 -64
- package/bin/server/http/services/services.js.map +1 -1
- package/bin/server/http/static/static.d.ts +13 -2
- package/bin/server/http/static/static.d.ts.map +1 -1
- package/bin/server/http/static/static.js +81 -79
- package/bin/server/http/static/static.js.map +1 -1
- package/bin/server/rpc/Server.d.ts +5 -3
- package/bin/server/rpc/Server.d.ts.map +1 -1
- package/bin/server/rpc/Server.js +22 -12
- package/bin/server/rpc/Server.js.map +1 -1
- package/bin/service/builtins/BaseService.d.ts +2 -2
- package/bin/service/builtins/BaseService.d.ts.map +1 -1
- package/bin/service/builtins/chat/Action.d.ts +1 -1
- package/bin/service/builtins/chat/Action.d.ts.map +1 -1
- package/bin/service/builtins/chat/ChatService.d.ts +2 -2
- package/bin/service/builtins/chat/ChatService.d.ts.map +1 -1
- package/bin/service/builtins/chat/ChatServiceTypes.d.ts +1 -1
- package/bin/service/builtins/chat/ChatServiceTypes.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/BaseChatChannel.d.ts +1 -1
- package/bin/service/builtins/chat/channels/BaseChatChannel.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/BaseChatChannelQueue.d.ts +1 -1
- package/bin/service/builtins/chat/channels/BaseChatChannelQueue.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/BaseChatChannelSupport.d.ts +1 -1
- package/bin/service/builtins/chat/channels/BaseChatChannelSupport.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/feishu/Feishu.d.ts +1 -1
- package/bin/service/builtins/chat/channels/feishu/Feishu.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/feishu/FeishuMessageHandler.d.ts +1 -1
- package/bin/service/builtins/chat/channels/feishu/FeishuMessageHandler.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/feishu/FeishuPlatformClient.d.ts +1 -1
- package/bin/service/builtins/chat/channels/feishu/FeishuPlatformClient.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/qq/QQ.d.ts +1 -1
- package/bin/service/builtins/chat/channels/qq/QQ.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/qq/QQMessageHandler.d.ts +1 -1
- package/bin/service/builtins/chat/channels/qq/QQMessageHandler.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/qq/QQSupport.d.ts +1 -1
- package/bin/service/builtins/chat/channels/qq/QQSupport.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/telegram/Bot.d.ts +1 -1
- package/bin/service/builtins/chat/channels/telegram/Bot.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/telegram/TelegramMessageHandler.d.ts +1 -1
- package/bin/service/builtins/chat/channels/telegram/TelegramMessageHandler.d.ts.map +1 -1
- package/bin/service/builtins/chat/channels/telegram/TelegramPlatformClient.d.ts +1 -1
- package/bin/service/builtins/chat/channels/telegram/TelegramPlatformClient.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChannelContextStore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChannelContextStore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatActionExecution.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatActionExecution.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatActionInput.d.ts +3 -36
- package/bin/service/builtins/chat/runtime/ChatActionInput.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatActionInput.js +3 -118
- package/bin/service/builtins/chat/runtime/ChatActionInput.js.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelActions.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelActions.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelConfig.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelLifecycle.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelLifecycle.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatHistoryStore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatHistoryStore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatIngressStore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatIngressStore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatMetaStore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatMetaStore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueReplyDispatch.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueReplyDispatch.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueSessionBridge.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueSessionBridge.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueStore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueStore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueWorker.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatQueueWorker.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatServiceActions.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatServiceActions.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatServiceActions.js +2 -109
- package/bin/service/builtins/chat/runtime/ChatServiceActions.js.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatServiceSystem.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatServiceSystem.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatSessionDelete.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatSessionDelete.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatkeySend.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatkeySend.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/EnqueueDispatch.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/EnqueueDispatch.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/InboundAugment.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/InboundAugment.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/PluginDispatch.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/PluginDispatch.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ReplyDispatch.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ReplyDispatch.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/SystemPrompt.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/SystemPrompt.d.ts.map +1 -1
- package/bin/service/builtins/contact/Action.d.ts +2 -2
- package/bin/service/builtins/contact/Action.d.ts.map +1 -1
- package/bin/service/builtins/contact/Action.js +2 -58
- package/bin/service/builtins/contact/Action.js.map +1 -1
- package/bin/service/builtins/contact/ContactService.d.ts +1 -1
- package/bin/service/builtins/contact/ContactService.d.ts.map +1 -1
- package/bin/service/builtins/contact/runtime/ChatRuntime.d.ts +1 -1
- package/bin/service/builtins/contact/runtime/ChatRuntime.d.ts.map +1 -1
- package/bin/service/builtins/contact/runtime/ContactPayload.d.ts +0 -7
- package/bin/service/builtins/contact/runtime/ContactPayload.d.ts.map +1 -1
- package/bin/service/builtins/contact/runtime/ContactPayload.js +0 -9
- package/bin/service/builtins/contact/runtime/ContactPayload.js.map +1 -1
- package/bin/service/builtins/contact/runtime/RemoteClient.d.ts +1 -1
- package/bin/service/builtins/contact/runtime/RemoteClient.d.ts.map +1 -1
- package/bin/service/builtins/contact/runtime/RemoteClient.js +37 -19
- package/bin/service/builtins/contact/runtime/RemoteClient.js.map +1 -1
- package/bin/service/builtins/contact/runtime/ShareBundle.d.ts +1 -1
- package/bin/service/builtins/contact/runtime/ShareBundle.d.ts.map +1 -1
- package/bin/service/builtins/memory/Action.d.ts +1 -1
- package/bin/service/builtins/memory/Action.d.ts.map +1 -1
- package/bin/service/builtins/memory/MemoryService.d.ts +1 -1
- package/bin/service/builtins/memory/MemoryService.d.ts.map +1 -1
- package/bin/service/builtins/memory/MemoryService.js +0 -27
- package/bin/service/builtins/memory/MemoryService.js.map +1 -1
- package/bin/service/builtins/memory/runtime/Flush.d.ts +1 -1
- package/bin/service/builtins/memory/runtime/Flush.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/Search.d.ts +1 -1
- package/bin/service/builtins/memory/runtime/Search.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/Store.d.ts +1 -1
- package/bin/service/builtins/memory/runtime/Store.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/SystemProvider.d.ts +1 -1
- package/bin/service/builtins/memory/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/Writer.d.ts +1 -1
- package/bin/service/builtins/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/service/builtins/schedule/ScheduleService.d.ts +39 -0
- package/bin/service/builtins/schedule/ScheduleService.d.ts.map +1 -0
- package/bin/service/builtins/schedule/ScheduleService.js +106 -0
- package/bin/service/builtins/schedule/ScheduleService.js.map +1 -0
- package/bin/service/builtins/shell/ShellRuntimeTypes.d.ts +1 -1
- package/bin/service/builtins/shell/ShellRuntimeTypes.d.ts.map +1 -1
- package/bin/service/builtins/shell/ShellService.d.ts +2 -2
- package/bin/service/builtins/shell/ShellService.d.ts.map +1 -1
- package/bin/service/builtins/shell/runtime/ShellActionResponse.d.ts +1 -1
- package/bin/service/builtins/shell/runtime/ShellActionResponse.d.ts.map +1 -1
- package/bin/service/builtins/shell/runtime/ShellActionRuntime.d.ts +1 -1
- package/bin/service/builtins/shell/runtime/ShellActionRuntime.d.ts.map +1 -1
- package/bin/service/builtins/shell/runtime/ShellActionRuntimeSupport.d.ts +1 -1
- package/bin/service/builtins/shell/runtime/ShellActionRuntimeSupport.d.ts.map +1 -1
- package/bin/service/builtins/shell/runtime/ShellRuntimeEnvironment.d.ts +1 -1
- package/bin/service/builtins/shell/runtime/ShellRuntimeEnvironment.d.ts.map +1 -1
- package/bin/service/builtins/task/Action.d.ts +1 -1
- package/bin/service/builtins/task/Action.d.ts.map +1 -1
- package/bin/service/builtins/task/Scheduler.d.ts +1 -1
- package/bin/service/builtins/task/Scheduler.d.ts.map +1 -1
- package/bin/service/builtins/task/TaskService.d.ts +2 -2
- package/bin/service/builtins/task/TaskService.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/CronRuntime.d.ts +1 -1
- package/bin/service/builtins/task/runtime/CronRuntime.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/Runner.d.ts +1 -1
- package/bin/service/builtins/task/runtime/Runner.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskActionExecution.d.ts +1 -1
- package/bin/service/builtins/task/runtime/TaskActionExecution.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskActionInput.d.ts +2 -31
- package/bin/service/builtins/task/runtime/TaskActionInput.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskActionInput.js +2 -141
- package/bin/service/builtins/task/runtime/TaskActionInput.js.map +1 -1
- package/bin/service/builtins/task/runtime/TaskRunChatDispatch.d.ts +1 -1
- package/bin/service/builtins/task/runtime/TaskRunChatDispatch.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskRunnerRound.d.ts +1 -1
- package/bin/service/builtins/task/runtime/TaskRunnerRound.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskRunnerScript.d.ts +1 -1
- package/bin/service/builtins/task/runtime/TaskRunnerScript.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskRunnerSession.d.ts +1 -1
- package/bin/service/builtins/task/runtime/TaskRunnerSession.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskServiceActions.d.ts +1 -1
- package/bin/service/builtins/task/runtime/TaskServiceActions.d.ts.map +1 -1
- package/bin/service/builtins/task/runtime/TaskServiceActions.js +2 -30
- package/bin/service/builtins/task/runtime/TaskServiceActions.js.map +1 -1
- package/bin/service/core/Manager.d.ts +0 -1
- package/bin/service/core/Manager.d.ts.map +1 -1
- package/bin/service/core/Manager.js +0 -1
- package/bin/service/core/Manager.js.map +1 -1
- package/bin/service/core/ServiceActionRunner.d.ts +1 -1
- package/bin/service/core/ServiceActionRunner.d.ts.map +1 -1
- package/bin/service/core/ServiceActionRunner.js +3 -1
- package/bin/service/core/ServiceActionRunner.js.map +1 -1
- package/bin/service/core/ServiceClassRegistry.d.ts +1 -1
- package/bin/service/core/ServiceClassRegistry.d.ts.map +1 -1
- package/bin/service/core/ServiceCommandRequest.d.ts +36 -0
- package/bin/service/core/ServiceCommandRequest.d.ts.map +1 -0
- package/bin/service/core/ServiceCommandRequest.js +53 -0
- package/bin/service/core/ServiceCommandRequest.js.map +1 -0
- package/bin/service/core/ServiceManager.d.ts +1 -1
- package/bin/service/core/ServiceManager.d.ts.map +1 -1
- package/bin/service/core/ServiceStateController.d.ts +20 -7
- package/bin/service/core/ServiceStateController.d.ts.map +1 -1
- package/bin/service/core/ServiceStateController.js +23 -20
- package/bin/service/core/ServiceStateController.js.map +1 -1
- package/bin/service/core/ServiceSystemProviders.d.ts +1 -1
- package/bin/service/core/ServiceSystemProviders.d.ts.map +1 -1
- package/bin/service/core/Services.d.ts +1 -1
- package/bin/service/core/Services.d.ts.map +1 -1
- package/bin/service/core/Services.js +2 -0
- package/bin/service/core/Services.js.map +1 -1
- package/bin/service/schedule/Executor.d.ts +1 -1
- package/bin/service/schedule/Executor.d.ts.map +1 -1
- package/bin/service/types/Service.d.ts +1 -23
- package/bin/service/types/Service.d.ts.map +1 -1
- package/bin/session/composer/system/default/DefaultSessionSystemComposer.d.ts +1 -1
- package/bin/session/composer/system/default/DefaultSessionSystemComposer.d.ts.map +1 -1
- package/bin/session/composer/system/default/SystemDomain.d.ts +1 -1
- package/bin/session/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/session/tools/shell/ShellToolBridge.d.ts +1 -1
- package/bin/session/tools/shell/ShellToolBridge.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/{runtime → core}/AgentContextTypes.ts +6 -7
- package/src/core/AgentCore.ts +527 -0
- package/src/{runtime/AgentRuntimeTypes.ts → core/AgentCoreTypes.ts} +6 -6
- package/src/host/runtime/PluginRuntime.ts +1 -1
- package/src/index.ts +24 -21
- package/src/plugin/builtins/asr/InboundAugment.ts +1 -1
- package/src/plugin/builtins/auth/runtime/AuthorizationConfig.ts +1 -1
- package/src/plugin/builtins/auth/runtime/AuthorizationStore.ts +1 -1
- package/src/plugin/builtins/voice/InboundAugment.ts +1 -1
- package/src/plugin/builtins/workboard/runtime/Collector.ts +2 -2
- package/src/plugin/builtins/workboard/runtime/Normalizer.ts +1 -1
- package/src/plugin/builtins/workboard/runtime/Store.ts +1 -1
- package/src/plugin/core/Activation.ts +2 -2
- package/src/plugin/core/HookRegistry.ts +1 -1
- package/src/plugin/core/HttpRoutes.ts +1 -1
- package/src/plugin/core/LocalExecution.ts +21 -20
- package/src/plugin/core/PluginRegistry.ts +1 -1
- package/src/plugin/types/Plugin.ts +1 -1
- package/src/sandbox/SandboxConfigResolver.ts +1 -1
- package/src/sandbox/SandboxRunner.ts +1 -1
- package/src/sdk/Agent.ts +99 -393
- package/src/sdk/AgentSdkTypes.ts +158 -0
- package/src/sdk/HttpServer.ts +27 -192
- package/src/sdk/RpcServer.ts +24 -211
- package/src/sdk/Session.ts +12 -2
- package/src/sdk/SessionServicePort.ts +1 -1
- package/src/server/http/Server.ts +63 -18
- package/src/server/http/control/AuthControlService.ts +1 -1
- package/src/server/http/control/ControlAuthorizationRoutes.ts +1 -1
- package/src/server/http/control/ControlRouter.ts +27 -11
- package/src/server/http/control/ExecuteBySession.ts +2 -2
- package/src/server/http/control/OverviewRoutes.ts +6 -2
- package/src/server/http/control/SessionSummaryStore.ts +1 -1
- package/src/server/http/control/types/ControlRoutes.ts +2 -2
- package/src/server/http/execute/execute.ts +107 -91
- package/src/server/http/plugins/plugins.ts +60 -44
- package/src/server/http/services/services.ts +68 -64
- package/src/server/http/static/static.ts +95 -79
- package/src/server/rpc/Server.ts +26 -15
- package/src/service/builtins/BaseService.ts +2 -2
- package/src/service/builtins/chat/Action.ts +1 -1
- package/src/service/builtins/chat/ChatService.ts +2 -2
- package/src/service/builtins/chat/ChatServiceTypes.ts +1 -1
- package/src/service/builtins/chat/channels/BaseChatChannel.ts +1 -1
- package/src/service/builtins/chat/channels/BaseChatChannelQueue.ts +1 -1
- package/src/service/builtins/chat/channels/BaseChatChannelSupport.ts +1 -1
- package/src/service/builtins/chat/channels/feishu/Feishu.ts +1 -1
- package/src/service/builtins/chat/channels/feishu/FeishuMessageHandler.ts +1 -1
- package/src/service/builtins/chat/channels/feishu/FeishuPlatformClient.ts +1 -1
- package/src/service/builtins/chat/channels/qq/QQ.ts +1 -1
- package/src/service/builtins/chat/channels/qq/QQMessageHandler.ts +1 -1
- package/src/service/builtins/chat/channels/qq/QQSupport.ts +1 -1
- package/src/service/builtins/chat/channels/telegram/Bot.ts +1 -1
- package/src/service/builtins/chat/channels/telegram/TelegramMessageHandler.ts +1 -1
- package/src/service/builtins/chat/channels/telegram/TelegramPlatformClient.ts +1 -1
- package/src/service/builtins/chat/runtime/ChannelContextStore.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatActionExecution.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatActionInput.ts +2 -158
- package/src/service/builtins/chat/runtime/ChatChannelActions.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatChannelConfig.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatChannelCore.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatChannelLifecycle.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatHistoryStore.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatIngressStore.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatMetaStore.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatQueueReplyDispatch.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatQueueSessionBridge.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatQueueStore.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatQueueWorker.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatServiceActions.ts +1 -118
- package/src/service/builtins/chat/runtime/ChatServiceSystem.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatSessionDelete.ts +1 -1
- package/src/service/builtins/chat/runtime/ChatkeySend.ts +1 -1
- package/src/service/builtins/chat/runtime/EnqueueDispatch.ts +1 -1
- package/src/service/builtins/chat/runtime/InboundAugment.ts +1 -1
- package/src/service/builtins/chat/runtime/PluginDispatch.ts +1 -1
- package/src/service/builtins/chat/runtime/ReplyDispatch.ts +1 -1
- package/src/service/builtins/chat/runtime/SystemPrompt.ts +1 -1
- package/src/service/builtins/contact/Action.ts +2 -59
- package/src/service/builtins/contact/ContactService.ts +2 -2
- package/src/service/builtins/contact/runtime/ChatRuntime.ts +1 -1
- package/src/service/builtins/contact/runtime/ContactPayload.ts +0 -12
- package/src/service/builtins/contact/runtime/RemoteClient.ts +40 -19
- package/src/service/builtins/contact/runtime/ShareBundle.ts +1 -1
- package/src/service/builtins/memory/Action.ts +1 -1
- package/src/service/builtins/memory/MemoryService.ts +1 -28
- package/src/service/builtins/memory/runtime/Flush.ts +1 -1
- package/src/service/builtins/memory/runtime/Search.ts +1 -1
- package/src/service/builtins/memory/runtime/Store.ts +1 -1
- package/src/service/builtins/memory/runtime/SystemProvider.ts +1 -1
- package/src/service/builtins/memory/runtime/Writer.ts +1 -1
- package/src/service/builtins/schedule/ScheduleService.ts +131 -0
- package/src/service/builtins/shell/ShellRuntimeTypes.ts +1 -1
- package/src/service/builtins/shell/ShellService.ts +2 -2
- package/src/service/builtins/shell/runtime/ShellActionResponse.ts +1 -1
- package/src/service/builtins/shell/runtime/ShellActionRuntime.ts +1 -1
- package/src/service/builtins/shell/runtime/ShellActionRuntimeSupport.ts +1 -1
- package/src/service/builtins/shell/runtime/ShellRuntimeEnvironment.ts +1 -1
- package/src/service/builtins/task/Action.ts +1 -1
- package/src/service/builtins/task/Scheduler.ts +1 -1
- package/src/service/builtins/task/TaskService.ts +2 -2
- package/src/service/builtins/task/runtime/CronRuntime.ts +1 -1
- package/src/service/builtins/task/runtime/Runner.ts +1 -1
- package/src/service/builtins/task/runtime/TaskActionExecution.ts +1 -1
- package/src/service/builtins/task/runtime/TaskActionInput.ts +3 -185
- package/src/service/builtins/task/runtime/TaskRunChatDispatch.ts +1 -1
- package/src/service/builtins/task/runtime/TaskRunnerRound.ts +1 -1
- package/src/service/builtins/task/runtime/TaskRunnerScript.ts +1 -1
- package/src/service/builtins/task/runtime/TaskRunnerSession.ts +1 -1
- package/src/service/builtins/task/runtime/TaskServiceActions.ts +1 -35
- package/src/service/core/Manager.ts +0 -1
- package/src/service/core/ServiceActionRunner.ts +4 -2
- package/src/service/core/ServiceClassRegistry.ts +1 -1
- package/src/service/core/ServiceCommandRequest.ts +93 -0
- package/src/service/core/ServiceManager.ts +0 -1
- package/src/service/core/ServiceStateController.ts +45 -20
- package/src/service/core/ServiceSystemProviders.ts +1 -1
- package/src/service/core/Services.ts +3 -1
- package/src/service/schedule/Executor.ts +1 -1
- package/src/service/types/Service.ts +1 -24
- package/src/session/composer/system/default/DefaultSessionSystemComposer.ts +1 -1
- package/src/session/composer/system/default/SystemDomain.ts +1 -1
- package/src/session/tools/shell/ShellToolBridge.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/runtime/AgentContext.d.ts +0 -23
- package/bin/runtime/AgentContext.d.ts.map +0 -1
- package/bin/runtime/AgentContext.js +0 -149
- package/bin/runtime/AgentContext.js.map +0 -1
- package/bin/runtime/AgentContextTypes.d.ts.map +0 -1
- package/bin/runtime/AgentContextTypes.js.map +0 -1
- package/bin/runtime/AgentRuntime.d.ts +0 -37
- package/bin/runtime/AgentRuntime.d.ts.map +0 -1
- package/bin/runtime/AgentRuntime.js +0 -291
- package/bin/runtime/AgentRuntime.js.map +0 -1
- package/bin/runtime/AgentRuntimeState.d.ts +0 -42
- package/bin/runtime/AgentRuntimeState.d.ts.map +0 -1
- package/bin/runtime/AgentRuntimeState.js +0 -172
- package/bin/runtime/AgentRuntimeState.js.map +0 -1
- package/bin/runtime/AgentRuntimeTypes.d.ts.map +0 -1
- package/bin/runtime/AgentRuntimeTypes.js +0 -10
- package/bin/runtime/AgentRuntimeTypes.js.map +0 -1
- package/bin/service/core/ServiceActionApi.d.ts +0 -15
- package/bin/service/core/ServiceActionApi.d.ts.map +0 -1
- package/bin/service/core/ServiceActionApi.js +0 -234
- package/bin/service/core/ServiceActionApi.js.map +0 -1
- package/bin/service/schedule/Runtime.d.ts +0 -17
- package/bin/service/schedule/Runtime.d.ts.map +0 -1
- package/bin/service/schedule/Runtime.js +0 -64
- package/bin/service/schedule/Runtime.js.map +0 -1
- package/src/runtime/AgentContext.ts +0 -182
- package/src/runtime/AgentRuntime.ts +0 -366
- package/src/runtime/AgentRuntimeState.ts +0 -213
- package/src/service/core/ServiceActionApi.ts +0 -304
- package/src/service/schedule/Runtime.ts +0 -78
package/src/sdk/Agent.ts
CHANGED
|
@@ -2,114 +2,36 @@
|
|
|
2
2
|
* Agent SDK 本地入口。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - `
|
|
5
|
+
* - `Agent` 现在是实例外观层,长期运行状态下沉到 `AgentCore`。
|
|
6
6
|
* - session、HTTP、RPC、service lifecycle 都按需异步初始化。
|
|
7
|
-
* -
|
|
7
|
+
* - `start/stop` 负责统一收口当前 agent 实例的生命周期。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import fs from "fs-extra";
|
|
11
|
-
import { nanoid } from "nanoid";
|
|
12
10
|
import type { Tool } from "ai";
|
|
13
|
-
import { Logger } from "@/utils/logger/Logger.js";
|
|
14
11
|
import type { BaseService } from "@/service/builtins/BaseService.js";
|
|
15
|
-
import type { AgentContext } from "@/
|
|
16
|
-
import type { AgentRuntime } from "@/
|
|
17
|
-
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
18
|
-
import type { JsonValue } from "@/types/common/Json.js";
|
|
19
|
-
import type { AgentPlatformRuntime } from "@/types/host/AgentHost.js";
|
|
12
|
+
import type { AgentContext } from "@/core/AgentContextTypes.js";
|
|
13
|
+
import type { AgentRuntime } from "@/core/AgentCoreTypes.js";
|
|
20
14
|
import type {
|
|
21
|
-
Plugin,
|
|
22
|
-
PluginAvailability,
|
|
23
15
|
PluginPort,
|
|
24
|
-
PluginView,
|
|
25
16
|
} from "@/plugin/types/Plugin.js";
|
|
26
17
|
import type {
|
|
27
18
|
AgentOptions,
|
|
19
|
+
AgentStartOptions,
|
|
20
|
+
AgentStartResult,
|
|
21
|
+
AgentStopResult,
|
|
28
22
|
AgentSessionMetadata,
|
|
29
|
-
AgentSessionSystemBlock,
|
|
30
23
|
} from "@/sdk/AgentSdkTypes.js";
|
|
31
24
|
import { Session } from "@/sdk/Session.js";
|
|
32
|
-
import { DEFAULT_SHIP_PROMPTS } from "@session/composer/system/default/SystemDomain.js";
|
|
33
|
-
import { getSdkAgentSessionsRootDirPath } from "@/sdk/Paths.js";
|
|
34
25
|
import { SdkAgentHttpServer } from "@/sdk/HttpServer.js";
|
|
35
26
|
import { SdkAgentRpcServer } from "@/sdk/RpcServer.js";
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
createAgentPluginConfigRuntime,
|
|
39
|
-
} from "@/host/runtime/AgentHostRuntime.js";
|
|
40
|
-
import { loadDowncityConfig } from "@/config/Config.js";
|
|
41
|
-
import { appendExecSessionMessage } from "@/service/builtins/chat/runtime/ChatIngressStore.js";
|
|
42
|
-
import { readChatMetaBySessionId } from "@/service/builtins/chat/runtime/ChatMetaStore.js";
|
|
43
|
-
import { resolveChatQueueStore } from "@/service/builtins/chat/runtime/ChatQueueStore.js";
|
|
44
|
-
import { HookRegistry } from "@/plugin/core/HookRegistry.js";
|
|
45
|
-
import { PluginRegistry } from "@/plugin/core/PluginRegistry.js";
|
|
46
|
-
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
47
|
-
|
|
48
|
-
const EMPTY_SDK_PLATFORM: AgentPlatformRuntime = {
|
|
49
|
-
getGlobalEnv: () => ({}),
|
|
50
|
-
getAgentEnv: () => ({}),
|
|
51
|
-
listModels: () => [],
|
|
52
|
-
listProviders: async () => [],
|
|
53
|
-
getModel: () => null,
|
|
54
|
-
getChannelAccount: () => null,
|
|
55
|
-
readChatAuthorizationConfig: () => ({
|
|
56
|
-
roles: {},
|
|
57
|
-
channels: {},
|
|
58
|
-
}),
|
|
59
|
-
writeChatAuthorizationConfig: async (_projectRoot, nextConfig) => nextConfig,
|
|
60
|
-
setChatAuthorizationUserRole: async () => ({
|
|
61
|
-
roles: {},
|
|
62
|
-
channels: {},
|
|
63
|
-
}),
|
|
64
|
-
isPluginEnabled: (pluginName) => pluginName === "auth",
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
function createFallbackSdkConfig(agentId: string): DowncityConfig {
|
|
68
|
-
return {
|
|
69
|
-
name: agentId,
|
|
70
|
-
version: "0.0.0",
|
|
71
|
-
} as DowncityConfig;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function normalizeInstructionInput(input: string | string[] | undefined): string[] {
|
|
75
|
-
const items = Array.isArray(input) ? input : typeof input === "string" ? [input] : [];
|
|
76
|
-
return items
|
|
77
|
-
.map((item) => String(item || "").trim())
|
|
78
|
-
.filter((item) => item.length > 0);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createCoreInstructionContent(projectRoot: string): string {
|
|
82
|
-
const currentYear = String(new Date().getFullYear());
|
|
83
|
-
return DEFAULT_SHIP_PROMPTS
|
|
84
|
-
.replaceAll("{{project_path}}", projectRoot)
|
|
85
|
-
.replaceAll("{{project_root}}", projectRoot)
|
|
86
|
-
.replaceAll("{{current_year}}", currentYear);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function createInstructionSystemBlocks(
|
|
90
|
-
instruction: string[],
|
|
91
|
-
projectRoot: string,
|
|
92
|
-
): AgentSessionSystemBlock[] {
|
|
93
|
-
if (instruction.length === 0) {
|
|
94
|
-
return [
|
|
95
|
-
{
|
|
96
|
-
source: "core",
|
|
97
|
-
name: "default",
|
|
98
|
-
content: createCoreInstructionContent(projectRoot),
|
|
99
|
-
},
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
return instruction.map((content, index) => ({
|
|
103
|
-
source: "instruction" as const,
|
|
104
|
-
name: instruction.length === 1 ? "agent" : `agent:${index + 1}`,
|
|
105
|
-
content,
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
27
|
+
import { AgentCore } from "@/core/AgentCore.js";
|
|
28
|
+
import { startAllServices, stopAllServices } from "@/service/core/Manager.js";
|
|
108
29
|
|
|
109
30
|
/**
|
|
110
31
|
* SDK 本地 Agent。
|
|
111
32
|
*/
|
|
112
33
|
export class Agent {
|
|
34
|
+
readonly core: AgentCore;
|
|
113
35
|
readonly id: string;
|
|
114
36
|
readonly path: string;
|
|
115
37
|
readonly tools: Record<string, Tool>;
|
|
@@ -117,47 +39,16 @@ export class Agent {
|
|
|
117
39
|
readonly rpc: SdkAgentRpcServer;
|
|
118
40
|
readonly services: Map<string, BaseService>;
|
|
119
41
|
readonly plugins: PluginPort;
|
|
120
|
-
|
|
121
|
-
private
|
|
122
|
-
private readonly sessionsById = new Map<string, Session>();
|
|
123
|
-
private readonly runtime: AgentRuntime;
|
|
124
|
-
private readonly serviceContext: AgentContext;
|
|
125
|
-
private readonly pluginRegistry: PluginRegistry;
|
|
126
|
-
private readonly pluginSystemProviders: Plugin[];
|
|
127
|
-
private readonly config: DowncityConfig;
|
|
128
|
-
private readonly platform: AgentPlatformRuntime;
|
|
129
|
-
private instruction: string[];
|
|
130
|
-
private servicesStartPromise: Promise<void> | null = null;
|
|
42
|
+
private servicesStarted = false;
|
|
43
|
+
private startPromise: Promise<AgentStartResult> | null = null;
|
|
131
44
|
|
|
132
45
|
constructor(options: AgentOptions) {
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
throw new Error("Agent requires a non-empty id");
|
|
140
|
-
}
|
|
141
|
-
if (!this.path) {
|
|
142
|
-
throw new Error("Agent requires a non-empty path");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
this.logger = new Logger();
|
|
146
|
-
this.logger.bindProjectRoot(this.path);
|
|
147
|
-
this.platform = options.platform || EMPTY_SDK_PLATFORM;
|
|
148
|
-
this.instruction = normalizeInstructionInput(options.instruction);
|
|
149
|
-
this.config = this.loadConfig();
|
|
150
|
-
this.services = this.createServiceMap(options.services || []);
|
|
151
|
-
this.runtime = this.createRuntime();
|
|
152
|
-
for (const service of this.services.values()) {
|
|
153
|
-
service.bindAgent(this.runtime);
|
|
154
|
-
}
|
|
155
|
-
this.pluginSystemProviders = Array.isArray(options.plugins)
|
|
156
|
-
? [...options.plugins]
|
|
157
|
-
: [];
|
|
158
|
-
this.pluginRegistry = this.createPluginRegistry(this.pluginSystemProviders);
|
|
159
|
-
this.plugins = this.createPluginPort();
|
|
160
|
-
this.serviceContext = this.createServiceContext();
|
|
46
|
+
this.core = new AgentCore(options);
|
|
47
|
+
this.id = this.core.id;
|
|
48
|
+
this.path = this.core.path;
|
|
49
|
+
this.tools = this.core.tools;
|
|
50
|
+
this.services = this.core.services;
|
|
51
|
+
this.plugins = this.core.plugins;
|
|
161
52
|
this.http = new SdkAgentHttpServer(this);
|
|
162
53
|
this.rpc = new SdkAgentRpcServer(this);
|
|
163
54
|
}
|
|
@@ -166,306 +57,121 @@ export class Agent {
|
|
|
166
57
|
* 获取或创建一个 session。
|
|
167
58
|
*/
|
|
168
59
|
async session(sessionId?: string): Promise<Session> {
|
|
169
|
-
|
|
170
|
-
await session.initialize();
|
|
171
|
-
return session;
|
|
60
|
+
return await this.core.session(sessionId);
|
|
172
61
|
}
|
|
173
62
|
|
|
174
63
|
/**
|
|
175
64
|
* 列出当前 agent 的全部 session 元数据。
|
|
176
65
|
*/
|
|
177
66
|
async sessions(): Promise<AgentSessionMetadata[]> {
|
|
178
|
-
|
|
179
|
-
if (!(await fs.pathExists(rootDir))) return [];
|
|
180
|
-
const entries = await fs.readdir(rootDir, { withFileTypes: true });
|
|
181
|
-
const items: AgentSessionMetadata[] = [];
|
|
182
|
-
for (const entry of entries) {
|
|
183
|
-
if (!entry.isDirectory()) continue;
|
|
184
|
-
let sessionId = "";
|
|
185
|
-
try {
|
|
186
|
-
sessionId = decodeURIComponent(entry.name);
|
|
187
|
-
} catch {
|
|
188
|
-
sessionId = entry.name;
|
|
189
|
-
}
|
|
190
|
-
if (!sessionId) continue;
|
|
191
|
-
const session = await this.session(sessionId);
|
|
192
|
-
items.push(await session.toMetadata());
|
|
193
|
-
}
|
|
194
|
-
items.sort((a, b) => (b.updatedAt || 0) - (a.updatedAt || 0));
|
|
195
|
-
return items;
|
|
67
|
+
return await this.core.sessions();
|
|
196
68
|
}
|
|
197
69
|
|
|
198
70
|
/**
|
|
199
71
|
* 确保显式注入的 services 已启动。
|
|
200
72
|
*/
|
|
201
73
|
async ensureServicesStarted(): Promise<void> {
|
|
202
|
-
if (this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
74
|
+
if (this.servicesStarted) return;
|
|
75
|
+
const lifecycle = await startAllServices(this.getContext());
|
|
76
|
+
this.servicesStarted = true;
|
|
77
|
+
for (const item of lifecycle.results) {
|
|
78
|
+
if (!item.success) {
|
|
79
|
+
this.getRuntime().logger.error(
|
|
80
|
+
`Service start failed: ${item.service?.name || "unknown"} - ${item.error || "unknown error"}`,
|
|
81
|
+
);
|
|
209
82
|
}
|
|
210
|
-
}
|
|
211
|
-
await this.servicesStartPromise;
|
|
83
|
+
}
|
|
212
84
|
}
|
|
213
85
|
|
|
214
86
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* 关键点(中文)
|
|
218
|
-
* - instruction 不做动态变量替换。
|
|
219
|
-
* - 已创建的 session 后续 run 会读取最新 instruction blocks。
|
|
87
|
+
* 启动当前 agent 实例的长期运行能力。
|
|
220
88
|
*/
|
|
221
|
-
|
|
222
|
-
this.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
private loadConfig(): DowncityConfig {
|
|
226
|
-
try {
|
|
227
|
-
return loadDowncityConfig(this.path, {
|
|
228
|
-
projectEnv: {},
|
|
229
|
-
agentEnv: {},
|
|
230
|
-
globalEnv: {},
|
|
231
|
-
});
|
|
232
|
-
} catch {
|
|
233
|
-
return createFallbackSdkConfig(this.id);
|
|
89
|
+
async start(options?: AgentStartOptions): Promise<AgentStartResult> {
|
|
90
|
+
if (this.startPromise) {
|
|
91
|
+
return await this.startPromise;
|
|
234
92
|
}
|
|
235
|
-
|
|
93
|
+
this.startPromise = (async () => {
|
|
94
|
+
const shouldStartServices = options?.services !== false;
|
|
236
95
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
for (const service of input) {
|
|
240
|
-
const name = String(service?.name || "").trim();
|
|
241
|
-
if (!name) {
|
|
242
|
-
throw new Error("Agent received a service without a valid name");
|
|
96
|
+
if (shouldStartServices) {
|
|
97
|
+
await this.ensureServicesStarted();
|
|
243
98
|
}
|
|
244
|
-
if (services.has(name)) {
|
|
245
|
-
throw new Error(`Duplicate service registration: ${name}`);
|
|
246
|
-
}
|
|
247
|
-
services.set(name, service);
|
|
248
|
-
}
|
|
249
|
-
return services;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
private createPluginRegistry(input: Plugin[]): PluginRegistry {
|
|
253
|
-
let pluginRegistryRef: PluginRegistry | null = null;
|
|
254
|
-
const hookRegistry = new HookRegistry({
|
|
255
|
-
contextResolver: () => this.serviceContext,
|
|
256
|
-
pluginEnabledChecker: (pluginName) => {
|
|
257
|
-
const plugin = pluginRegistryRef?.get(pluginName);
|
|
258
|
-
return plugin ? isPluginEnabled({ plugin, context: this.serviceContext }) : false;
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
const registry = new PluginRegistry({
|
|
262
|
-
contextResolver: () => this.serviceContext,
|
|
263
|
-
hookRegistry,
|
|
264
|
-
});
|
|
265
|
-
pluginRegistryRef = registry;
|
|
266
99
|
|
|
267
|
-
|
|
268
|
-
|
|
100
|
+
const httpBinding =
|
|
101
|
+
options?.http === false || options?.http === undefined
|
|
102
|
+
? undefined
|
|
103
|
+
: await this.http.start(options.http);
|
|
104
|
+
const rpcBinding =
|
|
105
|
+
options?.rpc === true
|
|
106
|
+
? await this.rpc.start()
|
|
107
|
+
: undefined;
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
...(httpBinding ? { http: httpBinding } : {}),
|
|
111
|
+
...(rpcBinding ? { rpc: rpcBinding } : {}),
|
|
112
|
+
servicesStarted: this.servicesStarted,
|
|
113
|
+
};
|
|
114
|
+
})();
|
|
115
|
+
try {
|
|
116
|
+
return await this.startPromise;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
this.startPromise = null;
|
|
119
|
+
throw error;
|
|
269
120
|
}
|
|
270
|
-
return registry;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
private createPluginPort(): PluginPort {
|
|
274
|
-
return {
|
|
275
|
-
list: (): PluginView[] => this.pluginRegistry.list(),
|
|
276
|
-
availability: async (pluginName: string): Promise<PluginAvailability> =>
|
|
277
|
-
await this.pluginRegistry.availability(pluginName),
|
|
278
|
-
runAction: async (params) => await this.pluginRegistry.runAction(params),
|
|
279
|
-
pipeline: async <T>(pointName: string, value: T): Promise<T> =>
|
|
280
|
-
await this.pluginRegistry.pipeline(pointName, value),
|
|
281
|
-
guard: async <T>(pointName: string, value: T): Promise<void> => {
|
|
282
|
-
await this.pluginRegistry.guard(pointName, value);
|
|
283
|
-
},
|
|
284
|
-
effect: async <T>(pointName: string, value: T): Promise<void> => {
|
|
285
|
-
await this.pluginRegistry.effect(pointName, value);
|
|
286
|
-
},
|
|
287
|
-
resolve: async <TInput, TOutput>(
|
|
288
|
-
pointName: string,
|
|
289
|
-
value: TInput,
|
|
290
|
-
): Promise<TOutput> =>
|
|
291
|
-
await this.pluginRegistry.resolve<TInput, TOutput>(pointName, value),
|
|
292
|
-
};
|
|
293
121
|
}
|
|
294
122
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
123
|
+
/**
|
|
124
|
+
* 停止当前 agent 实例的长期运行能力。
|
|
125
|
+
*/
|
|
126
|
+
async stop(): Promise<AgentStopResult> {
|
|
127
|
+
const servicesStarted = this.servicesStarted;
|
|
128
|
+
const rpcStarted = this.rpc.isStarted();
|
|
129
|
+
const httpStarted = this.http.isStarted();
|
|
130
|
+
|
|
131
|
+
if (servicesStarted) {
|
|
132
|
+
await stopAllServices(this.getContext());
|
|
133
|
+
this.servicesStarted = false;
|
|
134
|
+
}
|
|
298
135
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
for (const plugin of this.pluginSystemProviders) {
|
|
302
|
-
if (typeof plugin.system !== "function") continue;
|
|
303
|
-
try {
|
|
304
|
-
if (!isPluginEnabled({ plugin, context: this.serviceContext })) continue;
|
|
305
|
-
if (typeof plugin.availability === "function") {
|
|
306
|
-
const availability = await plugin.availability(this.serviceContext);
|
|
307
|
-
if (!availability.available) continue;
|
|
308
|
-
}
|
|
309
|
-
const text = String(await plugin.system(this.serviceContext)).trim();
|
|
310
|
-
if (!text) continue;
|
|
311
|
-
out.push({
|
|
312
|
-
source: "plugin",
|
|
313
|
-
name: plugin.name,
|
|
314
|
-
content: text,
|
|
315
|
-
});
|
|
316
|
-
} catch {
|
|
317
|
-
// 单个 plugin system 失败不应阻断 SDK session 主链路。
|
|
318
|
-
}
|
|
136
|
+
if (rpcStarted) {
|
|
137
|
+
await this.rpc.stop();
|
|
319
138
|
}
|
|
320
|
-
return out;
|
|
321
|
-
}
|
|
322
139
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
for (const service of this.services.values()) {
|
|
326
|
-
if (typeof service.system !== "function") continue;
|
|
327
|
-
try {
|
|
328
|
-
const text = String(await service.system(this.serviceContext)).trim();
|
|
329
|
-
if (!text) continue;
|
|
330
|
-
out.push({
|
|
331
|
-
source: "service",
|
|
332
|
-
name: service.name,
|
|
333
|
-
content: text,
|
|
334
|
-
});
|
|
335
|
-
} catch {
|
|
336
|
-
// 单个 service system 失败不应阻断 SDK session 主链路。
|
|
337
|
-
}
|
|
140
|
+
if (httpStarted) {
|
|
141
|
+
await this.http.stop();
|
|
338
142
|
}
|
|
339
|
-
return out;
|
|
340
|
-
}
|
|
341
143
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
env: {},
|
|
349
|
-
globalEnv: {},
|
|
350
|
-
systems: this.instruction,
|
|
351
|
-
paths: createAgentPathRuntime(this.path),
|
|
352
|
-
pluginConfig: createAgentPluginConfigRuntime(this.path),
|
|
353
|
-
platform: this.platform,
|
|
354
|
-
model: undefined,
|
|
355
|
-
getSession: (sessionId: string) => {
|
|
356
|
-
return this.getOrCreateSession(sessionId).getServicePort() as never;
|
|
357
|
-
},
|
|
358
|
-
listExecutingSessionIds: () =>
|
|
359
|
-
[...this.sessionsById.values()]
|
|
360
|
-
.filter((session) => session.isExecuting())
|
|
361
|
-
.map((session) => session.id),
|
|
362
|
-
getExecutingSessionCount: () =>
|
|
363
|
-
[...this.sessionsById.values()].filter((session) => session.isExecuting()).length,
|
|
364
|
-
services: this.services,
|
|
365
|
-
} satisfies Omit<AgentRuntime, "getSession"> & {
|
|
366
|
-
getSession(sessionId: string): never;
|
|
144
|
+
this.startPromise = null;
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
httpStopped: httpStarted,
|
|
148
|
+
rpcStopped: rpcStarted,
|
|
149
|
+
servicesStopped: servicesStarted,
|
|
367
150
|
};
|
|
368
|
-
return runtime as unknown as AgentRuntime;
|
|
369
151
|
}
|
|
370
152
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
globalEnv: {},
|
|
381
|
-
systems: this.instruction,
|
|
382
|
-
paths: this.runtime.paths,
|
|
383
|
-
pluginConfig: this.runtime.pluginConfig,
|
|
384
|
-
platform: this.platform,
|
|
385
|
-
session: {
|
|
386
|
-
get: (sessionId) => this.getOrCreateSession(sessionId).getServicePort(),
|
|
387
|
-
listExecutingSessionIds: () => this.runtime.listExecutingSessionIds(),
|
|
388
|
-
getExecutingSessionCount: () => this.runtime.getExecutingSessionCount(),
|
|
389
|
-
},
|
|
390
|
-
invoke: {
|
|
391
|
-
invoke: async (params: {
|
|
392
|
-
service: string;
|
|
393
|
-
action: string;
|
|
394
|
-
payload?: JsonValue;
|
|
395
|
-
}) => {
|
|
396
|
-
const serviceName = String(params.service || "").trim();
|
|
397
|
-
const actionName = String(params.action || "").trim();
|
|
398
|
-
const service = this.services.get(serviceName);
|
|
399
|
-
if (!service) {
|
|
400
|
-
return {
|
|
401
|
-
success: false,
|
|
402
|
-
error: `Unknown service: ${serviceName}`,
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
const action = service.actions[actionName];
|
|
406
|
-
if (!action) {
|
|
407
|
-
return {
|
|
408
|
-
success: false,
|
|
409
|
-
error: `Unknown action: ${serviceName}.${actionName}`,
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
const result = await action.execute({
|
|
413
|
-
context,
|
|
414
|
-
payload: params.payload ?? null,
|
|
415
|
-
serviceName,
|
|
416
|
-
actionName,
|
|
417
|
-
});
|
|
418
|
-
if (!result.success) {
|
|
419
|
-
return {
|
|
420
|
-
success: false,
|
|
421
|
-
...(result.error ? { error: result.error } : {}),
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
return {
|
|
425
|
-
success: true,
|
|
426
|
-
...(result.data !== undefined ? { data: result.data } : {}),
|
|
427
|
-
};
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
chat: {
|
|
431
|
-
readMetaBySessionId: async (sessionId: string) => {
|
|
432
|
-
return await readChatMetaBySessionId({
|
|
433
|
-
context,
|
|
434
|
-
sessionId,
|
|
435
|
-
});
|
|
436
|
-
},
|
|
437
|
-
appendExecSessionMessage: async (params) => {
|
|
438
|
-
await appendExecSessionMessage({
|
|
439
|
-
context,
|
|
440
|
-
sessionId: params.sessionId,
|
|
441
|
-
text: params.text,
|
|
442
|
-
extra: params.extra,
|
|
443
|
-
});
|
|
444
|
-
},
|
|
445
|
-
enqueue: (params) => resolveChatQueueStore(context).enqueue(params),
|
|
446
|
-
},
|
|
447
|
-
plugins: this.plugins,
|
|
448
|
-
};
|
|
449
|
-
return context;
|
|
153
|
+
/**
|
|
154
|
+
* 更新当前 SDK Agent 的静态基础指令。
|
|
155
|
+
*
|
|
156
|
+
* 关键点(中文)
|
|
157
|
+
* - instruction 不做动态变量替换。
|
|
158
|
+
* - 已创建的 session 后续 run 会读取最新 instruction blocks。
|
|
159
|
+
*/
|
|
160
|
+
setInstruction(input: string | string[]): void {
|
|
161
|
+
this.core.setInstruction(input);
|
|
450
162
|
}
|
|
451
163
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
164
|
+
/**
|
|
165
|
+
* 返回实例级 runtime 视图。
|
|
166
|
+
*/
|
|
167
|
+
getRuntime(): AgentRuntime {
|
|
168
|
+
return this.core.getRuntime();
|
|
169
|
+
}
|
|
457
170
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
logger: this.logger,
|
|
464
|
-
getInstructionSystemBlocks: () => this.loadInstructionSystemBlocks(),
|
|
465
|
-
getServiceSystemBlocks: () => this.loadServiceSystemBlocks(),
|
|
466
|
-
getPluginSystemBlocks: () => this.loadPluginSystemBlocks(),
|
|
467
|
-
});
|
|
468
|
-
this.sessionsById.set(resolvedSessionId, created);
|
|
469
|
-
return created;
|
|
171
|
+
/**
|
|
172
|
+
* 返回实例级执行上下文。
|
|
173
|
+
*/
|
|
174
|
+
getContext(): AgentContext {
|
|
175
|
+
return this.core.getContext();
|
|
470
176
|
}
|
|
471
177
|
}
|