@plumbus/ai-decision-typesafe 0.2.2 → 0.2.3

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/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ## 0.2.2 — Unreleased
3
+ ## 0.2.3 — 2026-10-08
4
+
5
+ - The README now uses the standard Plumbus package format (badges, Why?, What you get, When to use this vs alternatives, Status, Pricing, Configuration, Key gotchas, Links), keeping all of its earlier content. Runtime behavior and the core peer range are unchanged from 0.2.2.
6
+ - The published dependency on `@plumbus/ai-decision` is now `~0.2.3` (was `~0.2.2`), following the shared package's current version. Shared 0.2.3 validates TypeSafe answers exactly as 0.2.2 did.
7
+
8
+ ## 0.2.2 — 2026-09-23
4
9
 
5
10
  - Document core 0.7.4+ classification with per-call provider/model and probability threshold. Link the packaged classification recipe from agent instructions and correct stale package-only guidance. Core peer compatibility remains `0.7.x`.
6
11
 
package/README.md CHANGED
@@ -1,29 +1,116 @@
1
1
  # @plumbus/ai-decision-typesafe
2
2
 
3
+ > **TypeSafe/Jev decisions for [Plumbus](https://github.com/plumbus-framework/plumbus) AI.** TypeSafe/Jev provider for typed choices, scores, and probabilities, called through `ctx.ai.decide()` / `ctx.ai.classify()` with **input pricing** of the actual response model.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@plumbus/ai-decision-typesafe.svg)](https://www.npmjs.com/package/@plumbus/ai-decision-typesafe)
6
+ [![license](https://img.shields.io/npm/l/@plumbus/ai-decision-typesafe.svg)](https://github.com/plumbus-framework/plumbus/blob/main/LICENSE)
7
+ [![peer: @plumbus/core 0.7.x](https://img.shields.io/badge/peer-%40plumbus%2Fcore%200.7.x-blue)](https://www.npmjs.com/package/@plumbus/core)
8
+
9
+ ## What is this?
10
+
11
+ [Plumbus](https://github.com/plumbus-framework/plumbus) is an **AI-native, contract-driven TypeScript application framework**. Apps call `ctx.ai.decide()` (core 0.7.3+) and `ctx.ai.classify()` (core 0.7.4+) against decision adapters registered under `decisions.providers`, separately from text-generation providers.
12
+
13
+ `@plumbus/ai-decision-typesafe` is the **TypeSafe/Jev System One adapter**. It sends the shared [`@plumbus/ai-decision`](../ai-decision/) contract to TypeSafe's `/systemone` endpoint, checks the answers with the shared validator, and prices the actual response model. It calls the documented HTTP endpoint directly through the shared transport; there is no vendor SDK to install.
14
+
15
+ ## Why?
16
+
17
+ Typed decision models answer bounded questions (one option from a list, a level on an ordered scale, a probability) instead of generating text, so Plumbus registers them apart from text-generation providers. Each vendor ships as its own optional package:
18
+
19
+ - Apps install only the provider they use; no provider depends on another.
20
+ - The contract, validation, and transport live in `@plumbus/ai-decision`, so every provider takes the same request and core checks every result the same way.
21
+
22
+ This package gives apps that use TypeSafe's hosted Jev models a registered decision provider with per-call cost rows.
23
+
24
+ ## What you get
25
+
26
+ | Surface | What it does |
27
+ |---|---|
28
+ | `createTypeSafeDecisionAdapter()` | `DecisionProviderAdapter` (provider name `typesafe`) for `decisions.providers` in `app/server.ts`. |
29
+ | System One mapping | Shared questions to the System One wire format (`probability` maps to `noul`); answers validated by `@plumbus/ai-decision`. |
30
+ | Input pricing | Bundled `jev-1.13.0` rate (`TypeSafeDecisionInputRates`), `inputRates` overrides, priced by the actual response model. |
31
+ | Billed failures | Malformed answers keep the model, usage, and known cost, so core records the billed failure. |
32
+ | Bounded HTTP | Shared transport: deadlines, cancellation, retries on 429 and transient 5xx with `Retry-After`, redirects disabled. |
33
+ | Re-exports | `DecisionProviderError` and the protocol types `DecisionProviderAdapter`, `DecisionQuestions`, `DecisionRequest`, `DecisionResult`. |
34
+
35
+ ## When to use this vs alternatives
36
+
37
+ | You want | Reach for |
38
+ |---|---|
39
+ | Text responses, structured generation, or embeddings | Built-in text providers in `@plumbus/core` |
40
+ | Labels from a generative model | `ctx.ai.classify()` with a text provider (the default) |
41
+ | Hosted typed decisions from TypeSafe/Jev | **`@plumbus/ai-decision-typesafe`** (this package) |
42
+ | Typed decisions on your own servers, no hosted API | [`@plumbus/ai-decision-laya`](../ai-decision-laya/) |
43
+ | Hosted typed decisions from OpenAI (public beta) | [`@plumbus/ai-decision-openai`](../ai-decision-openai/) |
44
+ | Named contracts, answer types, or your own adapter | [`@plumbus/ai-decision`](../ai-decision/) |
45
+
46
+ ## Status
47
+
48
+ Optional decision provider, version `0.2.3` (version-locked **`0.2.x`**); required peer `@plumbus/core` exactly **`0.7.x`**; Node.js 20.6+. **Runtime floor:** `ctx.ai.decide()` needs `@plumbus/core` **≥ 0.7.3** and `ctx.ai.classify({ provider })` needs **≥ 0.7.4**; agent wiring **v17** (core 0.7.4+) links these instructions. Depends on `@plumbus/ai-decision` `~0.2.3`. Install alone is not enough until the adapter is registered under `decisions.providers`.
49
+
50
+ Not included: vendor model catalogs, automatic environment provider discovery, and dedicated decision CLI commands.
51
+
3
52
  Release notes: [changelog](./CHANGELOG.md) and [version/upgrade guide](../../docs/upgrading-classification.md).
4
53
 
5
- TypeSafe/Jev provider for typed choices, scores, and probabilities.
54
+ ## Install
55
+
56
+ ```bash
57
+ pnpm add @plumbus/ai-decision-typesafe
58
+ ```
6
59
 
7
- Version `0.2.2`; required peer `@plumbus/core` exactly `0.7.x`; Node.js 20.6+.
8
60
  Install explicitly with `pnpm add @plumbus/ai-decision-typesafe`. Provider packages install
9
- `@plumbus/ai-decision` transitively. There is no dependency on the other provider.
61
+ `@plumbus/ai-decision` transitively. There is no dependency on the other decision providers.
10
62
 
11
- ## Scope
63
+ Peer (copy literally): `@plumbus/core` `0.7.x`. See `node_modules/@plumbus/core/instructions/peer-dependencies.md`.
64
+
65
+ If agent wiring predates the decision provider instructions, refresh:
66
+
67
+ ```bash
68
+ plumbus init --patch --agent all
69
+ plumbus doctor
70
+ ```
71
+
72
+ ## Quick start
12
73
 
13
74
  Core `0.7.3+` provides `ctx.ai.decide()` with shared validation, security, budgets,
14
75
  and per-call cost recording. Define named contracts with `defineDecision` from
15
76
  `@plumbus/ai-decision`, and export explicit provider registration as `decisions`
16
77
  from `app/server.ts` for API and worker processes. See the
17
78
  [decision integration guide](../../docs/ai/decision-providers.md#application-integration-and-cost-recording).
18
- Direct adapter calls remain useful for infrastructure tests and do not record costs
19
- in core. Keep these adapters separate from the text-generation provider registry.
79
+
80
+ ```ts
81
+ // app/server.ts
82
+ import { createTypeSafeDecisionAdapter } from '@plumbus/ai-decision-typesafe';
83
+
84
+ export const decisions = {
85
+ providers: {
86
+ typesafe: createTypeSafeDecisionAdapter({ apiKey: process.env.TYPESAFE_API_KEY ?? '' }),
87
+ },
88
+ defaultProvider: 'typesafe',
89
+ };
90
+ ```
91
+
92
+ Then, inside a capability handler:
93
+
94
+ ```ts
95
+ const result = await ctx.ai.decide({
96
+ state: { message: input.message },
97
+ questions: {
98
+ refund: { type: 'probability', instructions: 'Does the customer request a refund?' },
99
+ },
100
+ signal: ctx.signal,
101
+ });
102
+ result.answers.refund.probability; // P(true), not a boolean
103
+ ```
20
104
 
21
105
  Core **0.7.4+** also supports `ctx.ai.classify({ text, labels, provider, model, threshold })`
22
106
  for generative or decision models. Start with
23
107
  `node_modules/@plumbus/core/instructions/ai-classification.md` for registration,
24
108
  model defaults, multi-label semantics, and cost recording.
25
109
 
26
- ## Quick start (infrastructure / smoke testing)
110
+ ### Infrastructure / smoke testing
111
+
112
+ Direct adapter calls remain useful for infrastructure tests and do not record costs
113
+ in core. Keep these adapters separate from the text-generation provider registry.
27
114
 
28
115
  ```ts
29
116
  import { createTypeSafeDecisionAdapter } from '@plumbus/ai-decision-typesafe';
@@ -36,22 +123,63 @@ const result = await adapter.decide({
36
123
  console.log(result.answers.refund.probability);
37
124
  ```
38
125
 
39
-
40
126
  Business logic belongs in Plumbus capabilities/flows and `ctx.*`. These examples
41
127
  exercise the provider protocol only; they do not provide the core execution lifecycle.
42
128
 
43
- ## Documentation
129
+ ## Pricing (important)
130
+
131
+ The adapter prices the **actual response model**, not the `jev-latest` alias, from input tokens. The bundled `jev-1.13.0` rate is $0.042 per million input tokens, with free output, verified against [TypeSafe's model documentation](https://docs.typesafe.ai/models) on 2026-09-22. An `inputRates` entry such as `{ 'model-id': rate }` overrides input USD per million tokens.
132
+
133
+ Unknown response models return `cost: null`; they are not free. Core records such calls as unpriced, and when a dollar budget is configured, unpriced prior calls block further calls.
134
+
135
+ ## Configuration
136
+
137
+ | Option | Default | Notes |
138
+ | --- | --- | --- |
139
+ | `apiKey` | required | TypeSafe API key; keep it on the server |
140
+ | `model` | `jev-latest` | Overridden by per-call `model`, then a `defineDecision` contract's `model`, then `decisions.defaultModel` |
141
+ | `baseUrl` | `https://api.typesafe.ai/v1` | API prefix; the adapter appends `/systemone` |
142
+ | `inputRates` | bundled `jev-1.13.0` rate | Input USD per million tokens, keyed by response model ID |
143
+ | `timeoutMs` | `30000` | Whole-call deadline, at most five minutes |
144
+ | `maxRetries` | `2` | Retries HTTP 429 and transient 5xx only (0–5) |
145
+ | `fetch` | `globalThis.fetch` | Injected HTTP implementation for tests |
44
146
 
45
- Read the [decision providers guide](https://github.com/plumbus-framework/plumbus/blob/main/docs/ai/decision-providers.md)
46
- for the complete contract, failure behavior, pricing, deployment, and live test environment.
47
- Local monorepo copy: [docs/ai/decision-providers.md](../../docs/ai/decision-providers.md).
147
+ ## Key gotchas
48
148
 
49
- ## Agent recipes
149
+ - **Register under `decisions`, not as a text provider.** Export `decisions = { providers, defaultProvider }` from `app/server.ts`; API and workers share it. Provider names must be distinct across the text and decision registries.
150
+ - **Direct adapter calls skip core.** They do not enforce core's PII checks, budgets, identity attribution, action confirmation, or ledger hooks. Use `ctx.ai.decide()` / `ctx.ai.classify()` in capabilities and flows.
151
+ - **Unknown cost is `null`, not free.** Only `jev-1.13.0` is bundled; another response model stays unpriced until you add its `inputRates` entry.
152
+ - **Failed calls are recorded.** Core records one row per dispatched call, including failed and cancelled calls; answer-validation failures keep the known model, usage, and cost because the call may already have been billed.
153
+ - **Probabilities are not permissions.** A probability is P(true), not a boolean, and a high confidence value is not authorization or proof of correctness. Validate thresholds on the actual task, model, and language.
154
+ - **Retries can repeat cost.** The transport retries HTTP 429, 500, 502, 503, 504, and 529 (two retries by default, honoring `Retry-After`); repeated requests can still incur cost, with no exactly-once guarantee.
155
+ - **Keys are used as given.** API keys must be printable ASCII without whitespace; credentials are never trimmed.
156
+ - **The local smoke app does not reach TypeSafe.** `examples/ai-decision-smoke` runs this adapter against the local Laya reference service; it does not verify hosted TypeSafe authentication or billing.
50
157
 
51
- - [Instructions index](instructions/README.md)
52
- - [Framework boundary and usage](instructions/framework.md)
53
- - [Testing](instructions/testing.md)
158
+ ## Documentation / Agent recipes
159
+
160
+ - **Concept docs:** read the [decision providers guide](https://github.com/plumbus-framework/plumbus/blob/main/docs/ai/decision-providers.md)
161
+ for the complete contract, failure behavior, pricing, deployment, and live test environment.
162
+ Local monorepo copy: [docs/ai/decision-providers.md](../../docs/ai/decision-providers.md).
163
+ - **Classification recipe** (after install): `node_modules/@plumbus/core/instructions/ai-classification.md`
164
+ - **Live smoke (monorepo):** [`examples/ai-decision-smoke`](../../examples/ai-decision-smoke) runs this adapter and Laya against a local Laya server; `scripts/smoke.mjs` sends one live request when `PLUMBUS_LIVE_DECISION_TESTS=1` and `TYPESAFE_API_KEY` are set (a repository tool, not in the npm package).
165
+ - **Agent recipes** (ship in this package, readable from `node_modules/@plumbus/ai-decision-typesafe/instructions/`):
166
+ - [Instructions index](instructions/README.md)
167
+ - [Framework boundary and usage](instructions/framework.md)
168
+ - [Testing](instructions/testing.md)
54
169
 
55
170
  ## The Plumbus ecosystem
56
171
 
57
172
  `@plumbus/ai-decision-typesafe` is one package in the Plumbus framework. For the full list of packages and when to use each, see the [Plumbus monorepo README](https://github.com/plumbus-framework/plumbus#packages).
173
+
174
+ ## Links
175
+
176
+ - **Plumbus framework** — [github.com/plumbus-framework/plumbus](https://github.com/plumbus-framework/plumbus)
177
+ - **Parent / peer** — [`@plumbus/core`](../plumbus-core/)
178
+ - **Shared contracts** — [`@plumbus/ai-decision`](../ai-decision/)
179
+ - **Full documentation** — [docs/](../../docs/) in the monorepo
180
+ - **Top-level README** — [`../../README.md`](../../README.md)
181
+ - **Issues** — [github.com/plumbus-framework/plumbus/issues](https://github.com/plumbus-framework/plumbus/issues)
182
+
183
+ ## License
184
+
185
+ MIT