broker.d.ts 4.5 KB

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