@downcity/plugins 1.0.173 → 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.
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
@@ -12,14 +12,11 @@ import type { PluginActions } from "@downcity/agent";
12
12
  import { createAction } from "@downcity/agent";
13
13
  import { z } from "zod";
14
14
  import type {
15
- ChatCloseActionPayload,
16
- ChatConfigurationActionPayload,
17
- ChatConfigureActionPayload,
18
15
  ChatDeleteActionPayload,
19
16
  ChatHistoryActionPayload,
17
+ ChatHistoryClearActionPayload,
20
18
  ChatInfoActionPayload,
21
19
  ChatListActionPayload,
22
- ChatOpenActionPayload,
23
20
  ChatReactActionPayload,
24
21
  ChatReconnectActionPayload,
25
22
  ChatSendActionPayload,
@@ -30,7 +27,6 @@ import type {
30
27
  import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
31
28
  import {
32
29
  mapChatChannelCommandInput,
33
- mapChatConfigureCommandInput,
34
30
  mapChatDeleteCommandInput,
35
31
  mapChatHistoryCommandInput,
36
32
  mapChatInfoCommandInput,
@@ -46,12 +42,9 @@ import {
46
42
  executeChatListAction,
47
43
  executeChatReactAction,
48
44
  executeChatSendAction,
45
+ execute_chat_history_clear_action,
49
46
  } from "./ChatActionExecution.js";
50
47
  import {
51
- executeChatCloseAction,
52
- executeChatConfigurationAction,
53
- executeChatConfigureAction,
54
- executeChatOpenAction,
55
48
  executeChatReconnectAction,
56
49
  executeChatStatusAction,
57
50
  executeChatTestAction,
@@ -166,95 +159,6 @@ export function createChatPluginActions(params: {
166
159
  });
167
160
  },
168
161
  }),
169
- open: createAction({
170
- description: "Open and enable the specified chat channel.",
171
- input_schema: {
172
- zod: z.object({}).passthrough(),
173
- json_schema: { type: "object", properties: {}, additionalProperties: true },
174
- },
175
- command: {
176
- description: "Open chat channel (enabled=true, and start it if configured).",
177
- configure(command: Command) {
178
- command.option("--channel <name>", "Specify channel (telegram|feishu|qq).");
179
- },
180
- mapInput: mapChatChannelCommandInput,
181
- },
182
- execute: async (actionParams) => {
183
- return executeChatOpenAction({
184
- state: params.channelState,
185
- context: actionParams.context,
186
- payload: actionParams.input as ChatOpenActionPayload,
187
- });
188
- },
189
- }),
190
- close: createAction({
191
- description: "Close and disable the specified chat channel.",
192
- input_schema: {
193
- zod: z.object({}).passthrough(),
194
- json_schema: { type: "object", properties: {}, additionalProperties: true },
195
- },
196
- command: {
197
- description: "Close chat channel (enabled=false and stop runtime).",
198
- configure(command: Command) {
199
- command.option("--channel <name>", "Specify channel (telegram|feishu|qq).");
200
- },
201
- mapInput: mapChatChannelCommandInput,
202
- },
203
- execute: async (actionParams) => {
204
- return executeChatCloseAction({
205
- state: params.channelState,
206
- context: actionParams.context,
207
- payload: actionParams.input as ChatCloseActionPayload,
208
- });
209
- },
210
- }),
211
- configuration: createAction({
212
- description: "View chat channel configuration metadata.",
213
- input_schema: {
214
- zod: z.object({}).passthrough(),
215
- json_schema: { type: "object", properties: {}, additionalProperties: true },
216
- },
217
- command: {
218
- description: "View chat channel configuration metadata (fields, types, descriptions).",
219
- configure(command: Command) {
220
- command.option("--channel <name>", "Specify channel (telegram|feishu|qq).");
221
- },
222
- mapInput: mapChatChannelCommandInput,
223
- },
224
- execute: async (actionParams) => {
225
- return executeChatConfigurationAction({
226
- context: actionParams.context,
227
- payload: actionParams.input as ChatConfigurationActionPayload,
228
- });
229
- },
230
- }),
231
- configure: createAction({
232
- description: "Update runtime parameters for a chat channel.",
233
- input_schema: {
234
- zod: z.object({}).passthrough(),
235
- json_schema: { type: "object", properties: {}, additionalProperties: true },
236
- },
237
- command: {
238
- description: "Update runtime parameters for a chat channel, optionally restarting it immediately.",
239
- configure(command: Command) {
240
- command
241
- .requiredOption("--channel <name>", "Specify channel (telegram|feishu|qq).")
242
- .requiredOption(
243
- "--config-json <json>",
244
- "Configuration patch JSON, for example '{\"channelAccountId\":\"qq-main\",\"enabled\":true}'.",
245
- )
246
- .option("--restart", "Restart the channel immediately after configuration.", false);
247
- },
248
- mapInput: mapChatConfigureCommandInput,
249
- },
250
- execute: async (actionParams) => {
251
- return executeChatConfigureAction({
252
- state: params.channelState,
253
- context: actionParams.context,
254
- payload: actionParams.input as ChatConfigureActionPayload,
255
- });
256
- },
257
- }),
258
162
  list: createAction({
259
163
  description: "List chat conversations recorded by the current agent.",
260
164
  input_schema: {
@@ -297,6 +201,7 @@ export function createChatPluginActions(params: {
297
201
  return executeChatInfoAction({
298
202
  context: actionParams.context,
299
203
  payload: actionParams.input as ChatInfoActionPayload,
204
+ run_context: actionParams.run_context,
300
205
  });
301
206
  },
302
207
  }),
@@ -327,6 +232,7 @@ export function createChatPluginActions(params: {
327
232
  return executeChatSendAction({
328
233
  context: actionParams.context,
329
234
  payload: actionParams.input as ChatSendActionPayload,
235
+ run_context: actionParams.run_context,
330
236
  });
331
237
  },
332
238
  }),
@@ -355,6 +261,7 @@ export function createChatPluginActions(params: {
355
261
  return executeChatReactAction({
356
262
  context: actionParams.context,
357
263
  payload: actionParams.input as ChatReactActionPayload,
264
+ run_context: actionParams.run_context,
358
265
  });
359
266
  },
360
267
  }),
@@ -381,6 +288,7 @@ export function createChatPluginActions(params: {
381
288
  return executeChatContextAction({
382
289
  context: actionParams.context,
383
290
  payload: actionParams.input as ChatSessionActionPayload,
291
+ run_context: actionParams.run_context,
384
292
  });
385
293
  },
386
294
  }),
