ModelOutputEvent
CORE · type · 类型合同
Delivery sink, awaited in order. Parts are unvalidated proposals, never execution receipts.
导入
ts
import type { ModelOutputEvent } from '@jangts/agent-core/model';js
/** @typedef {import('@jangts/agent-core/model').ModelOutputEvent} ModelOutputEvent */其他公开入口:@jangts/agent-core、@jangts/agent-core/model、@jangts/agent-core/types、@jangts/agent-core/structs。
定义
类型: ModelOutputEvent
类型表达式
ts
type ModelOutputEvent = Extract<
import('../execution/events.js').CoreEvent,
{ type: 'model.start' | 'model.output' | 'model.parsed' | 'model.end' }
>;联合分支结构
ModelOutputEvent的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
runId | string | 必需 | 只读。Root run id shared by every fact of one logical run. |
spanId | string | 必需 | 只读。Span that produced the fact. |
parentSpanId | string | undefined | 可省略 | 只读。Enclosing span; absent for a root span. |
invocationId | string | undefined | 可省略 | 只读。Invocation that produced the fact, when the fact belongs to one. |
parentInvocationId | string | undefined | 可省略 | 只读。Enclosing invocation, when one invocation triggers another. |
nodeRole | "invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefined | 可省略 | 只读。Role the emitting span plays in the execution graph. |
agentId | string | undefined | 可省略 | 只读。App-owned agent identity. |
branchId | string | undefined | 可省略 | 只读。App-owned branch identity. |
agentVersionId | string | undefined | 可省略 | 只读。App-owned immutable version identity of the agent definition. |
parentBranchId | string | undefined | 可省略 | 只读。Branch this branch was forked from, when applicable. |
parentAgentVersionId | string | undefined | 可省略 | 只读。Version of the parent branch at the fork point. |
forkPointId | string | undefined | 可省略 | 只读。App-owned fork marker shared by the forked branch and its origin. |
workflowInvocationId | string | undefined | 可省略 | 只读。Workflow invocation the fact belongs to. |
workflowNodeId | string | undefined | 可省略 | 只读。Workflow node invocation the fact belongs to. |
definitionKind | string | undefined | 可省略 | 只读。Kind of the workflow/agent definition that dispatched the node. |
definitionId | string | undefined | 可省略 | 只读。Id of that definition. |
definitionRevision | string | undefined | 可省略 | 只读。Revision of that definition; distinguishes executions of different definition states. |
nodeId | string | undefined | 可省略 | 只读。Node id inside the workflow. |
nodeName | string | undefined | 可省略 | 只读。Human-readable node name. |
nodeKind | string | undefined | 可省略 | 只读。Node kind as declared by the App. |
nodeDescription | string | undefined | 可省略 | 只读。Optional node description for diagnostics display. |
stageId | string | undefined | 可省略 | 只读。Model stage that produced the fact. |
modelId | string | undefined | 可省略 | 只读。Model binding used, when the fact concerns a model call. |
version | 2 | 必需 | Envelope version; consumers must reject anything else. |
eventId | string | 必需 | Unique id of this fact, stable across observers and log writers. |
type | "model.output" | 必需 | Discriminator matching payload. |
producerSequence | number | 必需 | Monotonic counter owned by the producing scope; starts at 1 for each producer. |
occurredAtMs | number | 必需 | Instant the fact occurred, in epoch milliseconds. |
payload | { stageId: string; callSequence: number; partIndex: number; part: import("./model/messages.js").ModelPart; } | 必需 | Event-specific facts. |
usedModel | boolean | undefined | 可省略 | Whether the reported step used a model; omitted when the producer did not state it. |
subSteps | readonly RecordedSubStep[] | 必需 | Reported sub-steps attached to this fact, bounded and already validated. |
subStepsDropped | number | 必需 | Number of reported sub-steps omitted by the recorder's bounds. |
subStepsTruncated | boolean | 必需 | True when reported sub-steps were truncated, so the attached list is incomplete. |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
runId | string | 必需 | 只读。Root run id shared by every fact of one logical run. |
spanId | string | 必需 | 只读。Span that produced the fact. |
parentSpanId | string | undefined | 可省略 | 只读。Enclosing span; absent for a root span. |
invocationId | string | undefined | 可省略 | 只读。Invocation that produced the fact, when the fact belongs to one. |
parentInvocationId | string | undefined | 可省略 | 只读。Enclosing invocation, when one invocation triggers another. |
nodeRole | "invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefined | 可省略 | 只读。Role the emitting span plays in the execution graph. |
agentId | string | undefined | 可省略 | 只读。App-owned agent identity. |
branchId | string | undefined | 可省略 | 只读。App-owned branch identity. |
agentVersionId | string | undefined | 可省略 | 只读。App-owned immutable version identity of the agent definition. |
parentBranchId | string | undefined | 可省略 | 只读。Branch this branch was forked from, when applicable. |
parentAgentVersionId | string | undefined | 可省略 | 只读。Version of the parent branch at the fork point. |
forkPointId | string | undefined | 可省略 | 只读。App-owned fork marker shared by the forked branch and its origin. |
workflowInvocationId | string | undefined | 可省略 | 只读。Workflow invocation the fact belongs to. |
workflowNodeId | string | undefined | 可省略 | 只读。Workflow node invocation the fact belongs to. |
definitionKind | string | undefined | 可省略 | 只读。Kind of the workflow/agent definition that dispatched the node. |
definitionId | string | undefined | 可省略 | 只读。Id of that definition. |
definitionRevision | string | undefined | 可省略 | 只读。Revision of that definition; distinguishes executions of different definition states. |
nodeId | string | undefined | 可省略 | 只读。Node id inside the workflow. |
nodeName | string | undefined | 可省略 | 只读。Human-readable node name. |
nodeKind | string | undefined | 可省略 | 只读。Node kind as declared by the App. |
nodeDescription | string | undefined | 可省略 | 只读。Optional node description for diagnostics display. |
stageId | string | undefined | 可省略 | 只读。Model stage that produced the fact. |
modelId | string | undefined | 可省略 | 只读。Model binding used, when the fact concerns a model call. |
version | 2 | 必需 | Envelope version; consumers must reject anything else. |
eventId | string | 必需 | Unique id of this fact, stable across observers and log writers. |
type | "model.parsed" | 必需 | Discriminator matching payload. |
producerSequence | number | 必需 | Monotonic counter owned by the producing scope; starts at 1 for each producer. |
occurredAtMs | number | 必需 | Instant the fact occurred, in epoch milliseconds. |
payload | { stageId: string; callSequence: number; value?: unknown; } | 必需 | Event-specific facts. |
usedModel | boolean | undefined | 可省略 | Whether the reported step used a model; omitted when the producer did not state it. |
subSteps | readonly RecordedSubStep[] | 必需 | Reported sub-steps attached to this fact, bounded and already validated. |
subStepsDropped | number | 必需 | Number of reported sub-steps omitted by the recorder's bounds. |
subStepsTruncated | boolean | 必需 | True when reported sub-steps were truncated, so the attached list is incomplete. |
分支 3
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
runId | string | 必需 | 只读。Root run id shared by every fact of one logical run. |
spanId | string | 必需 | 只读。Span that produced the fact. |
parentSpanId | string | undefined | 可省略 | 只读。Enclosing span; absent for a root span. |
invocationId | string | undefined | 可省略 | 只读。Invocation that produced the fact, when the fact belongs to one. |
parentInvocationId | string | undefined | 可省略 | 只读。Enclosing invocation, when one invocation triggers another. |
nodeRole | "invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefined | 可省略 | 只读。Role the emitting span plays in the execution graph. |
agentId | string | undefined | 可省略 | 只读。App-owned agent identity. |
branchId | string | undefined | 可省略 | 只读。App-owned branch identity. |
agentVersionId | string | undefined | 可省略 | 只读。App-owned immutable version identity of the agent definition. |
parentBranchId | string | undefined | 可省略 | 只读。Branch this branch was forked from, when applicable. |
parentAgentVersionId | string | undefined | 可省略 | 只读。Version of the parent branch at the fork point. |
forkPointId | string | undefined | 可省略 | 只读。App-owned fork marker shared by the forked branch and its origin. |
workflowInvocationId | string | undefined | 可省略 | 只读。Workflow invocation the fact belongs to. |
workflowNodeId | string | undefined | 可省略 | 只读。Workflow node invocation the fact belongs to. |
definitionKind | string | undefined | 可省略 | 只读。Kind of the workflow/agent definition that dispatched the node. |
definitionId | string | undefined | 可省略 | 只读。Id of that definition. |
definitionRevision | string | undefined | 可省略 | 只读。Revision of that definition; distinguishes executions of different definition states. |
nodeId | string | undefined | 可省略 | 只读。Node id inside the workflow. |
nodeName | string | undefined | 可省略 | 只读。Human-readable node name. |
nodeKind | string | undefined | 可省略 | 只读。Node kind as declared by the App. |
nodeDescription | string | undefined | 可省略 | 只读。Optional node description for diagnostics display. |
stageId | string | undefined | 可省略 | 只读。Model stage that produced the fact. |
modelId | string | undefined | 可省略 | 只读。Model binding used, when the fact concerns a model call. |
version | 2 | 必需 | Envelope version; consumers must reject anything else. |
eventId | string | 必需 | Unique id of this fact, stable across observers and log writers. |
type | "model.end" | 必需 | Discriminator matching payload. |
producerSequence | number | 必需 | Monotonic counter owned by the producing scope; starts at 1 for each producer. |
occurredAtMs | number | 必需 | Instant the fact occurred, in epoch milliseconds. |
payload | { stageId: string; state: Readonly<ModelCallTrace>; error?: unknown; receivedParts: number; } | 必需 | Event-specific facts. |
usedModel | boolean | undefined | 可省略 | Whether the reported step used a model; omitted when the producer did not state it. |
subSteps | readonly RecordedSubStep[] | 必需 | Reported sub-steps attached to this fact, bounded and already validated. |
subStepsDropped | number | 必需 | Number of reported sub-steps omitted by the recorder's bounds. |
subStepsTruncated | boolean | 必需 | True when reported sub-steps were truncated, so the attached list is incomplete. |
分支 4
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
runId | string | 必需 | 只读。Root run id shared by every fact of one logical run. |
spanId | string | 必需 | 只读。Span that produced the fact. |
parentSpanId | string | undefined | 可省略 | 只读。Enclosing span; absent for a root span. |
invocationId | string | undefined | 可省略 | 只读。Invocation that produced the fact, when the fact belongs to one. |
parentInvocationId | string | undefined | 可省略 | 只读。Enclosing invocation, when one invocation triggers another. |
nodeRole | "invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefined | 可省略 | 只读。Role the emitting span plays in the execution graph. |
agentId | string | undefined | 可省略 | 只读。App-owned agent identity. |
branchId | string | undefined | 可省略 | 只读。App-owned branch identity. |
agentVersionId | string | undefined | 可省略 | 只读。App-owned immutable version identity of the agent definition. |
parentBranchId | string | undefined | 可省略 | 只读。Branch this branch was forked from, when applicable. |
parentAgentVersionId | string | undefined | 可省略 | 只读。Version of the parent branch at the fork point. |
forkPointId | string | undefined | 可省略 | 只读。App-owned fork marker shared by the forked branch and its origin. |
workflowInvocationId | string | undefined | 可省略 | 只读。Workflow invocation the fact belongs to. |
workflowNodeId | string | undefined | 可省略 | 只读。Workflow node invocation the fact belongs to. |
definitionKind | string | undefined | 可省略 | 只读。Kind of the workflow/agent definition that dispatched the node. |
definitionId | string | undefined | 可省略 | 只读。Id of that definition. |
definitionRevision | string | undefined | 可省略 | 只读。Revision of that definition; distinguishes executions of different definition states. |
nodeId | string | undefined | 可省略 | 只读。Node id inside the workflow. |
nodeName | string | undefined | 可省略 | 只读。Human-readable node name. |
nodeKind | string | undefined | 可省略 | 只读。Node kind as declared by the App. |
nodeDescription | string | undefined | 可省略 | 只读。Optional node description for diagnostics display. |
stageId | string | undefined | 可省略 | 只读。Model stage that produced the fact. |
modelId | string | undefined | 可省略 | 只读。Model binding used, when the fact concerns a model call. |
version | 2 | 必需 | Envelope version; consumers must reject anything else. |
eventId | string | 必需 | Unique id of this fact, stable across observers and log writers. |
type | "model.start" | 必需 | Discriminator matching payload. |
producerSequence | number | 必需 | Monotonic counter owned by the producing scope; starts at 1 for each producer. |
occurredAtMs | number | 必需 | Instant the fact occurred, in epoch milliseconds. |
payload | { stageId: string; callSequence: number; transportId: string; } | 必需 | Event-specific facts. |
usedModel | boolean | undefined | 可省略 | Whether the reported step used a model; omitted when the producer did not state it. |
subSteps | readonly RecordedSubStep[] | 必需 | Reported sub-steps attached to this fact, bounded and already validated. |
subStepsDropped | number | 必需 | Number of reported sub-steps omitted by the recorder's bounds. |
subStepsTruncated | boolean | 必需 | True when reported sub-steps were truncated, so the attached list is incomplete. |
使用示例
- 正文预览:有序输出,不代替最终接受:按已登记的 stage/tool/字段路径提取可展示正文,拒绝把控制提议当作已执行结果。
为纯文本阶段增加预览
入门 · 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);只允许明确正文协议的可展示字段
配置 · Node.js
规则必须对应 App 实际登记的 reply Tool 与 Schema,配置预览本身不创建模型 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);