fascicle 0.13.0 → 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.
- package/CHANGELOG.md +28 -0
- package/README.md +20 -1
- package/dist/acp.d.ts +226 -0
- package/dist/acp.js +1886 -0
- package/dist/acp.js.map +1 -0
- package/dist/adapters.js +1 -2
- package/dist/agents.d.ts +1 -1
- package/dist/agents.js +1 -1
- package/dist/{core-B-M7nAkg.js → core-CDrz0NM1.js} +184 -53
- package/dist/core-CDrz0NM1.js.map +1 -0
- package/dist/diagram_bin.js +5 -2
- package/dist/diagram_bin.js.map +1 -1
- package/dist/{engine-BRzVcTBB.js → engine-BDWB2jdn.js} +12 -333
- package/dist/engine-BDWB2jdn.js.map +1 -0
- package/dist/index.d.ts +485 -623
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/{invoke-CIdhjChw.js → invoke-tjTjZLHj.js} +3 -3
- package/dist/{invoke-CIdhjChw.js.map → invoke-tjTjZLHj.js.map} +1 -1
- package/dist/json_schema_to_standard-r21kW2LI.js +288 -0
- package/dist/json_schema_to_standard-r21kW2LI.js.map +1 -0
- package/dist/leading_system-BQe_405V.js +330 -0
- package/dist/leading_system-BQe_405V.js.map +1 -0
- package/dist/mcp.d.ts +17 -16
- package/dist/mcp.js +2 -266
- package/dist/mcp.js.map +1 -1
- package/dist/search-CqH5hmuF.js +563 -0
- package/dist/search-CqH5hmuF.js.map +1 -0
- package/dist/search_worker.d.ts +1 -0
- package/dist/search_worker.js +19 -0
- package/dist/search_worker.js.map +1 -0
- package/dist/stdio.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -2
- package/dist/testing.js.map +1 -1
- package/dist/{types-CZ83Q5nm.d.ts → types-C_Rmcgck.d.ts} +7 -1
- package/dist/viewer-app/assets/index-Fnh5HKSU.js +2 -0
- package/dist/viewer-app/index.html +1 -1
- package/dist/viewer.js +1 -1
- package/package.json +30 -19
- package/dist/core-B-M7nAkg.js.map +0 -1
- package/dist/engine-BRzVcTBB.js.map +0 -1
- package/dist/viewer-app/assets/index-DXsB0byD.js +0 -2
package/dist/diagram_bin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as describe, O as is_step } from "./core-
|
|
1
|
+
import { D as describe, O as is_step } from "./core-CDrz0NM1.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -10,7 +10,7 @@ import { parseArgs } from "node:util";
|
|
|
10
10
|
* fascicle-diagram <module> print the diagram of the module's `flow`
|
|
11
11
|
* fascicle-diagram <module> --export <name> read another export instead
|
|
12
12
|
*
|
|
13
|
-
* Flags: --export <name> --width <n> --prefix <text> --help
|
|
13
|
+
* Flags: --export <name> --width <n> --prefix <text> --replays --help
|
|
14
14
|
*
|
|
15
15
|
* The export is a Step, or a function that builds one with no arguments,
|
|
16
16
|
* which is where an app wires its flow to stub dependencies so that drawing
|
|
@@ -36,6 +36,7 @@ Options:
|
|
|
36
36
|
--export <name> the export to draw (default flow)
|
|
37
37
|
--width <n> wrap descriptions so no line runs wider than n
|
|
38
38
|
--prefix <text> start every line with text, for example ' * '
|
|
39
|
+
--replays mark the steps a resumed run would pay for again
|
|
39
40
|
--help show this message
|
|
40
41
|
`;
|
|
41
42
|
/**
|
|
@@ -119,6 +120,7 @@ function parse(argv) {
|
|
|
119
120
|
options.width = width;
|
|
120
121
|
}
|
|
121
122
|
if (values.prefix !== void 0) options.prefix = values.prefix;
|
|
123
|
+
if (values.replays === true) options.replays = true;
|
|
122
124
|
return {
|
|
123
125
|
kind: "run",
|
|
124
126
|
args: {
|
|
@@ -140,6 +142,7 @@ function parse_flags(argv) {
|
|
|
140
142
|
export: { type: "string" },
|
|
141
143
|
width: { type: "string" },
|
|
142
144
|
prefix: { type: "string" },
|
|
145
|
+
replays: { type: "boolean" },
|
|
143
146
|
help: { type: "boolean" }
|
|
144
147
|
}
|
|
145
148
|
});
|
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> --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.\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 { 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 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 --help show this message\n`\n\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, 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 (!(export_name in exports)) {\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 io.out(`${describe.diagram(flow, options)}\\n`)\n return 0\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.\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 options: { width?: number; prefix?: string } = {}\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 return { kind: 'run', args: { module, export_name: values.export ?? 'flow', 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 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"],"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AM,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 --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.\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 { 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 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 --help show this message\n`\n\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, 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 (!(export_name in exports)) {\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 io.out(`${describe.diagram(flow, options)}\\n`)\n return 0\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.\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 options: { width?: number; prefix?: string; replays?: 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 return { kind: 'run', args: { module, export_name: values.export ?? 'flow', 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 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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AO,KAAA,KAAa,QAAQ,KAAK,OAAO,cAAc,YAAY,GAAG,GAE9D,gBAAqB,QAAQ,KAAK,MAAM,CAAC,CAAC"}
|
|
@@ -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-
|
|
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())
|
|
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-
|
|
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 {
|
|
7210
|
+
export { create_engine as t };
|
|
7532
7211
|
|
|
7533
|
-
//# sourceMappingURL=engine-
|
|
7212
|
+
//# sourceMappingURL=engine-BDWB2jdn.js.map
|