diff --git a/ui/src/components/voice/SpekoCallHistory.test.tsx b/ui/src/components/voice/SpekoCallHistory.test.tsx
new file mode 100644
index 00000000000..d3cb69dbe3a
--- /dev/null
+++ b/ui/src/components/voice/SpekoCallHistory.test.tsx
@@ -0,0 +1,41 @@
+// @vitest-environment jsdom
+import { act } from "react";
+import { createRoot, type Root } from "react-dom/client";
+import { MemoryRouter } from "react-router-dom";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { SpekoCallHistory } from "./SpekoCallHistory";
+import { callHistoryFixture } from "../../../storybook/fixtures/spekoCallHistory";
+const mocks = vi.hoisted(() => ({list: vi.fn(), incoming: vi.fn(), end: vi.fn()}));
+vi.mock("@/api/voiceHistory", () => ({voiceHistoryApi: {list: mocks.list}}));
+vi.mock("@/api/voicePhone", () => ({voicePhoneApi: {history: mocks.incoming}}));
+vi.mock("@/api/voiceSessions", () => ({voiceSessionsApi: {end: mocks.end}}));
+
+describe("saved Speko call history", () => {
+ let container: HTMLDivElement, root: Root, query: QueryClient;
+ beforeEach(() => {
+ vi.clearAllMocks(); container = document.createElement("div"); document.body.append(container);
+ root = createRoot(container); query = new QueryClient({defaultOptions: {queries: {retry: false}, mutations: {retry: false}}});
+ mocks.list.mockResolvedValue([callHistoryFixture]); mocks.incoming.mockResolvedValue([]);
+ });
+ afterEach(async () => {await act(async () => root.unmount()); query.clear(); container.remove();});
+ async function render() {
+ await act(async () => root.render( ));
+ }
+ it("keeps completed call transcripts when paused inbound admission cannot load", async () => {
+ mocks.incoming.mockRejectedValue(new Error("Connection is paused")); await render();
+ await vi.waitFor(() => expect(container.textContent).toContain("Unapproved calls could not be loaded"));
+ expect(container.querySelector("summary")?.textContent).toContain("Completed");
+ expect(container.querySelector('[aria-label="Call transcript"]')).not.toBeNull();
+ });
+ it("keeps readable call history after a failed end-call request", async () => {
+ mocks.list.mockResolvedValue([{...callHistoryFixture, session: {...callHistoryFixture.session, state: "active", endedAt: null}}]);
+ mocks.end.mockRejectedValue(new Error("Provider unavailable")); await render();
+ await vi.waitFor(() => expect(container.querySelector("summary")).not.toBeNull());
+ const end = [...container.querySelectorAll("button")].find(button => button.textContent === "End call")!;
+ await act(async () => end.click());
+ await vi.waitFor(() => expect(container.textContent).toContain("The call could not be ended"));
+ expect(container.querySelector("summary")?.textContent).toContain("In progress");
+ expect(container.querySelector('[aria-label="Call transcript"]')).not.toBeNull();
+ });
+});
diff --git a/ui/src/components/voice/SpekoCallHistory.tsx b/ui/src/components/voice/SpekoCallHistory.tsx
index 665f936ad86..72d1366b8cf 100644
--- a/ui/src/components/voice/SpekoCallHistory.tsx
+++ b/ui/src/components/voice/SpekoCallHistory.tsx
@@ -41,22 +41,24 @@ export function SpekoCallActivityItem({ entry: { session, report }, onEnd, endin
export function SpekoUnapprovedCallActivityItem({ call, presentation = "history" }: { call: VoiceUnapprovedCallHistoryEntry; presentation?: "history" | "activity" }) {
return
{call.state === "denied" ? "Call denied" : call.state === "expired" ? "Approval expired" : "Missed call"} · {new Date(call.createdAt).toLocaleString()}
No private task was connected.
;
}
-export interface SpekoCallHistoryViewProps { entries?: VoiceCallHistoryEntry[]; unapprovedCalls?: VoiceUnapprovedCallHistoryEntry[]; loading?: boolean; error?: string; onRetry(): void; onEnd?(sessionId: string): void; endingSessionId?: string }
-export function SpekoCallHistoryView({ entries = [], unapprovedCalls = [], loading, error, onRetry, onEnd, endingSessionId }: SpekoCallHistoryViewProps) {
+export interface SpekoCallHistoryViewProps { entries?: VoiceCallHistoryEntry[]; unapprovedCalls?: VoiceUnapprovedCallHistoryEntry[]; loading?: boolean; error?: string; incomingError?: string; endError?: string; onRetry(): void; onEnd?(sessionId: string): void; endingSessionId?: string }
+export function SpekoCallHistoryView({ entries = [], unapprovedCalls = [], loading, error, incomingError, endError, onRetry, onEnd, endingSessionId }: SpekoCallHistoryViewProps) {
return
Your calls Refresh
{loading && Loading calls…
}
{error && }
- {!loading && !error && !entries.length && !unapprovedCalls.length && Your browser conversations and phone calls will appear here.
}
+ {incomingError && Unapproved calls could not be loaded. {incomingError}
}
+ {endError && The call could not be ended. {endError}
}
+ {!loading && !error && !incomingError && !entries.length && !unapprovedCalls.length && Your browser conversations and phone calls will appear here.
}
{!error && entries.map(entry => )}
- {!error && unapprovedCalls.length > 0 && Unapproved incoming calls {unapprovedCalls.map(call => )} }
+ {!incomingError && unapprovedCalls.length > 0 && Unapproved incoming calls {unapprovedCalls.map(call => )} }
;
}
export function useSpekoCallHistory(companyId: string, endpointId: string, enabled = true) {
const query = useQuery({ queryKey: ["speko-history", companyId, endpointId], queryFn: () => voiceHistoryApi.list(companyId, endpointId), enabled, retry: false, refetchInterval: enabled ? 30_000 : false });
const incoming = useQuery({queryKey: ["speko-unapproved-history", companyId, endpointId], queryFn: () => voicePhoneApi.history(companyId, endpointId), retry: false, enabled: enabled && query.isSuccess, refetchInterval: enabled ? 30_000 : false});
const ending = useMutation({mutationFn: (sessionId: string) => voiceSessionsApi.end(companyId, sessionId), onSuccess: () => query.refetch()});
- return { entries: query.data ?? [], unapprovedCalls: incoming.data ?? [], loading: query.isLoading || incoming.isLoading, error: (ending.error ?? query.error ?? incoming.error)?.message, endingSessionId: ending.isPending ? ending.variables : undefined,
+ return { entries: query.data ?? [], unapprovedCalls: incoming.data ?? [], loading: query.isLoading || incoming.isLoading, error: query.error?.message, incomingError: incoming.error?.message, endError: ending.error?.message, endingSessionId: ending.isPending ? ending.variables : undefined,
onEnd: (sessionId: string) => ending.mutate(sessionId), onRetry: () => { ending.reset(); void query.refetch(); void incoming.refetch(); } };
}
export function SpekoCallHistory({ companyId, endpointId }: { companyId: string; endpointId: string }) {
diff --git a/ui/src/lib/voice-call-attempt.test.ts b/ui/src/lib/voice-call-attempt.test.ts
index 4c2d4e9d5fc..ac77b22f68b 100644
--- a/ui/src/lib/voice-call-attempt.test.ts
+++ b/ui/src/lib/voice-call-attempt.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest";
+import type { voiceSessionsApi } from "@/api/voiceSessions";
import type { VoiceSession, VoiceSessionMedia } from "@paperclipai/shared";
import { createVoiceCallAttempt, voiceCallJournal } from "./voice-call-attempt";
import { ApiError } from "@/api/client";
@@ -9,7 +10,7 @@ function fixture() {
const storage = { getItem: (key: string) => rows.get(key) ?? null, setItem: (key: string, value: string) => { rows.set(key, value); }, removeItem: (key: string) => { rows.delete(key); } };
const session = { id: "session", state: "active" } as VoiceSession;
const media = { sessionId: "session", generation: 1, transportToken: "must-never-be-saved", transportUrl: "wss://test.invalid" } satisfies VoiceSessionMedia;
- const client = { start: vi.fn(async () => ({ session, media })), end: vi.fn(async () => ({ ...session, state: "ended" as const })), get: vi.fn(async () => session), notification: vi.fn(async () => null) };
+ const client = { start: vi.fn(async (..._args: Parameters) => ({ session, media })), end: vi.fn(async () => ({ ...session, state: "ended" as const })), get: vi.fn(async () => session), notification: vi.fn(async () => null) };
const journal = voiceCallJournal(storage, "company", "operator");
return { rows, storage, client, journal };
}
diff --git a/ui/src/pages/apps/chat/ChatEndpointDetail.tsx b/ui/src/pages/apps/chat/ChatEndpointDetail.tsx
index 4c3dcd4c85e..d13701e915c 100644
--- a/ui/src/pages/apps/chat/ChatEndpointDetail.tsx
+++ b/ui/src/pages/apps/chat/ChatEndpointDetail.tsx
@@ -1005,7 +1005,7 @@ function Activity({
const activityEntries = [
...(!query.isError ? rows.map(item => ({ kind: "connection" as const, id: `connection:${item.id}`, createdAt: item.createdAt, item })) : []),
...(!cursor && !calls.error ? calls.entries.map(entry => ({ kind: "call" as const, id: `call:${entry.session.id}`, createdAt: entry.session.createdAt, entry })) : []),
- ...(!cursor && !calls.error ? calls.unapprovedCalls.map(call => ({ kind: "unapproved_call" as const, id: `unapproved:${call.id}`, createdAt: call.createdAt, call })) : []),
+ ...(!cursor && !calls.incomingError ? calls.unapprovedCalls.map(call => ({ kind: "unapproved_call" as const, id: `unapproved:${call.id}`, createdAt: call.createdAt, call })) : []),
].sort((a, b) => b.createdAt.localeCompare(a.createdAt) || a.id.localeCompare(b.id));
const { status } = endpoint;
@@ -1201,7 +1201,11 @@ function Activity({
)}
- {calls.error && endpoint.provider === "speko" && !cursor && Call activity could not be loaded. {calls.error}
Retry calls }
+ {endpoint.provider === "speko" && !cursor && [
+ calls.error && `Call activity could not be loaded. ${calls.error}`,
+ calls.incomingError && `Unapproved calls could not be loaded. ${calls.incomingError}`,
+ calls.endError && `The call could not be ended. ${calls.endError}`,
+ ].filter(Boolean).map((message) => )}
{activityEntries.map(entry => {
if (entry.kind === "call") return ;
if (entry.kind === "unapproved_call") return ;
@@ -1267,7 +1271,7 @@ function Activity({
);
})}
- {!query.isLoading && !query.isError && !calls.loading && !calls.error && activityEntries.length === 0 && (
+ {!query.isLoading && !query.isError && !calls.loading && !calls.error && !calls.incomingError && activityEntries.length === 0 && (
No connection activity yet.
diff --git a/ui/storybook/stories/speko/call-history.stories.tsx b/ui/storybook/stories/speko/call-history.stories.tsx
index e311fc00353..e6512332345 100644
--- a/ui/storybook/stories/speko/call-history.stories.tsx
+++ b/ui/storybook/stories/speko/call-history.stories.tsx
@@ -35,3 +35,12 @@ export const ActivityEndCallFocus: Story = { render: function ActivityFocusFixtu
const [ended, setEnded] = useState(false);
return setEnded(true)} entry={{...entry, session: {...entry.session, state: ended ? "ended" : "active", endedAt: ended ? entry.session.endedAt : null}}} />;
}, play: EndCallFocus.play };
+
+export const IncomingFailurePreservesHistory: Story = { args: { entries: [entry], incomingError: "This connection is paused." }, play: async ({canvasElement}) => {
+ const c = within(canvasElement); await expect(c.getByRole("alert")).toHaveTextContent("Unapproved calls could not be loaded");
+ await userEvent.click(canvasElement.querySelector("summary")!); await expect(c.getByRole("list", {name: "Call transcript"})).toBeVisible();
+} };
+export const EndFailurePreservesHistory: Story = { args: { entries: [entry], endError: "Try again after reconnecting." }, play: async ({canvasElement}) => {
+ const c = within(canvasElement); await expect(c.getByRole("alert")).toHaveTextContent("The call could not be ended");
+ await userEvent.click(canvasElement.querySelector("summary")!); await expect(c.getByRole("link", {name: "Conversation task"})).toBeVisible();
+} };