fascicle 0.17.8 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +25 -2
- package/dist/AGENTS.md +23 -11
- package/dist/acp.d.ts +3 -17
- package/dist/acp.js +25 -44
- package/dist/acp.js.map +1 -1
- package/dist/{adapters-CDUzZlby.js → adapters-CpKpDk7r.js} +9 -17
- package/dist/{adapters-CDUzZlby.js.map → adapters-CpKpDk7r.js.map} +1 -1
- package/dist/adapters.d.ts +1 -13
- package/dist/adapters.js +1 -1
- package/dist/agents.d.ts +3 -5
- package/dist/agents.js +2 -3
- package/dist/{console-CdB4pcFO.js → console-B1ozi_ii.js} +2 -3
- package/dist/{console-CdB4pcFO.js.map → console-B1ozi_ii.js.map} +1 -1
- package/dist/{core-Bfzt55Fl.js → core-BH7sWpEG.js} +34 -66
- package/dist/{core-Bfzt55Fl.js.map → core-BH7sWpEG.js.map} +1 -1
- package/dist/diagram_bin.d.ts +0 -2
- package/dist/diagram_bin.js +3 -5
- package/dist/diagram_bin.js.map +1 -1
- package/dist/{engine-D7ANZ8eq.js → engine-fOjYHcv6.js} +42 -79
- package/dist/{engine-D7ANZ8eq.js.map → engine-fOjYHcv6.js.map} +1 -1
- package/dist/index.d.ts +4 -98
- package/dist/index.js +27 -47
- package/dist/index.js.map +1 -1
- package/dist/{invoke-DnmWf8gE.js → invoke-7iu8db6V.js} +19 -12
- package/dist/{invoke-DnmWf8gE.js.map → invoke-7iu8db6V.js.map} +1 -1
- package/dist/{json_schema_to_standard-C4F4lXHE.js → json_schema_to_standard-BstoXjM8.js} +3 -4
- package/dist/{json_schema_to_standard-C4F4lXHE.js.map → json_schema_to_standard-BstoXjM8.js.map} +1 -1
- package/dist/{leading_system-CHSYz0h9.js → leading_system-BeQUSAim.js} +6 -10
- package/dist/{leading_system-CHSYz0h9.js.map → leading_system-BeQUSAim.js.map} +1 -1
- package/dist/{mcp-8mKK7eDY.js → mcp-CHJ88HiG.js} +9 -14
- package/dist/{mcp-8mKK7eDY.js.map → mcp-CHJ88HiG.js.map} +1 -1
- package/dist/mcp.d.ts +3 -11
- package/dist/mcp.js +2 -2
- package/dist/otel.d.ts +1 -5
- package/dist/otel.js +3 -6
- package/dist/otel.js.map +1 -1
- package/dist/{records-1HU7mWXf.js → records-Btlmvunj.js} +2 -3
- package/dist/{records-1HU7mWXf.js.map → records-Btlmvunj.js.map} +1 -1
- package/dist/{search-DjhdMsJ8.js → search-BZagxXtd.js} +7 -11
- package/dist/{search-DjhdMsJ8.js.map → search-BZagxXtd.js.map} +1 -1
- package/dist/search_worker.js +2 -3
- package/dist/stdio.d.ts +2 -6
- package/dist/stdio.js +5 -7
- package/dist/stdio.js.map +1 -1
- package/dist/testing.d.ts +2 -18
- package/dist/testing.js +12 -21
- package/dist/testing.js.map +1 -1
- package/dist/{trajectory-DeURWIhj.js → trajectory-CkCFZWNR.js} +2 -3
- package/dist/{trajectory-DeURWIhj.js.map → trajectory-CkCFZWNR.js.map} +1 -1
- package/dist/{trajectory-BKGNxi7u.d.ts → trajectory-Dt0-A7kb.d.ts} +1 -3
- package/dist/{types-CPqLZOEr.d.ts → types-BUXt_zgJ.d.ts} +1 -3
- package/dist/{types-BK0UW28o.d.ts → types-CvghbZ0x.d.ts} +1 -5
- package/dist/{types-C6PB2aP0.d.ts → types-Dk9tLpUq.d.ts} +3 -9
- package/dist/ui.d.ts +1 -3
- package/dist/ui.js +1 -2
- package/dist/viewer-app/assets/index-D8Tb3drm.js +4 -0
- package/dist/viewer-app/index.html +1 -1
- package/dist/viewer.d.ts +1 -11
- package/dist/viewer.js +8 -14
- package/dist/viewer.js.map +1 -1
- package/dist/web.d.ts +83 -0
- package/dist/web.js +2888 -0
- package/dist/web.js.map +1 -0
- package/package.json +34 -28
- package/dist/viewer-app/assets/index-YrQFld-l.js +0 -4
package/dist/diagram_bin.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/diagram_bin.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* The process side of the fascicle-diagram bin: the real streams, and module
|
|
4
3
|
* loading through the project's own `tsx`.
|
|
@@ -20,5 +19,4 @@
|
|
|
20
19
|
* an unhandled EPIPE.
|
|
21
20
|
*/
|
|
22
21
|
export declare function run_diagram_bin(argv: readonly string[]): Promise<void>;
|
|
23
|
-
//#endregion
|
|
24
22
|
//# sourceMappingURL=diagram_bin.d.ts.map
|
package/dist/diagram_bin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as is_step, k as describe } from "./core-
|
|
1
|
+
import { A as is_step, k as describe } from "./core-BH7sWpEG.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
|
-
|
|
6
|
+
// src/diagram_cli.ts
|
|
7
7
|
/**
|
|
8
8
|
* fascicle-diagram CLI.
|
|
9
9
|
*
|
|
@@ -191,8 +191,7 @@ async function build(value) {
|
|
|
191
191
|
function message_of(err) {
|
|
192
192
|
return err instanceof Error ? err.message : String(err);
|
|
193
193
|
}
|
|
194
|
-
|
|
195
|
-
//#region src/diagram_bin.ts
|
|
194
|
+
// src/diagram_bin.ts
|
|
196
195
|
/**
|
|
197
196
|
* The process side of the fascicle-diagram bin: the real streams, and module
|
|
198
197
|
* loading through the project's own `tsx`.
|
|
@@ -267,7 +266,6 @@ function as_record(value) {
|
|
|
267
266
|
return typeof value === "object" && value !== null ? { ...value } : {};
|
|
268
267
|
}
|
|
269
268
|
if (process.argv[1] !== void 0 && process.argv[1] === fileURLToPath(import.meta.url)) run_diagram_bin(process.argv.slice(2));
|
|
270
|
-
//#endregion
|
|
271
269
|
export { run_diagram_bin };
|
|
272
270
|
|
|
273
271
|
//# sourceMappingURL=diagram_bin.js.map
|
package/dist/diagram_bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagram_bin.js","names":[],"sources":["../src/diagram_cli.ts","../src/diagram_bin.ts"],"sourcesContent":["/**\n * fascicle-diagram CLI.\n *\n * fascicle-diagram <module> print the diagram of the module's `flow`\n * fascicle-diagram <module> --export <name> read another export instead\n *\n * Flags: --export <name> --width <n> --prefix <text> --replays --internals --outline --help\n *\n * The export is a Step, or a function that builds one with no arguments,\n * which is where an app wires its flow to stub dependencies so that drawing\n * it needs no credentials. The diagram is `describe.diagram` of that Step, so\n * it is what the code builds today and can be compared with the header in\n * `flow.ts` at a glance. `--outline` prints the plain `describe` outline\n * instead, with each node's kind, id, and config, which is the view to read\n * when the diagram hides something.\n *\n * This file holds every decision the command makes and touches nothing of\n * the process: output and module loading arrive through `DiagramCliIo`.\n * diagram_bin.ts binds that io to the real streams and to the project's\n * `tsx`, and is the entry that the package's bin shim runs.\n */\n\nimport { resolve } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { describe, is_step } from '#core'\nimport type { AnyStep, DiagramOptions } from '#core'\n\nexport type DiagramCliIo = {\n readonly out: (text: string) => void\n readonly err: (text: string) => void\n /** Import the module at an absolute path and return its exports. */\n readonly load: (path: string) => Promise<Readonly<Record<string, unknown>>>\n}\n\ntype CliArgs = {\n readonly module: string\n readonly export_name: string\n readonly outline: boolean\n readonly options: DiagramOptions\n}\n\ntype Parsed =\n | { readonly kind: 'help' }\n | { readonly kind: 'usage'; readonly message: string }\n | { readonly kind: 'run'; readonly args: CliArgs }\n\nconst HELP = `\\\nfascicle-diagram prints a flow as an annotated box-drawing tree.\n\nUsage:\n fascicle-diagram <module> draw the module's \\`flow\\` export\n fascicle-diagram <module> --export <name> draw another export instead\n\nThe export is a Step, or a function that builds one with no arguments.\n\nOptions:\n --export <name> the export to draw (default flow)\n --width <n> wrap descriptions so no line runs wider than n\n --prefix <text> start every line with text, for example ' * '\n --replays mark the steps a resumed run would pay for again\n --internals draw a named composite's internal steps, not only its parts\n --outline print describe()'s plain outline, with ids and config,\n instead of the diagram (no --width, --replays, or --internals)\n --help show this message\n`\n\n// The flags that only the diagram reads, which `--outline` refuses.\nconst DIAGRAM_ONLY = ['width', 'replays', 'internals'] as const\n\n/**\n * Run the CLI over `argv` and resolve to its exit code: 0 once the diagram is\n * printed, 1 when the module cannot be loaded or holds no Step, and 2 for a\n * usage error. Output and loading go through `io`, so the caller owns the\n * process.\n */\nexport async function run_diagram_cli(argv: readonly string[], io: DiagramCliIo): Promise<number> {\n const parsed = parse(argv)\n if (parsed.kind === 'help') {\n io.out(HELP)\n return 0\n }\n if (parsed.kind === 'usage') {\n io.err(`fascicle-diagram: ${parsed.message}\\n\\n${HELP}`)\n return 2\n }\n const { module, export_name, outline, options } = parsed.args\n const path = resolve(module)\n let exports: Readonly<Record<string, unknown>>\n try {\n exports = await io.load(path)\n } catch (err) {\n io.err(`fascicle-diagram: could not load ${module}: ${message_of(err)}\\n`)\n return 1\n }\n if (!Object.hasOwn(exports, export_name)) {\n const names = Object.keys(exports).join(', ') || 'nothing'\n io.err(\n `fascicle-diagram: ${module} has no export named ${export_name}: pass --export <name> (it exports ${names})\\n`,\n )\n return 1\n }\n let flow: unknown\n try {\n flow = await build(exports[export_name])\n } catch (err) {\n io.err(\n `fascicle-diagram: calling ${export_name}() in ${module} threw: ${message_of(err)}\\n` +\n 'Export a function that builds the flow with no arguments, wired to stub dependencies.\\n',\n )\n return 1\n }\n if (!is_step(flow)) {\n io.err(\n `fascicle-diagram: ${export_name} in ${module} is not a Step: export the flow itself, or a function that builds it with no arguments\\n`,\n )\n return 1\n }\n const text = outline ? outline_of(flow, options.prefix) : describe.diagram(flow, options)\n io.out(`${text}\\n`)\n return 0\n}\n\n/**\n * Render `describe`'s plain outline of `flow`, starting every line with\n * `prefix` the way the diagram does.\n */\nfunction outline_of(flow: AnyStep, prefix = ''): string {\n return describe(flow)\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n')\n}\n\n/**\n * Parse argv into a run request, a help request, or a usage error. Unknown\n * flags and a missing module are usage errors, and so is a width that is not\n * a positive integer. `--outline` with an option that only the diagram reads\n * is one too, since the outline would drop it without a word.\n */\nfunction parse(argv: readonly string[]): Parsed {\n let parsed: ReturnType<typeof parse_flags>\n try {\n parsed = parse_flags(argv)\n } catch (err) {\n return { kind: 'usage', message: message_of(err) }\n }\n const { values, positionals } = parsed\n if (values.help === true) return { kind: 'help' }\n const [module, ...extra] = positionals\n if (module === undefined) return { kind: 'usage', message: 'a <module> to draw is required' }\n if (extra.length > 0) return { kind: 'usage', message: `expected one <module>, got ${positionals.join(' ')}` }\n const outline = values.outline === true\n if (outline) {\n const dropped = DIAGRAM_ONLY.filter((flag) => values[flag] !== undefined)\n if (dropped.length > 0) {\n const flags = dropped.map((flag) => `--${flag}`).join(', ')\n return { kind: 'usage', message: `--outline can't take ${flags}, which only the diagram reads` }\n }\n }\n const options: { width?: number; prefix?: string; replays?: boolean; internals?: boolean } = {}\n if (values.width !== undefined) {\n const width = Number(values.width)\n if (!Number.isInteger(width) || width <= 0) {\n return { kind: 'usage', message: `invalid --width '${values.width}': expected a positive integer` }\n }\n options.width = width\n }\n if (values.prefix !== undefined) options.prefix = values.prefix\n if (values.replays === true) options.replays = true\n if (values.internals === true) options.internals = true\n return { kind: 'run', args: { module, export_name: values.export ?? 'flow', outline, options } }\n}\n\n/**\n * Read the CLI's flags with `node:util`'s strict parser, which throws on a\n * flag it does not know.\n */\nfunction parse_flags(argv: readonly string[]) {\n return parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: {\n export: { type: 'string' },\n width: { type: 'string' },\n prefix: { type: 'string' },\n replays: { type: 'boolean' },\n internals: { type: 'boolean' },\n outline: { type: 'boolean' },\n help: { type: 'boolean' },\n },\n })\n}\n\n/**\n * The Step an export stands for: the export itself, or what calling it with\n * no arguments returns (awaited, so an async builder works too).\n */\nasync function build(value: unknown): Promise<unknown> {\n return typeof value === 'function' ? await value() : value\n}\n\n/**\n * Render a thrown value as its message.\n */\nfunction message_of(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n","/**\n * The process side of the fascicle-diagram bin: the real streams, and module\n * loading through the project's own `tsx`.\n *\n * Every decision the command makes lives in diagram_cli.ts, which is unit\n * tested through an injected io. This file only binds that io to the process,\n * so it is exercised by spawning it (__tests__/diagram_bin.test.ts) and kept\n * out of mutation testing, which cannot see a spawned child's coverage.\n *\n * A TypeScript module loads through `tsx` because Node's built-in type\n * stripping cannot follow the `./flow.js` specifiers that point at `.ts`\n * files under NodeNext resolution. Anything else, or a project without\n * `tsx`, goes through a plain `import()`.\n */\n\nimport { createRequire } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { run_diagram_cli } from './diagram_cli.js'\n\nconst TS_MODULE = /\\.[cm]?tsx?$/\n\n/**\n * Run the fascicle-diagram command over `argv` against the real process, and\n * leave its exit code on `process.exitCode`. A reader that closes the pipe\n * early (`| head`) ends the output quietly instead of crashing the command on\n * an unhandled EPIPE.\n */\nexport async function run_diagram_bin(argv: readonly string[]): Promise<void> {\n process.stdout.once('error', (err: NodeJS.ErrnoException) => {\n if (err.code !== 'EPIPE') throw err\n })\n process.exitCode = await run_diagram_cli(argv, {\n out: (text) => process.stdout.write(text),\n err: (text) => process.stderr.write(text),\n load: load_module,\n })\n}\n\n/**\n * Import the module at `path`. A TypeScript module goes through the `tsx`\n * that the project installs, looked up from the module's own directory and\n * then from the working directory. Everything else is a plain dynamic import.\n */\nasync function load_module(path: string): Promise<Readonly<Record<string, unknown>>> {\n const url = pathToFileURL(path).href\n if (!TS_MODULE.test(path)) return as_record(await import(url))\n const tsx = find_tsx([path, resolve('package.json')])\n if (tsx === undefined) return import_without_tsx(url)\n const api: unknown = await import(pathToFileURL(tsx).href)\n const ts_import = as_record(api)['tsImport']\n if (typeof ts_import !== 'function') return as_record(await import(url))\n return as_record(await ts_import(url, import.meta.url))\n}\n\n/**\n * Import a TypeScript module with Node's own type stripping, which handles\n * only erasable syntax and specifiers that name real files. A failure says\n * that tsx is the fix, since this path is taken only when none was found.\n */\nasync function import_without_tsx(url: string): Promise<Readonly<Record<string, unknown>>> {\n try {\n return as_record(await import(url))\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err)\n throw new Error(`${reason} (no tsx was found to load TypeScript: install it with pnpm add -D tsx)`, {\n cause: err,\n })\n }\n}\n\n/**\n * Resolve tsx's programmatic API from the first of `origins` that can see it,\n * or `undefined` when none can.\n */\nfunction find_tsx(origins: readonly string[]): string | undefined {\n for (const origin of origins) {\n try {\n return createRequire(origin).resolve('tsx/esm/api')\n } catch {\n // Not installed where this origin looks; try the next one.\n }\n }\n return undefined\n}\n\n/**\n * View a loaded module namespace as a record of its exports.\n */\nfunction as_record(value: unknown): Readonly<Record<string, unknown>> {\n return typeof value === 'object' && value !== null ? { ...value } : {}\n}\n\n// Auto-run only when this file is the entry script (`tsx src/diagram_bin.ts`),\n// never when the bundle that contains it is imported. The path comparison is\n// the same guard the viewer CLI uses.\nconst invoked_directly =\n process.argv[1] !== undefined && process.argv[1] === fileURLToPath(import.meta.url)\n\nif (invoked_directly) void run_diagram_bin(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAqBb,MAAM,eAAe;CAAC;CAAS;CAAW;AAAW;;;;;;;AAQrD,eAAsB,gBAAgB,MAAyB,IAAmC;CAChG,MAAM,SAAS,MAAM,IAAI;CACzB,IAAI,OAAO,SAAS,QAAQ;EAC1B,GAAG,IAAI,IAAI;EACX,OAAO;CACT;CACA,IAAI,OAAO,SAAS,SAAS;EAC3B,GAAG,IAAI,qBAAqB,OAAO,QAAQ,MAAM,MAAM;EACvD,OAAO;CACT;CACA,MAAM,EAAE,QAAQ,aAAa,SAAS,YAAY,OAAO;CACzD,MAAM,OAAO,QAAQ,MAAM;CAC3B,IAAI;CACJ,IAAI;EACF,UAAU,MAAM,GAAG,KAAK,IAAI;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;;;;AAKA,SAAS,UAAU,OAAmD;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC;AACvE;AAQA,IAFE,QAAQ,KAAK,OAAO,KAAA,KAAa,QAAQ,KAAK,OAAO,cAAc,YAAY,GAAG,GAE9D,gBAAqB,QAAQ,KAAK,MAAM,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"diagram_bin.js","names":[],"sources":["../src/diagram_cli.ts","../src/diagram_bin.ts"],"sourcesContent":["/**\n * fascicle-diagram CLI.\n *\n * fascicle-diagram <module> print the diagram of the module's `flow`\n * fascicle-diagram <module> --export <name> read another export instead\n *\n * Flags: --export <name> --width <n> --prefix <text> --replays --internals --outline --help\n *\n * The export is a Step, or a function that builds one with no arguments,\n * which is where an app wires its flow to stub dependencies so that drawing\n * it needs no credentials. The diagram is `describe.diagram` of that Step, so\n * it is what the code builds today and can be compared with the header in\n * `flow.ts` at a glance. `--outline` prints the plain `describe` outline\n * instead, with each node's kind, id, and config, which is the view to read\n * when the diagram hides something.\n *\n * This file holds every decision the command makes and touches nothing of\n * the process: output and module loading arrive through `DiagramCliIo`.\n * diagram_bin.ts binds that io to the real streams and to the project's\n * `tsx`, and is the entry that the package's bin shim runs.\n */\n\nimport { resolve } from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { describe, is_step } from '#core'\nimport type { AnyStep, DiagramOptions } from '#core'\n\nexport type DiagramCliIo = {\n readonly out: (text: string) => void\n readonly err: (text: string) => void\n /** Import the module at an absolute path and return its exports. */\n readonly load: (path: string) => Promise<Readonly<Record<string, unknown>>>\n}\n\ntype CliArgs = {\n readonly module: string\n readonly export_name: string\n readonly outline: boolean\n readonly options: DiagramOptions\n}\n\ntype Parsed =\n | { readonly kind: 'help' }\n | { readonly kind: 'usage'; readonly message: string }\n | { readonly kind: 'run'; readonly args: CliArgs }\n\nconst HELP = `\\\nfascicle-diagram prints a flow as an annotated box-drawing tree.\n\nUsage:\n fascicle-diagram <module> draw the module's \\`flow\\` export\n fascicle-diagram <module> --export <name> draw another export instead\n\nThe export is a Step, or a function that builds one with no arguments.\n\nOptions:\n --export <name> the export to draw (default flow)\n --width <n> wrap descriptions so no line runs wider than n\n --prefix <text> start every line with text, for example ' * '\n --replays mark the steps a resumed run would pay for again\n --internals draw a named composite's internal steps, not only its parts\n --outline print describe()'s plain outline, with ids and config,\n instead of the diagram (no --width, --replays, or --internals)\n --help show this message\n`\n\n// The flags that only the diagram reads, which `--outline` refuses.\nconst DIAGRAM_ONLY = ['width', 'replays', 'internals'] as const\n\n/**\n * Run the CLI over `argv` and resolve to its exit code: 0 once the diagram is\n * printed, 1 when the module cannot be loaded or holds no Step, and 2 for a\n * usage error. Output and loading go through `io`, so the caller owns the\n * process.\n */\nexport async function run_diagram_cli(argv: readonly string[], io: DiagramCliIo): Promise<number> {\n const parsed = parse(argv)\n if (parsed.kind === 'help') {\n io.out(HELP)\n return 0\n }\n if (parsed.kind === 'usage') {\n io.err(`fascicle-diagram: ${parsed.message}\\n\\n${HELP}`)\n return 2\n }\n const { module, export_name, outline, options } = parsed.args\n const path = resolve(module)\n let exports: Readonly<Record<string, unknown>>\n try {\n exports = await io.load(path)\n } catch (err) {\n io.err(`fascicle-diagram: could not load ${module}: ${message_of(err)}\\n`)\n return 1\n }\n if (!Object.hasOwn(exports, export_name)) {\n const names = Object.keys(exports).join(', ') || 'nothing'\n io.err(\n `fascicle-diagram: ${module} has no export named ${export_name}: pass --export <name> (it exports ${names})\\n`,\n )\n return 1\n }\n let flow: unknown\n try {\n flow = await build(exports[export_name])\n } catch (err) {\n io.err(\n `fascicle-diagram: calling ${export_name}() in ${module} threw: ${message_of(err)}\\n` +\n 'Export a function that builds the flow with no arguments, wired to stub dependencies.\\n',\n )\n return 1\n }\n if (!is_step(flow)) {\n io.err(\n `fascicle-diagram: ${export_name} in ${module} is not a Step: export the flow itself, or a function that builds it with no arguments\\n`,\n )\n return 1\n }\n const text = outline ? outline_of(flow, options.prefix) : describe.diagram(flow, options)\n io.out(`${text}\\n`)\n return 0\n}\n\n/**\n * Render `describe`'s plain outline of `flow`, starting every line with\n * `prefix` the way the diagram does.\n */\nfunction outline_of(flow: AnyStep, prefix = ''): string {\n return describe(flow)\n .split('\\n')\n .map((line) => `${prefix}${line}`)\n .join('\\n')\n}\n\n/**\n * Parse argv into a run request, a help request, or a usage error. Unknown\n * flags and a missing module are usage errors, and so is a width that is not\n * a positive integer. `--outline` with an option that only the diagram reads\n * is one too, since the outline would drop it without a word.\n */\nfunction parse(argv: readonly string[]): Parsed {\n let parsed: ReturnType<typeof parse_flags>\n try {\n parsed = parse_flags(argv)\n } catch (err) {\n return { kind: 'usage', message: message_of(err) }\n }\n const { values, positionals } = parsed\n if (values.help === true) return { kind: 'help' }\n const [module, ...extra] = positionals\n if (module === undefined) return { kind: 'usage', message: 'a <module> to draw is required' }\n if (extra.length > 0) return { kind: 'usage', message: `expected one <module>, got ${positionals.join(' ')}` }\n const outline = values.outline === true\n if (outline) {\n const dropped = DIAGRAM_ONLY.filter((flag) => values[flag] !== undefined)\n if (dropped.length > 0) {\n const flags = dropped.map((flag) => `--${flag}`).join(', ')\n return { kind: 'usage', message: `--outline can't take ${flags}, which only the diagram reads` }\n }\n }\n const options: { width?: number; prefix?: string; replays?: boolean; internals?: boolean } = {}\n if (values.width !== undefined) {\n const width = Number(values.width)\n if (!Number.isInteger(width) || width <= 0) {\n return { kind: 'usage', message: `invalid --width '${values.width}': expected a positive integer` }\n }\n options.width = width\n }\n if (values.prefix !== undefined) options.prefix = values.prefix\n if (values.replays === true) options.replays = true\n if (values.internals === true) options.internals = true\n return { kind: 'run', args: { module, export_name: values.export ?? 'flow', outline, options } }\n}\n\n/**\n * Read the CLI's flags with `node:util`'s strict parser, which throws on a\n * flag it does not know.\n */\nfunction parse_flags(argv: readonly string[]) {\n return parseArgs({\n args: [...argv],\n allowPositionals: true,\n options: {\n export: { type: 'string' },\n width: { type: 'string' },\n prefix: { type: 'string' },\n replays: { type: 'boolean' },\n internals: { type: 'boolean' },\n outline: { type: 'boolean' },\n help: { type: 'boolean' },\n },\n })\n}\n\n/**\n * The Step an export stands for: the export itself, or what calling it with\n * no arguments returns (awaited, so an async builder works too).\n */\nasync function build(value: unknown): Promise<unknown> {\n return typeof value === 'function' ? await value() : value\n}\n\n/**\n * Render a thrown value as its message.\n */\nfunction message_of(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n","/**\n * The process side of the fascicle-diagram bin: the real streams, and module\n * loading through the project's own `tsx`.\n *\n * Every decision the command makes lives in diagram_cli.ts, which is unit\n * tested through an injected io. This file only binds that io to the process,\n * so it is exercised by spawning it (__tests__/diagram_bin.test.ts) and kept\n * out of mutation testing, which cannot see a spawned child's coverage.\n *\n * A TypeScript module loads through `tsx` because Node's built-in type\n * stripping cannot follow the `./flow.js` specifiers that point at `.ts`\n * files under NodeNext resolution. Anything else, or a project without\n * `tsx`, goes through a plain `import()`.\n */\n\nimport { createRequire } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { run_diagram_cli } from './diagram_cli.js'\n\nconst TS_MODULE = /\\.[cm]?tsx?$/\n\n/**\n * Run the fascicle-diagram command over `argv` against the real process, and\n * leave its exit code on `process.exitCode`. A reader that closes the pipe\n * early (`| head`) ends the output quietly instead of crashing the command on\n * an unhandled EPIPE.\n */\nexport async function run_diagram_bin(argv: readonly string[]): Promise<void> {\n process.stdout.once('error', (err: NodeJS.ErrnoException) => {\n if (err.code !== 'EPIPE') throw err\n })\n process.exitCode = await run_diagram_cli(argv, {\n out: (text) => process.stdout.write(text),\n err: (text) => process.stderr.write(text),\n load: load_module,\n })\n}\n\n/**\n * Import the module at `path`. A TypeScript module goes through the `tsx`\n * that the project installs, looked up from the module's own directory and\n * then from the working directory. Everything else is a plain dynamic import.\n */\nasync function load_module(path: string): Promise<Readonly<Record<string, unknown>>> {\n const url = pathToFileURL(path).href\n if (!TS_MODULE.test(path)) return as_record(await import(url))\n const tsx = find_tsx([path, resolve('package.json')])\n if (tsx === undefined) return import_without_tsx(url)\n const api: unknown = await import(pathToFileURL(tsx).href)\n const ts_import = as_record(api)['tsImport']\n if (typeof ts_import !== 'function') return as_record(await import(url))\n return as_record(await ts_import(url, import.meta.url))\n}\n\n/**\n * Import a TypeScript module with Node's own type stripping, which handles\n * only erasable syntax and specifiers that name real files. A failure says\n * that tsx is the fix, since this path is taken only when none was found.\n */\nasync function import_without_tsx(url: string): Promise<Readonly<Record<string, unknown>>> {\n try {\n return as_record(await import(url))\n } catch (err) {\n const reason = err instanceof Error ? err.message : String(err)\n throw new Error(`${reason} (no tsx was found to load TypeScript: install it with pnpm add -D tsx)`, {\n cause: err,\n })\n }\n}\n\n/**\n * Resolve tsx's programmatic API from the first of `origins` that can see it,\n * or `undefined` when none can.\n */\nfunction find_tsx(origins: readonly string[]): string | undefined {\n for (const origin of origins) {\n try {\n return createRequire(origin).resolve('tsx/esm/api')\n } catch {\n // Not installed where this origin looks; try the next one.\n }\n }\n return undefined\n}\n\n/**\n * View a loaded module namespace as a record of its exports.\n */\nfunction as_record(value: unknown): Readonly<Record<string, unknown>> {\n return typeof value === 'object' && value !== null ? { ...value } : {}\n}\n\n// Auto-run only when this file is the entry script (`tsx src/diagram_bin.ts`),\n// never when the bundle that contains it is imported. The path comparison is\n// the same guard the viewer CLI uses.\nconst invoked_directly =\n process.argv[1] !== undefined && process.argv[1] === fileURLToPath(import.meta.url)\n\nif (invoked_directly) void run_diagram_bin(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAqBb,MAAM,eAAe;CAAC;CAAS;CAAW;AAAW;;;;;;;AAQrD,eAAsB,gBAAgB,MAAyB,IAAmC;CAChG,MAAM,SAAS,MAAM,IAAI;CACzB,IAAI,OAAO,SAAS,QAAQ;EAC1B,GAAG,IAAI,IAAI;EACX,OAAO;CACT;CACA,IAAI,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AAO,GAAG;EAC9D,MAAM,IAAI,MAAM,GAAG,OAAO,0EAA0E,EAClG,OAAO,IACT,CAAC;CACH;AACF;;;;;AAMA,SAAS,SAAS,SAAgD;CAChE,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,OAAO,cAAc,MAAM,CAAC,CAAC,QAAQ,aAAa;CACpD,QAAQ,CAER;AAGJ;;;;AAKA,SAAS,UAAU,OAAmD;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC;AACvE;AAQA,IAFE,QAAQ,KAAK,OAAO,KAAA,KAAa,QAAQ,KAAK,OAAO,cAAc,YAAY,GAAG,GAE9D,gBAAqB,QAAQ,KAAK,MAAM,CAAC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
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-BeQUSAim.js";
|
|
2
|
+
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-BH7sWpEG.js";
|
|
3
|
+
import { n as is_record$1 } from "./records-Btlmvunj.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
|
-
|
|
8
|
+
// src/schema/errors.ts
|
|
9
9
|
/**
|
|
10
10
|
* The one error this zone raises.
|
|
11
11
|
*
|
|
@@ -21,8 +21,7 @@ var schema_not_convertible_error = class extends Error {
|
|
|
21
21
|
this.vendor = vendor;
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
|
|
25
|
-
//#region src/schema/json_schema.ts
|
|
24
|
+
// src/schema/json_schema.ts
|
|
26
25
|
/**
|
|
27
26
|
* JSON Schema emission for schemas that reach a model.
|
|
28
27
|
*
|
|
@@ -137,8 +136,7 @@ function strip_meta_keys(json) {
|
|
|
137
136
|
const { $schema: _schema, $id: _id, ...rest } = json;
|
|
138
137
|
return rest;
|
|
139
138
|
}
|
|
140
|
-
|
|
141
|
-
//#region src/engine/pricing.ts
|
|
139
|
+
// src/engine/pricing.ts
|
|
142
140
|
const FREE_PROVIDERS = /* @__PURE__ */ new Set(["ollama", "lmstudio"]);
|
|
143
141
|
const CACHE_READ_MULTIPLIER = .1;
|
|
144
142
|
const CACHE_WRITE_MULTIPLIER = 1.25;
|
|
@@ -411,8 +409,7 @@ function decompose_total_cost(total_cost_usd, usage) {
|
|
|
411
409
|
if (cache_write > 0) breakdown.cache_write_usd = cache_write_usd_raw;
|
|
412
410
|
return breakdown;
|
|
413
411
|
}
|
|
414
|
-
|
|
415
|
-
//#region src/engine/retry.ts
|
|
412
|
+
// src/engine/retry.ts
|
|
416
413
|
const DEFAULT_RETRY = {
|
|
417
414
|
max_attempts: 4,
|
|
418
415
|
initial_delay_ms: 1e3,
|
|
@@ -724,8 +721,7 @@ function classify_retryable$1(err) {
|
|
|
724
721
|
retryable.cause = err instanceof Error ? err : Reflect.get(err, "cause");
|
|
725
722
|
return retryable;
|
|
726
723
|
}
|
|
727
|
-
|
|
728
|
-
//#region src/engine/providers/sse_native.ts
|
|
724
|
+
// src/engine/providers/sse_native.ts
|
|
729
725
|
/**
|
|
730
726
|
* Incremental SSE decoder shared by the native (raw-HTTP) provider adapters.
|
|
731
727
|
*/
|
|
@@ -759,8 +755,7 @@ function create_sse_decoder() {
|
|
|
759
755
|
}
|
|
760
756
|
}, close_event);
|
|
761
757
|
}
|
|
762
|
-
|
|
763
|
-
//#region src/engine/providers/anthropic_native.ts
|
|
758
|
+
// src/engine/providers/anthropic_native.ts
|
|
764
759
|
/**
|
|
765
760
|
* Native Anthropic provider adapter (raw HTTP).
|
|
766
761
|
*
|
|
@@ -1499,8 +1494,7 @@ const create_anthropic_native_adapter = (init) => {
|
|
|
1499
1494
|
supports: (capability) => SUPPORTED$10.has(capability)
|
|
1500
1495
|
};
|
|
1501
1496
|
};
|
|
1502
|
-
|
|
1503
|
-
//#region src/engine/providers/anthropic.ts
|
|
1497
|
+
// src/engine/providers/anthropic.ts
|
|
1504
1498
|
/**
|
|
1505
1499
|
* Normalize Anthropic usage via the shared default mapper, since the AI SDK
|
|
1506
1500
|
* already reports cache and reasoning tokens in the fields the default reads.
|
|
@@ -1588,8 +1582,7 @@ const create_anthropic_ai_sdk_adapter = (init) => {
|
|
|
1588
1582
|
translate_cache: translate_anthropic_cache
|
|
1589
1583
|
};
|
|
1590
1584
|
};
|
|
1591
|
-
|
|
1592
|
-
//#region src/engine/providers/openai_compatible_native.ts
|
|
1585
|
+
// src/engine/providers/openai_compatible_native.ts
|
|
1593
1586
|
/**
|
|
1594
1587
|
* OpenAI-compatible native core: one `chat/completions` implementation
|
|
1595
1588
|
* talking raw HTTP, shared by every OpenAI-compatible provider.
|
|
@@ -2249,8 +2242,7 @@ const create_openai_compatible_adapter = (dialect) => {
|
|
|
2249
2242
|
supports: (capability) => SUPPORTED$8.has(capability)
|
|
2250
2243
|
};
|
|
2251
2244
|
};
|
|
2252
|
-
|
|
2253
|
-
//#region src/engine/providers/openai.ts
|
|
2245
|
+
// src/engine/providers/openai.ts
|
|
2254
2246
|
/**
|
|
2255
2247
|
* Normalize OpenAI's raw usage payload into UsageTotals.
|
|
2256
2248
|
*/
|
|
@@ -2331,8 +2323,7 @@ const create_openai_ai_sdk_adapter = (init) => {
|
|
|
2331
2323
|
prompt_cache: "automatic"
|
|
2332
2324
|
};
|
|
2333
2325
|
};
|
|
2334
|
-
|
|
2335
|
-
//#region src/engine/providers/google.ts
|
|
2326
|
+
// src/engine/providers/google.ts
|
|
2336
2327
|
/**
|
|
2337
2328
|
* Normalize Google's raw usage payload into UsageTotals.
|
|
2338
2329
|
*/
|
|
@@ -2370,8 +2361,7 @@ const create_google_adapter = (init) => {
|
|
|
2370
2361
|
prompt_cache: "automatic"
|
|
2371
2362
|
};
|
|
2372
2363
|
};
|
|
2373
|
-
|
|
2374
|
-
//#region src/engine/providers/ollama_native.ts
|
|
2364
|
+
// src/engine/providers/ollama_native.ts
|
|
2375
2365
|
/**
|
|
2376
2366
|
* Map user message content to a plain string, the shape this wire expects
|
|
2377
2367
|
* (no part-array support). Image parts throw a capability error: they are
|
|
@@ -2720,8 +2710,7 @@ const create_ollama_native_adapter = (init) => {
|
|
|
2720
2710
|
supports: (capability) => SUPPORTED$5.has(capability)
|
|
2721
2711
|
};
|
|
2722
2712
|
};
|
|
2723
|
-
|
|
2724
|
-
//#region src/engine/providers/ollama.ts
|
|
2713
|
+
// src/engine/providers/ollama.ts
|
|
2725
2714
|
/**
|
|
2726
2715
|
* Give a failure that `ai-sdk-ollama` raised the `url` and `statusCode` that
|
|
2727
2716
|
* the AI SDK's own errors carry. The package wraps the `ollama` client's
|
|
@@ -2811,8 +2800,7 @@ const create_ollama_ai_sdk_adapter = (init) => {
|
|
|
2811
2800
|
supports: (capability) => SUPPORTED$4.has(capability)
|
|
2812
2801
|
};
|
|
2813
2802
|
};
|
|
2814
|
-
|
|
2815
|
-
//#region src/engine/providers/lmstudio.ts
|
|
2803
|
+
// src/engine/providers/lmstudio.ts
|
|
2816
2804
|
/**
|
|
2817
2805
|
* LM Studio has no reasoning-effort control, so every non-`none` level is
|
|
2818
2806
|
* reported as ignored and no provider option is emitted.
|
|
@@ -2886,8 +2874,7 @@ const create_lmstudio_ai_sdk_adapter = (init) => {
|
|
|
2886
2874
|
supports: (capability) => SUPPORTED$3.has(capability)
|
|
2887
2875
|
};
|
|
2888
2876
|
};
|
|
2889
|
-
|
|
2890
|
-
//#region src/engine/providers/openrouter.ts
|
|
2877
|
+
// src/engine/providers/openrouter.ts
|
|
2891
2878
|
/**
|
|
2892
2879
|
* Map an EffortLevel to OpenRouter's `reasoning.effort` provider option.
|
|
2893
2880
|
*
|
|
@@ -2997,8 +2984,7 @@ const create_openrouter_ai_sdk_adapter = (init) => {
|
|
|
2997
2984
|
supports: (capability) => SUPPORTED$2.has(capability)
|
|
2998
2985
|
};
|
|
2999
2986
|
};
|
|
3000
|
-
|
|
3001
|
-
//#region src/engine/providers/bedrock.ts
|
|
2987
|
+
// src/engine/providers/bedrock.ts
|
|
3002
2988
|
/**
|
|
3003
2989
|
* Normalize Bedrock's raw usage payload into UsageTotals.
|
|
3004
2990
|
*/
|
|
@@ -3098,8 +3084,7 @@ const create_bedrock_adapter = (init) => {
|
|
|
3098
3084
|
supports: (capability) => SUPPORTED$1.has(capability)
|
|
3099
3085
|
};
|
|
3100
3086
|
};
|
|
3101
|
-
|
|
3102
|
-
//#region src/engine/providers/claude_cli/constants.ts
|
|
3087
|
+
// src/engine/providers/claude_cli/constants.ts
|
|
3103
3088
|
/**
|
|
3104
3089
|
* Frozen constants for the claude_cli provider: startup and idle defaults,
|
|
3105
3090
|
* the escalation window, and the auth failure pattern list.
|
|
@@ -3139,8 +3124,7 @@ const CLAUDE_CODE_SANDBOX_MIN_VERSION = Object.freeze([
|
|
|
3139
3124
|
314
|
|
3140
3125
|
]);
|
|
3141
3126
|
const DEFAULT_SETTING_SOURCES = Object.freeze(["project", "local"]);
|
|
3142
|
-
|
|
3143
|
-
//#region src/engine/providers/claude_cli/auth.ts
|
|
3127
|
+
// src/engine/providers/claude_cli/auth.ts
|
|
3144
3128
|
/**
|
|
3145
3129
|
* Authentication enforcement for the claude_cli adapter.
|
|
3146
3130
|
*
|
|
@@ -3263,8 +3247,7 @@ function stderr_is_auth_failure(stderr) {
|
|
|
3263
3247
|
for (const pattern of CLI_AUTH_ERROR_PATTERNS) if (lower.includes(pattern.toLowerCase())) return true;
|
|
3264
3248
|
return false;
|
|
3265
3249
|
}
|
|
3266
|
-
|
|
3267
|
-
//#region src/engine/providers/claude_cli/settings.ts
|
|
3250
|
+
// src/engine/providers/claude_cli/settings.ts
|
|
3268
3251
|
/**
|
|
3269
3252
|
* Claude Code's own sandbox for the claude_cli adapter.
|
|
3270
3253
|
*
|
|
@@ -3368,8 +3351,7 @@ function render_sandbox_settings(sandbox) {
|
|
|
3368
3351
|
disableAllHooks: true
|
|
3369
3352
|
});
|
|
3370
3353
|
}
|
|
3371
|
-
|
|
3372
|
-
//#region src/engine/providers/claude_cli/argv.ts
|
|
3354
|
+
// src/engine/providers/claude_cli/argv.ts
|
|
3373
3355
|
/**
|
|
3374
3356
|
* Assemble the full argv array for one `claude` CLI invocation.
|
|
3375
3357
|
*
|
|
@@ -3443,8 +3425,7 @@ function merge_allowed_tools(call_allowlist, tool_names) {
|
|
|
3443
3425
|
for (const n of tool_names) push_unique(n);
|
|
3444
3426
|
return merged;
|
|
3445
3427
|
}
|
|
3446
|
-
|
|
3447
|
-
//#region src/engine/providers/claude_cli/sandbox.ts
|
|
3428
|
+
// src/engine/providers/claude_cli/sandbox.ts
|
|
3448
3429
|
/**
|
|
3449
3430
|
* Sandbox wrapper for the claude_cli adapter.
|
|
3450
3431
|
*
|
|
@@ -3559,8 +3540,7 @@ function write_greywall_settings(sandbox) {
|
|
|
3559
3540
|
writeFileSync(path, JSON.stringify(payload, null, 2), "utf8");
|
|
3560
3541
|
return path;
|
|
3561
3542
|
}
|
|
3562
|
-
|
|
3563
|
-
//#region src/engine/providers/claude_cli/spawn.ts
|
|
3543
|
+
// src/engine/providers/claude_cli/spawn.ts
|
|
3564
3544
|
/**
|
|
3565
3545
|
* Subprocess lifecycle for the claude_cli adapter.
|
|
3566
3546
|
*
|
|
@@ -3842,8 +3822,7 @@ async function* build_stdout_lines(child, on_data) {
|
|
|
3842
3822
|
});
|
|
3843
3823
|
}
|
|
3844
3824
|
}
|
|
3845
|
-
|
|
3846
|
-
//#region src/engine/providers/claude_cli/version.ts
|
|
3825
|
+
// src/engine/providers/claude_cli/version.ts
|
|
3847
3826
|
/**
|
|
3848
3827
|
* Claude Code version gate for the `claude_code` sandbox.
|
|
3849
3828
|
*
|
|
@@ -3917,8 +3896,7 @@ function create_cli_version_gate(spawn_runtime, init) {
|
|
|
3917
3896
|
passed.add(path);
|
|
3918
3897
|
} };
|
|
3919
3898
|
}
|
|
3920
|
-
|
|
3921
|
-
//#region src/engine/providers/claude_cli/stream_parse.ts
|
|
3899
|
+
// src/engine/providers/claude_cli/stream_parse.ts
|
|
3922
3900
|
/** A non-null, non-array object: the shape every CLI event and sub-object takes. */
|
|
3923
3901
|
function is_record(value) {
|
|
3924
3902
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -4429,8 +4407,7 @@ function snapshot(state) {
|
|
|
4429
4407
|
if (state.api_error !== void 0) base.api_error = state.api_error;
|
|
4430
4408
|
return base;
|
|
4431
4409
|
}
|
|
4432
|
-
|
|
4433
|
-
//#region src/engine/providers/claude_cli/cost.ts
|
|
4410
|
+
// src/engine/providers/claude_cli/cost.ts
|
|
4434
4411
|
/**
|
|
4435
4412
|
* Cost allocation from the CLI's reported `total_cost_usd`.
|
|
4436
4413
|
*
|
|
@@ -4473,8 +4450,7 @@ function allocate_cost_across_turns(total_cost_usd, turns) {
|
|
|
4473
4450
|
const per_turn = split_total_across_turns(total_cost_usd, turns);
|
|
4474
4451
|
return turns.map((t, i) => decompose_total_cost(per_turn[i] ?? 0, t.usage));
|
|
4475
4452
|
}
|
|
4476
|
-
|
|
4477
|
-
//#region src/engine/providers/claude_cli/stream_result.ts
|
|
4453
|
+
// src/engine/providers/claude_cli/stream_result.ts
|
|
4478
4454
|
/**
|
|
4479
4455
|
* Sum a list of per-turn `UsageTotals` into one aggregate total.
|
|
4480
4456
|
*
|
|
@@ -4679,8 +4655,7 @@ function build_generate_result(input) {
|
|
|
4679
4655
|
if (Object.keys(provider_reported).length > 0) result.provider_reported = provider_reported;
|
|
4680
4656
|
return result;
|
|
4681
4657
|
}
|
|
4682
|
-
|
|
4683
|
-
//#region src/engine/schema.ts
|
|
4658
|
+
// src/engine/schema.ts
|
|
4684
4659
|
/**
|
|
4685
4660
|
* Schema parse and repair helpers.
|
|
4686
4661
|
*
|
|
@@ -4797,8 +4772,7 @@ function build_repair_prompt_text(issues) {
|
|
|
4797
4772
|
function throw_schema_validation(issues, raw_text) {
|
|
4798
4773
|
throw new schema_validation_error(`schema validation failed: ${format_schema_issues(issues)}`, issues, raw_text);
|
|
4799
4774
|
}
|
|
4800
|
-
|
|
4801
|
-
//#region src/engine/trajectory.ts
|
|
4775
|
+
// src/engine/trajectory.ts
|
|
4802
4776
|
/**
|
|
4803
4777
|
* Open the `engine.generate` span that brackets one whole generate call.
|
|
4804
4778
|
*/
|
|
@@ -5222,8 +5196,7 @@ function create_option_ignored_dedup(trajectory) {
|
|
|
5222
5196
|
});
|
|
5223
5197
|
} };
|
|
5224
5198
|
}
|
|
5225
|
-
|
|
5226
|
-
//#region src/engine/providers/claude_cli/adapter.ts
|
|
5199
|
+
// src/engine/providers/claude_cli/adapter.ts
|
|
5227
5200
|
/**
|
|
5228
5201
|
* claude_cli adapter factory.
|
|
5229
5202
|
*
|
|
@@ -5755,8 +5728,7 @@ function create_claude_cli_adapter(init) {
|
|
|
5755
5728
|
}
|
|
5756
5729
|
};
|
|
5757
5730
|
}
|
|
5758
|
-
|
|
5759
|
-
//#region src/engine/providers/registry.ts
|
|
5731
|
+
// src/engine/providers/registry.ts
|
|
5760
5732
|
/**
|
|
5761
5733
|
* Provider name → adapter factory lookup for the built-in set.
|
|
5762
5734
|
*
|
|
@@ -5793,8 +5765,7 @@ function get_provider_factory(name) {
|
|
|
5793
5765
|
if (factory === void 0) throw new engine_config_error(`unknown provider '${name}'; built-in providers are: ${list_builtin_providers().join(", ")}`, name);
|
|
5794
5766
|
return factory;
|
|
5795
5767
|
}
|
|
5796
|
-
|
|
5797
|
-
//#region src/engine/first_chunk_stamp.ts
|
|
5768
|
+
// src/engine/first_chunk_stamp.ts
|
|
5798
5769
|
/**
|
|
5799
5770
|
* Creates the stamp one turn's attempts share, cleared by `reset` as each
|
|
5800
5771
|
* attempt starts, so a failed attempt's chunks never count for the one that
|
|
@@ -5829,8 +5800,7 @@ function create_first_chunk_stamp() {
|
|
|
5829
5800
|
whole_tool_call: () => whole
|
|
5830
5801
|
};
|
|
5831
5802
|
}
|
|
5832
|
-
|
|
5833
|
-
//#region src/engine/merge_defaults.ts
|
|
5803
|
+
// src/engine/merge_defaults.ts
|
|
5834
5804
|
/**
|
|
5835
5805
|
* Default-merging helpers for engine-level `EngineDefaults`.
|
|
5836
5806
|
*/
|
|
@@ -5871,8 +5841,7 @@ function merge_provider_options(defaults, call) {
|
|
|
5871
5841
|
function is_plain_object$1(value) {
|
|
5872
5842
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5873
5843
|
}
|
|
5874
|
-
|
|
5875
|
-
//#region src/engine/streaming.ts
|
|
5844
|
+
// src/engine/streaming.ts
|
|
5876
5845
|
/**
|
|
5877
5846
|
* Build a dispatcher around a user-supplied on_chunk. Catches sync throws and
|
|
5878
5847
|
* rejected promises; once an error is recorded subsequent dispatch calls are
|
|
@@ -5896,8 +5865,7 @@ function create_chunk_dispatcher(on_chunk) {
|
|
|
5896
5865
|
}
|
|
5897
5866
|
};
|
|
5898
5867
|
}
|
|
5899
|
-
|
|
5900
|
-
//#region src/engine/usage.ts
|
|
5868
|
+
// src/engine/usage.ts
|
|
5901
5869
|
const OPTIONAL_FIELDS = [
|
|
5902
5870
|
"reasoning_tokens",
|
|
5903
5871
|
"cached_input_tokens",
|
|
@@ -5947,8 +5915,7 @@ function sum_usage(steps) {
|
|
|
5947
5915
|
for (const key of OPTIONAL_FIELDS) if (present[key]) total[key] = sums[key];
|
|
5948
5916
|
return total;
|
|
5949
5917
|
}
|
|
5950
|
-
|
|
5951
|
-
//#region src/engine/tool_call_salvage.ts
|
|
5918
|
+
// src/engine/tool_call_salvage.ts
|
|
5952
5919
|
/**
|
|
5953
5920
|
* Salvage tool calls that a model emitted as assistant TEXT instead of a
|
|
5954
5921
|
* structured tool_calls array. Local runtimes (Ollama native API, LM Studio
|
|
@@ -6330,8 +6297,7 @@ async function salvage_tool_calls(text, tool_map) {
|
|
|
6330
6297
|
stripped_text: strip_spans(text, calls.map((c) => c.span))
|
|
6331
6298
|
};
|
|
6332
6299
|
}
|
|
6333
|
-
|
|
6334
|
-
//#region src/engine/tool_loop.ts
|
|
6300
|
+
// src/engine/tool_loop.ts
|
|
6335
6301
|
/**
|
|
6336
6302
|
* Tool-call loop orchestration.
|
|
6337
6303
|
*
|
|
@@ -7525,8 +7491,7 @@ async function run_tool_loop(config) {
|
|
|
7525
7491
|
step_index += 1;
|
|
7526
7492
|
}
|
|
7527
7493
|
}
|
|
7528
|
-
|
|
7529
|
-
//#region src/engine/generate.ts
|
|
7494
|
+
// src/engine/generate.ts
|
|
7530
7495
|
/**
|
|
7531
7496
|
* Build the initial message list for a generate call from `opts.system` and
|
|
7532
7497
|
* `opts.prompt`.
|
|
@@ -8201,7 +8166,7 @@ async function build_ai_sdk_transport(cfg) {
|
|
|
8201
8166
|
const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
|
|
8202
8167
|
let ai_sdk_invoke_mod;
|
|
8203
8168
|
try {
|
|
8204
|
-
ai_sdk_invoke_mod = await import("./invoke-
|
|
8169
|
+
ai_sdk_invoke_mod = await import("./invoke-7iu8db6V.js");
|
|
8205
8170
|
} catch (err) {
|
|
8206
8171
|
throw missing_peer_error("ai", err);
|
|
8207
8172
|
}
|
|
@@ -8662,8 +8627,7 @@ function aggregate_cost(steps, provider) {
|
|
|
8662
8627
|
if (acc.reasoning_present) out.reasoning_usd = round6(acc.reasoning);
|
|
8663
8628
|
return out;
|
|
8664
8629
|
}
|
|
8665
|
-
|
|
8666
|
-
//#region src/engine/create_engine.ts
|
|
8630
|
+
// src/engine/create_engine.ts
|
|
8667
8631
|
/**
|
|
8668
8632
|
* Build the provider-name to adapter map from `providers`, resolving each
|
|
8669
8633
|
* name to a `custom_providers` factory when one is supplied, or the built-in
|
|
@@ -8841,7 +8805,6 @@ function create_engine(config) {
|
|
|
8841
8805
|
}
|
|
8842
8806
|
};
|
|
8843
8807
|
}
|
|
8844
|
-
//#endregion
|
|
8845
8808
|
export { to_json_schema as n, create_engine as t };
|
|
8846
8809
|
|
|
8847
|
-
//# sourceMappingURL=engine-
|
|
8810
|
+
//# sourceMappingURL=engine-fOjYHcv6.js.map
|