import { type ThisComputerErrorCode, type ThisComputerPermissionId, type ThisComputerWaitingOn } from "@opengeni/sdk/this-computer"; import type { OpenGeniText } from "../../messages/runtime.js"; import type { ThisComputerLabels } from "./labels.js"; import type { UseThisComputerResult } from "./use-this-computer.js"; /** * What is wrong while computer use is on: a sign-in, a server that can't be * reached at all, turning on that has waited too long (`stalled`, with what it * waits for), or anything else (with the server's or agent's own words when * there are some). A missing permission is not one of these: see * `needs_permission`. */ export type ComputerUseProblem = "signed_out" | "offline" | "stalled" | "error"; export type ComputerUseState = /** Outside a desktop app that can host the agent, or not read yet. */ { kind: "hidden"; } /** Never set up, turned off (paused), or removed on the server: all look the same. */ | { kind: "off"; } /** * Being turned on; `progress` while the agent downloads (0 to 1), and * `asking` while the system is asked for a permission. */ | { kind: "turning_on"; progress: number | null; asking: ThisComputerPermissionId | null; } | { kind: "on"; } /** * On, but seeing and controlling the screen waits on a system permission * the person hasn't given (yet). Files and commands work meanwhile, so it * is not an error. `appName` is the app the permission goes to when it * isn't the desktop app itself (e.g. "Opengeni Agent"). */ | { kind: "needs_permission"; appName: string | null; } | { kind: "problem"; problem: ComputerUseProblem; code: ThisComputerErrorCode | null; /** The host's or server's own message, if there is one. */ detail: string | null; /** For `stalled`: what turning on still waits for, when the host says. */ waitingOn?: ThisComputerWaitingOn | null; }; /** How a missing permission or a problem is fixed: one action each. */ export type ComputerUseFix = "open_settings" | "sign_in" | "try_again"; export declare function computerUseFix(problem: ComputerUseProblem | "permission"): ComputerUseFix; /** What a missing permission means, in one calm sentence (it isn't an error). */ export declare function computerUsePermissionText(appName: string, t: OpenGeniText): string; /** * The problem in one sentence. The network message is only for a server that * couldn't be reached; anything else keeps the server's or agent's own words. */ export declare function computerUseProblemText(state: Extract, machineName: string, t: OpenGeniText, labels: Pick): string; /** Why turning on has taken too long, in one plain sentence. */ export declare function computerUseStalledText(waitingOn: ThisComputerWaitingOn | null, machineName: string, t: OpenGeniText): string; /** The short form for a sidebar notice. */ export declare function computerUseNoticeText(state: Extract, t: OpenGeniText): string; /** * The one state to show. Removal on the server shows as off: turning it on * registers this computer again. Only a failure the host reports as the server * being out of reach is "offline"; a server that answered is never that. A * permission being asked for is still turning on; one the person didn't give * is `needs_permission`, never a problem. Turning on that has waited too long * (`stalled`, see `useThisComputer`) is a problem that says what it waits for. */ export declare function computerUseState(computer: Pick & { pending?: UseThisComputerResult["pending"] | undefined; asking?: UseThisComputerResult["asking"] | undefined; stalled?: UseThisComputerResult["stalled"] | undefined; }): ComputerUseState; export interface ComputerUseHandlers { /** * "Open System Settings" for a missing permission. By default it asks for * the next missing one (its System Settings list, with the app's guide). */ onAllowPermissions?: (() => void) | undefined; /** Signs the person in again; without it, a sign-in problem offers Try again. */ onSignIn?: (() => void) | undefined; } export interface ComputerUseControl { state: ComputerUseState; /** The switch: on in every state but off, so a problem shows what's wrong with it on. */ checked: boolean; /** The switch is saving; it ignores clicks meanwhile. */ busy: boolean; setChecked(on: boolean): void; /** The one action for a missing permission or a problem; null otherwise. */ fix: { kind: ComputerUseFix; run(): void; } | null; } /** * The switch for computer use on this computer, from `useThisComputer`. * Turning it on is the whole step: it asks for missing permissions itself. */ export declare function useComputerUse(computer: UseThisComputerResult | null, handlers?: ComputerUseHandlers): ComputerUseControl;