fascicle 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +20 -1
  3. package/dist/acp.d.ts +226 -0
  4. package/dist/acp.js +1886 -0
  5. package/dist/acp.js.map +1 -0
  6. package/dist/adapters.js +1 -2
  7. package/dist/agents.d.ts +1 -1
  8. package/dist/agents.js +1 -1
  9. package/dist/{core-DK7g1Z40.js → core-CDrz0NM1.js} +1 -12
  10. package/dist/core-CDrz0NM1.js.map +1 -0
  11. package/dist/diagram_bin.js +1 -1
  12. package/dist/{engine-BOGuc0X2.js → engine-BDWB2jdn.js} +12 -333
  13. package/dist/engine-BDWB2jdn.js.map +1 -0
  14. package/dist/index.d.ts +468 -622
  15. package/dist/index.js +20 -12
  16. package/dist/index.js.map +1 -1
  17. package/dist/{invoke-Beef3R3X.js → invoke-tjTjZLHj.js} +3 -3
  18. package/dist/{invoke-Beef3R3X.js.map → invoke-tjTjZLHj.js.map} +1 -1
  19. package/dist/json_schema_to_standard-r21kW2LI.js +288 -0
  20. package/dist/json_schema_to_standard-r21kW2LI.js.map +1 -0
  21. package/dist/leading_system-BQe_405V.js +330 -0
  22. package/dist/leading_system-BQe_405V.js.map +1 -0
  23. package/dist/mcp.d.ts +17 -16
  24. package/dist/mcp.js +2 -266
  25. package/dist/mcp.js.map +1 -1
  26. package/dist/search-CqH5hmuF.js +563 -0
  27. package/dist/search-CqH5hmuF.js.map +1 -0
  28. package/dist/search_worker.d.ts +1 -0
  29. package/dist/search_worker.js +19 -0
  30. package/dist/search_worker.js.map +1 -0
  31. package/dist/stdio.js +1 -1
  32. package/dist/testing.d.ts +1 -1
  33. package/dist/testing.js +3 -2
  34. package/dist/testing.js.map +1 -1
  35. package/dist/{types-CZ83Q5nm.d.ts → types-C_Rmcgck.d.ts} +7 -1
  36. package/dist/viewer-app/assets/index-Fnh5HKSU.js +2 -0
  37. package/dist/viewer-app/index.html +1 -1
  38. package/dist/viewer.js +1 -1
  39. package/package.json +30 -19
  40. package/dist/core-DK7g1Z40.js.map +0 -1
  41. package/dist/engine-BOGuc0X2.js.map +0 -1
  42. package/dist/viewer-app/assets/index-DXsB0byD.js +0 -2
@@ -1,4 +1,5 @@
1
- import { h as wait_with_abort, k as aborted_error, m as compute_backoff, o as format_schema_issues, s as validate_schema } from "./core-DK7g1Z40.js";
1
+ import { h as wait_with_abort, k as aborted_error, m as compute_backoff, o as format_schema_issues, s as validate_schema } from "./core-CDrz0NM1.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-BQe_405V.js";
2
3
  import { join } from "node:path";
3
4
  import { mkdtempSync, writeFileSync } from "node:fs";
4
5
  import { tmpdir } from "node:os";
