import type { JsonRecord } from "../utils/value.js"; export type CodexThread = JsonRecord & { id: string; cwd: string; turns?: CodexTurn[] }; export type CodexTurn = JsonRecord & { id: string; error?: CodexTurnError | null; durationMs?: number | null }; export type CodexTurnError = JsonRecord & { message: string }; export type CodexItem = JsonRecord & { id: string; type: string; text?: string }; export type CodexTurnInput = | { type: "text"; text: string; text_elements: [] } | { type: "localImage"; path: string }; type ThreadOptions = { approvalPolicy: "never"; sandbox: "workspace-write"; config: JsonRecord; cwd?: string; }; type CodexRequestSpec = { initialize: { params: { clientInfo: { name: string; title: string; version: string }; capabilities: { experimentalApi: boolean; requestAttestation: boolean }; }; result: JsonRecord; }; "thread/start": { params: ThreadOptions & { threadSource: "user" }; result: { thread: CodexThread }; }; "thread/resume": { params: ThreadOptions & { threadId: string }; result: { thread: CodexThread }; }; "thread/list": { params: { limit: number; sortKey: "updated_at"; sortDirection: "desc"; sourceKinds: Array<"cli" | "vscode" | "appServer" | "exec">; cwd: string; searchTerm?: string; }; result: { data: CodexThread[]; nextCursor: string | null; backwardsCursor: string | null }; }; "thread/read": { params: { threadId: string; includeTurns: boolean }; result: { thread: CodexThread }; }; "thread/archive": { params: { threadId: string }; result: Record; }; "turn/start": { params: { threadId: string; input: CodexTurnInput[]; approvalPolicy: "never" }; result: { turn: CodexTurn }; }; "turn/interrupt": { params: { threadId: string; turnId: string }; result: Record; }; }; export type CodexRequestMethod = keyof CodexRequestSpec; export type CodexRequestParams = CodexRequestSpec[Method]["params"]; export type CodexRequestResult = CodexRequestSpec[Method]["result"]; type TokenUsageBreakdown = { inputTokens: number; cachedInputTokens: number; outputTokens: number; reasoningOutputTokens: number; }; type CodexNotificationSpec = { "thread/started": { thread: CodexThread }; "turn/started": { threadId: string; turn: CodexTurn }; "turn/completed": { threadId: string; turn: CodexTurn }; "item/started": { threadId: string; turnId: string; item: CodexItem }; "item/completed": { threadId: string; turnId: string; item: CodexItem }; "item/agentMessage/delta": { threadId: string; turnId: string; itemId: string; delta: string }; "item/plan/delta": { threadId: string; turnId: string; itemId: string; delta: string }; "item/reasoning/summaryTextDelta": { threadId: string; turnId: string; itemId: string; delta: string; summaryIndex: number }; "item/commandExecution/outputDelta": { threadId: string; turnId: string; itemId: string; delta: string }; "thread/tokenUsage/updated": { threadId: string; turnId: string; tokenUsage: { last: TokenUsageBreakdown } }; error: { threadId: string; turnId: string; error: CodexTurnError; willRetry: boolean }; }; export type CodexNotificationMethod = keyof CodexNotificationSpec; export type CodexNotificationParams = CodexNotificationSpec[Method];