@molecule/api-ai-decisions-kev 0.0.0-stage → 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,397 @@
1
- # Temporary Holding Version
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-10-07T04:32:01.339Z
7
+ -->
2
8
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
9
+ # @molecule/api-ai-decisions-kev
10
+
11
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
+ > It is written to be read by coding agents as much as by people, and is generated from this
13
+ > package's source — edit `src/index.ts` JSDoc, not this file.
14
+
15
+ Kev decisions provider for molecule.dev — typed decisions from the
16
+ open-weights Kev models on a `kev.serve` host you run.
17
+
18
+ Kev (github.com/jaredpalmer/kev; code and weights Apache-2.0) is a family of
19
+ Qwen-based decision models — Kev-0.8B, 4B and 9B (LoRA adapters on
20
+ Qwen3.5-*-Base) and Kev-27B (a full fine-tune of Qwen3.8-27B) — that answer
21
+ `choice`, `score` and yes/no questions with calibrated probabilities and
22
+ generate no text. Its README recommends Kev-4B as the default. `kev.serve`
23
+ speaks TypeSafe Jev's `/v1/systemone` protocol, so swapping to
24
+ `@molecule/api-ai-decisions-jev`, `-laya` or `-jeff` is a one-line change.
25
+
26
+ ## Quick Start
27
+
28
+ ```bash
29
+ # Run the model server (NVIDIA/AMD GPU, or Apple silicon via MLX; Python 3.12/3.13)
30
+ git clone https://github.com/jaredpalmer/kev.git && cd kev && uv sync --extra serve
31
+ KEV_API_KEY=change-me uv run --extra serve python -m kev.serve --run jaredpalmer/kev-4b@v1.0
32
+ ```
33
+
34
+ ```typescript
35
+ import { setProvider, requireProvider } from '@molecule/api-ai-decisions'
36
+ import { provider } from '@molecule/api-ai-decisions-kev'
37
+
38
+ setProvider(provider) // reads KEV_URL + KEV_API_KEY on first use
39
+
40
+ const { answers } = await requireProvider().decide({
41
+ state: 'My card was charged twice, please refund one of them',
42
+ questions: {
43
+ queue: {
44
+ type: 'choice',
45
+ instructions: 'Which team?',
46
+ criteria: { billing: 'charges, refunds', tech: 'bugs, login' },
47
+ },
48
+ refund: { type: 'yesNo', instructions: 'The customer wants a refund.' },
49
+ },
50
+ })
51
+ answers.queue.choice // 'billing'
52
+ answers.refund.probability // 0.93
53
+ ```
54
+
55
+ ## Type
56
+
57
+ `provider`
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ npm install @molecule/api-ai-decisions-kev @molecule/api-ai-decisions @molecule/api-secrets
63
+ ```
64
+
65
+ ## API
66
+
67
+ ### Interfaces
68
+
69
+ #### `KevConfig`
70
+
71
+ Configuration for the Kev decisions provider.
72
+
73
+ ```typescript
74
+ interface KevConfig {
75
+ /** Base URL of the `kev.serve` host. Defaults to `KEV_URL`, then `http://localhost:8008`. */
76
+ baseUrl?: string
77
+ /** Bearer token, when the server sets `KEV_API_KEY`. Defaults to the `KEV_API_KEY` env var. */
78
+ apiKey?: string
79
+ /**
80
+ * Extra request headers, resolved before each call and merged over the
81
+ * defaults — for a host whose auth expires or is not a bearer token (a Cloud
82
+ * Run ID token, Modal proxy auth). Pair with `@molecule/api-model-hosting`:
83
+ * `headers: () => hosting.authHeaders(endpoint.id)`.
84
+ */
85
+ headers?: () => Record<string, string> | Promise<Record<string, string>>
86
+ /**
87
+ * Model id sent on every request. `kev.serve` accepts any string and echoes
88
+ * it back; it never selects a checkpoint (the server answers with the one
89
+ * it loaded via `--run`). Defaults to `'kev-latest'`.
90
+ */
91
+ model?: string
92
+ /**
93
+ * Most `choice` options / `score` levels sent in one question. Defaults to
94
+ * 255, `kev.serve`'s own limit. Lower it for another `/v1/systemone` server
95
+ * with a smaller one (Nimble: 26).
96
+ */
97
+ maxOptions?: number
98
+ /**
99
+ * Milliseconds to wait for one `decide()` (retries included) before
100
+ * aborting. Defaults to 120000 — long enough for a scale-to-zero host's
101
+ * cold start (~35 s on Modal) plus the model load.
102
+ */
103
+ timeoutMs?: number
104
+ }
105
+ ```
106
+
107
+ #### `PostOptions`
108
+
109
+ Options for {@link postSystemOne}.
110
+
111
+ ```typescript
112
+ interface PostOptions {
113
+ /** Full endpoint URL. */
114
+ url: string
115
+ /** Bearer token, if any. */
116
+ apiKey?: string
117
+ /** Extra headers resolved before the request (merged over the defaults). */
118
+ headers?: () => Record<string, string> | Promise<Record<string, string>>
119
+ /** Request body. */
120
+ body: Record<string, unknown>
121
+ /** Abort signal. */
122
+ signal?: AbortSignal
123
+ /** Label for error messages (`'Kev'`). */
124
+ label: string
125
+ /** Max retries on a retryable status (default 3). */
126
+ maxRetries?: number
127
+ }
128
+ ```
129
+
130
+ #### `WireAnswer`
131
+
132
+ One answer as received on the wire (only the fields we read).
133
+
134
+ ```typescript
135
+ interface WireAnswer {
136
+ type?: string
137
+ choice?: string
138
+ score?: number
139
+ noul?: number
140
+ probabilities?: Record<string, number>
141
+ }
142
+ ```
143
+
144
+ #### `WireQuestion`
145
+
146
+ One question as sent on the wire.
147
+
148
+ ```typescript
149
+ interface WireQuestion {
150
+ type: 'choice' | 'score' | 'noul'
151
+ instructions: string
152
+ criteria?: Record<string, string> | string[]
153
+ }
154
+ ```
155
+
156
+ #### `WireResponse`
157
+
158
+ The response body (only the fields we read).
159
+
160
+ ```typescript
161
+ interface WireResponse {
162
+ model?: string
163
+ answers?: Record<string, WireAnswer>
164
+ usage?: { input_tokens?: number; output_tokens?: number }
165
+ }
166
+ ```
167
+
168
+ ### Functions
169
+
170
+ #### `createProvider(config)`
171
+
172
+ Creates a Kev decisions provider.
173
+
174
+ ```typescript
175
+ function createProvider(config?: KevConfig): AIDecisionsProvider
176
+ ```
177
+
178
+ - `config` — Base URL, API key, headers hook, model id, option limit and timeout.
179
+
180
+ **Returns:** An `AIDecisionsProvider` backed by a `kev.serve` host.
181
+
182
+ #### `fromWireAnswer(id, question, wire, minConfidence)`
183
+
184
+ Converts one wire answer into the core's answer for `question`.
185
+
186
+ ```typescript
187
+ function fromWireAnswer(
188
+ id: string,
189
+ question: DecisionQuestion,
190
+ wire: WireAnswer | undefined,
191
+ minConfidence?: number,
192
+ ): DecisionAnswer
193
+ ```
194
+
195
+ - `id` — The question id (for error messages).
196
+ - `question` — The question that was asked.
197
+ - `wire` — The wire answer.
198
+ - `minConfidence` — Optional low-confidence threshold.
199
+
200
+ **Returns:** The typed answer.
201
+
202
+ #### `fromWireResponse(questions, body, minConfidence)`
203
+
204
+ Converts a whole wire response into the core's result.
205
+
206
+ ```typescript
207
+ function fromWireResponse(questions: Q, body: WireResponse, minConfidence?: number): DecideResult<Q>
208
+ ```
209
+
210
+ - `questions` — The questions that were asked.
211
+ - `body` — The parsed response body.
212
+ - `minConfidence` — Optional low-confidence threshold.
213
+
214
+ **Returns:** The typed result.
215
+
216
+ #### `postSystemOne(opts)`
217
+
218
+ POSTs a `/v1/systemone` request with retry on 429/5xx-busy, honouring
219
+ `Retry-After`. Throws an Error carrying `status` on a non-2xx response.
220
+
221
+ ```typescript
222
+ function postSystemOne(opts: PostOptions): Promise<WireResponse>
223
+ ```
224
+
225
+ - `opts` — Request options.
226
+
227
+ **Returns:** The parsed response body.
228
+
229
+ #### `toWireQuestions(questions)`
230
+
231
+ Converts the core's questions into wire questions (`yesNo` → `noul`).
232
+
233
+ ```typescript
234
+ function toWireQuestions(questions: Record<string, DecisionQuestion>): Record<string, WireQuestion>
235
+ ```
236
+
237
+ - `questions` — The questions keyed by id.
238
+
239
+ **Returns:** The wire `questions` object.
240
+
241
+ ### Constants
242
+
243
+ #### `aiDecisionsKevSecretDefinitions`
244
+
245
+ Secret definitions used by the Kev decisions bond.
246
+
247
+ ```typescript
248
+ const aiDecisionsKevSecretDefinitions: SecretDefinition[]
249
+ ```
250
+
251
+ #### `DEFAULT_KEV_MAX_OPTIONS`
252
+
253
+ Most `choice` options or `score` levels `kev.serve` accepts (`MAX_OPTIONS` in `kev/api.py`).
254
+
255
+ ```typescript
256
+ const DEFAULT_KEV_MAX_OPTIONS: 255
257
+ ```
258
+
259
+ #### `DEFAULT_KEV_MODEL`
260
+
261
+ The model id `kev.serve` documents; any string is echoed back, none selects a checkpoint.
262
+
263
+ ```typescript
264
+ const DEFAULT_KEV_MODEL: 'kev-latest'
265
+ ```
266
+
267
+ #### `DEFAULT_KEV_TIMEOUT_MS`
268
+
269
+ Default per-call timeout: room for a scale-to-zero cold start (~35 s on Modal).
270
+
271
+ ```typescript
272
+ const DEFAULT_KEV_TIMEOUT_MS: 120000
273
+ ```
274
+
275
+ #### `DEFAULT_KEV_URL`
276
+
277
+ `kev.serve`'s default bind (`--port` defaults to 8008; its README examples use 8009).
278
+
279
+ ```typescript
280
+ const DEFAULT_KEV_URL: 'http://localhost:8008'
281
+ ```
282
+
283
+ #### `provider`
284
+
285
+ The provider implementation — lazy, so env vars are read on first use.
286
+
287
+ ```typescript
288
+ const provider: AIDecisionsProvider
289
+ ```
290
+
291
+ ## Core Interface
292
+
293
+ Implements `@molecule/api-ai-decisions` interface.
294
+
295
+ ## Bond Wiring
296
+
297
+ Setup function to register this provider with the core interface:
298
+
299
+ ```typescript
300
+ import { setProvider } from '@molecule/api-ai-decisions'
301
+ import { provider } from '@molecule/api-ai-decisions-kev'
302
+
303
+ export function setupAiDecisionsKev(): void {
304
+ setProvider(provider)
305
+ }
306
+ ```
307
+
308
+ ## Injection Notes
309
+
310
+ ### Requirements
311
+
312
+ Peer dependencies:
313
+
314
+ - `@molecule/api-ai-decisions` ^1.1.0
315
+ - `@molecule/api-secrets` ^1.0.1
316
+
317
+ ### Environment Variables
318
+
319
+ - `KEV_URL` _(optional)_ — Kev server URL
320
+ - Setup: The base URL of your kev.serve host (clone github.com/jaredpalmer/kev, uv sync --extra serve, then uv run --extra serve python -m kev.serve --run jaredpalmer/kev-4b@v1.0). Defaults to http://localhost:8008.
321
+ - Get it here: [https://github.com/jaredpalmer/kev#readme](https://github.com/jaredpalmer/kev#readme)
322
+ - Example: `http://localhost:8008`
323
+ - `KEV_API_KEY` _(optional)_ — Kev server API key
324
+ - Setup: The bearer token your kev.serve host requires, if you set KEV_API_KEY on the server.
325
+ - Get it here: [https://github.com/jaredpalmer/kev#readme](https://github.com/jaredpalmer/kev#readme)
326
+ - Example: `a-long-random-string`
327
+
328
+ ### Runtime Dependencies
329
+
330
+ - `@molecule/api-ai-decisions`
331
+ - `@molecule/api-secrets`
332
+
333
+ - **You run the model.** `KEV_URL` (default `http://localhost:8008`, the
334
+ server's own default port) points at a `kev.serve` host; its README
335
+ examples use `--port 8009`, so set `KEV_URL` to match. `kev.serve` binds
336
+ `127.0.0.1` unless you pass `--host 0.0.0.0` — and it is OPEN by default:
337
+ set `KEV_API_KEY` on BOTH sides before exposing it, or you publish an
338
+ unauthenticated GPU endpoint.
339
+ - **Validated context.** The server accepts states up to 65,536 tokens, but
340
+ accuracy holds only to 8,192 tokens for Kev-0.8B/4B/9B (trained mostly on
341
+ states ≤384 tokens) and 65,536 for Kev-27B. A longer state is REFUSED with
342
+ a 422 naming its token count (unless the server runs
343
+ `KEV_TRUNCATE_STATES=1`); this bond surfaces it verbatim and never retries
344
+ a 422. Shorten the state instead.
345
+ - **`model` never selects a checkpoint.** Any string is echoed back; the
346
+ server answers with the one checkpoint it loaded via `--run`. Run a second
347
+ server for a second size.
348
+ - **1–255 options or levels per question** (Kev's own limit — not Jeff's
349
+ 26). This bond refuses more before sending. Option order can change an
350
+ answer: questions are isolated from each other, options within one are not.
351
+ - **Text only.** There is no `images` field; this bond throws if you pass
352
+ any. Use `@molecule/api-ai-decisions-intern-decision` or `-llm` for images.
353
+ - **Never use Kev-0.8B for tool routing** — it scores below chance on
354
+ When2Call (0.133). Date arithmetic is weak below 27B: start the server with
355
+ `KEV_DATE_FACTS=1`. Knowledge questions are capped by the base model, and
356
+ smaller sizes trail Jev by 13–31 points out of domain.
357
+ - **bf16 vs fp32.** Serving runs in bf16, so probabilities differ from the
358
+ published fp32 numbers by up to ~0.03 (GPU) / ~0.05 (Mac) and the top
359
+ answer flips on ~1 question in 300. `KEV_DTYPE=fp32` on the server gives
360
+ the exact evaluation path.
361
+ - **Ignore the wire `confidence`.** The server sends TypeSafe's dispersion
362
+ statistic, not an accuracy rate; this bond recomputes `confidence` as the
363
+ probability of the reported answer. Tune `minConfidence` on your own
364
+ labelled data — Kev-0.8B can automate far fewer decisions at a fixed error
365
+ budget than 4B/9B/27B.
366
+ - **Not a CPU model.** It runs on CUDA/ROCm or Apple MLX (Kev-4B: ~42 ms on
367
+ an L40S, ~721 ms on an M5). There is no `/health` route: probe
368
+ `GET /v1/models`. A scale-to-zero host (Modal) takes ~35 s on the first
369
+ call after idle; `createProvider({ timeoutMs })` defaults to 120 s for that.
370
+ - **Hosted on rented compute?** Pass `headers: () => hosting.authHeaders(endpoint.id)`
371
+ (`@molecule/api-model-hosting`) when the host's auth expires or is not a
372
+ bearer token — e.g. Modal proxy auth. It runs before every request and is
373
+ merged over the defaults.
374
+ - **Other `/v1/systemone` servers.** Point `baseUrl` at any server of the
375
+ same protocol and lower `maxOptions` to its limit (a self-hosted Nimble:
376
+ `model: 'nimble-latest'`, `maxOptions: 26` — check its license first).
377
+ - Use the core's `setProvider`, not `bond('ai-decisions', …)` directly.
378
+
379
+ ## E2E Tests
380
+
381
+ Integration checklist — drive the real UI (live preview, no mocks), adapt
382
+ each item to this app's actual screens/flows, and check every box off one
383
+ by one. A box you can't check is an integration bug to fix — not a skip:
384
+
385
+ - [ ] Each flow that makes a decision (routing, triage, moderation, a
386
+ guardrail) runs it from the real UI, and the answer DRIVES what happens
387
+ next (the item lands in the chosen queue, the badge shows, the action is
388
+ blocked) — not just printed.
389
+ - [ ] Both directions: a clearly-billing input routes to billing AND a
390
+ clearly-technical one routes elsewhere. One label for every input is a
391
+ broken integration.
392
+ - [ ] A low-confidence answer takes the app's fallback path (human review,
393
+ "unsure" state) instead of being acted on.
394
+ - [ ] Provider errors (service down, bad key) show a visible, recoverable
395
+ state — never a blank screen or an unhandled rejection.
396
+ - [ ] The call runs server-side: no provider request or key in the browser's
397
+ Network tab.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=browser-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Browser guard — `@molecule/api-ai-decisions-kev` is SERVER-ONLY.
3
+ *
4
+ * Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
5
+ * Evaluating a server package in a browser bundle is always an import-graph mistake
6
+ * (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
7
+ * ("Buffer is not defined") far from the culprit. Throwing here names the package and
8
+ * the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
9
+ * unaffected: the throw requires browser globals AND the absence of a node runtime.
10
+ */
11
+ const g = globalThis;
12
+ if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
13
+ throw new Error('@molecule/api-ai-decisions-kev is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
14
+ 'from server code (a server route/function or your API), or dynamic-import it inside ' +
15
+ 'the server handler — never from components or shared client modules, and never ' +
16
+ 'polyfill Buffer/process to silence this.');
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=browser-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,yGAAyG;QACvG,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}