fascicle 0.17.3 → 0.17.5

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.
@@ -1,6 +1,6 @@
1
- import { A as aborted_error, T as validate_schema, f as compute_backoff, p as wait_with_abort, w as format_schema_issues } from "./core-Dwir3pkb.js";
1
+ import { C as validate_schema, D as wait_with_abort, E as compute_backoff, S as format_schema_issues, T as failure_meta, j as aborted_error } from "./core-Bfzt55Fl.js";
2
2
  import { n as is_record$1 } from "./records-1HU7mWXf.js";
3
- import { A as tool_approval_denied_error, C as provider_auth_error, D as provider_required_error, E as provider_not_configured_error, M as turn_timeout_error, O as rate_limit_error, S as on_chunk_error, T as provider_error, _ as claude_cli_error, b as incomplete_generation_error, c as parse_tool_call_arguments, d as default_normalize_usage, f as load_optional_peer, g as translate_effort_to_sdk_reasoning, h as resolve_transport, i as invoke_http_turn, j as tool_error, k as schema_validation_error, l as read_dialect_init, m as normalize_local_usage, n as consume_framed_stream, o as map_messages_by_role, p as missing_peer_error, r as create_line_splitter, s as network_failure, t as split_leading_system_run, u as split_assistant_parts, v as engine_config_error, w as provider_capability_error, x as model_required_error, y as engine_disposed_error } from "./leading_system-DJvuhESU.js";
3
+ import { A as provider_auth_error, C as translate_effort_to_sdk_reasoning, D as incomplete_generation_error, E as engine_disposed_error, F as rate_limit_error, I as schema_validation_error, L as tool_approval_denied_error, M as provider_error, N as provider_not_configured_error, O as model_required_error, P as provider_required_error, R as tool_error, S as resolve_transport, T as engine_config_error, _ as load_optional_peer, a as invoke_http_turn, b as normalize_local_usage, c as network_detail, d as parse_tool_call_arguments, f as protocol_error, g as default_normalize_usage, h as unreachable_message, i as error_body_message, j as provider_capability_error, k as on_chunk_error, l as network_failure, m as split_assistant_parts, n as consume_framed_stream, p as read_dialect_init, r as create_line_splitter, s as map_messages_by_role, t as split_leading_system_run, u as non_retryable_status_error, v as missing_config_error, w as claude_cli_error, x as refuse_credentials_in_base_url, y as missing_peer_error, z as turn_timeout_error } from "./leading_system-CHSYz0h9.js";
4
4
  import { join } from "node:path";
5
5
  import { mkdtempSync, writeFileSync } from "node:fs";
6
6
  import { tmpdir } from "node:os";
