@downcity/plugins 1.0.56 → 1.0.57
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 -4
- 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/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 +2 -0
- package/bin/index.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 +37 -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/package.json +2 -2
- package/src/BuiltinPlugins.ts +0 -4
- package/src/asr/Plugin.ts +264 -483
- package/src/asr/types/AsrPlugin.ts +118 -0
- package/src/image/ImagePlugin.ts +23 -5
- package/src/index.ts +12 -0
- 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 +37 -113
- 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/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/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
package/src/asr/Dependency.ts
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ASR Plugin Dependency Helper。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - ASR 的转写依赖现在内聚在 plugin 内部,不再暴露独立依赖端口心智。
|
|
6
|
-
* - 这里统一管理检查、安装、配置读写与转写句柄解析。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { execFile as execFileCb } from "node:child_process";
|
|
10
|
-
import { promisify } from "node:util";
|
|
11
|
-
import type { JsonObject, JsonValue } from "@downcity/agent/internal/types/common/Json.js";
|
|
12
|
-
import type { PluginCommandContext } from "@downcity/agent/internal/plugin/types/Plugin.js";
|
|
13
|
-
import type {
|
|
14
|
-
VoicePluginConfig,
|
|
15
|
-
VoiceTranscriberConfig,
|
|
16
|
-
VoiceTranscriberInstallInput,
|
|
17
|
-
VoiceTranscriberHandle,
|
|
18
|
-
} from "@/voice/types/VoicePlugin.js";
|
|
19
|
-
import { transcribeVoiceAudio } from "@/voice/runtime/Transcriber.js";
|
|
20
|
-
import {
|
|
21
|
-
VOICE_MODEL_CATALOG,
|
|
22
|
-
resolveVoiceModelId,
|
|
23
|
-
} from "@/voice/runtime/Catalog.js";
|
|
24
|
-
import {
|
|
25
|
-
detectLocalVoiceModelInstallState,
|
|
26
|
-
installVoiceModelFromHuggingFace,
|
|
27
|
-
} from "@/voice/runtime/Installer.js";
|
|
28
|
-
import {
|
|
29
|
-
installVoiceTranscribeDependencies,
|
|
30
|
-
resolveVoiceRunnersByModels,
|
|
31
|
-
resolveVoiceStrategyByModel,
|
|
32
|
-
} from "@/voice/runtime/DependencyInstaller.js";
|
|
33
|
-
import { resolveVoiceModelsRootDir } from "@/voice/runtime/Paths.js";
|
|
34
|
-
import type { VoiceModelId } from "@/voice/types/Voice.js";
|
|
35
|
-
|
|
36
|
-
const execFileAsync = promisify(execFileCb);
|
|
37
|
-
|
|
38
|
-
export interface VoiceDependencyCheckResult {
|
|
39
|
-
/**
|
|
40
|
-
* 当前依赖是否可用。
|
|
41
|
-
*/
|
|
42
|
-
available: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* 不可用原因列表。
|
|
45
|
-
*/
|
|
46
|
-
reasons: string[];
|
|
47
|
-
/**
|
|
48
|
-
* 结构化附加数据(可选)。
|
|
49
|
-
*/
|
|
50
|
-
details?: JsonValue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface VoiceDependencyInstallResult {
|
|
54
|
-
/**
|
|
55
|
-
* 安装是否成功。
|
|
56
|
-
*/
|
|
57
|
-
success: boolean;
|
|
58
|
-
/**
|
|
59
|
-
* 人类可读消息(可选)。
|
|
60
|
-
*/
|
|
61
|
-
message?: string;
|
|
62
|
-
/**
|
|
63
|
-
* 结构化附加数据(可选)。
|
|
64
|
-
*/
|
|
65
|
-
details?: JsonValue;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function readVoicePluginRecord(context: PluginCommandContext): Record<string, unknown> {
|
|
69
|
-
const current = context.config.plugins?.asr;
|
|
70
|
-
if (!current || typeof current !== "object" || Array.isArray(current)) {
|
|
71
|
-
return {};
|
|
72
|
-
}
|
|
73
|
-
return current as Record<string, unknown>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function toJsonObject(input: Record<string, unknown> | null | undefined): JsonObject {
|
|
77
|
-
const out: JsonObject = {};
|
|
78
|
-
if (!input) return out;
|
|
79
|
-
for (const [key, value] of Object.entries(input)) {
|
|
80
|
-
if (value === undefined) continue;
|
|
81
|
-
if (
|
|
82
|
-
value === null ||
|
|
83
|
-
typeof value === "string" ||
|
|
84
|
-
typeof value === "number" ||
|
|
85
|
-
typeof value === "boolean"
|
|
86
|
-
) {
|
|
87
|
-
out[key] = value;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (Array.isArray(value)) {
|
|
91
|
-
out[key] = value
|
|
92
|
-
.filter((item) => item !== undefined)
|
|
93
|
-
.map((item) => item as JsonValue);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (typeof value === "object") {
|
|
97
|
-
out[key] = toJsonObject(value as Record<string, unknown>);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return out;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 读取 ASR 转写依赖配置。
|
|
105
|
-
*/
|
|
106
|
-
export function readVoiceTranscriberConfig(
|
|
107
|
-
context: PluginCommandContext,
|
|
108
|
-
): VoiceTranscriberConfig {
|
|
109
|
-
const { enabled: _ignoredEnabled, ...current } = readVoicePluginRecord(
|
|
110
|
-
context,
|
|
111
|
-
) as Record<string, unknown> & {
|
|
112
|
-
enabled?: boolean;
|
|
113
|
-
};
|
|
114
|
-
return {
|
|
115
|
-
provider: "local",
|
|
116
|
-
...(current as VoiceTranscriberConfig),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* 写入 ASR 转写依赖配置。
|
|
122
|
-
*/
|
|
123
|
-
export async function writeVoiceTranscriberConfig(params: {
|
|
124
|
-
context: PluginCommandContext;
|
|
125
|
-
value: Partial<VoiceTranscriberConfig>;
|
|
126
|
-
}): Promise<VoicePluginConfig> {
|
|
127
|
-
if (!params.context.config.plugins) {
|
|
128
|
-
params.context.config.plugins = {};
|
|
129
|
-
}
|
|
130
|
-
const current = readVoicePluginRecord(params.context);
|
|
131
|
-
const next: Record<string, unknown> & {
|
|
132
|
-
enabled?: boolean;
|
|
133
|
-
} = {
|
|
134
|
-
...current,
|
|
135
|
-
...params.value,
|
|
136
|
-
};
|
|
137
|
-
delete next.enabled;
|
|
138
|
-
params.context.config.plugins.asr = toJsonObject(next);
|
|
139
|
-
await params.context.pluginConfig.persistProjectPlugins(params.context.config.plugins);
|
|
140
|
-
return params.context.config.plugins.asr as VoicePluginConfig;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
async function checkLocalProviderAvailability(
|
|
144
|
-
context: PluginCommandContext,
|
|
145
|
-
config: VoiceTranscriberConfig,
|
|
146
|
-
): Promise<VoiceDependencyCheckResult> {
|
|
147
|
-
const reasons: string[] = [];
|
|
148
|
-
const modelId = resolveVoiceModelId(String(config.modelId || ""));
|
|
149
|
-
if (!modelId) {
|
|
150
|
-
reasons.push("asr transcriber modelId is missing");
|
|
151
|
-
return {
|
|
152
|
-
available: false,
|
|
153
|
-
reasons,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const modelsRootDir = resolveVoiceModelsRootDir({
|
|
158
|
-
projectRoot: context.rootPath,
|
|
159
|
-
modelsDir: config.modelsDir,
|
|
160
|
-
});
|
|
161
|
-
const installState = await detectLocalVoiceModelInstallState({
|
|
162
|
-
modelId,
|
|
163
|
-
modelsRootDir,
|
|
164
|
-
});
|
|
165
|
-
if (!installState.installed) {
|
|
166
|
-
reasons.push(`asr model is not installed: ${modelId}`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const pythonBin = String(config.pythonBin || "").trim() || "python3";
|
|
170
|
-
try {
|
|
171
|
-
await execFileAsync(pythonBin, ["--version"], {
|
|
172
|
-
timeout: 15_000,
|
|
173
|
-
maxBuffer: 1024 * 1024,
|
|
174
|
-
});
|
|
175
|
-
} catch (error) {
|
|
176
|
-
reasons.push(`python runtime missing: ${String(error)}`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return {
|
|
180
|
-
available: reasons.length === 0,
|
|
181
|
-
reasons,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* 检查 ASR 转写依赖可用性。
|
|
187
|
-
*/
|
|
188
|
-
export async function checkVoiceTranscriber(
|
|
189
|
-
context: PluginCommandContext,
|
|
190
|
-
): Promise<VoiceDependencyCheckResult> {
|
|
191
|
-
const config = readVoiceTranscriberConfig(context);
|
|
192
|
-
if (config.provider === "command") {
|
|
193
|
-
const command = String(config.command || "").trim();
|
|
194
|
-
return {
|
|
195
|
-
available: Boolean(command),
|
|
196
|
-
reasons: command ? [] : ["asr transcriber command is missing"],
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
return checkLocalProviderAvailability(context, config);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* 安装或修复 ASR 转写依赖。
|
|
204
|
-
*/
|
|
205
|
-
export async function installVoiceTranscriber(params: {
|
|
206
|
-
context: PluginCommandContext;
|
|
207
|
-
input?: VoiceTranscriberInstallInput;
|
|
208
|
-
}): Promise<VoiceDependencyInstallResult> {
|
|
209
|
-
const context = params.context;
|
|
210
|
-
const input = params.input;
|
|
211
|
-
const config = readVoiceTranscriberConfig(context);
|
|
212
|
-
if (config.provider === "command") {
|
|
213
|
-
return {
|
|
214
|
-
success: true,
|
|
215
|
-
message: "asr command provider does not require install",
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const requestedModelIds =
|
|
220
|
-
(Array.isArray(input?.modelIds) ? input?.modelIds : [])
|
|
221
|
-
.map((item) => resolveVoiceModelId(String(item || "").trim()))
|
|
222
|
-
.filter((item): item is VoiceModelId => Boolean(item));
|
|
223
|
-
const selectedModelIds: VoiceModelId[] =
|
|
224
|
-
requestedModelIds.length > 0
|
|
225
|
-
? requestedModelIds
|
|
226
|
-
: [resolveVoiceModelId(String(config.modelId || "SenseVoiceSmall")) || "SenseVoiceSmall"];
|
|
227
|
-
|
|
228
|
-
const modelsRootDir = resolveVoiceModelsRootDir({
|
|
229
|
-
projectRoot: context.rootPath,
|
|
230
|
-
modelsDir: input?.modelsDir || config.modelsDir,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
for (const modelId of selectedModelIds) {
|
|
234
|
-
const model = VOICE_MODEL_CATALOG.find((item) => item.id === modelId);
|
|
235
|
-
if (!model) {
|
|
236
|
-
throw new Error(`Unsupported asr model: ${modelId}`);
|
|
237
|
-
}
|
|
238
|
-
const installState = await detectLocalVoiceModelInstallState({
|
|
239
|
-
modelId,
|
|
240
|
-
modelsRootDir,
|
|
241
|
-
});
|
|
242
|
-
if (!installState.installed || input?.force === true) {
|
|
243
|
-
await installVoiceModelFromHuggingFace({
|
|
244
|
-
model,
|
|
245
|
-
modelsRootDir,
|
|
246
|
-
force: input?.force === true,
|
|
247
|
-
hfToken: input?.hfToken,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (input?.installDeps !== false) {
|
|
253
|
-
await installVoiceTranscribeDependencies({
|
|
254
|
-
pythonBin:
|
|
255
|
-
String(input?.pythonBin || config.pythonBin || "").trim() || "python3",
|
|
256
|
-
runners: resolveVoiceRunnersByModels(selectedModelIds),
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const activeModelId =
|
|
261
|
-
resolveVoiceModelId(String(input?.activeModel || "")) ||
|
|
262
|
-
selectedModelIds[0];
|
|
263
|
-
|
|
264
|
-
const nextConfig: VoiceTranscriberConfig = {
|
|
265
|
-
...config,
|
|
266
|
-
provider: "local",
|
|
267
|
-
modelId: activeModelId,
|
|
268
|
-
modelsDir: modelsRootDir,
|
|
269
|
-
pythonBin:
|
|
270
|
-
String(input?.pythonBin || config.pythonBin || "").trim() || undefined,
|
|
271
|
-
...(config.command ? { command: config.command } : {}),
|
|
272
|
-
language:
|
|
273
|
-
typeof config.language === "string" && config.language.trim()
|
|
274
|
-
? config.language.trim()
|
|
275
|
-
: undefined,
|
|
276
|
-
strategy: resolveVoiceStrategyByModel(activeModelId),
|
|
277
|
-
installedModels: selectedModelIds,
|
|
278
|
-
};
|
|
279
|
-
await writeVoiceTranscriberConfig({
|
|
280
|
-
context,
|
|
281
|
-
value: nextConfig,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
return {
|
|
285
|
-
success: true,
|
|
286
|
-
message: "asr transcriber installed",
|
|
287
|
-
details: {
|
|
288
|
-
modelIds: selectedModelIds,
|
|
289
|
-
activeModel: activeModelId,
|
|
290
|
-
modelsRootDir,
|
|
291
|
-
},
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* 解析 ASR 转写句柄。
|
|
297
|
-
*/
|
|
298
|
-
export async function resolveVoiceTranscriber(
|
|
299
|
-
context: PluginCommandContext,
|
|
300
|
-
): Promise<VoiceTranscriberHandle> {
|
|
301
|
-
return {
|
|
302
|
-
async transcribe(input) {
|
|
303
|
-
try {
|
|
304
|
-
const result = await transcribeVoiceAudio({
|
|
305
|
-
context,
|
|
306
|
-
audioPath: input.audioPath,
|
|
307
|
-
language: input.language,
|
|
308
|
-
});
|
|
309
|
-
return {
|
|
310
|
-
success: true,
|
|
311
|
-
text: result.text,
|
|
312
|
-
};
|
|
313
|
-
} catch (error) {
|
|
314
|
-
return {
|
|
315
|
-
success: false,
|
|
316
|
-
error: String(error),
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
},
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* 执行一次 ASR 转写。
|
|
325
|
-
*/
|
|
326
|
-
export async function transcribeWithVoiceDependency(params: {
|
|
327
|
-
context: PluginCommandContext;
|
|
328
|
-
audioPath: string;
|
|
329
|
-
language?: string;
|
|
330
|
-
}): Promise<{ success: boolean; text?: string; error?: string }> {
|
|
331
|
-
const transcriber = await resolveVoiceTranscriber(params.context);
|
|
332
|
-
return transcriber.transcribe({
|
|
333
|
-
audioPath: params.audioPath,
|
|
334
|
-
...(params.language ? { language: params.language } : {}),
|
|
335
|
-
});
|
|
336
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ASR 入站消息增强 hook。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 只处理 voice/audio 附件,转写结果作为 plugin section 注入。
|
|
6
|
-
* - 转写失败不阻塞主链路,保持 best-effort。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { AgentContext } from "@downcity/agent/internal/types/runtime/agent/AgentContext.js";
|
|
10
|
-
import type { ChatInboundAugmentInput } from "@/chat/types/ChatPlugin.js";
|
|
11
|
-
import type { JsonValue } from "@downcity/agent/internal/types/common/Json.js";
|
|
12
|
-
import { transcribeWithVoiceDependency } from "@/asr/Dependency.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 自动转写入站语音附件。
|
|
16
|
-
*/
|
|
17
|
-
export async function augmentAsrInboundMessage(params: {
|
|
18
|
-
context: AgentContext;
|
|
19
|
-
value: JsonValue;
|
|
20
|
-
}): Promise<JsonValue> {
|
|
21
|
-
const input = params.value as unknown as ChatInboundAugmentInput;
|
|
22
|
-
const voiceAttachments = (Array.isArray(input.attachments) ? input.attachments : []).filter(
|
|
23
|
-
(item) =>
|
|
24
|
-
(item.kind === "voice" || item.kind === "audio") &&
|
|
25
|
-
typeof item.path === "string" &&
|
|
26
|
-
item.path.trim(),
|
|
27
|
-
);
|
|
28
|
-
if (voiceAttachments.length === 0) {
|
|
29
|
-
return input as unknown as JsonValue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const pluginSections = Array.isArray(input.pluginSections)
|
|
33
|
-
? [...input.pluginSections]
|
|
34
|
-
: [];
|
|
35
|
-
|
|
36
|
-
for (const attachment of voiceAttachments) {
|
|
37
|
-
try {
|
|
38
|
-
const result = await transcribeWithVoiceDependency({
|
|
39
|
-
context: params.context,
|
|
40
|
-
audioPath: String(attachment.path || "").trim(),
|
|
41
|
-
});
|
|
42
|
-
const text = typeof result.text === "string" ? result.text.trim() : "";
|
|
43
|
-
if (!text) continue;
|
|
44
|
-
|
|
45
|
-
const absPath = String(attachment.path || "").trim();
|
|
46
|
-
const rel = absPath.startsWith(`${params.context.rootPath}/`)
|
|
47
|
-
? absPath.slice(params.context.rootPath.length + 1)
|
|
48
|
-
: absPath;
|
|
49
|
-
pluginSections.push(`【语音转写 ${attachment.kind}: ${rel}】\n${text}`);
|
|
50
|
-
} catch {
|
|
51
|
-
// 关键点(中文):转写失败不阻塞主链路,保持 best-effort。
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
...input,
|
|
57
|
-
pluginSections,
|
|
58
|
-
} as unknown as JsonValue;
|
|
59
|
-
}
|
package/src/asr/ModelCatalog.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Voice 插件模型目录封装。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 对 plugin 层暴露稳定的 ASR 模型目录接口。
|
|
6
|
-
* - plugin 不直接依赖底层 runtime 文件布局,只依赖这里的领域封装。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
VOICE_MODEL_CATALOG,
|
|
11
|
-
resolveVoiceModelId,
|
|
12
|
-
} from "@/voice/runtime/Catalog.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 列出内置 voice 模型目录。
|
|
16
|
-
*/
|
|
17
|
-
export function listVoiceModels(): Array<{
|
|
18
|
-
/**
|
|
19
|
-
* 稳定模型 ID。
|
|
20
|
-
*/
|
|
21
|
-
id: string;
|
|
22
|
-
/**
|
|
23
|
-
* 用户可读标签。
|
|
24
|
-
*/
|
|
25
|
-
label: string;
|
|
26
|
-
/**
|
|
27
|
-
* 用户可读说明。
|
|
28
|
-
*/
|
|
29
|
-
description: string;
|
|
30
|
-
}> {
|
|
31
|
-
return VOICE_MODEL_CATALOG.map((item) => ({
|
|
32
|
-
id: item.id,
|
|
33
|
-
label: item.label,
|
|
34
|
-
description: item.description,
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 解析用户输入的 voice 模型 ID。
|
|
40
|
-
*/
|
|
41
|
-
export function resolveVoicePluginModelId(input: string): string | null {
|
|
42
|
-
return resolveVoiceModelId(input);
|
|
43
|
-
}
|