fascicle 0.12.1 → 0.12.3

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 (47) hide show
  1. package/CHANGELOG.md +79 -33
  2. package/README.md +13 -13
  3. package/dist/{adapters-hmnJOOgf.js → adapters-CutexJd3.js} +12 -12
  4. package/dist/adapters-CutexJd3.js.map +1 -0
  5. package/dist/adapters.d.ts +10 -10
  6. package/dist/adapters.js +1 -1
  7. package/dist/agents.d.ts +13 -3
  8. package/dist/agents.js +12 -5
  9. package/dist/agents.js.map +1 -1
  10. package/dist/{core-DDRhHu5P.js → core-DdJEhyQc.js} +122 -488
  11. package/dist/core-DdJEhyQc.js.map +1 -0
  12. package/dist/{engine-b4ZH8esY.js → engine-J4lIxpw5.js} +40 -357
  13. package/dist/engine-J4lIxpw5.js.map +1 -0
  14. package/dist/index.d.ts +85 -25
  15. package/dist/index.js +402 -48
  16. package/dist/index.js.map +1 -1
  17. package/dist/{invoke-CyKNhvBw.js → invoke-CH_eJZeS.js} +8 -8
  18. package/dist/{invoke-CyKNhvBw.js.map → invoke-CH_eJZeS.js.map} +1 -1
  19. package/dist/leading_system-BUCT-PwD.js +330 -0
  20. package/dist/leading_system-BUCT-PwD.js.map +1 -0
  21. package/dist/mcp.d.ts +5 -5
  22. package/dist/mcp.js +10 -9
  23. package/dist/mcp.js.map +1 -1
  24. package/dist/otel.d.ts +1 -1
  25. package/dist/otel.js +4 -4
  26. package/dist/otel.js.map +1 -1
  27. package/dist/stdio.d.ts +2 -2
  28. package/dist/stdio.js +2 -2
  29. package/dist/testing.d.ts +1 -1
  30. package/dist/testing.js +3 -2
  31. package/dist/testing.js.map +1 -1
  32. package/dist/{trajectory-cSLNlHzh.d.ts → trajectory-ByoOQZ6T.d.ts} +10 -10
  33. package/dist/trajectory-D1eq9eue.js +81 -0
  34. package/dist/trajectory-D1eq9eue.js.map +1 -0
  35. package/dist/{types-BCtKsxrX.d.ts → types-BK0UW28o.d.ts} +3 -3
  36. package/dist/{types-BqUY6nRX.d.ts → types-DBpU27sQ.d.ts} +7 -2
  37. package/dist/{types-CXBB4aIM.d.ts → types-DU6cvoA4.d.ts} +3 -3
  38. package/dist/ui.d.ts +1 -1
  39. package/dist/ui.js +1 -1
  40. package/dist/ui.js.map +1 -1
  41. package/dist/viewer.d.ts +8 -8
  42. package/dist/viewer.js +16 -15
  43. package/dist/viewer.js.map +1 -1
  44. package/package.json +5 -4
  45. package/dist/adapters-hmnJOOgf.js.map +0 -1
  46. package/dist/core-DDRhHu5P.js.map +0 -1
  47. package/dist/engine-b4ZH8esY.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import { C as compute_backoff, P as aborted_error, g as validate_schema, h as format_schema_issues, w as wait_with_abort } from "./core-DDRhHu5P.js";
1
+ import { O as aborted_error, h as wait_with_abort, m as compute_backoff, o as format_schema_issues, s as validate_schema } from "./core-DdJEhyQc.js";
2
+ import { S as turn_timeout_error, _ as provider_required_error, a as normalize_local_usage, b as tool_approval_denied_error, c as engine_config_error, d as model_required_error, f as on_chunk_error, g as provider_not_configured_error, h as provider_error, i as missing_peer_error, l as engine_disposed_error, m as provider_capability_error, n as default_normalize_usage, o as resolve_transport, p as provider_auth_error, r as load_optional_peer, s as claude_cli_error, t as split_leading_system_run, u as incomplete_generation_error, v as rate_limit_error, x as tool_error, y as schema_validation_error } from "./leading_system-BUCT-PwD.js";
2
3
  import { join } from "node:path";
3
4
  import { mkdtempSync, writeFileSync } from "node:fs";
4
5
  import { tmpdir } from "node:os";
