| import { |
| getActiveBackend, |
| getRegisteredBackends, |
| } from "../backend-registry/active-store"; |
| import type { Backend } from "../backend-registry/types"; |
| import { getStoredConversationMetadata } from "../conversation-metadata-store"; |
| import type { |
| AppConversation, |
| AppConversationPage, |
| AppConversationStartRequest, |
| AppConversationStartTask, |
| } from "../conversation-service/agent-server-conversation-service.types"; |
| import { AGENT_CANVAS_CLIENT_HEADERS } from "../client-source"; |
| import { callCloudProxy } from "./proxy"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| function overlayStoredRepoSelection( |
| conversation: AppConversation | null, |
| ): AppConversation | null { |
| if (!conversation?.id) return conversation; |
| const stored = getStoredConversationMetadata(conversation.id); |
| if (!stored) return conversation; |
|
|
| return { |
| ...conversation, |
| selected_repository: |
| conversation.selected_repository ?? stored.selected_repository ?? null, |
| selected_branch: |
| conversation.selected_branch ?? stored.selected_branch ?? null, |
| git_provider: conversation.git_provider ?? stored.git_provider ?? null, |
| selected_workspace: |
| conversation.selected_workspace ?? stored.selected_workspace ?? null, |
| }; |
| } |
|
|
| function getActiveCloudBackend(): Backend { |
| const active = getActiveBackend().backend; |
| if (active.kind !== "cloud") { |
| throw new Error("Cloud conversations call requires a cloud backend."); |
| } |
| return active; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function pickCloudBackendForLaunch(): Backend | null { |
| const active = getActiveBackend().backend; |
| if (active.kind === "cloud") return active; |
| return ( |
| getRegisteredBackends().find( |
| (backend) => backend.kind === "cloud" && !!backend.apiKey, |
| ) ?? null |
| ); |
| } |
|
|
| |
| |
| |
| |
| |
| export async function searchCloudConversations( |
| limit: number = 20, |
| pageId?: string, |
| ): Promise<AppConversationPage> { |
| const backend = getActiveCloudBackend(); |
| const params = new URLSearchParams(); |
| params.set("limit", String(limit)); |
| if (pageId) params.set("page_id", pageId); |
| params.set("sort_order", "UPDATED_AT_DESC"); |
|
|
| const data = await callCloudProxy<{ |
| items: AppConversation[]; |
| next_page_id: string | null; |
| }>({ |
| backend, |
| method: "GET", |
| path: `/api/v1/app-conversations/search?${params.toString()}`, |
| }); |
|
|
| return { |
| items: (data?.items ?? []).map( |
| (item) => overlayStoredRepoSelection(item) as AppConversation, |
| ), |
| next_page_id: data?.next_page_id ?? null, |
| }; |
| } |
|
|
| |
| |
| |
| |
| export async function batchGetCloudConversations( |
| ids: string[], |
| ): Promise<(AppConversation | null)[]> { |
| if (ids.length === 0) return []; |
| const backend = getActiveCloudBackend(); |
| const params = new URLSearchParams(); |
| for (const id of ids) params.append("ids", id); |
| const data = await callCloudProxy<(AppConversation | null)[]>({ |
| backend, |
| method: "GET", |
| path: `/api/v1/app-conversations?${params.toString()}`, |
| }); |
| return (data ?? []).map(overlayStoredRepoSelection); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export async function createCloudAppConversation( |
| request: AppConversationStartRequest, |
| |
| |
| backendOverride?: Backend, |
| ): Promise<AppConversationStartTask> { |
| const backend = backendOverride ?? getActiveCloudBackend(); |
| const data = await callCloudProxy<AppConversationStartTask>({ |
| backend, |
| method: "POST", |
| path: "/api/v1/app-conversations", |
| body: request as unknown as Record<string, unknown>, |
| headers: AGENT_CANVAS_CLIENT_HEADERS, |
| }); |
| return data; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export async function downloadCloudConversation( |
| conversationId: string, |
| ): Promise<Blob> { |
| const backend = getActiveCloudBackend(); |
| return callCloudProxy<Blob>({ |
| backend, |
| method: "GET", |
| path: `/api/v1/app-conversations/${conversationId}/download`, |
| responseType: "blob", |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export async function deleteCloudConversation( |
| conversationId: string, |
| ): Promise<void> { |
| const backend = getActiveCloudBackend(); |
| await callCloudProxy<unknown>({ |
| backend, |
| method: "DELETE", |
| path: `/api/v1/app-conversations/${conversationId}`, |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function updateCloudConversationPublicFlag( |
| conversationId: string, |
| isPublic: boolean, |
| ): Promise<AppConversation> { |
| const backend = getActiveCloudBackend(); |
| const data = await callCloudProxy<AppConversation>({ |
| backend, |
| method: "PATCH", |
| path: `/api/v1/app-conversations/${conversationId}`, |
| body: { public: isPublic }, |
| }); |
| return data; |
| } |
|
|
| |
| |
| |
| |
| |
| export async function updateCloudConversationTitle( |
| conversationId: string, |
| title: string, |
| ): Promise<AppConversation> { |
| const backend = getActiveCloudBackend(); |
| return callCloudProxy<AppConversation>({ |
| backend, |
| method: "PATCH", |
| path: `/api/v1/app-conversations/${conversationId}`, |
| body: { title }, |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function pauseCloudSandbox(sandboxId: string): Promise<void> { |
| const backend = getActiveCloudBackend(); |
| await callCloudProxy<unknown>({ |
| backend, |
| method: "POST", |
| path: `/api/v1/sandboxes/${sandboxId}/pause`, |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export async function resumeCloudSandbox(sandboxId: string): Promise<void> { |
| const backend = getActiveCloudBackend(); |
| await callCloudProxy<unknown>({ |
| backend, |
| method: "POST", |
| path: `/api/v1/sandboxes/${sandboxId}/resume`, |
| }); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export async function readCloudConversationFile( |
| conversationId: string, |
| filePath: string, |
| ): Promise<string> { |
| const backend = getActiveCloudBackend(); |
| const params = new URLSearchParams(); |
| params.append("file_path", filePath); |
| const data = await callCloudProxy<string>({ |
| backend, |
| method: "GET", |
| path: `/api/v1/app-conversations/${conversationId}/file?${params.toString()}`, |
| }); |
| return data ?? ""; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export async function listCloudConversationFiles( |
| conversationId: string, |
| path: string, |
| ): Promise<string[]> { |
| const backend = getActiveCloudBackend(); |
| const params = new URLSearchParams(); |
| params.append("path", path); |
| const data = await callCloudProxy<string[]>({ |
| backend, |
| method: "GET", |
| path: `/api/v1/app-conversations/${conversationId}/files?${params.toString()}`, |
| }); |
| return Array.isArray(data) ? data : []; |
| } |
|
|
| |
| |
| |
| |
| |
| export async function getCloudAppConversationStartTask( |
| taskId: string, |
| backendOverride?: Backend, |
| ): Promise<AppConversationStartTask | null> { |
| const backend = backendOverride ?? getActiveCloudBackend(); |
| const params = new URLSearchParams(); |
| params.set("ids", taskId); |
| const data = await callCloudProxy<(AppConversationStartTask | null)[]>({ |
| backend, |
| method: "GET", |
| path: `/api/v1/app-conversations/start-tasks?${params.toString()}`, |
| }); |
| return data?.[0] ?? null; |
| } |
|
|