@plurnk/plurnk-providers 1.25.0 → 1.27.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 (51) hide show
  1. package/.env.defaults +4 -11
  2. package/README.md +6 -2
  3. package/SPEC.md +70 -41
  4. package/dist/AiSdkProvider.d.ts +0 -3
  5. package/dist/AiSdkProvider.d.ts.map +1 -1
  6. package/dist/AiSdkProvider.js +26 -46
  7. package/dist/AiSdkProvider.js.map +1 -1
  8. package/dist/accounting.d.ts.map +1 -1
  9. package/dist/accounting.js +39 -46
  10. package/dist/accounting.js.map +1 -1
  11. package/dist/aiSdkTransport.d.ts +5 -8
  12. package/dist/aiSdkTransport.d.ts.map +1 -1
  13. package/dist/aiSdkTransport.js +99 -176
  14. package/dist/aiSdkTransport.js.map +1 -1
  15. package/dist/catalogProvider.d.ts.map +1 -1
  16. package/dist/catalogProvider.js +0 -3
  17. package/dist/catalogProvider.js.map +1 -1
  18. package/dist/compatibleProvider.d.ts.map +1 -1
  19. package/dist/compatibleProvider.js +0 -3
  20. package/dist/compatibleProvider.js.map +1 -1
  21. package/dist/cost.d.ts.map +1 -1
  22. package/dist/cost.js +4 -5
  23. package/dist/cost.js.map +1 -1
  24. package/dist/env.d.ts.map +1 -1
  25. package/dist/env.js +0 -3
  26. package/dist/env.js.map +1 -1
  27. package/dist/errors.d.ts +2 -4
  28. package/dist/errors.d.ts.map +1 -1
  29. package/dist/errors.js +3 -32
  30. package/dist/errors.js.map +1 -1
  31. package/dist/native-tools.d.ts +5 -0
  32. package/dist/native-tools.d.ts.map +1 -0
  33. package/dist/native-tools.js +18 -0
  34. package/dist/native-tools.js.map +1 -0
  35. package/dist/ollama.d.ts.map +1 -1
  36. package/dist/ollama.js +2 -0
  37. package/dist/ollama.js.map +1 -1
  38. package/dist/providerError.d.ts +1 -1
  39. package/dist/providerError.d.ts.map +1 -1
  40. package/dist/providerError.js +1 -3
  41. package/dist/providerError.js.map +1 -1
  42. package/dist/sdkModels.d.ts.map +1 -1
  43. package/dist/sdkModels.js +11 -9
  44. package/dist/sdkModels.js.map +1 -1
  45. package/dist/types.d.ts +1 -1
  46. package/dist/types.d.ts.map +1 -1
  47. package/package.json +5 -5
  48. package/dist/RepeatedLine.d.ts +0 -9
  49. package/dist/RepeatedLine.d.ts.map +0 -1
  50. package/dist/RepeatedLine.js +0 -27
  51. package/dist/RepeatedLine.js.map +0 -1
package/.env.defaults CHANGED
@@ -99,21 +99,14 @@ PLURNK_PROVIDERS_CACHE_WRITE_POLICY=stable-system
99
99
  # Supported keys: input, output, reasoning, cacheRead, cacheWrite. This is estimation, not billing truth.
100
100
  # PLURNK_PROVIDERS_COST=input=0.22,output=0.66,reasoning=0.66,cacheRead=0.007
101
101
 
102
- # --- Connectivity (milliseconds; each deadline accepts 0 = off) ---
102
+ # --- Connectivity (milliseconds; 0 = off) ---
103
103
  # Logical generation deadline, including admission queues, physical attempts and retry delays.
104
104
  PLURNK_PROVIDERS_OPERATION_TIMEOUT=2700000
105
- # Deadline per physical generation attempt; a streamed attempt is bounded only until content flows.
105
+ # Discovery and tokenizer HTTP requests only; never a generation deadline.
106
106
  PLURNK_PROVIDERS_FETCH_TIMEOUT=600000
107
- # Wait from dispatch (after admission, before response headers) to first semantic content;
108
- # metadata/empty deltas do not count.
109
- PLURNK_PROVIDERS_FIRST_CONTENT_TIMEOUT=180000
110
- # Maximum silence between semantic content chunks after content begins.
111
- PLURNK_PROVIDERS_STREAM_IDLE_TIMEOUT=120000
112
- # A line of 16+ characters streamed this many times stops the response as a repetition; 0 = off.
113
- PLURNK_PROVIDERS_REPEATED_LINE_LIMIT=32
114
107
  # A response billed for this many more output tokens than it streamed characters (text and reasoning)