@@ -287,214 +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
- /**
383
- * A generate call named a provider the engine has no adapter for. Carries the
384
- * configured names, and the message repeats them, so a typo is visible from
385
- * the message alone rather than needing the engine config alongside it.
386
- */
387
- var provider_not_configured_error = class extends Error {
388
- kind = "provider_not_configured_error";
389
- provider;
390
- configured;
391
- constructor(provider, configured = []) {
392
- const state = configured.length > 0 ? configured.join(", ") : "none";
393
- super(`provider '${provider}' is not configured on this engine: pass it to create_engine({ providers }) (configured: ${state})`);
394
- this.name = "provider_not_configured_error";
395
- this.provider = provider;
396
- this.configured = configured;
397
- }
398
- };
399
- /**
400
- * No provider could be resolved for a generate call: several providers are
401
- * configured, the call named none, and no `defaults.provider` is set. Carries
402
- * the configured provider names so the message tells the caller exactly what
403
- * the engine can route to.
404
- */
405
- var provider_required_error = class extends Error {
406
- kind = "provider_required_error";
407
- configured;
408
- constructor(configured) {
409
- super(`no provider specified: pass \`provider\` to generate() or set \`defaults.provider\` (configured: ${configured.join(", ")})`);
410
- this.name = "provider_required_error";
411
- this.configured = configured;
412
- }
413
- };
414
- var engine_config_error = class extends Error {
415
- kind = "engine_config_error";
416
- provider;
417
- constructor(message, provider) {
418
- super(message);
419
- this.name = "engine_config_error";
420
- this.provider = provider;
421
- }
422
- };
423
- var on_chunk_error = class extends Error {
424
- kind = "on_chunk_error";
425
- cause;
426
- constructor(message, cause) {
427
- super(message);
428
- this.name = "on_chunk_error";
429
- this.cause = cause;
430
- }
431
- };
432
- var provider_capability_error = class extends Error {
433
- kind = "provider_capability_error";
434
- provider;
435
- capability;
436
- constructor(provider, capability, detail) {
437
- const suffix = detail !== void 0 ? `: ${detail}` : "";
438
- super(`provider '${provider}' does not support '${capability}'${suffix}`);
439
- this.name = "provider_capability_error";
440
- this.provider = provider;
441
- this.capability = capability;
442
- }
443
- };
444
- var engine_disposed_error = class extends Error {
445
- kind = "engine_disposed_error";
446
- constructor(message = "engine has been disposed: build a new one with create_engine()") {
447
- super(message);
448
- this.name = "engine_disposed_error";
449
- }
450
- };
451
- var claude_cli_error = class extends Error {
452
- kind = "claude_cli_error";
453
- reason;
454
- status;
455
- stderr_snippet;
456
- constructor(reason, message, metadata = {}) {
457
- super(message);
458
- this.name = "claude_cli_error";
459
- this.reason = reason;
460
- this.status = metadata.status;
461
- this.stderr_snippet = metadata.stderr_snippet;
462
- }
463
- };
464
- var provider_auth_error = class extends Error {
465
- kind = "provider_auth_error";
466
- provider;
467
- refresh_command;
468
- constructor(provider, message, metadata = {}) {
469
- super(message);
470
- this.name = "provider_auth_error";
471
- this.provider = provider;
472
- this.refresh_command = metadata.refresh_command;
473
- }
474
- };
475
- /**
476
- * A generate call that set a schema finished for a reason other than 'stop'
477
- * (content_filter, length, max_steps, tool_calls), so no schema-validated
478
- * value exists and validation was never attempted. Carries the raw model text
479
- * and the last provider-reported payload, so a guardrail trace or other
480
- * block detail stays reachable from the catch. Distinct from
481
- * schema_validation_error, which covers a response that completed normally
482
- * and then failed validation after its repair attempts ran out.
483
- */
484
- var incomplete_generation_error = class extends Error {
485
- kind = "incomplete_generation_error";
486
- finish_reason;
487
- raw_text;
488
- provider_reported;
489
- constructor(finish_reason, raw_text, provider_reported) {
490
- super(`generation finished with '${finish_reason}' before a schema-validated response was produced`);
491
- this.name = "incomplete_generation_error";
492
- this.finish_reason = finish_reason;
493
- this.raw_text = raw_text;
494
- this.provider_reported = provider_reported;
495
- }
496
- };
497
- //#endregion
498
291
  //#region src/engine/retry.ts
