CallRecord
KIT · interface · 类型合同
Detached snapshot of one accepted call, exposed through MockGPT.records.
导入
ts
import type { CallRecord } from '@jangts/agent-core/mock';js
/** @typedef {import('@jangts/agent-core/mock').CallRecord} CallRecord */其他公开入口:@jangts/agent-core/mock。
定义
ts
interface CallRecord字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | Wire-visible completion id in the form chatcmpl-mock-<index>; reused by the HTTP codec. |
index | number | 必需 | 1-based call sequence within the instance; monotonically increasing until reset. |
model | string | 必需 | Model from the matched request. |
path | string | undefined | 可省略 | Request path when served through fetch; absent for generate calls. |
ruleId | string | undefined | 可省略 | Id of the matched rule; absent for fallback calls. |
fallback | boolean | 必需 | True when the fallback generator produced the reply. |
status | "error" | "cancelled" | "pending" | "completed" | 必需 | Terminal state; pending only while the call or its stream is still running. |
errorCode | string | undefined | 可省略 | MOCK_* code describing the failure or cancellation; absent on success. |
metadata | Record<string, JsonValue> | 必需 | Diagnostic key/values from context.report, capped at 8192 serialized bytes; no model content. |
使用示例
- MockGPT:直接生成与 Provider 注入:直接取得字符串或 JSON;需要检验模型通信时,将同一个实例注入 Provider。
直接生成原生 JSON
入门 · 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);同一实例注入真实 Core 模型边界
配置 · 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);