import { invoke } from "$lib/runtime/invoke"; import type { BackendCommand, BackendResponse } from "./types"; function newCorrelationId(): string { return `ui-${Date.now()}-${Math.random().toString(16).slice(2)}`; } type SendCommandOptions = { keepalive?: boolean; }; export async function sendCommand( command: BackendCommand, options: SendCommandOptions = {}, ): Promise { const envelope: BackendCommand = { ...command, correlationId: command.correlationId ?? newCorrelationId(), }; const response = await invoke>("sidecar_command", { command: envelope, keepalive: options.keepalive === true, }); if (!response.ok) { throw new Error(response.error || "Backend command failed"); } return response.data; }