diff --git a/packages/mobile-voice/src/app/index.tsx b/packages/mobile-voice/src/app/index.tsx index c7e9dfcba1..9c91c06c0e 100644 --- a/packages/mobile-voice/src/app/index.tsx +++ b/packages/mobile-voice/src/app/index.tsx @@ -292,6 +292,34 @@ function findLatestAssistantCompletionText(payload: unknown): string { return "" } +type SessionItem = { + id: string + title: string + updated: number +} + +type ServerSessionPayload = { + id?: unknown + title?: unknown + time?: { + updated?: unknown + } +} + +function parseSessionItems(payload: unknown): SessionItem[] { + if (!Array.isArray(payload)) return [] + + return payload + .filter((item): item is ServerSessionPayload => !!item && typeof item === "object") + .map((item) => ({ + id: String(item.id ?? ""), + title: String(item.title ?? item.id ?? "Untitled session"), + updated: Number(item.time?.updated ?? 0), + })) + .filter((item) => item.id.length > 0) + .sort((a, b) => b.updated - a.updated) +} + type ServerItem = { id: string name: string @@ -304,12 +332,6 @@ type ServerItem = { sessionsLoading: boolean } -type SessionItem = { - id: string - title: string - updated: number -} - type MonitorJob = { id: string sessionID: string @@ -2275,16 +2297,7 @@ export default function DictationScreen() { } const json = sessionsRes.ok ? await sessionsRes.json() : [] - const sessions: SessionItem[] = Array.isArray(json) - ? json - .map((item: any) => ({ - id: String(item.id ?? ""), - title: String(item.title ?? item.id ?? "Untitled session"), - updated: Number(item?.time?.updated ?? 0), - })) - .filter((s) => s.id.length > 0) - .sort((a, b) => b.updated - a.updated) - : [] + const sessions = parseSessionItems(json) setServers((prev) => prev.map((s) => (s.id === serverID ? { ...s, status: "online", sessionsLoading: false, sessions } : s)),