appostle-installer 0.0.2 → 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/worker.js CHANGED
@@ -4,7 +4,7 @@ const require = __ac_createRequire(import.meta.url);
4
4
  // ../server/src/server/bootstrap.ts
5
5
  import express from "express";
6
6
  import { createServer as createHTTPServer } from "http";
7
- import { createReadStream, unlinkSync, existsSync as existsSync19 } from "fs";
7
+ import { createReadStream, unlinkSync, existsSync as existsSync18 } from "fs";
8
8
  import { stat as stat9 } from "fs/promises";
9
9
  import { randomUUID as randomUUID14 } from "node:crypto";
10
10
  import { hostname as getHostname2 } from "node:os";
@@ -16179,12 +16179,12 @@ function extractPlanNameFromFrontmatter(content) {
16179
16179
  return null;
16180
16180
  }
16181
16181
  function resolvePlanFilename(options) {
16182
- const { originalPath, newSlug, existsSync: existsSync22 } = options;
16182
+ const { originalPath, newSlug, existsSync: existsSync21 } = options;
16183
16183
  const dir = path5.dirname(originalPath);
16184
16184
  const base = `${newSlug}.md`;
16185
16185
  let candidate = path5.join(dir, base);
16186
16186
  let counter = 2;
16187
- while (candidate !== originalPath && existsSync22(candidate)) {
16187
+ while (candidate !== originalPath && existsSync21(candidate)) {
16188
16188
  candidate = path5.join(dir, `${newSlug}-${counter}.md`);
16189
16189
  counter += 1;
16190
16190
  }
@@ -43281,52 +43281,11 @@ var SHERPA_ONNX_MODEL_CATALOG = {
43281
43281
  description: "Kokoro TTS (higher quality; larger).",
43282
43282
  aliases: ["kokoro"],
43283
43283
  defaultFor: "tts"
43284
- },
43285
- "pocket-tts-onnx-int8": {
43286
- kind: "tts",
43287
- extractedDir: "pocket-tts-onnx-int8",
43288
- downloadFiles: [
43289
- {
43290
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/onnx/mimi_encoder.onnx",
43291
- relPath: "onnx/mimi_encoder.onnx"
43292
- },
43293
- {
43294
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/onnx/text_conditioner.onnx",
43295
- relPath: "onnx/text_conditioner.onnx"
43296
- },
43297
- {
43298
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/onnx/flow_lm_main_int8.onnx",
43299
- relPath: "onnx/flow_lm_main_int8.onnx"
43300
- },
43301
- {
43302
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/onnx/flow_lm_flow_int8.onnx",
43303
- relPath: "onnx/flow_lm_flow_int8.onnx"
43304
- },
43305
- {
43306
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/onnx/mimi_decoder_int8.onnx",
43307
- relPath: "onnx/mimi_decoder_int8.onnx"
43308
- },
43309
- {
43310
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/tokenizer.model",
43311
- relPath: "tokenizer.model"
43312
- },
43313
- {
43314
- url: "https://huggingface.co/KevinAHM/pocket-tts-onnx/resolve/main/reference_sample.wav",
43315
- relPath: "reference_sample.wav"
43316
- }
43317
- ],
43318
- requiredFiles: [
43319
- "onnx/mimi_encoder.onnx",
43320
- "onnx/text_conditioner.onnx",
43321
- "onnx/flow_lm_main_int8.onnx",
43322
- "onnx/flow_lm_flow_int8.onnx",
43323
- "onnx/mimi_decoder_int8.onnx",
43324
- "tokenizer.model",
43325
- "reference_sample.wav"
43326
- ],
43327
- description: "Pocket TTS ONNX (INT8) with streaming decode support (via onnxruntime).",
43328
- aliases: ["pocket", "pocket-tts"]
43329
43284
  }
43285
+ // pocket-tts-onnx-int8 was previously listed here. Removed on
43286
+ // 2026-05-02: source was a single individual HuggingFace account
43287
+ // (KevinAHM/pocket-tts-onnx) with no provenance/integrity guarantees.
43288
+ // Re-add only if we host a verified mirror with pinned hashes.
43330
43289
  };
43331
43290
  var ALL_MODEL_IDS = Object.keys(SHERPA_ONNX_MODEL_CATALOG);
43332
43291
  var LOCAL_STT_MODEL_IDS = ALL_MODEL_IDS.filter(
@@ -43575,426 +43534,13 @@ async function ensureLocalSpeechModels(options) {
43575
43534
  });
43576
43535
  }
43577
43536
 