115
- # never delivered its output; it fails as output_dropped and is re-issued (a tool-call finish always
116
- # does). Reasoning billed but not streamed is exempt. 0 = off.
108
+ # never delivered its output; it fails as output_dropped. Native tool calls are retained with a
109
+ # warning, not retried for this reason. Reasoning billed but not streamed is exempt. 0 = off.
117
110
  PLURNK_PROVIDERS_DROPPED_OUTPUT_TOKENS=32
118
111
  # Retries for 429, Retry-After, or X-Should-Retry:true; 0 = none. Other failures return immediately
119
112
  # to Core's separate recovery window. Retry-After takes precedence over backoff.
package/README.md CHANGED
@@ -12,6 +12,9 @@ Ordinary provider behavior is intentionally not reimplemented here:
12
12
  - PLURNK owns aliases, generation envelopes, normalized usage and errors,
13
13
  evidence capture, first-party metadata, and local endpoint capabilities.
14
14
 
15
+ Native tool calling is explicitly disabled through each protocol's standard
16
+ controls; PLURNK operations travel as text ({§provider-native-tools-disabled}).
17
+
15
18
  See [SPEC.md](SPEC.md) for the contract, [the model reference](docs/models.md)
16
19
  for what a model is told about routes and generation, and
17
20
  [.env.defaults](.env.defaults) for every knob.
@@ -188,9 +191,10 @@ opt-in for endpoints that emit a leading `<think>` envelope, not a reasoning swi
188
191
  | Concern | Boundary |
189
192
  | --- | --- |
190
193
  | Inference concurrency | Optional per-endpoint, process-local admission; queued calls remain cancellable. The default is unrestricted ({§provider-inference-admission}). |
191
- | Attempt, first-content, idle deadlines | Provider transport; a timeout surfaces a failure, not a fabricated response. |
194
+ | Generation deadline | One whole-call allowance across queueing, requests and retries; caller cancellation still applies. No first-content or inter-chunk cutoff. |
195
+ | Discovery/tokenizer HTTP | Separate non-generation fetch bound; does not limit inference. |
192
196
  | Provider-directed waits | Bounded retries honor `Retry-After`; other recoverable failures return to Core. |
193
- | Loop recovery | Core reissues within its recovery window, then parks for a prompt or wake. |
197
+ | Loop recovery | Core reissues within its recovery window, then parks attended loops or concludes unattended loops on the failure. |
194
198
  | Cache affinity | Stable Worker identity through documented provider controls; not a cache-hit guarantee. |
195
199
  | Explicit cache writes | Separate policy on supported routes; can affect billing. |
196
200
  | Service tier | Explicit route choice that may change price and availability. |
package/SPEC.md CHANGED
@@ -167,6 +167,25 @@ message count, grammar presence, worker identity, or another incidental request
167
167
  shape. The signal never enters model-facing messages. Generic
168
168
  provider callers MAY omit it; Core supplies it for every model call.
169
169
 
170
+ §provider-native-tools-disabled Generation requests declare no native tools and
171
+ select the SDK's portable `none` tool choice, for emissions and BARE alike.
172
+ The built-in transports preserve that intent after SDK serialization:
173
+
174
+ | Protocol | No-tool wire representation |
175
+ | --- | --- |
176
+ | OpenAI-compatible Chat Completions and Responses | `tools: []`, `tool_choice: "none"` |
177
+ | Anthropic Messages | `tools: []`, `tool_choice: {"type":"none"}` |
178
+ | Gemini GenerateContent | `tools: []`, `toolConfig: {"functionCallingConfig":{"mode":"NONE"}}` |
179
+ | Bedrock Converse | No tool configuration; the protocol has no `none` choice. |
180
+ | Installed SDK provider plugins | Portable `none` intent; the plugin owns its wire projection. |
181
+
182
+ This is a text-generation contract, not provider/model tuning or prompt
183
+ teaching. Callers cannot supply tools or override the choice through request
184
+ extensions. Do not add deprecated function-call fields, dummy tools, or fields
185
+ from another protocol. The opt-out neither constrains arbitrary prose nor
186
+ proves that an endpoint honors it; unexpected native calls retain their full
187
+ evidence and follow {§provider-native-tool-calls}.
188
+
170
189
  A successful return carries the model's raw content and reasoning, normalized
