Skip to content
中文

PreparedModelCall ​

CORE · interface · Type contract

Request-bound, single-use transport snapshot.

Repeated measurements do not prepare or spend calls.

Import ​

ts
import type { PreparedModelCall } from '@jangts/agent-core/model';
js
/** @typedef {import('@jangts/agent-core/model').PreparedModelCall} PreparedModelCall */

Other public entry points:@jangts/agent-core, @jangts/agent-core/model, @jangts/agent-core/types, @jangts/agent-core/structs.

Definition ​

ts
interface PreparedModelCall<Result>

Extends or implements: PreparedModelTransport<Result>.

Type parameters ​

Type parameterConstraintDefault type
Result—unknown

Field structure ​

FieldTypeRequiredDescription
modelIdstring | undefinedOptionalRead-only. Model binding the call was prepared with.
stageIdstringRequiredRead-only. See the type definition and usage context.
transportIdstringRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumberRequiredRead-only. See the type definition and usage context.
remainingCallsnumberRequiredRead-only. Calls still available; a live value, so later spends are visible.
measure(input: string | readonly ModelMessage[] | BuiltContext) => ModelInputMeasurementRequiredPreflight measurement of one input shape. Never marks the call used and never charges the budget.
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls" | "temperature">RequiredRead-only. See the type definition and usage context.
schemaCharsnumberRequiredRead-only. See the type definition and usage context.
instructionstring | undefinedOptionalRead-only. See the type definition and usage context.
createResponse() => ModelResponseCollector<Result>RequiredSee the type definition and usage context.

Member index ​

MemberPurpose
measurePreflight measurement of one input shape. Never marks the call used and never charges the budget.
createResponseSee the overload below for full inputs and outputs.

Member details ​

measure ​

Preflight measurement of one input shape.

Never marks the call used and never charges the budget.

ts
PreparedModelCall.measure(input: string | readonly ModelMessage[] | BuiltContext): ModelInputMeasurement

Preflight measurement of one input shape.

Never marks the call used and never charges the budget.

ParameterTypePassingDescription
inputstring | readonly ModelMessage[] | BuiltContextRequired—

Optional shapes of Parameter input: choose one shape; required fields for each branch are listed separately.

Branch 1

string

Branch 2

readonly ModelMessage[]

Branch 3
FieldTypeRequiredDescription
messagesModelMessage[]RequiredMessages in final model order.
fragmentUsageContextFragmentUsage[]RequiredPer-fragment accounting in the same order as the fragments were merged.
inputCharsnumberRequiredTotal counted characters across messages and usage.
maxInputCharsnumberRequiredBudget the assembly was validated against; Infinity means unbounded.

Returns: ModelInputMeasurement.

Return value structure
FieldTypeRequiredDescription
messageCharsnumberRequiredRead-only. Characters of the message content.
instructionCharsnumberRequiredRead-only. Characters of the instruction text.
schemaCharsnumberRequiredRead-only. Characters of the compiled capability schemas.
transportCharsnumberRequiredRead-only. Characters the transport itself contributes (for example framing).
inputCharsnumberRequiredRead-only. Sum of the character components above.
maxInputCharsnumberRequiredRead-only. Character budget the input was compared against.
maxSchemaCharsnumberRequiredRead-only. Schema budget the input was compared against.
maxOutputTokensnumberRequiredRead-only. Output tokens reserved for this call, which reduces the token input ceiling.
counterIdstring | undefinedOptionalRead-only. Tokenizer identity; present only when a token budget applies.
inputTokensnumber | undefinedOptionalRead-only. Measured input tokens.
inputTokenLimitnumber | undefinedOptionalRead-only. Token ceiling after reserving output and the safety margin.
withinBudgetbooleanRequiredRead-only. True when every applicable character and token budget accepted the input.

createResponse ​

ts
PreparedModelCall.createResponse(): ModelResponseCollector<Result>

No call parameters.

Returns: ModelResponseCollector<Result>.

Return value structure
FieldTypeRequiredDescription
call{ id: string; name: string; argumentChars: number; } | undefinedOptionalRead-only. Native function call that carried the selection, when the response used one.
callsreadonly { id: string; name: string; argumentChars: number; toolId?: string; }[] | undefinedOptionalRead-only. All native calls carried by a session response; omitted by single-selection collectors.
outputCharsnumberRequiredRead-only. Output characters accumulated so far, for output-budget accounting.
push(part: ModelPart) => voidRequiredAppends one streamed part; parts arrive in provider order.
finish() => ResultRequiredFinalizes the response. Throws when the accumulated content is not a valid selection.

Examples ​

Ordinary calls still only use invoke ​

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 });
console.log((await runner.invoke('你好')).value);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const runner = new ModelRunner({ provider });
console.log((await runner.invoke('你好')).value);

Prepare once only when measurement is needed ​

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, maxInputChars: 1000 });
const prepared = runner.prepare({ stageId: 'reply', maxOutputTokens: 400 });
const input = '你好,解释这次服务状态';
console.log(prepared.measure(input));
const result = await runner.invoke({ input, prepared });
console.log(result.value);
js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = {
    async *stream(messages) {
        yield '收到:' + messages.at(-1).content;
    },
};
const runner = new ModelRunner({ provider, maxInputChars: 1000 });
const prepared = runner.prepare({ stageId: 'reply', maxOutputTokens: 400 });
const input = '你好,解释这次服务状态';
console.log(prepared.measure(input));
const result = await runner.invoke({ input, prepared });
console.log(result.value);

API reference, usage examples and developer guides.