@feltdb/webllm

中文文档
0.21.0发布于 2026/11/04MITTypeScriptES Module近 30 天下载 3185

Private, in-browser LLM inference for FeltDB applications

原始使用文档
文档目录8 节
  1. Install
  2. Generate locally
  3. Typed semantic decisions
  4. Choose a model
  5. FeltDB application generation
  6. Contract-aware flow proposals
  7. Workers and lifecycle
  8. Privacy and deployment

@feltdb/webllm

Studio proposes and previews. CLI applies to the repository. FeltDB validates and stores the proposal as application state. Human approves. Nothing else writes source.

This package performs local inference and returns hash-bound proposals. It has no repository filesystem authority.

Pass model to select another WebLLM-compatible local model. Hosted and other OpenAI-compatible models are configured with feltdb ai model set; the CLI keeps their credentials out of the browser. All providers share the Core-owned FlowSpec guide, contract grounding, validation, and constrained repair pass.

Run a small language model entirely in the browser and use it as a FeltDB AI provider. Prompts and inference stay on the user's device; no frontier-model account or hosted inference API is required.

Install

npm install @feltdb/webllm

The package requires a browser with WebGPU. On first use, WebLLM downloads the selected model's artifacts and caches them in the browser.

Generate locally

import { WebLLMProvider } from '@feltdb/webllm';

const llm = new WebLLMProvider({
  onProgress: ({ progress, text }) => {
    console.log(`${Math.round(progress * 100)}%`, text);
  },
});

const answer = await llm.generate([
  { role: 'system', content: 'Return concise JSON.' },
  { role: 'user', content: 'Design a FeltDB task tracker.' },
], {
  responseFormat: { type: 'json_object' },
});

Typed semantic decisions

WebLLMDecisionRuntime is a browser-only evaluator for authorized context. It supports binary, choice, score, and isolated DecisionBatch requests using temperature 1 direct-label logprobs; it has no database or persistence authority.

const runtime = new WebLLMDecisionRuntime({ modelRevision: 'pinned-model-sha' });
const result = await runtime.decide({
  kind: 'choice',
  question: 'Which tier?',
  options: ['free', 'pro'],
  context: authorizedContext,
});

Initialization is lazy: the model loads on the first call to generate() or stream(). Call initialize() earlier to show loading progress sooner.

Choose a model

The default is SmolLM2-360M-Instruct-q4f32_1-MLC, a deliberately small model that needs roughly 580 MB of VRAM. Model selection is configurable:

import { RECOMMENDED_MODELS, WebLLMProvider } from '@feltdb/webllm';

const llm = new WebLLMProvider({
  model: RECOMMENDED_MODELS.balanced,
});
  • smallest: the default 360M model
  • balanced: SmolLM2 1.7B for stronger generation on capable devices
  • lowMemoryWithShaderF16: a smaller 360M quantization for devices supporting the WebGPU shader-f16 feature

Pass any model ID from WebLLM's prebuilt catalog, or call getAvailableModels() to inspect the installed catalog.

FeltDB application generation

Contract-aware flow proposals

generateFlow() grounds a proposal in the deterministic, secret-free contract snapshot shared by Core, the CLI, and Studio. It preserves generic generate() and stream() behavior and never writes files or publishes an application.

const llm = new WebLLMProvider({ contract: snapshot });
const proposal = await llm.generateFlow(
  'Add invitations for organization owners.',
  { currentFlow },
);

The proposal carries the base contract and flow hashes. The CLI refuses stale proposals, parses and semantically validates the proposed DSL, highlights authorization changes, and requires human approval before synchronizing feltdb.flow and the generated integration source. The snapshot contains schema and application definitions, not application records, credentials, connections, or environment configuration.

WebGPU is required only for local inference. Projects that decline the optional WebLLM dependency retain the complete non-AI FeltDB experience.

WebLLMProvider implements FeltDB's message-generation provider contract:

import { ApplicationFactory } from '@feltdb/ai';
import { WebLLMProvider } from '@feltdb/webllm';

const factory = new ApplicationFactory({
  provider: new WebLLMProvider(),
});

const application = await factory.generateApplication(
  'A collaborative, offline-first field inspection app',
);

@feltdb/ai is currently an experimental repository workspace. This package is independently usable through its generate() and stream() APIs.

Workers and lifecycle

Inference runs in the bundled Web Worker by default so execution does not block the UI. Set useWorker: false for main-thread execution, or pass an application-owned worker for custom hosting or CSP behavior.

Call interrupt() to stop generation and shutdown() to unload the model and terminate a package-owned worker.

Privacy and deployment

The model executes locally. Hosting and analytics code can still transmit data, and model files must be fetched before they are cached, so review your app's network and content-security policies. This package does not send prompts to FeltDB or an inference provider.

MIT licensed.

版本与发布记录

@feltdb/webllm 共发布 83 个版本,首次发布于 2026/08/18;过去 12 个月发布了 83 个版本。

版本发布日期距今
0.21.0latest2026/11/0410 天前
0.20.02026/11/0410 天前
0.19.02026/11/0410 天前
0.18.02026/11/0311 天前
0.17.12026/11/0212 天前
0.17.02026/10/3114 天前

关于 @feltdb/webllm 的常见问题

@feltdb/webllm 是什么?

Private, in-browser LLM inference for FeltDB applications

如何安装 @feltdb/webllm?

在项目目录运行 npm install @feltdb/webllm,或使用 pnpm add / yarn add / bun add。

@feltdb/webllm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@feltdb/webllm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@feltdb/webllm 可以商用吗?

@feltdb/webllm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@feltdb/webllm 的下载量有多少?

根据 npm 官方下载统计,@feltdb/webllm 在 2026/10/15 – 2026/11/13 这 30 天内被下载 3,185 次,日均约 106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@feltdb/webllm 还在维护吗?

最新版本 0.21.0 发布于 2026/11/04(10 天前);至今共发布 83 个版本,其中过去 12 个月发布了 83 个;首次发布于 2026/08/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。