@plurnk/plurnk-providers 1.3.11 → 1.4.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.
Files changed (132) hide show
  1. package/.env.defaults +40 -23
  2. package/README.md +65 -4
  3. package/SPEC.md +222 -56
  4. package/dist/AiSdkProvider.d.ts +18 -5
  5. package/dist/AiSdkProvider.d.ts.map +1 -1
  6. package/dist/AiSdkProvider.js +240 -153
  7. package/dist/AiSdkProvider.js.map +1 -1
  8. package/dist/Mock.d.ts +14 -15
  9. package/dist/Mock.d.ts.map +1 -1
  10. package/dist/Mock.js +26 -10
  11. package/dist/Mock.js.map +1 -1
  12. package/dist/Pool.d.ts +8 -2
  13. package/dist/Pool.d.ts.map +1 -1
  14. package/dist/Pool.js +41 -8
  15. package/dist/Pool.js.map +1 -1
  16. package/dist/ProviderRegistry.d.ts +4 -1
  17. package/dist/ProviderRegistry.d.ts.map +1 -1
  18. package/dist/ProviderRegistry.js +7 -3
  19. package/dist/ProviderRegistry.js.map +1 -1
  20. package/dist/aiSdkTransport.d.ts +4 -2
  21. package/dist/aiSdkTransport.d.ts.map +1 -1
  22. package/dist/aiSdkTransport.js +18 -3
  23. package/dist/aiSdkTransport.js.map +1 -1
  24. package/dist/catalogProvider.d.ts +3 -1
  25. package/dist/catalogProvider.d.ts.map +1 -1
  26. package/dist/catalogProvider.js +20 -7
  27. package/dist/catalogProvider.js.map +1 -1
  28. package/dist/compatibleProvider.d.ts.map +1 -1
  29. package/dist/compatibleProvider.js +11 -4
  30. package/dist/compatibleProvider.js.map +1 -1
  31. package/dist/cost.d.ts +11 -0
  32. package/dist/cost.d.ts.map +1 -0
  33. package/dist/cost.js +64 -0
  34. package/dist/cost.js.map +1 -0
  35. package/dist/discover.d.ts +2 -0
  36. package/dist/discover.d.ts.map +1 -1
  37. package/dist/discover.js +15 -9
  38. package/dist/discover.js.map +1 -1
  39. package/dist/env.d.ts +4 -0
  40. package/dist/env.d.ts.map +1 -1
  41. package/dist/env.js +29 -9
  42. package/dist/env.js.map +1 -1
  43. package/dist/errors.d.ts +27 -0
  44. package/dist/errors.d.ts.map +1 -0
  45. package/dist/errors.js +150 -0
  46. package/dist/errors.js.map +1 -0
  47. package/dist/index.d.ts +11 -5
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +7 -4
  50. package/dist/index.js.map +1 -1
  51. package/dist/notices.d.ts +10 -0
  52. package/dist/notices.d.ts.map +1 -0
  53. package/dist/notices.js +11 -0
  54. package/dist/notices.js.map +1 -0
  55. package/dist/ollama.d.ts.map +1 -1
  56. package/dist/ollama.js +3 -3
  57. package/dist/ollama.js.map +1 -1
  58. package/dist/openai.d.ts +1 -1
  59. package/dist/openai.d.ts.map +1 -1
  60. package/dist/promptTokens.d.ts +4 -0
  61. package/dist/promptTokens.d.ts.map +1 -0
  62. package/dist/promptTokens.js +32 -0
  63. package/dist/promptTokens.js.map +1 -0
  64. package/dist/sdkModels.d.ts.map +1 -1
  65. package/dist/sdkModels.js +4 -3
  66. package/dist/sdkModels.js.map +1 -1
  67. package/dist/types.d.ts +43 -16
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js +1 -1
  70. package/dist/types.js.map +1 -1
  71. package/dist/usage.d.ts +3 -0
  72. package/dist/usage.d.ts.map +1 -1
  73. package/dist/usage.js +26 -14
  74. package/dist/usage.js.map +1 -1
  75. package/dist/warnings.js +0 -0
  76. package/dist/warnings.js.map +1 -1
  77. package/package.json +13 -9
  78. package/src/AiSdkProvider.test.ts +480 -159
  79. package/src/AiSdkProvider.ts +320 -196
  80. package/src/Mock.test.ts +29 -14
  81. package/src/Mock.ts +33 -15
  82. package/src/Pool.test.ts +43 -6
  83. package/src/Pool.ts +56 -10
  84. package/src/ProviderRegistry.test.ts +158 -9
  85. package/src/ProviderRegistry.ts +19 -6
  86. package/src/aiSdkTransport.ts +25 -6
  87. package/src/boundaries.test.ts +8 -3
  88. package/src/catalogProvider.test.ts +17 -0
  89. package/src/catalogProvider.ts +25 -10
  90. package/src/compatibleProvider.test.ts +96 -0
  91. package/src/compatibleProvider.ts +15 -6
  92. package/src/cost.test.ts +63 -0
  93. package/src/cost.ts +83 -0
  94. package/src/defaults.test.ts +1 -0
  95. package/src/discover.test.ts +48 -7
  96. package/src/discover.ts +31 -21
  97. package/src/env.test.ts +38 -23
  98. package/src/env.ts +45 -18
  99. package/src/errors.test.ts +148 -0
  100. package/src/errors.ts +207 -0
  101. package/src/index.ts +29 -7
  102. package/src/lexicon-guard.test.ts +6 -6
  103. package/src/notices.ts +22 -0
  104. package/src/ollama.test.ts +64 -0
  105. package/src/ollama.ts +6 -3
  106. package/src/openai.ts +3 -0
  107. package/src/promptTokens.ts +41 -0
  108. package/src/sdkModels.test.ts +7 -0
  109. package/src/sdkModels.ts +4 -8
  110. package/src/types.ts +106 -64
  111. package/src/usage.test.ts +15 -4
  112. package/src/usage.ts +32 -14
  113. package/src/warnings.test.ts +10 -10
  114. package/src/warnings.ts +0 -0
  115. package/dist/OpenAICompat.d.ts +0 -76
  116. package/dist/OpenAICompat.d.ts.map +0 -1
  117. package/dist/OpenAICompat.js +0 -555
  118. package/dist/OpenAICompat.js.map +0 -1
  119. package/dist/openaiStream.d.ts +0 -47
  120. package/dist/openaiStream.d.ts.map +0 -1
  121. package/dist/openaiStream.js +0 -280
  122. package/dist/openaiStream.js.map +0 -1
  123. package/dist/standardProviders.d.ts +0 -31
  124. package/dist/standardProviders.d.ts.map +0 -1
  125. package/dist/standardProviders.js +0 -518
  126. package/dist/standardProviders.js.map +0 -1
  127. package/dist/telemetry.d.ts +0 -24
  128. package/dist/telemetry.d.ts.map +0 -1
  129. package/dist/telemetry.js +0 -85
  130. package/dist/telemetry.js.map +0 -1
  131. package/src/telemetry.test.ts +0 -69
  132. package/src/telemetry.ts +0 -116
