Files
kandev/apps/web/lib/api/domains/walkthrough-api.ts
T
João Salavisa 5257dfbaab fix(web): close the i18n coverage gaps in the non-JSX scanner and locale catalogs (#2727)
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 23:03:29 +00:00

35 lines
1.3 KiB
TypeScript

import { getWebSocketClient } from "@/lib/ws/connection";
import type { TaskWalkthrough } from "@/lib/types/http";
// i18n-exempt: precondition diagnostic for a programmer error; callers branch
// on the error type, never render this message.
const WS_CLIENT_UNAVAILABLE = "WebSocket client not available";
/**
* Get the agent-authored code walkthrough for a task, or null if none exists.
* Used to backfill the store on mount — live `task.walkthrough.created` events
* can fire before the page's WS subscription is established.
*/
export async function getTaskWalkthrough(taskId: string): Promise<TaskWalkthrough | null> {
const client = getWebSocketClient();
if (!client) {
throw new Error(WS_CLIENT_UNAVAILABLE);
}
const response = await client.request("task.walkthrough.get", { task_id: taskId });
if (!response || typeof response !== "object" || !("id" in response)) {
return null;
}
return response as TaskWalkthrough;
}
/** Delete the current persisted walkthrough for a task. */
export async function deleteTaskWalkthrough(taskId: string): Promise<void> {
const client = getWebSocketClient();
if (!client) {
throw new Error(WS_CLIENT_UNAVAILABLE);
}
await client.request("task.walkthrough.delete", { task_id: taskId }, 10000);
}