@plurnk/plurnk-providers 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/SPEC.md +18 -8
- package/dist/OpenAICompat.d.ts.map +1 -1
- package/dist/OpenAICompat.js +42 -1
- package/dist/OpenAICompat.js.map +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ The framework calls `YourClass.fromEnv(env, model)` (sync or async) and expects
|
|
|
33
33
|
|
|
34
34
|
### 3. What `generate` receives — and returns
|
|
35
35
|
|
|
36
|
-
`generate({ messages, runId, signal?, grammar?, maxTokens? }) → Promise<ProviderResponse>`. Return **raw** wire output: `content` unparsed (the consumer parses the plurnk DSL — never parse it yourself), `reasoning` is the wire-reported CoT only. Honor `signal`. The provider never mutates `messages` or injects turns. `grammar` (GBNF) is attached only by backends that support it; all others ignore it (SPEC §13).
|
|
36
|
+
`generate({ messages, runId, signal?, grammar?, maxTokens?, attributions?, client? }) → Promise<ProviderResponse>`. Return **raw** wire output: `content` unparsed (the consumer parses the plurnk DSL — never parse it yourself), `reasoning` is the wire-reported CoT only. Honor `signal`. The provider never mutates `messages` or injects turns. `grammar` (GBNF) is attached only by backends that support it; all others ignore it (SPEC §13). When a grammar *is* transported, the provider verifies the backend actually enforced it — non-conforming output rejects with a `grammar_unenforced` `ProviderError` (a conformance check via `@plurnk/gbnf`, never a plurnk-DSL parse). `attributions`/`client` are per-turn first-party metadata, forwarded as `Plurnk-*` headers **only** by a provider configured with `firstPartyMetadata` (the plurnk endpoint); every other provider drops them, so they can never reach a third-party backend (SPEC §11).
|
|
37
37
|
|
|
38
38
|
## Discovery & trust
|
|
39
39
|
|
|
@@ -47,10 +47,10 @@ First-party daughters install flat via [`@plurnk/plurnk-providers-all`](https://
|
|
|
47
47
|
|
|
48
48
|
## Exports
|
|
49
49
|
|
|
50
|
-
- `Provider`, `ChatMessage`, `ProviderResponse`, `ProviderAssistant`, `ProviderUsage`, `FinishReason`, `ProviderFactory` (+ `Discovery`, `DiscoverOptions`) — types.
|
|
51
|
-
- `parseAliasesFromEnv`, `resolveActiveAlias`, `instantiateProvider`, `loadActiveProvider`, `discover` — alias-cascade resolution + two-tier provider instantiation. Tier 1 is the standard table; tier 2 is a scope-agnostic `node_modules` scan for `plurnk.kind:"provider"` packages — first-party daughters (flat via `@plurnk/plurnk-providers-all`) and third-party providers under any scope, gated by the host `PLURNK_PLUGINS_TRUSTED_ONLY` allowlist. The framework is contract-only (SPEC §5).
|
|
52
|
-
- `OpenAICompatProvider` (+ `OpenAICompatConfig`, `ReasoningStyle`, `effortFromBudget`) — shared OpenAI-compatible transport spine; siblings extend it (SPEC §11). Transports GBNF grammar-
|
|
53
|
-
- `chatCompletionStream`, `OpenAiHttpError`, `StreamResponse` — the shared SSE client.
|
|
50
|
+
- `Provider`, `ChatMessage`, `ProviderResponse`, `ProviderAssistant`, `ProviderUsage`, `FinishReason`, `ProviderFactory`, `ProviderAlias` (+ `Discovery`, `DiscoverOptions`) — types.
|
|
51
|
+
- `parseAliasesFromEnv`, `resolveActiveAlias`, `instantiateProvider`, `loadActiveProvider`, `discover`, `resetDiscoveryCache` — alias-cascade resolution + two-tier provider instantiation (`resetDiscoveryCache` clears the memoized tier-2 scan; for tests). Tier 1 is the standard table; tier 2 is a scope-agnostic `node_modules` scan for `plurnk.kind:"provider"` packages — first-party daughters (flat via `@plurnk/plurnk-providers-all`) and third-party providers under any scope, gated by the host `PLURNK_PLUGINS_TRUSTED_ONLY` allowlist. The framework is contract-only (SPEC §5).
|
|
52
|
+
- `OpenAICompatProvider` (+ `OpenAICompatConfig`, `ReasoningStyle`, `GrammarStyle`, `effortFromBudget`) — shared OpenAI-compatible transport spine; siblings extend it (SPEC §11). Transports a GBNF grammar via `grammarStyle` — `llamacpp` (top-level `grammar` field) or `response_format` (Fireworks); `none` drops it — and verifies the backend enforced it against `@plurnk/gbnf`, rejecting non-conforming output as `grammar_unenforced` (SPEC §13).
|
|
53
|
+
- `chatCompletionStream`, `chatCompletion`, `OpenAiHttpError`, `StreamResponse` — the shared SSE client (`chatCompletion` is the non-streaming variant).
|
|
54
54
|
- `parseRequiredInt`, `parseOptionalInt`, `requireEnv`, `reasoningBudgetFromEnv` — env helpers (SPEC §4; all required-with-named-errors, no in-code defaults).
|
|
55
55
|
- `normalizeUsage`, `computeCost` (+ `RawUsage`, `TokenRates`) — usage normalization to the §2 invariant and the single cost formula (SPEC §11).
|
|
56
56
|
- `ProviderError`, `classifyProviderError`, `toProviderError`, `providerSource` (+ `TelemetryEvent`, `ProviderTelemetryKind`) — the TelemetryEvent envelope for transport failures (SPEC §12).
|
package/SPEC.md
CHANGED
|
@@ -39,8 +39,11 @@ interface Provider {
|
|
|
39
39
|
// grammar-constrained sampling (§13) — attached verbatim by capable
|
|
40
40
|
// backends, ignored by all others. `maxTokens` is the consumer's per-call
|
|
41
41
|
// output ceiling (wire `max_tokens`); absent means the server default,
|
|
42
|
-
// which is typically UNBOUNDED.
|
|
43
|
-
|
|
42
|
+
// which is typically UNBOUNDED. `attributions`/`client` are optional
|
|
43
|
+
// first-party metadata, forwarded as `Plurnk-*` headers ONLY by a provider
|
|
44
|
+
// configured with `firstPartyMetadata` (the plurnk endpoint) and dropped by
|
|
45
|
+
// every other — structurally unable to reach a third-party backend (§11).
|
|
46
|
+
generate(args: { messages: ChatMessage[]; runId: string; signal?: AbortSignal; grammar?: string; maxTokens?: number; attributions?: string[]; client?: string }): Promise<ProviderResponse>;
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
interface ProviderResponse {
|
|
@@ -76,6 +79,7 @@ Usage invariant: `total = prompt + completion + reasoning`; `cached ⊆ prompt`;
|
|
|
76
79
|
- `contextSize` resolves to `null` when provider can't determine the model's context window. Consumer treats null as "no budget info available."
|
|
77
80
|
- `generate` rejects on signal abort — does NOT resolve with partial content.
|
|
78
81
|
- `generate` transports `grammar` verbatim when the backend supports grammar-constrained sampling, and silently ignores it otherwise (§13). The provider never chooses or modifies the grammar.
|
|
82
|
+
- `generate` **verifies enforcement** when it transported a grammar: it validates the returned `content` against that grammar and rejects with a `grammar_unenforced` `ProviderError` if the backend did not actually constrain the output (§13). This is a grammar-**conformance** check against the grammar the provider already holds — *not* a plurnk-DSL parse (that stays consumer-side, below) — so it remains backend- and DSL-agnostic.
|
|
79
83
|
- **Backend affinity is the provider's internal guarantee, keyed by `runId`.** The consumer says *which run this is*, never *which backend resource serves it* — raw resource identifiers (slot integers, connections) never cross the contract in either direction. On slot-pinning backends (llama-server `--parallel N>1`), the provider keeps each run sticky to one slot and spreads distinct runs across slots, so each concurrent run keeps its KV-cache prefix warm (un-pinned routing is the server's similarity heuristic — slot hops re-pay full prefills). Backends without affinity semantics ignore `runId` entirely.
|
|
80
84
|
|
|
81
85
|
## §3 `fromEnv(env, model)` factory
|
|
@@ -104,7 +108,7 @@ The consumer's instantiation path calls `mod.default.fromEnv(env, alias.model)`
|
|
|
104
108
|
|
|
105
109
|
Each provider's `fromEnv` reads these:
|
|
106
110
|
|
|
107
|
-
- **`PLURNK_PROVIDERS_REASONING_BUDGET`** — REQUIRED integer `>= -1`. One knob carries the whole side-channel-reasoning space: **`0`** off, **`-1`** on/adaptive (no cap — model/backend decides depth), **`N>0`** on/capped at `N`. The provider maps this single intent to the active backend's mechanism — llama-server `chat_template_kwargs: { enable_thinking }` (always emitted; the explicit FALSE is the only working off-switch — llama-server ignores `think` and per-request budgets, and its `--reasoning-budget` default otherwise keeps the channel live, fatal under an active grammar, §13), Ollama `think`, relay `include_reasoning`, cloud `reasoning_effort` (tier from `N`; adaptive `-1` omits the field, letting the API pick its depth), Anthropic `thinking: { type: "adaptive" }` (`-1`) / `budget_tokens` (`N`). For native backends the magnitude is irrelevant — only zero vs non-zero matters. Consumers state intent, never mechanism. (
|
|
111
|
+
- **`PLURNK_PROVIDERS_REASONING_BUDGET`** — REQUIRED integer `>= -1`. One knob carries the whole side-channel-reasoning space: **`0`** off, **`-1`** on/adaptive (no cap — model/backend decides depth), **`N>0`** on/capped at `N`. The provider maps this single intent to the active backend's mechanism — llama-server `chat_template_kwargs: { enable_thinking }` (always emitted; the explicit FALSE is the only working off-switch — llama-server ignores `think` and per-request budgets, and its `--reasoning-budget` default otherwise keeps the channel live, fatal under an active grammar, §13), Ollama `think`, relay `include_reasoning`, cloud `reasoning_effort` (tier from `N`; adaptive `-1` omits the field, letting the API pick its depth), Anthropic `thinking: { type: "adaptive" }` (`-1`) / `budget_tokens` (`N`). For native backends the magnitude is irrelevant — only zero vs non-zero matters. Consumers state intent, never mechanism. (In-DSL `<<PLAN>>` reasoning has **no provider footprint** and no operator knob: `PLAN` is a required element of the canonical plurnk grammar the consumer attaches via `generate`'s `grammar`. The provider transports that grammar verbatim and never forces, prefills, or toggles `PLAN`.)
|
|
108
112
|
|
|
109
113
|
Read via `reasoningBudgetFromEnv` and **fail hard when unset** — configuration lives in the operator's env (the consumer's `.env.example` declares every var); the framework never defaults a knob in code.
|
|
110
114
|
- **`PLURNK_FETCH_TIMEOUT`** — service-wide ms ceiling on any single outbound request (**per attempt**, not shared across retries). Each `fromEnv` reads and passes as `AbortSignal.timeout`. Per-provider override envs are NOT part of the contract.
|
|
@@ -143,7 +147,7 @@ The framework is **contract-only** — it does **not** depend on its daughters.
|
|
|
143
147
|
|
|
144
148
|
## §6 Engine → provider guarantees (consumer side)
|
|
145
149
|
|
|
146
|
-
- `messages` is a complete prompt. Consumer has pre-assembled all sections. Provider does not add, reorder, or inject turns — the wire `messages` are exactly what the consumer passed. (
|
|
150
|
+
- `messages` is a complete prompt. Consumer has pre-assembled all sections. Provider does not add, reorder, or inject turns — the wire `messages` are exactly what the consumer passed. (The provider injects no `PLAN` turn — `PLAN` is part of the consumer's grammar contract, §4.)
|
|
147
151
|
- Every `generate` carries `runId` — the run's stable, opaque identity. Same run → same string across its turns; distinct runs → distinct strings.
|
|
148
152
|
- `signal` is wired to the run's AbortController.
|
|
149
153
|
- `generate` is single-call per turn. No parallel calls on the same instance.
|
|
@@ -211,6 +215,7 @@ A sibling package satisfies the contract when:
|
|
|
211
215
|
11. No DB access, no imports from `@plurnk/plurnk-service`.
|
|
212
216
|
12. No runtime import of `@plurnk/plurnk-grammar` parser entry points.
|
|
213
217
|
13. `generate` invoked with `grammar` against a backend without grammar support sends no grammar-related wire fields and does not error (§13).
|
|
218
|
+
14. `generate` that transported a grammar and received conforming output resolves; output the grammar rejects (or an incomplete match) rejects with a `grammar_unenforced` `ProviderError` (§13). (Inherited from `OpenAICompatProvider`; bespoke siblings on a non-compat transport implement it.)
|
|
214
219
|
|
|
215
220
|
Sibling-specific behavioral tests (wire-format compliance, model-family quirks, retry logic) live in each package's own test surface.
|
|
216
221
|
|
|
@@ -236,7 +241,7 @@ The framework ships the transport spine every OpenAI-compatible provider had bee
|
|
|
236
241
|
|
|
237
242
|
The `openai` standard provider sets `grammarStyle: "llamacpp"`, `supportsSlotPinning`, and `slotCount` from the same llama-server fingerprint (`/v1/models` `meta` block + `/props`). The run→slot mapping lives inside `OpenAICompatProvider`: sticky per `runId`, round-robin across new runs, LRU-bounded.
|
|
238
243
|
|
|
239
|
-
- **`chatCompletionStream` / `OpenAiHttpError` / `StreamResponse`** — the SSE
|
|
244
|
+
- **`chatCompletionStream` / `chatCompletion` / `OpenAiHttpError` / `StreamResponse`** — the shared HTTP client (`chatCompletionStream` for SSE, `chatCompletion` for the non-streamed JSON the `streaming: false` path uses). One shared copy.
|
|
240
245
|
- **`normalizeUsage(raw)` / `computeCost(usage, {input, output, cached})`** — usage normalization to the §2 invariant (handles both reasoning-reporting conventions) and the single cost formula (bills `completion + reasoning` at the output rate). `OpenAICompatProvider` applies `normalizeUsage` automatically; siblings pass their per-token rates to `computeCost` in their `costFor`.
|
|
241
246
|
- **`parseRequiredInt` / `parseOptionalInt` / `requireEnv`** — env helpers; each takes a provider `label` for error prefixing.
|
|
242
247
|
- **`tokenizerFor(family)` / `tokenizerByPublisher(model, table, index)` / `parseTokenizerFamily(...)`** — synchronous tokenizer strategies (`heuristic` | `cl100k` | `llama`) and per-publisher dispatch for relay providers.
|
|
@@ -259,7 +264,7 @@ Transport failures surface as a `ProviderError` (extends `Error`, so existing ca
|
|
|
259
264
|
```
|
|
260
265
|
|
|
261
266
|
- `source` is `provider:<vendor>` (schema pattern `^[a-z]+(:[a-z][a-z0-9-]*)?$`); standard providers set it from their name, siblings via the `source` config field (default `"provider"`).
|
|
262
|
-
- `kind` ∈ `rate_limit | network_failure | model_refused | invalid_response | unauthorized | quota_exceeded`. HTTP status maps: 401/403→`unauthorized`, 402→`quota_exceeded`, 429→`rate_limit`, ≥500→`network_failure`, other 4xx→`invalid_response`; timeouts/fetch errors→`network_failure`. (`model_refused` is response-level — minted consumer-side from a `content_filter` finish reason, not from a thrown error.)
|
|
267
|
+
- `kind` ∈ `rate_limit | network_failure | model_refused | invalid_response | unauthorized | quota_exceeded | grammar_unenforced`. HTTP status maps: 401/403→`unauthorized`, 402→`quota_exceeded`, 429→`rate_limit`, ≥500→`network_failure`, other 4xx→`invalid_response`; timeouts/fetch errors→`network_failure`. (`model_refused` is response-level — minted consumer-side from a `content_filter` finish reason, not from a thrown error.) **`grammar_unenforced`** is response-level too: the provider mints it when a transported grammar was not enforced by the backend (§13); terminal, never retried.
|
|
263
268
|
- `message` is terse and factual (no guidance prose); `position` is `null` (provider failures aren't localizable into prior content).
|
|
264
269
|
- **Caller-initiated abort is NOT telemetry** — an aborted `signal` rethrows the original abort, never a `ProviderError`.
|
|
265
270
|
|
|
@@ -270,14 +275,14 @@ The `TelemetryEvent` shape is mirrored **locally** (`./telemetry.ts`), structura
|
|
|
270
275
|
`@plurnk/plurnk-grammar` ships `@plurnk/plurnk-grammar/plurnk.gbnf` — a generated llama.cpp grammar constraining sampling to the canonical plurnk form. Ownership splits three ways:
|
|
271
276
|
|
|
272
277
|
- **plurnk-grammar** owns the artifact (canonical-form GBNF, `L(GBNF) ⊂ L(ANTLR)` invariant, tests).
|
|
273
|
-
- **This layer** owns capability detection
|
|
278
|
+
- **This layer** owns capability detection, transport, **and enforcement verification**: `generate({ …, grammar })` attaches the string **verbatim** as the `grammar` body field when the backend supports it, sends no grammar-related field otherwise (cloud APIs reject unknown params), and — when it did transport a grammar — checks that the response actually conforms. The provider never chooses or modifies the grammar.
|
|
274
279
|
- **The consumer** owns policy: whether to constrain a given call, and which root variant to send (e.g. the `root ::= statement` single-statement substitution that forces EOS at the close tag — the shipped `statement+` root never forces EOS, so greedy generation runs to `max_tokens`).
|
|
275
280
|
|
|
276
281
|
**Sampling guard.** Greedy decoding under hard constraint masks degenerates into repetition loops at `repeat_penalty: 1.0`, so `OpenAICompatProvider` sends a per-request `repeat_penalty: 1.15` floor alongside every attached grammar — never relying on server launch flags. (Probed live on llama.cpp b894 + gemma-4-26B; reference: plurnk-grammar `test/llama/gbnf-live.test.ts`.)
|
|
277
282
|
|
|
278
283
|
**The cap is the consumer's required guard.** The repeat-penalty floor suppresses short repetition cycles, NOT long-cycle degeneration: under the multi-op root (optional EOS) at near-greedy temperatures, a constrained emission can answer correctly in its first tokens and then loop to the **context wall** (observed live: 30,736 junk tokens to `finish_reason: length`, minutes of decode reading as a "hang", with the junk echoed into the next turn's prompt — providers#10). No layer defaults a cap: the wire default is unbounded (`n_predict: -1`) and the provider transports policy, never invents it. A consumer enabling constrained sampling MUST pass `maxTokens` (or send a root variant that forces EOS).
|
|
279
284
|
|
|
280
|
-
**Native reasoning and the grammar are mutually exclusive; in-DSL reasoning is the working pattern.** The GBNF masks every sampled token. With NATIVE thinking live (llama-server's own `--reasoning-budget` default, or `enable_thinking: true`), the server auto-gates the grammar past the think block — reasoning flows free — but content-channel enforcement then **leaks** (unconstrained prose, degenerates) or content never arrives; explicit `grammar_lazy`/`grammar_triggers` are ignored on the chat-completions path. The constrained configuration therefore requires the native channel **explicitly closed** — `PLURNK_PROVIDERS_REASONING_BUDGET=0`, which the `template` style emits as `enable_thinking: false`; mere field omission leaves the server default live, and think-inviting tasks then break the loop. With the channel closed, the model
|
|
285
|
+
**Native reasoning and the grammar are mutually exclusive; in-DSL reasoning is the working pattern.** The GBNF masks every sampled token. With NATIVE thinking live (llama-server's own `--reasoning-budget` default, or `enable_thinking: true`), the server auto-gates the grammar past the think block — reasoning flows free — but content-channel enforcement then **leaks** (unconstrained prose, degenerates) or content never arrives; explicit `grammar_lazy`/`grammar_triggers` are ignored on the chat-completions path. The constrained configuration therefore requires the native channel **explicitly closed** — `PLURNK_PROVIDERS_REASONING_BUDGET=0`, which the `template` style emits as `enable_thinking: false`; mere field omission leaves the server default live, and think-inviting tasks then break the loop. With the channel closed, the model reasons **inside the DSL**: the canonical grammar's required `PLAN` statement is a free-text body the model fills with genuine step-by-step reasoning before acting (probed live, b894+gemma: correct chain-of-thought inside `<<PLAN:…:PLAN`, then a clean `SEND`, `finish_reason: stop`). The `PLAN` element belongs to the consumer's grammar contract; the provider's only job is closing the native channel deterministically.
|
|
281
286
|
|
|
282
287
|
**Grammar transport — same GBNF, different wire shapes (`grammarStyle`, default `"none"`).** Backends carry the *same* grammar string differently:
|
|
283
288
|
- **`"llamacpp"`** — top-level `grammar` field + the repeat-penalty floor (§9). Detected from the §11 probe: only llama-server rows on `GET /v1/models` carry a `meta` block. This is any local llama-server (e.g. the generic `openai` provider fronting llama.cpp). `model.plurnk.ai` deliberately opts out via `detectLlamaServer: false` — it reads a window but is treated as a plain OpenAI endpoint, so it is never fingerprinted and never receives a grammar (the router injects its own).
|
|
@@ -286,4 +291,9 @@ The `TelemetryEvent` shape is mirrored **locally** (`./telemetry.ts`), structura
|
|
|
286
291
|
|
|
287
292
|
vLLM/Deepinfra was probed and does **not** expose working GBNF over its OpenAI-compat surface (`guided_grammar` silently ignored; `response_format` accepts only `'text'`) — deliberately left `"none"`. Bespoke siblings opt in via config when their backend qualifies. Capability stays provider-internal.
|
|
288
293
|
|
|
294
|
+
**Enforcement verification (the response side).** Transporting the grammar is necessary but not sufficient — a backend can silently drop the `grammar` field, mislabel the constrained channel (the Fireworks `reasoning_content` case above), or leak unconstrained prose. So when `generate` *did* transport a grammar (`grammarStyle !== "none"`), it validates the returned `content` against that grammar with **`@plurnk/gbnf`** — a zero-dependency, faithful TypeScript port of llama.cpp's own grammar engine, differentially tested against the compiled C validator, hence authoritative for the `llamacpp` path. (This is `@plurnk/gbnf`, the generic GBNF *validator* — **not** `@plurnk/plurnk-grammar`, the plurnk artifact + parser the framework still never depends on; §11.) The check is a grammar-**conformance** test against a string the provider already holds, carrying zero plurnk-DSL semantics, so it does not breach §7/§8 (no `content`→`PlurnkStatement[]` parse).
|
|
295
|
+
|
|
296
|
+
- **Strict.** Any non-`accept` verdict fails hard with a `grammar_unenforced` `ProviderError` (§12): a `reject` (a code point the grammar forbids — the constraint was not applied) *and* an `incomplete` (a valid prefix that never reached a terminal state — truncated or leaked output). The message names the diverging code point / what the grammar expected.
|
|
297
|
+
- **Verify gap is non-fatal.** If the validator cannot even parse the grammar the backend accepted (a port-vs-llama.cpp divergence), `generate` does **not** fail a transport that may have worked — it skips the check and emits a `process` warning (`code: "PLURNK_GRAMMAR_UNVERIFIABLE"`). That gap is a validator bug to fix, not a backend failure.
|
|
298
|
+
|
|
289
299
|
Zero grammar dependency (§11) is preserved: the GBNF string arrives per call; this package never imports the artifact.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAICompat.d.ts","sourceRoot":"","sources":["../src/OpenAICompat.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAgB,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAICompat.d.ts","sourceRoot":"","sources":["../src/OpenAICompat.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAgB,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,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CAAC,KAAK,EAAE,aAAa,GAAG,MAAM;IAoG/B,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE;QAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAgErQ"}
|
package/dist/OpenAICompat.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
// Pure-config providers come from ./standardProviders.ts with no sibling at all.
|
|
10
10
|
import { chatCompletionStream, chatCompletion, OpenAiHttpError } from "./openaiStream.js";
|
|
11
11
|
import { normalizeUsage } from "./usage.js";
|
|
12
|
-
import { toProviderError, classifyProviderError } from "./telemetry.js";
|
|
12
|
+
import { toProviderError, classifyProviderError, ProviderError } from "./telemetry.js";
|
|
13
|
+
import { validateGbnf } from "@plurnk/gbnf";
|
|
13
14
|
// Sampling guard under an active grammar (SPEC §13): greedy decoding under
|
|
14
15
|
// hard constraint masks degenerates into repetition loops at the server
|
|
15
16
|
// default of 1.0, so the floor rides per-request with every attached grammar —
|
|
@@ -49,6 +50,19 @@ export const effortFromBudget = (budget) => {
|
|
|
49
50
|
return "high";
|
|
50
51
|
};
|
|
51
52
|
const heuristicTokens = (text) => (text.length === 0 ? 0 : Math.ceil(text.length / 4));
|
|
53
|
+
// Render a non-accept verdict into a terse, factual grammar_unenforced message
|
|
54
|
+
// (SPEC §12 message policy: no guidance prose). `reject` names the diverging code
|
|
55
|
+
// point + what the grammar would have accepted; `incomplete` names the valid-prefix
|
|
56
|
+
// length that never reached a terminal state.
|
|
57
|
+
const describeUnenforced = (v) => {
|
|
58
|
+
if (v.status === "reject") {
|
|
59
|
+
const expected = v.expected.length > 0
|
|
60
|
+
? v.expected.map((e) => `${e.rule} accepts ${e.accepts}`).join(", ")
|
|
61
|
+
: "end of input";
|
|
62
|
+
return `grammar not enforced: output rejected by the transported grammar at code point ${v.pos} (${JSON.stringify(v.char)}); expected ${expected}`;
|
|
63
|
+
}
|
|
64
|
+
return `grammar not enforced: output is an incomplete match of the transported grammar — a valid prefix of ${v.pos} code points that never terminated`;
|
|
65
|
+
};
|
|
52
66
|
export default class OpenAICompatProvider {
|
|
53
67
|
#model;
|
|
54
68
|
#url;
|
|
@@ -162,6 +176,29 @@ export default class OpenAICompatProvider {
|
|
|
162
176
|
h["Plurnk-Client"] = client;
|
|
163
177
|
return h;
|
|
164
178
|
}
|
|
179
|
+
// Enforcement verification (SPEC §13). When a grammar was actually transported
|
|
180
|
+
// (grammarStyle !== "none"), the backend MUST have constrained the output;
|
|
181
|
+
// some silently drop the grammar field or mislabel the channel, and without
|
|
182
|
+
// this check we would return unconstrained output as if enforced. STRICT: any
|
|
183
|
+
// non-accept verdict (reject, or an incomplete/never-terminated match) is a
|
|
184
|
+
// grammar_unenforced failure. A grammar our own validator can't parse — even
|
|
185
|
+
// though the backend accepted it (a port-vs-llama.cpp gap) — is a non-fatal
|
|
186
|
+
// verify gap: warn, don't fail a transport that may have worked. This is a
|
|
187
|
+
// conformance check against the grammar we already hold, NOT a plurnk-DSL
|
|
188
|
+
// parse (§8) — it stays grammar-generic and backend-agnostic.
|
|
189
|
+
#verifyGrammarEnforced(grammar, content) {
|
|
190
|
+
let verdict;
|
|
191
|
+
try {
|
|
192
|
+
verdict = validateGbnf(grammar, content);
|
|
193
|
+
}
|
|
194
|
+
catch (cause) {
|
|
195
|
+
process.emitWarning(`${this.#source}: could not verify grammar enforcement — the transported grammar did not parse in @plurnk/gbnf (${cause.message})`, { code: "PLURNK_GRAMMAR_UNVERIFIABLE" });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (verdict.status === "accept")
|
|
199
|
+
return;
|
|
200
|
+
throw new ProviderError(this.#source, "grammar_unenforced", describeUnenforced(verdict));
|
|
201
|
+
}
|
|
165
202
|
async generate({ messages, runId, signal, grammar, maxTokens, attributions, client }) {
|
|
166
203
|
// Boundary validation (SPEC §2): the run identity is required.
|
|
167
204
|
if (runId === undefined || runId.length === 0)
|
|
@@ -211,6 +248,10 @@ export default class OpenAICompatProvider {
|
|
|
211
248
|
await sleepWithAbort(retryAfter ?? RETRY_BASE_DELAY_MS * 2 ** attempt, signal);
|
|
212
249
|
}
|
|
213
250
|
}
|
|
251
|
+
// Verify the backend honored the grammar we transported (§13) before the
|
|
252
|
+
// content reaches the consumer — only when we actually sent one.
|
|
253
|
+
if (grammar !== undefined && this.#grammarStyle !== "none")
|
|
254
|
+
this.#verifyGrammarEnforced(grammar, raw.content);
|
|
214
255
|
return {
|
|
215
256
|
assistant: {
|
|
216
257
|
content: raw.content,
|
package/dist/OpenAICompat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;AAGjF,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAICompat.js","sourceRoot":"","sources":["../src/OpenAICompat.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,4EAA4E;A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;aAClC;YACD,YAAY,EAAE,GAAG;SACpB,CAAC;IACN,CAAC;CACJ"}
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type TelemetryEvent = {
|
|
|
4
4
|
message?: string | null;
|
|
5
5
|
position?: null;
|
|
6
6
|
};
|
|
7
|
-
export type ProviderTelemetryKind = "rate_limit" | "network_failure" | "model_refused" | "invalid_response" | "unauthorized" | "quota_exceeded";
|
|
7
|
+
export type ProviderTelemetryKind = "rate_limit" | "network_failure" | "model_refused" | "invalid_response" | "unauthorized" | "quota_exceeded" | "grammar_unenforced";
|
|
8
8
|
export declare const providerSource: (vendor: string) => string;
|
|
9
9
|
export declare class ProviderError extends Error {
|
|
10
10
|
readonly source: string;
|
package/dist/telemetry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,cAAc,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,IAAI,CAAC;CACnB,CAAC;AAGF,MAAM,MAAM,qBAAqB,GAC3B,YAAY,GACZ,iBAAiB,GACjB,eAAe,GACf,kBAAkB,GAClB,cAAc,GACd,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,cAAc,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,EAAE,IAAI,CAAC;CACnB,CAAC;AAGF,MAAM,MAAM,qBAAqB,GAC3B,YAAY,GACZ,iBAAiB,GACjB,eAAe,GACf,kBAAkB,GAClB,cAAc,GACd,gBAAgB,GAIhB,oBAAoB,CAAC;AAG3B,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,MAA8B,CAAC;AAK/E,qBAAa,aAAc,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEnB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;IAQnI,gBAAgB,IAAI,cAAc;CAGrC;AAID,eAAO,MAAM,qBAAqB,GAAI,KAAK,OAAO,KAAG;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAalG,CAAC;AAIF,eAAO,MAAM,eAAe,GAAI,KAAK,OAAO,EAAE,QAAQ,MAAM,KAAG,aAK9D,CAAC"}
|
package/dist/telemetry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,iEAAiE;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,iEAAiE;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAyBpD,6EAA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B,EAAE,OAAO,EAAE,CAAC;QAC/D,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;QAC3D,IAAI,MAAM,IAAI,GAAG;YAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC;QAC/D,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC;IACjD,CAAC;IACD,MAAM,CAAC,GAAG,GAA0C,CAAC;IACrD,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,gBAAgB,CAAC;IAChE,wEAAwE;IACxE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,CAAC;AAChD,CAAC,CAAC;AAEF,+EAA+E;AAC/E,oDAAoD;AACpD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAY,EAAE,MAAc,EAAiB,EAAE;IAC3E,IAAI,GAAG,YAAY,aAAa;QAAE,OAAO,GAAG,CAAC;IAC7C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,GAAG,YAAY,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAClE,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plurnk/plurnk-providers",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Framework + contract for
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"description": "Framework + contract for plurnk LLM transports: built-in standard OpenAI-compatible providers plus scope-agnostic discovery of first-party and third-party provider packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plurnk",
|
|
7
7
|
"llm",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"typescript": "^6.0.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"@plurnk/gbnf": "0.1.1",
|
|
53
54
|
"@plurnk/plurnk-models": "0.1.0",
|
|
54
55
|
"gpt-tokenizer": "^3.4.0",
|
|
55
56
|
"llama-tokenizer-js": "^1.2.2"
|