Skip to content
中文

ModelOutputEvent ​

CORE · type · Type contract

Delivery sink, awaited in order. Parts are unvalidated proposals, never execution receipts.

Import ​

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

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

Definition ​

Type: ModelOutputEvent

Type expression
ts
type ModelOutputEvent = Extract<
  import('../execution/events.js').CoreEvent,
  { type: 'model.start' | 'model.output' | 'model.parsed' | 'model.end' }
>;

Union branch structure ​

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

Branch 1
FieldTypeRequiredDescription
runIdstringRequiredRead-only. Root run id shared by every fact of one logical run.
spanIdstringRequiredRead-only. Span that produced the fact.
parentSpanIdstring | undefinedOptionalRead-only. Enclosing span; absent for a root span.
invocationIdstring | undefinedOptionalRead-only. Invocation that produced the fact, when the fact belongs to one.
parentInvocationIdstring | undefinedOptionalRead-only. Enclosing invocation, when one invocation triggers another.
nodeRole"invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefinedOptionalRead-only. Role the emitting span plays in the execution graph.
agentIdstring | undefinedOptionalRead-only. App-owned agent identity.
branchIdstring | undefinedOptionalRead-only. App-owned branch identity.
agentVersionIdstring | undefinedOptionalRead-only. App-owned immutable version identity of the agent definition.
parentBranchIdstring | undefinedOptionalRead-only. Branch this branch was forked from, when applicable.
parentAgentVersionIdstring | undefinedOptionalRead-only. Version of the parent branch at the fork point.
forkPointIdstring | undefinedOptionalRead-only. App-owned fork marker shared by the forked branch and its origin.
workflowInvocationIdstring | undefinedOptionalRead-only. Workflow invocation the fact belongs to.
workflowNodeIdstring | undefinedOptionalRead-only. Workflow node invocation the fact belongs to.
definitionKindstring | undefinedOptionalRead-only. Kind of the workflow/agent definition that dispatched the node.
definitionIdstring | undefinedOptionalRead-only. Id of that definition.
definitionRevisionstring | undefinedOptionalRead-only. Revision of that definition; distinguishes executions of different definition states.
nodeIdstring | undefinedOptionalRead-only. Node id inside the workflow.
nodeNamestring | undefinedOptionalRead-only. Human-readable node name.
nodeKindstring | undefinedOptionalRead-only. Node kind as declared by the App.
nodeDescriptionstring | undefinedOptionalRead-only. Optional node description for diagnostics display.
stageIdstring | undefinedOptionalRead-only. Model stage that produced the fact.
modelIdstring | undefinedOptionalRead-only. Model binding used, when the fact concerns a model call.
version2RequiredEnvelope version; consumers must reject anything else.
eventIdstringRequiredUnique id of this fact, stable across observers and log writers.
type"model.output"RequiredDiscriminator matching payload.
producerSequencenumberRequiredMonotonic counter owned by the producing scope; starts at 1 for each producer.
occurredAtMsnumberRequiredInstant the fact occurred, in epoch milliseconds.
payload{ stageId: string; callSequence: number; partIndex: number; part: import("./model/messages.js").ModelPart; }RequiredEvent-specific facts.
usedModelboolean | undefinedOptionalWhether the reported step used a model; omitted when the producer did not state it.
subStepsreadonly RecordedSubStep[]RequiredReported sub-steps attached to this fact, bounded and already validated.
subStepsDroppednumberRequiredNumber of reported sub-steps omitted by the recorder's bounds.
subStepsTruncatedbooleanRequiredTrue when reported sub-steps were truncated, so the attached list is incomplete.
Branch 2
FieldTypeRequiredDescription
runIdstringRequiredRead-only. Root run id shared by every fact of one logical run.
spanIdstringRequiredRead-only. Span that produced the fact.
parentSpanIdstring | undefinedOptionalRead-only. Enclosing span; absent for a root span.
invocationIdstring | undefinedOptionalRead-only. Invocation that produced the fact, when the fact belongs to one.
parentInvocationIdstring | undefinedOptionalRead-only. Enclosing invocation, when one invocation triggers another.
nodeRole"invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefinedOptionalRead-only. Role the emitting span plays in the execution graph.
agentIdstring | undefinedOptionalRead-only. App-owned agent identity.
branchIdstring | undefinedOptionalRead-only. App-owned branch identity.
agentVersionIdstring | undefinedOptionalRead-only. App-owned immutable version identity of the agent definition.
parentBranchIdstring | undefinedOptionalRead-only. Branch this branch was forked from, when applicable.
parentAgentVersionIdstring | undefinedOptionalRead-only. Version of the parent branch at the fork point.
forkPointIdstring | undefinedOptionalRead-only. App-owned fork marker shared by the forked branch and its origin.
workflowInvocationIdstring | undefinedOptionalRead-only. Workflow invocation the fact belongs to.
workflowNodeIdstring | undefinedOptionalRead-only. Workflow node invocation the fact belongs to.
definitionKindstring | undefinedOptionalRead-only. Kind of the workflow/agent definition that dispatched the node.
definitionIdstring | undefinedOptionalRead-only. Id of that definition.
definitionRevisionstring | undefinedOptionalRead-only. Revision of that definition; distinguishes executions of different definition states.
nodeIdstring | undefinedOptionalRead-only. Node id inside the workflow.
nodeNamestring | undefinedOptionalRead-only. Human-readable node name.
nodeKindstring | undefinedOptionalRead-only. Node kind as declared by the App.
nodeDescriptionstring | undefinedOptionalRead-only. Optional node description for diagnostics display.
stageIdstring | undefinedOptionalRead-only. Model stage that produced the fact.
modelIdstring | undefinedOptionalRead-only. Model binding used, when the fact concerns a model call.
version2RequiredEnvelope version; consumers must reject anything else.
eventIdstringRequiredUnique id of this fact, stable across observers and log writers.
type"model.parsed"RequiredDiscriminator matching payload.
producerSequencenumberRequiredMonotonic counter owned by the producing scope; starts at 1 for each producer.
occurredAtMsnumberRequiredInstant the fact occurred, in epoch milliseconds.
payload{ stageId: string; callSequence: number; value?: unknown; }RequiredEvent-specific facts.
usedModelboolean | undefinedOptionalWhether the reported step used a model; omitted when the producer did not state it.
subStepsreadonly RecordedSubStep[]RequiredReported sub-steps attached to this fact, bounded and already validated.
subStepsDroppednumberRequiredNumber of reported sub-steps omitted by the recorder's bounds.
subStepsTruncatedbooleanRequiredTrue when reported sub-steps were truncated, so the attached list is incomplete.
Branch 3
FieldTypeRequiredDescription
runIdstringRequiredRead-only. Root run id shared by every fact of one logical run.
spanIdstringRequiredRead-only. Span that produced the fact.
parentSpanIdstring | undefinedOptionalRead-only. Enclosing span; absent for a root span.
invocationIdstring | undefinedOptionalRead-only. Invocation that produced the fact, when the fact belongs to one.
parentInvocationIdstring | undefinedOptionalRead-only. Enclosing invocation, when one invocation triggers another.
nodeRole"invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefinedOptionalRead-only. Role the emitting span plays in the execution graph.
agentIdstring | undefinedOptionalRead-only. App-owned agent identity.
branchIdstring | undefinedOptionalRead-only. App-owned branch identity.
agentVersionIdstring | undefinedOptionalRead-only. App-owned immutable version identity of the agent definition.
parentBranchIdstring | undefinedOptionalRead-only. Branch this branch was forked from, when applicable.
parentAgentVersionIdstring | undefinedOptionalRead-only. Version of the parent branch at the fork point.
forkPointIdstring | undefinedOptionalRead-only. App-owned fork marker shared by the forked branch and its origin.
workflowInvocationIdstring | undefinedOptionalRead-only. Workflow invocation the fact belongs to.
workflowNodeIdstring | undefinedOptionalRead-only. Workflow node invocation the fact belongs to.
definitionKindstring | undefinedOptionalRead-only. Kind of the workflow/agent definition that dispatched the node.
definitionIdstring | undefinedOptionalRead-only. Id of that definition.
definitionRevisionstring | undefinedOptionalRead-only. Revision of that definition; distinguishes executions of different definition states.
nodeIdstring | undefinedOptionalRead-only. Node id inside the workflow.
nodeNamestring | undefinedOptionalRead-only. Human-readable node name.
nodeKindstring | undefinedOptionalRead-only. Node kind as declared by the App.
nodeDescriptionstring | undefinedOptionalRead-only. Optional node description for diagnostics display.
stageIdstring | undefinedOptionalRead-only. Model stage that produced the fact.
modelIdstring | undefinedOptionalRead-only. Model binding used, when the fact concerns a model call.
version2RequiredEnvelope version; consumers must reject anything else.
eventIdstringRequiredUnique id of this fact, stable across observers and log writers.
type"model.end"RequiredDiscriminator matching payload.
producerSequencenumberRequiredMonotonic counter owned by the producing scope; starts at 1 for each producer.
occurredAtMsnumberRequiredInstant the fact occurred, in epoch milliseconds.
payload{ stageId: string; state: Readonly<ModelCallTrace>; error?: unknown; receivedParts: number; }RequiredEvent-specific facts.
usedModelboolean | undefinedOptionalWhether the reported step used a model; omitted when the producer did not state it.
subStepsreadonly RecordedSubStep[]RequiredReported sub-steps attached to this fact, bounded and already validated.
subStepsDroppednumberRequiredNumber of reported sub-steps omitted by the recorder's bounds.
subStepsTruncatedbooleanRequiredTrue when reported sub-steps were truncated, so the attached list is incomplete.
Branch 4
FieldTypeRequiredDescription
runIdstringRequiredRead-only. Root run id shared by every fact of one logical run.
spanIdstringRequiredRead-only. Span that produced the fact.
parentSpanIdstring | undefinedOptionalRead-only. Enclosing span; absent for a root span.
invocationIdstring | undefinedOptionalRead-only. Invocation that produced the fact, when the fact belongs to one.
parentInvocationIdstring | undefinedOptionalRead-only. Enclosing invocation, when one invocation triggers another.
nodeRole"invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefinedOptionalRead-only. Role the emitting span plays in the execution graph.
agentIdstring | undefinedOptionalRead-only. App-owned agent identity.
branchIdstring | undefinedOptionalRead-only. App-owned branch identity.
agentVersionIdstring | undefinedOptionalRead-only. App-owned immutable version identity of the agent definition.
parentBranchIdstring | undefinedOptionalRead-only. Branch this branch was forked from, when applicable.
parentAgentVersionIdstring | undefinedOptionalRead-only. Version of the parent branch at the fork point.
forkPointIdstring | undefinedOptionalRead-only. App-owned fork marker shared by the forked branch and its origin.
workflowInvocationIdstring | undefinedOptionalRead-only. Workflow invocation the fact belongs to.
workflowNodeIdstring | undefinedOptionalRead-only. Workflow node invocation the fact belongs to.
definitionKindstring | undefinedOptionalRead-only. Kind of the workflow/agent definition that dispatched the node.
definitionIdstring | undefinedOptionalRead-only. Id of that definition.
definitionRevisionstring | undefinedOptionalRead-only. Revision of that definition; distinguishes executions of different definition states.
nodeIdstring | undefinedOptionalRead-only. Node id inside the workflow.
nodeNamestring | undefinedOptionalRead-only. Human-readable node name.
nodeKindstring | undefinedOptionalRead-only. Node kind as declared by the App.
nodeDescriptionstring | undefinedOptionalRead-only. Optional node description for diagnostics display.
stageIdstring | undefinedOptionalRead-only. Model stage that produced the fact.
modelIdstring | undefinedOptionalRead-only. Model binding used, when the fact concerns a model call.
version2RequiredEnvelope version; consumers must reject anything else.
eventIdstringRequiredUnique id of this fact, stable across observers and log writers.
type"model.start"RequiredDiscriminator matching payload.
producerSequencenumberRequiredMonotonic counter owned by the producing scope; starts at 1 for each producer.
occurredAtMsnumberRequiredInstant the fact occurred, in epoch milliseconds.
payload{ stageId: string; callSequence: number; transportId: string; }RequiredEvent-specific facts.
usedModelboolean | undefinedOptionalWhether the reported step used a model; omitted when the producer did not state it.
subStepsreadonly RecordedSubStep[]RequiredReported sub-steps attached to this fact, bounded and already validated.
subStepsDroppednumberRequiredNumber of reported sub-steps omitted by the recorder's bounds.
subStepsTruncatedbooleanRequiredTrue when reported sub-steps were truncated, so the attached list is incomplete.

