import type { createOwnerClient } from "./owner-client"; export type SettingsConnection = ReturnType | null; export type SettingsConnectionProps = { connection: SettingsConnection; connected: boolean; connecting: boolean; }; // Agents 0.22 has RPC timeouts, but no per-call AbortSignal. Check cancellation // before and after the native call; Query cancellation cannot stop server work. export async function callOwner( connection: SettingsConnection, method: string, args: unknown[] = [], signal?: AbortSignal, ): Promise { signal?.throwIfAborted(); if (!connection?.isReady() || !navigator.onLine) throw new Error("Owner connection unavailable"); const client = await connection.ready; signal?.throwIfAborted(); if (!connection.isReady() || !navigator.onLine) throw new Error("Owner connection retired"); const value = await client.call(method, args); signal?.throwIfAborted(); if (!connection.isCurrent()) throw new Error("Owner connection retired"); return value; }