type Event = { event: E; data: D; }; type CustomizedEvent = Event<"Customized", { type: TType; data: TData; /** * Optional request-response correlation id. * * When a request carries an `id`, the response echoes it back so the caller * can match which response belongs to which request — similar to how CDP * uses `id`. * * @see https://github.com/lynx-family/debug-router/issues/162 */ id?: number; }>; export type AppInfo = { App: string; AppVersion: string; /** Android only */ AppProcessName?: string; /** iOS only */ bundleId?: string; /** OpenHarmony only */ bundleName?: string; debugRouterId: string; debugRouterVersion: string; deviceModel: string; did?: string; network: string; osVersion: string; sdkVersion: string; osType?: string; }; export type InitializeRequest = Event<"Initialize", number>; export type InitializeResponse = Event<"Register", { id: number; info: AppInfo; }>; export type AppResponse = CustomizedEvent<"App", { /** JSON string. See {@link AppResponseMessage} for parsed result. */ message: string; }>; export type AppResponseMessage = { id: number; /** JSON string */ result: string; }; export type CDPRequestMessage = { id?: number | undefined; method: string; params?: T | undefined; }; export type CDPRequest = CustomizedEvent<"CDP", { client_id: number; session_id: number; message: CDPRequestMessage & { id: number; }; }>; export type CDPResponse = CustomizedEvent<"CDP", { /** JSON string. See {@link CDPResponseMessage} for parsed result. */ message: string; }>; export type CDPResponseMessage = { id: number; } & ({ result: unknown; } | { error: { code: number; message: string; }; }); export type Session = { session_id: number; type: "" | "lynx" | "web"; url: string; }; export type ListSessionRequest = CustomizedEvent<"ListSession", Record>; export type ListSessionResponse = CustomizedEvent<"SessionList", Session[]>; export type GlobalKeys = "enable_devtool" | "enable_logbox" | "enable_debug_mode" | "enable_dom_tree" | "enable_quickjs_debug" | "enable_quickjs_cache" | "enable_v8" | "enable_cdp_domain_dom" | "enable_cdp_domain_css" | "enable_cdp_domain_page" | "enable_long_press_menu" | "enable_highlight_touch" | "enable_preview_screen_shot" | "enable_pixel_copy" | "enable_fsp_screenshot"; export type GetGlobalSwitchRequest = CustomizedEvent<"GetGlobalSwitch", { client_id: number; session_id: number; message: { global_key: GlobalKeys; }; }>; export type GetGlobalSwitchResponse = CustomizedEvent<"GetGlobalSwitch", { client_id: number; session_id: number; message: string | boolean | { global_value: string | boolean; }; }>; export type SetGlobalSwitchRequest = CustomizedEvent<"SetGlobalSwitch", { client_id: number; session_id: number; message: { global_key: GlobalKeys; global_value: boolean; }; }>; export type SetGlobalSwitchResponse = CustomizedEvent<"SetGlobalSwitch", { client_id: number; session_id: number; /** JSON string */ message: string; }>; /** JSON message envelope for a host-defined Customized protocol. */ export type CustomizedResponse = CustomizedEvent; export type CustomizedResponseMap = { App: AppResponse; CDP: CDPResponse; }; export type CustomizedResponseMessageMap = { App: AppResponseMessage; CDP: CDPResponseMessage; }; export type Response = InitializeResponse | ListSessionResponse | AppResponse | CDPResponse | GetGlobalSwitchResponse | SetGlobalSwitchResponse; export declare function isInitializeResponse(response: Response | CustomizedResponse): response is InitializeResponse; export declare function isListSessionResponse(response: Response | CustomizedResponse): response is ListSessionResponse; /** * Create a type guard that accepts a Customized response only when its `id` * correlates with the given request `id`. * * Correlation rules (matching CDP id semantics): * 1. Response has NO `id` field → accept (old SDK that doesn't support id yet) * 2. Response `id` matches our request `id` → accept (our response) * 3. Response `id` is -1 → reject (response to a request without id from another old client) * 4. Response `id` is a different positive number → reject (response to another client's request) * * @param baseFilter - A type guard to check the response type (e.g. isListSessionResponse) * @param requestId - The id we sent in the request * * @example * ```ts * // For ListSession: * new FilterTransformStream(createCorrelatedFilter(isListSessionResponse, id)) * // For GetGlobalSwitch (future): * new FilterTransformStream(createCorrelatedFilter(isGetGlobalSwitchResponse, id)) * ``` * * @see https://github.com/lynx-family/debug-router/issues/162 */ export declare function createCorrelatedFilter(baseFilter: (response: Input) => response is T, requestId: number): (response: Input) => response is T; export declare function isGetGlobalSwitchResponse(response: Response | CustomizedResponse): response is GetGlobalSwitchResponse; export declare function isSetGlobalSwitchResponse(response: Response | CustomizedResponse): response is SetGlobalSwitchResponse; export declare function isCustomizedResponseWithType(response: Response | CustomizedResponse, type: T): response is T extends keyof CustomizedResponseMap ? CustomizedResponseMap[T] : CustomizedResponse; export {};