UNPKG

@mastra/core

Version:
97 lines • 4.32 kB
import type { MessageListItem } from '../agent/message-list/types.js'; import type { SpanRecord } from '../storage/domains/observability/tracing.js'; import type { ProcessorSpanPayload } from './processor-span-record.js'; import type { AgentRunResult, AgentRunResumeInput, InterruptedSpanOutput, ModelGenerationResult, ModelStepMessage, ModelStepResult, ProcessorRunInputByPhase, ProcessorRunOutputByPhase, SpanErrorInfo } from './types/index.js'; import { SpanType } from './types/index.js'; export { describeProcessorPhase, describeProcessorPipeline } from './processor-span-record.js'; export type { ProcessorPipelineDescription, ProcessorSpanPayload } from './processor-span-record.js'; /** * Narrows a stored span record to one or more span types, typing its * `attributes`, `input` and `output` for that type. * * The check is on `spanType` only. Payloads are not validated: the typed view * trusts that the producer for that span type wrote the shape core declares, * the same trust `SpanTypeMap` already places in `attributes`. * * This module uses only the `SpanType` enum and browser-safe payload helpers * at runtime, without pulling in the rest of the observability utilities. * * @example * if (isSpanRecordOfType(span, SpanType.MODEL_GENERATION)) { * span.attributes?.usage; // UsageStats | undefined * } */ export declare function isSpanRecordOfType<TType extends SpanType>(span: SpanRecord, type: TType | readonly TType[]): span is SpanRecord<TType>; /** A message as it appears in a span input: a caller message, or the shallow preview a model step records. */ export type SpanInputMessage = MessageListItem | ModelStepMessage; /** * A span's `input`, tagged by what it holds so a renderer can switch on `type`. * The tag is derived at read time from `spanType` and the value's shape; it is * never stored. */ export type SpanInputDescription = { type: 'text'; value: string; } | { type: 'messages'; value: SpanInputMessage[]; } | { type: 'agent-run-resume'; value: AgentRunResumeInput; } | { type: 'processor'; value: ProcessorSpanPayload<ProcessorRunInputByPhase>; } | { type: 'json'; value: unknown; }; /** A span's `output`, tagged by what it holds so a renderer can switch on `type`. */ export type SpanOutputDescription = { type: 'interrupted'; value: InterruptedSpanOutput; } | { type: 'agent-run-result'; value: AgentRunResult; } | { type: 'model-generation-result'; value: ModelGenerationResult; } | { type: 'model-step-result'; value: ModelStepResult; } | { type: 'processor'; value: ProcessorSpanPayload<ProcessorRunOutputByPhase>; } | { type: 'text'; value: string; } | { type: 'json'; value: unknown; }; /** * Describes a stored span's `input` for rendering: the value tagged by what it * holds. Returns `undefined` when the span recorded no input. * * - `text`: a plain string, such as the prompt passed to an agent * - `messages`: a message list, unwrapped from the `{ messages }` envelope * model generation spans and legacy agent spans record * - `agent-run-resume`: the resume data of a resumed agent run, whatever shape it has * - `processor`: a processor payload, tagged with the pipeline phase that recorded it * - `json`: anything else, such as tool arguments or workflow step data */ export declare function describeSpanInput(span: SpanRecord): SpanInputDescription | undefined; /** * Describes a stored span's `output` for rendering: the value tagged by what it * holds. Returns `undefined` when the span recorded no output. * * - `interrupted`: the run suspended or was aborted before the span's result existed * - `agent-run-result`, `model-generation-result`, `model-step-result`: the * result of the span type that recorded it * - `processor`: a processor payload, tagged with the pipeline phase that recorded it * - `text`: a plain string * - `json`: anything else, such as a tool result or workflow step output */ export declare function describeSpanOutput(span: SpanRecord): SpanOutputDescription | undefined; /** The error a stored span recorded, typed, or `undefined` when the span succeeded. */ export declare function describeSpanError(span: SpanRecord): SpanErrorInfo | undefined; //# sourceMappingURL=span-record.d.ts.map