/**
 * types.ts
 * Core type definitions for OpenTelemetry trace parsing
 */
export interface Span {
    id: string;
    traceId: string;
    parentSpanId: string | null;
    name: string;
    duration: number;
    timestamp: string;
    serviceName: string;
    attributes: Record<string, any>;
    events?: SpanEvent[];
    resourceAttributes?: Record<string, any>;
}
export interface SpanEvent {
    timestamp: string;
    name: string;
    attributes: Record<string, any>;
}
/** Per-tool contract fields for LangGraph / OpenLit (and similar) traces. */
export interface ToolArgumentFields {
    /**
     * Tool argument schema from the span when present; otherwise inferred as a sorted list of parameter names
     * (e.g. input `{'stock': 'TCS'}` → `['stock']`).
     */
    argument_defination?: any;
    /** Arguments passed to the tool for this execution (same source as `input` for LangGraph). */
    argument?: any;
    /** Tool result for this execution (when nested under an agent summary). */
    output?: any;
}
export interface Tool {
    id: string;
    name: string;
    /** Tool description/instructions when present in trace attrs. */
    description?: string;
    input: any;
    output: any;
    /** @see ToolArgumentFields */
    argument_defination?: any;
    /** @see ToolArgumentFields */
    argument?: any;
    tokenUsage?: TokenUsage;
    duration: number;
    timestamp: string;
    spanId: string;
    /**
     * Trace-level dimensions (copied from any span's ResourceAttributes, if present).
     * If present in at least one span, we assume it applies to the whole trace.
     */
    environment?: string;
    version?: string;
    executionType?: 'actual' | 'decision';
    metadata?: Record<string, any>;
    /**
     * Rollups for any model calls observed underneath this tool span (via parentSpanId ancestry).
     * These are "cumulative" sums across child model spans (can exceed wall-clock due to concurrency).
     */
    ttft?: number[];
    cumulativeDurationMs?: number;
    cumulativeTokenUsage?: TokenUsage;
}
/** Tool usage scoped to a single LangGraph agent node (descendant tool spans). */
export interface AgentToolDefinition extends ToolArgumentFields {
    name: string;
    spanId: string;
    description?: string;
}
export interface Agent {
    id: string;
    name: string;
    type: string;
    /** Agent description/instructions when present in trace attrs. */
    description?: string;
    role?: string;
    goal?: string;
    backstory?: string;
    metadata?: Record<string, any>;
    /**
     * Tools invoked under this agent's span subtree (OpenLit LangGraph: `execute_tool` descendants).
     */
    toolDefinitions?: AgentToolDefinition[];
    /**
     * Trace-level dimensions (copied from any span's ResourceAttributes, if present).
     * If present in at least one span, we assume it applies to the whole trace.
     */
    environment?: string;
    version?: string;
    /**
     * Rollups for any model calls observed underneath this agent span (via parentSpanId ancestry).
     * These are "cumulative" sums across child model spans (can exceed wall-clock due to concurrency).
     */
    ttft?: number[];
    cumulativeDurationMs?: number;
    cumulativeTokenUsage?: TokenUsage;
}
export interface Model {
    id: string;
    provider: string;
    modelName: string;
    temperature?: number;
    tokenUsage: TokenUsage;
    cost?: number;
    spanId: string;
    timestamp: string;
    /**
     * Trace-level dimensions (copied from any span's ResourceAttributes, if present).
     * If present in at least one span, we assume it applies to the whole trace.
     */
    environment?: string;
    version?: string;
    duration?: number;
}
export interface TokenUsage {
    inputTokens: number;
    outputTokens: number;
    totalTokens: number;
    /** Cached/read tokens from input (reduces cost) */
    cachedTokens?: number;
    /** Cache read tokens (from usage_metadata.input_token_details.cache_read or gen_ai.usage) */
    cacheRead?: number;
    /** Cache write tokens (from usage_metadata.output_token_details.cache_write or gen_ai.usage) */
    cacheWrite?: number;
    /** Reasoning tokens from output (for o1/thinking models) */
    reasoningTokens?: number;
}
/**
 * Call-graph DAG types (unique entity nodes, edges = calls/sequence between entities)
 *
 * NOTE: This is intentionally different from `DAGNode` (span-level hierarchy).
 */
