offmute-v2 0.0.1 → 0.0.3

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/dist/cli.js CHANGED
@@ -102,6 +102,20 @@ function inputSignature(input2) {
102
102
  }
103
103
  return createHash("sha1").update(`${resolve(input2)}|${size}|${mtime}`).digest("hex");
104
104
  }
105
+ function configSignature(o) {
106
+ const relevant = {
107
+ model: o.model ?? DEFAULT_TRANSCRIBE_MODEL,
108
+ reasoner: o.reasoner ?? DEFAULT_REASONER_MODEL,
109
+ instructions: o.instructions ?? "",
110
+ knownSpeakers: o.knownSpeakers ?? [],
111
+ chunkDurationSec: o.chunkDurationSec ?? 600,
112
+ chunkOverlapSec: o.chunkOverlapSec ?? 60,
113
+ screenshotCount: o.screenshotCount ?? 6,
114
+ diarizationLevel: o.diarizationLevel ?? 2,
115
+ timestampedProvider: o.timestampedProvider ?? "assemblyai"
116
+ };
117
+ return createHash("sha1").update(JSON.stringify(relevant)).digest("hex");
118
+ }
105
119
  function planChunks(totalDuration, chunkDuration, overlap2) {
106
120
  const chunks = [];
107
121
  const step = chunkDuration - overlap2;
@@ -396,6 +410,21 @@ function detectMime(path) {
396
410
  return MIME_BY_EXT[ext2] ?? "application/octet-stream";
397
411
  }
398
412
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
413
+ function resolveThinking(model) {
414
+ const m = model.toLowerCase();
415
+ if (m.includes("gemini-2.0")) return void 0;
416
+ if (m.includes("gemini-2.5")) {
417
+ return { thinkingBudget: m.includes("pro") ? 128 : 0 };
418
+ }
419
+ if (m.includes("gemini-3") || m.includes("flash-latest") || m.includes("pro-latest")) {
420
+ return { thinkingLevel: m.includes("pro") ? "LOW" : "MINIMAL" };
421
+ }
422
+ return void 0;
423
+ }
424
+ function isThinkingConfigError(message) {
425
+ if (!message) return false;
426
+ return /thinking/i.test(message) && /(not supported|invalid|unsupported|unknown name|unexpected)/i.test(message);
427
+ }
399
428
  var GeminiClient = class {
400
429
  ai;
401
430
  constructor(apiKey) {
@@ -442,6 +471,8 @@ var GeminiClient = class {
442
471
  config.responseSchema = responseSchema;
443
472
  }
444
473
  if (systemInstruction) config.systemInstruction = systemInstruction;
474
+ const thinking = resolveThinking(model);
475
+ if (thinking) config.thinkingConfig = thinking;
445
476
  const parts = uploaded.map((f) => ({
446
477
  fileData: { fileUri: f.uri, mimeType: f.mimeType }
447
478
  }));
@@ -480,6 +511,11 @@ var GeminiClient = class {
480
511
  return result;
481
512
  } catch (err) {
482
513
  lastError = err instanceof Error ? err.message : String(err);
514
+ if (config.thinkingConfig && isThinkingConfigError(lastError)) {
515
+ delete config.thinkingConfig;
516
+ logger.warn(`[gemini] model ${model} rejected thinking config \u2014 retrying without it`);
517
+ continue;
518
+ }
483
519
  logger.warn(`[gemini] attempt ${attempt + 1}/${maxRetries} failed: ${lastError}`);
484
520
  logLlmCall({
485
521
  ts: new Date(t0).toISOString(),
@@ -1659,6 +1695,12 @@ function has(passes2, p) {
1659
1695
  return passes2.includes(p);
1660
1696
  }
1661
1697
  async function transcribe(opts2) {
1698
+ if (!opts2 || typeof opts2.input !== "string" || opts2.input.length === 0) {
1699
+ throw new Error("transcribe(options): 'input' (path to the audio/video file) is required");
1700
+ }
1701
+ if (typeof opts2.outputDir !== "string" || opts2.outputDir.length === 0) {
1702
+ throw new Error("transcribe(options): 'outputDir' (directory for outputs) is required");
1703
+ }
1662
1704
  const options = resolveOptions(opts2);
1663
1705
  const keys = resolveKeys(options.apiKeys);
1664
1706
  logger.setLevel(options.logLevel);
@@ -1670,15 +1712,26 @@ async function transcribe(opts2) {
1670
1712
  setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
1671
1713
  const sourcePath = `${options.intermediatesDir}/source.json`;
1672
1714
  const sig = inputSignature(options.input);
1715
+ const cfgSig = configSignature(opts2);
1673
1716
  const prevSig = readJson(sourcePath);
1674
1717
  const inputChanged = !prevSig || prevSig.signature !== sig;
1718
+ const configChanged = !prevSig || prevSig.config !== cfgSig;
1675
1719
  if (inputChanged && prevSig) {
1676
1720
  logger.warn(
1677
1721
  `input file changed since last run (was ${prevSig.input ?? "?"}) \u2014 discarding cached intermediates`
1678
1722
  );
1723
+ } else if (configChanged && prevSig) {
1724
+ logger.warn(
1725
+ "options changed since last run (model / chunking / instructions / provider) \u2014 discarding cached intermediates"
1726
+ );
1679
1727
  }
1680
- const forceAll = options.force || inputChanged;
1681
- writeJson(sourcePath, { input: options.input, signature: sig, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
1728
+ const forceAll = options.force || inputChanged || configChanged;
1729
+ writeJson(sourcePath, {
1730
+ input: options.input,
1731
+ signature: sig,
1732
+ config: cfgSig,
1733
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1734
+ });
1682
1735
  const passes2 = options.passes;
1683
1736
  const models = {
1684
1737
  transcribe: options.model ?? DEFAULT_TRANSCRIBE_MODEL,
@@ -1686,6 +1739,18 @@ async function transcribe(opts2) {
1686
1739
  };
1687
1740
  if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
1688
1741
  if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
1742
+ const tsProvider = options.timestampedProvider ?? "assemblyai";
1743
+ const willTimestamp = has(passes2, "timestamped") || has(passes2, "align");
1744
+ if (willTimestamp) {
1745
+ if (tsProvider === "assemblyai" && !keys.assemblyai) {
1746
+ throw new Error(
1747
+ "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)"
1748
+ );
1749
+ }
1750
+ if (tsProvider === "whisper-groq" && !keys.groq) {
1751
+ throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
1752
+ }
1753
+ }
1689
1754
  let probeInfo = null;
1690
1755
  const audioPath = `${options.intermediatesDir}/audio.flac`;
1691
1756
  const probePath = `${options.intermediatesDir}/probe.json`;
@@ -1808,6 +1873,13 @@ async function transcribe(opts2) {
1808
1873
  writeFileSync(`${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`, result2.raw);
1809
1874
  return tagWith(result2, chunk);
1810
1875
  });
1876
+ const errored = llmChunkResults.filter((r) => r.error);
1877
+ const producedSegments = llmChunkResults.reduce((n, r) => n + r.segments.length, 0);
1878
+ if (llmChunkResults.length > 0 && producedSegments === 0 && errored.length === llmChunkResults.length) {
1879
+ throw new Error(
1880
+ `LLM transcription failed for all ${llmChunkResults.length} chunk(s) with model "${models.transcribe}". First error: ${errored[0].error}`
1881
+ );
1882
+ }
1811
1883
  } else {
1812
1884
  const llmDir = `${options.intermediatesDir}/llm`;
1813
1885
  if (!forceAll && existsSync2(llmDir)) {
@@ -1920,7 +1992,10 @@ async function transcribe(opts2) {
1920
1992
  sourceFile: options.input,
1921
1993
  duration,
1922
1994
  processedAt: (/* @__PURE__ */ new Date()).toISOString(),
1923
- models: { transcribe: models.transcribe, timestamped: "assemblyai-universal-2" },
1995
+ models: {
1996
+ transcribe: models.transcribe,
1997
+ timestamped: tsProvider === "whisper-groq" ? "whisper-large-v3 (groq)" : tsProvider === "none" ? "none" : "assemblyai-universal-2"
1998
+ },
1924
1999
  passes: passes2
1925
2000
  };
1926
2001
  const result = { segments: finalSegments, speakers, metadata };
@@ -1985,7 +2060,12 @@ transcribe({
1985
2060
  const segs = result.segments.length;
1986
2061
  console.log(`Done. ${segs} segments.`);
1987
2062
  }).catch((err) => {
1988
- console.error("Fatal:", err);
2063
+ const msg = err instanceof Error ? err.message : String(err);
2064
+ console.error(`
2065
+ \u2717 ${msg}`);
2066
+ if (opts.logLevel === "debug" || process.env.OFFMUTE_DEBUG) {
2067
+ console.error(err instanceof Error ? err.stack : err);
2068
+ }
1989
2069
  process.exit(1);
1990
2070
  });
1991
2071
  //# sourceMappingURL=cli.js.map