@mulmoclaude/core 0.1.0
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/assets/helps/billing-clients-worklog.md +215 -0
- package/assets/helps/billing-invoice.md +458 -0
- package/assets/helps/business.md +104 -0
- package/assets/helps/collection-skills.md +810 -0
- package/assets/helps/custom-view.md +433 -0
- package/assets/helps/feeds.md +114 -0
- package/assets/helps/gemini.md +57 -0
- package/assets/helps/github.md +23 -0
- package/assets/helps/guide.md +61 -0
- package/assets/helps/index.md +89 -0
- package/assets/helps/lessons-collection.md +400 -0
- package/assets/helps/mulmoscript.md +249 -0
- package/assets/helps/portfolio-tracker.md +211 -0
- package/assets/helps/presentation-deck.md +828 -0
- package/assets/helps/presenthtml.md +89 -0
- package/assets/helps/sandbox.md +97 -0
- package/assets/helps/spreadsheet.md +43 -0
- package/assets/helps/storyteller.md +101 -0
- package/assets/helps/telegram.md +136 -0
- package/assets/helps/todo-collection.md +140 -0
- package/assets/helps/vocabulary.md +109 -0
- package/assets/helps/wiki.md +168 -0
- package/assets/skills-preset/mc-cooking-coach/SKILL.md +217 -0
- package/assets/skills-preset/mc-library/SKILL.md +188 -0
- package/assets/skills-preset/mc-manage-automations/SKILL.md +119 -0
- package/assets/skills-preset/mc-manage-skills/SKILL.md +141 -0
- package/assets/skills-preset/mc-wiki-deep-lint/SKILL.md +108 -0
- package/assets/skills-preset/mc-wiki-health-check/SKILL.md +61 -0
- package/assets/skills-preset/mc-wiki-ingest/SKILL.md +182 -0
- package/assets/skills-preset/mc-wiki-promote/SKILL.md +175 -0
- package/assets/skills-preset/mc-zenn/SKILL.md +136 -0
- package/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/collection/core/actionVisible.d.ts +34 -0
- package/dist/collection/core/calendarGrid.d.ts +120 -0
- package/dist/collection/core/deriveAll.d.ts +38 -0
- package/dist/collection/core/derivedFormula.d.ts +18 -0
- package/dist/collection/core/draft.d.ts +18 -0
- package/dist/collection/core/enumColors.d.ts +33 -0
- package/dist/collection/core/errorMessage.d.ts +4 -0
- package/dist/collection/core/itemLabel.d.ts +12 -0
- package/dist/collection/core/presentCollection.d.ts +13 -0
- package/dist/collection/core/promptSafety.d.ts +1 -0
- package/dist/collection/core/schema.d.ts +355 -0
- package/dist/collection/core/shortHexId.d.ts +8 -0
- package/dist/collection/core/sortItems.d.ts +29 -0
- package/dist/collection/core/uiTypes.d.ts +106 -0
- package/dist/collection/index.cjs +793 -0
- package/dist/collection/index.cjs.map +1 -0
- package/dist/collection/index.d.ts +14 -0
- package/dist/collection/index.js +740 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/paths.cjs +44 -0
- package/dist/collection/paths.cjs.map +1 -0
- package/dist/collection/paths.js +41 -0
- package/dist/collection/paths.js.map +1 -0
- package/dist/collection/server/atomic.d.ts +1 -0
- package/dist/collection/server/delete.d.ts +38 -0
- package/dist/collection/server/derive.d.ts +8 -0
- package/dist/collection/server/discoveredCollection.d.ts +18 -0
- package/dist/collection/server/discovery.d.ts +227 -0
- package/dist/collection/server/host.d.ts +77 -0
- package/dist/collection/server/index.cjs +1721 -0
- package/dist/collection/server/index.cjs.map +1 -0
- package/dist/collection/server/index.d.ts +11 -0
- package/dist/collection/server/index.js +1671 -0
- package/dist/collection/server/index.js.map +1 -0
- package/dist/collection/server/io.d.ts +114 -0
- package/dist/collection/server/paths.d.ts +52 -0
- package/dist/collection/server/spawn.d.ts +55 -0
- package/dist/collection/server/templatePath.d.ts +25 -0
- package/dist/collection/server/util.d.ts +3 -0
- package/dist/collection/server/validate.d.ts +19 -0
- package/dist/collection/server/views.d.ts +20 -0
- package/dist/deriveAll-C15OpM3K.cjs +399 -0
- package/dist/deriveAll-C15OpM3K.cjs.map +1 -0
- package/dist/deriveAll-C6BYnpBL.js +364 -0
- package/dist/deriveAll-C6BYnpBL.js.map +1 -0
- package/dist/file-change/index.cjs +72 -0
- package/dist/file-change/index.cjs.map +1 -0
- package/dist/file-change/index.d.ts +43 -0
- package/dist/file-change/index.js +66 -0
- package/dist/file-change/index.js.map +1 -0
- package/dist/notifier/engine.d.ts +72 -0
- package/dist/notifier/index.cjs +484 -0
- package/dist/notifier/index.cjs.map +1 -0
- package/dist/notifier/index.d.ts +3 -0
- package/dist/notifier/index.js +464 -0
- package/dist/notifier/index.js.map +1 -0
- package/dist/notifier/store.d.ts +18 -0
- package/dist/notifier/types.d.ts +118 -0
- package/dist/notifier/validate.d.ts +17 -0
- package/dist/scheduler/adapter.d.ts +48 -0
- package/dist/scheduler/index.cjs +352 -0
- package/dist/scheduler/index.cjs.map +1 -0
- package/dist/scheduler/index.d.ts +2 -0
- package/dist/scheduler/index.js +343 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/scheduler/task-manager.d.ts +51 -0
- package/dist/whisper/client.cjs +241 -0
- package/dist/whisper/client.cjs.map +1 -0
- package/dist/whisper/client.d.ts +35 -0
- package/dist/whisper/client.js +239 -0
- package/dist/whisper/client.js.map +1 -0
- package/dist/whisper/ffmpeg.d.ts +6 -0
- package/dist/whisper/index.cjs +433 -0
- package/dist/whisper/index.cjs.map +1 -0
- package/dist/whisper/index.d.ts +5 -0
- package/dist/whisper/index.js +425 -0
- package/dist/whisper/index.js.map +1 -0
- package/dist/whisper/internal.d.ts +11 -0
- package/dist/whisper/models.d.ts +49 -0
- package/dist/whisper/sidecar.d.ts +8 -0
- package/dist/whisper/whisper.d.ts +28 -0
- package/dist/workspace-setup/assets.d.ts +10 -0
- package/dist/workspace-setup/index.d.ts +3 -0
- package/dist/workspace-setup/index.js +556 -0
- package/dist/workspace-setup/index.js.map +1 -0
- package/dist/workspace-setup/slug.d.ts +6 -0
- package/dist/workspace-setup/slug.js +13 -0
- package/dist/workspace-setup/slug.js.map +1 -0
- package/dist/workspace-setup/sync.d.ts +94 -0
- package/package.json +95 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createWriteStream, mkdirSync, renameSync, statSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { execFile, spawn } from "node:child_process";
|
|
6
|
+
import { promisify } from "node:util";
|
|
7
|
+
import { once } from "node:events";
|
|
8
|
+
import { createServer } from "node:net";
|
|
9
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
10
|
+
//#region src/whisper/internal.ts
|
|
11
|
+
var ONE_SECOND_MS = 1e3;
|
|
12
|
+
var ONE_MINUTE_MS = 6e4;
|
|
13
|
+
function errorMessage(err) {
|
|
14
|
+
return err instanceof Error ? err.message : String(err);
|
|
15
|
+
}
|
|
16
|
+
var NOOP = () => void 0;
|
|
17
|
+
var NOOP_LOGGER = {
|
|
18
|
+
info: NOOP,
|
|
19
|
+
warn: NOOP,
|
|
20
|
+
error: NOOP
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/whisper/ffmpeg.ts
|
|
24
|
+
var execFileAsync = promisify(execFile);
|
|
25
|
+
/** ffmpeg args to decode any input to 16 kHz mono signed-16-bit WAV. Pure +
|
|
26
|
+
* exported for unit tests. */
|
|
27
|
+
function buildWav16kArgs(inputPath, outputPath) {
|
|
28
|
+
return [
|
|
29
|
+
"-y",
|
|
30
|
+
"-loglevel",
|
|
31
|
+
"error",
|
|
32
|
+
"-i",
|
|
33
|
+
inputPath,
|
|
34
|
+
"-ar",
|
|
35
|
+
"16000",
|
|
36
|
+
"-ac",
|
|
37
|
+
"1",
|
|
38
|
+
"-c:a",
|
|
39
|
+
"pcm_s16le",
|
|
40
|
+
outputPath
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
/** Convert `inputPath` to a 16 kHz mono WAV at `outputPath`. Throws on ffmpeg
|
|
44
|
+
* failure or timeout. */
|
|
45
|
+
async function convertToWav16k(inputPath, outputPath, ffmpegBinary = "ffmpeg") {
|
|
46
|
+
await execFileAsync(ffmpegBinary, buildWav16kArgs(inputPath, outputPath), { timeout: ONE_MINUTE_MS });
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/whisper/models.ts
|
|
50
|
+
var HF_BASE = "https://huggingface.co/ggerganov/whisper.cpp/resolve/main";
|
|
51
|
+
var WHISPER_MODELS = {
|
|
52
|
+
"large-v3-turbo": {
|
|
53
|
+
file: "ggml-large-v3-turbo.bin",
|
|
54
|
+
url: `${HF_BASE}/ggml-large-v3-turbo.bin`,
|
|
55
|
+
minBytes: 1e9
|
|
56
|
+
},
|
|
57
|
+
small: {
|
|
58
|
+
file: "ggml-small.bin",
|
|
59
|
+
url: `${HF_BASE}/ggml-small.bin`,
|
|
60
|
+
minBytes: 3e8
|
|
61
|
+
},
|
|
62
|
+
base: {
|
|
63
|
+
file: "ggml-base.bin",
|
|
64
|
+
url: `${HF_BASE}/ggml-base.bin`,
|
|
65
|
+
minBytes: 1e8
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var DEFAULT_WHISPER_MODEL = "large-v3-turbo";
|
|
69
|
+
function isWhisperModelName(value) {
|
|
70
|
+
return typeof value === "string" && Object.prototype.hasOwnProperty.call(WHISPER_MODELS, value);
|
|
71
|
+
}
|
|
72
|
+
/** Resolve a possibly-unset / unknown model name to a valid one. */
|
|
73
|
+
function resolveModelName(name) {
|
|
74
|
+
return isWhisperModelName(name) ? name : DEFAULT_WHISPER_MODEL;
|
|
75
|
+
}
|
|
76
|
+
function modelFilePath(modelsDir, name) {
|
|
77
|
+
return path.join(modelsDir, WHISPER_MODELS[name].file);
|
|
78
|
+
}
|
|
79
|
+
/** A model is "ready" when its file exists and meets the size floor. */
|
|
80
|
+
function isModelReady(modelsDir, name) {
|
|
81
|
+
try {
|
|
82
|
+
return statSync(modelFilePath(modelsDir, name)).size >= WHISPER_MODELS[name].minBytes;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
var DOWNLOAD_STALL_TIMEOUT_MS = ONE_MINUTE_MS;
|
|
88
|
+
function createModelDownloader(modelsDir, logger = NOOP_LOGGER) {
|
|
89
|
+
const downloadStatus = /* @__PURE__ */ new Map();
|
|
90
|
+
function getStatus(name) {
|
|
91
|
+
const live = downloadStatus.get(name);
|
|
92
|
+
if (live?.state === "downloading") return live;
|
|
93
|
+
if (isModelReady(modelsDir, name)) return { state: "ready" };
|
|
94
|
+
return live ?? { state: "idle" };
|
|
95
|
+
}
|
|
96
|
+
async function streamToFile(body, partialPath, total, name, onProgress) {
|
|
97
|
+
const reader = body.getReader();
|
|
98
|
+
const fileStream = createWriteStream(partialPath);
|
|
99
|
+
let received = 0;
|
|
100
|
+
try {
|
|
101
|
+
for (;;) {
|
|
102
|
+
const { done, value } = await reader.read();
|
|
103
|
+
if (done) break;
|
|
104
|
+
onProgress();
|
|
105
|
+
received += value.byteLength;
|
|
106
|
+
if (!fileStream.write(value)) await once(fileStream, "drain");
|
|
107
|
+
if (total > 0) downloadStatus.set(name, {
|
|
108
|
+
state: "downloading",
|
|
109
|
+
progress: received / total
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
fileStream.end();
|
|
113
|
+
await once(fileStream, "finish");
|
|
114
|
+
} catch (err) {
|
|
115
|
+
fileStream.destroy();
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function download(name) {
|
|
120
|
+
const spec = WHISPER_MODELS[name];
|
|
121
|
+
mkdirSync(modelsDir, { recursive: true });
|
|
122
|
+
const dest = modelFilePath(modelsDir, name);
|
|
123
|
+
const partial = `${dest}.partial`;
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
let stallTimer = null;
|
|
126
|
+
const resetStall = () => {
|
|
127
|
+
if (stallTimer) clearTimeout(stallTimer);
|
|
128
|
+
stallTimer = setTimeout(() => controller.abort(), DOWNLOAD_STALL_TIMEOUT_MS);
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
const response = await fetch(spec.url, { signal: controller.signal });
|
|
132
|
+
if (!response.ok || !response.body) throw new Error(`download failed: HTTP ${response.status}`);
|
|
133
|
+
const total = Number(response.headers.get("content-length")) || 0;
|
|
134
|
+
resetStall();
|
|
135
|
+
await streamToFile(response.body, partial, total, name, resetStall);
|
|
136
|
+
if (statSync(partial).size < spec.minBytes) {
|
|
137
|
+
unlinkSync(partial);
|
|
138
|
+
throw new Error("downloaded file is smaller than expected — likely truncated");
|
|
139
|
+
}
|
|
140
|
+
renameSync(partial, dest);
|
|
141
|
+
} finally {
|
|
142
|
+
if (stallTimer) clearTimeout(stallTimer);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function ensure(name) {
|
|
146
|
+
if (isModelReady(modelsDir, name)) {
|
|
147
|
+
downloadStatus.set(name, { state: "ready" });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (downloadStatus.get(name)?.state === "downloading") return;
|
|
151
|
+
downloadStatus.set(name, {
|
|
152
|
+
state: "downloading",
|
|
153
|
+
progress: 0
|
|
154
|
+
});
|
|
155
|
+
logger.info("model download: start", { model: name });
|
|
156
|
+
try {
|
|
157
|
+
await download(name);
|
|
158
|
+
downloadStatus.set(name, { state: "ready" });
|
|
159
|
+
logger.info("model download: ok", { model: name });
|
|
160
|
+
} catch (err) {
|
|
161
|
+
const error = errorMessage(err);
|
|
162
|
+
downloadStatus.set(name, {
|
|
163
|
+
state: "error",
|
|
164
|
+
error
|
|
165
|
+
});
|
|
166
|
+
logger.error("model download: failed", {
|
|
167
|
+
model: name,
|
|
168
|
+
error
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
getStatus,
|
|
174
|
+
ensure
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/whisper/sidecar.ts
|
|
179
|
+
var HOST = "127.0.0.1";
|
|
180
|
+
var READY_TIMEOUT_MS = 60 * ONE_SECOND_MS;
|
|
181
|
+
var READY_POLL_INTERVAL_MS = 500;
|
|
182
|
+
var INFERENCE_TIMEOUT_MS = 2 * ONE_MINUTE_MS;
|
|
183
|
+
async function findFreePort() {
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
const srv = createServer();
|
|
186
|
+
srv.on("error", reject);
|
|
187
|
+
srv.listen(0, HOST, () => {
|
|
188
|
+
const addr = srv.address();
|
|
189
|
+
if (addr && typeof addr === "object") {
|
|
190
|
+
const { port } = addr;
|
|
191
|
+
srv.close(() => resolve(port));
|
|
192
|
+
} else srv.close(() => reject(/* @__PURE__ */ new Error("could not determine a free port")));
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/** Resolve once the server answers any HTTP request (any status = listener up),
|
|
197
|
+
* or throw after the ready timeout. */
|
|
198
|
+
async function waitUntilReady(port) {
|
|
199
|
+
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
200
|
+
while (Date.now() < deadline) try {
|
|
201
|
+
await fetch(`http://${HOST}:${port}/`, { signal: AbortSignal.timeout(ONE_SECOND_MS) });
|
|
202
|
+
return;
|
|
203
|
+
} catch {
|
|
204
|
+
await setTimeout$1(READY_POLL_INTERVAL_MS);
|
|
205
|
+
}
|
|
206
|
+
throw new Error("whisper-server did not become ready in time");
|
|
207
|
+
}
|
|
208
|
+
function drainStderr(proc, tail) {
|
|
209
|
+
proc.stderr?.setEncoding("utf8");
|
|
210
|
+
proc.stderr?.on("data", (chunk) => {
|
|
211
|
+
tail.text = (tail.text + chunk).slice(-4e3);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function waitForReadyOrFailure(proc, port) {
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
let onError = () => void 0;
|
|
217
|
+
let onExit = () => void 0;
|
|
218
|
+
const cleanup = () => {
|
|
219
|
+
proc.removeListener("error", onError);
|
|
220
|
+
proc.removeListener("exit", onExit);
|
|
221
|
+
};
|
|
222
|
+
onError = (err) => {
|
|
223
|
+
cleanup();
|
|
224
|
+
reject(/* @__PURE__ */ new Error(`spawn failed: ${errorMessage(err)}`));
|
|
225
|
+
};
|
|
226
|
+
onExit = (code) => {
|
|
227
|
+
cleanup();
|
|
228
|
+
reject(/* @__PURE__ */ new Error(`exited early (code ${code})`));
|
|
229
|
+
};
|
|
230
|
+
proc.once("error", onError);
|
|
231
|
+
proc.once("exit", onExit);
|
|
232
|
+
waitUntilReady(port).then(() => {
|
|
233
|
+
cleanup();
|
|
234
|
+
resolve();
|
|
235
|
+
}).catch((err) => {
|
|
236
|
+
cleanup();
|
|
237
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function parseInferenceText(data) {
|
|
242
|
+
if (typeof data === "object" && data !== null && "text" in data) {
|
|
243
|
+
const { text } = data;
|
|
244
|
+
if (typeof text === "string") return text;
|
|
245
|
+
}
|
|
246
|
+
return "";
|
|
247
|
+
}
|
|
248
|
+
function createSidecar(modelsDir, serverBinary = "whisper-server", logger = NOOP_LOGGER) {
|
|
249
|
+
let sidecar = null;
|
|
250
|
+
let starting = null;
|
|
251
|
+
let startingProc = null;
|
|
252
|
+
let startToken = 0;
|
|
253
|
+
function shutdown() {
|
|
254
|
+
startToken += 1;
|
|
255
|
+
if (startingProc) {
|
|
256
|
+
startingProc.kill();
|
|
257
|
+
startingProc = null;
|
|
258
|
+
}
|
|
259
|
+
if (sidecar) {
|
|
260
|
+
sidecar.proc.kill();
|
|
261
|
+
sidecar = null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function startSidecar(model) {
|
|
265
|
+
const token = ++startToken;
|
|
266
|
+
const port = await findFreePort();
|
|
267
|
+
const args = [
|
|
268
|
+
"--model",
|
|
269
|
+
modelFilePath(modelsDir, model),
|
|
270
|
+
"--host",
|
|
271
|
+
HOST,
|
|
272
|
+
"--port",
|
|
273
|
+
String(port)
|
|
274
|
+
];
|
|
275
|
+
logger.info("sidecar: spawning", {
|
|
276
|
+
model,
|
|
277
|
+
port
|
|
278
|
+
});
|
|
279
|
+
const proc = spawn(serverBinary, args, { stdio: [
|
|
280
|
+
"ignore",
|
|
281
|
+
"ignore",
|
|
282
|
+
"pipe"
|
|
283
|
+
] });
|
|
284
|
+
startingProc = proc;
|
|
285
|
+
const stderrTail = { text: "" };
|
|
286
|
+
drainStderr(proc, stderrTail);
|
|
287
|
+
proc.on("error", (err) => logger.warn("sidecar: process error", {
|
|
288
|
+
model,
|
|
289
|
+
error: errorMessage(err)
|
|
290
|
+
}));
|
|
291
|
+
proc.on("exit", (code) => {
|
|
292
|
+
logger.warn("sidecar: exited", {
|
|
293
|
+
model,
|
|
294
|
+
code,
|
|
295
|
+
stderrTail: stderrTail.text.slice(-500)
|
|
296
|
+
});
|
|
297
|
+
if (sidecar?.proc === proc) sidecar = null;
|
|
298
|
+
});
|
|
299
|
+
try {
|
|
300
|
+
await waitForReadyOrFailure(proc, port);
|
|
301
|
+
} catch (err) {
|
|
302
|
+
proc.kill();
|
|
303
|
+
throw new Error(`whisper-server failed to start: ${errorMessage(err)} — stderr: ${stderrTail.text.slice(-500)}`);
|
|
304
|
+
} finally {
|
|
305
|
+
if (startingProc === proc) startingProc = null;
|
|
306
|
+
}
|
|
307
|
+
if (token !== startToken) {
|
|
308
|
+
proc.kill();
|
|
309
|
+
throw new Error("whisper-server start cancelled");
|
|
310
|
+
}
|
|
311
|
+
sidecar = {
|
|
312
|
+
port,
|
|
313
|
+
proc,
|
|
314
|
+
model
|
|
315
|
+
};
|
|
316
|
+
logger.info("sidecar: ready", {
|
|
317
|
+
model,
|
|
318
|
+
port
|
|
319
|
+
});
|
|
320
|
+
return sidecar;
|
|
321
|
+
}
|
|
322
|
+
function beginStart(model) {
|
|
323
|
+
const promise = startSidecar(model).finally(() => {
|
|
324
|
+
starting = null;
|
|
325
|
+
});
|
|
326
|
+
starting = {
|
|
327
|
+
model,
|
|
328
|
+
promise
|
|
329
|
+
};
|
|
330
|
+
return promise;
|
|
331
|
+
}
|
|
332
|
+
async function ensureSidecar(model) {
|
|
333
|
+
for (;;) {
|
|
334
|
+
if (sidecar && sidecar.model === model && !sidecar.proc.killed) return sidecar;
|
|
335
|
+
if (starting && starting.model === model) return starting.promise;
|
|
336
|
+
if (starting) {
|
|
337
|
+
await starting.promise.catch(() => void 0);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (sidecar && sidecar.model !== model) shutdown();
|
|
341
|
+
return beginStart(model);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async function warmup(model) {
|
|
345
|
+
try {
|
|
346
|
+
await ensureSidecar(model);
|
|
347
|
+
} catch (err) {
|
|
348
|
+
logger.warn("sidecar: warmup failed", {
|
|
349
|
+
model,
|
|
350
|
+
error: errorMessage(err)
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async function transcribeWav(wavPath, language, model) {
|
|
355
|
+
const active = await ensureSidecar(model);
|
|
356
|
+
const buf = await readFile(wavPath);
|
|
357
|
+
const form = new FormData();
|
|
358
|
+
form.append("file", new Blob([buf], { type: "audio/wav" }), "audio.wav");
|
|
359
|
+
form.append("response_format", "json");
|
|
360
|
+
form.append("language", language || "auto");
|
|
361
|
+
let res;
|
|
362
|
+
try {
|
|
363
|
+
res = await fetch(`http://${HOST}:${active.port}/inference`, {
|
|
364
|
+
method: "POST",
|
|
365
|
+
body: form,
|
|
366
|
+
signal: AbortSignal.timeout(INFERENCE_TIMEOUT_MS)
|
|
367
|
+
});
|
|
368
|
+
} catch (err) {
|
|
369
|
+
throw new Error(`whisper-server request failed: ${errorMessage(err)}`);
|
|
370
|
+
}
|
|
371
|
+
if (!res.ok) throw new Error(`whisper-server returned HTTP ${res.status}`);
|
|
372
|
+
return parseInferenceText(await res.json());
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
transcribeWav,
|
|
376
|
+
warmup,
|
|
377
|
+
shutdown
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/whisper/whisper.ts
|
|
382
|
+
var BLANK_MARKERS = new Set([
|
|
383
|
+
"[blank_audio]",
|
|
384
|
+
"[silence]",
|
|
385
|
+
"(silence)",
|
|
386
|
+
"[ inaudible ]"
|
|
387
|
+
]);
|
|
388
|
+
function normalizeTranscript(raw) {
|
|
389
|
+
const trimmed = raw.trim().replace(/\s+/g, " ");
|
|
390
|
+
return BLANK_MARKERS.has(trimmed.toLowerCase()) ? "" : trimmed;
|
|
391
|
+
}
|
|
392
|
+
function createWhisper(opts) {
|
|
393
|
+
const { modelsDir } = opts;
|
|
394
|
+
const logger = opts.logger ?? NOOP_LOGGER;
|
|
395
|
+
const ffmpegBinary = opts.ffmpegBinary ?? "ffmpeg";
|
|
396
|
+
const downloader = createModelDownloader(modelsDir, logger);
|
|
397
|
+
const sidecar = createSidecar(modelsDir, opts.serverBinary ?? "whisper-server", logger);
|
|
398
|
+
const scratchDir = path.join(modelsDir, ".scratch");
|
|
399
|
+
async function transcribe(req) {
|
|
400
|
+
mkdirSync(scratchDir, { recursive: true });
|
|
401
|
+
const clipId = randomUUID();
|
|
402
|
+
const inputPath = path.join(scratchDir, `utterance-${clipId}.webm`);
|
|
403
|
+
const wavPath = path.join(scratchDir, `utterance-${clipId}.wav`);
|
|
404
|
+
try {
|
|
405
|
+
await writeFile(inputPath, Buffer.from(req.base64, "base64"));
|
|
406
|
+
await convertToWav16k(inputPath, wavPath, ffmpegBinary);
|
|
407
|
+
return { text: normalizeTranscript(await sidecar.transcribeWav(wavPath, req.language, req.model)) };
|
|
408
|
+
} finally {
|
|
409
|
+
await rm(inputPath, { force: true });
|
|
410
|
+
await rm(wavPath, { force: true });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
isModelReady: (model) => isModelReady(modelsDir, model),
|
|
415
|
+
getModelStatus: (model) => downloader.getStatus(model),
|
|
416
|
+
ensureModelDownloaded: (model) => downloader.ensure(model),
|
|
417
|
+
warmup: (model) => sidecar.warmup(model),
|
|
418
|
+
transcribe,
|
|
419
|
+
shutdown: () => sidecar.shutdown()
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
423
|
+
export { DEFAULT_WHISPER_MODEL, WHISPER_MODELS, buildWav16kArgs, createWhisper, isWhisperModelName, resolveModelName };
|
|
424
|
+
|
|
425
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/whisper/internal.ts","../../src/whisper/ffmpeg.ts","../../src/whisper/models.ts","../../src/whisper/sidecar.ts","../../src/whisper/whisper.ts"],"sourcesContent":["// Small self-contained utilities so the package has no host dependencies.\n\nexport const ONE_SECOND_MS = 1_000;\nexport const ONE_MINUTE_MS = 60_000;\n\nexport function errorMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n\n/** Minimal logger the host can inject; defaults to no-op so the package\n * is silent unless wired up. */\nexport interface WhisperLogger {\n info: (message: string, data?: unknown) => void;\n warn: (message: string, data?: unknown) => void;\n error: (message: string, data?: unknown) => void;\n}\n\nconst NOOP = (): void => undefined;\nexport const NOOP_LOGGER: WhisperLogger = { info: NOOP, warn: NOOP, error: NOOP };\n","// Thin wrapper around the system `ffmpeg` binary (provided by the host) for\n// converting a browser webm/opus clip to the 16 kHz mono 16-bit WAV whisper.cpp\n// requires.\n\nimport { execFile } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { ONE_MINUTE_MS } from \"./internal.ts\";\n\nconst execFileAsync = promisify(execFile);\n\n/** ffmpeg args to decode any input to 16 kHz mono signed-16-bit WAV. Pure +\n * exported for unit tests. */\nexport function buildWav16kArgs(inputPath: string, outputPath: string): string[] {\n return [\"-y\", \"-loglevel\", \"error\", \"-i\", inputPath, \"-ar\", \"16000\", \"-ac\", \"1\", \"-c:a\", \"pcm_s16le\", outputPath];\n}\n\n/** Convert `inputPath` to a 16 kHz mono WAV at `outputPath`. Throws on ffmpeg\n * failure or timeout. */\nexport async function convertToWav16k(inputPath: string, outputPath: string, ffmpegBinary = \"ffmpeg\"): Promise<void> {\n await execFileAsync(ffmpegBinary, buildWav16kArgs(inputPath, outputPath), {\n timeout: ONE_MINUTE_MS,\n });\n}\n","// Whisper GGML model registry + on-disk management. The host injects the models\n// directory (e.g. `{workspace}/models`); nothing here reads a host module.\n\nimport { createWriteStream, mkdirSync, renameSync, statSync, unlinkSync } from \"node:fs\";\nimport { once } from \"node:events\";\nimport path from \"node:path\";\nimport { errorMessage, NOOP_LOGGER, ONE_MINUTE_MS, type WhisperLogger } from \"./internal.ts\";\n\nexport interface WhisperModelSpec {\n /** GGML filename — identical on disk and in the Hugging Face repo. */\n readonly file: string;\n /** Download URL (Hugging Face whisper.cpp model repo). */\n readonly url: string;\n /** Conservative lower bound on the finished file size, in bytes — guards\n * against a truncated transfer or an HTML error page saved as the model\n * without pinning an exact checksum. */\n readonly minBytes: number;\n}\n\nconst HF_BASE = \"https://huggingface.co/ggerganov/whisper.cpp/resolve/main\";\n\n// large-v3-turbo: strong accuracy, near-real-time on Apple Silicon with Metal.\n// small/base are lighter fallbacks for low-RAM machines.\nexport const WHISPER_MODELS = {\n \"large-v3-turbo\": { file: \"ggml-large-v3-turbo.bin\", url: `${HF_BASE}/ggml-large-v3-turbo.bin`, minBytes: 1_000_000_000 },\n small: { file: \"ggml-small.bin\", url: `${HF_BASE}/ggml-small.bin`, minBytes: 300_000_000 },\n base: { file: \"ggml-base.bin\", url: `${HF_BASE}/ggml-base.bin`, minBytes: 100_000_000 },\n} as const satisfies Record<string, WhisperModelSpec>;\n\nexport type WhisperModelName = keyof typeof WHISPER_MODELS;\nexport const DEFAULT_WHISPER_MODEL: WhisperModelName = \"large-v3-turbo\";\n\nexport function isWhisperModelName(value: unknown): value is WhisperModelName {\n // Own-property check — `in` would accept inherited keys like \"toString\",\n // which then crash the `WHISPER_MODELS[name]` lookups instead of falling\n // back to the default.\n return typeof value === \"string\" && Object.prototype.hasOwnProperty.call(WHISPER_MODELS, value);\n}\n\n/** Resolve a possibly-unset / unknown model name to a valid one. */\nexport function resolveModelName(name: string | undefined): WhisperModelName {\n return isWhisperModelName(name) ? name : DEFAULT_WHISPER_MODEL;\n}\n\nexport function modelFilePath(modelsDir: string, name: WhisperModelName): string {\n return path.join(modelsDir, WHISPER_MODELS[name].file);\n}\n\n/** A model is \"ready\" when its file exists and meets the size floor. */\nexport function isModelReady(modelsDir: string, name: WhisperModelName): boolean {\n try {\n return statSync(modelFilePath(modelsDir, name)).size >= WHISPER_MODELS[name].minBytes;\n } catch {\n return false;\n }\n}\n\nexport type ModelDownloadState = \"idle\" | \"downloading\" | \"ready\" | \"error\";\n\nexport interface ModelStatus {\n state: ModelDownloadState;\n /** 0..1 — present only while downloading and Content-Length is known. */\n progress?: number;\n /** Present only in the \"error\" state. */\n error?: string;\n}\n\n// Abort a download if no bytes arrive for this long (stalled connection).\nconst DOWNLOAD_STALL_TIMEOUT_MS = ONE_MINUTE_MS;\n\nexport interface ModelDownloader {\n getStatus: (name: WhisperModelName) => ModelStatus;\n ensure: (name: WhisperModelName) => Promise<void>;\n}\n\nexport function createModelDownloader(modelsDir: string, logger: WhisperLogger = NOOP_LOGGER): ModelDownloader {\n // A finished file on disk is the source of truth for \"ready\"; this map tracks\n // transient progress + the last error.\n const downloadStatus = new Map<WhisperModelName, ModelStatus>();\n\n function getStatus(name: WhisperModelName): ModelStatus {\n const live = downloadStatus.get(name);\n if (live?.state === \"downloading\") return live;\n if (isModelReady(modelsDir, name)) return { state: \"ready\" };\n return live ?? { state: \"idle\" };\n }\n\n async function streamToFile(\n body: ReadableStream<Uint8Array>,\n partialPath: string,\n total: number,\n name: WhisperModelName,\n onProgress: () => void,\n ): Promise<void> {\n const reader = body.getReader();\n const fileStream = createWriteStream(partialPath);\n let received = 0;\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n onProgress();\n received += value.byteLength;\n if (!fileStream.write(value)) await once(fileStream, \"drain\");\n if (total > 0) downloadStatus.set(name, { state: \"downloading\", progress: received / total });\n }\n fileStream.end();\n await once(fileStream, \"finish\");\n } catch (err) {\n fileStream.destroy();\n throw err;\n }\n }\n\n async function download(name: WhisperModelName): Promise<void> {\n const spec = WHISPER_MODELS[name];\n mkdirSync(modelsDir, { recursive: true });\n const dest = modelFilePath(modelsDir, name);\n const partial = `${dest}.partial`;\n const controller = new AbortController();\n let stallTimer: ReturnType<typeof setTimeout> | null = null;\n const resetStall = () => {\n if (stallTimer) clearTimeout(stallTimer);\n stallTimer = setTimeout(() => controller.abort(), DOWNLOAD_STALL_TIMEOUT_MS);\n };\n try {\n const response = await fetch(spec.url, { signal: controller.signal });\n if (!response.ok || !response.body) {\n throw new Error(`download failed: HTTP ${response.status}`);\n }\n const total = Number(response.headers.get(\"content-length\")) || 0;\n resetStall();\n await streamToFile(response.body, partial, total, name, resetStall);\n if (statSync(partial).size < spec.minBytes) {\n unlinkSync(partial);\n throw new Error(\"downloaded file is smaller than expected — likely truncated\");\n }\n renameSync(partial, dest);\n } finally {\n if (stallTimer) clearTimeout(stallTimer);\n }\n }\n\n // Fire-and-forget friendly: errors land in the status map, never thrown.\n // Idempotent — a second call while a download is in flight does nothing.\n async function ensure(name: WhisperModelName): Promise<void> {\n if (isModelReady(modelsDir, name)) {\n downloadStatus.set(name, { state: \"ready\" });\n return;\n }\n if (downloadStatus.get(name)?.state === \"downloading\") return;\n downloadStatus.set(name, { state: \"downloading\", progress: 0 });\n logger.info(\"model download: start\", { model: name });\n try {\n await download(name);\n downloadStatus.set(name, { state: \"ready\" });\n logger.info(\"model download: ok\", { model: name });\n } catch (err) {\n const error = errorMessage(err);\n downloadStatus.set(name, { state: \"error\", error });\n logger.error(\"model download: failed\", { model: name, error });\n }\n }\n\n return { getStatus, ensure };\n}\n","// whisper.cpp warm-model sidecar. Spawns `whisper-server` once with the model\n// preloaded and reuses it across transcriptions over its local HTTP API, so the\n// weights stay resident (no per-request reload). State is encapsulated per\n// instance via the factory closure.\n\nimport { spawn, type ChildProcess } from \"node:child_process\";\nimport { createServer } from \"node:net\";\nimport { readFile } from \"node:fs/promises\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport { errorMessage, NOOP_LOGGER, ONE_MINUTE_MS, ONE_SECOND_MS, type WhisperLogger } from \"./internal.ts\";\nimport { modelFilePath, type WhisperModelName } from \"./models.ts\";\n\nconst HOST = \"127.0.0.1\";\nconst READY_TIMEOUT_MS = 60 * ONE_SECOND_MS;\nconst READY_POLL_INTERVAL_MS = 500;\nconst INFERENCE_TIMEOUT_MS = 2 * ONE_MINUTE_MS;\n\ninterface ActiveSidecar {\n readonly port: number;\n readonly proc: ChildProcess;\n readonly model: WhisperModelName;\n}\n\nexport interface Sidecar {\n transcribeWav: (wavPath: string, language: string, model: WhisperModelName) => Promise<string>;\n warmup: (model: WhisperModelName) => Promise<void>;\n shutdown: () => void;\n}\n\nasync function findFreePort(): Promise<number> {\n return new Promise((resolve, reject) => {\n const srv = createServer();\n srv.on(\"error\", reject);\n srv.listen(0, HOST, () => {\n const addr = srv.address();\n if (addr && typeof addr === \"object\") {\n const { port } = addr;\n srv.close(() => resolve(port));\n } else {\n srv.close(() => reject(new Error(\"could not determine a free port\")));\n }\n });\n });\n}\n\n/** Resolve once the server answers any HTTP request (any status = listener up),\n * or throw after the ready timeout. */\nasync function waitUntilReady(port: number): Promise<void> {\n const deadline = Date.now() + READY_TIMEOUT_MS;\n while (Date.now() < deadline) {\n try {\n await fetch(`http://${HOST}:${port}/`, { signal: AbortSignal.timeout(ONE_SECOND_MS) });\n return;\n } catch {\n await delay(READY_POLL_INTERVAL_MS);\n }\n }\n throw new Error(\"whisper-server did not become ready in time\");\n}\n\n// whisper-server logs verbosely to stderr; left unread the OS pipe buffer fills\n// and the child blocks on its next write. Drain into a small tail buffer.\nfunction drainStderr(proc: ChildProcess, tail: { text: string }): void {\n proc.stderr?.setEncoding(\"utf8\");\n proc.stderr?.on(\"data\", (chunk: string) => {\n tail.text = (tail.text + chunk).slice(-4000);\n });\n}\n\n// Resolve when the server answers, or reject on spawn failure (e.g. ENOENT) /\n// early exit. Listeners are one-shot and removed once the race settles.\nfunction waitForReadyOrFailure(proc: ChildProcess, port: number): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n let onError: (err: Error) => void = () => undefined;\n let onExit: (code: number | null) => void = () => undefined;\n const cleanup = () => {\n proc.removeListener(\"error\", onError);\n proc.removeListener(\"exit\", onExit);\n };\n onError = (err: Error) => {\n cleanup();\n reject(new Error(`spawn failed: ${errorMessage(err)}`));\n };\n onExit = (code: number | null) => {\n cleanup();\n reject(new Error(`exited early (code ${code})`));\n };\n proc.once(\"error\", onError);\n proc.once(\"exit\", onExit);\n waitUntilReady(port)\n .then(() => {\n cleanup();\n resolve();\n })\n .catch((err: unknown) => {\n cleanup();\n reject(err instanceof Error ? err : new Error(String(err)));\n });\n });\n}\n\nfunction parseInferenceText(data: unknown): string {\n if (typeof data === \"object\" && data !== null && \"text\" in data) {\n const { text } = data as { text: unknown };\n if (typeof text === \"string\") return text;\n }\n return \"\";\n}\n\nexport function createSidecar(modelsDir: string, serverBinary = \"whisper-server\", logger: WhisperLogger = NOOP_LOGGER): Sidecar {\n let sidecar: ActiveSidecar | null = null;\n let starting: { model: WhisperModelName; promise: Promise<ActiveSidecar> } | null = null;\n // The child of an in-flight start (before it's published as `sidecar`), plus a\n // token that `shutdown()` bumps to cancel a start that's still booting — so\n // shutdown can't return with a child that then publishes itself afterwards.\n let startingProc: ChildProcess | null = null;\n let startToken = 0;\n\n function shutdown(): void {\n startToken += 1;\n if (startingProc) {\n startingProc.kill();\n startingProc = null;\n }\n if (sidecar) {\n sidecar.proc.kill();\n sidecar = null;\n }\n }\n\n async function startSidecar(model: WhisperModelName): Promise<ActiveSidecar> {\n const token = ++startToken;\n const port = await findFreePort();\n const args = [\"--model\", modelFilePath(modelsDir, model), \"--host\", HOST, \"--port\", String(port)];\n logger.info(\"sidecar: spawning\", { model, port });\n const proc = spawn(serverBinary, args, { stdio: [\"ignore\", \"ignore\", \"pipe\"] });\n startingProc = proc;\n const stderrTail = { text: \"\" };\n drainStderr(proc, stderrTail);\n // Permanent error listener — a missing one would let a process 'error'\n // (e.g. ENOENT) throw uncaught and crash the host.\n proc.on(\"error\", (err) => logger.warn(\"sidecar: process error\", { model, error: errorMessage(err) }));\n proc.on(\"exit\", (code) => {\n logger.warn(\"sidecar: exited\", { model, code, stderrTail: stderrTail.text.slice(-500) });\n if (sidecar?.proc === proc) sidecar = null;\n });\n try {\n await waitForReadyOrFailure(proc, port);\n } catch (err) {\n proc.kill();\n throw new Error(`whisper-server failed to start: ${errorMessage(err)} — stderr: ${stderrTail.text.slice(-500)}`);\n } finally {\n if (startingProc === proc) startingProc = null;\n }\n // shutdown() (or a newer start) ran while we were booting — discard this\n // child instead of publishing a sidecar after shutdown returned.\n // eslint-disable-next-line security/detect-possible-timing-attacks -- in-memory start-cancellation token, not an auth compare\n if (token !== startToken) {\n proc.kill();\n throw new Error(\"whisper-server start cancelled\");\n }\n sidecar = { port, proc, model };\n logger.info(\"sidecar: ready\", { model, port });\n return sidecar;\n }\n\n // Module-scoped spawn so it isn't a loop closure (no-loop-func). Only ever one\n // start is in flight at a time, so clearing `starting` on settle is safe.\n function beginStart(model: WhisperModelName): Promise<ActiveSidecar> {\n const promise = startSidecar(model).finally(() => {\n starting = null;\n });\n starting = { model, promise };\n return promise;\n }\n\n async function ensureSidecar(model: WhisperModelName): Promise<ActiveSidecar> {\n // Loop so that after awaiting an in-flight start for a DIFFERENT model we\n // re-evaluate; the decision-to-spawn path (beginStart) has no await, so the\n // first waiter sets `starting` synchronously and siblings then reuse it.\n for (;;) {\n if (sidecar && sidecar.model === model && !sidecar.proc.killed) return sidecar;\n if (starting && starting.model === model) return starting.promise;\n if (starting) {\n await starting.promise.catch(() => undefined);\n continue;\n }\n if (sidecar && sidecar.model !== model) shutdown();\n return beginStart(model);\n }\n }\n\n async function warmup(model: WhisperModelName): Promise<void> {\n try {\n await ensureSidecar(model);\n } catch (err) {\n logger.warn(\"sidecar: warmup failed\", { model, error: errorMessage(err) });\n }\n }\n\n async function transcribeWav(wavPath: string, language: string, model: WhisperModelName): Promise<string> {\n const active = await ensureSidecar(model);\n const buf = await readFile(wavPath);\n const form = new FormData();\n form.append(\"file\", new Blob([buf], { type: \"audio/wav\" }), \"audio.wav\");\n form.append(\"response_format\", \"json\");\n form.append(\"language\", language || \"auto\");\n let res: Response;\n try {\n res = await fetch(`http://${HOST}:${active.port}/inference`, { method: \"POST\", body: form, signal: AbortSignal.timeout(INFERENCE_TIMEOUT_MS) });\n } catch (err) {\n throw new Error(`whisper-server request failed: ${errorMessage(err)}`);\n }\n if (!res.ok) throw new Error(`whisper-server returned HTTP ${res.status}`);\n return parseInferenceText(await res.json());\n }\n\n return { transcribeWav, warmup, shutdown };\n}\n","// Public server-side façade: wires the model downloader, the warm sidecar, and\n// ffmpeg conversion into one host-agnostic service. The host injects the models\n// directory + a logger and gates capability itself (platform / binary presence);\n// this package assumes the binaries exist when called.\n\nimport { mkdirSync } from \"node:fs\";\nimport { rm, writeFile } from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport { NOOP_LOGGER, type WhisperLogger } from \"./internal.ts\";\nimport { convertToWav16k } from \"./ffmpeg.ts\";\nimport { createModelDownloader } from \"./models.ts\";\nimport { createSidecar } from \"./sidecar.ts\";\nimport { isModelReady, type ModelStatus, type WhisperModelName } from \"./models.ts\";\n\nexport interface WhisperOptions {\n /** Directory that holds the GGML model files (e.g. `{workspace}/models`). */\n modelsDir: string;\n logger?: WhisperLogger;\n /** Defaults to \"whisper-server\" / \"ffmpeg\" on PATH. */\n serverBinary?: string;\n ffmpegBinary?: string;\n}\n\nexport interface TranscribeRequest {\n base64: string;\n mimeType: string;\n language: string;\n model: WhisperModelName;\n}\n\nexport interface Whisper {\n isModelReady: (model: WhisperModelName) => boolean;\n getModelStatus: (model: WhisperModelName) => ModelStatus;\n /** Fire-and-forget friendly; never throws (errors land in the status). */\n ensureModelDownloaded: (model: WhisperModelName) => Promise<void>;\n warmup: (model: WhisperModelName) => Promise<void>;\n transcribe: (req: TranscribeRequest) => Promise<{ text: string }>;\n shutdown: () => void;\n}\n\n// whisper.cpp returns these sentinels for non-speech windows; treat them as\n// empty so the UI shows \"didn't catch that\" rather than a literal marker.\nconst BLANK_MARKERS = new Set([\"[blank_audio]\", \"[silence]\", \"(silence)\", \"[ inaudible ]\"]);\n\nfunction normalizeTranscript(raw: string): string {\n const trimmed = raw.trim().replace(/\\s+/g, \" \");\n return BLANK_MARKERS.has(trimmed.toLowerCase()) ? \"\" : trimmed;\n}\n\nexport function createWhisper(opts: WhisperOptions): Whisper {\n const { modelsDir } = opts;\n const logger = opts.logger ?? NOOP_LOGGER;\n const ffmpegBinary = opts.ffmpegBinary ?? \"ffmpeg\";\n const downloader = createModelDownloader(modelsDir, logger);\n const sidecar = createSidecar(modelsDir, opts.serverBinary ?? \"whisper-server\", logger);\n\n // Scratch dir for transient audio — a hidden subdir of the models dir so it\n // shares the (non-git) models tree. Files are deleted after each transcription.\n const scratchDir = path.join(modelsDir, \".scratch\");\n\n async function transcribe(req: TranscribeRequest): Promise<{ text: string }> {\n mkdirSync(scratchDir, { recursive: true });\n const clipId = randomUUID();\n const inputPath = path.join(scratchDir, `utterance-${clipId}.webm`);\n const wavPath = path.join(scratchDir, `utterance-${clipId}.wav`);\n try {\n await writeFile(inputPath, Buffer.from(req.base64, \"base64\"));\n await convertToWav16k(inputPath, wavPath, ffmpegBinary);\n const text = await sidecar.transcribeWav(wavPath, req.language, req.model);\n return { text: normalizeTranscript(text) };\n } finally {\n await rm(inputPath, { force: true });\n await rm(wavPath, { force: true });\n }\n }\n\n return {\n isModelReady: (model) => isModelReady(modelsDir, model),\n getModelStatus: (model) => downloader.getStatus(model),\n ensureModelDownloaded: (model) => downloader.ensure(model),\n warmup: (model) => sidecar.warmup(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AI,QAAQ,QAAQ,CAAC;GAC5D,MAAM,gBAAgB,WAAW,SAAS,YAAY;GAEtD,OAAO,EAAE,MAAM,oBAAoB,MADhB,QAAQ,cAAc,SAAS,IAAI,UAAU,IAAI,KAAK,CAClC,EAAE;EAC3C,UAAU;GACR,MAAM,GAAG,WAAW,EAAE,OAAO,KAAK,CAAC;GACnC,MAAM,GAAG,SAAS,EAAE,OAAO,KAAK,CAAC;EACnC;CACF;CAEA,OAAO;EACL,eAAe,UAAU,aAAa,WAAW,KAAK;EACtD,iBAAiB,UAAU,WAAW,UAAU,KAAK;EACrD,wBAAwB,UAAU,WAAW,OAAO,KAAK;EACzD,SAAS,UAAU,QAAQ,OAAO,KAAK;EACvC;EACA,gBAAgB,QAAQ,SAAS;CACnC;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ONE_SECOND_MS = 1000;
|
|
2
|
+
export declare const ONE_MINUTE_MS = 60000;
|
|
3
|
+
export declare function errorMessage(err: unknown): string;
|
|
4
|
+
/** Minimal logger the host can inject; defaults to no-op so the package
|
|
5
|
+
* is silent unless wired up. */
|
|
6
|
+
export interface WhisperLogger {
|
|
7
|
+
info: (message: string, data?: unknown) => void;
|
|
8
|
+
warn: (message: string, data?: unknown) => void;
|
|
9
|
+
error: (message: string, data?: unknown) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const NOOP_LOGGER: WhisperLogger;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { WhisperLogger } from './internal.ts';
|
|
2
|
+
export interface WhisperModelSpec {
|
|
3
|
+
/** GGML filename — identical on disk and in the Hugging Face repo. */
|
|
4
|
+
readonly file: string;
|
|
5
|
+
/** Download URL (Hugging Face whisper.cpp model repo). */
|
|
6
|
+
readonly url: string;
|
|
7
|
+
/** Conservative lower bound on the finished file size, in bytes — guards
|
|
8
|
+
* against a truncated transfer or an HTML error page saved as the model
|
|
9
|
+
* without pinning an exact checksum. */
|
|
10
|
+
readonly minBytes: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const WHISPER_MODELS: {
|
|
13
|
+
readonly "large-v3-turbo": {
|
|
14
|
+
readonly file: "ggml-large-v3-turbo.bin";
|
|
15
|
+
readonly url: "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo.bin";
|
|
16
|
+
readonly minBytes: 1000000000;
|
|
17
|
+
};
|
|
18
|
+
readonly small: {
|
|
19
|
+
readonly file: "ggml-small.bin";
|
|
20
|
+
readonly url: "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin";
|
|
21
|
+
readonly minBytes: 300000000;
|
|
22
|
+
};
|
|
23
|
+
readonly base: {
|
|
24
|
+
readonly file: "ggml-base.bin";
|
|
25
|
+
readonly url: "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.bin";
|
|
26
|
+
readonly minBytes: 100000000;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export type WhisperModelName = keyof typeof WHISPER_MODELS;
|
|
30
|
+
export declare const DEFAULT_WHISPER_MODEL: WhisperModelName;
|
|
31
|
+
export declare function isWhisperModelName(value: unknown): value is WhisperModelName;
|
|
32
|
+
/** Resolve a possibly-unset / unknown model name to a valid one. */
|
|
33
|
+
export declare function resolveModelName(name: string | undefined): WhisperModelName;
|
|
34
|
+
export declare function modelFilePath(modelsDir: string, name: WhisperModelName): string;
|
|
35
|
+
/** A model is "ready" when its file exists and meets the size floor. */
|
|
36
|
+
export declare function isModelReady(modelsDir: string, name: WhisperModelName): boolean;
|
|
37
|
+
export type ModelDownloadState = "idle" | "downloading" | "ready" | "error";
|
|
38
|
+
export interface ModelStatus {
|
|
39
|
+
state: ModelDownloadState;
|
|
40
|
+
/** 0..1 — present only while downloading and Content-Length is known. */
|
|
41
|
+
progress?: number;
|
|
42
|
+
/** Present only in the "error" state. */
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ModelDownloader {
|
|
46
|
+
getStatus: (name: WhisperModelName) => ModelStatus;
|
|
47
|
+
ensure: (name: WhisperModelName) => Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
export declare function createModelDownloader(modelsDir: string, logger?: WhisperLogger): ModelDownloader;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WhisperLogger } from './internal.ts';
|
|
2
|
+
import { WhisperModelName } from './models.ts';
|
|
3
|
+
export interface Sidecar {
|
|
4
|
+
transcribeWav: (wavPath: string, language: string, model: WhisperModelName) => Promise<string>;
|
|
5
|
+
warmup: (model: WhisperModelName) => Promise<void>;
|
|
6
|
+
shutdown: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createSidecar(modelsDir: string, serverBinary?: string, logger?: WhisperLogger): Sidecar;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { WhisperLogger } from './internal.ts';
|
|
2
|
+
import { ModelStatus, WhisperModelName } from './models.ts';
|
|
3
|
+
export interface WhisperOptions {
|
|
4
|
+
/** Directory that holds the GGML model files (e.g. `{workspace}/models`). */
|
|
5
|
+
modelsDir: string;
|
|
6
|
+
logger?: WhisperLogger;
|
|
7
|
+
/** Defaults to "whisper-server" / "ffmpeg" on PATH. */
|
|
8
|
+
serverBinary?: string;
|
|
9
|
+
ffmpegBinary?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TranscribeRequest {
|
|
12
|
+
base64: string;
|
|
13
|
+
mimeType: string;
|
|
14
|
+
language: string;
|
|
15
|
+
model: WhisperModelName;
|
|
16
|
+
}
|
|
17
|
+
export interface Whisper {
|
|
18
|
+
isModelReady: (model: WhisperModelName) => boolean;
|
|
19
|
+
getModelStatus: (model: WhisperModelName) => ModelStatus;
|
|
20
|
+
/** Fire-and-forget friendly; never throws (errors land in the status). */
|
|
21
|
+
ensureModelDownloaded: (model: WhisperModelName) => Promise<void>;
|
|
22
|
+
warmup: (model: WhisperModelName) => Promise<void>;
|
|
23
|
+
transcribe: (req: TranscribeRequest) => Promise<{
|
|
24
|
+
text: string;
|
|
25
|
+
}>;
|
|
26
|
+
shutdown: () => void;
|
|
27
|
+
}
|
|
28
|
+
export declare function createWhisper(opts: WhisperOptions): Whisper;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The bundled help-docs source dir (`assets/helps/`). */
|
|
2
|
+
export declare function helpsAssetDir(): string;
|
|
3
|
+
/** The bundled preset-skills source dir (`assets/skills-preset/`) — pass as the
|
|
4
|
+
* `sourceDir` of `syncPresetSkills` / `syncActivePresetSkills`. */
|
|
5
|
+
export declare function presetSkillsAssetDir(): string;
|
|
6
|
+
/** Copy every bundled help doc into `destDir` (created if missing). Idempotent —
|
|
7
|
+
* overwrites on each call so the help docs always track the package's version. */
|
|
8
|
+
export declare function seedHelps(opts: {
|
|
9
|
+
destDir: string;
|
|
10
|
+
}): void;
|