@@ -1,555 +0,0 @@
1
- // Shared OpenAI-compatible provider. Implements the universal generate()
2
- // spine — signal merging, the SSE call, usage mapping, finishReason
3
- // normalization, response assembly — that every sibling had duplicated.
4
- //
5
- // Composition, not inheritance: the per-provider deltas (resolved URL, auth
6
- // headers, reasoning translation style, tokenizer, cost) arrive as config.
7
- // A sibling's fromEnv probes whatever it needs (catalog, pricing, context
8
- // window), builds the config, and returns `new OpenAICompatProvider(config)`.
9
- // Pure-config providers come from ./standardProviders.ts with no sibling at all.
10
- import { executeOpenAICompatible } from "./aiSdkTransport.js";
11
- import { toProviderError, ProviderError } from "./telemetry.js";
12
- import { validateGbnf } from "@plurnk/gbnf";
13
- import { emitWarningOnce } from "./warnings.js";
14
- // #539: drop trailing occurrences of a server-rendered EOG marker. llama-server
15
- // under --special renders EOS as literal text, so a raw-EOS-ended turn carries a
16
- // trailing <eos> the grammar never sanctioned. Trailing-only + exact-match, so it
17
- // can never eat body content (a body ending in the literal marker isn't producible
18
- // under the grammar, and is vanishingly rare unconstrained).
19
- const stripTrailingSpecial = (content, marker) => {
20
- if (marker.length === 0)
21
- return content;
22
- let out = content;
23
- while (out.endsWith(marker))
24
- out = out.slice(0, -marker.length);
25
- return out;
26
- };
27
- // Shared budget→effort breakpoints (xai and google had identical copies).
28
- export const effortFromBudget = (budget) => {
29
- if (budget <= 1000)
30
- return "low";
31
- if (budget <= 4000)
32
- return "medium";
33
- return "high";
34
- };
35
- // chars/2 upper bound (see ./tokenizers.ts) — overcounts safely, never under.
36
- const heuristicTokens = (text) => (text.length === 0 ? 0 : Math.ceil(text.length / 2));
37
- // Body keys the provider owns — a caller's `sampling` passthrough may not set
38
- // these. Two families (#477 audit):
39
- // transport/managed — grammar transport, the stream/JSON choice, slot pinning,
40
- // data capture (SPEC §8: backend-specific fields never cross the contract);
41
- // contract invariants — `n` (atomic single completion: choices[0] is the
42
- // response; n>1 = paid, dropped output), the tool-calling family (tools-in-
43
- // body doctrine, §2: native tool_calls return null content = a broken turn),
44
- // modalities/audio (text-only contract), prediction (decode semantics, not
45
- // sampling), and the token caps (the envelope is the managed maxTokens —
46
- // sampling must not bypass the consumer's #425 cap).
47
- // Sampling intent (temperature, top_p, penalties, stop, seed, logit_bias) and
48
- // platform knobs (user, service_tier, prompt_cache_*, safety_identifier,
49
- // metadata, store, verbosity) pass through; the managed floors spread UNDER
50
- // sampling stay deliberately caller-overridable.
51
- const RESERVED_BODY_KEYS = new Set([
52
- "model", "messages", "stream", "stream_options", "grammar", "response_format", "id_slot", "logprobs", "top_logprobs",
53
- "n", "tools", "tool_choice", "functions", "function_call", "parallel_tool_calls",
54
- "modalities", "audio", "prediction", "max_tokens", "max_completion_tokens",
55
- "prompt_cache_key",
56
- ]);
57
- // Render a non-accept verdict into a terse, factual grammar_unenforced message
58
- // (SPEC §12 message policy: no guidance prose). `reject` names the diverging code
59
- // point + what the grammar would have accepted; `incomplete` names the valid-prefix
60
- // length that never reached a terminal state.
61
- const describeUnenforced = (v) => {
62
- if (v.status === "reject") {
63
- const expected = v.expected.length > 0
64
- ? v.expected.map((e) => `${e.rule} accepts ${e.accepts}`).join(", ")
65
- : "end of input";
66
- return `grammar not enforced: output rejected by the transported grammar at code point ${v.pos} (${JSON.stringify(v.char)}); expected ${expected}`;
67
- }
68
- return `grammar not enforced: output is an incomplete match of the transported grammar — a valid prefix of ${v.pos} code points that never terminated`;
69
- };
70
- export default class OpenAICompatProvider {
71
- #model;
72
- #url;
73
- #fetchTimeoutMs;
74
- #streamIdleTimeoutMs;
75
- #headers;
76
- #fetch;
77
- #hasApiKey = false;
78
- #apiKeyRejectedMessage;
79
- #eosText;
80
- #contextWindow;
81
- #reasoning;
82
- #temperature;
83
- #repeatPenalty;
84
- #frequencyPenalty;
85
- #dryMultiplier;
86
- #dryBase;
87
- #dryAllowedLength;
88
- #repeatLastN;
89
- #reasoningStyle;
90
- #countTokens;
91
- #calculateCost;
92
- #source;
93
- #grammarStyle;
94
- #promptCacheKey;
95
- #serviceTier;
96
- #gbnfDebug;
97
- #streaming;
98
- #firstPartyMetadata;
99
- #supportsSlotPinning;
100
- #slotCount;
101
- #retryAttempts;
102
- #topLogprobs;
103
- #reasoningReserve;
104
- #completionReserve;
105
- #tuningFloors;
106
- #rawBody;
107
- #servedModel;
108
- #requiresMaxTokens;
109
- // Optional capability (SPEC §2): exact tokenization served by the backend's
110
- // own vocab. Assigned in the constructor ONLY when the config carries a
111
- // tokenizeUrl (llama-server), so `provider.tokenize === undefined` remains
112
- // the honest capability signal for every other backend.
113
- tokenize;
114
- constructor(config) {
115
- this.#model = config.model;
116
- this.#url = config.url;
117
- this.#fetchTimeoutMs = config.fetchTimeoutMs;
118
- this.#streamIdleTimeoutMs = config.streamIdleTimeoutMs;
119
- this.#headers = config.headers ?? {};
120
- this.#fetch = config.fetch ?? ((input, init) => globalThis.fetch(input, init));
121
- this.#contextWindow = config.contextWindow ?? null;
122
- this.#reasoning = config.reasoning;
123
- // Loud guard: an out-of-date consumer (stale plugin dist) omitting the
124
- // required tuning fields must fail at construction, not silently send
125
- // undefined sampling on every grammar request.
126
- if (typeof config.temperature !== "number" || typeof config.repeatPenalty !== "number") {
127
- throw new Error(`${config.source ?? "provider"}: OpenAICompatConfig requires temperature + repeatPenalty (PLURNK_PROVIDERS_TEMPERATURE / _REPEAT_PENALTY) — rebuild against providers >= 0.33.0`);
128
- }
129
- this.#temperature = config.temperature;
130
- this.#repeatPenalty = config.repeatPenalty;
131
- this.#frequencyPenalty = typeof config.frequencyPenalty === "number" ? config.frequencyPenalty : 0;
132
- this.#dryMultiplier = config.dryMultiplier;
133
- this.#dryBase = config.dryBase;
134
- this.#dryAllowedLength = config.dryAllowedLength;
135
- this.#repeatLastN = config.repeatLastN;
136
- this.#retryAttempts = config.retryAttempts;
137
- this.#reasoningStyle = config.reasoningStyle ?? "none";
138
- this.#countTokens = config.countTokens ?? heuristicTokens;
139
- this.#calculateCost = config.calculateCost ?? (() => 0);
140
- this.#source = config.source ?? "provider";
141
- this.#grammarStyle = config.grammarStyle ?? "none";
142
- this.#promptCacheKey = config.promptCacheKey ?? false;
143
- this.#serviceTier = config.serviceTier;
144
- this.#gbnfDebug = config.gbnfDebug ?? false;
145
- this.#streaming = config.streaming ?? true;
146
- this.#firstPartyMetadata = config.firstPartyMetadata ?? false;
147
- this.#apiKeyRejectedMessage = config.apiKeyRejectedMessage;
148
- this.#eosText = config.eosText;
149
- this.#hasApiKey = "Authorization" in this.#headers;
150
- this.#supportsSlotPinning = config.supportsSlotPinning ?? false;
151
- this.#slotCount = config.slotCount ?? null;
152
- this.#topLogprobs = config.topLogprobs ?? null;
153
- this.#reasoningReserve = config.reasoningReserve;
154
- this.#completionReserve = config.completionReserve;
155
- this.#tuningFloors = config.tuningFloors ?? true;
156
- this.#rawBody = config.rawBody ?? false;
157
- this.#servedModel = config.servedModel;
158
- this.#requiresMaxTokens = config.requiresMaxTokens;
159
- const { tokenizeUrl } = config;
160
- if (tokenizeUrl !== undefined) {
161
- this.tokenize = async (text) => {
162
- const res = await this.#fetch(tokenizeUrl, {
163
- method: "POST",
164
- headers: { "Content-Type": "application/json", ...this.#headers },
165
- body: JSON.stringify({ content: text }),
166
- signal: AbortSignal.timeout(this.#fetchTimeoutMs),
167
- });
168
- if (!res.ok)
169
- throw new Error(`${this.#source}: tokenize endpoint returned ${res.status}`);
170
- const { tokens } = (await res.json());
171
- if (!Array.isArray(tokens) || !tokens.every((t) => typeof t === "number")) {
172
- throw new Error(`${this.#source}: tokenize endpoint returned no token array`);
173
- }
174
- return tokens;
175
- };
176
- }
177
- }
178
- get contextWindow() { return this.#contextWindow; }
179
- // #507: envelope reserves — absolute pins stand alone; percentages need the
180
- // detected window; null = underivable (no claim for core's no-cap path).
181
- #resolveReserve(spec) {
182
- if (spec === undefined)
183
- return null;
184
- if ("tokens" in spec)
185
- return spec.tokens;
186
- return this.#contextWindow === null ? null : Math.round(spec.percent * this.#contextWindow);
187
- }
188
- get reasoningReserve() { return this.#resolveReserve(this.#reasoningReserve); }
189
- get completionReserve() { return this.#resolveReserve(this.#completionReserve); }
190
- get model() { return this.#model; }
191
- // #37: backend's self-reported served id; undefined when unprobed/unknown.
192
- get servedModel() { return this.#servedModel; }
193
- // #43: resolved "decodes unbounded without a cap" fact; undefined = no claim.
194
- get requiresMaxTokens() { return this.#requiresMaxTokens; }
195
- // Resolved capability (#34): will a transported grammar actually constrain
196
- // this backend's decode? Introspectable so a consumer can verify the rails
197
- // are LIVE without spending a generation on a forcing-grammar probe.
198
- get constrainsOutput() { return this.#grammarStyle !== "none"; }
199
- countTokens(text) { return this.#countTokens(text); }
200
- calculateCost(usage) { return this.#calculateCost(usage); }
201
- // Maps the reasoning INTENT (off | adaptive | on+budget, #33) to the
202
- // backend's wire mechanism — including under a transported grammar. The #32
203
- // clamp (force reasoning_effort "none" under response_format) is LIFTED:
204
- // canary-verified live that fireworks masks ONLY the content channel — the
205
- // reasoning channel rides beside it unmasked, and the plurnk grammar's
206
- // reasoning?/preplan regions absorb any in-band spillover. The old measured
207
- // failures (low→cycles, high→spirals) were pre-max_tokens-cap; with a bounded
208
- // cap the matrix ACCEPTs across efforts (reasoning-rails matrix
209
- // F9). Clamping was the root of the plan-less regression (service#331).
210
- #reasoningBody() {
211
- const { mode, budget } = this.#reasoning;
212
- const on = mode !== "off";
213
- switch (this.#reasoningStyle) {
214
- // Native-channel styles. "template" ALWAYS emits — the explicit
215
- // enable_thinking:false is the only working off-switch on llama-server
216
- // (§13). Activation only; budget is enforced by the box's
217
- // --reasoning-budget launch flag (per-request numerics ignored, F7).
218
- //
219
- // #488 postmortem: intent maps IDENTICALLY under a transported
220
- // grammar. The brief rails-win-the-channel clamp (enable_thinking
221
- // forced false under a grammar) is REVERTED — specimens proved the
222
- // SANCTIONED think block is the protection, not the hazard: the
223
- // server auto-gates the grammar around it and content decodes
224
- // constrained (26-run baseline green; zero grammar rejects across
225
- // the #488 "railless" specimens). Closing the channel starved a
226
- // reasoning-tuned model into ESCAPING mid-content into the raw
227
- // thought channel — discarded server-side, decode unconstrained,
228
- // 12,288 tokens billed for 1,033 visible chars. The escape is
229
- // surfaced instead (vanished-token telemetry + meta rail state).
230
- case "template": return { chat_template_kwargs: { enable_thinking: on } };
231
- case "think": return on ? { think: true } : {};
232
- case "include_reasoning": return on ? { include_reasoning: true } : {};
233
- // effort tiers from the budget; off/adaptive omit the field (the
234
- // API's default depth is its adaptive).
235
- case "effort": return mode === "on" ? { reasoning_effort: effortFromBudget(budget) } : {};
236
- // Fireworks enum: OFF is sent EXPLICITLY ("none") — omission leaves a
237
- // reason-by-default model (DeepSeek V4: default 'high') reasoning (#30).
238
- // ADAPTIVE omits the field: the backend's own default posture IS the
239
- // adaptive semantics, and the literal "adaptive" is MiniMax-M3-only —
240
- // fireworks 400s it for every other model (wire-verified, #403; the
241
- // 1.0.2 adaptive default refused to boot on it). V4 gotcha: integer
242
- // efforts 400.
243
- case "effort_explicit": return mode === "off"
244
- ? { reasoning_effort: "none" }
245
- : mode === "on" ? { reasoning_effort: effortFromBudget(budget) } : {};
246
- // Anthropic compat: explicit thinking object. off → disabled; on →
247
- // enabled with budget_tokens; adaptive → omit (the API default).
248
- case "anthropic": return mode === "off"
249
- ? { thinking: { type: "disabled" } }
250
- : mode === "on" ? { thinking: { type: "enabled", budget_tokens: budget } } : {};
251
- case "none": return {};
252
- }
253
- }
254
- // Per-run slot affinity (#11): the consumer passes WHICH run this is; the
255
- // provider owns WHICH slot serves it. Sticky per workerId, round-robin across
256
- // new runs (distinct runs → distinct slots while slots last), LRU-bounded
257
- // bookkeeping so a long-lived daemon never grows the map unboundedly —
258
- // an evicted-and-returning run simply re-pins, worst case one cold prefill.
259
- #runSlots = new Map();
260
- #nextSlot = 0;
261
- #slotBody(workerId) {
262
- if (!this.#supportsSlotPinning || this.#slotCount === null || this.#slotCount < 1)
263
- return {};
264
- let slot = this.#runSlots.get(workerId);
265
- if (slot === undefined) {
266
- slot = this.#nextSlot++ % this.#slotCount;
267
- if (this.#runSlots.size >= this.#slotCount * 8) {
268
- this.#runSlots.delete(this.#runSlots.keys().next().value);
269
- }
270
- }
271
- else {
272
- this.#runSlots.delete(workerId); // re-insert to refresh LRU recency
273
- }
274
- this.#runSlots.set(workerId, slot);
275
- return { id_slot: slot };
276
- }
277
- // Optional local llama-server GBNF transport (SPEC §13). Unsupported
278
- // backends receive no grammar-related field.
279
- #grammarBody(grammar) {
280
- if (grammar === undefined)
281
- return {};
282
- switch (this.#grammarStyle) {
283
- // Greedy decoding under hard constraint loops without a repeat-penalty
284
- // floor (#9, SPEC §13) — llama.cpp spells it `repeat_penalty`.
285
- case "llamacpp": return { grammar, repeat_penalty: this.#repeatPenalty };
286
- case "none": return {};
287
- }
288
- }
289
- // Anti-degeneration DEFAULT on EVERY request (#426), keyed to the backend's wire
290
- // convention - NOT grammar-bound. GBNF is a local constraint, so a cloud
291
- // alias runs the sampler bare: firefast (deepseek/fireworks) ran 4/86 bench turns
292
- // straight to the token cap on pure looped repetition (run52). Ships next to
293
- // temperature so caller `sampling` can tune it; the grammar path re-asserts it as a
294
- // managed FLOOR in #grammarBody. llama.cpp takes the repeat_penalty
295
- // MULTIPLIER; the plain cloud path ("none") can't, so it gets
296
- // frequency_penalty - OpenAI-standard, accepted by every OpenAI-compat backend (verified
297
- // live: together/deepinfra/fireworks; it is OpenAI's own param, so real OpenAI takes it too).
298
- #repetitionPenaltyBody() {
299
- switch (this.#grammarStyle) {
300
- // #567: repeat_penalty + optional DRY (repeated-SEQUENCE penalty) + a wider
301
- // repeat_last_n window — the loop-breaking tools a llama.cpp backend serves.
302
- // Each rides only when its operator knob is set; absent = the box's default.
303
- case "llamacpp": return {
304
- repeat_penalty: this.#repeatPenalty,
305
- ...(this.#repeatLastN !== undefined ? { repeat_last_n: this.#repeatLastN } : {}),
306
- ...(this.#dryMultiplier !== undefined && this.#dryMultiplier > 0 ? {
307
- dry_multiplier: this.#dryMultiplier,
308
- ...(this.#dryBase !== undefined ? { dry_base: this.#dryBase } : {}),
309
- ...(this.#dryAllowedLength !== undefined ? { dry_allowed_length: this.#dryAllowedLength } : {}),
310
- } : {}),
311
- };
312
- case "none": return this.#frequencyPenalty > 0 ? { frequency_penalty: this.#frequencyPenalty } : {};
313
- }
314
- }
315
- // First-party telemetry headers (SPEC §5): forwarded ONLY when the spec
316
- // opted in (the plurnk endpoint). The gate is here, not at the call site, so
317
- // attributions/client/strikes can never reach a third-party backend even if
318
- // the consumer passes them to the wrong provider. Empty values emit no header
319
- // — EXCEPT strikes, where 0 is a real value (clean streak) distinct from
320
- // absent (consumer didn't report); contract per plurnk-service#313. Strikes
321
- // ride HTTP headers only — the packet never carries them (the model must
322
- // never see strike state; engine accounting is not a metric to game).
323
- #metadataHeaders(attributions, client, strikes, workerId, primaryWorkerId, workspaceId, loop, turn) {
324
- if (!this.#firstPartyMetadata)
325
- return {};
326
- const h = {};
327
- if (attributions !== undefined && attributions.length > 0)
328
- h["Plurnk-Attribution"] = JSON.stringify(attributions);
329
- if (client !== undefined && client.length > 0)
330
- h["Plurnk-Client"] = client;
331
- if (strikes !== undefined && Number.isInteger(strikes) && strikes >= 0)
332
- h["Plurnk-Strikes"] = String(strikes);
333
- // Worker identity (#26, wire-name completed #486/#511): the opaque workerId
334
- // the consumer already supplies, forwarded so the endpoint can key
335
- // per-worker affinity/telemetry — same gate as every first-party signal.
336
- h["Plurnk-Worker-Id"] = workerId;
337
- // Root worker of the lineage (#522): the no-parent ancestor of this turn's
338
- // worker tree. The consumer classifies primary-vs-spawned by equality
339
- // (primaryWorkerId == workerId ⇒ the primary/root worker). The provider
340
- // EMITS what the consumer supplies and never invents a primary; the
341
- // consumer's contract is to stamp it EVERY turn (including the primary's
342
- // own, where it equals workerId). Absence is the consumer's violation for
343
- // the endpoint to surface, not a provider default.
344
- if (primaryWorkerId !== undefined && primaryWorkerId.length > 0)
345
- h["Plurnk-Worker-Primary"] = primaryWorkerId;
346
- // Turn coordinate (#404, extends #26 per #391): workspace/loop/turn, the
347
- // daemon-side sequence the endpoint can never scrape from the wire.
348
- // Coordinates are 1-based — 0 is not a real value, so no strikes-style
349
- // zero exception; absent/empty/0 emits no header.
350
- if (workspaceId !== undefined && workspaceId.length > 0)
351
- h["Plurnk-Workspace-Id"] = workspaceId;
352
- if (loop !== undefined && Number.isInteger(loop) && loop >= 1)
353
- h["Plurnk-Loop"] = String(loop);
354
- if (turn !== undefined && Number.isInteger(turn) && turn >= 1)
355
- h["Plurnk-Turn"] = String(turn);
356
- return h;
357
- }
358
- // Enforcement verification (SPEC §13). When a grammar was actually transported
359
- // (grammarStyle !== "none"), the backend MUST have constrained the output;
360
- // some silently drop the grammar field or mislabel the channel, and without
361
- // this check we would return unconstrained output as if enforced. STRICT: any
362
- // non-accept verdict (reject, or an incomplete/never-terminated match) is a
363
- // grammar_unenforced failure. A grammar our own validator can't parse — even
364
- // though the backend accepted it (a port-vs-llama.cpp gap) — is a non-fatal
365
- // verify gap: warn, don't fail a transport that may have worked. This is a
366
- // conformance check against the grammar we already hold, NOT a plurnk-DSL
367
- // parse (§8) — it stays grammar-generic and backend-agnostic.
368
- // Validate output against the grammar. Returns the verdict, or null on the
369
- // verify GAP — a grammar our own validator can't parse (a port-vs-llama.cpp
370
- // gap): warn, don't manufacture a conflict from a check that didn't run.
371
- #grammarVerdict(grammar, content) {
372
- try {
373
- return validateGbnf(grammar, content);
374
- }
375
- catch (cause) {
376
- // Once per (code, message) — #40: this fires PER TURN otherwise.
377
- emitWarningOnce(`${this.#source}: could not verify grammar enforcement — the transported grammar did not parse in @plurnk/gbnf (${cause.message})`, "PLURNK_GRAMMAR_UNVERIFIABLE");
378
- return null;
379
- }
380
- }
381
- // PLURNK_PROVIDERS_GBNF_DEBUG (SPEC §13): validate the supplied GBNF locally and fail
382
- // hard if it's malformed, BEFORE any wire call — and the grammar is NOT
383
- // transported, so the request runs unconstrained. A debug aid to catch invalid
384
- // grammars (e.g. while editing the plurnk grammar) without a model round-trip;
385
- // off in production. `validateGbnf(grammar, "")` parses the grammar + resolves
386
- // its root, throwing iff the grammar itself is invalid (the empty input's
387
- // verdict is irrelevant — we only care that parsing succeeded).
388
- #assertGrammarValid(grammar) {
389
- try {
390
- validateGbnf(grammar, "");
391
- }
392
- catch (cause) {
393
- throw new Error(`grammar validation (PLURNK_PROVIDERS_GBNF_DEBUG): invalid GBNF — ${cause.message}`, { cause });
394
- }
395
- }
396
- // Per-turn metadata bag (#23): pass the backend's non-standard top-level fields
397
- // through verbatim. Providers do not reinterpret vendor currency or account
398
- // metadata; a monetary value carries its own amount and currency.
399
- #buildMeta(chunkMetadata) {
400
- const meta = { ...chunkMetadata };
401
- return Object.keys(meta).length > 0 ? meta : undefined;
402
- }
403
- // Caller-supplied OpenAI-compat sampling params (temperature, top_p, top_k,
404
- // penalties, stop, seed, …) merged UNDER the managed body: model, messages,
405
- // reasoning, grammar (+ its repeat-penalty floor), max_tokens and slot always
406
- // win, and reserved transport/protocol keys are stripped so the passthrough
407
- // can't smuggle a grammar, a stream toggle, or a backend slot (SPEC §8).
408
- #samplingBody(sampling) {
409
- if (sampling === undefined)
410
- return {};
411
- const out = {};
412
- for (const [k, v] of Object.entries(sampling))
413
- if (!RESERVED_BODY_KEYS.has(k))
414
- out[k] = v;
415
- return out;
416
- }
417
- async generate({ messages, workerId, primaryWorkerId, signal, grammar, maxTokens, attributions, client, strikes, workspaceId, loop, turn, sampling }) {
418
- // Boundary validation (SPEC §2): the worker identity is required.
419
- if (workerId === undefined || workerId.length === 0)
420
- throw new Error("generate: workerId is required — the worker's stable, opaque identity");
421
- // Reject before any wire call when already aborted (SPEC §10.8).
422
- signal?.throwIfAborted();
423
- // Grammar handling (SPEC §13). PLURNK_PROVIDERS_GBNF_DEBUG validates the supplied
424
- // grammar locally and throws on a malformed one, then WITHHOLDS it so the
425
- // model generates UNCONSTRAINED — and the free output is still verified
426
- // against the grammar (below), surfacing exactly where the model's natural
427
- // output and the grammar conflict. Otherwise the grammar is sent when the
428
- // backend supports it (grammarStyle !== "none").
429
- const wantGrammar = grammar !== undefined && this.#grammarStyle !== "none";
430
- if (wantGrammar && this.#gbnfDebug)
431
- this.#assertGrammarValid(grammar);
432
- const sendGrammar = wantGrammar && !this.#gbnfDebug ? grammar : undefined;
433
- // Assembly order = precedence: the family's sampling DEFAULTS
434
- // (PLURNK_PROVIDERS_TEMPERATURE — universal, #30 measured it on grammar
435
- // paths and the name promises every request) < the caller's `sampling`
436
- // < the managed fields, which always win.
437
- const body = {
438
- // #507: floors suppressed on router-owned-tuning providers (plurnk) —
439
- // the router's per-model tuning must not be overridden by client floors.
440
- ...(this.#tuningFloors ? { temperature: this.#temperature, ...this.#repetitionPenaltyBody() } : {}),
441
- ...this.#samplingBody(sampling),
442
- ...(this.#serviceTier !== undefined ? { service_tier: this.#serviceTier } : {}),
443
- model: this.#model,
444
- messages,
445
- ...this.#reasoningBody(),
446
- ...this.#grammarBody(sendGrammar),
447
- ...(maxTokens !== undefined ? { max_tokens: maxTokens } : {}),
448
- // #36: request per-token logprobs only when enabled (managed field —
449
- // reserved from caller sampling; the env flag is the single control).
450
- ...(this.#topLogprobs !== null ? { logprobs: true, top_logprobs: this.#topLogprobs } : {}),
451
- ...this.#slotBody(workerId),
452
- // #518: prompt-cache affinity -- workerId as the OpenAI-standard
453
- // prompt_cache_key routes a worker's turns to one serverless replica so
454
- // its stable prefix caches (managed; reserved from caller sampling).
455
- ...(this.#promptCacheKey ? { prompt_cache_key: workerId } : {}),
456
- };
457
- // Per-request headers = static auth/routing + any first-party telemetry.
458
- const metaHeaders = this.#metadataHeaders(attributions, client, strikes, workerId, primaryWorkerId, workspaceId, loop, turn);
459
- const headers = Object.keys(metaHeaders).length > 0 ? { ...this.#headers, ...metaHeaders } : this.#headers;
460
- let raw;
461
- try {
462
- raw = await executeOpenAICompatible({
463
- url: this.#url,
464
- model: this.#model,
465
- headers,
466
- body,
467
- messages,
468
- signal,
469
- fetch: this.#fetch,
470
- fetchTimeoutMs: this.#fetchTimeoutMs,
471
- streamIdleTimeoutMs: this.#streamIdleTimeoutMs,
472
- retryAttempts: this.#retryAttempts,
473
- streaming: this.#streaming,
474
- captureRawBody: this.#rawBody,
475
- });
476
- }
477
- catch (err) {
478
- if (signal?.aborted)
479
- throw err;
480
- const pe = toProviderError(err, this.#source);
481
- if ((pe.status === 401 || pe.status === 403) && this.#hasApiKey && this.#apiKeyRejectedMessage !== undefined) {
482
- throw new ProviderError(this.#source, "unauthorized", this.#apiKeyRejectedMessage, { status: pe.status, cause: err });
483
- }
484
- throw pe;
485
- }
486
- // #539: llama-server --special renders EOG tokens as text, so a turn ending
487
- // via raw EOS carries a trailing <eos> the grammar never sanctioned - it both
488
- // false-rejects the rail verdict and leaks a control token into the packet.
489
- // Strip the server-reported eos_token from the tail ONCE, before the verdict
490
- // grades it and before it reaches assistant/packet. rawBody keeps the verbatim
491
- // wire text for forensics.
492
- if (this.#eosText !== undefined)
493
- raw.content = stripTrailingSpecial(raw.content, this.#eosText);
494
- // Grammar conformance (§13): bytes always flow; the verdict is an
495
- // observation. Same check whether the grammar was transported
496
- // (sendGrammar) or withheld (PLURNK_PROVIDERS_GBNF_DEBUG filter mode) — a
497
- // non-accept verdict attaches a grammar_unenforced telemetry event
498
- // (message + divergence position) and the response returns normally.
499
- // Discard/retry/escalate/self-correct is the consumer's policy.
500
- let telemetry;
501
- let railsMeta;
502
- const usage = raw.usage;
503
- const observedGrammar = sendGrammar ?? (wantGrammar && this.#gbnfDebug ? grammar : undefined);
504
- if (observedGrammar !== undefined) {
505
- const verdict = this.#grammarVerdict(observedGrammar, raw.content);
506
- if (verdict !== null && verdict.status !== "accept") {
507
- telemetry = [{ source: this.#source, kind: "grammar_unenforced", message: describeUnenforced(verdict), position: verdict.pos }];
508
- }
509
- // #488 per-request loud state: rail attachment + conformance verdict
510
- // ride `meta` into the consumer's turn row, so a drill reads rail
511
- // presence PER TURN from the run db instead of inferring it from
512
- // output shape (the #488 misdiagnosis, twice).
513
- railsMeta = { railsAttached: sendGrammar !== undefined, railsVerdict: verdict?.status ?? "unverifiable" };
514
- // #488 channel-escape detector (the run105 class): completion tokens
515
- // billed far beyond every visible channel mean the decode ESCAPED into
516
- // a server-discarded reasoning block mid-emission — unconstrained,
517
- // invisible, billed (12,288 billed vs 1,033 chars visible, live).
518
- // countTokens OVERCOUNTS text (chars/2 upper bound), so billed
519
- // exceeding visible-plus-slack is real vanishing, not estimator noise.
520
- const visible = this.#countTokens(raw.content) + this.#countTokens(raw.reasoning);
521
- if (sendGrammar !== undefined && usage.completion > visible + 64) {
522
- (telemetry ??= []).push({
523
- source: this.#source,
524
- kind: "grammar_unenforced",
525
- message: `decode escaped the grammar: ${usage.completion} completion tokens billed but only ~${visible} visible across content+reasoning — the balance ran unconstrained in a discarded reasoning channel`,
526
- position: [...raw.content].length,
527
- });
528
- }
529
- }
530
- const builtMeta = this.#buildMeta(raw.metadata);
531
- const meta = railsMeta !== undefined ? { ...builtMeta, ...railsMeta } : builtMeta;
532
- const logprobs = raw.logprobs.length > 0 ? raw.logprobs : undefined;
533
- const meanLogprob = logprobs !== undefined
534
- ? logprobs.reduce((sum, token) => sum + token.logprob, 0) / logprobs.length
535
- : undefined;
536
- return {
537
- assistant: {
538
- content: raw.content,
539
- reasoning: raw.reasoning.length > 0 ? raw.reasoning : null,
540
- ...(raw.reasoningEncrypted.length > 0
541
- ? { reasoningEncrypted: raw.reasoningEncrypted }
542
- : {}),
543
- usage,
544
- finishReason: raw.finishReason,
545
- model: raw.model,
546
- ...(logprobs !== undefined ? { logprobs, meanLogprob } : {}),
547
- },
548
- assistantRaw: raw,
549
- ...(raw.rawBody !== undefined ? { rawBody: raw.rawBody } : {}),
550
- ...(meta !== undefined ? { meta } : {}),
551
- ...(telemetry !== undefined ? { telemetry } : {}),
552
- };
553
- }
554
- }
555
- //# sourceMappingURL=OpenAICompat.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OpenAICompat.js","sourceRoot":"","sources":["../src/OpenAICompat.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,0EAA0E;AAC1E,8EAA8E;AAC9E,iFAAiF;AAIjF,OAAO,EAAE,uBAAuB,E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string, string>;
4
- body: Record<string, unknown>;
5
- signal: AbortSignal;
6
- fetch: ProviderFetch;
7
- captureRawBody?: boolean;
8
- streamIdleTimeoutMs?: number;
9
- };
10
- import type { RawUsage } from "./usage.ts";
11
- import type { TokenLogprob } from "./types.ts";
12
- export type ProviderFetch = typeof globalThis.fetch;
13
- export type EncryptedReasoningItem = {
14
- id: string | null;
15
- subtype: string;
16
- encrypted: Array<{
17
- data: string;
18
- format: string | null;
19
- }>;
20
- };
21
- export type StreamResponse = {
22
- model: string | null;
23
- content: string;
24
- reasoning_content: string;
25
- reasoning_encrypted: EncryptedReasoningItem[];
26
- finish_reason: string | null;
27
- usage: RawUsage | null;
28
- chunkMetadata: Record<string, unknown>;
29
- logprobs: TokenLogprob[] | null;
30
- rawBody: unknown;
31
- };
32
- export declare const isEdgeStatus: (status: number) => boolean;
33
- export declare class OpenAiHttpError extends Error {
34
- #private;
35
- readonly status: number;
36
- readonly body: string;
37
- readonly retryAfter: number | null;
38
- constructor(status: number, body: string, retryAfter: number | null);
39
- }
40
- export declare class StreamIdleError extends Error {
41
- readonly timeoutMs: number;
42
- constructor(timeoutMs: number);
43
- }
44
- export declare const chatCompletion: ({ url, headers, body, signal, fetch, captureRawBody }: StreamRequest) => Promise<StreamResponse>;
45
- export declare const chatCompletionStream: ({ url, headers, body, signal, fetch, captureRawBody, streamIdleTimeoutMs }: StreamRequest) => Promise<StreamResponse>;
46
- export {};
47
- //# sourceMappingURL=openaiStream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openaiStream.d.ts","sourceRoot":"","sources":["../src/openaiStream.ts"],"names":[],"mappings":"AAMA,KAAK,aAAa,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,aA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