@kanzo-tech/llm
v0.46.0
Published
The two doors to a model's answer, without React — `stream` and `generate`, each asking once, over the AI SDK, which it does not re-export — `localModel` on `/local`, a model in the page resolved through one provider registry, and on `/testing` the one mo
Readme
@kanzo-tech/llm
The two doors to a model's answer, without React.
npm install @kanzo-tech/llm ai
npm install @browser-ai/web-llm @mlc-ai/web-llm # for localModel, a model in the pageai is a required peer, not an optional one: there is nothing here without it, and a host
installs it once so that its own agent and @kanzo-tech/ai's components share one UIMessage and
one transport. None of it is re-exported: import ToolLoopAgent, tool, Output and the
message types from ai by name, as every package here does.
What it holds
import { generate, stream, LlmError } from "@kanzo-tech/llm";
import { localModel, localProvider, setLocalProvider, serveLocalModel } from "@kanzo-tech/llm/local";
import { scriptedModel } from "@kanzo-tech/llm/testing";stream({ model, system, prompt, output })— an answer as it is written:streamText, never retried, read astext,elements(Output.array) orpartial(Output.object), each of which throws what stopped the model once it ends. The SDK alone reports a failed stream toonErrorand ends it as if it had finished.generate({ …, providerOptions })— the same, read whole:generateText, asked once. Every model call the library makes goes through one of the two.LlmError—llm/unavailable,data.reason"webgpu"(the page cannot run a model) or"unserved"(nothing serves it).localModel(id?), from@kanzo-tech/llm/local— the model, in the page, resolved by id through one provider registry: a host sets its provider once,setLocalProvider(localProvider({ baseURL: "/models", worker })), and every model listed in/models/app-config.json(WebLLM'sAppConfig) is served; without an id, the first. WebLLM on WebGPU through@browser-ai/web-llm: both optional peers that only this subpath reaches. One engine per model per page; without WebGPU a call fails asLlmError, before anything is downloaded. A call may passproviderOptions.kanzo.grammar, an EBNF the engine holds every token to.loadLocalModel(id?)downloads and loads it before the first call, andlocalModelLoad(id?)/watchLocalModel(id, listener)say where that stands.serveLocalModel()is the worker's whole script.scriptedModel(script), from@kanzo-tech/llm/testing— the one model double: the AI SDK'sMockLanguageModelV4answering from a script of turns. A unit test passes it where a model goes; an end-to-end test registers the script with@kanzo-tech/testing'splaywright(page, { models }), which registers it as that id's provider in the same registry.
Why it is not part of @kanzo-tech/ai
Reaching a model is not a user-interface concern, and not every caller draws one: a host's agent,
a server route or a test needs the model and none of the components. @kanzo-tech/ai depends on
this package and not the other way round.
