import { useState } from "react"; import { useServerFn } from "@tanstack/react-start"; import { AudioLines, Cloud, Mic, MicOff, Phone, PhoneOff } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useGeminiLive } from "@/hooks/use-gemini-live"; import { useAuth } from "@/hooks/use-auth"; import { getCloudWorkspace, startCloudLive } from "@/lib/cloud.functions"; export function CloudVoice({ onPublish }: { onPublish: (id: string, notify: (result: string) => void) => void }) { const startFn = useServerFn(startCloudLive), overview = useServerFn(getCloudWorkspace); const { user } = useAuth(); const [transcript, setTranscript] = useState<{ role: string; text: string }[]>([]); const voice = useGeminiLive({ saveCall: false, assistantName: "Stratus", startSession: name => startFn({ data: { name } }), onEvent: event => { if (event.type === "app.started") setTranscript([]); const delta = event["delta"]; if (typeof delta !== "string") return; const role = event.type === "session.input_transcript.delta" ? "You" : event.type === "session.output_transcript.delta" ? "Stratus" : null; if (!role) return; setTranscript(items => { const last = items.at(-1); return last?.role === role ? [...items.slice(0,-1), { role, text: (last.text + delta).slice(-4000) }] : [...items.slice(-7), { role, text: delta }]; }); }, onToolCall: async call => { if (call.name === "get_cloud_projects") return overview(); if (call.name === "request_publish_project") { const id = call.args?.["buildId"]; const workspace = await overview(); if (typeof id !== "string" || !workspace.projects.some(p => p.latest.id === id)) return { error: "Choose the latest version of one of your saved projects." }; onPublish(id, voice.reportTest); return { awaitingApproval: true, message: "The caller must approve the specific project on screen. It has not been published." }; } return { error: "Stratus only handles cloud project reads and permission requests." }; }, }); const active = voice.status === "connecting" || voice.status === "connected"; return

Stratus CLOUD VOICE

{voice.status === "connecting" ? "Connecting…" : voice.status === "connected" ? voice.muted ? "Microphone muted" : voice.phase === "speaking" ? "Stratus speaking" : "Listening" : "Your cloud, in conversation"}

{active ? <> : }
{voice.error &&

{voice.error}

} {transcript.length > 0 &&
{transcript.map((m,i) =>

{m.role}{m.text}

)}
}
; }