@niscorp/signal 0.1.3 → 0.1.4
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 +12 -0
- package/DOCS.md +51 -4
- package/dist/index.cjs +6 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @niscorp/signal
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a8b7133: DOCS.md states thirty-nine facts about the API that were written only in source comments, and describes `resolveTransport`.
|
|
8
|
+
|
|
9
|
+
`step()` and `stepStream()` now have their request and result fields described: the shape of a tool-calling transcript, `output.accept` and `output.outputTool`, what `toolCalls[].args` holds, what `usage.reported: false` means, `outcome`, `wire.rung` and `wire.recovered`, and the `reasoning` and `tool_call_delta` events. A new subsection gives `resolveTransport(spec, capabilities)`: every field of the spec and of the result. Also added: what `UNMEASURED_MODEL` assumes, `chatProviderEntry`, that `describe()` makes no request, that an OpenRouter row lists what the proxy accepts, and that `jev-latest` is an alias.
|
|
10
|
+
|
|
11
|
+
No behaviour changed.
|
|
12
|
+
|
|
13
|
+
**What to change:** nothing.
|
|
14
|
+
|
|
3
15
|
## 0.1.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/DOCS.md
CHANGED
|
@@ -37,7 +37,7 @@ Each provider has a capability profile that Signal uses to pick the right strate
|
|
|
37
37
|
- **`nativeJsonMode`** — Can it guarantee JSON output?
|
|
38
38
|
- **`toolsWithStructuredOutput`** — Is `response_format` accepted together with `tools` in one request?
|
|
39
39
|
- **`validatesToolArgs`** — Does the endpoint validate tool-call arguments server-side and reject the request on a mismatch?
|
|
40
|
-
- **`manglesNestedToolArgs`** — Does the model corrupt nested tool-call arguments?
|
|
40
|
+
- **`manglesNestedToolArgs`** — Does the model corrupt nested tool-call arguments? For example, a nested array arrives as a JSON string.
|
|
41
41
|
- **`multimodal`** — Does it accept image content?
|
|
42
42
|
- **`supportsEmbedding`** — Can it convert text to vectors?
|
|
43
43
|
|
|
@@ -152,14 +152,25 @@ does) joined with the model's registry row (what the MODEL does, as
|
|
|
152
152
|
measured by `scripts/probe-model.ts`). There is no override: a fact about
|
|
153
153
|
a model is a row in `src/registry.ts`. A model with no row resolves to the
|
|
154
154
|
conservative `UNMEASURED_MODEL`, and `describe().modelKnown` says so.
|
|
155
|
+
`UNMEASURED_MODEL` assumes the least: `nativeJsonSchema: false`,
|
|
156
|
+
`toolsWithStructuredOutput: false`, `manglesNestedToolArgs: true`,
|
|
157
|
+
`multimodal: false`.
|
|
155
158
|
A custom provider (by `baseUrl`) declares its own `capabilities`.
|
|
159
|
+
`chatProviderEntry(id)` returns a chat provider's registry row, and
|
|
160
|
+
`undefined` for an unknown id and for a decision provider.
|
|
156
161
|
```typescript
|
|
157
162
|
createSignal('groq').describe()
|
|
158
163
|
// { provider: 'groq', model: 'qwen/qwen3.8-27b', kind: 'chat', modelKnown: true, capabilities: {…} }
|
|
159
164
|
```
|
|
165
|
+
`describe()` makes no request and does not need an API key. For a custom
|
|
166
|
+
provider `modelKnown` is `false`, and `model` is `undefined` when none is set.
|
|
167
|
+
|
|
160
168
|
A `reasoningEffort` the model's row does not list is refused when the
|
|
161
169
|
client is built (`SignalError`, `E_VALIDATION_FAILED`), not by a provider 400
|
|
162
|
-
mid-run. An unmeasured model is not checked.
|
|
170
|
+
mid-run. An unmeasured model is not checked. On OpenRouter a row lists what
|
|
171
|
+
the proxy accepts, which is not what the routed model honours: it passes
|
|
172
|
+
`reasoning_effort` through to non-reasoning models too, so an accepted value
|
|
173
|
+
does not mean the model reasons.
|
|
163
174
|
|
|
164
175
|
### `.onRetry(handler)`
|
|
165
176
|
Hook called on each validation failure, including the last one that exhausts the retries.
|
|
@@ -221,6 +232,38 @@ Schema validation happens at the end of the stream; when the retries are spent t
|
|
|
221
232
|
|
|
222
233
|
The low-level primitives `complete()` and `stream()` are built on: one model call, no tool execution, no schema retries. The caller owns the loop. `step()` takes a `StepRequest` (`messages`, `tools`, `toolChoice`, `output`, `responseFormat`, `options`) and returns a `StepResult` (`content`, `toolCalls`, `usage`, `finishReason`, `raw`, and — when the request carried `output.accept` — the routed `outcome` and `wire` report). `stepStream()` yields `text`, `reasoning` and `tool_call_delta` events and a final `done` carrying the `StepResult`.
|
|
223
234
|
|
|
235
|
+
- **`messages`** — an assistant turn carries the calls it made as `toolCalls` (`{ id, name, args }`, `args` a JSON string) and has `content: ''` when it only called tools. Each result goes back as a `tool` message whose `toolCallId` is that call's `id`.
|
|
236
|
+
- **`tools`** — each is `{ name, description, parameters }`; `parameters` is the JSON Schema of the tool's input (`z.toJSONSchema()` of a Zod schema).
|
|
237
|
+
- **`output.accept`** — gates and does not transform: `outcome.value` is the accepted candidate itself, not the schema's parsed output, so a transform or a default in the schema is not applied.
|
|
238
|
+
- **`output.outputTool`** — the name of an exit tool. A call to it is routed as output, never as a tool call.
|
|
239
|
+
- **`responseFormat`** — passed to the provider as given. `step()` does not check it against the capabilities: with `tools` on a model without `toolsWithStructuredOutput`, the provider rejects the request.
|
|
240
|
+
- **`toolCalls`** — a call's `args` is the parsed JSON value, or the provider's string when it does not parse. It is not checked against the tool's `parameters`.
|
|
241
|
+
- **`usage`** — `reported: false` means the provider sent no usage and the numbers are an estimate (about 4 characters per token). A stream does not reliably carry its usage.
|
|
242
|
+
- **`outcome`** — also present, without `output.accept`, on a result recovered from a provider rejection.
|
|
243
|
+
- **`wire`** — `rung` names what produced the accepted output: `parse` for content that was valid JSON as it arrived, `call-args` for a call's arguments, otherwise the repair it took. `recovered` is set when the result was recovered from a provider rejection.
|
|
244
|
+
- **`reasoning` events** — the model's thinking, never part of `content`. Only a provider that streams its reasoning produces them; on Groq and OpenRouter Signal asks for it only when `reasoningEffort` is set.
|
|
245
|
+
- **`tool_call_delta` events** — each carries one fragment of a call's arguments (`argsText`) for the call at `index`. The assembled calls are in the `done` event's `toolCalls`.
|
|
246
|
+
|
|
247
|
+
### `resolveTransport(spec, capabilities)`
|
|
248
|
+
|
|
249
|
+
For a caller that runs its own loop over `step()`: resolves how an output contract travels — `respond` (the arguments of an exit tool), `native` (`response_format`) or `emit` (message content) — and returns what to put on each request. The `spec`:
|
|
250
|
+
|
|
251
|
+
- **`wire`** — the full schema of the output contract. It is the `response_format` under `native` and the exit tool's params under `respond`. An endpoint with `validatesToolArgs` is never sent it as tool params.
|
|
252
|
+
- **`looseWire`** — the same contract with the payload left untyped. It replaces `wire` as the exit tool's params when the contract has `data` and `wire` has no JSON Schema, has a `$ref` in it, or is longer than 8,192 characters as one.
|
|
253
|
+
- **`hasData`** — whether the contract carries a typed payload (a `data` field).
|
|
254
|
+
- **`forceTool`** — every turn must be a tool call: under `respond` the result carries `toolChoice: 'required'`. It makes `auto` resolve to `respond` where it would resolve to `emit`, and throws `E_VALIDATION_FAILED` with an explicit `emit`.
|
|
255
|
+
|
|
256
|
+
The result:
|
|
257
|
+
|
|
258
|
+
- **`respondDetail`** — under `respond`, how much of the contract the exit tool's params carry: `full` (`wire`), `loose` (`looseWire`) or `permissive` (the endpoint validates tool args, so the params name the envelope fields and constrain nothing).
|
|
259
|
+
- **`respondDescriptor`** — under `respond`, the exit tool to append to the request's `tools`.
|
|
260
|
+
- **`outputToolName`** — under `respond`, the exit tool's name (`RESPOND_TOOL_NAME`). Pass it as `output.outputTool`; the `tool_call_delta` events of a call with that name carry the output as it arrives.
|
|
261
|
+
- **`responseFormat`** — under `native`, the `responseFormat` to send on every request.
|
|
262
|
+
- **`toolChoice`** — `'required'` under `respond` with `forceTool`.
|
|
263
|
+
- **`injectSchemaDoc`** — `true` when the contract has `data` and the transport does not carry its full schema (`emit`, and `respond` with `loose` or `permissive` params): the caller adds its own schema documentation to the prompt.
|
|
264
|
+
- **`finishProtocol`** — the text that tells the model how the run ends under this transport. Add it unchanged as a system message, after any schema documentation.
|
|
265
|
+
- **`corrections`** — the messages to send back when a turn did not finish (`termination`) or its output was invalid (`invalidOutput`). The caller replaces `{issues}` in `invalidOutput` with the evidence.
|
|
266
|
+
|
|
224
267
|
### `.count(input)`
|
|
225
268
|
|
|
226
269
|
Rough token count for a string or a message list. A heuristic (about 4 characters per token), not a tokenizer.
|
|
@@ -286,7 +329,7 @@ const { response } = await createSignal('groq')
|
|
|
286
329
|
|
|
287
330
|
1. Zod schema is converted to JSON Schema (draft-07)
|
|
288
331
|
2. Based on capabilities:
|
|
289
|
-
- `nativeJsonSchema` (and, when tools are set, `toolsWithStructuredOutput`) → sends JSON Schema as `response_format`
|
|
332
|
+
- `nativeJsonSchema` (and, when tools are set, `toolsWithStructuredOutput`) → sends JSON Schema as `response_format`, with `strict: false`
|
|
290
333
|
- otherwise `nativeJsonMode` and no tools → sends `response_format: json_object` + schema in a system message
|
|
291
334
|
- otherwise → schema in a system message only
|
|
292
335
|
3. The response is normalized by the wire layer (JSON extraction and repairs, each counted only if the result passes the schema)
|
|
@@ -466,7 +509,7 @@ result.decisions.urgency.level; // 0 | 1 | 2 — index into criteria
|
|
|
466
509
|
|
|
467
510
|
You declare the questions once and never write an output type. Signal derives both halves from them:
|
|
468
511
|
|
|
469
|
-
- **The result type.** `choice` → the union of the `criteria` keys; `score` → a level index into `criteria`; `noul` → a boolean.
|
|
512
|
+
- **The result type.** `choice` → the union of the `criteria` keys; `score` → a level index into `criteria`; `noul` → a boolean. A `score` question's `criteria` lists its levels lowest first.
|
|
470
513
|
- **The acceptance gate.** The same derivation at runtime: a choice outside the asked options, a question left unanswered, a distribution over other keys, a probability outside [0, 1] — each fails the call with `E_VALIDATION_FAILED` and the provider's body under `context.raw`.
|
|
471
514
|
|
|
472
515
|
There is no repair and no correction retry. A decision model writes no bytes to repair and cannot be told what it got wrong.
|
|
@@ -485,6 +528,8 @@ if (result.calibrated) {
|
|
|
485
528
|
}
|
|
486
529
|
```
|
|
487
530
|
|
|
531
|
+
On a decision provider `level` is the most probable level and `answer` is `noul >= 0.5`.
|
|
532
|
+
|
|
488
533
|
On a chat provider `decide()` still works: the same questions run through structured output (native grammar where it exists, the repair ladder, correction retries) and come back as picks alone with `calibrated: false`. Signal does not invent a `1.0` — it would clear every threshold. Emulation is one to two orders of magnitude slower; a caller on a latency budget checks first:
|
|
489
534
|
|
|
490
535
|
```typescript
|
|
@@ -503,6 +548,8 @@ controller.abort(); // tears down the HTTP request
|
|
|
503
548
|
|
|
504
549
|
A provider is one of two kinds. A **decision provider** (`typesafe`) has `decide()` and nothing else — `complete`, `stream`, `step`, `stepStream` and `embed` fail with `E_VERB_NOT_SUPPORTED` before any request is built. A **chat provider** has every verb, `decide()` included, by emulation.
|
|
505
550
|
|
|
551
|
+
`typesafe`'s default model `jev-latest` is an alias for the provider's current version; `meta.model` is the version the provider reports having answered. A caller that records calibration against a version pins it with `.model('jev-1.13.0')`.
|
|
552
|
+
|
|
506
553
|
A decision provider by base URL — self-hosted, or the fake a check runs — names its protocol:
|
|
507
554
|
|
|
508
555
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -52,17 +52,11 @@ var providerRegistry = {
|
|
|
52
52
|
endpoint: {
|
|
53
53
|
nativeTools: true,
|
|
54
54
|
nativeJsonMode: true,
|
|
55
|
-
// Groq validates tool args server-side (tool_use_failed 400s).
|
|
56
55
|
validatesToolArgs: true,
|
|
57
56
|
supportsEmbedding: false
|
|
58
57
|
},
|
|
59
58
|
adapter: "openai-compatible",
|
|
60
|
-
// tool_use_failed / json_validate_failed 400s carry the model's
|
|
61
|
-
// attempt in failed_generation — recover and route it.
|
|
62
59
|
wire: ["failed-generation"],
|
|
63
|
-
// Reasoning models stream their trace only when asked to parse it out;
|
|
64
|
-
// `reasoning_format` is rejected on the non-reasoning ones, which is why
|
|
65
|
-
// this is opt-in (see reasoningRequest above).
|
|
66
60
|
reasoningRequest: { reasoning_format: "parsed" }
|
|
67
61
|
},
|
|
68
62
|
openai: {
|
|
@@ -77,8 +71,6 @@ var providerRegistry = {
|
|
|
77
71
|
supportsEmbedding: true
|
|
78
72
|
},
|
|
79
73
|
adapter: "openai-compatible",
|
|
80
|
-
// 4o-era models occasionally emit JSONL where one value was asked
|
|
81
|
-
// for; the acceptance gate decides, so this can never misfire.
|
|
82
74
|
wire: ["jsonl-lines"]
|
|
83
75
|
},
|
|
84
76
|
openrouter: {
|
|
@@ -93,8 +85,6 @@ var providerRegistry = {
|
|
|
93
85
|
supportsEmbedding: false
|
|
94
86
|
},
|
|
95
87
|
adapter: "openai-compatible",
|
|
96
|
-
// OpenRouter unifies reasoning across the models it routes; `enabled` turns
|
|
97
|
-
// the trace on for those that have one and is ignored by those that don't.
|
|
98
88
|
reasoningRequest: { reasoning: { enabled: true } }
|
|
99
89
|
},
|
|
100
90
|
anthropic: {
|
|
@@ -127,97 +117,78 @@ var providerRegistry = {
|
|
|
127
117
|
id: "typesafe",
|
|
128
118
|
baseUrl: "https://api.typesafe.ai/v1",
|
|
129
119
|
envKey: "TYPESAFE_API_KEY",
|
|
130
|
-
// The moving alias. A caller that records calibration against a model pins
|
|
131
|
-
// a version (`jev-1.13.0`) with `.model()`.
|
|
132
120
|
defaultModel: "jev-latest",
|
|
133
121
|
adapter: "systemone"
|
|
134
122
|
}
|
|
135
123
|
};
|
|
136
124
|
var modelRegistry = {
|
|
137
|
-
// ── groq ──
|
|
138
125
|
"groq/qwen/qwen3.8-27b": {
|
|
139
126
|
capabilities: { nativeJsonSchema: false, toolsWithStructuredOutput: false, manglesNestedToolArgs: true, multimodal: true },
|
|
140
|
-
// nested: 3 of 20 trials failed
|
|
141
127
|
reasoningEfforts: ["none", "default", "low", "medium", "high"],
|
|
142
128
|
verified: "2026-09-24"
|
|
143
129
|
},
|
|
144
130
|
"groq/openai/gpt-oss-120b": {
|
|
145
131
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: false, manglesNestedToolArgs: true, multimodal: false },
|
|
146
|
-
// nested: 1 of 20 trials failed
|
|
147
132
|
reasoningEfforts: ["low", "medium", "high"],
|
|
148
133
|
verified: "2026-09-24"
|
|
149
134
|
},
|
|
150
135
|
"groq/openai/gpt-oss-20b": {
|
|
151
136
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: false, manglesNestedToolArgs: true, multimodal: false },
|
|
152
|
-
// nested: 6 of 20 trials failed
|
|
153
137
|
reasoningEfforts: ["low", "medium", "high"],
|
|
154
138
|
verified: "2026-09-24"
|
|
155
139
|
},
|
|
156
|
-
// ── openai ──
|
|
157
140
|
"openai/gpt-4o": {
|
|
158
141
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
159
|
-
// nested: 0 of 20 trials failed
|
|
160
142
|
reasoningEfforts: [],
|
|
161
143
|
verified: "2026-09-24"
|
|
162
144
|
},
|
|
163
145
|
"openai/gpt-4o-mini": {
|
|
164
146
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
165
|
-
// nested: 0 of 20 trials failed
|
|
166
147
|
reasoningEfforts: [],
|
|
167
148
|
verified: "2026-09-24"
|
|
168
149
|
},
|
|
169
150
|
"openai/gpt-4.1-mini": {
|
|
170
151
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
171
|
-
// nested: 0 of 20 trials failed
|
|
172
152
|
reasoningEfforts: [],
|
|
173
153
|
verified: "2026-09-24"
|
|
174
154
|
},
|
|
175
|
-
// ── openrouter ──
|
|
176
155
|
"openrouter/qwen/qwen3.8-27b": {
|
|
177
156
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
178
|
-
// nested: 0 of 20 trials failed
|
|
179
157
|
reasoningEfforts: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
180
158
|
verified: "2026-09-24"
|
|
181
159
|
},
|
|
182
160
|
"openrouter/openai/gpt-4o": {
|
|
183
161
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
184
|
-
// nested: 0 of 20 trials failed
|
|
185
162
|
reasoningEfforts: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
186
163
|
verified: "2026-09-24"
|
|
187
164
|
},
|
|
188
165
|
"openrouter/openai/gpt-4o-mini": {
|
|
189
166
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
190
|
-
// nested: 0 of 20 trials failed
|
|
191
167
|
reasoningEfforts: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
192
168
|
verified: "2026-09-24"
|
|
193
169
|
},
|
|
194
170
|
"openrouter/openai/gpt-oss-120b": {
|
|
195
171
|
capabilities: { nativeJsonSchema: false, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: false },
|
|
196
|
-
// nested: 0 of 20 trials failed
|
|
197
172
|
reasoningEfforts: ["minimal", "low", "medium", "high", "xhigh", "max"],
|
|
198
173
|
verified: "2026-09-24"
|
|
199
174
|
},
|
|
200
175
|
"openrouter/z-ai/glm-5.2": {
|
|
201
176
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: true, multimodal: false },
|
|
202
|
-
// nested: 1 of 20 trials failed
|
|
203
177
|
reasoningEfforts: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
204
178
|
verified: "2026-09-24"
|
|
205
179
|
},
|
|
206
180
|
"openrouter/openai/gpt-5.6-luna": {
|
|
207
181
|
capabilities: { nativeJsonSchema: true, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: true },
|
|
208
|
-
// nested: 0 of 20 trials failed
|
|
209
182
|
reasoningEfforts: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
210
183
|
verified: "2026-09-24"
|
|
211
184
|
},
|
|
212
185
|
"openrouter/openai/gpt-oss-20b": {
|
|
213
186
|
capabilities: { nativeJsonSchema: false, toolsWithStructuredOutput: true, manglesNestedToolArgs: false, multimodal: false },
|
|
214
|
-
// nested: 0 of 20 trials failed
|
|
215
187
|
reasoningEfforts: ["minimal", "low", "medium", "high", "xhigh", "max"],
|
|
216
188
|
verified: "2026-09-24"
|
|
217
189
|
},
|
|
218
190
|
"openrouter/meta-llama/llama-3.3-70b-instruct": {
|
|
219
191
|
capabilities: { nativeJsonSchema: false, toolsWithStructuredOutput: true, manglesNestedToolArgs: true, multimodal: false },
|
|
220
|
-
// nested: 9 of 20 trials failed
|
|
221
192
|
reasoningEfforts: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
222
193
|
verified: "2026-09-24"
|
|
223
194
|
}
|
|
@@ -381,9 +352,8 @@ var createOpenAICompatibleAdapter = async (config) => {
|
|
|
381
352
|
async function* chatStream(request, options) {
|
|
382
353
|
const streamParams = {
|
|
383
354
|
...buildParams(request),
|
|
384
|
-
//
|
|
385
|
-
//
|
|
386
|
-
// the non-stream `chat` path never sees these, so its content is unmoved.
|
|
355
|
+
// Only when the caller set reasoningEffort: Groq answers `reasoning_format` with a 400
|
|
356
|
+
// on its non-reasoning models.
|
|
387
357
|
...request.options?.reasoningEffort !== void 0 && config.reasoningRequest !== void 0 ? config.reasoningRequest : {},
|
|
388
358
|
stream: true,
|
|
389
359
|
stream_options: { include_usage: true }
|
|
@@ -709,8 +679,6 @@ async function* executeStepStream(config) {
|
|
|
709
679
|
contentBuffer += delta.text;
|
|
710
680
|
yield { type: "text", text: delta.text };
|
|
711
681
|
break;
|
|
712
|
-
// Reasoning is passed straight through and deliberately NOT added to
|
|
713
|
-
// contentBuffer: it is the model thinking, not its answer.
|
|
714
682
|
case "reasoning":
|
|
715
683
|
yield { type: "reasoning", text: delta.text };
|
|
716
684
|
break;
|
|
@@ -1389,10 +1357,7 @@ var buildMessages = (config, input) => {
|
|
|
1389
1357
|
var recoveredStepResult = (recovered, routed, raw, sent) => ({
|
|
1390
1358
|
content: "",
|
|
1391
1359
|
toolCalls: routed.outcome.kind === "tool_calls" ? routed.outcome.calls : [],
|
|
1392
|
-
//
|
|
1393
|
-
// billed for it — and the 400 body carries none. The prompt is known exactly
|
|
1394
|
-
// and the model's attempt is in the rejection, so this is countable rather
|
|
1395
|
-
// than lost. Marked unreported, because it is a reckoning.
|
|
1360
|
+
// The provider bills a rejected generation and its 400 carries no usage.
|
|
1396
1361
|
usage: estimateUsage(sent, recovered.rejection.argsText, routed.outcome.kind === "tool_calls" ? routed.outcome.calls : []),
|
|
1397
1362
|
finishReason: "error_recovered",
|
|
1398
1363
|
raw,
|
|
@@ -1447,10 +1412,6 @@ var createSignalFromConfig = (config) => {
|
|
|
1447
1412
|
...providerTools && { tools: providerTools },
|
|
1448
1413
|
...request.toolChoice !== void 0 && { toolChoice: request.toolChoice },
|
|
1449
1414
|
...request.responseFormat !== void 0 && { responseFormat: request.responseFormat },
|
|
1450
|
-
// The client's own options are the floor; a request may override them
|
|
1451
|
-
// field by field. `complete`/`stream` already run on config.options —
|
|
1452
|
-
// step used to drop them, so a configured client behaved differently
|
|
1453
|
-
// depending on which door the caller came through.
|
|
1454
1415
|
...(config.options !== void 0 || request.options !== void 0) && {
|
|
1455
1416
|
options: { ...config.options, ...request.options }
|
|
1456
1417
|
}
|
|
@@ -1485,8 +1446,7 @@ var createSignalFromConfig = (config) => {
|
|
|
1485
1446
|
const result = {
|
|
1486
1447
|
content: response.content,
|
|
1487
1448
|
toolCalls,
|
|
1488
|
-
//
|
|
1489
|
-
// zero rather than a missing frame.
|
|
1449
|
+
// A non-streaming body always carries usage, so a zero here is a reported zero.
|
|
1490
1450
|
usage: { ...response.usage, reported: true },
|
|
1491
1451
|
finishReason: response.finishReason,
|
|
1492
1452
|
raw: response.raw
|
|
@@ -1582,8 +1542,7 @@ var createSignalFromConfig = (config) => {
|
|
|
1582
1542
|
decisions: acceptUncalibrated(request.questions, result.response, result.meta.provider.raw),
|
|
1583
1543
|
meta: {
|
|
1584
1544
|
model: result.meta.model,
|
|
1585
|
-
// complete()
|
|
1586
|
-
// and does not say which, so this total cannot be vouched for as measured.
|
|
1545
|
+
// complete() adds reported usage to estimated usage and does not say which.
|
|
1587
1546
|
usage: { ...result.meta.usage, reported: false },
|
|
1588
1547
|
durationMs: Date.now() - started,
|
|
1589
1548
|
provider: { raw: result.meta.provider.raw }
|
|
@@ -1591,7 +1550,6 @@ var createSignalFromConfig = (config) => {
|
|
|
1591
1550
|
};
|
|
1592
1551
|
};
|
|
1593
1552
|
return {
|
|
1594
|
-
// Builder methods
|
|
1595
1553
|
apiKey: (key) => fork({ apiKey: key }),
|
|
1596
1554
|
model: (m) => fork({ model: m }),
|
|
1597
1555
|
systemPrompt: (prompt) => fork({ systemPrompt: prompt }),
|
|
@@ -1621,7 +1579,6 @@ var createSignalFromConfig = (config) => {
|
|
|
1621
1579
|
modelKnown: false
|
|
1622
1580
|
};
|
|
1623
1581
|
},
|
|
1624
|
-
// Execution — thin wrappers over the step core (src/complete.ts).
|
|
1625
1582
|
complete: async (input) => runComplete(
|
|
1626
1583
|
{
|
|
1627
1584
|
messages: buildMessages(config, input),
|
|
@@ -1647,10 +1604,8 @@ var createSignalFromConfig = (config) => {
|
|
|
1647
1604
|
},
|
|
1648
1605
|
{ stepStream: stepStreamAs("stream"), model: resolveProvider(config).model, capabilities: resolveCapabilities(config) }
|
|
1649
1606
|
),
|
|
1650
|
-
// ─── Low-level primitives — the execution core itself ────
|
|
1651
1607
|
step,
|
|
1652
1608
|
stepStream,
|
|
1653
|
-
// ─── Embedding ────────────────────────────────────────────
|
|
1654
1609
|
embed: (async (input, options) => {
|
|
1655
1610
|
const adapter = await getChatAdapter("embed");
|
|
1656
1611
|
if (!adapter.embed) {
|
|
@@ -1670,7 +1625,6 @@ var createSignalFromConfig = (config) => {
|
|
|
1670
1625
|
}
|
|
1671
1626
|
return response.embeddings;
|
|
1672
1627
|
}),
|
|
1673
|
-
// ─── Decisions ────────────────────────────────────────────
|
|
1674
1628
|
decide: async (request) => {
|
|
1675
1629
|
assertQuestions(request.questions);
|
|
1676
1630
|
const started = Date.now();
|
|
@@ -1678,7 +1632,6 @@ var createSignalFromConfig = (config) => {
|
|
|
1678
1632
|
const model = resolveProvider(config).model;
|
|
1679
1633
|
return adapter.kind === "decisions" ? decideCalibrated(adapter, model, request, started) : decideEmulated(model, request, started);
|
|
1680
1634
|
},
|
|
1681
|
-
// ─── Low-level: token counting (heuristic) ───────────────
|
|
1682
1635
|
count: async (input) => {
|
|
1683
1636
|
const CHARS_PER_TOKEN2 = 4;
|
|
1684
1637
|
if (typeof input === "string") {
|
|
@@ -1786,8 +1739,7 @@ var resolveTransport = (spec, caps) => {
|
|
|
1786
1739
|
responseMode: spec.responseMode,
|
|
1787
1740
|
responseFormat: {
|
|
1788
1741
|
type: "json_schema",
|
|
1789
|
-
//
|
|
1790
|
-
// keywords; non-strict still constrains and never hard-fails.
|
|
1742
|
+
// Strict mode rejects open records and several keywords; non-strict still constrains.
|
|
1791
1743
|
jsonSchema: { name: "envelope", strict: false, schema: serialized }
|
|
1792
1744
|
},
|
|
1793
1745
|
injectSchemaDoc: injectSchemaDoc2,
|