@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
@@ -0,0 +1,118 @@
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/internal/types/common/Json.js";
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
+
@@ -1,20 +1,15 @@
1
1
  /**
2
- * ChatAuthorizationPlugin 类型与契约定义。
2
+ * ChatAuthorization 类型与契约定义。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 统一维护聊天授权 plugin 的领域类型、扩展点/action 名称、payload 契约。
6
- * - 业务层不应散落硬编码字符串,如 `chat.authorizeIncoming`、`set-user-role`。
7
- * - chat / console / plugin 执行链路都从这里共享同一份边界定义。
5
+ * - 统一维护 ChatPlugin 内置授权能力的领域类型、扩展点/action 名称、payload 契约。
6
+ * - 业务层不应散落硬编码字符串,如 `chat.authorizeIncoming`、`authorization-set-user-role`。
7
+ * - chat / console / plugin action 执行链路都从这里共享同一份边界定义。
8
8
  */
9
9
 
10
10
  import type { ChatDispatchChannel } from "@/chat/types/ChatDispatcher.js";
11
11
  import { CHAT_PLUGIN_POINTS } from "@/chat/runtime/PluginPoints.js";
12
12
 
13
- /**
14
- * 聊天授权 plugin 稳定名称。
15
- */
16
- export const CHAT_AUTHORIZATION_PLUGIN_NAME = "chat-authorization";
17
-
18
13
  /**
19
14
  * 聊天授权支持的渠道目录。
20
15
  */
