llm-mock-server 1.0.6 → 1.0.7
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/dist/cli/cli.d.ts +3 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +103 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/validators.d.ts +7 -0
- package/dist/cli/validators.d.ts.map +1 -0
- package/dist/cli/validators.js +53 -0
- package/dist/cli/validators.js.map +1 -0
- package/dist/formats/anthropic/index.d.ts +1 -1
- package/dist/formats/anthropic/index.d.ts.map +1 -1
- package/dist/formats/anthropic/index.js +1 -1
- package/dist/formats/anthropic/index.js.map +1 -1
- package/dist/formats/anthropic/parse.d.ts +2 -2
- package/dist/formats/anthropic/parse.d.ts.map +1 -1
- package/dist/formats/anthropic/parse.js +4 -2
- package/dist/formats/anthropic/parse.js.map +1 -1
- package/dist/formats/anthropic/schema.d.ts +1 -1
- package/dist/formats/anthropic/schema.d.ts.map +1 -1
- package/dist/formats/anthropic/schema.js +9 -4
- package/dist/formats/anthropic/schema.js.map +1 -1
- package/dist/formats/anthropic/serialize.d.ts +2 -2
- package/dist/formats/anthropic/serialize.d.ts.map +1 -1
- package/dist/formats/anthropic/serialize.js +76 -19
- package/dist/formats/anthropic/serialize.js.map +1 -1
- package/dist/formats/openai/chat-completions/index.d.ts +3 -0
- package/dist/formats/openai/chat-completions/index.d.ts.map +1 -0
- package/dist/formats/openai/chat-completions/index.js +13 -0
- package/dist/formats/openai/chat-completions/index.js.map +1 -0
- package/dist/formats/openai/chat-completions/parse.d.ts +4 -0
- package/dist/formats/openai/chat-completions/parse.d.ts.map +1 -0
- package/dist/formats/openai/chat-completions/parse.js +33 -0
- package/dist/formats/openai/chat-completions/parse.js.map +1 -0
- package/dist/formats/openai/chat-completions/schema.d.ts +93 -0
- package/dist/formats/openai/chat-completions/schema.d.ts.map +1 -0
- package/dist/formats/openai/chat-completions/schema.js +74 -0
- package/dist/formats/openai/chat-completions/schema.js.map +1 -0
- package/dist/formats/openai/chat-completions/serialize.d.ts +10 -0
- package/dist/formats/openai/chat-completions/serialize.d.ts.map +1 -0
- package/dist/formats/openai/chat-completions/serialize.js +99 -0
- package/dist/formats/openai/chat-completions/serialize.js.map +1 -0
- package/dist/formats/openai/responses/index.d.ts +3 -0
- package/dist/formats/openai/responses/index.d.ts.map +1 -0
- package/dist/formats/openai/responses/index.js +13 -0
- package/dist/formats/openai/responses/index.js.map +1 -0
- package/dist/formats/openai/responses/parse.d.ts +4 -0
- package/dist/formats/openai/responses/parse.d.ts.map +1 -0
- package/dist/formats/openai/responses/parse.js +51 -0
- package/dist/formats/openai/responses/parse.js.map +1 -0
- package/dist/formats/openai/responses/schema.d.ts +103 -0
- package/dist/formats/openai/responses/schema.d.ts.map +1 -0
- package/dist/formats/openai/responses/schema.js +71 -0
- package/dist/formats/openai/responses/schema.js.map +1 -0
- package/dist/formats/openai/responses/serialize.d.ts +10 -0
- package/dist/formats/openai/responses/serialize.d.ts.map +1 -0
- package/dist/formats/openai/responses/serialize.js +273 -0
- package/dist/formats/openai/responses/serialize.js.map +1 -0
- package/dist/formats/request-helpers.d.ts +1 -1
- package/dist/formats/request-helpers.d.ts.map +1 -1
- package/dist/formats/request-helpers.js.map +1 -1
- package/dist/formats/serialize-helpers.d.ts +1 -1
- package/dist/formats/serialize-helpers.d.ts.map +1 -1
- package/dist/formats/serialize-helpers.js +6 -3
- package/dist/formats/serialize-helpers.js.map +1 -1
- package/dist/formats/types.d.ts +2 -1
- package/dist/formats/types.d.ts.map +1 -1
- package/dist/history.d.ts +6 -2
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +2 -0
- package/dist/history.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +26 -9
- package/dist/loader.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +12 -4
- package/dist/logger.js.map +1 -1
- package/dist/mock-server.d.ts +44 -48
- package/dist/mock-server.d.ts.map +1 -1
- package/dist/mock-server.js +37 -85
- package/dist/mock-server.js.map +1 -1
- package/dist/route-handler.d.ts +1 -1
- package/dist/route-handler.d.ts.map +1 -1
- package/dist/route-handler.js +19 -7
- package/dist/route-handler.js.map +1 -1
- package/dist/rule-builder.d.ts +21 -0
- package/dist/rule-builder.d.ts.map +1 -0
- package/dist/rule-builder.js +58 -0
- package/dist/rule-builder.js.map +1 -0
- package/dist/rule-engine.d.ts +3 -1
- package/dist/rule-engine.d.ts.map +1 -1
- package/dist/rule-engine.js +7 -2
- package/dist/rule-engine.js.map +1 -1
- package/dist/sse-writer.d.ts +1 -1
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/types/reply.d.ts +51 -8
- package/dist/types/reply.d.ts.map +1 -1
- package/dist/types/request.d.ts +21 -6
- package/dist/types/request.d.ts.map +1 -1
- package/dist/types/rule.d.ts +65 -7
- package/dist/types/rule.d.ts.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +15 -9
- package/.claude/skills/desloppify/SKILL.md +0 -308
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/canonical_import_20260315_000801.json +0 -242
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/canonical_import_20260315_000905.json +0 -248
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/canonical_import_20260315_000917.json +0 -248
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/canonical_import_20260315_000950.json +0 -311
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/claude_launch_prompt.md +0 -17
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/review_result.json +0 -255
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/review_result.template.json +0 -22
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/reviewer_instructions.md +0 -20
- package/.desloppify/external_review_sessions/ext_20260315_000339_a6cdc3e6/session.json +0 -20
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/canonical_import_20260315_050000.json +0 -286
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/canonical_import_20260315_050028.json +0 -303
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/claude_launch_prompt.md +0 -17
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/review_result.json +0 -297
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/review_result.template.json +0 -22
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/reviewer_instructions.md +0 -20
- package/.desloppify/external_review_sessions/ext_20260315_045546_0587ea3b/session.json +0 -20
- package/.desloppify/query.json +0 -1312
- package/.desloppify/review_packet_blind.json +0 -1249
- package/.desloppify/review_packets/holistic_packet_20260315_000339.json +0 -1471
- package/.desloppify/review_packets/holistic_packet_20260315_045546.json +0 -1480
- package/.desloppify/review_packets/holistic_packet_20260315_185401.json +0 -1407
- package/.desloppify/review_packets/holistic_packet_20260315_185613.json +0 -1407
- package/.desloppify/state-typescript.json +0 -8438
- package/.desloppify/state-typescript.json.bak +0 -8432
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-1.log +0 -384
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-10.log +0 -484
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-2.log +0 -408
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-3.log +0 -416
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-4.log +0 -360
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-5.log +0 -360
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-6.log +0 -364
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-7.log +0 -428
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-8.log +0 -388
- package/.desloppify/subagents/runs/20260315_185401/logs/batch-9.log +0 -500
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-1.md +0 -83
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-10.md +0 -108
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-2.md +0 -89
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-3.md +0 -91
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-4.md +0 -77
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-5.md +0 -77
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-6.md +0 -78
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-7.md +0 -94
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-8.md +0 -84
- package/.desloppify/subagents/runs/20260315_185401/prompts/batch-9.md +0 -112
- package/.desloppify/subagents/runs/20260315_185401/results/batch-1.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-10.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-2.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-3.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-4.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-5.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-6.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-7.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-8.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/results/batch-9.raw.txt +0 -0
- package/.desloppify/subagents/runs/20260315_185401/run.log +0 -36
- package/.desloppify/subagents/runs/20260315_185401/run_summary.json +0 -156
- package/.desloppify/subagents/runs/20260315_185613/holistic_findings_merged.json +0 -741
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-1.log +0 -579
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-10.log +0 -1537
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-2.log +0 -829
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-3.log +0 -927
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-4.log +0 -429
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-5.log +0 -276
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-6.log +0 -450
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-7.log +0 -730
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-8.log +0 -698
- package/.desloppify/subagents/runs/20260315_185613/logs/batch-9.log +0 -938
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-1.md +0 -83
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-10.md +0 -108
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-2.md +0 -89
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-3.md +0 -91
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-4.md +0 -77
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-5.md +0 -77
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-6.md +0 -78
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-7.md +0 -94
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-8.md +0 -84
- package/.desloppify/subagents/runs/20260315_185613/prompts/batch-9.md +0 -112
- package/.desloppify/subagents/runs/20260315_185613/results/batch-1.raw.txt +0 -78
- package/.desloppify/subagents/runs/20260315_185613/results/batch-10.raw.txt +0 -242
- package/.desloppify/subagents/runs/20260315_185613/results/batch-2.raw.txt +0 -102
- package/.desloppify/subagents/runs/20260315_185613/results/batch-3.raw.txt +0 -94
- package/.desloppify/subagents/runs/20260315_185613/results/batch-4.raw.txt +0 -86
- package/.desloppify/subagents/runs/20260315_185613/results/batch-5.raw.txt +0 -1
- package/.desloppify/subagents/runs/20260315_185613/results/batch-6.raw.txt +0 -87
- package/.desloppify/subagents/runs/20260315_185613/results/batch-7.raw.txt +0 -1
- package/.desloppify/subagents/runs/20260315_185613/results/batch-8.raw.txt +0 -107
- package/.desloppify/subagents/runs/20260315_185613/results/batch-9.raw.txt +0 -67
- package/.desloppify/subagents/runs/20260315_185613/run.log +0 -96
- package/.desloppify/subagents/runs/20260315_185613/run_summary.json +0 -156
- package/.editorconfig +0 -12
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/docs.yml +0 -46
- package/.github/workflows/test.yml +0 -40
- package/.markdownlint.jsonc +0 -11
- package/.node-version +0 -1
- package/.oxfmtrc.json +0 -9
- package/.oxlintrc.json +0 -35
- package/docs/ARCHITECTURE.md +0 -125
- package/scorecard.png +0 -0
- package/src/cli/cli.ts +0 -141
- package/src/cli/validators.ts +0 -68
- package/src/formats/anthropic/index.ts +0 -14
- package/src/formats/anthropic/parse.ts +0 -70
- package/src/formats/anthropic/schema.ts +0 -74
- package/src/formats/anthropic/serialize.ts +0 -179
- package/src/formats/openai/chat-completions/index.ts +0 -14
- package/src/formats/openai/chat-completions/parse.ts +0 -47
- package/src/formats/openai/chat-completions/schema.ts +0 -92
- package/src/formats/openai/chat-completions/serialize.ts +0 -146
- package/src/formats/openai/responses/index.ts +0 -14
- package/src/formats/openai/responses/parse.ts +0 -73
- package/src/formats/openai/responses/schema.ts +0 -86
- package/src/formats/openai/responses/serialize.ts +0 -328
- package/src/formats/request-helpers.ts +0 -56
- package/src/formats/serialize-helpers.ts +0 -43
- package/src/formats/types.ts +0 -26
- package/src/history.ts +0 -70
- package/src/index.ts +0 -46
- package/src/loader.ts +0 -246
- package/src/logger.ts +0 -70
- package/src/mock-server.ts +0 -203
- package/src/route-handler.ts +0 -144
- package/src/rule-builder.ts +0 -73
- package/src/rule-engine.ts +0 -165
- package/src/sse-writer.ts +0 -35
- package/src/types/reply.ts +0 -92
- package/src/types/request.ts +0 -56
- package/src/types/rule.ts +0 -125
- package/src/types.ts +0 -24
- package/test/cli-validators.test.ts +0 -151
- package/test/formats/anthropic.test.ts +0 -336
- package/test/formats/openai.test.ts +0 -316
- package/test/formats/parse-helpers.test.ts +0 -315
- package/test/formats/responses.test.ts +0 -380
- package/test/helpers/make-req.ts +0 -18
- package/test/history.test.ts +0 -361
- package/test/loader.test.ts +0 -333
- package/test/logger.test.ts +0 -344
- package/test/mock-server.test.ts +0 -619
- package/test/rule-engine.test.ts +0 -229
- package/tsconfig.json +0 -24
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -9
- package/vitest.config.ts +0 -18
package/test/rule-engine.test.ts
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
-
import { RuleEngine } from "#/rule-engine.js";
|
|
3
|
-
import { makeReq } from "./helpers/make-req.js";
|
|
4
|
-
|
|
5
|
-
describe("RuleEngine", () => {
|
|
6
|
-
let engine: RuleEngine;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
engine = new RuleEngine();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("matches a string (substring, case-insensitive)", () => {
|
|
13
|
-
engine.add("hello", "Hi!");
|
|
14
|
-
const rule = engine.match(makeReq({ lastMessage: "say Hello world" }));
|
|
15
|
-
if (!rule) throw new Error("expected match");
|
|
16
|
-
expect(rule.description).toBe('"hello"');
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("matches a regex", () => {
|
|
20
|
-
engine.add(/explain (\w+)/i, "Here is an explanation.");
|
|
21
|
-
const rule = engine.match(
|
|
22
|
-
makeReq({ lastMessage: "Can you explain recursion?" }),
|
|
23
|
-
);
|
|
24
|
-
expect(rule).toBeDefined();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("matches a predicate function", () => {
|
|
28
|
-
engine.add((req) => req.messages.length > 2, "Long conversation");
|
|
29
|
-
const rule = engine.match(
|
|
30
|
-
makeReq({
|
|
31
|
-
messages: [
|
|
32
|
-
{ role: "system", content: "You are helpful" },
|
|
33
|
-
{ role: "user", content: "hi" },
|
|
34
|
-
{ role: "assistant", content: "hello" },
|
|
35
|
-
],
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
expect(rule).toBeDefined();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("matches a MatchObject with model", () => {
|
|
42
|
-
engine.add({ model: "gpt-5.4" }, "I'm GPT-5.4");
|
|
43
|
-
expect(engine.match(makeReq({ model: "gpt-5.4" }))).toBeDefined();
|
|
44
|
-
expect(engine.match(makeReq({ model: "claude-3" }))).toBeUndefined();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("matches a MatchObject with message + model", () => {
|
|
48
|
-
engine.add({ model: "gpt-5.4", message: "hello" }, "Hi from GPT-5.4");
|
|
49
|
-
expect(
|
|
50
|
-
engine.match(makeReq({ model: "gpt-5.4", lastMessage: "hello" })),
|
|
51
|
-
).toBeDefined();
|
|
52
|
-
expect(
|
|
53
|
-
engine.match(makeReq({ model: "gpt-5.4", lastMessage: "bye" })),
|
|
54
|
-
).toBeUndefined();
|
|
55
|
-
expect(
|
|
56
|
-
engine.match(makeReq({ model: "claude", lastMessage: "hello" })),
|
|
57
|
-
).toBeUndefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("matches a MatchObject with system", () => {
|
|
61
|
-
engine.add({ system: /pirate/i }, "Arrr!");
|
|
62
|
-
expect(
|
|
63
|
-
engine.match(makeReq({ systemMessage: "You are a pirate" })),
|
|
64
|
-
).toBeDefined();
|
|
65
|
-
expect(
|
|
66
|
-
engine.match(makeReq({ systemMessage: "You are helpful" })),
|
|
67
|
-
).toBeUndefined();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("matches a MatchObject with format", () => {
|
|
71
|
-
engine.add({ format: "anthropic" }, "Anthropic only");
|
|
72
|
-
expect(engine.match(makeReq({ format: "anthropic" }))).toBeDefined();
|
|
73
|
-
expect(engine.match(makeReq({ format: "openai" }))).toBeUndefined();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("returns first match (first-match-wins)", () => {
|
|
77
|
-
engine.add("hello", "First");
|
|
78
|
-
engine.add("hello", "Second");
|
|
79
|
-
const rule = engine.match(makeReq());
|
|
80
|
-
if (!rule) throw new Error("expected match");
|
|
81
|
-
expect(rule.resolve).toBe("First");
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("returns undefined when no rules match", () => {
|
|
85
|
-
engine.add("goodbye", "Bye!");
|
|
86
|
-
expect(engine.match(makeReq({ lastMessage: "hello" }))).toBeUndefined();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("times()", () => {
|
|
90
|
-
it("decrements and removes rule after N matches", () => {
|
|
91
|
-
const rule = engine.add("hello", "Once");
|
|
92
|
-
rule.remaining = 1;
|
|
93
|
-
|
|
94
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
95
|
-
expect(engine.match(makeReq())).toBeUndefined();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("allows multiple matches with times > 1", () => {
|
|
99
|
-
const rule = engine.add("hello", "Twice");
|
|
100
|
-
rule.remaining = 2;
|
|
101
|
-
|
|
102
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
103
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
104
|
-
expect(engine.match(makeReq())).toBeUndefined();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("isDone() returns true when all limited rules are consumed", () => {
|
|
108
|
-
const rule = engine.add("hello", "Once");
|
|
109
|
-
rule.remaining = 1;
|
|
110
|
-
engine.add("world", "Unlimited"); // no times limit
|
|
111
|
-
|
|
112
|
-
expect(engine.isDone()).toBe(false);
|
|
113
|
-
engine.match(makeReq());
|
|
114
|
-
expect(engine.isDone()).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("clear() removes all rules", () => {
|
|
119
|
-
engine.add("hello", "Hi");
|
|
120
|
-
engine.add("bye", "Bye");
|
|
121
|
-
engine.clear();
|
|
122
|
-
expect(engine.ruleCount).toBe(0);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("addHandler adds a handler-style rule", () => {
|
|
126
|
-
engine.addHandler(
|
|
127
|
-
(req) => req.lastMessage.includes("test"),
|
|
128
|
-
"Handler reply",
|
|
129
|
-
);
|
|
130
|
-
expect(
|
|
131
|
-
engine.match(makeReq({ lastMessage: "this is a test" })),
|
|
132
|
-
).toBeDefined();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("toolName matching", () => {
|
|
136
|
-
it("matches when toolNames includes the specified tool", () => {
|
|
137
|
-
engine.add({ toolName: "get_weather" }, "Weather tool present");
|
|
138
|
-
expect(
|
|
139
|
-
engine.match(makeReq({ toolNames: ["get_weather", "search"] })),
|
|
140
|
-
).toBeDefined();
|
|
141
|
-
expect(engine.match(makeReq({ toolNames: ["search"] }))).toBeUndefined();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("toolCallId matching", () => {
|
|
146
|
-
it("matches when lastToolCallId equals the specified id", () => {
|
|
147
|
-
engine.add({ toolCallId: "call_abc" }, "Tool result");
|
|
148
|
-
expect(
|
|
149
|
-
engine.match(makeReq({ lastToolCallId: "call_abc" })),
|
|
150
|
-
).toBeDefined();
|
|
151
|
-
expect(
|
|
152
|
-
engine.match(makeReq({ lastToolCallId: "call_xyz" })),
|
|
153
|
-
).toBeUndefined();
|
|
154
|
-
expect(engine.match(makeReq())).toBeUndefined();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe("moveToFront()", () => {
|
|
159
|
-
it("moves an existing rule to the front", () => {
|
|
160
|
-
engine.add("hello", "First");
|
|
161
|
-
const rule = engine.add("hello", "Second");
|
|
162
|
-
engine.moveToFront(rule);
|
|
163
|
-
const matched = engine.match(makeReq());
|
|
164
|
-
if (!matched) throw new Error("expected match");
|
|
165
|
-
expect(matched.resolve).toBe("Second");
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe("MatchObject with predicate", () => {
|
|
170
|
-
it("combines structured fields with a predicate function", () => {
|
|
171
|
-
engine.add(
|
|
172
|
-
{ model: "gpt-5.4", predicate: (req) => req.messages.length > 2 },
|
|
173
|
-
"Complex match",
|
|
174
|
-
);
|
|
175
|
-
expect(engine.match(makeReq({ model: "gpt-5.4" }))).toBeUndefined();
|
|
176
|
-
|
|
177
|
-
expect(
|
|
178
|
-
engine.match(
|
|
179
|
-
makeReq({
|
|
180
|
-
model: "gpt-5.4",
|
|
181
|
-
messages: [
|
|
182
|
-
{ role: "system", content: "sys" },
|
|
183
|
-
{ role: "user", content: "a" },
|
|
184
|
-
{ role: "assistant", content: "b" },
|
|
185
|
-
],
|
|
186
|
-
}),
|
|
187
|
-
),
|
|
188
|
-
).toBeDefined();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("predicate runs after other fields (short-circuits)", () => {
|
|
192
|
-
let called = false;
|
|
193
|
-
engine.add(
|
|
194
|
-
{
|
|
195
|
-
model: "claude",
|
|
196
|
-
predicate: () => {
|
|
197
|
-
called = true;
|
|
198
|
-
return true;
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
"Never reached",
|
|
202
|
-
);
|
|
203
|
-
engine.match(makeReq({ model: "gpt-5.4" }));
|
|
204
|
-
expect(called).toBe(false);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
describe("global/sticky regex safety", () => {
|
|
209
|
-
it("strips the g flag so test() is not stateful", () => {
|
|
210
|
-
engine.add(/hello/g, "Hi!");
|
|
211
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
212
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
213
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("strips the y flag so test() is not stateful", () => {
|
|
217
|
-
engine.add(/hello/y, "Hi!");
|
|
218
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
219
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it("strips g flag from regex inside a MatchObject", () => {
|
|
223
|
-
engine.add({ message: /hello/gi }, "Hi!");
|
|
224
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
225
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
226
|
-
expect(engine.match(makeReq())).toBeDefined();
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2025",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"lib": ["ES2025"],
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"rootDir": "./src",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"declarationMap": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"isolatedModules": true,
|
|
17
|
-
"noUncheckedIndexedAccess": true,
|
|
18
|
-
"noUnusedLocals": true,
|
|
19
|
-
"noUnusedParameters": true,
|
|
20
|
-
"exactOptionalPropertyTypes": true
|
|
21
|
-
},
|
|
22
|
-
"include": ["src/**/*"],
|
|
23
|
-
"exclude": ["node_modules", "dist", "test"]
|
|
24
|
-
}
|
package/tsconfig.test.json
DELETED
package/typedoc.json
DELETED
package/vitest.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vitest/config";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
globals: true,
|
|
6
|
-
testTimeout: 10_000,
|
|
7
|
-
coverage: {
|
|
8
|
-
provider: "v8",
|
|
9
|
-
include: ["src/**/*.ts"],
|
|
10
|
-
exclude: [
|
|
11
|
-
"src/cli.ts",
|
|
12
|
-
"src/types.ts",
|
|
13
|
-
"src/types/**",
|
|
14
|
-
"src/formats/types.ts",
|
|
15
|
-
],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
});
|