@downcity/plugins 1.0.254 → 1.0.280
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/builtin/BuiltinPluginReadmes.d.ts +14 -0
- package/bin/builtin/BuiltinPluginReadmes.d.ts.map +1 -0
- package/bin/builtin/BuiltinPluginReadmes.js +58 -0
- package/bin/builtin/BuiltinPluginReadmes.js.map +1 -0
- package/bin/builtin/BuiltinPluginTypes.d.ts +48 -0
- package/bin/builtin/BuiltinPluginTypes.d.ts.map +1 -0
- package/bin/builtin/BuiltinPluginTypes.js +161 -0
- package/bin/builtin/BuiltinPluginTypes.js.map +1 -0
- package/bin/builtin/PluginSettingsDefinitions.d.ts +9 -0
- package/bin/builtin/PluginSettingsDefinitions.d.ts.map +1 -0
- package/bin/builtin/PluginSettingsDefinitions.js +41 -0
- package/bin/builtin/PluginSettingsDefinitions.js.map +1 -0
- package/bin/builtin/main/PluginSettingsMain.d.ts +6 -0
- package/bin/builtin/main/PluginSettingsMain.d.ts.map +1 -0
- package/bin/builtin/main/PluginSettingsMain.js +65 -0
- package/bin/builtin/main/PluginSettingsMain.js.map +1 -0
- package/bin/builtin/renderer/PluginSettingsRenderer.d.ts +6 -0
- package/bin/builtin/renderer/PluginSettingsRenderer.d.ts.map +1 -0
- package/bin/builtin/renderer/PluginSettingsRenderer.js +76 -0
- package/bin/builtin/renderer/PluginSettingsRenderer.js.map +1 -0
- package/bin/builtin/types/PluginSettings.d.ts +35 -0
- package/bin/builtin/types/PluginSettings.d.ts.map +1 -0
- package/bin/builtin/types/PluginSettings.js +3 -0
- package/bin/builtin/types/PluginSettings.js.map +1 -0
- package/bin/chat/ChatPlugin.d.ts +12 -28
- package/bin/chat/ChatPlugin.d.ts.map +1 -1
- package/bin/chat/ChatPlugin.js +97 -49
- package/bin/chat/ChatPlugin.js.map +1 -1
- package/bin/chat/access/ChatAccessRuntime.js +1 -1
- package/bin/chat/access/ChatAccessRuntime.js.map +1 -1
- package/bin/chat/access/ChatAccessSchema.d.ts +2 -2
- package/bin/chat/access/ChatAccessSchema.d.ts.map +1 -1
- package/bin/chat/access/ChatAccessSchema.js +3 -3
- package/bin/chat/access/ChatAccessSchema.js.map +1 -1
- package/bin/chat/access/ChatAccessService.d.ts +2 -2
- package/bin/chat/access/ChatAccessService.d.ts.map +1 -1
- package/bin/chat/access/ChatAccessService.js +4 -4
- package/bin/chat/access/ChatAccessService.js.map +1 -1
- package/bin/chat/access/ChatAccessStore.d.ts +3 -3
- package/bin/chat/access/ChatAccessStore.d.ts.map +1 -1
- package/bin/chat/access/ChatAccessStore.js +17 -8
- package/bin/chat/access/ChatAccessStore.js.map +1 -1
- package/bin/chat/channels/BaseChatChannel.d.ts +1 -0
- package/bin/chat/channels/BaseChatChannel.d.ts.map +1 -1
- package/bin/chat/channels/BaseChatChannel.js +2 -0
- package/bin/chat/channels/BaseChatChannel.js.map +1 -1
- package/bin/chat/channels/RuntimeChannel.d.ts +4 -4
- package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -1
- package/bin/chat/channels/RuntimeChannel.js +8 -8
- package/bin/chat/channels/RuntimeChannel.js.map +1 -1
- package/bin/chat/channels/feishu/Feishu.js +1 -1
- package/bin/chat/channels/feishu/Feishu.js.map +1 -1
- package/bin/chat/channels/feishu/FeishuPlatformClient.d.ts +1 -0
- package/bin/chat/channels/feishu/FeishuPlatformClient.d.ts.map +1 -1
- package/bin/chat/channels/feishu/FeishuPlatformClient.js +3 -0
- package/bin/chat/channels/feishu/FeishuPlatformClient.js.map +1 -1
- package/bin/chat/channels/feishu/FeishuPlatformLookup.d.ts +2 -0
- package/bin/chat/channels/feishu/FeishuPlatformLookup.d.ts.map +1 -1
- package/bin/chat/channels/feishu/FeishuPlatformLookup.js +1 -1
- package/bin/chat/channels/feishu/FeishuPlatformLookup.js.map +1 -1
- package/bin/chat/channels/qq/QQ.d.ts.map +1 -1
- package/bin/chat/channels/qq/QQ.js +3 -2
- package/bin/chat/channels/qq/QQ.js.map +1 -1
- package/bin/chat/channels/qq/QQEventCapture.d.ts +1 -1
- package/bin/chat/channels/qq/QQEventCapture.d.ts.map +1 -1
- package/bin/chat/channels/qq/QQEventCapture.js +3 -3
- package/bin/chat/channels/qq/QQEventCapture.js.map +1 -1
- package/bin/chat/channels/qq/QQInboundDedupe.d.ts +1 -1
- package/bin/chat/channels/qq/QQInboundDedupe.d.ts.map +1 -1
- package/bin/chat/channels/qq/QQInboundDedupe.js +1 -1
- package/bin/chat/channels/qq/QQInboundDedupe.js.map +1 -1
- package/bin/chat/channels/qq/QQMessageHandler.d.ts +4 -0
- package/bin/chat/channels/qq/QQMessageHandler.d.ts.map +1 -1
- package/bin/chat/channels/qq/QQMessageHandler.js +2 -0
- package/bin/chat/channels/qq/QQMessageHandler.js.map +1 -1
- package/bin/chat/channels/qq/QQSupport.d.ts +4 -0
- package/bin/chat/channels/qq/QQSupport.d.ts.map +1 -1
- package/bin/chat/channels/qq/QQSupport.js +1 -0
- package/bin/chat/channels/qq/QQSupport.js.map +1 -1
- package/bin/chat/channels/qq/VoiceInput.d.ts +3 -0
- package/bin/chat/channels/qq/VoiceInput.d.ts.map +1 -1
- package/bin/chat/channels/qq/VoiceInput.js +1 -1
- package/bin/chat/channels/qq/VoiceInput.js.map +1 -1
- package/bin/chat/channels/telegram/ApiClient.d.ts +3 -1
- package/bin/chat/channels/telegram/ApiClient.d.ts.map +1 -1
- package/bin/chat/channels/telegram/ApiClient.js +4 -2
- package/bin/chat/channels/telegram/ApiClient.js.map +1 -1
- package/bin/chat/channels/telegram/StateStore.d.ts +1 -1
- package/bin/chat/channels/telegram/StateStore.d.ts.map +1 -1
- package/bin/chat/channels/telegram/StateStore.js +2 -2
- package/bin/chat/channels/telegram/StateStore.js.map +1 -1
- package/bin/chat/channels/telegram/TelegramPlatformClient.d.ts.map +1 -1
- package/bin/chat/channels/telegram/TelegramPlatformClient.js +2 -1
- package/bin/chat/channels/telegram/TelegramPlatformClient.js.map +1 -1
- package/bin/chat/main/ChatPluginMain.d.ts +4 -0
- package/bin/chat/main/ChatPluginMain.d.ts.map +1 -0
- package/bin/chat/main/ChatPluginMain.js +137 -0
- package/bin/chat/main/ChatPluginMain.js.map +1 -0
- package/bin/chat/renderer/ChatPluginRenderer.d.ts +4 -0
- package/bin/chat/renderer/ChatPluginRenderer.d.ts.map +1 -0
- package/bin/chat/renderer/ChatPluginRenderer.js +105 -0
- package/bin/chat/renderer/ChatPluginRenderer.js.map +1 -0
- package/bin/chat/runtime/ChannelContextStore.d.ts +2 -2
- package/bin/chat/runtime/ChannelContextStore.js +20 -20
- package/bin/chat/runtime/ChannelContextStore.js.map +1 -1
- package/bin/chat/runtime/ChatActionExecution.js +6 -6
- package/bin/chat/runtime/ChatActionExecution.js.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.js +7 -12
- package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.d.ts +3 -3
- package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.js +5 -5
- package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
- package/bin/chat/runtime/ChatHistoryStore.d.ts +1 -1
- package/bin/chat/runtime/ChatHistoryStore.js +7 -7
- package/bin/chat/runtime/ChatHistoryStore.js.map +1 -1
- package/bin/chat/runtime/ChatMetaStore.d.ts +1 -1
- package/bin/chat/runtime/ChatMetaStore.js +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.d.ts +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.d.ts.map +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.js +9 -9
- package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
- package/bin/chat/runtime/ChatQueue.d.ts +3 -38
- package/bin/chat/runtime/ChatQueue.d.ts.map +1 -1
- package/bin/chat/runtime/ChatQueue.js +3 -51
- package/bin/chat/runtime/ChatQueue.js.map +1 -1
- package/bin/chat/runtime/ChatQueueStore.d.ts +5 -16
- package/bin/chat/runtime/ChatQueueStore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatQueueStore.js +8 -22
- package/bin/chat/runtime/ChatQueueStore.js.map +1 -1
- package/bin/chat/runtime/ChatQueueWorker.d.ts +1 -1
- package/bin/chat/runtime/ChatQueueWorker.d.ts.map +1 -1
- package/bin/chat/runtime/ChatQueueWorker.js +1 -2
- package/bin/chat/runtime/ChatQueueWorker.js.map +1 -1
- package/bin/chat/runtime/ChatSessionDelete.d.ts +3 -3
- package/bin/chat/runtime/ChatSessionDelete.js +4 -4
- package/bin/chat/runtime/ChatSessionDelete.js.map +1 -1
- package/bin/chat/runtime/ChatStorage.d.ts +7 -7
- package/bin/chat/runtime/ChatStorage.js +24 -24
- package/bin/chat/runtime/ChatStorage.js.map +1 -1
- package/bin/chat/types/ChatAccess.d.ts +2 -2
- package/bin/chat/types/ChatAccess.d.ts.map +1 -1
- package/bin/chat/types/ChatCommand.d.ts +1 -1
- package/bin/chat/types/ChatPluginChannelConfig.d.ts +57 -0
- package/bin/chat/types/ChatPluginChannelConfig.d.ts.map +1 -0
- package/bin/chat/types/ChatPluginChannelConfig.js +3 -0
- package/bin/chat/types/ChatPluginChannelConfig.js.map +1 -0
- package/bin/chat/types/ChatPluginConfig.d.ts +19 -0
- package/bin/chat/types/ChatPluginConfig.d.ts.map +1 -0
- package/bin/chat/types/ChatPluginConfig.js +3 -0
- package/bin/chat/types/ChatPluginConfig.js.map +1 -0
- package/bin/chat/types/ChatPluginOptions.d.ts +4 -4
- package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -1
- package/bin/chat/types/ChatPluginOptions.js +1 -1
- package/bin/chat/types/ChatPluginProfile.d.ts +39 -0
- package/bin/chat/types/ChatPluginProfile.d.ts.map +1 -0
- package/bin/chat/types/ChatPluginProfile.js +3 -0
- package/bin/chat/types/ChatPluginProfile.js.map +1 -0
- package/bin/chat/types/ChatPluginRenderer.d.ts +17 -0
- package/bin/chat/types/ChatPluginRenderer.d.ts.map +1 -0
- package/bin/chat/types/ChatPluginRenderer.js +3 -0
- package/bin/chat/types/ChatPluginRenderer.js.map +1 -0
- package/bin/chat/types/ChatRuntime.d.ts +11 -0
- package/bin/chat/types/ChatRuntime.d.ts.map +1 -1
- package/bin/chat/types/ChatRuntimeAccount.d.ts +3 -3
- package/bin/chat/types/ChatRuntimeAccount.d.ts.map +1 -1
- package/bin/chat/types/ChatRuntimeAccount.js +2 -2
- package/bin/chat/types/ChatStorage.d.ts +2 -2
- package/bin/chat/types/ChatStorage.d.ts.map +1 -1
- package/bin/chat.d.ts +3 -4
- package/bin/chat.d.ts.map +1 -1
- package/bin/chat.js +1 -2
- package/bin/chat.js.map +1 -1
- package/bin/contact/Action.js +5 -5
- package/bin/contact/Action.js.map +1 -1
- package/bin/contact/ContactPlugin.js +15 -15
- package/bin/contact/ContactPlugin.js.map +1 -1
- package/bin/contact/runtime/ChatRuntime.js +3 -3
- package/bin/contact/runtime/ChatRuntime.js.map +1 -1
- package/bin/contact/runtime/ContactStore.d.ts +8 -8
- package/bin/contact/runtime/ContactStore.d.ts.map +1 -1
- package/bin/contact/runtime/ContactStore.js +20 -20
- package/bin/contact/runtime/ContactStore.js.map +1 -1
- package/bin/contact/runtime/EndpointNotice.js +2 -2
- package/bin/contact/runtime/EndpointNotice.js.map +1 -1
- package/bin/contact/runtime/InboxStore.d.ts +6 -6
- package/bin/contact/runtime/InboxStore.d.ts.map +1 -1
- package/bin/contact/runtime/InboxStore.js +16 -16
- package/bin/contact/runtime/InboxStore.js.map +1 -1
- package/bin/contact/runtime/LinkApproval.js +14 -14
- package/bin/contact/runtime/LinkApproval.js.map +1 -1
- package/bin/contact/runtime/LinkStore.d.ts +2 -2
- package/bin/contact/runtime/LinkStore.d.ts.map +1 -1
- package/bin/contact/runtime/LinkStore.js +5 -5
- package/bin/contact/runtime/LinkStore.js.map +1 -1
- package/bin/contact/runtime/Paths.d.ts +15 -15
- package/bin/contact/runtime/Paths.d.ts.map +1 -1
- package/bin/contact/runtime/Paths.js +29 -29
- package/bin/contact/runtime/Paths.js.map +1 -1
- package/bin/contact/runtime/ShareBundle.d.ts +1 -1
- package/bin/contact/runtime/ShareBundle.d.ts.map +1 -1
- package/bin/contact/runtime/ShareBundle.js +4 -4
- package/bin/contact/runtime/ShareBundle.js.map +1 -1
- package/bin/contact/types/ContactApproval.d.ts +2 -2
- package/bin/contact/types/ContactApproval.d.ts.map +1 -1
- package/bin/image/ImagePlugin.d.ts +1 -4
- package/bin/image/ImagePlugin.d.ts.map +1 -1
- package/bin/image/ImagePlugin.js +26 -34
- package/bin/image/ImagePlugin.js.map +1 -1
- package/bin/image/runtime/ImageResultStorage.d.ts +2 -2
- package/bin/image/runtime/ImageResultStorage.d.ts.map +1 -1
- package/bin/image/runtime/ImageResultStorage.js +15 -38
- package/bin/image/runtime/ImageResultStorage.js.map +1 -1
- package/bin/image/types/ImagePlugin.d.ts +23 -16
- package/bin/image/types/ImagePlugin.d.ts.map +1 -1
- package/bin/image/types/ImagePlugin.js +1 -1
- package/bin/image.d.ts +1 -1
- package/bin/image.d.ts.map +1 -1
- package/bin/index.d.ts +2 -0
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -0
- package/bin/index.js.map +1 -1
- package/bin/memory/MemoryPlugin.d.ts +1 -1
- package/bin/memory/MemoryPlugin.d.ts.map +1 -1
- package/bin/memory/MemoryPlugin.js +17 -7
- package/bin/memory/MemoryPlugin.js.map +1 -1
- package/bin/memory/types/Memory.d.ts +10 -4
- package/bin/memory/types/Memory.d.ts.map +1 -1
- package/bin/memory.d.ts +1 -1
- package/bin/memory.d.ts.map +1 -1
- package/bin/renderers.d.ts +5 -0
- package/bin/renderers.d.ts.map +1 -0
- package/bin/renderers.js +12 -0
- package/bin/renderers.js.map +1 -0
- package/bin/sound/Plugin.d.ts +2 -5
- package/bin/sound/Plugin.d.ts.map +1 -1
- package/bin/sound/Plugin.js +27 -31
- package/bin/sound/Plugin.js.map +1 -1
- package/bin/sound/types/SoundPlugin.d.ts +22 -15
- package/bin/sound/types/SoundPlugin.d.ts.map +1 -1
- package/bin/sound/types/SoundPlugin.js +2 -2
- package/bin/sound.d.ts +1 -1
- package/bin/sound.d.ts.map +1 -1
- package/bin/task/Action.d.ts +6 -6
- package/bin/task/Action.d.ts.map +1 -1
- package/bin/task/Action.js +21 -21
- package/bin/task/Action.js.map +1 -1
- package/bin/task/PROMPT.d.ts +1 -1
- package/bin/task/PROMPT.d.ts.map +1 -1
- package/bin/task/PROMPT.js +1 -1
- package/bin/task/PROMPT.js.map +1 -1
- package/bin/task/Scheduler.js +8 -8
- package/bin/task/Scheduler.js.map +1 -1
- package/bin/task/TaskPlugin.d.ts +7 -14
- package/bin/task/TaskPlugin.d.ts.map +1 -1
- package/bin/task/TaskPlugin.js +54 -43
- package/bin/task/TaskPlugin.js.map +1 -1
- package/bin/task/runtime/Model.d.ts +1 -5
- package/bin/task/runtime/Model.d.ts.map +1 -1
- package/bin/task/runtime/Model.js +2 -13
- package/bin/task/runtime/Model.js.map +1 -1
- package/bin/task/runtime/Paths.d.ts +7 -7
- package/bin/task/runtime/Paths.d.ts.map +1 -1
- package/bin/task/runtime/Paths.js +11 -11
- package/bin/task/runtime/Paths.js.map +1 -1
- package/bin/task/runtime/Runner.d.ts +1 -1
- package/bin/task/runtime/Runner.d.ts.map +1 -1
- package/bin/task/runtime/Runner.js +4 -5
- package/bin/task/runtime/Runner.js.map +1 -1
- package/bin/task/runtime/Store.d.ts +9 -9
- package/bin/task/runtime/Store.d.ts.map +1 -1
- package/bin/task/runtime/Store.js +17 -17
- package/bin/task/runtime/Store.js.map +1 -1
- package/bin/task/runtime/TaskActionExecution.js +6 -6
- package/bin/task/runtime/TaskActionExecution.js.map +1 -1
- package/bin/task/runtime/TaskPluginActionRegistry.js +1 -1
- package/bin/task/runtime/TaskPluginActionRegistry.js.map +1 -1
- package/bin/task/runtime/TaskRunnerRound.d.ts +0 -1
- package/bin/task/runtime/TaskRunnerRound.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerRound.js +8 -3
- package/bin/task/runtime/TaskRunnerRound.js.map +1 -1
- package/bin/task/runtime/TaskRunnerScript.d.ts +0 -4
- package/bin/task/runtime/TaskRunnerScript.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerScript.js +0 -1
- package/bin/task/runtime/TaskRunnerScript.js.map +1 -1
- package/bin/task/runtime/TaskRunnerSession.d.ts +2 -3
- package/bin/task/runtime/TaskRunnerSession.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerSession.js +2 -4
- package/bin/task/runtime/TaskRunnerSession.js.map +1 -1
- package/bin/task/types/TaskWorkspaceRuntime.d.ts +10 -0
- package/bin/task/types/TaskWorkspaceRuntime.d.ts.map +1 -0
- package/bin/task/types/TaskWorkspaceRuntime.js +3 -0
- package/bin/task/types/TaskWorkspaceRuntime.js.map +1 -0
- package/bin/web/Plugin.d.ts +2 -6
- package/bin/web/Plugin.d.ts.map +1 -1
- package/bin/web/Plugin.js +21 -17
- package/bin/web/Plugin.js.map +1 -1
- package/bin/web/providers/PlaywrightBrowserProvider.d.ts.map +1 -1
- package/bin/web/providers/PlaywrightBrowserProvider.js +59 -14
- package/bin/web/providers/PlaywrightBrowserProvider.js.map +1 -1
- package/bin/web/types/WebPlugin.d.ts +15 -9
- package/bin/web/types/WebPlugin.d.ts.map +1 -1
- package/bin/web.d.ts +1 -1
- package/bin/web.d.ts.map +1 -1
- package/bin/workboard/runtime/Collector.js +1 -1
- package/bin/workboard/runtime/Collector.js.map +1 -1
- package/package.json +29 -20
- package/scripts/chat-access.test.mjs +3 -2
- package/scripts/chat-channel-config.test.mjs +3 -3
- package/scripts/chat-storage.test.mjs +10 -14
- package/scripts/memory-plugin.test.mjs +9 -32
- package/scripts/playwright-browser-provider.test.mjs +260 -0
- package/scripts/plugin-main.test.mjs +101 -0
- package/scripts/plugin-subpaths.test.mjs +28 -0
- package/scripts/sound-plugin.test.mjs +21 -9
- package/scripts/unrestricted-sandbox-approval.test.mjs +1 -1
- package/scripts/web-plugin.test.mjs +43 -186
- package/src/builtin/BuiltinPluginReadmes.ts +58 -0
- package/src/builtin/BuiltinPluginTypes.ts +260 -0
- package/src/builtin/PluginSettingsDefinitions.ts +45 -0
- package/src/builtin/main/PluginSettingsMain.ts +75 -0
- package/src/builtin/renderer/PluginSettingsRenderer.tsx +110 -0
- package/src/builtin/types/PluginSettings.ts +46 -0
- package/src/chat/ChatPlugin.ts +99 -51
- package/src/chat/access/ChatAccessRuntime.ts +1 -1
- package/src/chat/access/ChatAccessSchema.ts +5 -5
- package/src/chat/access/ChatAccessService.ts +4 -4
- package/src/chat/access/ChatAccessStore.ts +17 -9
- package/src/chat/channels/BaseChatChannel.ts +2 -0
- package/src/chat/channels/RuntimeChannel.ts +9 -9
- package/src/chat/channels/feishu/Feishu.ts +1 -1
- package/src/chat/channels/feishu/FeishuPlatformClient.ts +3 -0
- package/src/chat/channels/feishu/FeishuPlatformLookup.ts +3 -1
- package/src/chat/channels/qq/QQ.ts +3 -2
- package/src/chat/channels/qq/QQEventCapture.ts +3 -3
- package/src/chat/channels/qq/QQInboundDedupe.ts +2 -3
- package/src/chat/channels/qq/QQMessageHandler.ts +6 -0
- package/src/chat/channels/qq/QQSupport.ts +5 -0
- package/src/chat/channels/qq/VoiceInput.ts +5 -1
- package/src/chat/channels/telegram/ApiClient.ts +10 -3
- package/src/chat/channels/telegram/StateStore.ts +2 -2
- package/src/chat/channels/telegram/TelegramPlatformClient.ts +2 -1
- package/src/chat/main/ChatPluginMain.ts +163 -0
- package/src/chat/renderer/ChatPluginRenderer.tsx +149 -0
- package/src/chat/runtime/ChannelContextStore.ts +20 -20
- package/src/chat/runtime/ChatActionExecution.ts +6 -6
- package/src/chat/runtime/ChatChannelConfig.ts +7 -14
- package/src/chat/runtime/ChatChannelCore.ts +9 -9
- package/src/chat/runtime/ChatHistoryStore.ts +7 -7
- package/src/chat/runtime/ChatMetaStore.ts +1 -1
- package/src/chat/runtime/ChatPluginActionRegistry.ts +10 -10
- package/src/chat/runtime/ChatQueue.ts +2 -69
- package/src/chat/runtime/ChatQueueStore.ts +10 -26
- package/src/chat/runtime/ChatQueueWorker.ts +2 -5
- package/src/chat/runtime/ChatSessionDelete.ts +4 -4
- package/src/chat/runtime/ChatStorage.ts +24 -24
- package/src/chat/types/ChatAccess.ts +2 -2
- package/src/chat/types/ChatCommand.ts +1 -1
- package/src/chat/types/ChatPluginChannelConfig.ts +63 -0
- package/src/chat/types/ChatPluginConfig.ts +21 -0
- package/src/chat/types/ChatPluginOptions.ts +4 -4
- package/src/chat/types/ChatPluginProfile.ts +52 -0
- package/src/chat/types/ChatPluginRenderer.ts +25 -0
- package/src/chat/types/ChatRuntime.ts +14 -0
- package/src/chat/types/ChatRuntimeAccount.ts +3 -3
- package/src/chat/types/ChatStorage.ts +2 -2
- package/src/chat.ts +6 -14
- package/src/contact/Action.ts +5 -5
- package/src/contact/ContactPlugin.ts +15 -15
- package/src/contact/runtime/ChatRuntime.ts +3 -3
- package/src/contact/runtime/ContactStore.ts +20 -20
- package/src/contact/runtime/EndpointNotice.ts +2 -2
- package/src/contact/runtime/InboxStore.ts +16 -16
- package/src/contact/runtime/LinkApproval.ts +16 -16
- package/src/contact/runtime/LinkStore.ts +5 -5
- package/src/contact/runtime/Paths.ts +29 -29
- package/src/contact/runtime/ShareBundle.ts +5 -5
- package/src/contact/types/ContactApproval.ts +2 -2
- package/src/image/ImagePlugin.ts +30 -33
- package/src/image/runtime/ImageResultStorage.ts +36 -62
- package/src/image/types/ImagePlugin.ts +25 -19
- package/src/image.ts +2 -0
- package/src/index.ts +8 -0
- package/src/memory/MemoryPlugin.ts +17 -5
- package/src/memory/types/Memory.ts +11 -4
- package/src/memory.ts +1 -0
- package/src/renderers.ts +18 -0
- package/src/sound/Plugin.ts +34 -33
- package/src/sound/types/SoundPlugin.ts +24 -19
- package/src/sound.ts +2 -0
- package/src/task/Action.ts +27 -27
- package/src/task/PROMPT.ts +1 -1
- package/src/task/PROMPT.ts.txt +5 -6
- package/src/task/Scheduler.ts +8 -8
- package/src/task/TaskPlugin.ts +55 -46
- package/src/task/runtime/Model.ts +3 -13
- package/src/task/runtime/Paths.ts +11 -11
- package/src/task/runtime/Runner.ts +5 -6
- package/src/task/runtime/Store.ts +22 -22
- package/src/task/runtime/TaskActionExecution.ts +6 -6
- package/src/task/runtime/TaskPluginActionRegistry.ts +1 -1
- package/src/task/runtime/TaskRunnerRound.ts +13 -4
- package/src/task/runtime/TaskRunnerScript.ts +0 -5
- package/src/task/runtime/TaskRunnerSession.ts +10 -8
- package/src/task/types/TaskWorkspaceRuntime.ts +12 -0
- package/src/web/Plugin.ts +23 -22
- package/src/web/providers/PlaywrightBrowserProvider.ts +93 -17
- package/src/web/types/WebPlugin.ts +16 -13
- package/src/web.ts +1 -0
- package/src/workboard/runtime/Collector.ts +1 -1
- package/tsconfig.json +4 -1
- package/LICENSE +0 -183
- package/bin/chat/Index.d.ts +0 -15
- package/bin/chat/Index.d.ts.map +0 -1
- package/bin/chat/Index.js +0 -11
- package/bin/chat/Index.js.map +0 -1
- package/bin/chat/config/ChatPluginConfig.d.ts +0 -67
- package/bin/chat/config/ChatPluginConfig.d.ts.map +0 -1
- package/bin/chat/config/ChatPluginConfig.js +0 -237
- package/bin/chat/config/ChatPluginConfig.js.map +0 -1
- package/bin/chat/types/ChatPluginResource.d.ts +0 -68
- package/bin/chat/types/ChatPluginResource.d.ts.map +0 -1
- package/bin/chat/types/ChatPluginResource.js +0 -10
- package/bin/chat/types/ChatPluginResource.js.map +0 -1
- package/bin/contact/Index.d.ts +0 -8
- package/bin/contact/Index.d.ts.map +0 -1
- package/bin/contact/Index.js +0 -8
- package/bin/contact/Index.js.map +0 -1
- package/bin/memory/Index.d.ts +0 -11
- package/bin/memory/Index.d.ts.map +0 -1
- package/bin/memory/Index.js +0 -11
- package/bin/memory/Index.js.map +0 -1
- package/bin/skill/Command.d.ts +0 -29
- package/bin/skill/Command.d.ts.map +0 -1
- package/bin/skill/Command.js +0 -35
- package/bin/skill/Command.js.map +0 -1
- package/bin/task/Index.d.ts +0 -9
- package/bin/task/Index.d.ts.map +0 -1
- package/bin/task/Index.js +0 -9
- package/bin/task/Index.js.map +0 -1
- package/src/chat/Index.ts +0 -36
- package/src/chat/config/ChatPluginConfig.ts +0 -266
- package/src/chat/types/ChatPluginResource.ts +0 -95
- package/src/contact/Index.ts +0 -8
- package/src/memory/Index.ts +0 -14
- package/src/skill/Command.ts +0 -58
- package/src/task/Index.ts +0 -8
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Web、Image 与 Sound Plugin 自己拥有的设置 Mainview 字段定义。 */
|
|
2
|
+
|
|
3
|
+
import type { PluginSettingsDefinition } from "@/builtin/types/PluginSettings.js";
|
|
4
|
+
|
|
5
|
+
/** Web Plugin Profile 设置。 */
|
|
6
|
+
export const WEB_PLUGIN_SETTINGS: PluginSettingsDefinition = {
|
|
7
|
+
title: "Web",
|
|
8
|
+
description: "配置浏览器连接与页面观察默认值。未填写 CDP 地址时仍可使用搜索和文档读取。",
|
|
9
|
+
fields: [
|
|
10
|
+
{
|
|
11
|
+
key: "browser",
|
|
12
|
+
label: "Browser provider",
|
|
13
|
+
description: "当前支持 Playwright CDP 连接。",
|
|
14
|
+
type: "select",
|
|
15
|
+
options: [{ value: "playwright", label: "Playwright" }],
|
|
16
|
+
},
|
|
17
|
+
{ key: "cdp_url", label: "CDP endpoint", description: "现有浏览器的 HTTP 或 WebSocket 调试地址。", type: "string" },
|
|
18
|
+
{ key: "default_url", label: "Default URL", description: "浏览器 Session 没有指定地址时打开的页面。", type: "string" },
|
|
19
|
+
{ key: "timeout_ms", label: "Operation timeout (ms)", type: "number", minimum: 1000, maximum: 60000 },
|
|
20
|
+
{ key: "max_observation_chars", label: "Observation character limit", type: "number", minimum: 1, maximum: 100000 },
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Image Plugin Profile 设置。 */
|
|
25
|
+
export const IMAGE_PLUGIN_SETTINGS: PluginSettingsDefinition = {
|
|
26
|
+
title: "Image",
|
|
27
|
+
description: "选择图像生成请求没有显式指定模型时使用的默认模型。",
|
|
28
|
+
fields: [
|
|
29
|
+
{ key: "default_model", label: "Default image model", type: "string" },
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Sound Plugin Profile 设置。 */
|
|
34
|
+
export const SOUND_PLUGIN_SETTINGS: PluginSettingsDefinition = {
|
|
35
|
+
title: "Sound",
|
|
36
|
+
description: "配置语音识别和语音合成的默认行为。",
|
|
37
|
+
fields: [
|
|
38
|
+
{ key: "default_asr_model", label: "Default ASR model", type: "string" },
|
|
39
|
+
{ key: "default_tts_model", label: "Default TTS model", type: "string" },
|
|
40
|
+
{ key: "auto_asr", label: "Automatic transcription", description: "收到音频输入后自动执行语音识别。", type: "boolean" },
|
|
41
|
+
{ key: "language", label: "Default language", type: "string" },
|
|
42
|
+
{ key: "voice", label: "Default voice", type: "string" },
|
|
43
|
+
{ key: "format", label: "Default audio format", type: "string" },
|
|
44
|
+
],
|
|
45
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** 官方简单设置 Plugin 的 main action 实现。 */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
define_plugin_main,
|
|
5
|
+
type PluginJsonObject,
|
|
6
|
+
type PluginJsonValue,
|
|
7
|
+
type PluginMainModule,
|
|
8
|
+
} from "@downcity/plugin";
|
|
9
|
+
import type {
|
|
10
|
+
PluginSettingField,
|
|
11
|
+
PluginSettingsDefinition,
|
|
12
|
+
} from "@/builtin/types/PluginSettings.js";
|
|
13
|
+
|
|
14
|
+
/** 为一个字段集合创建 Profile 读取和保存 action。 */
|
|
15
|
+
export function create_plugin_settings_main(
|
|
16
|
+
definition: PluginSettingsDefinition,
|
|
17
|
+
): PluginMainModule {
|
|
18
|
+
return define_plugin_main({
|
|
19
|
+
activate({ plugin }) {
|
|
20
|
+
plugin.action({
|
|
21
|
+
id: "profile.read",
|
|
22
|
+
run: async (_input, context) => await context.config.get(),
|
|
23
|
+
});
|
|
24
|
+
plugin.action({
|
|
25
|
+
id: "profile.save",
|
|
26
|
+
run: async (input, context) => {
|
|
27
|
+
const config = normalize_settings(input, definition.fields);
|
|
28
|
+
await context.config.set(config);
|
|
29
|
+
return config;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 按 Plugin 自己声明的字段校验并规范化配置。 */
|
|
37
|
+
function normalize_settings(
|
|
38
|
+
input: PluginJsonValue | undefined,
|
|
39
|
+
fields: readonly PluginSettingField[],
|
|
40
|
+
): PluginJsonObject {
|
|
41
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
42
|
+
throw new Error("Plugin Profile config must be an object");
|
|
43
|
+
}
|
|
44
|
+
const source = input as PluginJsonObject;
|
|
45
|
+
const result: PluginJsonObject = {};
|
|
46
|
+
for (const field of fields) {
|
|
47
|
+
const value = source[field.key];
|
|
48
|
+
if (value === undefined || value === "") continue;
|
|
49
|
+
if (field.type === "boolean") {
|
|
50
|
+
if (typeof value !== "boolean") throw invalid_field(field.key);
|
|
51
|
+
result[field.key] = value;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (field.type === "number") {
|
|
55
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw invalid_field(field.key);
|
|
56
|
+
if (field.minimum !== undefined && value < field.minimum) throw invalid_field(field.key);
|
|
57
|
+
if (field.maximum !== undefined && value > field.maximum) throw invalid_field(field.key);
|
|
58
|
+
result[field.key] = value;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (typeof value !== "string") throw invalid_field(field.key);
|
|
62
|
+
const normalized = value.trim();
|
|
63
|
+
if (!normalized) continue;
|
|
64
|
+
if (field.type === "select" && !field.options?.some((item) => item.value === normalized)) {
|
|
65
|
+
throw invalid_field(field.key);
|
|
66
|
+
}
|
|
67
|
+
result[field.key] = normalized;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 创建稳定的字段校验错误。 */
|
|
73
|
+
function invalid_field(key: string): Error {
|
|
74
|
+
return new Error(`Invalid Plugin Profile field: ${key}`);
|
|
75
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** 官方简单设置 Plugin 的统一 React Mainview 生成器。 */
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import type { PluginJsonObject, PluginJsonValue } from "@downcity/plugin";
|
|
5
|
+
import {
|
|
6
|
+
define_plugin_renderer,
|
|
7
|
+
type PluginRendererComponent,
|
|
8
|
+
type PluginRendererUiComponents,
|
|
9
|
+
} from "@downcity/plugin/react";
|
|
10
|
+
import type { PluginSettingField, PluginSettingsDefinition } from "@/builtin/types/PluginSettings.js";
|
|
11
|
+
|
|
12
|
+
/** 根据具体 Plugin 的字段声明创建使用宿主 UI Components 的 Mainview。 */
|
|
13
|
+
export function create_plugin_settings_renderer(
|
|
14
|
+
definition: PluginSettingsDefinition,
|
|
15
|
+
): PluginRendererComponent {
|
|
16
|
+
return define_plugin_renderer(function PluginSettingsRenderer({ plugin, ui }) {
|
|
17
|
+
const { Button, Callout, Group, Input, LoadingState, Page, Row, Select, Switch, Toolbar } = ui.components;
|
|
18
|
+
const [draft, set_draft] = useState<PluginJsonObject>();
|
|
19
|
+
const [loading, set_loading] = useState(true);
|
|
20
|
+
const [saving, set_saving] = useState(false);
|
|
21
|
+
const [error, set_error] = useState("");
|
|
22
|
+
|
|
23
|
+
const load = useCallback(async () => {
|
|
24
|
+
set_loading(true);
|
|
25
|
+
set_error("");
|
|
26
|
+
try {
|
|
27
|
+
set_draft(await plugin.invoke<PluginJsonObject>("profile.read"));
|
|
28
|
+
} catch (reason) {
|
|
29
|
+
set_error(to_error_message(reason));
|
|
30
|
+
} finally {
|
|
31
|
+
set_loading(false);
|
|
32
|
+
}
|
|
33
|
+
}, [plugin]);
|
|
34
|
+
|
|
35
|
+
useEffect(() => { void load(); }, [load]);
|
|
36
|
+
|
|
37
|
+
const set_field = (field: PluginSettingField, value: PluginJsonValue | undefined) => {
|
|
38
|
+
set_draft((current) => {
|
|
39
|
+
const next = { ...(current ?? {}) };
|
|
40
|
+
if (value === undefined || value === "") delete next[field.key];
|
|
41
|
+
else next[field.key] = value;
|
|
42
|
+
return next;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const save = async () => {
|
|
47
|
+
if (!draft) return;
|
|
48
|
+
set_saving(true);
|
|
49
|
+
set_error("");
|
|
50
|
+
try {
|
|
51
|
+
const saved = await plugin.invoke<PluginJsonObject>("profile.save", draft);
|
|
52
|
+
set_draft(saved);
|
|
53
|
+
ui.toast({ type: "success", message: "Profile 已保存" });
|
|
54
|
+
} catch (reason) {
|
|
55
|
+
const message = to_error_message(reason);
|
|
56
|
+
set_error(message);
|
|
57
|
+
ui.toast({ type: "error", message });
|
|
58
|
+
} finally {
|
|
59
|
+
set_saving(false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (loading && !draft) return <LoadingState label="正在读取 Profile…" />;
|
|
64
|
+
|
|
65
|
+
return <Page>
|
|
66
|
+
<Toolbar
|
|
67
|
+
actions={<Button variant="primary" disabled={!draft || saving} on_click={() => void save()}>{saving ? "保存中…" : "保存"}</Button>}
|
|
68
|
+
/>
|
|
69
|
+
{error ? <Callout tone="danger">{error}</Callout> : null}
|
|
70
|
+
<Group>{definition.fields.map((field) => <Row
|
|
71
|
+
key={field.key}
|
|
72
|
+
label={field.label}
|
|
73
|
+
description={field.description}
|
|
74
|
+
trailing={<SettingControl field={field} value={draft?.[field.key]} set_value={(value) => set_field(field, value)} components={{ Input, Select, Switch }} />}
|
|
75
|
+
/>)}</Group>
|
|
76
|
+
</Page>;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 根据字段类型选择宿主表单控件。 */
|
|
81
|
+
function SettingControl({ field, value, set_value, components }: {
|
|
82
|
+
/** 当前字段定义。 */
|
|
83
|
+
readonly field: PluginSettingField;
|
|
84
|
+
/** 当前字段值。 */
|
|
85
|
+
readonly value: PluginJsonValue | undefined;
|
|
86
|
+
/** 写回字段值。 */
|
|
87
|
+
set_value(value: PluginJsonValue | undefined): void;
|
|
88
|
+
/** 当前 Mainview 使用的表单组件。 */
|
|
89
|
+
readonly components: Pick<PluginRendererUiComponents, "Input" | "Select" | "Switch">;
|
|
90
|
+
}) {
|
|
91
|
+
const { Input, Select, Switch } = components;
|
|
92
|
+
if (field.type === "boolean") {
|
|
93
|
+
return <Switch checked={value === true} on_checked_change={set_value} aria_label={field.label} />;
|
|
94
|
+
}
|
|
95
|
+
if (field.type === "select") {
|
|
96
|
+
return <Select value={typeof value === "string" ? value : ""} options={field.options ?? []} on_value_change={set_value} />;
|
|
97
|
+
}
|
|
98
|
+
return <Input
|
|
99
|
+
type={field.type === "number" ? "number" : "text"}
|
|
100
|
+
value={typeof value === "string" || typeof value === "number" ? String(value) : ""}
|
|
101
|
+
minimum={field.minimum}
|
|
102
|
+
maximum={field.maximum}
|
|
103
|
+
on_value_change={(next_value) => set_value(field.type === "number" ? next_value === "" ? undefined : Number(next_value) : next_value)}
|
|
104
|
+
/>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 把未知失败转换为用户可见消息。 */
|
|
108
|
+
function to_error_message(reason: unknown): string {
|
|
109
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
110
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** 官方 Plugin 设置 Mainview 的内部声明类型。 */
|
|
2
|
+
|
|
3
|
+
/** 简单设置字段支持的值类型。 */
|
|
4
|
+
export type PluginSettingFieldType = "string" | "number" | "boolean" | "select";
|
|
5
|
+
|
|
6
|
+
/** 一个由具体 Plugin 声明的设置字段。 */
|
|
7
|
+
export interface PluginSettingField {
|
|
8
|
+
/** Profile 配置中的稳定字段名。 */
|
|
9
|
+
readonly key: string;
|
|
10
|
+
|
|
11
|
+
/** Mainview 展示名称。 */
|
|
12
|
+
readonly label: string;
|
|
13
|
+
|
|
14
|
+
/** 可选的用户说明。 */
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
|
|
17
|
+
/** 字段值类型。 */
|
|
18
|
+
readonly type: PluginSettingFieldType;
|
|
19
|
+
|
|
20
|
+
/** 数字字段允许的最小值。 */
|
|
21
|
+
readonly minimum?: number;
|
|
22
|
+
|
|
23
|
+
/** 数字字段允许的最大值。 */
|
|
24
|
+
readonly maximum?: number;
|
|
25
|
+
|
|
26
|
+
/** select 字段允许的稳定选项。 */
|
|
27
|
+
readonly options?: readonly {
|
|
28
|
+
/** 保存到配置的值。 */
|
|
29
|
+
readonly value: string;
|
|
30
|
+
|
|
31
|
+
/** Mainview 展示文本。 */
|
|
32
|
+
readonly label: string;
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 一个简单设置 Mainview 的完整定义。 */
|
|
37
|
+
export interface PluginSettingsDefinition {
|
|
38
|
+
/** Mainview 标题。 */
|
|
39
|
+
readonly title: string;
|
|
40
|
+
|
|
41
|
+
/** Mainview 说明。 */
|
|
42
|
+
readonly description: string;
|
|
43
|
+
|
|
44
|
+
/** Plugin 自己拥有的全部配置字段。 */
|
|
45
|
+
readonly fields: readonly PluginSettingField[];
|
|
46
|
+
}
|
package/src/chat/ChatPlugin.ts
CHANGED
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
import { BasePlugin } from "@downcity/agent";
|
|
12
12
|
import type { PluginActions } from "@downcity/agent";
|
|
13
|
-
import type { PluginContext } from "@downcity/agent";
|
|
13
|
+
import type { PluginContext, AgentPluginContext } from "@downcity/agent";
|
|
14
14
|
import type { PluginExecutionContext } from "@downcity/agent";
|
|
15
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
ChatChannelState,
|
|
17
|
+
ChatWorkspaceRuntime,
|
|
18
|
+
} from "@/chat/types/ChatRuntime.js";
|
|
16
19
|
import type { ChatQueueWorkerConfig } from "@/chat/types/ChatQueueWorker.js";
|
|
17
20
|
import type {
|
|
18
21
|
ChatChannel,
|
|
@@ -52,28 +55,11 @@ export class ChatPlugin extends BasePlugin {
|
|
|
52
55
|
*/
|
|
53
56
|
readonly name = "chat";
|
|
54
57
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
public readonly channelState: ChatChannelState = createChatChannelState();
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 当前实例持有的 chat queue worker。
|
|
62
|
-
*
|
|
63
|
-
* 关键点(中文)
|
|
64
|
-
* - worker 生命周期与 chat plugin 保持一致。
|
|
65
|
-
* - 这样 agent 只负责装配,不直接持有 chat 领域长期状态。
|
|
66
|
-
*/
|
|
67
|
-
public queueWorker: ChatQueueWorker | null = null;
|
|
58
|
+
/** 各 Workspace 独立持有的渠道与队列运行态。 */
|
|
59
|
+
private readonly runtimes_by_workspace = new Map<string, ChatWorkspaceRuntime>();
|
|
68
60
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
* 关键点(中文)
|
|
73
|
-
* - 这是 chat queue 状态的实例归属起点。
|
|
74
|
-
* - 迁移完成后,入队路径也会统一走这里,而不是模块级全局 queue。
|
|
75
|
-
*/
|
|
76
|
-
public readonly queueStore = new ChatQueueStore();
|
|
61
|
+
/** 各 Workspace 当前唯一的懒启动流程,避免 system/action 并发重复连接渠道。 */
|
|
62
|
+
private readonly starts_by_workspace = new Map<string, Promise<void>>();
|
|
77
63
|
|
|
78
64
|
/**
|
|
79
65
|
* 当前实例持有的显式 plugin 配置。
|
|
@@ -92,6 +78,7 @@ export class ChatPlugin extends BasePlugin {
|
|
|
92
78
|
context: PluginContext,
|
|
93
79
|
execution_context?: PluginExecutionContext,
|
|
94
80
|
): Promise<string> => {
|
|
81
|
+
await this.ensure_workspace_runtime(context);
|
|
95
82
|
return await buildChatPluginSystem(context, execution_context);
|
|
96
83
|
};
|
|
97
84
|
|
|
@@ -103,26 +90,52 @@ export class ChatPlugin extends BasePlugin {
|
|
|
103
90
|
/**
|
|
104
91
|
* 启动当前实例的 queue worker。
|
|
105
92
|
*/
|
|
106
|
-
private
|
|
107
|
-
if (this.
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
93
|
+
private async start_workspace_runtime(context: PluginContext): Promise<void> {
|
|
94
|
+
if (this.runtimes_by_workspace.has(context.workspace_id)) return;
|
|
95
|
+
const started = this.starts_by_workspace.get(context.workspace_id);
|
|
96
|
+
if (started) return await started;
|
|
97
|
+
const start_promise = (async () => {
|
|
98
|
+
const channel_state = createChatChannelState();
|
|
99
|
+
const queue_store = new ChatQueueStore();
|
|
100
|
+
const worker = new ChatQueueWorker({
|
|
101
|
+
logger: context.logger,
|
|
102
|
+
context,
|
|
103
|
+
queueStore: queue_store,
|
|
104
|
+
config: this.getQueueWorkerConfig(context),
|
|
105
|
+
});
|
|
106
|
+
worker.start();
|
|
107
|
+
this.runtimes_by_workspace.set(context.workspace_id, {
|
|
108
|
+
channel_state,
|
|
109
|
+
queue_store,
|
|
110
|
+
queue_worker: worker,
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
await startChatChannels(channel_state, context);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
this.runtimes_by_workspace.delete(context.workspace_id);
|
|
116
|
+
worker.stop();
|
|
117
|
+
await stopChatChannels(channel_state);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
this.starts_by_workspace.set(context.workspace_id, start_promise);
|
|
122
|
+
try {
|
|
123
|
+
await start_promise;
|
|
124
|
+
} finally {
|
|
125
|
+
if (this.starts_by_workspace.get(context.workspace_id) === start_promise) {
|
|
126
|
+
this.starts_by_workspace.delete(context.workspace_id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (!
|
|
125
|
-
|
|
131
|
+
/** 按当前 Workspace Context 懒启动 chat 运行态。 */
|
|
132
|
+
private async ensure_workspace_runtime(context: PluginContext): Promise<ChatWorkspaceRuntime> {
|
|
133
|
+
const existing = this.runtimes_by_workspace.get(context.workspace_id);
|
|
134
|
+
if (existing) return existing;
|
|
135
|
+
await this.start_workspace_runtime(context);
|
|
136
|
+
const runtime = this.runtimes_by_workspace.get(context.workspace_id);
|
|
137
|
+
if (!runtime) throw new Error(`ChatPlugin failed to start Workspace runtime: ${context.workspace_id}`);
|
|
138
|
+
return runtime;
|
|
126
139
|
}
|
|
127
140
|
|
|
128
141
|
constructor(options?: ChatPluginOptions) {
|
|
@@ -133,22 +146,57 @@ export class ChatPlugin extends BasePlugin {
|
|
|
133
146
|
: createDefaultChannels();
|
|
134
147
|
this.actions = {
|
|
135
148
|
...createChatPluginActions({
|
|
136
|
-
|
|
149
|
+
resolve_channel_state: (context) => this.resolve_channel_state(context),
|
|
137
150
|
}),
|
|
138
151
|
...create_chat_access_actions(),
|
|
139
152
|
};
|
|
140
153
|
this.lifecycle = {
|
|
141
|
-
start: async (
|
|
142
|
-
|
|
143
|
-
await
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
start: async (_context: AgentPluginContext) => {},
|
|
155
|
+
stop: async (_context: AgentPluginContext) => {
|
|
156
|
+
await Promise.allSettled([...this.starts_by_workspace.values()]);
|
|
157
|
+
await Promise.all([...this.runtimes_by_workspace.values()].map(async (runtime) => {
|
|
158
|
+
runtime.queue_worker.stop();
|
|
159
|
+
await stopChatChannels(runtime.channel_state);
|
|
160
|
+
}));
|
|
161
|
+
this.runtimes_by_workspace.clear();
|
|
162
|
+
this.starts_by_workspace.clear();
|
|
148
163
|
},
|
|
149
164
|
};
|
|
150
165
|
}
|
|
151
166
|
|
|
167
|
+
/** 读取当前 Workspace 的渠道状态。 */
|
|
168
|
+
private resolve_channel_state(context: PluginContext): ChatChannelState {
|
|
169
|
+
const runtime = this.runtimes_by_workspace.get(context.workspace_id);
|
|
170
|
+
if (!runtime) {
|
|
171
|
+
const channel_state = createChatChannelState();
|
|
172
|
+
const queue_store = new ChatQueueStore();
|
|
173
|
+
const worker = new ChatQueueWorker({
|
|
174
|
+
logger: context.logger,
|
|
175
|
+
context,
|
|
176
|
+
queueStore: queue_store,
|
|
177
|
+
config: this.getQueueWorkerConfig(context),
|
|
178
|
+
});
|
|
179
|
+
worker.start();
|
|
180
|
+
const created = { channel_state, queue_store, queue_worker: worker } satisfies ChatWorkspaceRuntime;
|
|
181
|
+
this.runtimes_by_workspace.set(context.workspace_id, created);
|
|
182
|
+
void startChatChannels(channel_state, context).catch((error) => {
|
|
183
|
+
context.logger.warn(`[chat] channel startup failed: ${String(error)}`);
|
|
184
|
+
});
|
|
185
|
+
return channel_state;
|
|
186
|
+
}
|
|
187
|
+
return runtime.channel_state;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** 向 chat 入队路径暴露当前 Workspace 的独立队列。 */
|
|
191
|
+
queue_store(context: PluginContext): ChatQueueStore {
|
|
192
|
+
const runtime = this.runtimes_by_workspace.get(context.workspace_id);
|
|
193
|
+
if (!runtime) {
|
|
194
|
+
this.resolve_channel_state(context);
|
|
195
|
+
return this.runtimes_by_workspace.get(context.workspace_id)!.queue_store;
|
|
196
|
+
}
|
|
197
|
+
return runtime.queue_store;
|
|
198
|
+
}
|
|
199
|
+
|
|
152
200
|
/**
|
|
153
201
|
* 读取 queue worker 配置。
|
|
154
202
|
*/
|
|
@@ -169,11 +217,11 @@ export class ChatPlugin extends BasePlugin {
|
|
|
169
217
|
/**
|
|
170
218
|
* 读取指定渠道的显式账户 ID。
|
|
171
219
|
*/
|
|
172
|
-
|
|
220
|
+
get_channel_id(
|
|
173
221
|
context: PluginContext,
|
|
174
222
|
channel: ChatChannelName,
|
|
175
223
|
): string {
|
|
176
|
-
return String(this.getChannel(channel)?.
|
|
224
|
+
return String(this.getChannel(channel)?.get_channel_id(context) || "").trim();
|
|
177
225
|
}
|
|
178
226
|
|
|
179
227
|
/**
|
|
@@ -28,7 +28,7 @@ export function resolve_chat_access_issuer_map(
|
|
|
28
28
|
/** 创建当前 Agent 的 ChatAccessService。 */
|
|
29
29
|
export function create_chat_access_service(context: PluginContext): ChatAccessService {
|
|
30
30
|
return new ChatAccessService({
|
|
31
|
-
|
|
31
|
+
data_path: context.data_path,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - WAL 与 busy_timeout 保证 Agent runtime 和 CLI 可以并发读写。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type
|
|
10
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
11
11
|
|
|
12
12
|
/** 当前 Chat Access Schema 版本。 */
|
|
13
13
|
export const CHAT_ACCESS_SCHEMA_VERSION = "1";
|
|
@@ -15,10 +15,10 @@ export const CHAT_ACCESS_SCHEMA_VERSION = "1";
|
|
|
15
15
|
/**
|
|
16
16
|
* 初始化 Chat Access Schema。
|
|
17
17
|
*/
|
|
18
|
-
export function ensure_chat_access_schema(database:
|
|
19
|
-
database.
|
|
20
|
-
database.
|
|
21
|
-
database.
|
|
18
|
+
export function ensure_chat_access_schema(database: DatabaseSync): void {
|
|
19
|
+
database.exec("PRAGMA journal_mode = WAL;");
|
|
20
|
+
database.exec("PRAGMA foreign_keys = ON;");
|
|
21
|
+
database.exec("PRAGMA busy_timeout = 5000;");
|
|
22
22
|
|
|
23
23
|
database.exec(`
|
|
24
24
|
CREATE TABLE IF NOT EXISTS chat_access_meta (
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 所有平台共用相同的 Principal、Grant、Request 和 Audit 业务规则。
|
|
6
6
|
* - Chat Access 只做准入判定,不向 Agent Session 或其他 Plugin 传播权限。
|
|
7
|
-
* -
|
|
7
|
+
* - 每个方法自行打开并关闭 Agent private runtime directory Store,避免 Channel 生命周期遗漏连接释放。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import path from "node:path";
|
|
@@ -63,13 +63,13 @@ export function resolve_chat_access_scope(
|
|
|
63
63
|
* 当前 Agent 的 Chat Access 应用服务。
|
|
64
64
|
*/
|
|
65
65
|
export class ChatAccessService {
|
|
66
|
-
private readonly
|
|
66
|
+
private readonly data_path: string;
|
|
67
67
|
constructor(options: ChatAccessServiceOptions) {
|
|
68
|
-
this.
|
|
68
|
+
this.data_path = path.resolve(normalize_text(options.data_path) || ".");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
private with_store<T>(operation: (store: ChatAccessStore) => T): T {
|
|
72
|
-
const store = new ChatAccessStore(this.
|
|
72
|
+
const store = new ChatAccessStore(this.data_path);
|
|
73
73
|
try {
|
|
74
74
|
return operation(store);
|
|
75
75
|
} finally {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Service 负责业务编排,Store 只负责结构化读写和事务。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import { DatabaseSync } from "node:sqlite";
|
|
11
11
|
import fs from "fs-extra";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import { generate_id } from "@downcity/agent";
|
|
@@ -34,10 +34,10 @@ import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
|
|
|
34
34
|
type SqlRow = Record<string, unknown>;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* 返回 Agent private runtime directory Chat Access 数据库路径。
|
|
38
38
|
*/
|
|
39
|
-
export function get_chat_access_db_path(
|
|
40
|
-
return path.join(path.resolve(
|
|
39
|
+
export function get_chat_access_db_path(data_path: string): string {
|
|
40
|
+
return path.join(path.resolve(data_path), "chat", "access.db");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function normalize_text(value: unknown): string {
|
|
@@ -126,15 +126,15 @@ function to_request(row: SqlRow | undefined): ChatAccessRequest | null {
|
|
|
126
126
|
* 当前 Agent 的 Chat Access SQLite Store。
|
|
127
127
|
*/
|
|
128
128
|
export class ChatAccessStore {
|
|
129
|
-
private readonly database:
|
|
129
|
+
private readonly database: DatabaseSync;
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* 打开当前项目 Chat Access 数据库。
|
|
133
133
|
*/
|
|
134
|
-
constructor(
|
|
135
|
-
const database_path = get_chat_access_db_path(
|
|
134
|
+
constructor(data_path: string) {
|
|
135
|
+
const database_path = get_chat_access_db_path(data_path);
|
|
136
136
|
fs.ensureDirSync(path.dirname(database_path), { mode: 0o700 });
|
|
137
|
-
this.database = new
|
|
137
|
+
this.database = new DatabaseSync(database_path);
|
|
138
138
|
ensure_chat_access_schema(this.database);
|
|
139
139
|
try {
|
|
140
140
|
fs.chmodSync(database_path, 0o600);
|
|
@@ -150,7 +150,15 @@ export class ChatAccessStore {
|
|
|
150
150
|
|
|
151
151
|
/** 在单个 SQLite 事务中执行操作。 */
|
|
152
152
|
transaction<T>(operation: () => T): T {
|
|
153
|
-
|
|
153
|
+
this.database.exec("BEGIN IMMEDIATE;");
|
|
154
|
+
try {
|
|
155
|
+
const result = operation();
|
|
156
|
+
this.database.exec("COMMIT;");
|
|
157
|
+
return result;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
this.database.exec("ROLLBACK;");
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
154
162
|
}
|
|
155
163
|
|
|
156
164
|
/** 读取 Store 元信息。 */
|
|
@@ -131,6 +131,7 @@ export abstract class BaseChatChannel {
|
|
|
131
131
|
readonly channel: ChatDispatchChannel;
|
|
132
132
|
protected readonly context: PluginContext;
|
|
133
133
|
protected readonly rootPath: string;
|
|
134
|
+
protected readonly dataPath: string;
|
|
134
135
|
protected readonly logger: Logger;
|
|
135
136
|
private readonly access_notice_sent_at = new Map<string, number>();
|
|
136
137
|
|
|
@@ -141,6 +142,7 @@ export abstract class BaseChatChannel {
|
|
|
141
142
|
this.channel = params.channel;
|
|
142
143
|
this.context = params.context;
|
|
143
144
|
this.rootPath = params.context.workspace_path;
|
|
145
|
+
this.dataPath = params.context.data_path;
|
|
144
146
|
this.logger = params.context.logger;
|
|
145
147
|
|
|
146
148
|
const dispatcher: ChatDispatcher = {
|