fascicle 0.9.10 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.10.0 — 2026-08-05
4
+
5
+ ### Added
6
+
7
+ - **`provider_reported` now carries what an `ai_sdk` provider reports, for every provider on that transport.** The AI SDK returns provider-volunteered detail on `providerMetadata` (Bedrock's guardrail trace, Anthropic's cache breakdown, OpenAI's service tier), already keyed by provider name. The transport read `text`, `toolCalls`, `finishReason`, and `usage` off the result and dropped the rest, so `GenerateResult.provider_reported` was structurally unreachable for every ai_sdk provider: only `claude_cli` ever populated it. The neutral `TurnResult` gains an optional `provider_reported`, the transport fills it from `providerMetadata` on both the `generateText` result and the streamed step-finish (so a streamed run and a plain run of the same call still report identically), the loop copies it onto `steps[i].provider_reported`, and `generate` folds the last reporting step into the call-level field. Keys and payloads ride through untranslated, so `provider_reported.bedrock.trace` needs no translation layer and a custom `ai_sdk` provider is served without per-provider code; a `native` adapter fills the same field from its own `invoke_turn`. Finish-reason mapping is untouched: a guardrail intervention still surfaces as `content_filter`, now with the trace beside it. This closes a real blind spot for Bedrock guardrails configured with a PII action of `NONE`, which detect and report without rewriting: the model output is byte-identical whether such a guardrail is attached and detecting or absent entirely, so the trace was the only in-process evidence it ran. `bedrock_guardrail_wire.test.ts` pins the round trip against the real peer over a stubbed fetch, and `provider_reported.test.ts` pins pass-through, stream parity, and the multi-step semantics.
8
+
9
+ ### Fixed
10
+
11
+ - **`docs/cli.md` named a `provider_reported` path that does not exist.** The multi-turn recipe said to capture `result.provider_reported.session_id`, but the adapter reports under a provider-name key, so the value has always been at `result.provider_reported.claude_cli.session_id`. Following the documented path yielded `undefined` and a fresh session on every call.
12
+
13
+ ### Internal
14
+
15
+ - **The Bedrock guardrail docs show how to read the trace the change above made readable.** `docs/providers.md` gains a worked read of `provider_reported.bedrock.trace` beside the existing guardrail recipe, `docs/troubleshooting.md` gains an entry for the symptom that actually gets reported ("the guardrail seems ignored, the output came back unchanged"), and the adapter docstring carries the same claim at the source. The entry separates policy from wiring: a PII action of `NONE` detects without rewriting, so unchanged output is the configured behaviour rather than a dropped `guardrailConfig`, and the way to test the wiring instead is a deliberately invalid `guardrailIdentifier`: AWS rejects the call only if the config reached the Converse command, so a call that succeeds is the failure signal.
16
+
17
+ ## v0.9.11 — 2026-08-05
18
+
19
+ ### Added
20
+
21
+ - **The bedrock provider has a real ambient-credential mode.** `use_credential_chain: true` loads `@aws-sdk/credential-providers` (a new optional peer) and hands `fromNodeProviderChain()` to the SDK, so `~/.aws/credentials` profiles, SSO, and ECS/EC2 instance roles authenticate without exporting keys into the environment first. `credential_provider` is the escape hatch for callers that already hold a provider, such as an assume-role flow; supplying both is an `engine_config_error`. The chain is built once per adapter so its memoized credential cache survives across requests.
22
+
23
+ ### Fixed
24
+
25
+ - **`bedrock` documented an ambient AWS credential chain it never had.** The adapter's doc comments, `docs/providers.md`, and `docs/troubleshooting.md` all said that omitting credentials falls back to the AWS credential chain. It does not: `@ai-sdk/amazon-bedrock` resolves SigV4 keys from `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` and never opens `~/.aws/credentials`, so "omit the keys" silently produced an unauthenticated client that failed with a SigV4 error reading like a missing IAM grant. The claim is corrected everywhere and the real capability is now the `use_credential_chain` flag above. Lambda was never affected, since the execution role injects those env vars. `bedrock_credential_chain_wire.test.ts` pins the fix where it actually bit: with every AWS variable deleted from the environment and only a shared-credentials profile on disk, driving the real peer over a stubbed fetch and asserting the profile's key appears in the SigV4 `Authorization` scope. Its negative control asserts the same environment fails without the flag, so the suite cannot be masked by ambient credentials the way the bug was.
26
+
27
+ ### Internal
28
+
29
+ - **The site's three pages carry real head metadata.** `index.html`, `docs.html`, and `blueprint.html` shipped with a head holding only charset and viewport, so tabs showed the bare URL and every link preview and search result had nothing to render. Each page now sets `lang="en"`, a distinct title and description drawn from its own copy, a canonical link, and the Open Graph and Twitter text tags. These sit in the static head rather than the `<helmet>` block, so crawlers that never run JavaScript still see them. No library changes.
30
+
3
31
  ## v0.9.10 — 2026-07-30
4
32
 
5
33
  ### Added
package/dist/agents.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { G as Step } from "./index-SkPG_Rew.js";
2
- import { y as Engine } from "./index-Bfjpd_3o.js";
2
+ import { y as Engine } from "./index-D20uBog5.js";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region src/agents/define_agent.d.ts
@@ -189,6 +189,12 @@ type StepRecord = {
189
189
  usage: UsageTotals;
190
190
  cost?: CostBreakdown;
191
191
  finish_reason: FinishReason;
192
+ /**
193
+ * This turn's provider-reported detail, keyed by provider name. See
194
+ * TurnResult.provider_reported; a multi-step call keeps every turn's payload
195
+ * here, since the call-level field can only carry one.
196
+ */
197
+ provider_reported?: Record<string, unknown>;
192
198
  };
193
199
  type UserContentPart = {
194
200
  type: 'text';
@@ -307,6 +313,18 @@ type TurnResult = {
307
313
  }>;
308
314
  readonly finish_reason: FinishReason;
309
315
  readonly usage: UsageTotals;
316
+ /**
317
+ * Opaque detail the provider reported about this turn, keyed by provider
318
+ * name: Bedrock's guardrail trace, Anthropic's cache breakdown, whatever a
319
+ * given provider volunteers beyond text/usage/finish_reason. The keys are the
320
+ * provider's own, so a caller narrows `provider_reported['bedrock']` at its
321
+ * use site rather than the engine modelling every payload.
322
+ *
323
+ * Absent when the provider reported nothing, never an empty object. The loop
324
+ * copies it onto the step record and generate folds it into
325
+ * GenerateResult.provider_reported.
326
+ */
327
+ readonly provider_reported?: Record<string, unknown>;
310
328
  };
311
329
  /**
312
330
  * One turn's resolved request handed to a native adapter's invoke_turn.
@@ -420,6 +438,12 @@ type GenerateResult<t = string> = {
420
438
  provider: string;
421
439
  model_id: string;
422
440
  };
441
+ /**
442
+ * Provider-keyed detail for the call, taken from the last step that reported
443
+ * any: provider payloads are opaque, so they cannot be summed the way usage
444
+ * and cost are. Mirrors `content` and `finish_reason` in reflecting the final
445
+ * turn; `steps[i].provider_reported` holds every turn's own payload.
446
+ */
423
447
  provider_reported?: Record<string, unknown>;
424
448
  };
