@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.
- package/bin/BuiltinPlugins.d.ts.map +1 -1
- package/bin/BuiltinPlugins.js +0 -6
- package/bin/BuiltinPlugins.js.map +1 -1
- package/bin/asr/Plugin.d.ts +67 -7
- package/bin/asr/Plugin.d.ts.map +1 -1
- package/bin/asr/Plugin.js +229 -461
- package/bin/asr/Plugin.js.map +1 -1
- package/bin/asr/types/AsrPlugin.d.ts +114 -0
- package/bin/asr/types/AsrPlugin.d.ts.map +1 -0
- package/bin/asr/types/AsrPlugin.js +10 -0
- package/bin/asr/types/AsrPlugin.js.map +1 -0
- package/bin/auth/types/AuthPlugin.d.ts +12 -16
- package/bin/auth/types/AuthPlugin.d.ts.map +1 -1
- package/bin/auth/types/AuthPlugin.js +9 -13
- package/bin/auth/types/AuthPlugin.js.map +1 -1
- package/bin/chat/ChatPlugin.d.ts +37 -6
- package/bin/chat/ChatPlugin.d.ts.map +1 -1
- package/bin/chat/ChatPlugin.js +58 -80
- package/bin/chat/ChatPlugin.js.map +1 -1
- package/bin/chat/Index.d.ts +4 -1
- package/bin/chat/Index.d.ts.map +1 -1
- package/bin/chat/Index.js +2 -1
- package/bin/chat/Index.js.map +1 -1
- package/bin/chat/channels/Configuration.d.ts +1 -1
- package/bin/chat/channels/Configuration.js +1 -1
- package/bin/chat/channels/RuntimeChannel.d.ts +145 -0
- package/bin/chat/channels/RuntimeChannel.d.ts.map +1 -0
- package/bin/chat/channels/RuntimeChannel.js +148 -0
- package/bin/chat/channels/RuntimeChannel.js.map +1 -0
- package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts +22 -0
- package/bin/chat/runtime/ChatAuthorizationRuntime.d.ts.map +1 -0
- package/bin/chat/runtime/ChatAuthorizationRuntime.js +189 -0
- package/bin/chat/runtime/ChatAuthorizationRuntime.js.map +1 -0
- package/bin/chat/runtime/ChatChannelActions.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelActions.js +19 -9
- package/bin/chat/runtime/ChatChannelActions.js.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.d.ts +2 -18
- package/bin/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelConfig.js +2 -73
- package/bin/chat/runtime/ChatChannelConfig.js.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.d.ts +22 -1
- package/bin/chat/runtime/ChatChannelCore.d.ts.map +1 -1
- package/bin/chat/runtime/ChatChannelCore.js +5 -5
- package/bin/chat/runtime/ChatChannelCore.js.map +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.js +1 -1
- package/bin/chat/runtime/ChatPluginActionRegistry.js.map +1 -1
- package/bin/chat/runtime/PluginPoints.d.ts +3 -3
- package/bin/chat/runtime/PluginPoints.js +3 -3
- package/bin/chat/types/ChannelStatus.d.ts +1 -1
- package/bin/chat/types/ChatPluginOptions.d.ts +76 -0
- package/bin/chat/types/ChatPluginOptions.d.ts.map +1 -0
- package/bin/chat/types/ChatPluginOptions.js +10 -0
- package/bin/chat/types/ChatPluginOptions.js.map +1 -0
- package/bin/image/ImagePlugin.d.ts +1 -1
- package/bin/image/ImagePlugin.d.ts.map +1 -1
- package/bin/image/ImagePlugin.js +23 -5
- package/bin/image/ImagePlugin.js.map +1 -1
- package/bin/index.d.ts +6 -3
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -2
- package/bin/index.js.map +1 -1
- package/bin/skill/Action.d.ts.map +1 -1
- package/bin/skill/Action.js +2 -2
- package/bin/skill/Action.js.map +1 -1
- package/bin/skill/Command.js +5 -5
- package/bin/skill/Command.js.map +1 -1
- package/bin/skill/Plugin.js +1 -1
- package/bin/skill/Plugin.js.map +1 -1
- package/bin/skill/runtime/Discovery.d.ts +4 -4
- package/bin/skill/runtime/Discovery.d.ts.map +1 -1
- package/bin/skill/runtime/Discovery.js +5 -5
- package/bin/skill/runtime/Discovery.js.map +1 -1
- package/bin/skill/runtime/Paths.d.ts +1 -5
- package/bin/skill/runtime/Paths.d.ts.map +1 -1
- package/bin/skill/runtime/Paths.js +1 -9
- package/bin/skill/runtime/Paths.js.map +1 -1
- package/bin/skill/runtime/Prompt.d.ts +2 -2
- package/bin/skill/runtime/Prompt.d.ts.map +1 -1
- package/bin/skill/runtime/Prompt.js +3 -3
- package/bin/skill/runtime/Prompt.js.map +1 -1
- package/bin/skill/runtime/Store.d.ts +2 -2
- package/bin/skill/runtime/Store.d.ts.map +1 -1
- package/bin/skill/runtime/Store.js.map +1 -1
- package/bin/skill/runtime/SystemProvider.js +4 -4
- package/bin/skill/runtime/SystemProvider.js.map +1 -1
- package/bin/skill/runtime/Types.d.ts +3 -3
- package/bin/skill/runtime/Types.d.ts.map +1 -1
- package/bin/skill/types/{ClaudeSkill.d.ts → SkillDefinition.d.ts} +4 -4
- package/bin/skill/types/SkillDefinition.d.ts.map +1 -0
- package/bin/skill/types/{ClaudeSkill.js → SkillDefinition.js} +2 -2
- package/bin/skill/types/SkillDefinition.js.map +1 -0
- package/bin/skill/types/SkillPlugin.d.ts +2 -2
- package/bin/skill/types/SkillPlugin.d.ts.map +1 -1
- package/bin/tts/Plugin.d.ts +53 -6
- package/bin/tts/Plugin.d.ts.map +1 -1
- package/bin/tts/Plugin.js +197 -474
- package/bin/tts/Plugin.js.map +1 -1
- package/bin/tts/types/TtsPlugin.d.ts +63 -102
- package/bin/tts/types/TtsPlugin.d.ts.map +1 -1
- package/bin/tts/types/TtsPlugin.js +4 -3
- package/bin/tts/types/TtsPlugin.js.map +1 -1
- package/bin/web/PROMPT.d.ts +1 -1
- package/bin/web/PROMPT.d.ts.map +1 -1
- package/bin/web/PROMPT.js +1 -1
- package/bin/web/PROMPT.js.map +1 -1
- package/bin/web/Plugin.d.ts +66 -5
- package/bin/web/Plugin.d.ts.map +1 -1
- package/bin/web/Plugin.js +126 -450
- package/bin/web/Plugin.js.map +1 -1
- package/bin/web/WebPromptAssets.d.ts +1 -9
- package/bin/web/WebPromptAssets.d.ts.map +1 -1
- package/bin/web/WebPromptAssets.js +1 -11
- package/bin/web/WebPromptAssets.js.map +1 -1
- package/bin/web/runtime/Install.d.ts +19 -0
- package/bin/web/runtime/Install.d.ts.map +1 -0
- package/bin/web/runtime/Install.js +178 -0
- package/bin/web/runtime/Install.js.map +1 -0
- package/bin/web/types/WebPlugin.d.ts +38 -109
- package/bin/web/types/WebPlugin.d.ts.map +1 -1
- package/bin/web/types/WebPlugin.js +5 -7
- package/bin/web/types/WebPlugin.js.map +1 -1
- package/bin/workboard/Plugin.d.ts +23 -3
- package/bin/workboard/Plugin.d.ts.map +1 -1
- package/bin/workboard/Plugin.js +66 -85
- package/bin/workboard/Plugin.js.map +1 -1
- package/package.json +2 -2
- package/src/BuiltinPlugins.ts +0 -6
- package/src/asr/Plugin.ts +264 -483
- package/src/asr/types/AsrPlugin.ts +118 -0
- package/src/auth/types/AuthPlugin.ts +12 -17
- package/src/chat/ChatPlugin.ts +92 -89
- package/src/chat/Index.ts +18 -1
- package/src/chat/channels/Configuration.ts +1 -1
- package/src/chat/channels/RuntimeChannel.ts +264 -0
- package/src/chat/runtime/ChatAuthorizationRuntime.ts +229 -0
- package/src/chat/runtime/ChatChannelActions.ts +24 -9
- package/src/chat/runtime/ChatChannelConfig.ts +2 -100
- package/src/chat/runtime/ChatChannelCore.ts +20 -8
- package/src/chat/runtime/ChatPluginActionRegistry.ts +1 -1
- package/src/chat/runtime/PluginPoints.ts +3 -3
- package/src/chat/types/ChannelStatus.ts +1 -1
- package/src/chat/types/ChatPluginOptions.ts +79 -0
- package/src/image/ImagePlugin.ts +23 -5
- package/src/index.ts +29 -6
- package/src/skill/Action.ts +10 -7
- package/src/skill/Command.ts +5 -5
- package/src/skill/Plugin.ts +1 -1
- package/src/skill/runtime/Discovery.ts +14 -11
- package/src/skill/runtime/Paths.ts +1 -13
- package/src/skill/runtime/Prompt.ts +5 -5
- package/src/skill/runtime/Store.ts +6 -3
- package/src/skill/runtime/SystemProvider.ts +4 -4
- package/src/skill/runtime/Types.ts +3 -3
- package/src/skill/types/{ClaudeSkill.ts → SkillDefinition.ts} +3 -3
- package/src/skill/types/SkillPlugin.ts +2 -2
- package/src/tts/Plugin.ts +225 -492
- package/src/tts/types/TtsPlugin.ts +67 -102
- package/src/web/PROMPT.ts +1 -1
- package/src/web/PROMPT.ts.txt +32 -6
- package/src/web/Plugin.ts +119 -453
- package/src/web/WebPromptAssets.ts +1 -13
- package/src/web/runtime/Install.ts +241 -0
- package/src/web/types/WebPlugin.ts +38 -114
- package/src/workboard/Plugin.ts +80 -95
- package/bin/asr/Config.d.ts +0 -43
- package/bin/asr/Config.d.ts.map +0 -1
- package/bin/asr/Config.js +0 -107
- package/bin/asr/Config.js.map +0 -1
- package/bin/asr/Dependency.d.ts +0 -77
- package/bin/asr/Dependency.d.ts.map +0 -1
- package/bin/asr/Dependency.js +0 -238
- package/bin/asr/Dependency.js.map +0 -1
- package/bin/asr/InboundAugment.d.ts +0 -17
- package/bin/asr/InboundAugment.d.ts.map +0 -1
- package/bin/asr/InboundAugment.js +0 -47
- package/bin/asr/InboundAugment.js.map +0 -1
- package/bin/asr/ModelCatalog.d.ts +0 -29
- package/bin/asr/ModelCatalog.d.ts.map +0 -1
- package/bin/asr/ModelCatalog.js +0 -25
- package/bin/asr/ModelCatalog.js.map +0 -1
- package/bin/auth/Plugin.d.ts +0 -17
- package/bin/auth/Plugin.d.ts.map +0 -1
- package/bin/auth/Plugin.js +0 -199
- package/bin/auth/Plugin.js.map +0 -1
- package/bin/chat/ChatPluginTypes.d.ts +0 -122
- package/bin/chat/ChatPluginTypes.d.ts.map +0 -1
- package/bin/chat/ChatPluginTypes.js +0 -10
- package/bin/chat/ChatPluginTypes.js.map +0 -1
- package/bin/skill/types/ClaudeSkill.d.ts.map +0 -1
- package/bin/skill/types/ClaudeSkill.js.map +0 -1
- package/bin/tts/Dependency.d.ts +0 -90
- package/bin/tts/Dependency.d.ts.map +0 -1
- package/bin/tts/Dependency.js +0 -344
- package/bin/tts/Dependency.js.map +0 -1
- package/bin/tts/PluginSupport.d.ts +0 -25
- package/bin/tts/PluginSupport.d.ts.map +0 -1
- package/bin/tts/PluginSupport.js +0 -72
- package/bin/tts/PluginSupport.js.map +0 -1
- package/bin/tts/runtime/Catalog.d.ts +0 -21
- package/bin/tts/runtime/Catalog.d.ts.map +0 -1
- package/bin/tts/runtime/Catalog.js +0 -90
- package/bin/tts/runtime/Catalog.js.map +0 -1
- package/bin/tts/runtime/DependencyInstaller.d.ts +0 -143
- package/bin/tts/runtime/DependencyInstaller.d.ts.map +0 -1
- package/bin/tts/runtime/DependencyInstaller.js +0 -261
- package/bin/tts/runtime/DependencyInstaller.js.map +0 -1
- package/bin/tts/runtime/Installer.d.ts +0 -89
- package/bin/tts/runtime/Installer.d.ts.map +0 -1
- package/bin/tts/runtime/Installer.js +0 -188
- package/bin/tts/runtime/Installer.js.map +0 -1
- package/bin/tts/runtime/Paths.d.ts +0 -20
- package/bin/tts/runtime/Paths.d.ts.map +0 -1
- package/bin/tts/runtime/Paths.js +0 -32
- package/bin/tts/runtime/Paths.js.map +0 -1
- package/bin/tts/runtime/Synthesizer.d.ts +0 -44
- package/bin/tts/runtime/Synthesizer.d.ts.map +0 -1
- package/bin/tts/runtime/Synthesizer.js +0 -363
- package/bin/tts/runtime/Synthesizer.js.map +0 -1
- package/bin/tts/types/Tts.d.ts +0 -91
- package/bin/tts/types/Tts.d.ts.map +0 -1
- package/bin/tts/types/Tts.js +0 -9
- package/bin/tts/types/Tts.js.map +0 -1
- package/bin/voice/Config.d.ts +0 -43
- package/bin/voice/Config.d.ts.map +0 -1
- package/bin/voice/Config.js +0 -104
- package/bin/voice/Config.js.map +0 -1
- package/bin/voice/Dependency.d.ts +0 -77
- package/bin/voice/Dependency.d.ts.map +0 -1
- package/bin/voice/Dependency.js +0 -237
- package/bin/voice/Dependency.js.map +0 -1
- package/bin/voice/InboundAugment.d.ts +0 -17
- package/bin/voice/InboundAugment.d.ts.map +0 -1
- package/bin/voice/InboundAugment.js +0 -47
- package/bin/voice/InboundAugment.js.map +0 -1
- package/bin/voice/ModelCatalog.d.ts +0 -29
- package/bin/voice/ModelCatalog.d.ts.map +0 -1
- package/bin/voice/ModelCatalog.js +0 -25
- package/bin/voice/ModelCatalog.js.map +0 -1
- package/bin/voice/runtime/Catalog.d.ts +0 -18
- package/bin/voice/runtime/Catalog.d.ts.map +0 -1
- package/bin/voice/runtime/Catalog.js +0 -61
- package/bin/voice/runtime/Catalog.js.map +0 -1
- package/bin/voice/runtime/DependencyInstaller.d.ts +0 -145
- package/bin/voice/runtime/DependencyInstaller.d.ts.map +0 -1
- package/bin/voice/runtime/DependencyInstaller.js +0 -309
- package/bin/voice/runtime/DependencyInstaller.js.map +0 -1
- package/bin/voice/runtime/Installer.d.ts +0 -94
- package/bin/voice/runtime/Installer.d.ts.map +0 -1
- package/bin/voice/runtime/Installer.js +0 -200
- package/bin/voice/runtime/Installer.js.map +0 -1
- package/bin/voice/runtime/Paths.d.ts +0 -8
- package/bin/voice/runtime/Paths.d.ts.map +0 -1
- package/bin/voice/runtime/Paths.js +0 -26
- package/bin/voice/runtime/Paths.js.map +0 -1
- package/bin/voice/runtime/Transcriber.d.ts +0 -57
- package/bin/voice/runtime/Transcriber.d.ts.map +0 -1
- package/bin/voice/runtime/Transcriber.js +0 -329
- package/bin/voice/runtime/Transcriber.js.map +0 -1
- package/bin/voice/types/Voice.d.ts +0 -58
- package/bin/voice/types/Voice.d.ts.map +0 -1
- package/bin/voice/types/Voice.js +0 -9
- package/bin/voice/types/Voice.js.map +0 -1
- package/bin/voice/types/VoicePlugin.d.ts +0 -190
- package/bin/voice/types/VoicePlugin.d.ts.map +0 -1
- package/bin/voice/types/VoicePlugin.js +0 -9
- package/bin/voice/types/VoicePlugin.js.map +0 -1
- package/bin/web/Dependency.d.ts +0 -10
- package/bin/web/Dependency.d.ts.map +0 -1
- package/bin/web/Dependency.js +0 -10
- package/bin/web/Dependency.js.map +0 -1
- package/bin/web/PROMPT.agent-browser.d.ts +0 -7
- package/bin/web/PROMPT.agent-browser.d.ts.map +0 -1
- package/bin/web/PROMPT.agent-browser.js +0 -8
- package/bin/web/PROMPT.agent-browser.js.map +0 -1
- package/bin/web/PROMPT.web-access.d.ts +0 -7
- package/bin/web/PROMPT.web-access.d.ts.map +0 -1
- package/bin/web/PROMPT.web-access.js +0 -8
- package/bin/web/PROMPT.web-access.js.map +0 -1
- package/bin/web/runtime/Config.d.ts +0 -21
- package/bin/web/runtime/Config.d.ts.map +0 -1
- package/bin/web/runtime/Config.js +0 -79
- package/bin/web/runtime/Config.js.map +0 -1
- package/bin/web/runtime/Source.d.ts +0 -29
- package/bin/web/runtime/Source.d.ts.map +0 -1
- package/bin/web/runtime/Source.js +0 -209
- package/bin/web/runtime/Source.js.map +0 -1
- package/src/asr/Config.ts +0 -138
- package/src/asr/Dependency.ts +0 -336
- package/src/asr/InboundAugment.ts +0 -59
- package/src/asr/ModelCatalog.ts +0 -43
- package/src/auth/Plugin.ts +0 -237
- package/src/chat/ChatPluginTypes.ts +0 -126
- package/src/tts/Dependency.ts +0 -473
- package/src/tts/PluginSupport.ts +0 -85
- package/src/tts/runtime/Catalog.ts +0 -97
- package/src/tts/runtime/DependencyInstaller.ts +0 -436
- package/src/tts/runtime/Installer.ts +0 -297
- package/src/tts/runtime/Paths.ts +0 -39
- package/src/tts/runtime/Synthesizer.ts +0 -480
- package/src/tts/types/Tts.ts +0 -99
- package/src/voice/Config.ts +0 -135
- package/src/voice/Dependency.ts +0 -329
- package/src/voice/InboundAugment.ts +0 -59
- package/src/voice/ModelCatalog.ts +0 -43
- package/src/voice/runtime/Catalog.ts +0 -68
- package/src/voice/runtime/DependencyInstaller.ts +0 -505
- package/src/voice/runtime/Installer.ts +0 -324
- package/src/voice/runtime/Paths.ts +0 -26
- package/src/voice/runtime/Transcriber.ts +0 -467
- package/src/voice/types/Voice.ts +0 -68
- package/src/voice/types/VoicePlugin.ts +0 -194
- package/src/web/Dependency.ts +0 -17
- package/src/web/PROMPT.agent-browser.ts +0 -9
- package/src/web/PROMPT.agent-browser.ts.txt +0 -17
- package/src/web/PROMPT.web-access.ts +0 -9
- package/src/web/PROMPT.web-access.ts.txt +0 -13
- package/src/web/runtime/Config.ts +0 -105
- package/src/web/runtime/Source.ts +0 -257
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Voice 转写依赖安装器。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 统一管理 `town voice` 的 Python 依赖安装逻辑。
|
|
6
|
-
* - 根据模型自动推导 runner(funasr / transformers-whisper)并执行 `python -m pip install`。
|
|
7
|
-
* - 返回结构化安装结果,供 CLI/日志/测试复用。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { execFile as execFileCb } from "node:child_process";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import path from "node:path";
|
|
13
|
-
import { promisify } from "node:util";
|
|
14
|
-
import fs from "fs-extra";
|
|
15
|
-
import type { VoiceModelId, VoiceTranscribeStrategy } from "@/voice/types/Voice.js";
|
|
16
|
-
|
|
17
|
-
const execFileAsync = promisify(execFileCb);
|
|
18
|
-
|
|
19
|
-
const DEFAULT_PYTHON_BIN = "python3";
|
|
20
|
-
const DEFAULT_PIP_TIMEOUT_MS = 300_000;
|
|
21
|
-
const OUTPUT_TAIL_LIMIT = 1200;
|
|
22
|
-
const DEFAULT_VENV_DIR = path.join(os.homedir(), ".downcity", "venvs", "voice");
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Voice 依赖 runner 类型。
|
|
26
|
-
*/
|
|
27
|
-
export type VoiceDependencyRunner = "funasr" | "transformers-whisper";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 单个 runner 的安装摘要。
|
|
31
|
-
*/
|
|
32
|
-
export interface VoiceDependencyInstallItem {
|
|
33
|
-
/**
|
|
34
|
-
* 当前安装 runner。
|
|
35
|
-
*/
|
|
36
|
-
runner: VoiceDependencyRunner;
|
|
37
|
-
/**
|
|
38
|
-
* Python 可执行文件。
|
|
39
|
-
*/
|
|
40
|
-
pythonBin: string;
|
|
41
|
-
/**
|
|
42
|
-
* 执行参数(不含 pythonBin)。
|
|
43
|
-
*/
|
|
44
|
-
args: string[];
|
|
45
|
-
/**
|
|
46
|
-
* 安装包列表。
|
|
47
|
-
*/
|
|
48
|
-
packages: string[];
|
|
49
|
-
/**
|
|
50
|
-
* 实际执行的命令行(便于排查)。
|
|
51
|
-
*/
|
|
52
|
-
command: string;
|
|
53
|
-
/**
|
|
54
|
-
* 执行耗时(毫秒)。
|
|
55
|
-
*/
|
|
56
|
-
elapsedMs: number;
|
|
57
|
-
/**
|
|
58
|
-
* 是否跳过安装。
|
|
59
|
-
*
|
|
60
|
-
* 说明(中文)
|
|
61
|
-
* - `true` 表示依赖已存在,仅做检查,不再重复安装。
|
|
62
|
-
* - `false` 或缺省表示执行了实际安装。
|
|
63
|
-
*/
|
|
64
|
-
skipped?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* 跳过原因(可选)。
|
|
67
|
-
*/
|
|
68
|
-
skipReason?: string;
|
|
69
|
-
/**
|
|
70
|
-
* stdout 尾部(可选)。
|
|
71
|
-
*/
|
|
72
|
-
stdoutTail?: string;
|
|
73
|
-
/**
|
|
74
|
-
* stderr 尾部(可选)。
|
|
75
|
-
*/
|
|
76
|
-
stderrTail?: string;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 依赖安装结果。
|
|
81
|
-
*/
|
|
82
|
-
export interface VoiceDependencyInstallResult {
|
|
83
|
-
/**
|
|
84
|
-
* 本次使用的 Python 可执行文件。
|
|
85
|
-
*/
|
|
86
|
-
pythonBin: string;
|
|
87
|
-
/**
|
|
88
|
-
* 本次处理的 runner 列表。
|
|
89
|
-
*/
|
|
90
|
-
runners: VoiceDependencyRunner[];
|
|
91
|
-
/**
|
|
92
|
-
* 各 runner 的安装摘要。
|
|
93
|
-
*/
|
|
94
|
-
items: VoiceDependencyInstallItem[];
|
|
95
|
-
/**
|
|
96
|
-
* 是否使用了虚拟环境安装。
|
|
97
|
-
*/
|
|
98
|
-
usedVirtualEnv: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* 虚拟环境目录(仅 `usedVirtualEnv=true` 时存在)。
|
|
101
|
-
*/
|
|
102
|
-
venvDir?: string;
|
|
103
|
-
/**
|
|
104
|
-
* 初始尝试使用的 Python(仅进入虚拟环境回退时存在)。
|
|
105
|
-
*/
|
|
106
|
-
basePythonBin?: string;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 依赖安装输入参数。
|
|
111
|
-
*/
|
|
112
|
-
export interface VoiceDependencyInstallInput {
|
|
113
|
-
/**
|
|
114
|
-
* Python 可执行文件(默认 `python3`)。
|
|
115
|
-
*/
|
|
116
|
-
pythonBin?: string;
|
|
117
|
-
/**
|
|
118
|
-
* 需要安装的 runner 列表。
|
|
119
|
-
*/
|
|
120
|
-
runners: VoiceDependencyRunner[];
|
|
121
|
-
/**
|
|
122
|
-
* 是否使用 `pip -U` 升级。
|
|
123
|
-
*/
|
|
124
|
-
upgrade?: boolean;
|
|
125
|
-
/**
|
|
126
|
-
* pip 安装超时(毫秒)。
|
|
127
|
-
*/
|
|
128
|
-
timeoutMs?: number;
|
|
129
|
-
/**
|
|
130
|
-
* 虚拟环境目录(可选)。
|
|
131
|
-
*
|
|
132
|
-
* 说明(中文)
|
|
133
|
-
* - 当系统 Python 命中 PEP 668(不允许全局 pip install)时,自动回退到该目录。
|
|
134
|
-
* - 默认 `~/.downcity/venvs/voice`。
|
|
135
|
-
*/
|
|
136
|
-
venvDir?: string;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function normalizePythonBin(input?: string): string {
|
|
140
|
-
const text = String(input || "").trim();
|
|
141
|
-
return text || DEFAULT_PYTHON_BIN;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function normalizeTimeoutMs(value?: number): number {
|
|
145
|
-
if (!Number.isFinite(value as number)) return DEFAULT_PIP_TIMEOUT_MS;
|
|
146
|
-
const ms = Math.floor(Number(value));
|
|
147
|
-
if (ms < 5_000) return 5_000;
|
|
148
|
-
if (ms > 1_800_000) return 1_800_000;
|
|
149
|
-
return ms;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function normalizeVenvDir(input?: string): string {
|
|
153
|
-
const text = String(input || "").trim();
|
|
154
|
-
if (!text) return DEFAULT_VENV_DIR;
|
|
155
|
-
return path.resolve(text);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function tailText(value: string): string | undefined {
|
|
159
|
-
const text = String(value || "").trim();
|
|
160
|
-
if (!text) return undefined;
|
|
161
|
-
if (text.length <= OUTPUT_TAIL_LIMIT) return text;
|
|
162
|
-
return text.slice(text.length - OUTPUT_TAIL_LIMIT);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function resolveVenvPythonBin(venvDir: string): string {
|
|
166
|
-
return path.join(venvDir, "bin", "python");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* 判断是否为 PEP 668(externally-managed-environment)错误。
|
|
171
|
-
*/
|
|
172
|
-
export function isPep668InstallError(text: string): boolean {
|
|
173
|
-
const msg = String(text || "").toLowerCase();
|
|
174
|
-
if (!msg) return false;
|
|
175
|
-
return (
|
|
176
|
-
msg.includes("externally-managed-environment") ||
|
|
177
|
-
msg.includes("this environment is externally managed") ||
|
|
178
|
-
msg.includes("pep 668") ||
|
|
179
|
-
msg.includes("--break-system-packages")
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function dedupeRunners(runners: VoiceDependencyRunner[]): VoiceDependencyRunner[] {
|
|
184
|
-
const seen = new Set<VoiceDependencyRunner>();
|
|
185
|
-
const out: VoiceDependencyRunner[] = [];
|
|
186
|
-
for (const runner of runners) {
|
|
187
|
-
if (seen.has(runner)) continue;
|
|
188
|
-
seen.add(runner);
|
|
189
|
-
out.push(runner);
|
|
190
|
-
}
|
|
191
|
-
return out;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function getRunnerPackages(runner: VoiceDependencyRunner): string[] {
|
|
195
|
-
if (runner === "funasr") {
|
|
196
|
-
// 关键点(中文):FunASR 在常见语音模型推理路径会依赖 torch/torchaudio。
|
|
197
|
-
// 仅安装 funasr 会在转写阶段触发 `ModuleNotFoundError: torch`。
|
|
198
|
-
return ["funasr", "torch", "torchaudio"];
|
|
199
|
-
}
|
|
200
|
-
return ["transformers", "torch", "torchaudio"];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async function checkRunnerPackagesInstalled(params: {
|
|
204
|
-
pythonBin: string;
|
|
205
|
-
packages: string[];
|
|
206
|
-
timeoutMs: number;
|
|
207
|
-
}): Promise<{
|
|
208
|
-
installed: boolean;
|
|
209
|
-
args: string[];
|
|
210
|
-
command: string;
|
|
211
|
-
}> {
|
|
212
|
-
const args = ["-m", "pip", "show", ...params.packages];
|
|
213
|
-
const command = [params.pythonBin, ...args].join(" ");
|
|
214
|
-
try {
|
|
215
|
-
await execFileAsync(params.pythonBin, args, {
|
|
216
|
-
timeout: params.timeoutMs,
|
|
217
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
218
|
-
});
|
|
219
|
-
return {
|
|
220
|
-
installed: true,
|
|
221
|
-
args,
|
|
222
|
-
command,
|
|
223
|
-
};
|
|
224
|
-
} catch {
|
|
225
|
-
return {
|
|
226
|
-
installed: false,
|
|
227
|
-
args,
|
|
228
|
-
command,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
type RunnerInstallFailure = {
|
|
234
|
-
runner: VoiceDependencyRunner;
|
|
235
|
-
command: string;
|
|
236
|
-
reason: string;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
type RunnerInstallAttempt =
|
|
240
|
-
| {
|
|
241
|
-
success: true;
|
|
242
|
-
item: VoiceDependencyInstallItem;
|
|
243
|
-
}
|
|
244
|
-
| {
|
|
245
|
-
success: false;
|
|
246
|
-
failure: RunnerInstallFailure;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
async function installRunnerWithPython(params: {
|
|
250
|
-
pythonBin: string;
|
|
251
|
-
runner: VoiceDependencyRunner;
|
|
252
|
-
upgrade: boolean;
|
|
253
|
-
timeoutMs: number;
|
|
254
|
-
}): Promise<RunnerInstallAttempt> {
|
|
255
|
-
const packages = getRunnerPackages(params.runner);
|
|
256
|
-
const checkStartedAt = Date.now();
|
|
257
|
-
const checkResult = await checkRunnerPackagesInstalled({
|
|
258
|
-
pythonBin: params.pythonBin,
|
|
259
|
-
packages,
|
|
260
|
-
timeoutMs: params.timeoutMs,
|
|
261
|
-
});
|
|
262
|
-
if (checkResult.installed) {
|
|
263
|
-
return {
|
|
264
|
-
success: true,
|
|
265
|
-
item: {
|
|
266
|
-
runner: params.runner,
|
|
267
|
-
pythonBin: params.pythonBin,
|
|
268
|
-
args: checkResult.args,
|
|
269
|
-
packages,
|
|
270
|
-
command: checkResult.command,
|
|
271
|
-
elapsedMs: Date.now() - checkStartedAt,
|
|
272
|
-
skipped: true,
|
|
273
|
-
skipReason: "already-installed",
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const args = [
|
|
279
|
-
"-m",
|
|
280
|
-
"pip",
|
|
281
|
-
"install",
|
|
282
|
-
...(params.upgrade ? ["-U"] : []),
|
|
283
|
-
...packages,
|
|
284
|
-
];
|
|
285
|
-
const command = [params.pythonBin, ...args].join(" ");
|
|
286
|
-
const startedAt = Date.now();
|
|
287
|
-
try {
|
|
288
|
-
const { stdout, stderr } = await execFileAsync(params.pythonBin, args, {
|
|
289
|
-
timeout: params.timeoutMs,
|
|
290
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
291
|
-
});
|
|
292
|
-
return {
|
|
293
|
-
success: true,
|
|
294
|
-
item: {
|
|
295
|
-
runner: params.runner,
|
|
296
|
-
pythonBin: params.pythonBin,
|
|
297
|
-
args,
|
|
298
|
-
packages,
|
|
299
|
-
command,
|
|
300
|
-
elapsedMs: Date.now() - startedAt,
|
|
301
|
-
...(tailText(String(stdout || ""))
|
|
302
|
-
? { stdoutTail: tailText(String(stdout || "")) }
|
|
303
|
-
: {}),
|
|
304
|
-
...(tailText(String(stderr || ""))
|
|
305
|
-
? { stderrTail: tailText(String(stderr || "")) }
|
|
306
|
-
: {}),
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
} catch (error) {
|
|
310
|
-
const errorLike = error as {
|
|
311
|
-
stdout?: string;
|
|
312
|
-
stderr?: string;
|
|
313
|
-
message?: string;
|
|
314
|
-
};
|
|
315
|
-
const stdoutTail = tailText(String(errorLike.stdout || ""));
|
|
316
|
-
const stderrTail = tailText(String(errorLike.stderr || ""));
|
|
317
|
-
const reason = stderrTail || stdoutTail || String(errorLike.message || error);
|
|
318
|
-
return {
|
|
319
|
-
success: false,
|
|
320
|
-
failure: {
|
|
321
|
-
runner: params.runner,
|
|
322
|
-
command,
|
|
323
|
-
reason,
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
async function installAllRunnersWithPython(params: {
|
|
330
|
-
pythonBin: string;
|
|
331
|
-
runners: VoiceDependencyRunner[];
|
|
332
|
-
upgrade: boolean;
|
|
333
|
-
timeoutMs: number;
|
|
334
|
-
}): Promise<
|
|
335
|
-
| {
|
|
336
|
-
success: true;
|
|
337
|
-
items: VoiceDependencyInstallItem[];
|
|
338
|
-
}
|
|
339
|
-
| {
|
|
340
|
-
success: false;
|
|
341
|
-
failure: RunnerInstallFailure;
|
|
342
|
-
}
|
|
343
|
-
> {
|
|
344
|
-
const items: VoiceDependencyInstallItem[] = [];
|
|
345
|
-
for (const runner of params.runners) {
|
|
346
|
-
const attempt = await installRunnerWithPython({
|
|
347
|
-
pythonBin: params.pythonBin,
|
|
348
|
-
runner,
|
|
349
|
-
upgrade: params.upgrade,
|
|
350
|
-
timeoutMs: params.timeoutMs,
|
|
351
|
-
});
|
|
352
|
-
if (!attempt.success) {
|
|
353
|
-
return {
|
|
354
|
-
success: false,
|
|
355
|
-
failure: attempt.failure,
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
items.push(attempt.item);
|
|
359
|
-
}
|
|
360
|
-
return {
|
|
361
|
-
success: true,
|
|
362
|
-
items,
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
function formatRunnerInstallFailure(failure: RunnerInstallFailure): string {
|
|
367
|
-
return `Failed to install voice dependencies for runner "${failure.runner}" via "${failure.command}": ${failure.reason}`;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
async function ensureVoiceVirtualEnvPython(params: {
|
|
371
|
-
basePythonBin: string;
|
|
372
|
-
venvDir: string;
|
|
373
|
-
timeoutMs: number;
|
|
374
|
-
}): Promise<string> {
|
|
375
|
-
await fs.ensureDir(path.dirname(params.venvDir));
|
|
376
|
-
const createArgs = ["-m", "venv", params.venvDir];
|
|
377
|
-
const createCommand = [params.basePythonBin, ...createArgs].join(" ");
|
|
378
|
-
try {
|
|
379
|
-
await execFileAsync(params.basePythonBin, createArgs, {
|
|
380
|
-
timeout: params.timeoutMs,
|
|
381
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
382
|
-
});
|
|
383
|
-
} catch (error) {
|
|
384
|
-
const errorLike = error as {
|
|
385
|
-
stdout?: string;
|
|
386
|
-
stderr?: string;
|
|
387
|
-
message?: string;
|
|
388
|
-
};
|
|
389
|
-
const stdoutTail = tailText(String(errorLike.stdout || ""));
|
|
390
|
-
const stderrTail = tailText(String(errorLike.stderr || ""));
|
|
391
|
-
const reason = stderrTail || stdoutTail || String(errorLike.message || error);
|
|
392
|
-
throw new Error(
|
|
393
|
-
`Failed to create voice virtual environment via "${createCommand}": ${reason}`,
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const venvPythonBin = resolveVenvPythonBin(params.venvDir);
|
|
398
|
-
const upgradePipArgs = ["-m", "pip", "install", "-U", "pip"];
|
|
399
|
-
const upgradePipCommand = [venvPythonBin, ...upgradePipArgs].join(" ");
|
|
400
|
-
try {
|
|
401
|
-
await execFileAsync(venvPythonBin, upgradePipArgs, {
|
|
402
|
-
timeout: params.timeoutMs,
|
|
403
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
404
|
-
});
|
|
405
|
-
} catch (error) {
|
|
406
|
-
const errorLike = error as {
|
|
407
|
-
stdout?: string;
|
|
408
|
-
stderr?: string;
|
|
409
|
-
message?: string;
|
|
410
|
-
};
|
|
411
|
-
const stdoutTail = tailText(String(errorLike.stdout || ""));
|
|
412
|
-
const stderrTail = tailText(String(errorLike.stderr || ""));
|
|
413
|
-
const reason = stderrTail || stdoutTail || String(errorLike.message || error);
|
|
414
|
-
throw new Error(
|
|
415
|
-
`Failed to upgrade pip in voice virtual environment via "${upgradePipCommand}": ${reason}`,
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
return venvPythonBin;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* 根据模型推导推荐 runner。
|
|
424
|
-
*/
|
|
425
|
-
export function resolveVoiceRunnerByModel(modelId: VoiceModelId): VoiceDependencyRunner {
|
|
426
|
-
if (modelId === "whisper-large-v3-turbo") return "transformers-whisper";
|
|
427
|
-
return "funasr";
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* 根据模型列表推导去重后的 runner 列表。
|
|
432
|
-
*/
|
|
433
|
-
export function resolveVoiceRunnersByModels(
|
|
434
|
-
modelIds: VoiceModelId[],
|
|
435
|
-
): VoiceDependencyRunner[] {
|
|
436
|
-
return dedupeRunners(modelIds.map((modelId) => resolveVoiceRunnerByModel(modelId)));
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* 根据模型推导推荐转写策略。
|
|
441
|
-
*/
|
|
442
|
-
export function resolveVoiceStrategyByModel(modelId: VoiceModelId): VoiceTranscribeStrategy {
|
|
443
|
-
if (modelId === "whisper-large-v3-turbo") return "transformers-whisper";
|
|
444
|
-
return "funasr";
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* 安装 Voice 转写依赖。
|
|
449
|
-
*
|
|
450
|
-
* 关键点(中文)
|
|
451
|
-
* - 逐个 runner 执行 pip 安装,任一失败即抛错。
|
|
452
|
-
* - 错误信息携带 stderr/stdout 尾部,便于用户快速定位。
|
|
453
|
-
*/
|
|
454
|
-
export async function installVoiceTranscribeDependencies(
|
|
455
|
-
input: VoiceDependencyInstallInput,
|
|
456
|
-
): Promise<VoiceDependencyInstallResult> {
|
|
457
|
-
const basePythonBin = normalizePythonBin(input.pythonBin);
|
|
458
|
-
const timeoutMs = normalizeTimeoutMs(input.timeoutMs);
|
|
459
|
-
const upgrade = input.upgrade !== false;
|
|
460
|
-
const runners = dedupeRunners(input.runners || []);
|
|
461
|
-
const firstAttempt = await installAllRunnersWithPython({
|
|
462
|
-
pythonBin: basePythonBin,
|
|
463
|
-
runners,
|
|
464
|
-
upgrade,
|
|
465
|
-
timeoutMs,
|
|
466
|
-
});
|
|
467
|
-
if (firstAttempt.success) {
|
|
468
|
-
return {
|
|
469
|
-
pythonBin: basePythonBin,
|
|
470
|
-
runners,
|
|
471
|
-
items: firstAttempt.items,
|
|
472
|
-
usedVirtualEnv: false,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (!isPep668InstallError(firstAttempt.failure.reason)) {
|
|
477
|
-
throw new Error(formatRunnerInstallFailure(firstAttempt.failure));
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// 关键点(中文):命中 PEP 668 时自动回退到独立 venv,避免要求用户手工排障。
|
|
481
|
-
const venvDir = normalizeVenvDir(input.venvDir);
|
|
482
|
-
const venvPythonBin = await ensureVoiceVirtualEnvPython({
|
|
483
|
-
basePythonBin,
|
|
484
|
-
venvDir,
|
|
485
|
-
timeoutMs,
|
|
486
|
-
});
|
|
487
|
-
const venvAttempt = await installAllRunnersWithPython({
|
|
488
|
-
pythonBin: venvPythonBin,
|
|
489
|
-
runners,
|
|
490
|
-
upgrade,
|
|
491
|
-
timeoutMs,
|
|
492
|
-
});
|
|
493
|
-
if (!venvAttempt.success) {
|
|
494
|
-
throw new Error(formatRunnerInstallFailure(venvAttempt.failure));
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return {
|
|
498
|
-
pythonBin: venvPythonBin,
|
|
499
|
-
runners,
|
|
500
|
-
items: venvAttempt.items,
|
|
501
|
-
usedVirtualEnv: true,
|
|
502
|
-
venvDir,
|
|
503
|
-
basePythonBin,
|
|
504
|
-
};
|
|
505
|
-
}
|