@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,97 +0,0 @@
1
- /**
2
- * TTS 内置模型目录。
3
- *
4
- * 关键点(中文)
5
- * - 默认主推 `Qwen 0.6B` 与 `Kokoro`。
6
- * - 目录只保留 Console/UI 需要的稳定元数据,不暴露底层实现细节。
7
- */
8
-
9
- import type { TtsModelCatalogItem, TtsModelId } from "@/tts/types/Tts.js";
10
-
11
- /**
12
- * 内置 TTS 模型目录。
13
- */
14
- export const TTS_MODEL_CATALOG: readonly TtsModelCatalogItem[] = [
15
- {
16
- id: "qwen3-tts-0.6b",
17
- label: "Qwen3-TTS 0.6B",
18
- description: "中英文与多语言能力更强,作为主推荐模型。",
19
- family: "qwen3",
20
- recommended: true,
21
- assets: [
22
- {
23
- repoId: "Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice",
24
- revision: "main",
25
- },
26
- ],
27
- },
28
- {
29
- id: "kokoro-82m",
30
- label: "Kokoro 82M",
31
- description: "体积更小,启动更轻,适合本地快速合成。",
32
- family: "kokoro",
33
- recommended: true,
34
- assets: [
35
- {
36
- repoId: "hexgrad/Kokoro-82M",
37
- revision: "main",
38
- files: [
39
- "config.json",
40
- "kokoro-v1_0.pth",
41
- "voices/af_heart.pt",
42
- "voices/zf_xiaoni.pt",
43
- ],
44
- },
45
- ],
46
- },
47
- {
48
- id: "qwen3-tts-1.7b",
49
- label: "Qwen3-TTS 1.7B",
50
- description: "效果更强,但体积更大,适合更看重质量的本地合成。",
51
- family: "qwen3",
52
- recommended: false,
53
- assets: [
54
- {
55
- repoId: "Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice",
56
- revision: "main",
57
- },
58
- ],
59
- },
60
- ] as const;
61
-
62
- const TTS_MODEL_ALIAS_MAP: Record<string, TtsModelId> = {
63
- "qwen3-tts-0.6b": "qwen3-tts-0.6b",
64
- qwen3tts06b: "qwen3-tts-0.6b",
65
- qwen_06b: "qwen3-tts-0.6b",
66
- "kokoro-82m": "kokoro-82m",
67
- kokoro82m: "kokoro-82m",
68
- "qwen3-tts-1.7b": "qwen3-tts-1.7b",
69
- qwen3tts17b: "qwen3-tts-1.7b",
70
- qwen_17b: "qwen3-tts-1.7b",
71
- };
72
-
73
- const CATALOG_BY_ID: Record<TtsModelId, TtsModelCatalogItem> = TTS_MODEL_CATALOG.reduce(
74
- (acc, item) => {
75
- acc[item.id] = item;
76
- return acc;
77
- },
78
- {} as Record<TtsModelId, TtsModelCatalogItem>,
79
- );
80
-
81
- /**
82
- * 解析用户输入为稳定模型 ID(支持别名与大小写)。
83
- */
84
- export function resolveTtsModelId(input: string): TtsModelId | null {
85
- const raw = String(input || "").trim();
86
- if (!raw) return null;
87
- const exact = TTS_MODEL_CATALOG.find((item) => item.id === raw);
88
- if (exact) return exact.id;
89
- return TTS_MODEL_ALIAS_MAP[raw.toLowerCase()] || null;
90
- }
91
-
92
- /**
93
- * 读取目录项;不存在返回 null。
94
- */
95
- export function getTtsModelCatalogItem(id: TtsModelId): TtsModelCatalogItem | null {
96
- return CATALOG_BY_ID[id] || null;
97
- }
@@ -1,436 +0,0 @@
1
- /**
2
- * TTS 依赖安装器。
3
- *
4
- * 关键点(中文)
5
- * - 统一管理 `town tts` 的 Python 依赖安装逻辑。
6
- * - 根据模型自动推导 runner(qwen3 / kokoro)并执行 `python -m pip install`。
7
- */
8
-
9
- import { execFile as execFileCb } from "node:child_process";
10
- import os from "node:os";
11
- import path from "node:path";
12
- import { promisify } from "node:util";
13
- import fs from "fs-extra";
14
- import type { TtsModelId, TtsRuntimeFamily } from "@/tts/types/Tts.js";
15
-
16
- const execFileAsync = promisify(execFileCb);
17
-
18
- const DEFAULT_PIP_TIMEOUT_MS = 300_000;
19
- const OUTPUT_TAIL_LIMIT = 1200;
20
- const DEFAULT_VENV_DIR = path.join(os.homedir(), ".downcity", "venvs", "tts");
21
-
22
- /**
23
- * TTS 依赖 runner 类型。
24
- */
25
- export type TtsDependencyRunner = TtsRuntimeFamily;
26
-
27
- /**
28
- * 单个 runner 的安装摘要。
29
- */
30
- export interface TtsDependencyInstallItem {
31
- /**
32
- * 当前安装 runner。
33
- */
34
- runner: TtsDependencyRunner;
35
- /**
36
- * Python 可执行文件。
37
- */
38
- pythonBin: string;
39
- /**
40
- * 执行参数(不含 pythonBin)。
41
- */
42
- args: string[];
43
- /**
44
- * 安装包列表。
45
- */
46
- packages: string[];
47
- /**
48
- * 实际执行的命令行。
49
- */
50
- command: string;
51
- /**
52
- * 执行耗时(毫秒)。
53
- */
54
- elapsedMs: number;
55
- /**
56
- * 是否跳过安装。
57
- */
58
- skipped?: boolean;
59
- /**
60
- * 跳过原因(可选)。
61
- */
62
- skipReason?: string;
63
- /**
64
- * stdout 尾部(可选)。
65
- */
66
- stdoutTail?: string;
67
- /**
68
- * stderr 尾部(可选)。
69
- */
70
- stderrTail?: string;
71
- }
72
-
73
- /**
74
- * 依赖安装结果。
75
- */
76
- export interface TtsDependencyInstallResult {
77
- /**
78
- * 本次使用的 Python 可执行文件。
79
- */
80
- pythonBin: string;
81
- /**
82
- * 本次处理的 runner 列表。
83
- */
84
- runners: TtsDependencyRunner[];
85
- /**
86
- * 各 runner 的安装摘要。
87
- */
88
- items: TtsDependencyInstallItem[];
89
- /**
90
- * 是否使用了虚拟环境安装。
91
- */
92
- usedVirtualEnv: boolean;
93
- /**
94
- * 虚拟环境目录(仅 `usedVirtualEnv=true` 时存在)。
95
- */
96
- venvDir?: string;
97
- /**
98
- * 初始尝试使用的 Python(仅进入虚拟环境回退时存在)。
99
- */
100
- basePythonBin?: string;
101
- }
102
-
103
- /**
104
- * 依赖安装输入参数。
105
- */
106
- export interface TtsDependencyInstallInput {
107
- /**
108
- * Python 可执行文件(默认 `python3`)。
109
- */
110
- pythonBin?: string;
111
- /**
112
- * 需要安装的 runner 列表。
113
- */
114
- runners: TtsDependencyRunner[];
115
- /**
116
- * 是否使用 `pip -U` 升级。
117
- */
118
- upgrade?: boolean;
119
- /**
120
- * pip 安装超时(毫秒)。
121
- */
122
- timeoutMs?: number;
123
- /**
124
- * 虚拟环境目录(可选)。
125
- */
126
- venvDir?: string;
127
- }
128
-
129
- function normalizePythonBin(input?: string): string {
130
- const text = String(input || "").trim();
131
- return text || "python3";
132
- }
133
-
134
- function normalizeTimeoutMs(value?: number): number {
135
- if (!Number.isFinite(value as number)) return DEFAULT_PIP_TIMEOUT_MS;
136
- const ms = Math.floor(Number(value));
137
- if (ms < 5_000) return 5_000;
138
- if (ms > 1_800_000) return 1_800_000;
139
- return ms;
140
- }
141
-
142
- function normalizeVenvDir(input?: string): string {
143
- const text = String(input || "").trim();
144
- if (!text) return DEFAULT_VENV_DIR;
145
- return path.resolve(text);
146
- }
147
-
148
- function tailText(value: string): string | undefined {
149
- const text = String(value || "").trim();
150
- if (!text) return undefined;
151
- if (text.length <= OUTPUT_TAIL_LIMIT) return text;
152
- return text.slice(text.length - OUTPUT_TAIL_LIMIT);
153
- }
154
-
155
- export function resolveTtsVenvPythonBin(venvDir: string): string {
156
- return path.join(venvDir, "bin", "python");
157
- }
158
-
159
- /**
160
- * 返回 TTS 默认虚拟环境目录。
161
- */
162
- export function resolveDefaultTtsVenvDir(): string {
163
- return DEFAULT_VENV_DIR;
164
- }
165
-
166
- /**
167
- * 返回 TTS 默认虚拟环境 Python 路径。
168
- */
169
- export function resolveDefaultTtsVenvPythonBin(): string {
170
- return resolveTtsVenvPythonBin(DEFAULT_VENV_DIR);
171
- }
172
-
173
- /**
174
- * 判断是否为 PEP 668(externally-managed-environment)错误。
175
- */
176
- export function isPep668InstallError(text: string): boolean {
177
- const msg = String(text || "").toLowerCase();
178
- if (!msg) return false;
179
- return (
180
- msg.includes("externally-managed-environment") ||
181
- msg.includes("this environment is externally managed") ||
182
- msg.includes("pep 668") ||
183
- msg.includes("--break-system-packages")
184
- );
185
- }
186
-
187
- function dedupeRunners(runners: TtsDependencyRunner[]): TtsDependencyRunner[] {
188
- const seen = new Set<TtsDependencyRunner>();
189
- const out: TtsDependencyRunner[] = [];
190
- for (const runner of runners) {
191
- if (seen.has(runner)) continue;
192
- seen.add(runner);
193
- out.push(runner);
194
- }
195
- return out;
196
- }
197
-
198
- function getRunnerPackages(runner: TtsDependencyRunner): string[] {
199
- if (runner === "qwen3") {
200
- return ["qwen-tts", "soundfile", "torch", "torchaudio", "transformers", "accelerate"];
201
- }
202
- return ["kokoro==0.7.16", "soundfile", "misaki[zh]", "torch"];
203
- }
204
-
205
- async function checkRunnerPackagesInstalled(params: {
206
- pythonBin: string;
207
- packages: string[];
208
- timeoutMs: number;
209
- }): Promise<{
210
- installed: boolean;
211
- args: string[];
212
- command: string;
213
- }> {
214
- const args = ["-m", "pip", "show", ...params.packages.map((item) => item.replace(/\[.*\]$/, "").replace(/==.+$/, ""))];
215
- const command = [params.pythonBin, ...args].join(" ");
216
- try {
217
- await execFileAsync(params.pythonBin, args, {
218
- timeout: params.timeoutMs,
219
- maxBuffer: 8 * 1024 * 1024,
220
- });
221
- return {
222
- installed: true,
223
- args,
224
- command,
225
- };
226
- } catch {
227
- return {
228
- installed: false,
229
- args,
230
- command,
231
- };
232
- }
233
- }
234
-
235
- type RunnerInstallFailure = {
236
- runner: TtsDependencyRunner;
237
- command: string;
238
- reason: string;
239
- };
240
-
241
- type RunnerInstallAttempt =
242
- | {
243
- success: true;
244
- item: TtsDependencyInstallItem;
245
- }
246
- | {
247
- success: false;
248
- failure: RunnerInstallFailure;
249
- };
250
-
251
- async function installRunnerWithPython(params: {
252
- pythonBin: string;
253
- runner: TtsDependencyRunner;
254
- upgrade: boolean;
255
- timeoutMs: number;
256
- }): Promise<RunnerInstallAttempt> {
257
- const packages = getRunnerPackages(params.runner);
258
- const checkStartedAt = Date.now();
259
- const checkResult = await checkRunnerPackagesInstalled({
260
- pythonBin: params.pythonBin,
261
- packages,
262
- timeoutMs: params.timeoutMs,
263
- });
264
- if (checkResult.installed) {
265
- return {
266
- success: true,
267
- item: {
268
- runner: params.runner,
269
- pythonBin: params.pythonBin,
270
- args: checkResult.args,
271
- packages,
272
- command: checkResult.command,
273
- elapsedMs: Date.now() - checkStartedAt,
274
- skipped: true,
275
- skipReason: "already-installed",
276
- },
277
- };
278
- }
279
-
280
- const args = [
281
- "-m",
282
- "pip",
283
- "install",
284
- ...(params.upgrade ? ["-U"] : []),
285
- ...packages,
286
- ];
287
- const command = [params.pythonBin, ...args].join(" ");
288
- const startedAt = Date.now();
289
- try {
290
- const { stdout, stderr } = await execFileAsync(params.pythonBin, args, {
291
- timeout: params.timeoutMs,
292
- maxBuffer: 8 * 1024 * 1024,
293
- });
294
- return {
295
- success: true,
296
- item: {
297
- runner: params.runner,
298
- pythonBin: params.pythonBin,
299
- args,
300
- packages,
301
- command,
302
- elapsedMs: Date.now() - startedAt,
303
- stdoutTail: tailText(String(stdout || "")),
304
- stderrTail: tailText(String(stderr || "")),
305
- },
306
- };
307
- } catch (error) {
308
- const errorLike = error as {
309
- stdout?: string;
310
- stderr?: string;
311
- message?: string;
312
- };
313
- const reason =
314
- tailText(String(errorLike.stderr || "")) ||
315
- tailText(String(errorLike.stdout || "")) ||
316
- String(errorLike.message || error);
317
- return {
318
- success: false,
319
- failure: {
320
- runner: params.runner,
321
- command,
322
- reason,
323
- },
324
- };
325
- }
326
- }
327
-
328
- export async function ensureTtsVirtualEnv(params: {
329
- /**
330
- * 虚拟环境目录。
331
- */
332
- venvDir?: string;
333
- /**
334
- * 用于创建 venv 的基础 Python。
335
- */
336
- basePythonBin?: string;
337
- }): Promise<string> {
338
- const venvDir = normalizeVenvDir(params.venvDir);
339
- const basePythonBin = normalizePythonBin(params.basePythonBin);
340
- const pythonBin = resolveTtsVenvPythonBin(venvDir);
341
- if (await fs.pathExists(pythonBin)) {
342
- return pythonBin;
343
- }
344
- await fs.ensureDir(venvDir);
345
- await execFileAsync(basePythonBin, ["-m", "venv", venvDir], {
346
- timeout: DEFAULT_PIP_TIMEOUT_MS,
347
- maxBuffer: 8 * 1024 * 1024,
348
- });
349
- return pythonBin;
350
- }
351
-
352
- async function installAllRunners(params: {
353
- pythonBin: string;
354
- runners: TtsDependencyRunner[];
355
- upgrade: boolean;
356
- timeoutMs: number;
357
- }): Promise<{
358
- success: boolean;
359
- items: TtsDependencyInstallItem[];
360
- failures: RunnerInstallFailure[];
361
- }> {
362
- const items: TtsDependencyInstallItem[] = [];
363
- const failures: RunnerInstallFailure[] = [];
364
- for (const runner of params.runners) {
365
- const result = await installRunnerWithPython({
366
- pythonBin: params.pythonBin,
367
- runner,
368
- upgrade: params.upgrade,
369
- timeoutMs: params.timeoutMs,
370
- });
371
- if (result.success) {
372
- items.push(result.item);
373
- } else {
374
- failures.push(result.failure);
375
- }
376
- }
377
- return {
378
- success: failures.length === 0,
379
- items,
380
- failures,
381
- };
382
- }
383
-
384
- /**
385
- * 安装 TTS Python 依赖。
386
- */
387
- export async function installTtsDependencies(
388
- input: TtsDependencyInstallInput,
389
- ): Promise<TtsDependencyInstallResult> {
390
- const runners = dedupeRunners(input.runners);
391
- const basePythonBin = normalizePythonBin(input.pythonBin);
392
- const timeoutMs = normalizeTimeoutMs(input.timeoutMs);
393
- const upgrade = input.upgrade === true;
394
- const venvDir = normalizeVenvDir(input.venvDir);
395
- const venvPythonBin = await ensureTtsVirtualEnv({
396
- venvDir,
397
- basePythonBin,
398
- });
399
- const venvAttempt = await installAllRunners({
400
- pythonBin: venvPythonBin,
401
- runners,
402
- upgrade,
403
- timeoutMs,
404
- });
405
- if (!venvAttempt.success) {
406
- throw new Error(
407
- venvAttempt.failures
408
- .map((item) => `${item.runner}: ${item.reason}`)
409
- .join("\n"),
410
- );
411
- }
412
-
413
- return {
414
- pythonBin: venvPythonBin,
415
- runners,
416
- items: venvAttempt.items,
417
- usedVirtualEnv: true,
418
- venvDir,
419
- basePythonBin,
420
- };
421
- }
422
-
423
- /**
424
- * 根据模型列表推导需要安装的 runner 集合。
425
- */
426
- export function resolveTtsRunnersByModels(modelIds: TtsModelId[]): TtsDependencyRunner[] {
427
- const runners = new Set<TtsDependencyRunner>();
428
- for (const modelId of modelIds) {
429
- if (modelId === "qwen3-tts-0.6b") {
430
- runners.add("qwen3");
431
- continue;
432
- }
433
- runners.add("kokoro");
434
- }
435
- return [...runners];
436
- }