Examples ​

Add a preview for a plain-text stage ​

Beginner · Node.js

ts
import { ModelRunner, Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({ rules: [{ stageId: 'reply' }],
  sink: bubbles => { console.log('preview', bubbles); },
});
const runner = new ModelRunner({ provider: { async *stream() { yield '你好'; yield ',Core'; } }, sink: { output: preview } });
console.log((await runner.invoke({ input: '你好', stageId: 'reply' })).value);
js
import { ModelRunner, Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({ rules: [{ stageId: 'reply' }],
    sink: bubbles => { console.log('preview', bubbles); },
});
const runner = new ModelRunner({ provider: { async *stream() { yield '你好'; yield ',Core'; } }, sink: { output: preview } });
console.log((await runner.invoke({ input: '你好', stageId: 'reply' })).value);

Allow only displayable fields of an explicit body protocol ​

Configuration · Node.js

Rules must correspond to the reply tool and Schema the App actually registers; configuring a preview does not create a model tool.

ts
import { Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({
  rules: [{ stageId: 'reply', toolId: 'reply', paths: [['answer'], ['bubbles', '*']],
    when: { path: ['kind'], values: ['reply'] } }],
  sink: async bubbles => { console.log('当前暂态正文', bubbles); },
  maxChars: 4000,
});
console.log(typeof preview);
js
import { Support } from '@jangts/agent-core';
const preview = Support.createReplyPreview({
    rules: [{ stageId: 'reply', toolId: 'reply', paths: [['answer'], ['bubbles', '*']],
            when: { path: ['kind'], values: ['reply'] } }],
    sink: async (bubbles) => { console.log('当前暂态正文', bubbles); },
    maxChars: 4000,
});
console.log(typeof preview);

API reference, usage examples and developer guides.