@mastra/core
Version:
58 lines • 3.15 kB
TypeScript
import type { SpanRecord } from '../storage/domains/observability/tracing.js';
import type { ProcessorPipelineAttributes, ProcessorRunInputByPhase, ProcessorRunOutputByPhase, ProcessorSpanPayloadPhase } from './types/index.js';
/**
* A processor span's payload with the phase that produced it, so a renderer can
* switch on `phase` instead of sniffing the payload's shape.
*
* A union over the phases rather than one `phase` field beside a union of
* payloads: narrowing on `phase` then narrows `data` to that phase's shape.
*/
export type ProcessorSpanPayload<TByPhase extends Record<ProcessorSpanPayloadPhase, unknown>> = {
[P in ProcessorSpanPayloadPhase]: {
phase: P;
/** The phase written for people, e.g. `'Tool result'`. */
phaseLabel: string;
data: TByPhase[P];
};
}[ProcessorSpanPayloadPhase];
/**
* The phase a processor span recorded, or `undefined` when it recorded none.
*
* Read from `attributes` rather than `spanType`, so a processor that retyped
* its span (`Processor.spanType`) still describes its payloads — the runner
* writes the same shapes either way. Spans stored before the attribute existed,
* and spans a newer version wrote with a phase this one does not know, return
* `undefined` and fall back to JSON.
*/
export declare function describeProcessorPhase(span: SpanRecord): ProcessorSpanPayloadPhase | undefined;
/** The `input` a processor span recorded, tagged by the phase that produced it. */
export declare function describeProcessorInput(span: SpanRecord, data: Record<string, unknown>): ProcessorSpanPayload<ProcessorRunInputByPhase> | undefined;
/** The `output` a processor span recorded, tagged by the phase that produced it. */
export declare function describeProcessorOutput(span: SpanRecord, data: Record<string, unknown>): ProcessorSpanPayload<ProcessorRunOutputByPhase> | undefined;
/**
* The pipeline facts a processor span records, with the phase resolved and the
* remaining attributes kept apart.
*
* `rest` is everything this view does not explain: a declared span type's own
* attributes, and anything a processor set itself. Keeping it separate is what
* lets a reader show the known fields as labelled values without repeating them
* in an undifferentiated JSON blob beside them.
*/
export interface ProcessorPipelineDescription {
phase: ProcessorSpanPayloadPhase;
phaseLabel: string;
executor?: 'workflow' | 'legacy';
processorIndex?: number;
hookDurationMs?: number;
messageListMutations?: ProcessorPipelineAttributes['messageListMutations'];
tripwireAbort?: ProcessorPipelineAttributes['tripwireAbort'];
/** Attributes this description does not cover; `undefined` when there are none. */
rest?: Record<string, unknown>;
}
/**
* Describes the runner-owned attributes of a processor span for rendering.
* Returns `undefined` when the span recorded no phase, so a legacy or
* non-processor span falls back to its raw attributes.
*/
export declare function describeProcessorPipeline(span: SpanRecord): ProcessorPipelineDescription | undefined;
//# sourceMappingURL=processor-span-record.d.ts.map