@godspeedai/cognate-provider-local

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3223

Deterministic offline ModelProvider for tests, demos, and fallback; scripted by rules, never a real model.

原始使用文档
文档目录6 节
  1. Installation
  2. Quick start
  3. Provider surface
  4. Limitations
  5. Related packages
  6. License

@godspeedai/cognate-provider-local

A deterministic, rule-scripted model provider for Cognate applications. It answers from rules you write — no network, no model weights, no randomness: the same request always produces the same response and the same stream chunks.

When to use this package: tests and fixtures that need a ModelProvider without any external dependency, offline demos, and local development before you point an app at a real endpoint. It is never a real model — do not use it where genuine model behavior matters. For real endpoints, use @godspeedai/cognate-provider-openai-compatible.

Installation

bun add @godspeedai/cognate-provider-local

Requires Bun >= 1.4.0. The SDK ships Bun-native TypeScript source, so add @types/bun and @types/node as dev dependencies when typechecking your project.

Quick start

import { localProvider } from "@godspeedai/cognate-provider-local";

const provider = localProvider({
  id: "demo", // provider id becomes `local:demo`
  rules: [
    {
      when: "refund", // matches a case-insensitive substring of the last user message
      respond: () => ({
        message: { role: "assistant", content: "Your refund is approved." },
        toolCalls: [],
        finishReason: "stop",
      }),
    },
    {
      // no `when`: matches everything the earlier rules did not
      respond: () => ({
        message: { role: "assistant", content: "Say 'refund' to exercise the flow." },
        toolCalls: [],
        finishReason: "stop",
      }),
    },
  ],
});

const response = await provider.generate({
  messages: [{ role: "user", content: "Can I get a refund?" }],
});
console.log(response.message.content); // "Your refund is approved."
console.log(response.model);           // "local-rules"

// Streaming yields the same content in text deltas (default 16 chars), then `done`
// with the exact response `generate` would return.
for await (const delta of provider.stream({ messages: [{ role: "user", content: "refund please" }] })) {
  if (delta.type === "text") process.stdout.write(delta.text);
}

Rules match in order: the first rule whose when (omitted means always) is a case-insensitive substring of the last user message produces the response. A rule's respond receives the full request and may return tool calls, so scripted tool-use flows work too. With no matching rule, the provider returns a fixed "no scripted answer" reply.

Provider surface

  • id: local:<id ?? "default">; model: the constant "local-rules".
  • Declared features: stream, tool_use, and structured_output are true; multimodal_input is false; context_limit is 8192. These flags are fixed regardless of what your rules actually do — set expectations in your own eligibility rules when it matters.
  • chunkSize (default 16) controls streamed text-delta length.

Limitations

  • Matching is substring-only: no embeddings, no ranking, no memory of earlier messages.
  • It declares tool-use and structured-output support even though only your rules decide what actually comes back; nothing validates that scripted responses match those flags.
  • Never use it in production paths that need real model judgment — it is deterministic by design.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-provider-local 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-provider-local 的常见问题

@godspeedai/cognate-provider-local 是什么?

Deterministic offline ModelProvider for tests, demos, and fallback; scripted by rules, never a real model.

如何安装 @godspeedai/cognate-provider-local?

在项目目录运行 npm install @godspeedai/cognate-provider-local,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-provider-local 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-provider-local 是否存在。

@godspeedai/cognate-provider-local 支持 ESM 还是 CommonJS?

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

@godspeedai/cognate-provider-local 可以商用吗?

@godspeedai/cognate-provider-local 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@godspeedai/cognate-provider-local 的下载量有多少?

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

@godspeedai/cognate-provider-local 还在维护吗?

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