@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.
Files changed (301) hide show
  1. package/bin/BuiltinPlugins.d.ts +4 -9
  2. package/bin/BuiltinPlugins.d.ts.map +1 -1
  3. package/bin/BuiltinPlugins.js +4 -8
  4. package/bin/BuiltinPlugins.js.map +1 -1
  5. package/bin/chat/Action.d.ts +8 -2
  6. package/bin/chat/Action.d.ts.map +1 -1
  7. package/bin/chat/Action.js +9 -5
  8. package/bin/chat/Action.js.map +1 -1
  9. package/bin/chat/ChatPlugin.d.ts +2 -22
  10. package/bin/chat/ChatPlugin.d.ts.map +1 -1
  11. package/bin/chat/ChatPlugin.js +2 -21
  12. package/bin/chat/ChatPlugin.js.map +1 -1
  13. package/bin/chat/Index.d.ts +1 -1
  14. package/bin/chat/Index.d.ts.map +1 -1
  15. package/bin/chat/channels/BaseChatChannel.js +1 -1
  16. package/bin/chat/channels/BaseChatChannel.js.map +1 -1
  17. package/bin/chat/channels/Configuration.d.ts +1 -1
  18. package/bin/chat/channels/Configuration.js +1 -1
  19. package/bin/chat/channels/RuntimeChannel.d.ts +2 -3
  20. package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -1
  21. package/bin/chat/channels/RuntimeChannel.js +0 -8
  22. package/bin/chat/channels/RuntimeChannel.js.map +1 -1
  23. package/bin/chat/channels/feishu/Feishu.d.ts.map +1 -1
  24. package/bin/chat/channels/feishu/Feishu.js +2 -1
  25. package/bin/chat/channels/feishu/Feishu.js.map +1 -1
  26. package/bin/chat/runtime/ChannelContextStore.d.ts.map +1 -1
  27. package/bin/chat/runtime/ChannelContextStore.js +13 -12
  28. package/bin/chat/runtime/ChannelContextStore.js.map +1 -1
  29. package/bin/chat/runtime/ChatActionExecution.d.ts +26 -1
  30. package/bin/chat/runtime/ChatActionExecution.d.ts.map +1 -1
  31. package/bin/chat/runtime/ChatActionExecution.js +31 -3
  32. package/bin/chat/runtime/ChatActionExecution.js.map +1 -1
  33. package/bin/chat/runtime/ChatActionInput.d.ts +1 -2
  34. package/bin/chat/runtime/ChatActionInput.d.ts.map +1 -1
  35. package/bin/chat/runtime/ChatActionInput.js +1 -27
  36. package/bin/chat/runtime/ChatActionInput.js.map +1 -1
  37. package/bin/chat/runtime/ChatChannelActions.d.ts +2 -66
  38. package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
  39. package/bin/chat/runtime/ChatChannelActions.js +3 -195
  40. package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
  41. package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -23
  42. package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
  43. package/bin/chat/runtime/ChatChannelConfig.js +3 -116
  44. package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
  45. package/bin/chat/runtime/ChatChannelCore.d.ts +0 -14
  46. package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
  47. package/bin/chat/runtime/ChatChannelCore.js +1 -1
  48. package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
  49. package/bin/chat/runtime/ChatChannelFacade.d.ts +1 -1
  50. package/bin/chat/runtime/ChatChannelFacade.d.ts.map +1 -1
  51. package/bin/chat/runtime/ChatChannelFacade.js +1 -1
  52. package/bin/chat/runtime/ChatChannelFacade.js.map +1 -1
  53. package/bin/chat/runtime/ChatHistoryStore.d.ts.map +1 -1
  54. package/bin/chat/runtime/ChatHistoryStore.js +4 -3
  55. package/bin/chat/runtime/ChatHistoryStore.js.map +1 -1
  56. package/bin/chat/runtime/ChatPluginActionRegistry.d.ts.map +1 -1
  57. package/bin/chat/runtime/ChatPluginActionRegistry.js +27 -89
  58. package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
  59. package/bin/chat/runtime/ChatPluginSystem.d.ts +3 -2
  60. package/bin/chat/runtime/ChatPluginSystem.d.ts.map +1 -1
  61. package/bin/chat/runtime/ChatPluginSystem.js +5 -5
  62. package/bin/chat/runtime/ChatPluginSystem.js.map +1 -1
  63. package/bin/chat/runtime/ChatQueueStore.d.ts +1 -1
  64. package/bin/chat/runtime/ChatQueueStore.js +2 -2
  65. package/bin/chat/runtime/ChatQueueStore.js.map +1 -1
  66. package/bin/chat/runtime/ChatQueueWorker.js +1 -1
  67. package/bin/chat/runtime/ChatQueueWorker.js.map +1 -1
  68. package/bin/chat/runtime/ChatSessionDelete.d.ts.map +1 -1
  69. package/bin/chat/runtime/ChatSessionDelete.js +11 -20
  70. package/bin/chat/runtime/ChatSessionDelete.js.map +1 -1
  71. package/bin/chat/runtime/ChatStorage.d.ts +32 -0
  72. package/bin/chat/runtime/ChatStorage.d.ts.map +1 -0
  73. package/bin/chat/runtime/ChatStorage.js +158 -0
  74. package/bin/chat/runtime/ChatStorage.js.map +1 -0
  75. package/bin/chat/runtime/SystemPrompt.d.ts +3 -2
  76. package/bin/chat/runtime/SystemPrompt.d.ts.map +1 -1
  77. package/bin/chat/runtime/SystemPrompt.js +4 -5
  78. package/bin/chat/runtime/SystemPrompt.js.map +1 -1
  79. package/bin/chat/types/ChannelConfiguration.d.ts +2 -2
  80. package/bin/chat/types/ChatPluginActionPayload.d.ts +7 -45
  81. package/bin/chat/types/ChatPluginActionPayload.d.ts.map +1 -1
  82. package/bin/chat/types/ChatPluginOptions.d.ts +0 -21
  83. package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -1
  84. package/bin/chat/types/ChatStorage.d.ts +36 -0
  85. package/bin/chat/types/ChatStorage.d.ts.map +1 -0
  86. package/bin/chat/types/ChatStorage.js +9 -0
  87. package/bin/chat/types/ChatStorage.js.map +1 -0
  88. package/bin/contact/Action.d.ts +3 -2
  89. package/bin/contact/Action.d.ts.map +1 -1
  90. package/bin/contact/Action.js +2 -2
  91. package/bin/contact/Action.js.map +1 -1
  92. package/bin/contact/ContactPlugin.d.ts.map +1 -1
  93. package/bin/contact/ContactPlugin.js +17 -14
  94. package/bin/contact/ContactPlugin.js.map +1 -1
  95. package/bin/contact/runtime/ChatRuntime.js +1 -1
  96. package/bin/contact/runtime/ChatRuntime.js.map +1 -1
  97. package/bin/contact/types/ContactPluginOptions.d.ts +4 -0
  98. package/bin/contact/types/ContactPluginOptions.d.ts.map +1 -1
  99. package/bin/index.d.ts +5 -5
  100. package/bin/index.d.ts.map +1 -1
  101. package/bin/index.js +2 -2
  102. package/bin/index.js.map +1 -1
  103. package/bin/memory/Action.d.ts.map +1 -1
  104. package/bin/memory/Action.js +16 -4
  105. package/bin/memory/Action.js.map +1 -1
  106. package/bin/memory/runtime/Store.d.ts.map +1 -1
  107. package/bin/memory/runtime/Store.js +0 -22
  108. package/bin/memory/runtime/Store.js.map +1 -1
  109. package/bin/memory/runtime/Writer.d.ts +1 -1
  110. package/bin/memory/runtime/Writer.d.ts.map +1 -1
  111. package/bin/memory/runtime/Writer.js +2 -4
  112. package/bin/memory/runtime/Writer.js.map +1 -1
  113. package/bin/skill/Command.d.ts +3 -11
  114. package/bin/skill/Command.d.ts.map +1 -1
  115. package/bin/skill/Command.js +3 -31
  116. package/bin/skill/Command.js.map +1 -1
  117. package/bin/skill/PROMPT.d.ts +1 -1
  118. package/bin/skill/PROMPT.d.ts.map +1 -1
  119. package/bin/skill/PROMPT.js +1 -1
  120. package/bin/skill/PROMPT.js.map +1 -1
  121. package/bin/skill/Plugin.d.ts +3 -2
  122. package/bin/skill/Plugin.d.ts.map +1 -1
  123. package/bin/skill/Plugin.js +37 -129
  124. package/bin/skill/Plugin.js.map +1 -1
  125. package/bin/skill/runtime/Prompt.d.ts +11 -2
  126. package/bin/skill/runtime/Prompt.d.ts.map +1 -1
  127. package/bin/skill/runtime/Prompt.js +93 -8
  128. package/bin/skill/runtime/Prompt.js.map +1 -1
  129. package/bin/skill/runtime/SystemProvider.d.ts +2 -1
  130. package/bin/skill/runtime/SystemProvider.d.ts.map +1 -1
  131. package/bin/skill/runtime/SystemProvider.js +4 -9
  132. package/bin/skill/runtime/SystemProvider.js.map +1 -1
  133. package/bin/skill/types/SkillPlugin.d.ts +6 -18
  134. package/bin/skill/types/SkillPlugin.d.ts.map +1 -1
  135. package/bin/skill/types/SkillPlugin.js +2 -2
  136. package/bin/sound/Plugin.d.ts +69 -0
  137. package/bin/sound/Plugin.d.ts.map +1 -0
  138. package/bin/sound/Plugin.js +623 -0
  139. package/bin/sound/Plugin.js.map +1 -0
  140. package/bin/sound/types/SoundPlugin.d.ts +150 -0
  141. package/bin/sound/types/SoundPlugin.d.ts.map +1 -0
  142. package/bin/sound/types/SoundPlugin.js +10 -0
  143. package/bin/sound/types/SoundPlugin.js.map +1 -0
  144. package/bin/task/Action.d.ts +2 -0
  145. package/bin/task/Action.d.ts.map +1 -1
  146. package/bin/task/Action.js +6 -0
  147. package/bin/task/Action.js.map +1 -1
  148. package/bin/task/runtime/Runner.d.ts +4 -0
  149. package/bin/task/runtime/Runner.d.ts.map +1 -1
  150. package/bin/task/runtime/Runner.js +15 -11
  151. package/bin/task/runtime/Runner.js.map +1 -1
  152. package/bin/task/runtime/TaskActionExecution.d.ts +2 -0
  153. package/bin/task/runtime/TaskActionExecution.d.ts.map +1 -1
  154. package/bin/task/runtime/TaskActionExecution.js +1 -0
  155. package/bin/task/runtime/TaskActionExecution.js.map +1 -1
  156. package/bin/task/runtime/TaskPluginActionRegistry.d.ts.map +1 -1
  157. package/bin/task/runtime/TaskPluginActionRegistry.js +1 -0
  158. package/bin/task/runtime/TaskPluginActionRegistry.js.map +1 -1
  159. package/bin/task/runtime/TaskRunChatDispatch.js +1 -1
  160. package/bin/task/runtime/TaskRunChatDispatch.js.map +1 -1
  161. package/bin/task/runtime/TaskRunnerRound.d.ts.map +1 -1
  162. package/bin/task/runtime/TaskRunnerRound.js +19 -26
  163. package/bin/task/runtime/TaskRunnerRound.js.map +1 -1
  164. package/bin/task/runtime/TaskRunnerSession.d.ts +6 -2
  165. package/bin/task/runtime/TaskRunnerSession.d.ts.map +1 -1
  166. package/bin/task/runtime/TaskRunnerSession.js +93 -72
  167. package/bin/task/runtime/TaskRunnerSession.js.map +1 -1
  168. package/bin/task/runtime/TaskRunnerTypes.d.ts +4 -4
  169. package/bin/task/runtime/TaskRunnerTypes.d.ts.map +1 -1
  170. package/bin/task/types/TaskPluginOptions.d.ts.map +1 -1
  171. package/bin/web/PROMPT.d.ts +1 -1
  172. package/bin/web/PROMPT.d.ts.map +1 -1
  173. package/bin/web/PROMPT.js +2 -2
  174. package/bin/web/PROMPT.js.map +1 -1
  175. package/bin/web/Plugin.d.ts +1 -21
  176. package/bin/web/Plugin.d.ts.map +1 -1
  177. package/bin/web/Plugin.js +14 -79
  178. package/bin/web/Plugin.js.map +1 -1
  179. package/bin/web/runtime/Prompt.d.ts +14 -0
  180. package/bin/web/runtime/Prompt.d.ts.map +1 -0
  181. package/bin/web/runtime/Prompt.js +77 -0
  182. package/bin/web/runtime/Prompt.js.map +1 -0
  183. package/bin/web/types/WebPlugin.d.ts +40 -29
  184. package/bin/web/types/WebPlugin.d.ts.map +1 -1
  185. package/bin/web/types/WebPlugin.js +11 -3
  186. package/bin/web/types/WebPlugin.js.map +1 -1
  187. package/bin/workboard/runtime/Collector.js +1 -1
  188. package/bin/workboard/runtime/Collector.js.map +1 -1
  189. package/bin/workboard/runtime/Normalizer.js +1 -1
  190. package/bin/workboard/runtime/Normalizer.js.map +1 -1
  191. package/bin/workboard/runtime/SessionSummary.d.ts.map +1 -1
  192. package/bin/workboard/runtime/SessionSummary.js +11 -38
  193. package/bin/workboard/runtime/SessionSummary.js.map +1 -1
  194. package/package.json +8 -4
  195. package/scripts/chat-access.test.mjs +1 -1
  196. package/scripts/chat-channel-config.test.mjs +15 -64
  197. package/scripts/chat-storage.test.mjs +92 -0
  198. package/scripts/skill-plugin.test.mjs +93 -0
  199. package/scripts/sound-plugin.test.mjs +250 -0
  200. package/scripts/web-plugin.test.mjs +85 -0
  201. package/src/BuiltinPlugins.ts +7 -17
  202. package/src/chat/Action.ts +16 -5
  203. package/src/chat/ChatPlugin.ts +6 -35
  204. package/src/chat/Index.ts +0 -1
  205. package/src/chat/channels/BaseChatChannel.ts +1 -1
  206. package/src/chat/channels/Configuration.ts +1 -1
  207. package/src/chat/channels/RuntimeChannel.ts +2 -14
  208. package/src/chat/channels/feishu/Feishu.ts +2 -1
  209. package/src/chat/runtime/ChannelContextStore.ts +16 -12
  210. package/src/chat/runtime/ChatActionExecution.ts +48 -3
  211. package/src/chat/runtime/ChatActionInput.ts +0 -31
  212. package/src/chat/runtime/ChatChannelActions.ts +3 -254
  213. package/src/chat/runtime/ChatChannelConfig.ts +4 -133
  214. package/src/chat/runtime/ChatChannelCore.ts +1 -15
  215. package/src/chat/runtime/ChatChannelFacade.ts +0 -4
  216. package/src/chat/runtime/ChatHistoryStore.ts +4 -3
  217. package/src/chat/runtime/ChatPluginActionRegistry.ts +26 -98
  218. package/src/chat/runtime/ChatPluginSystem.ts +9 -3
  219. package/src/chat/runtime/ChatQueueStore.ts +2 -2
  220. package/src/chat/runtime/ChatQueueWorker.ts +1 -1
  221. package/src/chat/runtime/ChatSessionDelete.ts +11 -21
  222. package/src/chat/runtime/ChatStorage.ts +203 -0
  223. package/src/chat/runtime/SystemPrompt.ts +8 -3
  224. package/src/chat/types/ChannelConfiguration.ts +2 -2
  225. package/src/chat/types/ChatPluginActionPayload.ts +8 -49
  226. package/src/chat/types/ChatPluginOptions.ts +0 -22
  227. package/src/chat/types/ChatStorage.ts +37 -0
  228. package/src/contact/Action.ts +9 -1
  229. package/src/contact/ContactPlugin.ts +38 -14
  230. package/src/contact/runtime/ChatRuntime.ts +1 -1
  231. package/src/contact/types/ContactPluginOptions.ts +6 -0
  232. package/src/index.ts +16 -14
  233. package/src/memory/Action.ts +19 -4
  234. package/src/memory/runtime/Store.ts +0 -27
  235. package/src/memory/runtime/Writer.ts +2 -5
  236. package/src/skill/Command.ts +3 -33
  237. package/src/skill/PROMPT.ts +1 -1
  238. package/src/skill/PROMPT.ts.txt +5 -1
  239. package/src/skill/Plugin.ts +49 -156
  240. package/src/skill/runtime/Prompt.ts +109 -9
  241. package/src/skill/runtime/SystemProvider.ts +5 -9
  242. package/src/skill/types/SkillPlugin.ts +6 -18
  243. package/src/sound/Plugin.ts +699 -0
  244. package/src/sound/types/SoundPlugin.ts +163 -0
  245. package/src/task/Action.ts +8 -0
  246. package/src/task/runtime/Runner.ts +19 -13
  247. package/src/task/runtime/TaskActionExecution.ts +3 -0
  248. package/src/task/runtime/TaskPluginActionRegistry.ts +1 -0
  249. package/src/task/runtime/TaskRunChatDispatch.ts +1 -1
  250. package/src/task/runtime/TaskRunnerRound.ts +20 -38
  251. package/src/task/runtime/TaskRunnerSession.ts +108 -72
  252. package/src/task/runtime/TaskRunnerTypes.ts +4 -4
  253. package/src/task/types/TaskPluginOptions.ts +1 -0
  254. package/src/web/PROMPT.ts +2 -2
  255. package/src/web/PROMPT.ts.txt +4 -2
  256. package/src/web/Plugin.ts +20 -90
  257. package/src/web/runtime/Prompt.ts +99 -0
  258. package/src/web/types/WebPlugin.ts +42 -29
  259. package/src/workboard/runtime/Collector.ts +1 -1
  260. package/src/workboard/runtime/Normalizer.ts +1 -1
  261. package/src/workboard/runtime/SessionSummary.ts +11 -42
  262. package/bin/asr/Plugin.d.ts +0 -63
  263. package/bin/asr/Plugin.d.ts.map +0 -1
  264. package/bin/asr/Plugin.js +0 -280
  265. package/bin/asr/Plugin.js.map +0 -1
  266. package/bin/asr/types/AsrPlugin.d.ts +0 -114
  267. package/bin/asr/types/AsrPlugin.d.ts.map +0 -1
  268. package/bin/asr/types/AsrPlugin.js +0 -10
  269. package/bin/asr/types/AsrPlugin.js.map +0 -1
  270. package/bin/chat/runtime/ChatSession.d.ts +0 -97
  271. package/bin/chat/runtime/ChatSession.d.ts.map +0 -1
  272. package/bin/chat/runtime/ChatSession.js +0 -91
  273. package/bin/chat/runtime/ChatSession.js.map +0 -1
  274. package/bin/chat/runtime/ChatSessionContextComposer.d.ts +0 -45
  275. package/bin/chat/runtime/ChatSessionContextComposer.d.ts.map +0 -1
  276. package/bin/chat/runtime/ChatSessionContextComposer.js +0 -60
  277. package/bin/chat/runtime/ChatSessionContextComposer.js.map +0 -1
  278. package/bin/chat/runtime/ChatSessionTypes.d.ts +0 -30
  279. package/bin/chat/runtime/ChatSessionTypes.d.ts.map +0 -1
  280. package/bin/chat/runtime/ChatSessionTypes.js +0 -9
  281. package/bin/chat/runtime/ChatSessionTypes.js.map +0 -1
  282. package/bin/tts/Plugin.d.ts +0 -49
  283. package/bin/tts/Plugin.d.ts.map +0 -1
  284. package/bin/tts/Plugin.js +0 -247
  285. package/bin/tts/Plugin.js.map +0 -1
  286. package/bin/tts/types/TtsPlugin.d.ts +0 -122
  287. package/bin/tts/types/TtsPlugin.d.ts.map +0 -1
  288. package/bin/tts/types/TtsPlugin.js +0 -10
  289. package/bin/tts/types/TtsPlugin.js.map +0 -1
  290. package/bin/web/runtime/Install.d.ts +0 -19
  291. package/bin/web/runtime/Install.d.ts.map +0 -1
  292. package/bin/web/runtime/Install.js +0 -178
  293. package/bin/web/runtime/Install.js.map +0 -1
  294. package/src/asr/Plugin.ts +0 -322
  295. package/src/asr/types/AsrPlugin.ts +0 -118
  296. package/src/chat/runtime/ChatSession.ts +0 -168
  297. package/src/chat/runtime/ChatSessionContextComposer.ts +0 -106
  298. package/src/chat/runtime/ChatSessionTypes.ts +0 -32
  299. package/src/tts/Plugin.ts +0 -284
  300. package/src/tts/types/TtsPlugin.ts +0 -129
  301. package/src/web/runtime/Install.ts +0 -241
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - chat 语义(chatKey 与 sessionId 映射)统一收口在本模块
6
- * - 通过 SessionRunScope(ALS)读取当前请求上下文
6
+ * - Session 运行上下文由 action 入口显式传入
7
7
  */