export type DagNodeKind = 'workflow' | 'agent' | 'tool' | 'model' | 'prompt' | 'response' | 'other';
export interface DagNodeMetrics {
    durationMs: number;
    tokensTotal?: number;
    costUsd?: number;
}
export interface DagNode {
    id: string;
    kind: DagNodeKind;
    label: string;
    role?: string;
    model?: string;
    metrics?: DagNodeMetrics;
}
export type DagEdgeType = 'invokes' | 'sequence' | 'parent' | 'prompt' | 'response';
export interface DagEdge {
    from: string;
    to: string;
    type: DagEdgeType;
    /**
     * Number of times we observed this edge in the trace.
     * (Keeps the graph unique while preserving frequency information.)
     */
    count?: number;
}
export interface DagGraph {
    nodes: DagNode[];
    edges: DagEdge[];
}
export type RenderLane = 'tools' | 'models' | 'agents' | 'middle';
export type RenderNodeKind = DagNodeKind | 'prompt' | 'response';
export interface RenderNode {
    id: string;
    kind: RenderNodeKind;
    label: string;
    lane: RenderLane;
    /**
     * Stable horizontal ordering for UI layout (UI converts to x-position).
     * Starts at 0.
     */
    order: number;
    /**
     * Optional text payload for prompt/response preview.
     */
    text?: string;
    /**
     * Optional per-node payload for trace-view DAG UI (tool/agent/model details).
     * NOTE: These are intentionally optional so existing DAG/linear views remain compatible.
     */
    request?: any;
    response?: any;
    /** Duration in milliseconds (for UI display). */
    duration?: number;
    /** ISO timestamp (span start time). */
    timestamp?: string;
}
export type RenderEdgeType = DagEdgeType | 'prompt' | 'response';
export interface RenderEdge {
    from: string;
    to: string;
    type: RenderEdgeType;
    count?: number;
}
export interface RenderDagGraph {
    nodes: RenderNode[];
    edges: RenderEdge[];
    entryId?: string;
    exitId?: string;
}
export interface RenderLinearGraph {
    nodes: RenderNode[];
    edges: RenderEdge[];
}
export interface DAGNode {
    id: string;
    type: 'llm' | 'tool' | 'agent' | 'workflow' | 'prompt' | 'response';
    name: string;
    children: string[];
    metadata: Record<string, any>;
}
export interface LinearStep {
    stepNumber: number;
    spanId: string;
    type: string;
    name: string;
    timestamp: string;
    duration: number;
    input?: any;
    output?: any;
    metadata?: Record<string, any>;
}
export interface ParseResult {
    framework: 'langchain' | 'crewai' | 'autogen' | 'generic' | 'llamaindex';
    tools: Tool[];
    agents: Agent[];
    models: Model[];
    unScopedModels: Model[];
    /**
     * Trace-level dimensions (copied from any span's ResourceAttributes, if present).
     */
    environment?: string;
    version?: string;
    /**
     * The initial user input/prompt that started the trace.
     */
    input?: string;
    /**
     * The final output/response from the trace execution.
     */
    output?: string;
    /**
     * Call-graph DAG (unique nodes, edges represent calls between entities).
     */
    dag: DagGraph;
    /**
     * Span-level DAG (raw parent/child relationships).
     * Kept for debugging/back-compat; prefer `dag`.
     */
    spanDag: DAGNode[];
    linearFlow: LinearStep[];
    metadata: ParseMetadata;
}
export interface ParseMetadata {
    totalDuration: number;
    totalCost: number;
    spanCount: number;
    toolCallCount: number;
    llmCallCount: number;
    agentCount: number;
    uniqueSpanCount: number;
    duplicateSpanCount: number;
    /**
     * Trace-level dimensions (copied from any span's ResourceAttributes, if present).
     */
    environment?: string;
    version?: string;
    totalTokens?: number;
    /** Total time to first token (ms) across all LLM calls that report it. */
    totalTimeToFirstToken?: number;
    /** Average time to first token (ms) over LLM calls that report it. */
    averageTimeToFirstToken?: number;
}
export interface ParsingContext {
    spans: Span[];
    spanMap: Map<string, Span>;
    seenSpans: Set<string>;
    tools: Tool[];
    agents: Agent[];
    models: Model[];
    dagNodes: DAGNode[];
    linearSteps: LinearStep[];
}
export interface EdgeCaseHandler {
    name: string;
    priority?: number;
    canHandle(span: Span, context: ParsingContext): boolean;
    handle(span: Span, context: ParsingContext): void;
}
export interface FrameworkParser {
    name: string;
    canParse(spans: Span[]): boolean;
    getTools(spans: Span[]): Tool[];
    getAgents(spans: Span[]): Agent[];
    getModels(spans: Span[]): Model[];
    getModelsFromUnscoped?(spans: Span[]): Model[];
    generateDag(spans: Span[]): DAGNode[];
    generateLinearFlow(spans: Span[]): LinearStep[];
}
//# sourceMappingURL=types.d.ts.map