/** * Session suggested-fix + resolution-note preview API (Phase 3). * * Mirrors backend endpoints under /api/v1/ai-sessions/{id}/... * See FLOWPILOT-MIGRATION.md Sections 5.2 + 5.4. */ import apiClient from './client' export type UserDecision = 'one_off' | 'draft_template' | 'build_template' | 'dismissed' export interface SessionSuggestedFix { id: string session_id: string title: string description: string confidence_pct: number script_template_id: string | null ai_drafted_script: string | null ai_drafted_parameters: Record | null user_decision: UserDecision | null superseded_at: string | null created_at: string } export interface DecisionResponse { id: string user_decision: UserDecision rendered_script: string | null redirect_path: string | null } export interface ResolutionNotePreview { markdown: string target_ticket_ref: string | null state_version: number from_cache: boolean } export const sessionSuggestedFixesApi = { /** * Returns the active suggested fix for a session, or `null` if there isn't one. * The endpoint returns 404 in the no-fix case, which is normal — we coerce * to null so callers don't have to distinguish "no fix" from "request failed". */ async getActive(sessionId: string): Promise { try { const r = await apiClient.get( `/ai-sessions/${sessionId}/suggested-fixes/active`, ) return r.data } catch (err) { const status = (err as { response?: { status?: number } })?.response?.status if (status === 404) return null throw err } }, async recordDecision( sessionId: string, fixId: string, decision: UserDecision, ): Promise { const r = await apiClient.post( `/ai-sessions/${sessionId}/suggested-fixes/${fixId}/decision`, { decision }, ) return r.data }, /** * Fetch (or get cached) draft markdown for the Resolve note. Backend cache * is keyed on state_version, so calling this back-to-back without intervening * fact / suggested-fix / script-generation writes returns the same payload * cheaply (no Sonnet call). */ async getResolutionNotePreview(sessionId: string): Promise { const r = await apiClient.post( `/ai-sessions/${sessionId}/resolution-note/preview`, ) return r.data }, } export default sessionSuggestedFixesApi