@copilotkit/aimock 1.43.0 → 1.44.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/CHANGELOG.md +15 -0
- package/README.md +8 -2
- package/dist/agui-handler.d.ts.map +1 -1
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/bedrock-converse.cjs +32 -4
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +32 -4
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/chaos.cjs +8 -5
- package/dist/chaos.cjs.map +1 -1
- package/dist/chaos.d.cts.map +1 -1
- package/dist/chaos.d.ts.map +1 -1
- package/dist/chaos.js +9 -6
- package/dist/chaos.js.map +1 -1
- package/dist/cli.cjs +89 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +91 -9
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +27 -1
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.js +27 -1
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +1 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +6 -2
- package/dist/constants.d.ts +6 -2
- package/dist/constants.js +8 -1
- package/dist/constants.js.map +1 -1
- package/dist/echo-text.cjs +65 -0
- package/dist/echo-text.cjs.map +1 -0
- package/dist/echo-text.d.cts +22 -0
- package/dist/echo-text.d.cts.map +1 -0
- package/dist/echo-text.d.ts +22 -0
- package/dist/echo-text.d.ts.map +1 -0
- package/dist/echo-text.js +65 -0
- package/dist/echo-text.js.map +1 -0
- package/dist/embeddings.cjs +18 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +1 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +1 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +18 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/files.cjs +9 -11
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +10 -13
- package/dist/files.js.map +1 -1
- package/dist/fine-tuning.cjs +1 -19
- package/dist/fine-tuning.cjs.map +1 -1
- package/dist/fine-tuning.d.cts.map +1 -1
- package/dist/fine-tuning.d.ts.map +1 -1
- package/dist/fine-tuning.js +2 -20
- package/dist/fine-tuning.js.map +1 -1
- package/dist/fixture-loader-services.cjs +116 -0
- package/dist/fixture-loader-services.cjs.map +1 -0
- package/dist/fixture-loader-services.d.cts +48 -0
- package/dist/fixture-loader-services.d.cts.map +1 -0
- package/dist/fixture-loader-services.d.ts +48 -0
- package/dist/fixture-loader-services.d.ts.map +1 -0
- package/dist/fixture-loader-services.js +114 -0
- package/dist/fixture-loader-services.js.map +1 -0
- package/dist/fixture-loader.cjs +172 -11
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts +95 -1
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts +95 -1
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +168 -12
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-embeddings.cjs +42 -2
- package/dist/gemini-embeddings.cjs.map +1 -1
- package/dist/gemini-embeddings.js +43 -3
- package/dist/gemini-embeddings.js.map +1 -1
- package/dist/gemini-interactions.cjs +38 -0
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.d.cts.map +1 -1
- package/dist/gemini-interactions.d.ts.map +1 -1
- package/dist/gemini-interactions.js +38 -0
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +8 -1
- 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 +8 -1
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +276 -5
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +275 -7
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +3 -2
- package/dist/images.cjs.map +1 -1
- package/dist/images.js +3 -2
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +30 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +9 -3
- package/dist/jest.cjs +15 -10
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +4 -2
- package/dist/jest.d.cts.map +1 -1
- package/dist/jest.d.ts +4 -2
- package/dist/jest.d.ts.map +1 -1
- package/dist/jest.js +16 -11
- package/dist/jest.js.map +1 -1
- package/dist/journal.cjs +20 -0
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts +16 -0
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts +16 -0
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +20 -0
- package/dist/journal.js.map +1 -1
- package/dist/llmock.cjs +82 -10
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +35 -0
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +35 -0
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +83 -11
- package/dist/llmock.js.map +1 -1
- package/dist/mcp-fakes-mount.cjs +216 -0
- package/dist/mcp-fakes-mount.cjs.map +1 -0
- package/dist/mcp-fakes-mount.js +210 -0
- package/dist/mcp-fakes-mount.js.map +1 -0
- package/dist/mcp-fakes.cjs +1619 -0
- package/dist/mcp-fakes.cjs.map +1 -0
- package/dist/mcp-fakes.d.cts +101 -0
- package/dist/mcp-fakes.d.cts.map +1 -0
- package/dist/mcp-fakes.d.ts +101 -0
- package/dist/mcp-fakes.d.ts.map +1 -0
- package/dist/mcp-fakes.js +1614 -0
- package/dist/mcp-fakes.js.map +1 -0
- package/dist/mcp-handler.cjs +331 -17
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.js +330 -18
- package/dist/mcp-handler.js.map +1 -1
- package/dist/mcp-mock.cjs +217 -49
- package/dist/mcp-mock.cjs.map +1 -1
- package/dist/mcp-mock.d.cts +66 -1
- package/dist/mcp-mock.d.cts.map +1 -1
- package/dist/mcp-mock.d.ts +66 -1
- package/dist/mcp-mock.d.ts.map +1 -1
- package/dist/mcp-mock.js +218 -50
- package/dist/mcp-mock.js.map +1 -1
- package/dist/mcp-stub.cjs +5 -1
- package/dist/mcp-stub.d.cts +3 -1
- package/dist/mcp-stub.d.ts +3 -1
- package/dist/mcp-stub.js +3 -1
- package/dist/mcp-types.d.cts +6 -0
- package/dist/mcp-types.d.ts +6 -0
- package/dist/message-text.cjs +192 -0
- package/dist/message-text.cjs.map +1 -0
- package/dist/message-text.d.cts +31 -0
- package/dist/message-text.d.cts.map +1 -0
- package/dist/message-text.d.ts +31 -0
- package/dist/message-text.d.ts.map +1 -0
- package/dist/message-text.js +184 -0
- package/dist/message-text.js.map +1 -0
- package/dist/messages.cjs +38 -0
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.js +38 -0
- package/dist/messages.js.map +1 -1
- package/dist/metrics.cjs +46 -66
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.cts +14 -6
- package/dist/metrics.d.cts.map +1 -1
- package/dist/metrics.d.ts +14 -6
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +32 -40
- package/dist/metrics.js.map +1 -1
- package/dist/ollama.cjs +5 -1
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +5 -1
- package/dist/ollama.js.map +1 -1
- package/dist/openapi.cjs +3405 -0
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +30 -0
- package/dist/openapi.d.cts.map +1 -0
- package/dist/openapi.d.ts +30 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +3404 -0
- package/dist/openapi.js.map +1 -0
- package/dist/openrouter-video.cjs +4 -4
- package/dist/openrouter-video.cjs.map +1 -1
- package/dist/openrouter-video.d.cts.map +1 -1
- package/dist/openrouter-video.d.ts.map +1 -1
- package/dist/openrouter-video.js +4 -4
- package/dist/openrouter-video.js.map +1 -1
- package/dist/recorder.cjs +9 -1
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +9 -1
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +43 -4
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +43 -4
- package/dist/responses.js.map +1 -1
- package/dist/route-registry.cjs +951 -0
- package/dist/route-registry.cjs.map +1 -0
- package/dist/route-registry.d.cts +33 -0
- package/dist/route-registry.d.cts.map +1 -0
- package/dist/route-registry.d.ts +33 -0
- package/dist/route-registry.d.ts.map +1 -0
- package/dist/route-registry.js +866 -0
- package/dist/route-registry.js.map +1 -0
- package/dist/router.cjs +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.js +1 -1
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +590 -191
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +4 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +498 -99
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +4 -2
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.js +4 -2
- package/dist/speech.js.map +1 -1
- package/dist/suite.cjs +1 -1
- package/dist/suite.js +1 -1
- package/dist/transcription.cjs +2 -2
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.cts.map +1 -1
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +2 -2
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs +18 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +202 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +202 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/validate-cli.cjs +89 -31
- package/dist/validate-cli.cjs.map +1 -1
- package/dist/validate-cli.js +91 -33
- package/dist/validate-cli.js.map +1 -1
- package/dist/vector-stores.cjs +1180 -0
- package/dist/vector-stores.cjs.map +1 -0
- package/dist/vector-stores.d.cts +106 -0
- package/dist/vector-stores.d.cts.map +1 -0
- package/dist/vector-stores.d.ts +106 -0
- package/dist/vector-stores.d.ts.map +1 -0
- package/dist/vector-stores.js +1164 -0
- package/dist/vector-stores.js.map +1 -0
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/vector-types.d.ts.map +1 -1
- package/dist/video.cjs +19 -0
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +19 -0
- package/dist/video.js.map +1 -1
- package/dist/vitest.cjs +15 -10
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +4 -2
- package/dist/vitest.d.cts.map +1 -1
- package/dist/vitest.d.ts +4 -2
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +16 -11
- package/dist/vitest.js.map +1 -1
- package/dist/ws-gemini-live.d.ts +2 -2
- package/dist/ws-realtime.d.ts +2 -2
- package/dist/ws-responses.cjs +14 -2
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.js +14 -2
- package/dist/ws-responses.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { fixturesOf, hasMcpFakesKey, listFixtureDir, readFixtureJson } from "./fixture-loader.js";
|
|
2
|
+
import { McpFakesAddError, validateMcpFakes } from "./mcp-fakes.js";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/fixture-loader-services.ts
|
|
6
|
+
/**
|
|
7
|
+
* Fixture loaders that carry MCP fakes (spec F1): the `…WithServices`
|
|
8
|
+
* variants of `loadFixtureFile` / `loadFixturesFromDir`. They return the LLM
|
|
9
|
+
* fixtures and the raw `mcpFakes` blocks with their entry-id `source` (I6).
|
|
10
|
+
*
|
|
11
|
+
* They live outside fixture-loader.ts because they validate blocks with
|
|
12
|
+
* `validateMcpFakes`, and mcp-fakes.ts imports `FixtureLoadError` from
|
|
13
|
+
* fixture-loader.ts at module load (`McpFakesAddError extends
|
|
14
|
+
* FixtureLoadError`): a value import of mcp-fakes.ts from fixture-loader.ts
|
|
15
|
+
* is an import cycle that leaves `FixtureLoadError` uninitialized whenever
|
|
16
|
+
* fixture-loader.ts is loaded first.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Load one parsed file into `load.out`: its `mcpFakes` blocks under
|
|
20
|
+
* `source`, then its LLM fixtures. A file with a bad block adds nothing; its
|
|
21
|
+
* errors go to `load.errors`, and the load goes on so every bad block of
|
|
22
|
+
* every file is reported (fail-loud rule, spec 5.4; L3). Its L8 warnings are
|
|
23
|
+
* kept either way.
|
|
24
|
+
*/
|
|
25
|
+
function loadServicesFile(filePath, source, load, logger, liveOptions) {
|
|
26
|
+
const { out } = load;
|
|
27
|
+
const read = readFixtureJson(filePath, logger);
|
|
28
|
+
if (read === null) {
|
|
29
|
+
out.unreadable.push(source);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const parsed = read.value;
|
|
33
|
+
const withFakes = hasMcpFakesKey(parsed);
|
|
34
|
+
if (withFakes) {
|
|
35
|
+
const raw = parsed.mcpFakes;
|
|
36
|
+
const validation = validateMcpFakes(raw, source);
|
|
37
|
+
out.mcpFakeWarnings.push(...validation.warnings);
|
|
38
|
+
if (validation.errors.length > 0) {
|
|
39
|
+
load.errors.push(...validation.errors);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(raw)) raw.forEach((block, blockIndex) => {
|
|
43
|
+
out.mcpFakes.push({
|
|
44
|
+
source,
|
|
45
|
+
blockIndex,
|
|
46
|
+
raw: block
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
else out.mcpFakes.push({
|
|
50
|
+
source,
|
|
51
|
+
blockIndex: null,
|
|
52
|
+
raw
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
out.fixtures.push(...fixturesOf(parsed, filePath, logger, liveOptions, withFakes));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The result of a finished load, or its errors thrown: the one
|
|
59
|
+
* `FixtureLoadError` alone, else a `McpFakesAddError` holding every error and
|
|
60
|
+
* the L8 warnings, so no warning is lost when the load fails.
|
|
61
|
+
*/
|
|
62
|
+
function finish(load) {
|
|
63
|
+
const { out, errors } = load;
|
|
64
|
+
const [first] = errors;
|
|
65
|
+
if (first === void 0) return out;
|
|
66
|
+
if (errors.length === 1 && out.mcpFakeWarnings.length === 0) throw first;
|
|
67
|
+
throw new McpFakesAddError(errors, out.mcpFakeWarnings);
|
|
68
|
+
}
|
|
69
|
+
function newLoad() {
|
|
70
|
+
return {
|
|
71
|
+
out: {
|
|
72
|
+
fixtures: [],
|
|
73
|
+
mcpFakes: [],
|
|
74
|
+
mcpFakeWarnings: [],
|
|
75
|
+
unreadable: []
|
|
76
|
+
},
|
|
77
|
+
errors: []
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Load one fixture file: its LLM fixtures and its `mcpFakes` blocks. A
|
|
82
|
+
* fakes-only file is accepted. The blocks' `source` (spec I6) is `filePath`
|
|
83
|
+
* as given, or `sourceLabel` when set (the URL of a remote fixture file).
|
|
84
|
+
* A bad block throws a `FixtureLoadError` (a `McpFakesAddError` when there
|
|
85
|
+
* is more than one error, or L8 warnings to keep with it).
|
|
86
|
+
*/
|
|
87
|
+
function loadFixtureFileWithServices(filePath, logger, liveOptions, sourceLabel) {
|
|
88
|
+
const load = newLoad();
|
|
89
|
+
loadServicesFile(filePath, sourceLabel ?? filePath, load, logger, liveOptions);
|
|
90
|
+
return finish(load);
|
|
91
|
+
}
|
|
92
|
+
function loadServicesDir(dirPath, relDir, load, logger, liveOptions) {
|
|
93
|
+
const listing = listFixtureDir(dirPath, logger);
|
|
94
|
+
if (listing === null) return;
|
|
95
|
+
for (const name of listing.jsonFiles) loadServicesFile(join(dirPath, name), relDir + name, load, logger, liveOptions);
|
|
96
|
+
for (const sub of listing.subdirs) loadServicesDir(join(dirPath, sub), `${relDir}${sub}/`, load, logger, liveOptions);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Load every `.json` file under `dirPath` (sorted, then subdirectories, at
|
|
100
|
+
* full depth, as {@link loadFixturesFromDir}): LLM fixtures and `mcpFakes`
|
|
101
|
+
* blocks. Each block's `source` (spec I6) is its file's path relative to
|
|
102
|
+
* `dirPath`, with `/` separators. Every file is checked before anything is
|
|
103
|
+
* thrown: the bad blocks of all files are reported together, as in
|
|
104
|
+
* {@link loadFixtureFileWithServices}.
|
|
105
|
+
*/
|
|
106
|
+
function loadFixturesFromDirWithServices(dirPath, logger, liveOptions) {
|
|
107
|
+
const load = newLoad();
|
|
108
|
+
loadServicesDir(dirPath, "", load, logger, liveOptions);
|
|
109
|
+
return finish(load);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
export { loadFixtureFileWithServices, loadFixturesFromDirWithServices };
|
|
114
|
+
//# sourceMappingURL=fixture-loader-services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-loader-services.js","names":[],"sources":["../src/fixture-loader-services.ts"],"sourcesContent":["/**\n * Fixture loaders that carry MCP fakes (spec F1): the `…WithServices`\n * variants of `loadFixtureFile` / `loadFixturesFromDir`. They return the LLM\n * fixtures and the raw `mcpFakes` blocks with their entry-id `source` (I6).\n *\n * They live outside fixture-loader.ts because they validate blocks with\n * `validateMcpFakes`, and mcp-fakes.ts imports `FixtureLoadError` from\n * fixture-loader.ts at module load (`McpFakesAddError extends\n * FixtureLoadError`): a value import of mcp-fakes.ts from fixture-loader.ts\n * is an import cycle that leaves `FixtureLoadError` uninitialized whenever\n * fixture-loader.ts is loaded first.\n */\nimport { join } from \"node:path\";\nimport type { LiveOptions } from \"./live-types.js\";\nimport type { Logger } from \"./logger.js\";\nimport {\n fixturesOf,\n hasMcpFakesKey,\n listFixtureDir,\n readFixtureJson,\n type FixtureLoadError,\n} from \"./fixture-loader.js\";\nimport { McpFakesAddError, validateMcpFakes, type McpFakeIssue } from \"./mcp-fakes.js\";\nimport type { Fixture, McpFakeSource } from \"./types.js\";\n\n/** What {@link loadFixtureFileWithServices} and {@link loadFixturesFromDirWithServices} return. */\nexport interface FixturesWithServices {\n /** LLM fixtures, as the old loaders return them. */\n fixtures: Fixture[];\n /**\n * The raw `mcpFakes` blocks, one per block, in load order, each with its\n * entry-id `source` (spec I6) and `blockIndex` (`null` for the\n * single-object form). Validated per file; checks across files and loads\n * (entry-id collisions) happen when a mount adds them.\n */\n mcpFakes: McpFakeSource[];\n /** Shadowed-entry warnings (L8) of those blocks, for the caller to print. */\n mcpFakeWarnings: McpFakeIssue[];\n /**\n * The entry-id `source` (I6) of each file that could not be read or was\n * not valid JSON. Such a file is warned and skipped, as before, so it adds\n * no fixtures and no blocks; a `--watch` reload uses this list to tell a\n * file it could not parse from a file whose `mcpFakes` were removed.\n */\n unreadable: string[];\n}\n\n/** A load in progress: the result, plus every bad-block error of every file. */\ninterface ServicesLoad {\n out: FixturesWithServices;\n errors: FixtureLoadError[];\n}\n\n/**\n * Load one parsed file into `load.out`: its `mcpFakes` blocks under\n * `source`, then its LLM fixtures. A file with a bad block adds nothing; its\n * errors go to `load.errors`, and the load goes on so every bad block of\n * every file is reported (fail-loud rule, spec 5.4; L3). Its L8 warnings are\n * kept either way.\n */\nfunction loadServicesFile(\n filePath: string,\n source: string,\n load: ServicesLoad,\n logger: Logger | undefined,\n liveOptions: LiveOptions | undefined,\n): void {\n const { out } = load;\n const read = readFixtureJson(filePath, logger);\n if (read === null) {\n out.unreadable.push(source);\n return;\n }\n const parsed = read.value;\n const withFakes = hasMcpFakesKey(parsed);\n if (withFakes) {\n const raw = parsed.mcpFakes;\n const validation = validateMcpFakes(raw, source);\n out.mcpFakeWarnings.push(...validation.warnings);\n if (validation.errors.length > 0) {\n load.errors.push(...validation.errors);\n return;\n }\n if (Array.isArray(raw)) {\n raw.forEach((block: unknown, blockIndex: number) => {\n out.mcpFakes.push({ source, blockIndex, raw: block });\n });\n } else {\n out.mcpFakes.push({ source, blockIndex: null, raw });\n }\n }\n out.fixtures.push(...fixturesOf(parsed, filePath, logger, liveOptions, withFakes));\n}\n\n/**\n * The result of a finished load, or its errors thrown: the one\n * `FixtureLoadError` alone, else a `McpFakesAddError` holding every error and\n * the L8 warnings, so no warning is lost when the load fails.\n */\nfunction finish(load: ServicesLoad): FixturesWithServices {\n const { out, errors } = load;\n const [first] = errors;\n if (first === undefined) return out;\n if (errors.length === 1 && out.mcpFakeWarnings.length === 0) throw first;\n throw new McpFakesAddError(errors, out.mcpFakeWarnings);\n}\n\nfunction newLoad(): ServicesLoad {\n return { out: { fixtures: [], mcpFakes: [], mcpFakeWarnings: [], unreadable: [] }, errors: [] };\n}\n\n/**\n * Load one fixture file: its LLM fixtures and its `mcpFakes` blocks. A\n * fakes-only file is accepted. The blocks' `source` (spec I6) is `filePath`\n * as given, or `sourceLabel` when set (the URL of a remote fixture file).\n * A bad block throws a `FixtureLoadError` (a `McpFakesAddError` when there\n * is more than one error, or L8 warnings to keep with it).\n */\nexport function loadFixtureFileWithServices(\n filePath: string,\n logger?: Logger,\n liveOptions?: LiveOptions,\n sourceLabel?: string,\n): FixturesWithServices {\n const load = newLoad();\n loadServicesFile(filePath, sourceLabel ?? filePath, load, logger, liveOptions);\n return finish(load);\n}\n\nfunction loadServicesDir(\n dirPath: string,\n relDir: string,\n load: ServicesLoad,\n logger: Logger | undefined,\n liveOptions: LiveOptions | undefined,\n): void {\n const listing = listFixtureDir(dirPath, logger);\n if (listing === null) return;\n for (const name of listing.jsonFiles) {\n loadServicesFile(join(dirPath, name), relDir + name, load, logger, liveOptions);\n }\n for (const sub of listing.subdirs) {\n loadServicesDir(join(dirPath, sub), `${relDir}${sub}/`, load, logger, liveOptions);\n }\n}\n\n/**\n * Load every `.json` file under `dirPath` (sorted, then subdirectories, at\n * full depth, as {@link loadFixturesFromDir}): LLM fixtures and `mcpFakes`\n * blocks. Each block's `source` (spec I6) is its file's path relative to\n * `dirPath`, with `/` separators. Every file is checked before anything is\n * thrown: the bad blocks of all files are reported together, as in\n * {@link loadFixtureFileWithServices}.\n */\nexport function loadFixturesFromDirWithServices(\n dirPath: string,\n logger?: Logger,\n liveOptions?: LiveOptions,\n): FixturesWithServices {\n const load = newLoad();\n loadServicesDir(dirPath, \"\", load, logger, liveOptions);\n return finish(load);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4DA,SAAS,iBACP,UACA,QACA,MACA,QACA,aACM;CACN,MAAM,EAAE,QAAQ;CAChB,MAAM,OAAO,gBAAgB,UAAU,OAAO;AAC9C,KAAI,SAAS,MAAM;AACjB,MAAI,WAAW,KAAK,OAAO;AAC3B;;CAEF,MAAM,SAAS,KAAK;CACpB,MAAM,YAAY,eAAe,OAAO;AACxC,KAAI,WAAW;EACb,MAAM,MAAM,OAAO;EACnB,MAAM,aAAa,iBAAiB,KAAK,OAAO;AAChD,MAAI,gBAAgB,KAAK,GAAG,WAAW,SAAS;AAChD,MAAI,WAAW,OAAO,SAAS,GAAG;AAChC,QAAK,OAAO,KAAK,GAAG,WAAW,OAAO;AACtC;;AAEF,MAAI,MAAM,QAAQ,IAAI,CACpB,KAAI,SAAS,OAAgB,eAAuB;AAClD,OAAI,SAAS,KAAK;IAAE;IAAQ;IAAY,KAAK;IAAO,CAAC;IACrD;MAEF,KAAI,SAAS,KAAK;GAAE;GAAQ,YAAY;GAAM;GAAK,CAAC;;AAGxD,KAAI,SAAS,KAAK,GAAG,WAAW,QAAQ,UAAU,QAAQ,aAAa,UAAU,CAAC;;;;;;;AAQpF,SAAS,OAAO,MAA0C;CACxD,MAAM,EAAE,KAAK,WAAW;CACxB,MAAM,CAAC,SAAS;AAChB,KAAI,UAAU,OAAW,QAAO;AAChC,KAAI,OAAO,WAAW,KAAK,IAAI,gBAAgB,WAAW,EAAG,OAAM;AACnE,OAAM,IAAI,iBAAiB,QAAQ,IAAI,gBAAgB;;AAGzD,SAAS,UAAwB;AAC/B,QAAO;EAAE,KAAK;GAAE,UAAU,EAAE;GAAE,UAAU,EAAE;GAAE,iBAAiB,EAAE;GAAE,YAAY,EAAE;GAAE;EAAE,QAAQ,EAAE;EAAE;;;;;;;;;AAUjG,SAAgB,4BACd,UACA,QACA,aACA,aACsB;CACtB,MAAM,OAAO,SAAS;AACtB,kBAAiB,UAAU,eAAe,UAAU,MAAM,QAAQ,YAAY;AAC9E,QAAO,OAAO,KAAK;;AAGrB,SAAS,gBACP,SACA,QACA,MACA,QACA,aACM;CACN,MAAM,UAAU,eAAe,SAAS,OAAO;AAC/C,KAAI,YAAY,KAAM;AACtB,MAAK,MAAM,QAAQ,QAAQ,UACzB,kBAAiB,KAAK,SAAS,KAAK,EAAE,SAAS,MAAM,MAAM,QAAQ,YAAY;AAEjF,MAAK,MAAM,OAAO,QAAQ,QACxB,iBAAgB,KAAK,SAAS,IAAI,EAAE,GAAG,SAAS,IAAI,IAAI,MAAM,QAAQ,YAAY;;;;;;;;;;AAYtF,SAAgB,gCACd,SACA,QACA,aACsB;CACtB,MAAM,OAAO,SAAS;AACtB,iBAAgB,SAAS,IAAI,MAAM,QAAQ,YAAY;AACvD,QAAO,OAAO,KAAK"}
|
package/dist/fixture-loader.cjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_constants = require('./constants.cjs');
|
|
3
|
+
const require_message_text = require('./message-text.cjs');
|
|
2
4
|
const require_helpers = require('./helpers.cjs');
|
|
3
5
|
const require_live_fixture = require('./live-fixture.cjs');
|
|
4
6
|
const require_chaos = require('./chaos.cjs');
|
|
@@ -33,7 +35,11 @@ function normalizeResponse(raw, liveOptions) {
|
|
|
33
35
|
});
|
|
34
36
|
return response;
|
|
35
37
|
}
|
|
38
|
+
var InvalidFixtureMatchError = class extends TypeError {};
|
|
36
39
|
function entryToFixture(entry, logger, liveOptions) {
|
|
40
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) throw new TypeError("Fixture entry must be an object");
|
|
41
|
+
if (entry.match == null) throw new TypeError("Fixture match must be an object");
|
|
42
|
+
if (typeof entry.match !== "object" || Array.isArray(entry.match)) throw new InvalidFixtureMatchError("Fixture match must be an object");
|
|
37
43
|
const fixture = {
|
|
38
44
|
match: {
|
|
39
45
|
userMessage: entry.match.userMessage,
|
|
@@ -92,34 +98,94 @@ function warn(logger, msg, ...rest) {
|
|
|
92
98
|
if (logger) logger.warn(msg, ...rest);
|
|
93
99
|
else console.warn(`[fixture-loader] ${msg}`, ...rest);
|
|
94
100
|
}
|
|
95
|
-
|
|
101
|
+
/**
|
|
102
|
+
* A parsed JSON value, or `null` when the file could not be read or parsed (warned).
|
|
103
|
+
*
|
|
104
|
+
* @internal Shared with fixture-loader-services.ts.
|
|
105
|
+
*/
|
|
106
|
+
function readFixtureJson(filePath, logger) {
|
|
96
107
|
let raw;
|
|
97
108
|
try {
|
|
98
109
|
raw = (0, node_fs.readFileSync)(filePath, "utf-8");
|
|
99
110
|
} catch (err) {
|
|
100
111
|
warn(logger, `Could not read file ${filePath}:`, err);
|
|
101
|
-
return
|
|
112
|
+
return null;
|
|
102
113
|
}
|
|
103
|
-
let parsed;
|
|
104
114
|
try {
|
|
105
|
-
|
|
115
|
+
return { value: JSON.parse(raw) };
|
|
106
116
|
} catch (err) {
|
|
107
117
|
warn(logger, `Invalid JSON in ${filePath}:`, err);
|
|
108
|
-
return
|
|
118
|
+
return null;
|
|
109
119
|
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* `parsed` is a JSON object with an own top-level `mcpFakes` key.
|
|
123
|
+
*
|
|
124
|
+
* @internal Shared with fixture-loader-services.ts.
|
|
125
|
+
*/
|
|
126
|
+
function hasMcpFakesKey(parsed) {
|
|
127
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) && Object.prototype.hasOwnProperty.call(parsed, "mcpFakes");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The LLM fixtures of a parsed file. A missing or non-array `fixtures` is
|
|
131
|
+
* warned and gives none, except that a file with `mcpFakes` may leave
|
|
132
|
+
* `fixtures` out (`fixturesOptional`, spec 5.4). An entry whose `match` is
|
|
133
|
+
* not an object is skipped with a warning; any other bad entry throws.
|
|
134
|
+
*
|
|
135
|
+
* @internal Shared with fixture-loader-services.ts.
|
|
136
|
+
*/
|
|
137
|
+
function fixturesOf(parsed, filePath, logger, liveOptions, fixturesOptional) {
|
|
138
|
+
if (fixturesOptional && typeof parsed === "object" && parsed !== null && !Object.prototype.hasOwnProperty.call(parsed, "fixtures")) return [];
|
|
110
139
|
if (typeof parsed !== "object" || parsed === null || !Array.isArray(parsed.fixtures)) {
|
|
111
140
|
warn(logger, `Missing or invalid "fixtures" array in ${filePath}`);
|
|
112
141
|
return [];
|
|
113
142
|
}
|
|
114
|
-
|
|
143
|
+
const fixtures = [];
|
|
144
|
+
for (const [index, entry] of parsed.fixtures.entries()) try {
|
|
145
|
+
fixtures.push(entryToFixture(entry, logger, liveOptions));
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (!(error instanceof InvalidFixtureMatchError)) throw error;
|
|
148
|
+
warn(logger, `Skipping fixture at index ${index} in ${filePath}: ${error.message}`);
|
|
149
|
+
}
|
|
150
|
+
return fixtures;
|
|
115
151
|
}
|
|
116
|
-
|
|
152
|
+
/**
|
|
153
|
+
* B13: the old loaders return LLM fixtures only, so a file with `mcpFakes`
|
|
154
|
+
* fails loud instead of losing its fakes.
|
|
155
|
+
*/
|
|
156
|
+
function cannotCarryFakes(filePath) {
|
|
157
|
+
return new FixtureLoadError({
|
|
158
|
+
rule: "mcp-fakes/loader-cannot-carry-fakes",
|
|
159
|
+
file: filePath,
|
|
160
|
+
blockId: null,
|
|
161
|
+
entryId: null,
|
|
162
|
+
detail: require_message_text.msg`top-level "mcpFakes" key: loadFixtureFile and loadFixturesFromDir cannot carry MCP fakes; use loadFixtureFileWithServices or loadFixturesFromDirWithServices, or LLMock.loadFixtureFile or LLMock.loadFixtureDir`
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Load the LLM fixtures of one file. Throws a `FixtureLoadError` (rule
|
|
167
|
+
* `mcp-fakes/loader-cannot-carry-fakes`) when the file has a top-level
|
|
168
|
+
* `mcpFakes` key; use `loadFixtureFileWithServices` (fixture-loader-services.ts) for such files.
|
|
169
|
+
*/
|
|
170
|
+
function loadFixtureFile(filePath, logger, liveOptions) {
|
|
171
|
+
const read = readFixtureJson(filePath, logger);
|
|
172
|
+
if (read === null) return [];
|
|
173
|
+
if (hasMcpFakesKey(read.value)) throw cannotCarryFakes(filePath);
|
|
174
|
+
return fixturesOf(read.value, filePath, logger, liveOptions, false);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The `.json` files (sorted) and the subdirectories (sorted) of `dirPath`,
|
|
178
|
+
* or `null` when it cannot be read (warned).
|
|
179
|
+
*
|
|
180
|
+
* @internal Shared with fixture-loader-services.ts.
|
|
181
|
+
*/
|
|
182
|
+
function listFixtureDir(dirPath, logger) {
|
|
117
183
|
let entries;
|
|
118
184
|
try {
|
|
119
185
|
entries = (0, node_fs.readdirSync)(dirPath);
|
|
120
186
|
} catch (err) {
|
|
121
187
|
warn(logger, `Could not read directory ${dirPath}:`, err);
|
|
122
|
-
return
|
|
188
|
+
return null;
|
|
123
189
|
}
|
|
124
190
|
const jsonFiles = [];
|
|
125
191
|
const subdirs = [];
|
|
@@ -137,13 +203,28 @@ function loadFixturesFromDir(dirPath, logger, liveOptions) {
|
|
|
137
203
|
if (name.endsWith(".json")) jsonFiles.push(name);
|
|
138
204
|
}
|
|
139
205
|
jsonFiles.sort();
|
|
206
|
+
subdirs.sort();
|
|
207
|
+
return {
|
|
208
|
+
jsonFiles,
|
|
209
|
+
subdirs
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Load the LLM fixtures of every `.json` file under `dirPath`. Throws a
|
|
214
|
+
* `FixtureLoadError` (rule `mcp-fakes/loader-cannot-carry-fakes`) on the
|
|
215
|
+
* first file with a top-level `mcpFakes` key; use
|
|
216
|
+
* `loadFixturesFromDirWithServices` (fixture-loader-services.ts) for such
|
|
217
|
+
* directories.
|
|
218
|
+
*/
|
|
219
|
+
function loadFixturesFromDir(dirPath, logger, liveOptions) {
|
|
220
|
+
const listing = listFixtureDir(dirPath, logger);
|
|
221
|
+
if (listing === null) return [];
|
|
140
222
|
const fixtures = [];
|
|
141
|
-
for (const name of jsonFiles) {
|
|
223
|
+
for (const name of listing.jsonFiles) {
|
|
142
224
|
const filePath = (0, node_path.join)(dirPath, name);
|
|
143
225
|
fixtures.push(...loadFixtureFile(filePath, logger, liveOptions));
|
|
144
226
|
}
|
|
145
|
-
subdirs.
|
|
146
|
-
for (const sub of subdirs) fixtures.push(...loadFixturesFromDir((0, node_path.join)(dirPath, sub), logger, liveOptions));
|
|
227
|
+
for (const sub of listing.subdirs) fixtures.push(...loadFixturesFromDir((0, node_path.join)(dirPath, sub), logger, liveOptions));
|
|
147
228
|
return fixtures;
|
|
148
229
|
}
|
|
149
230
|
/**
|
|
@@ -806,18 +887,98 @@ function validateFixtures(fixtures, liveOptions) {
|
|
|
806
887
|
}
|
|
807
888
|
return results;
|
|
808
889
|
}
|
|
890
|
+
/**
|
|
891
|
+
* `text` with every run of line breaks, and the spaces around it, folded to
|
|
892
|
+
* one space: CR, LF, VT, FF, NEL, and the Unicode line and paragraph
|
|
893
|
+
* separators.
|
|
894
|
+
*/
|
|
895
|
+
function oneLine(text) {
|
|
896
|
+
return text.replace(/\s*[\r\n\v\f\u0085\u2028\u2029]+\s*/g, " ");
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* The `detail` as a `FixtureLoadError` message adds it: built in a budget of
|
|
900
|
+
* its own, cut to at most `MCP_FAKES_ECHO_LIMIT` chars in all, with each of
|
|
901
|
+
* its user parts cut once. A text detail is folded onto one line, gets the
|
|
902
|
+
* escaping of every JSON text part (`jsonText`: each control char left, C0,
|
|
903
|
+
* DEL or C1, and the line and paragraph separators as `\uXXXX`) and is cut
|
|
904
|
+
* as JSON text (it is
|
|
905
|
+
* made of fixed text, paths and quoted values, where a backslash only starts
|
|
906
|
+
* a JSON escape; a stray one only moves the cut back a few chars).
|
|
907
|
+
*/
|
|
908
|
+
function capPart(detail) {
|
|
909
|
+
return require_message_text.within(require_constants.MCP_FAKES_ECHO_LIMIT, typeof detail === "string" ? require_message_text.msg`${require_message_text.jsonText(oneLine(detail))}` : detail);
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* One `file`, `blockId` or `entryId` as the message names it: JSON-quoted
|
|
913
|
+
* (control chars escaped, so a name can neither break the line nor pose as
|
|
914
|
+
* the message layout), and cut once to `MCP_FAKES_ECHO_LIMIT` chars at most.
|
|
915
|
+
* An empty string is `""`, so the message names every part `toJSON()` keeps.
|
|
916
|
+
*/
|
|
917
|
+
function namePart(text) {
|
|
918
|
+
return require_message_text.msg`${require_message_text.quote(text)}`;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Thrown for a fixture-load case aimock cannot honor (fail-loud rule). Only
|
|
922
|
+
* the MCP fakes code throws it; other fixture-loader paths log warnings.
|
|
923
|
+
* `blockId` and `entryId` are own properties only when supplied, so
|
|
924
|
+
* `toJSON()` (the control API's HTTP 400 `details`) omits them otherwise.
|
|
925
|
+
* The message names `file` and every non-null `blockId` and `entryId`, an
|
|
926
|
+
* empty string as `""`, so it agrees with `toJSON()`. `options.cause` (the
|
|
927
|
+
* standard `ErrorOptions`) keeps the underlying error, such as a JSON parse
|
|
928
|
+
* failure; `toJSON()` leaves it out.
|
|
929
|
+
*/
|
|
930
|
+
var FixtureLoadError = class extends Error {
|
|
931
|
+
/** Typed `string` so a subclass can set its own name. */
|
|
932
|
+
name = "FixtureLoadError";
|
|
933
|
+
rule;
|
|
934
|
+
file;
|
|
935
|
+
constructor(init, options) {
|
|
936
|
+
const file = init.file === null ? require_message_text.msg`<no file>` : namePart(init.file);
|
|
937
|
+
const block = init.blockId == null ? require_message_text.msg`` : require_message_text.msg`, block ${namePart(init.blockId)}`;
|
|
938
|
+
const entry = init.entryId == null ? require_message_text.msg`` : require_message_text.msg`, entry ${namePart(init.entryId)}`;
|
|
939
|
+
super(oneLine(require_message_text.build(require_message_text.msg`${file}${block}${entry}: [${require_message_text.fixed(init.rule)}] ${capPart(init.detail)}`)), options);
|
|
940
|
+
this.rule = init.rule;
|
|
941
|
+
this.file = init.file;
|
|
942
|
+
if (init.blockId !== void 0) Object.defineProperty(this, "blockId", {
|
|
943
|
+
value: init.blockId,
|
|
944
|
+
enumerable: true,
|
|
945
|
+
writable: false
|
|
946
|
+
});
|
|
947
|
+
if (init.entryId !== void 0) Object.defineProperty(this, "entryId", {
|
|
948
|
+
value: init.entryId,
|
|
949
|
+
enumerable: true,
|
|
950
|
+
writable: false
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
toJSON() {
|
|
954
|
+
const json = {
|
|
955
|
+
name: this.name,
|
|
956
|
+
rule: this.rule,
|
|
957
|
+
file: this.file,
|
|
958
|
+
message: this.message
|
|
959
|
+
};
|
|
960
|
+
if (this.blockId !== void 0) json.blockId = this.blockId;
|
|
961
|
+
if (this.entryId !== void 0) json.entryId = this.entryId;
|
|
962
|
+
return json;
|
|
963
|
+
}
|
|
964
|
+
};
|
|
809
965
|
|
|
810
966
|
//#endregion
|
|
967
|
+
exports.FixtureLoadError = FixtureLoadError;
|
|
811
968
|
exports.INJECTED_STATUS_RANGE = INJECTED_STATUS_RANGE;
|
|
812
969
|
exports.claimOneShotError = claimOneShotError;
|
|
813
970
|
exports.clearFixtureQueue = clearFixtureQueue;
|
|
814
971
|
exports.entryToFixture = entryToFixture;
|
|
972
|
+
exports.fixturesOf = fixturesOf;
|
|
973
|
+
exports.hasMcpFakesKey = hasMcpFakesKey;
|
|
815
974
|
exports.isInjectableStatus = isInjectableStatus;
|
|
816
975
|
exports.isOneShotError = isOneShotError;
|
|
976
|
+
exports.listFixtureDir = listFixtureDir;
|
|
817
977
|
exports.loadFixtureFile = loadFixtureFile;
|
|
818
978
|
exports.loadFixturesFromDir = loadFixturesFromDir;
|
|
819
979
|
exports.normalizeResponse = normalizeResponse;
|
|
820
980
|
exports.queueOneShotError = queueOneShotError;
|
|
981
|
+
exports.readFixtureJson = readFixtureJson;
|
|
821
982
|
exports.releaseOneShotError = releaseOneShotError;
|
|
822
983
|
exports.renderValidationRef = renderValidationRef;
|
|
823
984
|
exports.validateFixtures = validateFixtures;
|