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.cjs CHANGED
@@ -129,6 +129,20 @@ function inputSignature(input2) {
129
129
  }
130
130
  return (0, import_node_crypto.createHash)("sha1").update(`${(0, import_node_path.resolve)(input2)}|${size}|${mtime}`).digest("hex");
131
131
  }
132
+ function configSignature(o) {
133
+ const relevant = {
134
+ model: o.model ?? DEFAULT_TRANSCRIBE_MODEL,
135
+ reasoner: o.reasoner ?? DEFAULT_REASONER_MODEL,
136
+ instructions: o.instructions ?? "",
137
+ knownSpeakers: o.knownSpeakers ?? [],
138
+ chunkDurationSec: o.chunkDurationSec ?? 600,
139
+ chunkOverlapSec: o.chunkOverlapSec ?? 60,
140
+ screenshotCount: o.screenshotCount ?? 6,
141
+ diarizationLevel: o.diarizationLevel ?? 2,
142
+ timestampedProvider: o.timestampedProvider ?? "assemblyai"
143
+ };
144
+ return (0, import_node_crypto.createHash)("sha1").update(JSON.stringify(relevant)).digest("hex");
145
+ }
132
146
  function planChunks(totalDuration, chunkDuration, overlap2) {
133
147
  const chunks = [];
134
148
  const step = chunkDuration - overlap2;
@@ -423,6 +437,21 @@ function detectMime(path) {
423
437
  return MIME_BY_EXT[ext2] ?? "application/octet-stream";
424
438
  }
425
439
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
440
+ function resolveThinking(model) {
441
+ const m = model.toLowerCase();
442
+ if (m.includes("gemini-2.0")) return void 0;
443
+ if (m.includes("gemini-2.5")) {
444
+ return { thinkingBudget: m.includes("pro") ? 128 : 0 };
445
+ }
446
+ if (m.includes("gemini-3") || m.includes("flash-latest") || m.includes("pro-latest")) {
447
+ return { thinkingLevel: m.includes("pro") ? "LOW" : "MINIMAL" };
448
+ }
449
+ return void 0;
450
+ }
451
+ function isThinkingConfigError(message) {
452
+ if (!message) return false;
453
+ return /thinking/i.test(message) && /(not supported|invalid|unsupported|unknown name|unexpected)/i.test(message);
454
+ }
426
455
  var GeminiClient = class {
427
456
  ai;
428
457
  constructor(apiKey) {
@@ -469,6 +498,8 @@ var GeminiClient = class {
469
498
  config.responseSchema = responseSchema;
470
499
  }
471
500
  if (systemInstruction) config.systemInstruction = systemInstruction;
501
+ const thinking = resolveThinking(model);
502
+ if (thinking) config.thinkingConfig = thinking;
472
503
  const parts = uploaded.map((f) => ({
473
504
  fileData: { fileUri: f.uri, mimeType: f.mimeType }
474
505
  }));
@@ -507,6 +538,11 @@ var GeminiClient = class {
507
538
  return result;
508
539
  } catch (err) {
509
540
  lastError = err instanceof Error ? err.message : String(err);
541
+ if (config.thinkingConfig && isThinkingConfigError(lastError)) {
542
+ delete config.thinkingConfig;
543
+ logger.warn(`[gemini] model ${model} rejected thinking config \u2014 retrying without it`);
544
+ continue;
545
+ }
510
546
  logger.warn(`[gemini] attempt ${attempt + 1}/${maxRetries} failed: ${lastError}`);
511
547
  logLlmCall({
512
548
  ts: new Date(t0).toISOString(),
@@ -1686,6 +1722,12 @@ function has(passes2, p) {
1686
1722
  return passes2.includes(p);
1687
1723
  }
1688
1724
  async function transcribe(opts2) {
1725
+ if (!opts2 || typeof opts2.input !== "string" || opts2.input.length === 0) {
1726
+ throw new Error("transcribe(options): 'input' (path to the audio/video file) is required");
1727
+ }
1728
+ if (typeof opts2.outputDir !== "string" || opts2.outputDir.length === 0) {
1729
+ throw new Error("transcribe(options): 'outputDir' (directory for outputs) is required");
1730
+ }
1689
1731
  const options = resolveOptions(opts2);
1690
1732
  const keys = resolveKeys(options.apiKeys);
1691
1733
  logger.setLevel(options.logLevel);
@@ -1697,15 +1739,26 @@ async function transcribe(opts2) {
1697
1739
  setLlmLogPath(options.llmLog ? `${options.intermediatesDir}/llm-calls.jsonl` : null);
1698
1740
  const sourcePath = `${options.intermediatesDir}/source.json`;
1699
1741
  const sig = inputSignature(options.input);
1742
+ const cfgSig = configSignature(opts2);
1700
1743
  const prevSig = readJson(sourcePath);
1701
1744
  const inputChanged = !prevSig || prevSig.signature !== sig;
1745
+ const configChanged = !prevSig || prevSig.config !== cfgSig;
1702
1746
  if (inputChanged && prevSig) {
1703
1747
  logger.warn(
1704
1748
  `input file changed since last run (was ${prevSig.input ?? "?"}) \u2014 discarding cached intermediates`
1705
1749
  );
1750
+ } else if (configChanged && prevSig) {
1751
+ logger.warn(
1752
+ "options changed since last run (model / chunking / instructions / provider) \u2014 discarding cached intermediates"
1753
+ );
1706
1754
  }
1707
- const forceAll = options.force || inputChanged;
1708
- writeJson(sourcePath, { input: options.input, signature: sig, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
1755
+ const forceAll = options.force || inputChanged || configChanged;
1756
+ writeJson(sourcePath, {
1757
+ input: options.input,
1758
+ signature: sig,
1759
+ config: cfgSig,
1760
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1761
+ });
1709
1762
  const passes2 = options.passes;
1710
1763
  const models = {
1711
1764
  transcribe: options.model ?? DEFAULT_TRANSCRIBE_MODEL,
@@ -1713,6 +1766,18 @@ async function transcribe(opts2) {
1713
1766
  };
1714
1767
  if (!await checkFfmpeg()) throw new Error("ffmpeg/ffprobe not found in PATH");
1715
1768
  if (!keys.gemini) throw new Error("GEMINI_API_KEY (or GOOGLE_API_KEY) is required");
1769
+ const tsProvider = options.timestampedProvider ?? "assemblyai";
1770
+ const willTimestamp = has(passes2, "timestamped") || has(passes2, "align");
1771
+ if (willTimestamp) {
1772
+ if (tsProvider === "assemblyai" && !keys.assemblyai) {
1773
+ throw new Error(
1774
+ "ASSEMBLYAI_API_KEY is required for the timestamped pass (or use --timestamped whisper-groq)"
1775
+ );
1776
+ }
1777
+ if (tsProvider === "whisper-groq" && !keys.groq) {
1778
+ throw new Error("GROQ_API_KEY is required for --timestamped whisper-groq");
1779
+ }
1780
+ }
1716
1781
  let probeInfo = null;
1717
1782
  const audioPath = `${options.intermediatesDir}/audio.flac`;
1718
1783
  const probePath = `${options.intermediatesDir}/probe.json`;
@@ -1835,6 +1900,13 @@ async function transcribe(opts2) {
1835
1900
  (0, import_node_fs4.writeFileSync)(`${llmDir}/chunk_${String(chunk.index).padStart(2, "0")}_raw.json`, result2.raw);
1836
1901
  return tagWith(result2, chunk);
1837
1902
  });
1903
+ const errored = llmChunkResults.filter((r) => r.error);
1904
+ const producedSegments = llmChunkResults.reduce((n, r) => n + r.segments.length, 0);
1905
+ if (llmChunkResults.length > 0 && producedSegments === 0 && errored.length === llmChunkResults.length) {
1906
+ throw new Error(
1907
+ `LLM transcription failed for all ${llmChunkResults.length} chunk(s) with model "${models.transcribe}". First error: ${errored[0].error}`
1908
+ );
1909
+ }
1838
1910
  } else {
1839
1911
  const llmDir = `${options.intermediatesDir}/llm`;
1840
1912
  if (!forceAll && (0, import_node_fs4.existsSync)(llmDir)) {
@@ -1947,7 +2019,10 @@ async function transcribe(opts2) {
1947
2019
  sourceFile: options.input,
1948
2020
  duration,
1949
2021
  processedAt: (/* @__PURE__ */ new Date()).toISOString(),
1950
- models: { transcribe: models.transcribe, timestamped: "assemblyai-universal-2" },
2022
+ models: {
2023
+ transcribe: models.transcribe,
2024
+ timestamped: tsProvider === "whisper-groq" ? "whisper-large-v3 (groq)" : tsProvider === "none" ? "none" : "assemblyai-universal-2"
2025
+ },
1951
2026
  passes: passes2
1952
2027
  };
1953
2028
  const result = { segments: finalSegments, speakers, metadata };
@@ -2012,7 +2087,12 @@ transcribe({
2012
2087
  const segs = result.segments.length;
2013
2088
  console.log(`Done. ${segs} segments.`);
2014
2089
  }).catch((err) => {
2015
- console.error("Fatal:", err);
2090
+ const msg = err instanceof Error ? err.message : String(err);
2091
+ console.error(`
2092
+ \u2717 ${msg}`);
2093
+ if (opts.logLevel === "debug" || process.env.OFFMUTE_DEBUG) {
2094
+ console.error(err instanceof Error ? err.stack : err);
2095
+ }
2016
2096
  process.exit(1);
2017
2097
  });
2018
2098
  //# sourceMappingURL=cli.cjs.map