@dudko.dev/agent-web 0.0.21 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/dist/agent-web.js +93 -91
- package/dist/agent-web.js.map +1 -1
- package/dist/chunk-YA6TQQ3Q.js +425 -0
- package/dist/chunk-YA6TQQ3Q.js.map +1 -0
- package/dist/index.cjs +504 -270
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -9
- package/dist/index.d.ts +102 -9
- package/dist/index.js +76 -244
- package/dist/index.js.map +1 -1
- package/dist/{webllm-XUBUNKFN.js → webllm-QTJ3EGTG.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-IT65EW77.js +0 -38
- package/dist/chunk-IT65EW77.js.map +0 -1
- /package/dist/{webllm-XUBUNKFN.js.map → webllm-QTJ3EGTG.js.map} +0 -0
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
isWebGPUAvailable,
|
|
4
4
|
preloadWebLLMModel,
|
|
5
5
|
unloadWebLLMModel
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YA6TQQ3Q.js";
|
|
7
7
|
export {
|
|
8
8
|
createWebLLMModel,
|
|
9
9
|
isWebGPUAvailable,
|
|
10
10
|
preloadWebLLMModel,
|
|
11
11
|
unloadWebLLMModel
|
|
12
12
|
};
|
|
13
|
-
//# sourceMappingURL=webllm-
|
|
13
|
+
//# sourceMappingURL=webllm-QTJ3EGTG.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudko.dev/agent-web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "Headless, configurable in-browser LLM agent on the Vercel AI SDK: multi-provider bring-your-own-key (OpenAI, Anthropic, Google, xAI, DeepSeek, gateway, openai-compatible) AND local WebGPU/WebLLM, native + prompted tool-calling, structured output, an encrypted IndexedDB token vault, and a plan → execute → replan → synthesize loop. UI-agnostic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
package/dist/chunk-IT65EW77.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// src/providers/webllm.ts
|
|
2
|
-
import { generateText } from "ai";
|
|
3
|
-
var isWebGPUAvailable = () => typeof navigator !== "undefined" && "gpu" in navigator;
|
|
4
|
-
var preloadWebLLMModel = async (model) => {
|
|
5
|
-
await generateText({ model, prompt: "ok", maxOutputTokens: 1 });
|
|
6
|
-
};
|
|
7
|
-
var unloadWebLLMModel = async (model) => {
|
|
8
|
-
const engine = model.engine;
|
|
9
|
-
try {
|
|
10
|
-
await engine?.unload?.();
|
|
11
|
-
} catch {
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var createWebLLMModel = async (model, options) => {
|
|
15
|
-
let mod;
|
|
16
|
-
try {
|
|
17
|
-
mod = await import("@browser-ai/web-llm");
|
|
18
|
-
} catch {
|
|
19
|
-
throw new Error(
|
|
20
|
-
'Local models require "@browser-ai/web-llm" and its peer "@mlc-ai/web-llm". Install: npm install @browser-ai/web-llm @mlc-ai/web-llm'
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
const { preload = true, ...settings } = options ?? {};
|
|
24
|
-
const languageModel = mod.webLLM(
|
|
25
|
-
model,
|
|
26
|
-
settings
|
|
27
|
-
);
|
|
28
|
-
if (preload) await preloadWebLLMModel(languageModel);
|
|
29
|
-
return languageModel;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
isWebGPUAvailable,
|
|
34
|
-
preloadWebLLMModel,
|
|
35
|
-
unloadWebLLMModel,
|
|
36
|
-
createWebLLMModel
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=chunk-IT65EW77.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/providers/webllm.ts"],"sourcesContent":["import { generateText, type LanguageModel } from 'ai'\n\n/** WebGPU feature-detect — WebLLM requires it. Call before offering local models. */\nexport const isWebGPUAvailable = (): boolean =>\n typeof navigator !== 'undefined' && 'gpu' in navigator\n\nexport interface WebLLMModelOptions {\n /**\n * Progress callback for weight download / engine init. `report.progress` is\n * 0..1. Forwarded to WebLLM's `initProgressCallback`.\n */\n initProgressCallback?: (report: { progress: number; text: string }) => void\n /**\n * Download the weights and initialize the engine NOW (default true).\n *\n * The underlying provider initializes lazily on the first generation — with\n * a multi-GB model that means the download would silently happen on the\n * user's first message, with `initProgressCallback` never firing at a moment\n * the host can show it. Preloading runs a 1-token warm-up so the returned\n * model is truly ready and progress is reported during creation. Re-creating\n * an already-downloaded model is fast (weights live in the browser cache).\n *\n * Set to `false` to keep the lazy behavior.\n */\n preload?: boolean\n /** Any other @browser-ai/web-llm setting (temperature, worker handler, …). */\n [k: string]: unknown\n}\n\n/**\n * Force a model to download its weights and initialize its engine by running\n * a 1-token generation. Exposed for hosts that create models with\n * `preload: false` and want to warm them up later (e.g. behind their own UI).\n */\nexport const preloadWebLLMModel = async (model: LanguageModel): Promise<void> => {\n await generateText({ model, prompt: 'ok', maxOutputTokens: 1 })\n}\n\n/**\n * Best-effort release of a model's GPU memory (call when switching models —\n * an abandoned engine otherwise holds its buffers until the page reloads).\n *\n * `@browser-ai/web-llm` keeps its MLCEngine private and exposes no public\n * `unload()`, so this reaches into the instance defensively; it is a no-op on\n * an uninitialized model or if the provider's internals change shape.\n */\nexport const unloadWebLLMModel = async (model: LanguageModel): Promise<void> => {\n const engine = (model as { engine?: { unload?: () => Promise<void> } }).engine\n try {\n await engine?.unload?.()\n } catch {\n /* best-effort */\n }\n}\n\n/**\n * Build an AI SDK `LanguageModel` backed by WebLLM (WebGPU) via the community\n * provider `@browser-ai/web-llm` (an optional peer, dynamically imported so it\n * is code-split and never loads until a local model is actually used). Accepts\n * any WebLLM prebuilt model id, e.g. \"Llama-3.2-3B-Instruct-q4f16_1-MLC\".\n *\n * By default the weights are downloaded eagerly with progress (see\n * `WebLLMModelOptions.preload`).\n */\nexport const createWebLLMModel = async (\n model: string,\n options?: WebLLMModelOptions,\n): Promise<LanguageModel> => {\n let mod: typeof import('@browser-ai/web-llm')\n try {\n mod = await import('@browser-ai/web-llm')\n } catch {\n throw new Error(\n 'Local models require \"@browser-ai/web-llm\" and its peer \"@mlc-ai/web-llm\". Install: npm install @browser-ai/web-llm @mlc-ai/web-llm',\n )\n }\n const { preload = true, ...settings } = options ?? {}\n // webLLM(modelId, settings) returns a LanguageModel. The model id is a strict\n // union in the provider's types; we accept any string and cast at the seam.\n const languageModel = mod.webLLM(\n model as Parameters<typeof mod.webLLM>[0],\n settings as Parameters<typeof mod.webLLM>[1],\n )\n if (preload) await preloadWebLLMModel(languageModel)\n return languageModel\n}\n"],"mappings":";AAAA,SAAS,oBAAwC;AAG1C,IAAM,oBAAoB,MAC/B,OAAO,cAAc,eAAe,SAAS;AA8BxC,IAAM,qBAAqB,OAAO,UAAwC;AAC/E,QAAM,aAAa,EAAE,OAAO,QAAQ,MAAM,iBAAiB,EAAE,CAAC;AAChE;AAUO,IAAM,oBAAoB,OAAO,UAAwC;AAC9E,QAAM,SAAU,MAAwD;AACxE,MAAI;AACF,UAAM,QAAQ,SAAS;AAAA,EACzB,QAAQ;AAAA,EAER;AACF;AAWO,IAAM,oBAAoB,OAC/B,OACA,YAC2B;AAC3B,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,OAAO,qBAAqB;AAAA,EAC1C,QAAQ;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,EAAE,UAAU,MAAM,GAAG,SAAS,IAAI,WAAW,CAAC;AAGpD,QAAM,gBAAgB,IAAI;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AACA,MAAI,QAAS,OAAM,mBAAmB,aAAa;AACnD,SAAO;AACT;","names":[]}
|
|
File without changes
|