stan44 069b38071c Added Web WebGateway
Added connector so gateway works.
scripts are much more polished and functional.
2026-02-27 11:03:53 -06:00

28 lines
769 B
TypeScript

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<T>(command: BackendCommand, options: SendCommandOptions = {}): Promise<T> {
const envelope: BackendCommand = {
...command,
correlationId: command.correlationId ?? newCorrelationId()
};
const response = await invoke<BackendResponse<T>>("sidecar_command", {
command: envelope,
keepalive: options.keepalive === true
});
if (!response.ok) {
throw new Error(response.error || "Backend command failed");
}
return response.data;
}