43578
- // ../server/src/server/speech/providers/local/pocket/pocket-tts-onnx.ts
43579
- import { existsSync as existsSync12 } from "node:fs";
43580
- import { readFile as readFile3 } from "node:fs/promises";
43581
- import { Readable as Readable3 } from "node:stream";
43582
- function assertFileExists(filePath, label) {
43583
- if (!existsSync12(filePath)) {
43584
- throw new Error(`Missing ${label}: ${filePath}`);
43585
- }
43586
- }
43587
- function product(dims) {
43588
- let out = 1;
43589
- for (const d of dims) out *= d;
43590
- return out;
43591
- }
43592
- function normalizeDims(dims) {
43593
- return dims.map((d) => {
43594
- if (typeof d === "number" && Number.isFinite(d)) {
43595
- if (d === 0) return 0;
43596
- if (d > 0) return d;
43597
- return 1;
43598
- }
43599
- return 1;
43600
- });
43601
- }
43602
- function getSessionInputMeta(session, inputName) {
43603
- const metaAny = session.inputMetadata;
43604
- if (Array.isArray(metaAny)) {
43605
- const entry = metaAny.find(
43606
- (m) => m && typeof m === "object" && m.name === inputName
43607
- );
43608
- if (!entry) return void 0;
43609
- return { type: entry.type, dims: entry.shape };
43610
- }
43611
- if (metaAny && typeof metaAny === "object" && inputName in metaAny) {
43612
- const entry = metaAny[inputName];
43613
- return { type: entry?.type, dims: entry?.dimensions ?? entry?.shape };
43614
- }
43615
- return void 0;
43616
- }
43617
- function toBigInt64(values) {
43618
- const out = new BigInt64Array(values.length);
43619
- for (let i = 0; i < values.length; i += 1) {
43620
- out[i] = BigInt(values[i]);
43621
- }
43622
- return out;
43623
- }
43624
- function randn() {
43625
- let u = 0;
43626
- let v = 0;
43627
- while (u === 0) u = Math.random();
43628
- while (v === 0) v = Math.random();
43629
- return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
43630
- }
43631
- function normalizeTextForPocket(text) {
43632
- const trimmed = text.trim();
43633
- if (!trimmed) {
43634
- throw new Error("Cannot synthesize empty text");
43635
- }
43636
- let out = trimmed;
43637
- if (out.length > 0 && /[A-Za-z0-9]$/.test(out)) {
43638
- out = `${out}.`;
43639
- }
43640
- if (out.length > 0 && /[a-z]/.test(out[0])) {
43641
- out = out[0].toUpperCase() + out.slice(1);
43642
- }
43643
- return out;
43644
- }
43645
- async function loadOrt() {
43646
- return await import("onnxruntime-node");
43647
- }
43648
- async function loadSentencePiece(tokenizerModelPath) {
43649
- const mod = await import("@sctg/sentencepiece-js");
43650
- const Processor = mod.SentencePieceProcessor ?? mod.default?.SentencePieceProcessor ?? mod.default;
43651
- if (!Processor) {
43652
- throw new Error("Failed to load SentencePiece processor from @sctg/sentencepiece-js");
43653
- }
43654
- const sp = new Processor();
43655
- if (typeof sp.load === "function") {
43656
- await sp.load(tokenizerModelPath);
43657
- } else if (typeof sp.Load === "function") {
43658
- sp.Load(tokenizerModelPath);
43659
- } else {
43660
- throw new Error("SentencePiece processor does not expose load()/Load()");
43661
- }
43662
- return sp;
43663
- }
43664
- function getOrtProviders(ort, device) {
43665
- if (device === "cpu") return ["cpu"];
43666
- if (device === "cuda") return ["cuda", "cpu"];
43667
- void ort;
43668
- return ["cpu"];
43669
- }
43670
- function createZeroTensorForInput(ort, session, inputName) {
43671
- const meta = getSessionInputMeta(session, inputName);
43672
- const dims = normalizeDims(meta?.dims ?? []);
43673
- if (dims.length === 0) {
43674
- throw new Error(`Missing input metadata shape for ${inputName}`);
43675
- }
43676
- const type = (meta?.type ?? "float32").toLowerCase();
43677
- const size = product(dims);
43678
- if (type.includes("int64")) {
43679
- return new ort.Tensor("int64", new BigInt64Array(size), dims);
43680
- }
43681
- if (type.includes("bool")) {
43682
- return new ort.Tensor("bool", new Uint8Array(size), dims);
43683
- }
43684
- return new ort.Tensor("float32", new Float32Array(size), dims);
43685
- }
43686
- function initState(session, ort) {
43687
- const out = {};
43688
- for (const name of session.inputNames) {
43689
- if (name.startsWith("state_")) {
43690
- out[name] = createZeroTensorForInput(ort, session, name);
43691
- }
43692
- }
43693
- return out;
43694
- }
43695
- function updateStateFromOutputs(state, outputs) {
43696
- for (const [name, tensor] of Object.entries(outputs)) {
43697
- if (!name.startsWith("out_state_")) continue;
43698
- const idx = Number.parseInt(name.replace("out_state_", ""), 10);
43699
- if (Number.isFinite(idx)) {
43700
- state[`state_${idx}`] = tensor;
43701
- }
43702
- }
43703
- }
43704
- function tensorDataFloat32(t) {
43705
- const data = t.data;
43706
- if (data instanceof Float32Array) return data;
43707
- if (Array.isArray(data)) return Float32Array.from(data);
43708
- throw new Error("Unexpected tensor data type (expected Float32Array)");
43709
- }
43710
- var PocketTtsOnnxEngine = class _PocketTtsOnnxEngine {
43711
- static {
43712
- this.SAMPLE_RATE = 24e3;
43713
- }
43714
- static {
43715
- this.SAMPLES_PER_FRAME = 1920;
43716
- }
43717
- constructor(args) {
43718
- this.ort = args.ort;
43719
- this.temperature = args.temperature;
43720
- this.lsdSteps = args.lsdSteps;
43721
- this.maxFrames = args.maxFrames;
43722
- this.framesAfterEos = args.framesAfterEos;
43723
- this.firstChunkFrames = args.firstChunkFrames;
43724
- this.maxChunkFrames = args.maxChunkFrames;
43725
- this.tokenizer = args.tokenizer;
43726
- this.textConditioner = args.textConditioner;
43727
- this.flowLmMain = args.flowLmMain;
43728
- this.flowLmFlow = args.flowLmFlow;
43729
- this.mimiDecoder = args.mimiDecoder;
43730
- this.stBuffers = args.stBuffers;
43731
- this.voiceEmbeddings = args.voiceEmbeddings;
43732
- }
43733
- static async create(config, logger) {
43734
- const log = logger.child({
43735
- module: "speech",
43736
- provider: "pocket-tts",
43737
- component: "onnx-engine"
43738
- });
43739
- const modelDir = config.modelDir;
43740
- const onnxDir = `${modelDir}/onnx`;
43741
- const precision = config.precision ?? "int8";
43742
- const device = config.device ?? "auto";
43743
- const temperature = config.temperature ?? 0.7;
43744
- const lsdSteps = config.lsdSteps ?? 10;
43745
- const maxFrames = config.maxFrames ?? 500;
43746
- const framesAfterEos = config.framesAfterEos ?? 3;
43747
- const firstChunkFrames = config.firstChunkFrames ?? 2;
43748
- const maxChunkFrames = config.maxChunkFrames ?? 15;
43749
- const tokenizerPath = `${modelDir}/tokenizer.model`;
43750
- const referenceAudioFile = config.referenceAudioFile ?? `${modelDir}/reference_sample.wav`;
43751
- const flowMainFile = precision === "int8" ? "flow_lm_main_int8.onnx" : "flow_lm_main.onnx";
43752
- const flowFlowFile = precision === "int8" ? "flow_lm_flow_int8.onnx" : "flow_lm_flow.onnx";
43753
- const decoderFile = precision === "int8" ? "mimi_decoder_int8.onnx" : "mimi_decoder.onnx";
43754
- assertFileExists(`${onnxDir}/mimi_encoder.onnx`, "PocketTTS mimi_encoder");
43755
- assertFileExists(`${onnxDir}/text_conditioner.onnx`, "PocketTTS text_conditioner");
43756
- assertFileExists(`${onnxDir}/${flowMainFile}`, "PocketTTS flow_lm_main");
43757
- assertFileExists(`${onnxDir}/${flowFlowFile}`, "PocketTTS flow_lm_flow");
43758
- assertFileExists(`${onnxDir}/${decoderFile}`, "PocketTTS mimi_decoder");
43759
- assertFileExists(tokenizerPath, "PocketTTS tokenizer.model");
43760
- assertFileExists(referenceAudioFile, "PocketTTS reference_sample.wav");
43761
- const ort = await loadOrt();
43762
- const providers = getOrtProviders(ort, device);
43763
- const [tokenizer, mimiEncoder, textConditioner, flowLmMain, flowLmFlow, mimiDecoder] = await Promise.all([
43764
- loadSentencePiece(tokenizerPath),
43765
- ort.InferenceSession.create(`${onnxDir}/mimi_encoder.onnx`, {
43766
- executionProviders: providers
43767
- }),
43768
- ort.InferenceSession.create(`${onnxDir}/text_conditioner.onnx`, {
43769
- executionProviders: providers
43770
- }),
43771
- ort.InferenceSession.create(`${onnxDir}/${flowMainFile}`, {
43772
- executionProviders: providers
43773
- }),
43774
- ort.InferenceSession.create(`${onnxDir}/${flowFlowFile}`, {
43775
- executionProviders: providers
43776
- }),
43777
- ort.InferenceSession.create(`${onnxDir}/${decoderFile}`, { executionProviders: providers })
43778
- ]);
43779
- const stBuffers = [];
43780
- for (let j = 0; j < lsdSteps; j += 1) {
43781
- const s = j / lsdSteps;
43782
- const t = s + 1 / lsdSteps;
43783
- stBuffers.push({
43784
- s: new ort.Tensor("float32", new Float32Array([s]), [1, 1]),
43785
- t: new ort.Tensor("float32", new Float32Array([t]), [1, 1])
43786
- });
43787
- }
43788
- const refWav = await readFile3(referenceAudioFile);
43789
- const parsed = parsePcm16MonoWav(refWav);
43790
- let pcm16 = parsed.pcm16;
43791
- if (parsed.sampleRate !== _PocketTtsOnnxEngine.SAMPLE_RATE) {
43792
- const resampler = new Pcm16MonoResampler({
43793
- inputRate: parsed.sampleRate,
43794
- outputRate: _PocketTtsOnnxEngine.SAMPLE_RATE
43795
- });
43796
- pcm16 = resampler.processChunk(pcm16);
43797
- }
43798
- const floatAudio = pcm16leToFloat32(pcm16);
43799
- const audioTensor = new ort.Tensor("float32", floatAudio, [1, 1, floatAudio.length]);
43800
- const encoded = await mimiEncoder.run({ audio: audioTensor });
43801
- const firstOutName = mimiEncoder.outputNames?.[0];
43802
- const voiceEmb = firstOutName ? encoded[firstOutName] : Object.values(encoded)[0];
43803
- if (!voiceEmb) {
43804
- throw new Error("PocketTTS mimi_encoder: missing output");
43805
- }
43806
- log.info({ precision, device, providers, lsdSteps, temperature }, "PocketTTS ONNX initialized");
43807
- return new _PocketTtsOnnxEngine({
43808
- ort,
43809
- temperature,
43810
- lsdSteps,
43811
- maxFrames,
43812
- framesAfterEos,
43813
- firstChunkFrames,
43814
- maxChunkFrames,
43815
- tokenizer,
43816
- textConditioner,
43817
- flowLmMain,
43818
- flowLmFlow,
43819
- mimiDecoder,
43820
- stBuffers,
43821
- voiceEmbeddings: voiceEmb
43822
- });
43823
- }
43824
- tokenize(text) {
43825
- const normalized = normalizeTextForPocket(text);
43826
- const ids = this.tokenizer.encodeIds(normalized);
43827
- const data = toBigInt64(ids ?? []);
43828
- return new this.ort.Tensor("int64", data, [1, data.length]);
43829
- }
43830
- async runTextConditioner(tokenIds) {
43831
- const out = await this.textConditioner.run({ token_ids: tokenIds });
43832
- const firstOutName = this.textConditioner.outputNames?.[0];
43833
- const t = firstOutName ? out[firstOutName] : Object.values(out)[0];
43834
- if (!t) throw new Error("PocketTTS text_conditioner: missing output");
43835
- return t;
43836
- }
43837
- async *runFlowLm(textEmbeddings) {
43838
- const ort = this.ort;
43839
- const state = initState(this.flowLmMain, ort);
43840
- const emptySeq = new ort.Tensor("float32", new Float32Array(0), [1, 0, 32]);
43841
- const emptyText = new ort.Tensor("float32", new Float32Array(0), [1, 0, 1024]);
43842
- const resVoice = await this.flowLmMain.run({
43843
- sequence: emptySeq,
43844
- text_embeddings: this.voiceEmbeddings,
43845
- ...state
43846
- });
43847
- updateStateFromOutputs(state, resVoice);
43848
- const resText = await this.flowLmMain.run({
43849
- sequence: emptySeq,
43850
- text_embeddings: textEmbeddings,
43851
- ...state
43852
- });
43853
- updateStateFromOutputs(state, resText);
43854
- const curr = new Float32Array(32);
43855
- curr.fill(Number.NaN);
43856
- let currTensor = new ort.Tensor("float32", curr, [1, 1, 32]);
43857
- const dt = 1 / this.lsdSteps;
43858
- let eosStep = null;
43859
- for (let step = 0; step < this.maxFrames; step += 1) {
43860
- const resStep = await this.flowLmMain.run({
43861
- sequence: currTensor,
43862
- text_embeddings: emptyText,
43863
- ...state
43864
- });
43865
- const outputNames = this.flowLmMain.outputNames;
43866
- const conditioningName = outputNames?.[0] ?? Object.keys(resStep)[0];
43867
- const eosName = outputNames?.[1] ?? Object.keys(resStep)[1];
43868
- const conditioning = resStep[conditioningName];
43869
- const eos = resStep[eosName];
43870
- if (!conditioning || !eos) {
43871
- throw new Error("PocketTTS flow_lm_main: missing conditioning/EOS outputs");
43872
- }
43873
- updateStateFromOutputs(state, resStep);
43874
- const eosData = tensorDataFloat32(eos);
43875
- if (eosData[0] > -4 && eosStep === null) {
43876
- eosStep = step;
43877
- }
43878
- if (eosStep !== null && step >= eosStep + this.framesAfterEos) {
43879
- break;
43880
- }
43881
- const std = this.temperature > 0 ? Math.sqrt(this.temperature) : 0;
43882
- const x = new Float32Array(32);
43883
- if (std > 0) {
43884
- for (let i = 0; i < x.length; i += 1) {
43885
- x[i] = randn() * std;
43886
- }
43887
- }
43888
- for (const st of this.stBuffers) {
43889
- const xTensor = new ort.Tensor("float32", x, [1, 32]);
43890
- const flowOut = await this.flowLmFlow.run({
43891
- c: conditioning,
43892
- s: st.s,
43893
- t: st.t,
43894
- x: xTensor
43895
- });
43896
- const first = this.flowLmFlow.outputNames?.[0];
43897
- const flowTensor = first ? flowOut[first] : Object.values(flowOut)[0];
43898
- if (!flowTensor) throw new Error("PocketTTS flow_lm_flow: missing output");
43899
- const delta = tensorDataFloat32(flowTensor);
43900
- for (let i = 0; i < x.length; i += 1) {
43901
- x[i] = x[i] + delta[i] * dt;
43902
- }
43903
- }
43904
- yield x;
43905
- currTensor = new ort.Tensor("float32", x, [1, 1, 32]);
43906
- }
43907
- }
43908
- async decodeLatentsChunk(frames, state) {
43909
- const ort = this.ort;
43910
- const frameCount = frames.length;
43911
- const flattened = new Float32Array(frameCount * 32);
43912
- for (let i = 0; i < frameCount; i += 1) {
43913
- flattened.set(frames[i], i * 32);
43914
- }
43915
- const latent = new ort.Tensor("float32", flattened, [1, frameCount, 32]);
43916
- const out = await this.mimiDecoder.run({ latent, ...state });
43917
- updateStateFromOutputs(state, out);
43918
- const firstOutName = this.mimiDecoder.outputNames?.[0];
43919
- const audioTensor = firstOutName ? out[firstOutName] : Object.values(out)[0];
43920
- if (!audioTensor) {
43921
- throw new Error("PocketTTS mimi_decoder: missing audio output");
43922
- }
43923
- return tensorDataFloat32(audioTensor);
43924
- }
43925
- async *streamAudio(text) {
43926
- const tokenIds = this.tokenize(text);
43927
- const textEmb = await this.runTextConditioner(tokenIds);
43928
- const decoderState = initState(this.mimiDecoder, this.ort);
43929
- const generated = [];
43930
- let decodedFrames = 0;
43931
- for await (const latent of this.runFlowLm(textEmb)) {
43932
- generated.push(latent);
43933
- const pending = generated.length - decodedFrames;
43934
- let chunkSize = 0;
43935
- if (decodedFrames === 0) {
43936
- if (pending >= this.firstChunkFrames) {
43937
- chunkSize = this.firstChunkFrames;
43938
- }
43939
- } else if (pending >= this.maxChunkFrames) {
43940
- chunkSize = this.maxChunkFrames;
43941
- }
43942
- if (chunkSize > 0) {
43943
- const audio = await this.decodeLatentsChunk(
43944
- generated.slice(decodedFrames, decodedFrames + chunkSize),
43945
- decoderState
43946
- );
43947
- decodedFrames += chunkSize;
43948
- yield audio;
43949
- }
43950
- }
43951
- if (decodedFrames < generated.length) {
43952
- const audio = await this.decodeLatentsChunk(generated.slice(decodedFrames), decoderState);
43953
- yield audio;
43954
- }
43955
- }
43956
- };
43957
- var PocketTtsOnnxTTS = class _PocketTtsOnnxTTS {
43958
- constructor(engine, logger, chunkMs) {
43959
- this.engine = engine;
43960
- this.chunkMs = chunkMs;
43961
- this.logger = logger.child({ module: "speech", provider: "pocket-tts", component: "tts" });
43962
- }
43963
- static async create(config, logger) {
43964
- const engine = await PocketTtsOnnxEngine.create(config, logger);
43965
- const chunkMs = config.targetChunkMs ?? 50;
43966
- return new _PocketTtsOnnxTTS(engine, logger, chunkMs);
43967
- }
43968
- async synthesizeSpeech(text) {
43969
- const start = Date.now();
43970
- const sampleRate = PocketTtsOnnxEngine.SAMPLE_RATE;
43971
- const pcmChunkBytes = Math.max(2, Math.round(sampleRate * this.chunkMs / 1e3) * 2);
43972
- const iterable = (async function* (engine) {
43973
- for await (const floatChunk of engine.streamAudio(text)) {
43974
- const pcm = float32ToPcm16le(floatChunk);
43975
- for (const chunk of chunkBuffer(pcm, pcmChunkBytes)) {
43976
- yield chunk;
43977
- }
43978
- }
43979
- })(this.engine);
43980
- this.logger.debug(
43981
- { ms: Date.now() - start, textLength: text.length },
43982
- "PocketTTS stream ready"
43983
- );
43984
- return {
43985
- stream: Readable3.from(iterable),
43986
- format: `pcm;rate=${sampleRate}`
43987
- };
43988
- }
43989
- };
43990
-
43991
43537
  // ../server/src/server/speech/providers/local/sherpa/sherpa-offline-recognizer.ts
