normalizeDiagnosticEvent
CORE · function · Runtime value
Validate a persisted diagnostic record and return a detached copy.
Persisted data is untrusted, so the envelope version, event type, identity, ordering and the bounded sub-step shape are checked; the payload itself is not interpreted. The copy is deep cloned, so a store cannot hand back a record that later shares structure with the caller.
Import
import { normalizeDiagnosticEvent } from '@jangts/agent-core/diagnostics';import { normalizeDiagnosticEvent } from '@jangts/agent-core/diagnostics';Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/diagnostics.
Definition
Call
normalizeDiagnosticEvent(input: unknown): import("../structs/diagnostics.js").CoreDiagnosticRecordValidate a persisted diagnostic record and return a detached copy.
Persisted data is untrusted, so the envelope version, event type, identity, ordering and the bounded sub-step shape are checked; the payload itself is not interpreted. The copy is deep cloned, so a store cannot hand back a record that later shares structure with the caller.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | unknown | Required | — |
Returns: CoreDiagnosticRecord.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
version | 2 | Required | Read-only. Envelope version this record was written with. |
eventId | string | Required | Read-only. See the type definition and usage context. |
type | keyof CoreEventPayloads | Required | Read-only. See the type definition and usage context. |
producerSequence | number | Required | Read-only. Per-producer monotonic sequence; at least 1. |
occurredAtMs | number | Required | Read-only. See the type definition and usage context. |
payload | unknown | Required | Read-only. Unvalidated payload; only the envelope above is checked during normalization. |
usedModel | boolean | undefined | Optional | Read-only. See the type definition and usage context. |
subSteps | readonly RecordedSubStep[] | Required | Read-only. See the type definition and usage context. |
subStepsDropped | number | Required | Read-only. See the type definition and usage context. |
subStepsTruncated | boolean | Required | Read-only. See the type definition and usage context. |
runId | string | Required | Read-only. Root run id shared by every fact of one logical run. |
spanId | string | Required | Read-only. Span that produced the fact. |
parentSpanId | string | undefined | Optional | Read-only. Enclosing span; absent for a root span. |
invocationId | string | undefined | Optional | Read-only. Invocation that produced the fact, when the fact belongs to one. |
parentInvocationId | string | undefined | Optional | Read-only. Enclosing invocation, when one invocation triggers another. |
nodeRole | "invocation" | "workflow-node" | "workflow-boundary" | "loop-step" | undefined | Optional | Read-only. Role the emitting span plays in the execution graph. |
agentId | string | undefined | Optional | Read-only. App-owned agent identity. |
branchId | string | undefined | Optional | Read-only. App-owned branch identity. |
agentVersionId | string | undefined | Optional | Read-only. App-owned immutable version identity of the agent definition. |
parentBranchId | string | undefined | Optional | Read-only. Branch this branch was forked from, when applicable. |
parentAgentVersionId | string | undefined | Optional | Read-only. Version of the parent branch at the fork point. |
forkPointId | string | undefined | Optional | Read-only. App-owned fork marker shared by the forked branch and its origin. |
workflowInvocationId | string | undefined | Optional | Read-only. Workflow invocation the fact belongs to. |
workflowNodeId | string | undefined | Optional | Read-only. Workflow node invocation the fact belongs to. |
definitionKind | string | undefined | Optional | Read-only. Kind of the workflow/agent definition that dispatched the node. |
definitionId | string | undefined | Optional | Read-only. Id of that definition. |
definitionRevision | string | undefined | Optional | Read-only. Revision of that definition; distinguishes executions of different definition states. |
nodeId | string | undefined | Optional | Read-only. Node id inside the workflow. |
nodeName | string | undefined | Optional | Read-only. Human-readable node name. |
nodeKind | string | undefined | Optional | Read-only. Node kind as declared by the App. |
nodeDescription | string | undefined | Optional | Read-only. Optional node description for diagnostics display. |
stageId | string | undefined | Optional | Read-only. Model stage that produced the fact. |
modelId | string | undefined | Optional | Read-only. Model binding used, when the fact concerns a model call. |
Examples
- Process observation and node reports: The App subscribes to Core execution facts; nodes report their own usedModel and use an instance sub-logger to record intent first and then results, while the Loop owns identity and logging.
Observe the nodes and model events a task passes through
Beginner · Node.js
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type, event.eventId); } },
} });
console.log(await agent.run({ name: 'Ivan' }));import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({
id: 'greeting',
nodes: [{
id: 'greet', description: '根据本次姓名生成问候', startsRound: true,
run: state => ({ answer: '你好,' + state.name }),
routes: [route.deliver('answer')],
}],
});
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type, event.eventId); } },
} });
console.log(await agent.run({ name: 'Ivan' }));Report a business stage while the node executes
Configuration · Node.js
The node only reports facts it knows; Core owns node identity and execution association.
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { name: string; answer?: string };
const workflow = defineWorkflow<State, string>({ id: 'greeting', nodes: [{
id: 'greet', description: '生成问候', startsRound: true,
run(state, context) {
context.report({ payload: { phase: 'formatting' } });
return { answer: '你好,' + state.name };
}, routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type); } },
} });
console.log(await agent.run({ name: 'Ivan' }));import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'greeting', nodes: [{
id: 'greet', description: '生成问候', startsRound: true,
run(state, context) {
context.report({ payload: { phase: 'formatting' } });
return { answer: '你好,' + state.name };
}, routes: [route.deliver('answer')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: {
observe: { event(event) { console.log(event.type); } },
} });
console.log(await agent.run({ name: 'Ivan' }));Record an async plan first, then fill in the result
Configuration · Node.js
A scoped logger binds the group and only fixes its own writes; readAll exposes the full ledger. Every fix appends an independent record linked to its original write, without logger submission.
import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
type State = { result?: string };
const workflow = defineWorkflow<State, string>({ id: 'prepare', nodes: [{
id: 'prepare', description: '准备资料', async run(_, context) {
const subs = context.createSubFlowLogger();
const read = subs.fork('material-read');
const id = read.write({ name: '读取资料', kind: 'read', type: 'material.read' });
read.fix(id, { status: 'running' });
const result = await Promise.resolve('已准备');
read.fix(id, { status: 'success', usedModel: false, payload: { result } });
context.report({ usedModel: false });
console.log(read.readAll());
return { result };
}, routes: [route.deliver('result')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: { observe: {
accepts: ({ event, content }) => content === 'metadata' || event === 'node.progress',
event(event) { if (event.type === 'node.progress') console.log(event.payload.subStep, event.subSteps); },
} } });
console.log(await agent.run({}));import { AgentCoreEngine, defineWorkflow, route } from '@jangts/agent-core/engine';
const workflow = defineWorkflow({ id: 'prepare', nodes: [{
id: 'prepare', description: '准备资料', async run(_, context) {
const subs = context.createSubFlowLogger();
const read = subs.fork('material-read');
const id = read.write({ name: '读取资料', kind: 'read', type: 'material.read' });
read.fix(id, { status: 'running' });
const result = await Promise.resolve('已准备');
read.fix(id, { status: 'success', usedModel: false, payload: { result } });
context.report({ usedModel: false });
console.log(read.readAll());
return { result };
}, routes: [route.deliver('result')],
}] });
const agent = new AgentCoreEngine({ workflow, execution: { observe: {
accepts: ({ event, content }) => content === 'metadata' || event === 'node.progress',
event(event) { if (event.type === 'node.progress')
console.log(event.payload.subStep, event.subSteps); },
} } });
console.log(await agent.run({}));