@copilotkit/aimock 1.12.0 → 1.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/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +5 -5
- package/README.md +26 -3
- 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/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.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/fixture-loader.cjs +131 -29
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts +9 -2
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts +9 -2
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +132 -31
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini.cjs +76 -55
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +77 -56
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +142 -76
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +14 -4
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +14 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +142 -77
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- 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/llmock.cjs +1 -1
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +6 -6
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +6 -6
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +2 -2
- package/dist/llmock.js.map +1 -1
- package/dist/messages.cjs +69 -63
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +70 -64
- package/dist/messages.js.map +1 -1
- 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/recorder.cjs +1 -1
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.js +1 -1
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +66 -57
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +3 -3
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +3 -3
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +67 -58
- package/dist/responses.js.map +1 -1
- package/dist/server.cjs +57 -30
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +58 -31
- package/dist/server.js.map +1 -1
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js.map +1 -1
- package/dist/types.d.cts +64 -11
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +64 -11
- package/dist/types.d.ts.map +1 -1
- 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/example-multi-turn.json +1 -1
- package/fixtures/example-tool-call.json +1 -1
- package/fixtures/examples/a2a/a2a-config.json +42 -0
- package/fixtures/examples/adk/gemini-agent.json +47 -0
- package/fixtures/examples/agui/agui-text-response.json +35 -0
- package/fixtures/examples/chaos/chaos-config.json +10 -0
- package/fixtures/examples/crewai/multi-agent-crew.json +16 -0
- package/fixtures/examples/full-suite.json +116 -0
- package/fixtures/examples/langchain/agent-loop.json +27 -0
- package/fixtures/examples/llamaindex/aimock-config.json +62 -0
- package/fixtures/examples/llamaindex/rag-pipeline.json +34 -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/mastra/agent-workflow.json +32 -0
- package/fixtures/examples/mcp/mcp-config.json +26 -0
- package/fixtures/examples/pydanticai/structured-output.json +15 -0
- package/fixtures/examples/record-replay/record-config.json +11 -0
- package/fixtures/examples/vector/vector-config.json +34 -0
- package/package.json +60 -1
- package/skills/write-fixtures/SKILL.md +148 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-vidaimock.cjs","names":[],"sources":["../src/convert-vidaimock.ts"],"sourcesContent":["/**\n * VidaiMock -> aimock Fixture Converter\n *\n * Core conversion logic. Used by both the CLI (`aimock convert vidaimock`)\n * and the standalone script (`scripts/convert-vidaimock.ts`).\n */\n\nimport { readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { resolve, basename, extname } from \"node:path\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface AimockFixture {\n match: { userMessage: string };\n response: { content: string };\n}\n\nexport interface AimockFixtureFile {\n fixtures: AimockFixture[];\n}\n\n// ---------------------------------------------------------------------------\n// Tera template stripping\n// ---------------------------------------------------------------------------\n\n/**\n * Strip Tera template syntax and extract a usable response content string.\n *\n * Strategy:\n * 1. If the template looks like JSON, try to pull out the nested\n * `choices[].message.content` value (the most common VidaiMock pattern).\n * 2. Otherwise fall back to stripping all Tera delimiters and returning the\n * remaining text with placeholder variable names.\n */\nexport function stripTeraTemplate(raw: string): string {\n const trimmed = raw.trim();\n\n // --- Attempt JSON extraction first -----------------------------------\n const contentValue = extractJsonContent(trimmed);\n if (contentValue !== null) return contentValue;\n\n // --- Fallback: strip Tera syntax -------------------------------------\n let text = trimmed;\n\n // Remove comment blocks {# ... #}\n text = text.replace(/\\{#[\\s\\S]*?#\\}/g, \"\");\n\n // Remove block tags {% ... %}\n text = text.replace(/\\{%[\\s\\S]*?%\\}/g, \"\");\n\n // Replace expression tags {{ expr }} with the expression name\n text = text.replace(/\\{\\{\\s*([\\w.]+)\\s*\\}\\}/g, \"[$1]\");\n\n // Collapse excessive whitespace but preserve intentional newlines\n text = text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter((l) => l.length > 0)\n .join(\"\\n\");\n\n return text;\n}\n\n/**\n * Try to parse the template as JSON (after substituting Tera expressions with\n * dummy strings) and pull out `choices[0].message.content`.\n */\nfunction extractJsonContent(raw: string): string | null {\n try {\n // Step 1: remove Tera comments and blocks\n let substituted = raw.replace(/\\{#[\\s\\S]*?#\\}/g, \"\").replace(/\\{%[\\s\\S]*?%\\}/g, \"\");\n\n // Step 2: Replace Tera expressions inside existing JSON strings.\n // Pattern: the expression is already within quotes, e.g. \"foo-{{ bar }}-baz\"\n // We replace the {{ ... }} with the placeholder without adding extra quotes.\n substituted = substituted.replace(\n /\"([^\"]*?)\\{\\{\\s*([\\w.]+)\\s*\\}\\}([^\"]*?)\"/g,\n (_, before, varName, after) => `\"${before}[${varName}]${after}\"`,\n );\n\n // Step 3: Replace standalone Tera expressions (not inside quotes),\n // e.g. a bare `{{ content }}` used as a JSON value — wrap with quotes.\n substituted = substituted.replace(/\\{\\{\\s*([\\w.]+)\\s*\\}\\}/g, '\"[$1]\"');\n\n const parsed = JSON.parse(substituted);\n\n if (\n parsed &&\n Array.isArray(parsed.choices) &&\n parsed.choices.length > 0 &&\n parsed.choices[0]?.message?.content !== undefined\n ) {\n return String(parsed.choices[0].message.content);\n }\n } catch {\n // Not valid JSON even after substitution — fall through\n }\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// Filename -> match derivation\n// ---------------------------------------------------------------------------\n\n/**\n * Derive a `userMessage` match string from the template filename.\n *\n * Examples:\n * \"greeting.tera\" -> \"greeting\"\n * \"tell_me_a_joke.json\" -> \"tell me a joke\"\n * \"003-weather.txt\" -> \"weather\"\n */\nexport function deriveMatchFromFilename(filename: string): string {\n let name = basename(filename, extname(filename));\n\n // Strip leading numeric prefixes like \"003-\"\n name = name.replace(/^\\d+[-_]/, \"\");\n\n // Replace underscores / hyphens with spaces\n name = name.replace(/[-_]+/g, \" \");\n\n return name.trim();\n}\n\n// ---------------------------------------------------------------------------\n// File / directory conversion\n// ---------------------------------------------------------------------------\n\nconst TEMPLATE_EXTENSIONS = new Set([\n \".tera\",\n \".json\",\n \".txt\",\n \".html\",\n \".jinja\",\n \".jinja2\",\n \".j2\",\n]);\n\nexport function convertFile(filePath: string): AimockFixture | null {\n let raw: string;\n try {\n raw = readFileSync(filePath, \"utf-8\");\n } catch {\n // Unreadable / binary file — skip gracefully\n return null;\n }\n\n const content = stripTeraTemplate(raw);\n if (!content) return null;\n\n const match = deriveMatchFromFilename(filePath);\n return { match: { userMessage: match }, response: { content } };\n}\n\nexport function convertDirectory(dirPath: string): AimockFixture[] {\n const fixtures: AimockFixture[] = [];\n\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return fixtures;\n throw err; // permission errors, etc. should propagate\n }\n\n for (const entry of entries.sort()) {\n const fullPath = resolve(dirPath, entry);\n try {\n if (!statSync(fullPath).isFile()) continue;\n } catch {\n continue;\n }\n\n const ext = extname(entry).toLowerCase();\n if (!TEMPLATE_EXTENSIONS.has(ext)) continue;\n\n const fixture = convertFile(fullPath);\n if (fixture) fixtures.push(fixture);\n }\n\n return fixtures;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,kBAAkB,KAAqB;CACrD,MAAM,UAAU,IAAI,MAAM;CAG1B,MAAM,eAAe,mBAAmB,QAAQ;AAChD,KAAI,iBAAiB,KAAM,QAAO;CAGlC,IAAI,OAAO;AAGX,QAAO,KAAK,QAAQ,mBAAmB,GAAG;AAG1C,QAAO,KAAK,QAAQ,mBAAmB,GAAG;AAG1C,QAAO,KAAK,QAAQ,2BAA2B,OAAO;AAGtD,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,MAAM,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AAM;;AAGR,MAAK,MAAM,SAAS,QAAQ,MAAM,EAAE;EAClC,MAAM,kCAAmB,SAAS,MAAM;AACxC,MAAI;AACF,OAAI,uBAAU,SAAS,CAAC,QAAQ,CAAE;UAC5B;AACN;;EAGF,MAAM,6BAAc,MAAM,CAAC,aAAa;AACxC,MAAI,CAAC,oBAAoB,IAAI,IAAI,CAAE;EAEnC,MAAM,UAAU,YAAY,SAAS;AACrC,MAAI,QAAS,UAAS,KAAK,QAAQ;;AAGrC,QAAO"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { basename, extname, resolve } from "node:path";
|
|
2
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
|
|
4
|
+
//#region src/convert-vidaimock.ts
|
|
5
|
+
/**
|
|
6
|
+
* VidaiMock -> aimock Fixture Converter
|
|
7
|
+
*
|
|
8
|
+
* Core conversion logic. Used by both the CLI (`aimock convert vidaimock`)
|
|
9
|
+
* and the standalone script (`scripts/convert-vidaimock.ts`).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Strip Tera template syntax and extract a usable response content string.
|
|
13
|
+
*
|
|
14
|
+
* Strategy:
|
|
15
|
+
* 1. If the template looks like JSON, try to pull out the nested
|
|
16
|
+
* `choices[].message.content` value (the most common VidaiMock pattern).
|
|
17
|
+
* 2. Otherwise fall back to stripping all Tera delimiters and returning the
|
|
18
|
+
* remaining text with placeholder variable names.
|
|
19
|
+
*/
|
|
20
|
+
function stripTeraTemplate(raw) {
|
|
21
|
+
const trimmed = raw.trim();
|
|
22
|
+
const contentValue = extractJsonContent(trimmed);
|
|
23
|
+
if (contentValue !== null) return contentValue;
|
|
24
|
+
let text = trimmed;
|
|
25
|
+
text = text.replace(/\{#[\s\S]*?#\}/g, "");
|
|
26
|
+
text = text.replace(/\{%[\s\S]*?%\}/g, "");
|
|
27
|
+
text = text.replace(/\{\{\s*([\w.]+)\s*\}\}/g, "[$1]");
|
|
28
|
+
text = text.split("\n").map((l) => l.trim()).filter((l) => l.length > 0).join("\n");
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Try to parse the template as JSON (after substituting Tera expressions with
|
|
33
|
+
* dummy strings) and pull out `choices[0].message.content`.
|
|
34
|
+
*/
|
|
35
|
+
function extractJsonContent(raw) {
|
|
36
|
+
try {
|
|
37
|
+
let substituted = raw.replace(/\{#[\s\S]*?#\}/g, "").replace(/\{%[\s\S]*?%\}/g, "");
|
|
38
|
+
substituted = substituted.replace(/"([^"]*?)\{\{\s*([\w.]+)\s*\}\}([^"]*?)"/g, (_, before, varName, after) => `"${before}[${varName}]${after}"`);
|
|
39
|
+
substituted = substituted.replace(/\{\{\s*([\w.]+)\s*\}\}/g, "\"[$1]\"");
|
|
40
|
+
const parsed = JSON.parse(substituted);
|
|
41
|
+
if (parsed && Array.isArray(parsed.choices) && parsed.choices.length > 0 && parsed.choices[0]?.message?.content !== void 0) return String(parsed.choices[0].message.content);
|
|
42
|
+
} catch {}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Derive a `userMessage` match string from the template filename.
|
|
47
|
+
*
|
|
48
|
+
* Examples:
|
|
49
|
+
* "greeting.tera" -> "greeting"
|
|
50
|
+
* "tell_me_a_joke.json" -> "tell me a joke"
|
|
51
|
+
* "003-weather.txt" -> "weather"
|
|
52
|
+
*/
|
|
53
|
+
function deriveMatchFromFilename(filename) {
|
|
54
|
+
let name = basename(filename, extname(filename));
|
|
55
|
+
name = name.replace(/^\d+[-_]/, "");
|
|
56
|
+
name = name.replace(/[-_]+/g, " ");
|
|
57
|
+
return name.trim();
|
|
58
|
+
}
|
|
59
|
+
const TEMPLATE_EXTENSIONS = new Set([
|
|
60
|
+
".tera",
|
|
61
|
+
".json",
|
|
62
|
+
".txt",
|
|
63
|
+
".html",
|
|
64
|
+
".jinja",
|
|
65
|
+
".jinja2",
|
|
66
|
+
".j2"
|
|
67
|
+
]);
|
|
68
|
+
function convertFile(filePath) {
|
|
69
|
+
let raw;
|
|
70
|
+
try {
|
|
71
|
+
raw = readFileSync(filePath, "utf-8");
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const content = stripTeraTemplate(raw);
|
|
76
|
+
if (!content) return null;
|
|
77
|
+
return {
|
|
78
|
+
match: { userMessage: deriveMatchFromFilename(filePath) },
|
|
79
|
+
response: { content }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function convertDirectory(dirPath) {
|
|
83
|
+
const fixtures = [];
|
|
84
|
+
let entries;
|
|
85
|
+
try {
|
|
86
|
+
entries = readdirSync(dirPath);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
if (err.code === "ENOENT") return fixtures;
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
for (const entry of entries.sort()) {
|
|
92
|
+
const fullPath = resolve(dirPath, entry);
|
|
93
|
+
try {
|
|
94
|
+
if (!statSync(fullPath).isFile()) continue;
|
|
95
|
+
} catch {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const ext = extname(entry).toLowerCase();
|
|
99
|
+
if (!TEMPLATE_EXTENSIONS.has(ext)) continue;
|
|
100
|
+
const fixture = convertFile(fullPath);
|
|
101
|
+
if (fixture) fixtures.push(fixture);
|
|
102
|
+
}
|
|
103
|
+
return fixtures;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { convertDirectory, convertFile };
|
|
108
|
+
//# sourceMappingURL=convert-vidaimock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-vidaimock.js","names":[],"sources":["../src/convert-vidaimock.ts"],"sourcesContent":["/**\n * VidaiMock -> aimock Fixture Converter\n *\n * Core conversion logic. Used by both the CLI (`aimock convert vidaimock`)\n * and the standalone script (`scripts/convert-vidaimock.ts`).\n */\n\nimport { readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { resolve, basename, extname } from \"node:path\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface AimockFixture {\n match: { userMessage: string };\n response: { content: string };\n}\n\nexport interface AimockFixtureFile {\n fixtures: AimockFixture[];\n}\n\n// ---------------------------------------------------------------------------\n// Tera template stripping\n// ---------------------------------------------------------------------------\n\n/**\n * Strip Tera template syntax and extract a usable response content string.\n *\n * Strategy:\n * 1. If the template looks like JSON, try to pull out the nested\n * `choices[].message.content` value (the most common VidaiMock pattern).\n * 2. Otherwise fall back to stripping all Tera delimiters and returning the\n * remaining text with placeholder variable names.\n */\nexport function stripTeraTemplate(raw: string): string {\n const trimmed = raw.trim();\n\n // --- Attempt JSON extraction first -----------------------------------\n const contentValue = extractJsonContent(trimmed);\n if (contentValue !== null) return contentValue;\n\n // --- Fallback: strip Tera syntax -------------------------------------\n let text = trimmed;\n\n // Remove comment blocks {# ... #}\n text = text.replace(/\\{#[\\s\\S]*?#\\}/g, \"\");\n\n // Remove block tags {% ... %}\n text = text.replace(/\\{%[\\s\\S]*?%\\}/g, \"\");\n\n // Replace expression tags {{ expr }} with the expression name\n text = text.replace(/\\{\\{\\s*([\\w.]+)\\s*\\}\\}/g, \"[$1]\");\n\n // Collapse excessive whitespace but preserve intentional newlines\n text = text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter((l) => l.length > 0)\n .join(\"\\n\");\n\n return text;\n}\n\n/**\n * Try to parse the template as JSON (after substituting Tera expressions with\n * dummy strings) and pull out `choices[0].message.content`.\n */\nfunction extractJsonContent(raw: string): string | null {\n try {\n // Step 1: remove Tera comments and blocks\n let substituted = raw.replace(/\\{#[\\s\\S]*?#\\}/g, \"\").replace(/\\{%[\\s\\S]*?%\\}/g, \"\");\n\n // Step 2: Replace Tera expressions inside existing JSON strings.\n // Pattern: the expression is already within quotes, e.g. \"foo-{{ bar }}-baz\"\n // We replace the {{ ... }} with the placeholder without adding extra quotes.\n substituted = substituted.replace(\n /\"([^\"]*?)\\{\\{\\s*([\\w.]+)\\s*\\}\\}([^\"]*?)\"/g,\n (_, before, varName, after) => `\"${before}[${varName}]${after}\"`,\n );\n\n // Step 3: Replace standalone Tera expressions (not inside quotes),\n // e.g. a bare `{{ content }}` used as a JSON value — wrap with quotes.\n substituted = substituted.replace(/\\{\\{\\s*([\\w.]+)\\s*\\}\\}/g, '\"[$1]\"');\n\n const parsed = JSON.parse(substituted);\n\n if (\n parsed &&\n Array.isArray(parsed.choices) &&\n parsed.choices.length > 0 &&\n parsed.choices[0]?.message?.content !== undefined\n ) {\n return String(parsed.choices[0].message.content);\n }\n } catch {\n // Not valid JSON even after substitution — fall through\n }\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// Filename -> match derivation\n// ---------------------------------------------------------------------------\n\n/**\n * Derive a `userMessage` match string from the template filename.\n *\n * Examples:\n * \"greeting.tera\" -> \"greeting\"\n * \"tell_me_a_joke.json\" -> \"tell me a joke\"\n * \"003-weather.txt\" -> \"weather\"\n */\nexport function deriveMatchFromFilename(filename: string): string {\n let name = basename(filename, extname(filename));\n\n // Strip leading numeric prefixes like \"003-\"\n name = name.replace(/^\\d+[-_]/, \"\");\n\n // Replace underscores / hyphens with spaces\n name = name.replace(/[-_]+/g, \" \");\n\n return name.trim();\n}\n\n// ---------------------------------------------------------------------------\n// File / directory conversion\n// ---------------------------------------------------------------------------\n\nconst TEMPLATE_EXTENSIONS = new Set([\n \".tera\",\n \".json\",\n \".txt\",\n \".html\",\n \".jinja\",\n \".jinja2\",\n \".j2\",\n]);\n\nexport function convertFile(filePath: string): AimockFixture | null {\n let raw: string;\n try {\n raw = readFileSync(filePath, \"utf-8\");\n } catch {\n // Unreadable / binary file — skip gracefully\n return null;\n }\n\n const content = stripTeraTemplate(raw);\n if (!content) return null;\n\n const match = deriveMatchFromFilename(filePath);\n return { match: { userMessage: match }, response: { content } };\n}\n\nexport function convertDirectory(dirPath: string): AimockFixture[] {\n const fixtures: AimockFixture[] = [];\n\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") return fixtures;\n throw err; // permission errors, etc. should propagate\n }\n\n for (const entry of entries.sort()) {\n const fullPath = resolve(dirPath, entry);\n try {\n if (!statSync(fullPath).isFile()) continue;\n } catch {\n continue;\n }\n\n const ext = extname(entry).toLowerCase();\n if (!TEMPLATE_EXTENSIONS.has(ext)) continue;\n\n const fixture = convertFile(fullPath);\n if (fixture) fixtures.push(fixture);\n }\n\n return fixtures;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,kBAAkB,KAAqB;CACrD,MAAM,UAAU,IAAI,MAAM;CAG1B,MAAM,eAAe,mBAAmB,QAAQ;AAChD,KAAI,iBAAiB,KAAM,QAAO;CAGlC,IAAI,OAAO;AAGX,QAAO,KAAK,QAAQ,mBAAmB,GAAG;AAG1C,QAAO,KAAK,QAAQ,mBAAmB,GAAG;AAG1C,QAAO,KAAK,QAAQ,2BAA2B,OAAO;AAGtD,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,MAAM,EAAE,MAAM,CAAC,CACpB,QAAQ,MAAM,EAAE,SAAS,EAAE,CAC3B,KAAK,KAAK;AAEb,QAAO;;;;;;AAOT,SAAS,mBAAmB,KAA4B;AACtD,KAAI;EAEF,IAAI,cAAc,IAAI,QAAQ,mBAAmB,GAAG,CAAC,QAAQ,mBAAmB,GAAG;AAKnF,gBAAc,YAAY,QACxB,8CACC,GAAG,QAAQ,SAAS,UAAU,IAAI,OAAO,GAAG,QAAQ,GAAG,MAAM,GAC/D;AAID,gBAAc,YAAY,QAAQ,2BAA2B,WAAS;EAEtE,MAAM,SAAS,KAAK,MAAM,YAAY;AAEtC,MACE,UACA,MAAM,QAAQ,OAAO,QAAQ,IAC7B,OAAO,QAAQ,SAAS,KACxB,OAAO,QAAQ,IAAI,SAAS,YAAY,OAExC,QAAO,OAAO,OAAO,QAAQ,GAAG,QAAQ,QAAQ;SAE5C;AAGR,QAAO;;;;;;;;;;AAeT,SAAgB,wBAAwB,UAA0B;CAChE,IAAI,OAAO,SAAS,UAAU,QAAQ,SAAS,CAAC;AAGhD,QAAO,KAAK,QAAQ,YAAY,GAAG;AAGnC,QAAO,KAAK,QAAQ,UAAU,IAAI;AAElC,QAAO,KAAK,MAAM;;AAOpB,MAAM,sBAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,YAAY,UAAwC;CAClE,IAAI;AACJ,KAAI;AACF,QAAM,aAAa,UAAU,QAAQ;SAC/B;AAEN,SAAO;;CAGT,MAAM,UAAU,kBAAkB,IAAI;AACtC,KAAI,CAAC,QAAS,QAAO;AAGrB,QAAO;EAAE,OAAO,EAAE,aADJ,wBAAwB,SAAS,EACT;EAAE,UAAU,EAAE,SAAS;EAAE;;AAGjE,SAAgB,iBAAiB,SAAkC;CACjE,MAAM,WAA4B,EAAE;CAEpC,IAAI;AACJ,KAAI;AACF,YAAU,YAAY,QAAQ;UACvB,KAAK;AACZ,MAAK,IAA8B,SAAS,SAAU,QAAO;AAC7D,QAAM;;AAGR,MAAK,MAAM,SAAS,QAAQ,MAAM,EAAE;EAClC,MAAM,WAAW,QAAQ,SAAS,MAAM;AACxC,MAAI;AACF,OAAI,CAAC,SAAS,SAAS,CAAC,QAAQ,CAAE;UAC5B;AACN;;EAGF,MAAM,MAAM,QAAQ,MAAM,CAAC,aAAa;AACxC,MAAI,CAAC,oBAAoB,IAAI,IAAI,CAAE;EAEnC,MAAM,UAAU,YAAY,SAAS;AACrC,MAAI,QAAS,UAAS,KAAK,QAAQ;;AAGrC,QAAO"}
|
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":";;;;;;;;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AAI;AACF,+BAAc,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"}
|
|
@@ -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 } }, 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,aAAa;AACtB,QAAK,EAAE;SACF;AACL,OAAI,aAAa;AACjB,QAAK,EAAE;;AAET;;CAGF,MAAM,SAAS,KAAK;CACpB,MAAM,WAAW,KAAK;CACtB,MAAM,YAAY,KAAK;AAEvB,KAAI,CAAC,UAAU;AACb,WAAS,uCAAuC,eAAe;AAC/D,OAAK,EAAE;AACP;;AAGF,SAAQ,QAAR;EACE,KAAK;AACH,uBAAoB,UAAU,WAAW;IAAE;IAAK;IAAU;IAAM,CAAC;AACjE;EACF,KAAK;AACH,qBAAkB,UAAU,WAAW;IAAE;IAAK;IAAU;IAAM,CAAC;AAC/D;EACF;AACE,YAAS,0BAA0B,OAAO,QAAQ,eAAe;AACjE,QAAK,EAAE;;;AAQb,SAAS,oBACP,UACA,WACA,IACM;CACN,MAAM,YAAY,QAAQ,SAAS;CACnC,MAAM,aAAa,YAAY,QAAQ,UAAU,GAAG;CAEpD,IAAI;AAEJ,KAAI;AAEF,MADa,SAAS,UAAU,CACvB,aAAa,CACpB,YAAW,iBAAiB,UAAU;OACjC;GACL,MAAM,SAAS,YAAY,UAAU;AACrC,cAAW,SAAS,CAAC,OAAO,GAAG,EAAE;;UAE5B,KAAK;AACZ,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