@soverius-ai/browser-models 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +16 -8
  2. package/chunk-4RAISIWO.js +1 -0
  3. package/chunk-6TJV26R3.js +1 -0
  4. package/chunk-EFSLG2O3.js +1 -0
  5. package/chunk-MPBLCIMW.js +1 -0
  6. package/chunk-T3BB5C4O.js +1 -0
  7. package/chunk-T5TQFW45.js +1 -0
  8. package/chunk-UZW7NPZG.js +1 -0
  9. package/engines/prompt-api.d.ts +41 -0
  10. package/{src/engines → engines}/transformers.d.ts +22 -9
  11. package/engines/web-llm-default.worker.d.ts +1 -0
  12. package/engines/web-llm.d.ts +48 -0
  13. package/engines.d.ts +44 -0
  14. package/engines.js +1 -0
  15. package/index.d.ts +11 -0
  16. package/index.js +1 -0
  17. package/{src/lib → lib}/async-queue.d.ts +4 -0
  18. package/lib/engine.d.ts +107 -0
  19. package/{src/lib/parser.d.ts → lib/output-parser.d.ts} +4 -0
  20. package/{src/model-store.d.ts → model-store.d.ts} +3 -0
  21. package/models.d.ts +26 -0
  22. package/package.json +28 -47
  23. package/prompt-api.d.ts +6 -0
  24. package/prompt-api.js +1 -0
  25. package/transformers.d.ts +6 -0
  26. package/transformers.js +1 -0
  27. package/web-llm-default.worker.js +1 -0
  28. package/web-llm-worker.d.ts +6 -0
  29. package/web-llm-worker.js +1 -0
  30. package/web-llm.d.ts +6 -0
  31. package/web-llm.js +1 -0
  32. package/src/agent.d.ts +0 -52
  33. package/src/agent.js +0 -128
  34. package/src/agent.js.map +0 -1
  35. package/src/copilotkit.d.ts +0 -20
  36. package/src/copilotkit.js +0 -163
  37. package/src/copilotkit.js.map +0 -1
  38. package/src/engines/opfs-cache.js +0 -43
  39. package/src/engines/opfs-cache.js.map +0 -1
  40. package/src/engines/prompt-api.d.ts +0 -50
  41. package/src/engines/prompt-api.js +0 -124
  42. package/src/engines/prompt-api.js.map +0 -1
  43. package/src/engines/shared-load.js +0 -67
  44. package/src/engines/shared-load.js.map +0 -1
  45. package/src/engines/transformers.js +0 -209
  46. package/src/engines/transformers.js.map +0 -1
  47. package/src/engines/web-llm-worker.js +0 -15
  48. package/src/engines/web-llm-worker.js.map +0 -1
  49. package/src/engines/web-llm.d.ts +0 -41
  50. package/src/engines/web-llm.js +0 -135
  51. package/src/engines/web-llm.js.map +0 -1
  52. package/src/index.d.ts +0 -7
  53. package/src/index.js +0 -6
  54. package/src/index.js.map +0 -1
  55. package/src/lib/abort.js +0 -24
  56. package/src/lib/abort.js.map +0 -1
  57. package/src/lib/async-queue.js +0 -35
  58. package/src/lib/async-queue.js.map +0 -1
  59. package/src/lib/engine.d.ts +0 -45
  60. package/src/lib/engine.js +0 -2
  61. package/src/lib/engine.js.map +0 -1
  62. package/src/lib/parser.js +0 -124
  63. package/src/lib/parser.js.map +0 -1
  64. package/src/lib/partial-json.d.ts +0 -21
  65. package/src/lib/partial-json.js +0 -88
  66. package/src/lib/partial-json.js.map +0 -1
  67. package/src/lib/prompt.d.ts +0 -9
  68. package/src/lib/prompt.js +0 -82
  69. package/src/lib/prompt.js.map +0 -1
  70. package/src/lib/repair.d.ts +0 -47
  71. package/src/lib/repair.js +0 -217
  72. package/src/lib/repair.js.map +0 -1
  73. package/src/lib/run.d.ts +0 -40
  74. package/src/lib/run.js +0 -434
  75. package/src/lib/run.js.map +0 -1
  76. package/src/lib/schema.d.ts +0 -21
  77. package/src/lib/schema.js +0 -128
  78. package/src/lib/schema.js.map +0 -1
  79. package/src/lib/tools.d.ts +0 -33
  80. package/src/lib/tools.js +0 -20
  81. package/src/lib/tools.js.map +0 -1
  82. package/src/mcp.d.ts +0 -54
  83. package/src/mcp.js +0 -204
  84. package/src/mcp.js.map +0 -1
  85. package/src/model-store.js +0 -139
  86. package/src/model-store.js.map +0 -1
  87. package/src/prompt-api.d.ts +0 -1
  88. package/src/prompt-api.js +0 -3
  89. package/src/prompt-api.js.map +0 -1
  90. package/src/transformers.d.ts +0 -1
  91. package/src/transformers.js +0 -3
  92. package/src/transformers.js.map +0 -1
  93. package/src/web-llm-worker.d.ts +0 -1
  94. package/src/web-llm-worker.js +0 -3
  95. package/src/web-llm-worker.js.map +0 -1
  96. package/src/web-llm.d.ts +0 -1
  97. package/src/web-llm.js +0 -3
  98. package/src/web-llm.js.map +0 -1
  99. package/src/webmcp.d.ts +0 -43
  100. package/src/webmcp.js +0 -58
  101. package/src/webmcp.js.map +0 -1
  102. /package/{src/engines → engines}/opfs-cache.d.ts +0 -0
  103. /package/{src/engines → engines}/shared-load.d.ts +0 -0
  104. /package/{src/engines → engines}/web-llm-worker.d.ts +0 -0
  105. /package/{src/lib → lib}/abort.d.ts +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @soverius-ai/browser-models
2
2
 