@@ -403,6 +311,7 @@ export function createChatPluginActions(params: {
403
311
  return executeChatDeleteAction({
404
312
  context: actionParams.context,
405
313
  payload: actionParams.input as ChatDeleteActionPayload,
314
+ run_context: actionParams.run_context,
406
315
  });
407
316
  },
408
317
  }),
@@ -432,6 +341,25 @@ export function createChatPluginActions(params: {
432
341
  return executeChatHistoryAction({
433
342
  context: actionParams.context,
434
343
  payload: actionParams.input as ChatHistoryActionPayload,
344
+ run_context: actionParams.run_context,
345
+ });
346
+ },
347
+ }),
348
+ history_clear: createAction({
349
+ description: "Clear the Chat Plugin event history for one Session.",
350
+ input_schema: {
351
+ zod: z.object({ sessionId: z.string().min(1) }),
352
+ json_schema: {
353
+ type: "object",
354
+ properties: { sessionId: { type: "string" } },
355
+ required: ["sessionId"],
356
+ additionalProperties: false,
357
+ },
358
+ },
359
+ execute: async (actionParams) => {
360
+ return await execute_chat_history_clear_action({
361
+ context: actionParams.context,
362
+ payload: actionParams.input as unknown as ChatHistoryClearActionPayload,
435
363
  });
436
364
  },
437
365
  }),
@@ -7,6 +7,7 @@
7
7
  * - 该模块只负责 prompt 解析与拼装,不承担运行态控制职责。