@@ -25,7 +26,7 @@ var schema_not_convertible_error = class extends Error {
25
26
  * JSON Schema emission for schemas that reach a model.
26
27
  *
27
28
  * Standard JSON Schema exposes two directions, `input` and `output`. A tool
28
- * definition describes what the model should *produce*, so fascicle emits the
29
+ * definition describes what the model should *produce*, so Fascicle emits the
29
30
  * input direction: a field with a default is one the model may omit, and
30
31
  * saying otherwise asks it to supply a value the schema already supplies.
31
32
  *
@@ -35,7 +36,7 @@ var schema_not_convertible_error = class extends Error {
35
36
  * schema stops a model inventing one. `close_objects` supplies that guard,
36
37
  * which is also what the strict and constrained-decode modes require. The AI
37
38
  * SDK composes the same two halves for every `kind: 'ai_sdk'` provider, so
38
- * this is what the majority of fascicle's transports already send.
39
+ * this is what the majority of Fascicle's transports already send.
39
40
  */
40
41
  const DEFAULT_TARGET = "draft-2020-12";
41
42
  /**
@@ -287,206 +288,6 @@ function compute_cost(usage, pricing, provider) {
287
288
  return breakdown;
288
289
  }
289
290
  //#endregion
290
- //#region src/engine/errors.ts
291
- var rate_limit_error = class extends Error {
292
- kind = "rate_limit_error";
293
- retry_after_ms;
294
- attempts;
295
- status;
296
- constructor(message, metadata = {}) {
297
- super(message);
298
- this.name = "rate_limit_error";
299
- this.retry_after_ms = metadata.retry_after_ms;
300
- this.attempts = metadata.attempts ?? 0;
301
- this.status = metadata.status;
302
- }
303
- };
304
- var provider_error = class extends Error {
305
- kind = "provider_error";
306
- status;
307
- body;
308
- cause_kind;
309
- constructor(message, metadata = {}) {
310
- super(message);
311
- this.name = "provider_error";
312
- this.status = metadata.status;
313
- this.body = metadata.body;
314
- this.cause_kind = metadata.cause_kind;
315
- }
316
- };
317
- /**
318
- * Turn-timeout expiry. Thrown by the engine-owned retry_turn wrapper when a
319
- * single invoke_turn exceeds `turn_timeout_ms` before any chunk streamed.
320
- * Its `kind` is the RetryFailureKind wire value `'timeout'` (not the class
321
- * name) on purpose: that is the discriminant classify_retryable /
322
- * classify_provider_error already key on, so the shared classifier treats an
323
- * expiry as retryable without any timeout-specific branch. A mid-stream
324
- * expiry never reaches here; retry_turn converts it to a non-retryable
325
- * stream interruption first.
326
- */
327
- var turn_timeout_error = class extends Error {
328
- kind = "timeout";
329
- timeout_ms;
330
- step_index;
331
- constructor(timeout_ms, step_index) {
332
- super(`turn exceeded turn_timeout_ms budget of ${timeout_ms}ms`);
333
- this.name = "turn_timeout_error";
334
- this.timeout_ms = timeout_ms;
335
- this.step_index = step_index;
336
- }
337
- };
338
- var schema_validation_error = class extends Error {
339
- kind = "schema_validation_error";
340
- schema_issues;
341
- raw_text;
342
- constructor(message, schema_issues, raw_text) {
343
- super(message);
344
- this.name = "schema_validation_error";
345
- this.schema_issues = schema_issues;
346
- this.raw_text = raw_text;
347
- }
348
- };
349
- var tool_error = class extends Error {
350
- kind = "tool_error";
351
- tool_name;
352
- tool_call_id;
353
- cause;
354
- constructor(message, metadata) {
355
- super(message);
356
- this.name = "tool_error";
357
- this.tool_name = metadata.tool_name;
358
- this.tool_call_id = metadata.tool_call_id;
359
- this.cause = metadata.cause;
360
- }
361
- };
362
- var tool_approval_denied_error = class extends Error {
363
- kind = "tool_approval_denied_error";
364
- tool_name;
365
- step_index;
366
- tool_call_id;
367
- constructor(message, metadata) {
368
- super(message);
369
- this.name = "tool_approval_denied_error";
370
- this.tool_name = metadata.tool_name;
371
- this.step_index = metadata.step_index;
372
- this.tool_call_id = metadata.tool_call_id;
373
- }
374
- };
375
- var model_required_error = class extends Error {
376
- kind = "model_required_error";
377
- constructor(message = "no model specified: pass `model` to generate() or set `defaults.model` on the engine") {
378
- super(message);
379
- this.name = "model_required_error";
380
- }
381
- };
382
- var provider_not_configured_error = class extends Error {
383
- kind = "provider_not_configured_error";
384
- provider;
385
- constructor(provider) {
386
- super(`provider '${provider}' is not configured on this engine`);
387
- this.name = "provider_not_configured_error";
388
- this.provider = provider;
389
- }
390
- };
391
- /**
392
- * No provider could be resolved for a generate call: several providers are
393
- * configured, the call named none, and no `defaults.provider` is set. Carries
394
- * the configured provider names so the message tells the caller exactly what
395
- * the engine can route to.
396
- */
397
- var provider_required_error = class extends Error {
398
- kind = "provider_required_error";
399
- configured;
400
- constructor(configured) {
401
- super(`no provider specified: pass \`provider\` to generate() or set \`defaults.provider\` (configured: ${configured.join(", ")})`);
402
- this.name = "provider_required_error";
403
- this.configured = configured;
404
- }
405
- };
406
- var engine_config_error = class extends Error {
407
- kind = "engine_config_error";
408
- provider;
409
- constructor(message, provider) {
410
- super(message);
411
- this.name = "engine_config_error";
412
- this.provider = provider;
413
- }
414
- };
415
- var on_chunk_error = class extends Error {
416
- kind = "on_chunk_error";
417
- cause;
418
- constructor(message, cause) {
419
- super(message);
420
- this.name = "on_chunk_error";
421
- this.cause = cause;
422
- }
423
- };
424
- var provider_capability_error = class extends Error {
425
- kind = "provider_capability_error";
426
- provider;
427
- capability;
428
- constructor(provider, capability, detail) {
429
- const suffix = detail !== void 0 ? `: ${detail}` : "";
430
- super(`provider '${provider}' does not support '${capability}'${suffix}`);
431
- this.name = "provider_capability_error";
432
- this.provider = provider;
433
- this.capability = capability;
434
- }
435
- };
436
- var engine_disposed_error = class extends Error {
437
- kind = "engine_disposed_error";
438
- constructor(message = "engine has been disposed; further calls are not permitted") {
439
- super(message);
440
- this.name = "engine_disposed_error";
441
- }
442
- };
443
- var claude_cli_error = class extends Error {
444
- kind = "claude_cli_error";
445
- reason;
446
- status;
447
- stderr_snippet;
448
- constructor(reason, message, metadata = {}) {
449
- super(message);
450
- this.name = "claude_cli_error";
451
- this.reason = reason;
452
- this.status = metadata.status;
453
- this.stderr_snippet = metadata.stderr_snippet;
454
- }
455
- };
456
- var provider_auth_error = class extends Error {
457
- kind = "provider_auth_error";
458
- provider;
459
- refresh_command;
460
- constructor(provider, message, metadata = {}) {
461
- super(message);
462
- this.name = "provider_auth_error";
463
- this.provider = provider;
464
- this.refresh_command = metadata.refresh_command;
465
- }
466
- };
467
- /**
468
- * A generate call that set a schema finished for a reason other than 'stop'
469
- * (content_filter, length, max_steps, tool_calls), so no schema-validated
470
- * value exists and validation was never attempted. Carries the raw model text
471
- * and the last provider-reported payload, so a guardrail trace or other
472
- * block detail stays reachable from the catch. Distinct from
473
- * schema_validation_error, which covers a response that completed normally
474
- * and then failed validation after its repair attempts ran out.
475
- */
476
- var incomplete_generation_error = class extends Error {
477
- kind = "incomplete_generation_error";
478
- finish_reason;
479
- raw_text;
480
- provider_reported;
481
- constructor(finish_reason, raw_text, provider_reported) {
482
- super(`generation finished with '${finish_reason}' before a schema-validated response was produced`);
483
- this.name = "incomplete_generation_error";
484
- this.finish_reason = finish_reason;
485
- this.raw_text = raw_text;
486
- this.provider_reported = provider_reported;
487
- }
488
- };
489
- //#endregion
490
291
  //#region src/engine/retry.ts
491
292
  const DEFAULT_RETRY = {
492
293
  max_attempts: 3,
@@ -529,7 +330,7 @@ function is_retryable(kind, policy) {
529
330
  * The engine's convention, and the opposite of core's propagate-verbatim rule.
530
331
  * Two things depend on the wrap. A bare `controller.abort()` sets
531
332
  * `signal.reason` to a `DOMException`, which is an `Error` on Node, so
532
- * propagating would leak a non-fascicle error out of a boundary documented as
333
+ * propagating would leak a non-Fascicle error out of a boundary documented as
533
334
  * throwing `aborted_error`. And the engine's other abort sites (`generate`,
534
335
  * `tool_loop`, the adapters) wrap in order to attach `step_index` and
535
336
  * `tool_call_in_flight`, which only the construction site knows; propagating
@@ -686,82 +487,6 @@ function classify_retryable(err) {
686
487
  if (kind === "network" || kind === "timeout") return build_retryable_signal(err, kind);
687
488
  }
688
489
  //#endregion
689
- //#region src/engine/providers/types.ts
690
- /**
691
- * Read the `transport` selector off a provider init. Defaults to 'ai_sdk';
692
- * anything but the two known backends throws at construction so a typo
693
- * fails loud instead of silently running the default.
694
- */
695
- function resolve_transport(init, provider) {
696
- const raw = init["transport"];
697
- if (raw === void 0 || raw === "ai_sdk") return "ai_sdk";
698
- if (raw === "native") return "native";
699
- throw new engine_config_error(`${provider} provider: transport must be 'ai_sdk' or 'native', got ${JSON.stringify(raw)}`, provider);
700
- }
701
- /**
702
- * Map raw provider usage to UsageTotals, the mapper most adapters share.
703
- *
704
- * Missing usage zeroes the totals. Optional fields (reasoning and cache
705
- * tokens) are set only when the raw payload carries them, reading the
706
- * flattened field first and the AI SDK's *_details container second.
707
- */
708
- function default_normalize_usage(raw) {
709
- if (raw === void 0) return {
710
- input_tokens: 0,
711
- output_tokens: 0
712
- };
713
- const totals = {
714
- input_tokens: typeof raw.input_tokens === "number" ? raw.input_tokens : 0,
715
- output_tokens: typeof raw.output_tokens === "number" ? raw.output_tokens : 0
716
- };
717
- if (typeof raw.reasoning_tokens === "number") totals.reasoning_tokens = raw.reasoning_tokens;
718
- else if (typeof raw.output_token_details?.reasoning_tokens === "number") totals.reasoning_tokens = raw.output_token_details.reasoning_tokens;
719
- if (typeof raw.cached_input_tokens === "number") totals.cached_input_tokens = raw.cached_input_tokens;
720
- else if (typeof raw.input_token_details?.cached_tokens === "number") totals.cached_input_tokens = raw.input_token_details.cached_tokens;
721
- if (typeof raw.cache_write_tokens === "number") totals.cache_write_tokens = raw.cache_write_tokens;
722
- else if (typeof raw.input_token_details?.cache_creation_input_tokens === "number") totals.cache_write_tokens = raw.input_token_details.cache_creation_input_tokens;
723
- return totals;
724
- }
725
- /**
726
- * Usage mapper for local backends (Ollama, LM Studio) whose servers never
727
- * report cache or reasoning tokens: default-normalize, then strip those
728
- * fields so a stray *_details container cannot invent them.
729
- */
730
- function normalize_local_usage(raw) {
731
- const base = default_normalize_usage(raw);
732
- delete base.cached_input_tokens;
733
- delete base.cache_write_tokens;
734
- delete base.reasoning_tokens;
735
- return base;
736
- }
737
- /**
738
- * Build the standard missing-peer error: names the package and the install
739
- * command so a missing peer is diagnosable from the message alone. Shared so
740
- * every optional-peer failure reads identically, whether the failing
741
- * `import()` names the peer directly (load_optional_peer below) or a local
742
- * module that reaches the peer through its own static import (the ai_sdk
743
- * turn seam in generate.ts, whose dynamic import must stay written in
744
- * generate.ts for its relative specifier to resolve correctly).
745
- */
746
- function missing_peer_error(peer_name, cause) {
747
- const message = `missing peer dependency '${peer_name}'. Install it with your package manager, e.g. \`pnpm add ${peer_name}\` or \`npm install ${peer_name}\`. Cause: ${cause instanceof Error ? cause.message : JSON.stringify(cause)}`;
748
- return new Error(message, { cause });
749
- }
750
- /**
751
- * Dynamically import an optional peer dependency, rethrowing an import
752
- * failure via missing_peer_error so a missing peer is diagnosable from the
753
- * message alone.
754
- */
755
- async function load_optional_peer(specifier) {
756
- let mod;
757
- try {
758
- mod = await import(specifier);
759
- } catch (err) {
760
- throw missing_peer_error(specifier, err);
761
- }
762
- return mod;
763
- }
764
- //#endregion
765
490
  //#region src/engine/providers/native_shared.ts
766
491
  /**
767
492
  * The message under a JSON error envelope's `error` key, or undefined when
@@ -831,8 +556,8 @@ function rethrow_network_failure(err, abort, provider) {
831
556
  * Run one native turn over HTTP: POST the dialect's body, map a non-2xx to
832
557
  * the retry stack's shapes, and hand the response to the dialect's stream or
833
558
  * JSON consumer. `build_body` is called inside the network try/catch on
834
- * purpose: that is where each adapter historically built its body, so a
835
- * mapper throw keeps surfacing through the same path it always did.
559
+ * purpose, so a mapper that throws surfaces as a retryable network failure
560
+ * rather than escaping the turn unclassified.
836
561
  */
837
562
  async function invoke_http_turn(req, provider, request, consume) {
838
563
  let response;
@@ -994,7 +719,7 @@ function read_dialect_init(init, default_base_url) {
994
719
  * wire (any chunk boundary, including mid-line) and returns the data payloads
995
720
  * of every event completed by that chunk; flush() drains an event left open
996
721
  * when the stream ends without a trailing blank line. Only `data:` fields
997
- * matter to the streams fascicle consumes (the Messages API repeats the
722
+ * matter to the streams Fascicle consumes (the Messages API repeats the
998
723
  * event type inside the JSON payload and the Chat Completions stream sends
999
724
  * nothing but data frames), so `event:`/`id:`/`retry:` fields and `:`
1000
725
  * comments are dropped. Multi-line data joins with '\n' per the SSE spec.
@@ -1109,7 +834,7 @@ function to_assistant_blocks(content) {
1109
834
  return blocks;
1110
835
  }
1111
836
  /**
1112
- * Map fascicle Message[] to Messages-API shape: leading system messages hoist
837
+ * Map Fascicle Message[] to Messages-API shape: leading system messages hoist
1113
838
  * to the top-level `system` string, tool messages become `tool_result` blocks
1114
839
  * on a user turn, and empty text blocks are dropped (the API rejects them).
1115
840
  * generate.ts already hoists leading system into TurnRequest.system, so the
@@ -1155,7 +880,7 @@ function to_anthropic_messages(messages) {
1155
880
  };
1156
881
  }
1157
882
  /**
1158
- * Map fascicle tool definitions to the Messages-API tool shape, converting
883
+ * Map Fascicle tool definitions to the Messages-API tool shape, converting
1159
884
  * each input schema to JSON Schema.
1160
885
  */
1161
886
  function to_anthropic_tools(tools) {
@@ -1703,7 +1428,7 @@ function to_assistant_message$1(content) {
1703
1428
  return message;
1704
1429
  }
1705
1430
  /**
1706
- * Map fascicle Message[] to Chat Completions shape. Unlike the Messages API
1431
+ * Map Fascicle Message[] to Chat Completions shape. Unlike the Messages API
1707
1432
  * there is no top-level system field or role-alternation constraint: system
1708
1433
  * messages map in place at any position, and tool results are first-class
1709
1434
  * `tool` role messages keyed by tool_call_id.
@@ -1727,7 +1452,7 @@ function to_chat_messages(messages, provider) {
1727
1452
  });
1728
1453
  }
1729
1454
  /**
1730
- * Map fascicle Tool[] to the Chat Completions function-tool shape,
1455
+ * Map Fascicle Tool[] to the Chat Completions function-tool shape,
1731
1456
  * converting each input schema to JSON Schema.
1732
1457
  */
1733
1458
  function to_chat_tools(tools) {
@@ -1795,7 +1520,7 @@ function read_number(source, key) {
1795
1520
  * Map the Chat Completions usage object to UsageTotals. prompt_tokens is
1796
1521
  * already INCLUSIVE of cached tokens on this API, unlike Anthropic's
1797
1522
  * exclusive accounting, so a straight copy is correct; compute_cost
1798
- * subtracts the cached portion back out. There is no cache-write concept on
1523
+ * subtracts the cached portion back out. No cache-write concept exists on
1799
1524
  * this wire. A missing usage object throws under a strict dialect (a hosted
1800
1525
  * API omitting usage is a broken response) and zeroes under a tolerant one.
1801
1526
  */
@@ -2265,7 +1990,7 @@ function to_assistant_message(content) {
2265
1990
  return message;
2266
1991
  }
2267
1992
  /**
2268
- * Map fascicle Message[] to the /api/chat shape. System messages map in place
1993
+ * Map Fascicle Message[] to the /api/chat shape. System messages map in place
2269
1994
  * (no top-level system field); tool results are `tool` role messages keyed by
2270
1995
  * `tool_name`, since this wire has no tool_call_id to round-trip.
2271
1996
  */
@@ -2925,7 +2650,7 @@ const DEFAULT_SETTING_SOURCES = Object.freeze(["project", "local"]);
2925
2650
  * (greywall/bwrap on PATH, then `claude`) can be resolved and run.
2926
2651
  *
2927
2652
  * Mirrors `STANDARD_KEYS` in `src/forward_standard_env.ts`. Keep the two
2928
- * lists in sync; engine cannot import from fascicle (the umbrella depends
2653
+ * lists in sync; engine cannot import from Fascicle (the umbrella depends
2929
2654
  * on engine, not the other way).
2930
2655
  */
2931
2656
  const STANDARD_ENV_KEYS = [
@@ -3663,7 +3388,7 @@ function create_parser_state() {
3663
3388
  };
3664
3389
  }
3665
3390
  /**
3666
- * Convert the CLI's raw usage fields to fascicle's `UsageTotals` shape.
3391
+ * Convert the CLI's raw usage fields to Fascicle's `UsageTotals` shape.
3667
3392
  *
3668
3393
  * `cache_read_input_tokens` maps to `cached_input_tokens` and
3669
3394
  * `cache_creation_input_tokens` maps to `cache_write_tokens`; both are
@@ -4231,7 +3956,7 @@ function build_generate_result(input) {
4231
3956
  * When every candidate fails, we prefer the schema-validation issues from the
4232
3957
  * FIRST candidate that parsed as JSON: those issues reflect the model's
4233
3958
  * primary output and are what a repair prompt should feed back. Later
4234
- * candidates (e.g. the bracket-slice fallback) often produce noisy issues
3959
+ * candidates (for example, the bracket-slice fallback) often produce noisy issues
4235
3960
  * like "expected object, received array" that misdirect the model. Only when
4236
3961
  * NO candidate parses as JSON do we surface the JSON parse error.
4237
3962
  *
@@ -4749,7 +4474,7 @@ function emit_ignored_options(opts, trajectory) {
4749
4474
  function validate_request(prompt, tools_list, tool_bridge) {
4750
4475
  if (count_user_messages(prompt) >= 2) throw new provider_capability_error(PROVIDER_NAME, "multi_turn_history", "use provider_options.claude_cli.session_id instead");
4751
4476
  if (tools_list.length > 0 && tool_bridge === "forbid") {
4752
- if (tools_list.some((t) => typeof t.execute === "function")) throw new provider_capability_error(PROVIDER_NAME, "tool_execute", "tool_bridge is forbid; tools with execute closures cannot run under claude_cli");
4477
+ if (tools_list.some((t) => typeof t.execute === "function")) throw new provider_capability_error(PROVIDER_NAME, "tool_execute", "tool_bridge is 'forbid' and this tool has an execute closure — set tool_bridge: 'allowlist_only' or drop the closure");
4753
4478
  }
4754
4479
  }
4755
4480
  /**
@@ -4904,7 +4629,7 @@ function record_provider_costs(trajectory, steps) {
4904
4629
  for (const step of steps) if (step.cost !== void 0) record_cost(trajectory, step.index, step.cost, "provider_reported");
4905
4630
  }
4906
4631
  /**
4907
- * Close the eagerly-opened first step span against the steps the CLI
4632
+ * Close the eagerly opened first step span against the steps the CLI
4908
4633
  * reported, then emit paired open/close spans for steps 1..n; those arrive
4909
4634
  * all at once on process close, so their spans carry usage, not timing.
4910
4635
  * Clears `spans.first_step` so the error path cannot close it twice.
@@ -4944,7 +4669,7 @@ async function dispatch_finish(dispatch_chunk, result) {
4944
4669
  }
4945
4670
  /**
4946
4671
  * Close whatever spans are still open with the failure message. A failure
4947
- * after the step spans already closed (e.g. in the finish-chunk dispatch)
4672
+ * after the step spans already closed (for example, in the finish-chunk dispatch)
4948
4673
  * closes only the generate span.
4949
4674
  */
4950
4675
  function close_spans_on_error(trajectory, spans, err) {
@@ -5078,48 +4803,6 @@ function get_provider_factory(name) {
5078
4803
  return factory;
5079
4804
  }
5080
4805
  //#endregion
5081
- //#region src/engine/leading_system.ts
5082
- /**
5083
- * Collapse a leading run of system messages into a single joined string,
5084
- * returning the remaining messages.
5085
- *
5086
- * Both message paths hoist a leading system run out of their list the same way:
5087
- * the engine-Message side (generate.ts split_leading_system_messages) hands the
5088
- * run to a native adapter's TurnRequest.system, and the AI SDK side
5089
- * (providers/ai_sdk/invoke.ts split_leading_system) hands it to the SDK's
5090
- * top-level `instructions` option. Same guard, same '\n\n' join, and the same
5091
- * "return the list untouched when hoisting would leave `messages` empty" rule,
5092
- * since provider APIs reject an empty messages array. They differ only in the
5093
- * element type and how a system message's text is read, so each caller supplies
5094
- * `system_text`; the traversal and its guards live here once.
5095
- */
5096
- function split_leading_system_run(messages, system_text) {
5097
- let run_end = 0;
5098
- const system_parts = [];
5099
- while (run_end < messages.length) {
5100
- const m = messages[run_end];
5101
- if (!is_leading_system(m)) break;
5102
- system_parts.push(system_text(m));
5103
- run_end += 1;
5104
- }
5105
- const rest = messages.slice(run_end);
5106
- if (system_parts.length === 0 || rest.length === 0) return { messages: [...messages] };
5107
- return {
5108
- system: system_parts.join("\n\n"),
5109
- messages: rest
5110
- };
5111
- }
5112
- /**
5113
- * Narrow a possibly-undefined message to the system member of its union.
5114
- *
5115
- * A cast-free type guard so `split_leading_system_run` can hand the narrowed
5116
- * message straight to `system_text` without a `T`-eroding assertion; the
5117
- * optional chain covers the out-of-bounds `undefined` the index access yields.
5118
- */
5119
- function is_leading_system(m) {
5120
- return m?.role === "system";
5121
- }
5122
- //#endregion
5123
4806
  //#region src/engine/merge_defaults.ts
5124
4807
  /**
5125
4808
  * Default-merging helpers for engine-level `EngineDefaults`.
@@ -5131,9 +4814,9 @@ function is_leading_system(m) {
5131
4814
  * `provider_options` needs a two-level merge: outer keys are provider names
5132
4815
  * (`claude_cli`, `anthropic`, ...) and inner records hold per-provider
5133
4816
  * settings. Per-call inner keys override the matching default's inner keys;
5134
- * provider keys unique to either side fall through unchanged. There is no
5135
- * recursion past that second level, so deeper structures replace wholesale
5136
- * rather than merging further.
4817
+ * provider keys unique to either side fall through unchanged. Recursion stops
4818
+ * at that second level, so deeper structures replace wholesale rather than
4819
+ * merging further.
5137
4820
  */
5138
4821
  function merge_provider_options(defaults, call) {
5139
4822
  if (defaults === void 0 && call === void 0) return void 0;
@@ -5724,7 +5407,7 @@ async function request_approval(tool, input, step_index, tool_call_id, abort, on
5724
5407
  step_index,
5725
5408
  tool_call_id
5726
5409
  });
5727
- throw new tool_approval_denied_error(`tool approval required for '${tool.name}' but no on_tool_approval handler was provided`, {
5410
+ throw new tool_approval_denied_error(`tool approval required for '${tool.name}': pass an on_tool_approval handler to generate(), or clear needs_approval on the tool`, {
5728
5411
  tool_name: tool.name,
5729
5412
  step_index,
5730
5413
  tool_call_id
@@ -6237,8 +5920,8 @@ async function record_execute_failure(ctx, tool, raw_call, input, failure) {
6237
5920
  });
6238
5921
  }
6239
5922
  /**
6240
- * Run one raw tool call through the guard chain — final-turn skip, tool
6241
- * lookup, input validation, approval — then execute it. Each guard either
5923
+ * Run one raw tool call through the guard chain (final-turn skip, tool
5924
+ * lookup, input validation, approval), then execute it. Each guard either
6242
5925
  * records the failure (feed-back policy) and stops, or throws (throw
6243
5926
  * policy / abort).
6244
5927
  */
@@ -6301,8 +5984,8 @@ function resolve_turn_finish_reason(ctx, salvaged, turn_finish) {
6301
5984
  return turn_finish;
6302
5985
  }
6303
5986
  /**
6304
- * Build one StepRecord — cost derived and recorded, provider_reported
6305
- * passed through — push it, notify on_finish_step, and close the step span.
5987
+ * Build one StepRecord (cost derived and recorded, provider_reported
5988
+ * passed through), push it, notify on_finish_step, and close the step span.
6306
5989
  */
6307
5990
  function push_step_record(config, acc, step_index, turn, tool_calls, finish_reason, step_span) {
6308
5991
  const record = {
@@ -6719,7 +6402,7 @@ function resolve_turn_config(opts, engine) {
6719
6402
  const effort = opts.effort ?? engine.default_effort;
6720
6403
  const retry_policy = opts.retry ?? engine.default_retry;
6721
6404
  const turn_timeout_ms = opts.turn_timeout_ms ?? engine.default_turn_timeout_ms;
6722
- if (turn_timeout_ms !== void 0 && turn_timeout_ms <= 0) throw new engine_config_error("turn_timeout_ms must be > 0");
6405
+ if (turn_timeout_ms !== void 0 && turn_timeout_ms <= 0) throw new engine_config_error(`turn_timeout_ms must be > 0, got ${String(turn_timeout_ms)}`);
6723
6406
  return {
6724
6407
  effort,
6725
6408
  retry_policy,
@@ -6733,7 +6416,7 @@ function resolve_turn_config(opts, engine) {
6733
6416
  */
6734
6417
  function resolve_salvage_budget(opts, engine) {
6735
6418
  const tool_call_repair_attempts = opts.tool_call_repair_attempts ?? engine.default_tool_call_repair_attempts ?? 0;
6736
- if (tool_call_repair_attempts < 0) throw new engine_config_error("tool_call_repair_attempts must be >= 0");
6419
+ if (tool_call_repair_attempts < 0) throw new engine_config_error(`tool_call_repair_attempts must be >= 0, got ${String(tool_call_repair_attempts)}`);
6737
6420
  return tool_call_repair_attempts > 0 ? { remaining: tool_call_repair_attempts } : void 0;
6738
6421
  }
6739
6422
  /**
@@ -6746,7 +6429,7 @@ function resolve_loop_limits(opts, engine) {
6746
6429
  const schema_repair_attempts = opts.schema_repair_attempts ?? engine.default_schema_repair_attempts ?? 1;
6747
6430
  const salvage_budget = resolve_salvage_budget(opts, engine);
6748
6431
  const max_tool_calls_per_step = opts.max_tool_calls_per_step ?? engine.default_max_tool_calls_per_step;
6749
- if (max_tool_calls_per_step !== void 0 && max_tool_calls_per_step < 1) throw new engine_config_error("max_tool_calls_per_step must be >= 1");
6432
+ if (max_tool_calls_per_step !== void 0 && max_tool_calls_per_step < 1) throw new engine_config_error(`max_tool_calls_per_step must be >= 1, got ${String(max_tool_calls_per_step)}`);
6750
6433
  return {
6751
6434
  max_steps,
6752
6435
  tool_error_policy,
@@ -6768,7 +6451,7 @@ async function build_ai_sdk_transport(cfg) {
6768
6451
  const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
6769
6452
  let ai_sdk_invoke_mod;
6770
6453
  try {
6771
- ai_sdk_invoke_mod = await import("./invoke-CyKNhvBw.js");
6454
+ ai_sdk_invoke_mod = await import("./invoke-CH_eJZeS.js");
6772
6455
  } catch (err) {
6773
6456
  throw missing_peer_error("ai", err);
6774
6457
  }
@@ -6975,7 +6658,7 @@ async function generate(opts_in, engine) {
6975
6658
  if (opts_in.abort?.aborted === true) throw new aborted_error("aborted", { reason: opts_in.abort.reason });
6976
6659
  const { opts, target } = resolve_target(opts_in, engine);
6977
6660
  const adapter = engine.adapters.get(target.provider);
6978
- if (adapter === void 0) throw new provider_not_configured_error(target.provider);
6661
+ if (adapter === void 0) throw new provider_not_configured_error(target.provider, [...engine.adapters.keys()]);
6979
6662
  if (adapter.kind === "external") return adapter.generate(opts, target);
6980
6663
  const trajectory = with_timestamps(opts.trajectory);
6981
6664
  const on_chunk_provided = opts.on_chunk !== void 0;
@@ -7207,9 +6890,9 @@ function resolve_default_scalars(config) {
7207
6890
  function validate_numeric_defaults(defaults) {
7208
6891
  if (defaults === void 0) return;
7209
6892
  const { tool_call_repair_attempts, max_tool_calls_per_step, turn_timeout_ms } = defaults;
7210
- if (tool_call_repair_attempts !== void 0 && tool_call_repair_attempts < 0) throw new engine_config_error("defaults.tool_call_repair_attempts must be >= 0");
7211
- if (max_tool_calls_per_step !== void 0 && max_tool_calls_per_step < 1) throw new engine_config_error("defaults.max_tool_calls_per_step must be >= 1");
7212
- if (turn_timeout_ms !== void 0 && turn_timeout_ms <= 0) throw new engine_config_error("defaults.turn_timeout_ms must be > 0");
6893
+ if (tool_call_repair_attempts !== void 0 && tool_call_repair_attempts < 0) throw new engine_config_error(`defaults.tool_call_repair_attempts must be >= 0, got ${String(tool_call_repair_attempts)}`);
6894
+ if (max_tool_calls_per_step !== void 0 && max_tool_calls_per_step < 1) throw new engine_config_error(`defaults.max_tool_calls_per_step must be >= 1, got ${String(max_tool_calls_per_step)}`);
6895
+ if (turn_timeout_ms !== void 0 && turn_timeout_ms <= 0) throw new engine_config_error(`defaults.turn_timeout_ms must be > 0, got ${String(turn_timeout_ms)}`);
7213
6896
  }
7214
6897
  /**
7215
6898
  * Copy `value` onto `target[key]` only when it is defined, so an absent optional
@@ -7223,8 +6906,8 @@ function assign_if_present(target, key, value) {
7223
6906
  * plus whichever optional `defaults.*` knobs were supplied.
7224
6907
  *
7225
6908
  * The optional defaults form a fixed source-to-target table (`defaults.model` ->
7226
- * `default_model`, and so on); each is folded in only when present, matching the
7227
- * conditional-spread shape this replaced.
6909
+ * `default_model`, and so on), and each is folded in only when present, so an
6910
+ * omitted knob leaves its key off the object rather than present-as-undefined.
7228
6911
  */
7229
6912
  function build_internals(base, defaults) {
7230
6913
  const internals = {
@@ -7312,6 +6995,6 @@ function create_engine(config) {
7312
6995
  };
7313
6996
  }
7314
6997
  //#endregion
7315
- export { schema_validation_error as _, claude_cli_error as a, incomplete_generation_error as c, provider_auth_error as d, provider_capability_error as f, rate_limit_error as g, provider_required_error as h, load_optional_peer as i, model_required_error as l, provider_not_configured_error as m, split_leading_system_run as n, engine_config_error as o, provider_error as p, default_normalize_usage as r, engine_disposed_error as s, create_engine as t, on_chunk_error as u, tool_approval_denied_error as v, tool_error as y };
6998
+ export { create_engine as t };
7316
6999
 
7317
- //# sourceMappingURL=engine-b4ZH8esY.js.map
7000
+ //# sourceMappingURL=engine-J4lIxpw5.js.map