generators
KIT · constant · Runtime value
Import
import { generators } from '@jangts/agent-core/mock';import { generators } from '@jangts/agent-core/mock';Other public entry points:@jangts/agent-core/mock.
Definition
Member index
| Member | Purpose |
|---|---|
summary | Extractive summary, one paragraph, at most maxChars (default 240) characters. |
bullets | Same selection as summary, rendered as - bullet lines (default budget 500). |
keywords | Most frequent non-stopword terms, most frequent first. |
title | First sentence of the source with leading Markdown heading marks removed. |
reply | Short conversational answer that echoes the topic. Continuation prompts ("继续", "换个说法") reuse the previous user message so a demo conversation stays coherent without a model. |
extract | Extract the first match of each configured pattern into a JSON object. A capture group is preferred over the whole match, so id:(\d+) yields just the digits. A field with no match is null rather than omitted, keeping the output shape stable. |
integer | Uniform integer in an inclusive range. |
float | Continuous value in [min, max), or exactly min when both bounds are equal. |
boolean | Fair coin derived from the call PRNG. |
pick | Uniform choice from a fixed pool. The pool is copied at construction and each result is copied again, so a consumer mutating a returned object cannot corrupt later selections. |
id | Identifier that includes the call index plus a random suffix. The suffix is 32 random bits rendered in hex; it is a fixture value, not a UUID and not guaranteed unique or unguessable. |
date | ISO-8601 timestamp read from the injected clock. With a fixed clock option the value is constant, which keeps snapshot-style tests stable. |
sentence | One of three fixed Chinese sample sentences. The sentences are placeholders that read naturally in demos; selection still consumes the per-call PRNG so the value changes with the seed. |
imageUrl | Inline SVG data URL, so no network or filesystem access is needed. |
sequence | Play a fixed list one item per accepted call. Selection is driven by context.ruleIndex (1-based), so it advances with the rule's own hit count and is unaffected by other rules or by concurrent calls. |
toolCall | Shorthand for a reply that only emits one tool call. |
Member details
summary
Extractive summary, one paragraph, at most maxChars (default 240) characters.
generators.summary(options?: TextOptions): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
options | TextOptions | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
source | TextSource | undefined | Optional | Explicit text or async provider; defaults to the request prompt. |
maxChars | number | undefined | Optional | Maximum characters in the returned text (1-30 000); generator-specific default. |
count | number | undefined | Optional | How many items to select (1-100), e.g. bullets, keywords or summary sentences. |
Returns: Generator.
bullets
Same selection as summary, rendered as - bullet lines (default budget 500).
generators.bullets(options?: TextOptions): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
options | TextOptions | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
source | TextSource | undefined | Optional | Explicit text or async provider; defaults to the request prompt. |
maxChars | number | undefined | Optional | Maximum characters in the returned text (1-30 000); generator-specific default. |
count | number | undefined | Optional | How many items to select (1-100), e.g. bullets, keywords or summary sentences. |
Returns: Generator.
keywords
Most frequent non-stopword terms, most frequent first.
generators.keywords(options?: TextOptions): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
options | TextOptions | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
source | TextSource | undefined | Optional | Explicit text or async provider; defaults to the request prompt. |
maxChars | number | undefined | Optional | Maximum characters in the returned text (1-30 000); generator-specific default. |
count | number | undefined | Optional | How many items to select (1-100), e.g. bullets, keywords or summary sentences. |
Returns: Generator.
title
First sentence of the source with leading Markdown heading marks removed.
generators.title(options?: TextOptions): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
options | TextOptions | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
source | TextSource | undefined | Optional | Explicit text or async provider; defaults to the request prompt. |
maxChars | number | undefined | Optional | Maximum characters in the returned text (1-30 000); generator-specific default. |
count | number | undefined | Optional | How many items to select (1-100), e.g. bullets, keywords or summary sentences. |
Returns: Generator.
reply
Short conversational answer that echoes the topic.
Continuation prompts ("继续", "换个说法") reuse the previous user message so a demo conversation stays coherent without a model.
generators.reply(options?: TextOptions & { template?: (input: { text: string; previous: string; }) => string; }): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
options | TextOptions & { template?: (input: { text: string; previous: string; }) => string; } | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
source | TextSource | undefined | Optional | Explicit text or async provider; defaults to the request prompt. |
maxChars | number | undefined | Optional | Maximum characters in the returned text (1-30 000); generator-specific default. |
count | number | undefined | Optional | How many items to select (1-100), e.g. bullets, keywords or summary sentences. |
template | ((input: { text: string; previous: string; }) => string) | undefined | Optional | See the type definition and usage context. |
Returns: Generator.
extract
Extract the first match of each configured pattern into a JSON object.
A capture group is preferred over the whole match, so id:(\d+) yields just the digits. A field with no match is null rather than omitted, keeping the output shape stable.
generators.extract(options?: TextOptions & { fields?: Record<string, RegExp>; }): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
options | TextOptions & { fields?: Record<string, RegExp>; } | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
source | TextSource | undefined | Optional | Explicit text or async provider; defaults to the request prompt. |
maxChars | number | undefined | Optional | Maximum characters in the returned text (1-30 000); generator-specific default. |
count | number | undefined | Optional | How many items to select (1-100), e.g. bullets, keywords or summary sentences. |
fields | Record<string, RegExp> | undefined | Optional | See the type definition and usage context. |
Returns: Generator.
integer
Uniform integer in an inclusive range.
generators.integer(min?: number, max?: number): ValueGenerator<number>| Parameter | Type | Passing | Description |
|---|---|---|---|
min | number | Optional | — |
max | number | Optional | — |
Returns: ValueGenerator<number>.
float
Continuous value in [min, max), or exactly min when both bounds are equal.
generators.float(min?: number, max?: number): ValueGenerator<number>| Parameter | Type | Passing | Description |
|---|---|---|---|
min | number | Optional | — |
max | number | Optional | — |
Returns: ValueGenerator<number>.
boolean
Fair coin derived from the call PRNG.
generators.boolean(): ValueGenerator<boolean>No call parameters.
Returns: ValueGenerator<boolean>.
pick
Uniform choice from a fixed pool.
The pool is copied at construction and each result is copied again, so a consumer mutating a returned object cannot corrupt later selections.
generators.pick<T extends JsonValue>(items: readonly T[]): ValueGenerator<T>| Type parameter | Constraint | Default type |
|---|---|---|
T | JsonValue | — |
| Parameter | Type | Passing | Description |
|---|---|---|---|
items | readonly T[] | Required | — |
Returns: ValueGenerator<T>.
id
Identifier that includes the call index plus a random suffix.
The suffix is 32 random bits rendered in hex; it is a fixture value, not a UUID and not guaranteed unique or unguessable.
generators.id(prefix?: string): ValueGenerator<string>| Parameter | Type | Passing | Description |
|---|---|---|---|
prefix | string | Optional | — |
Returns: ValueGenerator<string>.
date
ISO-8601 timestamp read from the injected clock.
With a fixed clock option the value is constant, which keeps snapshot-style tests stable.
generators.date(): ValueGenerator<string>No call parameters.
Returns: ValueGenerator<string>.
sentence
One of three fixed Chinese sample sentences.
The sentences are placeholders that read naturally in demos; selection still consumes the per-call PRNG so the value changes with the seed.
generators.sentence(): ValueGenerator<string>No call parameters.
Returns: ValueGenerator<string>.
imageUrl
Inline SVG data URL, so no network or filesystem access is needed.
generators.imageUrl({ width, height, }?: { width?: number; height?: number; }): ValueGenerator<string>| Parameter | Type | Passing | Description |
|---|---|---|---|
__0 | { width?: number; height?: number; } | Optional | — |
Fields of __0
| Field | Type | Required | Description |
|---|---|---|---|
width | number | undefined | Optional | See the type definition and usage context. |
height | number | undefined | Optional | See the type definition and usage context. |
Returns: ValueGenerator<string>.
sequence
Play a fixed list one item per accepted call.
Selection is driven by context.ruleIndex (1-based), so it advances with the rule's own hit count and is unaffected by other rules or by concurrent calls.
generators.sequence(items: readonly Generator[]): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
items | readonly Generator[] | Required | — |
Returns: Generator.
toolCall
Shorthand for a reply that only emits one tool call.
generators.toolCall(name: string, args: JsonValue, options?: OutputOptions): Generator| Parameter | Type | Passing | Description |
|---|---|---|---|
name | string | Required | — |
args | JsonValue | Required | — |
options | OutputOptions | Optional | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
finishReason | "length" | "tool_calls" | "stop" | "content_filter" | undefined | Optional | Finish reason sent in the last content frame; defaults to tool_calls with tools, else stop. |
usage | Usage | undefined | Optional | Usage object included in non-stream replies and in the terminal usage chunk. |
delayMs | number | undefined | Optional | Artificial latency before the reply or first frame, in milliseconds; default 0. |
chunkSize | number | undefined | Optional | Maximum Unicode code points per content/tool-call delta; default 24; never splits a code point. |
intervalMs | number | undefined | Optional | Delay between SSE frames in milliseconds; default 0 (emit as fast as the consumer pulls). |
wireChunkSize | number | undefined | Optional | Optional transport-level byte chunks, independent of content/codepoint chunks. |
interruptAfter | number | undefined | Optional | Error the stream after this many data frames, without a success terminator. |
Returns: Generator.
Examples
- 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.
Encode a validated model result
Extension · Node.js
The adapter handles request validation, pre-first-byte delay, and lifecycle; the encoder does not execute rules or modify MockGPT call records.
import { encodeModelResponse } from '@jangts/agent-core/mock';
const controller = new AbortController();
const response = encodeModelResponse(
{ model: 'demo', messages: [{ role: 'user', content: '状态' }], stream: false },
{ content: '服务在线。' }, 'mock-1', 1700000000, controller.signal,
(error, cancelled) => console.log({ error, cancelled }),
);
console.log(await response.json());import { encodeModelResponse } from '@jangts/agent-core/mock';
const controller = new AbortController();
const response = encodeModelResponse({ model: 'demo', messages: [{ role: 'user', content: '状态' }], stream: false }, { content: '服务在线。' }, 'mock-1', 1700000000, controller.signal, (error, cancelled) => console.log({ error, cancelled }));
console.log(await response.json());Generate an inspectable summary from the input
Beginner · Node.js
import { MockGPT, generators } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ generator: generators.summary({ maxChars: 120, count: 2 }) }] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '服务刚完成维护。健康检查通过。用户可以查询状态。' }] }));
console.log(mock.records);import { MockGPT, generators } from '@jangts/agent-core/mock';
const mock = new MockGPT({ rules: [{ generator: generators.summary({ maxChars: 120, count: 2 }) }] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '服务刚完成维护。健康检查通过。用户可以查询状态。' }] }));
console.log(mock.records);Reuse the same random source across field generators
Configuration · Node.js
import { MockGPT, generators, generatorNames } from '@jangts/agent-core/mock';
const id = generators.id('user');
const age = generators.integer(18, 60);
const mock = new MockGPT({ seed: 42, clock: () => 1700000000000, rules: [{
generator: context => ({ id: id(context), age: age(context) }),
}] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '生成资料' }] }));
console.log(generatorNames);import { MockGPT, generators, generatorNames } from '@jangts/agent-core/mock';
const id = generators.id('user');
const age = generators.integer(18, 60);
const mock = new MockGPT({ seed: 42, clock: () => 1700000000000, rules: [{
generator: context => ({ id: id(context), age: age(context) }),
}] });
console.log(await mock.generate({ model: 'demo', messages: [{ role: 'user', content: '生成资料' }] }));
console.log(generatorNames);