CallRecord
KIT · interface · Type contract
Detached snapshot of one accepted call, exposed through MockGPT.records.
Import
ts
import type { CallRecord } from '@jangts/agent-core/mock';js
/** @typedef {import('@jangts/agent-core/mock').CallRecord} CallRecord */Other public entry points:@jangts/agent-core/mock.
Definition
ts
interface CallRecordField structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Wire-visible completion id in the form chatcmpl-mock-<index>; reused by the HTTP codec. |
index | number | Required | 1-based call sequence within the instance; monotonically increasing until reset. |
model | string | Required | Model from the matched request. |
path | string | undefined | Optional | Request path when served through fetch; absent for generate calls. |
ruleId | string | undefined | Optional | Id of the matched rule; absent for fallback calls. |
fallback | boolean | Required | True when the fallback generator produced the reply. |
status | "error" | "cancelled" | "pending" | "completed" | Required | Terminal state; pending only while the call or its stream is still running. |
errorCode | string | undefined | Optional | MOCK_* code describing the failure or cancellation; absent on success. |
metadata | Record<string, JsonValue> | Required | Diagnostic key/values from context.report, capped at 8192 serialized bytes; no model content. |
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);