@plurnk/plurnk-providers 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/.env.defaults +2 -0
  2. package/README.md +2 -2
  3. package/SPEC.md +163 -62
  4. package/dist/AiSdkProvider.d.ts +1 -2
  5. package/dist/AiSdkProvider.d.ts.map +1 -1
  6. package/dist/AiSdkProvider.js +8 -5
  7. package/dist/AiSdkProvider.js.map +1 -1
  8. package/dist/AiSdkRequestBody.d.ts.map +1 -1
  9. package/dist/AiSdkRequestBody.js +3 -1
  10. package/dist/AiSdkRequestBody.js.map +1 -1
  11. package/dist/LeadingReasoning.js +3 -3
  12. package/dist/LeadingReasoning.js.map +1 -1
  13. package/dist/Mock.d.ts +3 -3
  14. package/dist/Mock.d.ts.map +1 -1
  15. package/dist/Mock.js.map +1 -1
  16. package/dist/Pool.d.ts +1 -2
  17. package/dist/Pool.d.ts.map +1 -1
  18. package/dist/Pool.js +7 -8
  19. package/dist/Pool.js.map +1 -1
  20. package/dist/ProviderRegistry.d.ts.map +1 -1
  21. package/dist/ProviderRegistry.js +8 -4
  22. package/dist/ProviderRegistry.js.map +1 -1
  23. package/dist/RequestFields.d.ts.map +1 -1
  24. package/dist/RequestFields.js +15 -7
  25. package/dist/RequestFields.js.map +1 -1
  26. package/dist/accounting.d.ts.map +1 -1
  27. package/dist/accounting.js +8 -5
  28. package/dist/accounting.js.map +1 -1
  29. package/dist/aiSdkTransport.d.ts.map +1 -1
  30. package/dist/aiSdkTransport.js +25 -31
  31. package/dist/aiSdkTransport.js.map +1 -1
  32. package/dist/catalogProvider.d.ts +2 -3
  33. package/dist/catalogProvider.d.ts.map +1 -1
  34. package/dist/catalogProvider.js +9 -8
  35. package/dist/catalogProvider.js.map +1 -1
  36. package/dist/compatibleProvider.d.ts +1 -1
  37. package/dist/compatibleProvider.d.ts.map +1 -1
  38. package/dist/compatibleProvider.js +22 -9
  39. package/dist/compatibleProvider.js.map +1 -1
  40. package/dist/cost.d.ts.map +1 -1
  41. package/dist/cost.js +18 -8
  42. package/dist/cost.js.map +1 -1
  43. package/dist/env.d.ts +9 -8
  44. package/dist/env.d.ts.map +1 -1
  45. package/dist/env.js +4 -3
  46. package/dist/env.js.map +1 -1
  47. package/dist/errors.d.ts.map +1 -1
  48. package/dist/errors.js +7 -7
  49. package/dist/errors.js.map +1 -1
  50. package/dist/model-options.d.ts.map +1 -1
  51. package/dist/model-options.js +1 -1
  52. package/dist/model-options.js.map +1 -1
  53. package/dist/native-tools.d.ts.map +1 -1
  54. package/dist/native-tools.js +3 -0
  55. package/dist/native-tools.js.map +1 -1
  56. package/dist/ollama.d.ts.map +1 -1
  57. package/dist/ollama.js +3 -1
  58. package/dist/ollama.js.map +1 -1
  59. package/dist/promptTokens.d.ts.map +1 -1
  60. package/dist/promptTokens.js +11 -5
  61. package/dist/promptTokens.js.map +1 -1
  62. package/dist/sdkModels.d.ts.map +1 -1
  63. package/dist/sdkModels.js +9 -3
  64. package/dist/sdkModels.js.map +1 -1
  65. package/dist/usage.d.ts +1 -1
  66. package/dist/usage.d.ts.map +1 -1
  67. package/dist/usage.js +18 -5
  68. package/dist/usage.js.map +1 -1
  69. package/package.json +6 -6
package/.env.defaults CHANGED
@@ -51,6 +51,8 @@ PLURNK_PROVIDERS_REASONING_RESPONSE_STYLE=verbatim
51
51
  # PLURNK_PROVIDERS_REASONING_ON_BODY='{"enable_thinking":true}'
52
52
  # PLURNK_PROVIDERS_REASONING_OFF_BODY='{"enable_thinking":false}'
53
53
  # PLURNK_PROVIDERS_REASONING_EFFORTS=low,medium,high
54
+ # A llama-server route admits off and adaptive; declare the fixed efforts its chat template
55
+ # distinguishes, e.g. PLURNK_PROVIDERS_REASONING_EFFORTS_<alias>=low,medium,xhigh.
54
56
  # PLURNK_PROVIDERS_REASONING_TRANSPORT_EFFORTS=none,low,medium,high