3
- Run language models in the browser (Chrome/Edge Prompt API, WebLLM, transformers.js) as [AG-UI](https://docs.ag-ui.com) agents. CopilotKit or any AG-UI client works unchanged.
3
+ Run language models in the browser with one engine interface: the Chrome/Edge Prompt API, WebLLM and transformers.js. No AG-UI, no dependencies.
4
4
 
5
5
  ```bash
6
6
  pnpm add @soverius-ai/browser-models
@@ -9,16 +9,24 @@ pnpm add @huggingface/transformers # only for TransformersJsEngine
9
9
  ```
10
10
 
11
11
  ```ts
12
- import { BrowserModelsAgent } from '@soverius-ai/browser-models/agent';
13
12
  import { PromptApiEngine } from '@soverius-ai/browser-models/prompt-api';
14
13
 
15
- const agent = new BrowserModelsAgent({
16
- models: { nano: new PromptApiEngine() },
17
- defaultModel: 'nano',
18
- });
14
+ const engine = new PromptApiEngine({ sampling: 'balanced' });
15
+ if ((await engine.availability()) !== 'unavailable') {
16
+ await engine.load();
17
+ for await (const part of engine.generate({
18
+ messages: [{ role: 'user', content: 'Hi' }],
19
+ }))
20
+ if (part.type === 'text') output.textContent += part.text;
21
+ }
19
22
  ```
20
23
 
21
- Entries: `.`, `/agent`, `/prompt-api`, `/web-llm`, `/web-llm/worker`, `/transformers`, `/webmcp`, `/mcp`, `/copilotkit` ([Packages](https://browser-models.soverius.ai/docs#packages)).
22
- Framework packages: `@soverius-ai/browser-models-angular`, `@soverius-ai/browser-models-react`, `@soverius-ai/browser-models-vue`.
24
+ Entries: `.`, `/prompt-api`, `/web-llm`, `/web-llm/worker`, `/transformers`, `/engines` (all three, by `EngineKind`).
25
+
26
+ | Package | For |
27
+ | ------------------------------------------------------- | ----------------------------------------------- |
28
+ | `@soverius-ai/browser-models-agui` | AG-UI agent, for CopilotKit or any AG-UI client |
29
+ | `@soverius-ai/browser-models-tools` | tool calling, MCP, WebMCP, generative UI |
30
+ | `@soverius-ai/browser-models-angular`, `-react`, `-vue` | framework bindings |
23
31
 
24
32
  [Docs](https://browser-models.soverius.ai/docs) · [Playground](https://browser-models.soverius.ai/playground) · by [Soverius AI](https://soverius.ai) · MIT
@@ -0,0 +1 @@
1
+ import{c as o}from"./chunk-T3BB5C4O.js";var i=class{#t;#n;#r=new Set;#e;constructor(e,r){this.#t=e,this.#n=r}get state(){return this.#e?this.#e.ready?"ready":"loading":"idle"}async get({onProgress:e,signal:r}={}){r?.throwIfAborted();let t=this.#e??=this.#o(),{signal:n}=t.cancel;e&&this.#r.add(e);try{return await o(t.loaded,r?AbortSignal.any([r,n]):n)}finally{e&&this.#r.delete(e)}}async reset(){let e=this.#e;this.#e=void 0,e&&(e.ready?await this.#n(await e.loaded):e.cancel.abort(new DOMException("The model was unloaded.","AbortError")))}#o(){let e=new AbortController,r={cancel:e,ready:!1,loaded:this.#t(t=>this.#r.forEach(n=>n(t)),e.signal)};return r.loaded.then(()=>{r.ready=!0},()=>{this.#e===r&&(this.#e=void 0)}),r}};export{i as a};
@@ -0,0 +1 @@
1
+ import{a as f}from"./chunk-EFSLG2O3.js";import{a as g}from"./chunk-4RAISIWO.js";import{b as y}from"./chunk-T3BB5C4O.js";function w(l="soverius-transformers",t=()=>navigator.storage.getDirectory()){let e=async()=>(await t()).getDirectoryHandle(l,{create:!0});return{async match(n){try{let r=await(await e()).getFileHandle(await m(n));return new Response(await r.getFile())}catch{return}},async put(n,r){if(!r.body)return;let a=await m(n),i=await e(),d=await i.getFileHandle(a,{create:!0});try{await r.body.pipeTo(await d.createWritable())}catch(o){throw await i.removeEntry(a).catch(()=>{}),o}},async delete(n){try{return await(await e()).removeEntry(await m(n)),!0}catch{return!1}}}}async function m(l){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(l));return Array.from(new Uint8Array(t),e=>e.toString(16).padStart(2,"0")).join("")}var k=class{id;kind="transformers";supportsConstraint=!1;contextWindowSize;#e;#t;#a;#p;#s;#o;#n;#d=Promise.resolve();#l=!1;#c;constructor(t,e={}){this.id=`transformers:${t}`,this.contextWindowSize=e.contextWindowSize,this.#e=t,this.#t=e.task??"text-generation",this.#a=e.device??"webgpu",this.#p=e.dtype??(this.#a==="webgpu"?"q4f16":"q4");let n=e.sampling===void 0?0:y[e.sampling];this.#s={...e.native,max_new_tokens:e.maxOutputTokens??1024,...n>0?{do_sample:!0,temperature:n}:{do_sample:e.native?.do_sample??!1}},this.#o=e.storage==="opfs"?w():void 0,this.#n=new g((r,a)=>{let i=this.#h(r,a,this.#d);return this.#d=i.catch(()=>{}),i},r=>r.dispose())}async availability(){if(this.#a==="webgpu"&&!("gpu"in navigator))return"unavailable";if(this.#n.state==="loading"||this.#l)return"downloading";if(this.#n.state==="ready")return"available";let{ModelRegistry:t}=await this.#i();return(this.#t==="text-generation"?await t.is_pipeline_cached(this.#t,this.#e,this.#r()):await t.is_cached(this.#e,this.#r()))?"available":"downloadable"}async load(t){await this.#n.get(t)}async unload(){await this.#n.reset()}async delete(){this.#l=!0;try{await this.#d,await this.unload(),await this.#u()}finally{this.#l=!1}}async#u(){let{ModelRegistry:t}=await this.#i();this.#t==="text-generation"?await t.clear_pipeline_cache(this.#t,this.#e,this.#r()):await t.clear_cache(this.#e,this.#r())}async*generate({messages:t,signal:e}){let n=await this.#n.get(e?{signal:e}:{}),{TextStreamer:r,InterruptableStoppingCriteria:a}=await this.#i(),i=new a,d=()=>i.interrupt();e?.addEventListener("abort",d);let o=new f,c=0,h=new r(n.tokenizer,{skip_prompt:!0,skip_special_tokens:!0,callback_function:s=>{s&&o.push({type:"text",text:s})},token_callback_function:s=>{c+=s.length}}),p=b(n.tokenizer,t);n.run(t,{streamer:h,stopping:i}).then(()=>o.close(),s=>o.fail(s));let u=!1;try{yield*o,u=!0,e?.throwIfAborted();let s=this.#s.max_new_tokens;yield{type:"finish",reason:s!=null&&c>=s?"length":"stop",usage:{totalTokens:(p??0)+c,...p===void 0?{}:{promptTokens:p},outputTokens:c}}}finally{e?.removeEventListener("abort",d),u||d()}}#r(){return{device:this.#a,dtype:this.#p}}async#h(t,e,n){await n;let r=i=>{i.status==="progress_total"&&t(i.progress/100)},a=await(this.#t==="text-generation"?this.#m(r):this.#y(r));return e.aborted&&(await a.dispose(),e.throwIfAborted()),a}async#m(t){let{pipeline:e}=await this.#i(),n=await e("text-generation",this.#e,{...this.#r(),progress_callback:t});return{tokenizer:n.tokenizer,run:(r,{streamer:a,stopping:i})=>n([...r],{...this.#s,streamer:a,stopping_criteria:i}),dispose:()=>n.dispose()}}async#y(t){let{AutoProcessor:e,AutoModelForImageTextToText:n}=await this.#i(),[r,a]=await Promise.all([e.from_pretrained(this.#e),n.from_pretrained(this.#e,{...this.#r(),progress_callback:t})]),i=r.tokenizer;if(!i)throw await a.dispose(),new Error(`${this.#e} has no tokenizer.`);return{tokenizer:i,run:async(d,{streamer:o,stopping:c})=>{let h={add_generation_prompt:!0,enable_thinking:!1},p=r.apply_chat_template([...d],h),u=await r(p,null,null,{add_special_tokens:!1});return a.generate({...u,...this.#s,streamer:o,stopping_criteria:c})},dispose:()=>a.dispose()}}#i(){return this.#c??=import("@huggingface/transformers").then(t=>(this.#o&&(t.env.useCustomCache=!0,t.env.customCache=this.#o),t),t=>{throw this.#c=void 0,t}),this.#c}};function b(l,t){try{let e=l.apply_chat_template([...t],{tokenize:!0,add_generation_prompt:!0,return_tensor:!1,return_dict:!1});return Array.isArray(e)?e.length:void 0}catch{return}}export{k as a};
@@ -0,0 +1 @@
1
+ var e=class{#s=[];#t=!1;#e;#i;push(i){this.#s.push(i),this.#i?.()}close(){this.#t=!0,this.#i?.()}fail(i){this.#e=i??new Error("Failed."),this.close()}async*[Symbol.asyncIterator](){for(;;){let i=this.#s.shift();if(i!==void 0){yield i;continue}if(this.#e)throw this.#e;if(this.#t)return;await new Promise(s=>this.#i=s),this.#i=void 0}}};export{e as a};
@@ -0,0 +1 @@
1
+ import{a as h}from"./chunk-4RAISIWO.js";import{b as f}from"./chunk-T3BB5C4O.js";var y=class{id;kind="web-llm";supportsConstraint=!0;#n;#e;#t;#i;#a;constructor(e,n={}){this.id=`web-llm:${e}`,this.#n=e,this.#e=n,this.#t=new h((t,a)=>this.#r(t,a),u)}get contextWindowSize(){return this.#e.contextWindowSize??this.#e.native?.context_window_size??this.#a}async availability(){if(!("gpu"in navigator))return"unavailable";if(this.#t.state==="loading")return"downloading";if(this.#t.state==="ready")return"available";let{hasModelInCache:e}=await this.#o();return await e(this.#n,this.#e.appConfig)?"available":"downloadable"}async load(e){await this.#t.get(e)}async unload(){await this.#t.reset()}async delete(){await this.unload();let{deleteModelAllInfoInCache:e}=await this.#o();await e(this.#n,this.#e.appConfig)}async*generate({messages:e,constraint:n,signal:t}){let{mlc:a}=await this.#t.get(t?{signal:t}:{}),{maxOutputTokens:d}=this.#e,r=()=>{a.interruptGenerate()};t?.addEventListener("abort",r);let s=!1;try{let l=await a.chat.completions.create({messages:e.map(o=>({role:o.role,content:o.content})),stream:!0,stream_options:{include_usage:!0},...d===void 0?{}:{max_tokens:d},...n?{response_format:{type:"json_object",schema:JSON.stringify(n)}}:{}}),i="stop",p;for await(let o of l){let[c]=o.choices;c?.delta.content&&(yield{type:"text",text:c.delta.content}),c?.finish_reason==="length"&&(i="length"),o.usage&&(p={totalTokens:o.usage.total_tokens,promptTokens:o.usage.prompt_tokens,outputTokens:o.usage.completion_tokens})}s=!0,t?.throwIfAborted(),yield{type:"finish",reason:i,...p?{usage:p}:{}}}finally{t?.removeEventListener("abort",r),s||r()}}async#r(e,n){let t=await this.#o();n.throwIfAborted(),this.#a=(this.#e.appConfig??t.prebuiltAppConfig).model_list.find(i=>i.model_id===this.#n)?.overrides?.context_window_size;let a={...this.#e.appConfig?{appConfig:this.#e.appConfig}:{},initProgressCallback:i=>e(i.progress)},{worker:d=w}=this.#e,r=d===!1?void 0:d(),s={worker:r,mlc:r?new t.WebWorkerMLCEngine(r,a):new t.MLCEngine(a)},l=()=>{u(s).catch(()=>{})};n.addEventListener("abort",l);try{await s.mlc.reload(this.#n,this.#s())}catch(i){throw n.aborted||await u(s).catch(()=>{}),i}finally{n.removeEventListener("abort",l)}return n.throwIfAborted(),s}#s(){let{native:e,contextWindowSize:n,sampling:t}=this.#e;return n===void 0&&t===void 0?e:{...e,...n===void 0?{}:{context_window_size:n},...t===void 0?{}:{temperature:f[t]}}}#o(){return this.#i??=import("@mlc-ai/web-llm").catch(e=>{throw this.#i=void 0,e}),this.#i}};function w(){return new Worker(new URL("./web-llm-default.worker.js",import.meta.url),{type:"module"})}async function u({mlc:m,worker:e}){await m.unload(),e?.terminate()}export{y as a};
@@ -0,0 +1 @@
1
+ var a=(e=>(e.PromptApi="prompt-api",e.WebLlm="web-llm",e.TransformersJs="transformers",e))(a||{}),i={"most-predictable":0,predictable:.2,"slightly-predictable":.4,balanced:.7,"slightly-creative":.9,creative:1.1,"most-creative":1.3};function s(t,n){return n?(n.throwIfAborted(),new Promise((o,e)=>{let r=()=>e(n.reason);n.addEventListener("abort",r,{once:!0}),t.then(o,e).finally(()=>n.removeEventListener("abort",r))})):t}function d(t){return t instanceof Error&&t.name==="AbortError"}export{a,i as b,s as c,d};
@@ -0,0 +1 @@
1
+ import{WebWorkerMLCEngineHandler as o}from"@mlc-ai/web-llm";function s(){let e=new o;self.onmessage=n=>e.onmessage(n)}export{s as a};
@@ -0,0 +1 @@
1
+ import{a as c}from"./chunk-4RAISIWO.js";var h=class{id="prompt-api";kind="prompt-api";supportsConstraint=!0;#i;#t;#n;#e;#o;#a;constructor(e={}){let n=e.languages??["en"];this.#i=e.languageModel,this.#t={expectedInputs:[{type:"text",languages:[...n]}],expectedOutputs:[{type:"text",languages:[...n]}]},this.#a=e.sampling,this.#n=new c((t,a)=>this.#d(t,a),async()=>{})}get contextWindowSize(){return this.#o}async availability(){let e=this.#s();return e?e.availability(this.#t):"unavailable"}async load(e){await this.#n.get(e)}async unload(){await this.#n.reset(),this.#e?.session.destroy(),this.#e=void 0}async*generate({messages:e,constraint:n,signal:t}){let a=e.at(-1);if(a?.role!=="user")throw new Error("The last message sent to the Prompt API must be from the user.");let s=e.slice(0,-1),i=this.#e,l=i&&!i.busy&&M(i.history,s);i&&!i.busy&&!l&&i.session.destroy();let o=l?i.session:await this.#r().create({...this.#t,...this.#a?{samplingMode:this.#a}:{},initialPrompts:[...s],...t?{signal:t}:{}});this.#o=o.contextWindow??o.inputQuota;let r={session:o,history:s,busy:!0};this.#e=r;let u="",p=!1;try{let f=o.promptStreaming(a.content,{...t?{signal:t}:{},...n?{responseConstraint:n}:{}}).getReader();for(;;){let{done:m,value:y}=await f.read();if(m)break;u+=y,yield{type:"text",text:y}}t?.throwIfAborted(),r.history=[...s,a,{role:"assistant",content:u}],p=!0;let g=o.contextUsage??o.inputUsage;yield{type:"finish",reason:"stop",...g===void 0?{}:{usage:{totalTokens:g}}}}finally{r.busy=!1,(!p||this.#e!==r)&&(o.destroy(),this.#e===r&&(this.#e=void 0))}}async#d(e,n){let t=this.#r();if(await t.availability(this.#t)==="available")return;(await t.create({...this.#t,signal:n,monitor(s){s.addEventListener("downloadprogress",i=>e(i.loaded))}})).destroy()}#s(){return this.#i??(typeof LanguageModel>"u"?void 0:LanguageModel)}#r(){let e=this.#s();if(!e)throw new Error("The Prompt API (LanguageModel) is not available in this browser.");return e}};function M(d,e){return d.length===e.length&&d.every((n,t)=>{let a=e[t];return a!==void 0&&n.role===a.role&&n.content.trim()===a.content.trim()})}export{h as a};
@@ -0,0 +1,41 @@
1
+ /// <reference types="dom-chromium-ai" preserve="true" />
2
+ import { EngineKind, type Availability, type Engine, type EnginePart, type GenerateRequest, type LoadOptions, type ModelSettings } from '../lib/engine.ts';
3
+ /** Native Prompt API declarations supplied by @types/dom-chromium-ai. */
4
+ export type LanguageModelApi = Pick<typeof LanguageModel, 'availability' | 'create'>;
5
+ /** The languages a session must handle, as the browser's Prompt API expects them. */
6
+ export type LanguageModelExpectations = Pick<LanguageModelCreateCoreOptions, 'expectedInputs' | 'expectedOutputs'>;
7
+ /** A Prompt API session (`LanguageModel`). */
8
+ export type LanguageModelSession = LanguageModel;
9
+ /**
10
+ * Takes the same `ModelSettings` as the other engines, so one settings object fits all three.
11
+ * The browser sets the context size and the reply length: only `sampling` applies here.
12
+ */
13
+ export interface PromptApiOptions extends ModelSettings {
14
+ /** Languages of the conversation, for example `['en', 'de']`. Default `['en']`. */
15
+ readonly languages?: readonly string[];
16
+ /** The API to use. Defaults to the browser's global `LanguageModel`. */
17
+ readonly languageModel?: LanguageModelApi;
18
+ }
19
+ /**
20
+ * Engine for the model built into the browser: Gemini Nano in Chrome, Phi-4-mini in Edge.
21
+ * The browser downloads, stores and removes the model itself, so there is no `delete()`.
22
+ * `load()` may need a user gesture.
23
+ */
24
+ export declare class PromptApiEngine implements Engine {
25
+ #private;
26
+ readonly id = "prompt-api";
27
+ readonly kind = EngineKind.PromptApi;
28
+ readonly supportsConstraint = true;
29
+ constructor(options?: PromptApiOptions);
30
+ /**
31
+ * The browser sets the context size and only a session tells it, so it is known from the
32
+ * first answer on.
33
+ */
34
+ get contextWindowSize(): number | undefined;
35
+ /** What the browser answers for the configured languages; `unavailable` without the Prompt API. */
36
+ availability(): Promise<Availability>;
37
+ load(options?: LoadOptions): Promise<void>;
38
+ /** Stops a download this page is waiting for and destroys the kept session. */
39
+ unload(): Promise<void>;
40
+ generate({ messages, constraint, signal, }: GenerateRequest): AsyncGenerator<EnginePart>;
41
+ }
@@ -1,6 +1,6 @@
1
- import type { Availability, Engine, GenerateRequest, LoadOptions } from '../lib/engine.ts';
1
+ import { EngineKind, type Availability, type Engine, type EnginePart, type GenerateRequest, type LoadOptions, type ModelSettings, type Sampling } from '../lib/engine.ts';
2
2
  import type { GenerationConfig } from '@huggingface/transformers';
3
- export interface TransformersJsOptions {
3
+ export interface TransformersJsOptions extends ModelSettings {
4
4
  /**
5
5
  * How the model is loaded.
6
6
  * - `text-generation` (default): text-only models, for example "onnx-community/Qwen3-0.6B-ONNX".
@@ -12,14 +12,24 @@ export interface TransformersJsOptions {
12
12
  readonly device?: 'webgpu' | 'wasm';
13
13
  /** Weight precision. Default `q4f16` on WebGPU and `q4` on WASM. */
14
14
  readonly dtype?: 'q4f16' | 'q4' | 'q8' | 'fp16' | 'fp32';
15
- /** Longest reply in tokens. Default 1024. */
16
- readonly maxNewTokens?: number;
15
+ /** Default 1024. */
16
+ readonly maxOutputTokens?: number;
17
17
  /**
18
- * Any other transformers.js generation setting, passed to every run as it is: `do_sample`,
19
- * `temperature`, `top_p`, `repetition_penalty` and so on. Default `{ do_sample: false }`.
20
- * There is no context size to set: the context is the model's own, limited only by memory.
18
+ * Sets `do_sample` and `temperature`. Default: always the likeliest word (`do_sample: false`),
19
+ * like `most-predictable`.
21
20
  */
22
- readonly generation?: Partial<GenerationConfig>;
21
+ readonly sampling?: Sampling;
22
+ /**
23
+ * How many tokens the agent may send before it compacts the conversation. transformers.js
24
+ * has no context size to set: the context is the model's own, limited only by memory.
25
+ * Without this setting long conversations are never compacted and can run out of GPU memory.
26
+ */
27
+ readonly contextWindowSize?: number;
28
+ /**
29
+ * Any other transformers.js generation setting, passed to every run as it is: `top_p`,
30
+ * `top_k`, `repetition_penalty` and so on. The settings above win over the same option in here.
31
+ */
32
+ readonly native?: Partial<GenerationConfig>;
23
33
  /**
24
34
  * Where model files are stored. `cache-api` (default) is transformers.js' own choice;
25
35
  * `opfs` stores them in the Origin Private File System. transformers.js keeps this setting
@@ -35,11 +45,14 @@ export interface TransformersJsOptions {
35
45
  export declare class TransformersJsEngine implements Engine {
36
46
  #private;
37
47
  readonly id: string;
48
+ readonly kind = EngineKind.TransformersJs;
38
49
  readonly supportsConstraint = false;
50
+ readonly contextWindowSize: number | undefined;
39
51
  constructor(modelId: string, options?: TransformersJsOptions);
52
+ /** `unavailable` without WebGPU (on `device: 'webgpu'`); `available` once the files are cached. */
40
53
  availability(): Promise<Availability>;
41
54
  load(options?: LoadOptions): Promise<void>;
42
55
  unload(): Promise<void>;
43
56
  delete(): Promise<void>;
44
- generate({ messages, signal, }: GenerateRequest): AsyncGenerator<string>;
57
+ generate({ messages, signal, }: GenerateRequest): AsyncGenerator<EnginePart>;
45
58
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { EngineKind, type Availability, type Engine, type EnginePart, type GenerateRequest, type LoadOptions, type ModelSettings, type Sampling } from '../lib/engine.ts';
2
+ import type { AppConfig, ChatOptions } from '@mlc-ai/web-llm';
3
+ export interface WebLlmOptions extends ModelSettings {
4
+ /**
5
+ * Where the model runs. Default: a Web Worker of this package, so the page stays responsive.
6
+ * `false` runs it on the main thread. A function creates your own worker, whose file calls
7
+ * `startWebLlmWorker()` from `@soverius-ai/browser-models/web-llm/worker`. The worker is
8
+ * created once per load; `unload()` and `delete()` terminate it.
9
+ */
10
+ readonly worker?: false | (() => Worker);
11
+ /** WebLLM app config, for example `{ ...prebuiltAppConfig, cacheBackend: 'opfs' }`. */
12
+ readonly appConfig?: AppConfig;
13
+ /**
14
+ * Default: what the model was built with: 4096 for most prebuilt WebLLM models, 2048 or 1024
15
+ * for small ones. A call that needs more fails with WebLLM's
16
+ * `ContextWindowSizeExceededError`. A larger window needs more GPU memory.
17
+ */
18
+ readonly contextWindowSize?: number;
19
+ /** Default: until the model stops or the context is full. */
20
+ readonly maxOutputTokens?: number;
21
+ /** Sets `temperature`. Default: the model's own setting. */
22
+ readonly sampling?: Sampling;
23
+ /**
24
+ * Any other WebLLM chat option, passed to `reload()` as it is: `top_p`, `repetition_penalty`,
25
+ * `sliding_window_size` and so on. The settings above win over the same option in here.
26
+ */
27
+ readonly native?: ChatOptions;
28
+ }
29
+ /**
30
+ * Engine for WebLLM: models compiled for WebGPU, for example "Qwen3-0.6B-q4f16_1-MLC".
31
+ * Weights are stored by WebLLM itself (Cache API by default). The WebLLM library is
32
+ * loaded on first use, so it is not part of your initial bundle.
33
+ */
34
+ export declare class WebLlmEngine implements Engine {
35
+ #private;
36
+ readonly id: string;
37
+ readonly kind = EngineKind.WebLlm;
38
+ readonly supportsConstraint = true;
39
+ constructor(modelId: string, options?: WebLlmOptions);
40
+ /** The `contextWindowSize` option, or what the model was built with (known after `load()`). */
41
+ get contextWindowSize(): number | undefined;
42
+ /** `unavailable` without WebGPU; `available` once WebLLM has the model in its cache. */
43
+ availability(): Promise<Availability>;
44
+ load(options?: LoadOptions): Promise<void>;
45
+ unload(): Promise<void>;
46
+ delete(): Promise<void>;
47
+ generate({ messages, constraint, signal, }: GenerateRequest): AsyncGenerator<EnginePart>;
48
+ }
package/engines.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `@soverius-ai/browser-models/engines`: all three engines, created by `EngineKind`. Needs both engine libraries.
3
+ *
4
+ * @module all-engines
5
+ */
6
+ import { EngineKind } from './lib/engine.ts';
7
+ import { PromptApiEngine, type PromptApiOptions } from './engines/prompt-api.ts';
8
+ import { TransformersJsEngine, type TransformersJsOptions } from './engines/transformers.ts';
9
+ import { WebLlmEngine, type WebLlmOptions } from './engines/web-llm.ts';
10
+ /** The engine class and the constructor arguments of every `EngineKind`. */
11
+ export interface EngineTypes {
12
+ [EngineKind.PromptApi]: {
13
+ engine: PromptApiEngine;
14
+ args: [options?: PromptApiOptions];
15
+ };
16
+ [EngineKind.WebLlm]: {
17
+ engine: WebLlmEngine;
18
+ args: [modelId: string, options?: WebLlmOptions];
19
+ };
20
+ [EngineKind.TransformersJs]: {
21
+ engine: TransformersJsEngine;
22
+ args: [modelId: string, options?: TransformersJsOptions];
23
+ };
24
+ }
25
+ /** Any engine of this library. `switch (engine.kind)` narrows it to its class. */
26
+ export type BrowserEngine = EngineTypes[EngineKind]['engine'];
27
+ /**
28
+ * Creates any engine of this library by its kind, for apps that install all three engine
29
+ * libraries. Apps that use fewer import the engine classes from their own entry points, so
30
+ * the other libraries need not be installed.
31
+ *
32
+ * ```ts
33
+ * Engines.create(EngineKind.WebLlm, 'gemma-4-E2B-it-q4f16_1-MLC', { contextWindowSize: 16384 });
34
+ * Engines.create(EngineKind.PromptApi, { sampling: 'balanced' });
35
+ * ```
36
+ */
37
+ export declare class Engines {
38
+ /** A new engine of `kind`, with that engine's own constructor arguments. */
39
+ static create<Kind extends EngineKind>(kind: Kind, ...args: EngineTypes[Kind]['args']): EngineTypes[Kind]['engine'];
40
+ }
41
+ export { EngineKind };
42
+ export * from './engines/prompt-api.ts';
43
+ export * from './engines/transformers.ts';
44
+ export * from './engines/web-llm.ts';
package/engines.js ADDED
@@ -0,0 +1 @@
1
+ import{a as i}from"./chunk-UZW7NPZG.js";import{a as r}from"./chunk-MPBLCIMW.js";import{a as s}from"./chunk-6TJV26R3.js";import"./chunk-EFSLG2O3.js";import"./chunk-4RAISIWO.js";import{a as g}from"./chunk-T3BB5C4O.js";var m={"prompt-api":n=>new i(n),"web-llm":(n,e)=>new r(n,e),transformers:(n,e)=>new s(n,e)},o=class{static create(e,...p){let t=m[e];return t(...p)}};export{g as EngineKind,o as Engines,i as PromptApiEngine,s as TransformersJsEngine,r as WebLlmEngine};
package/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@soverius-ai/browser-models`: the engine interface, its settings and stream parts, `Models`, `ModelStore` and `OutputParser`. No engine library needed.
3
+ *
4
+ * @module core
5
+ */
6
+ export { EngineKind, SAMPLING_TEMPERATURE, type Availability, type ChatMessage, type Engine, type EnginePart, type FinishReason, type GenerateRequest, type JsonSchema, type LoadOptions, type ModelSettings, type Sampling, type Usage, } from './lib/engine.ts';
7
+ export { AsyncQueue } from './lib/async-queue.ts';
8
+ export { untilAborted } from './lib/abort.ts';
9
+ export { OutputParser, type OutputPart } from './lib/output-parser.ts';
10
+ export { ModelStore, type ModelSource, type ModelState, type ModelStatus, type StorageUse, } from './model-store.ts';
11
+ export { Models } from './models.ts';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ import{a as M}from"./chunk-EFSLG2O3.js";import{a as m,b as k,c as b,d as y}from"./chunk-T3BB5C4O.js";var f=[{kind:"tool-call",open:"```tool_call",close:"```"},{kind:"tool-result",open:"```tool_result",close:"```"},{kind:"tool-call",open:"<tool_call>",close:"</tool_call>"},{kind:"reasoning",open:"<think>",close:"</think>"}],d=class{#e="";#t;push(e){this.#e+=e;let t=[];for(;;){let i=this.#t;if(i){let o=this.#e.indexOf(i.close);if(i.kind==="tool-call"){if(o===-1){let l=this.#e.length-a(this.#e,[i.close]),u=this.#e.slice(0,l).trim();return u&&t.push({kind:"tool-call-partial",raw:u}),t}t.push({kind:"tool-call",raw:this.#e.slice(0,o).trim()})}else if(i.kind==="tool-result"){if(o===-1)return this.#e=this.#e.slice(this.#e.length-a(this.#e,[i.close])),t}else{let l=o===-1?this.#e.length-a(this.#e,[i.close]):o;if(r(t,"reasoning",this.#e.slice(0,l)),o===-1)return this.#e=this.#e.slice(l),t;t.push({kind:"reasoning-end"})}this.#e=this.#e.slice(o+i.close.length),this.#t=void 0;continue}let n=this.#i();if(n){r(t,"text",this.#e.slice(0,n.index)),this.#e=this.#e.slice(n.index+n.block.open.length),this.#t=n.block;continue}let g=a(this.#e,f.map(o=>o.open));return r(t,"text",this.#e.slice(0,this.#e.length-g)),this.#e=this.#e.slice(this.#e.length-g),t}}end(){let e=[];return this.#t?.kind==="tool-call"?e.push({kind:"tool-call-cut",raw:this.#e.trim()}):this.#t?.kind==="reasoning"?(r(e,"reasoning",this.#e),e.push({kind:"reasoning-end"})):this.#t?.kind==="tool-result"||r(e,"text",this.#e),this.#e="",this.#t=void 0,e}#i(){let e;for(let t of f){let i=this.#e.indexOf(t.open);i!==-1&&(!e||i<e.index)&&(e={index:i,block:t})}return e}};function r(s,e,t){t&&s.push({kind:e,text:t})}function a(s,e){let t=0;for(let i of e)for(let n=Math.min(i.length-1,s.length);n>t;n--)if(s.endsWith(i.slice(0,n))){t=n;break}return t}var h=class{agent;modelIds;#e=new Set;#t;constructor(e){this.agent=e,this.modelIds=e.modelIds,this.#t={selectedModel:e.selectedModel,availability:"checking",progress:void 0,error:void 0,models:[],storage:void 0},this.refresh()}getState=()=>this.#t;subscribe=e=>(this.#e.add(e),()=>this.#e.delete(e));async selectModel(e){let t=this.#t.selectedModel;this.agent.selectModel(e),this.#i({selectedModel:e,error:void 0,progress:void 0}),t!==e&&await this.#n(e,()=>this.agent.engine(t).unload()),await this.refresh()}async refresh(){let e=this.#t.selectedModel;this.#i({availability:"checking"});let t=await this.#s(this.agent.engine(e));this.#t.selectedModel===e&&this.#i({availability:t})}async refreshModels(){let e=await Promise.all(this.modelIds.map(async i=>{let n=this.agent.engine(i);return{id:i,engineId:n.id,availability:await this.#s(n),canDelete:n.delete!==void 0}})),t=await globalThis.navigator?.storage?.estimate?.();this.#i({models:e,storage:t?{usage:t.usage??0,quota:t.quota??0}:void 0})}async download(){let e=this.#t.selectedModel;this.#i({availability:"downloading",error:void 0}),await this.#n(e,()=>this.agent.engine(e).load({onProgress:t=>{this.#t.selectedModel===e&&this.#i({progress:t})}})),this.#t.selectedModel===e&&(this.#i({progress:void 0}),await this.refresh(),this.#t.models.length>0&&await this.refreshModels())}async deleteModel(e){await this.#n(this.#t.selectedModel,async()=>this.agent.engine(e).delete?.()),await this.refreshModels(),e===this.#t.selectedModel&&await this.refresh()}#i(e){this.#t={...this.#t,...e};for(let t of this.#e)t()}async#n(e,t){try{await t()}catch(i){!y(i)&&this.#t.selectedModel===e&&this.#i({error:p(i)})}}async#s(e){try{return await e.availability()}catch(t){return this.#i({error:p(t)}),"unavailable"}}};function p(s){return s instanceof Error?s.message:String(s)}var c=class{#e;#t;constructor(e,t){if(!(t in e))throw new Error(`defaultModel "${t}" is not one of the registered models.`);this.#e=e,this.#t=t}get modelIds(){return Object.keys(this.#e)}get selectedModel(){return this.#t}selectModel(e){if(!this.has(e))throw new Error(`Unknown model "${e}".`);this.#t=e}has(e){return Object.hasOwn(this.#e,e)}engine(e=this.#t){if(!this.has(e))throw new Error(`Unknown model "${e}".`);return this.#e[e]}};export{M as AsyncQueue,m as EngineKind,h as ModelStore,c as Models,d as OutputParser,k as SAMPLING_TEMPERATURE,b as untilAborted};
@@ -1,8 +1,12 @@
1
1
  /** Turns callbacks into an async iterable: push values in, read them with `for await`. */
2
2
  export declare class AsyncQueue<T> implements AsyncIterable<T> {
3
3
  #private;
4
+ /** Adds a value for the reader. */
4
5
  push(item: T): void;
6
+ /** Ends the stream after the values pushed so far. */
5
7
  close(): void;
8
+ /** Ends the stream with `error`: the reader throws it after the values pushed so far. */
6
9
  fail(error: unknown): void;
10
+ /** Reads the values with `for await`. Read once. */
7
11
  [Symbol.asyncIterator](): AsyncGenerator<T>;
8
12
  }
@@ -0,0 +1,107 @@
1
+ /** The engines of this library. `engine.kind` tells which one an engine is. */
2
+ export declare enum EngineKind {
3
+ PromptApi = "prompt-api",
4
+ WebLlm = "web-llm",
5
+ TransformersJs = "transformers"
6
+ }
7
+ /** Whether a model can be used right now, needs a download first, or cannot run on this device. */
8
+ export type Availability = 'available' | 'downloadable' | 'downloading' | 'unavailable';
9
+ /** One message in the plain chat format that engines understand. */
10
+ export interface ChatMessage {
11
+ readonly role: 'system' | 'user' | 'assistant';
12
+ readonly content: string;
13
+ }
14
+ /** A JSON Schema object, as used for tool arguments. */
15
+ export type JsonSchema = Readonly<Record<string, unknown>>;
16
+ /** Options of `Engine.load()`. */
17
+ export interface LoadOptions {
18
+ /** Download or load progress from 0 to 1. */
19
+ readonly onProgress?: (fraction: number) => void;
20
+ readonly signal?: AbortSignal;
21
+ }
22
+ /** What `Engine.generate()` gets. */
23
+ export interface GenerateRequest {
24
+ readonly messages: readonly ChatMessage[];
25
+ /** Force the output to match this JSON Schema. Only used when `supportsConstraint` is true. */
26
+ readonly constraint?: JsonSchema;
27
+ readonly signal?: AbortSignal;
28
+ }
29
+ /**
30
+ * How freely the model picks its words, from always the likeliest word to very varied. These
31
+ * are the levels of the Prompt API; WebLLM and transformers.js turn them into a temperature.
32
+ */
33
+ export type Sampling = 'most-predictable' | 'predictable' | 'slightly-predictable' | 'balanced' | 'slightly-creative' | 'creative' | 'most-creative';
34
+ /** The temperature WebLLM and transformers.js use for each sampling level. */
35
+ export declare const SAMPLING_TEMPERATURE: Readonly<Record<Sampling, number>>;
36
+ /**
37
+ * Settings that mean the same for every engine. Each engine takes the ones it supports, so a
38
+ * setting it cannot honour does not compile, and maps them to its library.
39
+ */
40
+ export interface ModelSettings {
41
+ /**
42
+ * How many tokens fit into the context: system prompt, conversation, tool results and the
43
+ * reply. The agent compacts the conversation to fit it.
44
+ */
45
+ readonly contextWindowSize?: number;
46
+ /** Longest reply in tokens. */
47
+ readonly maxOutputTokens?: number;
48
+ readonly sampling?: Sampling;
49
+ }
50
+ /** Tokens of one model call, as the engine counted them. */
51
+ export interface Usage {
52
+ /** Prompt and reply together: what the context holds after the call. */
53
+ readonly totalTokens: number;
54
+ readonly promptTokens?: number;
55
+ readonly outputTokens?: number;
56
+ }
57
+ /** `stop`: the model ended the reply. `length`: the reply reached `maxOutputTokens`. */
58
+ export type FinishReason = 'stop' | 'length';
59
+ /** A piece of a streamed reply. */
60
+ export type EnginePart = {
61
+ readonly type: 'text';
62
+ readonly text: string;
63
+ }
64
+ /** The last part: why the reply ended and, when the engine knows, the tokens it used. */
65
+ | {
66
+ readonly type: 'finish';
67
+ readonly reason: FinishReason;
68
+ readonly usage?: Usage;
69
+ };
70
+ /**
71
+ * A model running in the browser. Engines only turn chat messages into text:
72
+ * tool calling, repair and the AG-UI protocol are handled by the agent.
73
+ */
74
+ export interface Engine {
75
+ /** Stable id, for example "prompt-api" or "web-llm:Qwen3-1.7B-q4f16_1-MLC". */
76
+ readonly id: string;
77
+ /** Which engine of this library it is. Not set for an engine of your own. */
78
+ readonly kind?: EngineKind;
79
+ /** True when `generate` can force JSON output with `constraint`. */
80
+ readonly supportsConstraint: boolean;
81
+ /**
82
+ * How many tokens the model's context holds, prompt and reply together. The agent's
83
+ * compaction reads it after `load()` and cuts the conversation before it gets that long.
84
+ * Leave it out, or undefined, when the engine does not know: the compaction then leaves the
85
+ * conversation as it is.
86
+ */
87
+ readonly contextWindowSize?: number | undefined;
88
+ /** Whether the model can run here, needs a download, or is not supported. Downloads nothing. */
89
+ availability(): Promise<Availability>;
90
+ /** Downloads and loads the model. Browsers may require a user gesture for this. */
91
+ load(options?: LoadOptions): Promise<void>;
92
+ /**
93
+ * Streams the reply: `text` parts while the model writes, then one `finish` part. A reply
94
+ * without a `finish` part counts as stopped by the model. Throws when `signal` aborts.
95
+ */
96
+ generate(request: GenerateRequest): AsyncIterable<EnginePart>;
97
+ /**
98
+ * Frees the model (memory, GPU buffers, worker) and stops a load in progress; callers
99
+ * waiting for that load are rejected. Downloaded files stay, so the next `load()` is fast.
100
+ */
101
+ unload(): Promise<void>;
102
+ /**
103
+ * Unloads the model and removes its files from browser storage, using the library's own
104
+ * API. Optional because the Prompt API model belongs to the browser: a page cannot delete it.
105
+ */
106
+ delete?(): Promise<void>;
107
+ }
@@ -30,6 +30,10 @@ export type OutputPart = {
30
30
  /**
31
31
  * Splits streamed model output into text, thinking and tool calls. Text is passed on as
32
32
  * soon as it cannot be the start of a block, so block syntax never shows up in the chat.
33
+ *
34
+ * The agent reads every reply with it (thinking → `REASONING_*`, tool calls → `TOOL_CALL_*`),
35
+ * and so do the compaction and tool calling, to keep thinking out of summaries and arguments.
36
+ * It is in the core so a chat without AG-UI can split thinking from the answer too.
33
37
  */
34
38
  export declare class OutputParser {
35
39
  #private;
@@ -6,7 +6,9 @@ import type { Availability, Engine } from './lib/engine.ts';
6
6
  export interface ModelSource {
7
7
  readonly modelIds: readonly string[];
8
8
  readonly selectedModel: string;
9
+ /** Switches to another registered model. */
9
10
  selectModel(modelId: string): void;
11
+ /** The engine of a model, by default the selected one. */
10
12
  engine(modelId?: string): Engine;
11
13
  }
12
14
  /** One registered model and whether it is on this device. */
@@ -50,6 +52,7 @@ export declare class ModelStore {
50
52
  /** The ids of all registered models, for a model picker. */
51
53
  readonly modelIds: readonly string[];
52
54
  constructor(agent: ModelSource);
55
+ /** The current state. A new object after every change. */
53
56
  readonly getState: () => ModelState;
54
57
  /** Calls `listener` after every state change. Returns a function that stops it. */
55
58
  readonly subscribe: (listener: () => void) => (() => void);
package/models.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { Engine } from './lib/engine.ts';
2
+ import type { ModelSource } from './model-store.ts';
3
+ /**
4
+ * The models an app may use, by id, and the one it uses now. Selection is always explicit:
5
+ * there is no automatic fallback. Pass it to `ModelStore` for a model picker without an agent;
6
+ * `BrowserModelsAgent` keeps its models in one too. Ids are checked by TypeScript.
7
+ *
8
+ * ```ts
9
+ * const models = new Models({ nano: new PromptApiEngine(), gemma }, 'gemma');
10
+ * if ((await models.engine('nano').availability()) !== 'unavailable') models.selectModel('nano');
11
+ * ```
12
+ */
13
+ export declare class Models<Engines extends Readonly<Record<string, Engine>> = Readonly<Record<string, Engine>>> implements ModelSource {
14
+ #private;
15
+ constructor(engines: Engines, defaultModel: keyof Engines & string);
16
+ /** The ids of the registered models. */
17
+ get modelIds(): readonly (keyof Engines & string)[];
18
+ /** The model in use. Starts as `defaultModel`. */
19
+ get selectedModel(): keyof Engines & string;
20
+ /** Switches to another registered model. */
21
+ selectModel(modelId: keyof Engines & string): void;
22
+ /** True when `modelId` is registered, for ids that come from outside, like a request. */
23
+ has(modelId: string): modelId is keyof Engines & string;
24
+ /** The engine of a model (default: the selected one). */
25
+ engine<Id extends keyof Engines & string>(modelId?: Id): Engines[Id];
26
+ }
package/package.json CHANGED
@@ -1,21 +1,18 @@
1
1
  {
2
2
  "name": "@soverius-ai/browser-models",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
- "main": "./src/index.js",
6
- "types": "./src/index.d.ts",
5
+ "main": "./index.js",
6
+ "types": "./index.d.ts",
7
7
  "dependencies": {
8
- "@ag-ui/client": "1.0.2",
9
- "@ag-ui/core": "1.0.2",
10
- "jsonrepair": "^3.15.0",
11
- "rxjs": "7.8.1",
12
- "tslib": "^2.3.0",
13
- "zod": "^4.2.0"
8
+ "@types/dom-chromium-ai": "^0.0.18"
14
9
  },
15
- "sideEffects": false,
10
+ "sideEffects": [
11
+ "./web-llm-default.worker.js"
12
+ ],
16
13
  "license": "MIT",
17
14
  "homepage": "https://browser-models.soverius.ai",
18
- "description": "Run models in the browser (Prompt API, WebLLM, transformers.js) as AG-UI agents.",
15
+ "description": "Run models in the browser: one engine interface for the Prompt API, WebLLM and transformers.js.",
19
16
  "peerDependencies": {
20
17
  "@mlc-ai/web-llm": "^0.2.88",
21
18
  "@huggingface/transformers": "^4.3.2"
@@ -31,49 +28,34 @@
31
28
  "exports": {
32
29
  "./package.json": "./package.json",
33
30
  ".": {
34
- "types": "./src/index.d.ts",
35
- "import": "./src/index.js",
36
- "default": "./src/index.js"
37
- },
38
- "./agent": {
39
- "types": "./src/agent.d.ts",
40
- "import": "./src/agent.js",
41
- "default": "./src/agent.js"
31
+ "types": "./index.d.ts",
32
+ "import": "./index.js",
33
+ "default": "./index.js"
42
34
  },
43
35
  "./prompt-api": {
44
- "types": "./src/prompt-api.d.ts",
45
- "import": "./src/prompt-api.js",
46
- "default": "./src/prompt-api.js"
36
+ "types": "./prompt-api.d.ts",
37
+ "import": "./prompt-api.js",
38
+ "default": "./prompt-api.js"
47
39
  },
48
40
  "./web-llm": {
49
- "types": "./src/web-llm.d.ts",
50
- "import": "./src/web-llm.js",
51
- "default": "./src/web-llm.js"
41
+ "types": "./web-llm.d.ts",
42
+ "import": "./web-llm.js",
43
+ "default": "./web-llm.js"
52
44
  },
53
45
  "./web-llm/worker": {
54
- "types": "./src/web-llm-worker.d.ts",
55
- "import": "./src/web-llm-worker.js",
56
- "default": "./src/web-llm-worker.js"
46
+ "types": "./web-llm-worker.d.ts",
47
+ "import": "./web-llm-worker.js",
48
+ "default": "./web-llm-worker.js"
57
49
  },
58
50
  "./transformers": {
59
- "types": "./src/transformers.d.ts",
60
- "import": "./src/transformers.js",
61
- "default": "./src/transformers.js"
62
- },
63
- "./webmcp": {
64
- "types": "./src/webmcp.d.ts",
65
- "import": "./src/webmcp.js",
66
- "default": "./src/webmcp.js"
51
+ "types": "./transformers.d.ts",
52
+ "import": "./transformers.js",
53
+ "default": "./transformers.js"
67
54
  },
68
- "./mcp": {
69
- "types": "./src/mcp.d.ts",
70
- "import": "./src/mcp.js",
71
- "default": "./src/mcp.js"
72
- },
73
- "./copilotkit": {
74
- "types": "./src/copilotkit.d.ts",
75
- "import": "./src/copilotkit.js",
76
- "default": "./src/copilotkit.js"
55
+ "./engines": {
56
+ "types": "./engines.d.ts",
57
+ "import": "./engines.js",
58
+ "default": "./engines.js"
77
59
  }
78
60
  },
79
61
  "repository": {
@@ -83,6 +65,5 @@
83
65
  },
84
66
  "publishConfig": {
85
67
  "access": "public"
86
- },
87
- "module": "./src/index.js"
68
+ }
88
69
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@soverius-ai/browser-models/prompt-api`: the model built into the browser (Gemini Nano in Chrome, Phi-4-mini in Edge).
3
+ *
4
+ * @module prompt-api
5
+ */
6
+ export * from './engines/prompt-api.ts';
package/prompt-api.js ADDED
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-UZW7NPZG.js";import"./chunk-4RAISIWO.js";import"./chunk-T3BB5C4O.js";export{o as PromptApiEngine};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@soverius-ai/browser-models/transformers`: ONNX models from the Hugging Face Hub on transformers.js. Needs `@huggingface/transformers`.
3
+ *
4
+ * @module transformers
5
+ */
6
+ export * from './engines/transformers.ts';
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-6TJV26R3.js";import"./chunk-EFSLG2O3.js";import"./chunk-4RAISIWO.js";import"./chunk-T3BB5C4O.js";export{o as TransformersJsEngine};
@@ -0,0 +1 @@
1
+ import{a as r}from"./chunk-T5TQFW45.js";r();
@@ -0,0 +1,6 @@
1
+ /**
2
+ * `@soverius-ai/browser-models/web-llm/worker`: the worker file of `WebLlmEngine`. Needs `@mlc-ai/web-llm`.
3
+ *
4
+ * @module web-llm-worker
5
+ */
6
+ export * from './engines/web-llm-worker.ts';
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-T5TQFW45.js";export{o as startWebLlmWorker};