@copilotkit/aimock 1.44.0 → 1.45.1
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 +42 -0
- package/README.md +6 -0
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/aimock-cli.cjs +31 -5
- package/dist/aimock-cli.cjs.map +1 -1
- package/dist/aimock-cli.d.cts.map +1 -1
- package/dist/aimock-cli.d.ts.map +1 -1
- package/dist/aimock-cli.js +31 -5
- package/dist/aimock-cli.js.map +1 -1
- package/dist/bedrock-converse.cjs +312 -39
- 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 +313 -40
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +195 -42
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts.map +1 -1
- package/dist/bedrock.js +196 -43
- package/dist/bedrock.js.map +1 -1
- package/dist/chaos.cjs +1 -0
- package/dist/chaos.js +1 -1
- package/dist/cli.cjs +152 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +155 -8
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +132 -71
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +133 -72
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +62 -4
- package/dist/config-loader.cjs.map +1 -1
- package/dist/config-loader.d.cts +37 -4
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts +37 -4
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +62 -4
- package/dist/config-loader.js.map +1 -1
- package/dist/fakes-plugin.cjs +131 -0
- package/dist/fakes-plugin.cjs.map +1 -0
- package/dist/fakes-plugin.d.cts +23 -0
- package/dist/fakes-plugin.d.cts.map +1 -0
- package/dist/fakes-plugin.d.ts +23 -0
- package/dist/fakes-plugin.d.ts.map +1 -0
- package/dist/fakes-plugin.js +127 -0
- package/dist/fakes-plugin.js.map +1 -0
- package/dist/fixture-loader-services.cjs +1 -1
- package/dist/fixture-loader-services.cjs.map +1 -1
- package/dist/fixture-loader-services.js +1 -1
- package/dist/fixture-loader-services.js.map +1 -1
- package/dist/fixture-loader.cjs +389 -27
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts +47 -3
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts +47 -3
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +384 -29
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-interactions.cjs +250 -52
- 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 +251 -53
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +226 -37
- 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 +227 -38
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +881 -7
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +85 -4
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +85 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +839 -8
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +4 -3
- package/dist/jest.cjs +31 -7
- package/dist/jest.cjs.map +1 -1
- package/dist/jest.d.cts +43 -3
- package/dist/jest.d.cts.map +1 -1
- package/dist/jest.d.ts +43 -3
- package/dist/jest.d.ts.map +1 -1
- package/dist/jest.js +33 -9
- package/dist/jest.js.map +1 -1
- package/dist/journal.cjs +135 -13
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts +38 -4
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts +38 -4
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +135 -13
- package/dist/journal.js.map +1 -1
- package/dist/live-sanitize.cjs +4 -32
- package/dist/live-sanitize.cjs.map +1 -1
- package/dist/live-sanitize.js +4 -32
- package/dist/live-sanitize.js.map +1 -1
- package/dist/llmock.cjs +123 -30
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +16 -1
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +16 -1
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +125 -32
- package/dist/llmock.js.map +1 -1
- package/dist/mcp-fakes-mount.cjs +1 -0
- package/dist/mcp-fakes-mount.cjs.map +1 -1
- package/dist/mcp-fakes-mount.js +1 -0
- package/dist/mcp-fakes-mount.js.map +1 -1
- package/dist/mcp-fakes-report.cjs +111 -0
- package/dist/mcp-fakes-report.cjs.map +1 -0
- package/dist/mcp-fakes-report.d.cts +40 -0
- package/dist/mcp-fakes-report.d.cts.map +1 -0
- package/dist/mcp-fakes-report.d.ts +40 -0
- package/dist/mcp-fakes-report.d.ts.map +1 -0
- package/dist/mcp-fakes-report.js +107 -0
- package/dist/mcp-fakes-report.js.map +1 -0
- package/dist/mcp-fakes.cjs +331 -8
- package/dist/mcp-fakes.cjs.map +1 -1
- package/dist/mcp-fakes.d.cts +406 -3
- package/dist/mcp-fakes.d.cts.map +1 -1
- package/dist/mcp-fakes.d.ts +406 -3
- package/dist/mcp-fakes.d.ts.map +1 -1
- package/dist/mcp-fakes.js +331 -8
- package/dist/mcp-fakes.js.map +1 -1
- package/dist/mcp-handler.cjs +216 -17
- package/dist/mcp-handler.cjs.map +1 -1
- package/dist/mcp-handler.d.cts +49 -0
- package/dist/mcp-handler.d.cts.map +1 -0
- package/dist/mcp-handler.d.ts +49 -0
- package/dist/mcp-handler.d.ts.map +1 -0
- package/dist/mcp-handler.js +214 -18
- package/dist/mcp-handler.js.map +1 -1
- package/dist/mcp-mock.cjs +112 -1
- package/dist/mcp-mock.cjs.map +1 -1
- package/dist/mcp-mock.d.cts +33 -2
- package/dist/mcp-mock.d.cts.map +1 -1
- package/dist/mcp-mock.d.ts +33 -2
- package/dist/mcp-mock.d.ts.map +1 -1
- package/dist/mcp-mock.js +112 -1
- package/dist/mcp-mock.js.map +1 -1
- package/dist/mcp-recorder.cjs +1224 -0
- package/dist/mcp-recorder.cjs.map +1 -0
- package/dist/mcp-recorder.d.cts +108 -0
- package/dist/mcp-recorder.d.cts.map +1 -0
- package/dist/mcp-recorder.d.ts +108 -0
- package/dist/mcp-recorder.d.ts.map +1 -0
- package/dist/mcp-recorder.js +1215 -0
- package/dist/mcp-recorder.js.map +1 -0
- package/dist/messages.cjs +362 -56
- 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 +363 -58
- package/dist/messages.js.map +1 -1
- package/dist/misbehavior.cjs +1523 -0
- package/dist/misbehavior.cjs.map +1 -0
- package/dist/misbehavior.d.cts +43 -0
- package/dist/misbehavior.d.cts.map +1 -0
- package/dist/misbehavior.d.ts +43 -0
- package/dist/misbehavior.d.ts.map +1 -0
- package/dist/misbehavior.js +1511 -0
- package/dist/misbehavior.js.map +1 -0
- package/dist/ollama.cjs +310 -112
- 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 +311 -113
- package/dist/ollama.js.map +1 -1
- package/dist/openrouter-video.cjs +30 -2
- 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 +30 -2
- package/dist/openrouter-video.js.map +1 -1
- package/dist/record-sanitize.cjs +231 -0
- package/dist/record-sanitize.cjs.map +1 -0
- package/dist/record-sanitize.js +224 -0
- package/dist/record-sanitize.js.map +1 -0
- package/dist/recorder.cjs +106 -5
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts +2 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts +2 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +107 -7
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +667 -171
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +5 -13
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +5 -13
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +665 -174
- package/dist/responses.js.map +1 -1
- package/dist/router.cjs +24 -2
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +25 -4
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +572 -76
- 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 +574 -78
- package/dist/server.js.map +1 -1
- package/dist/stream-collapse.cjs +236 -34
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +39 -4
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +39 -4
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +235 -35
- package/dist/stream-collapse.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +315 -4
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +315 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validate-cli.cjs +36 -4
- package/dist/validate-cli.cjs.map +1 -1
- package/dist/validate-cli.js +37 -5
- package/dist/validate-cli.js.map +1 -1
- package/dist/vector-types.d.ts.map +1 -1
- package/dist/version.cjs +45 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.js +44 -0
- package/dist/version.js.map +1 -0
- package/dist/vitest.cjs +66 -10
- package/dist/vitest.cjs.map +1 -1
- package/dist/vitest.d.cts +35 -4
- package/dist/vitest.d.cts.map +1 -1
- package/dist/vitest.d.ts +35 -4
- package/dist/vitest.d.ts.map +1 -1
- package/dist/vitest.js +67 -11
- package/dist/vitest.js.map +1 -1
- package/dist/watcher.cjs +6 -2
- package/dist/watcher.cjs.map +1 -1
- package/dist/watcher.js +6 -2
- package/dist/watcher.js.map +1 -1
- package/dist/ws-gemini-live.cjs +210 -101
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +9 -3
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts +9 -3
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +211 -102
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +175 -62
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts +8 -3
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts +8 -3
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +176 -63
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +109 -16
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts +8 -12
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts +8 -12
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +111 -18
- package/dist/ws-responses.js.map +1 -1
- package/package.json +10 -2
- package/skills/write-fixtures/SKILL.md +179 -21
package/dist/llmock.cjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
const require_constants = require('./constants.cjs');
|
|
1
2
|
const require_message_text = require('./message-text.cjs');
|
|
2
3
|
const require_helpers = require('./helpers.cjs');
|
|
3
4
|
const require_live_fixture = require('./live-fixture.cjs');
|
|
5
|
+
const require_misbehavior = require('./misbehavior.cjs');
|
|
4
6
|
const require_fixture_loader = require('./fixture-loader.cjs');
|
|
5
7
|
const require_fal = require('./fal.cjs');
|
|
6
8
|
const require_elevenlabs_voice = require('./elevenlabs-voice.cjs');
|
|
9
|
+
const require_mcp_mock = require('./mcp-mock.cjs');
|
|
7
10
|
const require_mcp_fakes_mount = require('./mcp-fakes-mount.cjs');
|
|
8
11
|
const require_server = require('./server.cjs');
|
|
9
12
|
const require_fixture_loader_services = require('./fixture-loader-services.cjs');
|
|
@@ -11,6 +14,13 @@ const require_fixture_loader_services = require('./fixture-loader-services.cjs')
|
|
|
11
14
|
//#region src/llmock.ts
|
|
12
15
|
var LLMock = class LLMock {
|
|
13
16
|
fixtures = [];
|
|
17
|
+
fixtureAddition = 0;
|
|
18
|
+
fixtureCountOrigins = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* Fixtures this LLMock built itself (on() and the other helpers), so the
|
|
21
|
+
* caller never held them: the stored object is their identity.
|
|
22
|
+
*/
|
|
23
|
+
ownFixtures = /* @__PURE__ */ new WeakSet();
|
|
14
24
|
searchFixtures = [];
|
|
15
25
|
rerankFixtures = [];
|
|
16
26
|
moderationFixtures = [];
|
|
@@ -22,16 +32,46 @@ var LLMock = class LLMock {
|
|
|
22
32
|
options;
|
|
23
33
|
resolvedInboundAuth;
|
|
24
34
|
constructor(options, resolvedInboundAuth) {
|
|
35
|
+
require_helpers.markServerOwnedFixtures(this.fixtures);
|
|
25
36
|
this.options = options ?? {};
|
|
26
37
|
if (this.options.live !== void 0) require_live_fixture.normalizeLiveOptions(this.options.live);
|
|
38
|
+
if (this.misbehaviorEnabled && this.options.misbehavior !== void 0) this.setMisbehavior(this.options.misbehavior);
|
|
27
39
|
this.resolvedInboundAuth = resolvedInboundAuth;
|
|
28
40
|
}
|
|
41
|
+
/** Misbehavior (fixture keys, header, `misbehavior` option) needs `enableMisbehavior: true`. */
|
|
42
|
+
get misbehaviorEnabled() {
|
|
43
|
+
return this.options.enableMisbehavior === true;
|
|
44
|
+
}
|
|
29
45
|
normalizeFixture(fixture) {
|
|
30
|
-
|
|
46
|
+
const misbehaviorEnabled = this.misbehaviorEnabled;
|
|
47
|
+
if (misbehaviorEnabled) require_fixture_loader.enableHeldFixtureMisbehavior(fixture);
|
|
48
|
+
const own = this.ownFixtures.delete(fixture);
|
|
49
|
+
const countIdentity = own ? void 0 : this.fixtureCountOrigins.get(fixture) ?? fixture;
|
|
50
|
+
const previousPosition = require_misbehavior.getFixtureMisbehaviorPosition(fixture);
|
|
51
|
+
const isNewAddition = previousPosition === void 0 || /^code#\d+$/.test(previousPosition);
|
|
52
|
+
const position = isNewAddition ? `code#${this.fixtureAddition++}` : previousPosition;
|
|
53
|
+
if (isNewAddition && misbehaviorEnabled && !own) fixture = { ...fixture };
|
|
54
|
+
if (misbehaviorEnabled && fixture.misbehavior !== void 0) {
|
|
55
|
+
const parsed = require_misbehavior.parseMisbehavior(fixture.misbehavior);
|
|
56
|
+
if (parsed.ok) fixture = {
|
|
57
|
+
...fixture,
|
|
58
|
+
misbehavior: parsed.config
|
|
59
|
+
};
|
|
60
|
+
const issue = parsed.ok ? require_misbehavior.validateFixtureMisbehavior(fixture) : parsed.issue;
|
|
61
|
+
if (issue) throw new require_fixture_loader.MisbehaviorConfigError({
|
|
62
|
+
rule: issue.rule,
|
|
63
|
+
file: position,
|
|
64
|
+
detail: issue.message
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (require_helpers.isLiveResponse(fixture.response) || fixture.match.endpoint === "openai-live" && typeof fixture.response !== "function") fixture = {
|
|
31
68
|
...fixture,
|
|
32
69
|
match: { ...fixture.match },
|
|
33
70
|
response: require_live_fixture.normalizeLiveFixture(fixture.response, this.options.live)
|
|
34
71
|
};
|
|
72
|
+
else if (countIdentity !== void 0 && fixture !== countIdentity) this.fixtureCountOrigins.set(fixture, countIdentity);
|
|
73
|
+
require_misbehavior.setFixtureMisbehaviorPosition(fixture, position);
|
|
74
|
+
if (misbehaviorEnabled && fixture.misbehavior !== void 0) require_fixture_loader.markFixtureMisbehaviorEnabled(fixture);
|
|
35
75
|
return fixture;
|
|
36
76
|
}
|
|
37
77
|
addFixture(fixture) {
|
|
@@ -46,6 +86,11 @@ var LLMock = class LLMock {
|
|
|
46
86
|
this.fixtures.unshift(this.normalizeFixture(fixture));
|
|
47
87
|
return this;
|
|
48
88
|
}
|
|
89
|
+
/** Mark a fixture this LLMock built, for {@link normalizeFixture}. */
|
|
90
|
+
own(fixture) {
|
|
91
|
+
this.ownFixtures.add(fixture);
|
|
92
|
+
return fixture;
|
|
93
|
+
}
|
|
49
94
|
getFixtures() {
|
|
50
95
|
return this.fixtures;
|
|
51
96
|
}
|
|
@@ -71,6 +116,8 @@ var LLMock = class LLMock {
|
|
|
71
116
|
* still make `start()` reject.
|
|
72
117
|
*/
|
|
73
118
|
acceptLoaded(loaded) {
|
|
119
|
+
if (this.misbehaviorEnabled) loaded.fixtures.forEach(require_fixture_loader.enableHeldFixtureMisbehavior);
|
|
120
|
+
if (this.options.responsesTools === "extended") loaded.fixtures.forEach(require_fixture_loader.markFixtureResponsesToolsExtended);
|
|
74
121
|
if (loaded.mcpFakes.length > 0) if (this.serverInstance) this.addFakesAfterStart(this.serverInstance, loaded.mcpFakes);
|
|
75
122
|
else {
|
|
76
123
|
require_mcp_fakes_mount.planFileFakes(this.mounts, [...this.mcpFakeBuffer, ...loaded.mcpFakes], new Set(loaded.mcpFakes));
|
|
@@ -100,7 +147,8 @@ var LLMock = class LLMock {
|
|
|
100
147
|
const target = require_mcp_fakes_mount.ensureFakeMount(this.mounts, path, {
|
|
101
148
|
journal: server.journal,
|
|
102
149
|
...registry ? { registry } : {},
|
|
103
|
-
logger
|
|
150
|
+
logger,
|
|
151
|
+
replaySpeed: server.defaults.replaySpeed
|
|
104
152
|
}, logger);
|
|
105
153
|
if ("conflict" in target) continue;
|
|
106
154
|
const result = target.handler.addMcpFakes?.(group, { kind: "file" });
|
|
@@ -125,7 +173,17 @@ var LLMock = class LLMock {
|
|
|
125
173
|
}
|
|
126
174
|
else entries = input;
|
|
127
175
|
if (!Array.isArray(entries)) throw new TypeError("addFixturesFromJSON: expected an array of fixture entries; use loadFixtureFile for a {fixtures:[...]} file");
|
|
128
|
-
const converted = entries.map((
|
|
176
|
+
const converted = entries.map((entry) => {
|
|
177
|
+
const position = `code#${this.fixtureAddition++}`;
|
|
178
|
+
const fixture = require_fixture_loader.entryToFixture(entry, void 0, this.options.live, {
|
|
179
|
+
file: position,
|
|
180
|
+
index: 0
|
|
181
|
+
});
|
|
182
|
+
require_misbehavior.setFixtureMisbehaviorPosition(fixture, position);
|
|
183
|
+
if (this.misbehaviorEnabled) require_fixture_loader.enableHeldFixtureMisbehavior(fixture);
|
|
184
|
+
if (this.options.responsesTools === "extended") require_fixture_loader.markFixtureResponsesToolsExtended(fixture);
|
|
185
|
+
return fixture;
|
|
186
|
+
});
|
|
129
187
|
const errors = require_fixture_loader.validateFixtures(converted, this.options.live).filter((i) => i.severity === "error");
|
|
130
188
|
if (errors.length > 0) throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);
|
|
131
189
|
this.fixtures.push(...converted);
|
|
@@ -133,15 +191,21 @@ var LLMock = class LLMock {
|
|
|
133
191
|
}
|
|
134
192
|
clearFixtures() {
|
|
135
193
|
require_fixture_loader.clearFixtureQueue(this.fixtures);
|
|
194
|
+
this.serverInstance?.journal.clearMisbehaviorCounters();
|
|
136
195
|
this.unloadMcpFakes();
|
|
137
196
|
return this;
|
|
138
197
|
}
|
|
139
198
|
on(match, response, opts) {
|
|
140
|
-
|
|
199
|
+
let normalized = response;
|
|
200
|
+
if (typeof response !== "function") {
|
|
201
|
+
normalized = require_fixture_loader.normalizeResponse(response, this.options.live);
|
|
202
|
+
if (this.options.responsesTools === "extended" && !require_helpers.isLiveResponse(normalized)) require_fixture_loader.normalizeResponsesToolsKeys(normalized);
|
|
203
|
+
}
|
|
204
|
+
return this.addFixture(this.own({
|
|
141
205
|
match,
|
|
142
|
-
response:
|
|
206
|
+
response: normalized,
|
|
143
207
|
...opts
|
|
144
|
-
});
|
|
208
|
+
}));
|
|
145
209
|
}
|
|
146
210
|
onLive(match, transcript, opts) {
|
|
147
211
|
return this.on({
|
|
@@ -175,99 +239,99 @@ var LLMock = class LLMock {
|
|
|
175
239
|
}, response, opts);
|
|
176
240
|
}
|
|
177
241
|
onImage(prompt, response) {
|
|
178
|
-
return this.addFixture({
|
|
242
|
+
return this.addFixture(this.own({
|
|
179
243
|
match: {
|
|
180
244
|
userMessage: prompt,
|
|
181
245
|
endpoint: "image"
|
|
182
246
|
},
|
|
183
247
|
response
|
|
184
|
-
});
|
|
248
|
+
}));
|
|
185
249
|
}
|
|
186
250
|
onSpeech(input, response) {
|
|
187
|
-
return this.addFixture({
|
|
251
|
+
return this.addFixture(this.own({
|
|
188
252
|
match: {
|
|
189
253
|
userMessage: input,
|
|
190
254
|
endpoint: "speech"
|
|
191
255
|
},
|
|
192
256
|
response
|
|
193
|
-
});
|
|
257
|
+
}));
|
|
194
258
|
}
|
|
195
259
|
onTranscription(response) {
|
|
196
|
-
return this.addFixture({
|
|
260
|
+
return this.addFixture(this.own({
|
|
197
261
|
match: { endpoint: "transcription" },
|
|
198
262
|
response
|
|
199
|
-
});
|
|
263
|
+
}));
|
|
200
264
|
}
|
|
201
265
|
onTranslation(response) {
|
|
202
|
-
return this.addFixture({
|
|
266
|
+
return this.addFixture(this.own({
|
|
203
267
|
match: { endpoint: "translation" },
|
|
204
268
|
response
|
|
205
|
-
});
|
|
269
|
+
}));
|
|
206
270
|
}
|
|
207
271
|
onVideo(prompt, response) {
|
|
208
|
-
return this.addFixture({
|
|
272
|
+
return this.addFixture(this.own({
|
|
209
273
|
match: {
|
|
210
274
|
userMessage: prompt,
|
|
211
275
|
endpoint: "video"
|
|
212
276
|
},
|
|
213
277
|
response
|
|
214
|
-
});
|
|
278
|
+
}));
|
|
215
279
|
}
|
|
216
280
|
onAudio(input, response) {
|
|
217
|
-
return this.addFixture({
|
|
281
|
+
return this.addFixture(this.own({
|
|
218
282
|
match: { userMessage: input },
|
|
219
283
|
response
|
|
220
|
-
});
|
|
284
|
+
}));
|
|
221
285
|
}
|
|
222
286
|
onSoundEffect(text, response) {
|
|
223
|
-
return this.addFixture({
|
|
287
|
+
return this.addFixture(this.own({
|
|
224
288
|
match: {
|
|
225
289
|
userMessage: text,
|
|
226
290
|
endpoint: "audio-gen"
|
|
227
291
|
},
|
|
228
292
|
response
|
|
229
|
-
});
|
|
293
|
+
}));
|
|
230
294
|
}
|
|
231
295
|
onMusic(prompt, response) {
|
|
232
|
-
return this.addFixture({
|
|
296
|
+
return this.addFixture(this.own({
|
|
233
297
|
match: {
|
|
234
298
|
userMessage: prompt,
|
|
235
299
|
endpoint: "audio-gen"
|
|
236
300
|
},
|
|
237
301
|
response
|
|
238
|
-
});
|
|
302
|
+
}));
|
|
239
303
|
}
|
|
240
304
|
onElevenLabsTTS(text, response) {
|
|
241
|
-
return this.addFixture({
|
|
305
|
+
return this.addFixture(this.own({
|
|
242
306
|
match: {
|
|
243
307
|
userMessage: text,
|
|
244
308
|
endpoint: "elevenlabs-tts"
|
|
245
309
|
},
|
|
246
310
|
response
|
|
247
|
-
});
|
|
311
|
+
}));
|
|
248
312
|
}
|
|
249
313
|
onElevenLabsVoiceDesign(description, response) {
|
|
250
|
-
return this.addFixture({
|
|
314
|
+
return this.addFixture(this.own({
|
|
251
315
|
match: {
|
|
252
316
|
userMessage: description,
|
|
253
317
|
endpoint: "elevenlabs-voice-design"
|
|
254
318
|
},
|
|
255
319
|
response: require_elevenlabs_voice.voiceDesignToJson(response)
|
|
256
|
-
});
|
|
320
|
+
}));
|
|
257
321
|
}
|
|
258
322
|
onFalAudio(prompt, response, model) {
|
|
259
|
-
return this.addFixture({
|
|
323
|
+
return this.addFixture(this.own({
|
|
260
324
|
match: {
|
|
261
325
|
userMessage: prompt,
|
|
262
326
|
endpoint: "fal-audio",
|
|
263
327
|
...model ? { model } : {}
|
|
264
328
|
},
|
|
265
329
|
response
|
|
266
|
-
});
|
|
330
|
+
}));
|
|
267
331
|
}
|
|
268
332
|
onFalQueue(modelOrPrompt, response, opts) {
|
|
269
333
|
const { billableUnits, ...fixtureOpts } = opts ?? {};
|
|
270
|
-
return this.addFixture({
|
|
334
|
+
return this.addFixture(this.own({
|
|
271
335
|
match: {
|
|
272
336
|
model: modelOrPrompt,
|
|
273
337
|
endpoint: "fal"
|
|
@@ -277,7 +341,7 @@ var LLMock = class LLMock {
|
|
|
277
341
|
...billableUnits != null ? { billableUnits } : {}
|
|
278
342
|
},
|
|
279
343
|
...fixtureOpts
|
|
280
|
-
});
|
|
344
|
+
}));
|
|
281
345
|
}
|
|
282
346
|
onFalRun(modelOrPrompt, response, opts) {
|
|
283
347
|
return this.onFalQueue(modelOrPrompt, response, opts);
|
|
@@ -344,6 +408,7 @@ var LLMock = class LLMock {
|
|
|
344
408
|
if (registry && handler.setRegistry) handler.setRegistry(registry);
|
|
345
409
|
const logger = this.serverInstance.defaults.logger;
|
|
346
410
|
if (handler.setLogger) handler.setLogger(logger);
|
|
411
|
+
if (handler instanceof require_mcp_mock.MCPMock) handler.setReplaySpeed(this.serverInstance.defaults.replaySpeed);
|
|
347
412
|
if (shadowedBy) logger.warn(require_message_text.build(require_message_text.msg`MCP fakes: the mount at ${require_message_text.quote(path)} is shadowed by the MCP mock auto-mounted at ${require_message_text.quote(shadowedBy.path)}; its requests reach the auto-mount`));
|
|
348
413
|
}
|
|
349
414
|
return this;
|
|
@@ -392,6 +457,32 @@ var LLMock = class LLMock {
|
|
|
392
457
|
if (this.serverInstance) this.serverInstance.defaults.chaos = void 0;
|
|
393
458
|
return this;
|
|
394
459
|
}
|
|
460
|
+
/** Replace construction/runtime baselines without changing named test overrides. */
|
|
461
|
+
setMisbehavior(config) {
|
|
462
|
+
if (!this.misbehaviorEnabled) throw new TypeError("setMisbehavior: misbehavior is not enabled; construct with enableMisbehavior: true");
|
|
463
|
+
const parsed = require_misbehavior.parseMisbehavior(config);
|
|
464
|
+
if (!parsed.ok) throw new TypeError(`${parsed.issue.rule}: ${parsed.issue.message}`);
|
|
465
|
+
this.options.misbehavior = parsed.config;
|
|
466
|
+
const defaults = this.serverInstance?.defaults;
|
|
467
|
+
if (defaults?.misbehavior) {
|
|
468
|
+
defaults.misbehavior.baseline = parsed.config.seed === "random" ? {
|
|
469
|
+
...parsed.config,
|
|
470
|
+
seed: require_misbehavior.resolveMisbehaviorSeed(parsed.config.seed, defaults.logger)
|
|
471
|
+
} : parsed.config;
|
|
472
|
+
if (defaults.misbehavior.byTestId.has(require_constants.DEFAULT_TEST_ID)) defaults.misbehavior.byTestId.set(require_constants.DEFAULT_TEST_ID, defaults.misbehavior.baseline);
|
|
473
|
+
}
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
/** Clear the baseline and all runtime overrides, before or after start. */
|
|
477
|
+
clearMisbehavior() {
|
|
478
|
+
delete this.options.misbehavior;
|
|
479
|
+
const scope = this.serverInstance?.defaults.misbehavior;
|
|
480
|
+
if (scope) {
|
|
481
|
+
scope.baseline = void 0;
|
|
482
|
+
scope.byTestId.clear();
|
|
483
|
+
}
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
395
486
|
enableRecording(config) {
|
|
396
487
|
this.options.record = config;
|
|
397
488
|
return this;
|
|
@@ -441,6 +532,8 @@ var LLMock = class LLMock {
|
|
|
441
532
|
mcpFakes: [...this.mcpFakeBuffer]
|
|
442
533
|
};
|
|
443
534
|
this.serverInstance = await (this.resolvedInboundAuth ? require_server.createServerWithResolvedAuth(this.fixtures, this.options, this.resolvedInboundAuth, this.mounts, serviceFixtures) : require_server.createServer(this.fixtures, this.options, this.mounts, serviceFixtures));
|
|
535
|
+
const countIdentity = (fixture) => this.fixtureCountOrigins.get(fixture) ?? fixture;
|
|
536
|
+
this.serverInstance.journal.configureFixtureCountIdentity(countIdentity);
|
|
444
537
|
this.mcpFakeBuffer.length = 0;
|
|
445
538
|
return this.serverInstance.url;
|
|
446
539
|
}
|
package/dist/llmock.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmock.cjs","names":["isLiveResponse","normalizeLiveFixture","loadFixtureFileWithServices","loadFixturesFromDirWithServices","planFileFakes","ensureFakeMount","entryToFixture","validateFixtures","normalizeResponse","voiceDesignToJson","imageResponseToFalJson","videoResponseToFalJson","isInjectableStatus","INJECTED_STATUS_RANGE","isAutoMount","build","quote","createServerWithResolvedAuth","createServer"],"sources":["../src/llmock.ts"],"sourcesContent":["import type { LiveTranscript } from \"./live-types.js\";\nimport { normalizeLiveFixture, normalizeLiveOptions } from \"./live-fixture.js\";\nimport { isLiveResponse } from \"./helpers.js\";\nimport type {\n AudioResponse,\n ChaosConfig,\n EmbeddingFixtureOpts,\n FalQueueOpts,\n Fixture,\n FixtureFileEntry,\n FixtureFileResponse,\n FixtureMatch,\n FixtureOpts,\n ImageResponse,\n McpFakeSource,\n MockServerOptions,\n Mountable,\n RecordConfig,\n ResponseFactory,\n TranscriptionResponse,\n VideoResponse,\n VoiceDesignResponse,\n} from \"./types.js\";\nimport {\n createServer,\n createServerWithResolvedAuth,\n performFullReset,\n type ServerInstance,\n} from \"./server.js\";\nimport type { ResolvedInboundAuth } from \"./api-key-auth.js\";\nimport {\n isInjectableStatus,\n INJECTED_STATUS_RANGE,\n queueOneShotError,\n clearFixtureQueue,\n entryToFixture,\n normalizeResponse,\n validateFixtures,\n} from \"./fixture-loader.js\";\nimport {\n loadFixtureFileWithServices,\n loadFixturesFromDirWithServices,\n type FixturesWithServices,\n} from \"./fixture-loader-services.js\";\nimport { ensureFakeMount, isAutoMount, planFileFakes } from \"./mcp-fakes-mount.js\";\nimport { build, msg, quote } from \"./message-text.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\nimport { imageResponseToFalJson, videoResponseToFalJson } from \"./fal.js\";\nimport { voiceDesignToJson } from \"./elevenlabs-voice.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n /** `mcpFakes` blocks loaded before `start()`, handed to the server at start (W2). */\n private mcpFakeBuffer: McpFakeSource[] = [];\n /** MCPMocks the server or a load auto-mounted (W3, W6), for the L6 check. */\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n private readonly resolvedInboundAuth?: ResolvedInboundAuth;\n\n constructor(options?: MockServerOptions, resolvedInboundAuth?: ResolvedInboundAuth) {\n this.options = options ?? {};\n if (this.options.live !== undefined) normalizeLiveOptions(this.options.live);\n this.resolvedInboundAuth = resolvedInboundAuth;\n }\n\n // ---- Fixture management ----\n\n private normalizeFixture(fixture: Fixture): Fixture {\n if (\n isLiveResponse(fixture.response) ||\n (fixture.match.endpoint === \"openai-live\" && typeof fixture.response !== \"function\")\n ) {\n return {\n ...fixture,\n match: { ...fixture.match },\n response: normalizeLiveFixture(fixture.response, this.options.live),\n };\n }\n return fixture;\n }\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(this.normalizeFixture(fixture));\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures.map((fixture) => this.normalizeFixture(fixture)));\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(this.normalizeFixture(fixture));\n return this;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n /**\n * Load a fixture file: its LLM fixtures and its `mcpFakes` blocks (F4).\n * Before `start()` the blocks are buffered and handed to the server at\n * start (W2); after it they go to the MCPMock serving each block's `mount`\n * path, auto-mounted when none does (W6). A block that cannot be honored\n * throws a `FixtureLoadError` and nothing from the file is added.\n */\n loadFixtureFile(filePath: string): this {\n return this.acceptLoaded(loadFixtureFileWithServices(filePath, undefined, this.options.live));\n }\n\n /** As {@link loadFixtureFile}, for every fixture file under `dirPath`. */\n loadFixtureDir(dirPath: string): this {\n return this.acceptLoaded(\n loadFixturesFromDirWithServices(dirPath, undefined, this.options.live),\n );\n }\n\n /**\n * Add a load's fakes (all or nothing), then its LLM fixtures. Before start\n * the fakes are checked as the start-time hand-off will check them, with\n * the blocks already buffered and the mounts added so far, so a file whose\n * fakes would be rejected adds nothing. A mount added after the load can\n * still make `start()` reject.\n */\n private acceptLoaded(loaded: FixturesWithServices): this {\n if (loaded.mcpFakes.length > 0) {\n if (this.serverInstance) {\n this.addFakesAfterStart(this.serverInstance, loaded.mcpFakes);\n } else {\n planFileFakes(\n this.mounts,\n [...this.mcpFakeBuffer, ...loaded.mcpFakes],\n new Set(loaded.mcpFakes),\n );\n this.mcpFakeBuffer.push(...loaded.mcpFakes);\n }\n }\n this.fixtures.push(...loaded.fixtures);\n return this;\n }\n\n /**\n * W6 for a load after start. Every group of blocks (by `mount` path) is\n * checked before any mount is touched: a path held by a mount that is not\n * an MCPMock is a mount conflict, and each group is first added to a\n * throwaway store. Groups for an existing MCPMock are then added to it (its\n * own add is all or nothing and finds collisions with its loaded ids);\n * groups for a free path are added last, to a new auto-mounted MCPMock,\n * wired as W4. The add warnings (L8) are logged at `warn`.\n */\n private addFakesAfterStart(server: ServerInstance, sources: McpFakeSource[]): void {\n const { onExisting, onNew } = planFileFakes(this.mounts, sources);\n\n const logger = server.defaults.logger;\n for (const { handler, group } of onExisting) {\n const result = handler.addMcpFakes?.(group, { kind: \"file\" });\n for (const warning of result?.warnings ?? []) logger.warn(warning.message);\n }\n const registry = server.defaults.registry;\n for (const { path, group } of onNew) {\n const target = ensureFakeMount(\n this.mounts,\n path,\n {\n journal: server.journal,\n ...(registry ? { registry } : {}),\n logger,\n },\n logger,\n );\n // The check above found no mount at this path, and nothing ran since.\n if (\"conflict\" in target) continue;\n const result = target.handler.addMcpFakes?.(group, { kind: \"file\" });\n for (const warning of result?.warnings ?? []) logger.warn(warning.message);\n }\n }\n\n /** R4, R5: unload the fakes of every mount and the pre-start buffer. */\n private unloadMcpFakes(): void {\n this.mcpFakeBuffer.length = 0;\n for (const { handler } of this.mounts) handler.clearMcpFakes?.();\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n let entries: FixtureFileEntry[];\n if (typeof input === \"string\") {\n try {\n entries = JSON.parse(input);\n } catch (err) {\n throw new Error(\n `addFixturesFromJSON: invalid JSON — ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n } else {\n entries = input;\n }\n if (!Array.isArray(entries)) {\n throw new TypeError(\n \"addFixturesFromJSON: expected an array of fixture entries; use loadFixtureFile for a {fixtures:[...]} file\",\n );\n }\n const converted = entries.map((e) => entryToFixture(e, undefined, this.options.live));\n const issues = validateFixtures(converted, this.options.live);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Clears in place to preserve array reference identity — the running\n // server reads this same array on every request — and invalidates any\n // one-shot claim parked in flight so it cannot re-arm into the cleared queue.\n clearFixtures(): this {\n clearFixtureQueue(this.fixtures);\n this.unloadMcpFakes();\n return this;\n }\n\n // ---- Convenience ----\n\n on(\n match: FixtureMatch,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.addFixture({\n match,\n response:\n typeof response === \"function\" ? response : normalizeResponse(response, this.options.live),\n ...opts,\n });\n }\n\n onLive(\n match: Omit<FixtureMatch, \"endpoint\">,\n transcript: LiveTranscript,\n opts?: FixtureOpts,\n ): this {\n return this.on({ ...match, endpoint: \"openai-live\" }, { live: transcript }, opts);\n }\n\n onMessage(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(\n name: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(\n id: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n onTurn(\n turn: number,\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern, turnIndex: turn }, response, opts);\n }\n\n onImage(prompt: string | RegExp, response: ImageResponse): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"image\" },\n response,\n });\n }\n\n onSpeech(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: input, endpoint: \"speech\" },\n response,\n });\n }\n\n onTranscription(response: TranscriptionResponse): this {\n return this.addFixture({\n match: { endpoint: \"transcription\" },\n response,\n });\n }\n\n onTranslation(response: TranscriptionResponse): this {\n return this.addFixture({\n match: { endpoint: \"translation\" },\n response,\n });\n }\n\n onVideo(prompt: string | RegExp, response: VideoResponse): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"video\" },\n response,\n });\n }\n\n onAudio(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture({ match: { userMessage: input }, response });\n }\n\n onSoundEffect(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: text, endpoint: \"audio-gen\" },\n response,\n });\n }\n\n onMusic(prompt: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"audio-gen\" },\n response,\n });\n }\n\n onElevenLabsTTS(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: text, endpoint: \"elevenlabs-tts\" },\n response,\n });\n }\n\n onElevenLabsVoiceDesign(description: string | RegExp, response: VoiceDesignResponse): this {\n return this.addFixture({\n match: { userMessage: description, endpoint: \"elevenlabs-voice-design\" },\n response: voiceDesignToJson(response),\n });\n }\n\n onFalAudio(prompt: string | RegExp, response: AudioResponse, model?: string): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"fal-audio\", ...(model ? { model } : {}) },\n response,\n });\n }\n\n // fal.queue.* is the dominant client API; onFalRun is a sync alias.\n //\n // `opts.billableUnits` rides through to the completed `queue-result`\n // response's `x-fal-billable-units` header (emitted alongside\n // `x-fal-request-id`), letting consumers like `@tanstack/ai-fal` surface a\n // billed-units value on replay. Omit it to preserve the header-less default.\n onFalQueue(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n const { billableUnits, ...fixtureOpts } = opts ?? {};\n return this.addFixture({\n match: { model: modelOrPrompt, endpoint: \"fal\" },\n response: { json: response, ...(billableUnits != null ? { billableUnits } : {}) },\n ...fixtureOpts,\n });\n }\n\n onFalRun(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, response, opts);\n }\n\n /**\n * Register a fal.ai image fixture. Wraps an `ImageResponse` (the shape used\n * by `onImage` and OpenAI/Azure image fixtures) into fal's image envelope\n * before storing it as a `RawJSONResponse`. Defaults `width`/`height` to\n * 1024 when the fixture's `ImageItem` doesn't carry them.\n */\n onFalImage(modelOrPrompt: string | RegExp, response: ImageResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, imageResponseToFalJson(response), opts);\n }\n\n /**\n * Register a fal.ai video fixture. Wraps a `VideoResponse` into fal's video\n * envelope (`{ video: { url, content_type, file_name, file_size }, seed }`)\n * before storing it as a `RawJSONResponse`.\n */\n onFalVideo(modelOrPrompt: string | RegExp, response: VideoResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, videoResponseToFalJson(response), opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * inserted at the front of the fixture list; see `queueOneShotError` for\n * the endpoint gate and the served-not-evaluated consumption rule.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n // Same gate as `POST /__aimock/error` and fixture validation — this is the\n // form the docs use, and an unchecked status reaches `res.writeHead` on\n // the next matched request: 99/1000 throw there (the injected error is\n // lost and the caller sees a generic 500), and 1xx hangs the request until\n // the client times out. Throwing HERE names the offending call instead.\n if (!isInjectableStatus(status)) {\n throw new RangeError(\n `nextRequestError: invalid status ${String(status)} — must be ${INJECTED_STATUS_RANGE}`,\n );\n }\n queueOneShotError(this.fixtures, status, errorBody);\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n // W4: an auto-mounted MCPMock at `path` takes its requests first (dispatch\n // takes the first match), so the new mount is shadowed; so is one at\n // `path` plus \"/\", whose root request the auto-mount answers as its own.\n // An auto-mount lets any other sub-path fall through: that is no shadow.\n const shadowedBy = this.serverInstance\n ? this.mounts.find(\n (m) => isAutoMount(m.handler) && (path === m.path || path === m.path + \"/\"),\n )\n : undefined;\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, logger and baseUrl\n // immediately so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n const logger = this.serverInstance.defaults.logger;\n if (handler.setLogger) handler.setLogger(logger);\n if (shadowedBy) {\n logger.warn(\n build(\n msg`MCP fakes: the mount at ${quote(path)} is shadowed by the MCP mock auto-mounted at ${quote(shadowedBy.path)}; its requests reach the auto-mount`,\n ),\n );\n }\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n /**\n * Clear the request journal. Fixture match-counts (sequencing state) are\n * left intact — use `resetMatchCounts()` for those.\n */\n clearRequests(): void {\n this.journal.clearEntries();\n }\n\n /**\n * Reset fixture match counts, and the MCP fakes consumption state of every\n * mount (R6), for `testId` or for all test ids. Fakes stay loaded.\n */\n resetMatchCounts(testId?: string): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts(testId);\n }\n for (const { handler } of this.mounts) handler.resetScenarioState?.(testId);\n return this;\n }\n\n // ---- Chaos ----\n\n /**\n * Set the server-wide chaos baseline. Writes through to a RUNNING server as\n * well as the construction options: an untagged `POST /__aimock/chaos`\n * installs a baseline override that shadows `options.chaos`, and without this\n * the call would silently do nothing until the next `reset()`. Per-testId\n * overrides still win over the baseline.\n */\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n if (this.serverInstance) this.serverInstance.defaults.chaos = config;\n return this;\n }\n\n /**\n * Turn chaos off everywhere: the construction config, the runtime baseline,\n * and every per-testId override (assigning `undefined` is the full-clear\n * signal the `defaults.chaos` setter defines).\n */\n clearChaos(): this {\n delete this.options.chaos;\n if (this.serverInstance) this.serverInstance.defaults.chaos = undefined;\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n /**\n * Full reset — the in-process equivalent of `POST /__aimock/reset`. Shares\n * one implementation with the control-API route so the two cannot drift.\n *\n * The one deliberate difference: search / rerank / moderation fixtures are\n * also cleared here. Those are registered through this class only — the\n * control API has no route that creates them, so the HTTP reset can neither\n * reach nor observe them.\n *\n * NOT ALL OF THIS IS PER-INSTANCE. `performFullReset` clears module-global\n * state as well: the Gemini interaction and event-id counters\n * (`resetInteractionCounter` / `resetEventIdCounter` in\n * `./gemini-interactions.js`), the fal.ai job/queue maps (`falJobs`,\n * `falQueueStates`), the fine-tuning job store (`clearFineTuningStore`),\n * and the ElevenLabs Voice Design store (`clearElevenLabsVoices`). With two\n * `LLMock` instances live in one process,\n * `a.reset()` rewinds the Gemini id sequence that `b` is mid-way through —\n * `b` then re-emits `aimock-int-0` / `evt_1`, ids it has already handed\n * out — and drops `b`'s in-flight fal jobs. Give each instance its own\n * process (or its own vitest worker) if that matters.\n *\n * The global stores are cleared even before `start()`, when there is no\n * server instance to reset.\n */\n reset(): this {\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n // `ServerInstance` carries no mounts, so the fakes are unloaded here (R4).\n this.unloadMcpFakes();\n performFullReset(this.fixtures, this.serverInstance);\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n const serviceFixtures = {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n mcpFakes: [...this.mcpFakeBuffer],\n };\n this.serverInstance = await (this.resolvedInboundAuth\n ? createServerWithResolvedAuth(\n this.fixtures,\n this.options,\n this.resolvedInboundAuth,\n this.mounts,\n serviceFixtures,\n )\n : createServer(this.fixtures, this.options, this.mounts, serviceFixtures));\n // The server holds the buffered fakes now (W2). A start that rejects took\n // its hand-off back, so the buffer is kept for a retry.\n this.mcpFakeBuffer.length = 0;\n return this.serverInstance.url;\n }\n\n closeLiveSessions(testId?: string): this {\n this.serverInstance?.closeLiveSessions(testId);\n return this;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n\n/** @internal Configuration startup preserves a policy resolved from the selected source. */\nexport function createLLMockWithResolvedAuth(\n options: MockServerOptions,\n resolvedAuth: ResolvedInboundAuth,\n): LLMock {\n return new LLMock(options, resolvedAuth);\n}\n"],"mappings":";;;;;;;;;;;AAqDA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;;CAEhE,AAAQ,gBAAiC,EAAE;;CAE3C,AAAQ,iBAAwC;CAChD,AAAQ;CACR,AAAiB;CAEjB,YAA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AO,IAAI,OAAO,SAAS,aAAa"}
|
|
1
|
+
{"version":3,"file":"llmock.cjs","names":["getFixtureMisbehaviorPosition","parseMisbehavior","validateFixtureMisbehavior","MisbehaviorConfigError","isLiveResponse","normalizeLiveFixture","loadFixtureFileWithServices","loadFixturesFromDirWithServices","enableHeldFixtureMisbehavior","markFixtureResponsesToolsExtended","planFileFakes","ensureFakeMount","entryToFixture","validateFixtures","normalizeResponse","voiceDesignToJson","imageResponseToFalJson","videoResponseToFalJson","isInjectableStatus","INJECTED_STATUS_RANGE","isAutoMount","MCPMock","build","quote","resolveMisbehaviorSeed","DEFAULT_TEST_ID","createServerWithResolvedAuth","createServer"],"sources":["../src/llmock.ts"],"sourcesContent":["import type { LiveTranscript } from \"./live-types.js\";\nimport { normalizeLiveFixture, normalizeLiveOptions } from \"./live-fixture.js\";\nimport { isLiveResponse, markServerOwnedFixtures } from \"./helpers.js\";\nimport type {\n AudioResponse,\n ChaosConfig,\n EmbeddingFixtureOpts,\n FalQueueOpts,\n Fixture,\n FixtureFileEntry,\n FixtureFileResponse,\n FixtureMatch,\n FixtureOpts,\n FixtureResponse,\n ImageResponse,\n McpFakeSource,\n MockServerOptions,\n MisbehaviorConfig,\n MisbehaviorFaultId,\n Mountable,\n RecordConfig,\n ResponseFactory,\n TranscriptionResponse,\n VideoResponse,\n VoiceDesignResponse,\n} from \"./types.js\";\nimport {\n createServer,\n createServerWithResolvedAuth,\n performFullReset,\n type ServerInstance,\n} from \"./server.js\";\nimport type { ResolvedInboundAuth } from \"./api-key-auth.js\";\nimport {\n isInjectableStatus,\n INJECTED_STATUS_RANGE,\n queueOneShotError,\n clearFixtureQueue,\n entryToFixture,\n normalizeResponse,\n normalizeResponsesToolsKeys,\n validateFixtures,\n enableHeldFixtureMisbehavior,\n markFixtureResponsesToolsExtended,\n markFixtureMisbehaviorEnabled,\n MisbehaviorConfigError,\n} from \"./fixture-loader.js\";\nimport {\n loadFixtureFileWithServices,\n loadFixturesFromDirWithServices,\n type FixturesWithServices,\n} from \"./fixture-loader-services.js\";\nimport { ensureFakeMount, isAutoMount, planFileFakes } from \"./mcp-fakes-mount.js\";\nimport { MCPMock } from \"./mcp-mock.js\";\nimport { build, msg, quote } from \"./message-text.js\";\nimport { DEFAULT_TEST_ID } from \"./constants.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\nimport { imageResponseToFalJson, videoResponseToFalJson } from \"./fal.js\";\nimport { voiceDesignToJson } from \"./elevenlabs-voice.js\";\n\nimport {\n getFixtureMisbehaviorPosition,\n parseMisbehavior,\n resolveMisbehaviorSeed,\n setFixtureMisbehaviorPosition,\n validateFixtureMisbehavior,\n} from \"./misbehavior.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private fixtureAddition = 0;\n private readonly fixtureCountOrigins = new WeakMap<Fixture, Fixture>();\n /**\n * Fixtures this LLMock built itself (on() and the other helpers), so the\n * caller never held them: the stored object is their identity.\n */\n private readonly ownFixtures = new WeakSet<Fixture>();\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n /** `mcpFakes` blocks loaded before `start()`, handed to the server at start (W2). */\n private mcpFakeBuffer: McpFakeSource[] = [];\n /** MCPMocks the server or a load auto-mounted (W3, W6), for the L6 check. */\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n private readonly resolvedInboundAuth?: ResolvedInboundAuth;\n\n constructor(options?: MockServerOptions, resolvedInboundAuth?: ResolvedInboundAuth) {\n // Only this LLMock's server reads its array, so fixtures it makes may be marked in place.\n markServerOwnedFixtures(this.fixtures);\n this.options = options ?? {};\n if (this.options.live !== undefined) normalizeLiveOptions(this.options.live);\n // The `misbehavior` option is read only with `enableMisbehavior: true`;\n // otherwise it is unused data, as in 1.44.0.\n if (this.misbehaviorEnabled && this.options.misbehavior !== undefined) {\n this.setMisbehavior(this.options.misbehavior);\n }\n this.resolvedInboundAuth = resolvedInboundAuth;\n }\n\n /** Misbehavior (fixture keys, header, `misbehavior` option) needs `enableMisbehavior: true`. */\n private get misbehaviorEnabled(): boolean {\n return this.options.enableMisbehavior === true;\n }\n\n // ---- Fixture management ----\n\n private normalizeFixture(fixture: Fixture): Fixture {\n const misbehaviorEnabled = this.misbehaviorEnabled;\n // A fixture loaded from a file holds its `misbehavior` key until enabled.\n if (misbehaviorEnabled) enableHeldFixtureMisbehavior(fixture);\n // A fixture this LLMock built (on() and the helpers) is new to it, so it\n // needs no per-addition copy, and the object stored is its identity.\n const own = this.ownFixtures.delete(fixture);\n const countIdentity = own ? undefined : (this.fixtureCountOrigins.get(fixture) ?? fixture);\n const previousPosition = getFixtureMisbehaviorPosition(fixture);\n const isNewAddition = previousPosition === undefined || /^code#\\d+$/.test(previousPosition);\n const position = isNewAddition ? `code#${this.fixtureAddition++}` : previousPosition;\n // With misbehavior enabled, re-adding a code fixture creates a new fault\n // source without changing the old entry, so each addition is its own copy.\n // The journal counts and records every copy under the caller's object\n // (fixtureCountOrigins), so the identity APIs read as they do without\n // misbehavior: an object added twice is one caller fixture, as in 1.44.0.\n // Without misbehavior the position is never read, and the caller's object\n // is stored as in 1.44.0.\n if (isNewAddition && misbehaviorEnabled && !own) fixture = { ...fixture };\n if (misbehaviorEnabled && fixture.misbehavior !== undefined) {\n const parsed = parseMisbehavior(fixture.misbehavior);\n if (parsed.ok) fixture = { ...fixture, misbehavior: parsed.config };\n const issue = parsed.ok ? validateFixtureMisbehavior(fixture) : parsed.issue;\n if (issue) {\n throw new MisbehaviorConfigError({\n rule: issue.rule,\n file: position,\n detail: issue.message,\n });\n }\n }\n\n if (\n isLiveResponse(fixture.response) ||\n (fixture.match.endpoint === \"openai-live\" && typeof fixture.response !== \"function\")\n ) {\n fixture = {\n ...fixture,\n match: { ...fixture.match },\n response: normalizeLiveFixture(fixture.response, this.options.live),\n };\n } else if (countIdentity !== undefined && fixture !== countIdentity) {\n this.fixtureCountOrigins.set(fixture, countIdentity);\n }\n setFixtureMisbehaviorPosition(fixture, position);\n if (misbehaviorEnabled && fixture.misbehavior !== undefined) {\n markFixtureMisbehaviorEnabled(fixture);\n }\n // A fixture passed in is not marked for responsesTools \"extended\": the\n // server reads it through its extended view, so the caller's object (which\n // another server may share) is left as it was loaded.\n return fixture;\n }\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(this.normalizeFixture(fixture));\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures.map((fixture) => this.normalizeFixture(fixture)));\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(this.normalizeFixture(fixture));\n return this;\n }\n\n /** Mark a fixture this LLMock built, for {@link normalizeFixture}. */\n private own(fixture: Fixture): Fixture {\n this.ownFixtures.add(fixture);\n return fixture;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n /**\n * Load a fixture file: its LLM fixtures and its `mcpFakes` blocks (F4).\n * Before `start()` the blocks are buffered and handed to the server at\n * start (W2); after it they go to the MCPMock serving each block's `mount`\n * path, auto-mounted when none does (W6). A block that cannot be honored\n * throws a `FixtureLoadError` and nothing from the file is added.\n */\n loadFixtureFile(filePath: string): this {\n return this.acceptLoaded(loadFixtureFileWithServices(filePath, undefined, this.options.live));\n }\n\n /** As {@link loadFixtureFile}, for every fixture file under `dirPath`. */\n loadFixtureDir(dirPath: string): this {\n return this.acceptLoaded(\n loadFixturesFromDirWithServices(dirPath, undefined, this.options.live),\n );\n }\n\n /**\n * Add a load's fakes (all or nothing), then its LLM fixtures. Before start\n * the fakes are checked as the start-time hand-off will check them, with\n * the blocks already buffered and the mounts added so far, so a file whose\n * fakes would be rejected adds nothing. A mount added after the load can\n * still make `start()` reject.\n */\n private acceptLoaded(loaded: FixturesWithServices): this {\n // With misbehavior enabled, a bad `misbehavior` key throws before anything is added.\n if (this.misbehaviorEnabled) loaded.fixtures.forEach(enableHeldFixtureMisbehavior);\n if (this.options.responsesTools === \"extended\") {\n loaded.fixtures.forEach(markFixtureResponsesToolsExtended);\n }\n if (loaded.mcpFakes.length > 0) {\n if (this.serverInstance) {\n this.addFakesAfterStart(this.serverInstance, loaded.mcpFakes);\n } else {\n planFileFakes(\n this.mounts,\n [...this.mcpFakeBuffer, ...loaded.mcpFakes],\n new Set(loaded.mcpFakes),\n );\n this.mcpFakeBuffer.push(...loaded.mcpFakes);\n }\n }\n this.fixtures.push(...loaded.fixtures);\n return this;\n }\n\n /**\n * W6 for a load after start. Every group of blocks (by `mount` path) is\n * checked before any mount is touched: a path held by a mount that is not\n * an MCPMock is a mount conflict, and each group is first added to a\n * throwaway store. Groups for an existing MCPMock are then added to it (its\n * own add is all or nothing and finds collisions with its loaded ids);\n * groups for a free path are added last, to a new auto-mounted MCPMock,\n * wired as W4. The add warnings (L8) are logged at `warn`.\n */\n private addFakesAfterStart(server: ServerInstance, sources: McpFakeSource[]): void {\n const { onExisting, onNew } = planFileFakes(this.mounts, sources);\n\n const logger = server.defaults.logger;\n for (const { handler, group } of onExisting) {\n const result = handler.addMcpFakes?.(group, { kind: \"file\" });\n for (const warning of result?.warnings ?? []) logger.warn(warning.message);\n }\n const registry = server.defaults.registry;\n for (const { path, group } of onNew) {\n const target = ensureFakeMount(\n this.mounts,\n path,\n {\n journal: server.journal,\n ...(registry ? { registry } : {}),\n logger,\n replaySpeed: server.defaults.replaySpeed,\n },\n logger,\n );\n // The check above found no mount at this path, and nothing ran since.\n if (\"conflict\" in target) continue;\n const result = target.handler.addMcpFakes?.(group, { kind: \"file\" });\n for (const warning of result?.warnings ?? []) logger.warn(warning.message);\n }\n }\n\n /** R4, R5: unload the fakes of every mount and the pre-start buffer. */\n private unloadMcpFakes(): void {\n this.mcpFakeBuffer.length = 0;\n for (const { handler } of this.mounts) handler.clearMcpFakes?.();\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n let entries: FixtureFileEntry[];\n if (typeof input === \"string\") {\n try {\n entries = JSON.parse(input);\n } catch (err) {\n throw new Error(\n `addFixturesFromJSON: invalid JSON — ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n } else {\n entries = input;\n }\n if (!Array.isArray(entries)) {\n throw new TypeError(\n \"addFixturesFromJSON: expected an array of fixture entries; use loadFixtureFile for a {fixtures:[...]} file\",\n );\n }\n const converted = entries.map((entry) => {\n const position = `code#${this.fixtureAddition++}`;\n const fixture = entryToFixture(entry, undefined, this.options.live, {\n file: position,\n index: 0,\n });\n setFixtureMisbehaviorPosition(fixture, position);\n if (this.misbehaviorEnabled) enableHeldFixtureMisbehavior(fixture);\n if (this.options.responsesTools === \"extended\") markFixtureResponsesToolsExtended(fixture);\n return fixture;\n });\n\n const issues = validateFixtures(converted, this.options.live);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Clears in place to preserve array reference identity — the running\n // server reads this same array on every request — and invalidates any\n // one-shot claim parked in flight so it cannot re-arm into the cleared queue.\n clearFixtures(): this {\n clearFixtureQueue(this.fixtures);\n this.serverInstance?.journal.clearMisbehaviorCounters();\n this.unloadMcpFakes();\n return this;\n }\n\n // ---- Convenience ----\n\n on(\n match: FixtureMatch,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n let normalized: FixtureResponse | ResponseFactory = response as ResponseFactory;\n if (typeof response !== \"function\") {\n normalized = normalizeResponse(response, this.options.live);\n // `customToolCalls` / `responsesBlocks` are normalized only where they are\n // read; otherwise they stay as written, as in 1.44.0.\n if (this.options.responsesTools === \"extended\" && !isLiveResponse(normalized)) {\n normalizeResponsesToolsKeys(normalized as unknown as Record<string, unknown>);\n }\n }\n return this.addFixture(this.own({ match, response: normalized, ...opts }));\n }\n\n onLive(\n match: Omit<FixtureMatch, \"endpoint\">,\n transcript: LiveTranscript,\n opts?: FixtureOpts,\n ): this {\n return this.on({ ...match, endpoint: \"openai-live\" }, { live: transcript }, opts);\n }\n\n onMessage(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(\n name: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(\n id: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n onTurn(\n turn: number,\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern, turnIndex: turn }, response, opts);\n }\n\n onImage(prompt: string | RegExp, response: ImageResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"image\" },\n response,\n }),\n );\n }\n\n onSpeech(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: input, endpoint: \"speech\" },\n response,\n }),\n );\n }\n\n onTranscription(response: TranscriptionResponse): this {\n return this.addFixture(\n this.own({\n match: { endpoint: \"transcription\" },\n response,\n }),\n );\n }\n\n onTranslation(response: TranscriptionResponse): this {\n return this.addFixture(\n this.own({\n match: { endpoint: \"translation\" },\n response,\n }),\n );\n }\n\n onVideo(prompt: string | RegExp, response: VideoResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"video\" },\n response,\n }),\n );\n }\n\n onAudio(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture(this.own({ match: { userMessage: input }, response }));\n }\n\n onSoundEffect(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: text, endpoint: \"audio-gen\" },\n response,\n }),\n );\n }\n\n onMusic(prompt: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"audio-gen\" },\n response,\n }),\n );\n }\n\n onElevenLabsTTS(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: text, endpoint: \"elevenlabs-tts\" },\n response,\n }),\n );\n }\n\n onElevenLabsVoiceDesign(description: string | RegExp, response: VoiceDesignResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: description, endpoint: \"elevenlabs-voice-design\" },\n response: voiceDesignToJson(response),\n }),\n );\n }\n\n onFalAudio(prompt: string | RegExp, response: AudioResponse, model?: string): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"fal-audio\", ...(model ? { model } : {}) },\n response,\n }),\n );\n }\n\n // fal.queue.* is the dominant client API; onFalRun is a sync alias.\n //\n // `opts.billableUnits` rides through to the completed `queue-result`\n // response's `x-fal-billable-units` header (emitted alongside\n // `x-fal-request-id`), letting consumers like `@tanstack/ai-fal` surface a\n // billed-units value on replay. Omit it to preserve the header-less default.\n onFalQueue(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n const { billableUnits, ...fixtureOpts } = opts ?? {};\n return this.addFixture(\n this.own({\n match: { model: modelOrPrompt, endpoint: \"fal\" },\n response: { json: response, ...(billableUnits != null ? { billableUnits } : {}) },\n ...fixtureOpts,\n }),\n );\n }\n\n onFalRun(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, response, opts);\n }\n\n /**\n * Register a fal.ai image fixture. Wraps an `ImageResponse` (the shape used\n * by `onImage` and OpenAI/Azure image fixtures) into fal's image envelope\n * before storing it as a `RawJSONResponse`. Defaults `width`/`height` to\n * 1024 when the fixture's `ImageItem` doesn't carry them.\n */\n onFalImage(modelOrPrompt: string | RegExp, response: ImageResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, imageResponseToFalJson(response), opts);\n }\n\n /**\n * Register a fal.ai video fixture. Wraps a `VideoResponse` into fal's video\n * envelope (`{ video: { url, content_type, file_name, file_size }, seed }`)\n * before storing it as a `RawJSONResponse`.\n */\n onFalVideo(modelOrPrompt: string | RegExp, response: VideoResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, videoResponseToFalJson(response), opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * inserted at the front of the fixture list; see `queueOneShotError` for\n * the endpoint gate and the served-not-evaluated consumption rule.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n // Same gate as `POST /__aimock/error` and fixture validation — this is the\n // form the docs use, and an unchecked status reaches `res.writeHead` on\n // the next matched request: 99/1000 throw there (the injected error is\n // lost and the caller sees a generic 500), and 1xx hangs the request until\n // the client times out. Throwing HERE names the offending call instead.\n if (!isInjectableStatus(status)) {\n throw new RangeError(\n `nextRequestError: invalid status ${String(status)} — must be ${INJECTED_STATUS_RANGE}`,\n );\n }\n queueOneShotError(this.fixtures, status, errorBody);\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n // W4: an auto-mounted MCPMock at `path` takes its requests first (dispatch\n // takes the first match), so the new mount is shadowed; so is one at\n // `path` plus \"/\", whose root request the auto-mount answers as its own.\n // An auto-mount lets any other sub-path fall through: that is no shadow.\n const shadowedBy = this.serverInstance\n ? this.mounts.find(\n (m) => isAutoMount(m.handler) && (path === m.path || path === m.path + \"/\"),\n )\n : undefined;\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, logger and baseUrl\n // immediately so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n const logger = this.serverInstance.defaults.logger;\n if (handler.setLogger) handler.setLogger(logger);\n // B11/R12: only aimock's own MCPMock takes the replay speed; a custom\n // Mountable is never called (1.44.0 had no such hook).\n if (handler instanceof MCPMock) {\n handler.setReplaySpeed(this.serverInstance.defaults.replaySpeed);\n }\n if (shadowedBy) {\n logger.warn(\n build(\n msg`MCP fakes: the mount at ${quote(path)} is shadowed by the MCP mock auto-mounted at ${quote(shadowedBy.path)}; its requests reach the auto-mount`,\n ),\n );\n }\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n /**\n * Clear the request journal. Fixture match-counts (sequencing state) are\n * left intact — use `resetMatchCounts()` for those.\n */\n clearRequests(): void {\n this.journal.clearEntries();\n }\n\n /**\n * Reset fixture match counts, and the MCP fakes consumption state of every\n * mount (R6), for `testId` or for all test ids. Fakes stay loaded.\n */\n resetMatchCounts(testId?: string): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts(testId);\n }\n for (const { handler } of this.mounts) handler.resetScenarioState?.(testId);\n return this;\n }\n\n // ---- Chaos ----\n\n /**\n * Set the server-wide chaos baseline. Writes through to a RUNNING server as\n * well as the construction options: an untagged `POST /__aimock/chaos`\n * installs a baseline override that shadows `options.chaos`, and without this\n * the call would silently do nothing until the next `reset()`. Per-testId\n * overrides still win over the baseline.\n */\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n if (this.serverInstance) this.serverInstance.defaults.chaos = config;\n return this;\n }\n\n /**\n * Turn chaos off everywhere: the construction config, the runtime baseline,\n * and every per-testId override (assigning `undefined` is the full-clear\n * signal the `defaults.chaos` setter defines).\n */\n clearChaos(): this {\n delete this.options.chaos;\n if (this.serverInstance) this.serverInstance.defaults.chaos = undefined;\n return this;\n }\n\n // ---- Semantic misbehavior ----\n\n /** Replace construction/runtime baselines without changing named test overrides. */\n setMisbehavior(config: MisbehaviorConfig | MisbehaviorFaultId): this {\n if (!this.misbehaviorEnabled) {\n throw new TypeError(\n \"setMisbehavior: misbehavior is not enabled; construct with enableMisbehavior: true\",\n );\n }\n const parsed = parseMisbehavior(config);\n if (!parsed.ok) throw new TypeError(`${parsed.issue.rule}: ${parsed.issue.message}`);\n this.options.misbehavior = parsed.config;\n const defaults = this.serverInstance?.defaults;\n if (defaults?.misbehavior) {\n defaults.misbehavior.baseline =\n parsed.config.seed === \"random\"\n ? { ...parsed.config, seed: resolveMisbehaviorSeed(parsed.config.seed, defaults.logger) }\n : parsed.config;\n if (defaults.misbehavior.byTestId.has(DEFAULT_TEST_ID)) {\n defaults.misbehavior.byTestId.set(DEFAULT_TEST_ID, defaults.misbehavior.baseline);\n }\n }\n return this;\n }\n\n /** Clear the baseline and all runtime overrides, before or after start. */\n clearMisbehavior(): this {\n delete this.options.misbehavior;\n const scope = this.serverInstance?.defaults.misbehavior;\n if (scope) {\n scope.baseline = undefined;\n scope.byTestId.clear();\n }\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n /**\n * Full reset — the in-process equivalent of `POST /__aimock/reset`. Shares\n * one implementation with the control-API route so the two cannot drift.\n *\n * The one deliberate difference: search / rerank / moderation fixtures are\n * also cleared here. Those are registered through this class only — the\n * control API has no route that creates them, so the HTTP reset can neither\n * reach nor observe them.\n *\n * NOT ALL OF THIS IS PER-INSTANCE. `performFullReset` clears module-global\n * state as well: the Gemini interaction and event-id counters\n * (`resetInteractionCounter` / `resetEventIdCounter` in\n * `./gemini-interactions.js`), the fal.ai job/queue maps (`falJobs`,\n * `falQueueStates`), the fine-tuning job store (`clearFineTuningStore`),\n * and the ElevenLabs Voice Design store (`clearElevenLabsVoices`). With two\n * `LLMock` instances live in one process,\n * `a.reset()` rewinds the Gemini id sequence that `b` is mid-way through —\n * `b` then re-emits `aimock-int-0` / `evt_1`, ids it has already handed\n * out — and drops `b`'s in-flight fal jobs. Give each instance its own\n * process (or its own vitest worker) if that matters.\n *\n * The global stores are cleared even before `start()`, when there is no\n * server instance to reset.\n */\n reset(): this {\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n // `ServerInstance` carries no mounts, so the fakes are unloaded here (R4).\n this.unloadMcpFakes();\n performFullReset(this.fixtures, this.serverInstance);\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n const serviceFixtures = {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n mcpFakes: [...this.mcpFakeBuffer],\n };\n this.serverInstance = await (this.resolvedInboundAuth\n ? createServerWithResolvedAuth(\n this.fixtures,\n this.options,\n this.resolvedInboundAuth,\n this.mounts,\n serviceFixtures,\n )\n : createServer(this.fixtures, this.options, this.mounts, serviceFixtures));\n const countIdentity = (fixture: Fixture) => this.fixtureCountOrigins.get(fixture) ?? fixture;\n this.serverInstance.journal.configureFixtureCountIdentity(countIdentity);\n // The server holds the buffered fakes now (W2). A start that rejects took\n // its hand-off back, so the buffer is kept for a retry.\n this.mcpFakeBuffer.length = 0;\n return this.serverInstance.url;\n }\n\n closeLiveSessions(testId?: string): this {\n this.serverInstance?.closeLiveSessions(testId);\n return this;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n\n/** @internal Configuration startup preserves a policy resolved from the selected source. */\nexport function createLLMockWithResolvedAuth(\n options: MockServerOptions,\n resolvedAuth: ResolvedInboundAuth,\n): LLMock {\n return new LLMock(options, resolvedAuth);\n}\n"],"mappings":";;;;;;;;;;;;;;AAuEA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,kBAAkB;CAC1B,AAAiB,sCAAsB,IAAI,SAA2B;;;;;CAKtE,AAAiB,8BAAc,IAAI,SAAkB;CACrD,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;;CA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AI,OAAe;EACjB,MAAM,SAAS,IAAI,IAAI,KAAK,IAAI;AAChC,MAAI,CAAC,OAAO,KACV,OAAM,IAAI,MAAM,oCAAoC,KAAK,MAAM;AAEjE,SAAO,SAAS,OAAO,MAAM,GAAG;;CAKlC,aAAa,OAAO,SAA8C;EAChE,MAAM,WAAW,IAAI,OAAO,QAAQ;AACpC,QAAM,SAAS,OAAO;AACtB,SAAO;;;;AAKX,SAAgB,6BACd,SACA,cACQ;AACR,QAAO,IAAI,OAAO,SAAS,aAAa"}
|
package/dist/llmock.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Journal } from "./journal.cjs";
|
|
2
2
|
import { LiveTranscript } from "./live-types.cjs";
|
|
3
|
-
import { AudioResponse, ChaosConfig, EmbeddingFixtureOpts, FalQueueOpts, Fixture, FixtureFileEntry, FixtureFileResponse, FixtureMatch, FixtureOpts, ImageResponse, JournalEntry, MockServerOptions, Mountable, RecordConfig, ResponseFactory, TranscriptionResponse, VideoResponse, VoiceDesignResponse } from "./types.cjs";
|
|
3
|
+
import { AudioResponse, ChaosConfig, EmbeddingFixtureOpts, FalQueueOpts, Fixture, FixtureFileEntry, FixtureFileResponse, FixtureMatch, FixtureOpts, ImageResponse, JournalEntry, MisbehaviorConfig, MisbehaviorFaultId, MockServerOptions, Mountable, RecordConfig, ResponseFactory, TranscriptionResponse, VideoResponse, VoiceDesignResponse } from "./types.cjs";
|
|
4
4
|
import { ResolvedInboundAuth } from "./api-key-auth.cjs";
|
|
5
5
|
import { SearchResult } from "./search.cjs";
|
|
6
6
|
import { RerankResult } from "./rerank.cjs";
|
|
@@ -9,6 +9,13 @@ import { ModerationResult } from "./moderation.cjs";
|
|
|
9
9
|
//#region src/llmock.d.ts
|
|
10
10
|
declare class LLMock {
|
|
11
11
|
private fixtures;
|
|
12
|
+
private fixtureAddition;
|
|
13
|
+
private readonly fixtureCountOrigins;
|
|
14
|
+
/**
|
|
15
|
+
* Fixtures this LLMock built itself (on() and the other helpers), so the
|
|
16
|
+
* caller never held them: the stored object is their identity.
|
|
17
|
+
*/
|
|
18
|
+
private readonly ownFixtures;
|
|
12
19
|
private searchFixtures;
|
|
13
20
|
private rerankFixtures;
|
|
14
21
|
private moderationFixtures;
|
|
@@ -20,10 +27,14 @@ declare class LLMock {
|
|
|
20
27
|
private options;
|
|
21
28
|
private readonly resolvedInboundAuth?;
|
|
22
29
|
constructor(options?: MockServerOptions, resolvedInboundAuth?: ResolvedInboundAuth);
|
|
30
|
+
/** Misbehavior (fixture keys, header, `misbehavior` option) needs `enableMisbehavior: true`. */
|
|
31
|
+
private get misbehaviorEnabled();
|
|
23
32
|
private normalizeFixture;
|
|
24
33
|
addFixture(fixture: Fixture): this;
|
|
25
34
|
addFixtures(fixtures: Fixture[]): this;
|
|
26
35
|
prependFixture(fixture: Fixture): this;
|
|
36
|
+
/** Mark a fixture this LLMock built, for {@link normalizeFixture}. */
|
|
37
|
+
private own;
|
|
27
38
|
getFixtures(): readonly Fixture[];
|
|
28
39
|
/**
|
|
29
40
|
* Load a fixture file: its LLM fixtures and its `mcpFakes` blocks (F4).
|
|
@@ -136,6 +147,10 @@ declare class LLMock {
|
|
|
136
147
|
* signal the `defaults.chaos` setter defines).
|
|
137
148
|
*/
|
|
138
149
|
clearChaos(): this;
|
|
150
|
+
/** Replace construction/runtime baselines without changing named test overrides. */
|
|
151
|
+
setMisbehavior(config: MisbehaviorConfig | MisbehaviorFaultId): this;
|
|
152
|
+
/** Clear the baseline and all runtime overrides, before or after start. */
|
|
153
|
+
clearMisbehavior(): this;
|
|
139
154
|
enableRecording(config: RecordConfig): this;
|
|
140
155
|
disableRecording(): this;
|
|
141
156
|
/**
|
package/dist/llmock.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llmock.d.cts","names":[],"sources":["../src/llmock.ts"],"sourcesContent":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"llmock.d.cts","names":[],"sources":["../src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AA,GAjOM,MAiON,EAAA,QAAA,EAjOwB,aAiOxB,CAAA,EAAA,IAAA;SAAoB,CAAA,MAAA,EAAA,MAAA,GAxNlB,MAwNkB,EAAA,QAAA,EAxNA,aAwNA,CAAA,EAAA,IAAA;iBAmCnB,CAAA,IAAA,EAAA,MAAA,GAlPO,MAkPP,EAAA,QAAA,EAlPyB,aAkPzB,CAAA,EAAA,IAAA;yBAgDT,CAAA,WAAA,EAAA,MAAA,GAzR+B,MAyR/B,EAAA,QAAA,EAzRiD,mBAyRjD,CAAA,EAAA,IAAA;YAgCD,CAAA,MAAA,EAAA,MAAA,GAhTc,MAgTd,EAAA,QAAA,EAhTgC,aAgThC,EAAA,KAAA,CAAA,EAAA,MAAA,CAAA,EAAA,IAAA;YAaC,CAAA,aAAA,EAAA,MAAA,GA9SoB,MA8SpB,EAAA,QAAA,EAAA,OAAA,EAAA,IAAA,CAAA,EA9SsD,YA8StD,CAAA,EAAA,IAAA;UA4Be,CAAA,aAAA,EAAA,MAAA,GA/TG,MA+TH,EAAA,QAAA,EAAA,OAAA,EAAA,IAAA,CAAA,EA/TqC,YA+TrC,CAAA,EAAA,IAAA;;;;;;;qCArTK,kBAAkB,sBAAsB;;;;;;qCASxC,kBAAkB,sBAAsB;6BAMhD,iBAAiB;6BAKjB,iBAAiB;+BAKf,gBAAgB;;;;;;;;;;;;+BA+BhB;iBAAS,YAAA;oBAwCU,YAAA;;;;;;;;;;;;;;;;;;mBAqC/B;;;;;;;;yBAoBM,oBAAoB;;;0BAmCnB;;;;;;;;;;;;;;;;;;;;;;;;;;;WAgDT;;UAgCD;iBAaC;;;;0BA4Be,oBAAoB,QAAQ"}
|
package/dist/llmock.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Journal } from "./journal.js";
|
|
2
2
|
import { LiveTranscript } from "./live-types.js";
|
|
3
|
-
import { AudioResponse, ChaosConfig, EmbeddingFixtureOpts, FalQueueOpts, Fixture, FixtureFileEntry, FixtureFileResponse, FixtureMatch, FixtureOpts, ImageResponse, JournalEntry, MockServerOptions, Mountable, RecordConfig, ResponseFactory, TranscriptionResponse, VideoResponse, VoiceDesignResponse } from "./types.js";
|
|
3
|
+
import { AudioResponse, ChaosConfig, EmbeddingFixtureOpts, FalQueueOpts, Fixture, FixtureFileEntry, FixtureFileResponse, FixtureMatch, FixtureOpts, ImageResponse, JournalEntry, MisbehaviorConfig, MisbehaviorFaultId, MockServerOptions, Mountable, RecordConfig, ResponseFactory, TranscriptionResponse, VideoResponse, VoiceDesignResponse } from "./types.js";
|
|
4
4
|
import { ResolvedInboundAuth } from "./api-key-auth.js";
|
|
5
5
|
import { SearchResult } from "./search.js";
|
|
6
6
|
import { RerankResult } from "./rerank.js";
|
|
@@ -9,6 +9,13 @@ import { ModerationResult } from "./moderation.js";
|
|
|
9
9
|
//#region src/llmock.d.ts
|
|
10
10
|
declare class LLMock {
|
|
11
11
|
private fixtures;
|
|
12
|
+
private fixtureAddition;
|
|
13
|
+
private readonly fixtureCountOrigins;
|
|
14
|
+
/**
|
|
15
|
+
* Fixtures this LLMock built itself (on() and the other helpers), so the
|
|
16
|
+
* caller never held them: the stored object is their identity.
|
|
17
|
+
*/
|
|
18
|
+
private readonly ownFixtures;
|
|
12
19
|
private searchFixtures;
|
|
13
20
|
private rerankFixtures;
|
|
14
21
|
private moderationFixtures;
|
|
@@ -20,10 +27,14 @@ declare class LLMock {
|
|
|
20
27
|
private options;
|
|
21
28
|
private readonly resolvedInboundAuth?;
|
|
22
29
|
constructor(options?: MockServerOptions, resolvedInboundAuth?: ResolvedInboundAuth);
|
|
30
|
+
/** Misbehavior (fixture keys, header, `misbehavior` option) needs `enableMisbehavior: true`. */
|
|
31
|
+
private get misbehaviorEnabled();
|
|
23
32
|
private normalizeFixture;
|
|
24
33
|
addFixture(fixture: Fixture): this;
|
|
25
34
|
addFixtures(fixtures: Fixture[]): this;
|
|
26
35
|
prependFixture(fixture: Fixture): this;
|
|
36
|
+
/** Mark a fixture this LLMock built, for {@link normalizeFixture}. */
|
|
37
|
+
private own;
|
|
27
38
|
getFixtures(): readonly Fixture[];
|
|
28
39
|
/**
|
|
29
40
|
* Load a fixture file: its LLM fixtures and its `mcpFakes` blocks (F4).
|
|
@@ -136,6 +147,10 @@ declare class LLMock {
|
|
|
136
147
|
* signal the `defaults.chaos` setter defines).
|
|
137
148
|
*/
|
|
138
149
|
clearChaos(): this;
|
|
150
|
+
/** Replace construction/runtime baselines without changing named test overrides. */
|
|
151
|
+
setMisbehavior(config: MisbehaviorConfig | MisbehaviorFaultId): this;
|
|
152
|
+
/** Clear the baseline and all runtime overrides, before or after start. */
|
|
153
|
+
clearMisbehavior(): this;
|
|
139
154
|
enableRecording(config: RecordConfig): this;
|
|
140
155
|
disableRecording(): this;
|
|
141
156
|
/**
|