/**
 * Tool message protocol types (SSOT)
 *
 * Shared by worker-side (packages/sdk) and parent-side (apps/api) to
 * describe the postMessage() messages that cross the worker thread boundary.
 *
 * ToolCallMessage  — worker → parent (outbound request)
 * ToolCallResponse — parent → worker (inbound response)
 */

import type { ToolingErrorType } from './types'

/**
 * Token usage metadata optionally attached to a ToolCallResponse.
 * Populated for LLM tool calls where cost accounting is available.
 */
export interface TokenUsage {
  inputTokens: number
  outputTokens: number
  cost?: number
}

/** Outbound tool-call from worker to parent */
export interface ToolCallMessage {
  type: 'tool-call'
  id: string
  tool: string
  method: string
  params: unknown
  credential?: string
}

/** Inbound tool-result from parent to worker */
export interface ToolCallResponse {
  type: 'tool-result'
  id: string
  result?: unknown
  error?: string
  /** Structured error code from platform (ToolingErrorType) */
  code?: ToolingErrorType
  /** Token usage metadata (LLM tool calls only) */
  usage?: TokenUsage
}
