/* tslint:disable */
/* eslint-disable */
/**
 * A single global variable observed by `inspect_globals`.
 */
export interface WasmGlobalVariable {
    name: string;
    type: string;
    value: string | null;
    keys: string[] | null;
}

/**
 * An async command yielded from JS, waiting for external resolution.
 */
export interface WasmAsyncCommand {
    call_id: number;
    action: string;
    params: CommandParams;
    run_id: string | null;
}

/**
 * Consumer-facing result of running a single cell.
 * Either success with an optional result string, or an error.
 */
export type CellResult = { status: "ok"; stdout: string[]; stderr: string[]; result: string | null; execution_count: number } | { status: "err"; stdout: string[]; stderr: string[]; error: WasmCellError; execution_count: number };

/**
 * Error details inside an async response.
 */
export interface WasmAsyncError {
    message: string;
    code: string;
    category?: string;
    hint?: string;
    recovery?: string[];
    details?: Value;
}

/**
 * Response passed to `resume_cell` to resolve an async yield.
 */
export interface WasmAsyncResponse {
    ok: boolean;
    value: Value | null;
    error: WasmAsyncError | null;
}

/**
 * Result of running a single cell, including async-loop state.
 * Either still pending (waiting for async resolution) or done.
 */
export type WasmRunResult = { status: "pending"; stdout: string[]; stderr: string[]; commands: CommandParams[]; fuel_exhausted: boolean; execution_count: number; pending_commands: WasmAsyncCommand[] } | { status: "ok"; stdout: string[]; stderr: string[]; result: string | null; execution_count: number } | { status: "err"; stdout: string[]; stderr: string[]; error: WasmCellError; execution_count: number };

/**
 * Snapshot of all JS globals.
 */
export interface WasmGlobalsSnapshot {
    variables: WasmGlobalVariable[];
    execution_count: number;
}

/**
 * Status of a cell execution.
 */
export type WasmCellStatus = "done" | "async_pending";

/**
 * Structured error from running a cell.
 */
export type WasmCellError = { kind: "compile"; name: string | null; message: string; line: number | null } | { kind: "runtime"; name: string | null; message: string; line: number | null; action: string | null; code: string | null } | { kind: "fuel_exhausted" } | { kind: "internal"; message: string };

export interface CollectOptions {
    includeHidden?: boolean;
    includeNonInteractive?: boolean;
    includeGeometry?: boolean;
    includePath?: boolean;
    maxTextLength?: number;
    maxNodes?: number;
    interactiveOnly?: boolean;
    format?: SnapshotFormat;
}

export interface FsBoolResult {
    ok: boolean;
}

export interface FsCopyParams {
    from: string;
    to: string;
}

export interface FsExistsResult {
    exists: boolean;
}

export interface FsHashParams {
    path: string;
    algo: string;
}

export interface FsHashResult {
    hash: string;
}

export interface FsListEntry {
    name: string;
    kind: string;
}

export interface FsListResult {
    entries: FsListEntry[];
}

export interface FsPathParams {
    path: string;
}

export interface FsReadRangeDataParams {
    path: string;
    offset: number;
    data: string;
}

export interface FsReadRangeParams {
    path: string;
    offset: number;
    len: number;
}

export interface FsStatResult {
    path: string;
    name: string;
    kind: string;
    size: number;
    mime: string | null;
    created_at: number | null;
    modified_at: number | null;
}

export interface FsStringResult {
    data: string;
}

export interface FsWriteParams {
    path: string;
    data: string;
}

export interface JsApiAlias {
    namespace: string;
    name: string;
    fields: string[] | null;
}

export interface JsManifestEntry {
    action: string;
    namespace: string;
    name: string;
    publicName: string;
    description: string;
    fields: string[] | null;
    aliases: JsApiAlias[];
    paramsDoc: JsParamDoc[];
    returnsDoc: JsReturnDoc;
    errorCode: string;
    errorCategory: string | null;
    permission: string | null;
    example: string | null;
    prerequisites?: string[] | null;
    notes?: string[] | null;
    tags?: string[] | null;
    relatedApis?: string[] | null;
}

export interface JsParamDoc {
    name: string;
    type: string;
    required: boolean;
    description: string;
}

export interface JsReturnDoc {
    type: string;
    description: string;
}

export interface OutlineNode {
    role: string;
    name: string;
    ref_id: string;
}

