apirela17 commited on
Commit
fa911b4
·
verified ·
1 Parent(s): 5bb7afd

Deploy voice-call-wasm 0.1.4

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +23 -5
  2. __fusor/g-1793728780335015000-24920/boot.js +9 -0
  3. __fusor/g-1793728780335015000-24920/pkg/app.d.ts +44 -0
  4. __fusor/g-1793728780335015000-24920/pkg/app.js +3 -0
  5. __fusor/g-1793728780335015000-24920/pkg/app_bg.wasm +3 -0
  6. __fusor/g-1793728780335015000-24920/pkg/app_bg.wasm.d.ts +15 -0
  7. __fusor/g-1793728780335015000-24920/pkg/javascript-bundle.json +15 -0
  8. __fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/inline0.js +68 -0
  9. __fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/src/dom/mount/flat.js +393 -0
  10. __fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/src/dom/strings.js +89 -0
  11. __fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js +78 -0
  12. app.css +145 -0
  13. base.css +179 -0
  14. brand/fusor-ai.svg +9 -0
  15. brand/voice-call.svg +7 -0
  16. engine/asr.js +87 -0
  17. engine/capture.js +93 -0
  18. engine/dist/host/loader.js +234 -0
  19. engine/dist/host/worker.js +94 -0
  20. engine/dist/lfm3/web-single-relaxed/lfm3_runtime.js +419 -0
  21. engine/dist/lfm3/web-single-relaxed/lfm3_runtime_bg.wasm +3 -0
  22. engine/dist/lfm3/web-single/lfm3_runtime.js +419 -0
  23. engine/dist/lfm3/web-single/lfm3_runtime_bg.wasm +3 -0
  24. engine/dist/lfm3/web-threaded-relaxed/lfm3_runtime.js +547 -0
  25. engine/dist/lfm3/web-threaded-relaxed/lfm3_runtime_bg.wasm +3 -0
  26. engine/dist/lfm3/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js +8 -0
  27. engine/dist/lfm3/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +55 -0
  28. engine/dist/lfm3/web-threaded/lfm3_runtime.js +547 -0
  29. engine/dist/lfm3/web-threaded/lfm3_runtime_bg.wasm +3 -0
  30. engine/dist/lfm3/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js +8 -0
  31. engine/dist/lfm3/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +55 -0
  32. engine/dist/parakeet/web-single-relaxed/parakeet_runtime.js +453 -0
  33. engine/dist/parakeet/web-single-relaxed/parakeet_runtime_bg.wasm +3 -0
  34. engine/dist/parakeet/web-single/parakeet_runtime.js +453 -0
  35. engine/dist/parakeet/web-single/parakeet_runtime_bg.wasm +3 -0
  36. engine/dist/parakeet/web-threaded-relaxed/parakeet_runtime.js +581 -0
  37. engine/dist/parakeet/web-threaded-relaxed/parakeet_runtime_bg.wasm +3 -0
  38. engine/dist/parakeet/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js +8 -0
  39. engine/dist/parakeet/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +55 -0
  40. engine/dist/parakeet/web-threaded/parakeet_runtime.js +581 -0
  41. engine/dist/parakeet/web-threaded/parakeet_runtime_bg.wasm +3 -0
  42. engine/dist/parakeet/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js +8 -0
  43. engine/dist/parakeet/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +55 -0
  44. engine/dist/phonon/web-single-relaxed/phonon_runtime.js +440 -0
  45. engine/dist/phonon/web-single-relaxed/phonon_runtime_bg.wasm +3 -0
  46. engine/dist/phonon/web-single/phonon_runtime.js +440 -0
  47. engine/dist/phonon/web-single/phonon_runtime_bg.wasm +3 -0
  48. engine/dist/phonon/web-threaded-relaxed/phonon_runtime.js +568 -0
  49. engine/dist/phonon/web-threaded-relaxed/phonon_runtime_bg.wasm +3 -0
  50. engine/dist/phonon/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js +8 -0
README.md CHANGED
@@ -1,10 +1,28 @@
1
  ---
2
- title: Voice Call Wasm
3
- emoji: 📉
4
- colorFrom: red
5
- colorTo: purple
6
  sdk: static
 
7
  pinned: false
 
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: voice-call-wasm
3
+ short_description: A voice call answered by three models on your CPU
 
 
4
  sdk: static
5
+ app_file: index.html
6
  pinned: false
7
+ license: mit
8
+ models:
9
+ - fusorlabs/voice-call-wasm-web
10
+ - moondream/parakeet-redux
11
+ - LiquidAI/LFM3-1.7B
12
+ - gradium/phonon-31m-en
13
+ custom_headers:
14
+ cross-origin-embedder-policy: require-corp
15
+ cross-origin-opener-policy: same-origin
16
+ cross-origin-resource-policy: cross-origin
17
  ---
18
 
