@downcity/plugins 1.0.56 → 1.0.59

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 (318) hide show
  1. package/bin/BuiltinPlugins.d.ts.map +1 -1
  2. package/bin/BuiltinPlugins.js +0 -6
  3. package/bin/BuiltinPlugins.js.map +1 -1
  4. package/bin/asr/Plugin.d.ts +67 -7
  5. package/bin/asr/Plugin.d.ts.map +1 -1
  6. package/bin/asr/Plugin.js +229 -461
  7. package/bin/asr/Plugin.js.map +1 -1
  8. package/bin/asr/types/AsrPlugin.d.ts +114 -0
  9. package/bin/asr/types/AsrPlugin.d.ts.map +1 -0
  10. package/bin/asr/types/AsrPlugin.js +10 -0
  11. package/bin/asr/types/AsrPlugin.js.map +1 -0
  12. package/bin/auth/types/AuthPlugin.d.ts +12 -16
  13. package/bin/auth/types/AuthPlugin.d.ts.map +1 -1
  14. package/bin/auth/types/AuthPlugin.js +9 -13
  15. package/bin/auth/types/AuthPlugin.js.map +1 -1
  16. package/bin/chat/ChatPlugin.d.ts +37 -6
  17. package/bin/chat/ChatPlugin.d.ts.map +1 -1
  18. package/bin/chat/ChatPlugin.js +58 -80
  19. package/bin/chat/ChatPlugin.js.map +1 -1
  20. package/bin/chat/Index.d.ts +4 -1
  21. package/bin/chat/Index.d.ts.map +1 -1
  22. package/bin/chat/Index.js +2 -1
  23. package/bin/chat/Index.js.map +1 -1
  24. package/bin/chat/channels/Configuration.d.ts +1 -1
  25. package/bin/chat/channels/Configuration.js +1 -1
  26. package/bin/chat/channels/RuntimeChannel.d.ts +145 -0
  27. package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -0
  28. package/bin/chat/channels/RuntimeChannel.js +148 -0
  29. package/bin/chat/channels/RuntimeChannel.js.map +1 -0
  30. package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts +22 -0
  31. package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts.map +1 -0
  32. package/bin/chat/runtime/ChatAuthorizationRuntime.js +189 -0
  33. package/bin/chat/runtime/ChatAuthorizationRuntime.js.map +1 -0
  34. package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
  35. package/bin/chat/runtime/ChatChannelActions.js +19 -9
  36. package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
  37. package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -18
  38. package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
  39. package/bin/chat/runtime/ChatChannelConfig.js +2 -73
  40. package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
  41. package/bin/chat/runtime/ChatChannelCore.d.ts +22 -1
  42. package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
  43. package/bin/chat/runtime/ChatChannelCore.js +5 -5
  44. package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
  45. package/bin/chat/runtime/ChatPluginActionRegistry.js +1 -1
  46. package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
  47. package/bin/chat/runtime/PluginPoints.d.ts +3 -3
  48. package/bin/chat/runtime/PluginPoints.js +3 -3
  49. package/bin/chat/types/ChannelStatus.d.ts +1 -1
  50. package/bin/chat/types/ChatPluginOptions.d.ts +76 -0
  51. package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -0
  52. package/bin/chat/types/ChatPluginOptions.js +10 -0
  53. package/bin/chat/types/ChatPluginOptions.js.map +1 -0
  54. package/bin/image/ImagePlugin.d.ts +1 -1
  55. package/bin/image/ImagePlugin.d.ts.map +1 -1
  56. package/bin/image/ImagePlugin.js +23 -5
  57. package/bin/image/ImagePlugin.js.map +1 -1
  58. package/bin/index.d.ts +6 -3
  59. package/bin/index.d.ts.map +1 -1
  60. package/bin/index.js +2 -2
  61. package/bin/index.js.map +1 -1
  62. package/bin/skill/Action.d.ts.map +1 -1
  63. package/bin/skill/Action.js +2 -2
  64. package/bin/skill/Action.js.map +1 -1
  65. package/bin/skill/Command.js +5 -5
  66. package/bin/skill/Command.js.map +1 -1
  67. package/bin/skill/Plugin.js +1 -1
  68. package/bin/skill/Plugin.js.map +1 -1
  69. package/bin/skill/runtime/Discovery.d.ts +4 -4
  70. package/bin/skill/runtime/Discovery.d.ts.map +1 -1
  71. package/bin/skill/runtime/Discovery.js +5 -5
  72. package/bin/skill/runtime/Discovery.js.map +1 -1
  73. package/bin/skill/runtime/Paths.d.ts +1 -5
  74. package/bin/skill/runtime/Paths.d.ts.map +1 -1
  75. package/bin/skill/runtime/Paths.js +1 -9
  76. package/bin/skill/runtime/Paths.js.map +1 -1
  77. package/bin/skill/runtime/Prompt.d.ts +2 -2
  78. package/bin/skill/runtime/Prompt.d.ts.map +1 -1
  79. package/bin/skill/runtime/Prompt.js +3 -3
  80. package/bin/skill/runtime/Prompt.js.map +1 -1
  81. package/bin/skill/runtime/Store.d.ts +2 -2
  82. package/bin/skill/runtime/Store.d.ts.map +1 -1
  83. package/bin/skill/runtime/Store.js.map +1 -1
  84. package/bin/skill/runtime/SystemProvider.js +4 -4
  85. package/bin/skill/runtime/SystemProvider.js.map +1 -1
  86. package/bin/skill/runtime/Types.d.ts +3 -3
  87. package/bin/skill/runtime/Types.d.ts.map +1 -1
  88. package/bin/skill/types/{ClaudeSkill.d.ts → SkillDefinition.d.ts} +4 -4
  89. package/bin/skill/types/SkillDefinition.d.ts.map +1 -0
  90. package/bin/skill/types/{ClaudeSkill.js → SkillDefinition.js} +2 -2
  91. package/bin/skill/types/SkillDefinition.js.map +1 -0
  92. package/bin/skill/types/SkillPlugin.d.ts +2 -2
  93. package/bin/skill/types/SkillPlugin.d.ts.map +1 -1
  94. package/bin/tts/Plugin.d.ts +53 -6
  95. package/bin/tts/Plugin.d.ts.map +1 -1
  96. package/bin/tts/Plugin.js +197 -474
  97. package/bin/tts/Plugin.js.map +1 -1
  98. package/bin/tts/types/TtsPlugin.d.ts +63 -102
  99. package/bin/tts/types/TtsPlugin.d.ts.map +1 -1
  100. package/bin/tts/types/TtsPlugin.js +4 -3
  101. package/bin/tts/types/TtsPlugin.js.map +1 -1
  102. package/bin/web/PROMPT.d.ts +1 -1
  103. package/bin/web/PROMPT.d.ts.map +1 -1
  104. package/bin/web/PROMPT.js +1 -1
  105. package/bin/web/PROMPT.js.map +1 -1
  106. package/bin/web/Plugin.d.ts +66 -5
  107. package/bin/web/Plugin.d.ts.map +1 -1
  108. package/bin/web/Plugin.js +126 -450
  109. package/bin/web/Plugin.js.map +1 -1
  110. package/bin/web/WebPromptAssets.d.ts +1 -9
  111. package/bin/web/WebPromptAssets.d.ts.map +1 -1
  112. package/bin/web/WebPromptAssets.js +1 -11
  113. package/bin/web/WebPromptAssets.js.map +1 -1
  114. package/bin/web/runtime/Install.d.ts +19 -0
  115. package/bin/web/runtime/Install.d.ts.map +1 -0
  116. package/bin/web/runtime/Install.js +178 -0
  117. package/bin/web/runtime/Install.js.map +1 -0
  118. package/bin/web/types/WebPlugin.d.ts +38 -109
  119. package/bin/web/types/WebPlugin.d.ts.map +1 -1
  120. package/bin/web/types/WebPlugin.js +5 -7
  121. package/bin/web/types/WebPlugin.js.map +1 -1
  122. package/bin/workboard/Plugin.d.ts +23 -3
  123. package/bin/workboard/Plugin.d.ts.map +1 -1
  124. package/bin/workboard/Plugin.js +66 -85
  125. package/bin/workboard/Plugin.js.map +1 -1
  126. package/package.json +2 -2
  127. package/src/BuiltinPlugins.ts +0 -6
  128. package/src/asr/Plugin.ts +264 -483
  129. package/src/asr/types/AsrPlugin.ts +118 -0
  130. package/src/auth/types/AuthPlugin.ts +12 -17
  131. package/src/chat/ChatPlugin.ts +92 -89
  132. package/src/chat/Index.ts +18 -1
  133. package/src/chat/channels/Configuration.ts +1 -1
  134. package/src/chat/channels/RuntimeChannel.ts +264 -0
  135. package/src/chat/runtime/ChatAuthorizationRuntime.ts +229 -0
  136. package/src/chat/runtime/ChatChannelActions.ts +24 -9
  137. package/src/chat/runtime/ChatChannelConfig.ts +2 -100
  138. package/src/chat/runtime/ChatChannelCore.ts +20 -8
  139. package/src/chat/runtime/ChatPluginActionRegistry.ts +1 -1
  140. package/src/chat/runtime/PluginPoints.ts +3 -3
  141. package/src/chat/types/ChannelStatus.ts +1 -1
  142. package/src/chat/types/ChatPluginOptions.ts +79 -0
  143. package/src/image/ImagePlugin.ts +23 -5
  144. package/src/index.ts +29 -6
  145. package/src/skill/Action.ts +10 -7
  146. package/src/skill/Command.ts +5 -5
  147. package/src/skill/Plugin.ts +1 -1
  148. package/src/skill/runtime/Discovery.ts +14 -11
  149. package/src/skill/runtime/Paths.ts +1 -13
  150. package/src/skill/runtime/Prompt.ts +5 -5
  151. package/src/skill/runtime/Store.ts +6 -3
  152. package/src/skill/runtime/SystemProvider.ts +4 -4
  153. package/src/skill/runtime/Types.ts +3 -3
  154. package/src/skill/types/{ClaudeSkill.ts → SkillDefinition.ts} +3 -3
  155. package/src/skill/types/SkillPlugin.ts +2 -2
  156. package/src/tts/Plugin.ts +225 -492
  157. package/src/tts/types/TtsPlugin.ts +67 -102
  158. package/src/web/PROMPT.ts +1 -1
  159. package/src/web/PROMPT.ts.txt +32 -6
  160. package/src/web/Plugin.ts +119 -453
  161. package/src/web/WebPromptAssets.ts +1 -13
  162. package/src/web/runtime/Install.ts +241 -0
  163. package/src/web/types/WebPlugin.ts +38 -114
  164. package/src/workboard/Plugin.ts +80 -95
  165. package/bin/asr/Config.d.ts +0 -43
  166. package/bin/asr/Config.d.ts.map +0 -1
  167. package/bin/asr/Config.js +0 -107
  168. package/bin/asr/Config.js.map +0 -1
  169. package/bin/asr/Dependency.d.ts +0 -77
  170. package/bin/asr/Dependency.d.ts.map +0 -1
  171. package/bin/asr/Dependency.js +0 -238
  172. package/bin/asr/Dependency.js.map +0 -1
  173. package/bin/asr/InboundAugment.d.ts +0 -17
  174. package/bin/asr/InboundAugment.d.ts.map +0 -1
  175. package/bin/asr/InboundAugment.js +0 -47
  176. package/bin/asr/InboundAugment.js.map +0 -1
  177. package/bin/asr/ModelCatalog.d.ts +0 -29
  178. package/bin/asr/ModelCatalog.d.ts.map +0 -1
  179. package/bin/asr/ModelCatalog.js +0 -25
  180. package/bin/asr/ModelCatalog.js.map +0 -1
  181. package/bin/auth/Plugin.d.ts +0 -17
  182. package/bin/auth/Plugin.d.ts.map +0 -1
  183. package/bin/auth/Plugin.js +0 -199
  184. package/bin/auth/Plugin.js.map +0 -1
  185. package/bin/chat/ChatPluginTypes.d.ts +0 -122
  186. package/bin/chat/ChatPluginTypes.d.ts.map +0 -1
  187. package/bin/chat/ChatPluginTypes.js +0 -10
  188. package/bin/chat/ChatPluginTypes.js.map +0 -1
  189. package/bin/skill/types/ClaudeSkill.d.ts.map +0 -1
  190. package/bin/skill/types/ClaudeSkill.js.map +0 -1
  191. package/bin/tts/Dependency.d.ts +0 -90
  192. package/bin/tts/Dependency.d.ts.map +0 -1
  193. package/bin/tts/Dependency.js +0 -344
  194. package/bin/tts/Dependency.js.map +0 -1
  195. package/bin/tts/PluginSupport.d.ts +0 -25
  196. package/bin/tts/PluginSupport.d.ts.map +0 -1
  197. package/bin/tts/PluginSupport.js +0 -72
  198. package/bin/tts/PluginSupport.js.map +0 -1
  199. package/bin/tts/runtime/Catalog.d.ts +0 -21
  200. package/bin/tts/runtime/Catalog.d.ts.map +0 -1
  201. package/bin/tts/runtime/Catalog.js +0 -90
  202. package/bin/tts/runtime/Catalog.js.map +0 -1
  203. package/bin/tts/runtime/DependencyInstaller.d.ts +0 -143
  204. package/bin/tts/runtime/DependencyInstaller.d.ts.map +0 -1
  205. package/bin/tts/runtime/DependencyInstaller.js +0 -261
  206. package/bin/tts/runtime/DependencyInstaller.js.map +0 -1
  207. package/bin/tts/runtime/Installer.d.ts +0 -89
  208. package/bin/tts/runtime/Installer.d.ts.map +0 -1
  209. package/bin/tts/runtime/Installer.js +0 -188
  210. package/bin/tts/runtime/Installer.js.map +0 -1
  211. package/bin/tts/runtime/Paths.d.ts +0 -20
  212. package/bin/tts/runtime/Paths.d.ts.map +0 -1
  213. package/bin/tts/runtime/Paths.js +0 -32
  214. package/bin/tts/runtime/Paths.js.map +0 -1
  215. package/bin/tts/runtime/Synthesizer.d.ts +0 -44
  216. package/bin/tts/runtime/Synthesizer.d.ts.map +0 -1
  217. package/bin/tts/runtime/Synthesizer.js +0 -363
  218. package/bin/tts/runtime/Synthesizer.js.map +0 -1
  219. package/bin/tts/types/Tts.d.ts +0 -91
  220. package/bin/tts/types/Tts.d.ts.map +0 -1
  221. package/bin/tts/types/Tts.js +0 -9
  222. package/bin/tts/types/Tts.js.map +0 -1
  223. package/bin/voice/Config.d.ts +0 -43
  224. package/bin/voice/Config.d.ts.map +0 -1
  225. package/bin/voice/Config.js +0 -104
  226. package/bin/voice/Config.js.map +0 -1
  227. package/bin/voice/Dependency.d.ts +0 -77
  228. package/bin/voice/Dependency.d.ts.map +0 -1
  229. package/bin/voice/Dependency.js +0 -237
  230. package/bin/voice/Dependency.js.map +0 -1
  231. package/bin/voice/InboundAugment.d.ts +0 -17
  232. package/bin/voice/InboundAugment.d.ts.map +0 -1
  233. package/bin/voice/InboundAugment.js +0 -47
  234. package/bin/voice/InboundAugment.js.map +0 -1
  235. package/bin/voice/ModelCatalog.d.ts +0 -29
  236. package/bin/voice/ModelCatalog.d.ts.map +0 -1
  237. package/bin/voice/ModelCatalog.js +0 -25
  238. package/bin/voice/ModelCatalog.js.map +0 -1
  239. package/bin/voice/runtime/Catalog.d.ts +0 -18
  240. package/bin/voice/runtime/Catalog.d.ts.map +0 -1
  241. package/bin/voice/runtime/Catalog.js +0 -61
  242. package/bin/voice/runtime/Catalog.js.map +0 -1
  243. package/bin/voice/runtime/DependencyInstaller.d.ts +0 -145
  244. package/bin/voice/runtime/DependencyInstaller.d.ts.map +0 -1
  245. package/bin/voice/runtime/DependencyInstaller.js +0 -309
  246. package/bin/voice/runtime/DependencyInstaller.js.map +0 -1
  247. package/bin/voice/runtime/Installer.d.ts +0 -94
  248. package/bin/voice/runtime/Installer.d.ts.map +0 -1
  249. package/bin/voice/runtime/Installer.js +0 -200
  250. package/bin/voice/runtime/Installer.js.map +0 -1
  251. package/bin/voice/runtime/Paths.d.ts +0 -8
  252. package/bin/voice/runtime/Paths.d.ts.map +0 -1
  253. package/bin/voice/runtime/Paths.js +0 -26
  254. package/bin/voice/runtime/Paths.js.map +0 -1
  255. package/bin/voice/runtime/Transcriber.d.ts +0 -57
  256. package/bin/voice/runtime/Transcriber.d.ts.map +0 -1
  257. package/bin/voice/runtime/Transcriber.js +0 -329
  258. package/bin/voice/runtime/Transcriber.js.map +0 -1
  259. package/bin/voice/types/Voice.d.ts +0 -58
  260. package/bin/voice/types/Voice.d.ts.map +0 -1
  261. package/bin/voice/types/Voice.js +0 -9
  262. package/bin/voice/types/Voice.js.map +0 -1
  263. package/bin/voice/types/VoicePlugin.d.ts +0 -190
  264. package/bin/voice/types/VoicePlugin.d.ts.map +0 -1
  265. package/bin/voice/types/VoicePlugin.js +0 -9
  266. package/bin/voice/types/VoicePlugin.js.map +0 -1
  267. package/bin/web/Dependency.d.ts +0 -10
  268. package/bin/web/Dependency.d.ts.map +0 -1
  269. package/bin/web/Dependency.js +0 -10
  270. package/bin/web/Dependency.js.map +0 -1
  271. package/bin/web/PROMPT.agent-browser.d.ts +0 -7
  272. package/bin/web/PROMPT.agent-browser.d.ts.map +0 -1
  273. package/bin/web/PROMPT.agent-browser.js +0 -8
  274. package/bin/web/PROMPT.agent-browser.js.map +0 -1
  275. package/bin/web/PROMPT.web-access.d.ts +0 -7
  276. package/bin/web/PROMPT.web-access.d.ts.map +0 -1
  277. package/bin/web/PROMPT.web-access.js +0 -8
  278. package/bin/web/PROMPT.web-access.js.map +0 -1
  279. package/bin/web/runtime/Config.d.ts +0 -21
  280. package/bin/web/runtime/Config.d.ts.map +0 -1
  281. package/bin/web/runtime/Config.js +0 -79
  282. package/bin/web/runtime/Config.js.map +0 -1
  283. package/bin/web/runtime/Source.d.ts +0 -29
  284. package/bin/web/runtime/Source.d.ts.map +0 -1
  285. package/bin/web/runtime/Source.js +0 -209
  286. package/bin/web/runtime/Source.js.map +0 -1
  287. package/src/asr/Config.ts +0 -138
  288. package/src/asr/Dependency.ts +0 -336
  289. package/src/asr/InboundAugment.ts +0 -59
  290. package/src/asr/ModelCatalog.ts +0 -43
  291. package/src/auth/Plugin.ts +0 -237
  292. package/src/chat/ChatPluginTypes.ts +0 -126
  293. package/src/tts/Dependency.ts +0 -473
  294. package/src/tts/PluginSupport.ts +0 -85
  295. package/src/tts/runtime/Catalog.ts +0 -97
  296. package/src/tts/runtime/DependencyInstaller.ts +0 -436
  297. package/src/tts/runtime/Installer.ts +0 -297
  298. package/src/tts/runtime/Paths.ts +0 -39
  299. package/src/tts/runtime/Synthesizer.ts +0 -480
  300. package/src/tts/types/Tts.ts +0 -99
  301. package/src/voice/Config.ts +0 -135
  302. package/src/voice/Dependency.ts +0 -329
  303. package/src/voice/InboundAugment.ts +0 -59
  304. package/src/voice/ModelCatalog.ts +0 -43
  305. package/src/voice/runtime/Catalog.ts +0 -68
  306. package/src/voice/runtime/DependencyInstaller.ts +0 -505
  307. package/src/voice/runtime/Installer.ts +0 -324
  308. package/src/voice/runtime/Paths.ts +0 -26
  309. package/src/voice/runtime/Transcriber.ts +0 -467
  310. package/src/voice/types/Voice.ts +0 -68
  311. package/src/voice/types/VoicePlugin.ts +0 -194
  312. package/src/web/Dependency.ts +0 -17
  313. package/src/web/PROMPT.agent-browser.ts +0 -9
  314. package/src/web/PROMPT.agent-browser.ts.txt +0 -17
  315. package/src/web/PROMPT.web-access.ts +0 -9
  316. package/src/web/PROMPT.web-access.ts.txt +0 -13
  317. package/src/web/runtime/Config.ts +0 -105
  318. package/src/web/runtime/Source.ts +0 -257
