import { trackStudioEvent } from "../utils/studioTelemetry"; export interface ReadFailureState { fileTree: readonly string[]; fileTreeLoaded: boolean; refreshedAbsentPaths: Set; reportFailure: (read: TFailure, projectId: string, pathInTree: boolean | null) => string | null; setUnreachableProject: (value: string | null) => void; setCompositionMissing: (value: boolean) => void; onAbsentRead?: (path: string) => void; } export function applyReadFailure( state: ReadFailureState, read: TFailure, forProjectId: string, forPath: string, ): void { const pathInTree = state.fileTreeLoaded ? state.fileTree.includes(forPath) : null; state.setUnreachableProject(state.reportFailure(read, forProjectId, pathInTree)); state.setCompositionMissing(read.reason === "absent"); if (read.reason !== "absent") return; const key = `${forProjectId}:${forPath}`; if (state.refreshedAbsentPaths.has(key)) return; state.refreshedAbsentPaths.add(key); state.onAbsentRead?.(forPath); } export function reportSessionOpenError(error: unknown): void { trackStudioEvent("sdk_session_unavailable", { stage: "open", error_name: error instanceof Error ? error.name : typeof error, error: error instanceof Error ? error.message : String(error), }); }