diff --git a/ui/src/components/voice/SpekoIncomingCalls.test.tsx b/ui/src/components/voice/SpekoIncomingCalls.test.tsx
index e534bd09476..cf95116c9d9 100644
--- a/ui/src/components/voice/SpekoIncomingCalls.test.tsx
+++ b/ui/src/components/voice/SpekoIncomingCalls.test.tsx
@@ -5,8 +5,8 @@ import {MemoryRouter} from "react-router-dom";
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
import {afterEach, beforeEach, describe, expect, it, vi} from "vitest";
import {SpekoIncomingCalls} from "./SpekoIncomingCalls";
-const mocks = vi.hoisted(() => ({incoming: vi.fn(), list: vi.fn()}));
-vi.mock("@/api/voicePhone", () => ({voicePhoneApi: {incoming: mocks.incoming}}));
+const mocks = vi.hoisted(() => ({incoming: vi.fn(), list: vi.fn(), decide: vi.fn()}));
+vi.mock("@/api/voicePhone", () => ({voicePhoneApi: {incoming: mocks.incoming, decide: mocks.decide}}));
vi.mock("@/api/issues", () => ({issuesApi: {list: mocks.list}}));
describe("incoming call task selection", () => {
let container: HTMLDivElement, root: Root, client: QueryClient;
@@ -16,7 +16,7 @@ describe("incoming call task selection", () => {
root = createRoot(container); client = new QueryClient({defaultOptions: {queries: {retry: false}}});
mocks.incoming.mockResolvedValue([{id: "call", state: "awaiting_approval", approvalCode: "123456"}]);
});
- afterEach(async () => {await act(async () => root.unmount()); client.clear(); container.remove();});
+ afterEach(async () => {await act(async () => root.unmount()); client.clear(); container.remove(); vi.useRealTimers();});
async function render() {await act(async () => root.render( ));}
it("shows task request failures and lets callers retry the existing task inventory", async () => {
mocks.list.mockRejectedValueOnce(new Error("Offline")).mockResolvedValue(tasks); await render();
@@ -36,4 +36,22 @@ describe("incoming call task selection", () => {
await vi.waitFor(() => expect(container.textContent).toContain("Task list could not be loaded"));
expect(container.querySelector('option[value="task"]')).not.toBeNull();
});
+ it("expires a saved approval confirmation when the pending-call list omits it", async () => {
+ mocks.list.mockResolvedValue(tasks);
+ mocks.decide.mockResolvedValue({id: "call", state: "approved", approvalCode: "123456"});
+ await render();
+ await vi.waitFor(() => expect(container.querySelector('input')).not.toBeNull());
+ mocks.incoming.mockResolvedValue([]);
+ const input = container.querySelector('input')!;
+ await act(async () => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, '123456');
+ input.dispatchEvent(new Event('input', {bubbles: true}));
+ });
+ await act(async () => container.querySelector('form')!.dispatchEvent(new Event('submit', {bubbles: true, cancelable: true})));
+ await vi.waitFor(() => expect(container.textContent).toContain('Call approved'));
+ expect(container.textContent).not.toContain('You can now give instructions');
+ await act(async () => { await new Promise(resolve => setTimeout(resolve, 5100)); });
+ expect(container.textContent).not.toContain('Call approved');
+ }, 10000);
+
});
diff --git a/ui/src/components/voice/SpekoIncomingCalls.tsx b/ui/src/components/voice/SpekoIncomingCalls.tsx
index e32b6a567f2..10a3f0e00a7 100644
--- a/ui/src/components/voice/SpekoIncomingCalls.tsx
+++ b/ui/src/components/voice/SpekoIncomingCalls.tsx
@@ -29,12 +29,19 @@ export function SpekoIncomingCallCard({call, tasks = [], busy, error, onDecide}:
{invalid &&
That code does not match this live call. Ask the phone agent to repeat it.
}
{error && {error}
}
onDecide({approve: false, approvalCode: call.approvalCode})}>Deny call {busy ? "Confirming…" : "Approve live call"}
- : {call.state === "approved" ? "You can now give instructions on the phone. Earlier instructions were discarded." : "This call cannot access your private tasks."}
}
+ : {call.state === "approved" ? "Approval was sent for this call. Earlier instructions were discarded. Follow the call in Activity." : "This call cannot access your private tasks."}
}
;
}
export function SpekoIncomingCalls({companyId, endpointId, agentId}: {companyId: string; endpointId: string; agentId: string}) {
const [decision, setDecision] = useState();
const host = useRef(null), restoreTaskFocus = useRef(false);
+ useEffect(() => {
+ if (!decision) return;
+ // The pending-call API omits approved calls; this is a brief confirmation,
+ // not a live status indicator after the caller hangs up.
+ const timeout = setTimeout(() => setDecision(undefined), 5000);
+ return () => clearTimeout(timeout);
+ }, [decision]);
useEffect(() => { setDecision(undefined); restoreTaskFocus.current = false; }, [companyId, endpointId]);
const query = useQuery({queryKey: ["speko-incoming", companyId, endpointId], queryFn: () => voicePhoneApi.incoming(companyId, endpointId), refetchInterval: 2000, retry: false});
const needsTaskSelection = Boolean(query.data?.some(call => ["awaiting_approval", "approving"].includes(call.state)));
diff --git a/ui/storybook/stories/speko/incoming-call.stories.tsx b/ui/storybook/stories/speko/incoming-call.stories.tsx
index 4fdab5cbb4a..5db2d978332 100644
--- a/ui/storybook/stories/speko/incoming-call.stories.tsx
+++ b/ui/storybook/stories/speko/incoming-call.stories.tsx
@@ -55,3 +55,28 @@ export const TaskListFailureAndRecovery: Story = {
await waitFor(() => expect(canvas.getByRole("combobox", {name: "Conversation task"})).toHaveFocus());
},
};
+
+function ApprovalConfirmation() {
+ const [ready, setReady] = useState(false);
+ useLayoutEffect(() => {
+ const originalIncoming = voicePhoneApi.incoming, originalDecide = voicePhoneApi.decide, originalTasks = issuesApi.list;
+ let approved = false;
+ voicePhoneApi.incoming = async () => approved ? [] : [call];
+ voicePhoneApi.decide = async () => { approved = true; return {...call, state: "approved"}; };
+ issuesApi.list = async () => [];
+ setReady(true);
+ return () => { voicePhoneApi.incoming = originalIncoming; voicePhoneApi.decide = originalDecide; issuesApi.list = originalTasks; };
+ }, []);
+ return ready ? : null;
+}
+export const ApprovalConfirmationExpires: Story = {
+ render: () => ,
+ play: async ({canvasElement}) => {
+ const canvas = within(canvasElement);
+ await userEvent.type(await canvas.findByRole("textbox", {name: "Code spoken on your call"}), "123456");
+ await userEvent.click(canvas.getByRole("button", {name: "Approve live call"}));
+ await expect(await canvas.findByRole("heading", {name: "Call approved"})).toHaveFocus();
+ await expect(canvas.getByText(/Approval was sent/)).toBeVisible();
+ await waitFor(() => expect(canvas.queryByRole("heading", {name: "Call approved"})).not.toBeInTheDocument(), {timeout: 6500});
+ },
+};