@@ -28,7 +23,7 @@ export type ChatAuthorizationChannel = (typeof CHAT_AUTHORIZATION_CHANNELS)[numb
28
23
  /**
29
24
  * 聊天授权扩展点名称集合。
30
25
  */
31
- export const CHAT_AUTHORIZATION_PLUGIN_POINTS = {
26
+ export const CHAT_AUTHORIZATION_POINTS = {
32
27
  observePrincipal: CHAT_PLUGIN_POINTS.observePrincipal,
33
28
  authorizeIncoming: CHAT_PLUGIN_POINTS.authorizeIncoming,
34
29
  resolveUserRole: CHAT_PLUGIN_POINTS.resolveUserRole,
@@ -38,10 +33,10 @@ export const CHAT_AUTHORIZATION_PLUGIN_POINTS = {
38
33
  * 聊天授权 action 名称集合。
39
34
  */
40
35
  export const CHAT_AUTHORIZATION_ACTIONS = {
41
- snapshot: "snapshot",
42
- readConfig: "read-config",
43
- writeConfig: "write-config",
44
- setUserRole: "set-user-role",
36
+ snapshot: "authorization-snapshot",
37
+ readConfig: "authorization-read-config",
38
+ writeConfig: "authorization-write-config",
39
+ setUserRole: "authorization-set-user-role",
45
40
  } as const;
46
41
 
47
42
  /**
@@ -463,7 +458,7 @@ export interface ChatAuthorizationStateFile {
463
458
  }
464
459
 
465
460
  /**
466
- * plugin effect 输入:记录观测主体。
461
+ * ChatPlugin effect 输入:记录观测主体。
467
462
  */
468
463
  export interface ChatAuthorizationObservePrincipalPayload {
469
464
  /**
@@ -493,7 +488,7 @@ export interface ChatAuthorizationObservePrincipalPayload {
493
488
  }
494
489
 
495
490
  /**
496
- * plugin effect 输出:记录观测主体结果。
491
+ * ChatPlugin effect 输出:记录观测主体结果。
497
492
  */
498
493
  export interface ChatAuthorizationObservePrincipalResult {
499
494
  /**
@@ -503,7 +498,7 @@ export interface ChatAuthorizationObservePrincipalResult {
503
498
  }
504
499
 
505
500
  /**
506
- * plugin resolve 输入:查询用户角色。
501
+ * ChatPlugin resolve 输入:查询用户角色。
507
502
  */
508
503
  export interface ChatAuthorizationResolveUserRolePayload {
509
504
  /**
@@ -9,29 +9,47 @@
9
9
  */
10
10
 
11
11
  import { BasePlugin } from "@downcity/agent/internal/plugin/core/BasePlugin.js";
12
- import type { PluginActions } from "@downcity/agent/internal/plugin/types/Plugin.js";
12
+ import type {
13
+ PluginActions,
14
+ PluginHooks,
15
+ PluginResolves,
16
+ } from "@downcity/agent/internal/plugin/types/Plugin.js";
13
17
  import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
14
18
  import type { ChatChannelState } from "@/chat/types/ChatRuntime.js";
15
- import type { StoredChannelAccount } from "@downcity/agent/internal/types/platform/Store.js";
16
19
  import type { ChatQueueWorkerConfig } from "@/chat/types/ChatQueueWorker.js";
17
20
  import type {
18
- ChatPluginFeishuOptions,
21
+ ChatChannel,
19
22
  ChatPluginOptions,
20
- ChatPluginQqOptions,
21
- ChatPluginTelegramOptions,
22
- } from "@/chat/ChatPluginTypes.js";
23
+ } from "@/chat/types/ChatPluginOptions.js";
23
24
  import type { ChatChannelName } from "@/chat/types/ChannelStatus.js";
25
+ import {
26
+ FeishuChannel,
27
+ QqChannel,
28
+ TelegramChannel,
29
+ } from "@/chat/channels/RuntimeChannel.js";
24
30
  import {
25
31
  createChatChannelState,
26
32
  startChatChannels,
27
33
  stopChatChannels,
28
34
  } from "./runtime/ChatChannelFacade.js";
29
- import { getStoredChannelAccountSync } from "./accounts/Store.js";
30
35
  import { createChatPluginActions } from "./runtime/ChatPluginActions.js";
36
+ import {
37
+ createChatAuthorizationActions,
38
+ createChatAuthorizationHooks,
39
+ createChatAuthorizationResolves,
40
+ } from "./runtime/ChatAuthorizationRuntime.js";
31
41
  import { ChatQueueWorker } from "./runtime/ChatQueueWorker.js";
32
42
  import { buildChatPluginSystem } from "./runtime/ChatPluginSystem.js";
33
43
  import { ChatQueueStore } from "./runtime/ChatQueueStore.js";
34
44
 
45
+ function createDefaultChannels(): ChatChannel[] {
46
+ return [
47
+ new TelegramChannel({ enabled: false }),
48
+ new FeishuChannel({ enabled: false }),
49
+ new QqChannel({ enabled: false }),
50
+ ];
51
+ }
52
+
35
53
  /**
36
54
  * Chat plugin 类实现。
37
55
  */
@@ -69,6 +87,11 @@ export class ChatPlugin extends BasePlugin {
69
87
  */
70
88
  public readonly options: ChatPluginOptions;
71
89
 
90
+ /**
91
+ * 当前实例持有的 chat channels。
92
+ */
93
+ public readonly channels: ChatChannel[];
94
+
72
95
  /**
73
96
  * 当前 plugin 的 system 文本构建器。
74
97
  */
@@ -81,6 +104,16 @@ export class ChatPlugin extends BasePlugin {
81
104
  */
82
105
  readonly actions: PluginActions;
83
106
 
107
+ /**
108
+ * 当前 plugin 的 hook 定义表。
109
+ */
110
+ readonly hooks: PluginHooks;
111
+
112
+ /**
113
+ * 当前 plugin 的 resolve 定义表。
114
+ */
115
+ readonly resolves: PluginResolves;
116
+
84
117
  /**
85
118
  * 启动当前实例的 queue worker。
86
119
  */
@@ -109,9 +142,17 @@ export class ChatPlugin extends BasePlugin {
109
142
  constructor(options?: ChatPluginOptions) {
110
143
  super();
111
144
  this.options = options || {};
112
- this.actions = createChatPluginActions({
113
- channelState: this.channelState,
114
- });
145
+ this.channels = Array.isArray(this.options.channels)
146
+ ? [...this.options.channels]
147
+ : createDefaultChannels();
148
+ this.actions = {
149
+ ...createChatPluginActions({
150
+ channelState: this.channelState,
151
+ }),
152
+ ...createChatAuthorizationActions(),
153
+ };
154
+ this.hooks = createChatAuthorizationHooks();
155
+ this.resolves = createChatAuthorizationResolves();
115
156
  this.lifecycle = {
116
157
  start: async (context) => {
117
158
  this.startQueueWorker(context);
@@ -130,18 +171,15 @@ export class ChatPlugin extends BasePlugin {
130
171
  getQueueWorkerConfig(
131
172
  context: AgentContext,
132
173
  ): Partial<ChatQueueWorkerConfig> | undefined {
133
- return this.options.queue || context.config.plugins?.chat?.queue;
174
+ void context;
175
+ return this.options.queue;
134
176
  }
135
177
 
136
178
  /**
137
179
  * 判断指定渠道是否启用。
138
180
  */
139
181
  isChannelEnabled(context: AgentContext, channel: ChatChannelName): boolean {
140
- const explicit = this.getExplicitChannelOptions(channel);
141
- if (explicit) {
142
- return explicit.enabled !== false;
143
- }
144
- return context.config.plugins?.chat?.channels?.[channel]?.enabled === true;
182
+ return this.getChannel(channel)?.isEnabled(context) === true;
145
183
  }
146
184
 
147
185
  /**
@@ -151,13 +189,40 @@ export class ChatPlugin extends BasePlugin {
151
189
  context: AgentContext,
152
190
  channel: ChatChannelName,
153
191
  ): string {
154
- const explicit = this.getExplicitChannelOptions(channel);
155
- const explicitAccountId = String(explicit?.channelAccountId || "").trim();
156
- if (explicitAccountId) return explicitAccountId;
157
- const config = context.config.plugins?.chat?.channels?.[channel] as
158
- | { channelAccountId?: unknown }
159
- | undefined;
160
- return String(config?.channelAccountId || "").trim();
192
+ return String(this.getChannel(channel)?.getChannelAccountId(context) || "").trim();
193
+ }
194
+
195
+ /**
196
+ * 更新当前实例的渠道运行态配置。
197
+ *
198
+ * 关键点(中文)
199
+ * - chat.open/close/configure 只修改当前 plugin 实例,不写 downcity.json。
200
+ * - 当前运行态只允许更新 `enabled` 与 `channelAccountId`,密钥仍来自 constructor 或账号池。
201
+ */
202
+ applyChannelRuntimePatch(params: {
203
+ /**
204
+ * 目标渠道。
205
+ */
206
+ channel: ChatChannelName;
207
+ /**
208
+ * 是否启用该渠道。
209
+ */
210
+ enabled?: boolean;
211
+ /**
212
+ * 绑定的账号池记录 ID;传入 null 表示清空绑定。
213
+ */
214
+ channelAccountId?: string | null;
215
+ }): void {
216
+ const channel = this.getChannel(params.channel);
217
+ if (!channel) {
218
+ throw new Error(`Chat channel is not registered: ${params.channel}`);
219
+ }
220
+ channel.applyRuntimePatch({
221
+ ...(typeof params.enabled === "boolean" ? { enabled: params.enabled } : {}),
222
+ ...(Object.prototype.hasOwnProperty.call(params, "channelAccountId")
223
+ ? { channelAccountId: params.channelAccountId ?? null }
224
+ : {}),
225
+ });
161
226
  }
162
227
 
163
228
  /**
@@ -166,73 +231,11 @@ export class ChatPlugin extends BasePlugin {
166
231
  resolveChannelAccount(
167
232
  context: AgentContext,
168
233
  channel: ChatChannelName,
169
- ): StoredChannelAccount | null {
170
- const explicit = this.buildExplicitChannelAccount(channel);
171
- if (explicit) return explicit;
172
- const channelAccountId = this.getChannelAccountId(context, channel);
173
- if (!channelAccountId) return null;
174
- return getStoredChannelAccountSync(channelAccountId);
234
+ ) {
235
+ return this.getChannel(channel)?.getAccount(context) || null;
175
236
  }
176
237
 
177
- private getExplicitChannelOptions(
178
- channel: ChatChannelName,
179
- ): ChatPluginTelegramOptions | ChatPluginFeishuOptions | ChatPluginQqOptions | undefined {
180
- if (channel === "telegram") return this.options.telegram;
181
- if (channel === "feishu") return this.options.feishu;
182
- return this.options.qq;
183
- }
184
-
185
- private buildExplicitChannelAccount(
186
- channel: ChatChannelName,
187
- ): StoredChannelAccount | null {
188
- const now = new Date().toISOString();
189
-
190
- if (channel === "telegram") {
191
- const config = this.options.telegram;
192
- const botToken = String(config?.botToken || "").trim();
193
- if (!botToken) return null;
194
- return {
195
- id: String(config?.channelAccountId || `chat-sdk-${channel}`).trim(),
196
- channel,
197
- name: String(config?.name || "telegram").trim() || "telegram",
198
- botToken,
199
- createdAt: now,
200
- updatedAt: now,
201
- };
202
- }
203
-
204
- if (channel === "feishu") {
205
- const config = this.options.feishu;
206
- const appId = String(config?.appId || "").trim();
207
- const appSecret = String(config?.appSecret || "").trim();
208
- if (!appId || !appSecret) return null;
209
- return {
210
- id: String(config?.channelAccountId || `chat-sdk-${channel}`).trim(),
211
- channel,
212
- name: String(config?.name || "feishu").trim() || "feishu",
213
- appId,
214
- appSecret,
215
- ...(String(config?.domain || "").trim()
216
- ? { domain: String(config?.domain || "").trim() }
217
- : {}),
218
- createdAt: now,
219
- updatedAt: now,
220
- };
221
- }
222
-
223
- const config = this.options.qq;
224
- const appId = String(config?.appId || "").trim();
225
- const appSecret = String(config?.appSecret || "").trim();
226
- if (!appId || !appSecret) return null;
227
- return {
228
- id: String(config?.channelAccountId || `chat-sdk-${channel}`).trim(),
229
- channel,
230
- name: String(config?.name || "qq").trim() || "qq",
231
- appId,
232
- appSecret,
233
- ...(config?.sandbox === true ? { sandbox: true } : {}),
234
- createdAt: now,
235
- updatedAt: now,
236
- };
238
+ private getChannel(channel: ChatChannelName): ChatChannel | null {
239
+ return this.channels.find((item) => item.name === channel) || null;
237
240
  }
238
241
  }
package/src/chat/Index.ts CHANGED
@@ -2,7 +2,24 @@
2
2
  * Chat Plugin 导出入口。
3
3
  *
4
4
  * 关键点(中文)
5
- * - Index 只负责导出类实现。
5
+ * - Index 只负责导出类实现与 channel SDK 对象。
6
6
  * - 真正的类实现位于 `ChatPlugin.ts`。
7
7
  */
8
8
  export { ChatPlugin } from "./ChatPlugin.js";
9
+ export {
10
+ FeishuChannel,
11
+ QqChannel,
12
+ TelegramChannel,
13
+ } from "./channels/RuntimeChannel.js";
14
+ export type {
15
+ BaseChatChannelOptions,
16
+ ChatChannelEnv,
17
+ FeishuChannelOptions,
18
+ QqChannelOptions,
19
+ TelegramChannelOptions,
20
+ } from "./channels/RuntimeChannel.js";
21
+ export type {
22
+ ChatChannel,
23
+ ChatChannelRuntimePatch,
24
+ ChatPluginOptions,
25
+ } from "./types/ChatPluginOptions.js";
@@ -27,7 +27,7 @@ export abstract class ChatChannelConfiguration {
27
27
  abstract describe(): ChatChannelConfigurationDescriptor;
28
28
 
29
29
  /**
30
- * 返回可通过 `chat.configure` 写入的 downcity.json 字段定义。
30
+ * 返回可通过 `chat.configure` 更新的运行态字段定义。
31
31
  */
32
32
  getWritableShipFields(): ChatChannelConfigurationField[] {
33
33
  return this.describe().fields.ship.filter((field) => field.writable);