@@ -414,8 +414,8 @@ function decompose_total_cost(total_cost_usd, usage) {
414
414
  //#endregion
415
415
  //#region src/engine/retry.ts
416
416
  const DEFAULT_RETRY = {
417
- max_attempts: 3,
418
- initial_delay_ms: 500,
417
+ max_attempts: 4,
418
+ initial_delay_ms: 1e3,
419
419
  max_delay_ms: 3e4,
420
420
  retry_on: [
421
421
  "rate_limit",
@@ -465,40 +465,60 @@ function to_abort_error(reason) {
465
465
  return new aborted_error("aborted", { reason });
466
466
  }
467
467
  /**
468
+ * The message a typed error carries: `lead`, which says what this layer did,
469
+ * then the status when the failure had one, then the provider's own message
470
+ * when it had one, as in `provider_5xx after 4 attempts (status 503): Service
471
+ * Unavailable`. The lead comes first so the message reads the same whether
472
+ * or not the provider said anything.
473
+ */
474
+ function compose_message(lead, status, message) {
475
+ return `${lead}${status === void 0 ? "" : ` (status ${status})`}${message === void 0 ? "" : `: ${message}`}`;
476
+ }
477
+ /**
468
478
  * Build the `rate_limit_error` for a 429 that this layer won't retry again.
469
479
  * Prefers the failing attempt's own `Retry-After`, falling back to the most
470
- * recent one a prior attempt carried (`last_rate_limit_after`), and carries
471
- * the failure's own message, or `fallback` when it had none.
480
+ * recent one a prior attempt carried (`last_rate_limit_after`), and keeps the
481
+ * failure's original error as its `cause`.
472
482
  */
473
- function build_rate_limit_error(retryable, attempt, last_rate_limit_after, fallback) {
474
- const metadata = { attempts: attempt };
483
+ function build_rate_limit_error(retryable, attempt, last_rate_limit_after, lead) {
484
+ const metadata = {
485
+ attempts: attempt,
486
+ cause: retryable.cause
487
+ };
475
488
  if (retryable.retry_after_ms !== void 0) metadata.retry_after_ms = retryable.retry_after_ms;
476
489
  else if (last_rate_limit_after !== void 0) metadata.retry_after_ms = last_rate_limit_after;
477
490
  if (retryable.status !== void 0) metadata.status = retryable.status;
478
- return new rate_limit_error(retryable.message ?? fallback, metadata);
491
+ return new rate_limit_error(compose_message(lead, retryable.status, retryable.message), metadata);
479
492
  }
480
493
  /**
481
494
  * Build the `provider_error` for a 5xx, network, or timeout failure that this
482
- * layer won't retry again. Timeout collapses onto the `network` cause; only
483
- * 5xx carries status/body. The failure's own message wins over `fallback`.
495
+ * layer won't retry again, after `attempt` failures in all. Timeout collapses
496
+ * onto the `network` cause; only 5xx carries status/body. The failure's
497
+ * original error is its `cause`.
484
498
  */
485
- function build_provider_error(retryable, fallback) {
486
- const metadata = { cause_kind: retryable.kind === "provider_5xx" ? "provider_5xx" : "network" };
499
+ function build_provider_error(retryable, attempt, lead) {
500
+ const metadata = {
501
+ cause_kind: retryable.kind === "provider_5xx" ? "provider_5xx" : "network",
502
+ attempts: attempt,
503
+ cause: retryable.cause
504
+ };
505
+ let status;
487
506
  if (retryable.kind === "provider_5xx") {
488
- if (retryable.status !== void 0) metadata.status = retryable.status;
507
+ status = retryable.status;
508
+ if (status !== void 0) metadata.status = status;
489
509
  if (retryable.body !== void 0) metadata.body = retryable.body;
490
510
  }
491
- return new provider_error(retryable.message ?? fallback, metadata);
511
+ return new provider_error(compose_message(lead, status, retryable.message), metadata);
492
512
  }
493
513
  /**
494
514
  * Map a classified failure that this layer won't retry again onto the error
495
515
  * it rejects with: `rate_limit_error` for 429s, `provider_error` for
496
- * everything else, after `attempt` failures in all. `fallback` is the message
497
- * for a failure that carried none of its own.
516
+ * everything else, after `attempt` failures in all. `lead` opens the message
517
+ * and says why this layer stopped.
498
518
  */
499
- function build_typed_error(retryable, attempt, last_rate_limit_after, fallback) {
500
- if (retryable.kind === "rate_limit") return build_rate_limit_error(retryable, attempt, last_rate_limit_after, fallback);
501
- return build_provider_error(retryable, fallback);
519
+ function build_typed_error(retryable, attempt, last_rate_limit_after, lead) {
520
+ if (retryable.kind === "rate_limit") return build_rate_limit_error(retryable, attempt, last_rate_limit_after, lead);
521
+ return build_provider_error(retryable, attempt, lead);
502
522
  }
503
523
  /**
504
524
  * The error for a failure whose kind `retry_on` leaves out. One that's
@@ -510,13 +530,14 @@ function build_typed_error(retryable, attempt, last_rate_limit_after, fallback)
510
530
  */
511
531
  function build_left_out_error(err, retryable, attempt, last_rate_limit_after) {
512
532
  if (err instanceof Error) return err;
513
- return build_typed_error(retryable, attempt, last_rate_limit_after, `${retryable.kind} not retried: retry_on leaves ${retryable.kind} out`);
533
+ return build_typed_error(retryable, attempt, last_rate_limit_after, `${retryable.kind} left out of retry_on`);
514
534
  }
515
535
  /**
516
- * The message for an exhausted failure that carried none of its own.
536
+ * The lead of an exhausted failure's message, which counts its attempts.
517
537
  */
518
- function exhaustion_message(retryable, attempt) {
519
- return retryable.kind === "rate_limit" ? `rate limited after ${attempt} attempts` : `${retryable.kind} after ${attempt} attempts`;
538
+ function exhaustion_lead(retryable, attempt) {
539
+ const attempts = attempt === 1 ? "1 attempt" : `${attempt} attempts`;
540
+ return retryable.kind === "rate_limit" ? `rate limited after ${attempts}` : `${retryable.kind} after ${attempts}`;
520
541
  }
521
542
  /**
522
543
  * The server's `Retry-After`, in milliseconds, that a 429 or a 5xx carried,
@@ -572,13 +593,15 @@ function build_attempt_info(retryable, attempt, delay_ms) {
572
593
  * An aborted `abort` signal interrupts a pending backoff wait and throws
573
594
  * `aborted_error`. Returns the value from the last successful `fn()` call. On
574
595
  * exhaustion, throws `rate_limit_error` (for 429s) or `provider_error` (for
575
- * 5xx/network/timeout).
596
+ * 5xx/network/timeout), counting the attempts, with the last failure's
597
+ * original error as its `cause` and a message that says how many attempts it
598
+ * took before the status and the provider's own message.
576
599
  *
577
600
  * A failure whose kind `retry_on` leaves out isn't retried. It's rethrown as
578
601
  * it is when it's already an `Error`, and a plain record becomes the
579
602
  * `rate_limit_error` or `provider_error` that exhaustion would throw for its
580
- * kind, counting every failure so far in `attempts`, with the record's own
581
- * message, or else one that says `retry_on` leaves its kind out.
603
+ * kind, counting every failure so far in `attempts`, with a message that
604
+ * says `retry_on` leaves its kind out.
582
605
  *
583
606
  * `on_retry` fires once per retried failure, just before its backoff wait.
584
607
  * It does NOT fire for a first attempt that succeeds, a non-retryable
@@ -599,11 +622,11 @@ async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort, on_retry) {
599
622
  try {
600
623
  return await fn(attempt);
601
624
  } catch (err) {
602
- const retryable = classify_retryable(err);
625
+ const retryable = classify_retryable$1(err);
603
626
  if (retryable === void 0) throw err;
604
627
  attempt += 1;
605
628
  if (!is_retryable(retryable.kind, policy)) throw build_left_out_error(err, retryable, attempt, last_rate_limit_after);
606
- if (attempt >= policy.max_attempts) throw build_typed_error(retryable, attempt, last_rate_limit_after, exhaustion_message(retryable, attempt));
629
+ if (attempt >= policy.max_attempts) throw build_typed_error(retryable, attempt, last_rate_limit_after, exhaustion_lead(retryable, attempt));
607
630
  const backoff = next_backoff(retryable, backoff_policy, attempt);
608
631
  last_rate_limit_after = carry_rate_limit_after(retryable, backoff, last_rate_limit_after);
609
632
  on_retry?.(build_attempt_info(retryable, attempt, backoff.delay));
@@ -674,19 +697,32 @@ function build_retryable_signal(err, kind) {
674
697
  return base;
675
698
  }
676
699
  /**
700
+ * Read the retryable shape for a recognized `kind`, or `undefined` for any
701
+ * other.
702
+ */
703
+ function read_retryable(err) {
704
+ const kind = read_string$1(err, "kind");
705
+ if (kind === "rate_limit") return build_retryable_rate_limit(err);
706
+ if (kind === "provider_5xx") return build_retryable_5xx(err);
707
+ if (kind === "network" || kind === "timeout") return build_retryable_signal(err, kind);
708
+ }
709
+ /**
677
710
  * Classify a thrown value into a `RetryableError`, or `undefined` if it
678
711
  * does not carry one of the recognized retryable `kind`s.
679
712
  *
680
713
  * Providers throw plain objects tagged with `kind` (set by
681
714
  * `classify_provider_error` in generate.ts); this reads that shape back out
682
- * field by field rather than trusting it wholesale.
715
+ * field by field rather than trusting it wholesale. The failure's `cause` is
716
+ * what a typed error hands back as its own: the original error that a plain
717
+ * record names as its `cause`, or the thrown value itself when it is already
718
+ * an `Error`, such as `turn_timeout_error`.
683
719
  */
684
- function classify_retryable(err) {
720
+ function classify_retryable$1(err) {
685
721
  if (err === null || typeof err !== "object") return void 0;
686
- const kind = read_string$1(err, "kind");
687
- if (kind === "rate_limit") return build_retryable_rate_limit(err);
688
- if (kind === "provider_5xx") return build_retryable_5xx(err);
689
- if (kind === "network" || kind === "timeout") return build_retryable_signal(err, kind);
722
+ const retryable = read_retryable(err);
723
+ if (retryable === void 0) return void 0;
724
+ retryable.cause = err instanceof Error ? err : Reflect.get(err, "cause");
725
+ return retryable;
690
726
  }
691
727
  //#endregion
692
728
  //#region src/engine/providers/sse_native.ts
@@ -1123,7 +1159,7 @@ function carries_provider_data(parts) {
1123
1159
  * `'stop'` finish, so the loop continues the turn.
1124
1160
  */
1125
1161
  function parse_messages_response(payload) {
1126
- if (payload === null || typeof payload !== "object") throw new provider_error("anthropic native: response payload is not a JSON object");
1162
+ if (payload === null || typeof payload !== "object") throw protocol_error("anthropic", "response payload is not a JSON object");
1127
1163
  const { text_parts, tool_calls, parts } = collect_content_blocks(Reflect.get(payload, "content"));
1128
1164
  const stop_reason = Reflect.get(payload, "stop_reason");
1129
1165
  const result = {
@@ -1170,7 +1206,7 @@ function stream_event_error(event) {
1170
1206
  */
1171
1207
  function read_block_index(event) {
1172
1208
  const index = Reflect.get(event, "index");
1173
- if (typeof index !== "number") throw new provider_error("anthropic native: stream event is missing its block index");
1209
+ if (typeof index !== "number") throw protocol_error("anthropic", "stream event is missing its block index");
1174
1210
  return index;
1175
1211
  }
1176
1212
  /**
@@ -1185,7 +1221,7 @@ function parse_stream_event(data) {
1185
1221
  try {
1186
1222
  return JSON.parse(data);
1187
1223
  } catch {
1188
- throw new provider_error("anthropic native: stream event is not valid JSON");
1224
+ throw protocol_error("anthropic", "stream event is not valid JSON");
1189
1225
  }
1190
1226
  }
1191
1227
  /**
@@ -1439,7 +1475,7 @@ const SUPPORTED$10 = /* @__PURE__ */ new Set([
1439
1475
  */
1440
1476
  const create_anthropic_native_adapter = (init) => {
1441
1477
  const api_key = typeof init.api_key === "string" ? init.api_key : "";
1442
- if (api_key.length === 0) throw new engine_config_error("anthropic provider requires a non-empty api_key", "anthropic");
1478
+ if (api_key.length === 0) throw missing_config_error("anthropic", "api_key", "process.env.ANTHROPIC_API_KEY");
1443
1479
  const base_url = (typeof init.base_url === "string" && init.base_url.length > 0 ? init.base_url : DEFAULT_BASE_URL$2).replace(/\/+$/, "");
1444
1480
  return {
1445
1481
  kind: "native",
@@ -1534,7 +1570,7 @@ const create_anthropic_adapter = (init) => {
1534
1570
  */
1535
1571
  const create_anthropic_ai_sdk_adapter = (init) => {
1536
1572
  const api_key = typeof init.api_key === "string" ? init.api_key : "";
1537
- if (api_key.length === 0) throw new engine_config_error("anthropic provider requires a non-empty api_key", "anthropic");
1573
+ if (api_key.length === 0) throw missing_config_error("anthropic", "api_key", "process.env.ANTHROPIC_API_KEY");
1538
1574
  const base_url = typeof init.base_url === "string" ? init.base_url : void 0;
1539
1575
  return {
1540
1576
  kind: "ai_sdk",
@@ -1797,7 +1833,7 @@ function map_chat_usage(raw, dialect) {
1797
1833
  input_tokens: 0,
1798
1834
  output_tokens: 0
1799
1835
  };
1800
- throw new provider_error(`${dialect.name} native: response is missing its usage object`);
1836
+ throw protocol_error(dialect.name, "response is missing its usage object", "use the lmstudio provider for a self-hosted server");
1801
1837
  }
1802
1838
  const totals = {
1803
1839
  input_tokens: read_number(raw, "prompt_tokens") ?? 0,
@@ -1861,12 +1897,12 @@ function parse_tool_call(raw, provider) {
1861
1897
  * rebuilds this same payload shape from deltas before calling it.
1862
1898
  */
1863
1899
  function parse_chat_completion(payload, dialect) {
1864
- if (payload === null || typeof payload !== "object") throw new provider_error(`${dialect.name} native: response payload is not a JSON object`);
1900
+ if (payload === null || typeof payload !== "object") throw protocol_error(dialect.name, "response payload is not a JSON object");
1865
1901
  const choices = Reflect.get(payload, "choices");
1866
1902
  const choice = Array.isArray(choices) ? choices[0] : void 0;
1867
- if (choice === null || choice === void 0 || typeof choice !== "object") throw new provider_error(`${dialect.name} native: response has no choices`);
1903
+ if (choice === null || choice === void 0 || typeof choice !== "object") throw protocol_error(dialect.name, "response has no choices");
1868
1904
  const message = Reflect.get(choice, "message");
1869
- if (message === null || typeof message !== "object") throw new provider_error(`${dialect.name} native: response choice has no message`);
1905
+ if (message === null || typeof message !== "object") throw protocol_error(dialect.name, "response choice has no message");
1870
1906
  const content = Reflect.get(message, "content");
1871
1907
  const raw_tool_calls = Reflect.get(message, "tool_calls");
1872
1908
  const tool_calls = Array.isArray(raw_tool_calls) ? raw_tool_calls.map((entry) => parse_tool_call(entry, dialect.name)) : [];
@@ -2120,7 +2156,7 @@ function create_chat_stream_aggregator(dialect, step_index, dispatch) {
2120
2156
  try {
2121
2157
  frame = JSON.parse(data);
2122
2158
  } catch {
2123
- throw new provider_error(`${dialect.name} native: stream frame is not valid JSON`);
2159
+ throw protocol_error(dialect.name, "stream frame is not valid JSON");
2124
2160
  }
2125
2161
  if (frame === null || typeof frame !== "object") return;
2126
2162
  const error = Reflect.get(frame, "error");
@@ -2188,7 +2224,7 @@ const SUPPORTED$8 = /* @__PURE__ */ new Set([
2188
2224
  * the mappers above.
2189
2225
  */
2190
2226
  const create_openai_compatible_adapter = (dialect) => {
2191
- if (dialect.auth.kind === "bearer" && dialect.auth.api_key.length === 0) throw new engine_config_error(`${dialect.name} provider requires a non-empty api_key`, dialect.name);
2227
+ if (dialect.auth.kind === "bearer" && dialect.auth.api_key.length === 0) throw missing_config_error(dialect.name, "api_key", `process.env.${dialect.name.toUpperCase()}_API_KEY`);
2192
2228
  const base_url = dialect.base_url.replace(/\/+$/, "");
2193
2229
  const headers = {
2194
2230
  "content-type": "application/json",
@@ -2249,7 +2285,7 @@ const create_openai_adapter = (init) => {
2249
2285
  * `max_completion_tokens` token-limit field, and strict usage (a hosted API
2250
2286
  * omitting usage is a broken response, not a local-runtime quirk). The
2251
2287
  * empty-api_key guard rides on the core, which throws the same
2252
- * `openai provider requires a non-empty api_key` engine_config_error.
2288
+ * engine_config_error as the ai_sdk branch, naming `OPENAI_API_KEY`.
2253
2289
  */
2254
2290
  const create_openai_native_adapter = (init) => {
2255
2291
  const { api_key, base_url } = read_dialect_init(init, DEFAULT_BASE_URL$1);
@@ -2276,7 +2312,7 @@ const create_openai_native_adapter = (init) => {
2276
2312
  */
2277
2313
  const create_openai_ai_sdk_adapter = (init) => {
2278
2314
  const api_key = typeof init.api_key === "string" ? init.api_key : "";
2279
- if (api_key.length === 0) throw new engine_config_error("openai provider requires a non-empty api_key", "openai");
2315
+ if (api_key.length === 0) throw missing_config_error("openai", "api_key", "process.env.OPENAI_API_KEY");
2280
2316
  const base_url = typeof init.base_url === "string" ? init.base_url : void 0;
2281
2317
  const organization = typeof init["organization"] === "string" ? init["organization"] : void 0;
2282
2318
  return {
@@ -2317,7 +2353,7 @@ const SUPPORTED$6 = /* @__PURE__ */ new Set([
2317
2353
  */
2318
2354
  const create_google_adapter = (init) => {
2319
2355
  const api_key = typeof init.api_key === "string" ? init.api_key : "";
2320
- if (api_key.length === 0) throw new engine_config_error("google provider requires a non-empty api_key", "google");
2356
+ if (api_key.length === 0) throw missing_config_error("google", "api_key", "process.env.GOOGLE_API_KEY");
2321
2357
  const base_url = typeof init.base_url === "string" ? init.base_url : void 0;
2322
2358
  return {
2323
2359
  kind: "ai_sdk",
@@ -2505,9 +2541,9 @@ function parse_ollama_tool_call(raw, ordinal, step_index) {
2505
2541
  * its frames before calling it.
2506
2542
  */
2507
2543
  function parse_ollama_chat(payload, step_index) {
2508
- if (payload === null || typeof payload !== "object") throw new provider_error("ollama native: response payload is not a JSON object");
2544
+ if (payload === null || typeof payload !== "object") throw protocol_error("ollama", "response payload is not a JSON object");
2509
2545
  const message = Reflect.get(payload, "message");
2510
- if (message === null || message === void 0 || typeof message !== "object") throw new provider_error("ollama native: response has no message");
2546
+ if (message === null || message === void 0 || typeof message !== "object") throw protocol_error("ollama", "response has no message");
2511
2547
  const content = Reflect.get(message, "content");
2512
2548
  const raw_tool_calls = Reflect.get(message, "tool_calls");
2513
2549
  const tool_calls = Array.isArray(raw_tool_calls) ? raw_tool_calls.map((entry, ordinal) => parse_ollama_tool_call(entry, ordinal, step_index)) : [];
@@ -2600,7 +2636,7 @@ function create_ollama_stream_aggregator(step_index, dispatch) {
2600
2636
  try {
2601
2637
  frame = JSON.parse(line);
2602
2638
  } catch {
2603
- throw new provider_error("ollama native: stream frame is not valid JSON");
2639
+ throw protocol_error("ollama", "stream frame is not valid JSON");
2604
2640
  }
2605
2641
  if (frame === null || typeof frame !== "object") return;
2606
2642
  const error = Reflect.get(frame, "error");
@@ -2665,7 +2701,7 @@ const SUPPORTED$5 = /* @__PURE__ */ new Set([
2665
2701
  */
2666
2702
  const create_ollama_native_adapter = (init) => {
2667
2703
  const raw_base_url = typeof init.base_url === "string" ? init.base_url : "";
2668
- if (raw_base_url.length === 0) throw new engine_config_error("ollama provider requires a non-empty base_url", "ollama");
2704
+ if (raw_base_url.length === 0) throw missing_config_error("ollama", "base_url", "http://localhost:11434");
2669
2705
  const base_url = raw_base_url.replace(/\/+$/, "");
2670
2706
  return {
2671
2707
  kind: "native",
@@ -2687,6 +2723,44 @@ const create_ollama_native_adapter = (init) => {
2687
2723
  //#endregion
2688
2724
  //#region src/engine/providers/ollama.ts
2689
2725
  /**
2726
+ * Give a failure that `ai-sdk-ollama` raised the `url` and `statusCode` that
2727
+ * the AI SDK's own errors carry. The package wraps the `ollama` client's
2728
+ * error, which keeps the status as `status_code` on the `cause`, and names
2729
+ * no URL, so without these the engine can't retry a 429 or a 5xx, and can't
2730
+ * say which address didn't answer.
2731
+ */
2732
+ function add_request_facts(err, url) {
2733
+ if (err === null || typeof err !== "object") return;
2734
+ const cause = Reflect.get(err, "cause");
2735
+ const status = cause !== null && typeof cause === "object" ? Reflect.get(cause, "status_code") : void 0;
2736
+ Object.assign(err, typeof status === "number" ? {
2737
+ url,
2738
+ statusCode: status
2739
+ } : { url });
2740
+ }
2741
+ /**
2742
+ * The package's model, with a `doStream` whose failures carry the request's
2743
+ * URL and status (see add_request_facts), and everything else read through
2744
+ * to the model itself. Only `doStream` is wrapped, since every engine turn
2745
+ * streams, and only its own rejection, which is a failure before the stream
2746
+ * began. A connection that drops mid-stream reaches the stream as it is, so
2747
+ * it's never named as a server that couldn't be reached.
2748
+ */
2749
+ function with_request_facts(model, url) {
2750
+ if (model === null || typeof model !== "object") return model;
2751
+ const do_stream = Reflect.get(model, "doStream");
2752
+ if (typeof do_stream !== "function") return model;
2753
+ const stream = async (...args) => {
2754
+ try {
2755
+ return await Reflect.apply(do_stream, model, args);
2756
+ } catch (err) {
2757
+ add_request_facts(err, url);
2758
+ throw err;
2759
+ }
2760
+ };
2761
+ return Object.create(model, { doStream: { value: stream } });
2762
+ }
2763
+ /**
2690
2764
  * Ollama has no reasoning-effort control on this transport, so every
2691
2765
  * non-`none` level is reported as ignored and no provider option is emitted.
2692
2766
  */
@@ -2719,16 +2793,18 @@ const create_ollama_adapter = (init) => {
2719
2793
  };
2720
2794
  /**
2721
2795
  * Build the Ollama ai_sdk adapter: validates the required base_url and
2722
- * lazily loads ai-sdk-ollama to build models.
2796
+ * lazily loads ai-sdk-ollama to build models, whose failures before a stream
2797
+ * begins carry the chat URL and the status (see with_request_facts).
2723
2798
  */
2724
2799
  const create_ollama_ai_sdk_adapter = (init) => {
2725
2800
  const base_url = typeof init.base_url === "string" ? init.base_url : "";
2726
- if (base_url.length === 0) throw new engine_config_error("ollama provider requires a non-empty base_url", "ollama");
2801
+ if (base_url.length === 0) throw missing_config_error("ollama", "base_url", "http://localhost:11434");
2802
+ const chat_url = `${base_url.replace(/\/+$/, "")}/api/chat`;
2727
2803
  return {
2728
2804
  kind: "ai_sdk",
2729
2805
  name: "ollama",
2730
2806
  async build_model(model_id) {
2731
- return (await load_optional_peer("ai-sdk-ollama")).createOllama({ baseURL: base_url })(model_id);
2807
+ return with_request_facts((await load_optional_peer("ai-sdk-ollama")).createOllama({ baseURL: base_url })(model_id), chat_url);
2732
2808
  },
2733
2809
  translate_effort: translate_ollama_effort,
2734
2810
  normalize_usage: normalize_ollama_usage,
@@ -2776,7 +2852,7 @@ const create_lmstudio_adapter = (init) => {
2776
2852
  */
2777
2853
  const create_lmstudio_native_adapter = (init) => {
2778
2854
  const base_url = typeof init.base_url === "string" ? init.base_url : "";
2779
- if (base_url.length === 0) throw new engine_config_error("lmstudio provider requires a non-empty base_url", "lmstudio");
2855
+ if (base_url.length === 0) throw missing_config_error("lmstudio", "base_url", "http://localhost:1234/v1");
2780
2856
  return create_openai_compatible_adapter({
2781
2857
  name: "lmstudio",
2782
2858
  base_url,
@@ -2794,7 +2870,7 @@ const create_lmstudio_native_adapter = (init) => {
2794
2870
  */
2795
2871
  const create_lmstudio_ai_sdk_adapter = (init) => {
2796
2872
  const base_url = typeof init.base_url === "string" ? init.base_url : "";
2797
- if (base_url.length === 0) throw new engine_config_error("lmstudio provider requires a non-empty base_url", "lmstudio");
2873
+ if (base_url.length === 0) throw missing_config_error("lmstudio", "base_url", "http://localhost:1234/v1");
2798
2874
  return {
2799
2875
  kind: "ai_sdk",
2800
2876
  name: "lmstudio",
@@ -2866,7 +2942,7 @@ const create_openrouter_adapter = (init) => {
2866
2942
  * the cost OpenRouter reports on every response, and caching only when the
2867
2943
  * call or the engine asks for it, since only Claude models take the field.
2868
2944
  * The empty-api_key guard rides on the core, which throws the same
2869
- * `openrouter provider requires a non-empty api_key` engine_config_error.
2945
+ * engine_config_error as the ai_sdk branch, naming `OPENROUTER_API_KEY`.
2870
2946
  */
2871
2947
  const create_openrouter_native_adapter = (init) => {
2872
2948
  const { api_key, base_url } = read_dialect_init(init, DEFAULT_BASE_URL);
@@ -2899,7 +2975,7 @@ const create_openrouter_native_adapter = (init) => {
2899
2975
  */
2900
2976
  const create_openrouter_ai_sdk_adapter = (init) => {
2901
2977
  const api_key = typeof init.api_key === "string" ? init.api_key : "";
2902
- if (api_key.length === 0) throw new engine_config_error("openrouter provider requires a non-empty api_key", "openrouter");
2978
+ if (api_key.length === 0) throw missing_config_error("openrouter", "api_key", "process.env.OPENROUTER_API_KEY");
2903
2979
  const base_url = typeof init.base_url === "string" ? init.base_url : void 0;
2904
2980
  const http_referer = typeof init["http_referer"] === "string" ? init["http_referer"] : void 0;
2905
2981
  const x_title = typeof init["x_title"] === "string" ? init["x_title"] : void 0;
@@ -2945,7 +3021,7 @@ function read_string(init, key) {
2945
3021
  /** Pull the static fields off init, rejecting a missing or non-string region. */
2946
3022
  function read_static_credentials(init) {
2947
3023
  const region = read_string(init, "region") ?? "";
2948
- if (region.length === 0) throw new engine_config_error("bedrock provider requires a non-empty region", "bedrock");
3024
+ if (region.length === 0) throw missing_config_error("bedrock", "region", "process.env.AWS_REGION");
2949
3025
  return {
2950
3026
  region,
2951
3027
  api_key: read_string(init, "api_key"),
@@ -3040,6 +3116,11 @@ const CLI_AUTH_ERROR_PATTERNS = Object.freeze([
3040
3116
  "oauth token has expired",
3041
3117
  "invalid_api_key"
3042
3118
  ]);
3119
+ /**
3120
+ * The command that logs the CLI in again, which an auth failure's message
3121
+ * names and its `refresh_command` carries.
3122
+ */
3123
+ const CLI_REFRESH_COMMAND = "claude auth login";
3043
3124
  const DEFAULT_SETTING_SOURCES = Object.freeze(["project", "local"]);
3044
3125
  //#endregion
3045
3126
  //#region src/engine/providers/claude_cli/auth.ts
@@ -3356,6 +3437,15 @@ function write_greywall_settings(sandbox) {
3356
3437
  * `shell: false` via argv array form; no value is string-interpolated into
3357
3438
  * argv.
3358
3439
  */
3440
+ /**
3441
+ * The message for a command that couldn't be started: the command, Node's
3442
+ * reason, and, when the claude binary itself is missing, how to install it
3443
+ * or point at it. A sandbox wrapper that's missing gets no such advice,
3444
+ * since installing Claude Code won't help it.
3445
+ */
3446
+ function spawn_failure_message(cmd, reason, detail) {
3447
+ return `failed to spawn '${cmd}': ${detail}${reason === "binary_not_found" ? ": install Claude Code, or set providers.claude_cli.binary to where it is" : ""}`;
3448
+ }
3359
3449
  const ALL_REGISTRIES = /* @__PURE__ */ new Set();
3360
3450
  let exit_handler_installed = false;
3361
3451
  /**
@@ -3414,7 +3504,7 @@ function create_spawn_runtime() {
3414
3504
  child = spawn(args.cmd, [...args.argv], spawn_opts);
3415
3505
  } catch (err) {
3416
3506
  const message = err instanceof Error ? err.message : String(err);
3417
- throw new claude_cli_error(spawn_failure_reason, `failed to spawn '${args.cmd}': ${message}`);
3507
+ throw new claude_cli_error(spawn_failure_reason, spawn_failure_message(args.cmd, spawn_failure_reason, message));
3418
3508
  }
3419
3509
  live_children.add(child);
3420
3510
  let spawn_error;
@@ -3456,14 +3546,14 @@ function create_spawn_runtime() {
3456
3546
  };
3457
3547
  if (args.startup_timeout_ms > 0) startup_timer = setTimeout(() => {
3458
3548
  if (first_stdout_byte_seen) return;
3459
- startup_error = new claude_cli_error("startup_timeout", `no stdout within ${String(args.startup_timeout_ms)}ms`);
3549
+ startup_error = new claude_cli_error("startup_timeout", `no stdout within ${String(args.startup_timeout_ms)}ms: raise providers.claude_cli.startup_timeout_ms if Claude Code needs longer to start`);
3460
3550
  escalate("timeout");
3461
3551
  }, args.startup_timeout_ms);
3462
3552
  const arm_stall_timer = () => {
3463
3553
  if (args.stall_timeout_ms <= 0) return;
3464
3554
  clearTimeout(stall_timer);
3465
3555
  stall_timer = setTimeout(() => {
3466
- stall_error = new claude_cli_error("stall_timeout", `no stdout for ${String(args.stall_timeout_ms)}ms`);
3556
+ stall_error = new claude_cli_error("stall_timeout", `no stdout for ${String(args.stall_timeout_ms)}ms: raise providers.claude_cli.stall_timeout_ms if the model's pauses run longer`);
3467
3557
  escalate("timeout");
3468
3558
  }, args.stall_timeout_ms);
3469
3559
  };
@@ -3507,10 +3597,7 @@ function create_spawn_runtime() {
3507
3597
  stdout_lines,
3508
3598
  wait_close: async () => {
3509
3599
  const outcome = await close_promise;
3510
- if (spawn_error !== void 0) {
3511
- const message = spawn_error.message;
3512
- throw new claude_cli_error(spawn_failure_reason, message);
3513
- }
3600
+ if (spawn_error !== void 0) throw new claude_cli_error(spawn_failure_reason, spawn_failure_message(args.cmd, spawn_failure_reason, spawn_error.message));
3514
3601
  if (startup_error !== void 0) throw startup_error;
3515
3602
  if (stall_error !== void 0) throw stall_error;
3516
3603
  if (terminate_reason === "abort") throw new aborted_error("aborted", { reason: args.abort?.reason });
@@ -4497,8 +4584,19 @@ function start_generate_span(trajectory, meta) {
4497
4584
  return trajectory.start_span("engine.generate", { ...meta });
4498
4585
  }
4499
4586
  /**
4587
+ * The meta an engine span ends with when its call throws: the message as
4588
+ * `error`, and the status, attempts, cause kind, and `Retry-After` that a
4589
+ * typed provider error carries (see `failure_meta`).
4590
+ */
4591
+ function error_span_meta(err) {
4592
+ return {
4593
+ error: err instanceof Error ? err.message : String(err),
4594
+ ...failure_meta(err)
4595
+ };
4596
+ }
4597
+ /**
4500
4598
  * Close the `engine.generate` span with usage, finish reason, resolved model,
4501
- * or the error message on failure. `step_count` and `tool_call_count` are the
4599
+ * or the error meta on failure. `step_count` and `tool_call_count` are the
4502
4600
  * call-level totals (model turns and tool executions in the call), the
4503
4601
  * span-attribute analog of the GenAI semconv agent metrics
4504
4602
  * `inference_calls` / `tool_calls`.
@@ -5026,7 +5124,10 @@ function classify_close_error(code, signal, stderr, parsed) {
5026
5124
  const snippet = stderr.slice(0, 512);
5027
5125
  const reported = parsed?.is_error === true ? parsed.final_text.slice(0, 512) : "";
5028
5126
  const detail = snippet.length > 0 ? snippet : reported;
5029
- if (stderr_is_auth_failure(stderr) || parsed?.api_error === "authentication_failed") return new provider_auth_error(PROVIDER_NAME, `claude CLI reported an auth failure: ${detail}`, { refresh_command: "claude auth login" });
5127
+ if (stderr_is_auth_failure(stderr) || parsed?.api_error === "authentication_failed") {
5128
+ const reason = detail.length > 0 ? `${detail}: ` : "";
5129
+ return new provider_auth_error(PROVIDER_NAME, `claude CLI reported an auth failure: ${reason}run ${CLI_REFRESH_COMMAND}`, { refresh_command: CLI_REFRESH_COMMAND });
5130
+ }
5030
5131
  const sandboxed_binary = BWRAP_EXEC_MISSING.exec(stderr)?.[1];
5031
5132
  if (sandboxed_binary !== void 0) return new claude_cli_error("binary_not_found", `bwrap ran but found no claude binary at '${sandboxed_binary}' inside its sandbox, which binds only /usr, /bin, /lib, /lib64, and additional_write_paths: ${snippet}`, { stderr_snippet: snippet });
5032
5133
  if (/bwrap|greywall|sandbox/i.test(stderr) && /not found|no such file|enoent/i.test(stderr)) return new claude_cli_error("sandbox_unavailable", `sandbox binary unavailable: ${snippet}`, { stderr_snippet: snippet });
@@ -6648,8 +6749,7 @@ async function invoke_turn(config, memory, step_index, step_span) {
6648
6749
  });
6649
6750
  return turn;
6650
6751
  } catch (err) {
6651
- const message = err instanceof Error ? err.message : String(err);
6652
- end_step_span(config.trajectory, step_span, { error: message });
6752
+ end_step_span(config.trajectory, step_span, error_span_meta(err));
6653
6753
  throw err;
6654
6754
  }
6655
6755
  }
@@ -7252,15 +7352,43 @@ function resolve_error_status(err) {
7252
7352
  return typeof status_alt === "number" ? status_alt : void 0;
7253
7353
  }
7254
7354
  /**
7255
- * Copy the error's `message` onto a classification record when it is a string,
7256
- * returning the same record for chaining.
7355
+ * The provider's own message: the one a JSON `responseBody` carries, when the
7356
+ * AI SDK attached one, over the error's `message`. A provider package renders
7357
+ * that message from the body, and `@ai-sdk/amazon-bedrock` renders a Bedrock
7358
+ * 503's `{ message }` as `undefined: <message>`, since the body has no
7359
+ * `type`. A native adapter's message already names the provider and the
7360
+ * status it read, so it stays as it is.
7257
7361
  */
7258
- function with_error_message(err, out) {
7362
+ function provider_message(err) {
7363
+ const body = Reflect.get(err, "responseBody");
7364
+ const from_body = typeof body === "string" ? error_body_message(body) : void 0;
7365
+ if (from_body !== void 0) return from_body;
7259
7366
  const message = Reflect.get(err, "message");
7260
- if (typeof message === "string") out["message"] = message;
7367
+ return typeof message === "string" ? message : void 0;
7368
+ }
7369
+ /**
7370
+ * Copy the provider's message onto a classification record when there is one,
7371
+ * and the thrown error itself as its `cause`, so the typed error that
7372
+ * retry_with_policy throws in the end still holds it. Returns the same record
7373
+ * for chaining.
7374
+ */
7375
+ function with_error_source(err, out) {
7376
+ const message = provider_message(err);
7377
+ if (message !== void 0) out["message"] = message;
7378
+ out["cause"] = err;
7261
7379
  return out;
7262
7380
  }
7263
7381
  /**
7382
+ * The body of the failed response: the AI SDK's `responseBody`, or else the
7383
+ * `body` a native adapter attaches, when either is a string.
7384
+ */
7385
+ function response_body(err) {
7386
+ const sdk_body = Reflect.get(err, "responseBody");
7387
+ if (typeof sdk_body === "string") return sdk_body;
7388
+ const body = Reflect.get(err, "body");
7389
+ return typeof body === "string" ? body : void 0;
7390
+ }
7391
+ /**
7264
7392
  * Parse a `Retry-After` value off the error's `responseHeaders`, if present.
7265
7393
  */
7266
7394
  function retry_after_from_error(err) {
@@ -7271,15 +7399,18 @@ function retry_after_from_error(err) {
7271
7399
  }
7272
7400
  /**
7273
7401
  * Build the classification for a retryable status (`rate_limit` for a 429,
7274
- * `provider_5xx` for a 5xx), attaching the message and a parsed `Retry-After`
7275
- * when either is present. HTTP defines the header for a 503 as well as a 429,
7276
- * so a server's wait counts on both.
7402
+ * `provider_5xx` for a 5xx), attaching the message, the response body, and a
7403
+ * parsed `Retry-After` when each is present, and the error as its `cause`.
7404
+ * HTTP defines the header for a 503 as well as a 429, so a server's wait
7405
+ * counts on both.
7277
7406
  */
7278
7407
  function classify_status(err, kind, status) {
7279
- const out = with_error_message(err, {
7408
+ const out = with_error_source(err, {
7280
7409
  kind,
7281
7410
  status
7282
7411
  });
7412
+ const body = response_body(err);
7413
+ if (body !== void 0) out["body"] = body;
7283
7414
  const retry_after_ms = retry_after_from_error(err);
7284
7415
  if (retry_after_ms !== void 0) out["retry_after_ms"] = retry_after_ms;
7285
7416
  return out;
@@ -7293,13 +7424,30 @@ function has_network_code(value) {
7293
7424
  return typeof code === "string" && NETWORK_ERROR_CODES.has(code);
7294
7425
  }
7295
7426
  /**
7296
- * Build the `network` classification when the error or its `cause` carries a
7297
- * known network error code, or `undefined` when neither does. The AI SDK
7298
- * wraps a failed fetch in an `APICallError` whose `cause` holds undici's code.
7427
+ * True when `err`, or any error down its chain of `cause`s, carries a known
7428
+ * network error code. The AI SDK wraps a failed fetch in an `APICallError`
7429
+ * whose `cause` holds undici's code, and `ai-sdk-ollama` wraps fetch's own
7430
+ * `TypeError`, whose `cause` holds it, one level further down. A chain that
7431
+ * leads back to an error already seen ends there.
7432
+ */
7433
+ function has_network_code_in_chain(err) {
7434
+ const seen = /* @__PURE__ */ new Set();
7435
+ let value = err;
7436
+ while (value !== null && typeof value === "object" && !seen.has(value)) {
7437
+ if (has_network_code(value)) return true;
7438
+ seen.add(value);
7439
+ value = Reflect.get(value, "cause");
7440
+ }
7441
+ return false;
7442
+ }
7443
+ /**
7444
+ * Build the `network` classification when the error or an error down its
7445
+ * chain of `cause`s carries a known network error code, or `undefined` when
7446
+ * none does.
7299
7447
  */
7300
7448
  function classify_network_error(err) {
7301
- if (!has_network_code(err) && !has_network_code(Reflect.get(err, "cause"))) return void 0;
7302
- return with_error_message(err, { kind: "network" });
7449
+ if (!has_network_code_in_chain(err)) return void 0;
7450
+ return with_error_source(err, { kind: "network" });
7303
7451
  }
7304
7452
  /**
7305
7453
  * Classify a thrown provider error into the shape `retry_with_policy`
@@ -7308,19 +7456,84 @@ function classify_network_error(err) {
7308
7456
  * Passes through anything that already carries a recognized `kind`.
7309
7457
  * Otherwise inspects `statusCode`/`status`: 429 becomes `rate_limit` and 5xx
7310
7458
  * becomes `provider_5xx`, each reading `Retry-After` off `responseHeaders`
7311
- * when present, and a known network error code (`ECONNRESET`, `ETIMEDOUT`,
7459
+ * and the body off `responseBody` or `body` when present, and a known network
7460
+ * error code (`ECONNRESET`, `ETIMEDOUT`,
7312
7461
  * `ENOTFOUND`, `ECONNREFUSED`, or undici's `UND_ERR_HEADERS_TIMEOUT`,
7313
- * `UND_ERR_BODY_TIMEOUT`, and `UND_ERR_SOCKET`), on the error or on its
7314
- * `cause`, becomes `network`. Anything else passes through unclassified,
7315
- * which `retry_with_policy` treats as non-retryable.
7462
+ * `UND_ERR_BODY_TIMEOUT`, and `UND_ERR_SOCKET`), on the error or anywhere
7463
+ * down its chain of `cause`s, becomes `network`. Anything else passes through unclassified,
7464
+ * which `retry_with_policy` treats as non-retryable. The ai_sdk transport
7465
+ * runs it inside classify_ai_sdk_error, which also types any other 4xx.
7316
7466
  */
7317
7467
  function classify_provider_error(err) {
7318
7468
  if (err === null || typeof err !== "object") return err;
7319
7469
  if (has_retry_kind(err)) return err;
7470
+ return classify_retryable(err) ?? err;
7471
+ }
7472
+ /**
7473
+ * The record for a failure that retries, a 429, a 5xx, or a known network
7474
+ * code, or `undefined` for any other.
7475
+ */
7476
+ function classify_retryable(err) {
7320
7477
  const status = resolve_error_status(err);
7321
7478
  if (status === 429) return classify_status(err, "rate_limit", status);
7322
7479
  if (status !== void 0 && status >= 500 && status < 600) return classify_status(err, "provider_5xx", status);
7323
- return classify_network_error(err) ?? err;
7480
+ return classify_network_error(err);
7481
+ }
7482
+ /**
7483
+ * True when `err` carries any string `kind`, the mark of a Fascicle typed
7484
+ * error and of every record classify_provider_error builds.
7485
+ */
7486
+ function has_kind(err) {
7487
+ return typeof Reflect.get(err, "kind") === "string";
7488
+ }
7489
+ /**
7490
+ * The typed error for an AI SDK failure whose status says a retry won't
7491
+ * help, any 4xx but the 429 that classify_provider_error claims first, or
7492
+ * `undefined` when the failure carries no such status. It's the error the
7493
+ * native transport throws for the same status, with the SDK's error as its
7494
+ * `cause` and the provider's own message read off the body when the SDK
7495
+ * attached one.
7496
+ */
7497
+ function classify_client_status(provider, err) {
7498
+ const status = resolve_error_status(err);
7499
+ if (status === void 0 || status < 400 || status > 499) return void 0;
7500
+ return non_retryable_status_error(provider, status, provider_message(err) ?? "(no detail)", {
7501
+ body: response_body(err),
7502
+ cause: err
7503
+ });
7504
+ }
7505
+ /**
7506
+ * A network record whose message names the URL that the SDK couldn't reach,
7507
+ * in the words the native transport uses, when the SDK's error carries its
7508
+ * `url`, and the record as it is otherwise. The detail comes from the SDK
7509
+ * error's `cause`, the failure that fetch threw, when it has one, since the
7510
+ * SDK's own message only puts `Cannot connect to API:` in front of it.
7511
+ */
7512
+ function name_unreachable_url(provider, err, record) {
7513
+ const url = Reflect.get(err, "url");
7514
+ if (record["kind"] !== "network" || typeof url !== "string") return record;
7515
+ const detail = network_detail(Reflect.get(err, "cause") ?? err);
7516
+ return {
7517
+ ...record,
7518
+ message: unreachable_message(provider, url, detail)
7519
+ };
7520
+ }
7521
+ /**
7522
+ * Build the classifier for one ai_sdk provider. A 429, a 5xx, or a network
7523
+ * failure becomes the record classify_provider_error builds for it, with a
7524
+ * network failure's message naming the URL, and any other 4xx becomes the
7525
+ * typed error the native transport throws, closed over `provider` so that
7526
+ * its message can name the config key to check. Anything already classified
7527
+ * or typed, and anything with no status, passes through as it is.
7528
+ */
7529
+ function classify_ai_sdk_error(provider) {
7530
+ return (err) => {
7531
+ if (err === null || typeof err !== "object" || has_retry_kind(err)) return err;
7532
+ const record = classify_retryable(err);
7533
+ if (record !== void 0) return name_unreachable_url(provider, err, record);
7534
+ if (has_kind(err)) return err;
7535
+ return classify_client_status(provider, err) ?? err;
7536
+ };
7324
7537
  }
7325
7538
  /**
7326
7539
  * Compose the per-attempt turn signal: the user's abort OR'd with a fresh
@@ -7396,7 +7609,10 @@ function retry_turn(call_once, args, stamp, retry_policy, classify, turn_timeout
7396
7609
  });
7397
7610
  if (has_streamed()) {
7398
7611
  const message = err instanceof Error ? err.message : String(err);
7399
- throw new provider_error(`stream interrupted: ${message}`, { cause_kind: "unknown" });
7612
+ throw new provider_error(`stream interrupted: ${message}`, {
7613
+ cause_kind: "unknown",
7614
+ cause: err
7615
+ });
7400
7616
  }
7401
7617
  if (deadline.timed_out()) throw new turn_timeout_error(turn_timeout_ms ?? 0, args.step_index);
7402
7618
  if (err instanceof aborted_error) throw err;
@@ -7429,9 +7645,11 @@ function build_step_timing(started_at, stamp) {
7429
7645
  * turn streams; this builder owns only retry and the first-chunk stamp, which
7430
7646
  * it clears as each attempt starts, and which both makes a failure after a
7431
7647
  * chunk reached a consumer a non-retryable interruption and doubles as
7432
- * StepTiming.first_chunk_ms.
7648
+ * StepTiming.first_chunk_ms. Its classifier is classify_ai_sdk_error, closed
7649
+ * over the call's provider.
7433
7650
  */
7434
7651
  function build_ai_sdk_invoke(cfg) {
7652
+ const classify = classify_ai_sdk_error(cfg.provider);
7435
7653
  return async (args) => {
7436
7654
  const stamp = create_first_chunk_stamp();
7437
7655
  const call_once = (turn_abort) => {
@@ -7443,7 +7661,7 @@ function build_ai_sdk_invoke(cfg) {
7443
7661
  observe_chunk: stamp.observe
7444
7662
  });
7445
7663
  };
7446
- return await retry_turn(call_once, args, stamp, cfg.retry_policy, classify_provider_error, cfg.turn_timeout_ms, cfg.trajectory, cfg.on_chunk_provided);
7664
+ return await retry_turn(call_once, args, stamp, cfg.retry_policy, classify, cfg.turn_timeout_ms, cfg.trajectory, cfg.on_chunk_provided);
7447
7665
  };
7448
7666
  }
7449
7667
  /**
@@ -7739,12 +7957,13 @@ async function build_ai_sdk_transport(cfg) {
7739
7957
  const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
7740
7958
  let ai_sdk_invoke_mod;
7741
7959
  try {
7742
- ai_sdk_invoke_mod = await import("./invoke-DF7YLovL.js");
7960
+ ai_sdk_invoke_mod = await import("./invoke-DnmWf8gE.js");
7743
7961
  } catch (err) {
7744
7962
  throw missing_peer_error("ai", err);
7745
7963
  }
7746
7964
  const { create_ai_sdk_turn } = ai_sdk_invoke_mod;
7747
7965
  return build_ai_sdk_invoke({
7966
+ provider: cfg.target.provider,
7748
7967
  invoke_turn: create_ai_sdk_turn({
7749
7968
  adapter,
7750
7969
  model_id: cfg.target.model_id,
@@ -8100,7 +8319,7 @@ async function generate(opts_in, engine) {
8100
8319
  result.timing = call_timing(started_at);
8101
8320
  return result;
8102
8321
  } catch (err) {
8103
- end_generate_span(trajectory, generate_span, { error: err instanceof Error ? err.message : String(err) });
8322
+ end_generate_span(trajectory, generate_span, error_span_meta(err));
8104
8323
  throw err;
8105
8324
  }
8106
8325
  }
@@ -8209,7 +8428,9 @@ function aggregate_cost(steps, provider) {
8209
8428
  * Each factory validates its init value synchronously, so a bad credential
8210
8429
  * throws here at construction time rather than later; loading the
8211
8430
  * underlying SDK is deferred until the first `generate` call. Throws if
8212
- * `custom_providers` tries to shadow a built-in provider name.
8431
+ * `custom_providers` tries to shadow a built-in provider name, or if a
8432
+ * built-in provider's `base_url` holds credentials, which no built-in
8433
+ * adapter could send.
8213
8434
  */
8214
8435
  function build_provider_adapters(providers, custom_providers) {
8215
8436
  if (custom_providers !== void 0) {
@@ -8219,7 +8440,10 @@ function build_provider_adapters(providers, custom_providers) {
8219
8440
  const adapters = /* @__PURE__ */ new Map();
8220
8441
  for (const [name, init] of Object.entries(providers)) {
8221
8442
  if (init === void 0) continue;
8222
- const adapter = ((custom_providers !== void 0 && Object.hasOwn(custom_providers, name) ? custom_providers[name] : void 0) ?? get_provider_factory(name))(init);
8443
+ const custom = custom_providers !== void 0 && Object.hasOwn(custom_providers, name) ? custom_providers[name] : void 0;
8444
+ const factory = custom ?? get_provider_factory(name);
8445
+ if (custom === void 0) refuse_credentials_in_base_url(name, init);
8446
+ const adapter = factory(init);
8223
8447
  adapters.set(name, adapter);
8224
8448
  }
8225
8449
  return adapters;
@@ -8376,4 +8600,4 @@ function create_engine(config) {
8376
8600
  //#endregion
8377
8601
  export { to_json_schema as n, create_engine as t };
8378
8602
 
8379
- //# sourceMappingURL=engine-DPPqAVdZ.js.map
8603
+ //# sourceMappingURL=engine-BTijBDlY.js.map