MockGPTOptions
KIT · interface · Type contract
Construction options of a MockGPT instance.
Import
ts
import type { MockGPTOptions } from '@jangts/agent-core/mock';1
js
/** @typedef {import('@jangts/agent-core/mock').MockGPTOptions} MockGPTOptions */1
Other public entry points:@jangts/agent-core/mock.
Definition
ts
interface MockGPTOptions1
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
rules | readonly Rule[] | Required | Ordered rules; the first rule whose filters all pass wins, so order is significant. |
fallback | Generator | undefined | Optional | Generator used when no rule matches; absent makes an unmatched call a MOCK_RULE_NOT_FOUND error. |
selectPrompt | ((request: ModelRequest) => string) | undefined | Optional | Overrides prompt extraction; must return a string synchronously; default is the last user text. |
stream | Pick<OutputOptions, "chunkSize" | "intervalMs" | "wireChunkSize"> | undefined | Optional | Defaults merged under every generated output; explicit output fields take precedence. |
seed | number | undefined | Optional | Seed for the deterministic PRNG (0-0xffffffff); default 1, so identical call sequences repeat. |
clock | (() => number) | undefined | Optional | Millisecond timestamp source for date generators and response created; must be finite. |
recordLimit | number | undefined | Optional | Ring-buffer size of records; 0 disables recording; max 10 000; default 100. |
maxBodyBytes | number | undefined | Optional | Maximum accepted request body in bytes for fetch; default 1 MiB. |
maxOutputChars | number | undefined | Optional | Maximum generated content in code points plus serialized tool calls; default 1 000 000. |
Examples
- MockGPT: direct generation and Provider injection: Get a string or JSON directly; inject the same instance into a Provider when you need to exercise model communication.
Generate native JSON directly
Beginner · Node.js
ts
import { MockGPT } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: { online: true, source: 'fixture' } }] });
const value = await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '服务状态' }] });
console.log(value); // { online: true, source: 'fixture' }
console.log(mock.counts, mock.records);1
2
3
4
5
2
3
4
5
js
import { MockGPT } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: { online: true, source: 'fixture' } }] });
const value = await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '服务状态' }] });
console.log(value); // { online: true, source: 'fixture' }
console.log(mock.counts, mock.records);1
2
3
4
5
2
3
4
5
Inject the same instance into the real Core model boundary
Configuration · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
import { MockGPT, responses } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: responses.text('服务在线。', { chunkSize: 2, wireChunkSize: 3 }) }] });
const provider = new Support.CompatibleModelProvider({
config: { baseUrl: 'https://mock.local/v1', apiKey: 'offline-example', model: 'demo' },
ports: { request: mock.fetch },
});
const result = await new ModelRunner({ provider, maxCalls: 1 }).invoke('服务状态');
console.log(result.value, result.invocation.status);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { ModelRunner, Support } from '@jangts/agent-core';
import { MockGPT, responses } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ prompt: '服务状态', generator: responses.text('服务在线。', { chunkSize: 2, wireChunkSize: 3 }) }] });
const provider = new Support.CompatibleModelProvider({
config: { baseUrl: 'https://mock.local/v1', apiKey: 'offline-example', model: 'demo' },
ports: { request: mock.fetch },
});
const result = await new ModelRunner({ provider, maxCalls: 1 }).invoke('服务状态');
console.log(result.value, result.invocation.status);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9