(cmd: string, args?: Record<string, unknown>)
| 30 | } |
| 31 | |
| 32 | export async function invoke<T>(cmd: string, args?: Record<string, unknown>): Promise<T> { |
| 33 | if (isTauri()) return tauriInvoke<T>(cmd, args); |
| 34 | const response = await fetch("/api/invoke", { |
| 35 | method: "POST", |
| 36 | headers: { |
| 37 | "Content-Type": "application/json", |
| 38 | ...(token ? { Authorization: `Bearer ${token}` } : {}), |
| 39 | }, |
| 40 | body: JSON.stringify({ cmd, args: args ?? {} }), |
| 41 | }); |
| 42 | const body = await response.json().catch(() => null); |
| 43 | if (!response.ok) { |
| 44 | throw new Error(body?.error ?? `HTTP ${response.status}`); |
| 45 | } |
| 46 | return body as T; |
| 47 | } |
| 48 | |
| 49 | export async function ask(message: string, options?: AskOptions): Promise<boolean> { |
| 50 | if (isTauri()) return tauriAsk(message, options); |
no test coverage detected