@@ -1,336 +0,0 @@
1
- /**
2
- * ASR Plugin Dependency Helper。
3
- *
4
- * 关键点(中文)
5
- * - ASR 的转写依赖现在内聚在 plugin 内部,不再暴露独立依赖端口心智。
6
- * - 这里统一管理检查、安装、配置读写与转写句柄解析。
7
- */
8
-
9
- import { execFile as execFileCb } from "node:child_process";
10
- import { promisify } from "node:util";
11
- import type { JsonObject, JsonValue } from "@downcity/agent/internal/types/common/Json.js";
12
- import type { PluginCommandContext } from "@downcity/agent/internal/plugin/types/Plugin.js";
13
- import type {
14
- VoicePluginConfig,
15
- VoiceTranscriberConfig,
16
- VoiceTranscriberInstallInput,
17
- VoiceTranscriberHandle,
18
- } from "@/voice/types/VoicePlugin.js";
19
- import { transcribeVoiceAudio } from "@/voice/runtime/Transcriber.js";
20
- import {
21
- VOICE_MODEL_CATALOG,
22
- resolveVoiceModelId,
23
- } from "@/voice/runtime/Catalog.js";
24
- import {
25
- detectLocalVoiceModelInstallState,
26
- installVoiceModelFromHuggingFace,
27
- } from "@/voice/runtime/Installer.js";
28
- import {
29
- installVoiceTranscribeDependencies,
30
- resolveVoiceRunnersByModels,
31
- resolveVoiceStrategyByModel,
32
- } from "@/voice/runtime/DependencyInstaller.js";
33
- import { resolveVoiceModelsRootDir } from "@/voice/runtime/Paths.js";
34
- import type { VoiceModelId } from "@/voice/types/Voice.js";
35
-
36
- const execFileAsync = promisify(execFileCb);
37
-
38
- export interface VoiceDependencyCheckResult {
39
- /**
40
- * 当前依赖是否可用。
41
- */
42
- available: boolean;
43
- /**
44
- * 不可用原因列表。
45
- */
46
- reasons: string[];
47
- /**
48
- * 结构化附加数据(可选)。
49
- */
50
- details?: JsonValue;
51
- }
52
-
53
- export interface VoiceDependencyInstallResult {
54
- /**
55
- * 安装是否成功。
56
- */
57
- success: boolean;
58
- /**
59
- * 人类可读消息(可选)。
60
- */
61
- message?: string;
62
- /**
63
- * 结构化附加数据(可选)。
64
- */
65
- details?: JsonValue;
66
- }
67
-
68
- function readVoicePluginRecord(context: PluginCommandContext): Record<string, unknown> {
69
- const current = context.config.plugins?.asr;
70
- if (!current || typeof current !== "object" || Array.isArray(current)) {
71
- return {};
72
- }
73
- return current as Record<string, unknown>;
74
- }
75
-
76
- function toJsonObject(input: Record<string, unknown> | null | undefined): JsonObject {
77
- const out: JsonObject = {};
78
- if (!input) return out;
79
- for (const [key, value] of Object.entries(input)) {
80
- if (value === undefined) continue;
81
- if (
82
- value === null ||
83
- typeof value === "string" ||
84
- typeof value === "number" ||
85
- typeof value === "boolean"
86
- ) {
87
- out[key] = value;
88
- continue;
89
- }
90
- if (Array.isArray(value)) {
91
- out[key] = value
92
- .filter((item) => item !== undefined)
93
- .map((item) => item as JsonValue);
94
- continue;
95
- }
96
- if (typeof value === "object") {
97
- out[key] = toJsonObject(value as Record<string, unknown>);
98
- }
99
- }
100
- return out;
101
- }
102
-
103
- /**
104
- * 读取 ASR 转写依赖配置。
105
- */
106
- export function readVoiceTranscriberConfig(
107
- context: PluginCommandContext,
108
- ): VoiceTranscriberConfig {
109
- const { enabled: _ignoredEnabled, ...current } = readVoicePluginRecord(
110
- context,
111
- ) as Record<string, unknown> & {
112
- enabled?: boolean;
113
- };
114
- return {
115
- provider: "local",
116
- ...(current as VoiceTranscriberConfig),
117
- };
118
- }
119
-
120
- /**
121
- * 写入 ASR 转写依赖配置。
122
- */
123
- export async function writeVoiceTranscriberConfig(params: {
124
- context: PluginCommandContext;
125
- value: Partial<VoiceTranscriberConfig>;
126
- }): Promise<VoicePluginConfig> {
127
- if (!params.context.config.plugins) {
128
- params.context.config.plugins = {};
129
- }
130
- const current = readVoicePluginRecord(params.context);
131
- const next: Record<string, unknown> & {
132
- enabled?: boolean;
133
- } = {
134
- ...current,
135
- ...params.value,
136
- };
137
- delete next.enabled;
138
- params.context.config.plugins.asr = toJsonObject(next);
139
- await params.context.pluginConfig.persistProjectPlugins(params.context.config.plugins);
140
- return params.context.config.plugins.asr as VoicePluginConfig;
141
- }
142
-
143
- async function checkLocalProviderAvailability(
144
- context: PluginCommandContext,
145
- config: VoiceTranscriberConfig,
146
- ): Promise<VoiceDependencyCheckResult> {
147
- const reasons: string[] = [];
148
- const modelId = resolveVoiceModelId(String(config.modelId || ""));
149
- if (!modelId) {
150
- reasons.push("asr transcriber modelId is missing");
151
- return {
152
- available: false,
153
- reasons,
154
- };
155
- }
156
-
157
- const modelsRootDir = resolveVoiceModelsRootDir({
158
- projectRoot: context.rootPath,
159
- modelsDir: config.modelsDir,
160
- });
161
- const installState = await detectLocalVoiceModelInstallState({
162
- modelId,
163
- modelsRootDir,
164
- });
165
- if (!installState.installed) {
166
- reasons.push(`asr model is not installed: ${modelId}`);
167
- }
168
-
169
- const pythonBin = String(config.pythonBin || "").trim() || "python3";
170
- try {
171
- await execFileAsync(pythonBin, ["--version"], {
172
- timeout: 15_000,
173
- maxBuffer: 1024 * 1024,
174
- });
175
- } catch (error) {
176
- reasons.push(`python runtime missing: ${String(error)}`);
177
- }
178
-
179
- return {
180
- available: reasons.length === 0,
181
- reasons,
182
- };
183
- }
184
-
185
- /**
186
- * 检查 ASR 转写依赖可用性。
187
- */
188
- export async function checkVoiceTranscriber(
189
- context: PluginCommandContext,
190
- ): Promise<VoiceDependencyCheckResult> {
191
- const config = readVoiceTranscriberConfig(context);
192
- if (config.provider === "command") {
193
- const command = String(config.command || "").trim();
194
- return {
195
- available: Boolean(command),
196
- reasons: command ? [] : ["asr transcriber command is missing"],
197
- };
198
- }
199
- return checkLocalProviderAvailability(context, config);
200
- }
201
-
202
- /**
203
- * 安装或修复 ASR 转写依赖。
204
- */
205
- export async function installVoiceTranscriber(params: {
206
- context: PluginCommandContext;
207
- input?: VoiceTranscriberInstallInput;
208
- }): Promise<VoiceDependencyInstallResult> {
209
- const context = params.context;
210
- const input = params.input;
211
- const config = readVoiceTranscriberConfig(context);
212
- if (config.provider === "command") {
213
- return {
214
- success: true,
215
- message: "asr command provider does not require install",
216
- };
217
- }
218
-
219
- const requestedModelIds =
220
- (Array.isArray(input?.modelIds) ? input?.modelIds : [])
221
- .map((item) => resolveVoiceModelId(String(item || "").trim()))
222
- .filter((item): item is VoiceModelId => Boolean(item));
223
- const selectedModelIds: VoiceModelId[] =
224
- requestedModelIds.length > 0
225
- ? requestedModelIds
226
- : [resolveVoiceModelId(String(config.modelId || "SenseVoiceSmall")) || "SenseVoiceSmall"];
227
-
228
- const modelsRootDir = resolveVoiceModelsRootDir({
229
- projectRoot: context.rootPath,
230
- modelsDir: input?.modelsDir || config.modelsDir,
231
- });
232
-
233
- for (const modelId of selectedModelIds) {
234
- const model = VOICE_MODEL_CATALOG.find((item) => item.id === modelId);
235
- if (!model) {
236
- throw new Error(`Unsupported asr model: ${modelId}`);
237
- }
238
- const installState = await detectLocalVoiceModelInstallState({
239
- modelId,
240
- modelsRootDir,
241
- });
242
- if (!installState.installed || input?.force === true) {
243
- await installVoiceModelFromHuggingFace({
244
- model,
245
- modelsRootDir,
246
- force: input?.force === true,
247
- hfToken: input?.hfToken,
248
- });
249
- }
250
- }
251
-
252
- if (input?.installDeps !== false) {
253
- await installVoiceTranscribeDependencies({
254
- pythonBin:
255
- String(input?.pythonBin || config.pythonBin || "").trim() || "python3",
256
- runners: resolveVoiceRunnersByModels(selectedModelIds),
257
- });
258
- }
259
-
260
- const activeModelId =
261
- resolveVoiceModelId(String(input?.activeModel || "")) ||
262
- selectedModelIds[0];
263
-
264
- const nextConfig: VoiceTranscriberConfig = {
265
- ...config,
266
- provider: "local",
267
- modelId: activeModelId,
268
- modelsDir: modelsRootDir,
269
- pythonBin:
270
- String(input?.pythonBin || config.pythonBin || "").trim() || undefined,
271
- ...(config.command ? { command: config.command } : {}),
272
- language:
273
- typeof config.language === "string" && config.language.trim()
274
- ? config.language.trim()
275
- : undefined,
276
- strategy: resolveVoiceStrategyByModel(activeModelId),
277
- installedModels: selectedModelIds,
278
- };
279
- await writeVoiceTranscriberConfig({
280
- context,
281
- value: nextConfig,
282
- });
283
-
284
- return {
285
- success: true,
286
- message: "asr transcriber installed",
287
- details: {
288
- modelIds: selectedModelIds,
289
- activeModel: activeModelId,
290
- modelsRootDir,
291
- },
292
- };
293
- }
294
-
295
- /**
296
- * 解析 ASR 转写句柄。
297
- */
298
- export async function resolveVoiceTranscriber(
299
- context: PluginCommandContext,
300
- ): Promise<VoiceTranscriberHandle> {
301
- return {
302
- async transcribe(input) {
303
- try {
304
- const result = await transcribeVoiceAudio({
305
- context,
306
- audioPath: input.audioPath,
307
- language: input.language,
308
- });
309
- return {
310
- success: true,
311
- text: result.text,
312
- };
313
- } catch (error) {
314
- return {
315
- success: false,
316
- error: String(error),
317
- };
318
- }
319
- },
320
- };
321
- }
322
-
323
- /**
324
- * 执行一次 ASR 转写。
325
- */
326
- export async function transcribeWithVoiceDependency(params: {
327
- context: PluginCommandContext;
328
- audioPath: string;
329
- language?: string;
330
- }): Promise<{ success: boolean; text?: string; error?: string }> {
331
- const transcriber = await resolveVoiceTranscriber(params.context);
332
- return transcriber.transcribe({
333
- audioPath: params.audioPath,
334
- ...(params.language ? { language: params.language } : {}),
335
- });
336
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * ASR 入站消息增强 hook。
3
- *
4
- * 关键点(中文)
5
- * - 只处理 voice/audio 附件,转写结果作为 plugin section 注入。
6
- * - 转写失败不阻塞主链路,保持 best-effort。
7
- */
8
-
9
- import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
10
- import type { ChatInboundAugmentInput } from "@/chat/types/ChatPlugin.js";
11
- import type { JsonValue } from "@downcity/agent/internal/types/common/Json.js";
12
- import { transcribeWithVoiceDependency } from "@/asr/Dependency.js";
13
-
14
- /**
15
- * 自动转写入站语音附件。
16
- */
17
- export async function augmentAsrInboundMessage(params: {
18
- context: AgentContext;
19
- value: JsonValue;
20
- }): Promise<JsonValue> {
21
- const input = params.value as unknown as ChatInboundAugmentInput;
22
- const voiceAttachments = (Array.isArray(input.attachments) ? input.attachments : []).filter(
23
- (item) =>
24
- (item.kind === "voice" || item.kind === "audio") &&
25
- typeof item.path === "string" &&
26
- item.path.trim(),
27
- );
28
- if (voiceAttachments.length === 0) {
29
- return input as unknown as JsonValue;
30
- }
31
-
32
- const pluginSections = Array.isArray(input.pluginSections)
33
- ? [...input.pluginSections]
34
- : [];
35
-
36
- for (const attachment of voiceAttachments) {
37
- try {
38
- const result = await transcribeWithVoiceDependency({
39
- context: params.context,
40
- audioPath: String(attachment.path || "").trim(),
41
- });
42
- const text = typeof result.text === "string" ? result.text.trim() : "";
43
- if (!text) continue;
44
-
45
- const absPath = String(attachment.path || "").trim();
46
- const rel = absPath.startsWith(`${params.context.rootPath}/`)
47
- ? absPath.slice(params.context.rootPath.length + 1)
48
- : absPath;
49
- pluginSections.push(`【语音转写 ${attachment.kind}: ${rel}】\n${text}`);
50
- } catch {
51
- // 关键点(中文):转写失败不阻塞主链路,保持 best-effort。
52
- }
53
- }
54
-
55
- return {
56
- ...input,
57
- pluginSections,
58
- } as unknown as JsonValue;
59
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * Voice 插件模型目录封装。
3
- *
4
- * 关键点(中文)
5
- * - 对 plugin 层暴露稳定的 ASR 模型目录接口。
6
- * - plugin 不直接依赖底层 runtime 文件布局,只依赖这里的领域封装。
7
- */
8
-
9
- import {
10
- VOICE_MODEL_CATALOG,
11
- resolveVoiceModelId,
12
- } from "@/voice/runtime/Catalog.js";
13
-
14
- /**
15
- * 列出内置 voice 模型目录。
16
- */
17
- export function listVoiceModels(): Array<{
18
- /**
19
- * 稳定模型 ID。
20
- */
21
- id: string;
22
- /**
23
- * 用户可读标签。
24
- */
25
- label: string;
26
- /**
27
- * 用户可读说明。
28
- */
29
- description: string;
30
- }> {
31
- return VOICE_MODEL_CATALOG.map((item) => ({
32
- id: item.id,
33
- label: item.label,
34
- description: item.description,
35
- }));
36
- }
37
-
38
- /**
39
- * 解析用户输入的 voice 模型 ID。
40
- */
41
- export function resolveVoicePluginModelId(input: string): string | null {
42
- return resolveVoiceModelId(input);
43
- }
@@ -1,237 +0,0 @@
1
- /**
2
- * ChatAuthorizationPlugin。
3
- *
4
- * 关键点(中文)
5
- * - chat-authorization 是内建且必需的 plugin,不走可选启停语义。
6
- * - 静态授权配置与动态观测态都收敛在项目 `.downcity/chat/authorization/`。
7
- * - 它只负责聊天主体授权,不负责 Town HTTP Bearer token 或路由访问鉴权。
8
- */
9
-
10
- import { BasePlugin } from "@downcity/agent/internal/plugin/core/BasePlugin.js";
11
- import type { Plugin } from "@downcity/agent/internal/plugin/types/Plugin.js";
12
- import type { JsonValue } from "@downcity/agent/internal/types/common/Json.js";
13
- import { CHAT_PLUGIN_POINTS } from "@/chat/runtime/PluginPoints.js";
14
- import {
15
- CHAT_AUTHORIZATION_ACTIONS,
16
- CHAT_AUTHORIZATION_CATALOG,
17
- CHAT_AUTHORIZATION_PLUGIN_NAME,
18
- type ChatAuthorizationObservePrincipalPayload,
19
- type ChatAuthorizationSetUserRolePayload,
20
- type ChatAuthorizationWriteConfigPayload,
21
- type ChatAuthorizationConfig,
22
- type ChatAuthorizationEvaluateInput,
23
- type ChatAuthorizationSnapshot,
24
- } from "@/auth/types/AuthPlugin.js";
25
- import {
26
- readChatAuthorizationConfig,
27
- setChatAuthorizationUserRole,
28
- writeChatAuthorizationConfig,
29
- } from "@/auth/runtime/AuthorizationConfig.js";
30
- import {
31
- evaluateIncomingChatAuthorization,
32
- resolveAuthorizedUserRole,
33
- } from "@/auth/runtime/AuthorizationPolicy.js";
34
- import {
35
- readAuthorizationSnapshot,
36
- recordObservedAuthorizationPrincipal,
37
- } from "@/auth/runtime/AuthorizationStore.js";
38
- import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
39
-
40
- function toChannel(value: unknown): ChatDispatchChannel | null {
41
- const text = String(value || "").trim().toLowerCase();
42
- if (text === "telegram" || text === "feishu" || text === "qq") return text;
43
- return null;
44
- }
45
-
46
- function toRecord(value: unknown): Record<string, unknown> {
47
- if (!value || typeof value !== "object" || Array.isArray(value)) return {};
48
- return value as Record<string, unknown>;
49
- }
50
-
51
- function toEvaluateInput(payload: Record<string, unknown>): ChatAuthorizationEvaluateInput {
52
- const channel = toChannel(payload.channel);
53
- if (!channel) {
54
- throw new Error("chat-authorization.authorize_incoming requires a valid channel");
55
- }
56
- return {
57
- channel,
58
- chatId: String(payload.chatId || "").trim(),
59
- ...(typeof payload.chatType === "string" ? { chatType: payload.chatType.trim() } : {}),
60
- ...(typeof payload.userId === "string" ? { userId: payload.userId.trim() } : {}),
61
- ...(typeof payload.username === "string" ? { username: payload.username.trim() } : {}),
62
- ...(typeof payload.chatTitle === "string" ? { chatTitle: payload.chatTitle.trim() } : {}),
63
- };
64
- }
65
-
66
- function toSnapshotData(snapshot: ChatAuthorizationSnapshot): JsonValue {
67
- return {
68
- catalog: CHAT_AUTHORIZATION_CATALOG as unknown as JsonValue,
69
- config: snapshot.config as unknown as JsonValue,
70
- users: snapshot.users as unknown as JsonValue,
71
- chats: snapshot.chats as unknown as JsonValue,
72
- };
73
- }
74
-
75
- function createChatAuthorizationPluginDefinition(): Plugin {
76
- return {
77
- name: CHAT_AUTHORIZATION_PLUGIN_NAME,
78
- title: "Chat Access",
79
- description:
80
- "Controls who can talk to the agent through chat platforms, records observed users and chats, and resolves each user's effective role for downstream service decisions.",
81
- availability() {
82
- return {
83
- enabled: true,
84
- available: true,
85
- reasons: [],
86
- };
87
- },
88
- hooks: {
89
- guard: {
90
- [CHAT_PLUGIN_POINTS.authorizeIncoming]: [
91
- async ({ context, value }) => {
92
- const input =
93
- value && typeof value === "object" && !Array.isArray(value)
94
- ? (value as Record<string, unknown>)
95
- : {};
96
- const evaluateInput = toEvaluateInput(input);
97
- const authorizationConfig = readChatAuthorizationConfig(context);
98
- const result = evaluateIncomingChatAuthorization({
99
- config: context.config,
100
- channel: evaluateInput.channel,
101
- input: evaluateInput,
102
- authorizationConfig,
103
- });
104
- if (result.decision !== "allow") {
105
- throw new Error(result.reason || "chat authorization blocked");
106
- }
107
- },
108
- ],
109
- },
110
- effect: {
111
- [CHAT_PLUGIN_POINTS.observePrincipal]: [
112
- async ({ context, value }) => {
113
- const input = toRecord(
114
- value,
115
- ) as unknown as ChatAuthorizationObservePrincipalPayload;
116
- const channel = toChannel(input.channel);
117
- if (!channel) {
118
- throw new Error("chat.observePrincipal requires a valid channel");
119
- }
120
- await recordObservedAuthorizationPrincipal({
121
- context,
122
- channel,
123
- chatId: String(input.chatId || "").trim(),
124
- ...(typeof input.chatType === "string"
125
- ? { chatType: input.chatType.trim() }
126
- : {}),
127
- ...(typeof input.chatTitle === "string"
128
- ? { chatTitle: input.chatTitle.trim() }
129
- : {}),
130
- ...(typeof input.userId === "string"
131
- ? { userId: input.userId.trim() }
132
- : {}),
133
- ...(typeof input.username === "string"
134
- ? { username: input.username.trim() }
135
- : {}),
136
- });
137
- },
138
- ],
139
- },
140
- },
141
- resolves: {
142
- [CHAT_PLUGIN_POINTS.resolveUserRole]: async ({ context, value }) => {
143
- const input =
144
- value && typeof value === "object" && !Array.isArray(value)
145
- ? (value as Record<string, unknown>)
146
- : {};
147
- const channel = toChannel(input.channel);
148
- if (!channel) {
149
- throw new Error("chat.resolveUserRole requires a valid channel");
150
- }
151
- const role = resolveAuthorizedUserRole({
152
- channel,
153
- userId: String(input.userId || "").trim(),
154
- rootPath: context.rootPath,
155
- });
156
- return ((role || null) as unknown) as JsonValue;
157
- },
158
- },
159
- actions: {
160
- [CHAT_AUTHORIZATION_ACTIONS.snapshot]: {
161
- execute: async ({ context }) => {
162
- const snapshot = await readAuthorizationSnapshot({
163
- context,
164
- });
165
- return {
166
- success: true,
167
- data: toSnapshotData(snapshot),
168
- };
169
- },
170
- },
171
- [CHAT_AUTHORIZATION_ACTIONS.readConfig]: {
172
- execute: async ({ context }) => {
173
- return {
174
- success: true,
175
- data: readChatAuthorizationConfig(context) as unknown as JsonValue,
176
- };
177
- },
178
- },
179
- [CHAT_AUTHORIZATION_ACTIONS.writeConfig]: {
180
- execute: async ({ context, payload }) => {
181
- const body = toRecord(
182
- payload,
183
- ) as unknown as ChatAuthorizationWriteConfigPayload;
184
- const nextConfig =
185
- body.config && typeof body.config === "object" && !Array.isArray(body.config)
186
- ? (body.config as ChatAuthorizationConfig)
187
- : {};
188
- await writeChatAuthorizationConfig({
189
- context,
190
- nextConfig,
191
- });
192
- return {
193
- success: true,
194
- data: readChatAuthorizationConfig(context) as unknown as JsonValue,
195
- };
196
- },
197
- },
198
- [CHAT_AUTHORIZATION_ACTIONS.setUserRole]: {
199
- execute: async ({ context, payload }) => {
200
- const body = toRecord(
201
- payload,
202
- ) as unknown as ChatAuthorizationSetUserRolePayload;
203
- const channel = toChannel(body.channel);
204
- if (!channel) {
205
- return {
206
- success: false,
207
- error: "set-user-role requires a valid channel",
208
- message: "set-user-role requires a valid channel",
209
- };
210
- }
211
- await setChatAuthorizationUserRole({
212
- context,
213
- channel,
214
- userId: String(body.userId || "").trim(),
215
- roleId: String(body.roleId || "").trim(),
216
- });
217
- return {
218
- success: true,
219
- data: readChatAuthorizationConfig(context) as unknown as JsonValue,
220
- };
221
- },
222
- },
223
- },
224
- };
225
- }
226
-
227
- /**
228
- * ChatAuthorizationPlugin:统一承载聊天用户授权能力。
229
- */
230
- export class ChatAuthorizationPlugin extends BasePlugin {
231
- readonly name = CHAT_AUTHORIZATION_PLUGIN_NAME;
232
-
233
- constructor() {
234
- super();
235
- Object.assign(this, createChatAuthorizationPluginDefinition());
236
- }
237
- }