llm-mock-server 1.0.5 → 1.0.6
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/.github/workflows/docs.yml +1 -1
- package/README.md +1 -1
- package/package.json +12 -9
- package/src/cli/cli.ts +2 -2
- package/src/cli/validators.ts +1 -1
- package/src/formats/anthropic/index.ts +2 -2
- package/src/formats/anthropic/parse.ts +5 -2
- package/src/formats/anthropic/serialize.ts +3 -3
- package/src/formats/openai/chat-completions/index.ts +2 -2
- package/src/formats/openai/chat-completions/parse.ts +5 -2
- package/src/formats/openai/chat-completions/serialize.ts +3 -3
- package/src/formats/openai/responses/index.ts +2 -2
- package/src/formats/openai/responses/parse.ts +5 -2
- package/src/formats/openai/responses/serialize.ts +3 -7
- package/src/formats/request-helpers.ts +1 -1
- package/src/formats/serialize-helpers.ts +1 -1
- package/src/formats/types.ts +2 -2
- package/test/cli-validators.test.ts +1 -1
- package/test/history.test.ts +1 -1
- package/test/loader.test.ts +3 -3
- package/test/logger.test.ts +2 -2
- package/test/mock-server.test.ts +1 -1
- package/test/rule-engine.test.ts +1 -1
- package/tsconfig.json +2 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# llm-mock-server
|
|
1
|
+
# llm-mock-server [](https://www.npmjs.com/package/llm-mock-server) 
|
|
2
2
|
|
|
3
3
|
A mock LLM server for testing. It handles OpenAI `/chat/completions`, Anthropic `/messages`, and OpenAI `/responses` API formats, with both streaming (SSE) and non-streaming responses. Point any client at it and get instant, deterministic replies. Used by [xcode-copilot-server](https://github.com/theblixguy/xcode-copilot-server) and [copilot-sdk-proxy](https://github.com/theblixguy/copilot-sdk-proxy) for their integration tests.
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-mock-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A standalone mock LLM server for deterministic testing: OpenAI, Anthropic, and Responses API formats",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
|
+
"imports": {
|
|
19
|
+
"#/*": "./src/*"
|
|
20
|
+
},
|
|
18
21
|
"bin": {
|
|
19
22
|
"llm-mock-server": "./dist/cli/cli.js"
|
|
20
23
|
},
|
|
@@ -43,21 +46,21 @@
|
|
|
43
46
|
"license": "MIT",
|
|
44
47
|
"dependencies": {
|
|
45
48
|
"commander": "14.0.3",
|
|
46
|
-
"fastify": "5.8.
|
|
49
|
+
"fastify": "5.8.4",
|
|
47
50
|
"json5": "2.2.3",
|
|
48
|
-
"llm-schemas": "1.0.
|
|
51
|
+
"llm-schemas": "1.0.2",
|
|
49
52
|
"picocolors": "1.1.1",
|
|
50
53
|
"zod": "4.3.6"
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|
|
53
56
|
"@types/node": "25.5.0",
|
|
54
|
-
"@vitest/coverage-v8": "4.1.
|
|
55
|
-
"oxfmt": "0.
|
|
56
|
-
"oxlint": "1.
|
|
57
|
+
"@vitest/coverage-v8": "4.1.2",
|
|
58
|
+
"oxfmt": "0.42.0",
|
|
59
|
+
"oxlint": "1.57.0",
|
|
57
60
|
"tsx": "4.21.0",
|
|
58
|
-
"typedoc": "0.28.
|
|
61
|
+
"typedoc": "0.28.18",
|
|
59
62
|
"typedoc-theme-oxide": "0.2.5",
|
|
60
|
-
"typescript": "
|
|
61
|
-
"vitest": "4.1.
|
|
63
|
+
"typescript": "6.0.2",
|
|
64
|
+
"vitest": "4.1.2"
|
|
62
65
|
}
|
|
63
66
|
}
|
package/src/cli/cli.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { watch } from "node:fs";
|
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import pc from "picocolors";
|
|
7
|
-
import { MockServer } from "
|
|
8
|
-
import { Logger } from "
|
|
7
|
+
import { MockServer } from "#/mock-server.js";
|
|
8
|
+
import { Logger } from "#/logger.js";
|
|
9
9
|
import {
|
|
10
10
|
parsePort,
|
|
11
11
|
parseHost,
|
package/src/cli/validators.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isIP } from "node:net";
|
|
2
2
|
import { lookup } from "node:dns/promises";
|
|
3
|
-
import { LEVEL_PRIORITY, type LogLevel } from "
|
|
3
|
+
import { LEVEL_PRIORITY, type LogLevel } from "#/logger.js";
|
|
4
4
|
|
|
5
5
|
const VALID_LOG_LEVELS: string[] = Object.keys(LEVEL_PRIORITY);
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Format } from "
|
|
2
|
-
import { isStreaming } from "
|
|
1
|
+
import type { Format } from "#/formats/types.js";
|
|
2
|
+
import { isStreaming } from "#/formats/request-helpers.js";
|
|
3
3
|
import { parseRequest } from "./parse.js";
|
|
4
4
|
import { serialize, serializeComplete, serializeError } from "./serialize.js";
|
|
5
5
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { MockRequest, Message, ToolDef } from "
|
|
2
|
-
import {
|
|
1
|
+
import type { MockRequest, Message, ToolDef } from "#/types/request.js";
|
|
2
|
+
import {
|
|
3
|
+
buildMockRequest,
|
|
4
|
+
type RequestMeta,
|
|
5
|
+
} from "#/formats/request-helpers.js";
|
|
3
6
|
import { AnthropicRequestSchema, type AnthropicRequest } from "./schema.js";
|
|
4
7
|
|
|
5
8
|
function extractSystem(system: AnthropicRequest["system"]): Message[] {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ReplyObject, ReplyOptions } from "
|
|
2
|
-
import type { SSEChunk } from "
|
|
1
|
+
import type { ReplyObject, ReplyOptions } from "#/types/reply.js";
|
|
2
|
+
import type { SSEChunk } from "#/formats/types.js";
|
|
3
3
|
import {
|
|
4
4
|
splitText,
|
|
5
5
|
genId,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
shouldEmitText,
|
|
8
8
|
finishReason,
|
|
9
9
|
DEFAULT_USAGE,
|
|
10
|
-
} from "
|
|
10
|
+
} from "#/formats/serialize-helpers.js";
|
|
11
11
|
|
|
12
12
|
function buildUsage(usage: { input: number; output: number }) {
|
|
13
13
|
return { input_tokens: usage.input, output_tokens: usage.output };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Format } from "
|
|
2
|
-
import { isStreaming } from "
|
|
1
|
+
import type { Format } from "#/formats/types.js";
|
|
2
|
+
import { isStreaming } from "#/formats/request-helpers.js";
|
|
3
3
|
import { parseRequest } from "./parse.js";
|
|
4
4
|
import { serialize, serializeComplete, serializeError } from "./serialize.js";
|
|
5
5
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { MockRequest, Message, ToolDef } from "
|
|
2
|
-
import {
|
|
1
|
+
import type { MockRequest, Message, ToolDef } from "#/types/request.js";
|
|
2
|
+
import {
|
|
3
|
+
buildMockRequest,
|
|
4
|
+
type RequestMeta,
|
|
5
|
+
} from "#/formats/request-helpers.js";
|
|
3
6
|
import { OpenAIRequestSchema, type OpenAIRequest } from "./schema.js";
|
|
4
7
|
|
|
5
8
|
function extractContent(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ReplyObject, ReplyOptions } from "
|
|
2
|
-
import type { SSEChunk } from "
|
|
1
|
+
import type { ReplyObject, ReplyOptions } from "#/types/reply.js";
|
|
2
|
+
import type { SSEChunk } from "#/formats/types.js";
|
|
3
3
|
import {
|
|
4
4
|
splitText,
|
|
5
5
|
genId,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
finishReason,
|
|
8
8
|
MS_PER_SECOND,
|
|
9
9
|
DEFAULT_USAGE,
|
|
10
|
-
} from "
|
|
10
|
+
} from "#/formats/serialize-helpers.js";
|
|
11
11
|
|
|
12
12
|
function buildUsage(usage: { input: number; output: number }) {
|
|
13
13
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Format } from "
|
|
2
|
-
import { isStreaming } from "
|
|
1
|
+
import type { Format } from "#/formats/types.js";
|
|
2
|
+
import { isStreaming } from "#/formats/request-helpers.js";
|
|
3
3
|
import { parseRequest } from "./parse.js";
|
|
4
4
|
import { serialize, serializeComplete, serializeError } from "./serialize.js";
|
|
5
5
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { MockRequest, Message, ToolDef } from "
|
|
2
|
-
import {
|
|
1
|
+
import type { MockRequest, Message, ToolDef } from "#/types/request.js";
|
|
2
|
+
import {
|
|
3
|
+
buildMockRequest,
|
|
4
|
+
type RequestMeta,
|
|
5
|
+
} from "#/formats/request-helpers.js";
|
|
3
6
|
import {
|
|
4
7
|
ResponsesRequestSchema,
|
|
5
8
|
FunctionToolSchema,
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
ReplyOptions,
|
|
4
|
-
ToolCall,
|
|
5
|
-
} from "../../../types/reply.js";
|
|
6
|
-
import type { SSEChunk } from "../../types.js";
|
|
1
|
+
import type { ReplyObject, ReplyOptions, ToolCall } from "#/types/reply.js";
|
|
2
|
+
import type { SSEChunk } from "#/formats/types.js";
|
|
7
3
|
import {
|
|
8
4
|
splitText,
|
|
9
5
|
genId,
|
|
@@ -11,7 +7,7 @@ import {
|
|
|
11
7
|
shouldEmitText,
|
|
12
8
|
MS_PER_SECOND,
|
|
13
9
|
DEFAULT_USAGE,
|
|
14
|
-
} from "
|
|
10
|
+
} from "#/formats/serialize-helpers.js";
|
|
15
11
|
|
|
16
12
|
function buildUsage(usage: { input: number; output: number }) {
|
|
17
13
|
return {
|
package/src/formats/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FormatName, MockRequest } from "
|
|
2
|
-
import type { ReplyObject, ReplyOptions } from "
|
|
1
|
+
import type { FormatName, MockRequest } from "#/types/request.js";
|
|
2
|
+
import type { ReplyObject, ReplyOptions } from "#/types/reply.js";
|
|
3
3
|
import type { RequestMeta } from "./request-helpers.js";
|
|
4
4
|
|
|
5
5
|
export interface SSEChunk {
|
package/test/history.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
-
import { RequestHistory, type RecordedRequest } from "
|
|
2
|
+
import { RequestHistory, type RecordedRequest } from "#/history.js";
|
|
3
3
|
import { makeReq } from "./helpers/make-req.js";
|
|
4
4
|
|
|
5
5
|
describe("RequestHistory", () => {
|
package/test/loader.test.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
2
|
import { writeFile, mkdir, rm } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { RuleEngine } from "
|
|
5
|
-
import { loadRulesFromPath } from "
|
|
6
|
-
import type { MockRequest } from "
|
|
4
|
+
import { RuleEngine } from "#/rule-engine.js";
|
|
5
|
+
import { loadRulesFromPath } from "#/loader.js";
|
|
6
|
+
import type { MockRequest } from "#/types.js";
|
|
7
7
|
import { makeReq } from "./helpers/make-req.js";
|
|
8
8
|
|
|
9
9
|
const tmpDir = join(import.meta.dirname, ".tmp-loader-test");
|
package/test/logger.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
|
-
import { Logger, LEVEL_PRIORITY } from "
|
|
3
|
-
import type { LogLevel } from "
|
|
2
|
+
import { Logger, LEVEL_PRIORITY } from "#/logger.js";
|
|
3
|
+
import type { LogLevel } from "#/logger.js";
|
|
4
4
|
|
|
5
5
|
afterEach(() => {
|
|
6
6
|
vi.restoreAllMocks();
|
package/test/mock-server.test.ts
CHANGED
package/test/rule-engine.test.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2025",
|
|
4
4
|
"module": "NodeNext",
|
|
5
5
|
"moduleResolution": "NodeNext",
|
|
6
|
-
"lib": ["
|
|
6
|
+
"lib": ["ES2025"],
|
|
7
7
|
"outDir": "./dist",
|
|
8
8
|
"rootDir": "./src",
|
|
9
9
|
"declaration": true,
|
|
10
10
|
"declarationMap": true,
|
|
11
11
|
"sourceMap": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
12
|
"skipLibCheck": true,
|
|
15
13
|
"forceConsistentCasingInFileNames": true,
|
|
16
14
|
"verbatimModuleSyntax": true,
|