8
8
 
9
9
  import type { AgentContext } from "@downcity/agent";
10
- import { getSessionRunContext } from "@downcity/agent";
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) SessionRunScope(ALS)
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 = getSessionRunContext();
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 与当前请求上下文一致时,才复用 `DC_CTX_MESSAGE_ID` / ALS 快照。
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) {
@@ -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 (context: AgentContext): Promise<string> => {
91
- return await buildChatPluginSystem(context);
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
@@ -20,6 +20,5 @@ export type {
20
20
  } from "./channels/RuntimeChannel.js";
21
21
  export type {
22
22
  ChatChannel,
23
- ChatChannelRuntimePatch,
24
23
  ChatPluginOptions,
25
24
  } from "./types/ChatPluginOptions.js";
@@ -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.config.id || "agent").trim() || "agent";
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
- * 返回可通过 `chat.configure` 更新的运行态字段定义。
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
- * - 可通过 chat.open / chat.close 在运行态修改。
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 = path.join(context.paths.getCacheDirPath(), "feishu", "dedupe");
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.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelDirPath(),
271
- filePath: params.context.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelDirPath(),
337
- filePath: params.context.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelDirPath(),
388
- filePath: params.context.paths.getDowncityChannelMetaPath(),
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.paths.getDowncityChannelMetaPath(),
199
+ get_chat_channel_meta_path(params.context.rootPath),
164
200
  );
165
201
  const chatDirPath = toPosixRelativePath(
166
- path.join(params.context.rootPath, ".downcity", "chat", sessionId),
202
+ get_chat_session_dir_path(params.context.rootPath, sessionId),
167
203
  );
168
204
  const historyPath = toPosixRelativePath(
169
- params.context.paths.getDowncityChatHistoryPath(sessionId),
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 {