55
57
  # PLURNK_PROVIDERS_OPTIONS_NAMESPACE=openrouter
56
58
  # PLURNK_PROVIDERS_REASONING_ADAPTIVE_BODY='{}'
package/README.md CHANGED
@@ -221,7 +221,7 @@ One specimen at a time, deterministically:
221
221
 
222
222
  ```sh
223
223
  cd plurnk-core
224
- npm run test:live:specimen -- "<test-name-pattern>"
224
+ npm run test:live -- --specimen "<exact specimen name>"
225
225
  ```
226
226
 
227
227
  The selector inserts `--test-name-pattern` before the expanded live file list in
@@ -256,5 +256,5 @@ npm run test:lint -w @plurnk/plurnk-providers
256
256
  npm run test:unit -w @plurnk/plurnk-providers
257
257
  ```
258
258
 
259
- `npm run test:providersPing` is an explicit paid diagnostic; it calls each
259
+ `npm run probe:providers` is an explicit paid diagnostic; it calls each
260
260
  keyed provider once and prints the retained sanitized evidence directory.
package/SPEC.md CHANGED
@@ -6,6 +6,14 @@ ordinary provider protocols.
6
6
 
7
7
  ## §1 Ownership
8
8
 
9
+ <!-- map -->
10
+ | Tag | Promise |
11
+ | --- | --- |
12
+ | {§provider-runtime-neutral-accounting} | `@plurnk/plurnk-providers/accounting` — Provider-request aggregation, Models.dev cost estimation, and their… |
13
+ | {§provider-runtime-neutral-errors} | `@plurnk/plurnk-providers/errors` — Normalized `ProviderError`, `ProviderErrorKind`, and the types of its… |
14
+ | {§provider-runtime-neutral-openai} | `@plurnk/plurnk-providers/openai` — The OpenAI-compatible provider: SDK transport, request capture,… |
15
+ <!-- /map -->
16
+
9
17
  The provider stack has four owners:
10
18
 
11
19
  1. Models.dev supplies a release-time snapshot of provider package, API
@@ -22,20 +30,39 @@ model prefix, context window, price, or vendor request shape into a PLURNK
22
30
  table. A missing or wrong catalog fact is fixed upstream, overridden through a
23
31
  provider declaration, or left explicitly unknown.
24
32
 
25
- The package exposes two runtime-neutral public surfaces:
33
+ The package exposes three runtime-neutral public surfaces:
26
34
 
27
35
  | Surface | Contract |
28
36
  | --- | --- |
29
37
  | §provider-runtime-neutral-accounting `@plurnk/plurnk-providers/accounting` | Provider-request aggregation, Models.dev cost estimation, and their wire types. |
30
38
  | §provider-runtime-neutral-errors `@plurnk/plurnk-providers/errors` | Normalized `ProviderError`, `ProviderErrorKind`, and the types of its attempt, accounting, and capacity evidence. |
39
+ | §provider-runtime-neutral-openai `@plurnk/plurnk-providers/openai` | The OpenAI-compatible provider: SDK transport, request capture, accounting, capacity and error normalization, reaching no Node built-in. |
31
40
 
32
- Both surfaces re-export the package's sole implementations without evaluating
41
+ All three re-export the package's sole implementations without evaluating
33
42
  Node-only provider discovery, filesystem defaults, or runtime construction.
34
43
  The package root remains the Node provider-runtime composition surface and is
35
44
  not a Worker entrypoint.
36
45
 
37
46
  ## §2 Provider interface
38
47
 
48
+ <!-- map -->
49
+ | Tag | Promise |
50
+ | --- | --- |
51
+ | {§provider-interface} | `Provider` exposes immutable model facts and one generation operation: |
52
+ | {§provider-prompt-measurement} | `PromptTokenMeasurement` is a discriminated request-level result: |
53
+ | {§provider-capacity-admission} | `assessRequestCapacity` intersects every known physical input constraint |
54
+ | {§provider-monetary-evidence} | One precedence path converts each physical provider request into {§provider-cost} evidence before the request… |
55
+ | {§provider-cache-identity} | `generate` requires a non-empty, stable, opaque `workerId`. |
56
+ | {§provider-call-kind} | `callKind` is either `emission` (the response is a PLURNK turn emission) or `bare` (the response is… |
57
+ | {§provider-native-tools-disabled} | Generation requests declare no native tools and select the SDK's portable `none` tool choice, for emissions… |
58
+ | {§provider-generation-completion} | Stream consumption follows the provider's completion boundary, subject to caller cancellation and configured… |
59
+ | {§provider-request-observer} | When a consumer supplies the request observer, the adapter opens one durable identity through it immediately… |
60
+ | {§provider-dispatched-request} | With `PLURNK_PROVIDERS_RAWBODY` enabled, installed SDK transports also retain the exact serialized generation… |
61
+ | {§provider-reasoning-observer} | When a consumer supplies `observeReasoning`, the provider synchronously delivers each exact, ordered,… |
62
+ | {§provider-finish-reason} | The finish reason is the AI SDK's unified classification |
63
+ | {§provider-tagged-reasoning} | Structured provider or SDK reasoning fields are authoritative. |
64
+ <!-- /map -->
65
+
39
66
  §provider-interface `Provider` exposes immutable model facts and one generation
40
67
  operation:
41
68
 
@@ -93,19 +120,20 @@ provided its detail names the cause; one unable to quantify anything returns
93
120
  `unavailable`. A malformed measurement is a provider contract violation and
94
121
  fails hard.
95
122
 
96
- §provider-capacity-admission `assessRequestCapacity` intersects every known
97
- physical input constraint: independent `maxInputTokens` and
98
- `contextWindow - outputFloor`, the input wall ({§provider-output-floor}). Its result is `admit`, `reject`, or `defer` and
99
- retains the complete limit and measurement evidence. Exact fit admits; exact
100
- overflow of the wall rejects; a prompt between the curation reservation and the wall is admitted with its grant flexed down. A proven upper bound admits only when it fits. Unknown limits,
101
- an upper bound above a limit, estimates, and unavailable measurements defer to
102
- the upstream provider as capacity oracle. The curation reservation's intersection, `maxInputTokens` and `contextWindow - outputBudget`, is
103
- exposed as `inputCapacity`, the line Core packs the room against; the wall's, as `inputWall`; `null` means the available limits cannot establish
104
- one. A known combined context and output budget must leave positive input
105
- capacity. Consumers may display or use that fact as policy, but MUST NOT
106
- substitute their own content heuristic for request-shaped admission. A consumer
107
- may assess a request before sending it; `generate` repeats the assessment as its
108
- own guard.
123
+ §provider-capacity-admission **`assessRequestCapacity` intersects every known physical input constraint** — independent `maxInputTokens` and `contextWindow - outputFloor`, the input wall ({§provider-output-floor}) — and answers `admit`, `reject`, or `defer`, retaining the complete limit and measurement evidence. A consumer may assess a request before sending it; `generate` repeats the assessment as its own guard. Consumers may display or use that fact as policy, but MUST NOT substitute their own content heuristic for request-shaped admission.
124
+
125
+ | Measurement | Verdict |
126
+ | --- | --- |
127
+ | Exact fit | admit |
128
+ | Exact overflow of the wall | reject |
129
+ | A prompt between the curation reservation and the wall | admitted with its grant flexed down |
130
+ | A proven upper bound | admits only when it fits |
131
+ | Unknown limits, an upper bound above a limit, estimates, and unavailable measurements | defer to the upstream provider as capacity oracle |
132
+
133
+ | Exposed | Meaning |
134
+ | --- | --- |
135
+ | `inputCapacity` | the curation reservation's intersection, `maxInputTokens` and `contextWindow - outputBudget`: the line Core packs the room against |
136
+ | `inputWall` | the wall's; `null` means the available limits cannot establish one; a known combined context and output budget must leave positive input capacity |
109
137
 
110
138
  `tokenize` is the separate content-token capability and exists only when the
111
139
  endpoint exposes its real vocabulary. Content tokenization does not substitute
@@ -300,12 +328,28 @@ rail observed.
300
328
 
301
329
  ## §3 AI SDK boundary
302
330
 
331
+ <!-- map -->
332
+ | Tag | Promise |
333
+ | --- | --- |
334
+ | {§provider-sdk-boundary} | Cataloged providers instantiate their Models.dev-declared AI SDK package. |
335
+ | {§operator-cost-override} | Models.dev is the rate starting point; the operator may overlay it. |
336
+ | {§provider-effort} | The portable vocabulary comes from {§effort-wire}. |
337
+ | {§provider-readable-reasoning} | Route-owned options may request exposed reasoning text. |
338
+ | {§provider-sdk-warning} | AI SDK compatibility, unsupported-feature, deprecation, and other call warnings become source-attributed… |
339
+ | {§provider-cache-affinity} | Cache affinity is route-owned request projection. |
340
+ | {§provider-model-options} | A model family's native options are a provider declaration. |
341
+ | {§provider-cache-write-policy} | Cache-write policy is separate from affinity. |
342
+ | {§deepseek-reasoning-request} | Direct DeepSeek uses the panel's request-field declarations under {§provider-wire-declaration}. |
343
+ | {§provider-wire-declaration} | Request-field declarations |
344
+ <!-- /map -->
345
+
303
346
  §provider-sdk-boundary Cataloged providers instantiate their
304
347
  Models.dev-declared AI SDK package.
305
348
  Standard request shaping, streaming, usage, and vendor error parsing belong to
306
349
  the SDK. PLURNK supplies cancellation and deadline signals and owns the sole
307
350
  cross-attempt scheduler so every physical request remains observable and
308
- accountable.
351
+ accountable. The adapter hands the SDK the conversation as authored: a leading
352
+ system message reaches the wire as the request's system message.
309
353
 
310
354
  | Usage input | Normalization |
311
355
  | --- | --- |
@@ -490,7 +534,10 @@ openai-compatible (DeepInfra, Together) write `reasoning_effort` from their own
490
534
  §provider-configuration Every operational value is an environment knob
491
535
  documented in `.env.defaults`.
492
536
  There are no hidden tuning constants. Every `PLURNK_PROVIDERS_*` knob may be
493
- scoped to an alias by appending `_<alias>`; the scoped value wins.
537
+ scoped to an alias by appending `_<alias>`; the scoped value wins, and the alias
538
+ segment folds case. The scoping takes a closed list of knob names: a consumer
539
+ scopes its own knobs by passing its list, and neither list reaches the other's
540
+ knobs.
494
541
  Each projection reads one fresh environment snapshot without modifying its
495
542
  source; later projections observe later configuration, never a cached view.
496
543
 
@@ -516,6 +563,16 @@ defaults.
516
563
 
517
564
  ## §5 Resolution
518
565
 
566
+ <!-- map -->
567
+ | Tag | Promise |
568
+ | --- | --- |
569
+ | {§provider-resolution} | `PLURNK_MODEL_<alias>=<provider>/<model-id>` declares an alias. |
570
+ | {§model-catalog-readiness} | Catalog readiness and construction share one local configuration predicate. |
571
+ | {§provider-input-modalities} | Native input parts |
572
+ | {§model-fact-resolution} | Model fact precedence |
573
+ | {§provider-fact-authority} | Provider declarations configure facts, not credentials, and Models.dev is authoritative for cataloged… |
574
+ <!-- /map -->
575
+
519
576
  §provider-resolution `PLURNK_MODEL_<alias>=<provider>/<model-id>` declares an
520
577
  alias.
521
578
  `PLURNK_MODEL=<selector>` selects either a declared alias or an exact
@@ -537,21 +594,15 @@ model request.
537
594
 
538
595
  ### §provider-input-modalities Native input parts
539
596
 
540
- A provider declares `inputModalities`, the set of native non-text inputs its model
541
- accepts, from the catalog's input modalities (Models.dev `modalities.input` minus
542
- `text`, kept to the vocabulary `image`, `pdf`, `audio`, `video`; empty when the
543
- model is unknown). A user `ChatMessage` may then carry text beside the AI SDK's
544
- current `{ type: "file", data: bytes, mediaType }` part; `mediaType` distinguishes
545
- an image, PDF, audio, or future native input without a second internal part shape. The
546
- AI SDK transport forwards those parts as the model's native file inputs; it
547
- alone serializes the canonical model and messages before provider extension
548
- fields are merged. System and assistant messages stay text, and prompt-token estimates count text
549
- only, the provider's reported usage owning each part's cost. A pool declares a
550
- modality only when every backend does; the Mock declares them by option and
551
- records every request it receives. Which parts actually ride a request is the
552
- service's decision per attachment ({§packet-attachment-parts} in the core specification).
553
- An accepted modality does not imply every codec/container is supported: SDK or endpoint
554
- format rejections remain provider errors, never silent omission or a text-only substitute.
597
+ A provider declares `inputModalities`, the set of native non-text inputs its model accepts, from the catalog's input modalities (Models.dev `modalities.input` minus `text`, kept to the vocabulary `image`, `pdf`, `audio`, `video`; empty when the model is unknown). Which parts actually ride a request is the service's decision per attachment ({§packet-attachment-parts} in the core specification).
598
+
599
+ | Fact | Rule |
600
+ | --- | --- |
601
+ | The part | a user `ChatMessage` may carry text beside the AI SDK's current `{ type: "file", data: bytes, mediaType }` part; `mediaType` distinguishes an image, PDF, audio, or future native input without a second internal part shape |
602
+ | The transport | the AI SDK transport forwards those parts as the model's native file inputs; it alone serializes the canonical model and messages before provider extension fields are merged |
603
+ | Other messages | system and assistant messages stay text, and prompt-token estimates count text only, the provider's reported usage owning each part's cost |
604
+ | Pools and the Mock | a pool declares a modality only when every backend does; the Mock declares them by option and records every request it receives |
605
+ | Codecs | an accepted modality does not imply every codec/container is supported: SDK or endpoint format rejections remain provider errors, never silent omission or a text-only substitute |
555
606
 
556
607
  ### §model-fact-resolution Model fact precedence
557
608
 
@@ -660,6 +711,14 @@ model physics. `Discovery.packageAttributions` carries the canonical package map
660
711
 
661
712
  ## §7 Local capabilities
662
713
 
714
+ <!-- map -->
715
+ | Tag | Promise |
716
+ | --- | --- |
717
+ | {§provider-local-capabilities} | The `openai` local adapter probes `/v1/models`. |
718
+ | {§llama-template-effort} | A detected llama-server rail admits `off` and `adaptive`, and a fixed effort only where the operator declares… |
719
+ | {§llama-reasoning-request} | The allowance is cumulative across the complete response. |
720
+ <!-- /map -->
721
+
663
722
  §provider-local-capabilities The `openai` local adapter probes `/v1/models`. A
664
723
  llama-server fingerprint may
665
724
  also expose:
@@ -684,13 +743,17 @@ OpenAI-compatible generation endpoint through the SDK adapter.
684
743
  For a detected llama-server, PLURNK sends the complete reasoning contract on
685
744
  every request:
686
745
 
687
- | Posture | Template activation | `thinking_budget_tokens` |
688
- |---|---:|---:|
689
- | `off` | false | `0` |
690
- | `adaptive` | true | configured reasoning subset, otherwise omitted |
746
+ | Posture | Template activation | Template `reasoning_effort` | `thinking_budget_tokens` |
747
+ |---|---:|---|---:|
748
+ | `off` | false | none | `0` |
749
+ | `adaptive` | true | none | configured reasoning subset, otherwise omitted |
750
+ | A declared fixed effort | true | the effort's name | configured reasoning subset, otherwise omitted |
691
751
 
692
- The template control cannot express distinct fixed effort levels, so this
693
- adapter advertises only `off` and `adaptive`.
752
+ §llama-template-effort A detected llama-server rail admits `off` and `adaptive`, and a fixed
753
+ effort only where the operator declares it (`REASONING_EFFORTS`,
754
+ {§provider-wire-declaration}). The chat template decides what each level means and which
755
+ levels it accepts; PLURNK infers neither from the template nor from the model's name, and a
756
+ template that refuses a declared level answers on the first request.
694
757
 
695
758
  The allowance is contained by the request's total output budget. Template calls
696
759
  normally use `reasoning_format: "auto"` for a separate
@@ -705,8 +768,22 @@ later reasoning block does not replenish it. Template parsing, the reasoning
705
768
  sampler, normalized usage, and the returned reasoning channel MUST agree on that
706
769
  response boundary.
707
770
 
771
+ ## Probes
772
+
773
+ §provider-ping-probe **`npm run probe:providers` reaches every keyed provider once, by one cheapest declared route.** Planning selects, per provider that has a credential, its cheapest declared alias; a provider-named alias resolves that provider's own unpriced route without guessing another model, a catalog key with no declared route stays explicitly red, and several unpriced aliases of one provider are one ambiguous provider, never guessed routes. Execution invokes every selected route exactly once and preserves red outcomes. Each attempted provider leaves one safe JSON record: response evidence keeps its structure and no provider scalar values, retained diagnostics redact credentials, account identity and URL authority, and secret discovery never mistakes a token-limit control for a credential.
774
+
775
+ §token-envelope-probe **`npm run probe:tokens` measures output-token envelopes for the aliases named explicitly, and no other.** Its output-token modes distinguish the configured policy from the model's physics.
776
+
708
777
  ## §8 Request authority
709
778
 
779
+ <!-- map -->
780
+ | Tag | Promise |
781
+ | --- | --- |
782
+ | {§provider-request-authority} | The caller's `sampling` bag expresses sampling intent. |
783
+ | {§provider-request-controls} | A configured service tier or logprobs count reaches a native route only through the per-call option its SDK… |
784
+ | {§openrouter-app-attribution} | A route on the OpenRouter SDK identifies the calling application only as its provider declares. |
785
+ <!-- /map -->
786
+
710
787
  §provider-request-authority The caller's `sampling` bag expresses sampling
711
788
  intent. It cannot override:
712
789
 
@@ -755,6 +832,25 @@ both.
755
832
 
756
833
  ## §9 Failures, retries, and cancellation
757
834
 
835
+ <!-- map -->
836
+ | Tag | Promise |
837
+ | --- | --- |
838
+ | {§provider-failure-normalization} | Provider failures normalize to `ProviderError`. |
839
+ | {§provider-retryable-truth} | `retryable` states what happens next. |
840
+ | {§provider-failure-cause} | The wrapper's cause is evidence, bounded. |
841
+ | {§provider-capacity-failure} | A proven exact preflight overflow and an upstream context rejection normalize to… |
842
+ | {§provider-flexed-allowance} | The grant is the window's remainder, between the floor and the model's limit. |
843
+ | {§provider-output-floor} | The floor is the wall's other side. |
844
+ | {§provider-sampling-passthrough} | Unconfigured sampling retains endpoint defaults. |
845
+ | {§provider-connectivity} | The provider adapter owns one attempt scheduler around the complete generation exchange; SDK-internal retries… |
846
+ | {§provider-cancellation-evidence} | Received usage/charge evidence and available response identity survive cancellation and deadline… |
847
+ | {§provider-native-tool-calls} | A response with native tool-call data, or a `tool_calls` finish, preserves its text, reasoning, structured… |
848
+ | {§provider-completed-admission} | A completed exchange is admitted as the provider delivered it. |
849
+ | {§provider-request-rejection} | An HTTP 4xx rejection not classified as authorization, quota, capacity, grammar, rate limit, or transient… |
850
+ | {§provider-interrupted-attempt} | Provider-declared interruption |
851
+ | {§provider-generation-failed} | Provider-declared generation error |
852
+ <!-- /map -->
853
+
758
854
  §provider-failure-normalization Provider failures normalize to `ProviderError`.
759
855
  Its public contract is an RFC
760
856
  9457 Problem Details object with an exact status, stable type, occurrence
@@ -764,7 +860,10 @@ into an empty model turn or reduced to a message plus a generic status.
764
860
  Upstream diagnostic text is bounded by
765
861
  `PLURNK_PROVIDERS_ERROR_DETAIL_LIMIT`; the committed `.env.defaults` owns its
766
862
  normal value. Retry exhaustion is preserved as `attempts` and
767
- `retryExhausted`; it does not change the Problem's `retryable`.
863
+ `retryExhausted`; it does not change the Problem's `retryable`. A provider's
864
+ producer id is `provider:<name>`, the name folded to the `source` grammar of
865
+ `Notice.json` (lower-case words and hyphens; a leading digit is prefixed
866
+ `p-`); an empty name is refused.
768
867
 
769
868
  §provider-retryable-truth **`retryable` states what happens next.** A Problem's
770
869
  `retryable` is exactly membership of its kind in the exported
@@ -798,16 +897,12 @@ request-accounting row. Capacity failures are not connectivity failures and are
798
897
  never retried by the provider scheduler; bounded packet recovery belongs to the
799
898
  consumer.
800
899
 
801
- §provider-flexed-allowance **The grant is the window's remainder, between the floor and the model's limit.** The
802
- configured output budget is the reservation curation packs the input against
803
- (`window − outputBudget`), and it is the only allowance the model is ever
804
- shown — the packet's disclosed `tokensResponseMax` stays the configured reservation
805
- so the response discipline it teaches never varies. The wire grants the remainder: with an exact prompt count
806
- (llama-server's input-token endpoint) `window − promptTokens − 256`, clamped to no less than the
807
- output floor and no more than the model's own output limit, so a response overflowing the disclosed reservation
808
- completes whenever the window's unclaimed room can hold it, and a prompt that ate into the reservation still leaves the floor. Every other
809
- measurement kind — and any pool — grants the reservation, clamped by the same remainder taken from the prompt's estimate so the wire never asks the window for more than it has; an estimate proves
810
- nothing about the true remainder, so it never rejects.
900
+ §provider-flexed-allowance **The grant is the window's remainder, between the floor and the model's limit.** The configured output budget is the reservation curation packs the input against (`window − outputBudget`), and it is the only allowance the model is ever shown — the packet's disclosed `tokensResponseMax` stays the configured reservation so the response discipline it teaches never varies.
901
+
902
+ | Prompt measurement | The wire grants |
903
+ | --- | --- |
904
+ | An exact prompt count (llama-server's input-token endpoint) | `window − promptTokens − 256`, clamped to no less than the output floor and no more than the model's own output limit, so a response overflowing the disclosed reservation completes whenever the window's unclaimed room can hold it, and a prompt that ate into the reservation still leaves the floor |
905
+ | Every other measurement kind, and any pool | the reservation, clamped by the same remainder taken from the prompt's estimate so the wire never asks the window for more than it has; an estimate proves nothing about the true remainder, so it never rejects |
811
906
 
812
907
  §provider-output-floor **The floor is the wall's other side.** `PLURNK_PROVIDERS_OUTPUT_FLOOR`, shipped as `10%`, is the least response room any request keeps, capped by the output budget; `window − floor`, intersected with `maxInputTokens`, is the physical input wall exposed as `inputWall`. A request under the curation reservation is the ordinary case; a request between the reservation and the wall is admitted with its grant flexed down to the remainder; an exact prompt over the wall is rejected before I/O; an estimate over the wall defers to the upstream provider as capacity oracle with its grant at the floor. Core consults the wall, never the reservation, to end a loop ({§context-wall} in the core contract). A response exceeding even the grant is cut,
813
908
  and the notice names the true per-call grant (`capacity.responseMax` on the
@@ -957,6 +1052,15 @@ the service issues a verdict on it.
957
1052
 
958
1053
  ## §11 Evidence and metadata
959
1054
 
1055
+ <!-- map -->
1056
+ | Tag | Promise |
1057
+ | --- | --- |
1058
+ | {§provider-evidence} | `assistantRaw` is an opaque normalized transport record. |
1059
+ | {§provider-wire-emission} | The emission is retained as the wire carried it, on every response. |
1060
+ | {§provider-usage-refusal} | The provider's bookkeeping is not the exchange. |
1061
+ | {§provider-open-reasoning} | Plurnk requires endpoints with open, verbatim reasoning. |
1062
+ <!-- /map -->
1063
+
960
1064
  §provider-evidence `assistantRaw` is an opaque normalized transport record.
961
1065
  Provider top-level
962
1066
  metadata is forwarded as an open bag without reinterpreting currencies or
@@ -968,19 +1072,16 @@ The latter retains SDK response bodies/chunks and the dispatched request body
968
1072
  under {§provider-dispatched-request}, without requesting extra model output.
969
1073
  Neither changes unconditional accounting or failed-response evidence.
970
1074
 
971
- §provider-wire-emission **The emission is retained as the wire carried it, on every
972
- response.** Beside the normalized `content` and `reasoning`, the transport record keeps
973
- `wire`: the number of raw chunks, the chunks that carried no field at all, every delta or
974
- message field the stream carried with the number of chunks carrying it, tool calls merged
975
- by index with their arguments as streamed, the finish reasons seen, and the verbatim text
976
- of every string field the record does not already hold. Nothing is opt-in and nothing is
977
- reinterpreted: a blank emission reads as thirteen chunks that carried nothing, or as a
978
- tool-call section the model emitted into a channel the protocol does not read, instead of
979
- being guessed at from token counts. Frames outside the recognized OpenAI-compatible
980
- envelope remain verbatim in `wire.unmappedChunks`; the recorder never discards an
981
- unrecognized/native payload or invents another provider parser. This required
982
- evidence is independent of the optional complete `rawBody` dataset capture.
983
- Covered by `aiSdkTransport.test.ts` and core's `Digest.wire-evidence.test.ts`.
1075
+ §provider-wire-emission **The emission is retained as the wire carried it, on every response.** Beside the normalized `content` and `reasoning`, the transport record keeps `wire`. Nothing is opt-in and nothing is reinterpreted: a blank emission reads as thirteen chunks that carried nothing, or as a tool-call section the model emitted into a channel the protocol does not read, instead of being guessed at from token counts. This required evidence is independent of the optional complete `rawBody` dataset capture. Covered by `aiSdkTransport.test.ts` and core's `Digest.wire-evidence.test.ts`.
1076
+
1077
+ | `wire` holds | What |
1078
+ | --- | --- |
1079
+ | Chunks | the number of raw chunks, and the chunks that carried no field at all |
1080
+ | Fields | every delta or message field the stream carried with the number of chunks carrying it |
1081
+ | Tool calls | merged by index with their arguments as streamed |
1082
+ | Finish reasons | those seen |
1083
+ | Text | the verbatim text of every string field the record does not already hold |
1084
+ | `wire.unmappedChunks` | frames outside the recognized OpenAI-compatible envelope, verbatim; the recorder never discards an unrecognized/native payload or invents another provider parser |
984
1085
 
985
1086
  §provider-usage-refusal **The provider's bookkeeping is not the exchange.** Usage
986
1087
  normalization is exact; a refusal never fails or retries the response. The same
@@ -1,8 +1,7 @@
1
- import type { ChatMessage, PromptTokenMeasurement, Provider, ProviderCostNormalizer, ProviderGenerateArgs, ProviderRequestCapacity, ProviderResponse, ProviderUsage, Effort } from "./types.ts";
1
+ import type { ChatMessage, PromptTokenMeasurement, Provider, ProviderCostNormalizer, ProviderGenerateArgs, ProviderRequestCapacity, ProviderResponse, ProviderUsage, Effort, InputModality } from "./types.ts";
2
2
  import type { ProviderCost } from "@plurnk/plurnk-contracts";
3
3
  import type { JSONValue } from "ai";
4
4
  import type { EffortSetting, ReasoningResponseStyle } from "./env.ts";
5
- import type { InputModality } from "./types.ts";
6
5
  import type { LanguageModelSource } from "./aiSdkTransport.ts";
7
6
  import type { ExtensionAttribution, ExtensionAttributionContext } from "@plurnk/plurnk-meta";
8
7
  import type RequestFields from "./RequestFields.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"AiSdkProvider.d.ts","sourceRoot":"","sources":["../src/AiSdkProvider.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAmB,sBAAsB,EAAE,QAAQ,EAAmB,sBAAsB,EAAE,oBAAoB,EAA6B,uBAAuB,EAA6B,gBAAgB,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACxR,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,IAAI,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAM/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAQ7F,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAG9D,MAAM,MAAM,aAAa,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAwBpD,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;AAI3E,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAE/C,MAAM,MAAM,aAAa,GACnB;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7D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,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA2f9K;CAEJ"}
@@ -5,7 +5,7 @@
5
5
  // Composition, not inheritance: an official AI SDK language model supplies the
6
6
  // ordinary vendor protocol. The compatible URL path serves only PLURNK
7
7
  // extensions and local endpoint probes the SDK cannot represent.
8
- import { EFFORTS, MAX_TIMER_MS } from "@plurnk/plurnk-contracts";
8
+ import { EFFORTS, MAX_TIMER_MS, isRecord, isSafeInteger } from "@plurnk/plurnk-contracts";
9
9
  import { UnsupportedEffortError } from "./types.js";
10
10
  import { executeAiSdkModel, executeOpenAICompatible, transportFailureOutputObserved, transportFailureEvidence } from "./aiSdkTransport.js";
11
11
  import { prepareRetries } from "ai/internal";
@@ -325,7 +325,8 @@ export default class AiSdkProvider {
325
325
  });
326
326
  if (!res.ok)
327
327
  throw new Error(`${this.#source}: tokenize endpoint returned ${res.status}`);
328
- const { tokens } = (await res.json());
328
+ const body = await res.json();
329
+ const tokens = isRecord(body) ? body.tokens : undefined;
329
330
  if (!Array.isArray(tokens) || !tokens.every((t) => typeof t === "number")) {
330
331
  throw new Error(`${this.#source}: tokenize endpoint returned no token array`);
331
332
  }
@@ -394,12 +395,13 @@ export default class AiSdkProvider {
394
395
  return estimatePromptTokens(messages, `llama-server input-token endpoint returned HTTP ${response.status}`);
395
396
  }
396
397
  const body = await response.json();
397
- if (!Number.isInteger(body.input_tokens) || body.input_tokens < 0) {
398
+ const inputTokens = isRecord(body) ? body.input_tokens : undefined;
399
+ if (!isSafeInteger(inputTokens) || inputTokens < 0) {
398
400
  return estimatePromptTokens(messages, "llama-server input-token endpoint returned no non-negative integer input_tokens");
399
401
  }
400
402
  return {
401
403
  kind: "exact",
402
- tokens: body.input_tokens,
404
+ tokens: inputTokens,
403
405
  source: "llama-server:/v1/chat/completions/input_tokens",
404
406
  };
405
407
  }
@@ -623,6 +625,7 @@ export default class AiSdkProvider {
623
625
  fetch,
624
626
  headers: requestHeaders,
625
627
  providerOptions: this.#requestBody.requestProviderOptions(workerId, nativeReasoningBudget, this.#requestFields?.namespace === undefined ? undefined : {
628
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- request fields are JSON: parsed from the operator's settings, composed from strings and numbers
626
629
  [this.#requestFields.namespace]: this.#requestFields.body(this.#effort.mode, null, capacity.reasoningBudget),
627
630
  }),
628
631
  systemProviderOptions: this.#systemCacheProviderOptions,
@@ -825,7 +828,7 @@ export default class AiSdkProvider {
825
828
  kind: "output_unaccounted",
826
829
  level: "warn",
827
830
  message: `${usage.outputTokens} output tokens billed; ${visible} visible across content and reasoning.`,
828
- position: [...raw.content].length,
831
+ position: Array.from(raw.content).length,
829
832
  });
830
833
  }
831
834
  }