@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
@@ -1,178 +0,0 @@
1
- /**
2
- * WebPlugin 安装器。
3
- *
4
- * 关键点(中文)
5
- * - install 只负责准备联网相关 skill / CLI 依赖,不写 provider 配置。
6
- * - skill 安装复用 SkillPlugin 的 `npx skills` 通道,避免 web 自建 registry。
7
- * - agent-browser 额外准备 npm CLI 包,因为其 skill 需要 `agent-browser` 命令可用。
8
- */
9
- import { execa } from "execa";
10
- import fs from "node:fs";
11
- import path from "node:path";
12
- import { skillInstallCommand } from "../../skill/Command.js";
13
- /**
14
- * 读取字符串字段。
15
- */
16
- function read_string(value) {
17
- if (typeof value !== "string")
18
- return undefined;
19
- const trimmed = value.trim();
20
- return trimmed || undefined;
21
- }
22
- /**
23
- * 读取布尔字段。
24
- */
25
- function read_boolean(value) {
26
- return typeof value === "boolean" ? value : undefined;
27
- }
28
- /**
29
- * 归一化安装目标。
30
- */
31
- function resolve_install_target(value) {
32
- const target = read_string(value);
33
- if (target === "web-access" || target === "agent-browser" || target === "all") {
34
- return target;
35
- }
36
- return "web-access";
37
- }
38
- /**
39
- * 归一化安装作用域。
40
- */
41
- function resolve_install_scope(value) {
42
- const scope = read_string(value);
43
- return scope === "project" ? "project" : "user";
44
- }
45
- /**
46
- * 判断命令是否已经可用。
47
- */
48
- async function command_exists(command) {
49
- try {
50
- const result = await execa(command, ["--help"], {
51
- reject: false,
52
- timeout: 15_000,
53
- });
54
- return (result.exitCode ?? 1) === 0;
55
- }
56
- catch {
57
- return false;
58
- }
59
- }
60
- /**
61
- * 执行 npm 包安装。
62
- */
63
- async function install_npm_package(params) {
64
- if (params.scope === "project") {
65
- const package_manager = resolve_project_package_manager(params.root_path);
66
- const args = package_manager === "pnpm"
67
- ? ["add", "-D", params.package_name]
68
- : package_manager === "yarn"
69
- ? ["add", "-D", params.package_name]
70
- : ["install", "--save-dev", params.package_name];
71
- await execa(package_manager, args, {
72
- cwd: params.root_path,
73
- stdio: "inherit",
74
- });
75
- return;
76
- }
77
- await execa("npm", ["install", "-g", params.package_name], {
78
- stdio: "inherit",
79
- });
80
- }
81
- /**
82
- * 根据锁文件推断项目包管理器。
83
- */
84
- function resolve_project_package_manager(root_path) {
85
- if (fs.existsSync(path.join(root_path, "pnpm-lock.yaml")))
86
- return "pnpm";
87
- if (fs.existsSync(path.join(root_path, "yarn.lock")))
88
- return "yarn";
89
- return "npm";
90
- }
91
- /**
92
- * 将步骤列表转成 JSON。
93
- */
94
- function serialize_steps(steps) {
95
- return steps.map((step) => ({
96
- name: step.name,
97
- success: step.success,
98
- message: step.message,
99
- }));
100
- }
101
- /**
102
- * 安装 skill。
103
- */
104
- async function install_skill(params) {
105
- await skillInstallCommand(params.spec, {
106
- global: params.scope === "user",
107
- yes: params.yes,
108
- agent: params.agent,
109
- });
110
- params.steps.push({
111
- name: `${params.spec}:skill`,
112
- success: true,
113
- message: params.scope === "user"
114
- ? `Installed ${params.spec} skill in user scope.`
115
- : `Installed ${params.spec} skill in project scope.`,
116
- });
117
- }
118
- /**
119
- * 准备 agent-browser CLI。
120
- */
121
- async function install_agent_browser_cli(params) {
122
- if (await command_exists("agent-browser")) {
123
- params.steps.push({
124
- name: "agent-browser:cli",
125
- success: true,
126
- message: "agent-browser CLI is already available.",
127
- });
128
- return;
129
- }
130
- await install_npm_package({
131
- root_path: params.context.rootPath,
132
- package_name: "agent-browser",
133
- scope: params.scope,
134
- });
135
- params.steps.push({
136
- name: "agent-browser:cli",
137
- success: true,
138
- message: params.scope === "user"
139
- ? "Installed agent-browser CLI globally with npm."
140
- : "Installed agent-browser as a project devDependency.",
141
- });
142
- }
143
- /**
144
- * 执行 WebPlugin install action。
145
- */
146
- export async function installWebPluginTargets(params) {
147
- const payload = params.payload || {};
148
- const target = resolve_install_target(payload.target);
149
- const scope = resolve_install_scope(payload.scope);
150
- const yes = read_boolean(payload.yes) ?? true;
151
- const agent = read_string(payload.agent);
152
- const targets = target === "all" ? ["web-access", "agent-browser"] : [target];
153
- const steps = [];
154
- for (const item of targets) {
155
- await install_skill({
156
- spec: item,
157
- scope,
158
- yes,
159
- agent,
160
- steps,
161
- });
162
- if (item === "agent-browser") {
163
- await install_agent_browser_cli({
164
- context: params.context,
165
- scope,
166
- steps,
167
- });
168
- }
169
- }
170
- return {
171
- target,
172
- scope,
173
- ...(agent ? { agent } : {}),
174
- steps: serialize_steps(steps),
175
- nextAction: "Use SkillPlugin lookup/list to inspect installed skills, then let the agent choose the concrete web path during task execution.",
176
- };
177
- }
178
- //# sourceMappingURL=Install.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Install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CAAC,CAAC,EAAE,CAAC;QAC3B,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC;QAC7B,UAAU,EACR,iIAAiI;KACpI,CAAC;AACJ,CAAC"}
package/src/asr/Plugin.ts DELETED
@@ -1,322 +0,0 @@
1
- /**
2
- * AsrPlugin:语音转写插件。
3
- *
4
- * 关键点(中文)
5
- * - ASR 能力通过 constructor 注入,推荐传入 `city.ai.asr`。
6
- * - plugin 不负责本地模型、Python 依赖、provider 或项目配置。
7
- * - `auto: true` 时会在 chat 入站阶段自动转写 voice/audio 附件,并把结果写入正文。
8
- */
9
-
10
- import path from "node:path";
11
- import { BasePlugin } from "@downcity/agent";
12
- import { createAction } from "@downcity/agent";
13
- import { z } from "zod";
14
- import type { AgentContext } from "@downcity/agent";
15
- import type {
16
- JsonObject,
17
- JsonValue,
18
- } from "@downcity/agent";
19
- import { CHAT_PLUGIN_POINTS } from "@/chat/runtime/PluginPoints.js";
20
- import type {
21
- ChatInboundAugmentInput,
22
- ChatPluginAttachment,
23
- } from "@/chat/types/ChatPlugin.js";
24
- import type {
25
- AsrPluginInput,
26
- AsrPluginOptions,
27
- AsrPluginResult,
28
- } from "@/asr/types/AsrPlugin.js";
29
-
30
- const DEFAULT_ASR_PLUGIN_NAME = "asr";
31
- const DEFAULT_ASR_PLUGIN_TITLE = "ASR";
32
- const DEFAULT_ASR_PLUGIN_DESCRIPTION =
33
- "Transcribe voice and audio attachments through an injected ASR function.";
34
-
35
- /**
36
- * 判断值是否为普通对象。
37
- */
38
- function to_record(value: unknown): Record<string, unknown> | null {
39
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
40
- return value as Record<string, unknown>;
41
- }
42
-
43
- /**
44
- * XML 文本转义。
45
- */
46
- function escape_xml_text(value: string): string {
47
- return String(value || "")
48
- .replace(/&/g, "&amp;")
49
- .replace(/</g, "&lt;")
50
- .replace(/>/g, "&gt;");
51
- }
52
-
53
- /**
54
- * XML 属性转义。
55
- */
56
- function escape_xml_attr(value: string): string {
57
- return escape_xml_text(value).replace(/"/g, "&quot;");
58
- }
59
-
60
- /**
61
- * 归一化 action payload。
62
- */
63
- function normalize_asr_payload(payload: JsonValue | undefined): AsrPluginInput {
64
- const record = to_record(payload ?? {});
65
- if (!record) {
66
- throw new TypeError("AsrPlugin.transcribe payload must be an object");
67
- }
68
- const audio_path =
69
- typeof record.audio_path === "string"
70
- ? record.audio_path.trim()
71
- : "";
72
- const url = typeof record.url === "string" ? record.url.trim() : "";
73
- const data_url = typeof record.data_url === "string" ? record.data_url.trim() : "";
74
- if (!audio_path && !url && !data_url) {
75
- throw new Error("AsrPlugin.transcribe requires audio_path, url, or data_url");
76
- }
77
- return {
78
- ...(record as AsrPluginInput),
79
- ...(audio_path ? { audio_path } : {}),
80
- ...(url ? { url } : {}),
81
- ...(data_url ? { data_url } : {}),
82
- };
83
- }
84
-
85
- /**
86
- * 校验 ASR 返回结果。
87
- */
88
- function normalize_asr_result(result: AsrPluginResult): AsrPluginResult {
89
- const record = to_record(result);
90
- if (!record || typeof record.text !== "string") {
91
- throw new TypeError("AsrPlugin asr function must return { text: string }");
92
- }
93
- return {
94
- ...record,
95
- text: record.text.trim(),
96
- } as AsrPluginResult;
97
- }
98
-
99
- /**
100
- * 生成相对展示路径。
101
- */
102
- function to_display_src(root_path: string, attachment: ChatPluginAttachment): string {
103
- const raw =
104
- typeof attachment.path === "string" && attachment.path.trim()
105
- ? attachment.path.trim()
106
- : attachment.fileName || attachment.attachmentId || attachment.kind;
107
- const normalized_root = path.resolve(root_path);
108
- const normalized_raw = path.isAbsolute(raw) ? path.resolve(raw) : raw;
109
- if (path.isAbsolute(normalized_raw) && normalized_raw.startsWith(`${normalized_root}${path.sep}`)) {
110
- return normalized_raw.slice(normalized_root.length + 1);
111
- }
112
- return raw;
113
- }
114
-
115
- /**
116
- * 把语音转写结果写入 bodyText。
117
- */
118
- function append_voice_text(input: ChatInboundAugmentInput, voice_blocks: string[]): ChatInboundAugmentInput {
119
- const current = String(input.bodyText || "").trim();
120
- const addition = voice_blocks.map((item) => item.trim()).filter(Boolean).join("\n\n");
121
- if (!addition) return input;
122
- return {
123
- ...input,
124
- bodyText: [current, addition].filter(Boolean).join("\n\n"),
125
- };
126
- }
127
-
128
- /**
129
- * Agent ASR 插件。
130
- */
131
- export class AsrPlugin extends BasePlugin {
132
- /**
133
- * 当前 plugin 稳定名称。
134
- */
135
- readonly name: string;
136
-
137
- /**
138
- * 插件标题。
139
- */
140
- readonly title: string;
141
-
142
- /**
143
- * 插件说明。
144
- */
145
- readonly description: string;
146
-
147
- private readonly asr: AsrPluginOptions["asr"];
148
- private readonly auto: boolean;
149
- private readonly language?: string;
150
-
151
- constructor(options: AsrPluginOptions) {
152
- super();
153
- const name = String(options.name || DEFAULT_ASR_PLUGIN_NAME).trim();
154
- if (!name) {
155
- throw new Error("AsrPlugin requires a non-empty name");
156
- }
157
- if (typeof options.asr !== "function") {
158
- throw new Error("AsrPlugin requires an asr function");
159
- }
160
- this.name = name;
161
- this.title = String(options.title || DEFAULT_ASR_PLUGIN_TITLE).trim();
162
- this.description = String(
163
- options.description || DEFAULT_ASR_PLUGIN_DESCRIPTION,
164
- ).trim();
165
- this.asr = options.asr;
166
- this.auto = options.auto === true;
167
- this.language =
168
- typeof options.language === "string" && options.language.trim()
169
- ? options.language.trim()
170
- : undefined;
171
- }
172
-
173
- /**
174
- * ASR 插件给模型的使用说明。
175
- */
176
- system(_context: AgentContext): string {
177
- return [
178
- "# ASR Plugin",
179
- "",
180
- "Use this plugin when the user asks to transcribe, recognize, or understand voice/audio content.",
181
- this.auto
182
- ? "Inbound voice/audio chat attachments are automatically transcribed into `<voice src=\"...\">...</voice>` blocks in the user text."
183
- : "Automatic inbound voice transcription is disabled; call the plugin explicitly when transcription is needed.",
184
- "",
185
- "Call through `plugin_call`:",
186
- "",
187
- "```ts",
188
- "plugin_call({",
189
- ` plugin: "${this.name}",`,
190
- ' action: "transcribe",',
191
- " payload: {",
192
- ' audio_path: "...",',
193
- " },",
194
- "});",
195
- "```",
196
- "",
197
- "Payload rules:",
198
- "- Provide one of `audio_path`, `url`, or `data_url`.",
199
- "- Optional fields: `language`, `media_type`, `file_name`, `provider_options`.",
200
- "- Do not invent transcript text. If transcription fails, report the failure clearly.",
201
- ].join("\n");
202
- }
203
-
204
- /**
205
- * 执行一次 ASR 转写。
206
- */
207
- private async transcribe(input: AsrPluginInput): Promise<AsrPluginResult> {
208
- const result = await this.asr({
209
- ...(this.language ? { language: this.language } : {}),
210
- ...input,
211
- });
212
- return normalize_asr_result(result);
213
- }
214
-
215
- /**
216
- * 自动增强 chat 入站消息。
217
- */
218
- private async auto_transcribe_inbound(params: {
219
- context: AgentContext;
220
- value: JsonValue;
221
- }): Promise<JsonValue> {
222
- if (!this.auto) return params.value;
223
- const input = params.value as unknown as ChatInboundAugmentInput;
224
- const voice_attachments = (Array.isArray(input.attachments) ? input.attachments : []).filter(
225
- (item) =>
226
- (item.kind === "voice" || item.kind === "audio") &&
227
- typeof item.path === "string" &&
228
- item.path.trim(),
229
- );
230
- if (voice_attachments.length === 0) {
231
- return input as unknown as JsonValue;
232
- }
233
-
234
- const voice_blocks: string[] = [];
235
- for (const attachment of voice_attachments) {
236
- try {
237
- const result = await this.transcribe({
238
- audio_path: String(attachment.path || "").trim(),
239
- ...(attachment.contentType ? { media_type: attachment.contentType } : {}),
240
- ...(attachment.fileName ? { file_name: attachment.fileName } : {}),
241
- });
242
- if (!result.text) continue;
243
- const src = to_display_src(params.context.rootPath, attachment);
244
- voice_blocks.push(
245
- `<voice src="${escape_xml_attr(src)}">${escape_xml_text(result.text)}</voice>`,
246
- );
247
- } catch {
248
- // 关键点(中文):自动转写失败不阻塞主消息链路。
249
- }
250
- }
251
-
252
- return append_voice_text(input, voice_blocks) as unknown as JsonValue;
253
- }
254
-
255
- /**
256
- * pipeline / action 扩展点。
257
- */
258
- readonly hooks = {
259
- pipeline: {
260
- [CHAT_PLUGIN_POINTS.augmentInbound]: [
261
- async ({ context, value }: { context: AgentContext; value: JsonValue }) => {
262
- return await this.auto_transcribe_inbound({ context, value });
263
- },
264
- ],
265
- },
266
- };
267
-
268
- /**
269
- * 显式 action 集合。
270
- */
271
- readonly actions = {
272
- transcribe: createAction({
273
- description:
274
- "Transcribe a voice or audio source into text. Provide one of audio_path / url / data_url.",
275
- input_schema: {
276
- zod: z
277
- .object({
278
- audio_path: z.string().optional(),
279
- url: z.string().optional(),
280
- data_url: z.string().optional(),
281
- language: z.string().optional(),
282
- media_type: z.string().optional(),
283
- file_name: z.string().optional(),
284
- provider_options: z.record(z.string(), z.unknown()).optional(),
285
- })
286
- .passthrough(),
287
- json_schema: {
288
- type: "object",
289
- properties: {
290
- audio_path: { type: "string", description: "Absolute or relative local audio path." },
291
- url: { type: "string", description: "Online audio URL." },
292
- data_url: { type: "string", description: "Audio as a data: URL." },
293
- language: { type: "string", description: "Target language code, optional." },
294
- media_type: { type: "string", description: "Media type, optional." },
295
- file_name: { type: "string", description: "File name, optional." },
296
- },
297
- },
298
- },
299
- examples: [
300
- { title: "Local audio", payload: { audio_path: "./input.wav" } },
301
- { title: "Remote URL", payload: { url: "https://example.com/a.mp3" } },
302
- ],
303
- execute: async ({ input }: { input: JsonValue }) => {
304
- try {
305
- const transcribe_input = normalize_asr_payload(input);
306
- const result = await this.transcribe(transcribe_input);
307
- return {
308
- success: true,
309
- data: result as unknown as JsonObject,
310
- message: "audio transcribed",
311
- };
312
- } catch (error) {
313
- return {
314
- success: false,
315
- error: String(error),
316
- message: String(error),
317
- };
318
- }
319
- },
320
- }),
321
- };
322
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * AsrPlugin 类型定义。
3
- *
4
- * 关键点(中文)
5
- * - ASR plugin 只定义 agent 侧协议,不绑定本地模型、Python 或 City 具体实现。
6
- * - 真实转写能力通过 constructor 的 `asr` 函数注入,推荐传入 `city.ai.asr`。
7
- * - `auto` 只表示是否在 chat 入站时自动转写语音附件。
8
- */
9
-
10
- import type { JsonObject, JsonValue } from "@downcity/agent";
11
-
12
- /**
13
- * ASR 输入。
14
- */
15
- export interface AsrPluginInput {
16
- /**
17
- * 本地音频文件路径。
18
- *
19
- * 说明(中文)
20
- * - chat runtime 下载附件后会传入本地路径。
21
- * - 显式 action 调用时也优先使用该字段。
22
- */
23
- audio_path?: string;
24
- /**
25
- * 远程音频 URL。
26
- */
27
- url?: string;
28
- /**
29
- * data URL 音频内容。
30
- */
31
- data_url?: string;
32
- /**
33
- * 语言提示,例如 `auto`、`zh`、`en`。
34
- */
35
- language?: string;
36
- /**
37
- * 音频 MIME 类型,例如 `audio/ogg`。
38
- */
39
- media_type?: string;
40
- /**
41
- * 原始文件名。
42
- */
43
- file_name?: string;
44
- /**
45
- * Provider 私有参数。
46
- */
47
- provider_options?: JsonObject;
48
- /**
49
- * 允许外部 asr 函数接收其他 JSON 可序列化参数。
50
- */
51
- [key: string]: JsonValue | undefined;
52
- }
53
-
54
- /**
55
- * ASR 输出。
56
- */
57
- export interface AsrPluginResult {
58
- /**
59
- * 转写文本。
60
- */
61
- text: string;
62
- /**
63
- * 识别到的语言(可选)。
64
- */
65
- language?: string;
66
- /**
67
- * 结果置信度(可选)。
68
- */
69
- confidence?: number;
70
- /**
71
- * Provider 原始元信息(可选)。
72
- */
73
- metadata?: JsonObject;
74
- /**
75
- * 允许外部 asr 函数返回其他 JSON 可序列化字段。
76
- */
77
- [key: string]: JsonValue | undefined;
78
- }
79
-
80
- /**
81
- * AsrPlugin 构造参数。
82
- */
83
- export interface AsrPluginOptions {
84
- /**
85
- * Plugin 稳定名称,默认 `asr`。
86
- */
87
- name?: string;
88
- /**
89
- * Plugin 展示标题,默认 `ASR`。
90
- */
91
- title?: string;
92
- /**
93
- * Plugin 用途说明。
94
- */
95
- description?: string;
96
- /**
97
- * 真实 ASR 能力函数。
98
- *
99
- * 说明(中文)
100
- * - 推荐传入 `(input) => city.ai.asr(input)`。
101
- * - plugin 只负责调用该函数,不关心模型、provider、鉴权或运行依赖。
102
- */
103
- asr: (input: AsrPluginInput) => Promise<AsrPluginResult> | AsrPluginResult;
104
- /**
105
- * 是否自动转写 chat 入站语音附件。
106
- *
107
- * 说明(中文)
108
- * - `true`:遇到 voice/audio 附件时自动调用 `asr`。
109
- * - `false`:仅保留显式 `transcribe` action。
110
- * - 默认 `false`,避免 agent 隐式调用外部 ASR 成本。
111
- */
112
- auto?: boolean;
113
- /**
114
- * 默认语言提示。
115
- */
116
- language?: string;
117
- }
118
-