5257dfbaab
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
35 lines
1.3 KiB
TypeScript
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);
|
|
}
|