@plurnk/plurnk-providers 6.0.1 → 6.0.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/.env.defaults +1 -4
- package/README.md +2 -7
- package/SPEC.md +7 -9
- package/dist/LeadingReasoning.d.ts +0 -2
- package/dist/LeadingReasoning.d.ts.map +1 -1
- package/dist/LeadingReasoning.js +2 -10
- package/dist/LeadingReasoning.js.map +1 -1
- package/dist/Mock.d.ts +2 -3
- package/dist/Mock.d.ts.map +1 -1
- package/dist/Mock.js +1 -6
- package/dist/Mock.js.map +1 -1
- package/dist/ModelProvider.d.ts +1 -4
- package/dist/ModelProvider.d.ts.map +1 -1
- package/dist/ModelProvider.js +11 -87
- package/dist/ModelProvider.js.map +1 -1
- package/dist/ModelRequestBody.d.ts +3 -5
- package/dist/ModelRequestBody.d.ts.map +1 -1
- package/dist/ModelRequestBody.js +21 -43
- package/dist/ModelRequestBody.js.map +1 -1
- package/dist/Pool.d.ts +0 -1
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +1 -5
- package/dist/Pool.js.map +1 -1
- package/dist/ProviderRegistry.d.ts.map +1 -1
- package/dist/ProviderRegistry.js +1 -3
- package/dist/ProviderRegistry.js.map +1 -1
- package/dist/catalogProvider.d.ts +2 -3
- package/dist/catalogProvider.d.ts.map +1 -1
- package/dist/catalogProvider.js +45 -81
- package/dist/catalogProvider.js.map +1 -1
- package/dist/compatibleProvider.d.ts.map +1 -1
- package/dist/compatibleProvider.js +0 -3
- package/dist/compatibleProvider.js.map +1 -1
- package/dist/discover.d.ts +0 -2
- package/dist/discover.d.ts.map +1 -1
- package/dist/discover.js +1 -8
- package/dist/discover.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +2 -3
- package/dist/env.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -11
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modelAdapters.d.ts +3 -0
- package/dist/modelAdapters.d.ts.map +1 -1
- package/dist/modelAdapters.js +42 -87
- package/dist/modelAdapters.js.map +1 -1
- package/dist/openai.d.ts +1 -1
- package/dist/openai.d.ts.map +1 -1
- package/dist/pi-transport.d.ts.map +1 -1
- package/dist/pi-transport.js +26 -57
- package/dist/pi-transport.js.map +1 -1
- package/dist/providerError.d.ts +1 -1
- package/dist/providerError.d.ts.map +1 -1
- package/dist/providerError.js +1 -3
- package/dist/providerError.js.map +1 -1
- package/dist/types.d.ts +0 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/native-tools.d.ts +0 -4
- package/dist/native-tools.d.ts.map +0 -1
- package/dist/native-tools.js +0 -19
- package/dist/native-tools.js.map +0 -1
package/.env.defaults
CHANGED
|
@@ -107,12 +107,9 @@ PLURNK_PROVIDERS_PROBE_ATTEMPTS=3
|
|
|
107
107
|
# Initial probe backoff, ms.
|
|
108
108
|
PLURNK_PROVIDERS_PROBE_DELAY=250
|
|
109
109
|
|
|
110
|
-
# --- Local endpoints
|
|
110
|
+
# --- Local endpoints ---
|
|
111
111
|
# llama-server: unset = detect; 1 = pin capabilities; 0 = force plain compatible transport.
|
|
112
112
|
# PLURNK_PROVIDERS_LLAMA_SERVER=1
|
|
113
|
-
# Path of an operator-written GBNF grammar carried verbatim to a llama-server route; unset/0 = none.
|
|
114
|
-
# The service ships no grammar profile; a bare name is an error. Per alias: PLURNK_PROVIDERS_GBNF_<alias>.
|
|
115
|
-
# PLURNK_PROVIDERS_GBNF=~/.config/plurnk/my-rail.gbnf
|
|
116
113
|
|
|
117
114
|
# --- Evidence capture ---
|
|
118
115
|
# OpenAI top_logprobs: off/unset = none; 0 = chosen token only; N > 0 = alternatives.
|
package/README.md
CHANGED
|
@@ -169,8 +169,6 @@ llama-server capabilities, slots, EOS token, and exact tokenization.
|
|
|
169
169
|
PLURNK_MODEL_local=openai/model-name-from-endpoint
|
|
170
170
|
PLURNK_BASEURL_local=http://127.0.0.1:8080/v1
|
|
171
171
|
PLURNK_MODEL=local
|
|
172
|
-
# Optional: your own GBNF grammar, carried verbatim to this llama-server route:
|
|
173
|
-
# PLURNK_PROVIDERS_GBNF_local=~/.config/plurnk/local.gbnf
|
|
174
172
|
# Optional explicit generation allowances, in tokens:
|
|
175
173
|
# PLURNK_PROVIDERS_OUTPUT_BUDGET_local=8192
|
|
176
174
|
# PLURNK_PROVIDERS_REASONING_BUDGET_local=4096
|
|
@@ -180,13 +178,10 @@ PLURNK_MODEL=local
|
|
|
180
178
|
|
|
181
179
|
Endpoint probing supplies served-model capacity and llama-server capabilities.
|
|
182
180
|
Pin `PLURNK_PROVIDERS_LLAMA_SERVER_local=1` only for a known llama-server that
|
|
183
|
-
cannot be fingerprinted reliably.
|
|
184
|
-
no grammar profile and never validates or grades one; the file's text reaches
|
|
185
|
-
the route verbatim, and configuring it on a route without grammar transport is
|
|
186
|
-
an error. Parsing always applies.
|
|
181
|
+
cannot be fingerprinted reliably.
|
|
187
182
|
|
|
188
183
|
Sampling stays at endpoint defaults unless configured. Repetition penalties can
|
|
189
|
-
fight exact source copying and
|
|
184
|
+
fight exact source copying and operation syntax repetition. Measure local tuning; it is
|
|
190
185
|
not a portable cloud policy. `think-tags` response interpretation is a separate
|
|
191
186
|
opt-in for endpoints that emit a leading `<think>` envelope, not a reasoning switch.
|
|
192
187
|
|
package/SPEC.md
CHANGED
|
@@ -16,12 +16,12 @@ Every `Provider` instance exposes:
|
|
|
16
16
|
|
|
17
17
|
| Member | Contract |
|
|
18
18
|
|---|---|
|
|
19
|
-
| Physical & policy getters | `model`, `servedModel`, `contextWindow`, `maxInputTokens`, `maxOutputTokens`, `outputBudget`, `outputFloor`, `reasoningBudget`, `inputCapacity`, `inputWall`, `supportedEfforts`, `inputModalities` (`ReadonlySet<"image" \| "audio" \| "video" \| "pdf">`),
|
|
19
|
+
| Physical & policy getters | `model`, `servedModel`, `contextWindow`, `maxInputTokens`, `maxOutputTokens`, `outputBudget`, `outputFloor`, `reasoningBudget`, `inputCapacity`, `inputWall`, `supportedEfforts`, `inputModalities` (`ReadonlySet<"image" \| "audio" \| "video" \| "pdf">`), and `requiresOutputBudget` |
|
|
20
20
|
| `countPromptTokens(messages, signal?)` | Measures or estimates prompt token weight (`PromptTokenMeasurement`) |
|
|
21
21
|
| `assessRequestCapacity(messages, maxOutputTokens?, signal?)` | Evaluates `inputCapacity`, `inputWall`, admission `decision` (`"admit" \| "defer" \| "reject"`), and flexed `responseMax` |
|
|
22
|
-
| `generate(args)` | Requires non-empty `sessionId` (used for KV-cache and slot affinity), optional `callKind` (`"emission"` or `"bare"`),
|
|
22
|
+
| `generate(args)` | Requires non-empty `sessionId` (used for KV-cache and slot affinity), optional `callKind` (`"emission"` or `"bare"`), `maxOutputTokens`, `sampling`, `observeRequest`, and `observeReasoning`. Native tool calls are unconditionally disabled on every protocol |
|
|
23
23
|
| `observeRequest` | Opens before each physical HTTP attempt and settles once with `(requestAccounting, forensicEvidence)`. When `PLURNK_PROVIDERS_RAWBODY=1`, `forensicEvidence.request` records `{ origin, method, body }` with credentials and URL path/query secrets stripped |
|
|
24
|
-
| `observeReasoning` | Streams reasoning deltas live from structured reasoning events (`thinking_delta`) or leading tagged reasoning envelopes (`<think>...</think>` when `PLURNK_PROVIDERS_REASONING_RESPONSE_STYLE=think-tags
|
|
24
|
+
| `observeReasoning` | Streams reasoning deltas live from structured reasoning events (`thinking_delta`) or leading tagged reasoning envelopes (`<think>...</think>` when `PLURNK_PROVIDERS_REASONING_RESPONSE_STYLE=think-tags`) |
|
|
25
25
|
| `Pool` | Fronts $N \ge 1$ homogeneous backends sharing a `model` id: aggregates limits to conservative floors, pins each `sessionId` to one backend for KV-cache locality, and overflows to a healthy sibling on retryable availability failures (`network_failure`, `rate_limit`, `deadline_exceeded`) while never overflowing terminal errors or `resource_interrupted` attempts |
|
|
26
26
|
|
|
27
27
|
## §provider-capacity-admission Capacity and prompt measurement
|
|
@@ -68,7 +68,7 @@ Every physical attempt settles a `ProviderRequestAccounting` record (`{ provider
|
|
|
68
68
|
- `catalogEfforts(providerInfo, modelInfo, env)` intersects the model's cataloged effort vocabulary (extended by `PLURNK_PROVIDERS_PROVIDER_<ID>_REASONING_EFFORTS` for reasoning models) with what the provider adapter can preserve on the wire.
|
|
69
69
|
- On `adaptive`, routes with native adaptive reasoning (such as Anthropic adaptive thinking or Gemini thinking) request their native adaptive posture; graded effort routes use `PLURNK_PROVIDERS_EFFORT_FALLBACK` (default `high`) when supported by the model's effort set.
|
|
70
70
|
- When `PLURNK_PROVIDERS_REASONING_BUDGET` is set alongside `adaptive`, budget-capable routes send the token budget (`thinkingBudgets` / `thinking.budget_tokens` / `thinkingConfig.thinkingBudget` / `reasoning.max_tokens`); setting a fixed effort alongside `PLURNK_PROVIDERS_REASONING_BUDGET` is rejected at construction. On Google routes where `maxOutputTokens` is shared across `thoughtsTokenCount` and `candidatesTokenCount`, `thinkingConfig.thinkingBudget` is bounded by `maxOutputTokens - outputFloor` (or `maxOutputTokens - 1` when tightened below `outputFloor`) so visible output headroom is reserved.
|
|
71
|
-
- On detected llama-server routes, `off` and `adaptive` send `chat_template_kwargs: { enable_thinking: false | true }`, and fixed efforts declared in `PLURNK_PROVIDERS_REASONING_EFFORTS` add `reasoning_effort`.
|
|
71
|
+
- On detected llama-server routes, `off` and `adaptive` send `chat_template_kwargs: { enable_thinking: false | true }`, and fixed efforts declared in `PLURNK_PROVIDERS_REASONING_EFFORTS` add `reasoning_effort`.
|
|
72
72
|
|
|
73
73
|
## §provider-configuration Environment configuration and envelope
|
|
74
74
|
|
|
@@ -86,7 +86,7 @@ Every physical attempt settles a `ProviderRequestAccounting` record (`{ provider
|
|
|
86
86
|
|
|
87
87
|
- Every knob in `PROVIDERS_KNOBS` is documented in `plurnk-providers/.env.defaults` and supports case-insensitive per-alias suffix scoping (`<KNOB>_<ALIAS>`) via `scopeEnvToAlias(env, alias)`.
|
|
88
88
|
- Sampling knobs (`TEMPERATURE`, `TOP_P`, `TOP_K`, `PRESENCE_PENALTY`, `FREQUENCY_PENALTY`, `SEED`, `REPEAT_PENALTY`, `REPEAT_LAST_N`, `DRY_MULTIPLIER`, `DRY_BASE`, `DRY_ALLOWED_LENGTH`) validate at construction; caller `sampling` overrides configured defaults on a per-call basis, and `DRY_MULTIPLIER=0` suppresses all DRY fields.
|
|
89
|
-
- `instantiateProvider` resolves cataloged providers and `ollama` in-framework before scanning `node_modules` for third-party provider extensions (gated by `PLURNK_EXTENSIONS_TRUSTED_ONLY`). `providerReadiness(provider, env)`
|
|
89
|
+
- `instantiateProvider` resolves cataloged providers and `ollama` in-framework before scanning `node_modules` for third-party provider extensions (gated by `PLURNK_EXTENSIONS_TRUSTED_ONLY`). `providerReadiness(provider, env)` and `routeReadiness(route, env)` report missing credentials or endpoint configuration without exposing secret values.
|
|
90
90
|
|
|
91
91
|
## §model-fact-resolution Route facts and local probes
|
|
92
92
|
|
|
@@ -97,12 +97,11 @@ Every physical attempt settles a `ProviderRequestAccounting` record (`{ provider
|
|
|
97
97
|
| Built-in Ollama rail (`ollama.ts`) | Probes `POST <origin>/api/show` for `*.context_length`, capped by optional `PLURNK_PROVIDERS_CONTEXT_WINDOW`, and dispatches chat completions to `<origin>/v1/chat/completions`. |
|
|
98
98
|
| Operator probe scripts (`scripts/`) | `providers-ping.mjs` probes one cheapest declared route per keyed provider and writes redacted JSON evidence; `token-envelope-probe.mjs` probes explicit aliases across configured or physical output limits. |
|
|
99
99
|
|
|
100
|
-
## §provider-request-authority Request controls
|
|
100
|
+
## §provider-request-authority Request controls
|
|
101
101
|
|
|
102
|
-
- Caller `sampling` and extension body fields cannot override protocol-owned fields (`model`, `messages`, `stream`, `tools`, `tool_choice`, `response_format`, `
|
|
102
|
+
- Caller `sampling` and extension body fields cannot override protocol-owned fields (`model`, `messages`, `stream`, `tools`, `tool_choice`, `response_format`, `logprobs`, `top_logprobs`).
|
|
103
103
|
- `PLURNK_PROVIDERS_SERVICE_TIER` and `PLURNK_PROVIDERS_TOP_LOGPROBS` project onto native SDK requests only when the route's SDK documents the control; unsupported controls emit a single `PLURNK_REQUEST_CONTROL_UNSUPPORTED` process warning and are omitted from the wire.
|
|
104
104
|
- OpenRouter requests attach `HTTP-Referer` and `X-OpenRouter-Title` from `PLURNK_PROVIDERS_PROVIDER_OPENROUTER_APP_URL` (validated as an absolute HTTP(S) URL) and `PLURNK_PROVIDERS_PROVIDER_OPENROUTER_APP_NAME`.
|
|
105
|
-
- Grammar strings (`generate({ grammar })`) are transported only when `grammarStyle === "llamacpp"` (`constrainsOutput === true`), preserving `grammarEvidence` (`{ input, contentStart, transported }`) on the response. When `tokenize` is available on a grammar turn and billed `outputTokens` exceed visible content + reasoning tokens by more than 64, an `output_unaccounted` notice is attached ({§diagnostic-observation}).
|
|
106
105
|
|
|
107
106
|
## §provider-failure-normalization Failure normalization and evidence
|
|
108
107
|
|
|
@@ -114,7 +113,6 @@ All transport and response failures normalize into `ProviderError` carrying an R
|
|
|
114
113
|
| `quota_exceeded` | 402 or billing/quota exhaustion | 402 | `false` | `cause` |
|
|
115
114
|
| `rate_limit` | 429 | 429 | `true` | `cause` |
|
|
116
115
|
| `capacity_exceeded` | Preflight exact wall overflow, 413, or upstream context-length code | 413 | `false` | `cause` |
|
|
117
|
-
| `grammar_invalid` | 422 with `error.type === "grammar_invalid"` | 422 | `false` | `cause` |
|
|
118
116
|
| `request_rejected` | Other 400, 404, 405, 422 | 400..422 | `false` | `cause` |
|
|
119
117
|
| `network_failure` | 408, 409, 5xx, socket/TLS/proxy error, or mid-stream disconnect | 502 / 503 | `true` | `cause`, optional `attempt` |
|
|
120
118
|
| `deadline_exceeded` | `PLURNK_PROVIDERS_FETCH_TIMEOUT` or `PLURNK_PROVIDERS_OPERATION_TIMEOUT` | 504 | `true` | `cause`, optional `attempt` |
|
|
@@ -2,7 +2,6 @@ export type ReasoningEnvelope = readonly [opening: string, closing: string];
|
|
|
2
2
|
export default class LeadingReasoning {
|
|
3
3
|
#private;
|
|
4
4
|
static readonly THINK: readonly ReasoningEnvelope[];
|
|
5
|
-
static readonly TEMPLATE: readonly ReasoningEnvelope[];
|
|
6
5
|
constructor(envelopes: readonly ReasoningEnvelope[]);
|
|
7
6
|
push(text: string): string;
|
|
8
7
|
finish(): string;
|
|
@@ -10,7 +9,6 @@ export default class LeadingReasoning {
|
|
|
10
9
|
content: string;
|
|
11
10
|
reasoning: string;
|
|
12
11
|
projected: boolean;
|
|
13
|
-
contentStart: number;
|
|
14
12
|
};
|
|
15
13
|
}
|
|
16
14
|
//# sourceMappingURL=LeadingReasoning.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LeadingReasoning.d.ts","sourceRoot":"","sources":["../src/LeadingReasoning.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAI5E,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IACjC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAA6B;
|
|
1
|
+
{"version":3,"file":"LeadingReasoning.d.ts","sourceRoot":"","sources":["../src/LeadingReasoning.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAI5E,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IACjC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAA6B;IAUhF,YAAY,SAAS,EAAE,SAAS,iBAAiB,EAAE,EAElD;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAmCzB;IAED,MAAM,IAAI,MAAM,CAMf;IAOD,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,iBAAiB,EAAE,GAAG;QACzF,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;KAC1D,CAMA;CACJ"}
|
package/dist/LeadingReasoning.js
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
// observation and settled response projection. Only an undecided delimiter is held.
|
|
3
3
|
export default class LeadingReasoning {
|
|
4
4
|
static THINK = [["<think>", "</think>"]];
|
|
5
|
-
static TEMPLATE = [
|
|
6
|
-
["<|channel>thought\n", "<channel|>"],
|
|
7
|
-
["<think>\n", "</think>"],
|
|
8
|
-
];
|
|
9
5
|
#envelopes;
|
|
10
6
|
#pending = "";
|
|
11
7
|
#closing = null;
|
|
@@ -13,7 +9,6 @@ export default class LeadingReasoning {
|
|
|
13
9
|
#projected = false;
|
|
14
10
|
#reasoning = "";
|
|
15
11
|
#content = "";
|
|
16
|
-
#contentStart = 0;
|
|
17
12
|
constructor(envelopes) {
|
|
18
13
|
this.#envelopes = envelopes;
|
|
19
14
|
}
|
|
@@ -37,12 +32,10 @@ export default class LeadingReasoning {
|
|
|
37
32
|
this.#pending = this.#pending.slice(opening.length);
|
|
38
33
|
this.#closing = closing;
|
|
39
34
|
this.#projected = true;
|
|
40
|
-
this.#contentStart = Array.from(opening).length;
|
|
41
35
|
}
|
|
42
36
|
const end = this.#pending.indexOf(this.#closing);
|
|
43
37
|
if (end !== -1) {
|
|
44
38
|
const delta = this.#emit(this.#pending.slice(0, end));
|
|
45
|
-
this.#contentStart += Array.from(this.#closing).length;
|
|
46
39
|
this.#content = this.#pending.slice(end + this.#closing.length);
|
|
47
40
|
this.#pending = "";
|
|
48
41
|
this.#closed = true;
|
|
@@ -66,16 +59,15 @@ export default class LeadingReasoning {
|
|
|
66
59
|
}
|
|
67
60
|
#emit(delta) {
|
|
68
61
|
this.#reasoning += delta;
|
|
69
|
-
this.#contentStart += Array.from(delta).length;
|
|
70
62
|
return delta;
|
|
71
63
|
}
|
|
72
64
|
static project(content, reasoning, envelopes) {
|
|
73
65
|
if (reasoning.length > 0)
|
|
74
|
-
return { content, reasoning, projected: false
|
|
66
|
+
return { content, reasoning, projected: false };
|
|
75
67
|
const parser = new LeadingReasoning(envelopes);
|
|
76
68
|
parser.push(content);
|
|
77
69
|
parser.finish();
|
|
78
|
-
return { content: parser.#content, reasoning: parser.#reasoning, projected: parser.#projected
|
|
70
|
+
return { content: parser.#content, reasoning: parser.#reasoning, projected: parser.#projected };
|
|
79
71
|
}
|
|
80
72
|
}
|
|
81
73
|
//# sourceMappingURL=LeadingReasoning.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LeadingReasoning.js","sourceRoot":"","sources":["../src/LeadingReasoning.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,oFAAoF;AACpF,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACjC,MAAM,CAAU,KAAK,GAAiC,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"LeadingReasoning.js","sourceRoot":"","sources":["../src/LeadingReasoning.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,oFAAoF;AACpF,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACjC,MAAM,CAAU,KAAK,GAAiC,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IAEvE,UAAU,CAA+B;IAClD,QAAQ,GAAG,EAAE,CAAC;IACd,QAAQ,GAAkB,IAAI,CAAC;IAC/B,OAAO,GAAG,KAAK,CAAC;IAChB,UAAU,GAAG,KAAK,CAAC;IACnB,UAAU,GAAG,EAAE,CAAC;IAChB,QAAQ,GAAG,EAAE,CAAC;IAEd,YAAY,SAAuC;QAC/C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,IAAY;QACb,IAAI,IAAI,CAAC,OA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GAAG,IAAI,CAAC;QACpB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,KAAa;QACf,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC;QACzB,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAAe,EAAE,SAAiB,EAAE,SAAuC;QAGtF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,MAAM,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;IACpG,CAAC;CACJ"}
|
package/dist/Mock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InputModality, ChatMessage, FinishReason,
|
|
1
|
+
import type { InputModality, ChatMessage, FinishReason, PromptTokenMeasurement, Provider, ProviderAssistant, ProviderCost, ProviderRequestCapacity, ProviderResponse, ProviderUsage } from "./types.ts";
|
|
2
2
|
import { type Effort } from "@plurnk/plurnk-contracts";
|
|
3
3
|
export type MockAssistant = {
|
|
4
4
|
content: string;
|
|
@@ -12,7 +12,6 @@ export type MockResponse = {
|
|
|
12
12
|
assistantRaw?: unknown;
|
|
13
13
|
usage?: Partial<ProviderUsage>;
|
|
14
14
|
cost?: ProviderCost;
|
|
15
|
-
grammarEvidence?: GrammarEvidence;
|
|
16
15
|
};
|
|
17
16
|
export type MockReturnedAssistant = ProviderAssistant & {
|
|
18
17
|
ops?: unknown[];
|
|
@@ -45,7 +44,7 @@ export default class Mock implements Provider {
|
|
|
45
44
|
get model(): string;
|
|
46
45
|
countPromptTokens(messages: readonly ChatMessage[]): Promise<PromptTokenMeasurement>;
|
|
47
46
|
assessRequestCapacity(messages: readonly ChatMessage[], maxOutputTokens?: number): Promise<ProviderRequestCapacity>;
|
|
48
|
-
generate({ messages, maxOutputTokens, signal,
|
|
47
|
+
generate({ messages, maxOutputTokens, signal, observeRequest, observeReasoning }: MockGenerateArgs): Promise<MockReturnedResponse>;
|
|
49
48
|
get remaining(): number;
|
|
50
49
|
}
|
|
51
50
|
export { MOCK_USAGE as mockDefaultUsage };
|
package/dist/Mock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mock.d.ts","sourceRoot":"","sources":["../src/Mock.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"Mock.d.ts","sourceRoot":"","sources":["../src/Mock.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,sBAAsB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,EAA6B,uBAAuB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnO,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKhE,MAAM,MAAM,aAAa,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IAMf,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB,SAAS,EAAE,aAAa,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,KAAK,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/B,IAAI,CAAC,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,MAAM,GAAG,IAAI,CAM7B;IACD,IAAI,KAAK,IAAI,MAAM,CAAmB;IAKhC,iBAAiB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAMzF;IAEK,qBAAqB,CACvB,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,eAAe,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,uBAAuB,CAAC,CAoBlC;IAEK,QAAQ,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA+DvI;IAED,IAAI,SAAS,IAAI,MAAM,CAA+B;CACzD;AAED,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,CAAC"}
|
package/dist/Mock.js
CHANGED
|
@@ -93,7 +93,7 @@ export default class Mock {
|
|
|
93
93
|
measurement: await this.countPromptTokens(messages),
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
-
async generate({ messages, maxOutputTokens, signal,
|
|
96
|
+
async generate({ messages, maxOutputTokens, signal, observeRequest, observeReasoning }) {
|
|
97
97
|
// Honor abort before consuming the queue — an aborted call makes no
|
|
98
98
|
// "wire call" and must not exhaust a queued response
|
|
99
99
|
// ({§provider-failure-normalization}).
|
|
@@ -145,16 +145,11 @@ export default class Mock {
|
|
|
145
145
|
if (assistant.reasoning !== null && assistant.reasoning.length > 0) {
|
|
146
146
|
observeReasoning?.(assistant.reasoning);
|
|
147
147
|
}
|
|
148
|
-
const grammarEvidence = next.grammarEvidence
|
|
149
|
-
?? (grammar === undefined
|
|
150
|
-
? undefined
|
|
151
|
-
: { input: assistant.content, contentStart: 0, transported: true });
|
|
152
148
|
return {
|
|
153
149
|
assistant,
|
|
154
150
|
assistantRaw: next.assistantRaw ?? null,
|
|
155
151
|
accounting: [requestAccounting],
|
|
156
152
|
capacity,
|
|
157
|
-
...(grammarEvidence !== undefined ? { grammarEvidence } : {}),
|
|
158
153
|
};
|
|
159
154
|
}
|
|
160
155
|
get remaining() { return this.#queue.length; }
|
package/dist/Mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mock.js","sourceRoot":"","sources":["../src/Mock.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,wEAAwE;AACxE,2CAA2C;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAe,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Mock.js","sourceRoot":"","sources":["../src/Mock.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,wEAAwE;AACxE,2CAA2C;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAe,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AA2BnJ,MAAM,UAAU,GAAkB;IAC9B,WAAW,EAAE,CAAC;IACd,YAAY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,IAAI,SAAS,CAAC,SAAS,KAAK,IAAI,IAAI,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjE,gBAAgB,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO;YACH,SAAS;YACT,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,IAAI;YACvC,UAAU,EAAE,CAAC,iBAAiB,CAAC;YAC/B,QAAQ;SACX,CAAC;IACN,CAAC;IAED,IAAI,SAAS,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;CACzD;AAED,OAAO,EAAE,UAAU,IAAI,gBAAgB,EAAE,CAAC"}
|
package/dist/ModelProvider.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type InferenceAdmission from "./InferenceAdmission.ts";
|
|
|
6
6
|
export type ProviderFetch = typeof globalThis.fetch;
|
|
7
7
|
export type ReasoningStyle = "none" | "think" | "template";
|
|
8
8
|
export type NativeEffort = "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
9
|
-
export type GrammarStyle = "none" | "llamacpp";
|
|
10
9
|
export type CacheAffinity = {
|
|
11
10
|
readonly target: "header" | "body";
|
|
12
11
|
readonly name: string;
|
|
@@ -40,7 +39,6 @@ export type ModelProviderConfig = {
|
|
|
40
39
|
estimateCost?: (usage: ProviderUsage | undefined) => ProviderCost;
|
|
41
40
|
normalizeCost?: ProviderCostNormalizer;
|
|
42
41
|
source?: string;
|
|
43
|
-
grammarStyle?: GrammarStyle;
|
|
44
42
|
cacheAffinity?: CacheAffinity;
|
|
45
43
|
systemCacheBreakpoint?: boolean;
|
|
46
44
|
serviceTier?: string;
|
|
@@ -93,9 +91,8 @@ export default class ModelProvider implements Provider {
|
|
|
93
91
|
get model(): string;
|
|
94
92
|
get servedModel(): string | undefined;
|
|
95
93
|
get requiresOutputBudget(): boolean | undefined;
|
|
96
|
-
get constrainsOutput(): boolean;
|
|
97
94
|
countPromptTokens(messages: readonly ChatMessage[], signal?: AbortSignal): Promise<PromptTokenMeasurement>;
|
|
98
95
|
assessRequestCapacity(messages: readonly ChatMessage[], maxOutputTokens?: number, signal?: AbortSignal): Promise<ProviderRequestCapacity>;
|
|
99
|
-
generate({ messages, sessionId, signal,
|
|
96
|
+
generate({ messages, sessionId, signal, maxOutputTokens, sampling, observeRequest, observeReasoning, callKind }: ProviderGenerateArgs): Promise<ProviderResponse>;
|
|
100
97
|
}
|
|
101
98
|
//# sourceMappingURL=ModelProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelProvider.d.ts","sourceRoot":"","sources":["../src/ModelProvider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,WAAW,EACX,MAAM,
|
|
1
|
+
{"version":3,"file":"ModelProvider.d.ts","sourceRoot":"","sources":["../src/ModelProvider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACR,WAAW,EACX,MAAM,EACN,aAAa,EACb,sBAAsB,EACtB,QAAQ,EAER,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EAEb,uBAAuB,EAEvB,gBAAgB,EAChB,aAAa,EAChB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAMtE,OAAO,EAAiB,KAAK,oBAAoB,EAAE,KAAK,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAOjH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAM9D,MAAM,MAAM,aAAa,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAGpD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3E,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AI,KAAK,IAAI,MAAM,CAAwB;IAE3C,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAA8B;IAEnE,IAAI,oBAAoB,IAAI,OAAO,GAAG,SAAS,CAAuC;IAEhF,iBAAiB,CACnB,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,sBAAsB,CAAC,CAsDjC;IAEK,qBAAqB,CACvB,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,eAAe,CAAC,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,uBAAuB,CAAC,CAoBlC;IA4BK,QAAQ,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgbtK;CAEJ"}
|
package/dist/ModelProvider.js
CHANGED
|
@@ -41,9 +41,8 @@ class ProviderReasoningObserverError extends Error {
|
|
|
41
41
|
}
|
|
42
42
|
// Drop trailing occurrences of a server-rendered EOG marker. llama-server
|
|
43
43
|
// under --special renders EOS as literal text, so a raw-EOS-ended turn carries a
|
|
44
|
-
// trailing <eos
|
|
45
|
-
// can never eat body content
|
|
46
|
-
// under the grammar, and is vanishingly rare unconstrained).
|
|
44
|
+
// trailing <eos>. Trailing-only + exact-match, so it
|
|
45
|
+
// can never eat body content.
|
|
47
46
|
const stripTrailingSpecial = (content, marker) => {
|
|
48
47
|
if (marker.length === 0)
|
|
49
48
|
return content;
|
|
@@ -115,7 +114,6 @@ export default class ModelProvider {
|
|
|
115
114
|
#estimateCost;
|
|
116
115
|
#normalizeCost;
|
|
117
116
|
#source;
|
|
118
|
-
#grammarStyle;
|
|
119
117
|
#cacheAffinity;
|
|
120
118
|
#systemCacheBreakpoint;
|
|
121
119
|
#serviceTier;
|
|
@@ -175,7 +173,7 @@ export default class ModelProvider {
|
|
|
175
173
|
}
|
|
176
174
|
// Loud guard: an out-of-date consumer (stale extension dist) omitting the
|
|
177
175
|
// required tuning fields must fail at construction, not silently send
|
|
178
|
-
// undefined sampling on every
|
|
176
|
+
// undefined sampling on every request.
|
|
179
177
|
if (config.temperature === undefined || config.repeatPenalty === undefined) {
|
|
180
178
|
throw new Error(`${config.source ?? "provider"}: ModelProviderConfig requires temperature + repeatPenalty declared (PLURNK_PROVIDERS_TEMPERATURE / _REPEAT_PENALTY; null = provider default)`);
|
|
181
179
|
}
|
|
@@ -213,7 +211,6 @@ export default class ModelProvider {
|
|
|
213
211
|
}));
|
|
214
212
|
this.#normalizeCost = config.normalizeCost;
|
|
215
213
|
this.#source = config.source ?? "provider";
|
|
216
|
-
this.#grammarStyle = config.grammarStyle ?? "none";
|
|
217
214
|
this.#cacheAffinity = config.cacheAffinity;
|
|
218
215
|
this.#systemCacheBreakpoint = config.systemCacheBreakpoint === true;
|
|
219
216
|
if (this.#providerModel === undefined && this.#systemCacheBreakpoint) {
|
|
@@ -288,7 +285,7 @@ export default class ModelProvider {
|
|
|
288
285
|
return tokens;
|
|
289
286
|
};
|
|
290
287
|
}
|
|
291
|
-
this.#requestBody = new ModelRequestBody({ reasoningBudget: this.#reasoningBudget, additiveReasoningProvider: this.#additiveReasoningProvider, effort: this.#effort, nativeAdaptiveThinking: this.#nativeAdaptiveThinking, repeatPenalty: this.#repeatPenalty, dryMultiplier: this.#dryMultiplier, dryBase: this.#dryBase, dryAllowedLength: this.#dryAllowedLength, repeatLastN: this.#repeatLastN, reasoningStyle: this.#reasoningStyle, source: this.#source,
|
|
288
|
+
this.#requestBody = new ModelRequestBody({ reasoningBudget: this.#reasoningBudget, additiveReasoningProvider: this.#additiveReasoningProvider, effort: this.#effort, nativeAdaptiveThinking: this.#nativeAdaptiveThinking, repeatPenalty: this.#repeatPenalty, dryMultiplier: this.#dryMultiplier, dryBase: this.#dryBase, dryAllowedLength: this.#dryAllowedLength, repeatLastN: this.#repeatLastN, reasoningStyle: this.#reasoningStyle, source: this.#source, supportsSlotPinning: this.#supportsSlotPinning, slotCount: this.#slotCount });
|
|
292
289
|
}
|
|
293
290
|
get contextWindow() { return this.#contextWindow; }
|
|
294
291
|
get inputModalities() { return this.#inputModalities; }
|
|
@@ -318,10 +315,6 @@ export default class ModelProvider {
|
|
|
318
315
|
get servedModel() { return this.#servedModel; }
|
|
319
316
|
// Resolved "decodes unbounded without a cap" fact; undefined = no claim.
|
|
320
317
|
get requiresOutputBudget() { return this.#requiresOutputBudget; }
|
|
321
|
-
// Resolved capability: will a transported grammar actually constrain
|
|
322
|
-
// this backend's decode? Introspectable so a consumer can verify the rails
|
|
323
|
-
// are LIVE without spending a generation on a forcing-grammar probe.
|
|
324
|
-
get constrainsOutput() { return this.#grammarStyle !== "none"; }
|
|
325
318
|
async countPromptTokens(messages, signal) {
|
|
326
319
|
if (this.#promptTokensUrl === undefined) {
|
|
327
320
|
return assertPromptTokenMeasurement(await this.#countPromptTokens(messages, signal), this.#source);
|
|
@@ -405,7 +398,7 @@ export default class ModelProvider {
|
|
|
405
398
|
cost: resolveProviderCost(direct, this.#estimateCost(knownUsage)),
|
|
406
399
|
});
|
|
407
400
|
}
|
|
408
|
-
async generate({ messages, sessionId, signal,
|
|
401
|
+
async generate({ messages, sessionId, signal, maxOutputTokens, sampling, observeRequest, observeReasoning, callKind }) {
|
|
409
402
|
// {§provider-interface} The session identity is required.
|
|
410
403
|
if (sessionId === undefined || sessionId.length === 0)
|
|
411
404
|
throw new Error("generate: sessionId is required — the session's stable, opaque identity");
|
|
@@ -415,12 +408,6 @@ export default class ModelProvider {
|
|
|
415
408
|
// Reject before any wire call when already aborted
|
|
416
409
|
// ({§provider-failure-normalization}).
|
|
417
410
|
signal?.throwIfAborted();
|
|
418
|
-
// Grammar transport ({§provider-request-authority}): an operator's grammar rides a
|
|
419
|
-
// llama-style route verbatim and is never sent on any other style.
|
|
420
|
-
const wantGrammar = grammar !== undefined && this.#grammarStyle !== "none";
|
|
421
|
-
const sendGrammar = wantGrammar ? grammar : undefined;
|
|
422
|
-
const preserveGrammarSentence = wantGrammar
|
|
423
|
-
&& this.#reasoningStyle === "template";
|
|
424
411
|
const capacity = await this.assessRequestCapacity(messages, maxOutputTokens, signal);
|
|
425
412
|
if (capacity.decision === "reject") {
|
|
426
413
|
if (capacity.prompt.kind !== "exact") {
|
|
@@ -443,9 +430,8 @@ export default class ModelProvider {
|
|
|
443
430
|
...(this.#serviceTier !== undefined ? { service_tier: this.#serviceTier } : {}),
|
|
444
431
|
...(this.#reasoningRequestBody !== undefined
|
|
445
432
|
? this.#reasoningRequestBody(this.#effort.mode, capacity.reasoningBudget)
|
|
446
|
-
: this.#requestBody.reasoningBody(
|
|
433
|
+
: this.#requestBody.reasoningBody(capacity.reasoningBudget)),
|
|
447
434
|
...(effectiveMaxOutputTokens === undefined ? {} : { [this.#outputTokenField]: effectiveMaxOutputTokens }),
|
|
448
|
-
...this.#requestBody.grammarBody(sendGrammar),
|
|
449
435
|
// Request per-token logprobs only when enabled (managed field —
|
|
450
436
|
// reserved from caller sampling; the env flag is the single control).
|
|
451
437
|
...(this.#topLogprobs !== null ? { logprobs: true, top_logprobs: this.#topLogprobs } : {}),
|
|
@@ -494,8 +480,7 @@ export default class ModelProvider {
|
|
|
494
480
|
const capture = this.#rawBody ? new RequestCapture() : undefined;
|
|
495
481
|
let requestReasoningStream = "";
|
|
496
482
|
let structuredReasoning = false;
|
|
497
|
-
const envelopes =
|
|
498
|
-
: this.#reasoningResponseStyle === "think-tags" ? LeadingReasoning.THINK : [];
|
|
483
|
+
const envelopes = this.#reasoningResponseStyle === "think-tags" ? LeadingReasoning.THINK : [];
|
|
499
484
|
const observing = emitReasoning !== undefined;
|
|
500
485
|
const liveProjection = observing && envelopes.length > 0 ? new LeadingReasoning(envelopes) : undefined;
|
|
501
486
|
const observeRequestReasoning = !observing
|
|
@@ -686,46 +671,12 @@ export default class ModelProvider {
|
|
|
686
671
|
throw pe;
|
|
687
672
|
}
|
|
688
673
|
// llama-server --special renders EOG tokens as text, so a turn ending
|
|
689
|
-
// via raw EOS carries a trailing <eos>
|
|
690
|
-
//
|
|
691
|
-
//
|
|
692
|
-
// grades it and before it reaches assistant/packet. rawBody keeps the verbatim
|
|
693
|
-
// wire text for forensics.
|
|
674
|
+
// via raw EOS carries a trailing <eos> that would leak a control token into the packet.
|
|
675
|
+
// Strip the server-reported eos_token from the tail ONCE, before it reaches assistant/packet.
|
|
676
|
+
// rawBody keeps the verbatim wire text for forensics.
|
|
694
677
|
if (this.#eosText !== undefined)
|
|
695
678
|
raw.content = stripTrailingSpecial(raw.content, this.#eosText);
|
|
696
|
-
const
|
|
697
|
-
const projectedReasoning = LeadingReasoning.project(raw.content, raw.reasoning, preserveGrammarSentence && !raw.reasoningProjected ? LeadingReasoning.TEMPLATE
|
|
698
|
-
: this.#reasoningResponseStyle === "think-tags" ? LeadingReasoning.THINK : []);
|
|
699
|
-
// Preserve the exact pre-projection response. Constrained template turns
|
|
700
|
-
// request `reasoning_format: "none"`, so even an empty channel and any
|
|
701
|
-
// template-provided opener remain observable. An unexpectedly projected
|
|
702
|
-
// response cannot supply independent evidence.
|
|
703
|
-
let grammarEvidence;
|
|
704
|
-
if (wantGrammar) {
|
|
705
|
-
if (preserveGrammarSentence) {
|
|
706
|
-
if (!raw.reasoningProjected) {
|
|
707
|
-
grammarEvidence = {
|
|
708
|
-
input: grammarInput,
|
|
709
|
-
contentStart: projectedReasoning.projected ? projectedReasoning.contentStart : 0,
|
|
710
|
-
transported: sendGrammar !== undefined,
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
else if (projectedReasoning.projected) {
|
|
715
|
-
grammarEvidence = {
|
|
716
|
-
input: grammarInput,
|
|
717
|
-
contentStart: projectedReasoning.contentStart,
|
|
718
|
-
transported: sendGrammar !== undefined,
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
else {
|
|
722
|
-
grammarEvidence = {
|
|
723
|
-
input: grammarInput,
|
|
724
|
-
contentStart: 0,
|
|
725
|
-
transported: sendGrammar !== undefined,
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
}
|
|
679
|
+
const projectedReasoning = LeadingReasoning.project(raw.content, raw.reasoning, this.#reasoningResponseStyle === "think-tags" ? LeadingReasoning.THINK : []);
|
|
729
680
|
if (projectedReasoning.projected) {
|
|
730
681
|
raw.content = projectedReasoning.content;
|
|
731
682
|
raw.reasoning = projectedReasoning.reasoning;
|
|
@@ -762,32 +713,6 @@ export default class ModelProvider {
|
|
|
762
713
|
});
|
|
763
714
|
}
|
|
764
715
|
const usage = raw.usage;
|
|
765
|
-
if (sendGrammar !== undefined
|
|
766
|
-
&& this.tokenize !== undefined
|
|
767
|
-
&& usage?.outputTokens !== undefined) {
|
|
768
|
-
// {§diagnostic-observation} — billed output tokens far beyond every visible channel are reported
|
|
769
|
-
// as the two counts, naming no cause. The count requires the serving vocabulary; an estimate
|
|
770
|
-
// cannot prove absence.
|
|
771
|
-
try {
|
|
772
|
-
const [contentTokens, reasoningTokens] = await Promise.all([
|
|
773
|
-
this.tokenize(raw.content),
|
|
774
|
-
this.tokenize(raw.reasoning),
|
|
775
|
-
]);
|
|
776
|
-
const visible = contentTokens.length + reasoningTokens.length;
|
|
777
|
-
if (usage.outputTokens > visible + 64) {
|
|
778
|
-
(notices ??= []).push({
|
|
779
|
-
source: this.#source,
|
|
780
|
-
kind: "output_unaccounted",
|
|
781
|
-
level: "warn",
|
|
782
|
-
message: `${usage.outputTokens} output tokens billed; ${visible} visible across content and reasoning.`,
|
|
783
|
-
position: Array.from(raw.content).length,
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
catch (cause) {
|
|
788
|
-
emitWarningOnce(`${this.#source}: exact visible-token diagnostic unavailable (${cause instanceof Error ? cause.message : String(cause)})`, "PLURNK_VISIBLE_TOKEN_COUNT_UNAVAILABLE");
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
716
|
const meta = this.#buildMeta(raw.metadata);
|
|
792
717
|
const logprobs = raw.logprobs.length > 0 ? raw.logprobs : undefined;
|
|
793
718
|
const meanLogprob = logprobs !== undefined
|
|
@@ -804,7 +729,6 @@ export default class ModelProvider {
|
|
|
804
729
|
assistantRaw: raw,
|
|
805
730
|
accounting,
|
|
806
731
|
capacity,
|
|
807
|
-
...(grammarEvidence !== undefined ? { grammarEvidence } : {}),
|
|
808
732
|
...(raw.rawBody !== undefined ? { rawBody: raw.rawBody } : {}),
|
|
809
733
|
...(meta !== undefined ? { meta } : {}),
|
|
810
734
|
...(notices !== undefined ? { notices } : {}),
|