425
449
  type ProviderInit = {
@@ -427,6 +451,18 @@ type ProviderInit = {
427
451
  base_url?: string;
428
452
  [k: string]: unknown;
429
453
  };
454
+ /**
455
+ * AWS credentials as `@ai-sdk/amazon-bedrock`'s `credentialProvider` seam
456
+ * expects them. The SDK supplies `region` itself, calls the provider once per
457
+ * request, and never passes arguments, so a provider that caches and refreshes
458
+ * (as `fromNodeProviderChain()` does) is the norm rather than the exception.
459
+ */
460
+ type BedrockCredentials = {
461
+ accessKeyId: string;
462
+ secretAccessKey: string;
463
+ sessionToken?: string;
464
+ };
465
+ type BedrockCredentialProvider = () => PromiseLike<BedrockCredentials>;
430
466
  type ProviderConfigMap = {
431
467
  anthropic?: {
432
468
  api_key: string;
@@ -465,6 +501,8 @@ type ProviderConfigMap = {
465
501
  secret_access_key?: string;
466
502
  session_token?: string;
467
503
  base_url?: string;
504
+ use_credential_chain?: boolean;
505
+ credential_provider?: BedrockCredentialProvider;
468
506
  };
469
507
  claude_cli?: ClaudeCliProviderConfig;
470
508
  [custom: string]: ProviderInit | undefined;
@@ -670,4 +708,4 @@ declare class provider_auth_error extends Error {
670
708
  }
671
709
  //#endregion
672
710
  export { ProviderFactory as $, PricingTable as A, ToolApprovalRequest as B, GenerateOptions as C, PrepareStepHook as D, PrepareStepContext as E, RetryPolicy as F, UsageTotals as G, ToolExecContext as H, StepRecord as I, EffortTranslation as J, UserContentPart as K, StreamChunk as L, ProviderInit as M, ResolvedModel as N, PrepareStepResult as O, RetryFailureKind as P, ProviderCapability as Q, Tool as R, FinishReason as S, Message as T, TurnRequest as U, ToolCallRecord as V, TurnResult as W, NativeProviderAdapter as X, ExternalAgentAdapter as Y, ProviderAdapter as Z, CostBreakdown as _, on_chunk_error as a, EngineConfig as b, provider_error as c, schema_validation_error as d, ProviderTransport as et, tool_approval_denied_error as f, AssistantContentPart as g, AiSdkTelemetrySettings as h, model_required_error as i, ProviderConfigMap as j, Pricing as k, provider_not_configured_error as l, create_engine as m, engine_config_error as n, default_normalize_usage as nt, provider_auth_error as o, tool_error as p, AiSdkProviderAdapter as q, engine_disposed_error as r, provider_capability_error as s, claude_cli_error as t, RawProviderUsage as tt, rate_limit_error as u, EffortLevel as v, GenerateResult as w, EngineDefaults as x, Engine as y, ToolApprovalHandler as z };
673
- //# sourceMappingURL=index-Bfjpd_3o.d.ts.map
711
+ //# sourceMappingURL=index-D20uBog5.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as fallback, B as describe, C as checkpoint, D as LoopResult, E as LoopGuardResult, F as parallel, G as Step, H as run, I as sequence, J as TrajectoryLogger, K as StepMetadata, L as DescribeOptions, M as pipe, N as map, O as loop, P as branch, R as FlowNode, S as suspend, T as LoopConfig, U as CheckpointStore, V as step, W as RunContext, Y as __json_default_export, _ as suspended_error, a as SpanStartEvent, b as stash, c as span_end_event_schema, d as STEP_KINDS, f as StepKind, g as resume_validation_error, h as describe_cycle_error, i as SpanEndEvent, j as retry, k as timeout, l as span_start_event_schema, m as aborted_error, n as EmitEvent, o as custom_event_schema, p as is_step_kind, q as TrajectoryEvent, r as ParsedTrajectoryEvent, s as emit_event_schema, t as CustomTrajectoryEvent, u as trajectory_event_schema, v as timeout_error, w as compose, x as use, y as scope, z as FlowValue } from "./index-SkPG_Rew.js";
2
- import { $ as ProviderFactory, A as PricingTable, B as ToolApprovalRequest, C as GenerateOptions, D as PrepareStepHook, E as PrepareStepContext, F as RetryPolicy, G as UsageTotals, H as ToolExecContext, I as StepRecord, J as EffortTranslation, K as UserContentPart, L as StreamChunk, M as ProviderInit, N as ResolvedModel, O as PrepareStepResult, P as RetryFailureKind, Q as ProviderCapability, R as Tool, S as FinishReason, T as Message, U as TurnRequest, V as ToolCallRecord, W as TurnResult, X as NativeProviderAdapter, Y as ExternalAgentAdapter, Z as ProviderAdapter, _ as CostBreakdown, a as on_chunk_error, b as EngineConfig, c as provider_error, d as schema_validation_error, et as ProviderTransport, f as tool_approval_denied_error, g as AssistantContentPart, h as AiSdkTelemetrySettings, i as model_required_error, j as ProviderConfigMap, k as Pricing, l as provider_not_configured_error, m as create_engine, n as engine_config_error, nt as default_normalize_usage, o as provider_auth_error, p as tool_error, q as AiSdkProviderAdapter, r as engine_disposed_error, s as provider_capability_error, t as claude_cli_error, tt as RawProviderUsage, u as rate_limit_error, v as EffortLevel, w as GenerateResult, x as EngineDefaults, y as Engine, z as ToolApprovalHandler } from "./index-Bfjpd_3o.js";
2
+ import { $ as ProviderFactory, A as PricingTable, B as ToolApprovalRequest, C as GenerateOptions, D as PrepareStepHook, E as PrepareStepContext, F as RetryPolicy, G as UsageTotals, H as ToolExecContext, I as StepRecord, J as EffortTranslation, K as UserContentPart, L as StreamChunk, M as ProviderInit, N as ResolvedModel, O as PrepareStepResult, P as RetryFailureKind, Q as ProviderCapability, R as Tool, S as FinishReason, T as Message, U as TurnRequest, V as ToolCallRecord, W as TurnResult, X as NativeProviderAdapter, Y as ExternalAgentAdapter, Z as ProviderAdapter, _ as CostBreakdown, a as on_chunk_error, b as EngineConfig, c as provider_error, d as schema_validation_error, et as ProviderTransport, f as tool_approval_denied_error, g as AssistantContentPart, h as AiSdkTelemetrySettings, i as model_required_error, j as ProviderConfigMap, k as Pricing, l as provider_not_configured_error, m as create_engine, n as engine_config_error, nt as default_normalize_usage, o as provider_auth_error, p as tool_error, q as AiSdkProviderAdapter, r as engine_disposed_error, s as provider_capability_error, t as claude_cli_error, tt as RawProviderUsage, u as rate_limit_error, v as EffortLevel, w as GenerateResult, x as EngineDefaults, y as Engine, z as ToolApprovalHandler } from "./index-D20uBog5.js";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region src/composites/adversarial.d.ts
package/dist/index.js CHANGED
@@ -1683,7 +1683,7 @@ async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort) {
1683
1683
  /**
1684
1684
  * Read `key` off `err` and return it only if the value is a string.
1685
1685
  */
1686
- function read_string(err, key) {
1686
+ function read_string$1(err, key) {
1687
1687
  const value = Reflect.get(err, key);
1688
1688
  return typeof value === "string" ? value : void 0;
1689
1689
  }
@@ -1704,14 +1704,14 @@ function read_number$1(err, key) {
1704
1704
  */
1705
1705
  function classify_retryable(err) {
1706
1706
  if (err === null || typeof err !== "object") return void 0;
1707
- const kind = read_string(err, "kind");
1707
+ const kind = read_string$1(err, "kind");
1708
1708
  if (kind === "rate_limit") {
1709
1709
  const base = { kind: "rate_limit" };
1710
1710
  const retry_after = read_number$1(err, "retry_after_ms");
1711
1711
  if (retry_after !== void 0) base.retry_after_ms = retry_after;
1712
1712
  const status = read_number$1(err, "status");
1713
1713
  if (status !== void 0) base.status = status;
1714
- const message = read_string(err, "message");
1714
+ const message = read_string$1(err, "message");
1715
1715
  if (message !== void 0) base.message = message;
1716
1716
  return base;
1717
1717
  }
@@ -1719,15 +1719,15 @@ function classify_retryable(err) {
1719
1719
  const base = { kind: "provider_5xx" };
1720
1720
  const status = read_number$1(err, "status");
1721
1721
  if (status !== void 0) base.status = status;
1722
- const body = read_string(err, "body");
1722
+ const body = read_string$1(err, "body");
1723
1723
  if (body !== void 0) base.body = body;
1724
- const message = read_string(err, "message");
1724
+ const message = read_string$1(err, "message");
1725
1725
  if (message !== void 0) base.message = message;
1726
1726
  return base;
1727
1727
  }
1728
1728
  if (kind === "network" || kind === "timeout") {
1729
1729
  const base = { kind };
1730
- const message = read_string(err, "message");
1730
+ const message = read_string$1(err, "message");
1731
1731
  if (message !== void 0) base.message = message;
1732
1732
  return base;
1733
1733
  }
@@ -3922,31 +3922,85 @@ const SUPPORTED$1 = /* @__PURE__ */ new Set([
3922
3922
  "image_input",
3923
3923
  "reasoning"
3924
3924
  ]);
3925
+ /** Read a config field only when it is a string, so junk values stay unset. */
3926
+ function read_string(init, key) {
3927
+ const value = init[key];
3928
+ return typeof value === "string" ? value : void 0;
3929
+ }
3930
+ /** Pull the static fields off init, rejecting a missing or non-string region. */
3931
+ function read_static_credentials(init) {
3932
+ const region = read_string(init, "region") ?? "";
3933
+ if (region.length === 0) throw new engine_config_error("bedrock provider requires a non-empty region", "bedrock");
3934
+ return {
3935
+ region,
3936
+ api_key: read_string(init, "api_key"),
3937
+ access_key_id: read_string(init, "access_key_id"),
3938
+ secret_access_key: read_string(init, "secret_access_key"),
3939
+ session_token: read_string(init, "session_token"),
3940
+ base_url: read_string(init, "base_url")
3941
+ };
3942
+ }
3943
+ /** True when the caller is already supplying credentials in any static form. */
3944
+ function has_static_credentials(statics) {
3945
+ return statics.api_key !== void 0 || statics.access_key_id !== void 0 || statics.secret_access_key !== void 0 || statics.session_token !== void 0;
3946
+ }
3947
+ /**
3948
+ * Pick the dynamic credential source, or none. A bearer token or any explicit
3949
+ * SigV4 field short-circuits it: attaching a provider anyway would either
3950
+ * override the caller's keys (the SDK prefers `credentialProvider` over
3951
+ * `accessKeyId`) or force the optional @aws-sdk/credential-providers peer on
3952
+ * bearer-token users who never need it. The conflict check runs first, since
3953
+ * naming two dynamic sources is a mistake whatever else is set.
3954
+ */
3955
+ function resolve_dynamic_source(init, statics) {
3956
+ const use_chain = init["use_credential_chain"] === true;
3957
+ const raw = init["credential_provider"];
3958
+ const provider = typeof raw === "function" ? raw : void 0;
3959
+ if (use_chain && provider !== void 0) throw new engine_config_error("bedrock provider accepts use_credential_chain or credential_provider, not both", "bedrock");
3960
+ if (has_static_credentials(statics)) return void 0;
3961
+ if (provider !== void 0) return {
3962
+ kind: "explicit",
3963
+ provider
3964
+ };
3965
+ return use_chain ? { kind: "chain" } : void 0;
3966
+ }
3967
+ /**
3968
+ * Build the camelCase config the SDK expects, assigning only fields that are
3969
+ * set so the object carries no `undefined` entries. The SDK reads either shape
3970
+ * identically; the tests assert on key presence, which is the cheaper signal
3971
+ * that a credential really was omitted rather than silently resolved.
3972
+ */
3973
+ function to_sdk_config(statics, credential_provider) {
3974
+ const config = { region: statics.region };
3975
+ if (statics.api_key !== void 0) config.apiKey = statics.api_key;
3976
+ if (statics.access_key_id !== void 0) config.accessKeyId = statics.access_key_id;
3977
+ if (statics.secret_access_key !== void 0) config.secretAccessKey = statics.secret_access_key;
3978
+ if (statics.session_token !== void 0) config.sessionToken = statics.session_token;
3979
+ if (statics.base_url !== void 0) config.baseURL = statics.base_url;
3980
+ if (credential_provider !== void 0) config.credentialProvider = credential_provider;
3981
+ return config;
3982
+ }
3925
3983
  /**
3926
3984
  * Build the Bedrock ai_sdk adapter: validates the required region, resolves
3927
- * the chosen auth mode (bearer token, SigV4 keys, or the ambient AWS
3928
- * credential chain), and lazily loads @ai-sdk/amazon-bedrock to build models.
3985
+ * the chosen auth mode (bearer token, explicit SigV4 keys, or a dynamic
3986
+ * credential source), and lazily loads @ai-sdk/amazon-bedrock to build models.
3987
+ * See the module docstring for the full precedence ladder.
3929
3988
  */
3930
3989
  const create_bedrock_adapter = (init) => {
3931
- const region = typeof init["region"] === "string" ? init["region"] : "";
3932
- if (region.length === 0) throw new engine_config_error("bedrock provider requires a non-empty region", "bedrock");
3933
- const api_key = typeof init.api_key === "string" ? init.api_key : void 0;
3934
- const access_key_id = typeof init["access_key_id"] === "string" ? init["access_key_id"] : void 0;
3935
- const secret_access_key = typeof init["secret_access_key"] === "string" ? init["secret_access_key"] : void 0;
3936
- const session_token = typeof init["session_token"] === "string" ? init["session_token"] : void 0;
3937
- const base_url = typeof init.base_url === "string" ? init.base_url : void 0;
3990
+ const statics = read_static_credentials(init);
3991
+ const dynamic_source = resolve_dynamic_source(init, statics);
3992
+ let chain;
3993
+ async function resolve_credential_provider() {
3994
+ if (dynamic_source === void 0) return void 0;
3995
+ if (dynamic_source.kind === "explicit") return dynamic_source.provider;
3996
+ chain ??= (await load_optional_peer("@aws-sdk/credential-providers")).fromNodeProviderChain();
3997
+ return chain;
3998
+ }
3938
3999
  return {
3939
4000
  kind: "ai_sdk",
3940
4001
  name: "bedrock",
3941
4002
  async build_model(model_id) {
3942
- const sdk = await load_optional_peer("@ai-sdk/amazon-bedrock");
3943
- const config = { region };
3944
- if (api_key !== void 0) config.apiKey = api_key;
3945
- if (access_key_id !== void 0) config.accessKeyId = access_key_id;
3946
- if (secret_access_key !== void 0) config.secretAccessKey = secret_access_key;
3947
- if (session_token !== void 0) config.sessionToken = session_token;
3948
- if (base_url !== void 0) config.baseURL = base_url;
3949
- return sdk.createAmazonBedrock(config)(model_id);
4003
+ return (await load_optional_peer("@ai-sdk/amazon-bedrock")).createAmazonBedrock(to_sdk_config(statics, await resolve_credential_provider()))(model_id);
3950
4004
  },
3951
4005
  translate_effort: translate_bedrock_effort,
3952
4006
  normalize_usage: normalize_bedrock_usage,
@@ -6733,6 +6787,7 @@ async function run_tool_loop(config) {
6733
6787
  };
6734
6788
  const breakdown = compute_and_record_cost(config, step_index, turn.usage);
6735
6789
  if (breakdown !== void 0) record_step.cost = breakdown;
6790
+ if (turn.provider_reported !== void 0) record_step.provider_reported = turn.provider_reported;
6736
6791
  steps.push(record_step);
6737
6792
  if (config.on_finish_step !== void 0) config.on_finish_step(record_step);
6738
6793
  end_step_span(config.trajectory, step_span, {
@@ -6988,6 +7043,7 @@ async function run_tool_loop(config) {
6988
7043
  };
6989
7044
  const breakdown = compute_and_record_cost(config, step_index, turn.usage);
6990
7045
  if (breakdown !== void 0) step_record.cost = breakdown;
7046
+ if (turn.provider_reported !== void 0) step_record.provider_reported = turn.provider_reported;
6991
7047
  steps.push(step_record);
6992
7048
  if (config.on_finish_step !== void 0) config.on_finish_step(step_record);
6993
7049
  end_step_span(config.trajectory, step_span, {
@@ -7100,6 +7156,26 @@ function to_raw_provider_usage(usage) {
7100
7156
  return raw;
7101
7157
  }
7102
7158
  /**
7159
+ * Normalize an AI SDK `providerMetadata` value into the neutral
7160
+ * TurnResult.provider_reported shape.
7161
+ *
7162
+ * The SDK's metadata is already keyed by provider name, which is the shape
7163
+ * provider_reported documents, so the keys ride through untranslated and every
7164
+ * ai_sdk provider is served by this one seam: bedrock's guardrail `trace`,
7165
+ * anthropic's cache detail, openai's own fields. The payloads stay opaque
7166
+ * (callers narrow them at the use site), so this copies the top level and
7167
+ * inspects nothing below it. An absent or empty map returns undefined, keeping
7168
+ * "the provider reported nothing" spelled one way.
7169
+ */
7170
+ function to_provider_reported(metadata) {
7171
+ if (metadata === null || typeof metadata !== "object") return void 0;
7172
+ const keys = Object.keys(metadata);
7173
+ if (keys.length === 0) return void 0;
7174
+ const reported = {};
7175
+ for (const key of keys) reported[key] = Reflect.get(metadata, key);
7176
+ return reported;
7177
+ }
7178
+ /**
7103
7179
  * Map fascicle's Message[] to the AI SDK's ModelMessage[] shape.
7104
7180
  */
7105
7181
  function to_sdk_messages(messages) {
@@ -7287,6 +7363,7 @@ async function collect_stream(params, step_index, dispatcher, on_first_chunk, in
7287
7363
  const tool_calls = [];
7288
7364
  let finish_reason = "stop";
7289
7365
  let raw_usage = {};
7366
+ let provider_reported;
7290
7367
  let first = true;
7291
7368
  for await (const part of stream_result.stream) {
7292
7369
  if (first) {
@@ -7302,6 +7379,7 @@ async function collect_stream(params, step_index, dispatcher, on_first_chunk, in
7302
7379
  if (part.type === "finish-step") {
7303
7380
  finish_reason = map_finish_reason(part.finishReason);
7304
7381
  raw_usage = to_raw_provider_usage(part.usage);
7382
+ provider_reported = to_provider_reported(part.providerMetadata);
7305
7383
  }
7306
7384
  if (part.type === "error") throw part.error;
7307
7385
  if (part.type === "abort") throw new aborted_error("aborted", { step_index });
@@ -7318,7 +7396,8 @@ async function collect_stream(params, step_index, dispatcher, on_first_chunk, in
7318
7396
  text,
7319
7397
  tool_calls,
7320
7398
  finish_reason,
7321
- usage: adapter.normalize_usage(raw_usage)
7399
+ usage: adapter.normalize_usage(raw_usage),
7400
+ ...provider_reported !== void 0 ? { provider_reported } : {}
7322
7401
  };
7323
7402
  }
7324
7403
  /**
@@ -7342,11 +7421,13 @@ async function collect_non_stream(params, adapter) {
7342
7421
  input: tc.input
7343
7422
  });
7344
7423
  const raw_usage = to_raw_provider_usage(result.usage);
7424
+ const provider_reported = to_provider_reported(result.providerMetadata);
7345
7425
  return {
7346
7426
  text: result.text,
7347
7427
  tool_calls,
7348
7428
  finish_reason: map_finish_reason(result.finishReason),
7349
- usage: adapter.normalize_usage(raw_usage)
7429
+ usage: adapter.normalize_usage(raw_usage),
7430
+ ...provider_reported !== void 0 ? { provider_reported } : {}
7350
7431
  };
7351
7432
  }
7352
7433
  /**
@@ -7359,6 +7440,10 @@ async function collect_non_stream(params, adapter) {
7359
7440
  * turn result, so `parse_with_schema` re-validates it and the repair loop
7360
7441
  * engages exactly as it does for the prompt-based path. Returns undefined for
7361
7442
  * any other error so the caller rethrows.
7443
+ *
7444
+ * The recovered turn carries no provider_reported: the SDK's error exposes
7445
+ * text, usage, finishReason and response metadata, but not providerMetadata,
7446
+ * so there is nothing to read. The repair turn that follows reports normally.
7362
7447
  */
7363
7448
  function recover_no_object_generated(err, adapter) {
7364
7449
  if (!NoObjectGeneratedError.isInstance(err)) return void 0;
@@ -7869,6 +7954,8 @@ async function generate(opts_in, engine) {
7869
7954
  }
7870
7955
  };
7871
7956
  if (aggregated_cost !== void 0) result.cost = aggregated_cost;
7957
+ const aggregated_reported = last_provider_reported(steps_accum);
7958
+ if (aggregated_reported !== void 0) result.provider_reported = aggregated_reported;
7872
7959
  if (on_chunk_provided) await dispatcher.dispatch({
7873
7960
  kind: "finish",
7874
7961
  finish_reason,
@@ -7892,6 +7979,19 @@ function round6(v) {
7892
7979
  return Math.round(v * 1e6) / 1e6;
7893
7980
  }
7894
7981
  /**
7982
+ * Pick the call-level `provider_reported` from the step records: the payload of
7983
+ * the last step that reported one.
7984
+ *
7985
+ * Provider payloads are opaque, so unlike usage and cost there is nothing to
7986
+ * sum and no safe way to merge two turns' keys (a provider reports the same keys
7987
+ * every turn, so merging would silently overwrite rather than combine). Taking
7988
+ * the final reporting turn matches how `content` and `finish_reason` are drawn
7989
+ * from the last turn; every turn's own payload stays on `steps[i]`.
7990
+ */
7991
+ function last_provider_reported(steps) {
7992
+ return steps.findLast((s) => s.provider_reported !== void 0)?.provider_reported;
7993
+ }
7994
+ /**
7895
7995
  * Sum per-step cost breakdowns into a single `CostBreakdown` for the whole
7896
7996
  * generate call.
7897
7997
  *