Merge final Speko setup recovery into qualification

Co-Authored-By: Paperclip <noreply@paperclip.ing>

* codex/speko-voice-ui:
  fix(ui): recover interrupted Speko credential setup
  fix(voice): expose callback secret presence for setup recovery
This commit is contained in:
DottaandPaperclip committed 2026-10-09 21:10:10 -05:00
commit 2eb76dce95
6 files changed
+55 -6

No files matched your search

@@ -63,6 +63,15 @@ const support = await getEmbeddedPostgresTestSupport();
return { companyId, endpointId, agentId, connectionId, issueId, conversationId, callerId, sessionId, store, request, reserved, accept, toolInput, publication };
}
it("reports signing-secret presence for interrupted setup without returning credential refs", async () => {
const f = await fixture();
const chat = chatChannelService(db, {heartbeat: {wakeup: vi.fn()}});
expect((await chat.get(f.endpointId)).setup.webhookSecretConfigured).toBe(false);
await db.update(toolConnections).set({credentialSecretRefs: [{configPath: "credentials.signingSecret", secretId: randomUUID()}]}).where(eq(toolConnections.id, f.connectionId));
const endpoint = await chat.get(f.endpointId);
expect(endpoint.setup.webhookSecretConfigured).toBe(true);
expect(endpoint).not.toHaveProperty("credentialSecretRefs");
});
it("deduplicates concurrent session requests before creating a second task", async () => {
const f = await fixture();
const results = await Promise.all([f.store.reserve(f.request), f.store.reserve(f.request)]);
+5 -1
View File
@@ -5886,7 +5886,11 @@ export function chatChannelService(db: Db, options: ChatChannelServiceOptions) {
(ref) => ref.configPath === "credentials.webhookSecret",
),
}
: {}),
: endpoint.provider === "speko" ? {
webhookSecretConfigured: row.credentialSecretRefs.some(
(ref) => ref.configPath === "credentials.signingSecret",
),
} : {}),
},
healthMessage: endpoint.healthMessage,
lastError: endpoint.lastError,
@@ -0,0 +1,20 @@
// @vitest-environment jsdom
import {act} from "react";
import {createRoot} from "react-dom/client";
import {expect, it, vi} from "vitest";
import {SpekoProviderSetup} from "./SpekoProviderSetup";
it("recovers interrupted setup with a signing secret, and preserves saved secrets on reconnect", async () => {
const onConnect = vi.fn(), onChange = vi.fn();
const props = {agentName: "Agent", callbackUrl: "https://test.invalid/callback", repairing: true,
credentials: {apiKey: "synthetic", agentId: "agent_fixture"}, onConnect, onChange};
const container = document.createElement("div"), root = createRoot(container);
document.body.append(container);
try {
await act(async () => root.render(<SpekoProviderSetup {...props} signingSecretConfigured={false} />));
await act(async () => (container.querySelector("button:last-child") as HTMLButtonElement).click());
expect(onConnect).toHaveBeenLastCalledWith(expect.objectContaining({signingSecret: expect.stringMatching(/^whsec_/)}));
await act(async () => root.render(<SpekoProviderSetup {...props} signingSecretConfigured />));
await act(async () => (container.querySelector("button:last-child") as HTMLButtonElement).click());
expect(onConnect).toHaveBeenLastCalledWith(props.credentials);
} finally { await act(async () => root.unmount()); container.remove(); }
});
@@ -11,14 +11,17 @@ export interface SpekoProviderSetupProps {
callbackUrl?: string | null;
pending?: boolean;
repairing?: boolean;
/** Presence only; existing callback secrets never reach the browser. */
signingSecretConfigured?: boolean;
}
export function SpekoProviderSetup({ agentName, onSaveExit, credentials, onChange, onConnect, callbackUrl, pending = false, repairing = false }: SpekoProviderSetupProps) {
const ready = repairing || Boolean(credentials.apiKey?.trim() && credentials.agentId?.trim());
export function SpekoProviderSetup({ agentName, onSaveExit, credentials, onChange, onConnect, callbackUrl, pending = false, repairing = false, signingSecretConfigured }: SpekoProviderSetupProps) {
const hasSavedSecret = signingSecretConfigured ?? repairing;
const ready = repairing && hasSavedSecret || Boolean(credentials.apiKey?.trim() && credentials.agentId?.trim());
const reachable = callbackUrl?.startsWith("https://") === true;
function connect() {
if (!ready || !reachable || pending) return;
const values = Object.fromEntries(Object.entries(credentials).filter(([, value]) => value.trim()));
if (!repairing && !values.signingSecret) {
if (!hasSavedSecret && !values.signingSecret) {
const bytes = crypto.getRandomValues(new Uint8Array(32));
values.signingSecret = `whsec_${btoa(String.fromCharCode(...bytes))}`;
onChange(values);
+1 -1
View File
@@ -898,7 +898,7 @@ function ProviderConnectStep({
null,
2,
);
if (provider === "speko") return <SpekoProviderSetup onSaveExit={() => navigate("/apps")} agentName={agentName} credentials={credentials} onChange={setCredentials} onConnect={(values) => onAction(repairing ? "reconnect" : "configure", values)} callbackUrl={endpoint.setup?.webhookUrl} pending={pending} repairing={repairing} />;
if (provider === "speko") return <SpekoProviderSetup onSaveExit={() => navigate("/apps")} agentName={agentName} credentials={credentials} onChange={setCredentials} onConnect={(values) => onAction(repairing ? "reconnect" : "configure", values)} callbackUrl={endpoint.setup?.webhookUrl} pending={pending} repairing={repairing} signingSecretConfigured={endpoint.setup?.webhookSecretConfigured} />;
if (provider === "imessage-photon") return <PhotonConnectStep endpoint={endpoint} agentName={agentName} repairing={repairing} pending={pending} onAction={onAction} />;
if (provider === "discord") {
const applicationId = credentials.applicationId?.trim() ?? "";
@@ -6,7 +6,7 @@ import { voiceStoryLifecycle } from "../fixtures/voiceStoryLifecycle";
function Fixture(props: Partial<SpekoProviderSetupProps>) {
const [credentials, setCredentials] = useState(props.credentials ?? {});
const [connected, setConnected] = useState(false);
return connected ? <p role="status">Credentials saved. Continue to the test conversation.</p> : <SpekoProviderSetup onSaveExit={() => {}} agentName="Company Phone Agent" callbackUrl="https://paperclip.example/api/voice-webhooks/endpoint/tools" {...props} credentials={credentials} onChange={setCredentials} onConnect={(values) => { if (!props.repairing && !values.signingSecret?.startsWith("whsec_")) throw new Error("Missing signing secret"); setConnected(true); }} />;
return connected ? <p role="status">Credentials saved. Continue to the test conversation.</p> : <SpekoProviderSetup onSaveExit={() => {}} agentName="Company Phone Agent" callbackUrl="https://paperclip.example/api/voice-webhooks/endpoint/tools" {...props} credentials={credentials} onChange={setCredentials} onConnect={(values) => { if ((!props.repairing || props.signingSecretConfigured === false) && !values.signingSecret?.startsWith("whsec_")) throw new Error("Missing signing secret"); setConnected(true); }} />;
}
const meta: Meta<typeof SpekoProviderSetup> = { ...voiceStoryLifecycle, title: "Connections/Speko/Provider setup", component: SpekoProviderSetup, parameters: { layout: "padded" } };
export default meta;
@@ -37,3 +37,16 @@ export const KeyboardValidationAndConnect: Story = {
await expect(canvas.getByRole("status")).toHaveTextContent("Credentials saved");
},
};
export const InterruptedBeforeCredentials: Story = {
render: () => <Fixture repairing signingSecretConfigured={false} />,
play: async ({canvasElement}) => {
const canvas = within(canvasElement);
const connect = canvas.getByRole("button", {name: "Reconnect Speko"});
await expect(connect).toBeDisabled();
await userEvent.type(canvas.getByRole("textbox", {name: "Speko agent ID"}), "agent_fixture");
await userEvent.type(canvas.getByLabelText("Speko API key"), "synthetic-not-a-key");
await userEvent.click(connect);
await expect(canvas.getByRole("status")).toHaveTextContent("Credentials saved");
},
};