fix(renderer): avoid non-iterable provider data

This commit is contained in:
DeskClaw Bot
2026-04-22 04:03:15 +00:00
Unverified
parent b916ff4c74
commit e2717ceb1f
3 changed files with 25 additions and 7 deletions

View File

@@ -89,15 +89,33 @@ function parseUnifiedProxyResponse<T>(
} }
const data: HostApiProxyData = response.data ?? {}; const data: HostApiProxyData = response.data ?? {};
const status = data.status ?? 200;
const ok = typeof data.ok === 'boolean'
? data.ok
: status >= 200 && status < 300;
trackUiEvent('hostapi.fetch', { trackUiEvent('hostapi.fetch', {
path, path,
method, method,
source: 'ipc-proxy', source: 'ipc-proxy',
durationMs: Date.now() - startedAt, durationMs: Date.now() - startedAt,
status: data.status ?? 200, status,
}); });
if (data.status === 204) return undefined as T; if (!ok) {
const json = data.json;
const message = (json && typeof json === 'object' && 'error' in (json as Record<string, unknown>))
? String((json as Record<string, unknown>).error)
: (typeof json === 'string' && json.trim() ? json : (data.text || `HTTP ${status}`));
throw normalizeAppError(new Error(message), {
source: 'ipc-proxy',
path,
method,
status,
});
}
if (status === 204) return undefined as T;
if (data.json !== undefined) return data.json as T; if (data.json !== undefined) return data.json as T;
return data.text as T; return data.text as T;
} }

View File

@@ -77,13 +77,13 @@ export function ChatToolbar() {
const providerVendorById = useMemo(() => { const providerVendorById = useMemo(() => {
const map = new Map<string, ProviderVendorInfo>(); const map = new Map<string, ProviderVendorInfo>();
for (const v of providerVendors) map.set(v.id, v); for (const v of (Array.isArray(providerVendors) ? providerVendors : [])) map.set(v.id, v);
return map; return map;
}, [providerVendors]); }, [providerVendors]);
const providerStatusById = useMemo(() => { const providerStatusById = useMemo(() => {
const map = new Map<string, ProviderWithKeyInfo>(); const map = new Map<string, ProviderWithKeyInfo>();
for (const s of providerStatuses) map.set(s.id, s); for (const s of (Array.isArray(providerStatuses) ? providerStatuses : [])) map.set(s.id, s);
return map; return map;
}, [providerStatuses]); }, [providerStatuses]);

View File

@@ -88,9 +88,9 @@ export const useProviderStore = create<ProviderState>((set, get) => ({
const snapshot = await fetchProviderSnapshot(); const snapshot = await fetchProviderSnapshot();
set({ set({
statuses: snapshot.statuses ?? [], statuses: Array.isArray(snapshot.statuses) ? snapshot.statuses : [],
accounts: snapshot.accounts ?? [], accounts: Array.isArray(snapshot.accounts) ? snapshot.accounts : [],
vendors: snapshot.vendors ?? [], vendors: Array.isArray(snapshot.vendors) ? snapshot.vendors : [],
defaultAccountId: snapshot.defaultAccountId ?? null, defaultAccountId: snapshot.defaultAccountId ?? null,
loading: false loading: false
}); });