8
8
  */
9
9
  import type { AgentContext } from "@downcity/agent";
10
+ import type { PluginRunContext } from "@downcity/agent";
10
11
  import {
11
12
  buildCurrentChatEnvironmentPrompt,
12
13
  resolveCurrentChatEnvironmentPromptInput,
@@ -42,8 +43,12 @@ function resolveCurrentChatPromptChannel(
42
43
  */
43
44
  export async function buildCurrentChannelPrompts(
44
45
  context: AgentContext,
46
+ run_context?: PluginRunContext,
45
47
  ): Promise<string[]> {
46
- const chatEnvironment = await resolveCurrentChatEnvironmentPromptInput(context);
48
+ const chatEnvironment = await resolveCurrentChatEnvironmentPromptInput(
49
+ context,
50
+ run_context,
51
+ );
47
52
  if (!chatEnvironment) return [];
48
53
  const channel = resolveCurrentChatPromptChannel(
49
54
  String(chatEnvironment.channel || "")
@@ -59,11 +64,12 @@ export async function buildCurrentChannelPrompts(
59
64
  */
60
65
  export async function buildChatPluginSystem(
61
66
  context: AgentContext,
67
+ run_context?: PluginRunContext,
62
68
  ): Promise<string> {
63
69
  return [
64
70
  CHAT_PLUGIN_PROMPT,
65
- await buildCurrentChatEnvironmentPrompt(context),
66
- ...(await buildCurrentChannelPrompts(context)),
71
+ await buildCurrentChatEnvironmentPrompt(context, run_context),
72
+ ...(await buildCurrentChannelPrompts(context, run_context)),
67
73
  ]
68
74
  .filter(Boolean)
69
75
  .join("\n\n");
@@ -171,11 +171,11 @@ export function getSharedChatQueueStore(): ChatQueueStore {
171
171
  * 从运行时解析 chat queue store。
172
172
  *
173
173
  * 关键点(中文)
174
- * - 新路径优先读取 `context.pluginInstances.chat.queueStore`。
174
+ * - 新路径优先读取当前 Agent 注册的 ChatPlugin 实例。
175
175
  * - 迁移阶段若拿不到,则回退到共享 queue store,保证旧入口可继续工作。
176
176
  */
177
177
  export function resolveChatQueueStore(context?: AgentContext): ChatQueueStorePort {
178
- const chatService = context?.pluginInstances?.get?.("chat") as
178
+ const chatService = context?.plugins.get("chat") as
179
179
  | { queueStore?: ChatQueueStorePort }
180
180
  | undefined;
181
181
  if (chatService?.queueStore) {
@@ -466,6 +466,6 @@ export class ChatQueueWorker {
466
466
  * - 在使用点显式校验,避免隐藏依赖来源。
467
467
  */
468
468
  private requireContext(sessionId: string) {
469
- return this.context.session.get(sessionId);
469
+ return this.context.sessions.runtime(sessionId);
470
470
  }
471
471
  }
@@ -8,11 +8,9 @@
8
8
  * - 清理运行中 agent 与队列,避免残留任务继续执行
9
9
  */
10
10
 
11
- import fs from "fs-extra";
12
- import path from "node:path";
13
11
  import type { AgentContext } from "@downcity/agent";
14
12
  import { resolveChatQueueStore } from "@/chat/runtime/ChatQueue.js";
15
- import { removeChatMetaBySessionId } from "@/chat/runtime/ChatMetaStore.js";
13
+ import { clean_chat_storage } from "@/chat/runtime/ChatStorage.js";
16
14
 
17
15
  function normalizeSessionId(sessionId: string): string {
18
16
  return String(sessionId || "").trim();
@@ -53,32 +51,24 @@ export async function deleteChatSessionById(params: {
53
51
  // 关键点(中文):先停执行,再删文件,避免删除过程中仍有任务写入。
54
52
  resolveChatQueueStore(params.context).clear(sessionId);
55
53
 
56
- const removedMetaResult = await removeChatMetaBySessionId({
57
- context: params.context,
58
- sessionId,
54
+ const chat_result = await clean_chat_storage({
55
+ root_path: params.context.rootPath,
56
+ session_id: sessionId,
59
57
  });
60
-
61
- const chatDir = path.join(params.context.rootPath, ".downcity", "chat", sessionId);
62
- const sessionDir = params.context.paths.getDowncitySessionDirPath(sessionId);
63
- const hadChatDir = await fs.pathExists(chatDir);
64
- const hadSessionDir = await fs.pathExists(sessionDir);
65
- if (hadChatDir) {
66
- await fs.remove(chatDir);
67
- }
68
- if (hadSessionDir) {
69
- await fs.remove(sessionDir);
70
- }
58
+ const removed_session_dir = await params.context.sessions.remove(sessionId);
71
59
 
72
60
  const deleted =
73
- removedMetaResult.removed || hadChatDir || hadSessionDir;
61
+ chat_result.removed_route ||
62
+ chat_result.removed_chat_dir ||
63
+ removed_session_dir;
74
64
 
75
65
  return {
76
66
  success: true,
77
67
  sessionId,
78
68
  deleted,
79
- removedMeta: removedMetaResult.removed,
80
- removedChatDir: hadChatDir,
81
- removedSessionDir: hadSessionDir,
69
+ removedMeta: chat_result.removed_route,
70
+ removedChatDir: chat_result.removed_chat_dir,
71
+ removedSessionDir: removed_session_dir,
82
72
  };
83
73
  } catch (error) {
84
74
  return {
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Chat Plugin 存储路径与离线维护能力。
3
+ *
4
+ * 关键点(中文)
5
+ * - Chat Plugin 是 channel meta、chat history 与渠道缓存路径的唯一所有者。
6
+ * - AgentContext 只提供项目根目录,不暴露任何 Chat 领域路径。
7
+ * - CLI 离线维护通过本模块操作 Chat 存储,不复制内部 JSON 结构。
8
+ */
9
+
10
+ import path from "node:path";
11
+ import fs from "fs-extra";
12
+ import type {
13
+ ChatStorageCleanInput,
14
+ ChatStorageCleanResult,
15
+ } from "@/chat/types/ChatStorage.js";
16
+ import type {
17
+ ChannelContextMetaFileV1,
18
+ ChannelContextRouteV1,
19
+ } from "@/chat/types/ChannelContext.js";
20
+
21
+ function normalize_text(input: unknown): string {
22
+ return String(input || "").trim();
23
+ }
24
+
25
+ function normalize_thread_id(input: unknown): number | undefined {
26
+ const value = Number(input);
27
+ if (!Number.isFinite(value) || value <= 0) return undefined;
28
+ return Math.trunc(value);
29
+ }
30
+
31
+ function get_downcity_path(root_path: string): string {
32
+ return path.join(root_path, ".downcity");
33
+ }
34
+
35
+ /** 返回 Chat 渠道路由目录。 */
36
+ export function get_chat_channel_dir_path(root_path: string): string {
37
+ return path.join(get_downcity_path(root_path), "channel");
38
+ }
39
+
40
+ /** 返回 Chat 渠道路由文件。 */
41
+ export function get_chat_channel_meta_path(root_path: string): string {
42
+ return path.join(get_chat_channel_dir_path(root_path), "meta.json");
43
+ }
44
+
45
+ /** 返回单个 Chat 会话的事件目录。 */
46
+ export function get_chat_session_dir_path(
47
+ root_path: string,
48
+ session_id: string,
49
+ ): string {
50
+ return path.join(
51
+ get_downcity_path(root_path),
52
+ "chat",
53
+ encodeURIComponent(normalize_text(session_id)),
54
+ );
55
+ }
56
+
57
+ /** 返回单个 Chat 会话的事件流文件。 */
58
+ export function get_chat_history_path(
59
+ root_path: string,
60
+ session_id: string,
61
+ ): string {
62
+ return path.join(get_chat_session_dir_path(root_path, session_id), "history.jsonl");
63
+ }
64
+
65
+ /** 返回飞书渠道的消息去重目录。 */
66
+ export function get_feishu_dedupe_dir_path(root_path: string): string {
67
+ return path.join(get_downcity_path(root_path), ".cache", "feishu", "dedupe");
68
+ }
69
+
70
+ async function read_channel_meta(
71
+ root_path: string,
72
+ ): Promise<Partial<ChannelContextMetaFileV1>> {
73
+ const raw = await fs.readJson(get_chat_channel_meta_path(root_path)).catch(() => null);
74
+ return raw && typeof raw === "object"
75
+ ? raw as Partial<ChannelContextMetaFileV1>
76
+ : {};
77
+ }
78
+
79
+ function build_target_key(input: ChatStorageCleanInput): string {
80
+ const channel = normalize_text(input.channel);
81
+ const chat_id = normalize_text(input.chat_id);
82
+ if (!channel || !chat_id) return "";
83
+ return [
84
+ channel,
85
+ chat_id,
86
+ normalize_text(input.target_type),
87
+ normalize_thread_id(input.thread_id) || "",
88
+ ].join("|");
89
+ }
90
+
91
+ function matches_target(
92
+ route: ChannelContextRouteV1,
93
+ input: ChatStorageCleanInput,
94
+ ): boolean {
95
+ const channel = normalize_text(input.channel);
96
+ const chat_id = normalize_text(input.chat_id);
97
+ const target_type = normalize_text(input.target_type);
98
+ const thread_id = normalize_thread_id(input.thread_id);
99
+ if (!channel || !chat_id) return false;
100
+ if (normalize_text(route.channel) !== channel) return false;
101
+ if (normalize_text(route.chatId) !== chat_id) return false;
102
+ if (target_type && normalize_text(route.targetType) !== target_type) return false;
103
+ if (thread_id && normalize_thread_id(route.threadId) !== thread_id) return false;
104
+ return true;
105
+ }
106
+
107
+ function resolve_session_id(
108
+ meta: Partial<ChannelContextMetaFileV1>,
109
+ input: ChatStorageCleanInput,
110
+ ): string {
111
+ const explicit = normalize_text(input.session_id);
112
+ if (explicit) return explicit;
113
+ const target_key = build_target_key(input);
114
+ const mapped = normalize_text(
115
+ target_key ? meta.sessionIdByTargetKey?.[target_key] : "",
116
+ );
117
+ if (mapped) return mapped;
118
+ for (const route of Object.values(meta.routesBySessionId || {})) {
119
+ if (route && matches_target(route, input)) {
120
+ return normalize_text(route.sessionId);
121
+ }
122
+ }
123
+ return "";
124
+ }
125
+
126
+ async function remove_route(
127
+ root_path: string,
128
+ meta: Partial<ChannelContextMetaFileV1>,
129
+ session_id: string,
130
+ ): Promise<boolean> {
131
+ const routes_by_session_id = { ...(meta.routesBySessionId || {}) };
132
+ const session_id_by_target_key = { ...(meta.sessionIdByTargetKey || {}) };
133
+ let removed = false;
134
+ if (routes_by_session_id[session_id]) {
135
+ delete routes_by_session_id[session_id];
136
+ removed = true;
137
+ }
138
+ for (const [target_key, mapped_session_id] of Object.entries(
139
+ session_id_by_target_key,
140
+ )) {
141
+ if (normalize_text(mapped_session_id) !== session_id) continue;
142
+ delete session_id_by_target_key[target_key];
143
+ removed = true;
144
+ }
145
+ if (!removed) return false;
146
+ await fs.ensureDir(get_chat_channel_dir_path(root_path));
147
+ await fs.writeJson(
148
+ get_chat_channel_meta_path(root_path),
149
+ {
150
+ ...meta,
151
+ v: 1,
152
+ updatedAt: Date.now(),
153
+ routesBySessionId: routes_by_session_id,
154
+ sessionIdByTargetKey: session_id_by_target_key,
155
+ },
156
+ { spaces: 2 },
157
+ );
158
+ return true;
159
+ }
160
+
161
+ /**
162
+ * 清空单个 Chat 会话的事件历史。
163
+ */
164
+ export async function clear_chat_history(
165
+ root_path: string,
166
+ session_id: string,
167
+ ): Promise<boolean> {
168
+ const history_path = get_chat_history_path(root_path, session_id);
169
+ const existed = await fs.pathExists(history_path);
170
+ if (existed) await fs.remove(history_path);
171
+ return existed;
172
+ }
173
+
174
+ /**
175
+ * 清理单个 Chat 会话的领域存储。
176
+ *
177
+ * 关键点(中文)
178
+ * - 只删除 Chat Plugin 自己拥有的路由与事件目录。
179
+ * - Agent Session 数据由调用方通过 Session API 单独删除。
180
+ */
181
+ export async function clean_chat_storage(
182
+ input: ChatStorageCleanInput,
183
+ ): Promise<ChatStorageCleanResult> {
184
+ const root_path = path.resolve(normalize_text(input.root_path) || ".");
185
+ const meta = await read_channel_meta(root_path);
186
+ const session_id = resolve_session_id(meta, input);
187
+ if (!session_id) {
188
+ return {
189
+ session_id: "",
190
+ removed_chat_dir: false,
191
+ removed_route: false,
192
+ };
193
+ }
194
+ const chat_dir_path = get_chat_session_dir_path(root_path, session_id);
195
+ const removed_chat_dir = await fs.pathExists(chat_dir_path);
196
+ if (removed_chat_dir) await fs.remove(chat_dir_path);
197
+ const removed_route = await remove_route(root_path, meta, session_id);
198
+ return {
199
+ session_id,
200
+ removed_chat_dir,
201
+ removed_route,
202
+ };
203
+ }
@@ -7,8 +7,8 @@
7
7
  * - 统一从 request context + ChatMetaStore 读取当前 chat 元信息。
8
8
  */
9
9
 
10
- import { getSessionRunContext } from "@downcity/agent";
11
10
  import type { AgentContext } from "@downcity/agent";
11
+ import type { PluginRunContext } from "@downcity/agent";
12
12
  import type { ChatEnvironmentPromptInput } from "@/chat/types/ChatPromptContext.js";
13
13
  import { readChatMetaBySessionId } from "@/chat/runtime/ChatMetaStore.js";
14
14
 
@@ -25,8 +25,9 @@ function normalizePromptValue(value: unknown, fallback: string): string {
25
25
  */
26
26
  export async function resolveCurrentChatEnvironmentPromptInput(
27
27
  context: AgentContext,
28
+ run_context?: PluginRunContext,
28
29
  ): Promise<ChatEnvironmentPromptInput | null> {
29
- const sessionId = String(getSessionRunContext()?.sessionId || "").trim();
30
+ const sessionId = String(run_context?.sessionId || "").trim();
30
31
  if (!sessionId) return null;
31
32
 
32
33
  const meta = await readChatMetaBySessionId({
@@ -77,8 +78,12 @@ export function buildChatEnvironmentPrompt(input: ChatEnvironmentPromptInput): s
77
78
  */
78
79
  export async function buildCurrentChatEnvironmentPrompt(
79
80
  context: AgentContext,
81
+ run_context?: PluginRunContext,
80
82
  ): Promise<string> {
81
- const input = await resolveCurrentChatEnvironmentPromptInput(context);
83
+ const input = await resolveCurrentChatEnvironmentPromptInput(
84
+ context,
85
+ run_context,
86
+ );
82
87
  if (!input) return "";
83
88
  return buildChatEnvironmentPrompt(input);
84
89
  }
@@ -82,7 +82,7 @@ export interface ChatChannelConfigurationField {
82
82
  */
83
83
  nullable: boolean;
84
84
  /**
85
- * 是否允许通过 `chat.configure` 写入。
85
+ * 是否允许上游产品写入。
86
86
  */
87
87
  writable: boolean;
88
88
  /**
@@ -136,7 +136,7 @@ export interface ChatChannelConfigurationDescriptor {
136
136
  */
137
137
  canBindChannelAccount: boolean;
138
138
  /**
139
- * 是否支持 `chat.configure`。
139
+ * 上游产品是否支持编辑该渠道配置。
140
140
  */
141
141
  canConfigure: boolean;
142
142
  };
@@ -7,7 +7,6 @@
7
7
  * - 字段命名保持与 CLI/API 参数一致,降低映射心智负担。
8
8
  */
9
9
 
10
- import type { JsonValue } from "@downcity/agent";
11
10
  import type {
12
11
  ChatDeleteRequest,
13
12
  ChatHistoryRequest,
@@ -66,6 +65,14 @@ export type ChatSessionActionPayload = {
66
65
  */
67
66
  export type ChatHistoryActionPayload = ChatHistoryRequest;
68
67
 
68
+ /**
69
+ * `chat.history_clear` action 的输入载荷。
70
+ */
71
+ export interface ChatHistoryClearActionPayload {
72
+ /** 要清空 Chat 事件历史的 Session 标识。 */
73
+ sessionId: string;
74
+ }
75
+
69
76
  /**
70
77
  * `chat.react` action 的输入载荷。
71
78
  */
@@ -115,51 +122,3 @@ export type ChatReconnectActionPayload = {
115
122
  */
116
123
  channel?: ChatChannelName;
117
124
  };
118
-
119
- /**
120
- * `chat.open` action 的输入载荷。
121
- */
122
- export type ChatOpenActionPayload = {
123
- /**
124
- * 指定目标渠道;省略时表示全部渠道。
125
- */
126
- channel?: ChatChannelName;
127
- };
128
-
129
- /**
130
- * `chat.close` action 的输入载荷。
131
- */
132
- export type ChatCloseActionPayload = {
133
- /**
134
- * 指定目标渠道;省略时表示全部渠道。
135
- */
136
- channel?: ChatChannelName;
137
- };
138
-
139
- /**
140
- * `chat.configuration` action 的输入载荷。
141
- */
142
- export type ChatConfigurationActionPayload = {
143
- /**
144
- * 指定目标渠道;省略时表示全部渠道。
145
- */
146
- channel?: ChatChannelName;
147
- };
148
-
149
- /**
150
- * `chat.configure` action 的输入载荷。
151
- */
152
- export type ChatConfigureActionPayload = {
153
- /**
154
- * 要更新的目标渠道。
155
- */
156
- channel: ChatChannelName;
157
- /**
158
- * 渠道配置 patch;值类型遵循 channel configuration 元信息。
159
- */
160
- config: Record<string, JsonValue>;
161
- /**
162
- * 配置完成后是否立即重启目标渠道;默认由上层解释为 true。
163
- */
164
- restart?: boolean;
165
- };
@@ -12,24 +12,6 @@ import type { StoredChannelAccount } from "@downcity/agent";
12
12
  import type { ChatChannelName } from "@/chat/types/ChannelStatus.js";
13
13
  import type { ChatQueueWorkerConfig } from "@/chat/types/ChatQueueWorker.js";
14
14
 
15
- /**
16
- * Chat channel 运行态 patch。
17
- */
18
- export interface ChatChannelRuntimePatch {
19
- /**
20
- * 是否启用该 channel。
21
- */
22
- enabled?: boolean;
23
- /**
24
- * 绑定的账号池记录 ID。
25
- *
26
- * 说明(中文)
27
- * - 传入字符串表示绑定到该账号池记录。
28
- * - 传入 `null` 表示清空账号池绑定。
29
- */
30
- channelAccountId?: string | null;
31
- }
32
-
33
15
  /**
34
16
  * Chat channel 对象协议。
35
17
  */
@@ -50,10 +32,6 @@ export interface ChatChannel {
50
32
  * 解析当前 channel 的运行态账号。
51
33
  */
52
34
  getAccount(context: AgentContext): StoredChannelAccount | null;
53
- /**
54
- * 应用运行态配置 patch。
55
- */
56
- applyRuntimePatch(patch: ChatChannelRuntimePatch): void;
57
35
  }
58
36
 
59
37
  /**