export interface Rect {
    x: number;
    y: number;
    width: number;
    height: number;
    top: number;
    right: number;
    bottom: number;
    left: number;
}

export interface SemanticNode {
    refId: string;
    role: string;
    name?: string;
    description?: string;
    tag: string;
    id?: string;
    classes?: string[];
    value?: string;
    placeholder?: string;
    href?: string;
    states: States;
    inputType?: string;
    rect?: Rect;
    inViewport: boolean;
    visible: boolean;
    path?: string;
}

export interface States {
    disabled?: boolean;
    checked?: boolean;
    selected?: boolean;
    expanded?: boolean;
    pressed?: boolean;
    required?: boolean;
    readonly?: boolean;
    invalid?: boolean;
    hidden?: boolean;
    focusable?: boolean;
    interactive?: boolean;
    current?: boolean;
}

export interface TreeSnapshot {
    version: string;
    url: string | null;
    title: string | null;
    viewport: Viewport | null;
    nodes: SemanticNode[];
    outline?: OutlineNode[];
}

export interface Viewport {
    width: number;
    height: number;
    scrollX: number;
    scrollY: number;
}

export type SnapshotFormat = "compact-text" | "json" | "json-pretty";


/**
 * ExtensionSession wraps BaseSession for the Chrome Extension environment.
 * WASM runs inside a Web Worker; all browser side-effects are dispatched
 * through the unified executable handler registry (Rust-local handlers or JS-registered callbacks).
 */
export class ExtensionSession {
    free(): void;
    [Symbol.dispose](): void;
    /**
     * Generate API documentation for every registered public API.
     */
    apiDocs(format: string): string;
    fsAppend(params: FsWriteParams): Promise<FsBoolResult>;
    fsAppendBase64(params: FsWriteParams): Promise<FsBoolResult>;
    fsAppendText(params: FsWriteParams): Promise<FsBoolResult>;
    fsCopy(params: FsCopyParams): Promise<FsBoolResult>;
    fsDelete(params: FsPathParams): Promise<FsBoolResult>;
    fsExists(params: FsPathParams): Promise<FsExistsResult>;
    fsHash(params: FsHashParams): Promise<FsHashResult>;
    fsList(params: FsPathParams): Promise<FsListResult>;
    fsMkdir(params: FsPathParams): Promise<FsBoolResult>;
    fsMove(params: FsCopyParams): Promise<FsBoolResult>;
    fsRead(params: FsPathParams): Promise<FsStringResult>;
    fsReadBase64(params: FsPathParams): Promise<FsStringResult>;
    fsReadRange(params: FsReadRangeParams): Promise<FsStringResult>;
    fsReadText(params: FsPathParams): Promise<FsStringResult>;
    fsStat(params: FsPathParams): Promise<FsStatResult>;
    fsUpdate(params: FsReadRangeDataParams): Promise<FsBoolResult>;
    fsWrite(params: FsWriteParams): Promise<FsBoolResult>;
    fsWriteBase64(params: FsWriteParams): Promise<FsBoolResult>;
    fsWriteText(params: FsWriteParams): Promise<FsBoolResult>;
    /**
     * Inject async and sync API bindings from the doc registry into the JS environment.
     * Must be called after all manifest entries are registered.
     */
    injectRegistryBindings(): void;
    /**
     * Inspect all global variables in the current JS state.
     */
    inspect_globals(): WasmGlobalsSnapshot;
    /**
     * Load a JS library by executing its source code.
     */
    load_library(source: string): CellResult;
    /**
     * Create a new extension session.
     */
    constructor();
    /**
     * Reset the session, clearing all JS state.
     */
    reset(): void;
    /**
     * Run a cell, automatically resolving all async calls through the
     * unified handler registry.
     */
    runCellAsync(code: string, stdin: string, run_id: string): Promise<CellResult>;
    /**
     * Signal the async execution loop to abort between command batches.
     */
    setAborted(value: boolean): void;
    /**
     * Set the fuel limit for execution.
     */
    set_fuel_limit(limit: number): void;
    /**
     * Clean up the session and release resources.
     */
    stopWith(): void;
}

export function collect_document(options: CollectOptions): TreeSnapshot;

export function collect_element(root: Element, options: CollectOptions): TreeSnapshot;

export function format_snapshot_js(snapshot: TreeSnapshot, format?: SnapshotFormat | null): string;

export function freezeManifest(): void;

export function importManifestEntries(entries: Array<any>): void;

export function main(): void;

