/** * Internal domain model — the reconstructed shape of one opencode turn, * decoupled from both the opencode event/message wire format (source/types.ts) * and the OTEL span output. This is the seam the event source produces and the * span emitter consumes; it is intentionally identical in spirit to the * weave-codex model so the entire spans/ emit half ports over unchanged. */ /** Normalized token usage for a single model call or a turn total. */ export interface NormalizedUsage { inputTokens: number; outputTokens: number; cachedInputTokens: number; reasoningOutputTokens: number; } export type ToolKind = 'function' | 'web_search' | 'mcp'; /** A tool execution → one `execute_tool` span. */ export interface ToolCall { callId: string; name: string; kind: ToolKind; startTime: Date; endTime: Date; arguments?: string; result?: string; error?: string; mcpServer?: string; } /** A tool the model requested within a chat (for that chat's output.messages). */ export interface ChatToolRef { callId: string; name: string; arguments?: string; } /** A single model round-trip → one `chat` span. */ export interface ChatCall { startTime: Date; endTime: Date; text?: string; reasoning?: string; toolCalls: ChatToolRef[]; usage?: NormalizedUsage; finishReason: string; } /** One completed user→agent turn → one trace rooted at an `invoke_agent` span. */ export interface ReconstructedTurn { sessionId: string; turnId: string; conversationId: string; /** opencode is multi-provider; provider drives gen_ai.provider.name. */ provider?: string; model: string; startTime: Date; endTime: Date; cwd?: string; cliVersion?: string; /** Set when this turn belongs to a spawned subagent (child) session. */ parentSessionId?: string; userMessage?: string; finalAssistantMessage?: string; chats: ChatCall[]; tools: ToolCall[]; usageTotal: NormalizedUsage; }