import type { z } from 'zod'; import { type ComputerPreviewActivity, type ComputerAction, type ComputerCommand, type ComputerModelBinding, type ComputerObservation, type ComputerReceipt, type ComputerTarget, type ComputerApp, type ComputerWindow, type ComputerInputTiming } from '@xopcai/computer-control-contract'; import { type ComputerConfig } from './config.js'; import type { ComputerNativeTiming } from './diagnostics.js'; import { type ComputerDiagnosticSchema } from './errors.js'; export interface DriverObservation { target: ComputerTarget; summary: string; focusedEditableRef?: string; stateDigest: string; image: Uint8Array; mimeType: 'image/png' | 'image/jpeg'; imageWidth: number; imageHeight: number; } export interface ComputerDriver { getPreparationState?(): { startedAt: number; } | undefined; discover(query: string, signal: AbortSignal): Promise>; validateAction?(action: ComputerAction): void; resolveTarget(appId: string, signal: AbortSignal, options: { prepare: boolean; windowRef?: string; }): Promise; observe(target: ComputerTarget, signal: AbortSignal): Promise; perform(target: ComputerTarget, action: ComputerAction, signal: AbortSignal, onProgress?: (index: number, dispatch: 'notStarted' | 'started' | 'completed' | 'unknown') => void): Promise; getLastInputTiming?(): ComputerInputTiming | undefined; focusTarget?(target: ComputerTarget, signal: AbortSignal): Promise; validatePreviewTarget?(target: ComputerTarget, signal: AbortSignal): Promise; /** Must finish only after no further input can be dispatched. */ stop(): Promise; /** Quiescent broker-only release: discard target state, retain private transport briefly. */ idle?(): Promise; } export type ComputerApproval = { kind: 'session'; id: string; appId: string; appName: string; mode: 'observe' | 'control'; prepare: boolean; model: ComputerModelBinding; } | { kind: 'action'; id: string; target: ComputerTarget; action: ComputerAction; }; export interface ComputerBrokerHost { /** Hosts exposing a separate approval UI may opt into the legacy held-action protocol. */ deferApproval?: boolean; requestApproval(request: ComputerApproval, signal: AbortSignal): Promise; isVisible(): boolean; onStateChange?(): void; } type Status = 'pending_authorization' | 'ready' | 'running' | 'pending_action' | 'paused' | 'stopped'; export interface BrokerResult { status: Status; sessionId: string; brokerEpoch: string; generation: number; grantId?: string; observation?: ComputerObservation; receipt?: ComputerReceipt; nativeMs?: ComputerNativeTiming; diagnostic?: z.infer; errorCode?: string; apps?: ComputerApp[]; windows?: ComputerWindow[]; frame?: { bytes: Uint8Array; mimeType: 'image/png' | 'image/jpeg'; }; } /** Host-only authority; never serialize target identities or the session signal. */ export interface ComputerPreviewAuthority { conversationId: string; runId?: string; computerSessionId: string; brokerEpoch: string; appName: string; status: string; activity?: ComputerPreviewActivity; target?: ComputerTarget; signal: AbortSignal; } /** Main-process-only authority. Never expose this object or its approval hook to a renderer. */ export declare class ComputerBroker { private readonly driver; private readonly host; private readonly now; private readonly durationNow; readonly epoch: `${string}-${string}-${string}-${string}-${string}`; private session?; private busy; private stopping?; private discovery?; private readonly apps; private readonly config; private readonly timer; constructor(driver: ComputerDriver, host: ComputerBrokerHost, config?: Partial, now?: () => number, durationNow?: () => number); private expired; private result; private active; /** Settings-only app catalog. It never returns window contents or task-bound refs. */ listAppsForSettings(): Promise>; command(raw: ComputerCommand): Promise; private discover; private open; private awaitDecision; private observe; private act; stop(errorCode?: 'COMPUTER_LOCAL_UI_REQUIRED', retainDriver?: boolean): Promise; cancel(command: ComputerCommand): Promise; snapshot(): { status: Status | 'idle'; errorCode?: string; appId?: string; preparation?: { startedAt: number; }; dispatch?: ComputerReceipt['dispatch']; }; previewAuthority(): ComputerPreviewAuthority | undefined; validatePreview(authority: ComputerPreviewAuthority): Promise; focusConversation(conversationId: string): Promise; dispose(): Promise; } export {};