171
190
  finish reason, model identity, its ordered {§provider-request-accounting}, the
172
191
  request's `ProviderRequestCapacity`, opaque evidence, optional metadata, and
@@ -175,6 +194,12 @@ accounting evidence. The provider transports and observes model
175
194
  output; it never retries, discards, or repairs an otherwise completed exchange
176
195
  because PLURNK grammar did not accept it.
177
196
 
197
+ §provider-generation-completion Stream consumption follows the provider's
198
+ completion boundary, subject to caller cancellation and configured deadlines.
199
+ Repeated content or reasoning does not interrupt a response or request another
200
+ generation. Preserve the complete response, its finish reason, and trailing
201
+ usage and charge evidence before returning it to the consumer.
202
+
178
203
  §provider-request-observer When a consumer supplies the request observer, the
179
204
  adapter opens one durable identity through it immediately before each physical
180
205
  I/O and settles that identity with the resulting
@@ -184,6 +209,15 @@ observer is a durability sink, not an alternate evidence representation; the
184
209
  same ordered records remain on the final generation result or
185
210
  error.
186
211
 
212
+ The adapter also settles {§provider-request-evidence}. A successful request
213
+ retains its normalized transport response; a failed request retains received
214
+ SDK raw chunks (or the error response body), partial content and reasoning,
215
+ available response identity/headers, usage/charge evidence, and its error and
216
+ cancellation cause. Failure capture is independent of successful raw-body
217
+ capture. These are the SDK's received values, not a claim of byte-for-byte
218
+ HTTP capture. Settlement is durable before returning the failure; a process
219
+ crash before settlement leaves a pending request, not an invented response.
220
+
187
221
  §provider-reasoning-observer When a consumer supplies `observeReasoning`, the
188
222
  provider synchronously delivers each exact, ordered, nonempty readable-reasoning
189
223
  delta as it becomes available. A transport without incremental reasoning emits
@@ -328,13 +362,10 @@ Models.dev identifies the route's controls but not a provider-specific toggle
328
362
  or budget field name. The adapter supplies that last-mile mechanism; it never
329
363
  invents a cataloged effort value.
330
364
 
331
- §provider-readable-reasoning **Reasoning is verbatim or it is nothing.** A route
332
- either returns the model's own reasoning text or it returns none; the service
333
- carries no projection that requests, unwraps, or reconstitutes a summarized,
334
- redacted, or otherwise abridged reasoning stream. A route that bills reasoning
335
- tokens and returns no reasoning text is a route whose `reasoning://` is empty,
336
- and that is reported rather than compensated for. Models.dev's reasoning bit
337
- remains capability metadata.
365
+ §provider-readable-reasoning Route-owned options may request exposed reasoning
366
+ text. Normalization follows {§provider-open-reasoning}; Models.dev's reasoning
367
+ bit is capability metadata, not a statement about returned text's fidelity.
368
+ Billing without exposed text does not create a reasoning source.
338
369
 
339
370
  §provider-sdk-warning AI SDK compatibility, unsupported-feature, deprecation,
340
371
  and other call warnings become source-attributed provider Notices on the
@@ -449,7 +480,7 @@ The universal groups are:
449
480
  - reasoning activation and optional explicit budget;
450
481
  - explicit reasoning response-content style;
451
482
  - decode tuning;
452
- - operation, physical-attempt, first-content, stream-idle, retry, and probe budgets;
483
+ - whole-call generation, discovery/tokenizer HTTP, retry, and probe budgets;
453
484
  - local GBNF and llama-server capability pins;
454
485
  - context-window and generation-envelope overrides;
455
486
  - provider-documented cache affinity and explicit cache-write policy;
@@ -646,16 +677,6 @@ reasoning enclosure only after preserving grammar evidence. Process-wide
646
677
  llama-server flags are fallback server configuration, not part of the PLURNK
647
678
  contract and need not be synchronized with an alias.
648
679
 
