export interface RadioSessionResponse { session_id: string flow_slug: string current_state: string variables: Record flags: Record expected_pilot_template: string | null } export interface RadioTransmitResponse { session_id: string next_state_id: string active_flow: string controller_say_template: string | null controller_say_rendered: string | null expected_pilot_template: string | null variables: Record flags: Record trace: Array<{ type: string; message: string }> fallback_used: boolean fallback_reason: string | null auto_advanced_states?: string[] /** True when the full chain is done — show the completion screen. */ session_complete?: boolean } export function useRadioBackend() { const config = useRuntimeConfig() function baseUrl(): string { return (config.public.radioBackendUrl as string) || 'http://127.0.0.1:8000' } async function createSession( flowSlug: string, variables?: Record, noChain: boolean = false, ): Promise { return await $fetch(`${baseUrl()}/api/radio/session`, { method: 'POST', body: { flow_slug: flowSlug, variables: variables ?? null, no_chain: noChain }, }) } async function transmit(sessionId: string, pilotUtterance: string): Promise { return await $fetch( `${baseUrl()}/api/radio/session/${sessionId}/transmissions`, { method: 'POST', body: { pilot_utterance: pilotUtterance }, }, ) } async function deleteSession(sessionId: string): Promise { await $fetch(`${baseUrl()}/api/radio/session/${sessionId}`, { method: 'DELETE' }) } async function fetchFlows(): Promise { return await $fetch(`${baseUrl()}/api/decision-flows/runtime`) } return { createSession, transmit, deleteSession, fetchFlows } }