Message
KIT · type · Type contract
One entry of an OpenAI chat conversation.
The runtime validates role against the OpenAI role set and validates the outer shape of content; every other field is retained verbatim so vendor extensions flow through.
Import
ts
import type { Message } from '@jangts/agent-core/mock';1
js
/** @typedef {import('@jangts/agent-core/mock').Message} Message */1
Other public entry points:@jangts/agent-core/mock.
Definition
Type: Message
Type expression
ts
type Message = Readonly<{
/**
* `system`, `developer`, `user`, `assistant`, `tool` or `function`; anything else is rejected.
*/
role: string;
/** Text, a multimodal content-block array or null; numbers and objects are rejected. */
content?: unknown;
/** Opaque tool-call array from a previous assistant turn; never interpreted here. */
tool_calls?: unknown;
/** Correlates a `tool` message with the assistant tool call it answers. */
tool_call_id?: string;
/** Vendor extensions are snapshotted and preserved but never interpreted by the runtime. */
[key: string]: unknown;
}>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Required | system, developer, user, assistant, tool or function; anything else is rejected. |
content | unknown | Optional | Text, a multimodal content-block array or null; numbers and objects are rejected. |
tool_calls | unknown | Optional | Opaque tool-call array from a previous assistant turn; never interpreted here. |
tool_call_id | string | undefined | Optional | Correlates a tool message with the assistant tool call it answers. |
Index structure
| Field | Type | Required | Description |
|---|---|---|---|
[key: string] | unknown | Required | Read-only. Index entry. |
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.
- MockGPT: response descriptions and scenario generators: Fixed results serve strict regression, input-dependent generators explore wiring, and explicit response descriptions cover failure and streaming scenarios.
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