ModelRunnerPorts
CORE · interface · Type contract
Host ports a model runner needs in addition to its provider and transports.
Import
ts
import type { ModelRunnerPorts } from '@jangts/agent-core/model';js
/** @typedef {import('@jangts/agent-core/model').ModelRunnerPorts} ModelRunnerPorts */Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs.
Definition
ts
interface ModelRunnerPortsField structure
| Field | Type | Required | Description |
|---|---|---|---|
onOutput | ((event: ModelOutputEvent) => void | Promise<void>) | undefined | Optional | Ordered delivery of model events; awaits each call before continuing. |
transports | readonly ModelTransportDefinition<unknown>[] | undefined | Optional | Transports available by id and instance. |
diagnostics | DiagnosticContext | undefined | Optional | See the type definition and usage context. |
maxSchemaChars | number | undefined | Optional | Separate allowance for registered schemas; existing context budgets keep their meaning. |
tokenBudget | ModelTokenBudget | undefined | Optional | See the type definition and usage context. |
inputBudgetError | ((limit: number) => Error) | undefined | Optional | Builds the error for an input that exceeds the character or token limit. |
outputBudgetError | (() => Error) | undefined | Optional | Builds the error for output that exceeds the character limit. |
Examples
- ModelRunner: input can be shortened while the output contract stays the same: Execute one model interaction through the real Provider port and return a value plus the invocation for this call.
Two inputs for the same output
Beginner · Node.js
ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const runner = new ModelRunner({ provider });
const first = await runner.invoke('你好');
const second = await runner.invoke({ input: '你好' });
console.log(first.value, second.value);
console.log(first.invocation.invocationId);Add budget and request cancellation
Configuration · Node.js
ts
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages: readonly { content: string }[]) {
yield '收到:' + messages.at(-1)!.content;
},
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
maxOutputChars: 2000, callTimeoutMs: 15000,
execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
async *stream(messages) {
yield '收到:' + messages.at(-1).content;
},
};
const runner = new ModelRunner({ provider, maxCalls: 2, maxInputChars: 4000,
maxOutputChars: 2000, callTimeoutMs: 15000,
execution: { signal: AbortSignal.timeout(20000) },
});
const result = await runner.invoke({ input: '你好', stageId: 'reply', maxOutputTokens: 600 });
console.log(result.value, runner.remainingCalls);