@godspeedai/cognate-provider-local 0.1.0 → 0.1.2

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 (2) hide show
  1. package/README.md +94 -12
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,14 +1,96 @@
1
1
  # @godspeedai/cognate-provider-local
2
2
 
3
- A deterministic, rule-scripted `ModelProvider` (spec §26) for tests, demos,
4
- and offline fallback. It is never a real model: `localProvider(options)`
5
- matches `rules` in order by a case-insensitive substring of the last user
6
- message and returns the first match's `respond(request)`. No match returns
7
- a fixed "no scripted answer" reply.
8
-
9
- Provider id is `local:<id ?? "default">`, model is the constant
10
- `"local-rules"`, and every feature flag is `true` except
11
- `multimodal_input`. `generate` and `stream` on the same request always
12
- agree: `stream` chunks the generated content into `chunkSize` (default 16)
13
- character text deltas, then yields `done` with the exact response
14
- `generate` would return.
3
+ A deterministic, rule-scripted model provider for Cognate applications. It answers from rules
4
+ you write — no network, no model weights, no randomness: the same request always produces the
5
+ same response and the same stream chunks.
6
+
7
+ **When to use this package:** tests and fixtures that need a `ModelProvider` without any
8
+ external dependency, offline demos, and local development before you point an app at a real
9
+ endpoint. It is never a real model — do not use it where genuine model behavior matters.
10
+ For real endpoints, use
11
+ [`@godspeedai/cognate-provider-openai-compatible`](https://www.npmjs.com/package/@godspeedai/cognate-provider-openai-compatible).
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ bun add @godspeedai/cognate-provider-local
17
+ ```
18
+
19
+ Requires [Bun](https://bun.sh) >= 1.4.0. The SDK ships Bun-native TypeScript source, so add
20
+ `@types/bun` and `@types/node` as dev dependencies when typechecking your project.
21
+
22
+ ## Quick start
23
+
24
+ ```ts
25
+ import { localProvider } from "@godspeedai/cognate-provider-local";
26
+
27
+ const provider = localProvider({
28
+ id: "demo", // provider id becomes `local:demo`
29
+ rules: [
30
+ {
31
+ when: "refund", // matches a case-insensitive substring of the last user message
32
+ respond: () => ({
33
+ message: { role: "assistant", content: "Your refund is approved." },
34
+ toolCalls: [],
35
+ finishReason: "stop",
36
+ }),
37
+ },
38
+ {
39
+ // no `when`: matches everything the earlier rules did not
40
+ respond: () => ({
41
+ message: { role: "assistant", content: "Say 'refund' to exercise the flow." },
42
+ toolCalls: [],
43
+ finishReason: "stop",
44
+ }),
45
+ },
46
+ ],
47
+ });
48
+
49
+ const response = await provider.generate({
50
+ messages: [{ role: "user", content: "Can I get a refund?" }],
51
+ });
52
+ console.log(response.message.content); // "Your refund is approved."
53
+ console.log(response.model); // "local-rules"
54
+
55
+ // Streaming yields the same content in text deltas (default 16 chars), then `done`
56
+ // with the exact response `generate` would return.
57
+ for await (const delta of provider.stream({ messages: [{ role: "user", content: "refund please" }] })) {
58
+ if (delta.type === "text") process.stdout.write(delta.text);
59
+ }
60
+ ```
61
+
62
+ Rules match in order: the first rule whose `when` (omitted means always) is a case-insensitive
63
+ substring of the last user message produces the response. A rule's `respond` receives the full
64
+ request and may return tool calls, so scripted tool-use flows work too. With no matching rule,
65
+ the provider returns a fixed "no scripted answer" reply.
66
+
67
+ ## Provider surface
68
+
69
+ - `id`: `local:<id ?? "default">`; `model`: the constant `"local-rules"`.
70
+ - Declared features: `stream`, `tool_use`, and `structured_output` are `true`;
71
+ `multimodal_input` is `false`; `context_limit` is `8192`. These flags are fixed regardless
72
+ of what your rules actually do — set expectations in your own eligibility rules when it
73
+ matters.
74
+ - `chunkSize` (default `16`) controls streamed text-delta length.
75
+
76
+ ## Limitations
77
+
78
+ - Matching is substring-only: no embeddings, no ranking, no memory of earlier messages.
79
+ - It declares tool-use and structured-output support even though only your rules decide what
80
+ actually comes back; nothing validates that scripted responses match those flags.
81
+ - Never use it in production paths that need real model judgment — it is deterministic by
82
+ design.
83
+
84
+ ## Related packages
85
+
86
+ - [`@godspeedai/cognate-capabilities`](https://www.npmjs.com/package/@godspeedai/cognate-capabilities) —
87
+ the `ModelProvider` contract and selection engine this provider implements.
88
+ - [`@godspeedai/cognate-provider-openai-compatible`](https://www.npmjs.com/package/@godspeedai/cognate-provider-openai-compatible) —
89
+ the provider for real OpenAI-compatible HTTP endpoints.
90
+ - [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun) —
91
+ the reference runtime; pass a provider to give agents a model.
92
+ - [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
93
+
94
+ ## License
95
+
96
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godspeedai/cognate-provider-local",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Deterministic offline ModelProvider for tests, demos, and fallback; scripted by rules, never a real model.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -22,8 +22,8 @@
22
22
  ".": "./src/index.ts"
23
23
  },
24
24
  "dependencies": {
25
- "@godspeedai/cognate-capabilities": "^0.1.0",
26
- "@godspeedai/cognate-events": "^0.1.0",
27
- "@godspeedai/cognate-kernel-api": "^0.1.0"
25
+ "@godspeedai/cognate-capabilities": "^0.1.2",
26
+ "@godspeedai/cognate-events": "^0.1.2",
27
+ "@godspeedai/cognate-kernel-api": "^0.1.2"
28
28
  }
29
29
  }