@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.
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
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Chat Plugin 存储维护类型。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这些类型只描述 Chat Plugin 自己的持久化数据维护能力。
6
+ * - Agent、Server 与 CLI 不需要知道 channel meta 或 chat history 的实际目录结构。
7
+ */
8
+
9
+ /**
10
+ * 清理单个 Chat 会话存储的输入。
11
+ */
12
+ export interface ChatStorageCleanInput {
13
+ /** 当前 Agent 项目根目录。 */
14
+ root_path: string;
15
+ /** 已知的 Session 标识;提供时优先使用。 */
16
+ session_id?: string;
17
+ /** Chat 渠道名称;未提供 Session 标识时用于解析目标会话。 */
18
+ channel?: string;
19
+ /** Chat 渠道目标标识;未提供 Session 标识时用于解析目标会话。 */
20
+ chat_id?: string;
21
+ /** 可选的 Chat 目标类型,用于缩小路由匹配范围。 */
22
+ target_type?: string;
23
+ /** 可选的消息线程标识,用于缩小路由匹配范围。 */
24
+ thread_id?: number;
25
+ }
26
+
27
+ /**
28
+ * 清理单个 Chat 会话存储的结果。
29
+ */
30
+ export interface ChatStorageCleanResult {
31
+ /** 最终解析出的 Session 标识;未找到目标时为空字符串。 */
32
+ session_id: string;
33
+ /** 是否删除了 Chat 事件目录。 */
34
+ removed_chat_dir: boolean;
35
+ /** 是否从 channel meta 中删除了路由映射。 */
36
+ removed_route: boolean;
37
+ }
@@ -9,6 +9,7 @@
9
9
  import type { AgentContext } from "@downcity/agent";
10
10
  import type { JsonObject, JsonValue } from "@downcity/agent";
11
11
  import type { PluginActions } from "@downcity/agent";
12
+ import type { PluginRunContext } from "@downcity/agent";
12
13
  import { createAction } from "@downcity/agent";
13
14
  import { z } from "zod";
