MockGPTError
KIT · class · Runtime value
Error type carrying a stable machine-readable code plus optional HTTP status and details.
The HTTP adapter maps status onto the response and serializes code/details into the OpenAI-style error body, so codes are part of the public contract.
Import
ts
import { MockGPTError } from '@jangts/agent-core/mock';js
import { MockGPTError } from '@jangts/agent-core/mock';Other public entry points:@jangts/agent-core/mock.
Definition
ts
class MockGPTErrorExtends or implements: Error.
Constructor
ts
new MockGPTError(code: string, message: string, status?: number, details?: Record<string, JsonValue> | undefined): MockGPTError| Parameter | Type | Passing | Description |
|---|---|---|---|
code | string | Required | — |
message | string | Required | — |
status | number | Optional | — |
details | Record<string, JsonValue> | undefined | Optional | — |
Returns: MockGPTError.
Instance properties
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Required | Read-only. See the type definition and usage context. |
status | number | Required | Read-only. See the type definition and usage context. |
details | Record<string, JsonValue> | undefined | Optional | Read-only. See the type definition and usage context. |
Member index
| Member | Purpose |
|---|---|
[Symbol.hasInstance] | Static. See the overload below for full inputs and outputs. |
Member details
[Symbol.hasInstance]
Static member.
ts
MockGPTError[Symbol.hasInstance](value: unknown): boolean| Parameter | Type | Passing | Description |
|---|---|---|---|
value | unknown | Required | — |
Returns: boolean.
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);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);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);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);