broker.d.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. export { HELPER_GHOST_CURSOR_OVERLAY_ARG } from "./broker-helper-constants.js";
  2. export declare const BROKER_SOCKET_ENV: string;
  3. export declare const BROKER_UNAVAILABLE_ENV: string;
  4. export declare class BrokerError extends Error {
  5. code: string;
  6. details?: unknown;
  7. constructor(message?: string, options?: { code?: string; details?: unknown });
  8. }
  9. export declare class CuaHelperError extends Error {
  10. code: string;
  11. constructor(message?: string, options?: { code?: string });
  12. }
  13. export declare function isCuaHelperError(value: unknown): value is CuaHelperError;
  14. export declare const notAuthorized: (message?: string, details?: unknown) => BrokerError;
  15. export declare const notSelectable: (message?: string, details?: unknown) => BrokerError;
  16. export declare const notSettable: (message?: string, details?: unknown) => BrokerError;
  17. export declare const elementUnavailable: (message?: string, details?: unknown) => BrokerError;
  18. export declare const actionUnavailable: (message?: string, details?: unknown) => BrokerError;
  19. export declare const foregroundRequired: (message?: string, details?: unknown) => BrokerError;
  20. export interface HelperHealth {
  21. bundleId: string | null;
  22. pid: number | null;
  23. }
  24. export interface CallBrokerMethodArgs {
  25. socketPath: string;
  26. method: string;
  27. params?: unknown;
  28. timeoutMs?: number;
  29. }
  30. export declare function callBrokerMethod<T = unknown>(args: CallBrokerMethodArgs): Promise<T>;
  31. export interface ProbeHelperHealthOptions {
  32. timeoutMs?: number;
  33. pollIntervalMs?: number;
  34. perTryTimeoutMs?: number;
  35. }
  36. export declare function probeHelperHealth(
  37. socketPath: string,
  38. options?: ProbeHelperHealthOptions,
  39. ): Promise<HelperHealth>;
  40. export interface SocketPathOptions {
  41. dir?: string;
  42. env?: Record<string, string | undefined>;
  43. }
  44. export declare function mintBrokerSocketPath(options?: SocketPathOptions): string;
  45. export declare function resolveBrokerSocketPath(options?: SocketPathOptions): string;
  46. export interface BrokerRequest {
  47. id?: string | null;
  48. method: string;
  49. params?: unknown;
  50. }
  51. export interface BrokerResponse {
  52. ok: boolean;
  53. [key: string]: unknown;
  54. }
  55. export declare function parseRequestLine(line: string): BrokerRequest | undefined;
  56. export declare function okResponse(result: unknown): BrokerResponse;
  57. export declare function errorResponse(message: string, options?: { code?: string }): BrokerResponse;
  58. export declare function errorResponseFromException(error: unknown): BrokerResponse;
  59. export declare function serializeResponse(response: BrokerResponse): string;
  60. export type BrokerErrorCode = string;
  61. export type BrokerMethod = string;
  62. export type CuaHelperErrorCode = string;
  63. export type NativeAutomationBackend = Record<string, unknown>;
  64. export interface BrokerHandler {
  65. (params: unknown, context?: unknown): Promise<unknown>;
  66. }
  67. export declare function dispatchRequest(
  68. backend: NativeAutomationBackend,
  69. request: BrokerRequest,
  70. ): Promise<BrokerResponse>;
  71. export declare function handleRequestLine(
  72. backend: NativeAutomationBackend,
  73. line: string,
  74. ): Promise<BrokerResponse>;
  75. export declare function isBrokerMethod(method: string): method is BrokerMethod;
  76. export declare function isReadOnlyBrokerMethod(method: string): boolean;
  77. export type CuaPermissionState = "granted" | "stale" | "denied" | "unknown";
  78. export interface CuaPermissionStatus {
  79. available?: true;
  80. platform?: string;
  81. grantOwner: string | null;
  82. owner?: { display_name?: string } | null;
  83. accessibility: CuaPermissionState;
  84. accessibility_probe_ok?: boolean;
  85. accessibilityProbeOk?: boolean;
  86. grantOwnerDisplayName?: string | null;
  87. screenRecording: CuaPermissionState;
  88. screenCaptureProbeOk?: boolean;
  89. idle?: boolean;
  90. reason?: string;
  91. }
  92. export interface CuaPermissionStatusUnavailable {
  93. available: false;
  94. reason: string;
  95. idle?: boolean;
  96. grantOwnerDisplayName?: string | null;
  97. }
  98. export type CuaPermissionStatusResult = CuaPermissionStatus | CuaPermissionStatusUnavailable;
  99. export interface CuaPermissionStatusQueryOptions {
  100. probeScreenCapture?: boolean;
  101. [key: string]: unknown;
  102. }
  103. export interface CuaPermissionRestartResult {
  104. ok: boolean;
  105. reason?: string;
  106. [key: string]: unknown;
  107. }
  108. export interface CuaPermissionRestartOptions {
  109. onboardingSessionId?: string;
  110. reason?: string;
  111. beforeFreshStart?: () => void;
  112. [key: string]: unknown;
  113. }
  114. export interface ICuaPermissionService {
  115. getStatus(
  116. workspacePath: string,
  117. workspaceIdentity?: string,
  118. options?: CuaPermissionStatusQueryOptions,
  119. ): Promise<CuaPermissionStatusResult>;
  120. restartHelper(
  121. workspacePath?: string,
  122. workspaceIdentity?: string,
  123. options?: CuaPermissionRestartOptions,
  124. ): Promise<CuaPermissionRestartResult>;
  125. }