19
+ A voice call computed on your own CPU in the browser, by three models working together rather than
20
+ one speech-to-speech model: [Moondream Parakeet Redux](https://huggingface.co/moondream/parakeet-redux)
21
+ writes down what you say while you say it, [LFM3-1.7B](https://huggingface.co/LiquidAI/LFM3-1.7B)
22
+ writes the answer, and [Phonon](https://huggingface.co/gradium/phonon-31m-en) speaks each clause of
23
+ it while the rest is still being written. Each model, compiled to WebAssembly with fusor-ai, downloads
24
+ once from [fusorlabs/voice-call-wasm-web](https://huggingface.co/fusorlabs/voice-call-wasm-web) and
25
+ then runs sealed from the network; nothing you say leaves the page. Every turn is timed from the end
26
+ of your sentence to the first sound of the reply. Parakeet Redux is CC-BY-4.0, LFM3-1.7B is under the
27
+ LFM Open License v1.0 (its license ships beside its bundle) and Phonon is Apache-2.0. The page's code
28
+ is MIT; its source is [github.com/fusor-rs/voice-call-wasm](https://github.com/fusor-rs/voice-call-wasm).
__fusor/g-1793728780335015000-24920/boot.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+
2
+ try {
3
+ const client = await import('./pkg/app.js');
4
+ if (typeof client.__fusor_start !== 'function') throw new Error("entry HTML declares App but generated startup is absent; include fusor::template!(\"web/index.html\") in the entry state's Rust module");
5
+ await client.default();
6
+ } catch (error) {
7
+ console.error('fusor failed to initialize:', error);
8
+ document.dispatchEvent(new CustomEvent('fusor:error', { detail: error }));
9
+ }
__fusor/g-1793728780335015000-24920/pkg/app.d.ts ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function __fusor_start(): void;
5
+
6
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
7
+
8
+ export interface InitOutput {
9
+ readonly memory: WebAssembly.Memory;
10
+ readonly __fusor_start: () => void;
11
+ readonly wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___u32__u32__web_sys_ae7f1b7cd0959356___features__gen_Event__Event______true_: (a: number, b: number, c: number, d: number, e: any) => void;
12
+ readonly wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___bool______true_: (a: number, b: number, c: number) => void;
13
+ readonly wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___core_608f92abc48d28da___result__Result_wasm_bindgen_4f5e0b79d4fe650e___JsValue__wasm_bindgen_4f5e0b79d4fe650e___JsValue___true_: (a: number, b: number) => [number, number, number];
14
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
15
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
+ readonly __externref_table_alloc: () => number;
17
+ readonly __wbindgen_externrefs: WebAssembly.Table;
18
+ readonly __wbindgen_exn_store: (a: number) => void;
19
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
20
+ readonly __externref_table_dealloc: (a: number) => void;
21
+ readonly __wbindgen_start: () => void;
22
+ }
23
+
24
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
25
+
26
+ /**
27
+ * Instantiates the given `module`, which can either be bytes or
28
+ * a precompiled `WebAssembly.Module`.
29
+ *
30
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
31
+ *
32
+ * @returns {InitOutput}
33
+ */
34
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
35
+
36
+ /**
37
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
38
+ * for everything else, calls `WebAssembly.instantiate` directly.
39
+ *
40
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
41
+ *
42
+ * @returns {Promise<InitOutput>}
43
+ */
44
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
__fusor/g-1793728780335015000-24920/pkg/app.js ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ var nt=Object.defineProperty;var H=(n,e)=>{for(var t in e)nt(n,t,{get:e[t],enumerable:!0})};var ie={};H(ie,{onMount:()=>dt});var re="fusor-ai-spawn-compute",Te="fusor-ai-rayon-init",Se="fusor-ai-rayon-ready",Oe="fusor-ai-rayon-error";var q=class{#e=[];#t;constructor(e){this.#t=e}async spawn({url:e,count:t,module:r,memory:o,receiver:s,mainJS:i,port:c}){try{let f=Array.from({length:t},(l,d)=>this.#n(d,e,{module:r,memory:o,receiver:s,mainJS:i}));await Promise.all(f),c.postMessage({ready:!0})}catch(f){this.terminate(),c.postMessage({ready:!1,error:String(f?.message??f)})}}terminate(){this.#e.forEach(e=>e.terminate()),this.#e=[]}#n(e,t,r){let o=new Worker(t,{type:"module",name:`fusor-ai-compute-${e}`});return this.#e.push(o),new Promise((s,i)=>{let c=!1;o.onmessage=({data:f})=>{f?.type===Se&&(c=!0,s()),f?.type===Oe&&i(new Error(f.message))},o.onerror=f=>{let l=f.message||"a compute thread failed";c?this.#t(l):i(new Error(l))},o.postMessage({type:Te,...r})})}};var rt=/[.!?…]+["')\]]*\s+/g,ot=/[,;:—]\s+/g;var st=/[*_#`]/g,V=class{#e=0;#t=0;take(e,t){let r=[];for(let o=this.#r(e);o!==null;o=this.#r(e))this.#n(r,e.slice(this.#e,o)),this.#e=o;return t&&(this.#n(r,e.slice(this.#e)),this.#e=e.length),r}get count(){return this.#t}#n(e,t){let r=t.replace(st,"").trim();r&&(e.push(r),this.#t++)}#r(e){let t=e.slice(this.#e),r=[Ie(t,rt,0)];this.#t===0&&r.push(Ie(t,ot,4));let o=r.filter(s=>s!==null);return o.length?this.#e+Math.min(...o):null}};function Ie(n,e,t){for(let r of n.matchAll(e))if(it(n.slice(0,r.index))>=t)return r.index+r[0].length;return null}var it=n=>n.split(/\s+/).filter(Boolean).length;var Y=new URLSearchParams(location.search),ct=navigator.hardwareConcurrency||4,oe=(n,e)=>Math.min(ct,Number.parseInt(Y.get(n)??"",10)||e),ut="https://huggingface.co/fusorlabs/voice-call-wasm-web/resolve/main/",se=location.hostname.endsWith(".hf.space")?ut:"model/",at={asr:{label:"Parakeet Redux",model:`${se}parakeet/`,threads:oe("asr",4)},llm:{label:"LFM3-1.7B",model:`${se}lfm3-1.7b/`,threads:oe("llm",6)},tts:{label:"Phonon",model:`${se}phonon/`,threads:oe("tts",2)}},Ne=Number.parseFloat(Y.get("endpoint")??"")||.6,Me=Number.parseFloat(Y.get("level")??"")||.015,ft=16e3,_t=160,lt="You are a friendly assistant on a phone call. Answer the way people talk: one to three short sentences of plain spoken English, never a list, markdown or emoji.",Re=n=>`${(n/1e6).toFixed(0)} MB`,Ce=()=>crypto.getRandomValues(new Uint32Array(1))[0];function dt({root:n,inputs:e,onCleanup:t}){let r=new Map,o=0,s=(a,u)=>{r.set(a,u),o||=requestAnimationFrame(()=>{o=0;for(let p of r.values())n.dispatchEvent(new CustomEvent("engine",{detail:JSON.stringify(p)}));r.clear()})},i=a=>s("status",{type:"status",status:a}),c={},f={asr:0,llm:0,tts:0},l=null,d=1,b=null,S=!1,ze={asr:{text:({turn:a,text:u})=>L(a)&&s("hearing",{type:"hearing",text:u}),final:tt},llm:{reply:ke,done:ke},tts:{"first-audio":({turn:a,index:u})=>u===0&&Ae(L(a),"firstAudio"),spoken:({networkRequests:a})=>ne("tts",a)}},Je={level:({rms:a})=>s("level",{type:"level",level:a/Me}),speech:()=>i("Hearing you\u2026"),endpoint:({speechEnd:a})=>{let{turn:u}=b;u.marks.endpoint=performance.now(),u.marks.speechEnd=u.marks.endpoint-Ne*1e3,c.asr.worker.postMessage({type:"finish",turn:u.id,speechEnd:a}),i("Thinking\u2026")}},Ge={started:({job:a})=>{let u=L(a);u&&(u.marks.firstSound=performance.now()+b.output.outputLatency*1e3,P(u),i("Speaking\u2026"))},drained:({job:a,gapSeconds:u})=>{let p=L(a);p&&(p.gap_seconds=u,P(p),te())}};for(let[a,u]of Object.entries(at))Ke(a,u);function Ke(a,{label:u,model:p,threads:y}){let x=new Worker(new URL(`engine/${a}.js`,document.baseURI),{type:"module",name:`${a}-engine`}),g=new q(v=>F(`${u}: a compute thread stopped (${v})`)),T={id:a,label:u,fraction:0,detail:`waiting for ${y} threads`,loaded:null};c[a]={worker:x,pool:g,shown:T};let M={...Xe(a),...ze[a],[re]:v=>g.spawn(v),warning:({message:v})=>console.warn(`${u}: ${v}`),error:({message:v})=>F(`${u}: ${v}`),fatal:({message:v})=>F(`${u}: ${v}`)};x.onmessage=({data:v})=>{S||M[v.type]?.(v)},x.onerror=v=>F(`${u}: ${v.message||"the engine worker failed"}`),x.postMessage({type:"load",modelUrl:new URL(p,document.baseURI).href,threads:y,build:Y.get("build")})}function Xe(a){let u=c[a],p=()=>s(`engine-${a}`,{type:"engine",engine:{...u.shown}});return p(),{runtime:({build:y,threads:x,sampleRate:g})=>{g&&(l=Qe(g)),u.started={build:y,threads:x},u.shown.detail=`${y} \xB7 loading`,p()},progress:({done:y,total:x})=>{u.shown.fraction=y/x,u.shown.detail=`${Re(y)} / ${Re(x)}`,p()},ready:({ms:y,cache:x,total:g,voices:T})=>{u.shown.fraction=1,u.shown.loaded={...u.started,bundle_bytes:g,load_ms:y,from_device:x===g},p(),T&&s("voices",{type:"voices",voices:T})}}}async function Qe(a){let u=new AudioContext({sampleRate:ft,latencyHint:"interactive"}),p=new AudioContext({sampleRate:a,latencyHint:"interactive"}),y=x=>new URL(`engine/${x}.js`,document.baseURI);return await Promise.all([u.audioWorklet.addModule(y("capture")),p.audioWorklet.addModule(y("playback"))]),{input:u,output:p}}async function Ze(){let a=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),{input:u,output:p}=await l,y=u.createMediaStreamSource(a),x=new AudioWorkletNode(u,"call-capture",{outputChannelCount:[1]});y.connect(x),x.connect(u.destination),x.port.onmessage=({data:M})=>Je[M.type](M);let g=new AudioWorkletNode(p,"call-playback",{outputChannelCount:[1]});g.connect(p.destination),g.port.onmessage=({data:M})=>Ge[M.type](M);let T=new MessageChannel;g.port.postMessage({type:"engine",port:T.port1},[T.port1]),c.tts.worker.postMessage({type:"audio",port:T.port2},[T.port2]),await Promise.all([u.resume(),p.resume()]),b={microphone:a,source:y,input:u,output:p,capture:x,playback:g,turn:null,voice:n.querySelector("input[name=voice]:checked")?.value??"default"},s("calling",{type:"calling",active:!0}),te()}function ee(){if(!b)return;let a=b.turn.id;b.capture.port.postMessage({type:"close"}),b.microphone.getTracks().forEach(u=>u.stop());for(let u of[b.source,b.capture,b.playback])u.disconnect();b.input.suspend(),b.output.suspend(),c.asr.worker.postMessage({type:"stop"}),c.llm.worker.postMessage({type:"stop",job:a}),c.llm.worker.postMessage({type:"reset"}),c.tts.worker.postMessage({type:"stop",turn:a}),b=null,s("calling",{type:"calling",active:!1}),s("level",{type:"level",level:0}),i("Call ended.")}function et(){if(b)return ee();i("Asking for the microphone\u2026"),Ze().catch(a=>i(`No call: ${a?.message??a}`))}function te(){let a={id:d++,caller:"",reply:"",marks:{},clauses:new V,tokens:0,gap_seconds:null,asr:null};b.turn=a;let u=new MessageChannel;b.capture.port.postMessage({type:"open",port:u.port1,level:Me,endpoint:Ne},[u.port1]),c.asr.worker.postMessage({type:"listen",turn:a.id,port:u.port2},[u.port2]),i("Listening: speak, then pause.")}function tt({turn:a,text:u,reused:p,finishMs:y,networkRequests:x}){let g=L(a);if(!g)return;if(ne("asr",x),!u)return te();g.caller=u,g.asr=p?"streamed":`finish() ${y.toFixed(0)} ms`,s("hearing",{type:"hearing",text:""}),Ae(g,"transcript"),b.playback.port.postMessage({type:"start",job:a});let T={text:u,system:lt,thinking:!1,mode:"text",max_tokens:_t,seed:Ce()};c.llm.worker.postMessage({type:"send",job:a,message:JSON.stringify(T)})}function ke({type:a,job:u,answer:p,tokens:y,networkRequests:x}){let g=L(u);if(!g)return;let T=a==="done";y&&!g.marks.firstToken&&(g.marks.firstToken=performance.now()),g.tokens=y,g.reply=p;for(let M of g.clauses.take(p,T)){let v=g.clauses.count-1;v===0&&(g.marks.firstClause=performance.now()),c.tts.worker.postMessage({type:"speak",turn:u,index:v,text:M,voice:b.voice,seed:Ce()})}T&&(g.marks.replyDone=performance.now(),ne("llm",x),c.tts.worker.postMessage({type:"end",turn:u})),P(g)}function Ae(a,u){a&&(a.marks[u]=performance.now(),P(a))}function P(a){if(!a.caller)return;let{clauses:u,...p}=a;s(`turn-${a.id}`,{type:"turn",turn:{...p,marks:{...a.marks}}})}function L(a){return b?.turn?.id===a?b.turn:null}function ne(a,u){f[a]=u,s("network",{type:"network",requests:Object.values(f).reduce((p,y)=>p+y,0)})}function F(a){ee(),S=!0,ve(),s("broken",{type:"broken",message:a})}function ve(){for(let{worker:a,pool:u}of Object.values(c))a.terminate(),u.terminate()}t(bt(e.calls,et)),t(()=>{ee(),ve(),l?.then(({input:a,output:u})=>Promise.all([a.close(),u.close()]))})}function bt(n,e){let t=0;return n.subscribe(r=>{for(;t<r;t++)e()})}var D={};H(D,{bindingElement:()=>le,bindingIntegerText:()=>kt,bindingRemoveAttributeOk:()=>_e,bindingSetAttributeOk:()=>fe,bindingSetIntegerAttributeOk:()=>At,bindingText:()=>ue,flatPlan:()=>pt,hydrateRoot:()=>Pe,hydrateRootOk:()=>ae,mountTemplate:()=>Ue,mountTemplateOk:()=>ce,resolveBindings:()=>J,resolveFlat:()=>Le,takeOutcome:()=>Et});var $e="fusor:",je="/fusor:";function pt(n,e,t,r){return{elements:new Map(n.map((o,s)=>[o,s])),tags:e,texts:new Map(t.map((o,s)=>[o,s])),elementIds:n,textIds:t,textElements:r,textHosts:new Map(Array.from({length:r.length/3},(o,s)=>[r[s*3],s*3]))}}function m(n){throw`fusor: template mismatch: ${n}`}function Le(n,e){let t=n.elementIds.length,r=t+n.textIds.length*3,o=new Array(r+n.textElements.length/3*2),s=e;do if(s.nodeType===1){let i=s.getAttribute("data-fusor-node"),c=s.getAttribute("data-fusor-text");if(c!==null){let f=n.textHosts.get(c);f===void 0&&m("unexpected text element");let l=n.textElements[f+1],d=n.textElements[f+2];l!==null&&l!==i&&m("mismatched text host"),(s.localName!==d||s.namespaceURI!=="http://www.w3.org/1999/xhtml")&&m(`text element ${c} must be <${d}>`);let b=r+f/3*2;o[b]&&m(`duplicate text element ${c}`),o[b]=s}if(i!==null){let f=n.elements.get(i);f===void 0&&m("unexpected element identifiers"),o[f]&&m(`duplicate element ${i}`),(s.localName!==n.tags[f]||s.namespaceURI!=="http://www.w3.org/1999/xhtml")&&m(`element ${i} must be <${n.tags[f]}>, found <${s.localName}>`),o[f]=s}}else if(s.nodeType===8){let i=s.nodeValue,c,f;if(i.startsWith($e))c=i.slice($e.length),f=!1;else if(i.startsWith(je))c=i.slice(je.length),f=!0;else continue;let l=n.texts.get(c);l===void 0&&m("unexpected text or component identifiers");let d=t+l*3+(f?1:0);o[d]&&m(`duplicate text ${f?"end":"start"} ${c}`),o[d]=s}while(s=gt(s,e));return mt(n,o)}function gt(n,e){let t=n.firstChild;if(t)return t;for(;n!==e;){let r=n.nextSibling;if(r)return r;n=n.parentNode}return null}function mt(n,e){let t=n.elementIds.length,r=t+n.textIds.length*3;for(let o=0;o<n.elementIds.length;o++)e[o]||m(`missing element ${n.elementIds[o]}`);for(let o=0;o<n.textIds.length;o++){let s=t+o*3,i=n.textIds[o],c=e[s],f=e[s+1];c||m(`missing text start ${i}`),f||m(`missing text end ${i}`);let l=c.nextSibling;l||m(`unpaired text slot ${i}`);let d=null;l!==f&&(l.nextSibling!==f&&m(`unexpected nodes in text slot ${i}`),l.nodeType!==3&&m(`expected a text node in slot ${i}`),d=l),e[s+2]=d}for(let o=0;o<n.textElements.length;o+=3){let s=r+o/3*2,i=n.textElements[o],c=e[s];c||m(`missing or mismatched text element ${i}`);let f=c.firstChild;f&&f.nextSibling&&m(`unexpected nodes in text element ${i}`),f&&f.nodeType!==3&&m(`expected a text node in text element ${i}`),e[s+1]=f}return e}function W(n,e){let t=!1;try{switch(e){case"Element":t=n instanceof Element;break;case"HTMLInputElement":t=n instanceof HTMLInputElement;break;case"Node":t=n instanceof Node;break;case"Text":t=n instanceof Text;break}}catch{}if(!t)throw n}function wt(n,e){let t=n.elementIds.length,r=t+n.textIds.length*3;for(let o=0;o<t;o++)W(e[o],n.tags[o]==="input"?"HTMLInputElement":"Element");for(let o=0;o<n.textIds.length;o++){let s=t+o*3;W(e[s],"Node"),W(e[s+1],"Node"),e[s+2]!==null&&W(e[s+2],"Text")}for(let o=0;o<n.textElements.length/3;o++){let s=r+o*2;W(e[s],"Element"),e[s+1]!==null&&W(e[s+1],"Text")}}function z(n,e){let t=[],r=e;for(;r!==n;){let o=r.previousSibling,s=0;for(;o;)s++,o=o.previousSibling;t.push(s),r=r.parentNode,r||m("detached cached handle")}return t.reverse()}function We(n,e){let t=n;for(let r of e){t=t.firstChild;for(let o=0;t&&o<r;o++)t=t.nextSibling;t||m("template changed during resolution")}return t}function ht(n,e,t){let r=n.elementIds.length,o=r+n.textIds.length*3,c=e.ownerDocument.createElement("template").content.ownerDocument.importNode(e,!0),f=[],l=[];for(let d=0;d<r;d++)f.push(z(e,t[d])),l.push(0);for(let d=0;d<n.textIds.length;d++){let b=r+d*3,S=t[b+2];f.push(z(e,S??t[b+1])),l.push(S?0:1)}for(let d=0;d<n.textElements.length/3;d++){let b=o+d*2,S=t[b+1];f.push(z(e,S??t[b])),l.push(S?0:2)}n.bindingCache={pristine:c,paths:f,creates:l}}function De(n,e,t){let{paths:r,creates:o}=n,s=r.length,i=new Array(s+t);for(let c=0;c<s;c++)i[c]=We(e,r[c]);for(let c=0;c<s;c++){let f=o[c];if(f===0)continue;let l=document.createTextNode(""),d=i[c];f===1?d.parentNode.insertBefore(l,d):d.appendChild(l),i[c]=l}return i}function Be(n,e,t){let r=Le(n,e);if(wt(n,r),t)try{ht(n,e,r)}catch{}let o=n.elementIds.length,s=o+n.textIds.length*3;for(let i=0;i<n.textIds.length;i++){let c=o+i*3,f=r[c],l=r[c+1],d=r[c+2];if(d===null){d=document.createTextNode("");let b=f.parentNode;b||m("detached text anchor"),b.insertBefore(d,l)}r[o+i]=d}for(let i=0;i<n.textElements.length/3;i++){let c=s+i*2,f=r[c],l=r[c+1];l===null&&(l=document.createTextNode(""),f.appendChild(l)),r[o+n.textIds.length+i]=l}return r.length=o+n.textIds.length+n.textElements.length/3,r}function J(n,e,t){let r=t&&n.bindingCache;return r&&e.isEqualNode(r.pristine)?De(r,e,0):Be(n,e,t)}function Ue(n,e,t,r,o){let s=document.querySelectorAll(e);s.length!==1&&m(`component ${r} requires exactly one root, found ${s.length}`);let i=s[0];i.getAttribute("data-fusor-version")!==t&&m("HTML schema version differs from Wasm; rebuild the application"),i instanceof HTMLTemplateElement||m("expected an HTML template");let c=i.content;if(c.childElementCount!==1)throw"fusor: a row template needs exactly one root element";let f=c.firstElementChild;o||m("unsupported descriptor version; rebuild the application");let l=n.bindingCache;if(l&&f.isEqualNode(l.pristine)){let S=l.mounted;return(S===void 0||S.identity!==r)&&(S=l.mounted=xt(l,r)),yt(S)}let d=f.cloneNode(!0),b=Be(n,d,!0);return b.push(d),d.setAttribute("data-fusor-instance",r),b}function yt(n){let e=n.root.cloneNode(!0),t=n.paths,r=t.length,o=new Array(r+1);for(let s=0;s<r;s++)o[s]=We(e,t[s]);return o[r]=e,o}function xt(n,e){let t=n.pristine.cloneNode(!0),r=De(n,t,0);return t.setAttribute("data-fusor-instance",e),{identity:e,root:t,paths:r.map(o=>z(t,o))}}var R;function ce(n,e,t,r,o){try{return R=Ue(n,e,t,r,o),!0}catch(s){return R=s,!1}}function Et(){let n=R;return R=void 0,n}function Pe(n,e,t,r,o){(e.getAttribute("data-fusor-version")!==t||e.getAttribute("data-fusor-component")!==r)&&m("server root identity differs from the browser template"),o||m("unsupported descriptor version; rebuild the application");let s=J(n,e,!1);return e.setAttribute("data-fusor-instance",r),s}function ue(n,e,t){let r=n[e];r.data!==t&&(r.data=t)}function kt(n,e,t){let r=n[e],o=""+t;r.data!==o&&(r.data=o)}function ae(n,e,t,r,o){try{return R=Pe(n,e,t,r,o),!0}catch(s){return R=s,!1}}function fe(n,e,t,r){try{return n[e].setAttribute(t,r),!0}catch(o){return R=o,!1}}function At(n,e,t,r){try{return n[e].setAttribute(t,""+r),!0}catch(o){return R=o,!1}}function _e(n,e,t){try{return n[e].removeAttribute(t),!0}catch(r){return R=r,!1}}function le(n,e){return n[e]}var $={};H($,{insertBeforeOk:()=>Tt,listenBundleOk:()=>ge,listenOk:()=>X,serverRows:()=>pe,setIntegerAttribute:()=>be,setIntegerTextIfChanged:()=>vt,setTextIfChanged:()=>G,takeRemovalFailure:()=>St,unlistenBundleOk:()=>me,unlistenOk:()=>K});function G(n,e){n.data!==e&&(n.data=e)}function vt(n,e){let t=""+e;G(n,t)}function be(n,e,t){n.setAttribute(e,""+t)}function pe(n,e,t,r,o){let s=r?t.split(`
2
+ `):[],i=new Array(r),c=n.firstElementChild;for(let f=0;f<r;f++){if(!c)throw"missing native row";if(c.getAttribute(e)!==s[f])throw"native row key mismatch";i[f]=c,c=c.nextElementSibling}if(o?c:!c)throw o?"unexpected native row":"missing native row";return i}var de=[],C;function ge(n,e,t,r,o,s){try{return X(n[e],t,r,o,s)}catch(i){return C=i,!1}}function me(n,e,t,r){try{return K(n[e],t,r)}catch(o){return C=o,!1}}function K(n,e,t){try{let r=de[t];return de[t]=void 0,n.removeEventListener(e,r),!0}catch(r){return C=r,!1}}function Tt(n,e,t){try{return n.insertBefore(e,t),!0}catch(r){return C=r,!1}}function St(){let n=C;return C=void 0,n}function X(n,e,t,r,o){try{let s=i=>t(r,o,i);return n.addEventListener(e,s),de[r]=s,!0}catch(s){return C=s,!1}}var O={};H(O,{input_api:()=>Nt,input_create:()=>It,input_dispose:()=>Rt,input_publish:()=>Mt,inputs_create:()=>Ot,module_activate:()=>he,module_create:()=>we,module_dispose:()=>Ct});function Ot(){return Object.create(null)}function It(n,e){let t={read:n,observe:e,listeners:new Map,next:0,closed:!1},r=Object.freeze({get(){if(t.closed)throw new Error("fusor: JavaScript input belongs to a disposed component");return t.read()},subscribe(o){if(typeof o!="function")throw new TypeError("fusor: inputs.subscribe requires a function");if(t.closed)throw new Error("fusor: cannot subscribe to a disposed component");let s=++t.next;t.listeners.set(s,o);let i=()=>{!t.listeners.delete(s)||t.closed||t.listeners.size===0&&t.observe(!1)};try{if(t.listeners.size===1&&t.observe(!0),t.closed)throw new Error("fusor: cannot subscribe to a disposed component");o(t.read())}catch(c){throw i(),c}return i}});return t.api=r,t}function Nt(n){return n.api}function Mt(n,e){if(!n.closed)for(let[t,r]of[...n.listeners]){if(n.closed)break;if(n.listeners.has(t))try{r(e)}catch(o){console.error(o)}}}function Rt(n){n.closed=!0,n.listeners.clear(),n.read=n.observe=null}function we(n,e,t){let r=new AbortController;return{root:n,inputs:Object.freeze(e),id:t,controller:r,closed:!1,cleanups:[]}}function Fe(n){try{n()}catch(e){console.error(e)}}function he(n){if(n.closed)return;let t=globalThis[Symbol.for("fusor.javascript.modules.v1")]?.get(n.id);if(!t)throw new Error(`fusor: component module ${n.id} is missing; build with cargo fusor build and enable JavaScript tooling`);if(!("onMount"in t))return;if(typeof t.onMount!="function")throw new TypeError(`fusor: ${n.id} exports onMount, but it is not a function`);if(t.onMount.constructor?.name==="AsyncFunction")throw new TypeError(`fusor: ${n.id} onMount must be synchronous; start async work inside onMount and use signal`);let r=s=>{if(typeof s!="function")throw new TypeError("fusor: onCleanup requires a function");n.closed?Fe(s):n.cleanups.push(s)},o=t.onMount(Object.freeze({root:n.root,signal:n.controller.signal,inputs:n.inputs,onCleanup:r}));if(o!==void 0)if(typeof o=="function")r(o);else throw o!=null&&typeof o.then=="function"&&Promise.resolve(o).catch(s=>console.error(s)),new TypeError(`fusor: ${n.id} onMount must return nothing or a cleanup function; promises are unsupported`)}function Ct(n){if(!n.closed){for(n.closed=!0,n.controller.abort();n.cleanups.length;)Fe(n.cleanups.pop());n.root=n.inputs=null}}function Zt(){_.__fusor_start()}function Ve(){return{__proto__:null,"./app_bg.js":{__proto__:null,__wbg___wbindgen_debug_string_dd5d2d07ce9e6c57:function(e,t){let r=Ee(t),o=N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},__wbg___wbindgen_is_undefined_c0cca72b82b86f4d:function(e){return e===void 0},__wbg___wbindgen_jsval_eq_7d430e744a913d26:function(e,t){return e===t},__wbg___wbindgen_rethrow_828b2014a519945b:function(e){throw e},__wbg___wbindgen_string_get_914df97fcfa788f2:function(e,t){let r=t,o=typeof r=="string"?r:void 0;var s=w(o)?0:N(o,_.__wbindgen_malloc,_.__wbindgen_realloc),i=I;E().setInt32(e+4,i,!0),E().setInt32(e+0,s,!0)},__wbg___wbindgen_throw_81fc77679af83bc6:function(e,t){throw new Error(A(e,t))},__wbg__wbg_cb_unref_3c3b4f651835fbcb:function(e){e._wbg_cb_unref()},__wbg_activeElement_41dff9147c0c1503:function(e){let t=e.activeElement;return w(t)?0:k(t)},__wbg_appendChild_8eab65de52dd0834:function(){return h(function(e,t){return e.appendChild(t)},arguments)},__wbg_bindingElement_95d5884c254d9ca5:function(e,t){return le(e,t>>>0)},__wbg_bindingRemoveAttributeOk_3895b982330b8f6d:function(e,t,r){return _e(e,t>>>0,r)},__wbg_bindingSetAttributeOk_0a9c5eff6df76b71:function(e,t,r,o,s){return fe(e,t>>>0,r,A(o,s))},__wbg_bindingText_37c92705f8bdcc10:function(e,t,r,o){ue(e,t>>>0,A(r,o))},__wbg_checked_65962e3958007db9:function(e){return e.checked},__wbg_childElementCount_d49ab6935b3dd2ca:function(e){return e.childElementCount},__wbg_childNodes_b4f95a9b583ab2a6:function(e){return e.childNodes},__wbg_cloneNode_d1f6f9e667a9cbe6:function(){return h(function(e,t){return e.cloneNode(t!==0)},arguments)},__wbg_contains_211f324619de206c:function(e,t){return e.contains(t)},__wbg_content_4026faf4c753dcc0:function(e){return e.content},__wbg_createComment_1801ee922675e137:function(e,t,r){return e.createComment(A(t,r))},__wbg_createElement_8640e331213b402e:function(){return h(function(e,t,r){return e.createElement(A(t,r))},arguments)},__wbg_createTextNode_5237bc38e22bbce2:function(e,t,r){return e.createTextNode(A(t,r))},__wbg_createTreeWalker_706f6b93d0d9c87c:function(){return h(function(e,t){return e.createTreeWalker(t)},arguments)},__wbg_data_d487d24a0109d68a:function(e,t){let r=t.data,o=N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},__wbg_detail_442b1f5fc44e8259:function(e){return e.detail},__wbg_document_a28a21ae315de4ea:function(e){let t=e.document;return w(t)?0:k(t)},__wbg_error_38bec0a78dd8ded8:function(e){console.error(e)},__wbg_firstChild_33f958f631120ef3:function(e){let t=e.firstChild;return w(t)?0:k(t)},__wbg_firstElementChild_42287636a23b59a1:function(e){let t=e.firstElementChild;return w(t)?0:k(t)},__wbg_firstElementChild_82ffb462e49f2716:function(e){let t=e.firstElementChild;return w(t)?0:k(t)},__wbg_focus_93aead258d471c93:function(){return h(function(e){e.focus()},arguments)},__wbg_getAttribute_2c222f8bf0fee751:function(e,t){return e.getAttribute(t)},__wbg_getAttribute_7231384a7142ae08:function(e,t,r,o){let s=t.getAttribute(A(r,o));var i=w(s)?0:N(s,_.__wbindgen_malloc,_.__wbindgen_realloc),c=I;E().setInt32(e+4,c,!0),E().setInt32(e+0,i,!0)},__wbg_getAttribute_853e47709679aeb0:function(e,t,r){let o=t.getAttribute(r);var s=w(o)?0:N(o,_.__wbindgen_malloc,_.__wbindgen_realloc),i=I;E().setInt32(e+4,i,!0),E().setInt32(e+0,s,!0)},__wbg_get_4848e350b40afc16:function(e,t){return e[t>>>0]},__wbg_hasAttribute_06b62a585d40c909:function(e,t,r){return e.hasAttribute(A(t,r))},__wbg_hydrateRootOk_ea8322bf193da8f0:function(e,t,r,o,s){return ae(e,t,r,o,s!==0)},__wbg_importNode_0e454e7ad97653b9:function(){return h(function(e,t,r){return e.importNode(t,r!==0)},arguments)},__wbg_insertBefore_485cf0d248f903b5:function(){return h(function(e,t,r){return e.insertBefore(t,r)},arguments)},__wbg_instanceof_CustomEvent_030c9b6df5a8ba59:function(e){let t;try{t=e instanceof CustomEvent}catch{t=!1}return t},__wbg_instanceof_Element_c4784e8a9522e087:function(e){let t;try{t=e instanceof Element}catch{t=!1}return t},__wbg_instanceof_HtmlElement_43b8bbfdb4aaefd5:function(e){let t;try{t=e instanceof HTMLElement}catch{t=!1}return t},__wbg_instanceof_HtmlInputElement_ed700e6a857d360a:function(e){let t;try{t=e instanceof HTMLInputElement}catch{t=!1}return t},__wbg_instanceof_HtmlTemplateElement_b38f3aeaca857549:function(e){let t;try{t=e instanceof HTMLTemplateElement}catch{t=!1}return t},__wbg_instanceof_Text_51836e3946fd14bf:function(e){let t;try{t=e instanceof Text}catch{t=!1}return t},__wbg_instanceof_Window_c0fee4c064502536:function(e){let t;try{t=e instanceof Window}catch{t=!1}return t},__wbg_isEqualNode_0216d34f4a07d1d9:function(e,t){return e.isEqualNode(t)},__wbg_isSameNode_786ccd98b6fbab8e:function(e,t){return e.isSameNode(t)},__wbg_item_e196018f5c602c98:function(e,t){let r=e.item(t>>>0);return w(r)?0:k(r)},__wbg_length_6de1491902a7581f:function(e){return e.length},__wbg_listenBundleOk_d376ea54d2f172e6:function(e,t,r,o,s,i){return ge(e,t>>>0,r,o,s>>>0,i>>>0)},__wbg_listenOk_ee072754e0b27322:function(e,t,r,o,s){return X(e,t,r,o>>>0,s>>>0)},__wbg_localName_9244e41a41cc6f94:function(e,t){let r=t.localName,o=N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},__wbg_module_activate_8fa83913d4ba9581:function(){return h(function(e){he(e)},arguments)},__wbg_module_create_010d31a7bc85a6d7:function(e,t,r,o){return we(e,t,A(r,o))},__wbg_mountTemplateOk_345d3a9c2ab2bf96:function(e,t,r,o,s){return ce(e,t,r,o,s!==0)},__wbg_namespaceURI_ffd4d92adae6f71d:function(e,t){let r=t.namespaceURI;var o=w(r)?0:N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},__wbg_new_f3c9df4f38f3f798:function(){return new Array},__wbg_nextElementSibling_5e8e702616559039:function(e){let t=e.nextElementSibling;return w(t)?0:k(t)},__wbg_nextNode_9003c40615bbd302:function(){return h(function(e){let t=e.nextNode();return w(t)?0:k(t)},arguments)},__wbg_nextSibling_3e40535a1981b752:function(){return h(function(e){let t=e.nextSibling();return w(t)?0:k(t)},arguments)},__wbg_nextSibling_75b36cf047b6e78e:function(e){let t=e.nextSibling;return w(t)?0:k(t)},__wbg_nodeType_fb5193b41ad86036:function(e){return e.nodeType},__wbg_nodeValue_fc2e21d4aca76b9e:function(e,t){let r=t.nodeValue;var o=w(r)?0:N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},__wbg_ownerDocument_901ae68b3dc486e6:function(e){let t=e.ownerDocument;return w(t)?0:k(t)},__wbg_parentElement_13801cac47d62f97:function(e){let t=e.parentElement;return w(t)?0:k(t)},__wbg_parentNode_a27f2ea2dcc0a6f6:function(e){let t=e.parentNode;return w(t)?0:k(t)},__wbg_parentNode_f96a763f205b09b8:function(){return h(function(e){let t=e.parentNode();return w(t)?0:k(t)},arguments)},__wbg_previousSibling_e4db4051a93c984b:function(e){let t=e.previousSibling;return w(t)?0:k(t)},__wbg_push_6bdbc990be5ac37b:function(e,t){return e.push(t)},__wbg_querySelectorAll_de99710087e04ae8:function(){return h(function(e,t){return e.querySelectorAll(t)},arguments)},__wbg_removeAttribute_b0fc6f5d8fc2d952:function(){return h(function(e,t,r){e.removeAttribute(A(t,r))},arguments)},__wbg_removeChild_874b23fe5a1ca1bb:function(){return h(function(e,t){return e.removeChild(t)},arguments)},__wbg_remove_b0ab1a7ea21cda2e:function(e){e.remove()},__wbg_resolveBindings_3b043331eb0df138:function(){return h(function(e,t,r){return J(e,t,r!==0)},arguments)},__wbg_selectionDirection_fe6a1fca784350e3:function(){return h(function(e,t){let r=t.selectionDirection;var o=w(r)?0:N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},arguments)},__wbg_selectionEnd_6dfcdf4e62a8bbcd:function(){return h(function(e){let t=e.selectionEnd;return w(t)?4294967297:t>>>0},arguments)},__wbg_selectionStart_5b16e02595e73f0d:function(){return h(function(e){let t=e.selectionStart;return w(t)?4294967297:t>>>0},arguments)},__wbg_serverRows_a4604a7407b66a56:function(){return h(function(e,t,r,o,s,i){return pe(e,t,A(r,o),s>>>0,i!==0)},arguments)},__wbg_setAttribute_5799fb5befe29601:function(){return h(function(e,t,r,o,s){e.setAttribute(A(t,r),A(o,s))},arguments)},__wbg_setAttribute_dd78390c2c42f1e3:function(){return h(function(e,t,r){e.setAttribute(t,r)},arguments)},__wbg_setIntegerAttribute_9d06d6bf212908cb:function(){return h(function(e,t,r,o){be(e,A(t,r),o)},arguments)},__wbg_setSelectionRange_d22472d173dc9922:function(){return h(function(e,t,r,o,s){e.setSelectionRange(t>>>0,r>>>0,A(o,s))},arguments)},__wbg_setTextIfChanged_31f62dd00d3e876d:function(e,t,r){G(e,A(t,r))},__wbg_set_8ee2d34facb8466e:function(){return h(function(e,t,r){return Reflect.set(e,t,r)},arguments)},__wbg_set_checked_18422721365981ae:function(e,t){e.checked=t!==0},__wbg_set_currentNode_921ec8b76404ced7:function(e,t){e.currentNode=t},__wbg_set_innerHTML_7e29b346becaeb8b:function(e,t,r){e.innerHTML=A(t,r)},__wbg_set_textContent_b5ed93950bde4be6:function(e,t,r){e.textContent=t===0?void 0:A(t,r)},__wbg_static_accessor_GLOBAL_THIS_a1248013d790bf5f:function(){let e=typeof globalThis>"u"?null:globalThis;return w(e)?0:k(e)},__wbg_static_accessor_GLOBAL_f2e0f995a21329ff:function(){let e=typeof global>"u"?null:global;return w(e)?0:k(e)},__wbg_static_accessor_SELF_24f78b6d23f286ea:function(){let e=typeof self>"u"?null:self;return w(e)?0:k(e)},__wbg_static_accessor_WINDOW_59fd959c540fe405:function(){let e=typeof window>"u"?null:window;return w(e)?0:k(e)},__wbg_type_884048a46f93c939:function(e,t){let r=t.type,o=N(r,_.__wbindgen_malloc,_.__wbindgen_realloc),s=I;E().setInt32(e+4,s,!0),E().setInt32(e+0,o,!0)},__wbg_unlistenBundleOk_92b4254118c47895:function(e,t,r,o){return me(e,t>>>0,r,o>>>0)},__wbg_unlistenOk_d6428300886fe9f1:function(e,t,r){return K(e,t,r>>>0)},__wbindgen_cast_0000000000000001:function(e,t){return ye(e,t,jt)},__wbindgen_cast_0000000000000002:function(e,t){return ye(e,t,Lt)},__wbindgen_cast_0000000000000003:function(e,t){return ye(e,t,$t)},__wbindgen_cast_0000000000000004:function(e){return e},__wbindgen_cast_0000000000000005:function(e,t){return A(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}},"./snippets/fusor-core-b8e34eae654c12f7/src/dom/strings.js":$,"./snippets/fusor-core-b8e34eae654c12f7/src/dom/mount/flat.js":D,"./snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js":O,"./snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js":O,"./snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js":O,"./snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js":O,"./snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js":O,"./snippets/fusor-core-b8e34eae654c12f7/src/dom/strings.js":$,"./snippets/fusor-core-b8e34eae654c12f7/src/dom/strings.js":$,"./snippets/fusor-core-b8e34eae654c12f7/src/dom/mount/flat.js":D,"./snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js":O}}function $t(n,e){let t=_.wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___core_608f92abc48d28da___result__Result_wasm_bindgen_4f5e0b79d4fe650e___JsValue__wasm_bindgen_4f5e0b79d4fe650e___JsValue___true_(n,e);if(t[2])throw qe(t[1]);return qe(t[0])}function jt(n,e,t){_.wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___bool______true_(n,e,t)}function Lt(n,e,t,r,o){_.wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___u32__u32__web_sys_ae7f1b7cd0959356___features__gen_Event__Event______true_(n,e,t,r,o)}function k(n){let e=_.__externref_table_alloc();return _.__wbindgen_externrefs.set(e,n),e}var He=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(n=>_.__wbindgen_destroy_closure(n.a,n.b));function Ee(n){let e=typeof n;if(e=="number"||e=="boolean"||n==null)return`${n}`;if(e=="string")return`"${n}"`;if(e=="symbol"){let o=n.description;return o==null?"Symbol":`Symbol(${o})`}if(e=="function"){let o=n.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(n)){let o=n.length,s="[";o>0&&(s+=Ee(n[0]));for(let i=1;i<o;i++)s+=", "+Ee(n[i]);return s+="]",s}let t=/\[object ([^\]]+)\]/.exec(toString.call(n)),r;if(t&&t.length>1)r=t[1];else return toString.call(n);if(r=="Object")try{return"Object("+JSON.stringify(n)+")"}catch{return"Object"}return n instanceof Error?`${n.name}: ${n.message}
3
+ ${n.stack}`:r}var j=null;function E(){return(j===null||j.buffer.detached===!0||j.buffer.detached===void 0&&j.buffer!==_.memory.buffer)&&(j=new DataView(_.memory.buffer)),j}function A(n,e){return n=n>>>0,Dt(n,e)}var B=null;function Q(){return(B===null||B.byteLength===0)&&(B=new Uint8Array(_.memory.buffer)),B}function h(n,e){try{return n.apply(this,e)}catch(t){let r=k(t);_.__wbindgen_exn_store(r)}}function w(n){return n==null}function ye(n,e,t){let r={a:n,b:e,cnt:1},o=(...s)=>{r.cnt++;try{return t(r.a,r.b,...s)}finally{o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--r.cnt===0&&(_.__wbindgen_destroy_closure(r.a,r.b),r.a=0,He.unregister(r))},He.register(o,r,r),o}function N(n,e,t){if(t===void 0){let c=U.encode(n),f=e(c.length,1)>>>0;return Q().subarray(f,f+c.length).set(c),I=c.length,f}let r=n.length,o=e(r,1)>>>0,s=Q(),i=0;for(;i<r;i++){let c=n.charCodeAt(i);if(c>127)break;s[o+i]=c}if(i!==r){i!==0&&(n=n.slice(i)),o=t(o,r,r=i+n.length*3,1)>>>0;let c=Q().subarray(o+i,o+r),f=U.encodeInto(n,c);i+=f.written,o=t(o,r,i,1)>>>0}return I=i,o}function qe(n){let e=_.__wbindgen_externrefs.get(n);return _.__externref_table_dealloc(n),e}var Z=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});Z.decode();var Wt=2146435072,xe=0;function Dt(n,e){return xe+=e,xe>=Wt&&(Z=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),Z.decode(),xe=e),Z.decode(Q().subarray(n,n+e))}var U=new TextEncoder;"encodeInto"in U||(U.encodeInto=function(n,e){let t=U.encode(n);return e.set(t),{read:n.length,written:t.length}});var I=0,Bt,_;function Ye(n,e){return _=n.exports,Bt=e,j=null,B=null,_.__wbindgen_start(),_}async function Ut(n,e){if(typeof Response=="function"&&n instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(n,e)}catch(o){if(n.ok&&t(n.type)&&n.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",o);else throw o}let r=await n.arrayBuffer();return await WebAssembly.instantiate(r,e)}else{let r=await WebAssembly.instantiate(n,e);return r instanceof WebAssembly.Instance?{instance:r,module:n}:r}function t(r){switch(r){case"basic":case"cors":case"default":return!0}return!1}}function en(n){if(_!==void 0)return _;n!==void 0&&(Object.getPrototypeOf(n)===Object.prototype?{module:n}=n:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let e=Ve();n instanceof WebAssembly.Module||(n=new WebAssembly.Module(n));let t=new WebAssembly.Instance(n,e);return Ye(t,n)}async function Pt(n){if(_!==void 0)return _;n!==void 0&&(Object.getPrototypeOf(n)===Object.prototype?{module_or_path:n}=n:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),n===void 0&&(n=new URL("app_bg.wasm",import.meta.url));let e=Ve();(typeof n=="string"||typeof Request=="function"&&n instanceof Request||typeof URL=="function"&&n instanceof URL)&&(n=fetch(n));let{instance:t,module:r}=await Ut(await n,e);return Ye(t,r)}globalThis[Symbol.for("fusor.javascript.modules.v1")]=new Map([["App:9716b107902dce12:0",ie]]);export{Zt as __fusor_start,Pt as default,en as initSync};
__fusor/g-1793728780335015000-24920/pkg/app_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab87180be1790b90381fe428084c9f94fb43443138450ea9bc81ca1b9a7b8a45
3
+ size 734709
__fusor/g-1793728780335015000-24920/pkg/app_bg.wasm.d.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __fusor_start: () => void;
5
+ export const wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___u32__u32__web_sys_ae7f1b7cd0959356___features__gen_Event__Event______true_: (a: number, b: number, c: number, d: number, e: any) => void;
6
+ export const wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___bool______true_: (a: number, b: number, c: number) => void;
7
+ export const wasm_bindgen_4f5e0b79d4fe650e___convert__closures_____invoke___core_608f92abc48d28da___result__Result_wasm_bindgen_4f5e0b79d4fe650e___JsValue__wasm_bindgen_4f5e0b79d4fe650e___JsValue___true_: (a: number, b: number) => [number, number, number];
8
+ export const __wbindgen_malloc: (a: number, b: number) => number;
9
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
10
+ export const __externref_table_alloc: () => number;
11
+ export const __wbindgen_externrefs: WebAssembly.Table;
12
+ export const __wbindgen_exn_store: (a: number) => void;
13
+ export const __wbindgen_destroy_closure: (a: number, b: number) => void;
14
+ export const __externref_table_dealloc: (a: number) => void;
15
+ export const __wbindgen_start: () => void;
__fusor/g-1793728780335015000-24920/pkg/javascript-bundle.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "inputs": [
3
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/node_modules/@esbuild/darwin-arm64/package.json",
4
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/node_modules/esbuild/lib/main.js",
5
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/node_modules/esbuild/package.json",
6
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/package-lock.json",
7
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/package.json",
8
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/web/app.js",
9
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/web/clauses.js",
10
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/app/web/index.html",
11
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/vendor/fusor-ai/packages/host/compute.js",
12
+ "/Users/andrespirela/workspace/andreespirela/voice-call-wasm/vendor/fusor-ai/packages/host/protocol.js"
13
+ ],
14
+ "styles": []
15
+ }
__fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/inline0.js ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ const unset = Symbol('fusor unset property');
3
+ const definitions = new WeakMap();
4
+ function report(s, error) {
5
+ if (!s.active) return;
6
+ console.error(error);
7
+ s.element.dispatchEvent(new CustomEvent('fusor:error', {detail: error, bubbles: true}));
8
+ }
9
+ function flush(s) {
10
+ if (!s.active || !s.ready || s.value === unset || Object.is(s.written, s.value)) return;
11
+ const value = s.value;
12
+ s.written = value;
13
+ try {
14
+ if (!Reflect.set(s.element, s.name, value)) throw new TypeError(`Cannot set custom element property ${s.name}`);
15
+ } catch (error) {
16
+ if (s.active && Object.is(s.written, value)) s.written = unset;
17
+ throw error;
18
+ }
19
+ }
20
+ export function property_create(element, name) {
21
+ return {element, name, value: unset, written: unset, active: false, ready: false, pending: null};
22
+ }
23
+ export function property_value(s, value) { s.value = value; flush(s); }
24
+ export function property_activate(s) {
25
+ s.active = true;
26
+ const registry = s.element.ownerDocument.defaultView.customElements;
27
+ const name = s.element.localName;
28
+ if (registry.get(name)) {
29
+ registry.upgrade(s.element);
30
+ s.ready = true;
31
+ flush(s);
32
+ } else {
33
+ let tags = definitions.get(registry);
34
+ if (!tags) { tags = new Map(); definitions.set(registry, tags); }
35
+ let pending = tags.get(name);
36
+ if (!pending) {
37
+ pending = new Set();
38
+ tags.set(name, pending);
39
+ // Keep an empty entry until definition: repeated mount/drop must not add
40
+ // unbounded callbacks to the registry's never-settled promise.
41
+ registry.whenDefined(name).then(() => {
42
+ tags.delete(name);
43
+ for (const binding of pending) {
44
+ pending.delete(binding);
45
+ binding.pending = null;
46
+ if (!binding.active) continue;
47
+ try {
48
+ registry.upgrade(binding.element);
49
+ binding.ready = true;
50
+ flush(binding);
51
+ } catch (error) { report(binding, error); }
52
+ }
53
+ }).catch(error => {
54
+ tags.delete(name);
55
+ for (const binding of pending) { binding.pending = null; report(binding, error); }
56
+ pending.clear();
57
+ });
58
+ }
59
+ pending.add(s);
60
+ s.pending = pending;
61
+ }
62
+ }
63
+ export function property_dispose(s) {
64
+ s.active = false;
65
+ if (s.pending) { s.pending.delete(s); s.pending = null; }
66
+ s.element = null;
67
+ s.value = s.written = unset;
68
+ }
__fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/src/dom/mount/flat.js ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // A complete protocol scan for templates without managed regions or child mounts.
2
+ // This never caches a live DOM node, skips validation, or installs behavior.
3
+ const START = 'fusor:';
4
+ const END = '/fusor:';
5
+
6
+ export function flatPlan(elementIds, tags, textIds, textElements) {
7
+ return {
8
+ elements: new Map(elementIds.map((id, index) => [id, index])),
9
+ tags,
10
+ texts: new Map(textIds.map((id, index) => [id, index])),
11
+ elementIds,
12
+ textIds,
13
+ textElements,
14
+ textHosts: new Map(Array.from({ length: textElements.length / 3 }, (_, i) =>
15
+ [textElements[i * 3], i * 3])),
16
+ };
17
+ }
18
+
19
+ function mismatch(message) {
20
+ throw `fusor: template mismatch: ${message}`;
21
+ }
22
+
23
+ export function resolveFlat(plan, root) {
24
+ const textOffset = plan.elementIds.length;
25
+ const hostOffset = textOffset + plan.textIds.length * 3;
26
+ // One descriptor-sized output array also holds validation state. It is local
27
+ // to this call; no application nodes enter the cached immutable plan.
28
+ const elements = new Array(hostOffset + plan.textElements.length / 3 * 2);
29
+ let node = root;
30
+ do {
31
+ if (node.nodeType === 1) {
32
+ const id = node.getAttribute('data-fusor-node');
33
+ const text = node.getAttribute('data-fusor-text');
34
+ if (text !== null) {
35
+ const offset = plan.textHosts.get(text);
36
+ if (offset === undefined) mismatch('unexpected text element');
37
+ const host = plan.textElements[offset + 1], tag = plan.textElements[offset + 2];
38
+ if (host !== null && host !== id) mismatch('mismatched text host');
39
+ if (node.localName !== tag || node.namespaceURI !== 'http://www.w3.org/1999/xhtml') mismatch(`text element ${text} must be <${tag}>`);
40
+ const slot = hostOffset + offset / 3 * 2;
41
+ if (elements[slot]) mismatch(`duplicate text element ${text}`);
42
+ elements[slot] = node;
43
+ }
44
+ if (id !== null) {
45
+ const index = plan.elements.get(id);
46
+ if (index === undefined) mismatch('unexpected element identifiers');
47
+ if (elements[index]) mismatch(`duplicate element ${id}`);
48
+ if (node.localName !== plan.tags[index] || node.namespaceURI !== 'http://www.w3.org/1999/xhtml') {
49
+ mismatch(`element ${id} must be <${plan.tags[index]}>, found <${node.localName}>`);
50
+ }
51
+ elements[index] = node;
52
+ }
53
+ } else if (node.nodeType === 8) {
54
+ const value = node.nodeValue;
55
+ let id, end;
56
+ if (value.startsWith(START)) {
57
+ id = value.slice(START.length); end = false;
58
+ } else if (value.startsWith(END)) {
59
+ id = value.slice(END.length); end = true;
60
+ } else continue;
61
+ const index = plan.texts.get(id);
62
+ // Mount anchors are impossible in this descriptor too; unknown, malformed
63
+ // and noncanonical IDs all fail before any node is inserted or bound.
64
+ if (index === undefined) mismatch('unexpected text or component identifiers');
65
+ const slot = textOffset + index * 3 + (end ? 1 : 0);
66
+ if (elements[slot]) mismatch(`duplicate text ${end ? 'end' : 'start'} ${id}`);
67
+ elements[slot] = node;
68
+ }
69
+ } while ((node = following(node, root)));
70
+ return validateSlots(plan, elements);
71
+ }
72
+
73
+ // The next node of a SHOW_ALL TreeWalker's pre-order walk confined to `root`,
74
+ // without allocating a walker for every scan.
75
+ function following(node, root) {
76
+ const child = node.firstChild;
77
+ if (child) return child;
78
+ while (node !== root) {
79
+ const sibling = node.nextSibling;
80
+ if (sibling) return sibling;
81
+ node = node.parentNode;
82
+ }
83
+ return null;
84
+ }
85
+
86
+ function validateSlots(plan, elements) {
87
+ const textOffset = plan.elementIds.length;
88
+ const hostOffset = textOffset + plan.textIds.length * 3;
89
+ for (let index = 0; index < plan.elementIds.length; index++) {
90
+ if (!elements[index]) mismatch(`missing element ${plan.elementIds[index]}`);
91
+ }
92
+ for (let index = 0; index < plan.textIds.length; index++) {
93
+ const slot = textOffset + index * 3;
94
+ const id = plan.textIds[index], start = elements[slot], end = elements[slot + 1];
95
+ if (!start) mismatch(`missing text start ${id}`);
96
+ if (!end) mismatch(`missing text end ${id}`);
97
+ const next = start.nextSibling;
98
+ if (!next) mismatch(`unpaired text slot ${id}`);
99
+ let text = null;
100
+ if (next !== end) {
101
+ if (next.nextSibling !== end) mismatch(`unexpected nodes in text slot ${id}`);
102
+ if (next.nodeType !== 3) mismatch(`expected a text node in slot ${id}`);
103
+ text = next;
104
+ }
105
+ elements[slot + 2] = text;
106
+ }
107
+ for (let index = 0; index < plan.textElements.length; index += 3) {
108
+ const slot = hostOffset + index / 3 * 2;
109
+ const id = plan.textElements[index], host = elements[slot];
110
+ if (!host) mismatch(`missing or mismatched text element ${id}`);
111
+ const text = host.firstChild;
112
+ if (text && text.nextSibling) mismatch(`unexpected nodes in text element ${id}`);
113
+ if (text && text.nodeType !== 3) mismatch(`expected a text node in text element ${id}`);
114
+ elements[slot + 1] = text;
115
+ }
116
+ return elements;
117
+ }
118
+
119
+ // These checks replace the typed Rust dyn_into calls at the same validation
120
+ // boundary. Use the application's global constructors, including cross-realm
121
+ // rejection, rather than treating nodeType/tag checks as equivalent casts.
122
+ function checked(value, constructor) {
123
+ let valid = false;
124
+ try {
125
+ switch (constructor) {
126
+ case 'Element': valid = value instanceof Element; break;
127
+ case 'HTMLInputElement': valid = value instanceof HTMLInputElement; break;
128
+ case 'Node': valid = value instanceof Node; break;
129
+ case 'Text': valid = value instanceof Text; break;
130
+ }
131
+ } catch (_) {}
132
+ if (!valid) throw value;
133
+ }
134
+
135
+ function validateBundleTypes(plan, nodes) {
136
+ const textOffset = plan.elementIds.length;
137
+ const hostOffset = textOffset + plan.textIds.length * 3;
138
+ for (let i = 0; i < textOffset; i++) {
139
+ checked(nodes[i], plan.tags[i] === 'input' ? 'HTMLInputElement' : 'Element');
140
+ }
141
+ for (let i = 0; i < plan.textIds.length; i++) {
142
+ const slot = textOffset + i * 3;
143
+ checked(nodes[slot], 'Node');
144
+ checked(nodes[slot + 1], 'Node');
145
+ if (nodes[slot + 2] !== null) checked(nodes[slot + 2], 'Text');
146
+ }
147
+ for (let i = 0; i < plan.textElements.length / 3; i++) {
148
+ const slot = hostOffset + i * 2;
149
+ checked(nodes[slot], 'Element');
150
+ if (nodes[slot + 1] !== null) checked(nodes[slot + 1], 'Text');
151
+ }
152
+ }
153
+
154
+ function pathFrom(root, target) {
155
+ const path = [];
156
+ let node = target;
157
+ while (node !== root) {
158
+ let sibling = node.previousSibling, index = 0;
159
+ while (sibling) { index++; sibling = sibling.previousSibling; }
160
+ path.push(index);
161
+ node = node.parentNode;
162
+ if (!node) mismatch('detached cached handle');
163
+ }
164
+ return path.reverse();
165
+ }
166
+
167
+ function followPath(root, path) {
168
+ let node = root;
169
+ for (const index of path) {
170
+ // Sibling steps address the same child as childNodes.item(index) without
171
+ // materializing a live NodeList for every step.
172
+ node = node.firstChild;
173
+ for (let step = 0; node && step < index; step++) node = node.nextSibling;
174
+ if (!node) mismatch('template changed during resolution');
175
+ }
176
+ return node;
177
+ }
178
+
179
+ function rememberBundle(plan, root, nodes) {
180
+ const textOffset = plan.elementIds.length;
181
+ const hostOffset = textOffset + plan.textIds.length * 3;
182
+ // Match the typed cache's inert-document import. Do not run custom-element
183
+ // construction again or retain an application node in cached metadata.
184
+ const wrapper = root.ownerDocument.createElement('template');
185
+ const inert = wrapper.content.ownerDocument;
186
+ const pristine = inert.importNode(root, true);
187
+ // One step per bundle target, in bundle order: the node at a path, or a new
188
+ // empty Text before an end anchor (1) or inside a text host (2).
189
+ const paths = [], creates = [];
190
+ for (let i = 0; i < textOffset; i++) {
191
+ paths.push(pathFrom(root, nodes[i]));
192
+ creates.push(0);
193
+ }
194
+ for (let i = 0; i < plan.textIds.length; i++) {
195
+ const slot = textOffset + i * 3, text = nodes[slot + 2];
196
+ paths.push(pathFrom(root, text ?? nodes[slot + 1]));
197
+ creates.push(text ? 0 : 1);
198
+ }
199
+ for (let i = 0; i < plan.textElements.length / 3; i++) {
200
+ const slot = hostOffset + i * 2, text = nodes[slot + 1];
201
+ paths.push(pathFrom(root, text ?? nodes[slot]));
202
+ creates.push(text ? 0 : 2);
203
+ }
204
+ plan.bindingCache = { pristine, paths, creates };
205
+ }
206
+
207
+ // An equal clone of the validated inert certificate has the same slots and
208
+ // node interfaces at every path: inert template documents never upgrade.
209
+ // `extra` trailing entries are left for the caller.
210
+ function certifiedBindings(certificate, root, extra) {
211
+ const { paths, creates } = certificate, count = paths.length;
212
+ const nodes = new Array(count + extra);
213
+ // Resolve every location before insertion can shift a later native path.
214
+ for (let i = 0; i < count; i++) nodes[i] = followPath(root, paths[i]);
215
+ // Match finish_resolution's global document rather than root.ownerDocument.
216
+ for (let i = 0; i < count; i++) {
217
+ const create = creates[i];
218
+ if (create === 0) continue;
219
+ const text = document.createTextNode(''), target = nodes[i];
220
+ if (create === 1) target.parentNode.insertBefore(text, target);
221
+ else target.appendChild(text);
222
+ nodes[i] = text;
223
+ }
224
+ return nodes;
225
+ }
226
+
227
+ function scannedBindings(plan, root, cached) {
228
+ const nodes = resolveFlat(plan, root);
229
+ validateBundleTypes(plan, nodes);
230
+ if (cached) {
231
+ // Optional cache construction must not make a validated mount fail.
232
+ try { rememberBundle(plan, root, nodes); } catch (_) {}
233
+ }
234
+ const textOffset = plan.elementIds.length;
235
+ const hostOffset = textOffset + plan.textIds.length * 3;
236
+ // The complete scan, shape checks and typed casts have finished. Keep the
237
+ // exact original targets through user construction and synchronous callbacks.
238
+ // Match finish_resolution's global document rather than root.ownerDocument.
239
+ for (let i = 0; i < plan.textIds.length; i++) {
240
+ const slot = textOffset + i * 3;
241
+ const start = nodes[slot], end = nodes[slot + 1];
242
+ let text = nodes[slot + 2];
243
+ if (text === null) {
244
+ text = document.createTextNode('');
245
+ const parent = start.parentNode;
246
+ if (!parent) mismatch('detached text anchor');
247
+ parent.insertBefore(text, end);
248
+ }
249
+ nodes[textOffset + i] = text;
250
+ }
251
+ for (let i = 0; i < plan.textElements.length / 3; i++) {
252
+ const slot = hostOffset + i * 2, host = nodes[slot];
253
+ let text = nodes[slot + 1];
254
+ if (text === null) { text = document.createTextNode(''); host.appendChild(text); }
255
+ nodes[textOffset + plan.textIds.length + i] = text;
256
+ }
257
+ nodes.length = textOffset + plan.textIds.length + plan.textElements.length / 3;
258
+ return nodes;
259
+ }
260
+
261
+ export function resolveBindings(plan, root, cached) {
262
+ const certificate = cached && plan.bindingCache;
263
+ if (certificate && root.isEqualNode(certificate.pristine)) return certifiedBindings(certificate, root, 0);
264
+ return scannedBindings(plan, root, cached);
265
+ }
266
+
267
+ // The document-template mount of a flat bundled descriptor in one native call.
268
+ // Same checks, clone source, errors and order as the typed Rust sequence:
269
+ // unique root, schema, template kind, one root element, descriptor version,
270
+ // then complete validation before instance marking. The root follows the
271
+ // binding targets in the returned bundle.
272
+ export function mountTemplate(plan, selector, schema, identity, versionOk) {
273
+ const roots = document.querySelectorAll(selector);
274
+ if (roots.length !== 1) mismatch(`component ${identity} requires exactly one root, found ${roots.length}`);
275
+ const template = roots[0];
276
+ if (template.getAttribute('data-fusor-version') !== schema) mismatch('HTML schema version differs from Wasm; rebuild the application');
277
+ if (!(template instanceof HTMLTemplateElement)) mismatch('expected an HTML template');
278
+ const content = template.content;
279
+ if (content.childElementCount !== 1) throw 'fusor: a row template needs exactly one root element';
280
+ const source = content.firstElementChild;
281
+ if (!versionOk) mismatch('unsupported descriptor version; rebuild the application');
282
+ const certificate = plan.bindingCache;
283
+ // A template equal to its certificate clones the certificate's mounted form,
284
+ // which already holds the created text nodes and the instance mark.
285
+ if (certificate && source.isEqualNode(certificate.pristine)) {
286
+ let mounted = certificate.mounted;
287
+ if (mounted === undefined || mounted.identity !== identity) {
288
+ mounted = certificate.mounted = mountedForm(certificate, identity);
289
+ }
290
+ return mountedBindings(mounted);
291
+ }
292
+ const root = source.cloneNode(true);
293
+ const nodes = scannedBindings(plan, root, true);
294
+ nodes.push(root);
295
+ root.setAttribute('data-fusor-instance', identity);
296
+ return nodes;
297
+ }
298
+
299
+ // A clone of the mounted form, with its binding targets and then its root.
300
+ function mountedBindings(mounted) {
301
+ const root = mounted.root.cloneNode(true), paths = mounted.paths, count = paths.length;
302
+ const nodes = new Array(count + 1);
303
+ for (let i = 0; i < count; i++) nodes[i] = followPath(root, paths[i]);
304
+ nodes[count] = root;
305
+ return nodes;
306
+ }
307
+
308
+ // The certified template as a certified mount leaves it: an inert copy of the
309
+ // pristine snapshot with its created text nodes and instance mark, and the
310
+ // path of every binding target within it.
311
+ function mountedForm(certificate, identity) {
312
+ const root = certificate.pristine.cloneNode(true);
313
+ const targets = certifiedBindings(certificate, root, 0);
314
+ root.setAttribute('data-fusor-instance', identity);
315
+ return { identity, root, paths: targets.map((node) => pathFrom(root, node)) };
316
+ }
317
+
318
+ // Fallible entry points report success and keep their result or what they
319
+ // threw for `takeOutcome`, so neither host call needs an exception wrapper.
320
+ let outcome;
321
+ export function mountTemplateOk(plan, selector, schema, identity, versionOk) {
322
+ try {
323
+ outcome = mountTemplate(plan, selector, schema, identity, versionOk);
324
+ return true;
325
+ } catch (error) {
326
+ outcome = error;
327
+ return false;
328
+ }
329
+ }
330
+ export function takeOutcome() {
331
+ const value = outcome;
332
+ outcome = undefined;
333
+ return value;
334
+ }
335
+
336
+ // A server-rendered root of a flat bundled descriptor in one native call, in
337
+ // the typed Rust order: server identity, descriptor version, the complete
338
+ // protocol scan, then instance marking.
339
+ export function hydrateRoot(plan, root, schema, identity, versionOk) {
340
+ if (root.getAttribute('data-fusor-version') !== schema || root.getAttribute('data-fusor-component') !== identity) {
341
+ mismatch('server root identity differs from the browser template');
342
+ }
343
+ if (!versionOk) mismatch('unsupported descriptor version; rebuild the application');
344
+ const nodes = resolveBindings(plan, root, false);
345
+ root.setAttribute('data-fusor-instance', identity);
346
+ return nodes;
347
+ }
348
+
349
+ export function bindingText(nodes, index, value) {
350
+ const text = nodes[index];
351
+ if (text.data !== value) text.data = value;
352
+ }
353
+ export function bindingIntegerText(nodes, index, number) {
354
+ const text = nodes[index], value = "" + number;
355
+ if (text.data !== value) text.data = value;
356
+ }
357
+ export function hydrateRootOk(plan, root, schema, identity, versionOk) {
358
+ try {
359
+ outcome = hydrateRoot(plan, root, schema, identity, versionOk);
360
+ return true;
361
+ } catch (error) {
362
+ outcome = error;
363
+ return false;
364
+ }
365
+ }
366
+ export function bindingSetAttributeOk(nodes, index, name, value) {
367
+ try {
368
+ nodes[index].setAttribute(name, value);
369
+ return true;
370
+ } catch (error) {
371
+ outcome = error;
372
+ return false;
373
+ }
374
+ }
375
+ export function bindingSetIntegerAttributeOk(nodes, index, name, number) {
376
+ try {
377
+ nodes[index].setAttribute(name, "" + number);
378
+ return true;
379
+ } catch (error) {
380
+ outcome = error;
381
+ return false;
382
+ }
383
+ }
384
+ export function bindingRemoveAttributeOk(nodes, index, name) {
385
+ try {
386
+ nodes[index].removeAttribute(name);
387
+ return true;
388
+ } catch (error) {
389
+ outcome = error;
390
+ return false;
391
+ }
392
+ }
393
+ export function bindingElement(nodes, index) { return nodes[index]; }
__fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/src/dom/strings.js ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function setTextIfChanged(node, value) {
2
+ if (node.data !== value) node.data = value;
3
+ }
4
+
5
+ export function setIntegerTextIfChanged(node, number) {
6
+ const value = '' + number;
7
+ setTextIfChanged(node, value);
8
+ }
9
+
10
+ export function setIntegerAttribute(node, name, number) {
11
+ node.setAttribute(name, '' + number);
12
+ }
13
+
14
+ export function serverRows(container, name, encoded, count, complete) {
15
+ const keys = count ? encoded.split('\n') : [];
16
+ const rows = new Array(count);
17
+ let node = container.firstElementChild;
18
+ for (let index = 0; index < count; index++) {
19
+ if (!node) throw 'missing native row';
20
+ if (node.getAttribute(name) !== keys[index]) throw 'native row key mismatch';
21
+ rows[index] = node;
22
+ node = node.nextElementSibling;
23
+ }
24
+ if (complete ? node : !node) {
25
+ throw complete ? 'unexpected native row' : 'missing native row';
26
+ }
27
+ return rows;
28
+ }
29
+
30
+ const listeners = [];
31
+ let removal;
32
+
33
+ export function listenBundleOk(nodes, index, name, dispatch, slot, generation) {
34
+ try {
35
+ return listenOk(nodes[index], name, dispatch, slot, generation);
36
+ } catch (error) {
37
+ removal = error;
38
+ return false;
39
+ }
40
+ }
41
+
42
+ export function unlistenBundleOk(nodes, index, name, slot) {
43
+ try {
44
+ return unlistenOk(nodes[index], name, slot);
45
+ } catch (error) {
46
+ removal = error;
47
+ return false;
48
+ }
49
+ }
50
+
51
+ export function unlistenOk(target, name, slot) {
52
+ try {
53
+ const listener = listeners[slot];
54
+ listeners[slot] = undefined;
55
+ target.removeEventListener(name, listener);
56
+ return true;
57
+ } catch (error) {
58
+ removal = error;
59
+ return false;
60
+ }
61
+ }
62
+
63
+ export function insertBeforeOk(parent, node, anchor) {
64
+ try {
65
+ parent.insertBefore(node, anchor);
66
+ return true;
67
+ } catch (error) {
68
+ removal = error;
69
+ return false;
70
+ }
71
+ }
72
+
73
+ export function takeRemovalFailure() {
74
+ const error = removal;
75
+ removal = undefined;
76
+ return error;
77
+ }
78
+
79
+ export function listenOk(target, name, dispatch, slot, generation) {
80
+ try {
81
+ const listener = event => dispatch(slot, generation, event);
82
+ target.addEventListener(name, listener);
83
+ listeners[slot] = listener;
84
+ return true;
85
+ } catch (error) {
86
+ removal = error;
87
+ return false;
88
+ }
89
+ }
__fusor/g-1793728780335015000-24920/pkg/snippets/fusor-core-b8e34eae654c12f7/src/js/runtime.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Optional native JavaScript component bridge. No scanning, polling, or graph.
2
+ export function inputs_create() { return Object.create(null); }
3
+ export function input_create(read, observe) {
4
+ const state = { read, observe, listeners: new Map(), next: 0, closed: false };
5
+ const api = Object.freeze({
6
+ get() {
7
+ if (state.closed) throw new Error('fusor: JavaScript input belongs to a disposed component');
8
+ return state.read();
9
+ },
10
+ subscribe(callback) {
11
+ if (typeof callback !== 'function') throw new TypeError('fusor: inputs.subscribe requires a function');
12
+ if (state.closed) throw new Error('fusor: cannot subscribe to a disposed component');
13
+ const id = ++state.next;
14
+ state.listeners.set(id, callback);
15
+ const unsubscribe = () => {
16
+ if (!state.listeners.delete(id) || state.closed) return;
17
+ if (state.listeners.size === 0) state.observe(false);
18
+ };
19
+ try {
20
+ if (state.listeners.size === 1) state.observe(true);
21
+ if (state.closed) throw new Error('fusor: cannot subscribe to a disposed component');
22
+ callback(state.read());
23
+ } catch (error) { unsubscribe(); throw error; }
24
+ return unsubscribe;
25
+ },
26
+ });
27
+ state.api = api;
28
+ return state;
29
+ }
30
+ export function input_api(state) { return state.api; }
31
+ export function input_publish(state, value) {
32
+ if (state.closed) return;
33
+ for (const [id, callback] of [...state.listeners]) {
34
+ if (state.closed) break;
35
+ if (!state.listeners.has(id)) continue;
36
+ try { callback(value); } catch (error) { console.error(error); }
37
+ }
38
+ }
39
+ export function input_dispose(state) {
40
+ state.closed = true;
41
+ state.listeners.clear();
42
+ state.read = state.observe = null;
43
+ }
44
+ export function module_create(root, inputs, id) {
45
+ const controller = new AbortController();
46
+ return { root, inputs: Object.freeze(inputs), id, controller, closed: false, cleanups: [] };
47
+ }
48
+ function cleanup(fn) {
49
+ try { fn(); } catch (error) { console.error(error); }
50
+ }
51
+ export function module_activate(state) {
52
+ if (state.closed) return;
53
+ const modules = globalThis[Symbol.for('fusor.javascript.modules.v1')];
54
+ const module = modules?.get(state.id);
55
+ if (!module) throw new Error(`fusor: component module ${state.id} is missing; build with cargo fusor build and enable JavaScript tooling`);
56
+ if (!('onMount' in module)) return;
57
+ if (typeof module.onMount !== 'function') throw new TypeError(`fusor: ${state.id} exports onMount, but it is not a function`);
58
+ if (module.onMount.constructor?.name === 'AsyncFunction') throw new TypeError(`fusor: ${state.id} onMount must be synchronous; start async work inside onMount and use signal`);
59
+ const onCleanup = fn => {
60
+ if (typeof fn !== 'function') throw new TypeError('fusor: onCleanup requires a function');
61
+ if (state.closed) cleanup(fn); else state.cleanups.push(fn);
62
+ };
63
+ const result = module.onMount(Object.freeze({ root: state.root, signal: state.controller.signal, inputs: state.inputs, onCleanup }));
64
+ if (result !== undefined) {
65
+ if (typeof result === 'function') onCleanup(result);
66
+ else {
67
+ if (result != null && typeof result.then === 'function') Promise.resolve(result).catch(error => console.error(error));
68
+ throw new TypeError(`fusor: ${state.id} onMount must return nothing or a cleanup function; promises are unsupported`);
69
+ }
70
+ }
71
+ }
72
+ export function module_dispose(state) {
73
+ if (state.closed) return;
74
+ state.closed = true;
75
+ state.controller.abort();
76
+ while (state.cleanups.length) cleanup(state.cleanups.pop());
77
+ state.root = state.inputs = null;
78
+ }
app.css ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ main {
2
+ max-width: 64rem;
3
+ margin: 0 auto;
4
+ padding: 2rem 1rem 3rem;
5
+ display: grid;
6
+ gap: 1rem;
7
+ }
8
+
9
+ .wordmark {
10
+ font-weight: 650;
11
+ font-size: 1.125rem;
12
+ }
13
+
14
+ .engine {
15
+ display: grid;
16
+ gap: 0.375rem;
17
+ }
18
+
19
+ .level {
20
+ --level: 0;
21
+ height: 0.375rem;
22
+ border-radius: 999px;
23
+ background: linear-gradient(var(--accent), var(--accent)) no-repeat left / calc(var(--level) * 100%) 100%, var(--surface);
24
+ }
25
+
26
+ .hearing,
27
+ .conversation p {
28
+ margin: 0;
29
+ }
30
+
31
+ .hearing:empty {
32
+ display: none;
33
+ }
34
+
35
+ .table {
36
+ overflow-x: auto;
37
+ }
38
+
39
+ table {
40
+ width: 100%;
41
+ border-collapse: collapse;
42
+ font-size: 0.85rem;
43
+ font-variant-numeric: tabular-nums;
44
+ }
45
+
46
+ th,
47
+ td {
48
+ padding: 0.375rem 0.5rem;
49
+ border-bottom: 1px solid var(--hairline);
50
+ text-align: right;
51
+ white-space: nowrap;
52
+ }
53
+
54
+ th:first-child,
55
+ td:first-child {
56
+ text-align: left;
57
+ }
58
+
59
+ thead th {
60
+ color: var(--ink-soft);
61
+ font-weight: 550;
62
+ cursor: help;
63
+ }
64
+
65
+ td:nth-child(2),
66
+ tfoot td,
67
+ tfoot th {
68
+ font-weight: 650;
69
+ }
70
+
71
+ .conversation {
72
+ list-style: none;
73
+ margin: 0;
74
+ padding: 0;
75
+ display: grid;
76
+ gap: 1rem;
77
+ }
78
+
79
+ .conversation li {
80
+ display: grid;
81
+ gap: 0.25rem;
82
+ }
83
+
84
+ .caller {
85
+ color: var(--ink-soft);
86
+ }
87
+
88
+ .caller::before {
89
+ content: "You: ";
90
+ font-weight: 650;
91
+ }
92
+
93
+ .assistant::before {
94
+ content: "Assistant: ";
95
+ font-weight: 650;
96
+ color: var(--accent);
97
+ }
98
+
99
+ fieldset {
100
+ margin: 0;
101
+ padding: 0;
102
+ border: 0;
103
+ display: grid;
104
+ gap: 0.5rem;
105
+ }
106
+
107
+ legend {
108
+ padding: 0;
109
+ margin-bottom: 0.5rem;
110
+ color: var(--ink-soft);
111
+ font-size: 0.875rem;
112
+ }
113
+
114
+ .voices {
115
+ display: flex;
116
+ flex-wrap: wrap;
117
+ gap: 0.5rem;
118
+ }
119
+
120
+ .voice input {
121
+ position: absolute;
122
+ opacity: 0;
123
+ pointer-events: none;
124
+ }
125
+
126
+ .voice span {
127
+ display: block;
128
+ border: 1px solid var(--hairline);
129
+ border-radius: 999px;
130
+ padding: 0.375rem 0.875rem;
131
+ font-size: 0.85rem;
132
+ cursor: pointer;
133
+ transition: background-color 0.2s, color 0.2s, border-color 0.2s;
134
+ }
135
+
136
+ .voice input:checked + span {
137
+ background: var(--ink);
138
+ border-color: var(--ink);
139
+ color: var(--canvas);
140
+ }
141
+
142
+ .voice input:focus-visible + span {
143
+ outline: 2px solid var(--accent);
144
+ outline-offset: 2px;
145
+ }
base.css ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* fusor's landing palette (fusor-rs/fusor, apps/landing/web/theme.css) and its control shapes. */
2
+ :root {
3
+ --canvas: #faf9f6;
4
+ --surface: #f1efea;
5
+ --raised: #ffffff;
6
+ --ink: #272a2c;
7
+ --ink-soft: #5c5f61;
8
+ --ink-faint: #686b6d;
9
+ --hairline: #e3e0d9;
10
+ --accent: #a83228;
11
+ --on-accent: #faf9f6;
12
+ --ease-spring: linear(0, 0.049, 0.157, 0.285, 0.411, 0.525, 0.624, 0.705, 0.772, 0.825, 0.866, 0.899, 0.924, 0.943, 0.957, 0.968, 0.976, 0.982, 0.987, 0.99, 0.993, 0.995, 0.996, 0.997, 1);
13
+ color-scheme: light dark;
14
+ }
15
+
16
+ @media (prefers-color-scheme: dark) {
17
+ :root {
18
+ --canvas: #121314;
19
+ --surface: #1b1d1e;
20
+ --raised: #222426;
21
+ --ink: #f2f1ed;
22
+ --ink-soft: #b4b5b3;
23
+ --ink-faint: #8b8d8d;
24
+ --hairline: #303335;
25
+ --accent: #f0715a;
26
+ --on-accent: #121314;
27
+ }
28
+ }
29
+
30
+ * {
31
+ box-sizing: border-box;
32
+ }
33
+
34
+ /* `display` rules below would otherwise override the attribute. */
35
+ [hidden] {
36
+ display: none !important;
37
+ }
38
+
39
+ body {
40
+ margin: 0;
41
+ background: var(--canvas);
42
+ color: var(--ink);
43
+ font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
44
+ -webkit-font-smoothing: antialiased;
45
+ }
46
+
47
+ :focus-visible {
48
+ outline: 2px solid var(--accent);
49
+ outline-offset: 2px;
50
+ }
51
+
52
+ a {
53
+ color: inherit;
54
+ text-underline-offset: 3px;
55
+ }
56
+
57
+ .masthead {
58
+ margin-bottom: 0.5rem;
59
+ }
60
+
61
+ .lockup {
62
+ display: flex;
63
+ align-items: center;
64
+ gap: 0.75rem;
65
+ }
66
+
67
+ .times {
68
+ color: var(--ink-faint);
69
+ font-size: 1.25rem;
70
+ }
71
+
72
+ h1 {
73
+ margin: 1.25rem 0 0.5rem;
74
+ font-size: clamp(1.75rem, 5vw, 2.5rem);
75
+ line-height: 1.1;
76
+ letter-spacing: -0.02em;
77
+ font-weight: 650;
78
+ }
79
+
80
+ .lede {
81
+ margin: 0;
82
+ color: var(--ink-soft);
83
+ font-size: 1.05rem;
84
+ }
85
+
86
+ .card {
87
+ background: var(--raised);
88
+ border: 1px solid var(--hairline);
89
+ border-radius: 1.25rem;
90
+ padding: 1.25rem;
91
+ display: grid;
92
+ gap: 0.75rem;
93
+ }
94
+
95
+ .broken {
96
+ border-color: var(--accent);
97
+ }
98
+
99
+ .broken p {
100
+ margin: 0;
101
+ }
102
+
103
+ .row {
104
+ display: flex;
105
+ flex-wrap: wrap;
106
+ align-items: center;
107
+ gap: 0.75rem;
108
+ justify-content: space-between;
109
+ }
110
+
111
+ .control {
112
+ border: 1px solid var(--hairline);
113
+ border-radius: 999px;
114
+ background: transparent;
115
+ color: var(--ink);
116
+ padding: 0.5rem 1.125rem;
117
+ font: inherit;
118
+ font-size: 0.9rem;
119
+ font-weight: 550;
120
+ text-decoration: none;
121
+ transition: scale 0.2s var(--ease-spring), background-color 0.2s, color 0.2s;
122
+ user-select: none;
123
+ }
124
+
125
+ .control:not(:disabled) {
126
+ cursor: pointer;
127
+ }
128
+
129
+ .control:active:not(:disabled) {
130
+ scale: 0.97;
131
+ }
132
+
133
+ .control:disabled {
134
+ cursor: not-allowed;
135
+ opacity: 0.4;
136
+ }
137
+
138
+ .primary {
139
+ background: var(--accent);
140
+ border-color: var(--accent);
141
+ color: var(--on-accent);
142
+ }
143
+
144
+ progress {
145
+ width: 100%;
146
+ height: 0.375rem;
147
+ appearance: none;
148
+ border: 0;
149
+ border-radius: 999px;
150
+ background: var(--surface);
151
+ overflow: hidden;
152
+ }
153
+
154
+ progress::-webkit-progress-bar {
155
+ background: var(--surface);
156
+ }
157
+
158
+ progress::-webkit-progress-value {
159
+ background: var(--accent);
160
+ border-radius: 999px;
161
+ transition: width 0.2s;
162
+ }
163
+
164
+ progress::-moz-progress-bar {
165
+ background: var(--accent);
166
+ }
167
+
168
+ .muted {
169
+ color: var(--ink-faint);
170
+ font-size: 0.875rem;
171
+ }
172
+
173
+ footer {
174
+ display: flex;
175
+ flex-wrap: wrap;
176
+ justify-content: space-between;
177
+ gap: 0.5rem;
178
+ margin-top: 0.5rem;
179
+ }
brand/fusor-ai.svg ADDED
brand/voice-call.svg ADDED
engine/asr.js ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The ears: Parakeet Redux in a module Worker. While the caller has the floor, the capture
2
+ // worklet posts 16 kHz audio straight here through a MessagePort and every `MIN_FRESH_SECONDS`
3
+ // of new audio is transcribed again, so at the end of the turn the transcript is usually ready:
4
+ // when the last update already heard past the end of speech, that update is the transcript, and
5
+ // only otherwise does `finish()` read the rest.
6
+
7
+ import { engine, load, post, requestsSinceReady, serve, yieldTask } from './dist/host/worker.js';
8
+
9
+ const MIN_FRESH_SECONDS = 0.5;
10
+
11
+ let sampleRate = 0;
12
+ let live = null;
13
+
14
+ serve({
15
+ load: ({ modelUrl, threads, build }) =>
16
+ load({
17
+ modelUrl,
18
+ threads,
19
+ build,
20
+ glueName: 'parakeet_runtime',
21
+ cacheName: 'voice-call-parakeet',
22
+ distUrl: new URL('./dist/parakeet/', import.meta.url),
23
+ onRuntime: (started) => {
24
+ sampleRate = started.glue.sample_rate();
25
+ post({ type: 'runtime', build: started.build.name, threads: started.threads });
26
+ },
27
+ onReady: (progress) => post({ type: 'ready', ...progress }),
28
+ }),
29
+ listen,
30
+ finish,
31
+ stop: () => close(),
32
+ });
33
+
34
+ function listen({ turn, port }) {
35
+ close();
36
+ engine.rt.listen();
37
+ const session = { turn, port, fresh: 0, committed: [], provisional: [], heard: 0, running: false };
38
+ port.onmessage = ({ data: samples }) => {
39
+ engine.rt.hear(samples);
40
+ session.fresh += samples.length;
41
+ pump(session);
42
+ };
43
+ live = session;
44
+ }
45
+
46
+ function close() {
47
+ live?.port.close();
48
+ const session = live;
49
+ live = null;
50
+ return session;
51
+ }
52
+
53
+ /** Transcribes `session` again while enough new audio keeps arriving, one update per macrotask. */
54
+ async function pump(session) {
55
+ if (session.running) return;
56
+ session.running = true;
57
+ try {
58
+ while (live === session && session.fresh >= MIN_FRESH_SECONDS * sampleRate) {
59
+ session.fresh = 0;
60
+ take(session, JSON.parse(engine.rt.update()));
61
+ post({ type: 'text', turn: session.turn, text: transcript(session) });
62
+ await yieldTask();
63
+ }
64
+ } finally {
65
+ session.running = false;
66
+ }
67
+ }
68
+
69
+ /** The turn's transcript, `speechEnd` seconds after listening began being the end of speech. */
70
+ async function finish({ turn, speechEnd }) {
71
+ const session = close();
72
+ if (session?.turn !== turn) return;
73
+ while (session.running) await yieldTask();
74
+ const t0 = performance.now();
75
+ const reused = session.heard >= speechEnd;
76
+ if (!reused) take(session, JSON.parse(engine.rt.finish()));
77
+ const finishMs = performance.now() - t0;
78
+ post({ type: 'final', turn, text: transcript(session), reused, finishMs, networkRequests: requestsSinceReady() });
79
+ }
80
+
81
+ function take(session, update) {
82
+ session.committed.push(...update.committed);
83
+ session.provisional = update.provisional;
84
+ session.heard = update.heard;
85
+ }
86
+
87
+ const transcript = (session) => [...session.committed, ...session.provisional].map((sentence) => sentence.text.trim()).join(' ');
engine/capture.js ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The microphone's audio worklet, in a context at Parakeet's 16 kHz. The call is half duplex:
2
+ // the page opens the floor for each caller turn (`open`, with the port of the ASR worker's
3
+ // listening session) and nothing is heard while the assistant speaks.
4
+ //
5
+ // While open, the audio, channels averaged, goes to the ASR worker in pieces of `PIECE_SECONDS`,
6
+ // and every `FRAME_SECONDS` frame is judged voiced when its RMS reaches `level`. Once the caller
7
+ // has spoken for `MIN_SPEECH_SECONDS` and then been silent for `endpoint` seconds, the turn ends:
8
+ // the page hears `endpoint` with `speechEnd`, the seconds of audio sent up to the last voiced
9
+ // frame, and the floor closes. The page also hears each frame's level.
10
+
11
+ const PIECE_SECONDS = 0.1;
12
+ const FRAME_SECONDS = 0.02;
13
+ const MIN_SPEECH_SECONDS = 0.1;
14
+ const PIECE_SAMPLES = Math.round(PIECE_SECONDS * sampleRate);
15
+ const FRAME_SAMPLES = Math.round(FRAME_SECONDS * sampleRate);
16
+
17
+ class Capture extends AudioWorkletProcessor {
18
+ #engine = null;
19
+ #level = 0;
20
+ #endpointSamples = 0;
21
+ #piece = new Float32Array(PIECE_SAMPLES);
22
+ #filled = 0;
23
+ #sent = 0;
24
+ #energy = 0;
25
+ #voicedSamples = 0;
26
+ #voicedEnd = 0;
27
+
28
+ constructor() {
29
+ super();
30
+ this.port.onmessage = ({ data }) => {
31
+ if (data.type === 'open') this.#open(data);
32
+ else if (data.type === 'close') this.#close();
33
+ };
34
+ }
35
+
36
+ #open({ port, level, endpoint }) {
37
+ this.#engine = port;
38
+ this.#level = level;
39
+ this.#endpointSamples = Math.round(endpoint * sampleRate);
40
+ this.#filled = 0;
41
+ this.#sent = 0;
42
+ this.#energy = 0;
43
+ this.#voicedSamples = 0;
44
+ this.#voicedEnd = 0;
45
+ }
46
+
47
+ #close() {
48
+ this.#engine?.close();
49
+ this.#engine = null;
50
+ }
51
+
52
+ process([channels]) {
53
+ if (!channels.length || !this.#engine) return true;
54
+ for (let i = 0; i < channels[0].length && this.#engine; i++) {
55
+ let sample = 0;
56
+ for (const channel of channels) sample += channel[i] / channels.length;
57
+ this.#take(sample);
58
+ }
59
+ return true;
60
+ }
61
+
62
+ #take(sample) {
63
+ this.#piece[this.#filled++] = sample;
64
+ this.#sent++;
65
+ if (this.#filled === PIECE_SAMPLES) {
66
+ // Transferring the piece detaches it: the next one is new.
67
+ this.#engine.postMessage(this.#piece, [this.#piece.buffer]);
68
+ this.#piece = new Float32Array(PIECE_SAMPLES);
69
+ this.#filled = 0;
70
+ }
71
+ this.#energy += sample * sample;
72
+ if (this.#sent % FRAME_SAMPLES === 0) this.#judgeFrame();
73
+ }
74
+
75
+ #judgeFrame() {
76
+ const rms = Math.sqrt(this.#energy / FRAME_SAMPLES);
77
+ this.#energy = 0;
78
+ this.port.postMessage({ type: 'level', rms });
79
+ if (rms >= this.#level) {
80
+ this.#voicedSamples += FRAME_SAMPLES;
81
+ this.#voicedEnd = this.#sent;
82
+ if (this.#voicedSamples === FRAME_SAMPLES) this.port.postMessage({ type: 'speech' });
83
+ return;
84
+ }
85
+ const spoke = this.#voicedSamples >= MIN_SPEECH_SECONDS * sampleRate;
86
+ if (spoke && this.#sent - this.#voicedEnd >= this.#endpointSamples) {
87
+ this.port.postMessage({ type: 'endpoint', speechEnd: this.#voicedEnd / sampleRate });
88
+ this.#close();
89
+ }
90
+ }
91
+ }
92
+
93
+ registerProcessor('call-capture', Capture);
engine/dist/host/loader.js ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Starting a fusor-ai runtime in a module Worker and streaming a bundle into it.
2
+ //
3
+ // `startRuntime` picks the best runtime build this browser runs (threads need a cross-origin
4
+ // isolated page, relaxed SIMD is probed), instantiates it and, for threaded builds, starts its
5
+ // compute pool; when threads cannot be set up it falls back to a single-threaded build.
6
+ //
7
+ // `loadParts` streams every part of a bundle into the runtime — from OPFS when cached there,
8
+ // else from the network while caching it — through the runtime's part protocol:
9
+ // `write_part(index, bytes)` in order, `end_part(index)` (which checks size and BLAKE3 and
10
+ // throws `{"kind","message"}` JSON), and `restart_part(index)`. Only an `integrity` failure
11
+ // evicts a cached part; other errors are reported as they are.
12
+
13
+ const PARALLEL_PARTS = 4;
14
+ const PUSH_BYTES = 4 << 20; // coalesce network chunks into writes of this size
15
+
16
+ // Relaxed SIMD: a function using `i32x4.relaxed_dot_i8x16_i7x16_add_s` (0xfd 0x93 0x02), the
17
+ // instruction the relaxed kernels are built on. Engines without the proposal reject it.
18
+ const RELAXED_PROBE = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 19, 1, 17, 0, 65, 1, 253, 15, 65, 2, 253, 15, 65, 3, 253, 15, 253, 147, 2, 11]);
19
+
20
+ // Runtime builds, best first (`scripts/build-runtime.sh` builds each into `<dist>/<name>/`).
21
+ export const BUILDS = [
22
+ { name: 'web-threaded-relaxed', threads: true, relaxed: true },
23
+ { name: 'web-threaded', threads: true, relaxed: false },
24
+ { name: 'web-single-relaxed', threads: false, relaxed: true },
25
+ { name: 'web-single', threads: false, relaxed: false },
26
+ ];
27
+
28
+ /** A runtime's `{"kind","message"}` error, or null for any other error. */
29
+ function runtimeError(error) {
30
+ try {
31
+ return JSON.parse(String(error?.message ?? error));
32
+ } catch {
33
+ return null; // not thrown by the runtime as JSON
34
+ }
35
+ }
36
+
37
+ /** The `kind` of a runtime error (`format`, `integrity`, …), or null for other errors. */
38
+ export function errorKind(error) {
39
+ return runtimeError(error)?.kind ?? null;
40
+ }
41
+
42
+ /** A runtime error's message, or the runtime's last Rust panic behind a wasm trap. */
43
+ export function describe(error, glue) {
44
+ const runtime = runtimeError(error);
45
+ if (runtime) return runtime.message;
46
+ const text = String(error?.message ?? error);
47
+ const panic = glue?.last_panic?.();
48
+ return panic ? `${text} (panic: ${panic})` : text;
49
+ }
50
+
51
+ /** The best build this browser runs, or `requested` (a `BUILDS` name) when it can run that. */
52
+ export function chooseBuild(threads, requested) {
53
+ const threaded = self.crossOriginIsolated === true && threads > 1;
54
+ const relaxed = WebAssembly.validate(RELAXED_PROBE);
55
+ const usable = BUILDS.filter((b) => (!b.threads || threaded) && (!b.relaxed || relaxed));
56
+ return usable.find((b) => b.name === requested) ?? usable[0];
57
+ }
58
+
59
+ /**
60
+ * Imports and instantiates `<distUrl>/<build>/<glueName>.js`. Returns `{ glue, build, threads }`.
61
+ * `onWarning(message)` hears about a fallback to one thread.
62
+ */
63
+ export async function startRuntime({ distUrl, glueName, threads, requested, onWarning }) {
64
+ const build = chooseBuild(threads, requested);
65
+ try {
66
+ return { glue: await instantiate(distUrl, glueName, build, threads), build, threads: build.threads ? threads : 1 };
67
+ } catch (error) {
68
+ // The shared memory or the compute workers could not be set up: one thread still works.
69
+ if (!build.threads) throw error;
70
+ onWarning?.(`threads unavailable (${describe(error)}); running on one thread`);
71
+ const single = chooseBuild(1);
72
+ return { glue: await instantiate(distUrl, glueName, single, 1), build: single, threads: 1 };
73
+ }
74
+ }
75
+
76
+ async function instantiate(distUrl, glueName, build, threads) {
77
+ const base = new URL(`${build.name}/`, distUrl);
78
+ const glue = await import(new URL(`${glueName}.js`, base));
79
+ await glue.default({ module_or_path: new URL(`${glueName}_bg.wasm`, base) });
80
+ if (build.threads) await glue.initThreadPool(threads);
81
+ return glue;
82
+ }
83
+
84
+ /**
85
+ * Streams every part of `manifest` (relative to `baseUrl`) into `runtime`. `onProgress` gets
86
+ * `{ done, total, network, cache }` byte counts. Parts are cached in the OPFS directory
87
+ * `cacheName`, one file per part named by its BLAKE3.
88
+ */
89
+ export async function loadParts({ runtime, manifest, baseUrl, cacheName, onProgress }) {
90
+ const store = await openStore(cacheName);
91
+ const total = manifest.parts.reduce((n, part) => n + part.bytes, 0);
92
+ const progress = { done: 0, total, network: 0, cache: 0 };
93
+ const report = (bytes, source) => {
94
+ progress.done += bytes;
95
+ progress[source] += bytes;
96
+ onProgress?.({ ...progress });
97
+ };
98
+ const queue = manifest.parts.map((part, index) => ({ part, index }));
99
+ const lane = async () => {
100
+ for (let item = queue.shift(); item; item = queue.shift()) {
101
+ await loadPart({ runtime, store, item, baseUrl, report });
102
+ }
103
+ };
104
+ await Promise.all(Array.from({ length: PARALLEL_PARTS }, lane));
105
+ return progress;
106
+ }
107
+
108
+ async function loadPart({ runtime, store, item: { part, index }, baseUrl, report }) {
109
+ if (await store?.has(part)) {
110
+ const pushed = await pushStream(runtime, index, await store.read(part), (n) => report(n, 'cache'));
111
+ try {
112
+ runtime.end_part(index);
113
+ return;
114
+ } catch (error) {
115
+ // Only a hash mismatch means the cached copy is bad; anything else (the runtime failing
116
+ // to build from a complete bundle) is reported as is.
117
+ if (errorKind(error) !== 'integrity') throw error;
118
+ await store.remove(part);
119
+ runtime.restart_part(index);
120
+ report(-pushed, 'cache');
121
+ }
122
+ }
123
+ const response = await fetchOk(new URL(part.file, baseUrl));
124
+ const sink = await store?.writer(part);
125
+ try {
126
+ await pushStream(runtime, index, response.body, (n) => report(n, 'network'), sink);
127
+ runtime.end_part(index);
128
+ } catch (error) {
129
+ sink?.close();
130
+ if (errorKind(error) !== 'format') await store?.remove(part); // bad bytes, or a cut-off download
131
+ throw error;
132
+ }
133
+ sink?.close();
134
+ }
135
+
136
+ /** Pushes a byte stream into part `index` in writes of about PUSH_BYTES; returns the bytes. */
137
+ async function pushStream(runtime, index, stream, onBytes, sink) {
138
+ const reader = stream.getReader();
139
+ let pending = [];
140
+ let pendingBytes = 0;
141
+ let total = 0;
142
+ const flush = () => {
143
+ if (!pendingBytes) return;
144
+ const bytes = pending.length === 1 ? pending[0] : concat(pending, pendingBytes);
145
+ runtime.write_part(index, bytes);
146
+ sink?.write(bytes);
147
+ onBytes(bytes.length);
148
+ total += bytes.length;
149
+ pending = [];
150
+ pendingBytes = 0;
151
+ };
152
+ for (;;) {
153
+ const { done, value } = await reader.read();
154
+ if (done) break;
155
+ pending.push(value);
156
+ pendingBytes += value.length;
157
+ if (pendingBytes >= PUSH_BYTES) flush();
158
+ }
159
+ flush();
160
+ return total;
161
+ }
162
+
163
+ function concat(chunks, length) {
164
+ const out = new Uint8Array(length);
165
+ let offset = 0;
166
+ for (const chunk of chunks) {
167
+ out.set(chunk, offset);
168
+ offset += chunk.length;
169
+ }
170
+ return out;
171
+ }
172
+
173
+ export async function fetchOk(url) {
174
+ const response = await fetch(url);
175
+ if (!response.ok) throw new Error(`${url}: HTTP ${response.status}`);
176
+ return response;
177
+ }
178
+
179
+ /**
180
+ * Parts cached in the origin-private file system. A file whose part fails verification is
181
+ * deleted; a cached file is verified again on every load (an interrupted write leaves a short
182
+ * file, which `has` rejects). Without OPFS everything is fetched.
183
+ */
184
+ async function openStore(cacheName) {
185
+ let dir;
186
+ try {
187
+ dir = await (await navigator.storage.getDirectory()).getDirectoryHandle(cacheName, { create: true });
188
+ } catch {
189
+ return null;
190
+ }
191
+ return {
192
+ async has(part) {
193
+ try {
194
+ return (await (await dir.getFileHandle(part.blake3)).getFile()).size === part.bytes;
195
+ } catch {
196
+ return false;
197
+ }
198
+ },
199
+ async read(part) {
200
+ return (await (await dir.getFileHandle(part.blake3)).getFile()).stream();
201
+ },
202
+ async remove(part) {
203
+ await dir.removeEntry(part.blake3).catch(() => {});
204
+ },
205
+ async writer(part) {
206
+ let access;
207
+ try {
208
+ access = await (await dir.getFileHandle(part.blake3, { create: true })).createSyncAccessHandle();
209
+ } catch {
210
+ return null; // no sync access handles (or another tab holds the file): don't cache
211
+ }
212
+ access.truncate(0);
213
+ let offset = 0;
214
+ let failed = false; // e.g. quota exceeded: keep loading, just stop caching this part
215
+ return {
216
+ write(bytes) {
217
+ if (failed) return;
218
+ try {
219
+ offset += access.write(bytes, { at: offset });
220
+ } catch {
221
+ failed = true;
222
+ }
223
+ },
224
+ close() {
225
+ try {
226
+ access.flush();
227
+ } finally {
228
+ access.close();
229
+ }
230
+ },
231
+ };
232
+ },
233
+ };
234
+ }
engine/dist/host/worker.js ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The shared half of a model's engine worker: the module Worker that loads the model and runs it
2
+ // off the page's main thread. A product's worker imports this beside the loader and keeps only
3
+ // its own message handlers.
4
+ //
5
+ // `load` overlaps the manifest download with the runtime's start, streams every part into the
6
+ // runtime (from OPFS when cached there, else from the network), and afterwards deletes the cached
7
+ // parts of earlier bundles. `serve` routes the page's messages to the handlers and reports their
8
+ // failures. After the model is loaded nothing else should be fetched: `requestsSinceReady` counts
9
+ // what was, for the page to show.
10
+
11
+ import { describe, errorKind, fetchOk, loadParts, startRuntime } from './loader.js';
12
+
13
+ export const post = (message, transfer) => self.postMessage(message, transfer ?? []);
14
+
15
+ // A macrotask without setTimeout's 4 ms clamp on nested timers. Resolvers queue, so overlapping
16
+ // awaits each resume.
17
+ const ticks = new MessageChannel();
18
+ const waiting = [];
19
+ ticks.port1.onmessage = () => waiting.shift()();
20
+ export const yieldTask = () => new Promise((resolve) => {
21
+ waiting.push(resolve);
22
+ ticks.port2.postMessage(null);
23
+ });
24
+
25
+ /** The loaded runtime, `{ rt, glue }`: null until `load` created it. */
26
+ export let engine = null;
27
+ let resolveReady;
28
+ /** Resolves once every part is in and the model is built. */
29
+ export const ready = new Promise((resolve) => (resolveReady = resolve));
30
+ let readyAt = Infinity;
31
+
32
+ /** The requests this worker made after the model was ready. */
33
+ export const requestsSinceReady = () => performance.getEntriesByType('resource').filter((entry) => entry.startTime >= readyAt).length;
34
+
35
+ /**
36
+ * Loads the bundle at `modelUrl` into the best runtime build of `glueName` under `distUrl`.
37
+ * `onRuntime(started)` runs once the runtime exists, `onReady({ ms, ...progress })` once the model
38
+ * is built; `progress` and `warning` messages are posted on the way.
39
+ */
40
+ export async function load({ modelUrl, threads, build, glueName, cacheName, distUrl, onRuntime, onReady }) {
41
+ const t0 = performance.now();
42
+ const [manifestText, started] = await Promise.all([
43
+ fetchOk(new URL('manifest.json', modelUrl)).then((response) => response.text()),
44
+ startRuntime({ distUrl, glueName, threads, requested: build, onWarning: (message) => post({ type: 'warning', message }) }),
45
+ ]);
46
+ const manifest = JSON.parse(manifestText);
47
+ engine = { rt: new started.glue.Runtime(manifestText), glue: started.glue };
48
+ onRuntime(started);
49
+ const progress = await loadParts({
50
+ runtime: engine.rt,
51
+ manifest,
52
+ baseUrl: modelUrl,
53
+ cacheName,
54
+ onProgress: (p) => post({ type: 'progress', ...p }),
55
+ });
56
+ readyAt = performance.now();
57
+ onReady({ ms: readyAt - t0, ...progress });
58
+ resolveReady();
59
+ await evictStaleParts(manifest, cacheName);
60
+ }
61
+
62
+ /** Deletes cached parts this bundle does not name: those of earlier bundles. */
63
+ async function evictStaleParts(manifest, cacheName) {
64
+ const keep = new Set(manifest.parts.map((part) => part.blake3));
65
+ let dir;
66
+ try {
67
+ dir = await (await navigator.storage.getDirectory()).getDirectoryHandle(cacheName);
68
+ } catch {
69
+ return; // no OPFS, or nothing was cached
70
+ }
71
+ for await (const name of dir.keys()) {
72
+ if (!keep.has(name)) await dir.removeEntry(name);
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Posts a failure of `job`. A runtime error is `{"kind","message"}` JSON and leaves the engine
78
+ * usable: it is posted as `error`. Anything else is a trap (the runtimes abort on panic) or a bug
79
+ * that lost the module's state: it is posted as `fatal`.
80
+ */
81
+ export function report(error, job) {
82
+ post({ type: errorKind(error) ? 'error' : 'fatal', job, message: describe(error, engine?.glue) });
83
+ }
84
+
85
+ /** Routes each page message to `handlers[type]`, and reports what fails. */
86
+ export function serve(handlers) {
87
+ self.onmessage = async ({ data }) => {
88
+ try {
89
+ await handlers[data.type]?.(data);
90
+ } catch (error) {
91
+ report(error, data.job);
92
+ }
93
+ };
94
+ }
engine/dist/lfm3/web-single-relaxed/lfm3_runtime.js ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class Runtime {
2
+ __destroy_into_raw() {
3
+ const ptr = this.__wbg_ptr;
4
+ this.__wbg_ptr = 0;
5
+ RuntimeFinalization.unregister(this);
6
+ return ptr;
7
+ }
8
+ free() {
9
+ const ptr = this.__destroy_into_raw();
10
+ wasm.__wbg_runtime_free(ptr, 0);
11
+ }
12
+ cancel() {
13
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
14
+ if (ret[1]) {
15
+ throw takeFromExternrefTable0(ret[0]);
16
+ }
17
+ }
18
+ /**
19
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
20
+ * whether the engine is ready.
21
+ * @param {number} part
22
+ * @returns {boolean}
23
+ */
24
+ end_part(part) {
25
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] !== 0;
30
+ }
31
+ /**
32
+ * @param {string} manifest_json
33
+ */
34
+ constructor(manifest_json) {
35
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ret = wasm.runtime_new(ptr0, len0);
38
+ if (ret[2]) {
39
+ throw takeFromExternrefTable0(ret[1]);
40
+ }
41
+ this.__wbg_ptr = ret[0];
42
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
43
+ return this;
44
+ }
45
+ /**
46
+ * Forgets the conversation, to start a new one.
47
+ */
48
+ reset() {
49
+ const ret = wasm.runtime_reset(this.__wbg_ptr);
50
+ if (ret[1]) {
51
+ throw takeFromExternrefTable0(ret[0]);
52
+ }
53
+ }
54
+ /**
55
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
56
+ * again.
57
+ * @param {number} part
58
+ */
59
+ restart_part(part) {
60
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
61
+ if (ret[1]) {
62
+ throw takeFromExternrefTable0(ret[0]);
63
+ }
64
+ }
65
+ /**
66
+ * The 24 kHz mono samples the reply spoke since the last call.
67
+ * @returns {Float32Array}
68
+ */
69
+ speech() {
70
+ const ret = wasm.runtime_speech(this.__wbg_ptr);
71
+ if (ret[3]) {
72
+ throw takeFromExternrefTable0(ret[2]);
73
+ }
74
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
75
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
76
+ return v1;
77
+ }
78
+ /**
79
+ * Starts replying to `message_json` (`{"text", "system"?, "thinking"?, "mode"?,
80
+ * "max_tokens"?, "sampling"?, "seed"}`, `mode` one of `text`, `transcribe`, `speech` and
81
+ * `interleaved`), the conversation's next turn, with the images whose RGBA pixels `rgba`
82
+ * holds and the 16 kHz mono clips whose samples `audio` holds, as `layout_json` lays them out
83
+ * (`{"images": [[width, height]…], "clips": [samples…]}`); returns its plan (`{"images",
84
+ * "clips", "prompt_tokens", "max_tokens", "sampling"}`).
85
+ * @param {string} message_json
86
+ * @param {Uint8Array} rgba
87
+ * @param {Float32Array} audio
88
+ * @param {string} layout_json
89
+ * @returns {string}
90
+ */
91
+ start(message_json, rgba, audio, layout_json) {
92
+ let deferred6_0;
93
+ let deferred6_1;
94
+ try {
95
+ const ptr0 = passStringToWasm0(message_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
96
+ const len0 = WASM_VECTOR_LEN;
97
+ const ptr1 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc);
98
+ const len1 = WASM_VECTOR_LEN;
99
+ const ptr2 = passArrayF32ToWasm0(audio, wasm.__wbindgen_malloc);
100
+ const len2 = WASM_VECTOR_LEN;
101
+ const ptr3 = passStringToWasm0(layout_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
102
+ const len3 = WASM_VECTOR_LEN;
103
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
104
+ var ptr5 = ret[0];
105
+ var len5 = ret[1];
106
+ if (ret[3]) {
107
+ ptr5 = 0; len5 = 0;
108
+ throw takeFromExternrefTable0(ret[2]);
109
+ }
110
+ deferred6_0 = ptr5;
111
+ deferred6_1 = len5;
112
+ return getStringFromWasm0(ptr5, len5);
113
+ } finally {
114
+ wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
115
+ }
116
+ }
117
+ /**
118
+ * Runs the next stage; returns `{"stage", "reasoning", "answer", "tokens", "frames",
119
+ * "done"}`, the reply so far.
120
+ * @returns {string}
121
+ */
122
+ step() {
123
+ let deferred2_0;
124
+ let deferred2_1;
125
+ try {
126
+ const ret = wasm.runtime_step(this.__wbg_ptr);
127
+ var ptr1 = ret[0];
128
+ var len1 = ret[1];
129
+ if (ret[3]) {
130
+ ptr1 = 0; len1 = 0;
131
+ throw takeFromExternrefTable0(ret[2]);
132
+ }
133
+ deferred2_0 = ptr1;
134
+ deferred2_1 = len1;
135
+ return getStringFromWasm0(ptr1, len1);
136
+ } finally {
137
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
138
+ }
139
+ }
140
+ /**
141
+ * @returns {number}
142
+ */
143
+ threads() {
144
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
145
+ if (ret[2]) {
146
+ throw takeFromExternrefTable0(ret[1]);
147
+ }
148
+ return ret[0] >>> 0;
149
+ }
150
+ /**
151
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
152
+ * @param {number} part
153
+ * @param {Uint8Array} bytes
154
+ */
155
+ write_part(part, bytes) {
156
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
157
+ const len0 = WASM_VECTOR_LEN;
158
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
159
+ if (ret[1]) {
160
+ throw takeFromExternrefTable0(ret[0]);
161
+ }
162
+ }
163
+ }
164
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
165
+
166
+ /**
167
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
168
+ * @returns {string}
169
+ */
170
+ export function last_panic() {
171
+ let deferred1_0;
172
+ let deferred1_1;
173
+ try {
174
+ const ret = wasm.last_panic();
175
+ deferred1_0 = ret[0];
176
+ deferred1_1 = ret[1];
177
+ return getStringFromWasm0(ret[0], ret[1]);
178
+ } finally {
179
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
180
+ }
181
+ }
182
+ function __wbg_get_imports() {
183
+ const import0 = {
184
+ __proto__: null,
185
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
186
+ const ret = Error(getStringFromWasm0(arg0, arg1));
187
+ return ret;
188
+ },
189
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
190
+ throw new Error(getStringFromWasm0(arg0, arg1));
191
+ },
192
+ __wbindgen_init_externref_table: function() {
193
+ const table = wasm.__wbindgen_externrefs;
194
+ const offset = table.grow(4);
195
+ table.set(0, undefined);
196
+ table.set(offset + 0, undefined);
197
+ table.set(offset + 1, null);
198
+ table.set(offset + 2, true);
199
+ table.set(offset + 3, false);
200
+ },
201
+ };
202
+ return {
203
+ __proto__: null,
204
+ "./lfm3_runtime_bg.js": import0,
205
+ };
206
+ }
207
+
208
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
209
+ ? { register: () => {}, unregister: () => {} }
210
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
211
+
212
+ function getArrayF32FromWasm0(ptr, len) {
213
+ ptr = ptr >>> 0;
214
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
215
+ }
216
+
217
+ let cachedFloat32ArrayMemory0 = null;
218
+ function getFloat32ArrayMemory0() {
219
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
220
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
221
+ }
222
+ return cachedFloat32ArrayMemory0;
223
+ }
224
+
225
+ function getStringFromWasm0(ptr, len) {
226
+ return decodeText(ptr >>> 0, len);
227
+ }
228
+
229
+ let cachedUint8ArrayMemory0 = null;
230
+ function getUint8ArrayMemory0() {
231
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
232
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
233
+ }
234
+ return cachedUint8ArrayMemory0;
235
+ }
236
+
237
+ function passArray8ToWasm0(arg, malloc) {
238
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
239
+ getUint8ArrayMemory0().set(arg, ptr / 1);
240
+ WASM_VECTOR_LEN = arg.length;
241
+ return ptr;
242
+ }
243
+
244
+ function passArrayF32ToWasm0(arg, malloc) {
245
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
246
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
247
+ WASM_VECTOR_LEN = arg.length;
248
+ return ptr;
249
+ }
250
+
251
+ function passStringToWasm0(arg, malloc, realloc) {
252
+ if (realloc === undefined) {
253
+ const buf = cachedTextEncoder.encode(arg);
254
+ const ptr = malloc(buf.length, 1) >>> 0;
255
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
256
+ WASM_VECTOR_LEN = buf.length;
257
+ return ptr;
258
+ }
259
+
260
+ let len = arg.length;
261
+ let ptr = malloc(len, 1) >>> 0;
262
+
263
+ const mem = getUint8ArrayMemory0();
264
+
265
+ let offset = 0;
266
+
267
+ for (; offset < len; offset++) {
268
+ const code = arg.charCodeAt(offset);
269
+ if (code > 0x7F) break;
270
+ mem[ptr + offset] = code;
271
+ }
272
+ if (offset !== len) {
273
+ if (offset !== 0) {
274
+ arg = arg.slice(offset);
275
+ }
276
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
277
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
278
+ const ret = cachedTextEncoder.encodeInto(arg, view);
279
+
280
+ offset += ret.written;
281
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
282
+ }
283
+
284
+ WASM_VECTOR_LEN = offset;
285
+ return ptr;
286
+ }
287
+
288
+ function takeFromExternrefTable0(idx) {
289
+ const value = wasm.__wbindgen_externrefs.get(idx);
290
+ wasm.__externref_table_dealloc(idx);
291
+ return value;
292
+ }
293
+
294
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
295
+ cachedTextDecoder.decode();
296
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
297
+ let numBytesDecoded = 0;
298
+ function decodeText(ptr, len) {
299
+ numBytesDecoded += len;
300
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
301
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
302
+ cachedTextDecoder.decode();
303
+ numBytesDecoded = len;
304
+ }
305
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
306
+ }
307
+
308
+ const cachedTextEncoder = new TextEncoder();
309
+
310
+ if (!('encodeInto' in cachedTextEncoder)) {
311
+ cachedTextEncoder.encodeInto = function (arg, view) {
312
+ const buf = cachedTextEncoder.encode(arg);
313
+ view.set(buf);
314
+ return {
315
+ read: arg.length,
316
+ written: buf.length
317
+ };
318
+ };
319
+ }
320
+
321
+ let WASM_VECTOR_LEN = 0;
322
+
323
+ let wasmModule, wasmInstance, wasm;
324
+ function __wbg_finalize_init(instance, module) {
325
+ wasmInstance = instance;
326
+ wasm = instance.exports;
327
+ wasmModule = module;
328
+ cachedFloat32ArrayMemory0 = null;
329
+ cachedUint8ArrayMemory0 = null;
330
+ wasm.__wbindgen_start();
331
+ return wasm;
332
+ }
333
+
334
+ async function __wbg_load(module, imports) {
335
+ if (typeof Response === 'function' && module instanceof Response) {
336
+ if (!module.ok) {
337
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
338
+ }
339
+
340
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
341
+ try {
342
+ return await WebAssembly.instantiateStreaming(module, imports);
343
+ } catch (e) {
344
+ const validResponse = expectedResponseType(module.type);
345
+
346
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
347
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
348
+
349
+ } else { throw e; }
350
+ }
351
+ }
352
+
353
+ const bytes = await module.arrayBuffer();
354
+ return await WebAssembly.instantiate(bytes, imports);
355
+ } else {
356
+ const instance = await WebAssembly.instantiate(module, imports);
357
+
358
+ if (instance instanceof WebAssembly.Instance) {
359
+ return { instance, module };
360
+ } else {
361
+ return instance;
362
+ }
363
+ }
364
+
365
+ function expectedResponseType(type) {
366
+ switch (type) {
367
+ case 'basic': case 'cors': case 'default': return true;
368
+ }
369
+ return false;
370
+ }
371
+ }
372
+
373
+ function initSync(module) {
374
+ if (wasm !== undefined) return wasm;
375
+
376
+
377
+ if (module !== undefined) {
378
+ if (Object.getPrototypeOf(module) === Object.prototype) {
379
+ ({module} = module)
380
+ } else {
381
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
382
+ }
383
+ }
384
+
385
+ const imports = __wbg_get_imports();
386
+ if (!(module instanceof WebAssembly.Module)) {
387
+ module = new WebAssembly.Module(module);
388
+ }
389
+ const instance = new WebAssembly.Instance(module, imports);
390
+ return __wbg_finalize_init(instance, module);
391
+ }
392
+
393
+ async function __wbg_init(module_or_path) {
394
+ if (wasm !== undefined) return wasm;
395
+
396
+
397
+ if (module_or_path !== undefined) {
398
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
399
+ ({module_or_path} = module_or_path)
400
+ } else {
401
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
402
+ }
403
+ }
404
+
405
+ if (module_or_path === undefined) {
406
+ module_or_path = new URL('lfm3_runtime_bg.wasm', import.meta.url);
407
+ }
408
+ const imports = __wbg_get_imports();
409
+
410
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
411
+ module_or_path = fetch(module_or_path);
412
+ }
413
+
414
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
415
+
416
+ return __wbg_finalize_init(instance, module);
417
+ }
418
+
419
+ export { initSync, __wbg_init as default };
engine/dist/lfm3/web-single-relaxed/lfm3_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2dde9afba833aa3c45f7cab26c8ed0792d67aaf6f335901ddddc6904fc660420
3
+ size 3995002
engine/dist/lfm3/web-single/lfm3_runtime.js ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class Runtime {
2
+ __destroy_into_raw() {
3
+ const ptr = this.__wbg_ptr;
4
+ this.__wbg_ptr = 0;
5
+ RuntimeFinalization.unregister(this);
6
+ return ptr;
7
+ }
8
+ free() {
9
+ const ptr = this.__destroy_into_raw();
10
+ wasm.__wbg_runtime_free(ptr, 0);
11
+ }
12
+ cancel() {
13
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
14
+ if (ret[1]) {
15
+ throw takeFromExternrefTable0(ret[0]);
16
+ }
17
+ }
18
+ /**
19
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
20
+ * whether the engine is ready.
21
+ * @param {number} part
22
+ * @returns {boolean}
23
+ */
24
+ end_part(part) {
25
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] !== 0;
30
+ }
31
+ /**
32
+ * @param {string} manifest_json
33
+ */
34
+ constructor(manifest_json) {
35
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ret = wasm.runtime_new(ptr0, len0);
38
+ if (ret[2]) {
39
+ throw takeFromExternrefTable0(ret[1]);
40
+ }
41
+ this.__wbg_ptr = ret[0];
42
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
43
+ return this;
44
+ }
45
+ /**
46
+ * Forgets the conversation, to start a new one.
47
+ */
48
+ reset() {
49
+ const ret = wasm.runtime_reset(this.__wbg_ptr);
50
+ if (ret[1]) {
51
+ throw takeFromExternrefTable0(ret[0]);
52
+ }
53
+ }
54
+ /**
55
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
56
+ * again.
57
+ * @param {number} part
58
+ */
59
+ restart_part(part) {
60
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
61
+ if (ret[1]) {
62
+ throw takeFromExternrefTable0(ret[0]);
63
+ }
64
+ }
65
+ /**
66
+ * The 24 kHz mono samples the reply spoke since the last call.
67
+ * @returns {Float32Array}
68
+ */
69
+ speech() {
70
+ const ret = wasm.runtime_speech(this.__wbg_ptr);
71
+ if (ret[3]) {
72
+ throw takeFromExternrefTable0(ret[2]);
73
+ }
74
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
75
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
76
+ return v1;
77
+ }
78
+ /**
79
+ * Starts replying to `message_json` (`{"text", "system"?, "thinking"?, "mode"?,
80
+ * "max_tokens"?, "sampling"?, "seed"}`, `mode` one of `text`, `transcribe`, `speech` and
81
+ * `interleaved`), the conversation's next turn, with the images whose RGBA pixels `rgba`
82
+ * holds and the 16 kHz mono clips whose samples `audio` holds, as `layout_json` lays them out
83
+ * (`{"images": [[width, height]…], "clips": [samples…]}`); returns its plan (`{"images",
84
+ * "clips", "prompt_tokens", "max_tokens", "sampling"}`).
85
+ * @param {string} message_json
86
+ * @param {Uint8Array} rgba
87
+ * @param {Float32Array} audio
88
+ * @param {string} layout_json
89
+ * @returns {string}
90
+ */
91
+ start(message_json, rgba, audio, layout_json) {
92
+ let deferred6_0;
93
+ let deferred6_1;
94
+ try {
95
+ const ptr0 = passStringToWasm0(message_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
96
+ const len0 = WASM_VECTOR_LEN;
97
+ const ptr1 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc);
98
+ const len1 = WASM_VECTOR_LEN;
99
+ const ptr2 = passArrayF32ToWasm0(audio, wasm.__wbindgen_malloc);
100
+ const len2 = WASM_VECTOR_LEN;
101
+ const ptr3 = passStringToWasm0(layout_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
102
+ const len3 = WASM_VECTOR_LEN;
103
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
104
+ var ptr5 = ret[0];
105
+ var len5 = ret[1];
106
+ if (ret[3]) {
107
+ ptr5 = 0; len5 = 0;
108
+ throw takeFromExternrefTable0(ret[2]);
109
+ }
110
+ deferred6_0 = ptr5;
111
+ deferred6_1 = len5;
112
+ return getStringFromWasm0(ptr5, len5);
113
+ } finally {
114
+ wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
115
+ }
116
+ }
117
+ /**
118
+ * Runs the next stage; returns `{"stage", "reasoning", "answer", "tokens", "frames",
119
+ * "done"}`, the reply so far.
120
+ * @returns {string}
121
+ */
122
+ step() {
123
+ let deferred2_0;
124
+ let deferred2_1;
125
+ try {
126
+ const ret = wasm.runtime_step(this.__wbg_ptr);
127
+ var ptr1 = ret[0];
128
+ var len1 = ret[1];
129
+ if (ret[3]) {
130
+ ptr1 = 0; len1 = 0;
131
+ throw takeFromExternrefTable0(ret[2]);
132
+ }
133
+ deferred2_0 = ptr1;
134
+ deferred2_1 = len1;
135
+ return getStringFromWasm0(ptr1, len1);
136
+ } finally {
137
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
138
+ }
139
+ }
140
+ /**
141
+ * @returns {number}
142
+ */
143
+ threads() {
144
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
145
+ if (ret[2]) {
146
+ throw takeFromExternrefTable0(ret[1]);
147
+ }
148
+ return ret[0] >>> 0;
149
+ }
150
+ /**
151
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
152
+ * @param {number} part
153
+ * @param {Uint8Array} bytes
154
+ */
155
+ write_part(part, bytes) {
156
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
157
+ const len0 = WASM_VECTOR_LEN;
158
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
159
+ if (ret[1]) {
160
+ throw takeFromExternrefTable0(ret[0]);
161
+ }
162
+ }
163
+ }
164
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
165
+
166
+ /**
167
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
168
+ * @returns {string}
169
+ */
170
+ export function last_panic() {
171
+ let deferred1_0;
172
+ let deferred1_1;
173
+ try {
174
+ const ret = wasm.last_panic();
175
+ deferred1_0 = ret[0];
176
+ deferred1_1 = ret[1];
177
+ return getStringFromWasm0(ret[0], ret[1]);
178
+ } finally {
179
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
180
+ }
181
+ }
182
+ function __wbg_get_imports() {
183
+ const import0 = {
184
+ __proto__: null,
185
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
186
+ const ret = Error(getStringFromWasm0(arg0, arg1));
187
+ return ret;
188
+ },
189
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
190
+ throw new Error(getStringFromWasm0(arg0, arg1));
191
+ },
192
+ __wbindgen_init_externref_table: function() {
193
+ const table = wasm.__wbindgen_externrefs;
194
+ const offset = table.grow(4);
195
+ table.set(0, undefined);
196
+ table.set(offset + 0, undefined);
197
+ table.set(offset + 1, null);
198
+ table.set(offset + 2, true);
199
+ table.set(offset + 3, false);
200
+ },
201
+ };
202
+ return {
203
+ __proto__: null,
204
+ "./lfm3_runtime_bg.js": import0,
205
+ };
206
+ }
207
+
208
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
209
+ ? { register: () => {}, unregister: () => {} }
210
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
211
+
212
+ function getArrayF32FromWasm0(ptr, len) {
213
+ ptr = ptr >>> 0;
214
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
215
+ }
216
+
217
+ let cachedFloat32ArrayMemory0 = null;
218
+ function getFloat32ArrayMemory0() {
219
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
220
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
221
+ }
222
+ return cachedFloat32ArrayMemory0;
223
+ }
224
+
225
+ function getStringFromWasm0(ptr, len) {
226
+ return decodeText(ptr >>> 0, len);
227
+ }
228
+
229
+ let cachedUint8ArrayMemory0 = null;
230
+ function getUint8ArrayMemory0() {
231
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
232
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
233
+ }
234
+ return cachedUint8ArrayMemory0;
235
+ }
236
+
237
+ function passArray8ToWasm0(arg, malloc) {
238
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
239
+ getUint8ArrayMemory0().set(arg, ptr / 1);
240
+ WASM_VECTOR_LEN = arg.length;
241
+ return ptr;
242
+ }
243
+
244
+ function passArrayF32ToWasm0(arg, malloc) {
245
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
246
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
247
+ WASM_VECTOR_LEN = arg.length;
248
+ return ptr;
249
+ }
250
+
251
+ function passStringToWasm0(arg, malloc, realloc) {
252
+ if (realloc === undefined) {
253
+ const buf = cachedTextEncoder.encode(arg);
254
+ const ptr = malloc(buf.length, 1) >>> 0;
255
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
256
+ WASM_VECTOR_LEN = buf.length;
257
+ return ptr;
258
+ }
259
+
260
+ let len = arg.length;
261
+ let ptr = malloc(len, 1) >>> 0;
262
+
263
+ const mem = getUint8ArrayMemory0();
264
+
265
+ let offset = 0;
266
+
267
+ for (; offset < len; offset++) {
268
+ const code = arg.charCodeAt(offset);
269
+ if (code > 0x7F) break;
270
+ mem[ptr + offset] = code;
271
+ }
272
+ if (offset !== len) {
273
+ if (offset !== 0) {
274
+ arg = arg.slice(offset);
275
+ }
276
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
277
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
278
+ const ret = cachedTextEncoder.encodeInto(arg, view);
279
+
280
+ offset += ret.written;
281
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
282
+ }
283
+
284
+ WASM_VECTOR_LEN = offset;
285
+ return ptr;
286
+ }
287
+
288
+ function takeFromExternrefTable0(idx) {
289
+ const value = wasm.__wbindgen_externrefs.get(idx);
290
+ wasm.__externref_table_dealloc(idx);
291
+ return value;
292
+ }
293
+
294
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
295
+ cachedTextDecoder.decode();
296
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
297
+ let numBytesDecoded = 0;
298
+ function decodeText(ptr, len) {
299
+ numBytesDecoded += len;
300
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
301
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
302
+ cachedTextDecoder.decode();
303
+ numBytesDecoded = len;
304
+ }
305
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
306
+ }
307
+
308
+ const cachedTextEncoder = new TextEncoder();
309
+
310
+ if (!('encodeInto' in cachedTextEncoder)) {
311
+ cachedTextEncoder.encodeInto = function (arg, view) {
312
+ const buf = cachedTextEncoder.encode(arg);
313
+ view.set(buf);
314
+ return {
315
+ read: arg.length,
316
+ written: buf.length
317
+ };
318
+ };
319
+ }
320
+
321
+ let WASM_VECTOR_LEN = 0;
322
+
323
+ let wasmModule, wasmInstance, wasm;
324
+ function __wbg_finalize_init(instance, module) {
325
+ wasmInstance = instance;
326
+ wasm = instance.exports;
327
+ wasmModule = module;
328
+ cachedFloat32ArrayMemory0 = null;
329
+ cachedUint8ArrayMemory0 = null;
330
+ wasm.__wbindgen_start();
331
+ return wasm;
332
+ }
333
+
334
+ async function __wbg_load(module, imports) {
335
+ if (typeof Response === 'function' && module instanceof Response) {
336
+ if (!module.ok) {
337
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
338
+ }
339
+
340
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
341
+ try {
342
+ return await WebAssembly.instantiateStreaming(module, imports);
343
+ } catch (e) {
344
+ const validResponse = expectedResponseType(module.type);
345
+
346
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
347
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
348
+
349
+ } else { throw e; }
350
+ }
351
+ }
352
+
353
+ const bytes = await module.arrayBuffer();
354
+ return await WebAssembly.instantiate(bytes, imports);
355
+ } else {
356
+ const instance = await WebAssembly.instantiate(module, imports);
357
+
358
+ if (instance instanceof WebAssembly.Instance) {
359
+ return { instance, module };
360
+ } else {
361
+ return instance;
362
+ }
363
+ }
364
+
365
+ function expectedResponseType(type) {
366
+ switch (type) {
367
+ case 'basic': case 'cors': case 'default': return true;
368
+ }
369
+ return false;
370
+ }
371
+ }
372
+
373
+ function initSync(module) {
374
+ if (wasm !== undefined) return wasm;
375
+
376
+
377
+ if (module !== undefined) {
378
+ if (Object.getPrototypeOf(module) === Object.prototype) {
379
+ ({module} = module)
380
+ } else {
381
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
382
+ }
383
+ }
384
+
385
+ const imports = __wbg_get_imports();
386
+ if (!(module instanceof WebAssembly.Module)) {
387
+ module = new WebAssembly.Module(module);
388
+ }
389
+ const instance = new WebAssembly.Instance(module, imports);
390
+ return __wbg_finalize_init(instance, module);
391
+ }
392
+
393
+ async function __wbg_init(module_or_path) {
394
+ if (wasm !== undefined) return wasm;
395
+
396
+
397
+ if (module_or_path !== undefined) {
398
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
399
+ ({module_or_path} = module_or_path)
400
+ } else {
401
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
402
+ }
403
+ }
404
+
405
+ if (module_or_path === undefined) {
406
+ module_or_path = new URL('lfm3_runtime_bg.wasm', import.meta.url);
407
+ }
408
+ const imports = __wbg_get_imports();
409
+
410
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
411
+ module_or_path = fetch(module_or_path);
412
+ }
413
+
414
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
415
+
416
+ return __wbg_finalize_init(instance, module);
417
+ }
418
+
419
+ export { initSync, __wbg_init as default };
engine/dist/lfm3/web-single/lfm3_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:65c7393afb34d1a25b53674f7e23819431da43b68a3e2f9693f296b6b3476b61
3
+ size 3912784
engine/dist/lfm3/web-threaded-relaxed/lfm3_runtime.js ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { startWorkers } from './snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js';
2
+
3
+
4
+ export class Runtime {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ RuntimeFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_runtime_free(ptr, 0);
14
+ }
15
+ cancel() {
16
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
17
+ if (ret[1]) {
18
+ throw takeFromExternrefTable0(ret[0]);
19
+ }
20
+ }
21
+ /**
22
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
23
+ * whether the engine is ready.
24
+ * @param {number} part
25
+ * @returns {boolean}
26
+ */
27
+ end_part(part) {
28
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
29
+ if (ret[2]) {
30
+ throw takeFromExternrefTable0(ret[1]);
31
+ }
32
+ return ret[0] !== 0;
33
+ }
34
+ /**
35
+ * @param {string} manifest_json
36
+ */
37
+ constructor(manifest_json) {
38
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
39
+ const len0 = WASM_VECTOR_LEN;
40
+ const ret = wasm.runtime_new(ptr0, len0);
41
+ if (ret[2]) {
42
+ throw takeFromExternrefTable0(ret[1]);
43
+ }
44
+ this.__wbg_ptr = ret[0];
45
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
46
+ return this;
47
+ }
48
+ /**
49
+ * Forgets the conversation, to start a new one.
50
+ */
51
+ reset() {
52
+ const ret = wasm.runtime_reset(this.__wbg_ptr);
53
+ if (ret[1]) {
54
+ throw takeFromExternrefTable0(ret[0]);
55
+ }
56
+ }
57
+ /**
58
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
59
+ * again.
60
+ * @param {number} part
61
+ */
62
+ restart_part(part) {
63
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
64
+ if (ret[1]) {
65
+ throw takeFromExternrefTable0(ret[0]);
66
+ }
67
+ }
68
+ /**
69
+ * The 24 kHz mono samples the reply spoke since the last call.
70
+ * @returns {Float32Array}
71
+ */
72
+ speech() {
73
+ const ret = wasm.runtime_speech(this.__wbg_ptr);
74
+ if (ret[3]) {
75
+ throw takeFromExternrefTable0(ret[2]);
76
+ }
77
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
78
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
79
+ return v1;
80
+ }
81
+ /**
82
+ * Starts replying to `message_json` (`{"text", "system"?, "thinking"?, "mode"?,
83
+ * "max_tokens"?, "sampling"?, "seed"}`, `mode` one of `text`, `transcribe`, `speech` and
84
+ * `interleaved`), the conversation's next turn, with the images whose RGBA pixels `rgba`
85
+ * holds and the 16 kHz mono clips whose samples `audio` holds, as `layout_json` lays them out
86
+ * (`{"images": [[width, height]…], "clips": [samples…]}`); returns its plan (`{"images",
87
+ * "clips", "prompt_tokens", "max_tokens", "sampling"}`).
88
+ * @param {string} message_json
89
+ * @param {Uint8Array} rgba
90
+ * @param {Float32Array} audio
91
+ * @param {string} layout_json
92
+ * @returns {string}
93
+ */
94
+ start(message_json, rgba, audio, layout_json) {
95
+ let deferred6_0;
96
+ let deferred6_1;
97
+ try {
98
+ const ptr0 = passStringToWasm0(message_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
99
+ const len0 = WASM_VECTOR_LEN;
100
+ const ptr1 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc);
101
+ const len1 = WASM_VECTOR_LEN;
102
+ const ptr2 = passArrayF32ToWasm0(audio, wasm.__wbindgen_malloc);
103
+ const len2 = WASM_VECTOR_LEN;
104
+ const ptr3 = passStringToWasm0(layout_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
105
+ const len3 = WASM_VECTOR_LEN;
106
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
107
+ var ptr5 = ret[0];
108
+ var len5 = ret[1];
109
+ if (ret[3]) {
110
+ ptr5 = 0; len5 = 0;
111
+ throw takeFromExternrefTable0(ret[2]);
112
+ }
113
+ deferred6_0 = ptr5;
114
+ deferred6_1 = len5;
115
+ return getStringFromWasm0(ptr5, len5);
116
+ } finally {
117
+ wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
118
+ }
119
+ }
120
+ /**
121
+ * Runs the next stage; returns `{"stage", "reasoning", "answer", "tokens", "frames",
122
+ * "done"}`, the reply so far.
123
+ * @returns {string}
124
+ */
125
+ step() {
126
+ let deferred2_0;
127
+ let deferred2_1;
128
+ try {
129
+ const ret = wasm.runtime_step(this.__wbg_ptr);
130
+ var ptr1 = ret[0];
131
+ var len1 = ret[1];
132
+ if (ret[3]) {
133
+ ptr1 = 0; len1 = 0;
134
+ throw takeFromExternrefTable0(ret[2]);
135
+ }
136
+ deferred2_0 = ptr1;
137
+ deferred2_1 = len1;
138
+ return getStringFromWasm0(ptr1, len1);
139
+ } finally {
140
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
141
+ }
142
+ }
143
+ /**
144
+ * @returns {number}
145
+ */
146
+ threads() {
147
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
148
+ if (ret[2]) {
149
+ throw takeFromExternrefTable0(ret[1]);
150
+ }
151
+ return ret[0] >>> 0;
152
+ }
153
+ /**
154
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
155
+ * @param {number} part
156
+ * @param {Uint8Array} bytes
157
+ */
158
+ write_part(part, bytes) {
159
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
160
+ const len0 = WASM_VECTOR_LEN;
161
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
162
+ if (ret[1]) {
163
+ throw takeFromExternrefTable0(ret[0]);
164
+ }
165
+ }
166
+ }
167
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
168
+
169
+ /**
170
+ * @param {number} num_threads
171
+ * @returns {Promise<any>}
172
+ */
173
+ export function initThreadPool(num_threads) {
174
+ const ret = wasm.initThreadPool(num_threads);
175
+ return ret;
176
+ }
177
+
178
+ /**
179
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
180
+ * @returns {string}
181
+ */
182
+ export function last_panic() {
183
+ let deferred1_0;
184
+ let deferred1_1;
185
+ try {
186
+ const ret = wasm.last_panic();
187
+ deferred1_0 = ret[0];
188
+ deferred1_1 = ret[1];
189
+ return getStringFromWasm0(ret[0], ret[1]);
190
+ } finally {
191
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
192
+ }
193
+ }
194
+
195
+ export class wbg_rayon_PoolBuilder {
196
+ static __wrap(ptr) {
197
+ const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
198
+ obj.__wbg_ptr = ptr;
199
+ wbg_rayon_PoolBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
200
+ return obj;
201
+ }
202
+ __destroy_into_raw() {
203
+ const ptr = this.__wbg_ptr;
204
+ this.__wbg_ptr = 0;
205
+ wbg_rayon_PoolBuilderFinalization.unregister(this);
206
+ return ptr;
207
+ }
208
+ free() {
209
+ const ptr = this.__destroy_into_raw();
210
+ wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 0);
211
+ }
212
+ build() {
213
+ wasm.wbg_rayon_poolbuilder_build(this.__wbg_ptr);
214
+ }
215
+ /**
216
+ * @returns {string}
217
+ */
218
+ mainJS() {
219
+ const ret = wasm.wbg_rayon_poolbuilder_mainJS(this.__wbg_ptr);
220
+ return ret;
221
+ }
222
+ /**
223
+ * @returns {number}
224
+ */
225
+ numThreads() {
226
+ const ret = wasm.wbg_rayon_poolbuilder_numThreads(this.__wbg_ptr);
227
+ return ret >>> 0;
228
+ }
229
+ /**
230
+ * @returns {number}
231
+ */
232
+ receiver() {
233
+ const ret = wasm.wbg_rayon_poolbuilder_receiver(this.__wbg_ptr);
234
+ return ret >>> 0;
235
+ }
236
+ }
237
+ if (Symbol.dispose) wbg_rayon_PoolBuilder.prototype[Symbol.dispose] = wbg_rayon_PoolBuilder.prototype.free;
238
+
239
+ /**
240
+ * @param {number} receiver
241
+ */
242
+ export function wbg_rayon_start_worker(receiver) {
243
+ wasm.wbg_rayon_start_worker(receiver);
244
+ }
245
+ function __wbg_get_imports(memory) {
246
+ const import0 = {
247
+ __proto__: null,
248
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
249
+ const ret = Error(getStringFromWasm0(arg0, arg1));
250
+ return ret;
251
+ },
252
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
253
+ const ret = arg0 === undefined;
254
+ return ret;
255
+ },
256
+ __wbg___wbindgen_memory_caa4a6165639c8b5: function() {
257
+ const ret = wasm.memory;
258
+ return ret;
259
+ },
260
+ __wbg___wbindgen_module_7115fb14045f9891: function() {
261
+ const ret = wasmModule;
262
+ return ret;
263
+ },
264
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
265
+ throw new Error(getStringFromWasm0(arg0, arg1));
266
+ },
267
+ __wbg_instanceof_Window_82d71df4eddf88bc: function(arg0) {
268
+ let result;
269
+ try {
270
+ result = arg0 instanceof Window;
271
+ } catch (_) {
272
+ result = false;
273
+ }
274
+ const ret = result;
275
+ return ret;
276
+ },
277
+ __wbg_startWorkers_622cedd0d351664e: function(arg0, arg1, arg2) {
278
+ const ret = startWorkers(arg0, arg1, wbg_rayon_PoolBuilder.__wrap(arg2));
279
+ return ret;
280
+ },
281
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
282
+ const ret = typeof global === 'undefined' ? null : global;
283
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
284
+ },
285
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
286
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
287
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
288
+ },
289
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
290
+ const ret = typeof self === 'undefined' ? null : self;
291
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
292
+ },
293
+ __wbg_static_accessor_URL_fac851ed3060f4eb: function() {
294
+ const ret = import.meta.url;
295
+ return ret;
296
+ },
297
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
298
+ const ret = typeof window === 'undefined' ? null : window;
299
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
300
+ },
301
+ __wbindgen_init_externref_table: function() {
302
+ const table = wasm.__wbindgen_externrefs;
303
+ const offset = table.grow(4);
304
+ table.set(0, undefined);
305
+ table.set(offset + 0, undefined);
306
+ table.set(offset + 1, null);
307
+ table.set(offset + 2, true);
308
+ table.set(offset + 3, false);
309
+ },
310
+ memory: memory || new WebAssembly.Memory({initial:27,maximum:65536,shared:true}),
311
+ };
312
+ return {
313
+ __proto__: null,
314
+ "./lfm3_runtime_bg.js": import0,
315
+ };
316
+ }
317
+
318
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
319
+ ? { register: () => {}, unregister: () => {} }
320
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
321
+ const wbg_rayon_PoolBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
322
+ ? { register: () => {}, unregister: () => {} }
323
+ : new FinalizationRegistry(ptr => wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 1));
324
+
325
+ function addToExternrefTable0(obj) {
326
+ const idx = wasm.__externref_table_alloc();
327
+ wasm.__wbindgen_externrefs.set(idx, obj);
328
+ return idx;
329
+ }
330
+
331
+ function getArrayF32FromWasm0(ptr, len) {
332
+ ptr = ptr >>> 0;
333
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
334
+ }
335
+
336
+ let cachedFloat32ArrayMemory0 = null;
337
+ function getFloat32ArrayMemory0() {
338
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.buffer !== wasm.memory.buffer) {
339
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
340
+ }
341
+ return cachedFloat32ArrayMemory0;
342
+ }
343
+
344
+ function getStringFromWasm0(ptr, len) {
345
+ return decodeText(ptr >>> 0, len);
346
+ }
347
+
348
+ let cachedUint8ArrayMemory0 = null;
349
+ function getUint8ArrayMemory0() {
350
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
351
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
352
+ }
353
+ return cachedUint8ArrayMemory0;
354
+ }
355
+
356
+ function isLikeNone(x) {
357
+ return x === undefined || x === null;
358
+ }
359
+
360
+ function passArray8ToWasm0(arg, malloc) {
361
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
362
+ getUint8ArrayMemory0().set(arg, ptr / 1);
363
+ WASM_VECTOR_LEN = arg.length;
364
+ return ptr;
365
+ }
366
+
367
+ function passArrayF32ToWasm0(arg, malloc) {
368
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
369
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
370
+ WASM_VECTOR_LEN = arg.length;
371
+ return ptr;
372
+ }
373
+
374
+ function passStringToWasm0(arg, malloc, realloc) {
375
+ if (realloc === undefined) {
376
+ const buf = cachedTextEncoder.encode(arg);
377
+ const ptr = malloc(buf.length, 1) >>> 0;
378
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
379
+ WASM_VECTOR_LEN = buf.length;
380
+ return ptr;
381
+ }
382
+
383
+ let len = arg.length;
384
+ let ptr = malloc(len, 1) >>> 0;
385
+
386
+ const mem = getUint8ArrayMemory0();
387
+
388
+ let offset = 0;
389
+
390
+ for (; offset < len; offset++) {
391
+ const code = arg.charCodeAt(offset);
392
+ if (code > 0x7F) break;
393
+ mem[ptr + offset] = code;
394
+ }
395
+ if (offset !== len) {
396
+ if (offset !== 0) {
397
+ arg = arg.slice(offset);
398
+ }
399
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
400
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
401
+ const ret = cachedTextEncoder.encodeInto(arg, view);
402
+
403
+ offset += ret.written;
404
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
405
+ }
406
+
407
+ WASM_VECTOR_LEN = offset;
408
+ return ptr;
409
+ }
410
+
411
+ function takeFromExternrefTable0(idx) {
412
+ const value = wasm.__wbindgen_externrefs.get(idx);
413
+ wasm.__externref_table_dealloc(idx);
414
+ return value;
415
+ }
416
+
417
+ let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : undefined);
418
+ if (cachedTextDecoder) cachedTextDecoder.decode();
419
+
420
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
421
+ let numBytesDecoded = 0;
422
+ function decodeText(ptr, len) {
423
+ numBytesDecoded += len;
424
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
425
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
426
+ cachedTextDecoder.decode();
427
+ numBytesDecoded = len;
428
+ }
429
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));
430
+ }
431
+
432
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined);
433
+
434
+ if (cachedTextEncoder) {
435
+ cachedTextEncoder.encodeInto = function (arg, view) {
436
+ const buf = cachedTextEncoder.encode(arg);
437
+ view.set(buf);
438
+ return {
439
+ read: arg.length,
440
+ written: buf.length
441
+ };
442
+ };
443
+ }
444
+
445
+ let WASM_VECTOR_LEN = 0;
446
+
447
+ let wasmModule, wasmInstance, wasm;
448
+ function __wbg_finalize_init(instance, module, thread_stack_size) {
449
+ wasmInstance = instance;
450
+ wasm = instance.exports;
451
+ wasmModule = module;
452
+ cachedFloat32ArrayMemory0 = null;
453
+ cachedUint8ArrayMemory0 = null;
454
+ if (typeof thread_stack_size !== 'undefined' && (typeof thread_stack_size !== 'number' || thread_stack_size === 0 || thread_stack_size % 65536 !== 0)) {
455
+ throw new Error('invalid stack size');
456
+ }
457
+
458
+ wasm.__wbindgen_start(thread_stack_size);
459
+ return wasm;
460
+ }
461
+
462
+ async function __wbg_load(module, imports) {
463
+ if (typeof Response === 'function' && module instanceof Response) {
464
+ if (!module.ok) {
465
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
466
+ }
467
+
468
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
469
+ try {
470
+ return await WebAssembly.instantiateStreaming(module, imports);
471
+ } catch (e) {
472
+ const validResponse = expectedResponseType(module.type);
473
+
474
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
475
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
476
+
477
+ } else { throw e; }
478
+ }
479
+ }
480
+
481
+ const bytes = await module.arrayBuffer();
482
+ return await WebAssembly.instantiate(bytes, imports);
483
+ } else {
484
+ const instance = await WebAssembly.instantiate(module, imports);
485
+
486
+ if (instance instanceof WebAssembly.Instance) {
487
+ return { instance, module };
488
+ } else {
489
+ return instance;
490
+ }
491
+ }
492
+
493
+ function expectedResponseType(type) {
494
+ switch (type) {
495
+ case 'basic': case 'cors': case 'default': return true;
496
+ }
497
+ return false;
498
+ }
499
+ }
500
+
501
+ function initSync(module, memory) {
502
+ if (wasm !== undefined) return wasm;
503
+
504
+ let thread_stack_size
505
+ if (module !== undefined) {
506
+ if (Object.getPrototypeOf(module) === Object.prototype) {
507
+ ({module, memory, thread_stack_size} = module)
508
+ } else {
509
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
510
+ }
511
+ }
512
+
513
+ const imports = __wbg_get_imports(memory);
514
+ if (!(module instanceof WebAssembly.Module)) {
515
+ module = new WebAssembly.Module(module);
516
+ }
517
+ const instance = new WebAssembly.Instance(module, imports);
518
+ return __wbg_finalize_init(instance, module, thread_stack_size);
519
+ }
520
+
521
+ async function __wbg_init(module_or_path, memory) {
522
+ if (wasm !== undefined) return wasm;
523
+
524
+ let thread_stack_size
525
+ if (module_or_path !== undefined) {
526
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
527
+ ({module_or_path, memory, thread_stack_size} = module_or_path)
528
+ } else {
529
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
530
+ }
531
+ }
532
+
533
+ if (module_or_path === undefined) {
534
+ module_or_path = new URL('lfm3_runtime_bg.wasm', import.meta.url);
535
+ }
536
+ const imports = __wbg_get_imports(memory);
537
+
538
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
539
+ module_or_path = fetch(module_or_path);
540
+ }
541
+
542
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
543
+
544
+ return __wbg_finalize_init(instance, module, thread_stack_size);
545
+ }
546
+
547
+ export { initSync, __wbg_init as default };
engine/dist/lfm3/web-threaded-relaxed/lfm3_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f7bb303ec55627f311565519646568a21ba33bf18e233c1a43fb659db4d75d6
3
+ size 4023378
engine/dist/lfm3/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ // The messages between a threaded runtime's thread host (thread-host.js, in the engine worker
2
+ // and in each compute worker) and the page's compute pool (compute.js). `build-runtime.sh` copies
3
+ // this file next to the thread host.
4
+
5
+ export const SPAWN_COMPUTE = 'fusor-ai-spawn-compute';
6
+ export const RAYON_INIT = 'fusor-ai-rayon-init';
7
+ export const RAYON_READY = 'fusor-ai-rayon-ready';
8
+ export const RAYON_ERROR = 'fusor-ai-rayon-error';
engine/dist/lfm3/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The thread host for wasm-bindgen-rayon 1.3.0. `scripts/build-runtime.sh` copies it over the
2
+ // adapter's `workerHelpers.no-bundler.js`, keeping the adapter's public PoolBuilder ABI (the same
3
+ // approach as fusor's worker host, crates/fusor-cli/src/pipeline/workers/rayon.js in the fusor
4
+ // repository).
5
+ //
6
+ // Two differences from the stock adapter:
7
+ // - it fetches nothing (the stock one re-downloads itself to make a blob URL);
8
+ // - the page, not the runtime's worker, creates every compute worker, so the page can always
9
+ // terminate the whole pool, and a blocked coordinator cannot leak threads.
10
+ //
11
+ // As a compute worker: wait for an init message, instantiate the same verified module on the
12
+ // shared memory, then run Rayon's worker loop. As a module imported by the runtime glue:
13
+ // export `startWorkers`, which asks the page for workers and waits until they are all ready.
14
+
15
+ import { RAYON_ERROR, RAYON_INIT, RAYON_READY, SPAWN_COMPUTE } from './protocol.js';
16
+
17
+ self.addEventListener('message', ({ data }) => {
18
+ if (data?.type !== RAYON_INIT) return;
19
+ initialize(data).catch((error) => {
20
+ postMessage({ type: RAYON_ERROR, message: String(error) });
21
+ self.close();
22
+ });
23
+ });
24
+
25
+ async function initialize(data) {
26
+ const pkg = await import(data.mainJS);
27
+ pkg.initSync({ module: data.module, memory: data.memory });
28
+ postMessage({ type: RAYON_READY });
29
+ pkg.wbg_rayon_start_worker(data.receiver);
30
+ }
31
+
32
+ export async function startWorkers(module, memory, builder) {
33
+ const count = builder.numThreads();
34
+ if (count === 0) throw new Error('num_threads must be > 0');
35
+ const channel = new MessageChannel();
36
+ try {
37
+ await new Promise((resolve, reject) => {
38
+ channel.port1.onmessage = ({ data }) => (data.ready ? resolve() : reject(new Error(data.error)));
39
+ const spawn = {
40
+ type: SPAWN_COMPUTE,
41
+ url: import.meta.url,
42
+ count,
43
+ module,
44
+ memory,
45
+ receiver: builder.receiver(),
46
+ mainJS: builder.mainJS(),
47
+ port: channel.port2,
48
+ };
49
+ postMessage(spawn, [channel.port2]);
50
+ });
51
+ builder.build();
52
+ } finally {
53
+ channel.port1.close();
54
+ }
55
+ }
engine/dist/lfm3/web-threaded/lfm3_runtime.js ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { startWorkers } from './snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js';
2
+
3
+
4
+ export class Runtime {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ RuntimeFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_runtime_free(ptr, 0);
14
+ }
15
+ cancel() {
16
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
17
+ if (ret[1]) {
18
+ throw takeFromExternrefTable0(ret[0]);
19
+ }
20
+ }
21
+ /**
22
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
23
+ * whether the engine is ready.
24
+ * @param {number} part
25
+ * @returns {boolean}
26
+ */
27
+ end_part(part) {
28
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
29
+ if (ret[2]) {
30
+ throw takeFromExternrefTable0(ret[1]);
31
+ }
32
+ return ret[0] !== 0;
33
+ }
34
+ /**
35
+ * @param {string} manifest_json
36
+ */
37
+ constructor(manifest_json) {
38
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
39
+ const len0 = WASM_VECTOR_LEN;
40
+ const ret = wasm.runtime_new(ptr0, len0);
41
+ if (ret[2]) {
42
+ throw takeFromExternrefTable0(ret[1]);
43
+ }
44
+ this.__wbg_ptr = ret[0];
45
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
46
+ return this;
47
+ }
48
+ /**
49
+ * Forgets the conversation, to start a new one.
50
+ */
51
+ reset() {
52
+ const ret = wasm.runtime_reset(this.__wbg_ptr);
53
+ if (ret[1]) {
54
+ throw takeFromExternrefTable0(ret[0]);
55
+ }
56
+ }
57
+ /**
58
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
59
+ * again.
60
+ * @param {number} part
61
+ */
62
+ restart_part(part) {
63
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
64
+ if (ret[1]) {
65
+ throw takeFromExternrefTable0(ret[0]);
66
+ }
67
+ }
68
+ /**
69
+ * The 24 kHz mono samples the reply spoke since the last call.
70
+ * @returns {Float32Array}
71
+ */
72
+ speech() {
73
+ const ret = wasm.runtime_speech(this.__wbg_ptr);
74
+ if (ret[3]) {
75
+ throw takeFromExternrefTable0(ret[2]);
76
+ }
77
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
78
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
79
+ return v1;
80
+ }
81
+ /**
82
+ * Starts replying to `message_json` (`{"text", "system"?, "thinking"?, "mode"?,
83
+ * "max_tokens"?, "sampling"?, "seed"}`, `mode` one of `text`, `transcribe`, `speech` and
84
+ * `interleaved`), the conversation's next turn, with the images whose RGBA pixels `rgba`
85
+ * holds and the 16 kHz mono clips whose samples `audio` holds, as `layout_json` lays them out
86
+ * (`{"images": [[width, height]…], "clips": [samples…]}`); returns its plan (`{"images",
87
+ * "clips", "prompt_tokens", "max_tokens", "sampling"}`).
88
+ * @param {string} message_json
89
+ * @param {Uint8Array} rgba
90
+ * @param {Float32Array} audio
91
+ * @param {string} layout_json
92
+ * @returns {string}
93
+ */
94
+ start(message_json, rgba, audio, layout_json) {
95
+ let deferred6_0;
96
+ let deferred6_1;
97
+ try {
98
+ const ptr0 = passStringToWasm0(message_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
99
+ const len0 = WASM_VECTOR_LEN;
100
+ const ptr1 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc);
101
+ const len1 = WASM_VECTOR_LEN;
102
+ const ptr2 = passArrayF32ToWasm0(audio, wasm.__wbindgen_malloc);
103
+ const len2 = WASM_VECTOR_LEN;
104
+ const ptr3 = passStringToWasm0(layout_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
105
+ const len3 = WASM_VECTOR_LEN;
106
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
107
+ var ptr5 = ret[0];
108
+ var len5 = ret[1];
109
+ if (ret[3]) {
110
+ ptr5 = 0; len5 = 0;
111
+ throw takeFromExternrefTable0(ret[2]);
112
+ }
113
+ deferred6_0 = ptr5;
114
+ deferred6_1 = len5;
115
+ return getStringFromWasm0(ptr5, len5);
116
+ } finally {
117
+ wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
118
+ }
119
+ }
120
+ /**
121
+ * Runs the next stage; returns `{"stage", "reasoning", "answer", "tokens", "frames",
122
+ * "done"}`, the reply so far.
123
+ * @returns {string}
124
+ */
125
+ step() {
126
+ let deferred2_0;
127
+ let deferred2_1;
128
+ try {
129
+ const ret = wasm.runtime_step(this.__wbg_ptr);
130
+ var ptr1 = ret[0];
131
+ var len1 = ret[1];
132
+ if (ret[3]) {
133
+ ptr1 = 0; len1 = 0;
134
+ throw takeFromExternrefTable0(ret[2]);
135
+ }
136
+ deferred2_0 = ptr1;
137
+ deferred2_1 = len1;
138
+ return getStringFromWasm0(ptr1, len1);
139
+ } finally {
140
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
141
+ }
142
+ }
143
+ /**
144
+ * @returns {number}
145
+ */
146
+ threads() {
147
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
148
+ if (ret[2]) {
149
+ throw takeFromExternrefTable0(ret[1]);
150
+ }
151
+ return ret[0] >>> 0;
152
+ }
153
+ /**
154
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
155
+ * @param {number} part
156
+ * @param {Uint8Array} bytes
157
+ */
158
+ write_part(part, bytes) {
159
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
160
+ const len0 = WASM_VECTOR_LEN;
161
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
162
+ if (ret[1]) {
163
+ throw takeFromExternrefTable0(ret[0]);
164
+ }
165
+ }
166
+ }
167
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
168
+
169
+ /**
170
+ * @param {number} num_threads
171
+ * @returns {Promise<any>}
172
+ */
173
+ export function initThreadPool(num_threads) {
174
+ const ret = wasm.initThreadPool(num_threads);
175
+ return ret;
176
+ }
177
+
178
+ /**
179
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
180
+ * @returns {string}
181
+ */
182
+ export function last_panic() {
183
+ let deferred1_0;
184
+ let deferred1_1;
185
+ try {
186
+ const ret = wasm.last_panic();
187
+ deferred1_0 = ret[0];
188
+ deferred1_1 = ret[1];
189
+ return getStringFromWasm0(ret[0], ret[1]);
190
+ } finally {
191
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
192
+ }
193
+ }
194
+
195
+ export class wbg_rayon_PoolBuilder {
196
+ static __wrap(ptr) {
197
+ const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
198
+ obj.__wbg_ptr = ptr;
199
+ wbg_rayon_PoolBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
200
+ return obj;
201
+ }
202
+ __destroy_into_raw() {
203
+ const ptr = this.__wbg_ptr;
204
+ this.__wbg_ptr = 0;
205
+ wbg_rayon_PoolBuilderFinalization.unregister(this);
206
+ return ptr;
207
+ }
208
+ free() {
209
+ const ptr = this.__destroy_into_raw();
210
+ wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 0);
211
+ }
212
+ build() {
213
+ wasm.wbg_rayon_poolbuilder_build(this.__wbg_ptr);
214
+ }
215
+ /**
216
+ * @returns {string}
217
+ */
218
+ mainJS() {
219
+ const ret = wasm.wbg_rayon_poolbuilder_mainJS(this.__wbg_ptr);
220
+ return ret;
221
+ }
222
+ /**
223
+ * @returns {number}
224
+ */
225
+ numThreads() {
226
+ const ret = wasm.wbg_rayon_poolbuilder_numThreads(this.__wbg_ptr);
227
+ return ret >>> 0;
228
+ }
229
+ /**
230
+ * @returns {number}
231
+ */
232
+ receiver() {
233
+ const ret = wasm.wbg_rayon_poolbuilder_receiver(this.__wbg_ptr);
234
+ return ret >>> 0;
235
+ }
236
+ }
237
+ if (Symbol.dispose) wbg_rayon_PoolBuilder.prototype[Symbol.dispose] = wbg_rayon_PoolBuilder.prototype.free;
238
+
239
+ /**
240
+ * @param {number} receiver
241
+ */
242
+ export function wbg_rayon_start_worker(receiver) {
243
+ wasm.wbg_rayon_start_worker(receiver);
244
+ }
245
+ function __wbg_get_imports(memory) {
246
+ const import0 = {
247
+ __proto__: null,
248
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
249
+ const ret = Error(getStringFromWasm0(arg0, arg1));
250
+ return ret;
251
+ },
252
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
253
+ const ret = arg0 === undefined;
254
+ return ret;
255
+ },
256
+ __wbg___wbindgen_memory_caa4a6165639c8b5: function() {
257
+ const ret = wasm.memory;
258
+ return ret;
259
+ },
260
+ __wbg___wbindgen_module_7115fb14045f9891: function() {
261
+ const ret = wasmModule;
262
+ return ret;
263
+ },
264
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
265
+ throw new Error(getStringFromWasm0(arg0, arg1));
266
+ },
267
+ __wbg_instanceof_Window_82d71df4eddf88bc: function(arg0) {
268
+ let result;
269
+ try {
270
+ result = arg0 instanceof Window;
271
+ } catch (_) {
272
+ result = false;
273
+ }
274
+ const ret = result;
275
+ return ret;
276
+ },
277
+ __wbg_startWorkers_622cedd0d351664e: function(arg0, arg1, arg2) {
278
+ const ret = startWorkers(arg0, arg1, wbg_rayon_PoolBuilder.__wrap(arg2));
279
+ return ret;
280
+ },
281
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
282
+ const ret = typeof global === 'undefined' ? null : global;
283
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
284
+ },
285
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
286
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
287
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
288
+ },
289
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
290
+ const ret = typeof self === 'undefined' ? null : self;
291
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
292
+ },
293
+ __wbg_static_accessor_URL_fac851ed3060f4eb: function() {
294
+ const ret = import.meta.url;
295
+ return ret;
296
+ },
297
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
298
+ const ret = typeof window === 'undefined' ? null : window;
299
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
300
+ },
301
+ __wbindgen_init_externref_table: function() {
302
+ const table = wasm.__wbindgen_externrefs;
303
+ const offset = table.grow(4);
304
+ table.set(0, undefined);
305
+ table.set(offset + 0, undefined);
306
+ table.set(offset + 1, null);
307
+ table.set(offset + 2, true);
308
+ table.set(offset + 3, false);
309
+ },
310
+ memory: memory || new WebAssembly.Memory({initial:27,maximum:65536,shared:true}),
311
+ };
312
+ return {
313
+ __proto__: null,
314
+ "./lfm3_runtime_bg.js": import0,
315
+ };
316
+ }
317
+
318
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
319
+ ? { register: () => {}, unregister: () => {} }
320
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
321
+ const wbg_rayon_PoolBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
322
+ ? { register: () => {}, unregister: () => {} }
323
+ : new FinalizationRegistry(ptr => wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 1));
324
+
325
+ function addToExternrefTable0(obj) {
326
+ const idx = wasm.__externref_table_alloc();
327
+ wasm.__wbindgen_externrefs.set(idx, obj);
328
+ return idx;
329
+ }
330
+
331
+ function getArrayF32FromWasm0(ptr, len) {
332
+ ptr = ptr >>> 0;
333
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
334
+ }
335
+
336
+ let cachedFloat32ArrayMemory0 = null;
337
+ function getFloat32ArrayMemory0() {
338
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.buffer !== wasm.memory.buffer) {
339
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
340
+ }
341
+ return cachedFloat32ArrayMemory0;
342
+ }
343
+
344
+ function getStringFromWasm0(ptr, len) {
345
+ return decodeText(ptr >>> 0, len);
346
+ }
347
+
348
+ let cachedUint8ArrayMemory0 = null;
349
+ function getUint8ArrayMemory0() {
350
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
351
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
352
+ }
353
+ return cachedUint8ArrayMemory0;
354
+ }
355
+
356
+ function isLikeNone(x) {
357
+ return x === undefined || x === null;
358
+ }
359
+
360
+ function passArray8ToWasm0(arg, malloc) {
361
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
362
+ getUint8ArrayMemory0().set(arg, ptr / 1);
363
+ WASM_VECTOR_LEN = arg.length;
364
+ return ptr;
365
+ }
366
+
367
+ function passArrayF32ToWasm0(arg, malloc) {
368
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
369
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
370
+ WASM_VECTOR_LEN = arg.length;
371
+ return ptr;
372
+ }
373
+
374
+ function passStringToWasm0(arg, malloc, realloc) {
375
+ if (realloc === undefined) {
376
+ const buf = cachedTextEncoder.encode(arg);
377
+ const ptr = malloc(buf.length, 1) >>> 0;
378
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
379
+ WASM_VECTOR_LEN = buf.length;
380
+ return ptr;
381
+ }
382
+
383
+ let len = arg.length;
384
+ let ptr = malloc(len, 1) >>> 0;
385
+
386
+ const mem = getUint8ArrayMemory0();
387
+
388
+ let offset = 0;
389
+
390
+ for (; offset < len; offset++) {
391
+ const code = arg.charCodeAt(offset);
392
+ if (code > 0x7F) break;
393
+ mem[ptr + offset] = code;
394
+ }
395
+ if (offset !== len) {
396
+ if (offset !== 0) {
397
+ arg = arg.slice(offset);
398
+ }
399
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
400
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
401
+ const ret = cachedTextEncoder.encodeInto(arg, view);
402
+
403
+ offset += ret.written;
404
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
405
+ }
406
+
407
+ WASM_VECTOR_LEN = offset;
408
+ return ptr;
409
+ }
410
+
411
+ function takeFromExternrefTable0(idx) {
412
+ const value = wasm.__wbindgen_externrefs.get(idx);
413
+ wasm.__externref_table_dealloc(idx);
414
+ return value;
415
+ }
416
+
417
+ let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : undefined);
418
+ if (cachedTextDecoder) cachedTextDecoder.decode();
419
+
420
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
421
+ let numBytesDecoded = 0;
422
+ function decodeText(ptr, len) {
423
+ numBytesDecoded += len;
424
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
425
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
426
+ cachedTextDecoder.decode();
427
+ numBytesDecoded = len;
428
+ }
429
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));
430
+ }
431
+
432
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined);
433
+
434
+ if (cachedTextEncoder) {
435
+ cachedTextEncoder.encodeInto = function (arg, view) {
436
+ const buf = cachedTextEncoder.encode(arg);
437
+ view.set(buf);
438
+ return {
439
+ read: arg.length,
440
+ written: buf.length
441
+ };
442
+ };
443
+ }
444
+
445
+ let WASM_VECTOR_LEN = 0;
446
+
447
+ let wasmModule, wasmInstance, wasm;
448
+ function __wbg_finalize_init(instance, module, thread_stack_size) {
449
+ wasmInstance = instance;
450
+ wasm = instance.exports;
451
+ wasmModule = module;
452
+ cachedFloat32ArrayMemory0 = null;
453
+ cachedUint8ArrayMemory0 = null;
454
+ if (typeof thread_stack_size !== 'undefined' && (typeof thread_stack_size !== 'number' || thread_stack_size === 0 || thread_stack_size % 65536 !== 0)) {
455
+ throw new Error('invalid stack size');
456
+ }
457
+
458
+ wasm.__wbindgen_start(thread_stack_size);
459
+ return wasm;
460
+ }
461
+
462
+ async function __wbg_load(module, imports) {
463
+ if (typeof Response === 'function' && module instanceof Response) {
464
+ if (!module.ok) {
465
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
466
+ }
467
+
468
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
469
+ try {
470
+ return await WebAssembly.instantiateStreaming(module, imports);
471
+ } catch (e) {
472
+ const validResponse = expectedResponseType(module.type);
473
+
474
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
475
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
476
+
477
+ } else { throw e; }
478
+ }
479
+ }
480
+
481
+ const bytes = await module.arrayBuffer();
482
+ return await WebAssembly.instantiate(bytes, imports);
483
+ } else {
484
+ const instance = await WebAssembly.instantiate(module, imports);
485
+
486
+ if (instance instanceof WebAssembly.Instance) {
487
+ return { instance, module };
488
+ } else {
489
+ return instance;
490
+ }
491
+ }
492
+
493
+ function expectedResponseType(type) {
494
+ switch (type) {
495
+ case 'basic': case 'cors': case 'default': return true;
496
+ }
497
+ return false;
498
+ }
499
+ }
500
+
501
+ function initSync(module, memory) {
502
+ if (wasm !== undefined) return wasm;
503
+
504
+ let thread_stack_size
505
+ if (module !== undefined) {
506
+ if (Object.getPrototypeOf(module) === Object.prototype) {
507
+ ({module, memory, thread_stack_size} = module)
508
+ } else {
509
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
510
+ }
511
+ }
512
+
513
+ const imports = __wbg_get_imports(memory);
514
+ if (!(module instanceof WebAssembly.Module)) {
515
+ module = new WebAssembly.Module(module);
516
+ }
517
+ const instance = new WebAssembly.Instance(module, imports);
518
+ return __wbg_finalize_init(instance, module, thread_stack_size);
519
+ }
520
+
521
+ async function __wbg_init(module_or_path, memory) {
522
+ if (wasm !== undefined) return wasm;
523
+
524
+ let thread_stack_size
525
+ if (module_or_path !== undefined) {
526
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
527
+ ({module_or_path, memory, thread_stack_size} = module_or_path)
528
+ } else {
529
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
530
+ }
531
+ }
532
+
533
+ if (module_or_path === undefined) {
534
+ module_or_path = new URL('lfm3_runtime_bg.wasm', import.meta.url);
535
+ }
536
+ const imports = __wbg_get_imports(memory);
537
+
538
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
539
+ module_or_path = fetch(module_or_path);
540
+ }
541
+
542
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
543
+
544
+ return __wbg_finalize_init(instance, module, thread_stack_size);
545
+ }
546
+
547
+ export { initSync, __wbg_init as default };
engine/dist/lfm3/web-threaded/lfm3_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca866507018758ea6c932304765a9b5607e6ded49d8dc1dfbe6b6c47242481f1
3
+ size 3939332
engine/dist/lfm3/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ // The messages between a threaded runtime's thread host (thread-host.js, in the engine worker
2
+ // and in each compute worker) and the page's compute pool (compute.js). `build-runtime.sh` copies
3
+ // this file next to the thread host.
4
+
5
+ export const SPAWN_COMPUTE = 'fusor-ai-spawn-compute';
6
+ export const RAYON_INIT = 'fusor-ai-rayon-init';
7
+ export const RAYON_READY = 'fusor-ai-rayon-ready';
8
+ export const RAYON_ERROR = 'fusor-ai-rayon-error';
engine/dist/lfm3/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The thread host for wasm-bindgen-rayon 1.3.0. `scripts/build-runtime.sh` copies it over the
2
+ // adapter's `workerHelpers.no-bundler.js`, keeping the adapter's public PoolBuilder ABI (the same
3
+ // approach as fusor's worker host, crates/fusor-cli/src/pipeline/workers/rayon.js in the fusor
4
+ // repository).
5
+ //
6
+ // Two differences from the stock adapter:
7
+ // - it fetches nothing (the stock one re-downloads itself to make a blob URL);
8
+ // - the page, not the runtime's worker, creates every compute worker, so the page can always
9
+ // terminate the whole pool, and a blocked coordinator cannot leak threads.
10
+ //
11
+ // As a compute worker: wait for an init message, instantiate the same verified module on the
12
+ // shared memory, then run Rayon's worker loop. As a module imported by the runtime glue:
13
+ // export `startWorkers`, which asks the page for workers and waits until they are all ready.
14
+
15
+ import { RAYON_ERROR, RAYON_INIT, RAYON_READY, SPAWN_COMPUTE } from './protocol.js';
16
+
17
+ self.addEventListener('message', ({ data }) => {
18
+ if (data?.type !== RAYON_INIT) return;
19
+ initialize(data).catch((error) => {
20
+ postMessage({ type: RAYON_ERROR, message: String(error) });
21
+ self.close();
22
+ });
23
+ });
24
+
25
+ async function initialize(data) {
26
+ const pkg = await import(data.mainJS);
27
+ pkg.initSync({ module: data.module, memory: data.memory });
28
+ postMessage({ type: RAYON_READY });
29
+ pkg.wbg_rayon_start_worker(data.receiver);
30
+ }
31
+
32
+ export async function startWorkers(module, memory, builder) {
33
+ const count = builder.numThreads();
34
+ if (count === 0) throw new Error('num_threads must be > 0');
35
+ const channel = new MessageChannel();
36
+ try {
37
+ await new Promise((resolve, reject) => {
38
+ channel.port1.onmessage = ({ data }) => (data.ready ? resolve() : reject(new Error(data.error)));
39
+ const spawn = {
40
+ type: SPAWN_COMPUTE,
41
+ url: import.meta.url,
42
+ count,
43
+ module,
44
+ memory,
45
+ receiver: builder.receiver(),
46
+ mainJS: builder.mainJS(),
47
+ port: channel.port2,
48
+ };
49
+ postMessage(spawn, [channel.port2]);
50
+ });
51
+ builder.build();
52
+ } finally {
53
+ channel.port1.close();
54
+ }
55
+ }
engine/dist/parakeet/web-single-relaxed/parakeet_runtime.js ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class Runtime {
2
+ __destroy_into_raw() {
3
+ const ptr = this.__wbg_ptr;
4
+ this.__wbg_ptr = 0;
5
+ RuntimeFinalization.unregister(this);
6
+ return ptr;
7
+ }
8
+ free() {
9
+ const ptr = this.__destroy_into_raw();
10
+ wasm.__wbg_runtime_free(ptr, 0);
11
+ }
12
+ cancel() {
13
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
14
+ if (ret[1]) {
15
+ throw takeFromExternrefTable0(ret[0]);
16
+ }
17
+ }
18
+ /**
19
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
20
+ * whether the engine is ready.
21
+ * @param {number} part
22
+ * @returns {boolean}
23
+ */
24
+ end_part(part) {
25
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] !== 0;
30
+ }
31
+ /**
32
+ * Makes everything heard final; returns `{"committed","provisional","heard"}`.
33
+ * @returns {string}
34
+ */
35
+ finish() {
36
+ let deferred2_0;
37
+ let deferred2_1;
38
+ try {
39
+ const ret = wasm.runtime_finish(this.__wbg_ptr);
40
+ var ptr1 = ret[0];
41
+ var len1 = ret[1];
42
+ if (ret[3]) {
43
+ ptr1 = 0; len1 = 0;
44
+ throw takeFromExternrefTable0(ret[2]);
45
+ }
46
+ deferred2_0 = ptr1;
47
+ deferred2_1 = len1;
48
+ return getStringFromWasm0(ptr1, len1);
49
+ } finally {
50
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
51
+ }
52
+ }
53
+ /**
54
+ * The next live samples (16 kHz mono).
55
+ * @param {Float32Array} samples
56
+ */
57
+ hear(samples) {
58
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
59
+ const len0 = WASM_VECTOR_LEN;
60
+ const ret = wasm.runtime_hear(this.__wbg_ptr, ptr0, len0);
61
+ if (ret[1]) {
62
+ throw takeFromExternrefTable0(ret[0]);
63
+ }
64
+ }
65
+ /**
66
+ * Starts listening to live audio afresh.
67
+ */
68
+ listen() {
69
+ const ret = wasm.runtime_listen(this.__wbg_ptr);
70
+ if (ret[1]) {
71
+ throw takeFromExternrefTable0(ret[0]);
72
+ }
73
+ }
74
+ /**
75
+ * @param {string} manifest_json
76
+ */
77
+ constructor(manifest_json) {
78
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
79
+ const len0 = WASM_VECTOR_LEN;
80
+ const ret = wasm.runtime_new(ptr0, len0);
81
+ if (ret[2]) {
82
+ throw takeFromExternrefTable0(ret[1]);
83
+ }
84
+ this.__wbg_ptr = ret[0];
85
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
86
+ return this;
87
+ }
88
+ /**
89
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
90
+ * again.
91
+ * @param {number} part
92
+ */
93
+ restart_part(part) {
94
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
95
+ if (ret[1]) {
96
+ throw takeFromExternrefTable0(ret[0]);
97
+ }
98
+ }
99
+ /**
100
+ * Starts transcribing a recording (16 kHz mono); returns its plan
101
+ * (`{"segments": [{"start","end"}], "seconds"}`).
102
+ * @param {Float32Array} pcm
103
+ * @returns {string}
104
+ */
105
+ start(pcm) {
106
+ let deferred3_0;
107
+ let deferred3_1;
108
+ try {
109
+ const ptr0 = passArrayF32ToWasm0(pcm, wasm.__wbindgen_malloc);
110
+ const len0 = WASM_VECTOR_LEN;
111
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
112
+ var ptr2 = ret[0];
113
+ var len2 = ret[1];
114
+ if (ret[3]) {
115
+ ptr2 = 0; len2 = 0;
116
+ throw takeFromExternrefTable0(ret[2]);
117
+ }
118
+ deferred3_0 = ptr2;
119
+ deferred3_1 = len2;
120
+ return getStringFromWasm0(ptr2, len2);
121
+ } finally {
122
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
123
+ }
124
+ }
125
+ /**
126
+ * Transcribes the next segment; returns `{"segment","segments","sentences","done"}`, each
127
+ * sentence `{"text","start","end"}` in seconds.
128
+ * @returns {string}
129
+ */
130
+ step() {
131
+ let deferred2_0;
132
+ let deferred2_1;
133
+ try {
134
+ const ret = wasm.runtime_step(this.__wbg_ptr);
135
+ var ptr1 = ret[0];
136
+ var len1 = ret[1];
137
+ if (ret[3]) {
138
+ ptr1 = 0; len1 = 0;
139
+ throw takeFromExternrefTable0(ret[2]);
140
+ }
141
+ deferred2_0 = ptr1;
142
+ deferred2_1 = len1;
143
+ return getStringFromWasm0(ptr1, len1);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
146
+ }
147
+ }
148
+ /**
149
+ * @returns {number}
150
+ */
151
+ threads() {
152
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
153
+ if (ret[2]) {
154
+ throw takeFromExternrefTable0(ret[1]);
155
+ }
156
+ return ret[0] >>> 0;
157
+ }
158
+ /**
159
+ * Transcribes what was heard; returns `{"committed","provisional","heard"}`.
160
+ * @returns {string}
161
+ */
162
+ update() {
163
+ let deferred2_0;
164
+ let deferred2_1;
165
+ try {
166
+ const ret = wasm.runtime_update(this.__wbg_ptr);
167
+ var ptr1 = ret[0];
168
+ var len1 = ret[1];
169
+ if (ret[3]) {
170
+ ptr1 = 0; len1 = 0;
171
+ throw takeFromExternrefTable0(ret[2]);
172
+ }
173
+ deferred2_0 = ptr1;
174
+ deferred2_1 = len1;
175
+ return getStringFromWasm0(ptr1, len1);
176
+ } finally {
177
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
178
+ }
179
+ }
180
+ /**
181
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
182
+ * @param {number} part
183
+ * @param {Uint8Array} bytes
184
+ */
185
+ write_part(part, bytes) {
186
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
187
+ const len0 = WASM_VECTOR_LEN;
188
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
189
+ if (ret[1]) {
190
+ throw takeFromExternrefTable0(ret[0]);
191
+ }
192
+ }
193
+ }
194
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
195
+
196
+ /**
197
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
198
+ * @returns {string}
199
+ */
200
+ export function last_panic() {
201
+ let deferred1_0;
202
+ let deferred1_1;
203
+ try {
204
+ const ret = wasm.last_panic();
205
+ deferred1_0 = ret[0];
206
+ deferred1_1 = ret[1];
207
+ return getStringFromWasm0(ret[0], ret[1]);
208
+ } finally {
209
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
210
+ }
211
+ }
212
+
213
+ /**
214
+ * The rate of the PCM the runtime reads, in Hz.
215
+ * @returns {number}
216
+ */
217
+ export function sample_rate() {
218
+ const ret = wasm.sample_rate();
219
+ return ret >>> 0;
220
+ }
221
+ function __wbg_get_imports() {
222
+ const import0 = {
223
+ __proto__: null,
224
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
225
+ const ret = Error(getStringFromWasm0(arg0, arg1));
226
+ return ret;
227
+ },
228
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
229
+ throw new Error(getStringFromWasm0(arg0, arg1));
230
+ },
231
+ __wbindgen_init_externref_table: function() {
232
+ const table = wasm.__wbindgen_externrefs;
233
+ const offset = table.grow(4);
234
+ table.set(0, undefined);
235
+ table.set(offset + 0, undefined);
236
+ table.set(offset + 1, null);
237
+ table.set(offset + 2, true);
238
+ table.set(offset + 3, false);
239
+ },
240
+ };
241
+ return {
242
+ __proto__: null,
243
+ "./parakeet_runtime_bg.js": import0,
244
+ };
245
+ }
246
+
247
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
248
+ ? { register: () => {}, unregister: () => {} }
249
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
250
+
251
+ let cachedFloat32ArrayMemory0 = null;
252
+ function getFloat32ArrayMemory0() {
253
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
254
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
255
+ }
256
+ return cachedFloat32ArrayMemory0;
257
+ }
258
+
259
+ function getStringFromWasm0(ptr, len) {
260
+ return decodeText(ptr >>> 0, len);
261
+ }
262
+
263
+ let cachedUint8ArrayMemory0 = null;
264
+ function getUint8ArrayMemory0() {
265
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
266
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
267
+ }
268
+ return cachedUint8ArrayMemory0;
269
+ }
270
+
271
+ function passArray8ToWasm0(arg, malloc) {
272
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
273
+ getUint8ArrayMemory0().set(arg, ptr / 1);
274
+ WASM_VECTOR_LEN = arg.length;
275
+ return ptr;
276
+ }
277
+
278
+ function passArrayF32ToWasm0(arg, malloc) {
279
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
280
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
281
+ WASM_VECTOR_LEN = arg.length;
282
+ return ptr;
283
+ }
284
+
285
+ function passStringToWasm0(arg, malloc, realloc) {
286
+ if (realloc === undefined) {
287
+ const buf = cachedTextEncoder.encode(arg);
288
+ const ptr = malloc(buf.length, 1) >>> 0;
289
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
290
+ WASM_VECTOR_LEN = buf.length;
291
+ return ptr;
292
+ }
293
+
294
+ let len = arg.length;
295
+ let ptr = malloc(len, 1) >>> 0;
296
+
297
+ const mem = getUint8ArrayMemory0();
298
+
299
+ let offset = 0;
300
+
301
+ for (; offset < len; offset++) {
302
+ const code = arg.charCodeAt(offset);
303
+ if (code > 0x7F) break;
304
+ mem[ptr + offset] = code;
305
+ }
306
+ if (offset !== len) {
307
+ if (offset !== 0) {
308
+ arg = arg.slice(offset);
309
+ }
310
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
311
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
312
+ const ret = cachedTextEncoder.encodeInto(arg, view);
313
+
314
+ offset += ret.written;
315
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
316
+ }
317
+
318
+ WASM_VECTOR_LEN = offset;
319
+ return ptr;
320
+ }
321
+
322
+ function takeFromExternrefTable0(idx) {
323
+ const value = wasm.__wbindgen_externrefs.get(idx);
324
+ wasm.__externref_table_dealloc(idx);
325
+ return value;
326
+ }
327
+
328
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
329
+ cachedTextDecoder.decode();
330
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
331
+ let numBytesDecoded = 0;
332
+ function decodeText(ptr, len) {
333
+ numBytesDecoded += len;
334
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
335
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
336
+ cachedTextDecoder.decode();
337
+ numBytesDecoded = len;
338
+ }
339
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
340
+ }
341
+
342
+ const cachedTextEncoder = new TextEncoder();
343
+
344
+ if (!('encodeInto' in cachedTextEncoder)) {
345
+ cachedTextEncoder.encodeInto = function (arg, view) {
346
+ const buf = cachedTextEncoder.encode(arg);
347
+ view.set(buf);
348
+ return {
349
+ read: arg.length,
350
+ written: buf.length
351
+ };
352
+ };
353
+ }
354
+
355
+ let WASM_VECTOR_LEN = 0;
356
+
357
+ let wasmModule, wasmInstance, wasm;
358
+ function __wbg_finalize_init(instance, module) {
359
+ wasmInstance = instance;
360
+ wasm = instance.exports;
361
+ wasmModule = module;
362
+ cachedFloat32ArrayMemory0 = null;
363
+ cachedUint8ArrayMemory0 = null;
364
+ wasm.__wbindgen_start();
365
+ return wasm;
366
+ }
367
+
368
+ async function __wbg_load(module, imports) {
369
+ if (typeof Response === 'function' && module instanceof Response) {
370
+ if (!module.ok) {
371
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
372
+ }
373
+
374
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
375
+ try {
376
+ return await WebAssembly.instantiateStreaming(module, imports);
377
+ } catch (e) {
378
+ const validResponse = expectedResponseType(module.type);
379
+
380
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
381
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
382
+
383
+ } else { throw e; }
384
+ }
385
+ }
386
+
387
+ const bytes = await module.arrayBuffer();
388
+ return await WebAssembly.instantiate(bytes, imports);
389
+ } else {
390
+ const instance = await WebAssembly.instantiate(module, imports);
391
+
392
+ if (instance instanceof WebAssembly.Instance) {
393
+ return { instance, module };
394
+ } else {
395
+ return instance;
396
+ }
397
+ }
398
+
399
+ function expectedResponseType(type) {
400
+ switch (type) {
401
+ case 'basic': case 'cors': case 'default': return true;
402
+ }
403
+ return false;
404
+ }
405
+ }
406
+
407
+ function initSync(module) {
408
+ if (wasm !== undefined) return wasm;
409
+
410
+
411
+ if (module !== undefined) {
412
+ if (Object.getPrototypeOf(module) === Object.prototype) {
413
+ ({module} = module)
414
+ } else {
415
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
416
+ }
417
+ }
418
+
419
+ const imports = __wbg_get_imports();
420
+ if (!(module instanceof WebAssembly.Module)) {
421
+ module = new WebAssembly.Module(module);
422
+ }
423
+ const instance = new WebAssembly.Instance(module, imports);
424
+ return __wbg_finalize_init(instance, module);
425
+ }
426
+
427
+ async function __wbg_init(module_or_path) {
428
+ if (wasm !== undefined) return wasm;
429
+
430
+
431
+ if (module_or_path !== undefined) {
432
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
433
+ ({module_or_path} = module_or_path)
434
+ } else {
435
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
436
+ }
437
+ }
438
+
439
+ if (module_or_path === undefined) {
440
+ module_or_path = new URL('parakeet_runtime_bg.wasm', import.meta.url);
441
+ }
442
+ const imports = __wbg_get_imports();
443
+
444
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
445
+ module_or_path = fetch(module_or_path);
446
+ }
447
+
448
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
449
+
450
+ return __wbg_finalize_init(instance, module);
451
+ }
452
+
453
+ export { initSync, __wbg_init as default };
engine/dist/parakeet/web-single-relaxed/parakeet_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5e28c26b253959079597fee69f601c8b42bdbca0a744ab7b735c92f8527f490
3
+ size 1234833
engine/dist/parakeet/web-single/parakeet_runtime.js ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class Runtime {
2
+ __destroy_into_raw() {
3
+ const ptr = this.__wbg_ptr;
4
+ this.__wbg_ptr = 0;
5
+ RuntimeFinalization.unregister(this);
6
+ return ptr;
7
+ }
8
+ free() {
9
+ const ptr = this.__destroy_into_raw();
10
+ wasm.__wbg_runtime_free(ptr, 0);
11
+ }
12
+ cancel() {
13
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
14
+ if (ret[1]) {
15
+ throw takeFromExternrefTable0(ret[0]);
16
+ }
17
+ }
18
+ /**
19
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
20
+ * whether the engine is ready.
21
+ * @param {number} part
22
+ * @returns {boolean}
23
+ */
24
+ end_part(part) {
25
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] !== 0;
30
+ }
31
+ /**
32
+ * Makes everything heard final; returns `{"committed","provisional","heard"}`.
33
+ * @returns {string}
34
+ */
35
+ finish() {
36
+ let deferred2_0;
37
+ let deferred2_1;
38
+ try {
39
+ const ret = wasm.runtime_finish(this.__wbg_ptr);
40
+ var ptr1 = ret[0];
41
+ var len1 = ret[1];
42
+ if (ret[3]) {
43
+ ptr1 = 0; len1 = 0;
44
+ throw takeFromExternrefTable0(ret[2]);
45
+ }
46
+ deferred2_0 = ptr1;
47
+ deferred2_1 = len1;
48
+ return getStringFromWasm0(ptr1, len1);
49
+ } finally {
50
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
51
+ }
52
+ }
53
+ /**
54
+ * The next live samples (16 kHz mono).
55
+ * @param {Float32Array} samples
56
+ */
57
+ hear(samples) {
58
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
59
+ const len0 = WASM_VECTOR_LEN;
60
+ const ret = wasm.runtime_hear(this.__wbg_ptr, ptr0, len0);
61
+ if (ret[1]) {
62
+ throw takeFromExternrefTable0(ret[0]);
63
+ }
64
+ }
65
+ /**
66
+ * Starts listening to live audio afresh.
67
+ */
68
+ listen() {
69
+ const ret = wasm.runtime_listen(this.__wbg_ptr);
70
+ if (ret[1]) {
71
+ throw takeFromExternrefTable0(ret[0]);
72
+ }
73
+ }
74
+ /**
75
+ * @param {string} manifest_json
76
+ */
77
+ constructor(manifest_json) {
78
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
79
+ const len0 = WASM_VECTOR_LEN;
80
+ const ret = wasm.runtime_new(ptr0, len0);
81
+ if (ret[2]) {
82
+ throw takeFromExternrefTable0(ret[1]);
83
+ }
84
+ this.__wbg_ptr = ret[0];
85
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
86
+ return this;
87
+ }
88
+ /**
89
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
90
+ * again.
91
+ * @param {number} part
92
+ */
93
+ restart_part(part) {
94
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
95
+ if (ret[1]) {
96
+ throw takeFromExternrefTable0(ret[0]);
97
+ }
98
+ }
99
+ /**
100
+ * Starts transcribing a recording (16 kHz mono); returns its plan
101
+ * (`{"segments": [{"start","end"}], "seconds"}`).
102
+ * @param {Float32Array} pcm
103
+ * @returns {string}
104
+ */
105
+ start(pcm) {
106
+ let deferred3_0;
107
+ let deferred3_1;
108
+ try {
109
+ const ptr0 = passArrayF32ToWasm0(pcm, wasm.__wbindgen_malloc);
110
+ const len0 = WASM_VECTOR_LEN;
111
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
112
+ var ptr2 = ret[0];
113
+ var len2 = ret[1];
114
+ if (ret[3]) {
115
+ ptr2 = 0; len2 = 0;
116
+ throw takeFromExternrefTable0(ret[2]);
117
+ }
118
+ deferred3_0 = ptr2;
119
+ deferred3_1 = len2;
120
+ return getStringFromWasm0(ptr2, len2);
121
+ } finally {
122
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
123
+ }
124
+ }
125
+ /**
126
+ * Transcribes the next segment; returns `{"segment","segments","sentences","done"}`, each
127
+ * sentence `{"text","start","end"}` in seconds.
128
+ * @returns {string}
129
+ */
130
+ step() {
131
+ let deferred2_0;
132
+ let deferred2_1;
133
+ try {
134
+ const ret = wasm.runtime_step(this.__wbg_ptr);
135
+ var ptr1 = ret[0];
136
+ var len1 = ret[1];
137
+ if (ret[3]) {
138
+ ptr1 = 0; len1 = 0;
139
+ throw takeFromExternrefTable0(ret[2]);
140
+ }
141
+ deferred2_0 = ptr1;
142
+ deferred2_1 = len1;
143
+ return getStringFromWasm0(ptr1, len1);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
146
+ }
147
+ }
148
+ /**
149
+ * @returns {number}
150
+ */
151
+ threads() {
152
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
153
+ if (ret[2]) {
154
+ throw takeFromExternrefTable0(ret[1]);
155
+ }
156
+ return ret[0] >>> 0;
157
+ }
158
+ /**
159
+ * Transcribes what was heard; returns `{"committed","provisional","heard"}`.
160
+ * @returns {string}
161
+ */
162
+ update() {
163
+ let deferred2_0;
164
+ let deferred2_1;
165
+ try {
166
+ const ret = wasm.runtime_update(this.__wbg_ptr);
167
+ var ptr1 = ret[0];
168
+ var len1 = ret[1];
169
+ if (ret[3]) {
170
+ ptr1 = 0; len1 = 0;
171
+ throw takeFromExternrefTable0(ret[2]);
172
+ }
173
+ deferred2_0 = ptr1;
174
+ deferred2_1 = len1;
175
+ return getStringFromWasm0(ptr1, len1);
176
+ } finally {
177
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
178
+ }
179
+ }
180
+ /**
181
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
182
+ * @param {number} part
183
+ * @param {Uint8Array} bytes
184
+ */
185
+ write_part(part, bytes) {
186
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
187
+ const len0 = WASM_VECTOR_LEN;
188
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
189
+ if (ret[1]) {
190
+ throw takeFromExternrefTable0(ret[0]);
191
+ }
192
+ }
193
+ }
194
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
195
+
196
+ /**
197
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
198
+ * @returns {string}
199
+ */
200
+ export function last_panic() {
201
+ let deferred1_0;
202
+ let deferred1_1;
203
+ try {
204
+ const ret = wasm.last_panic();
205
+ deferred1_0 = ret[0];
206
+ deferred1_1 = ret[1];
207
+ return getStringFromWasm0(ret[0], ret[1]);
208
+ } finally {
209
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
210
+ }
211
+ }
212
+
213
+ /**
214
+ * The rate of the PCM the runtime reads, in Hz.
215
+ * @returns {number}
216
+ */
217
+ export function sample_rate() {
218
+ const ret = wasm.sample_rate();
219
+ return ret >>> 0;
220
+ }
221
+ function __wbg_get_imports() {
222
+ const import0 = {
223
+ __proto__: null,
224
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
225
+ const ret = Error(getStringFromWasm0(arg0, arg1));
226
+ return ret;
227
+ },
228
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
229
+ throw new Error(getStringFromWasm0(arg0, arg1));
230
+ },
231
+ __wbindgen_init_externref_table: function() {
232
+ const table = wasm.__wbindgen_externrefs;
233
+ const offset = table.grow(4);
234
+ table.set(0, undefined);
235
+ table.set(offset + 0, undefined);
236
+ table.set(offset + 1, null);
237
+ table.set(offset + 2, true);
238
+ table.set(offset + 3, false);
239
+ },
240
+ };
241
+ return {
242
+ __proto__: null,
243
+ "./parakeet_runtime_bg.js": import0,
244
+ };
245
+ }
246
+
247
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
248
+ ? { register: () => {}, unregister: () => {} }
249
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
250
+
251
+ let cachedFloat32ArrayMemory0 = null;
252
+ function getFloat32ArrayMemory0() {
253
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
254
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
255
+ }
256
+ return cachedFloat32ArrayMemory0;
257
+ }
258
+
259
+ function getStringFromWasm0(ptr, len) {
260
+ return decodeText(ptr >>> 0, len);
261
+ }
262
+
263
+ let cachedUint8ArrayMemory0 = null;
264
+ function getUint8ArrayMemory0() {
265
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
266
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
267
+ }
268
+ return cachedUint8ArrayMemory0;
269
+ }
270
+
271
+ function passArray8ToWasm0(arg, malloc) {
272
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
273
+ getUint8ArrayMemory0().set(arg, ptr / 1);
274
+ WASM_VECTOR_LEN = arg.length;
275
+ return ptr;
276
+ }
277
+
278
+ function passArrayF32ToWasm0(arg, malloc) {
279
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
280
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
281
+ WASM_VECTOR_LEN = arg.length;
282
+ return ptr;
283
+ }
284
+
285
+ function passStringToWasm0(arg, malloc, realloc) {
286
+ if (realloc === undefined) {
287
+ const buf = cachedTextEncoder.encode(arg);
288
+ const ptr = malloc(buf.length, 1) >>> 0;
289
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
290
+ WASM_VECTOR_LEN = buf.length;
291
+ return ptr;
292
+ }
293
+
294
+ let len = arg.length;
295
+ let ptr = malloc(len, 1) >>> 0;
296
+
297
+ const mem = getUint8ArrayMemory0();
298
+
299
+ let offset = 0;
300
+
301
+ for (; offset < len; offset++) {
302
+ const code = arg.charCodeAt(offset);
303
+ if (code > 0x7F) break;
304
+ mem[ptr + offset] = code;
305
+ }
306
+ if (offset !== len) {
307
+ if (offset !== 0) {
308
+ arg = arg.slice(offset);
309
+ }
310
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
311
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
312
+ const ret = cachedTextEncoder.encodeInto(arg, view);
313
+
314
+ offset += ret.written;
315
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
316
+ }
317
+
318
+ WASM_VECTOR_LEN = offset;
319
+ return ptr;
320
+ }
321
+
322
+ function takeFromExternrefTable0(idx) {
323
+ const value = wasm.__wbindgen_externrefs.get(idx);
324
+ wasm.__externref_table_dealloc(idx);
325
+ return value;
326
+ }
327
+
328
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
329
+ cachedTextDecoder.decode();
330
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
331
+ let numBytesDecoded = 0;
332
+ function decodeText(ptr, len) {
333
+ numBytesDecoded += len;
334
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
335
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
336
+ cachedTextDecoder.decode();
337
+ numBytesDecoded = len;
338
+ }
339
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
340
+ }
341
+
342
+ const cachedTextEncoder = new TextEncoder();
343
+
344
+ if (!('encodeInto' in cachedTextEncoder)) {
345
+ cachedTextEncoder.encodeInto = function (arg, view) {
346
+ const buf = cachedTextEncoder.encode(arg);
347
+ view.set(buf);
348
+ return {
349
+ read: arg.length,
350
+ written: buf.length
351
+ };
352
+ };
353
+ }
354
+
355
+ let WASM_VECTOR_LEN = 0;
356
+
357
+ let wasmModule, wasmInstance, wasm;
358
+ function __wbg_finalize_init(instance, module) {
359
+ wasmInstance = instance;
360
+ wasm = instance.exports;
361
+ wasmModule = module;
362
+ cachedFloat32ArrayMemory0 = null;
363
+ cachedUint8ArrayMemory0 = null;
364
+ wasm.__wbindgen_start();
365
+ return wasm;
366
+ }
367
+
368
+ async function __wbg_load(module, imports) {
369
+ if (typeof Response === 'function' && module instanceof Response) {
370
+ if (!module.ok) {
371
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
372
+ }
373
+
374
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
375
+ try {
376
+ return await WebAssembly.instantiateStreaming(module, imports);
377
+ } catch (e) {
378
+ const validResponse = expectedResponseType(module.type);
379
+
380
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
381
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
382
+
383
+ } else { throw e; }
384
+ }
385
+ }
386
+
387
+ const bytes = await module.arrayBuffer();
388
+ return await WebAssembly.instantiate(bytes, imports);
389
+ } else {
390
+ const instance = await WebAssembly.instantiate(module, imports);
391
+
392
+ if (instance instanceof WebAssembly.Instance) {
393
+ return { instance, module };
394
+ } else {
395
+ return instance;
396
+ }
397
+ }
398
+
399
+ function expectedResponseType(type) {
400
+ switch (type) {
401
+ case 'basic': case 'cors': case 'default': return true;
402
+ }
403
+ return false;
404
+ }
405
+ }
406
+
407
+ function initSync(module) {
408
+ if (wasm !== undefined) return wasm;
409
+
410
+
411
+ if (module !== undefined) {
412
+ if (Object.getPrototypeOf(module) === Object.prototype) {
413
+ ({module} = module)
414
+ } else {
415
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
416
+ }
417
+ }
418
+
419
+ const imports = __wbg_get_imports();
420
+ if (!(module instanceof WebAssembly.Module)) {
421
+ module = new WebAssembly.Module(module);
422
+ }
423
+ const instance = new WebAssembly.Instance(module, imports);
424
+ return __wbg_finalize_init(instance, module);
425
+ }
426
+
427
+ async function __wbg_init(module_or_path) {
428
+ if (wasm !== undefined) return wasm;
429
+
430
+
431
+ if (module_or_path !== undefined) {
432
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
433
+ ({module_or_path} = module_or_path)
434
+ } else {
435
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
436
+ }
437
+ }
438
+
439
+ if (module_or_path === undefined) {
440
+ module_or_path = new URL('parakeet_runtime_bg.wasm', import.meta.url);
441
+ }
442
+ const imports = __wbg_get_imports();
443
+
444
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
445
+ module_or_path = fetch(module_or_path);
446
+ }
447
+
448
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
449
+
450
+ return __wbg_finalize_init(instance, module);
451
+ }
452
+
453
+ export { initSync, __wbg_init as default };
engine/dist/parakeet/web-single/parakeet_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:870f21acfa436086fd6adf52c2d427775b8b61282b28dd77ce9506c3d620fbb7
3
+ size 1184581
engine/dist/parakeet/web-threaded-relaxed/parakeet_runtime.js ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { startWorkers } from './snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js';
2
+
3
+
4
+ export class Runtime {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ RuntimeFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_runtime_free(ptr, 0);
14
+ }
15
+ cancel() {
16
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
17
+ if (ret[1]) {
18
+ throw takeFromExternrefTable0(ret[0]);
19
+ }
20
+ }
21
+ /**
22
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
23
+ * whether the engine is ready.
24
+ * @param {number} part
25
+ * @returns {boolean}
26
+ */
27
+ end_part(part) {
28
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
29
+ if (ret[2]) {
30
+ throw takeFromExternrefTable0(ret[1]);
31
+ }
32
+ return ret[0] !== 0;
33
+ }
34
+ /**
35
+ * Makes everything heard final; returns `{"committed","provisional","heard"}`.
36
+ * @returns {string}
37
+ */
38
+ finish() {
39
+ let deferred2_0;
40
+ let deferred2_1;
41
+ try {
42
+ const ret = wasm.runtime_finish(this.__wbg_ptr);
43
+ var ptr1 = ret[0];
44
+ var len1 = ret[1];
45
+ if (ret[3]) {
46
+ ptr1 = 0; len1 = 0;
47
+ throw takeFromExternrefTable0(ret[2]);
48
+ }
49
+ deferred2_0 = ptr1;
50
+ deferred2_1 = len1;
51
+ return getStringFromWasm0(ptr1, len1);
52
+ } finally {
53
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
54
+ }
55
+ }
56
+ /**
57
+ * The next live samples (16 kHz mono).
58
+ * @param {Float32Array} samples
59
+ */
60
+ hear(samples) {
61
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
62
+ const len0 = WASM_VECTOR_LEN;
63
+ const ret = wasm.runtime_hear(this.__wbg_ptr, ptr0, len0);
64
+ if (ret[1]) {
65
+ throw takeFromExternrefTable0(ret[0]);
66
+ }
67
+ }
68
+ /**
69
+ * Starts listening to live audio afresh.
70
+ */
71
+ listen() {
72
+ const ret = wasm.runtime_listen(this.__wbg_ptr);
73
+ if (ret[1]) {
74
+ throw takeFromExternrefTable0(ret[0]);
75
+ }
76
+ }
77
+ /**
78
+ * @param {string} manifest_json
79
+ */
80
+ constructor(manifest_json) {
81
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
82
+ const len0 = WASM_VECTOR_LEN;
83
+ const ret = wasm.runtime_new(ptr0, len0);
84
+ if (ret[2]) {
85
+ throw takeFromExternrefTable0(ret[1]);
86
+ }
87
+ this.__wbg_ptr = ret[0];
88
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
89
+ return this;
90
+ }
91
+ /**
92
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
93
+ * again.
94
+ * @param {number} part
95
+ */
96
+ restart_part(part) {
97
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
98
+ if (ret[1]) {
99
+ throw takeFromExternrefTable0(ret[0]);
100
+ }
101
+ }
102
+ /**
103
+ * Starts transcribing a recording (16 kHz mono); returns its plan
104
+ * (`{"segments": [{"start","end"}], "seconds"}`).
105
+ * @param {Float32Array} pcm
106
+ * @returns {string}
107
+ */
108
+ start(pcm) {
109
+ let deferred3_0;
110
+ let deferred3_1;
111
+ try {
112
+ const ptr0 = passArrayF32ToWasm0(pcm, wasm.__wbindgen_malloc);
113
+ const len0 = WASM_VECTOR_LEN;
114
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
115
+ var ptr2 = ret[0];
116
+ var len2 = ret[1];
117
+ if (ret[3]) {
118
+ ptr2 = 0; len2 = 0;
119
+ throw takeFromExternrefTable0(ret[2]);
120
+ }
121
+ deferred3_0 = ptr2;
122
+ deferred3_1 = len2;
123
+ return getStringFromWasm0(ptr2, len2);
124
+ } finally {
125
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
126
+ }
127
+ }
128
+ /**
129
+ * Transcribes the next segment; returns `{"segment","segments","sentences","done"}`, each
130
+ * sentence `{"text","start","end"}` in seconds.
131
+ * @returns {string}
132
+ */
133
+ step() {
134
+ let deferred2_0;
135
+ let deferred2_1;
136
+ try {
137
+ const ret = wasm.runtime_step(this.__wbg_ptr);
138
+ var ptr1 = ret[0];
139
+ var len1 = ret[1];
140
+ if (ret[3]) {
141
+ ptr1 = 0; len1 = 0;
142
+ throw takeFromExternrefTable0(ret[2]);
143
+ }
144
+ deferred2_0 = ptr1;
145
+ deferred2_1 = len1;
146
+ return getStringFromWasm0(ptr1, len1);
147
+ } finally {
148
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
149
+ }
150
+ }
151
+ /**
152
+ * @returns {number}
153
+ */
154
+ threads() {
155
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
156
+ if (ret[2]) {
157
+ throw takeFromExternrefTable0(ret[1]);
158
+ }
159
+ return ret[0] >>> 0;
160
+ }
161
+ /**
162
+ * Transcribes what was heard; returns `{"committed","provisional","heard"}`.
163
+ * @returns {string}
164
+ */
165
+ update() {
166
+ let deferred2_0;
167
+ let deferred2_1;
168
+ try {
169
+ const ret = wasm.runtime_update(this.__wbg_ptr);
170
+ var ptr1 = ret[0];
171
+ var len1 = ret[1];
172
+ if (ret[3]) {
173
+ ptr1 = 0; len1 = 0;
174
+ throw takeFromExternrefTable0(ret[2]);
175
+ }
176
+ deferred2_0 = ptr1;
177
+ deferred2_1 = len1;
178
+ return getStringFromWasm0(ptr1, len1);
179
+ } finally {
180
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
181
+ }
182
+ }
183
+ /**
184
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
185
+ * @param {number} part
186
+ * @param {Uint8Array} bytes
187
+ */
188
+ write_part(part, bytes) {
189
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
192
+ if (ret[1]) {
193
+ throw takeFromExternrefTable0(ret[0]);
194
+ }
195
+ }
196
+ }
197
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
198
+
199
+ /**
200
+ * @param {number} num_threads
201
+ * @returns {Promise<any>}
202
+ */
203
+ export function initThreadPool(num_threads) {
204
+ const ret = wasm.initThreadPool(num_threads);
205
+ return ret;
206
+ }
207
+
208
+ /**
209
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
210
+ * @returns {string}
211
+ */
212
+ export function last_panic() {
213
+ let deferred1_0;
214
+ let deferred1_1;
215
+ try {
216
+ const ret = wasm.last_panic();
217
+ deferred1_0 = ret[0];
218
+ deferred1_1 = ret[1];
219
+ return getStringFromWasm0(ret[0], ret[1]);
220
+ } finally {
221
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * The rate of the PCM the runtime reads, in Hz.
227
+ * @returns {number}
228
+ */
229
+ export function sample_rate() {
230
+ const ret = wasm.sample_rate();
231
+ return ret >>> 0;
232
+ }
233
+
234
+ export class wbg_rayon_PoolBuilder {
235
+ static __wrap(ptr) {
236
+ const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
237
+ obj.__wbg_ptr = ptr;
238
+ wbg_rayon_PoolBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
239
+ return obj;
240
+ }
241
+ __destroy_into_raw() {
242
+ const ptr = this.__wbg_ptr;
243
+ this.__wbg_ptr = 0;
244
+ wbg_rayon_PoolBuilderFinalization.unregister(this);
245
+ return ptr;
246
+ }
247
+ free() {
248
+ const ptr = this.__destroy_into_raw();
249
+ wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 0);
250
+ }
251
+ build() {
252
+ wasm.wbg_rayon_poolbuilder_build(this.__wbg_ptr);
253
+ }
254
+ /**
255
+ * @returns {string}
256
+ */
257
+ mainJS() {
258
+ const ret = wasm.wbg_rayon_poolbuilder_mainJS(this.__wbg_ptr);
259
+ return ret;
260
+ }
261
+ /**
262
+ * @returns {number}
263
+ */
264
+ numThreads() {
265
+ const ret = wasm.wbg_rayon_poolbuilder_numThreads(this.__wbg_ptr);
266
+ return ret >>> 0;
267
+ }
268
+ /**
269
+ * @returns {number}
270
+ */
271
+ receiver() {
272
+ const ret = wasm.wbg_rayon_poolbuilder_receiver(this.__wbg_ptr);
273
+ return ret >>> 0;
274
+ }
275
+ }
276
+ if (Symbol.dispose) wbg_rayon_PoolBuilder.prototype[Symbol.dispose] = wbg_rayon_PoolBuilder.prototype.free;
277
+
278
+ /**
279
+ * @param {number} receiver
280
+ */
281
+ export function wbg_rayon_start_worker(receiver) {
282
+ wasm.wbg_rayon_start_worker(receiver);
283
+ }
284
+ function __wbg_get_imports(memory) {
285
+ const import0 = {
286
+ __proto__: null,
287
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
288
+ const ret = Error(getStringFromWasm0(arg0, arg1));
289
+ return ret;
290
+ },
291
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
292
+ const ret = arg0 === undefined;
293
+ return ret;
294
+ },
295
+ __wbg___wbindgen_memory_caa4a6165639c8b5: function() {
296
+ const ret = wasm.memory;
297
+ return ret;
298
+ },
299
+ __wbg___wbindgen_module_7115fb14045f9891: function() {
300
+ const ret = wasmModule;
301
+ return ret;
302
+ },
303
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
304
+ throw new Error(getStringFromWasm0(arg0, arg1));
305
+ },
306
+ __wbg_instanceof_Window_82d71df4eddf88bc: function(arg0) {
307
+ let result;
308
+ try {
309
+ result = arg0 instanceof Window;
310
+ } catch (_) {
311
+ result = false;
312
+ }
313
+ const ret = result;
314
+ return ret;
315
+ },
316
+ __wbg_startWorkers_622cedd0d351664e: function(arg0, arg1, arg2) {
317
+ const ret = startWorkers(arg0, arg1, wbg_rayon_PoolBuilder.__wrap(arg2));
318
+ return ret;
319
+ },
320
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
321
+ const ret = typeof global === 'undefined' ? null : global;
322
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
323
+ },
324
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
325
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
326
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
327
+ },
328
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
329
+ const ret = typeof self === 'undefined' ? null : self;
330
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
331
+ },
332
+ __wbg_static_accessor_URL_fac851ed3060f4eb: function() {
333
+ const ret = import.meta.url;
334
+ return ret;
335
+ },
336
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
337
+ const ret = typeof window === 'undefined' ? null : window;
338
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
339
+ },
340
+ __wbindgen_init_externref_table: function() {
341
+ const table = wasm.__wbindgen_externrefs;
342
+ const offset = table.grow(4);
343
+ table.set(0, undefined);
344
+ table.set(offset + 0, undefined);
345
+ table.set(offset + 1, null);
346
+ table.set(offset + 2, true);
347
+ table.set(offset + 3, false);
348
+ },
349
+ memory: memory || new WebAssembly.Memory({initial:19,maximum:65536,shared:true}),
350
+ };
351
+ return {
352
+ __proto__: null,
353
+ "./parakeet_runtime_bg.js": import0,
354
+ };
355
+ }
356
+
357
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
358
+ ? { register: () => {}, unregister: () => {} }
359
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
360
+ const wbg_rayon_PoolBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
361
+ ? { register: () => {}, unregister: () => {} }
362
+ : new FinalizationRegistry(ptr => wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 1));
363
+
364
+ function addToExternrefTable0(obj) {
365
+ const idx = wasm.__externref_table_alloc();
366
+ wasm.__wbindgen_externrefs.set(idx, obj);
367
+ return idx;
368
+ }
369
+
370
+ let cachedFloat32ArrayMemory0 = null;
371
+ function getFloat32ArrayMemory0() {
372
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.buffer !== wasm.memory.buffer) {
373
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
374
+ }
375
+ return cachedFloat32ArrayMemory0;
376
+ }
377
+
378
+ function getStringFromWasm0(ptr, len) {
379
+ return decodeText(ptr >>> 0, len);
380
+ }
381
+
382
+ let cachedUint8ArrayMemory0 = null;
383
+ function getUint8ArrayMemory0() {
384
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
385
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
386
+ }
387
+ return cachedUint8ArrayMemory0;
388
+ }
389
+
390
+ function isLikeNone(x) {
391
+ return x === undefined || x === null;
392
+ }
393
+
394
+ function passArray8ToWasm0(arg, malloc) {
395
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
396
+ getUint8ArrayMemory0().set(arg, ptr / 1);
397
+ WASM_VECTOR_LEN = arg.length;
398
+ return ptr;
399
+ }
400
+
401
+ function passArrayF32ToWasm0(arg, malloc) {
402
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
403
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
404
+ WASM_VECTOR_LEN = arg.length;
405
+ return ptr;
406
+ }
407
+
408
+ function passStringToWasm0(arg, malloc, realloc) {
409
+ if (realloc === undefined) {
410
+ const buf = cachedTextEncoder.encode(arg);
411
+ const ptr = malloc(buf.length, 1) >>> 0;
412
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
413
+ WASM_VECTOR_LEN = buf.length;
414
+ return ptr;
415
+ }
416
+
417
+ let len = arg.length;
418
+ let ptr = malloc(len, 1) >>> 0;
419
+
420
+ const mem = getUint8ArrayMemory0();
421
+
422
+ let offset = 0;
423
+
424
+ for (; offset < len; offset++) {
425
+ const code = arg.charCodeAt(offset);
426
+ if (code > 0x7F) break;
427
+ mem[ptr + offset] = code;
428
+ }
429
+ if (offset !== len) {
430
+ if (offset !== 0) {
431
+ arg = arg.slice(offset);
432
+ }
433
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
434
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
435
+ const ret = cachedTextEncoder.encodeInto(arg, view);
436
+
437
+ offset += ret.written;
438
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
439
+ }
440
+
441
+ WASM_VECTOR_LEN = offset;
442
+ return ptr;
443
+ }
444
+
445
+ function takeFromExternrefTable0(idx) {
446
+ const value = wasm.__wbindgen_externrefs.get(idx);
447
+ wasm.__externref_table_dealloc(idx);
448
+ return value;
449
+ }
450
+
451
+ let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : undefined);
452
+ if (cachedTextDecoder) cachedTextDecoder.decode();
453
+
454
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
455
+ let numBytesDecoded = 0;
456
+ function decodeText(ptr, len) {
457
+ numBytesDecoded += len;
458
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
459
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
460
+ cachedTextDecoder.decode();
461
+ numBytesDecoded = len;
462
+ }
463
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));
464
+ }
465
+
466
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined);
467
+
468
+ if (cachedTextEncoder) {
469
+ cachedTextEncoder.encodeInto = function (arg, view) {
470
+ const buf = cachedTextEncoder.encode(arg);
471
+ view.set(buf);
472
+ return {
473
+ read: arg.length,
474
+ written: buf.length
475
+ };
476
+ };
477
+ }
478
+
479
+ let WASM_VECTOR_LEN = 0;
480
+
481
+ let wasmModule, wasmInstance, wasm;
482
+ function __wbg_finalize_init(instance, module, thread_stack_size) {
483
+ wasmInstance = instance;
484
+ wasm = instance.exports;
485
+ wasmModule = module;
486
+ cachedFloat32ArrayMemory0 = null;
487
+ cachedUint8ArrayMemory0 = null;
488
+ if (typeof thread_stack_size !== 'undefined' && (typeof thread_stack_size !== 'number' || thread_stack_size === 0 || thread_stack_size % 65536 !== 0)) {
489
+ throw new Error('invalid stack size');
490
+ }
491
+
492
+ wasm.__wbindgen_start(thread_stack_size);
493
+ return wasm;
494
+ }
495
+
496
+ async function __wbg_load(module, imports) {
497
+ if (typeof Response === 'function' && module instanceof Response) {
498
+ if (!module.ok) {
499
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
500
+ }
501
+
502
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
503
+ try {
504
+ return await WebAssembly.instantiateStreaming(module, imports);
505
+ } catch (e) {
506
+ const validResponse = expectedResponseType(module.type);
507
+
508
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
509
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
510
+
511
+ } else { throw e; }
512
+ }
513
+ }
514
+
515
+ const bytes = await module.arrayBuffer();
516
+ return await WebAssembly.instantiate(bytes, imports);
517
+ } else {
518
+ const instance = await WebAssembly.instantiate(module, imports);
519
+
520
+ if (instance instanceof WebAssembly.Instance) {
521
+ return { instance, module };
522
+ } else {
523
+ return instance;
524
+ }
525
+ }
526
+
527
+ function expectedResponseType(type) {
528
+ switch (type) {
529
+ case 'basic': case 'cors': case 'default': return true;
530
+ }
531
+ return false;
532
+ }
533
+ }
534
+
535
+ function initSync(module, memory) {
536
+ if (wasm !== undefined) return wasm;
537
+
538
+ let thread_stack_size
539
+ if (module !== undefined) {
540
+ if (Object.getPrototypeOf(module) === Object.prototype) {
541
+ ({module, memory, thread_stack_size} = module)
542
+ } else {
543
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
544
+ }
545
+ }
546
+
547
+ const imports = __wbg_get_imports(memory);
548
+ if (!(module instanceof WebAssembly.Module)) {
549
+ module = new WebAssembly.Module(module);
550
+ }
551
+ const instance = new WebAssembly.Instance(module, imports);
552
+ return __wbg_finalize_init(instance, module, thread_stack_size);
553
+ }
554
+
555
+ async function __wbg_init(module_or_path, memory) {
556
+ if (wasm !== undefined) return wasm;
557
+
558
+ let thread_stack_size
559
+ if (module_or_path !== undefined) {
560
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
561
+ ({module_or_path, memory, thread_stack_size} = module_or_path)
562
+ } else {
563
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
564
+ }
565
+ }
566
+
567
+ if (module_or_path === undefined) {
568
+ module_or_path = new URL('parakeet_runtime_bg.wasm', import.meta.url);
569
+ }
570
+ const imports = __wbg_get_imports(memory);
571
+
572
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
573
+ module_or_path = fetch(module_or_path);
574
+ }
575
+
576
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
577
+
578
+ return __wbg_finalize_init(instance, module, thread_stack_size);
579
+ }
580
+
581
+ export { initSync, __wbg_init as default };
engine/dist/parakeet/web-threaded-relaxed/parakeet_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40066138207f4edd7d359dfa6e3d88cbef292a4bc451909cc8333cb337fac7b0
3
+ size 1308101
engine/dist/parakeet/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ // The messages between a threaded runtime's thread host (thread-host.js, in the engine worker
2
+ // and in each compute worker) and the page's compute pool (compute.js). `build-runtime.sh` copies
3
+ // this file next to the thread host.
4
+
5
+ export const SPAWN_COMPUTE = 'fusor-ai-spawn-compute';
6
+ export const RAYON_INIT = 'fusor-ai-rayon-init';
7
+ export const RAYON_READY = 'fusor-ai-rayon-ready';
8
+ export const RAYON_ERROR = 'fusor-ai-rayon-error';
engine/dist/parakeet/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The thread host for wasm-bindgen-rayon 1.3.0. `scripts/build-runtime.sh` copies it over the
2
+ // adapter's `workerHelpers.no-bundler.js`, keeping the adapter's public PoolBuilder ABI (the same
3
+ // approach as fusor's worker host, crates/fusor-cli/src/pipeline/workers/rayon.js in the fusor
4
+ // repository).
5
+ //
6
+ // Two differences from the stock adapter:
7
+ // - it fetches nothing (the stock one re-downloads itself to make a blob URL);
8
+ // - the page, not the runtime's worker, creates every compute worker, so the page can always
9
+ // terminate the whole pool, and a blocked coordinator cannot leak threads.
10
+ //
11
+ // As a compute worker: wait for an init message, instantiate the same verified module on the
12
+ // shared memory, then run Rayon's worker loop. As a module imported by the runtime glue:
13
+ // export `startWorkers`, which asks the page for workers and waits until they are all ready.
14
+
15
+ import { RAYON_ERROR, RAYON_INIT, RAYON_READY, SPAWN_COMPUTE } from './protocol.js';
16
+
17
+ self.addEventListener('message', ({ data }) => {
18
+ if (data?.type !== RAYON_INIT) return;
19
+ initialize(data).catch((error) => {
20
+ postMessage({ type: RAYON_ERROR, message: String(error) });
21
+ self.close();
22
+ });
23
+ });
24
+
25
+ async function initialize(data) {
26
+ const pkg = await import(data.mainJS);
27
+ pkg.initSync({ module: data.module, memory: data.memory });
28
+ postMessage({ type: RAYON_READY });
29
+ pkg.wbg_rayon_start_worker(data.receiver);
30
+ }
31
+
32
+ export async function startWorkers(module, memory, builder) {
33
+ const count = builder.numThreads();
34
+ if (count === 0) throw new Error('num_threads must be > 0');
35
+ const channel = new MessageChannel();
36
+ try {
37
+ await new Promise((resolve, reject) => {
38
+ channel.port1.onmessage = ({ data }) => (data.ready ? resolve() : reject(new Error(data.error)));
39
+ const spawn = {
40
+ type: SPAWN_COMPUTE,
41
+ url: import.meta.url,
42
+ count,
43
+ module,
44
+ memory,
45
+ receiver: builder.receiver(),
46
+ mainJS: builder.mainJS(),
47
+ port: channel.port2,
48
+ };
49
+ postMessage(spawn, [channel.port2]);
50
+ });
51
+ builder.build();
52
+ } finally {
53
+ channel.port1.close();
54
+ }
55
+ }
engine/dist/parakeet/web-threaded/parakeet_runtime.js ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { startWorkers } from './snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js';
2
+
3
+
4
+ export class Runtime {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ RuntimeFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_runtime_free(ptr, 0);
14
+ }
15
+ cancel() {
16
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
17
+ if (ret[1]) {
18
+ throw takeFromExternrefTable0(ret[0]);
19
+ }
20
+ }
21
+ /**
22
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
23
+ * whether the engine is ready.
24
+ * @param {number} part
25
+ * @returns {boolean}
26
+ */
27
+ end_part(part) {
28
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
29
+ if (ret[2]) {
30
+ throw takeFromExternrefTable0(ret[1]);
31
+ }
32
+ return ret[0] !== 0;
33
+ }
34
+ /**
35
+ * Makes everything heard final; returns `{"committed","provisional","heard"}`.
36
+ * @returns {string}
37
+ */
38
+ finish() {
39
+ let deferred2_0;
40
+ let deferred2_1;
41
+ try {
42
+ const ret = wasm.runtime_finish(this.__wbg_ptr);
43
+ var ptr1 = ret[0];
44
+ var len1 = ret[1];
45
+ if (ret[3]) {
46
+ ptr1 = 0; len1 = 0;
47
+ throw takeFromExternrefTable0(ret[2]);
48
+ }
49
+ deferred2_0 = ptr1;
50
+ deferred2_1 = len1;
51
+ return getStringFromWasm0(ptr1, len1);
52
+ } finally {
53
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
54
+ }
55
+ }
56
+ /**
57
+ * The next live samples (16 kHz mono).
58
+ * @param {Float32Array} samples
59
+ */
60
+ hear(samples) {
61
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
62
+ const len0 = WASM_VECTOR_LEN;
63
+ const ret = wasm.runtime_hear(this.__wbg_ptr, ptr0, len0);
64
+ if (ret[1]) {
65
+ throw takeFromExternrefTable0(ret[0]);
66
+ }
67
+ }
68
+ /**
69
+ * Starts listening to live audio afresh.
70
+ */
71
+ listen() {
72
+ const ret = wasm.runtime_listen(this.__wbg_ptr);
73
+ if (ret[1]) {
74
+ throw takeFromExternrefTable0(ret[0]);
75
+ }
76
+ }
77
+ /**
78
+ * @param {string} manifest_json
79
+ */
80
+ constructor(manifest_json) {
81
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
82
+ const len0 = WASM_VECTOR_LEN;
83
+ const ret = wasm.runtime_new(ptr0, len0);
84
+ if (ret[2]) {
85
+ throw takeFromExternrefTable0(ret[1]);
86
+ }
87
+ this.__wbg_ptr = ret[0];
88
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
89
+ return this;
90
+ }
91
+ /**
92
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
93
+ * again.
94
+ * @param {number} part
95
+ */
96
+ restart_part(part) {
97
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
98
+ if (ret[1]) {
99
+ throw takeFromExternrefTable0(ret[0]);
100
+ }
101
+ }
102
+ /**
103
+ * Starts transcribing a recording (16 kHz mono); returns its plan
104
+ * (`{"segments": [{"start","end"}], "seconds"}`).
105
+ * @param {Float32Array} pcm
106
+ * @returns {string}
107
+ */
108
+ start(pcm) {
109
+ let deferred3_0;
110
+ let deferred3_1;
111
+ try {
112
+ const ptr0 = passArrayF32ToWasm0(pcm, wasm.__wbindgen_malloc);
113
+ const len0 = WASM_VECTOR_LEN;
114
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
115
+ var ptr2 = ret[0];
116
+ var len2 = ret[1];
117
+ if (ret[3]) {
118
+ ptr2 = 0; len2 = 0;
119
+ throw takeFromExternrefTable0(ret[2]);
120
+ }
121
+ deferred3_0 = ptr2;
122
+ deferred3_1 = len2;
123
+ return getStringFromWasm0(ptr2, len2);
124
+ } finally {
125
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
126
+ }
127
+ }
128
+ /**
129
+ * Transcribes the next segment; returns `{"segment","segments","sentences","done"}`, each
130
+ * sentence `{"text","start","end"}` in seconds.
131
+ * @returns {string}
132
+ */
133
+ step() {
134
+ let deferred2_0;
135
+ let deferred2_1;
136
+ try {
137
+ const ret = wasm.runtime_step(this.__wbg_ptr);
138
+ var ptr1 = ret[0];
139
+ var len1 = ret[1];
140
+ if (ret[3]) {
141
+ ptr1 = 0; len1 = 0;
142
+ throw takeFromExternrefTable0(ret[2]);
143
+ }
144
+ deferred2_0 = ptr1;
145
+ deferred2_1 = len1;
146
+ return getStringFromWasm0(ptr1, len1);
147
+ } finally {
148
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
149
+ }
150
+ }
151
+ /**
152
+ * @returns {number}
153
+ */
154
+ threads() {
155
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
156
+ if (ret[2]) {
157
+ throw takeFromExternrefTable0(ret[1]);
158
+ }
159
+ return ret[0] >>> 0;
160
+ }
161
+ /**
162
+ * Transcribes what was heard; returns `{"committed","provisional","heard"}`.
163
+ * @returns {string}
164
+ */
165
+ update() {
166
+ let deferred2_0;
167
+ let deferred2_1;
168
+ try {
169
+ const ret = wasm.runtime_update(this.__wbg_ptr);
170
+ var ptr1 = ret[0];
171
+ var len1 = ret[1];
172
+ if (ret[3]) {
173
+ ptr1 = 0; len1 = 0;
174
+ throw takeFromExternrefTable0(ret[2]);
175
+ }
176
+ deferred2_0 = ptr1;
177
+ deferred2_1 = len1;
178
+ return getStringFromWasm0(ptr1, len1);
179
+ } finally {
180
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
181
+ }
182
+ }
183
+ /**
184
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
185
+ * @param {number} part
186
+ * @param {Uint8Array} bytes
187
+ */
188
+ write_part(part, bytes) {
189
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
192
+ if (ret[1]) {
193
+ throw takeFromExternrefTable0(ret[0]);
194
+ }
195
+ }
196
+ }
197
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
198
+
199
+ /**
200
+ * @param {number} num_threads
201
+ * @returns {Promise<any>}
202
+ */
203
+ export function initThreadPool(num_threads) {
204
+ const ret = wasm.initThreadPool(num_threads);
205
+ return ret;
206
+ }
207
+
208
+ /**
209
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
210
+ * @returns {string}
211
+ */
212
+ export function last_panic() {
213
+ let deferred1_0;
214
+ let deferred1_1;
215
+ try {
216
+ const ret = wasm.last_panic();
217
+ deferred1_0 = ret[0];
218
+ deferred1_1 = ret[1];
219
+ return getStringFromWasm0(ret[0], ret[1]);
220
+ } finally {
221
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * The rate of the PCM the runtime reads, in Hz.
227
+ * @returns {number}
228
+ */
229
+ export function sample_rate() {
230
+ const ret = wasm.sample_rate();
231
+ return ret >>> 0;
232
+ }
233
+
234
+ export class wbg_rayon_PoolBuilder {
235
+ static __wrap(ptr) {
236
+ const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
237
+ obj.__wbg_ptr = ptr;
238
+ wbg_rayon_PoolBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
239
+ return obj;
240
+ }
241
+ __destroy_into_raw() {
242
+ const ptr = this.__wbg_ptr;
243
+ this.__wbg_ptr = 0;
244
+ wbg_rayon_PoolBuilderFinalization.unregister(this);
245
+ return ptr;
246
+ }
247
+ free() {
248
+ const ptr = this.__destroy_into_raw();
249
+ wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 0);
250
+ }
251
+ build() {
252
+ wasm.wbg_rayon_poolbuilder_build(this.__wbg_ptr);
253
+ }
254
+ /**
255
+ * @returns {string}
256
+ */
257
+ mainJS() {
258
+ const ret = wasm.wbg_rayon_poolbuilder_mainJS(this.__wbg_ptr);
259
+ return ret;
260
+ }
261
+ /**
262
+ * @returns {number}
263
+ */
264
+ numThreads() {
265
+ const ret = wasm.wbg_rayon_poolbuilder_numThreads(this.__wbg_ptr);
266
+ return ret >>> 0;
267
+ }
268
+ /**
269
+ * @returns {number}
270
+ */
271
+ receiver() {
272
+ const ret = wasm.wbg_rayon_poolbuilder_receiver(this.__wbg_ptr);
273
+ return ret >>> 0;
274
+ }
275
+ }
276
+ if (Symbol.dispose) wbg_rayon_PoolBuilder.prototype[Symbol.dispose] = wbg_rayon_PoolBuilder.prototype.free;
277
+
278
+ /**
279
+ * @param {number} receiver
280
+ */
281
+ export function wbg_rayon_start_worker(receiver) {
282
+ wasm.wbg_rayon_start_worker(receiver);
283
+ }
284
+ function __wbg_get_imports(memory) {
285
+ const import0 = {
286
+ __proto__: null,
287
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
288
+ const ret = Error(getStringFromWasm0(arg0, arg1));
289
+ return ret;
290
+ },
291
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
292
+ const ret = arg0 === undefined;
293
+ return ret;
294
+ },
295
+ __wbg___wbindgen_memory_caa4a6165639c8b5: function() {
296
+ const ret = wasm.memory;
297
+ return ret;
298
+ },
299
+ __wbg___wbindgen_module_7115fb14045f9891: function() {
300
+ const ret = wasmModule;
301
+ return ret;
302
+ },
303
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
304
+ throw new Error(getStringFromWasm0(arg0, arg1));
305
+ },
306
+ __wbg_instanceof_Window_82d71df4eddf88bc: function(arg0) {
307
+ let result;
308
+ try {
309
+ result = arg0 instanceof Window;
310
+ } catch (_) {
311
+ result = false;
312
+ }
313
+ const ret = result;
314
+ return ret;
315
+ },
316
+ __wbg_startWorkers_622cedd0d351664e: function(arg0, arg1, arg2) {
317
+ const ret = startWorkers(arg0, arg1, wbg_rayon_PoolBuilder.__wrap(arg2));
318
+ return ret;
319
+ },
320
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
321
+ const ret = typeof global === 'undefined' ? null : global;
322
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
323
+ },
324
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
325
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
326
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
327
+ },
328
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
329
+ const ret = typeof self === 'undefined' ? null : self;
330
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
331
+ },
332
+ __wbg_static_accessor_URL_fac851ed3060f4eb: function() {
333
+ const ret = import.meta.url;
334
+ return ret;
335
+ },
336
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
337
+ const ret = typeof window === 'undefined' ? null : window;
338
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
339
+ },
340
+ __wbindgen_init_externref_table: function() {
341
+ const table = wasm.__wbindgen_externrefs;
342
+ const offset = table.grow(4);
343
+ table.set(0, undefined);
344
+ table.set(offset + 0, undefined);
345
+ table.set(offset + 1, null);
346
+ table.set(offset + 2, true);
347
+ table.set(offset + 3, false);
348
+ },
349
+ memory: memory || new WebAssembly.Memory({initial:19,maximum:65536,shared:true}),
350
+ };
351
+ return {
352
+ __proto__: null,
353
+ "./parakeet_runtime_bg.js": import0,
354
+ };
355
+ }
356
+
357
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
358
+ ? { register: () => {}, unregister: () => {} }
359
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
360
+ const wbg_rayon_PoolBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
361
+ ? { register: () => {}, unregister: () => {} }
362
+ : new FinalizationRegistry(ptr => wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 1));
363
+
364
+ function addToExternrefTable0(obj) {
365
+ const idx = wasm.__externref_table_alloc();
366
+ wasm.__wbindgen_externrefs.set(idx, obj);
367
+ return idx;
368
+ }
369
+
370
+ let cachedFloat32ArrayMemory0 = null;
371
+ function getFloat32ArrayMemory0() {
372
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.buffer !== wasm.memory.buffer) {
373
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
374
+ }
375
+ return cachedFloat32ArrayMemory0;
376
+ }
377
+
378
+ function getStringFromWasm0(ptr, len) {
379
+ return decodeText(ptr >>> 0, len);
380
+ }
381
+
382
+ let cachedUint8ArrayMemory0 = null;
383
+ function getUint8ArrayMemory0() {
384
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
385
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
386
+ }
387
+ return cachedUint8ArrayMemory0;
388
+ }
389
+
390
+ function isLikeNone(x) {
391
+ return x === undefined || x === null;
392
+ }
393
+
394
+ function passArray8ToWasm0(arg, malloc) {
395
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
396
+ getUint8ArrayMemory0().set(arg, ptr / 1);
397
+ WASM_VECTOR_LEN = arg.length;
398
+ return ptr;
399
+ }
400
+
401
+ function passArrayF32ToWasm0(arg, malloc) {
402
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
403
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
404
+ WASM_VECTOR_LEN = arg.length;
405
+ return ptr;
406
+ }
407
+
408
+ function passStringToWasm0(arg, malloc, realloc) {
409
+ if (realloc === undefined) {
410
+ const buf = cachedTextEncoder.encode(arg);
411
+ const ptr = malloc(buf.length, 1) >>> 0;
412
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
413
+ WASM_VECTOR_LEN = buf.length;
414
+ return ptr;
415
+ }
416
+
417
+ let len = arg.length;
418
+ let ptr = malloc(len, 1) >>> 0;
419
+
420
+ const mem = getUint8ArrayMemory0();
421
+
422
+ let offset = 0;
423
+
424
+ for (; offset < len; offset++) {
425
+ const code = arg.charCodeAt(offset);
426
+ if (code > 0x7F) break;
427
+ mem[ptr + offset] = code;
428
+ }
429
+ if (offset !== len) {
430
+ if (offset !== 0) {
431
+ arg = arg.slice(offset);
432
+ }
433
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
434
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
435
+ const ret = cachedTextEncoder.encodeInto(arg, view);
436
+
437
+ offset += ret.written;
438
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
439
+ }
440
+
441
+ WASM_VECTOR_LEN = offset;
442
+ return ptr;
443
+ }
444
+
445
+ function takeFromExternrefTable0(idx) {
446
+ const value = wasm.__wbindgen_externrefs.get(idx);
447
+ wasm.__externref_table_dealloc(idx);
448
+ return value;
449
+ }
450
+
451
+ let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : undefined);
452
+ if (cachedTextDecoder) cachedTextDecoder.decode();
453
+
454
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
455
+ let numBytesDecoded = 0;
456
+ function decodeText(ptr, len) {
457
+ numBytesDecoded += len;
458
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
459
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
460
+ cachedTextDecoder.decode();
461
+ numBytesDecoded = len;
462
+ }
463
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));
464
+ }
465
+
466
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined);
467
+
468
+ if (cachedTextEncoder) {
469
+ cachedTextEncoder.encodeInto = function (arg, view) {
470
+ const buf = cachedTextEncoder.encode(arg);
471
+ view.set(buf);
472
+ return {
473
+ read: arg.length,
474
+ written: buf.length
475
+ };
476
+ };
477
+ }
478
+
479
+ let WASM_VECTOR_LEN = 0;
480
+
481
+ let wasmModule, wasmInstance, wasm;
482
+ function __wbg_finalize_init(instance, module, thread_stack_size) {
483
+ wasmInstance = instance;
484
+ wasm = instance.exports;
485
+ wasmModule = module;
486
+ cachedFloat32ArrayMemory0 = null;
487
+ cachedUint8ArrayMemory0 = null;
488
+ if (typeof thread_stack_size !== 'undefined' && (typeof thread_stack_size !== 'number' || thread_stack_size === 0 || thread_stack_size % 65536 !== 0)) {
489
+ throw new Error('invalid stack size');
490
+ }
491
+
492
+ wasm.__wbindgen_start(thread_stack_size);
493
+ return wasm;
494
+ }
495
+
496
+ async function __wbg_load(module, imports) {
497
+ if (typeof Response === 'function' && module instanceof Response) {
498
+ if (!module.ok) {
499
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
500
+ }
501
+
502
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
503
+ try {
504
+ return await WebAssembly.instantiateStreaming(module, imports);
505
+ } catch (e) {
506
+ const validResponse = expectedResponseType(module.type);
507
+
508
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
509
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
510
+
511
+ } else { throw e; }
512
+ }
513
+ }
514
+
515
+ const bytes = await module.arrayBuffer();
516
+ return await WebAssembly.instantiate(bytes, imports);
517
+ } else {
518
+ const instance = await WebAssembly.instantiate(module, imports);
519
+
520
+ if (instance instanceof WebAssembly.Instance) {
521
+ return { instance, module };
522
+ } else {
523
+ return instance;
524
+ }
525
+ }
526
+
527
+ function expectedResponseType(type) {
528
+ switch (type) {
529
+ case 'basic': case 'cors': case 'default': return true;
530
+ }
531
+ return false;
532
+ }
533
+ }
534
+
535
+ function initSync(module, memory) {
536
+ if (wasm !== undefined) return wasm;
537
+
538
+ let thread_stack_size
539
+ if (module !== undefined) {
540
+ if (Object.getPrototypeOf(module) === Object.prototype) {
541
+ ({module, memory, thread_stack_size} = module)
542
+ } else {
543
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
544
+ }
545
+ }
546
+
547
+ const imports = __wbg_get_imports(memory);
548
+ if (!(module instanceof WebAssembly.Module)) {
549
+ module = new WebAssembly.Module(module);
550
+ }
551
+ const instance = new WebAssembly.Instance(module, imports);
552
+ return __wbg_finalize_init(instance, module, thread_stack_size);
553
+ }
554
+
555
+ async function __wbg_init(module_or_path, memory) {
556
+ if (wasm !== undefined) return wasm;
557
+
558
+ let thread_stack_size
559
+ if (module_or_path !== undefined) {
560
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
561
+ ({module_or_path, memory, thread_stack_size} = module_or_path)
562
+ } else {
563
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
564
+ }
565
+ }
566
+
567
+ if (module_or_path === undefined) {
568
+ module_or_path = new URL('parakeet_runtime_bg.wasm', import.meta.url);
569
+ }
570
+ const imports = __wbg_get_imports(memory);
571
+
572
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
573
+ module_or_path = fetch(module_or_path);
574
+ }
575
+
576
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
577
+
578
+ return __wbg_finalize_init(instance, module, thread_stack_size);
579
+ }
580
+
581
+ export { initSync, __wbg_init as default };
engine/dist/parakeet/web-threaded/parakeet_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4465b499dc0d38424b4d78408bc9b99e06823aa05a63ea7c02c678851b75beb
3
+ size 1256432
engine/dist/parakeet/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ // The messages between a threaded runtime's thread host (thread-host.js, in the engine worker
2
+ // and in each compute worker) and the page's compute pool (compute.js). `build-runtime.sh` copies
3
+ // this file next to the thread host.
4
+
5
+ export const SPAWN_COMPUTE = 'fusor-ai-spawn-compute';
6
+ export const RAYON_INIT = 'fusor-ai-rayon-init';
7
+ export const RAYON_READY = 'fusor-ai-rayon-ready';
8
+ export const RAYON_ERROR = 'fusor-ai-rayon-error';
engine/dist/parakeet/web-threaded/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The thread host for wasm-bindgen-rayon 1.3.0. `scripts/build-runtime.sh` copies it over the
2
+ // adapter's `workerHelpers.no-bundler.js`, keeping the adapter's public PoolBuilder ABI (the same
3
+ // approach as fusor's worker host, crates/fusor-cli/src/pipeline/workers/rayon.js in the fusor
4
+ // repository).
5
+ //
6
+ // Two differences from the stock adapter:
7
+ // - it fetches nothing (the stock one re-downloads itself to make a blob URL);
8
+ // - the page, not the runtime's worker, creates every compute worker, so the page can always
9
+ // terminate the whole pool, and a blocked coordinator cannot leak threads.
10
+ //
11
+ // As a compute worker: wait for an init message, instantiate the same verified module on the
12
+ // shared memory, then run Rayon's worker loop. As a module imported by the runtime glue:
13
+ // export `startWorkers`, which asks the page for workers and waits until they are all ready.
14
+
15
+ import { RAYON_ERROR, RAYON_INIT, RAYON_READY, SPAWN_COMPUTE } from './protocol.js';
16
+
17
+ self.addEventListener('message', ({ data }) => {
18
+ if (data?.type !== RAYON_INIT) return;
19
+ initialize(data).catch((error) => {
20
+ postMessage({ type: RAYON_ERROR, message: String(error) });
21
+ self.close();
22
+ });
23
+ });
24
+
25
+ async function initialize(data) {
26
+ const pkg = await import(data.mainJS);
27
+ pkg.initSync({ module: data.module, memory: data.memory });
28
+ postMessage({ type: RAYON_READY });
29
+ pkg.wbg_rayon_start_worker(data.receiver);
30
+ }
31
+
32
+ export async function startWorkers(module, memory, builder) {
33
+ const count = builder.numThreads();
34
+ if (count === 0) throw new Error('num_threads must be > 0');
35
+ const channel = new MessageChannel();
36
+ try {
37
+ await new Promise((resolve, reject) => {
38
+ channel.port1.onmessage = ({ data }) => (data.ready ? resolve() : reject(new Error(data.error)));
39
+ const spawn = {
40
+ type: SPAWN_COMPUTE,
41
+ url: import.meta.url,
42
+ count,
43
+ module,
44
+ memory,
45
+ receiver: builder.receiver(),
46
+ mainJS: builder.mainJS(),
47
+ port: channel.port2,
48
+ };
49
+ postMessage(spawn, [channel.port2]);
50
+ });
51
+ builder.build();
52
+ } finally {
53
+ channel.port1.close();
54
+ }
55
+ }
engine/dist/phonon/web-single-relaxed/phonon_runtime.js ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class Runtime {
2
+ __destroy_into_raw() {
3
+ const ptr = this.__wbg_ptr;
4
+ this.__wbg_ptr = 0;
5
+ RuntimeFinalization.unregister(this);
6
+ return ptr;
7
+ }
8
+ free() {
9
+ const ptr = this.__destroy_into_raw();
10
+ wasm.__wbg_runtime_free(ptr, 0);
11
+ }
12
+ cancel() {
13
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
14
+ if (ret[1]) {
15
+ throw takeFromExternrefTable0(ret[0]);
16
+ }
17
+ }
18
+ /**
19
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
20
+ * whether the engine is ready.
21
+ * @param {number} part
22
+ * @returns {boolean}
23
+ */
24
+ end_part(part) {
25
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] !== 0;
30
+ }
31
+ /**
32
+ * @param {string} manifest_json
33
+ */
34
+ constructor(manifest_json) {
35
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ret = wasm.runtime_new(ptr0, len0);
38
+ if (ret[2]) {
39
+ throw takeFromExternrefTable0(ret[1]);
40
+ }
41
+ this.__wbg_ptr = ret[0];
42
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
43
+ return this;
44
+ }
45
+ /**
46
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
47
+ * again.
48
+ * @param {number} part
49
+ */
50
+ restart_part(part) {
51
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
52
+ if (ret[1]) {
53
+ throw takeFromExternrefTable0(ret[0]);
54
+ }
55
+ }
56
+ /**
57
+ * Starts a synthesis (`session::Request` as JSON); returns the plan (`{"fragments"}`).
58
+ * @param {string} request_json
59
+ * @returns {string}
60
+ */
61
+ start(request_json) {
62
+ let deferred3_0;
63
+ let deferred3_1;
64
+ try {
65
+ const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
+ const len0 = WASM_VECTOR_LEN;
67
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
68
+ var ptr2 = ret[0];
69
+ var len2 = ret[1];
70
+ if (ret[3]) {
71
+ ptr2 = 0; len2 = 0;
72
+ throw takeFromExternrefTable0(ret[2]);
73
+ }
74
+ deferred3_0 = ptr2;
75
+ deferred3_1 = len2;
76
+ return getStringFromWasm0(ptr2, len2);
77
+ } finally {
78
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
79
+ }
80
+ }
81
+ /**
82
+ * One frame; returns `{"fragment","fragments","frame","done"}`.
83
+ * @returns {string}
84
+ */
85
+ step() {
86
+ let deferred2_0;
87
+ let deferred2_1;
88
+ try {
89
+ const ret = wasm.runtime_step(this.__wbg_ptr);
90
+ var ptr1 = ret[0];
91
+ var len1 = ret[1];
92
+ if (ret[3]) {
93
+ ptr1 = 0; len1 = 0;
94
+ throw takeFromExternrefTable0(ret[2]);
95
+ }
96
+ deferred2_0 = ptr1;
97
+ deferred2_1 = len1;
98
+ return getStringFromWasm0(ptr1, len1);
99
+ } finally {
100
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
101
+ }
102
+ }
103
+ /**
104
+ * The samples (mono, `sample_rate()` Hz) produced since the last call.
105
+ * @returns {Float32Array}
106
+ */
107
+ take_audio() {
108
+ const ret = wasm.runtime_take_audio(this.__wbg_ptr);
109
+ if (ret[3]) {
110
+ throw takeFromExternrefTable0(ret[2]);
111
+ }
112
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
113
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
114
+ return v1;
115
+ }
116
+ /**
117
+ * @returns {number}
118
+ */
119
+ threads() {
120
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
121
+ if (ret[2]) {
122
+ throw takeFromExternrefTable0(ret[1]);
123
+ }
124
+ return ret[0] >>> 0;
125
+ }
126
+ /**
127
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
128
+ * @param {number} part
129
+ * @param {Uint8Array} bytes
130
+ */
131
+ write_part(part, bytes) {
132
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
135
+ if (ret[1]) {
136
+ throw takeFromExternrefTable0(ret[0]);
137
+ }
138
+ }
139
+ }
140
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
141
+
142
+ /**
143
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
144
+ * @returns {string}
145
+ */
146
+ export function last_panic() {
147
+ let deferred1_0;
148
+ let deferred1_1;
149
+ try {
150
+ const ret = wasm.last_panic();
151
+ deferred1_0 = ret[0];
152
+ deferred1_1 = ret[1];
153
+ return getStringFromWasm0(ret[0], ret[1]);
154
+ } finally {
155
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
156
+ }
157
+ }
158
+
159
+ /**
160
+ * The rate of the PCM `take_audio` returns, in Hz.
161
+ * @returns {number}
162
+ */
163
+ export function sample_rate() {
164
+ const ret = wasm.sample_rate();
165
+ return ret >>> 0;
166
+ }
167
+
168
+ /**
169
+ * `[{"id","label"}]` of the built-in voices.
170
+ * @returns {string}
171
+ */
172
+ export function voices() {
173
+ let deferred1_0;
174
+ let deferred1_1;
175
+ try {
176
+ const ret = wasm.voices();
177
+ deferred1_0 = ret[0];
178
+ deferred1_1 = ret[1];
179
+ return getStringFromWasm0(ret[0], ret[1]);
180
+ } finally {
181
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
182
+ }
183
+ }
184
+
185
+ /**
186
+ * `samples` as a 16-bit PCM WAV file at `sample_rate()`.
187
+ * @param {Float32Array} samples
188
+ * @returns {Uint8Array}
189
+ */
190
+ export function wav(samples) {
191
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
192
+ const len0 = WASM_VECTOR_LEN;
193
+ const ret = wasm.wav(ptr0, len0);
194
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
195
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
196
+ return v2;
197
+ }
198
+ function __wbg_get_imports() {
199
+ const import0 = {
200
+ __proto__: null,
201
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
202
+ const ret = Error(getStringFromWasm0(arg0, arg1));
203
+ return ret;
204
+ },
205
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
206
+ throw new Error(getStringFromWasm0(arg0, arg1));
207
+ },
208
+ __wbindgen_init_externref_table: function() {
209
+ const table = wasm.__wbindgen_externrefs;
210
+ const offset = table.grow(4);
211
+ table.set(0, undefined);
212
+ table.set(offset + 0, undefined);
213
+ table.set(offset + 1, null);
214
+ table.set(offset + 2, true);
215
+ table.set(offset + 3, false);
216
+ },
217
+ };
218
+ return {
219
+ __proto__: null,
220
+ "./phonon_runtime_bg.js": import0,
221
+ };
222
+ }
223
+
224
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
225
+ ? { register: () => {}, unregister: () => {} }
226
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
227
+
228
+ function getArrayF32FromWasm0(ptr, len) {
229
+ ptr = ptr >>> 0;
230
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
231
+ }
232
+
233
+ function getArrayU8FromWasm0(ptr, len) {
234
+ ptr = ptr >>> 0;
235
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
236
+ }
237
+
238
+ let cachedFloat32ArrayMemory0 = null;
239
+ function getFloat32ArrayMemory0() {
240
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
241
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
242
+ }
243
+ return cachedFloat32ArrayMemory0;
244
+ }
245
+
246
+ function getStringFromWasm0(ptr, len) {
247
+ return decodeText(ptr >>> 0, len);
248
+ }
249
+
250
+ let cachedUint8ArrayMemory0 = null;
251
+ function getUint8ArrayMemory0() {
252
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
253
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
254
+ }
255
+ return cachedUint8ArrayMemory0;
256
+ }
257
+
258
+ function passArray8ToWasm0(arg, malloc) {
259
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
260
+ getUint8ArrayMemory0().set(arg, ptr / 1);
261
+ WASM_VECTOR_LEN = arg.length;
262
+ return ptr;
263
+ }
264
+
265
+ function passArrayF32ToWasm0(arg, malloc) {
266
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
267
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
268
+ WASM_VECTOR_LEN = arg.length;
269
+ return ptr;
270
+ }
271
+
272
+ function passStringToWasm0(arg, malloc, realloc) {
273
+ if (realloc === undefined) {
274
+ const buf = cachedTextEncoder.encode(arg);
275
+ const ptr = malloc(buf.length, 1) >>> 0;
276
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
277
+ WASM_VECTOR_LEN = buf.length;
278
+ return ptr;
279
+ }
280
+
281
+ let len = arg.length;
282
+ let ptr = malloc(len, 1) >>> 0;
283
+
284
+ const mem = getUint8ArrayMemory0();
285
+
286
+ let offset = 0;
287
+
288
+ for (; offset < len; offset++) {
289
+ const code = arg.charCodeAt(offset);
290
+ if (code > 0x7F) break;
291
+ mem[ptr + offset] = code;
292
+ }
293
+ if (offset !== len) {
294
+ if (offset !== 0) {
295
+ arg = arg.slice(offset);
296
+ }
297
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
298
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
299
+ const ret = cachedTextEncoder.encodeInto(arg, view);
300
+
301
+ offset += ret.written;
302
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
303
+ }
304
+
305
+ WASM_VECTOR_LEN = offset;
306
+ return ptr;
307
+ }
308
+
309
+ function takeFromExternrefTable0(idx) {
310
+ const value = wasm.__wbindgen_externrefs.get(idx);
311
+ wasm.__externref_table_dealloc(idx);
312
+ return value;
313
+ }
314
+
315
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
316
+ cachedTextDecoder.decode();
317
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
318
+ let numBytesDecoded = 0;
319
+ function decodeText(ptr, len) {
320
+ numBytesDecoded += len;
321
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
322
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
323
+ cachedTextDecoder.decode();
324
+ numBytesDecoded = len;
325
+ }
326
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
327
+ }
328
+
329
+ const cachedTextEncoder = new TextEncoder();
330
+
331
+ if (!('encodeInto' in cachedTextEncoder)) {
332
+ cachedTextEncoder.encodeInto = function (arg, view) {
333
+ const buf = cachedTextEncoder.encode(arg);
334
+ view.set(buf);
335
+ return {
336
+ read: arg.length,
337
+ written: buf.length
338
+ };
339
+ };
340
+ }
341
+
342
+ let WASM_VECTOR_LEN = 0;
343
+
344
+ let wasmModule, wasmInstance, wasm;
345
+ function __wbg_finalize_init(instance, module) {
346
+ wasmInstance = instance;
347
+ wasm = instance.exports;
348
+ wasmModule = module;
349
+ cachedFloat32ArrayMemory0 = null;
350
+ cachedUint8ArrayMemory0 = null;
351
+ wasm.__wbindgen_start();
352
+ return wasm;
353
+ }
354
+
355
+ async function __wbg_load(module, imports) {
356
+ if (typeof Response === 'function' && module instanceof Response) {
357
+ if (!module.ok) {
358
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
359
+ }
360
+
361
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
362
+ try {
363
+ return await WebAssembly.instantiateStreaming(module, imports);
364
+ } catch (e) {
365
+ const validResponse = expectedResponseType(module.type);
366
+
367
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
368
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
369
+
370
+ } else { throw e; }
371
+ }
372
+ }
373
+
374
+ const bytes = await module.arrayBuffer();
375
+ return await WebAssembly.instantiate(bytes, imports);
376
+ } else {
377
+ const instance = await WebAssembly.instantiate(module, imports);
378
+
379
+ if (instance instanceof WebAssembly.Instance) {
380
+ return { instance, module };
381
+ } else {
382
+ return instance;
383
+ }
384
+ }
385
+
386
+ function expectedResponseType(type) {
387
+ switch (type) {
388
+ case 'basic': case 'cors': case 'default': return true;
389
+ }
390
+ return false;
391
+ }
392
+ }
393
+
394
+ function initSync(module) {
395
+ if (wasm !== undefined) return wasm;
396
+
397
+
398
+ if (module !== undefined) {
399
+ if (Object.getPrototypeOf(module) === Object.prototype) {
400
+ ({module} = module)
401
+ } else {
402
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
403
+ }
404
+ }
405
+
406
+ const imports = __wbg_get_imports();
407
+ if (!(module instanceof WebAssembly.Module)) {
408
+ module = new WebAssembly.Module(module);
409
+ }
410
+ const instance = new WebAssembly.Instance(module, imports);
411
+ return __wbg_finalize_init(instance, module);
412
+ }
413
+
414
+ async function __wbg_init(module_or_path) {
415
+ if (wasm !== undefined) return wasm;
416
+
417
+
418
+ if (module_or_path !== undefined) {
419
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
420
+ ({module_or_path} = module_or_path)
421
+ } else {
422
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
423
+ }
424
+ }
425
+
426
+ if (module_or_path === undefined) {
427
+ module_or_path = new URL('phonon_runtime_bg.wasm', import.meta.url);
428
+ }
429
+ const imports = __wbg_get_imports();
430
+
431
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
432
+ module_or_path = fetch(module_or_path);
433
+ }
434
+
435
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
436
+
437
+ return __wbg_finalize_init(instance, module);
438
+ }
439
+
440
+ export { initSync, __wbg_init as default };
engine/dist/phonon/web-single-relaxed/phonon_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23bd49e3623a808c0ff28a67bedef23ed02478cae3f601b2ab4977a2a845d657
3
+ size 2883386
engine/dist/phonon/web-single/phonon_runtime.js ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export class Runtime {
2
+ __destroy_into_raw() {
3
+ const ptr = this.__wbg_ptr;
4
+ this.__wbg_ptr = 0;
5
+ RuntimeFinalization.unregister(this);
6
+ return ptr;
7
+ }
8
+ free() {
9
+ const ptr = this.__destroy_into_raw();
10
+ wasm.__wbg_runtime_free(ptr, 0);
11
+ }
12
+ cancel() {
13
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
14
+ if (ret[1]) {
15
+ throw takeFromExternrefTable0(ret[0]);
16
+ }
17
+ }
18
+ /**
19
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
20
+ * whether the engine is ready.
21
+ * @param {number} part
22
+ * @returns {boolean}
23
+ */
24
+ end_part(part) {
25
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] !== 0;
30
+ }
31
+ /**
32
+ * @param {string} manifest_json
33
+ */
34
+ constructor(manifest_json) {
35
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
36
+ const len0 = WASM_VECTOR_LEN;
37
+ const ret = wasm.runtime_new(ptr0, len0);
38
+ if (ret[2]) {
39
+ throw takeFromExternrefTable0(ret[1]);
40
+ }
41
+ this.__wbg_ptr = ret[0];
42
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
43
+ return this;
44
+ }
45
+ /**
46
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
47
+ * again.
48
+ * @param {number} part
49
+ */
50
+ restart_part(part) {
51
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
52
+ if (ret[1]) {
53
+ throw takeFromExternrefTable0(ret[0]);
54
+ }
55
+ }
56
+ /**
57
+ * Starts a synthesis (`session::Request` as JSON); returns the plan (`{"fragments"}`).
58
+ * @param {string} request_json
59
+ * @returns {string}
60
+ */
61
+ start(request_json) {
62
+ let deferred3_0;
63
+ let deferred3_1;
64
+ try {
65
+ const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
+ const len0 = WASM_VECTOR_LEN;
67
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
68
+ var ptr2 = ret[0];
69
+ var len2 = ret[1];
70
+ if (ret[3]) {
71
+ ptr2 = 0; len2 = 0;
72
+ throw takeFromExternrefTable0(ret[2]);
73
+ }
74
+ deferred3_0 = ptr2;
75
+ deferred3_1 = len2;
76
+ return getStringFromWasm0(ptr2, len2);
77
+ } finally {
78
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
79
+ }
80
+ }
81
+ /**
82
+ * One frame; returns `{"fragment","fragments","frame","done"}`.
83
+ * @returns {string}
84
+ */
85
+ step() {
86
+ let deferred2_0;
87
+ let deferred2_1;
88
+ try {
89
+ const ret = wasm.runtime_step(this.__wbg_ptr);
90
+ var ptr1 = ret[0];
91
+ var len1 = ret[1];
92
+ if (ret[3]) {
93
+ ptr1 = 0; len1 = 0;
94
+ throw takeFromExternrefTable0(ret[2]);
95
+ }
96
+ deferred2_0 = ptr1;
97
+ deferred2_1 = len1;
98
+ return getStringFromWasm0(ptr1, len1);
99
+ } finally {
100
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
101
+ }
102
+ }
103
+ /**
104
+ * The samples (mono, `sample_rate()` Hz) produced since the last call.
105
+ * @returns {Float32Array}
106
+ */
107
+ take_audio() {
108
+ const ret = wasm.runtime_take_audio(this.__wbg_ptr);
109
+ if (ret[3]) {
110
+ throw takeFromExternrefTable0(ret[2]);
111
+ }
112
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
113
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
114
+ return v1;
115
+ }
116
+ /**
117
+ * @returns {number}
118
+ */
119
+ threads() {
120
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
121
+ if (ret[2]) {
122
+ throw takeFromExternrefTable0(ret[1]);
123
+ }
124
+ return ret[0] >>> 0;
125
+ }
126
+ /**
127
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
128
+ * @param {number} part
129
+ * @param {Uint8Array} bytes
130
+ */
131
+ write_part(part, bytes) {
132
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
135
+ if (ret[1]) {
136
+ throw takeFromExternrefTable0(ret[0]);
137
+ }
138
+ }
139
+ }
140
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
141
+
142
+ /**
143
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
144
+ * @returns {string}
145
+ */
146
+ export function last_panic() {
147
+ let deferred1_0;
148
+ let deferred1_1;
149
+ try {
150
+ const ret = wasm.last_panic();
151
+ deferred1_0 = ret[0];
152
+ deferred1_1 = ret[1];
153
+ return getStringFromWasm0(ret[0], ret[1]);
154
+ } finally {
155
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
156
+ }
157
+ }
158
+
159
+ /**
160
+ * The rate of the PCM `take_audio` returns, in Hz.
161
+ * @returns {number}
162
+ */
163
+ export function sample_rate() {
164
+ const ret = wasm.sample_rate();
165
+ return ret >>> 0;
166
+ }
167
+
168
+ /**
169
+ * `[{"id","label"}]` of the built-in voices.
170
+ * @returns {string}
171
+ */
172
+ export function voices() {
173
+ let deferred1_0;
174
+ let deferred1_1;
175
+ try {
176
+ const ret = wasm.voices();
177
+ deferred1_0 = ret[0];
178
+ deferred1_1 = ret[1];
179
+ return getStringFromWasm0(ret[0], ret[1]);
180
+ } finally {
181
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
182
+ }
183
+ }
184
+
185
+ /**
186
+ * `samples` as a 16-bit PCM WAV file at `sample_rate()`.
187
+ * @param {Float32Array} samples
188
+ * @returns {Uint8Array}
189
+ */
190
+ export function wav(samples) {
191
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
192
+ const len0 = WASM_VECTOR_LEN;
193
+ const ret = wasm.wav(ptr0, len0);
194
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
195
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
196
+ return v2;
197
+ }
198
+ function __wbg_get_imports() {
199
+ const import0 = {
200
+ __proto__: null,
201
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
202
+ const ret = Error(getStringFromWasm0(arg0, arg1));
203
+ return ret;
204
+ },
205
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
206
+ throw new Error(getStringFromWasm0(arg0, arg1));
207
+ },
208
+ __wbindgen_init_externref_table: function() {
209
+ const table = wasm.__wbindgen_externrefs;
210
+ const offset = table.grow(4);
211
+ table.set(0, undefined);
212
+ table.set(offset + 0, undefined);
213
+ table.set(offset + 1, null);
214
+ table.set(offset + 2, true);
215
+ table.set(offset + 3, false);
216
+ },
217
+ };
218
+ return {
219
+ __proto__: null,
220
+ "./phonon_runtime_bg.js": import0,
221
+ };
222
+ }
223
+
224
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
225
+ ? { register: () => {}, unregister: () => {} }
226
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
227
+
228
+ function getArrayF32FromWasm0(ptr, len) {
229
+ ptr = ptr >>> 0;
230
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
231
+ }
232
+
233
+ function getArrayU8FromWasm0(ptr, len) {
234
+ ptr = ptr >>> 0;
235
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
236
+ }
237
+
238
+ let cachedFloat32ArrayMemory0 = null;
239
+ function getFloat32ArrayMemory0() {
240
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
241
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
242
+ }
243
+ return cachedFloat32ArrayMemory0;
244
+ }
245
+
246
+ function getStringFromWasm0(ptr, len) {
247
+ return decodeText(ptr >>> 0, len);
248
+ }
249
+
250
+ let cachedUint8ArrayMemory0 = null;
251
+ function getUint8ArrayMemory0() {
252
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
253
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
254
+ }
255
+ return cachedUint8ArrayMemory0;
256
+ }
257
+
258
+ function passArray8ToWasm0(arg, malloc) {
259
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
260
+ getUint8ArrayMemory0().set(arg, ptr / 1);
261
+ WASM_VECTOR_LEN = arg.length;
262
+ return ptr;
263
+ }
264
+
265
+ function passArrayF32ToWasm0(arg, malloc) {
266
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
267
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
268
+ WASM_VECTOR_LEN = arg.length;
269
+ return ptr;
270
+ }
271
+
272
+ function passStringToWasm0(arg, malloc, realloc) {
273
+ if (realloc === undefined) {
274
+ const buf = cachedTextEncoder.encode(arg);
275
+ const ptr = malloc(buf.length, 1) >>> 0;
276
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
277
+ WASM_VECTOR_LEN = buf.length;
278
+ return ptr;
279
+ }
280
+
281
+ let len = arg.length;
282
+ let ptr = malloc(len, 1) >>> 0;
283
+
284
+ const mem = getUint8ArrayMemory0();
285
+
286
+ let offset = 0;
287
+
288
+ for (; offset < len; offset++) {
289
+ const code = arg.charCodeAt(offset);
290
+ if (code > 0x7F) break;
291
+ mem[ptr + offset] = code;
292
+ }
293
+ if (offset !== len) {
294
+ if (offset !== 0) {
295
+ arg = arg.slice(offset);
296
+ }
297
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
298
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
299
+ const ret = cachedTextEncoder.encodeInto(arg, view);
300
+
301
+ offset += ret.written;
302
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
303
+ }
304
+
305
+ WASM_VECTOR_LEN = offset;
306
+ return ptr;
307
+ }
308
+
309
+ function takeFromExternrefTable0(idx) {
310
+ const value = wasm.__wbindgen_externrefs.get(idx);
311
+ wasm.__externref_table_dealloc(idx);
312
+ return value;
313
+ }
314
+
315
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
316
+ cachedTextDecoder.decode();
317
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
318
+ let numBytesDecoded = 0;
319
+ function decodeText(ptr, len) {
320
+ numBytesDecoded += len;
321
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
322
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
323
+ cachedTextDecoder.decode();
324
+ numBytesDecoded = len;
325
+ }
326
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
327
+ }
328
+
329
+ const cachedTextEncoder = new TextEncoder();
330
+
331
+ if (!('encodeInto' in cachedTextEncoder)) {
332
+ cachedTextEncoder.encodeInto = function (arg, view) {
333
+ const buf = cachedTextEncoder.encode(arg);
334
+ view.set(buf);
335
+ return {
336
+ read: arg.length,
337
+ written: buf.length
338
+ };
339
+ };
340
+ }
341
+
342
+ let WASM_VECTOR_LEN = 0;
343
+
344
+ let wasmModule, wasmInstance, wasm;
345
+ function __wbg_finalize_init(instance, module) {
346
+ wasmInstance = instance;
347
+ wasm = instance.exports;
348
+ wasmModule = module;
349
+ cachedFloat32ArrayMemory0 = null;
350
+ cachedUint8ArrayMemory0 = null;
351
+ wasm.__wbindgen_start();
352
+ return wasm;
353
+ }
354
+
355
+ async function __wbg_load(module, imports) {
356
+ if (typeof Response === 'function' && module instanceof Response) {
357
+ if (!module.ok) {
358
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
359
+ }
360
+
361
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
362
+ try {
363
+ return await WebAssembly.instantiateStreaming(module, imports);
364
+ } catch (e) {
365
+ const validResponse = expectedResponseType(module.type);
366
+
367
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
368
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
369
+
370
+ } else { throw e; }
371
+ }
372
+ }
373
+
374
+ const bytes = await module.arrayBuffer();
375
+ return await WebAssembly.instantiate(bytes, imports);
376
+ } else {
377
+ const instance = await WebAssembly.instantiate(module, imports);
378
+
379
+ if (instance instanceof WebAssembly.Instance) {
380
+ return { instance, module };
381
+ } else {
382
+ return instance;
383
+ }
384
+ }
385
+
386
+ function expectedResponseType(type) {
387
+ switch (type) {
388
+ case 'basic': case 'cors': case 'default': return true;
389
+ }
390
+ return false;
391
+ }
392
+ }
393
+
394
+ function initSync(module) {
395
+ if (wasm !== undefined) return wasm;
396
+
397
+
398
+ if (module !== undefined) {
399
+ if (Object.getPrototypeOf(module) === Object.prototype) {
400
+ ({module} = module)
401
+ } else {
402
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
403
+ }
404
+ }
405
+
406
+ const imports = __wbg_get_imports();
407
+ if (!(module instanceof WebAssembly.Module)) {
408
+ module = new WebAssembly.Module(module);
409
+ }
410
+ const instance = new WebAssembly.Instance(module, imports);
411
+ return __wbg_finalize_init(instance, module);
412
+ }
413
+
414
+ async function __wbg_init(module_or_path) {
415
+ if (wasm !== undefined) return wasm;
416
+
417
+
418
+ if (module_or_path !== undefined) {
419
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
420
+ ({module_or_path} = module_or_path)
421
+ } else {
422
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
423
+ }
424
+ }
425
+
426
+ if (module_or_path === undefined) {
427
+ module_or_path = new URL('phonon_runtime_bg.wasm', import.meta.url);
428
+ }
429
+ const imports = __wbg_get_imports();
430
+
431
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
432
+ module_or_path = fetch(module_or_path);
433
+ }
434
+
435
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
436
+
437
+ return __wbg_finalize_init(instance, module);
438
+ }
439
+
440
+ export { initSync, __wbg_init as default };
engine/dist/phonon/web-single/phonon_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:24cc3fa9615a7c1d4b81dd3dcfec848f76a1de5ace971d1bfb5f55212580f464
3
+ size 2855010
engine/dist/phonon/web-threaded-relaxed/phonon_runtime.js ADDED
@@ -0,0 +1,568 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { startWorkers } from './snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js';
2
+
3
+
4
+ export class Runtime {
5
+ __destroy_into_raw() {
6
+ const ptr = this.__wbg_ptr;
7
+ this.__wbg_ptr = 0;
8
+ RuntimeFinalization.unregister(this);
9
+ return ptr;
10
+ }
11
+ free() {
12
+ const ptr = this.__destroy_into_raw();
13
+ wasm.__wbg_runtime_free(ptr, 0);
14
+ }
15
+ cancel() {
16
+ const ret = wasm.runtime_cancel(this.__wbg_ptr);
17
+ if (ret[1]) {
18
+ throw takeFromExternrefTable0(ret[0]);
19
+ }
20
+ }
21
+ /**
22
+ * Checks the part's size and BLAKE3; after the last part, builds the engine. Returns
23
+ * whether the engine is ready.
24
+ * @param {number} part
25
+ * @returns {boolean}
26
+ */
27
+ end_part(part) {
28
+ const ret = wasm.runtime_end_part(this.__wbg_ptr, part);
29
+ if (ret[2]) {
30
+ throw takeFromExternrefTable0(ret[1]);
31
+ }
32
+ return ret[0] !== 0;
33
+ }
34
+ /**
35
+ * @param {string} manifest_json
36
+ */
37
+ constructor(manifest_json) {
38
+ const ptr0 = passStringToWasm0(manifest_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
39
+ const len0 = WASM_VECTOR_LEN;
40
+ const ret = wasm.runtime_new(ptr0, len0);
41
+ if (ret[2]) {
42
+ throw takeFromExternrefTable0(ret[1]);
43
+ }
44
+ this.__wbg_ptr = ret[0];
45
+ RuntimeFinalization.register(this, this.__wbg_ptr, this);
46
+ return this;
47
+ }
48
+ /**
49
+ * Discards what was written to part `part` (after a failed `end_part`), to write it
50
+ * again.
51
+ * @param {number} part
52
+ */
53
+ restart_part(part) {
54
+ const ret = wasm.runtime_restart_part(this.__wbg_ptr, part);
55
+ if (ret[1]) {
56
+ throw takeFromExternrefTable0(ret[0]);
57
+ }
58
+ }
59
+ /**
60
+ * Starts a synthesis (`session::Request` as JSON); returns the plan (`{"fragments"}`).
61
+ * @param {string} request_json
62
+ * @returns {string}
63
+ */
64
+ start(request_json) {
65
+ let deferred3_0;
66
+ let deferred3_1;
67
+ try {
68
+ const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
69
+ const len0 = WASM_VECTOR_LEN;
70
+ const ret = wasm.runtime_start(this.__wbg_ptr, ptr0, len0);
71
+ var ptr2 = ret[0];
72
+ var len2 = ret[1];
73
+ if (ret[3]) {
74
+ ptr2 = 0; len2 = 0;
75
+ throw takeFromExternrefTable0(ret[2]);
76
+ }
77
+ deferred3_0 = ptr2;
78
+ deferred3_1 = len2;
79
+ return getStringFromWasm0(ptr2, len2);
80
+ } finally {
81
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
82
+ }
83
+ }
84
+ /**
85
+ * One frame; returns `{"fragment","fragments","frame","done"}`.
86
+ * @returns {string}
87
+ */
88
+ step() {
89
+ let deferred2_0;
90
+ let deferred2_1;
91
+ try {
92
+ const ret = wasm.runtime_step(this.__wbg_ptr);
93
+ var ptr1 = ret[0];
94
+ var len1 = ret[1];
95
+ if (ret[3]) {
96
+ ptr1 = 0; len1 = 0;
97
+ throw takeFromExternrefTable0(ret[2]);
98
+ }
99
+ deferred2_0 = ptr1;
100
+ deferred2_1 = len1;
101
+ return getStringFromWasm0(ptr1, len1);
102
+ } finally {
103
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
104
+ }
105
+ }
106
+ /**
107
+ * The samples (mono, `sample_rate()` Hz) produced since the last call.
108
+ * @returns {Float32Array}
109
+ */
110
+ take_audio() {
111
+ const ret = wasm.runtime_take_audio(this.__wbg_ptr);
112
+ if (ret[3]) {
113
+ throw takeFromExternrefTable0(ret[2]);
114
+ }
115
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
116
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
117
+ return v1;
118
+ }
119
+ /**
120
+ * @returns {number}
121
+ */
122
+ threads() {
123
+ const ret = wasm.runtime_threads(this.__wbg_ptr);
124
+ if (ret[2]) {
125
+ throw takeFromExternrefTable0(ret[1]);
126
+ }
127
+ return ret[0] >>> 0;
128
+ }
129
+ /**
130
+ * The next bytes of part `part` (index into the manifest's `parts`), in order.
131
+ * @param {number} part
132
+ * @param {Uint8Array} bytes
133
+ */
134
+ write_part(part, bytes) {
135
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
136
+ const len0 = WASM_VECTOR_LEN;
137
+ const ret = wasm.runtime_write_part(this.__wbg_ptr, part, ptr0, len0);
138
+ if (ret[1]) {
139
+ throw takeFromExternrefTable0(ret[0]);
140
+ }
141
+ }
142
+ }
143
+ if (Symbol.dispose) Runtime.prototype[Symbol.dispose] = Runtime.prototype.free;
144
+
145
+ /**
146
+ * @param {number} num_threads
147
+ * @returns {Promise<any>}
148
+ */
149
+ export function initThreadPool(num_threads) {
150
+ const ret = wasm.initThreadPool(num_threads);
151
+ return ret;
152
+ }
153
+
154
+ /**
155
+ * The message of the last panic, for the host to read after a `RuntimeError: unreachable`.
156
+ * @returns {string}
157
+ */
158
+ export function last_panic() {
159
+ let deferred1_0;
160
+ let deferred1_1;
161
+ try {
162
+ const ret = wasm.last_panic();
163
+ deferred1_0 = ret[0];
164
+ deferred1_1 = ret[1];
165
+ return getStringFromWasm0(ret[0], ret[1]);
166
+ } finally {
167
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
168
+ }
169
+ }
170
+
171
+ /**
172
+ * The rate of the PCM `take_audio` returns, in Hz.
173
+ * @returns {number}
174
+ */
175
+ export function sample_rate() {
176
+ const ret = wasm.sample_rate();
177
+ return ret >>> 0;
178
+ }
179
+
180
+ /**
181
+ * `[{"id","label"}]` of the built-in voices.
182
+ * @returns {string}
183
+ */
184
+ export function voices() {
185
+ let deferred1_0;
186
+ let deferred1_1;
187
+ try {
188
+ const ret = wasm.voices();
189
+ deferred1_0 = ret[0];
190
+ deferred1_1 = ret[1];
191
+ return getStringFromWasm0(ret[0], ret[1]);
192
+ } finally {
193
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
194
+ }
195
+ }
196
+
197
+ /**
198
+ * `samples` as a 16-bit PCM WAV file at `sample_rate()`.
199
+ * @param {Float32Array} samples
200
+ * @returns {Uint8Array}
201
+ */
202
+ export function wav(samples) {
203
+ const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
204
+ const len0 = WASM_VECTOR_LEN;
205
+ const ret = wasm.wav(ptr0, len0);
206
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
207
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
208
+ return v2;
209
+ }
210
+
211
+ export class wbg_rayon_PoolBuilder {
212
+ static __wrap(ptr) {
213
+ const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
214
+ obj.__wbg_ptr = ptr;
215
+ wbg_rayon_PoolBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
216
+ return obj;
217
+ }
218
+ __destroy_into_raw() {
219
+ const ptr = this.__wbg_ptr;
220
+ this.__wbg_ptr = 0;
221
+ wbg_rayon_PoolBuilderFinalization.unregister(this);
222
+ return ptr;
223
+ }
224
+ free() {
225
+ const ptr = this.__destroy_into_raw();
226
+ wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 0);
227
+ }
228
+ build() {
229
+ wasm.wbg_rayon_poolbuilder_build(this.__wbg_ptr);
230
+ }
231
+ /**
232
+ * @returns {string}
233
+ */
234
+ mainJS() {
235
+ const ret = wasm.wbg_rayon_poolbuilder_mainJS(this.__wbg_ptr);
236
+ return ret;
237
+ }
238
+ /**
239
+ * @returns {number}
240
+ */
241
+ numThreads() {
242
+ const ret = wasm.wbg_rayon_poolbuilder_numThreads(this.__wbg_ptr);
243
+ return ret >>> 0;
244
+ }
245
+ /**
246
+ * @returns {number}
247
+ */
248
+ receiver() {
249
+ const ret = wasm.wbg_rayon_poolbuilder_receiver(this.__wbg_ptr);
250
+ return ret >>> 0;
251
+ }
252
+ }
253
+ if (Symbol.dispose) wbg_rayon_PoolBuilder.prototype[Symbol.dispose] = wbg_rayon_PoolBuilder.prototype.free;
254
+
255
+ /**
256
+ * @param {number} receiver
257
+ */
258
+ export function wbg_rayon_start_worker(receiver) {
259
+ wasm.wbg_rayon_start_worker(receiver);
260
+ }
261
+ function __wbg_get_imports(memory) {
262
+ const import0 = {
263
+ __proto__: null,
264
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
265
+ const ret = Error(getStringFromWasm0(arg0, arg1));
266
+ return ret;
267
+ },
268
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
269
+ const ret = arg0 === undefined;
270
+ return ret;
271
+ },
272
+ __wbg___wbindgen_memory_caa4a6165639c8b5: function() {
273
+ const ret = wasm.memory;
274
+ return ret;
275
+ },
276
+ __wbg___wbindgen_module_7115fb14045f9891: function() {
277
+ const ret = wasmModule;
278
+ return ret;
279
+ },
280
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
281
+ throw new Error(getStringFromWasm0(arg0, arg1));
282
+ },
283
+ __wbg_instanceof_Window_82d71df4eddf88bc: function(arg0) {
284
+ let result;
285
+ try {
286
+ result = arg0 instanceof Window;
287
+ } catch (_) {
288
+ result = false;
289
+ }
290
+ const ret = result;
291
+ return ret;
292
+ },
293
+ __wbg_startWorkers_622cedd0d351664e: function(arg0, arg1, arg2) {
294
+ const ret = startWorkers(arg0, arg1, wbg_rayon_PoolBuilder.__wrap(arg2));
295
+ return ret;
296
+ },
297
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
298
+ const ret = typeof global === 'undefined' ? null : global;
299
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
300
+ },
301
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
302
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
303
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
304
+ },
305
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
306
+ const ret = typeof self === 'undefined' ? null : self;
307
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
308
+ },
309
+ __wbg_static_accessor_URL_fac851ed3060f4eb: function() {
310
+ const ret = import.meta.url;
311
+ return ret;
312
+ },
313
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
314
+ const ret = typeof window === 'undefined' ? null : window;
315
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
316
+ },
317
+ __wbindgen_init_externref_table: function() {
318
+ const table = wasm.__wbindgen_externrefs;
319
+ const offset = table.grow(4);
320
+ table.set(0, undefined);
321
+ table.set(offset + 0, undefined);
322
+ table.set(offset + 1, null);
323
+ table.set(offset + 2, true);
324
+ table.set(offset + 3, false);
325
+ },
326
+ memory: memory || new WebAssembly.Memory({initial:27,maximum:65536,shared:true}),
327
+ };
328
+ return {
329
+ __proto__: null,
330
+ "./phonon_runtime_bg.js": import0,
331
+ };
332
+ }
333
+
334
+ const RuntimeFinalization = (typeof FinalizationRegistry === 'undefined')
335
+ ? { register: () => {}, unregister: () => {} }
336
+ : new FinalizationRegistry(ptr => wasm.__wbg_runtime_free(ptr, 1));
337
+ const wbg_rayon_PoolBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
338
+ ? { register: () => {}, unregister: () => {} }
339
+ : new FinalizationRegistry(ptr => wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 1));
340
+
341
+ function addToExternrefTable0(obj) {
342
+ const idx = wasm.__externref_table_alloc();
343
+ wasm.__wbindgen_externrefs.set(idx, obj);
344
+ return idx;
345
+ }
346
+
347
+ function getArrayF32FromWasm0(ptr, len) {
348
+ ptr = ptr >>> 0;
349
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
350
+ }
351
+
352
+ function getArrayU8FromWasm0(ptr, len) {
353
+ ptr = ptr >>> 0;
354
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
355
+ }
356
+
357
+ let cachedFloat32ArrayMemory0 = null;
358
+ function getFloat32ArrayMemory0() {
359
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.buffer !== wasm.memory.buffer) {
360
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
361
+ }
362
+ return cachedFloat32ArrayMemory0;
363
+ }
364
+
365
+ function getStringFromWasm0(ptr, len) {
366
+ return decodeText(ptr >>> 0, len);
367
+ }
368
+
369
+ let cachedUint8ArrayMemory0 = null;
370
+ function getUint8ArrayMemory0() {
371
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.buffer !== wasm.memory.buffer) {
372
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
373
+ }
374
+ return cachedUint8ArrayMemory0;
375
+ }
376
+
377
+ function isLikeNone(x) {
378
+ return x === undefined || x === null;
379
+ }
380
+
381
+ function passArray8ToWasm0(arg, malloc) {
382
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
383
+ getUint8ArrayMemory0().set(arg, ptr / 1);
384
+ WASM_VECTOR_LEN = arg.length;
385
+ return ptr;
386
+ }
387
+
388
+ function passArrayF32ToWasm0(arg, malloc) {
389
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
390
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
391
+ WASM_VECTOR_LEN = arg.length;
392
+ return ptr;
393
+ }
394
+
395
+ function passStringToWasm0(arg, malloc, realloc) {
396
+ if (realloc === undefined) {
397
+ const buf = cachedTextEncoder.encode(arg);
398
+ const ptr = malloc(buf.length, 1) >>> 0;
399
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
400
+ WASM_VECTOR_LEN = buf.length;
401
+ return ptr;
402
+ }
403
+
404
+ let len = arg.length;
405
+ let ptr = malloc(len, 1) >>> 0;
406
+
407
+ const mem = getUint8ArrayMemory0();
408
+
409
+ let offset = 0;
410
+
411
+ for (; offset < len; offset++) {
412
+ const code = arg.charCodeAt(offset);
413
+ if (code > 0x7F) break;
414
+ mem[ptr + offset] = code;
415
+ }
416
+ if (offset !== len) {
417
+ if (offset !== 0) {
418
+ arg = arg.slice(offset);
419
+ }
420
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
421
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
422
+ const ret = cachedTextEncoder.encodeInto(arg, view);
423
+
424
+ offset += ret.written;
425
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
426
+ }
427
+
428
+ WASM_VECTOR_LEN = offset;
429
+ return ptr;
430
+ }
431
+
432
+ function takeFromExternrefTable0(idx) {
433
+ const value = wasm.__wbindgen_externrefs.get(idx);
434
+ wasm.__externref_table_dealloc(idx);
435
+ return value;
436
+ }
437
+
438
+ let cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : undefined);
439
+ if (cachedTextDecoder) cachedTextDecoder.decode();
440
+
441
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
442
+ let numBytesDecoded = 0;
443
+ function decodeText(ptr, len) {
444
+ numBytesDecoded += len;
445
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
446
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
447
+ cachedTextDecoder.decode();
448
+ numBytesDecoded = len;
449
+ }
450
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().slice(ptr, ptr + len));
451
+ }
452
+
453
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined);
454
+
455
+ if (cachedTextEncoder) {
456
+ cachedTextEncoder.encodeInto = function (arg, view) {
457
+ const buf = cachedTextEncoder.encode(arg);
458
+ view.set(buf);
459
+ return {
460
+ read: arg.length,
461
+ written: buf.length
462
+ };
463
+ };
464
+ }
465
+
466
+ let WASM_VECTOR_LEN = 0;
467
+
468
+ let wasmModule, wasmInstance, wasm;
469
+ function __wbg_finalize_init(instance, module, thread_stack_size) {
470
+ wasmInstance = instance;
471
+ wasm = instance.exports;
472
+ wasmModule = module;
473
+ cachedFloat32ArrayMemory0 = null;
474
+ cachedUint8ArrayMemory0 = null;
475
+ if (typeof thread_stack_size !== 'undefined' && (typeof thread_stack_size !== 'number' || thread_stack_size === 0 || thread_stack_size % 65536 !== 0)) {
476
+ throw new Error('invalid stack size');
477
+ }
478
+
479
+ wasm.__wbindgen_start(thread_stack_size);
480
+ return wasm;
481
+ }
482
+
483
+ async function __wbg_load(module, imports) {
484
+ if (typeof Response === 'function' && module instanceof Response) {
485
+ if (!module.ok) {
486
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
487
+ }
488
+
489
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
490
+ try {
491
+ return await WebAssembly.instantiateStreaming(module, imports);
492
+ } catch (e) {
493
+ const validResponse = expectedResponseType(module.type);
494
+
495
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
496
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
497
+
498
+ } else { throw e; }
499
+ }
500
+ }
501
+
502
+ const bytes = await module.arrayBuffer();
503
+ return await WebAssembly.instantiate(bytes, imports);
504
+ } else {
505
+ const instance = await WebAssembly.instantiate(module, imports);
506
+
507
+ if (instance instanceof WebAssembly.Instance) {
508
+ return { instance, module };
509
+ } else {
510
+ return instance;
511
+ }
512
+ }
513
+
514
+ function expectedResponseType(type) {
515
+ switch (type) {
516
+ case 'basic': case 'cors': case 'default': return true;
517
+ }
518
+ return false;
519
+ }
520
+ }
521
+
522
+ function initSync(module, memory) {
523
+ if (wasm !== undefined) return wasm;
524
+
525
+ let thread_stack_size
526
+ if (module !== undefined) {
527
+ if (Object.getPrototypeOf(module) === Object.prototype) {
528
+ ({module, memory, thread_stack_size} = module)
529
+ } else {
530
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
531
+ }
532
+ }
533
+
534
+ const imports = __wbg_get_imports(memory);
535
+ if (!(module instanceof WebAssembly.Module)) {
536
+ module = new WebAssembly.Module(module);
537
+ }
538
+ const instance = new WebAssembly.Instance(module, imports);
539
+ return __wbg_finalize_init(instance, module, thread_stack_size);
540
+ }
541
+
542
+ async function __wbg_init(module_or_path, memory) {
543
+ if (wasm !== undefined) return wasm;
544
+
545
+ let thread_stack_size
546
+ if (module_or_path !== undefined) {
547
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
548
+ ({module_or_path, memory, thread_stack_size} = module_or_path)
549
+ } else {
550
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
551
+ }
552
+ }
553
+
554
+ if (module_or_path === undefined) {
555
+ module_or_path = new URL('phonon_runtime_bg.wasm', import.meta.url);
556
+ }
557
+ const imports = __wbg_get_imports(memory);
558
+
559
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
560
+ module_or_path = fetch(module_or_path);
561
+ }
562
+
563
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
564
+
565
+ return __wbg_finalize_init(instance, module, thread_stack_size);
566
+ }
567
+
568
+ export { initSync, __wbg_init as default };
engine/dist/phonon/web-threaded-relaxed/phonon_runtime_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51007f552b1c15de8f5a4fe84e12a1e3c4a67d0865ad01119d902902e152531d
3
+ size 2906959
engine/dist/phonon/web-threaded-relaxed/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/protocol.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ // The messages between a threaded runtime's thread host (thread-host.js, in the engine worker
2
+ // and in each compute worker) and the page's compute pool (compute.js). `build-runtime.sh` copies
3
+ // this file next to the thread host.
4
+
5
+ export const SPAWN_COMPUTE = 'fusor-ai-spawn-compute';
6
+ export const RAYON_INIT = 'fusor-ai-rayon-init';
7
+ export const RAYON_READY = 'fusor-ai-rayon-ready';
8
+ export const RAYON_ERROR = 'fusor-ai-rayon-error';