@copilotkit/aimock 1.12.0 → 1.13.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +20 -2
- package/dist/_virtual/_rolldown/runtime.cjs +2 -0
- package/dist/_virtual/_rolldown/runtime.js +29 -0
- package/dist/a2a-types.d.cts.map +1 -1
- package/dist/a2a-types.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +16 -0
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.d.cts +2 -0
- package/dist/aimock-cli.d.cts.map +1 -1
- package/dist/aimock-cli.d.ts +2 -0
- package/dist/aimock-cli.d.ts.map +1 -1
- package/dist/aimock-cli.js +16 -0
- package/dist/aimock-cli.js.map +1 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/convert-mockllm.cjs +232 -0
- package/dist/convert-mockllm.cjs.map +1 -0
- package/dist/convert-mockllm.js +230 -0
- package/dist/convert-mockllm.js.map +1 -0
- package/dist/convert-vidaimock.cjs +110 -0
- package/dist/convert-vidaimock.cjs.map +1 -0
- package/dist/convert-vidaimock.js +108 -0
- package/dist/convert-vidaimock.js.map +1 -0
- package/dist/convert.cjs +158 -0
- package/dist/convert.cjs.map +1 -0
- package/dist/convert.d.cts +16 -0
- package/dist/convert.d.cts.map +1 -0
- package/dist/convert.d.ts +16 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +157 -0
- package/dist/convert.js.map +1 -0
- package/dist/jest.cjs +70 -0
- package/dist/jest.cjs.map +1 -0
- package/dist/jest.d.cts +33 -0
- package/dist/jest.d.cts.map +1 -0
- package/dist/jest.d.ts +33 -0
- package/dist/jest.d.ts.map +1 -0
- package/dist/jest.js +67 -0
- package/dist/jest.js.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.cjs +934 -0
- package/dist/node_modules/.pnpm/@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.js +934 -0
- package/dist/node_modules/.pnpm/@vitest_pretty-format@3.2.4/node_modules/@vitest/pretty-format/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.cjs +1051 -0
- package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.js +1042 -0
- package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/chunk-hooks.js.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/index.cjs +1 -0
- package/dist/node_modules/.pnpm/@vitest_runner@3.2.4/node_modules/@vitest/runner/dist/index.js +3 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.cjs +96 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js +93 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.js.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.cjs +49 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.js +43 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/helpers.js.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/index.cjs +456 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/index.js +456 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/source-map.cjs +170 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/source-map.cjs.map +1 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/source-map.js +169 -0
- package/dist/node_modules/.pnpm/@vitest_utils@3.2.4/node_modules/@vitest/utils/dist/source-map.js.map +1 -0
- package/dist/node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.cjs +388 -0
- package/dist/node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.js +385 -0
- package/dist/node_modules/.pnpm/js-tokens@9.0.1/node_modules/js-tokens/index.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/arguments.cjs +12 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/arguments.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/arguments.js +12 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/arguments.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/array.cjs +17 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/array.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/array.js +17 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/array.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/bigint.cjs +12 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/bigint.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/bigint.js +12 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/bigint.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/class.cjs +16 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/class.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/class.js +16 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/class.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/date.cjs +14 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/date.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/date.js +14 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/date.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/error.cjs +35 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/error.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/error.js +35 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/error.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/function.cjs +13 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/function.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/function.js +13 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/function.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/helpers.cjs +128 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/helpers.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/helpers.js +123 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/helpers.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/html.cjs +41 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/html.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/html.js +40 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/html.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.cjs +100 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.js +100 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/index.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/map.cjs +26 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/map.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/map.js +26 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/map.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/number.cjs +15 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/number.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/number.js +15 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/number.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/object.cjs +22 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/object.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/object.js +22 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/object.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/promise.cjs +7 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/promise.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/promise.js +6 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/promise.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/regexp.cjs +13 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/regexp.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/regexp.js +13 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/regexp.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/set.cjs +19 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/set.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/set.js +19 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/set.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/string.cjs +26 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/string.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/string.js +26 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/string.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/symbol.cjs +10 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/symbol.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/symbol.js +9 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/symbol.js.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.cjs +31 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.cjs.map +1 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.js +31 -0
- package/dist/node_modules/.pnpm/loupe@3.2.1/node_modules/loupe/lib/typedarray.js.map +1 -0
- package/dist/node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.cjs +52 -0
- package/dist/node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.cjs.map +1 -0
- package/dist/node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.js +52 -0
- package/dist/node_modules/.pnpm/strip-literal@3.1.0/node_modules/strip-literal/dist/index.js.map +1 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.cjs +83 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.cjs.map +1 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.js +82 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/chunk-BVHSVHOK.js.map +1 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.cjs +10 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.cjs.map +1 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.js +10 -0
- package/dist/node_modules/.pnpm/tinyrainbow@2.0.0/node_modules/tinyrainbow/dist/node.js.map +1 -0
- package/dist/vitest.cjs +80 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +30 -0
- package/dist/vitest.d.cts.map +1 -0
- package/dist/vitest.d.ts +30 -0
- package/dist/vitest.d.ts.map +1 -0
- package/dist/vitest.js +77 -0
- package/dist/vitest.js.map +1 -0
- package/fixtures/examples/a2a/a2a-config.json +42 -0
- package/fixtures/examples/agui/agui-text-response.json +35 -0
- package/fixtures/examples/chaos/chaos-config.json +10 -0
- package/fixtures/examples/full-suite.json +116 -0
- package/fixtures/examples/llm/embeddings.json +10 -0
- package/fixtures/examples/llm/error-injection.json +15 -0
- package/fixtures/examples/llm/sequential-responses.json +20 -0
- package/fixtures/examples/llm/streaming-physics.json +15 -0
- package/fixtures/examples/mcp/mcp-config.json +26 -0
- package/fixtures/examples/record-replay/record-config.json +11 -0
- package/fixtures/examples/vector/vector-config.json +34 -0
- package/package.json +59 -1
package/dist/convert.cjs
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_convert_vidaimock = require('./convert-vidaimock.cjs');
|
|
3
|
+
const require_convert_mockllm = require('./convert-mockllm.cjs');
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
let node_fs = require("node:fs");
|
|
6
|
+
|
|
7
|
+
//#region src/convert.ts
|
|
8
|
+
/**
|
|
9
|
+
* CLI dispatcher for `aimock convert` subcommands.
|
|
10
|
+
*
|
|
11
|
+
* Delegates to the converter modules in src/convert-vidaimock.ts and
|
|
12
|
+
* src/convert-mockllm.ts.
|
|
13
|
+
*/
|
|
14
|
+
const CONVERT_HELP = `
|
|
15
|
+
Usage: aimock convert <format> <input> [output]
|
|
16
|
+
|
|
17
|
+
Formats:
|
|
18
|
+
vidaimock Convert VidaiMock Tera templates to aimock JSON
|
|
19
|
+
mockllm Convert mock-llm YAML config to aimock JSON
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
aimock convert vidaimock ./templates/ ./fixtures/
|
|
23
|
+
aimock convert mockllm ./config.yaml ./fixtures/converted.json
|
|
24
|
+
`.trim();
|
|
25
|
+
function runConvertCli(deps) {
|
|
26
|
+
const { argv, log, logError, exit } = deps;
|
|
27
|
+
if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
|
|
28
|
+
if (argv.length === 0) {
|
|
29
|
+
logError(CONVERT_HELP);
|
|
30
|
+
exit(1);
|
|
31
|
+
} else {
|
|
32
|
+
log(CONVERT_HELP);
|
|
33
|
+
exit(0);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const format = argv[0];
|
|
38
|
+
const inputArg = argv[1];
|
|
39
|
+
const outputArg = argv[2];
|
|
40
|
+
if (!inputArg) {
|
|
41
|
+
logError(`Error: missing <input> argument.\n\n${CONVERT_HELP}`);
|
|
42
|
+
exit(1);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
switch (format) {
|
|
46
|
+
case "vidaimock":
|
|
47
|
+
runVidaimockConvert(inputArg, outputArg, {
|
|
48
|
+
log,
|
|
49
|
+
logError,
|
|
50
|
+
exit
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
case "mockllm":
|
|
54
|
+
runMockllmConvert(inputArg, outputArg, {
|
|
55
|
+
log,
|
|
56
|
+
logError,
|
|
57
|
+
exit
|
|
58
|
+
});
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
logError(`Error: unknown format "${format}".\n\n${CONVERT_HELP}`);
|
|
62
|
+
exit(1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function runVidaimockConvert(inputArg, outputArg, io) {
|
|
66
|
+
const inputPath = (0, node_path.resolve)(inputArg);
|
|
67
|
+
const outputPath = outputArg ? (0, node_path.resolve)(outputArg) : null;
|
|
68
|
+
let fixtures;
|
|
69
|
+
try {
|
|
70
|
+
if ((0, node_fs.statSync)(inputPath).isDirectory()) fixtures = require_convert_vidaimock.convertDirectory(inputPath);
|
|
71
|
+
else {
|
|
72
|
+
const single = require_convert_vidaimock.convertFile(inputPath);
|
|
73
|
+
fixtures = single ? [single] : [];
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
io.logError(`Error reading input path: ${inputPath}`);
|
|
77
|
+
io.logError(err instanceof Error ? err.message : String(err));
|
|
78
|
+
io.exit(1);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (fixtures.length === 0) {
|
|
82
|
+
io.logError("No fixtures produced — check that the input contains valid VidaiMock templates.");
|
|
83
|
+
io.exit(1);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const output = { fixtures };
|
|
87
|
+
const json = JSON.stringify(output, null, 2) + "\n";
|
|
88
|
+
if (outputPath) {
|
|
89
|
+
try {
|
|
90
|
+
(0, node_fs.writeFileSync)(outputPath, json, "utf-8");
|
|
91
|
+
} catch (err) {
|
|
92
|
+
io.logError(`Error writing output: ${err.message}`);
|
|
93
|
+
io.exit(1);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
io.log(`Wrote ${fixtures.length} fixture(s) to ${outputPath}`);
|
|
97
|
+
} else io.log(json.trimEnd());
|
|
98
|
+
}
|
|
99
|
+
function runMockllmConvert(inputArg, outputArg, io) {
|
|
100
|
+
const inputPath = (0, node_path.resolve)(inputArg);
|
|
101
|
+
const outputPath = outputArg ? (0, node_path.resolve)(outputArg) : null;
|
|
102
|
+
let yamlContent;
|
|
103
|
+
try {
|
|
104
|
+
yamlContent = (0, node_fs.readFileSync)(inputPath, "utf-8");
|
|
105
|
+
} catch (err) {
|
|
106
|
+
io.logError(`Error reading input file: ${err.message}`);
|
|
107
|
+
io.exit(1);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const parsed = require_convert_mockllm.parseSimpleYaml(yamlContent);
|
|
111
|
+
if (!parsed || typeof parsed !== "object") {
|
|
112
|
+
io.logError("Error: could not parse YAML config");
|
|
113
|
+
io.exit(1);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const result = require_convert_mockllm.convertConfig(parsed);
|
|
117
|
+
const fixtureJson = JSON.stringify({ fixtures: result.fixtures }, null, 2);
|
|
118
|
+
if (outputPath) {
|
|
119
|
+
try {
|
|
120
|
+
(0, node_fs.writeFileSync)(outputPath, fixtureJson + "\n", "utf-8");
|
|
121
|
+
} catch (err) {
|
|
122
|
+
io.logError(`Error writing output: ${err.message}`);
|
|
123
|
+
io.exit(1);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
io.log(`Wrote fixtures to ${outputPath}`);
|
|
127
|
+
if (result.mcpTools) {
|
|
128
|
+
const configPath = outputPath.endsWith(".json") ? outputPath.replace(/\.json$/, ".aimock.json") : outputPath + ".aimock.json";
|
|
129
|
+
const aimockConfig = {
|
|
130
|
+
llm: { fixtures: outputPath },
|
|
131
|
+
mcp: { tools: result.mcpTools.map((t) => ({
|
|
132
|
+
name: t.name,
|
|
133
|
+
description: t.description ?? "",
|
|
134
|
+
inputSchema: t.inputSchema ?? {},
|
|
135
|
+
result: `Mock result for ${t.name}`
|
|
136
|
+
})) }
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
(0, node_fs.writeFileSync)(configPath, JSON.stringify(aimockConfig, null, 2) + "\n", "utf-8");
|
|
140
|
+
} catch (err) {
|
|
141
|
+
io.logError(`Error writing config: ${err.message}`);
|
|
142
|
+
io.exit(1);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
io.log(`Wrote aimock config with MCP tools to ${configPath}`);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
io.log(fixtureJson);
|
|
149
|
+
if (result.mcpTools) {
|
|
150
|
+
io.log("\n--- MCP Tools (aimock config format) ---");
|
|
151
|
+
io.log(JSON.stringify({ mcp: { tools: result.mcpTools } }, null, 2));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
exports.runConvertCli = runConvertCli;
|
|
158
|
+
//# sourceMappingURL=convert.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.cjs","names":["convertDirectory","convertFile","parseSimpleYaml","convertConfig"],"sources":["../src/convert.ts"],"sourcesContent":["/**\n * CLI dispatcher for `aimock convert` subcommands.\n *\n * Delegates to the converter modules in src/convert-vidaimock.ts and\n * src/convert-mockllm.ts.\n */\n\nimport { readFileSync, writeFileSync, statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { convertFile, convertDirectory, type AimockFixtureFile } from \"./convert-vidaimock.js\";\nimport { parseSimpleYaml, convertConfig, type MockLLMConfig } from \"./convert-mockllm.js\";\n\nconst CONVERT_HELP = `\nUsage: aimock convert <format> <input> [output]\n\nFormats:\n vidaimock Convert VidaiMock Tera templates to aimock JSON\n mockllm Convert mock-llm YAML config to aimock JSON\n\nExamples:\n aimock convert vidaimock ./templates/ ./fixtures/\n aimock convert mockllm ./config.yaml ./fixtures/converted.json\n`.trim();\n\nexport interface ConvertCliDeps {\n argv: string[];\n log: (msg: string) => void;\n logError: (msg: string) => void;\n exit: (code: number) => void;\n}\n\nexport function runConvertCli(deps: ConvertCliDeps): void {\n const { argv, log, logError, exit } = deps;\n\n if (argv.length === 0 || argv[0] === \"--help\" || argv[0] === \"-h\") {\n if (argv.length === 0) {\n logError(CONVERT_HELP);\n exit(1);\n } else {\n log(CONVERT_HELP);\n exit(0);\n }\n return;\n }\n\n const format = argv[0];\n const inputArg = argv[1];\n const outputArg = argv[2];\n\n if (!inputArg) {\n logError(`Error: missing <input> argument.\\n\\n${CONVERT_HELP}`);\n exit(1);\n return;\n }\n\n switch (format) {\n case \"vidaimock\":\n runVidaimockConvert(inputArg, outputArg, { log, logError, exit });\n break;\n case \"mockllm\":\n runMockllmConvert(inputArg, outputArg, { log, logError, exit });\n break;\n default:\n logError(`Error: unknown format \"${format}\".\\n\\n${CONVERT_HELP}`);\n exit(1);\n }\n}\n\n// ---------------------------------------------------------------------------\n// VidaiMock converter\n// ---------------------------------------------------------------------------\n\nfunction runVidaimockConvert(\n inputArg: string,\n outputArg: string | undefined,\n io: { log: (msg: string) => void; logError: (msg: string) => void; exit: (code: number) => void },\n): void {\n const inputPath = resolve(inputArg);\n const outputPath = outputArg ? resolve(outputArg) : null;\n\n let fixtures: AimockFixtureFile[\"fixtures\"];\n\n try {\n const stat = statSync(inputPath);\n if (stat.isDirectory()) {\n fixtures = convertDirectory(inputPath);\n } else {\n const single = convertFile(inputPath);\n fixtures = single ? [single] : [];\n }\n } catch (err) {\n io.logError(`Error reading input path: ${inputPath}`);\n io.logError(err instanceof Error ? err.message : String(err));\n io.exit(1);\n return;\n }\n\n if (fixtures.length === 0) {\n io.logError(\"No fixtures produced — check that the input contains valid VidaiMock templates.\");\n io.exit(1);\n return;\n }\n\n const output: AimockFixtureFile = { fixtures };\n const json = JSON.stringify(output, null, 2) + \"\\n\";\n\n if (outputPath) {\n try {\n writeFileSync(outputPath, json, \"utf-8\");\n } catch (err) {\n io.logError(`Error writing output: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n io.log(`Wrote ${fixtures.length} fixture(s) to ${outputPath}`);\n } else {\n io.log(json.trimEnd());\n }\n}\n\n// ---------------------------------------------------------------------------\n// mock-llm converter\n// ---------------------------------------------------------------------------\n\nfunction runMockllmConvert(\n inputArg: string,\n outputArg: string | undefined,\n io: { log: (msg: string) => void; logError: (msg: string) => void; exit: (code: number) => void },\n): void {\n const inputPath = resolve(inputArg);\n const outputPath = outputArg ? resolve(outputArg) : null;\n\n let yamlContent: string;\n try {\n yamlContent = readFileSync(inputPath, \"utf-8\");\n } catch (err) {\n io.logError(`Error reading input file: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n\n const parsed = parseSimpleYaml(yamlContent) as MockLLMConfig | null;\n if (!parsed || typeof parsed !== \"object\") {\n io.logError(\"Error: could not parse YAML config\");\n io.exit(1);\n return;\n }\n\n const result = convertConfig(parsed);\n const fixtureJson = JSON.stringify({ fixtures: result.fixtures }, null, 2);\n\n if (outputPath) {\n try {\n writeFileSync(outputPath, fixtureJson + \"\\n\", \"utf-8\");\n } catch (err) {\n io.logError(`Error writing output: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n io.log(`Wrote fixtures to ${outputPath}`);\n\n if (result.mcpTools) {\n const configPath = outputPath.endsWith(\".json\")\n ? outputPath.replace(/\\.json$/, \".aimock.json\")\n : outputPath + \".aimock.json\";\n const aimockConfig = {\n llm: { fixtures: outputPath },\n mcp: {\n tools: result.mcpTools.map((t) => ({\n name: t.name,\n description: t.description ?? \"\",\n inputSchema: t.inputSchema ?? {},\n result: `Mock result for ${t.name}`,\n })),\n },\n };\n try {\n writeFileSync(configPath, JSON.stringify(aimockConfig, null, 2) + \"\\n\", \"utf-8\");\n } catch (err) {\n io.logError(`Error writing config: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n io.log(`Wrote aimock config with MCP tools to ${configPath}`);\n }\n } else {\n io.log(fixtureJson);\n\n if (result.mcpTools) {\n io.log(\"\\n--- MCP Tools (aimock config format) ---\");\n io.log(JSON.stringify({ mcp: { tools: result.mcpTools } }, null, 2));\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAM,eAAe;;;;;;;;;;EAUnB,MAAM;AASR,SAAgB,cAAc,MAA4B;CACxD,MAAM,EAAE,MAAM,KAAK,UAAU,SAAS;AAEtC,KAAI,KAAK,WAAW,KAAK,KAAK,OAAO,YAAY,KAAK,OAAO,MAAM;AACjE,MAAI,KAAK,WAAW,GAAG;AACrB,YAAS,aAA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I,OAAO,UAAU;AACnB,MAAG,IAAI,6CAA6C;AACpD,MAAG,IAAI,KAAK,UAAU,EAAE,KAAK,EAAE,OAAO,OAAO,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/convert.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* CLI dispatcher for `aimock convert` subcommands.
|
|
4
|
+
*
|
|
5
|
+
* Delegates to the converter modules in src/convert-vidaimock.ts and
|
|
6
|
+
* src/convert-mockllm.ts.
|
|
7
|
+
*/
|
|
8
|
+
interface ConvertCliDeps {
|
|
9
|
+
argv: string[];
|
|
10
|
+
log: (msg: string) => void;
|
|
11
|
+
logError: (msg: string) => void;
|
|
12
|
+
exit: (code: number) => void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ConvertCliDeps };
|
|
16
|
+
//# sourceMappingURL=convert.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.cts","names":[],"sources":["../src/convert.ts"],"sourcesContent":[],"mappings":";;AAwBA;;;;;UAAiB,cAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/convert.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* CLI dispatcher for `aimock convert` subcommands.
|
|
4
|
+
*
|
|
5
|
+
* Delegates to the converter modules in src/convert-vidaimock.ts and
|
|
6
|
+
* src/convert-mockllm.ts.
|
|
7
|
+
*/
|
|
8
|
+
interface ConvertCliDeps {
|
|
9
|
+
argv: string[];
|
|
10
|
+
log: (msg: string) => void;
|
|
11
|
+
logError: (msg: string) => void;
|
|
12
|
+
exit: (code: number) => void;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ConvertCliDeps };
|
|
16
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","names":[],"sources":["../src/convert.ts"],"sourcesContent":[],"mappings":";;AAwBA;;;;;UAAiB,cAAA"}
|
package/dist/convert.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { convertDirectory, convertFile } from "./convert-vidaimock.js";
|
|
2
|
+
import { convertConfig, parseSimpleYaml } from "./convert-mockllm.js";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { readFileSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region src/convert.ts
|
|
7
|
+
/**
|
|
8
|
+
* CLI dispatcher for `aimock convert` subcommands.
|
|
9
|
+
*
|
|
10
|
+
* Delegates to the converter modules in src/convert-vidaimock.ts and
|
|
11
|
+
* src/convert-mockllm.ts.
|
|
12
|
+
*/
|
|
13
|
+
const CONVERT_HELP = `
|
|
14
|
+
Usage: aimock convert <format> <input> [output]
|
|
15
|
+
|
|
16
|
+
Formats:
|
|
17
|
+
vidaimock Convert VidaiMock Tera templates to aimock JSON
|
|
18
|
+
mockllm Convert mock-llm YAML config to aimock JSON
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
aimock convert vidaimock ./templates/ ./fixtures/
|
|
22
|
+
aimock convert mockllm ./config.yaml ./fixtures/converted.json
|
|
23
|
+
`.trim();
|
|
24
|
+
function runConvertCli(deps) {
|
|
25
|
+
const { argv, log, logError, exit } = deps;
|
|
26
|
+
if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
|
|
27
|
+
if (argv.length === 0) {
|
|
28
|
+
logError(CONVERT_HELP);
|
|
29
|
+
exit(1);
|
|
30
|
+
} else {
|
|
31
|
+
log(CONVERT_HELP);
|
|
32
|
+
exit(0);
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const format = argv[0];
|
|
37
|
+
const inputArg = argv[1];
|
|
38
|
+
const outputArg = argv[2];
|
|
39
|
+
if (!inputArg) {
|
|
40
|
+
logError(`Error: missing <input> argument.\n\n${CONVERT_HELP}`);
|
|
41
|
+
exit(1);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
switch (format) {
|
|
45
|
+
case "vidaimock":
|
|
46
|
+
runVidaimockConvert(inputArg, outputArg, {
|
|
47
|
+
log,
|
|
48
|
+
logError,
|
|
49
|
+
exit
|
|
50
|
+
});
|
|
51
|
+
break;
|
|
52
|
+
case "mockllm":
|
|
53
|
+
runMockllmConvert(inputArg, outputArg, {
|
|
54
|
+
log,
|
|
55
|
+
logError,
|
|
56
|
+
exit
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
logError(`Error: unknown format "${format}".\n\n${CONVERT_HELP}`);
|
|
61
|
+
exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function runVidaimockConvert(inputArg, outputArg, io) {
|
|
65
|
+
const inputPath = resolve(inputArg);
|
|
66
|
+
const outputPath = outputArg ? resolve(outputArg) : null;
|
|
67
|
+
let fixtures;
|
|
68
|
+
try {
|
|
69
|
+
if (statSync(inputPath).isDirectory()) fixtures = convertDirectory(inputPath);
|
|
70
|
+
else {
|
|
71
|
+
const single = convertFile(inputPath);
|
|
72
|
+
fixtures = single ? [single] : [];
|
|
73
|
+
}
|
|
74
|
+
} catch (err) {
|
|
75
|
+
io.logError(`Error reading input path: ${inputPath}`);
|
|
76
|
+
io.logError(err instanceof Error ? err.message : String(err));
|
|
77
|
+
io.exit(1);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (fixtures.length === 0) {
|
|
81
|
+
io.logError("No fixtures produced — check that the input contains valid VidaiMock templates.");
|
|
82
|
+
io.exit(1);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const output = { fixtures };
|
|
86
|
+
const json = JSON.stringify(output, null, 2) + "\n";
|
|
87
|
+
if (outputPath) {
|
|
88
|
+
try {
|
|
89
|
+
writeFileSync(outputPath, json, "utf-8");
|
|
90
|
+
} catch (err) {
|
|
91
|
+
io.logError(`Error writing output: ${err.message}`);
|
|
92
|
+
io.exit(1);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
io.log(`Wrote ${fixtures.length} fixture(s) to ${outputPath}`);
|
|
96
|
+
} else io.log(json.trimEnd());
|
|
97
|
+
}
|
|
98
|
+
function runMockllmConvert(inputArg, outputArg, io) {
|
|
99
|
+
const inputPath = resolve(inputArg);
|
|
100
|
+
const outputPath = outputArg ? resolve(outputArg) : null;
|
|
101
|
+
let yamlContent;
|
|
102
|
+
try {
|
|
103
|
+
yamlContent = readFileSync(inputPath, "utf-8");
|
|
104
|
+
} catch (err) {
|
|
105
|
+
io.logError(`Error reading input file: ${err.message}`);
|
|
106
|
+
io.exit(1);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const parsed = parseSimpleYaml(yamlContent);
|
|
110
|
+
if (!parsed || typeof parsed !== "object") {
|
|
111
|
+
io.logError("Error: could not parse YAML config");
|
|
112
|
+
io.exit(1);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const result = convertConfig(parsed);
|
|
116
|
+
const fixtureJson = JSON.stringify({ fixtures: result.fixtures }, null, 2);
|
|
117
|
+
if (outputPath) {
|
|
118
|
+
try {
|
|
119
|
+
writeFileSync(outputPath, fixtureJson + "\n", "utf-8");
|
|
120
|
+
} catch (err) {
|
|
121
|
+
io.logError(`Error writing output: ${err.message}`);
|
|
122
|
+
io.exit(1);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
io.log(`Wrote fixtures to ${outputPath}`);
|
|
126
|
+
if (result.mcpTools) {
|
|
127
|
+
const configPath = outputPath.endsWith(".json") ? outputPath.replace(/\.json$/, ".aimock.json") : outputPath + ".aimock.json";
|
|
128
|
+
const aimockConfig = {
|
|
129
|
+
llm: { fixtures: outputPath },
|
|
130
|
+
mcp: { tools: result.mcpTools.map((t) => ({
|
|
131
|
+
name: t.name,
|
|
132
|
+
description: t.description ?? "",
|
|
133
|
+
inputSchema: t.inputSchema ?? {},
|
|
134
|
+
result: `Mock result for ${t.name}`
|
|
135
|
+
})) }
|
|
136
|
+
};
|
|
137
|
+
try {
|
|
138
|
+
writeFileSync(configPath, JSON.stringify(aimockConfig, null, 2) + "\n", "utf-8");
|
|
139
|
+
} catch (err) {
|
|
140
|
+
io.logError(`Error writing config: ${err.message}`);
|
|
141
|
+
io.exit(1);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
io.log(`Wrote aimock config with MCP tools to ${configPath}`);
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
io.log(fixtureJson);
|
|
148
|
+
if (result.mcpTools) {
|
|
149
|
+
io.log("\n--- MCP Tools (aimock config format) ---");
|
|
150
|
+
io.log(JSON.stringify({ mcp: { tools: result.mcpTools } }, null, 2));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
export { runConvertCli };
|
|
157
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","names":[],"sources":["../src/convert.ts"],"sourcesContent":["/**\n * CLI dispatcher for `aimock convert` subcommands.\n *\n * Delegates to the converter modules in src/convert-vidaimock.ts and\n * src/convert-mockllm.ts.\n */\n\nimport { readFileSync, writeFileSync, statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { convertFile, convertDirectory, type AimockFixtureFile } from \"./convert-vidaimock.js\";\nimport { parseSimpleYaml, convertConfig, type MockLLMConfig } from \"./convert-mockllm.js\";\n\nconst CONVERT_HELP = `\nUsage: aimock convert <format> <input> [output]\n\nFormats:\n vidaimock Convert VidaiMock Tera templates to aimock JSON\n mockllm Convert mock-llm YAML config to aimock JSON\n\nExamples:\n aimock convert vidaimock ./templates/ ./fixtures/\n aimock convert mockllm ./config.yaml ./fixtures/converted.json\n`.trim();\n\nexport interface ConvertCliDeps {\n argv: string[];\n log: (msg: string) => void;\n logError: (msg: string) => void;\n exit: (code: number) => void;\n}\n\nexport function runConvertCli(deps: ConvertCliDeps): void {\n const { argv, log, logError, exit } = deps;\n\n if (argv.length === 0 || argv[0] === \"--help\" || argv[0] === \"-h\") {\n if (argv.length === 0) {\n logError(CONVERT_HELP);\n exit(1);\n } else {\n log(CONVERT_HELP);\n exit(0);\n }\n return;\n }\n\n const format = argv[0];\n const inputArg = argv[1];\n const outputArg = argv[2];\n\n if (!inputArg) {\n logError(`Error: missing <input> argument.\\n\\n${CONVERT_HELP}`);\n exit(1);\n return;\n }\n\n switch (format) {\n case \"vidaimock\":\n runVidaimockConvert(inputArg, outputArg, { log, logError, exit });\n break;\n case \"mockllm\":\n runMockllmConvert(inputArg, outputArg, { log, logError, exit });\n break;\n default:\n logError(`Error: unknown format \"${format}\".\\n\\n${CONVERT_HELP}`);\n exit(1);\n }\n}\n\n// ---------------------------------------------------------------------------\n// VidaiMock converter\n// ---------------------------------------------------------------------------\n\nfunction runVidaimockConvert(\n inputArg: string,\n outputArg: string | undefined,\n io: { log: (msg: string) => void; logError: (msg: string) => void; exit: (code: number) => void },\n): void {\n const inputPath = resolve(inputArg);\n const outputPath = outputArg ? resolve(outputArg) : null;\n\n let fixtures: AimockFixtureFile[\"fixtures\"];\n\n try {\n const stat = statSync(inputPath);\n if (stat.isDirectory()) {\n fixtures = convertDirectory(inputPath);\n } else {\n const single = convertFile(inputPath);\n fixtures = single ? [single] : [];\n }\n } catch (err) {\n io.logError(`Error reading input path: ${inputPath}`);\n io.logError(err instanceof Error ? err.message : String(err));\n io.exit(1);\n return;\n }\n\n if (fixtures.length === 0) {\n io.logError(\"No fixtures produced — check that the input contains valid VidaiMock templates.\");\n io.exit(1);\n return;\n }\n\n const output: AimockFixtureFile = { fixtures };\n const json = JSON.stringify(output, null, 2) + \"\\n\";\n\n if (outputPath) {\n try {\n writeFileSync(outputPath, json, \"utf-8\");\n } catch (err) {\n io.logError(`Error writing output: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n io.log(`Wrote ${fixtures.length} fixture(s) to ${outputPath}`);\n } else {\n io.log(json.trimEnd());\n }\n}\n\n// ---------------------------------------------------------------------------\n// mock-llm converter\n// ---------------------------------------------------------------------------\n\nfunction runMockllmConvert(\n inputArg: string,\n outputArg: string | undefined,\n io: { log: (msg: string) => void; logError: (msg: string) => void; exit: (code: number) => void },\n): void {\n const inputPath = resolve(inputArg);\n const outputPath = outputArg ? resolve(outputArg) : null;\n\n let yamlContent: string;\n try {\n yamlContent = readFileSync(inputPath, \"utf-8\");\n } catch (err) {\n io.logError(`Error reading input file: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n\n const parsed = parseSimpleYaml(yamlContent) as MockLLMConfig | null;\n if (!parsed || typeof parsed !== \"object\") {\n io.logError(\"Error: could not parse YAML config\");\n io.exit(1);\n return;\n }\n\n const result = convertConfig(parsed);\n const fixtureJson = JSON.stringify({ fixtures: result.fixtures }, null, 2);\n\n if (outputPath) {\n try {\n writeFileSync(outputPath, fixtureJson + \"\\n\", \"utf-8\");\n } catch (err) {\n io.logError(`Error writing output: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n io.log(`Wrote fixtures to ${outputPath}`);\n\n if (result.mcpTools) {\n const configPath = outputPath.endsWith(\".json\")\n ? outputPath.replace(/\\.json$/, \".aimock.json\")\n : outputPath + \".aimock.json\";\n const aimockConfig = {\n llm: { fixtures: outputPath },\n mcp: {\n tools: result.mcpTools.map((t) => ({\n name: t.name,\n description: t.description ?? \"\",\n inputSchema: t.inputSchema ?? {},\n result: `Mock result for ${t.name}`,\n })),\n },\n };\n try {\n writeFileSync(configPath, JSON.stringify(aimockConfig, null, 2) + \"\\n\", \"utf-8\");\n } catch (err) {\n io.logError(`Error writing config: ${(err as Error).message}`);\n io.exit(1);\n return;\n }\n io.log(`Wrote aimock config with MCP tools to ${configPath}`);\n }\n } else {\n io.log(fixtureJson);\n\n if (result.mcpTools) {\n io.log(\"\\n--- MCP Tools (aimock config format) ---\");\n io.log(JSON.stringify({ mcp: { tools: result.mcpTools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EAAE;KAChC,QAAQ,mBAAmB,EAAE;KAC9B,EAAE,EACJ;IACF;AACD,OAAI;AACF,kBAAc,YAAY,KAAK,UAAU,cAAc,MAAM,EAAE,GAAG,MAAM,QAAQ;YACzE,KAAK;AACZ,OAAG,SAAS,yBAA0B,IAAc,UAAU;AAC9D,OAAG,KAAK,EAAE;AACV;;AAEF,MAAG,IAAI,yCAAyC,aAAa;;QAE1D;AACL,KAAG,IAAI,YAAY;AAEnB,MAAI,OAAO,UAAU;AACnB,MAAG,IAAI,6CAA6C;AACpD,MAAG,IAAI,KAAK,UAAU,EAAE,KAAK,EAAE,OAAO,OAAO,UAAU,EAAE,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/jest.cjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_fixture_loader = require('./fixture-loader.cjs');
|
|
4
|
+
const require_llmock = require('./llmock.cjs');
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
let node_fs = require("node:fs");
|
|
7
|
+
|
|
8
|
+
//#region src/jest.ts
|
|
9
|
+
/**
|
|
10
|
+
* Start an aimock server for the duration of the test suite.
|
|
11
|
+
*
|
|
12
|
+
* - `beforeAll`: starts the server and optionally loads fixtures
|
|
13
|
+
* - `beforeEach`: resets fixture match counts (not fixtures themselves)
|
|
14
|
+
* - `afterAll`: stops the server
|
|
15
|
+
*
|
|
16
|
+
* Returns a getter function — call it inside tests to access the handle.
|
|
17
|
+
*
|
|
18
|
+
* NOTE: Jest globals (beforeAll, afterAll, beforeEach) must be available
|
|
19
|
+
* in the test environment. This works with the default jest configuration.
|
|
20
|
+
*/
|
|
21
|
+
function useAimock(options = {}) {
|
|
22
|
+
let handle = null;
|
|
23
|
+
beforeAll(async () => {
|
|
24
|
+
const { fixtures: fixturePath, patchEnv, ...serverOpts } = options;
|
|
25
|
+
const llm = new require_llmock.LLMock(serverOpts);
|
|
26
|
+
if (fixturePath) {
|
|
27
|
+
const loadedFixtures = loadFixtures((0, node_path.resolve)(fixturePath));
|
|
28
|
+
for (const f of loadedFixtures) llm.addFixture(f);
|
|
29
|
+
}
|
|
30
|
+
const url = await llm.start();
|
|
31
|
+
if (patchEnv !== false) {
|
|
32
|
+
process.env.OPENAI_BASE_URL = `${url}/v1`;
|
|
33
|
+
process.env.ANTHROPIC_BASE_URL = `${url}/v1`;
|
|
34
|
+
}
|
|
35
|
+
handle = {
|
|
36
|
+
llm,
|
|
37
|
+
url
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
if (handle) handle.llm.resetMatchCounts();
|
|
42
|
+
});
|
|
43
|
+
afterAll(async () => {
|
|
44
|
+
if (handle) {
|
|
45
|
+
if (options.patchEnv !== false) {
|
|
46
|
+
delete process.env.OPENAI_BASE_URL;
|
|
47
|
+
delete process.env.ANTHROPIC_BASE_URL;
|
|
48
|
+
}
|
|
49
|
+
await handle.llm.stop();
|
|
50
|
+
handle = null;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return () => {
|
|
54
|
+
if (!handle) throw new Error("useAimock(): server not started — are you calling this inside a test?");
|
|
55
|
+
return handle;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function loadFixtures(fixturePath) {
|
|
59
|
+
try {
|
|
60
|
+
if ((0, node_fs.statSync)(fixturePath).isDirectory()) return require_fixture_loader.loadFixturesFromDir(fixturePath);
|
|
61
|
+
return require_fixture_loader.loadFixtureFile(fixturePath);
|
|
62
|
+
} catch {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
exports.LLMock = require_llmock.LLMock;
|
|
69
|
+
exports.useAimock = useAimock;
|
|
70
|
+
//# sourceMappingURL=jest.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.cjs","names":["LLMock","loadFixturesFromDir","loadFixtureFile"],"sources":["../src/jest.ts"],"sourcesContent":["/**\n * Jest integration for aimock.\n *\n * Usage:\n * import { useAimock } from \"@copilotkit/aimock/jest\";\n *\n * const mock = useAimock({ fixtures: \"./fixtures\" });\n *\n * it(\"responds\", async () => {\n * const res = await fetch(`${mock().url}/v1/chat/completions`, { ... });\n * });\n */\n\n/* eslint-disable no-var */\n// Jest globals — available at runtime in jest test files\ndeclare var beforeAll: (fn: () => Promise<void> | void, timeout?: number) => void;\ndeclare var afterAll: (fn: () => Promise<void> | void, timeout?: number) => void;\ndeclare var beforeEach: (fn: () => Promise<void> | void, timeout?: number) => void;\n/* eslint-enable no-var */\n\nimport { LLMock } from \"./llmock.js\";\nimport { loadFixtureFile, loadFixturesFromDir } from \"./fixture-loader.js\";\nimport type { Fixture, MockServerOptions } from \"./types.js\";\nimport { statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nexport interface UseAimockOptions extends MockServerOptions {\n /** Path to fixture file or directory. Loaded automatically on start. */\n fixtures?: string;\n /** If true, sets process.env.OPENAI_BASE_URL to the mock URL + /v1. */\n patchEnv?: boolean;\n}\n\nexport interface AimockHandle {\n /** The LLMock instance. */\n readonly llm: LLMock;\n /** The server URL (e.g., http://127.0.0.1:4010). */\n readonly url: string;\n}\n\n/**\n * Start an aimock server for the duration of the test suite.\n *\n * - `beforeAll`: starts the server and optionally loads fixtures\n * - `beforeEach`: resets fixture match counts (not fixtures themselves)\n * - `afterAll`: stops the server\n *\n * Returns a getter function — call it inside tests to access the handle.\n *\n * NOTE: Jest globals (beforeAll, afterAll, beforeEach) must be available\n * in the test environment. This works with the default jest configuration.\n */\nexport function useAimock(options: UseAimockOptions = {}): () => AimockHandle {\n let handle: AimockHandle | null = null;\n\n beforeAll(async () => {\n const { fixtures: fixturePath, patchEnv, ...serverOpts } = options;\n const llm = new LLMock(serverOpts);\n\n if (fixturePath) {\n const resolved = resolve(fixturePath);\n const loadedFixtures = loadFixtures(resolved);\n for (const f of loadedFixtures) {\n llm.addFixture(f);\n }\n }\n\n const url = await llm.start();\n\n if (patchEnv !== false) {\n process.env.OPENAI_BASE_URL = `${url}/v1`;\n process.env.ANTHROPIC_BASE_URL = `${url}/v1`;\n }\n\n handle = { llm, url };\n });\n\n beforeEach(() => {\n if (handle) {\n handle.llm.resetMatchCounts();\n }\n });\n\n afterAll(async () => {\n if (handle) {\n if (options.patchEnv !== false) {\n delete process.env.OPENAI_BASE_URL;\n delete process.env.ANTHROPIC_BASE_URL;\n }\n await handle.llm.stop();\n handle = null;\n }\n });\n\n return () => {\n if (!handle) {\n throw new Error(\"useAimock(): server not started — are you calling this inside a test?\");\n }\n return handle;\n };\n}\n\nfunction loadFixtures(fixturePath: string): Fixture[] {\n try {\n const stat = statSync(fixturePath);\n if (stat.isDirectory()) {\n return loadFixturesFromDir(fixturePath);\n }\n return loadFixtureFile(fixturePath);\n } catch {\n return [];\n }\n}\n\nexport { LLMock } from \"./llmock.js\";\nexport type { MockServerOptions, Fixture } from \"./types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,UAAU,UAA4B,EAAE,EAAsB;CAC5E,IAAI,SAA8B;AAElC,WAAU,YAAY;EACpB,MAAM,EAAE,UAAU,aAAa,UAAU,GAAG,eAAe;EAC3D,MAAM,MAAM,IAAIA,sBAAO,WAAW;AAElC,MAAI,aAAa;GAEf,MAAM,iBAAiB,oCADE,YAAY,CACQ;AAC7C,QAAK,MAAM,KAAK,eACd,KAAI,WAAW,EAAE;;EAIrB,MAAM,MAAM,MAAM,IAAI,OAAO;AAE7B,MAAI,aAAa,OAAO;AACtB,WAAQ,IAAI,kBAAkB,GAAG,IAAI;AACrC,WAAQ,IAAI,qBAAqB,GAAG,IAAI;;AAG1C,WAAS;GAAE;GAAK;GAAK;GACrB;AAEF,kBAAiB;AACf,MAAI,OACF,QAAO,IAAI,kBAAkB;GAE/B;AAEF,UAAS,YAAY;AACnB,MAAI,QAAQ;AACV,OAAI,QAAQ,aAAa,OAAO;AAC9B,WAAO,QAAQ,IAAI;AACnB,WAAO,QAAQ,IAAI;;AAErB,SAAM,OAAO,IAAI,MAAM;AACvB,YAAS;;GAEX;AAEF,cAAa;AACX,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,wEAAwE;AAE1F,SAAO;;;AAIX,SAAS,aAAa,aAAgC;AACpD,KAAI;AAEF,4BADsB,YAAY,CACzB,aAAa,CACpB,QAAOC,2CAAoB,YAAY;AAEzC,SAAOC,uCAAgB,YAAY;SAC7B;AACN,SAAO,EAAE"}
|
package/dist/jest.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Fixture, MockServerOptions } from "./types.cjs";
|
|
2
|
+
import { LLMock } from "./llmock.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/jest.d.ts
|
|
5
|
+
|
|
6
|
+
interface UseAimockOptions extends MockServerOptions {
|
|
7
|
+
/** Path to fixture file or directory. Loaded automatically on start. */
|
|
8
|
+
fixtures?: string;
|
|
9
|
+
/** If true, sets process.env.OPENAI_BASE_URL to the mock URL + /v1. */
|
|
10
|
+
patchEnv?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface AimockHandle {
|
|
13
|
+
/** The LLMock instance. */
|
|
14
|
+
readonly llm: LLMock;
|
|
15
|
+
/** The server URL (e.g., http://127.0.0.1:4010). */
|
|
16
|
+
readonly url: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Start an aimock server for the duration of the test suite.
|
|
20
|
+
*
|
|
21
|
+
* - `beforeAll`: starts the server and optionally loads fixtures
|
|
22
|
+
* - `beforeEach`: resets fixture match counts (not fixtures themselves)
|
|
23
|
+
* - `afterAll`: stops the server
|
|
24
|
+
*
|
|
25
|
+
* Returns a getter function — call it inside tests to access the handle.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: Jest globals (beforeAll, afterAll, beforeEach) must be available
|
|
28
|
+
* in the test environment. This works with the default jest configuration.
|
|
29
|
+
*/
|
|
30
|
+
declare function useAimock(options?: UseAimockOptions): () => AimockHandle;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AimockHandle, type Fixture, LLMock, type MockServerOptions, UseAimockOptions, useAimock };
|
|
33
|
+
//# sourceMappingURL=jest.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.d.cts","names":[],"sources":["../src/jest.ts"],"sourcesContent":[],"mappings":";;;;;UA0BiB,gBAAA,SAAyB;;;;;;UAOzB,YAAA;;gBAED;;;;;;;;;;;;;;;;iBAiBA,SAAA,WAAmB,yBAA8B"}
|
package/dist/jest.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Fixture, MockServerOptions } from "./types.js";
|
|
2
|
+
import { LLMock } from "./llmock.js";
|
|
3
|
+
|
|
4
|
+
//#region src/jest.d.ts
|
|
5
|
+
|
|
6
|
+
interface UseAimockOptions extends MockServerOptions {
|
|
7
|
+
/** Path to fixture file or directory. Loaded automatically on start. */
|
|
8
|
+
fixtures?: string;
|
|
9
|
+
/** If true, sets process.env.OPENAI_BASE_URL to the mock URL + /v1. */
|
|
10
|
+
patchEnv?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface AimockHandle {
|
|
13
|
+
/** The LLMock instance. */
|
|
14
|
+
readonly llm: LLMock;
|
|
15
|
+
/** The server URL (e.g., http://127.0.0.1:4010). */
|
|
16
|
+
readonly url: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Start an aimock server for the duration of the test suite.
|
|
20
|
+
*
|
|
21
|
+
* - `beforeAll`: starts the server and optionally loads fixtures
|
|
22
|
+
* - `beforeEach`: resets fixture match counts (not fixtures themselves)
|
|
23
|
+
* - `afterAll`: stops the server
|
|
24
|
+
*
|
|
25
|
+
* Returns a getter function — call it inside tests to access the handle.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: Jest globals (beforeAll, afterAll, beforeEach) must be available
|
|
28
|
+
* in the test environment. This works with the default jest configuration.
|
|
29
|
+
*/
|
|
30
|
+
declare function useAimock(options?: UseAimockOptions): () => AimockHandle;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AimockHandle, type Fixture, LLMock, type MockServerOptions, UseAimockOptions, useAimock };
|
|
33
|
+
//# sourceMappingURL=jest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.d.ts","names":[],"sources":["../src/jest.ts"],"sourcesContent":[],"mappings":";;;;;UA0BiB,gBAAA,SAAyB;;;;;;UAOzB,YAAA;;gBAED;;;;;;;;;;;;;;;;iBAiBA,SAAA,WAAmB,yBAA8B"}
|
package/dist/jest.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { loadFixtureFile, loadFixturesFromDir } from "./fixture-loader.js";
|
|
2
|
+
import { LLMock } from "./llmock.js";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { statSync } from "node:fs";
|
|
5
|
+
|
|
6
|
+
//#region src/jest.ts
|
|
7
|
+
/**
|
|
8
|
+
* Start an aimock server for the duration of the test suite.
|
|
9
|
+
*
|
|
10
|
+
* - `beforeAll`: starts the server and optionally loads fixtures
|
|
11
|
+
* - `beforeEach`: resets fixture match counts (not fixtures themselves)
|
|
12
|
+
* - `afterAll`: stops the server
|
|
13
|
+
*
|
|
14
|
+
* Returns a getter function — call it inside tests to access the handle.
|
|
15
|
+
*
|
|
16
|
+
* NOTE: Jest globals (beforeAll, afterAll, beforeEach) must be available
|
|
17
|
+
* in the test environment. This works with the default jest configuration.
|
|
18
|
+
*/
|
|
19
|
+
function useAimock(options = {}) {
|
|
20
|
+
let handle = null;
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
const { fixtures: fixturePath, patchEnv, ...serverOpts } = options;
|
|
23
|
+
const llm = new LLMock(serverOpts);
|
|
24
|
+
if (fixturePath) {
|
|
25
|
+
const loadedFixtures = loadFixtures(resolve(fixturePath));
|
|
26
|
+
for (const f of loadedFixtures) llm.addFixture(f);
|
|
27
|
+
}
|
|
28
|
+
const url = await llm.start();
|
|
29
|
+
if (patchEnv !== false) {
|
|
30
|
+
process.env.OPENAI_BASE_URL = `${url}/v1`;
|
|
31
|
+
process.env.ANTHROPIC_BASE_URL = `${url}/v1`;
|
|
32
|
+
}
|
|
33
|
+
handle = {
|
|
34
|
+
llm,
|
|
35
|
+
url
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
if (handle) handle.llm.resetMatchCounts();
|
|
40
|
+
});
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
if (handle) {
|
|
43
|
+
if (options.patchEnv !== false) {
|
|
44
|
+
delete process.env.OPENAI_BASE_URL;
|
|
45
|
+
delete process.env.ANTHROPIC_BASE_URL;
|
|
46
|
+
}
|
|
47
|
+
await handle.llm.stop();
|
|
48
|
+
handle = null;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return () => {
|
|
52
|
+
if (!handle) throw new Error("useAimock(): server not started — are you calling this inside a test?");
|
|
53
|
+
return handle;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function loadFixtures(fixturePath) {
|
|
57
|
+
try {
|
|
58
|
+
if (statSync(fixturePath).isDirectory()) return loadFixturesFromDir(fixturePath);
|
|
59
|
+
return loadFixtureFile(fixturePath);
|
|
60
|
+
} catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { LLMock, useAimock };
|
|
67
|
+
//# sourceMappingURL=jest.js.map
|
package/dist/jest.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.js","names":[],"sources":["../src/jest.ts"],"sourcesContent":["/**\n * Jest integration for aimock.\n *\n * Usage:\n * import { useAimock } from \"@copilotkit/aimock/jest\";\n *\n * const mock = useAimock({ fixtures: \"./fixtures\" });\n *\n * it(\"responds\", async () => {\n * const res = await fetch(`${mock().url}/v1/chat/completions`, { ... });\n * });\n */\n\n/* eslint-disable no-var */\n// Jest globals — available at runtime in jest test files\ndeclare var beforeAll: (fn: () => Promise<void> | void, timeout?: number) => void;\ndeclare var afterAll: (fn: () => Promise<void> | void, timeout?: number) => void;\ndeclare var beforeEach: (fn: () => Promise<void> | void, timeout?: number) => void;\n/* eslint-enable no-var */\n\nimport { LLMock } from \"./llmock.js\";\nimport { loadFixtureFile, loadFixturesFromDir } from \"./fixture-loader.js\";\nimport type { Fixture, MockServerOptions } from \"./types.js\";\nimport { statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nexport interface UseAimockOptions extends MockServerOptions {\n /** Path to fixture file or directory. Loaded automatically on start. */\n fixtures?: string;\n /** If true, sets process.env.OPENAI_BASE_URL to the mock URL + /v1. */\n patchEnv?: boolean;\n}\n\nexport interface AimockHandle {\n /** The LLMock instance. */\n readonly llm: LLMock;\n /** The server URL (e.g., http://127.0.0.1:4010). */\n readonly url: string;\n}\n\n/**\n * Start an aimock server for the duration of the test suite.\n *\n * - `beforeAll`: starts the server and optionally loads fixtures\n * - `beforeEach`: resets fixture match counts (not fixtures themselves)\n * - `afterAll`: stops the server\n *\n * Returns a getter function — call it inside tests to access the handle.\n *\n * NOTE: Jest globals (beforeAll, afterAll, beforeEach) must be available\n * in the test environment. This works with the default jest configuration.\n */\nexport function useAimock(options: UseAimockOptions = {}): () => AimockHandle {\n let handle: AimockHandle | null = null;\n\n beforeAll(async () => {\n const { fixtures: fixturePath, patchEnv, ...serverOpts } = options;\n const llm = new LLMock(serverOpts);\n\n if (fixturePath) {\n const resolved = resolve(fixturePath);\n const loadedFixtures = loadFixtures(resolved);\n for (const f of loadedFixtures) {\n llm.addFixture(f);\n }\n }\n\n const url = await llm.start();\n\n if (patchEnv !== false) {\n process.env.OPENAI_BASE_URL = `${url}/v1`;\n process.env.ANTHROPIC_BASE_URL = `${url}/v1`;\n }\n\n handle = { llm, url };\n });\n\n beforeEach(() => {\n if (handle) {\n handle.llm.resetMatchCounts();\n }\n });\n\n afterAll(async () => {\n if (handle) {\n if (options.patchEnv !== false) {\n delete process.env.OPENAI_BASE_URL;\n delete process.env.ANTHROPIC_BASE_URL;\n }\n await handle.llm.stop();\n handle = null;\n }\n });\n\n return () => {\n if (!handle) {\n throw new Error(\"useAimock(): server not started — are you calling this inside a test?\");\n }\n return handle;\n };\n}\n\nfunction loadFixtures(fixturePath: string): Fixture[] {\n try {\n const stat = statSync(fixturePath);\n if (stat.isDirectory()) {\n return loadFixturesFromDir(fixturePath);\n }\n return loadFixtureFile(fixturePath);\n } catch {\n return [];\n }\n}\n\nexport { LLMock } from \"./llmock.js\";\nexport type { MockServerOptions, Fixture } from \"./types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,SAAgB,UAAU,UAA4B,EAAE,EAAsB;CAC5E,IAAI,SAA8B;AAElC,WAAU,YAAY;EACpB,MAAM,EAAE,UAAU,aAAa,UAAU,GAAG,eAAe;EAC3D,MAAM,MAAM,IAAI,OAAO,WAAW;AAElC,MAAI,aAAa;GAEf,MAAM,iBAAiB,aADN,QAAQ,YAAY,CACQ;AAC7C,QAAK,MAAM,KAAK,eACd,KAAI,WAAW,EAAE;;EAIrB,MAAM,MAAM,MAAM,IAAI,OAAO;AAE7B,MAAI,aAAa,OAAO;AACtB,WAAQ,IAAI,kBAAkB,GAAG,IAAI;AACrC,WAAQ,IAAI,qBAAqB,GAAG,IAAI;;AAG1C,WAAS;GAAE;GAAK;GAAK;GACrB;AAEF,kBAAiB;AACf,MAAI,OACF,QAAO,IAAI,kBAAkB;GAE/B;AAEF,UAAS,YAAY;AACnB,MAAI,QAAQ;AACV,OAAI,QAAQ,aAAa,OAAO;AAC9B,WAAO,QAAQ,IAAI;AACnB,WAAO,QAAQ,IAAI;;AAErB,SAAM,OAAO,IAAI,MAAM;AACvB,YAAS;;GAEX;AAEF,cAAa;AACX,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,wEAAwE;AAE1F,SAAO;;;AAIX,SAAS,aAAa,aAAgC;AACpD,KAAI;AAEF,MADa,SAAS,YAAY,CACzB,aAAa,CACpB,QAAO,oBAAoB,YAAY;AAEzC,SAAO,gBAAgB,YAAY;SAC7B;AACN,SAAO,EAAE"}
|