649
- §repetition-stop **A response that repeats itself is stopped.** A degenerate model can stream one line
650
- without end; content keeps arriving, so no silence deadline fires, and the call runs to its output
651
- allowance. The transport counts the complete lines of each streamed channel, text and reasoning, and
652
- when one line of 16 or more characters has appeared `PLURNK_PROVIDERS_REPEATED_LINE_LIMIT` times it stops
653
- reading: the stream is cancelled, the physical request settles with whatever usage the chunks carried,
654
- and the call fails as `repetition` (422, not retryable) carrying the partial attempt and the sentence
655
- "The response repeated one line N times and was stopped: `<line>`". The consumer reads it as an invalid
656
- emission, never as a provider failure to recover. Measured: a granite-4.2-8b run repeated one line 358
657
- times across 45,875 tokens and 9 min 42 s; a limit of 32 stops it 14.6% of the way in (#876).
658
-
659
680
  §llama-reasoning-request The allowance is cumulative across the complete response. Opening a second or
660
681
  later reasoning block does not replenish it. Template parsing, the reasoning
661
682
  sampler, normalized usage, and the returned reasoning channel MUST agree on that
@@ -775,29 +796,30 @@ unconfigured. Their grammar protection remains at {§provider-grammar-transport}
775
796
  §provider-connectivity The provider adapter owns one attempt scheduler around
776
797
  the complete generation exchange; SDK-internal retries are disabled.
777
798
  `PLURNK_PROVIDERS_RETRY_ATTEMPTS=N` permits at most `N + 1` physical requests.
778
- The layers are independent and a configured value of zero disables only that
779
- deadline:
799
+ Generation has one configurable deadline; `0` disables it. Caller cancellation
800
+ and the caller's task allowance remain authoritative. Initial silence, a pause
801
+ between chunks, and buffered output do not acquire separate deadlines.
780
802
 
781
803
  | Layer | Operator knob | Boundary | Expiry |
782
804
  | --- | --- | --- | --- |
783
805
  | Operation | `PLURNK_PROVIDERS_OPERATION_TIMEOUT` | Complete logical call, including admission queueing, every attempt and retry delay. | Final `deadline_exceeded` Problem at 504 with `timeoutPhase=operation`; not retried inside this operation. Consumer recovery is separate. Enforced as a race, not only the advisory signal, so a wedged transport that never observes the abort cannot hang the loop past the deadline (#505); a well-behaved transport unwinds within a short grace and settles its own attempt evidence first. |
784
- | Attempt | `PLURNK_PROVIDERS_FETCH_TIMEOUT` | One physical generation request. A non-streamed request is bounded through response consumption; a streamed one only until its first semantic content. After content begins, stream-idle bounds silence and the operation deadline still bounds the whole call. | Surfaced `network_failure` with `timeoutPhase=attempt`; never transport-retried (#479) — the consumer's recovery owns re-issue. |
785
- | First content | `PLURNK_PROVIDERS_FIRST_CONTENT_TIMEOUT` | Dispatch through first semantic model content ({§provider-first-content-at-dispatch}); metadata, empty deltas, and transport activity do not satisfy it. | Surfaced `network_failure` with `timeoutPhase=first_content`; never transport-retried (#479). |
786
- | Stream idle | `PLURNK_PROVIDERS_STREAM_IDLE_TIMEOUT` | Silence between semantic content chunks after content begins. | Surfaced `network_failure` with `timeoutPhase=stream_idle`; never transport-retried (#479). |
787
- | Repeated line | `PLURNK_PROVIDERS_REPEATED_LINE_LIMIT` | A streamed line of 16 or more characters repeated this many times; `0` disables. | Stopped as `repetition` ({§repetition-stop}); never transport-retried. |
788
-
789
- §provider-first-content-at-dispatch The first-content deadline is armed when the
790
- admitted attempt is dispatched, before response headers, so an endpoint that accepts
791
- the request and never answers fails at `timeoutPhase=first_content` instead of holding
792
- the attempt for the whole attempt deadline. It still begins only after admission
793
- ({§provider-inference-admission}).
806
+ | Discovery/tokenizer HTTP | `PLURNK_PROVIDERS_FETCH_TIMEOUT` | Non-generation endpoint discovery and tokenizer requests only. | Ordinary HTTP failure at the owning discovery or measurement boundary. Never interrupts generation. |
794
807
 
795
808
  Settled calls remove their deadline timers and cancellation subscriptions.
796
809
 
797
810
  Caller cancellation spans the operation and preserves the caller's reason.
811
+
812
+ §provider-cancellation-evidence Received usage/charge evidence and available
813
+ response identity survive cancellation and deadline normalization through
814
+ physical-request settlement, independently of optional raw-body capture.
815
+ This includes SDK abort events and non-Error cancellation reasons. Concurrent
816
+ requests keep independent evidence even when cancelled by the same scope.
817
+ Absent evidence remains absent; stopping a request neither invents usage nor
818
+ retries generation to obtain it. Partial output is never a completed response.
819
+
798
820
  A 2xx exchange whose body cannot be processed (a provider invalid-response)
799
821
  classifies as the non-retryable 502 on the first failure unless an explicit
800
- `x-should-retry` directive says otherwise (#479). Inner deadline failures surface on the first failure; when a
822
+ `x-should-retry` directive says otherwise (#479). When a
801
823
  directive-driven retry sequence exhausts, `attempts` and `retryExhausted`
802
824
  are added and the classification is final. Every admitted physical attempt opens
803
825
  and settles exactly one ordered {§provider-request-accounting} record, including
@@ -821,6 +843,14 @@ ordinary 5xx surface on the first failure as consumer-recoverable kinds; one
821
843
  retry authority — the consumer's own provider-recovery machinery — owns
822
844
  re-issue, backoff, and park above the transport.
823
845
 
846
+ §provider-native-tool-calls A response with native tool-call data, or a
847
+ `tool_calls` finish, preserves its text, reasoning, structured wire evidence,
848
+ finish reason and accounting and emits one provider warning. It is not a
849
+ transport failure and does not trigger provider recovery. The adapter executes
850
+ no call and invents no textual operation; the consumer owns admission and
851
+ no-operation handling. Text-only missing-output checks do not apply because
852
+ the billed output includes structured calls.
853
+
824
854
  §provider-output-dropped **A completed exchange whose own evidence proves its
825
855
  text never arrived is `output_dropped`**, a 502 carrying the complete response as
826
856
  `error.attempt` and `stage: "provider-response"`; it is never admitted as an empty or
@@ -828,7 +858,6 @@ truncated turn, and the consumer re-issues it ({§provider-retryable-truth}):
828
858
 
829
859
  | Evidence | Detail | Facts |
830
860
  | --- | --- | --- |
831
- | `finish_reason` `tool_calls` (Plurnk never declares tools) | `The provider ended the response with tool calls although no tools were declared (N native tool call(s)); the response text was not delivered as text.` | `toolCallCount` |
832
861
  | Billed output tokens exceed the code points streamed across every channel — text and reasoning, before projection — by at least `PLURNK_PROVIDERS_DROPPED_OUTPUT_TOKENS` (`0` disables; an output token decodes to at least one character) | `The provider billed T output tokens but streamed C characters of text and reasoning; at least T−C tokens of output never arrived.` | `billedOutputTokens`, `streamedCharacters`, `droppedOutputTokens` |
833
862
 
834
863
  The token rule needs a billed output count, and it does not apply when the response bills
@@ -920,14 +949,14 @@ available; catalog estimation requires all quantities its rates need, otherwise
920
949
  cost is `unknown`. Covered by `usage.test.ts`, `aiSdkTransport.test.ts`, and
921
950
  `AiSdkProvider.test.ts`.
922
951
 
923
- §provider-open-reasoning **Plurnk reads the model's own reasoning.** The service is
924
- built for open models, whose reasoning arrives as text it can read, address at
925
- `reasoning://`, and let a model curate with NOTE. Encrypted, redacted and
926
- summarized reasoning carry no text to read, so the service does not collect them:
927
- there is no encrypted-reasoning carrier, no summary unwrapping, and no request
928
- option that asks for either. A route that withholds its reasoning is not refused
929
- and not compensated for — its `reasoning://` is simply empty, and the reasoning
930
- tokens it bills are visible in accounting as spend with nothing behind it.
952
+ §provider-open-reasoning **Plurnk requires endpoints with open, verbatim reasoning.**
953
+ The adapter retains the reasoning text its transport exposes; fidelity is not
954
+ inferred from a model name or catalog flag. Hidden or summarized reasoning is not
955
+ a supported substitute, and encrypted or redacted payloads are never reconstructed
956
+ into text. A single response without reasoning does not establish endpoint
957
+ incapability: its `reasoning://` reads empty, while billed reasoning tokens remain
958
+ visible in accounting. Exposed operations follow {§reasoning-operations}; no
959
+ compatibility teaching or alternate admission mode is selected for a route.
931
960
  Unrecognized detail shapes are omitted at this normalization boundary. Core
932
961
  may preserve normalized items as forensic evidence, but a client protocol must
933
962
  correlate them to an entity it actually created rather than reusing `id`.
@@ -984,7 +1013,7 @@ alias scoping. Zero, other negative values and non-integers are invalid.
984
1013
  | Admission | FIFO among live waiters. The lease begins before the physical request observer and ends after the complete response or transport failure settles, including streamed bodies. |
985
1014
  | Cancellation | A queued abort removes that waiter and preserves the caller's reason. It opens no physical request or accounting row. In-flight cancellation signals the transport; capacity is released when that attempt unwinds. A transport still running despite abort does not authorize exceeding the limit. |
986
1015
  | Retries | Backoff holds no lease. Each retry rejoins admission as a new physical attempt. |
987
- | Deadlines | The existing operation deadline includes queueing. Attempt, first-content and stream-idle deadlines begin only after admission; queued work is not a stalled stream. |
1016
+ | Deadline | The whole-call operation deadline includes queueing, every physical attempt and retry wait. Transport adds no generation deadline. |
988
1017
  | Scope | Workers, tools, messages, waits, token measurement and endpoint discovery are not serialized by inference admission. Independent endpoints progress independently. No cross-process or machine-wide capacity guarantee is implied. |
989
1018
 
990
1019
  Admission neither changes worker lifecycle nor selects another model or endpoint.
@@ -28,9 +28,6 @@ export type AiSdkProviderConfig = {
28
28
  attributions?: (context: PluginAttributionContext) => PluginAttribution;
29
29
  fetchTimeoutMs: number;
30
30
  operationTimeoutMs: number;
31
- firstContentTimeoutMs: number;
32
- streamIdleTimeoutMs?: number;
33
- repeatedLineLimit?: number;
34
31
  droppedOutputTokens?: number;
35
32
  headers?: Record<string, string>;
36
33
  fetch?: ProviderFetch;
@@ -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,aAAa,EAAE,MAAM,IAAI,CAAC;AAMxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAQvF,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAC;AAE9D,MAAM,MAAM,aAAa,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAwBpD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GA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#languageModel;
90
90
  #fetchTimeoutMs;
91
91
  #operationTimeoutMs;
92
- #firstContentTimeoutMs;
93
- #streamIdleTimeoutMs;
94
- #repeatedLineLimit;
95
92
  #droppedOutputTokens;
96
93
  #headers;
97
94
  #fetch;
@@ -156,8 +153,6 @@ export default class AiSdkProvider {
156
153
  for (const [name, value] of [
157
154
  ["fetchTimeoutMs", config.fetchTimeoutMs],
158
155
  ["operationTimeoutMs", config.operationTimeoutMs],
159
- ["firstContentTimeoutMs", config.firstContentTimeoutMs],
160
- ["streamIdleTimeoutMs", config.streamIdleTimeoutMs],
161
156
  ]) {
162
157
  if (value !== undefined && (!Number.isInteger(value) || value < 0 || value > MAX_TIMER_MS)) {
163
158
  throw new Error(`${config.source ?? "provider"}: ${name} must be an integer from 0 through ${MAX_TIMER_MS} milliseconds`);
@@ -165,9 +160,6 @@ export default class AiSdkProvider {
165
160
  }
166
161
  this.#fetchTimeoutMs = config.fetchTimeoutMs;
167
162
  this.#operationTimeoutMs = config.operationTimeoutMs;
168
- this.#firstContentTimeoutMs = config.firstContentTimeoutMs;
169
- this.#streamIdleTimeoutMs = config.streamIdleTimeoutMs;
170
- this.#repeatedLineLimit = config.repeatedLineLimit ?? 0;
171
163
  this.#droppedOutputTokens = config.droppedOutputTokens ?? 0;
172
164
  this.#headers = config.headers ?? {};
173
165
  this.#fetch = config.fetch ?? ((input, init) => globalThis.fetch(input, init));
@@ -500,12 +492,13 @@ export default class AiSdkProvider {
500
492
  let structuredReasoning = false;
501
493
  const envelopes = preserveGrammarSentence ? LeadingReasoning.TEMPLATE
502
494
  : this.#reasoningResponseStyle === "think-tags" ? LeadingReasoning.THINK : [];
503
- const liveProjection = emitReasoning !== undefined && envelopes.length > 0 ? new LeadingReasoning(envelopes) : undefined;
504
- const observeRequestReasoning = emitReasoning === undefined
495
+ const observing = emitReasoning !== undefined;
496
+ const liveProjection = observing && envelopes.length > 0 ? new LeadingReasoning(envelopes) : undefined;
497
+ const observeRequestReasoning = !observing
505
498
  ? undefined
506
499
  : (delta) => {
507
500
  requestReasoningStream += delta;
508
- emitReasoning(delta);
501
+ emitReasoning?.(delta);
509
502
  };
510
503
  const observers = {
511
504
  ...(observeRequestReasoning === undefined ? {} : { observeReasoning: (delta) => {
@@ -513,8 +506,9 @@ export default class AiSdkProvider {
513
506
  observeRequestReasoning(delta);
514
507
  } }),
515
508
  ...(liveProjection === undefined ? {} : { observeText: (delta) => {
516
- if (!structuredReasoning)
509
+ if (!structuredReasoning) {
517
510
  observeRequestReasoning(liveProjection.push(delta));
511
+ }
518
512
  } }),
519
513
  };
520
514
  let settle;
@@ -527,7 +521,7 @@ export default class AiSdkProvider {
527
521
  catch (cause) {
528
522
  throw new ProviderRequestObserverError(cause);
529
523
  }
530
- const settleAccounting = async (outcome, usage, evidence, status) => {
524
+ const settleAccounting = async (outcome, usage, evidence, forensicEvidence, status) => {
531
525
  let requestAccounting;
532
526
  let normalizationFailure;
533
527
  try {
@@ -556,7 +550,7 @@ export default class AiSdkProvider {
556
550
  }
557
551
  accounting.push(requestAccounting);
558
552
  try {
559
- await settle?.(requestAccounting);
553
+ await settle?.(requestAccounting, forensicEvidence);
560
554
  }
561
555
  catch (cause) {
562
556
  throw new ProviderRequestObserverError(cause);
@@ -577,10 +571,6 @@ export default class AiSdkProvider {
577
571
  messages,
578
572
  signal: operationSignal,
579
573
  fetch: this.#fetch,
580
- fetchTimeoutMs: this.#fetchTimeoutMs,
581
- firstContentTimeoutMs: this.#firstContentTimeoutMs,
582
- streamIdleTimeoutMs: this.#streamIdleTimeoutMs,
583
- repeatedLineLimit: this.#repeatedLineLimit,
584
574
  streaming: this.#streaming,
585
575
  captureRawBody: this.#rawBody,
586
576
  ...observers,
@@ -594,10 +584,6 @@ export default class AiSdkProvider {
594
584
  systemProviderOptions: this.#systemCacheProviderOptions,
595
585
  messages,
596
586
  signal: operationSignal,
597
- fetchTimeoutMs: this.#fetchTimeoutMs,
598
- firstContentTimeoutMs: this.#firstContentTimeoutMs,
599
- streamIdleTimeoutMs: this.#streamIdleTimeoutMs,
600
- repeatedLineLimit: this.#repeatedLineLimit,
601
587
  streaming: this.#streaming,
602
588
  captureRawBody: this.#rawBody,
603
589
  ...observers,
@@ -626,13 +612,13 @@ export default class AiSdkProvider {
626
612
  if (transportFailureOutputObserved(error))
627
613
  recoveredAfterOutput = true;
628
614
  const failure = transportFailureEvidence(error);
629
- await settleAccounting("error", failure.usage, failure.chargeEvidence, failure.status);
615
+ await settleAccounting("error", failure.usage, failure.chargeEvidence, failure, failure.status);
630
616
  throw error;
631
617
  }
632
618
  if (!structuredReasoning && liveProjection !== undefined)
633
619
  observeRequestReasoning(liveProjection.finish());
634
620
  successfulReasoningStream = requestReasoningStream;
635
- await settleAccounting("response", response.usage, response.chargeEvidence);
621
+ await settleAccounting("response", response.usage, response.chargeEvidence, response);
636
622
  return response;
637
623
  };
638
624
  const executeRequest = async () => {
@@ -665,9 +651,9 @@ export default class AiSdkProvider {
665
651
  || err instanceof ProviderReasoningObserverError)
666
652
  throw err.cause;
667
653
  if (signal?.aborted)
668
- throw err;
654
+ throw signal.reason;
669
655
  if (operationTimeout?.aborted) {
670
- const timeout = new ProviderTimeoutError("operation", this.#operationTimeoutMs, err);
656
+ const timeout = new ProviderTimeoutError(this.#operationTimeoutMs, err);
671
657
  throw new ProviderError(this.#source, "deadline_exceeded", timeout.message, {
672
658
  status: 504,
673
659
  cause: timeout,
@@ -749,6 +735,16 @@ export default class AiSdkProvider {
749
735
  emitReasoning(missing);
750
736
  }
751
737
  let notices;
738
+ const nativeCalls = raw.finishReason === "tool_calls" || raw.wire.toolCalls.length > 0;
739
+ if (nativeCalls) {
740
+ (notices ??= []).push({
741
+ source: this.#source,
742
+ kind: "provider_warning",
743
+ level: "warn",
744
+ message: "The response included native tool calls, but no tools were declared.",
745
+ position: null,
746
+ });
747
+ }
752
748
  if (recoveredAfterOutput && accounting.at(-1)?.outcome === "response") {
753
749
  (notices ??= []).push({
754
750
  source: this.#source,
@@ -838,16 +834,6 @@ export default class AiSdkProvider {
838
834
  },
839
835
  });
840
836
  }
841
- if (raw.finishReason === "repetition") {
842
- // {§repetition-stop}: the stream was stopped at a repeated line; the partial attempt is evidence, and the
843
- // consumer reads it as an invalid emission, never as a provider failure to recover.
844
- const attempt = {
845
- assistant: { ...assistant, finishReason: raw.finishReason },
846
- ...evidence,
847
- };
848
- const { line, count } = raw.repetition;
849
- throw new ProviderError(this.#source, "repetition", `The response repeated one line ${count} times and was stopped: \`${line}\``, { attempt, accounting, extensions: { stage: "provider-response", finishReason: "repetition", repeatedLine: line, repeatedCount: count } });
850
- }
851
837
  if (raw.finishReason === "resource_interrupted") {
852
838
  const attempt = {
853
839
  assistant: { ...assistant, finishReason: raw.finishReason },
@@ -865,7 +851,8 @@ export default class AiSdkProvider {
865
851
  },
866
852
  });
867
853
  }
868
- const dropped = this.#droppedOutput(raw, streamedCharacters);
854
+ // {§provider-native-tool-calls} Structured output is not missing text.
855
+ const dropped = nativeCalls ? null : this.#droppedOutput(raw, streamedCharacters);
869
856
  if (dropped !== null) {
870
857
  const attempt = {
871
858
  assistant: { ...assistant, finishReason: raw.finishReason },
@@ -888,17 +875,10 @@ export default class AiSdkProvider {
888
875
  };
889
876
  }
890
877
  // {§provider-output-dropped} A completed exchange whose own evidence proves its output never arrived:
891
- // a tool-call finish on a request that declares no tools, or billed output tokens exceeding every
892
- // streamed character (text and reasoning together) by the configured margin — an output token decodes
878
+ // billed output tokens exceeding every streamed character (text and reasoning together) by the
879
+ // configured margin — an output token decodes
893
880
  // to at least one character. Reasoning billed but streamed nowhere is hidden reasoning, not a drop.
894
881
  #droppedOutput(raw, streamedCharacters) {
895
- if (raw.finishReason === "tool_calls") {
896
- const toolCallCount = raw.wire.toolCalls.length;
897
- return {
898
- message: `The provider ended the response with tool calls although no tools were declared (${toolCallCount} native tool call${toolCallCount === 1 ? "" : "s"}); the response text was not delivered as text.`,
899
- facts: { toolCallCount },
900
- };
901
- }
902
882
  const billedOutputTokens = raw.usage?.outputTokens;
903
883
  if (this.#droppedOutputTokens === 0 || billedOutputTokens === undefined)
904
884
  return null;