@downcity/plugins 1.0.174 → 1.0.193
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
package/src/chat/Action.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - chat 语义(chatKey 与 sessionId 映射)统一收口在本模块
|
|
6
|
-
* -
|
|
6
|
+
* - Session 运行上下文由 action 入口显式传入
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { AgentContext } from "@downcity/agent";
|
|
10
|
-
import {
|
|
10
|
+
import type { PluginRunContext } from "@downcity/agent";
|
|
11
11
|
import {
|
|
12
12
|
sendActionByChatKey,
|
|
13
13
|
sendTextByChatKey,
|
|
@@ -51,15 +51,16 @@ function readEnvNumber(name: string): number | undefined {
|
|
|
51
51
|
*
|
|
52
52
|
* 优先级(中文)
|
|
53
53
|
* 1) 显式参数
|
|
54
|
-
* 2)
|
|
54
|
+
* 2) 显式 PluginRunContext
|
|
55
55
|
* 3) 环境变量回退
|
|
56
56
|
*/
|
|
57
57
|
export function resolveChatSessionSnapshot(input?: {
|
|
58
58
|
sessionId?: string;
|
|
59
59
|
chatKey?: string;
|
|
60
60
|
context?: AgentContext;
|
|
61
|
+
run_context?: PluginRunContext;
|
|
61
62
|
}): ChatSessionSnapshot {
|
|
62
|
-
const run_context =
|
|
63
|
+
const run_context = input?.run_context;
|
|
63
64
|
|
|
64
65
|
const explicitSessionId = String(input?.sessionId || "").trim();
|
|
65
66
|
const explicitChatKey = String(input?.chatKey || "").trim();
|
|
@@ -127,11 +128,13 @@ export function resolveSessionId(input?: {
|
|
|
127
128
|
sessionId?: string;
|
|
128
129
|
chatKey?: string;
|
|
129
130
|
context?: AgentContext;
|
|
131
|
+
run_context?: PluginRunContext;
|
|
130
132
|
}): string | undefined {
|
|
131
133
|
const snapshot = resolveChatSessionSnapshot({
|
|
132
134
|
sessionId: input?.sessionId,
|
|
133
135
|
chatKey: input?.chatKey,
|
|
134
136
|
context: input?.context,
|
|
137
|
+
run_context: input?.run_context,
|
|
135
138
|
});
|
|
136
139
|
const key = String(snapshot.sessionId || "").trim();
|
|
137
140
|
return key ? key : undefined;
|
|
@@ -144,11 +147,13 @@ export function resolveChatKey(input?: {
|
|
|
144
147
|
chatKey?: string;
|
|
145
148
|
sessionId?: string;
|
|
146
149
|
context?: AgentContext;
|
|
150
|
+
run_context?: PluginRunContext;
|
|
147
151
|
}): string | undefined {
|
|
148
152
|
const snapshot = resolveChatSessionSnapshot({
|
|
149
153
|
chatKey: input?.chatKey,
|
|
150
154
|
sessionId: input?.sessionId,
|
|
151
155
|
context: input?.context,
|
|
156
|
+
run_context: input?.run_context,
|
|
152
157
|
});
|
|
153
158
|
const key = String(snapshot.chatKey || "").trim();
|
|
154
159
|
return key ? key : undefined;
|
|
@@ -159,7 +164,7 @@ export function resolveChatKey(input?: {
|
|
|
159
164
|
*
|
|
160
165
|
* 关键点(中文)
|
|
161
166
|
* - 只有显式 reply 且未手动传入 messageId 时才尝试补全。
|
|
162
|
-
* - 仅在目标 chatKey
|
|
167
|
+
* - 仅在目标 chatKey 与当前显式请求上下文一致时,才复用 `DC_CTX_MESSAGE_ID`。
|
|
163
168
|
* - 这样可把一次 run 固定到触发它的那条消息,避免处理中被后续新消息覆盖。
|
|
164
169
|
*/
|
|
165
170
|
function resolveReplyMessageIdForChatSend(params: {
|
|
@@ -167,6 +172,7 @@ function resolveReplyMessageIdForChatSend(params: {
|
|
|
167
172
|
context: AgentContext;
|
|
168
173
|
replyToMessage: boolean;
|
|
169
174
|
explicitMessageId?: string;
|
|
175
|
+
run_context?: PluginRunContext;
|
|
170
176
|
}): string | undefined {
|
|
171
177
|
const explicitMessageId =
|
|
172
178
|
typeof params.explicitMessageId === "string" && params.explicitMessageId.trim()
|
|
@@ -177,6 +183,7 @@ function resolveReplyMessageIdForChatSend(params: {
|
|
|
177
183
|
|
|
178
184
|
const snapshot = resolveChatSessionSnapshot({
|
|
179
185
|
context: params.context,
|
|
186
|
+
run_context: params.run_context,
|
|
180
187
|
});
|
|
181
188
|
const snapshotChatKey = String(snapshot.chatKey || "").trim();
|
|
182
189
|
const snapshotMessageId = String(snapshot.messageId || "").trim();
|
|
@@ -274,6 +281,7 @@ export async function sendChatTextByChatKey(params: {
|
|
|
274
281
|
nonBlockingDelay?: boolean;
|
|
275
282
|
replyToMessage?: boolean;
|
|
276
283
|
messageId?: string;
|
|
284
|
+
run_context?: PluginRunContext;
|
|
277
285
|
}): Promise<ChatSendResponse> {
|
|
278
286
|
const chatKey = String(params.chatKey || "").trim();
|
|
279
287
|
const text = normalizeChatSendText(String(params.text ?? ""));
|
|
@@ -305,6 +313,7 @@ export async function sendChatTextByChatKey(params: {
|
|
|
305
313
|
chatKey,
|
|
306
314
|
replyToMessage,
|
|
307
315
|
explicitMessageId: params.messageId,
|
|
316
|
+
run_context: params.run_context,
|
|
308
317
|
});
|
|
309
318
|
const targetWaitMs = resolveTargetWaitMs({ delayMs, sendAtMs });
|
|
310
319
|
if (params.nonBlockingDelay === true && targetWaitMs > 0) {
|
|
@@ -446,11 +455,13 @@ export async function deleteChatByChatKey(params: {
|
|
|
446
455
|
context: AgentContext;
|
|
447
456
|
chatKey?: string;
|
|
448
457
|
sessionId?: string;
|
|
458
|
+
run_context?: PluginRunContext;
|
|
449
459
|
}): Promise<ChatDeleteResponse> {
|
|
450
460
|
const chatKey = resolveChatKey({
|
|
451
461
|
context: params.context,
|
|
452
462
|
chatKey: params.chatKey,
|
|
453
463
|
sessionId: params.sessionId,
|
|
464
|
+
run_context: params.run_context,
|
|
454
465
|
});
|
|
455
466
|
const sessionId = String(chatKey || "").trim();
|
|
456
467
|
if (!sessionId) {
|
package/src/chat/ChatPlugin.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { BasePlugin } from "@downcity/agent";
|
|
12
12
|
import type { PluginActions } from "@downcity/agent";
|
|
13
13
|
import type { AgentContext } from "@downcity/agent";
|
|
14
|
+
import type { PluginRunContext } from "@downcity/agent";
|
|
14
15
|
import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
|
|
15
16
|
import type { ChatQueueWorkerConfig } from "@/chat/types/ChatQueueWorker.js";
|
|
16
17
|
import type {
|
|
@@ -87,8 +88,11 @@ export class ChatPlugin extends BasePlugin {
|
|
|
87
88
|
/**
|
|
88
89
|
* 当前 plugin 的 system 文本构建器。
|
|
89
90
|
*/
|
|
90
|
-
readonly system = async (
|
|
91
|
-
|
|
91
|
+
readonly system = async (
|
|
92
|
+
context: AgentContext,
|
|
93
|
+
run_context?: PluginRunContext,
|
|
94
|
+
): Promise<string> => {
|
|
95
|
+
return await buildChatPluginSystem(context, run_context);
|
|
92
96
|
};
|
|
93
97
|
|
|
94
98
|
/**
|
|
@@ -172,39 +176,6 @@ export class ChatPlugin extends BasePlugin {
|
|
|
172
176
|
return String(this.getChannel(channel)?.getChannelAccountId(context) || "").trim();
|
|
173
177
|
}
|
|
174
178
|
|
|
175
|
-
/**
|
|
176
|
-
* 更新当前实例的渠道运行态配置。
|
|
177
|
-
*
|
|
178
|
-
* 关键点(中文)
|
|
179
|
-
* - chat.open/close/configure 由 action 先调用宿主持久化能力,再修改当前实例。
|
|
180
|
-
* - 当前运行态只允许更新 `enabled` 与 `channelAccountId`,密钥仍来自 constructor 或账号池。
|
|
181
|
-
*/
|
|
182
|
-
applyChannelRuntimePatch(params: {
|
|
183
|
-
/**
|
|
184
|
-
* 目标渠道。
|
|
185
|
-
*/
|
|
186
|
-
channel: ChatChannelName;
|
|
187
|
-
/**
|
|
188
|
-
* 是否启用该渠道。
|
|
189
|
-
*/
|
|
190
|
-
enabled?: boolean;
|
|
191
|
-
/**
|
|
192
|
-
* 绑定的账号池记录 ID;传入 null 表示清空绑定。
|
|
193
|
-
*/
|
|
194
|
-
channelAccountId?: string | null;
|
|
195
|
-
}): void {
|
|
196
|
-
const channel = this.getChannel(params.channel);
|
|
197
|
-
if (!channel) {
|
|
198
|
-
throw new Error(`Chat channel is not registered: ${params.channel}`);
|
|
199
|
-
}
|
|
200
|
-
channel.applyRuntimePatch({
|
|
201
|
-
...(typeof params.enabled === "boolean" ? { enabled: params.enabled } : {}),
|
|
202
|
-
...(Object.prototype.hasOwnProperty.call(params, "channelAccountId")
|
|
203
|
-
? { channelAccountId: params.channelAccountId ?? null }
|
|
204
|
-
: {}),
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
179
|
/**
|
|
209
180
|
* 解析指定渠道当前应使用的账户。
|
|
210
181
|
*/
|
package/src/chat/Index.ts
CHANGED
|
@@ -245,7 +245,7 @@ export abstract class BaseChatChannel {
|
|
|
245
245
|
protected buildAccessBlockedText(params: {
|
|
246
246
|
result: IncomingChatAccessResult;
|
|
247
247
|
}): string {
|
|
248
|
-
const agent_id = String(this.context.
|
|
248
|
+
const agent_id = String(this.context.agent_id || "agent").trim() || "agent";
|
|
249
249
|
const displayed_agent_id = this.format_access_code(agent_id);
|
|
250
250
|
if (params.result.reason === "identity_missing") {
|
|
251
251
|
return "当前平台身份无法识别,请联系管理员检查 Chat 账号配置。";
|
|
@@ -27,7 +27,7 @@ export abstract class ChatChannelConfiguration {
|
|
|
27
27
|
abstract describe(): ChatChannelConfigurationDescriptor;
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* 返回允许上游产品编辑的 Agent 配置字段定义。
|
|
31
31
|
*/
|
|
32
32
|
get_writable_agent_config_fields(): ChatChannelConfigurationField[] {
|
|
33
33
|
return this.describe().fields.agent_config.filter((field) => field.writable);
|
|
@@ -10,10 +10,7 @@
|
|
|
10
10
|
import type { AgentContext } from "@downcity/agent";
|
|
11
11
|
import type { StoredChannelAccount } from "@downcity/agent";
|
|
12
12
|
import type { ChatChannelName } from "@/chat/types/ChannelStatus.js";
|
|
13
|
-
import type {
|
|
14
|
-
ChatChannel,
|
|
15
|
-
ChatChannelRuntimePatch,
|
|
16
|
-
} from "@/chat/types/ChatPluginOptions.js";
|
|
13
|
+
import type { ChatChannel } from "@/chat/types/ChatPluginOptions.js";
|
|
17
14
|
import { getStoredChannelAccountSync } from "@/chat/accounts/Store.js";
|
|
18
15
|
|
|
19
16
|
/**
|
|
@@ -30,7 +27,7 @@ export interface BaseChatChannelOptions {
|
|
|
30
27
|
*
|
|
31
28
|
* 说明(中文)
|
|
32
29
|
* - 默认值为 `true`,因为传入 channel 对象通常表示希望启用它。
|
|
33
|
-
* -
|
|
30
|
+
* - 该值由宿主构造 channel 时传入,运行期间保持不变。
|
|
34
31
|
*/
|
|
35
32
|
enabled?: boolean;
|
|
36
33
|
/**
|
|
@@ -81,15 +78,6 @@ abstract class BaseRuntimeChatChannel implements ChatChannel {
|
|
|
81
78
|
return this.channelAccountId;
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
applyRuntimePatch(patch: ChatChannelRuntimePatch): void {
|
|
85
|
-
if (typeof patch.enabled === "boolean") {
|
|
86
|
-
this.enabled = patch.enabled;
|
|
87
|
-
}
|
|
88
|
-
if (Object.prototype.hasOwnProperty.call(patch, "channelAccountId")) {
|
|
89
|
-
this.channelAccountId = String(patch.channelAccountId || "").trim();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
81
|
protected getStoredAccount(): StoredChannelAccount | null {
|
|
94
82
|
if (!this.channelAccountId) return null;
|
|
95
83
|
const account = getStoredChannelAccountSync(this.channelAccountId);
|
|
@@ -27,6 +27,7 @@ import { parseFeishuAttachments } from "./Shared.js";
|
|
|
27
27
|
import { FeishuPlatformClient } from "./FeishuPlatformClient.js";
|
|
28
28
|
import { handleFeishuMessage } from "./FeishuMessageHandler.js";
|
|
29
29
|
import { isMissingFeishuSdkDependencyError } from "./FeishuSdk.js";
|
|
30
|
+
import { get_feishu_dedupe_dir_path } from "@/chat/runtime/ChatStorage.js";
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* 飞书入站确认 reaction 类型。
|
|
@@ -63,7 +64,7 @@ export class FeishuBot extends BaseChatChannel {
|
|
|
63
64
|
this.appId = appId;
|
|
64
65
|
this.appSecret = appSecret;
|
|
65
66
|
this.domain = domain;
|
|
66
|
-
this.dedupeDir =
|
|
67
|
+
this.dedupeDir = get_feishu_dedupe_dir_path(context.rootPath);
|
|
67
68
|
this.platform = new FeishuPlatformClient({
|
|
68
69
|
context,
|
|
69
70
|
config: {
|
|
@@ -15,6 +15,10 @@ import type {
|
|
|
15
15
|
ChannelContextRouteV1,
|
|
16
16
|
ChannelContextTarget,
|
|
17
17
|
} from "@/chat/types/ChannelContext.js";
|
|
18
|
+
import {
|
|
19
|
+
get_chat_channel_dir_path,
|
|
20
|
+
get_chat_channel_meta_path,
|
|
21
|
+
} from "@/chat/runtime/ChatStorage.js";
|
|
18
22
|
|
|
19
23
|
function toOptionalTrimmedString(input: unknown): string | undefined {
|
|
20
24
|
const value = String(input || "").trim();
|
|
@@ -169,7 +173,7 @@ export async function readChannelSessionRouteBySessionId(params: {
|
|
|
169
173
|
const sessionId = toOptionalTrimmedString(params.sessionId);
|
|
170
174
|
if (!rootPath || !sessionId) return null;
|
|
171
175
|
const file = await readMetaFile({
|
|
172
|
-
filePath: params.context.
|
|
176
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
173
177
|
});
|
|
174
178
|
return normalizeRoute(file.routesBySessionId[sessionId]);
|
|
175
179
|
}
|
|
@@ -195,7 +199,7 @@ export async function listChannelSessionRoutes(params: {
|
|
|
195
199
|
};
|
|
196
200
|
}
|
|
197
201
|
const file = await readMetaFile({
|
|
198
|
-
filePath: params.context.
|
|
202
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
199
203
|
});
|
|
200
204
|
const routes = Object.values(file.routesBySessionId)
|
|
201
205
|
.map((route) => normalizeRoute(route))
|
|
@@ -219,7 +223,7 @@ export async function resolveChannelSessionIdByTarget(params: {
|
|
|
219
223
|
const targetKey = buildChannelTargetKey(params.target);
|
|
220
224
|
if (!targetKey) return null;
|
|
221
225
|
const file = await readMetaFile({
|
|
222
|
-
filePath: params.context.
|
|
226
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
223
227
|
});
|
|
224
228
|
const sessionId = toOptionalTrimmedString(file.sessionIdByTargetKey[targetKey]);
|
|
225
229
|
if (!sessionId) return null;
|
|
@@ -241,7 +245,7 @@ export async function resolveOrCreateChannelSessionIdByTarget(params: {
|
|
|
241
245
|
if (!targetKey) return null;
|
|
242
246
|
|
|
243
247
|
const file = await readMetaFile({
|
|
244
|
-
filePath: params.context.
|
|
248
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
245
249
|
});
|
|
246
250
|
const existingSessionId = toOptionalTrimmedString(file.sessionIdByTargetKey[targetKey]);
|
|
247
251
|
if (
|
|
@@ -267,8 +271,8 @@ export async function resolveOrCreateChannelSessionIdByTarget(params: {
|
|
|
267
271
|
};
|
|
268
272
|
file.updatedAt = Date.now();
|
|
269
273
|
await writeMetaFile({
|
|
270
|
-
dirPath: params.context.
|
|
271
|
-
filePath: params.context.
|
|
274
|
+
dirPath: get_chat_channel_dir_path(params.context.rootPath),
|
|
275
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
272
276
|
file,
|
|
273
277
|
});
|
|
274
278
|
return nextSessionId;
|
|
@@ -294,7 +298,7 @@ export async function upsertChannelSessionRouteBySessionId(params: {
|
|
|
294
298
|
if (!targetKey) return;
|
|
295
299
|
|
|
296
300
|
const file = await readMetaFile({
|
|
297
|
-
filePath: params.context.
|
|
301
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
298
302
|
});
|
|
299
303
|
const prev = normalizeRoute(file.routesBySessionId[sessionId]);
|
|
300
304
|
const nextRoute: ChannelContextRouteV1 = {
|
|
@@ -333,8 +337,8 @@ export async function upsertChannelSessionRouteBySessionId(params: {
|
|
|
333
337
|
file.sessionIdByTargetKey[targetKey] = sessionId;
|
|
334
338
|
file.updatedAt = Date.now();
|
|
335
339
|
await writeMetaFile({
|
|
336
|
-
dirPath: params.context.
|
|
337
|
-
filePath: params.context.
|
|
340
|
+
dirPath: get_chat_channel_dir_path(params.context.rootPath),
|
|
341
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
338
342
|
file,
|
|
339
343
|
});
|
|
340
344
|
}
|
|
@@ -363,7 +367,7 @@ export async function removeChannelSessionRouteBySessionId(params: {
|
|
|
363
367
|
}
|
|
364
368
|
|
|
365
369
|
const file = await readMetaFile({
|
|
366
|
-
filePath: params.context.
|
|
370
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
367
371
|
});
|
|
368
372
|
const route = normalizeRoute(file.routesBySessionId[sessionId]);
|
|
369
373
|
if (!route) {
|
|
@@ -384,8 +388,8 @@ export async function removeChannelSessionRouteBySessionId(params: {
|
|
|
384
388
|
|
|
385
389
|
file.updatedAt = Date.now();
|
|
386
390
|
await writeMetaFile({
|
|
387
|
-
dirPath: params.context.
|
|
388
|
-
filePath: params.context.
|
|
391
|
+
dirPath: get_chat_channel_dir_path(params.context.rootPath),
|
|
392
|
+
filePath: get_chat_channel_meta_path(params.context.rootPath),
|
|
389
393
|
file,
|
|
390
394
|
});
|
|
391
395
|
return {
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import type { JsonObject } from "@downcity/agent";
|
|
12
12
|
import type { AgentContext } from "@downcity/agent";
|
|
13
|
+
import type { PluginRunContext } from "@downcity/agent";
|
|
13
14
|
import type {
|
|
14
15
|
ChatDeleteActionPayload,
|
|
15
16
|
ChatHistoryActionPayload,
|
|
17
|
+
ChatHistoryClearActionPayload,
|
|
16
18
|
ChatInfoActionPayload,
|
|
17
19
|
ChatListActionPayload,
|
|
18
20
|
ChatReactActionPayload,
|
|
@@ -32,6 +34,36 @@ import { listChannelSessionRoutes } from "@/chat/runtime/ChannelContextStore.js"
|
|
|
32
34
|
import { readChatHistory } from "@/chat/runtime/ChatHistoryStore.js";
|
|
33
35
|
import { readChatMetaBySessionId } from "@/chat/runtime/ChatMetaStore.js";
|
|
34
36
|
import { resolveChatChannelNameOrThrow } from "@/chat/runtime/ChatChannelFacade.js";
|
|
37
|
+
import {
|
|
38
|
+
clear_chat_history,
|
|
39
|
+
get_chat_channel_meta_path,
|
|
40
|
+
get_chat_history_path,
|
|
41
|
+
get_chat_session_dir_path,
|
|
42
|
+
} from "@/chat/runtime/ChatStorage.js";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 执行 `chat.history_clear` action。
|
|
46
|
+
*/
|
|
47
|
+
export async function execute_chat_history_clear_action(params: {
|
|
48
|
+
context: AgentContext;
|
|
49
|
+
payload: ChatHistoryClearActionPayload;
|
|
50
|
+
}) {
|
|
51
|
+
const session_id = String(params.payload.sessionId || "").trim();
|
|
52
|
+
if (!session_id) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
error: "Missing sessionId",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const cleared = await clear_chat_history(params.context.rootPath, session_id);
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
data: {
|
|
62
|
+
sessionId: session_id,
|
|
63
|
+
cleared,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
35
67
|
|
|
36
68
|
function toChatHistoryView(events: ChatHistoryEventV1[]): JsonObject[] {
|
|
37
69
|
return events.map((event) => ({
|
|
@@ -46,9 +78,11 @@ function toChatHistoryView(events: ChatHistoryEventV1[]): JsonObject[] {
|
|
|
46
78
|
export async function executeChatContextAction(params: {
|
|
47
79
|
context: AgentContext;
|
|
48
80
|
payload: ChatSessionActionPayload;
|
|
81
|
+
run_context?: PluginRunContext;
|
|
49
82
|
}) {
|
|
50
83
|
const snapshot = resolveChatSessionSnapshot({
|
|
51
84
|
context: params.context,
|
|
85
|
+
run_context: params.run_context,
|
|
52
86
|
...(params.payload.chatKey ? { chatKey: params.payload.chatKey } : {}),
|
|
53
87
|
...(params.payload.sessionId ? { sessionId: params.payload.sessionId } : {}),
|
|
54
88
|
});
|
|
@@ -132,11 +166,13 @@ export async function executeChatListAction(params: {
|
|
|
132
166
|
export async function executeChatInfoAction(params: {
|
|
133
167
|
context: AgentContext;
|
|
134
168
|
payload: ChatInfoActionPayload;
|
|
169
|
+
run_context?: PluginRunContext;
|
|
135
170
|
}) {
|
|
136
171
|
const explicitSessionId = String(params.payload.sessionId || "").trim();
|
|
137
172
|
const explicitChatKey = String(params.payload.chatKey || "").trim();
|
|
138
173
|
const snapshot = resolveChatSessionSnapshot({
|
|
139
174
|
context: params.context,
|
|
175
|
+
run_context: params.run_context,
|
|
140
176
|
...(explicitSessionId ? { sessionId: explicitSessionId } : {}),
|
|
141
177
|
...(explicitChatKey ? { chatKey: explicitChatKey } : {}),
|
|
142
178
|
});
|
|
@@ -160,13 +196,13 @@ export async function executeChatInfoAction(params: {
|
|
|
160
196
|
path.relative(params.context.rootPath, absPath).split(path.sep).join("/");
|
|
161
197
|
|
|
162
198
|
const channelMetaPath = toPosixRelativePath(
|
|
163
|
-
params.context.
|
|
199
|
+
get_chat_channel_meta_path(params.context.rootPath),
|
|
164
200
|
);
|
|
165
201
|
const chatDirPath = toPosixRelativePath(
|
|
166
|
-
|
|
202
|
+
get_chat_session_dir_path(params.context.rootPath, sessionId),
|
|
167
203
|
);
|
|
168
204
|
const historyPath = toPosixRelativePath(
|
|
169
|
-
params.context.
|
|
205
|
+
get_chat_history_path(params.context.rootPath, sessionId),
|
|
170
206
|
);
|
|
171
207
|
|
|
172
208
|
return {
|
|
@@ -192,10 +228,12 @@ export async function executeChatInfoAction(params: {
|
|
|
192
228
|
export async function executeChatHistoryAction(params: {
|
|
193
229
|
context: AgentContext;
|
|
194
230
|
payload: ChatHistoryActionPayload;
|
|
231
|
+
run_context?: PluginRunContext;
|
|
195
232
|
}) {
|
|
196
233
|
const payload = params.payload;
|
|
197
234
|
const snapshot = resolveChatSessionSnapshot({
|
|
198
235
|
context: params.context,
|
|
236
|
+
run_context: params.run_context,
|
|
199
237
|
...(payload.chatKey ? { chatKey: payload.chatKey } : {}),
|
|
200
238
|
...(payload.sessionId ? { sessionId: payload.sessionId } : {}),
|
|
201
239
|
});
|
|
@@ -242,10 +280,12 @@ export async function executeChatHistoryAction(params: {
|
|
|
242
280
|
export async function executeChatSendAction(params: {
|
|
243
281
|
context: AgentContext;
|
|
244
282
|
payload: ChatSendActionPayload;
|
|
283
|
+
run_context?: PluginRunContext;
|
|
245
284
|
}) {
|
|
246
285
|
const chatKey = resolveChatKey({
|
|
247
286
|
chatKey: params.payload.chatKey,
|
|
248
287
|
context: params.context,
|
|
288
|
+
run_context: params.run_context,
|
|
249
289
|
});
|
|
250
290
|
if (!chatKey) {
|
|
251
291
|
return {
|
|
@@ -270,6 +310,7 @@ export async function executeChatSendAction(params: {
|
|
|
270
310
|
...(typeof params.payload.messageId === "string" && params.payload.messageId.trim()
|
|
271
311
|
? { messageId: params.payload.messageId.trim() }
|
|
272
312
|
: {}),
|
|
313
|
+
run_context: params.run_context,
|
|
273
314
|
});
|
|
274
315
|
if (!result.success) {
|
|
275
316
|
return {
|
|
@@ -291,10 +332,12 @@ export async function executeChatSendAction(params: {
|
|
|
291
332
|
export async function executeChatReactAction(params: {
|
|
292
333
|
context: AgentContext;
|
|
293
334
|
payload: ChatReactActionPayload;
|
|
335
|
+
run_context?: PluginRunContext;
|
|
294
336
|
}) {
|
|
295
337
|
const chatKey = resolveChatKey({
|
|
296
338
|
chatKey: params.payload.chatKey,
|
|
297
339
|
context: params.context,
|
|
340
|
+
run_context: params.run_context,
|
|
298
341
|
});
|
|
299
342
|
if (!chatKey) {
|
|
300
343
|
return {
|
|
@@ -337,9 +380,11 @@ export async function executeChatReactAction(params: {
|
|
|
337
380
|
export async function executeChatDeleteAction(params: {
|
|
338
381
|
context: AgentContext;
|
|
339
382
|
payload: ChatDeleteActionPayload;
|
|
383
|
+
run_context?: PluginRunContext;
|
|
340
384
|
}) {
|
|
341
385
|
const result = await deleteChatByChatKey({
|
|
342
386
|
context: params.context,
|
|
387
|
+
run_context: params.run_context,
|
|
343
388
|
...(params.payload.chatKey ? { chatKey: params.payload.chatKey } : {}),
|
|
344
389
|
...(params.payload.sessionId ? { sessionId: params.payload.sessionId } : {}),
|
|
345
390
|
});
|
|
@@ -7,10 +7,8 @@
|
|
|
7
7
|
* - `chat send` 的 frontmatter / <file> 协议也在这里完成标准化解析。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { JsonObject, JsonValue } from "@downcity/agent";
|
|
11
10
|
import type { PluginActionCommandInput } from "@downcity/agent";
|
|
12
11
|
import type {
|
|
13
|
-
ChatConfigureActionPayload,
|
|
14
12
|
ChatDeleteActionPayload,
|
|
15
13
|
ChatHistoryActionPayload,
|
|
16
14
|
ChatInfoActionPayload,
|
|
@@ -22,7 +20,6 @@ import { resolveChatChannelNameOrThrow } from "@/chat/runtime/ChatChannelFacade.
|
|
|
22
20
|
import {
|
|
23
21
|
getBooleanOpt,
|
|
24
22
|
getStringOpt,
|
|
25
|
-
isJsonObject,
|
|
26
23
|
parseOptionalTimestampOrThrow,
|
|
27
24
|
parsePositiveIntOptionOrThrow,
|
|
28
25
|
readHistoryDirectionOrThrow,
|
|
@@ -67,34 +64,6 @@ export function mapChatInfoCommandInput(
|
|
|
67
64
|
};
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
export function mapChatConfigureCommandInput(
|
|
71
|
-
input: PluginActionCommandInput,
|
|
72
|
-
): ChatConfigureActionPayload {
|
|
73
|
-
const channelRaw = getStringOpt(input.opts, "channel");
|
|
74
|
-
if (!channelRaw) {
|
|
75
|
-
throw new Error("Missing --channel. Use telegram|feishu|qq.");
|
|
76
|
-
}
|
|
77
|
-
const channel = resolveChatChannelNameOrThrow(channelRaw);
|
|
78
|
-
const rawConfigJson = getStringOpt(input.opts, "configJson");
|
|
79
|
-
if (!rawConfigJson) {
|
|
80
|
-
throw new Error("Missing --config-json.");
|
|
81
|
-
}
|
|
82
|
-
let parsed: JsonValue = {};
|
|
83
|
-
try {
|
|
84
|
-
parsed = JSON.parse(rawConfigJson) as JsonValue;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
throw new Error(`Invalid --config-json: ${String(error)}`);
|
|
87
|
-
}
|
|
88
|
-
if (!isJsonObject(parsed)) {
|
|
89
|
-
throw new Error("--config-json must be a JSON object");
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
channel,
|
|
93
|
-
config: parsed as Record<string, JsonValue>,
|
|
94
|
-
restart: getBooleanOpt(input.opts, "restart"),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
67
|
export function mapChatHistoryCommandInput(
|
|
99
68
|
input: PluginActionCommandInput,
|
|
100
69
|
): ChatHistoryActionPayload {
|