14
15
  import type {
@@ -44,13 +45,18 @@ export type ContactActionHandlers = {
44
45
  /**
45
46
  * 生成一次性联系码。
46
47
  */
47
- link: (context: AgentContext, payload: ContactLinkCommandPayload) => Promise<JsonValue>;
48
+ link: (
49
+ context: AgentContext,
50
+ payload: ContactLinkCommandPayload,
51
+ run_context?: PluginRunContext,
52
+ ) => Promise<JsonValue>;
48
53
  /**
49
54
  * 使用联系码建立 contact。
50
55
  */
51
56
  approve: (
52
57
  context: AgentContext,
53
58
  payload: ContactApproveCommandPayload,
59
+ run_context?: PluginRunContext,
54
60
  ) => Promise<JsonValue>;
55
61
  /**
56
62
  * 检查 contact 或 endpoint 可用性。
@@ -124,6 +130,7 @@ export function createContactActions(handlers: ContactActionHandlers): PluginAct
124
130
  data: await handlers.link(
125
131
  params.context,
126
132
  params.input as ContactLinkCommandPayload,
133
+ params.run_context,
127
134
  ),
128
135
  }),
129
136
  }),
@@ -166,6 +173,7 @@ export function createContactActions(handlers: ContactActionHandlers): PluginAct
166
173
  data: await handlers.approve(
167
174
  params.context,
168
175
  params.input as unknown as ContactApproveCommandPayload,
176
+ params.run_context,
169
177
  ),
170
178
  }),
171
179
  }),
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import type { AgentContext } from "@downcity/agent";
11
+ import type { PluginRunContext } from "@downcity/agent";
11
12
  import type { JsonValue } from "@downcity/agent";
12
13
  import type { PluginActions } from "@downcity/agent";
13
14
  import { BasePlugin } from "@downcity/agent";
@@ -82,32 +83,40 @@ import {
82
83
 
83
84
  async function resolveSelfEndpoint(
84
85
  context: AgentContext,
86
+ options: ContactPluginOptions,
85
87
  endpointOverride?: string,
88
+ effective_env?: Readonly<Record<string, string>>,
86
89
  ): Promise<string> {
87
90
  const explicit = String(endpointOverride || "").trim();
88
91
  if (explicit) return normalizeContactEndpoint(explicit);
89
- const start = context.config.start || {};
90
92
  const env = {
91
93
  ...process.env,
92
94
  ...context.env,
95
+ ...effective_env,
93
96
  };
94
97
  const runtimePort = Number(process.env.DC_CITY_PORT || env.DC_CITY_PORT || "");
95
98
  // 关键点(中文):link code 必须写入当前 runtime 的真实监听端口,不能使用可能已经过期的配置端口。
96
- const port = Number.isFinite(runtimePort) && runtimePort > 0 ? runtimePort : start.port;
99
+ const port = Number.isFinite(runtimePort) && runtimePort > 0
100
+ ? runtimePort
101
+ : options.port;
97
102
  const runtimeHost = String(process.env.DC_CITY_HOST || env.DC_CITY_HOST || "").trim();
98
103
  return normalizeContactEndpoint(
99
104
  await resolveContactSelfEndpoint({
100
- host: runtimeHost || start.host,
105
+ host: runtimeHost || options.host,
101
106
  port,
102
107
  env,
103
108
  }),
104
109
  );
105
110
  }
106
111
 
107
- function hasRuntimePublicEndpointEnv(context: AgentContext): boolean {
112
+ function hasRuntimePublicEndpointEnv(
113
+ context: AgentContext,
114
+ effective_env?: Readonly<Record<string, string>>,
115
+ ): boolean {
108
116
  const env = {
109
117
  ...process.env,
110
118
  ...context.env,
119
+ ...effective_env,
111
120
  };
112
121
  return Boolean(
113
122
  String(env.DOWNCITY_PUBLIC_URL || "").trim() ||
@@ -116,7 +125,7 @@ function hasRuntimePublicEndpointEnv(context: AgentContext): boolean {
116
125
  }
117
126
 
118
127
  function getAgentName(context: AgentContext): string {
119
- return String(context.config.id || "downcity-agent").trim() || "downcity-agent";
128
+ return String(context.agent_id || "downcity-agent").trim() || "downcity-agent";
120
129
  }
121
130
 
122
131
  function requireOutboundContact(contact: AgentContact): {
@@ -155,10 +164,10 @@ export class ContactPlugin extends BasePlugin {
155
164
  super();
156
165
  this.options = options || {};
157
166
  this.actions = createContactActions({
158
- link: async (context, payload) =>
159
- (await this.link(context, payload)) as unknown as JsonValue,
160
- approve: async (context, payload) =>
161
- (await this.approve(context, payload)) as unknown as JsonValue,
167
+ link: async (context, payload, run_context) =>
168
+ (await this.link(context, payload, run_context)) as unknown as JsonValue,
169
+ approve: async (context, payload, run_context) =>
170
+ (await this.approve(context, payload, run_context)) as unknown as JsonValue,
162
171
  check: async (context, payload) =>
163
172
  (await this.check(context, payload)) as unknown as JsonValue,
164
173
  chat: async (context, payload) =>
@@ -180,7 +189,11 @@ export class ContactPlugin extends BasePlugin {
180
189
  return buildContactPluginSystemText();
181
190
  }
182
191
 
183
- private async link(context: AgentContext, payload: ContactLinkCommandPayload) {
192
+ private async link(
193
+ context: AgentContext,
194
+ payload: ContactLinkCommandPayload,
195
+ run_context?: PluginRunContext,
196
+ ) {
184
197
  const now = Date.now();
185
198
  const ttlSeconds = Math.max(
186
199
  60,
@@ -190,7 +203,9 @@ export class ContactPlugin extends BasePlugin {
190
203
  const secret = createContactToken();
191
204
  const endpoint = await resolveSelfEndpoint(
192
205
  context,
206
+ this.options,
193
207
  payload.endpoint || this.options.endpoint,
208
+ run_context?.agentEnv,
194
209
  );
195
210
  const agentName = getAgentName(context);
196
211
 
@@ -224,7 +239,11 @@ export class ContactPlugin extends BasePlugin {
224
239
  };
225
240
  }
226
241
 
227
- private async approve(context: AgentContext, payload: ContactApproveCommandPayload) {
242
+ private async approve(
243
+ context: AgentContext,
244
+ payload: ContactApproveCommandPayload,
245
+ run_context?: PluginRunContext,
246
+ ) {
228
247
  const parsed = parseContactLinkCode(payload.code);
229
248
  // 关键点(中文):approve 端不使用本机时钟预判过期,避免两台机器时钟不一致时把本来可用的 link 提前拦截。
230
249
  // 是否过期统一交给 link 持有方在远端按本地记录判断。
@@ -232,11 +251,16 @@ export class ContactPlugin extends BasePlugin {
232
251
  const targetReachability = classifyContactEndpoint(parsed.endpoint);
233
252
  const shouldResolveRequesterEndpoint =
234
253
  payload.endpoint ||
235
- hasRuntimePublicEndpointEnv(context) ||
254
+ hasRuntimePublicEndpointEnv(context, run_context?.agentEnv) ||
236
255
  targetReachability === "loopback" ||
237
256
  targetReachability === "private";
238
257
  const requesterEndpointCandidate = shouldResolveRequesterEndpoint
239
- ? await resolveSelfEndpoint(context, payload.endpoint || this.options.endpoint)
258
+ ? await resolveSelfEndpoint(
259
+ context,
260
+ this.options,
261
+ payload.endpoint || this.options.endpoint,
262
+ run_context?.agentEnv,
263
+ )
240
264
  : undefined;
241
265
  const callbackDecision = buildContactApproveCallbackDecision({
242
266
  targetEndpoint: parsed.endpoint,
@@ -458,7 +482,7 @@ export class ContactPlugin extends BasePlugin {
458
482
  return await approveContactLinkRequest({
459
483
  projectRoot: context.rootPath,
460
484
  ownerAgentName: getAgentName(context),
461
- ownerEndpoint: await resolveSelfEndpoint(context),
485
+ ownerEndpoint: await resolveSelfEndpoint(context, this.options),
462
486
  request,
463
487
  });
464
488
  }
@@ -64,7 +64,7 @@ export async function receiveContactChatMessage(params: {
64
64
  });
65
65
 
66
66
  const sessionId = `contact_${contact.id}`;
67
- const turn = await params.context.session.get(sessionId).prompt({
67
+ const turn = await params.context.sessions.runtime(sessionId).prompt({
68
68
  query: params.message,
69
69
  });
70
70
  const result = await turn.finished;
@@ -19,6 +19,12 @@ export interface ContactPluginOptions {
19
19
  */
20
20
  endpoint?: string;
21
21
 
22
+ /** 当前 Agent HTTP runtime 的监听 host。 */
23
+ host?: string;
24
+
25
+ /** 当前 Agent HTTP runtime 的监听 port。 */
26
+ port?: number;
27
+
22
28
  /**
23
29
  * 默认 link 有效秒数。
24
30
  *
package/src/index.ts CHANGED
@@ -26,8 +26,7 @@ export { ImagePlugin } from "./image/ImagePlugin.js";
26
26
  export { ChatChannelAccountManager } from "./chat/accounts/ChannelAccountManager.js";
27
27
  export { SkillPlugin } from "./skill/Plugin.js";
28
28
  export { WebPlugin } from "./web/Plugin.js";
29
- export { AsrPlugin } from "./asr/Plugin.js";
30
- export { TtsPlugin } from "./tts/Plugin.js";
29
+ export { SoundPlugin } from "./sound/Plugin.js";
31
30
  export { WorkboardPlugin } from "./workboard/Plugin.js";
32
31
  export { TaskPlugin } from "./task/TaskPlugin.js";
33
32
  export { MemoryPlugin } from "./memory/MemoryPlugin.js";
@@ -39,10 +38,15 @@ export {
39
38
  } from "./chat/access/ChatAccessService.js";
40
39
  export { get_chat_access_db_path } from "./chat/access/ChatAccessStore.js";
41
40
  export { CHAT_ACCESS_ACTIONS } from "./chat/types/ChatAccess.js";
41
+ export { clean_chat_storage } from "./chat/runtime/ChatStorage.js";
42
42
 
43
43
  export type {
44
44
  ChatChannelAccountListItem,
45
45
  } from "./chat/types/ChannelAccount.js";
46
+ export type {
47
+ ChatStorageCleanInput,
48
+ ChatStorageCleanResult,
49
+ } from "./chat/types/ChatStorage.js";
46
50
  export type {
47
51
  BaseChatChannelOptions,
48
52
  ChatChannelEnv,
@@ -52,7 +56,6 @@ export type {
52
56
  } from "./chat/channels/RuntimeChannel.js";
53
57
  export type {
54
58
  ChatChannel,
55
- ChatChannelRuntimePatch,
56
59
  ChatPluginOptions,
57
60
  } from "./chat/types/ChatPluginOptions.js";
58
61
  export type { ContactPluginOptions } from "./contact/types/ContactPluginOptions.js";
@@ -85,17 +88,16 @@ export type {
85
88
  MemoryWikiPageDraft,
86
89
  } from "./memory/types/Memory.js";
87
90
  export type {
88
- AsrPluginInput,
89
- AsrPluginOptions,
90
- AsrPluginResult,
91
- } from "./asr/types/AsrPlugin.js";
92
- export type {
93
- TtsPluginInput,
94
- TtsPluginOptions,
95
- TtsPluginResult,
96
- TtsPluginSimpleAudioResult,
97
- TtsPluginUiMessageResult,
98
- } from "./tts/types/TtsPlugin.js";
91
+ SoundPluginAsrInput,
92
+ SoundPluginAsrResult,
93
+ SoundPluginAsrSegment,
94
+ SoundPluginCapability,
95
+ SoundPluginModel,
96
+ SoundPluginModelsResult,
97
+ SoundPluginOptions,
98
+ SoundPluginTtsInput,
99
+ SoundPluginTtsResult,
100
+ } from "./sound/types/SoundPlugin.js";
99
101
  export type {
100
102
  ImagePluginContent,
101
103
  ImagePluginDefaultModel,
@@ -12,6 +12,7 @@ import { isTextUIPart } from "ai";
12
12
  import type { PluginActionResult } from "@downcity/agent";
13
13
  import type { AgentContext } from "@downcity/agent";
14
14
  import type { JsonValue } from "@downcity/agent";
15
+ import type { SessionMessage } from "@downcity/agent";
15
16
  import type {
16
17
  MemoryDigestPayload,
17
18
  MemoryDigestResponse,
@@ -67,6 +68,20 @@ function extractReadableLine(message: unknown): string {
67
68
  return `${role}: ${text}`;
68
69
  }
69
70
 
71
+ /** 从 canonical Session Message 提取 Memory digest 文本。 */
72
+ function extract_session_message_line(message: SessionMessage): string {
73
+ if (message.type !== "user" && message.type !== "assistant") return "";
74
+ const role = message.type === "user" ? "User" : "Assistant";
75
+ const text = message.parts
76
+ .flatMap((part) =>
77
+ part.type === "text" ? [String(part.text || "").trim()] : [],
78
+ )
79
+ .filter(Boolean)
80
+ .join("\n")
81
+ .trim();
82
+ return text ? `${role}: ${text}` : "";
83
+ }
84
+
70
85
  function readDigestPages(result: Awaited<ReturnType<NonNullable<MemoryPluginOptions["digest"]>>>): {
71
86
  pages: Array<{ path?: string; title?: string; content: string; tags?: string[] }>;
72
87
  summary?: string;
@@ -267,12 +282,12 @@ export async function digestMemoryAction(
267
282
  const maxMessages = Number.isFinite(payload.maxMessages)
268
283
  ? Math.max(1, Math.floor(payload.maxMessages as number))
269
284
  : 30;
270
- const historyStore = context.session.get(sessionId).getHistoryStore();
271
- const total = await historyStore.record_count();
285
+ const snapshot = await context.sessions.runtime(sessionId).context();
286
+ const total = snapshot.messages.length;
272
287
  const start = Math.max(0, total - maxMessages);
273
- const messages = await historyStore.slice_records(start, total);
288
+ const messages = snapshot.messages.slice(start);
274
289
  const lines = messages
275
- .map((msg) => extractReadableLine(msg))
290
+ .map((message) => extract_session_message_line(message))
276
291
  .filter((line) => line.length > 0);
277
292
  const transcript =
278
293
  lines.length > 0
@@ -143,33 +143,6 @@ export async function listMemorySourceFiles(
143
143
  );
144
144
  }
145
145
 
146
- const sessionRootDir = path.join(rootPath, ".downcity", "session");
147
- let sessions: Dirent[] = [];
148
- try {
149
- sessions = await fsp.readdir(sessionRootDir, { withFileTypes: true });
150
- } catch {
151
- sessions = [];
152
- }
153
- for (const sessionDir of sessions) {
154
- if (!sessionDir.isDirectory() || sessionDir.isSymbolicLink()) {
155
- continue;
156
- }
157
- const workingPath = path.join(
158
- sessionRootDir,
159
- sessionDir.name,
160
- "memory",
161
- "working.md",
162
- );
163
- if (!(await pathExists(workingPath))) {
164
- continue;
165
- }
166
- out.push({
167
- source: "working",
168
- absPath: workingPath,
169
- relPath: normalizeRelPath(rootPath, workingPath),
170
- });
171
- }
172
-
173
146
  return out;
174
147
  }
175
148
 
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - `sources/` 保存原始证据,`wiki/` 保存整理后的长期记忆。
6
- * - 所有外部传入路径都必须限制在 `.downcity/memory` 或 session working memory 内。
6
+ * - 所有外部传入路径都必须限制在 Memory Plugin 自己的 `.downcity/memory` 目录内。
7
7
  * - 无 LLM 注入时使用 append fallback,保证 MemoryPlugin 仍然可用。
8
8
  */
9
9
 
@@ -83,11 +83,8 @@ function resolveAllowedReadPath(context: AgentContext, relPath: string): string
83
83
  }
84
84
  const absPath = path.resolve(context.rootPath, normalized);
85
85
  const memoryRoot = path.resolve(path.join(context.rootPath, ".downcity", "memory"));
86
- const sessionRoot = path.resolve(context.paths.getDowncitySessionRootDirPath());
87
86
  const isMemoryPath = isWithin(memoryRoot, absPath);
88
- const isWorkingPath =
89
- isWithin(sessionRoot, absPath) && normalized.endsWith("/memory/working.md");
90
- if (!isMemoryPath && !isWorkingPath) {
87
+ if (!isMemoryPath) {
91
88
  throw new Error("path is not allowed");
92
89
  }
93
90
  if (!normalized.toLowerCase().endsWith(".md")) {
@@ -1,15 +1,12 @@
1
1
  /**
2
- * `downcity skill` 命令 helper。
2
+ * Skill 安装命令 helper。
3
3
  *
4
4
  * 设计目标(中文)
5
- * - 尽量不自建 registry:直接复用社区的 `npx skills` 生态(find/install)。
6
- * - 同时提供本地视角的 `list`:按 SkillPlugin 默认构造参数列出当前项目 skills。
5
+ * - 不自建 registry,直接复用社区的 `npx skills` 安装生态。
6
+ * - 当前 helper 由需要准备 skill 依赖的其他 plugin 复用,不作为 SkillPlugin action 暴露。
7
7
  */
8
8
 
9
- import path from "node:path";
10
9
  import { execa } from "execa";
11
- import { discoverSkillsSync } from "@/skill/runtime/Discovery.js";
12
- import { getSkillSearchRoots } from "@/skill/runtime/Paths.js";
13
10
 
14
11
  async function runNpxSkills(args: string[], opts?: { yes?: boolean }): Promise<number> {
15
12
  const yes = opts?.yes !== false;
@@ -19,15 +16,6 @@ async function runNpxSkills(args: string[], opts?: { yes?: boolean }): Promise<n
19
16
  return result.exitCode ?? 0;
20
17
  }
21
18
 
22
- /**
23
- * 执行远程 skill 查找。
24
- */
25
- export async function skillFindCommand(query: string): Promise<void> {
26
- const q = String(query || "").trim();
27
- if (!q) throw new Error("Missing query");
28
- await runNpxSkills(["find", q], { yes: true });
29
- }
30
-
31
19
  /**
32
20
  * skill 安装选项。
33
21
  */
@@ -68,21 +56,3 @@ export async function skillInstallCommand(
68
56
 
69
57
  await runNpxSkills(args, { yes });
70
58
  }
71
-
72
- /**
73
- * 输出当前项目的本地 skill 列表。
74
- */
75
- export async function skillListCommand(cwd: string = "."): Promise<void> {
76
- const projectRoot = path.resolve(String(cwd || "."));
77
- const roots = getSkillSearchRoots(projectRoot);
78
- const skills = discoverSkillsSync(projectRoot);
79
-
80
- console.log("Skill roots:");
81
- for (const root of roots) console.log(`- [${root.source}] ${root.display}`);
82
-
83
- console.log(`\nFound: ${skills.length}`);
84
- for (const skill of skills) {
85
- const desc = skill.description ? ` — ${skill.description}` : "";
86
- console.log(`- [${skill.source}] ${skill.id}: ${skill.name}${desc}`);
87
- }
88
- }
@@ -4,6 +4,6 @@
4
4
  */
5
5
 
6
6
  // Source: src/skill/PROMPT.ts.txt
7
- const TEXT_MODULE_CONTENT = "# Skill Plugin\n\nSkills are capabilities available to you. For every user request or task, first consider whether a relevant skill can help you complete it with higher quality.\n\n## Usage\n\nBefore using a skill, load its content through the `skill` plugin's `lookup` action.\n\nIf `plugin_call` is available, use:\n\n```ts\nplugin_call({\n plugin: \"skill\",\n action: \"lookup\",\n payload: {\n name: \"<skill-name>\",\n },\n});\n```\n\nAvailable actions include `list`, `find`, `install`, and `lookup`.\n";
7
+ const TEXT_MODULE_CONTENT = "# Skill Plugin\n\nSkills are capabilities available to you. For every user request or task, first consider whether a relevant skill can help you complete it with higher quality.\n\n## Usage\n\nBefore using a skill, load its content through the `skill` plugin's `lookup` action.\n\nIf `plugin_call` is available, use:\n\n```ts\nplugin_call({\n plugin: \"skill\",\n action: \"lookup\",\n payload: {\n name: \"<skill-name>\",\n },\n});\n```\n\nAvailable actions are `find`, `install`, `list`, and `lookup`.\n\n`find` and `install` are instruction-only actions. They return the Shell steps the agent should take, but never execute commands, access the network, install a skill, or change files themselves. The `install` instructions are generated from this SkillPlugin instance's configured scan roots.\n\nThe returned installation prompt tells the agent to call `list` after running the Shell command. This is workflow guidance, not code-level enforcement. If the installed skill appears in `list`, call `lookup` before using it.\n";
8
8
 
9
9
  export default TEXT_MODULE_CONTENT;
@@ -18,4 +18,8 @@ plugin_call({
18
18
  });
19
19
  ```
20
20
 
21
- Available actions include `list`, `find`, `install`, and `lookup`.
21
+ Available actions are `find`, `install`, `list`, and `lookup`.
22
+
23
+ `find` and `install` are instruction-only actions. They return the Shell steps the agent should take, but never execute commands, access the network, install a skill, or change files themselves. The `install` instructions are generated from this SkillPlugin instance's configured scan roots.
24
+
25
+ The returned installation prompt tells the agent to call `list` after running the Shell command. This is workflow guidance, not code-level enforcement. If the installed skill appears in `list`, call `lookup` before using it.