@downcity/plugins 1.0.174 → 1.0.194
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/BuiltinPlugins.d.ts +4 -9
- package/bin/BuiltinPlugins.d.ts.map +1 -1
- package/bin/BuiltinPlugins.js +4 -8
- package/bin/BuiltinPlugins.js.map +1 -1
- package/bin/chat/Action.d.ts +8 -2
- package/bin/chat/Action.d.ts.map +1 -1
- package/bin/chat/Action.js +9 -5
- package/bin/chat/Action.js.map +1 -1
- package/bin/chat/ChatPlugin.d.ts +2 -22
- package/bin/chat/ChatPlugin.d.ts.map +1 -1
- package/bin/chat/ChatPlugin.js +2 -21
- package/bin/chat/ChatPlugin.js.map +1 -1
- package/bin/chat/Index.d.ts +1 -1
- package/bin/chat/Index.d.ts.map +1 -1
- package/bin/chat/channels/BaseChatChannel.js +1 -1
- package/bin/chat/channels/BaseChatChannel.js.map +1 -1
- package/bin/chat/channels/Configuration.d.ts +1 -1
- package/bin/chat/channels/Configuration.js +1 -1
- package/bin/chat/channels/RuntimeChannel.d.ts +2 -3
- package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -1
- package/bin/chat/channels/RuntimeChannel.js +0 -8
- package/bin/chat/channels/RuntimeChannel.js.map +1 -1
- package/bin/chat/channels/feishu/Feishu.d.ts.map +1 -1
- package/bin/chat/channels/feishu/Feishu.js +2 -1
- package/bin/chat/channels/feishu/Feishu.js.map +1 -1
- package/bin/chat/runtime/ChannelContextStore.d.ts.map +1 -1
- package/bin/chat/runtime/ChannelContextStore.js +13 -12
- package/bin/chat/runtime/ChannelContextStore.js.map +1 -1
- package/bin/chat/runtime/ChatActionExecution.d.ts +26 -1
- package/bin/chat/runtime/ChatActionExecution.d.ts.map +1 -1
- package/bin/chat/runtime/ChatActionExecution.js +31 -3
- package/bin/chat/runtime/ChatActionExecution.js.map +1 -1
- package/bin/chat/runtime/ChatActionInput.d.ts +1 -2
- package/bin/chat/runtime/ChatActionInput.d.ts.map +1 -1
- package/bin/chat/runtime/ChatActionInput.js +1 -27
- package/bin/chat/runtime/ChatActionInput.js.map +1 -1
- package/bin/chat/runtime/ChatChannelActions.d.ts +2 -66
- package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelActions.js +3 -195
- package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -23
- package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.js +3 -116
- package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.d.ts +0 -14
- package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.js +1 -1
- package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
- package/bin/chat/runtime/ChatChannelFacade.d.ts +1 -1
- package/bin/chat/runtime/ChatChannelFacade.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelFacade.js +1 -1
- package/bin/chat/runtime/ChatChannelFacade.js.map +1 -1
- package/bin/chat/runtime/ChatHistoryStore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatHistoryStore.js +4 -3
- package/bin/chat/runtime/ChatHistoryStore.js.map +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.d.ts.map +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.js +27 -89
- package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
- package/bin/chat/runtime/ChatPluginSystem.d.ts +3 -2
- package/bin/chat/runtime/ChatPluginSystem.d.ts.map +1 -1
- package/bin/chat/runtime/ChatPluginSystem.js +5 -5
- package/bin/chat/runtime/ChatPluginSystem.js.map +1 -1
- package/bin/chat/runtime/ChatQueueStore.d.ts +1 -1
- package/bin/chat/runtime/ChatQueueStore.js +2 -2
- package/bin/chat/runtime/ChatQueueStore.js.map +1 -1
- package/bin/chat/runtime/ChatQueueWorker.js +1 -1
- package/bin/chat/runtime/ChatQueueWorker.js.map +1 -1
- package/bin/chat/runtime/ChatSessionDelete.d.ts.map +1 -1
- package/bin/chat/runtime/ChatSessionDelete.js +11 -20
- package/bin/chat/runtime/ChatSessionDelete.js.map +1 -1
- package/bin/chat/runtime/ChatStorage.d.ts +32 -0
- package/bin/chat/runtime/ChatStorage.d.ts.map +1 -0
- package/bin/chat/runtime/ChatStorage.js +158 -0
- package/bin/chat/runtime/ChatStorage.js.map +1 -0
- package/bin/chat/runtime/SystemPrompt.d.ts +3 -2
- package/bin/chat/runtime/SystemPrompt.d.ts.map +1 -1
- package/bin/chat/runtime/SystemPrompt.js +4 -5
- package/bin/chat/runtime/SystemPrompt.js.map +1 -1
- package/bin/chat/types/ChannelConfiguration.d.ts +2 -2
- package/bin/chat/types/ChatPluginActionPayload.d.ts +7 -45
- package/bin/chat/types/ChatPluginActionPayload.d.ts.map +1 -1
- package/bin/chat/types/ChatPluginOptions.d.ts +0 -21
- package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -1
- package/bin/chat/types/ChatStorage.d.ts +36 -0
- package/bin/chat/types/ChatStorage.d.ts.map +1 -0
- package/bin/chat/types/ChatStorage.js +9 -0
- package/bin/chat/types/ChatStorage.js.map +1 -0
- package/bin/contact/Action.d.ts +3 -2
- package/bin/contact/Action.d.ts.map +1 -1
- package/bin/contact/Action.js +2 -2
- package/bin/contact/Action.js.map +1 -1
- package/bin/contact/ContactPlugin.d.ts.map +1 -1
- package/bin/contact/ContactPlugin.js +17 -14
- package/bin/contact/ContactPlugin.js.map +1 -1
- package/bin/contact/runtime/ChatRuntime.js +1 -1
- package/bin/contact/runtime/ChatRuntime.js.map +1 -1
- package/bin/contact/types/ContactPluginOptions.d.ts +4 -0
- package/bin/contact/types/ContactPluginOptions.d.ts.map +1 -1
- package/bin/index.d.ts +5 -5
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -2
- package/bin/index.js.map +1 -1
- package/bin/memory/Action.d.ts.map +1 -1
- package/bin/memory/Action.js +16 -4
- package/bin/memory/Action.js.map +1 -1
- package/bin/memory/runtime/Store.d.ts.map +1 -1
- package/bin/memory/runtime/Store.js +0 -22
- package/bin/memory/runtime/Store.js.map +1 -1
- package/bin/memory/runtime/Writer.d.ts +1 -1
- package/bin/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/memory/runtime/Writer.js +2 -4
- package/bin/memory/runtime/Writer.js.map +1 -1
- package/bin/skill/Command.d.ts +3 -11
- package/bin/skill/Command.d.ts.map +1 -1
- package/bin/skill/Command.js +3 -31
- package/bin/skill/Command.js.map +1 -1
- package/bin/skill/PROMPT.d.ts +1 -1
- package/bin/skill/PROMPT.d.ts.map +1 -1
- package/bin/skill/PROMPT.js +1 -1
- package/bin/skill/PROMPT.js.map +1 -1
- package/bin/skill/Plugin.d.ts +3 -2
- package/bin/skill/Plugin.d.ts.map +1 -1
- package/bin/skill/Plugin.js +37 -129
- package/bin/skill/Plugin.js.map +1 -1
- package/bin/skill/runtime/Prompt.d.ts +11 -2
- package/bin/skill/runtime/Prompt.d.ts.map +1 -1
- package/bin/skill/runtime/Prompt.js +93 -8
- package/bin/skill/runtime/Prompt.js.map +1 -1
- package/bin/skill/runtime/SystemProvider.d.ts +2 -1
- package/bin/skill/runtime/SystemProvider.d.ts.map +1 -1
- package/bin/skill/runtime/SystemProvider.js +4 -9
- package/bin/skill/runtime/SystemProvider.js.map +1 -1
- package/bin/skill/types/SkillPlugin.d.ts +6 -18
- package/bin/skill/types/SkillPlugin.d.ts.map +1 -1
- package/bin/skill/types/SkillPlugin.js +2 -2
- package/bin/sound/Plugin.d.ts +69 -0
- package/bin/sound/Plugin.d.ts.map +1 -0
- package/bin/sound/Plugin.js +623 -0
- package/bin/sound/Plugin.js.map +1 -0
- package/bin/sound/types/SoundPlugin.d.ts +150 -0
- package/bin/sound/types/SoundPlugin.d.ts.map +1 -0
- package/bin/sound/types/SoundPlugin.js +10 -0
- package/bin/sound/types/SoundPlugin.js.map +1 -0
- package/bin/task/Action.d.ts +2 -0
- package/bin/task/Action.d.ts.map +1 -1
- package/bin/task/Action.js +6 -0
- package/bin/task/Action.js.map +1 -1
- package/bin/task/runtime/Runner.d.ts +4 -0
- package/bin/task/runtime/Runner.d.ts.map +1 -1
- package/bin/task/runtime/Runner.js +15 -11
- package/bin/task/runtime/Runner.js.map +1 -1
- package/bin/task/runtime/TaskActionExecution.d.ts +2 -0
- package/bin/task/runtime/TaskActionExecution.d.ts.map +1 -1
- package/bin/task/runtime/TaskActionExecution.js +1 -0
- package/bin/task/runtime/TaskActionExecution.js.map +1 -1
- package/bin/task/runtime/TaskPluginActionRegistry.d.ts.map +1 -1
- package/bin/task/runtime/TaskPluginActionRegistry.js +1 -0
- package/bin/task/runtime/TaskPluginActionRegistry.js.map +1 -1
- package/bin/task/runtime/TaskRunChatDispatch.js +1 -1
- package/bin/task/runtime/TaskRunChatDispatch.js.map +1 -1
- package/bin/task/runtime/TaskRunnerRound.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerRound.js +19 -26
- package/bin/task/runtime/TaskRunnerRound.js.map +1 -1
- package/bin/task/runtime/TaskRunnerSession.d.ts +6 -2
- package/bin/task/runtime/TaskRunnerSession.d.ts.map +1 -1
- package/bin/task/runtime/TaskRunnerSession.js +93 -72
- package/bin/task/runtime/TaskRunnerSession.js.map +1 -1
- package/bin/task/runtime/TaskRunnerTypes.d.ts +4 -4
- package/bin/task/runtime/TaskRunnerTypes.d.ts.map +1 -1
- package/bin/task/types/TaskPluginOptions.d.ts.map +1 -1
- package/bin/web/PROMPT.d.ts +1 -1
- package/bin/web/PROMPT.d.ts.map +1 -1
- package/bin/web/PROMPT.js +2 -2
- package/bin/web/PROMPT.js.map +1 -1
- package/bin/web/Plugin.d.ts +1 -21
- package/bin/web/Plugin.d.ts.map +1 -1
- package/bin/web/Plugin.js +14 -79
- package/bin/web/Plugin.js.map +1 -1
- package/bin/web/runtime/Prompt.d.ts +14 -0
- package/bin/web/runtime/Prompt.d.ts.map +1 -0
- package/bin/web/runtime/Prompt.js +77 -0
- package/bin/web/runtime/Prompt.js.map +1 -0
- package/bin/web/types/WebPlugin.d.ts +40 -29
- package/bin/web/types/WebPlugin.d.ts.map +1 -1
- package/bin/web/types/WebPlugin.js +11 -3
- package/bin/web/types/WebPlugin.js.map +1 -1
- package/bin/workboard/runtime/Collector.js +1 -1
- package/bin/workboard/runtime/Collector.js.map +1 -1
- package/bin/workboard/runtime/Normalizer.js +1 -1
- package/bin/workboard/runtime/Normalizer.js.map +1 -1
- package/bin/workboard/runtime/SessionSummary.d.ts.map +1 -1
- package/bin/workboard/runtime/SessionSummary.js +11 -38
- package/bin/workboard/runtime/SessionSummary.js.map +1 -1
- package/package.json +8 -4
- package/scripts/chat-access.test.mjs +1 -1
- package/scripts/chat-channel-config.test.mjs +15 -64
- package/scripts/chat-storage.test.mjs +92 -0
- package/scripts/skill-plugin.test.mjs +93 -0
- package/scripts/sound-plugin.test.mjs +250 -0
- package/scripts/web-plugin.test.mjs +85 -0
- package/src/BuiltinPlugins.ts +7 -17
- package/src/chat/Action.ts +16 -5
- package/src/chat/ChatPlugin.ts +6 -35
- package/src/chat/Index.ts +0 -1
- package/src/chat/channels/BaseChatChannel.ts +1 -1
- package/src/chat/channels/Configuration.ts +1 -1
- package/src/chat/channels/RuntimeChannel.ts +2 -14
- package/src/chat/channels/feishu/Feishu.ts +2 -1
- package/src/chat/runtime/ChannelContextStore.ts +16 -12
- package/src/chat/runtime/ChatActionExecution.ts +48 -3
- package/src/chat/runtime/ChatActionInput.ts +0 -31
- package/src/chat/runtime/ChatChannelActions.ts +3 -254
- package/src/chat/runtime/ChatChannelConfig.ts +4 -133
- package/src/chat/runtime/ChatChannelCore.ts +1 -15
- package/src/chat/runtime/ChatChannelFacade.ts +0 -4
- package/src/chat/runtime/ChatHistoryStore.ts +4 -3
- package/src/chat/runtime/ChatPluginActionRegistry.ts +26 -98
- package/src/chat/runtime/ChatPluginSystem.ts +9 -3
- package/src/chat/runtime/ChatQueueStore.ts +2 -2
- package/src/chat/runtime/ChatQueueWorker.ts +1 -1
- package/src/chat/runtime/ChatSessionDelete.ts +11 -21
- package/src/chat/runtime/ChatStorage.ts +203 -0
- package/src/chat/runtime/SystemPrompt.ts +8 -3
- package/src/chat/types/ChannelConfiguration.ts +2 -2
- package/src/chat/types/ChatPluginActionPayload.ts +8 -49
- package/src/chat/types/ChatPluginOptions.ts +0 -22
- package/src/chat/types/ChatStorage.ts +37 -0
- package/src/contact/Action.ts +9 -1
- package/src/contact/ContactPlugin.ts +38 -14
- package/src/contact/runtime/ChatRuntime.ts +1 -1
- package/src/contact/types/ContactPluginOptions.ts +6 -0
- package/src/index.ts +16 -14
- package/src/memory/Action.ts +19 -4
- package/src/memory/runtime/Store.ts +0 -27
- package/src/memory/runtime/Writer.ts +2 -5
- package/src/skill/Command.ts +3 -33
- package/src/skill/PROMPT.ts +1 -1
- package/src/skill/PROMPT.ts.txt +5 -1
- package/src/skill/Plugin.ts +49 -156
- package/src/skill/runtime/Prompt.ts +109 -9
- package/src/skill/runtime/SystemProvider.ts +5 -9
- package/src/skill/types/SkillPlugin.ts +6 -18
- package/src/sound/Plugin.ts +699 -0
- package/src/sound/types/SoundPlugin.ts +163 -0
- package/src/task/Action.ts +8 -0
- package/src/task/runtime/Runner.ts +19 -13
- package/src/task/runtime/TaskActionExecution.ts +3 -0
- package/src/task/runtime/TaskPluginActionRegistry.ts +1 -0
- package/src/task/runtime/TaskRunChatDispatch.ts +1 -1
- package/src/task/runtime/TaskRunnerRound.ts +20 -38
- package/src/task/runtime/TaskRunnerSession.ts +108 -72
- package/src/task/runtime/TaskRunnerTypes.ts +4 -4
- package/src/task/types/TaskPluginOptions.ts +1 -0
- package/src/web/PROMPT.ts +2 -2
- package/src/web/PROMPT.ts.txt +4 -2
- package/src/web/Plugin.ts +20 -90
- package/src/web/runtime/Prompt.ts +99 -0
- package/src/web/types/WebPlugin.ts +42 -29
- package/src/workboard/runtime/Collector.ts +1 -1
- package/src/workboard/runtime/Normalizer.ts +1 -1
- package/src/workboard/runtime/SessionSummary.ts +11 -42
- package/bin/asr/Plugin.d.ts +0 -63
- package/bin/asr/Plugin.d.ts.map +0 -1
- package/bin/asr/Plugin.js +0 -280
- package/bin/asr/Plugin.js.map +0 -1
- package/bin/asr/types/AsrPlugin.d.ts +0 -114
- package/bin/asr/types/AsrPlugin.d.ts.map +0 -1
- package/bin/asr/types/AsrPlugin.js +0 -10
- package/bin/asr/types/AsrPlugin.js.map +0 -1
- package/bin/chat/runtime/ChatSession.d.ts +0 -97
- package/bin/chat/runtime/ChatSession.d.ts.map +0 -1
- package/bin/chat/runtime/ChatSession.js +0 -91
- package/bin/chat/runtime/ChatSession.js.map +0 -1
- package/bin/chat/runtime/ChatSessionContextComposer.d.ts +0 -45
- package/bin/chat/runtime/ChatSessionContextComposer.d.ts.map +0 -1
- package/bin/chat/runtime/ChatSessionContextComposer.js +0 -60
- package/bin/chat/runtime/ChatSessionContextComposer.js.map +0 -1
- package/bin/chat/runtime/ChatSessionTypes.d.ts +0 -30
- package/bin/chat/runtime/ChatSessionTypes.d.ts.map +0 -1
- package/bin/chat/runtime/ChatSessionTypes.js +0 -9
- package/bin/chat/runtime/ChatSessionTypes.js.map +0 -1
- package/bin/tts/Plugin.d.ts +0 -49
- package/bin/tts/Plugin.d.ts.map +0 -1
- package/bin/tts/Plugin.js +0 -247
- package/bin/tts/Plugin.js.map +0 -1
- package/bin/tts/types/TtsPlugin.d.ts +0 -122
- package/bin/tts/types/TtsPlugin.d.ts.map +0 -1
- package/bin/tts/types/TtsPlugin.js +0 -10
- package/bin/tts/types/TtsPlugin.js.map +0 -1
- package/bin/web/runtime/Install.d.ts +0 -19
- package/bin/web/runtime/Install.d.ts.map +0 -1
- package/bin/web/runtime/Install.js +0 -178
- package/bin/web/runtime/Install.js.map +0 -1
- package/src/asr/Plugin.ts +0 -322
- package/src/asr/types/AsrPlugin.ts +0 -118
- package/src/chat/runtime/ChatSession.ts +0 -168
- package/src/chat/runtime/ChatSessionContextComposer.ts +0 -106
- package/src/chat/runtime/ChatSessionTypes.ts +0 -32
- package/src/tts/Plugin.ts +0 -284
- package/src/tts/types/TtsPlugin.ts +0 -129
- package/src/web/runtime/Install.ts +0 -241
|
@@ -2,39 +2,22 @@
|
|
|
2
2
|
* ChatChannelActions:chat 渠道 action 执行模块。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - status/test/reconnect
|
|
5
|
+
* - status/test/reconnect 的执行逻辑统一收敛在这里。
|
|
6
6
|
* - 该模块复用 lifecycle/config 模块,不直接持有长期运行态。
|
|
7
7
|
* - 对外只暴露 action 级入口,供 ChatPluginActions 装配使用。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
11
|
-
AgentContext,
|
|
12
|
-
DowncityChatChannelConfig,
|
|
13
|
-
DowncityConfig,
|
|
14
|
-
} from "@downcity/agent";
|
|
10
|
+
import type { AgentContext } from "@downcity/agent";
|
|
15
11
|
import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
|
|
16
|
-
import { getStoredChannelAccountSync } from "@/chat/accounts/Store.js";
|
|
17
12
|
import type {
|
|
18
|
-
ChatCloseActionPayload,
|
|
19
|
-
ChatConfigurationActionPayload,
|
|
20
|
-
ChatConfigureActionPayload,
|
|
21
|
-
ChatOpenActionPayload,
|
|
22
13
|
ChatReconnectActionPayload,
|
|
23
14
|
ChatStatusActionPayload,
|
|
24
15
|
ChatTestActionPayload,
|
|
25
16
|
} from "@/chat/types/ChatPluginActionPayload.js";
|
|
26
17
|
import type { ChatChannelTestResult } from "@/chat/types/ChannelStatus.js";
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
describeChatChannelConfiguration,
|
|
30
|
-
getChatChannelStatus,
|
|
31
|
-
listChatChannelConfigurationDescriptions,
|
|
32
|
-
normalizeChatChannelConfigPatch,
|
|
33
|
-
} from "./ChatChannelConfig.js";
|
|
18
|
+
import { getChatChannelStatus } from "./ChatChannelConfig.js";
|
|
34
19
|
import {
|
|
35
|
-
type ChatRuntimeBindings,
|
|
36
20
|
getChatChannelBot,
|
|
37
|
-
resolveChatPluginBindings,
|
|
38
21
|
resolveTargetChannels,
|
|
39
22
|
} from "./ChatChannelCore.js";
|
|
40
23
|
import {
|
|
@@ -42,66 +25,6 @@ import {
|
|
|
42
25
|
stopSingleChatChannel,
|
|
43
26
|
} from "./ChatChannelLifecycle.js";
|
|
44
27
|
|
|
45
|
-
type ChatRuntimeControlBindings = ChatRuntimeBindings & {
|
|
46
|
-
applyChannelRuntimePatch: NonNullable<ChatRuntimeBindings["applyChannelRuntimePatch"]>;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
function getChatRuntimeBindings(context: AgentContext): ChatRuntimeControlBindings {
|
|
50
|
-
const plugin = resolveChatPluginBindings(context);
|
|
51
|
-
if (!plugin?.applyChannelRuntimePatch) {
|
|
52
|
-
throw new Error("ChatPlugin runtime instance is not available");
|
|
53
|
-
}
|
|
54
|
-
return plugin as ChatRuntimeControlBindings;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 将 channel patch 合并进完整 plugins 配置并交给宿主持久化。
|
|
59
|
-
*
|
|
60
|
-
* 关键点(中文)
|
|
61
|
-
* - 始终写回完整 plugins 对象,避免覆盖其他 plugin 配置。
|
|
62
|
-
* - 宿主持久化成功后才更新当前 context 快照,保证运行态与存储态一致。
|
|
63
|
-
*/
|
|
64
|
-
async function persist_chat_channel_patches(params: {
|
|
65
|
-
context: AgentContext;
|
|
66
|
-
patches: Array<{
|
|
67
|
-
channel: ChatChannelName;
|
|
68
|
-
enabled?: boolean;
|
|
69
|
-
channel_account_id?: string | null;
|
|
70
|
-
}>;
|
|
71
|
-
}): Promise<DowncityConfig["plugins"]> {
|
|
72
|
-
const current_plugins = params.context.config.plugins || {};
|
|
73
|
-
const current_chat = current_plugins.chat || {};
|
|
74
|
-
const next_channels = { ...(current_chat.channels || {}) };
|
|
75
|
-
|
|
76
|
-
for (const patch of params.patches) {
|
|
77
|
-
const current_channel = next_channels[patch.channel] || {};
|
|
78
|
-
const next_channel: DowncityChatChannelConfig = { ...current_channel };
|
|
79
|
-
if (typeof patch.enabled === "boolean") {
|
|
80
|
-
next_channel.enabled = patch.enabled;
|
|
81
|
-
}
|
|
82
|
-
if (Object.prototype.hasOwnProperty.call(patch, "channel_account_id")) {
|
|
83
|
-
const channel_account_id = String(patch.channel_account_id || "").trim();
|
|
84
|
-
if (channel_account_id) {
|
|
85
|
-
next_channel.channelAccountId = channel_account_id;
|
|
86
|
-
} else {
|
|
87
|
-
delete next_channel.channelAccountId;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
next_channels[patch.channel] = next_channel;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const next_plugins: DowncityConfig["plugins"] = {
|
|
94
|
-
...current_plugins,
|
|
95
|
-
chat: {
|
|
96
|
-
...current_chat,
|
|
97
|
-
channels: next_channels,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
await params.context.pluginConfig.persistProjectPlugins(next_plugins);
|
|
101
|
-
params.context.config.plugins = next_plugins;
|
|
102
|
-
return next_plugins;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
28
|
/**
|
|
106
29
|
* 执行 `chat.status` action。
|
|
107
30
|
*/
|
|
@@ -218,177 +141,3 @@ export async function executeChatReconnectAction(params: {
|
|
|
218
141
|
},
|
|
219
142
|
};
|
|
220
143
|
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* 执行 `chat.open` action。
|
|
224
|
-
*/
|
|
225
|
-
export async function executeChatOpenAction(params: {
|
|
226
|
-
state: ChatChannelState;
|
|
227
|
-
context: AgentContext;
|
|
228
|
-
payload: ChatOpenActionPayload;
|
|
229
|
-
}) {
|
|
230
|
-
const targets = resolveTargetChannels(params.payload.channel);
|
|
231
|
-
const plugin = getChatRuntimeBindings(params.context);
|
|
232
|
-
await persist_chat_channel_patches({
|
|
233
|
-
context: params.context,
|
|
234
|
-
patches: targets.map((channel) => ({ channel, enabled: true })),
|
|
235
|
-
});
|
|
236
|
-
for (const channel of targets) {
|
|
237
|
-
plugin.applyChannelRuntimePatch({
|
|
238
|
-
channel,
|
|
239
|
-
enabled: true,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
for (const channel of targets) {
|
|
244
|
-
const snapshot = getChatChannelStatus(params.state, params.context, channel);
|
|
245
|
-
if (!snapshot.configured) continue;
|
|
246
|
-
if (snapshot.running) continue;
|
|
247
|
-
await startSingleChatChannel(params.state, params.context, channel);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const channels = targets.map((channel) =>
|
|
251
|
-
getChatChannelStatus(params.state, params.context, channel),
|
|
252
|
-
);
|
|
253
|
-
return {
|
|
254
|
-
success: true,
|
|
255
|
-
data: {
|
|
256
|
-
channels,
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 执行 `chat.close` action。
|
|
263
|
-
*/
|
|
264
|
-
export async function executeChatCloseAction(params: {
|
|
265
|
-
state: ChatChannelState;
|
|
266
|
-
context: AgentContext;
|
|
267
|
-
payload: ChatCloseActionPayload;
|
|
268
|
-
}) {
|
|
269
|
-
const targets = resolveTargetChannels(params.payload.channel);
|
|
270
|
-
const plugin = getChatRuntimeBindings(params.context);
|
|
271
|
-
await persist_chat_channel_patches({
|
|
272
|
-
context: params.context,
|
|
273
|
-
patches: targets.map((channel) => ({ channel, enabled: false })),
|
|
274
|
-
});
|
|
275
|
-
for (const channel of targets) {
|
|
276
|
-
await stopSingleChatChannel(params.state, channel);
|
|
277
|
-
plugin.applyChannelRuntimePatch({
|
|
278
|
-
channel,
|
|
279
|
-
enabled: false,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const channels = targets.map((channel) =>
|
|
284
|
-
getChatChannelStatus(params.state, params.context, channel),
|
|
285
|
-
);
|
|
286
|
-
return {
|
|
287
|
-
success: true,
|
|
288
|
-
data: {
|
|
289
|
-
channels,
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* 执行 `chat.configuration` action。
|
|
296
|
-
*/
|
|
297
|
-
export async function executeChatConfigurationAction(params: {
|
|
298
|
-
context: AgentContext;
|
|
299
|
-
payload: ChatConfigurationActionPayload;
|
|
300
|
-
}) {
|
|
301
|
-
void params.context;
|
|
302
|
-
const targets = resolveTargetChannels(params.payload.channel);
|
|
303
|
-
const items = targets.map((channel) => ({
|
|
304
|
-
channel,
|
|
305
|
-
configuration: describeChatChannelConfiguration(channel),
|
|
306
|
-
}));
|
|
307
|
-
return {
|
|
308
|
-
success: true,
|
|
309
|
-
data: {
|
|
310
|
-
channels: items,
|
|
311
|
-
allChannels: listChatChannelConfigurationDescriptions(),
|
|
312
|
-
},
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* 执行 `chat.configure` action。
|
|
318
|
-
*/
|
|
319
|
-
export async function executeChatConfigureAction(params: {
|
|
320
|
-
state: ChatChannelState;
|
|
321
|
-
context: AgentContext;
|
|
322
|
-
payload: ChatConfigureActionPayload;
|
|
323
|
-
}) {
|
|
324
|
-
const channel = params.payload.channel;
|
|
325
|
-
const patch = normalizeChatChannelConfigPatch({
|
|
326
|
-
channel,
|
|
327
|
-
config: params.payload.config || {},
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
if (Object.keys(patch).length === 0) {
|
|
331
|
-
return {
|
|
332
|
-
success: false,
|
|
333
|
-
error: "No valid config fields provided",
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (Object.prototype.hasOwnProperty.call(patch, "channelAccountId")) {
|
|
338
|
-
const channelAccountId = String(patch.channelAccountId || "").trim();
|
|
339
|
-
if (channelAccountId) {
|
|
340
|
-
const account = getStoredChannelAccountSync(channelAccountId);
|
|
341
|
-
if (!account) {
|
|
342
|
-
return {
|
|
343
|
-
success: false,
|
|
344
|
-
error: `Bot account not found: ${channelAccountId}`,
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
if (account.channel !== channel) {
|
|
348
|
-
return {
|
|
349
|
-
success: false,
|
|
350
|
-
error: `Bot account channel mismatch: expected ${channel}, got ${account.channel}`,
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const plugin = getChatRuntimeBindings(params.context);
|
|
357
|
-
await persist_chat_channel_patches({
|
|
358
|
-
context: params.context,
|
|
359
|
-
patches: [{
|
|
360
|
-
channel,
|
|
361
|
-
...(typeof patch.enabled === "boolean" ? { enabled: patch.enabled } : {}),
|
|
362
|
-
...(Object.prototype.hasOwnProperty.call(patch, "channelAccountId")
|
|
363
|
-
? { channel_account_id: String(patch.channelAccountId || "").trim() || null }
|
|
364
|
-
: {}),
|
|
365
|
-
}],
|
|
366
|
-
});
|
|
367
|
-
plugin.applyChannelRuntimePatch({
|
|
368
|
-
channel,
|
|
369
|
-
...(typeof patch.enabled === "boolean" ? { enabled: patch.enabled } : {}),
|
|
370
|
-
...(Object.prototype.hasOwnProperty.call(patch, "channelAccountId")
|
|
371
|
-
? { channelAccountId: String(patch.channelAccountId || "").trim() || null }
|
|
372
|
-
: {}),
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
// 关键点(中文):默认重载一次目标渠道,让新配置立刻生效。
|
|
376
|
-
const restart = params.payload.restart !== false;
|
|
377
|
-
if (restart) {
|
|
378
|
-
await stopSingleChatChannel(params.state, channel);
|
|
379
|
-
const snapshot = getChatChannelStatus(params.state, params.context, channel);
|
|
380
|
-
if (snapshot.enabled && snapshot.configured) {
|
|
381
|
-
await startSingleChatChannel(params.state, params.context, channel);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return {
|
|
386
|
-
success: true,
|
|
387
|
-
data: {
|
|
388
|
-
channel,
|
|
389
|
-
restartApplied: restart,
|
|
390
|
-
appliedKeys: Object.keys(patch),
|
|
391
|
-
channels: [getChatChannelStatus(params.state, params.context, channel)],
|
|
392
|
-
},
|
|
393
|
-
};
|
|
394
|
-
}
|
|
@@ -2,24 +2,19 @@
|
|
|
2
2
|
* ChatChannelConfig:chat 渠道配置与状态快照模块。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* - 该模块不直接负责 action 流程控制,只提供可复用的底层能力。
|
|
5
|
+
* - 渠道配置摘要与状态快照统一收敛在这里。
|
|
6
|
+
* - Plugin 只读取宿主构造时传入的 channel 配置,不负责修改或持久化。
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
import type { JsonObject
|
|
9
|
+
import type { JsonObject } from "@downcity/agent";
|
|
11
10
|
import type { AgentContext } from "@downcity/agent";
|
|
12
11
|
import type { StoredChannelAccount } from "@downcity/agent";
|
|
13
12
|
import type {
|
|
14
13
|
ChatChannelName,
|
|
15
14
|
ChatChannelStateSnapshot,
|
|
16
15
|
} from "@/chat/types/ChannelStatus.js";
|
|
17
|
-
import type { ChatChannelConfigurationField } from "@/chat/types/ChannelConfiguration.js";
|
|
18
16
|
import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
|
|
19
|
-
import {
|
|
20
|
-
getChatChannelConfiguration,
|
|
21
|
-
listChatChannelConfigurations,
|
|
22
|
-
} from "@/chat/channels/ConfigurationRegistry.js";
|
|
17
|
+
import { getChatChannelConfiguration } from "@/chat/channels/ConfigurationRegistry.js";
|
|
23
18
|
import {
|
|
24
19
|
getChatChannelBot,
|
|
25
20
|
isChatChannelEnabled,
|
|
@@ -106,127 +101,3 @@ export function getChatChannelStatus(
|
|
|
106
101
|
},
|
|
107
102
|
};
|
|
108
103
|
}
|
|
109
|
-
|
|
110
|
-
function isJsonObject(value: JsonValue): value is JsonObject {
|
|
111
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function readOptionalStringPatch(value: JsonValue): string | null | undefined {
|
|
115
|
-
if (value === null) return null;
|
|
116
|
-
if (typeof value === "string") {
|
|
117
|
-
const text = value.trim();
|
|
118
|
-
return text || null;
|
|
119
|
-
}
|
|
120
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
121
|
-
return String(value);
|
|
122
|
-
}
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function readOptionalBooleanPatch(value: JsonValue): boolean | undefined {
|
|
127
|
-
if (value === true) return true;
|
|
128
|
-
if (value === false) return false;
|
|
129
|
-
if (typeof value === "string") {
|
|
130
|
-
const text = value.trim().toLowerCase();
|
|
131
|
-
if (text === "true" || text === "1") return true;
|
|
132
|
-
if (text === "false" || text === "0") return false;
|
|
133
|
-
}
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function readOptionalNumberPatch(value: JsonValue): number | null | undefined {
|
|
138
|
-
if (value === null) return null;
|
|
139
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
140
|
-
if (typeof value === "string") {
|
|
141
|
-
const text = value.trim();
|
|
142
|
-
if (!text) return null;
|
|
143
|
-
const parsed = Number(text);
|
|
144
|
-
if (Number.isFinite(parsed)) return parsed;
|
|
145
|
-
}
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function normalizePatchFieldValue(params: {
|
|
150
|
-
field: ChatChannelConfigurationField;
|
|
151
|
-
value: JsonValue;
|
|
152
|
-
}): string | number | boolean | null | undefined {
|
|
153
|
-
const { field, value } = params;
|
|
154
|
-
|
|
155
|
-
if (field.type === "boolean") {
|
|
156
|
-
if (value === null) return field.nullable ? null : undefined;
|
|
157
|
-
return readOptionalBooleanPatch(value);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (field.type === "number") {
|
|
161
|
-
const normalized = readOptionalNumberPatch(value);
|
|
162
|
-
if (normalized === null) {
|
|
163
|
-
return field.nullable ? null : undefined;
|
|
164
|
-
}
|
|
165
|
-
return normalized;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const normalizedText = readOptionalStringPatch(value);
|
|
169
|
-
if (normalizedText === null) {
|
|
170
|
-
return field.nullable ? null : undefined;
|
|
171
|
-
}
|
|
172
|
-
if (normalizedText === undefined) {
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (field.type === "enum" && Array.isArray(field.options) && field.options.length > 0) {
|
|
177
|
-
const allowed = new Set(
|
|
178
|
-
field.options.map((item) => String(item.value || "").trim()).filter(Boolean),
|
|
179
|
-
);
|
|
180
|
-
if (!allowed.has(normalizedText)) {
|
|
181
|
-
throw new Error(
|
|
182
|
-
`Invalid value for ${field.key}: ${normalizedText}. Allowed: ${[...allowed].join(", ")}`,
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return normalizedText;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* 解析 chat.configure patch。
|
|
191
|
-
*/
|
|
192
|
-
export function normalizeChatChannelConfigPatch(params: {
|
|
193
|
-
channel: ChatChannelName;
|
|
194
|
-
config: Record<string, JsonValue>;
|
|
195
|
-
}): Record<string, string | number | boolean | null> {
|
|
196
|
-
const configDefinition = getChatChannelConfiguration(params.channel);
|
|
197
|
-
const writableFields = configDefinition.get_writable_agent_config_fields();
|
|
198
|
-
const patch: Record<string, string | number | boolean | null> = {};
|
|
199
|
-
|
|
200
|
-
for (const field of writableFields) {
|
|
201
|
-
if (!Object.prototype.hasOwnProperty.call(params.config, field.key)) continue;
|
|
202
|
-
const rawValue = params.config[field.key];
|
|
203
|
-
const normalizedValue = normalizePatchFieldValue({
|
|
204
|
-
field,
|
|
205
|
-
value: rawValue,
|
|
206
|
-
});
|
|
207
|
-
if (normalizedValue === undefined) continue;
|
|
208
|
-
patch[field.key] = normalizedValue;
|
|
209
|
-
}
|
|
210
|
-
return patch;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 读取渠道 configuration 描述。
|
|
215
|
-
*/
|
|
216
|
-
export function describeChatChannelConfiguration(channel: ChatChannelName): JsonObject {
|
|
217
|
-
return toJsonObject(getChatChannelConfiguration(channel).describe());
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 读取全部渠道 configuration 描述。
|
|
222
|
-
*/
|
|
223
|
-
export function listChatChannelConfigurationDescriptions(): JsonObject[] {
|
|
224
|
-
return listChatChannelConfigurations().map((item) => toJsonObject(item.describe()));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* 判断输入是否为 JSON object。
|
|
229
|
-
*/
|
|
230
|
-
export function isChatChannelConfigObject(value: JsonValue): value is JsonObject {
|
|
231
|
-
return isJsonObject(value);
|
|
232
|
-
}
|
|
@@ -22,26 +22,12 @@ export type ChatRuntimeBindings = {
|
|
|
22
22
|
channel: ChatChannelName,
|
|
23
23
|
): StoredChannelAccount | null;
|
|
24
24
|
isChannelEnabled?(context: AgentContext, channel: ChatChannelName): boolean;
|
|
25
|
-
applyChannelRuntimePatch?(params: {
|
|
26
|
-
/**
|
|
27
|
-
* 目标渠道。
|
|
28
|
-
*/
|
|
29
|
-
channel: ChatChannelName;
|
|
30
|
-
/**
|
|
31
|
-
* 是否启用该渠道。
|
|
32
|
-
*/
|
|
33
|
-
enabled?: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* 绑定的账号池记录 ID;传入 null 表示清空绑定。
|
|
36
|
-
*/
|
|
37
|
-
channelAccountId?: string | null;
|
|
38
|
-
}): void;
|
|
39
25
|
};
|
|
40
26
|
|
|
41
27
|
export function resolveChatPluginBindings(
|
|
42
28
|
context: AgentContext,
|
|
43
29
|
): ChatRuntimeBindings | null {
|
|
44
|
-
const candidate = context.
|
|
30
|
+
const candidate = context.plugins.get("chat") as
|
|
45
31
|
| ChatRuntimeBindings
|
|
46
32
|
| undefined;
|
|
47
33
|
return candidate || null;
|
|
@@ -11,6 +11,7 @@ import fs from "fs-extra";
|
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import { generateId } from "@downcity/agent";
|
|
13
13
|
import type { AgentContext } from "@downcity/agent";
|
|
14
|
+
import { get_chat_history_path } from "@/chat/runtime/ChatStorage.js";
|
|
14
15
|
import type { JsonObject } from "@downcity/agent";
|
|
15
16
|
import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
|
|
16
17
|
import type {
|
|
@@ -163,7 +164,7 @@ export async function appendInboundChatHistory(params: {
|
|
|
163
164
|
extra: toOptionalObject(params.extra),
|
|
164
165
|
});
|
|
165
166
|
|
|
166
|
-
const file = params.context.
|
|
167
|
+
const file = get_chat_history_path(params.context.rootPath, sessionId);
|
|
167
168
|
await fs.ensureDir(path.dirname(file));
|
|
168
169
|
await fs.appendFile(file, JSON.stringify(event) + "\n", "utf8");
|
|
169
170
|
}
|
|
@@ -206,7 +207,7 @@ export async function appendOutboundChatHistory(params: {
|
|
|
206
207
|
extra: toOptionalObject(params.extra),
|
|
207
208
|
});
|
|
208
209
|
|
|
209
|
-
const file = params.context.
|
|
210
|
+
const file = get_chat_history_path(params.context.rootPath, sessionId);
|
|
210
211
|
await fs.ensureDir(path.dirname(file));
|
|
211
212
|
await fs.appendFile(file, JSON.stringify(event) + "\n", "utf8");
|
|
212
213
|
}
|
|
@@ -228,7 +229,7 @@ export async function readChatHistory(params: {
|
|
|
228
229
|
}): Promise<{ historyPath: string; events: ChatHistoryEventV1[] }> {
|
|
229
230
|
const rootPath = normalizeTrimmedString(params.context.rootPath);
|
|
230
231
|
const sessionId = normalizeTrimmedString(params.sessionId);
|
|
231
|
-
const historyPath = params.context.
|
|
232
|
+
const historyPath = get_chat_history_path(params.context.rootPath, sessionId);
|
|
232
233
|
if (!rootPath || !sessionId) {
|
|
233
234
|
return {
|
|
234
235
|
historyPath,
|