43992
- import { existsSync as existsSync14 } from "node:fs";
43538
+ import { existsSync as existsSync13 } from "node:fs";
43993
43539
 
43994
43540
  // ../server/src/server/speech/providers/local/sherpa/sherpa-onnx-node-loader.ts
43995
43541
  import { createRequire as createRequire4 } from "node:module";
43996
43542
  import path18 from "node:path";
43997
- import { existsSync as existsSync13 } from "node:fs";
43543
+ import { existsSync as existsSync12 } from "node:fs";
43998
43544
  import { spawnSync } from "node:child_process";
43999
43545
 
44000
43546
  // ../server/src/server/speech/providers/local/sherpa/sherpa-runtime-env.ts
@@ -44147,7 +43693,7 @@ function loadSherpaOnnxNode() {
44147
43693
  if (platformPkgDir) {
44148
43694
  applySherpaLoaderEnv(process.env);
44149
43695
  const addonPath = path18.join(platformPkgDir, "sherpa-onnx.node");
44150
- if (existsSync13(addonPath)) {
43696
+ if (existsSync12(addonPath)) {
44151
43697
  const byPath = loadWithRequire(require4, addonPath, attempts);
44152
43698
  if (byPath) {
44153
43699
  cached = byPath;
@@ -44165,8 +43711,8 @@ function loadSherpaOnnxNode() {
44165
43711
  }
44166
43712
 
44167
43713
  // ../server/src/server/speech/providers/local/sherpa/sherpa-offline-recognizer.ts
44168
- function assertFileExists2(filePath, label) {
44169
- if (!existsSync14(filePath)) {
43714
+ function assertFileExists(filePath, label) {
43715
+ if (!existsSync13(filePath)) {
44170
43716
  throw new Error(`Missing ${label}: ${filePath}`);
44171
43717
  }
44172
43718
  }
@@ -44177,10 +43723,10 @@ var SherpaOfflineRecognizerEngine = class {
44177
43723
  provider: "local",
44178
43724
  component: "offline-recognizer"
44179
43725
  });
44180
- assertFileExists2(config.model.encoder, "offline encoder");
44181
- assertFileExists2(config.model.decoder, "offline decoder");
44182
- assertFileExists2(config.model.joiner, "offline joiner");
44183
- assertFileExists2(config.model.tokens, "tokens");
43726
+ assertFileExists(config.model.encoder, "offline encoder");
43727
+ assertFileExists(config.model.decoder, "offline decoder");
43728
+ assertFileExists(config.model.joiner, "offline joiner");
43729
+ assertFileExists(config.model.tokens, "tokens");
44184
43730
  const sherpa = loadSherpaOnnxNode();
44185
43731
  const recognizerConfig = {
44186
43732
  featConfig: {
@@ -44233,7 +43779,7 @@ var SherpaOfflineRecognizerEngine = class {
44233
43779
  };
44234
43780
 
44235
43781
  // ../server/src/server/speech/providers/local/sherpa/sherpa-online-recognizer.ts
44236
- import { existsSync as existsSync15 } from "node:fs";
43782
+ import { existsSync as existsSync14 } from "node:fs";
44237
43783
 
44238
43784
  // ../server/src/server/speech/providers/local/sherpa/sherpa-onnx-loader.ts
44239
43785
  import { createRequire as createRequire5 } from "node:module";
@@ -44248,8 +43794,8 @@ function loadSherpaOnnx() {
44248
43794
  }
44249
43795
 
44250
43796
  // ../server/src/server/speech/providers/local/sherpa/sherpa-online-recognizer.ts
44251
- function assertFileExists3(filePath, label) {
44252
- if (!existsSync15(filePath)) {
43797
+ function assertFileExists2(filePath, label) {
43798
+ if (!existsSync14(filePath)) {
44253
43799
  throw new Error(`Missing ${label}: ${filePath}`);
44254
43800
  }
44255
43801
  }
@@ -44262,14 +43808,14 @@ var SherpaOnlineRecognizerEngine = class {
44262
43808
  });
44263
43809
  const { model } = config;
44264
43810
  if (model.kind === "transducer") {
44265
- assertFileExists3(model.encoder, "transducer encoder");
44266
- assertFileExists3(model.decoder, "transducer decoder");
44267
- assertFileExists3(model.joiner, "transducer joiner");
44268
- assertFileExists3(model.tokens, "tokens");
43811
+ assertFileExists2(model.encoder, "transducer encoder");
43812
+ assertFileExists2(model.decoder, "transducer decoder");
43813
+ assertFileExists2(model.joiner, "transducer joiner");
43814
+ assertFileExists2(model.tokens, "tokens");
44269
43815
  } else {
44270
- assertFileExists3(model.encoder, "paraformer encoder");
44271
- assertFileExists3(model.decoder, "paraformer decoder");
44272
- assertFileExists3(model.tokens, "tokens");
43816
+ assertFileExists2(model.encoder, "paraformer encoder");
43817
+ assertFileExists2(model.decoder, "paraformer decoder");
43818
+ assertFileExists2(model.tokens, "tokens");
44273
43819
  }
44274
43820
  const sherpa = loadSherpaOnnx();
44275
43821
  const modelConfig = model.kind === "transducer" ? {
@@ -44824,10 +44370,10 @@ var SherpaOnnxSTT = class {
44824
44370
  };
44825
44371
 
44826
44372
  // ../server/src/server/speech/providers/local/sherpa/sherpa-tts.ts
44827
- import { Readable as Readable4 } from "node:stream";
44828
- import { existsSync as existsSync16 } from "node:fs";
44829
- function assertFileExists4(filePath, label) {
44830
- if (!existsSync16(filePath)) {
44373
+ import { Readable as Readable3 } from "node:stream";
44374
+ import { existsSync as existsSync15 } from "node:fs";
44375
+ function assertFileExists3(filePath, label) {
44376
+ if (!existsSync15(filePath)) {
44831
44377
  throw new Error(`Missing ${label}: ${filePath}`);
44832
44378
  }
44833
44379
  }
@@ -44848,10 +44394,10 @@ var SherpaOnnxTTS = class {
44848
44394
  const voicesPath = `${config.modelDir}/voices.bin`;
44849
44395
  const tokensPath = `${config.modelDir}/tokens.txt`;
44850
44396
  const dataDir = `${config.modelDir}/espeak-ng-data`;
44851
- assertFileExists4(modelPath, "TTS model");
44852
- assertFileExists4(voicesPath, "TTS voices");
44853
- assertFileExists4(tokensPath, "TTS tokens");
44854
- assertFileExists4(dataDir, "TTS espeak-ng dataDir");
44397
+ assertFileExists3(modelPath, "TTS model");
44398
+ assertFileExists3(voicesPath, "TTS voices");
44399
+ assertFileExists3(tokensPath, "TTS tokens");
44400
+ assertFileExists3(dataDir, "TTS espeak-ng dataDir");
44855
44401
  const modelConfig = config.preset === "kokoro-en-v0_19" ? {
44856
44402
  kokoro: {
44857
44403
  model: modelPath,
@@ -44904,7 +44450,7 @@ var SherpaOnnxTTS = class {
44904
44450
  const chunkBytes = Math.max(2, Math.round(sampleRate * 0.05) * 2);
44905
44451
  const chunks = chunkBuffer(pcm16, chunkBytes);
44906
44452
  return {
44907
- stream: Readable4.from(chunks),
44453
+ stream: Readable3.from(chunks),
44908
44454
  format: `pcm;rate=${sampleRate}`
44909
44455
  };
44910
44456
  }
@@ -45350,20 +44896,7 @@ async function initializeLocalSpeechServices(params) {
45350
44896
  );
45351
44897
  } else {
45352
44898
  try {
45353
- if (localModels.voiceLocalTtsModel === "pocket-tts-onnx-int8") {
45354
- const modelDir = getLocalSpeechModelDir(
45355
- localConfig.modelsDir,
45356
- localModels.voiceLocalTtsModel
45357
- );
45358
- localVoiceTtsProvider = await PocketTtsOnnxTTS.create(
45359
- {
45360
- modelDir,
45361
- precision: "int8",
45362
- targetChunkMs: 50
45363
- },
45364
- logger
45365
- );
45366
- } else {
44899
+ {
45367
44900
  const modelDir = getLocalSpeechModelDir(
45368
44901
  localConfig.modelsDir,
45369
44902
  localModels.voiceLocalTtsModel
@@ -46548,7 +46081,7 @@ import { z as z33 } from "zod";
46548
46081
  import { getSessionMessages } from "@anthropic-ai/claude-agent-sdk";
46549
46082
 
46550
46083
  // ../server/src/server/agent/session-fork.ts
46551
- import { readFileSync as readFileSync8, writeFileSync as writeFileSync7, readdirSync, existsSync as existsSync17 } from "node:fs";
46084
+ import { readFileSync as readFileSync8, writeFileSync as writeFileSync7, readdirSync, existsSync as existsSync16 } from "node:fs";
46552
46085
  import { dirname as dirname6, join as join12 } from "node:path";
46553
46086
  import { homedir as homedir5 } from "node:os";
46554
46087
  var ForkPointInvalidError = class extends Error {
@@ -46570,11 +46103,11 @@ function jsonLineIsToolResultUser(json) {
46570
46103
  function findClaudeSessionFile(params) {
46571
46104
  const home = params.claudeHomeDir ?? join12(homedir5(), ".claude");
46572
46105
  const projectsDir = join12(home, "projects");
46573
- if (!existsSync17(projectsDir)) return null;
46106
+ if (!existsSync16(projectsDir)) return null;
46574
46107
  for (const entry of readdirSync(projectsDir, { withFileTypes: true })) {
46575
46108
  if (!entry.isDirectory()) continue;
46576
46109
  const candidate = join12(projectsDir, entry.name, `${params.sessionId}.jsonl`);
46577
- if (existsSync17(candidate)) return candidate;
46110
+ if (existsSync16(candidate)) return candidate;
46578
46111
  }
46579
46112
  return null;
46580
46113
  }
@@ -46626,7 +46159,7 @@ function forkSession(input) {
46626
46159
  const lastCopiedIndex = nextUserLineIndex === -1 ? lines.length - 1 : nextUserLineIndex - 1;
46627
46160
  const copied = lines.slice(0, lastCopiedIndex + 1).filter((l) => l.length > 0);
46628
46161
  const targetDir = dirname6(input.targetSessionPath);
46629
- if (!existsSync17(targetDir)) {
46162
+ if (!existsSync16(targetDir)) {
46630
46163
  throw new Error(`Target directory does not exist: ${targetDir}`);
46631
46164
  }
46632
46165
  writeFileSync7(input.targetSessionPath, copied.join("\n") + "\n", "utf-8");
@@ -52008,7 +51541,7 @@ import { join as join15 } from "node:path";
52008
51541
 
52009
51542
  // ../server/src/server/schedule/store.ts
52010
51543
  import { randomBytes as randomBytes2 } from "node:crypto";
52011
- import { mkdir as mkdir6, readFile as readFile4, readdir as readdir4, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
51544
+ import { mkdir as mkdir6, readFile as readFile3, readdir as readdir4, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
52012
51545
  import { join as join14 } from "node:path";
52013
51546
  function generateScheduleId() {
52014
51547
  return randomBytes2(4).toString("hex");
@@ -52028,7 +51561,7 @@ var ScheduleStore = class {
52028
51561
  const entries = await readdir4(this.dir, { withFileTypes: true });
52029
51562
  const schedules = await Promise.all(
52030
51563
  entries.filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map(async (entry) => {
52031
- const content = await readFile4(join14(this.dir, entry.name), "utf-8");
51564
+ const content = await readFile3(join14(this.dir, entry.name), "utf-8");
52032
51565
  return StoredScheduleSchema.parse(JSON.parse(content));
52033
51566
  })
52034
51567
  );
@@ -52037,7 +51570,7 @@ var ScheduleStore = class {
52037
51570
  async get(id) {
52038
51571
  await this.ensureDir();
52039
51572
  try {
52040
- const content = await readFile4(this.filePath(id), "utf-8");
51573
+ const content = await readFile3(this.filePath(id), "utf-8");
52041
51574
  return StoredScheduleSchema.parse(JSON.parse(content));
52042
51575
  } catch (error) {
52043
51576
  if (error.code === "ENOENT") {
@@ -52647,7 +52180,7 @@ function mergeMutableConfigIntoPersistedConfig(params) {
52647
52180
 
52648
52181
  // ../server/src/server/workspace-git-service.ts
52649
52182
  import { watch } from "node:fs";
52650
- import { readFile as readFile5, readdir as readdir5 } from "node:fs/promises";
52183
+ import { readFile as readFile4, readdir as readdir5 } from "node:fs/promises";
52651
52184
  import { join as join16, resolve as resolve12 } from "node:path";
52652
52185
  var WORKSPACE_GIT_WATCH_DEBOUNCE_MS = 500;
52653
52186
  var BACKGROUND_GIT_FETCH_INTERVAL_MS = 18e4;
@@ -52877,7 +52410,7 @@ var WorkspaceGitServiceImpl = class {
52877
52410
  }
52878
52411
  async resolveWorkspaceGitRefsRoot(gitDir) {
52879
52412
  try {
52880
- const commonDir = (await readFile5(join16(gitDir, "commondir"), "utf8")).trim();
52413
+ const commonDir = (await readFile4(join16(gitDir, "commondir"), "utf8")).trim();
52881
52414
  if (commonDir.length > 0) {
52882
52415
  return resolve12(gitDir, commonDir);
52883
52416
  }
@@ -54103,7 +53636,7 @@ function createAuthServerClient(options) {
54103
53636
  }
54104
53637
 
54105
53638
  // ../server/src/server/package-version.ts
54106
- import { existsSync as existsSync18, readFileSync as readFileSync9 } from "node:fs";
53639
+ import { existsSync as existsSync17, readFileSync as readFileSync9 } from "node:fs";
54107
53640
  import path23 from "node:path";
54108
53641
  import { fileURLToPath as fileURLToPath3 } from "node:url";
54109
53642
  var PackageVersionResolutionError = class extends Error {
@@ -54117,7 +53650,7 @@ function resolvePackageVersion(params) {
54117
53650
  let currentDir = path23.dirname(fileURLToPath3(moduleUrl));
54118
53651
  while (true) {
54119
53652
  const packageJsonPath = path23.join(currentDir, "package.json");
54120
- if (existsSync18(packageJsonPath)) {
53653
+ if (existsSync17(packageJsonPath)) {
54121
53654
  try {
54122
53655
  const packageJson = JSON.parse(readFileSync9(packageJsonPath, "utf8"));
54123
53656
  if (packageJson.name === params.packageName) {
@@ -54974,7 +54507,7 @@ async function createAppostleDaemon(config, rootLogger) {
54974
54507
  if (listenTarget.type === "tcp") {
54975
54508
  httpServer.listen(listenTarget.port, listenTarget.host);
54976
54509
  } else {
54977
- if (listenTarget.type === "socket" && existsSync19(listenTarget.path)) {
54510
+ if (listenTarget.type === "socket" && existsSync18(listenTarget.path)) {
54978
54511
  unlinkSync(listenTarget.path);
54979
54512
  }
54980
54513
  httpServer.listen(listenTarget.path);
@@ -55004,7 +54537,7 @@ async function createAppostleDaemon(config, rootLogger) {
55004
54537
  await new Promise((resolve14) => {
55005
54538
  httpServer.close(() => resolve14());
55006
54539
  });
55007
- if (listenTarget.type === "socket" && existsSync19(listenTarget.path)) {
54540
+ if (listenTarget.type === "socket" && existsSync18(listenTarget.path)) {
55008
54541
  unlinkSync(listenTarget.path);
55009
54542
  }
55010
54543
  };
@@ -55343,7 +54876,7 @@ function loadConfig(appostleHome, options) {
55343
54876
  }
55344
54877
 
55345
54878
  // ../server/src/server/logger.ts
55346
- import { existsSync as existsSync20, mkdirSync as mkdirSync7, readdirSync as readdirSync2, renameSync as renameSync3, unlinkSync as unlinkSync2 } from "node:fs";
54879
+ import { existsSync as existsSync19, mkdirSync as mkdirSync7, readdirSync as readdirSync2, renameSync as renameSync3, unlinkSync as unlinkSync2 } from "node:fs";
55347
54880
  import path27 from "node:path";
55348
54881
  import pino from "pino";
55349
54882
  import pretty from "pino-pretty";
@@ -55430,7 +54963,7 @@ function normalizeLoggerConfigInput(config) {
55430
54963
  return config;
55431
54964
  }
55432
54965
  function rotateOnRestart(filePath, maxFiles) {
55433
- if (!existsSync20(filePath)) return;
54966
+ if (!existsSync19(filePath)) return;
55434
54967
  const dir = path27.dirname(filePath);
55435
54968
  const base = path27.basename(filePath);
55436
54969
  const now = /* @__PURE__ */ new Date();
@@ -55515,8 +55048,8 @@ function createRootLogger(configInput, options) {
55515
55048
  }
55516
55049
 
55517
55050
  // ../server/src/server/pid-lock.ts
55518
- import { open, readFile as readFile6, unlink as unlink2, mkdir as mkdir7 } from "node:fs/promises";
55519
- import { existsSync as existsSync21 } from "node:fs";
55051
+ import { open, readFile as readFile5, unlink as unlink2, mkdir as mkdir7 } from "node:fs/promises";
55052
+ import { existsSync as existsSync20 } from "node:fs";
55520
55053
  import { join as join17 } from "node:path";
55521
55054
  import { hostname } from "node:os";
55522
55055
  var PidLockError = class extends Error {
@@ -55545,12 +55078,12 @@ function resolveOwnerPid(ownerPid) {
55545
55078
  }
55546
55079
  async function acquirePidLock(appostleHome, listen, options) {
55547
55080
  const pidPath = getPidFilePath(appostleHome);
55548
- if (!existsSync21(appostleHome)) {
55081
+ if (!existsSync20(appostleHome)) {
55549
55082
  await mkdir7(appostleHome, { recursive: true });
55550
55083
  }
55551
55084
  let existingLock = null;
55552
55085
  try {
55553
- const content = await readFile6(pidPath, "utf-8");
55086
+ const content = await readFile5(pidPath, "utf-8");
55554
55087
  existingLock = JSON.parse(content);
55555
55088
  } catch {
55556
55089
  }
@@ -55583,7 +55116,7 @@ async function acquirePidLock(appostleHome, listen, options) {
55583
55116
  } catch (err) {
55584
55117
  if (err.code === "EEXIST") {
55585
55118
  try {
55586
- const content = await readFile6(pidPath, "utf-8");
55119
+ const content = await readFile5(pidPath, "utf-8");
55587
55120
  const raceLock = JSON.parse(content);
55588
55121
  throw new PidLockError(
55589
55122
  `Another Appostle daemon is already running (PID ${raceLock.pid})`,
@@ -55602,7 +55135,7 @@ async function acquirePidLock(appostleHome, listen, options) {
55602
55135
  async function updatePidLock(appostleHome, patch, options) {
55603
55136
  const pidPath = getPidFilePath(appostleHome);
55604
55137
  const lockOwnerPid = resolveOwnerPid(options?.ownerPid);
55605
- const content = await readFile6(pidPath, "utf-8");
55138
+ const content = await readFile5(pidPath, "utf-8");
55606
55139
  const existingLock = JSON.parse(content);
55607
55140
  if (existingLock.pid !== lockOwnerPid) {
55608
55141
  throw new PidLockError(`Cannot update PID lock owned by PID ${existingLock.pid}`, existingLock);
@@ -55623,7 +55156,7 @@ async function releasePidLock(appostleHome, options) {
55623
55156
  const pidPath = getPidFilePath(appostleHome);
55624
55157
  const lockOwnerPid = resolveOwnerPid(options?.ownerPid);
55625
55158
  try {
55626
- const content = await readFile6(pidPath, "utf-8");
55159
+ const content = await readFile5(pidPath, "utf-8");
55627
55160
  const lock = JSON.parse(content);
55628
55161
  if (lock.pid === lockOwnerPid) {
55629
55162
  await unlink2(pidPath);