499
292
  const DEFAULT_RETRY = {
500
293
  max_attempts: 3,
@@ -716,82 +509,6 @@ function classify_retryable(err) {
716
509
  if (kind === "network" || kind === "timeout") return build_retryable_signal(err, kind);
717
510
  }
718
511
  //#endregion
719
- //#region src/engine/providers/types.ts
720
- /**
721
- * Read the `transport` selector off a provider init. Defaults to 'ai_sdk';
722
- * anything but the two known backends throws at construction so a typo
723
- * fails loud instead of silently running the default.
724
- */
725
- function resolve_transport(init, provider) {
726
- const raw = init["transport"];
727
- if (raw === void 0 || raw === "ai_sdk") return "ai_sdk";
728
- if (raw === "native") return "native";
729
- throw new engine_config_error(`${provider} provider: transport must be 'ai_sdk' or 'native', got ${JSON.stringify(raw)}`, provider);
730
- }
731
- /**
732
- * Map raw provider usage to UsageTotals, the mapper most adapters share.
733
- *
734
- * Missing usage zeroes the totals. Optional fields (reasoning and cache
735
- * tokens) are set only when the raw payload carries them, reading the
736
- * flattened field first and the AI SDK's *_details container second.
737
- */
738
- function default_normalize_usage(raw) {
739
- if (raw === void 0) return {
740
- input_tokens: 0,
741
- output_tokens: 0
742
- };
743
- const totals = {
744
- input_tokens: typeof raw.input_tokens === "number" ? raw.input_tokens : 0,
745
- output_tokens: typeof raw.output_tokens === "number" ? raw.output_tokens : 0
746
- };
747
- if (typeof raw.reasoning_tokens === "number") totals.reasoning_tokens = raw.reasoning_tokens;
748
- else if (typeof raw.output_token_details?.reasoning_tokens === "number") totals.reasoning_tokens = raw.output_token_details.reasoning_tokens;
749
- if (typeof raw.cached_input_tokens === "number") totals.cached_input_tokens = raw.cached_input_tokens;
750
- else if (typeof raw.input_token_details?.cached_tokens === "number") totals.cached_input_tokens = raw.input_token_details.cached_tokens;
751
- if (typeof raw.cache_write_tokens === "number") totals.cache_write_tokens = raw.cache_write_tokens;
752
- else if (typeof raw.input_token_details?.cache_creation_input_tokens === "number") totals.cache_write_tokens = raw.input_token_details.cache_creation_input_tokens;
753
- return totals;
754
- }
755
- /**
756
- * Usage mapper for local backends (Ollama, LM Studio) whose servers never
757
- * report cache or reasoning tokens: default-normalize, then strip those
758
- * fields so a stray *_details container cannot invent them.
759
- */
760
- function normalize_local_usage(raw) {
761
- const base = default_normalize_usage(raw);
762
- delete base.cached_input_tokens;
763
- delete base.cache_write_tokens;
764
- delete base.reasoning_tokens;
765
- return base;
766
- }
767
- /**
768
- * Build the standard missing-peer error: names the package and the install
769
- * command so a missing peer is diagnosable from the message alone. Shared so
770
- * every optional-peer failure reads identically, whether the failing
771
- * `import()` names the peer directly (load_optional_peer below) or a local
772
- * module that reaches the peer through its own static import (the ai_sdk
773
- * turn seam in generate.ts, whose dynamic import must stay written in
774
- * generate.ts for its relative specifier to resolve correctly).
775
- */
776
- function missing_peer_error(peer_name, cause) {
777
- 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)}`;
778
- return new Error(message, { cause });
779
- }
780
- /**
781
- * Dynamically import an optional peer dependency, rethrowing an import
782
- * failure via missing_peer_error so a missing peer is diagnosable from the
783
- * message alone.
784
- */
785
- async function load_optional_peer(specifier) {
786
- let mod;
787
- try {
788
- mod = await import(specifier);
789
- } catch (err) {
790
- throw missing_peer_error(specifier, err);
791
- }
792
- return mod;
793
- }
794
- //#endregion
795
512
  //#region src/engine/providers/native_shared.ts
796
513
  /**
797
514
  * The message under a JSON error envelope's `error` key, or undefined when
@@ -5249,48 +4966,6 @@ function get_provider_factory(name) {
5249
4966
  return factory;
5250
4967
  }
5251
4968
  //#endregion
5252
- //#region src/engine/leading_system.ts
5253
- /**
5254
- * Collapse a leading run of system messages into a single joined string,
5255
- * returning the remaining messages.
5256
- *
5257
- * Both message paths hoist a leading system run out of their list the same way:
5258
- * the engine-Message side (generate.ts split_leading_system_messages) hands the
5259
- * run to a native adapter's TurnRequest.system, and the AI SDK side
5260
- * (providers/ai_sdk/invoke.ts split_leading_system) hands it to the SDK's
5261
- * top-level `instructions` option. Same guard, same '\n\n' join, and the same
5262
- * "return the list untouched when hoisting would leave `messages` empty" rule,
5263
- * since provider APIs reject an empty messages array. They differ only in the
5264
- * element type and how a system message's text is read, so each caller supplies
5265
- * `system_text`; the traversal and its guards live here once.
5266
- */
5267
- function split_leading_system_run(messages, system_text) {
5268
- let run_end = 0;
5269
- const system_parts = [];
5270
- while (run_end < messages.length) {
5271
- const m = messages[run_end];
5272
- if (!is_leading_system(m)) break;
5273
- system_parts.push(system_text(m));
5274
- run_end += 1;
5275
- }
5276
- const rest = messages.slice(run_end);
5277
- if (system_parts.length === 0 || rest.length === 0) return { messages: [...messages] };
5278
- return {
5279
- system: system_parts.join("\n\n"),
5280
- messages: rest
5281
- };
5282
- }
5283
- /**
5284
- * Narrow a possibly undefined message to the system member of its union.
5285
- *
5286
- * A cast-free type guard so `split_leading_system_run` can hand the narrowed
5287
- * message straight to `system_text` without a `T`-eroding assertion; the
5288
- * optional chain covers the out-of-bounds `undefined` the index access yields.
5289
- */
5290
- function is_leading_system(m) {
5291
- return m?.role === "system";
5292
- }
5293
- //#endregion
5294
4969
  //#region src/engine/merge_defaults.ts
5295
4970
  /**
5296
4971
  * Default-merging helpers for engine-level `EngineDefaults`.
@@ -5905,6 +5580,7 @@ async function request_approval(tool, input, step_index, tool_call_id, abort, on
5905
5580
  tool_name: tool.name,
5906
5581
  input,
5907
5582
  step_index,
5583
+ tool_call_id,
5908
5584
  abort
5909
5585
  }));
5910
5586
  const approved = await new Promise((resolve, reject) => {
@@ -6751,7 +6427,10 @@ function retry_turn(call_once, args, first_chunk_at, retry_policy, classify, tur
6751
6427
  reason: args.abort.reason,
6752
6428
  step_index: args.step_index
6753
6429
  });
6754
- if (has_streamed()) throw new provider_error(`stream interrupted: ${err instanceof Error ? err.message : String(err)}`, { cause_kind: "unknown" });
6430
+ if (has_streamed()) {
6431
+ const message = err instanceof Error ? err.message : String(err);
6432
+ throw new provider_error(`stream interrupted: ${message}`, { cause_kind: "unknown" });
6433
+ }
6755
6434
  if (deadline.timed_out()) throw new turn_timeout_error(turn_timeout_ms ?? 0, args.step_index);
6756
6435
  if (err instanceof aborted_error) throw err;
6757
6436
  throw classify(err);
@@ -6964,7 +6643,7 @@ async function build_ai_sdk_transport(cfg) {
6964
6643
  const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
6965
6644
  let ai_sdk_invoke_mod;
6966
6645
  try {
6967
- ai_sdk_invoke_mod = await import("./invoke-Beef3R3X.js");
6646
+ ai_sdk_invoke_mod = await import("./invoke-tjTjZLHj.js");
6968
6647
  } catch (err) {
6969
6648
  throw missing_peer_error("ai", err);
6970
6649
  }
@@ -7025,9 +6704,9 @@ function build_loop_config(cfg) {
7025
6704
  const resolve_pricing = () => {
7026
6705
  return cfg.pricing[pricing_key(target.provider, target.model_id)];
7027
6706
  };
7028
- const dispatch_chunk = cfg.on_chunk_provided ? async (chunk) => {
6707
+ const dispatch_chunk = cfg.on_chunk_provided ? (async (chunk) => {
7029
6708
  await cfg.dispatcher.dispatch(chunk);
7030
- } : void 0;
6709
+ }) : void 0;
7031
6710
  return {
7032
6711
  invoke_once: cfg.invoke_once,
7033
6712
  messages: cfg.messages,
@@ -7528,6 +7207,6 @@ function create_engine(config) {
7528
7207
  };
7529
7208
  }
7530
7209
  //#endregion
7531
- 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 };
7210
+ export { create_engine as t };
7532
7211
 
7533
- //# sourceMappingURL=engine-BOGuc0X2.js.map
7212
+ //# sourceMappingURL=engine-BDWB2jdn.js.map