export function registerJsCall(entry: JsManifestEntry, callback: Function): void;

export function registerJsCallBatch(items: Array<any>): void;

export function registerSharedDispatch(callback: Function): void;

/**
 * 0=trace, 1=debug, 2=info, 3=warn, 4=error, 5=none
 */
export function setLogLevel(level: number): void;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
    readonly memory: WebAssembly.Memory;
    readonly __wbg_extensionsession_free: (a: number, b: number) => void;
    readonly extensionsession_apiDocs: (a: number, b: number, c: number) => [number, number, number, number];
    readonly extensionsession_fsAppend: (a: number, b: any) => any;
    readonly extensionsession_fsAppendBase64: (a: number, b: any) => any;
    readonly extensionsession_fsAppendText: (a: number, b: any) => any;
    readonly extensionsession_fsCopy: (a: number, b: any) => any;
    readonly extensionsession_fsDelete: (a: number, b: any) => any;
    readonly extensionsession_fsExists: (a: number, b: any) => any;
    readonly extensionsession_fsHash: (a: number, b: any) => any;
    readonly extensionsession_fsList: (a: number, b: any) => any;
    readonly extensionsession_fsMkdir: (a: number, b: any) => any;
    readonly extensionsession_fsMove: (a: number, b: any) => any;
    readonly extensionsession_fsRead: (a: number, b: any) => any;
    readonly extensionsession_fsReadBase64: (a: number, b: any) => any;
    readonly extensionsession_fsReadRange: (a: number, b: any) => any;
    readonly extensionsession_fsReadText: (a: number, b: any) => any;
    readonly extensionsession_fsStat: (a: number, b: any) => any;
    readonly extensionsession_fsUpdate: (a: number, b: any) => any;
    readonly extensionsession_fsWrite: (a: number, b: any) => any;
    readonly extensionsession_fsWriteBase64: (a: number, b: any) => any;
    readonly extensionsession_fsWriteText: (a: number, b: any) => any;
    readonly extensionsession_injectRegistryBindings: (a: number) => void;
    readonly extensionsession_inspect_globals: (a: number) => any;
    readonly extensionsession_load_library: (a: number, b: number, c: number) => any;
    readonly extensionsession_new: () => number;
    readonly extensionsession_reset: (a: number) => void;
    readonly extensionsession_runCellAsync: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
    readonly extensionsession_setAborted: (a: number, b: number) => void;
    readonly extensionsession_set_fuel_limit: (a: number, b: number) => void;
    readonly extensionsession_stopWith: (a: number) => void;
    readonly freezeManifest: () => [number, number];
    readonly importManifestEntries: (a: any) => [number, number];
    readonly main: () => void;
    readonly registerJsCall: (a: any, b: any) => [number, number];
    readonly registerJsCallBatch: (a: any) => [number, number];
    readonly registerSharedDispatch: (a: any) => [number, number];
    readonly setLogLevel: (a: number) => void;
    readonly collect_document: (a: any) => any;
    readonly collect_element: (a: any, b: any) => any;
    readonly format_snapshot_js: (a: any, b: number) => [number, number];
    readonly wasm_bindgen__convert__closures_____invoke__hafd7db4a84e7076d: (a: number, b: number, c: any) => [number, number];
    readonly wasm_bindgen__convert__closures_____invoke__h72adce5fbcd58c92: (a: number, b: number, c: any, d: any) => void;
    readonly wasm_bindgen__convert__closures_____invoke__h027ec0463d981e5e: (a: number, b: number) => number;
    readonly wasm_bindgen__convert__closures_____invoke__h2f71c847222394ea: (a: number, b: number) => void;
    readonly __wbindgen_malloc: (a: number, b: number) => number;
    readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
    readonly __wbindgen_exn_store: (a: number) => void;
    readonly __externref_table_alloc: () => number;
    readonly __wbindgen_externrefs: WebAssembly.Table;
    readonly __wbindgen_free: (a: number, b: number, c: number) => void;
    readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
    readonly __externref_table_dealloc: (a: number) => void;
    readonly __wbindgen_start: () => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;

/**
 * Instantiates the given `module`, which can either be bytes or
 * a precompiled `WebAssembly.Module`.
 *
 * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
 *
 * @returns {InitOutput}
 */
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;

/**
 * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
 * for everything else, calls `WebAssembly.instantiate` directly.
 *
 * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
 *
 * @returns {Promise<InitOutput>}
 */
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
