/* tslint:disable */
/* eslint-disable */

/**
 * Compatibility entry — decrypt and return plaintext bytes via JS.
 * This crosses the boundary so it's NOT the isolation path; kept
 * for parity with the typage flow during migration. Prefer
 * ageDecryptToHandle for new code.
 */
export function ageDecryptToBytes(ciphertext: Uint8Array, passphrase: string): Uint8Array;

/**
 * Decrypt an age envelope with a passphrase, place the plaintext
 * in the registry, return the handle. Plaintext never crosses to
 * JS through this entry — callers use the handle.
 */
export function ageDecryptToHandle(ciphertext: Uint8Array, passphrase: string): number;

export function ageDecryptWithIdentitiesToHandle(ciphertext: Uint8Array, identities: any): number;

/**
 * JS-bridge entry — `appendArrowIpc(existing, new_batch)` parses both
 * inputs as Arrow IPC streams, verifies the schemas match, and emits
 * a unified IPC stream containing all batches from both inputs under
 * a single schema header + EOS.
 *
 * Replaces the broken naive byte concatenation in the JS-side
 * `appendMemory` shim. Naive concat produces `<stream1><stream2>`
 * which IPC readers truncate at the first EOS — losing rows from
 * any append past the first. This binding instead reads both
 * streams, validates schemas, and writes a fresh well-formed
 * stream.
 *
 * Schema compatibility: same field count, same field names + data
 * types + nullability, ignoring schema metadata. Anything else
 * throws — incompatible appends would produce a stream that
 * readers can't decode correctly.
 */
export function appendArrowIpc(existing: Uint8Array, new_batch: Uint8Array): Uint8Array;

export function arrowDecodeToJsonRows(bytes: Uint8Array): string;

export function arrowEncodeJsonRows(schema_json: string, rows_json: string): Uint8Array;

/**
 * Build metadata for compatibility checks against the manifest's
 * `runtime.bundleVersion` and `runtime.contractVersion`.
 */
export function build_info(): any;

/**
 * Smoke-test entry — proves Candle is alive in the WASM bundle by doing
 * a trivial tensor operation. Returns the result as a stringified vec.
 *
 * Used by the future `examples/candle-smoke/` demo and by P4.7 benchmarks
 * to capture the cold-start cost of Candle initialization separately
 * from the cost of actual model loading.
 */
export function candleSmokeTest(): any;

export function destroyRuntime(_req: any): any;

/**
 * Drop the bytes at this handle. Returns true if the slot was
 * occupied; false if it had already been disposed or never existed.
 */
export function handleDispose(id: number): boolean;

/**
 * Escape hatch — copy the plaintext out to JS. The whole point of
 * handles is to avoid this; use only when a cell genuinely needs
 * raw bytes (custom cell language without a handle-aware Rust
 * path). Returns an empty Vec if the handle is unknown.
 */
export function handleExport(id: number): Uint8Array;

/**
 * SHA-256 (lowercase hex) of the plaintext at this handle. Used by
 * the resolver to verify the post-decrypt digest matches the
 * `sha256` attribute on the `<wb-data>` element WITHOUT exporting
 * bytes back to JS. Returns empty string if the handle is unknown
 * (caller treats as integrity failure).
 */
export function handleSha256(id: number): string;

/**
 * Bytes-length of the plaintext at this handle. 0 if the handle
 * has been disposed or never existed (unobservable from a slot
 * that legitimately held zero bytes; that case doesn't occur
 * with age decrypts).
 */
export function handleSize(id: number): number;

/**
 * Decode an image (jpeg/png/webp/etc), resize to (width × height),
 * normalize per-channel with the given mean/std, and emit a
 * CHW-ordered float32 tensor of shape `[1, 3, height, width]`.
 *
 * Standard ImageNet defaults:
 *   mean = [0.485, 0.456, 0.406]
 *   std  = [0.229, 0.224, 0.225]
 *
 * CLIP defaults:
 *   mean = [0.48145466, 0.4578275, 0.40821073]
 *   std  = [0.26862954, 0.26130258, 0.27577711]
 */
export function imageToTensorRgb(bytes: Uint8Array, width: number, height: number, mean: Float32Array, std: Float32Array): any;

/**
 * Initialize a runtime instance for the given workbook.
 *
 * Loads sql.js / DuckDB-WASM, initializes Polars LazyFrame engine, and
 * wires up any other feature slices the workbook declared. Returns a
 * `runtime_id` the caller passes back into `run_cell()`.
 */
export function initRuntime(req: any): any;

/**
 * Library-load hook. Wires up panic forwarding to the JS console so a panic
 * in any cell surfaces as a readable error in the workbook UI rather than a
 * silent abort.
 */
export function on_load(): void;

/**
 * Drop a previously-loaded model, freeing its memory. Calling free on
 * an unknown id is a no-op (so the JS side can call it defensively
 * without first checking existence).
 */
export function onnxFree(handle: number): void;

/**
 * Parse an ONNX model from raw bytes and stash it in the registry.
 * Returns a handle the caller passes to `onnxRun` / `onnxFree`.
 */
export function onnxLoad(bytes: Uint8Array): number;

/**
 * Run inference on a previously-loaded model.
 *
 * `inputs` is a JS object `{ name: TensorJs }`. The returned value is
 * shaped the same — `{ name: TensorJs }` — for every output the model
 * declares.
 *
 * Errors from candle-onnx (unsupported op, shape mismatch, missing
 * input) are surfaced verbatim so the JS side can show useful
 * diagnostics.
 */
export function onnxRun(handle: number, inputs: any): any;

export function pauseRuntime(_req: any): any;

/**
 * Materialize the full leaf at a past commit. Returns an array of
 * [key, value] pairs (value is a Uint8Array on the JS side).
 */
export function prollyCheckout(serialized: Uint8Array, commit_hash_hex: string): any;

/**
 * Remove a key in the current leaf and commit. Returns new
 * serialized history bytes.
 */
export function prollyDelete(serialized: Uint8Array, key: string, message: string): Uint8Array;

/**
 * Get a value at key from the current HEAD's leaf.
 */
export function prollyGet(serialized: Uint8Array, key: string): any;

/**
 * Read the HEAD commit's hash as hex.
 */
export function prollyHead(serialized: Uint8Array): string;

/**
 * Initialize a fresh history with one root commit. Returns the
 * serialized bytes ready for embedding in `<wb-history>`.
 */
export function prollyInit(message: string): Uint8Array;

/**
 * List all keys present in the current HEAD's leaf (utf-8 keys only).
 */
export function prollyKeys(serialized: Uint8Array): any;

/**
 * Walk the parent chain from HEAD, returning each commit as
 * {hash, parent, root, timestamp_ms, message}.
 */
export function prollyLog(serialized: Uint8Array): any;

/**
 * Set a key=value in the current leaf and commit. Returns new
 * serialized history bytes — the host writes them back to the
 * `<wb-history>` element body on save.
 */
export function prollySet(serialized: Uint8Array, key: string, value: Uint8Array, message: string): Uint8Array;

/**
 * Truncate the chain to a past commit. Returns new serialized
 * history bytes where HEAD = target_hex and every commit after
 * target on the linear parent chain has been dropped. Errors if
 * target isn't reachable from current HEAD.
 */
export function prollyTruncateTo(serialized: Uint8Array, target_hex: string): Uint8Array;

/**
 * Heavier tensor-op demo (T1.1) — runs three ops typical of a real ML
 * workload and reports wall-clock timing + first few output values:
 *
 *   matmul:   (N x N) @ (N x N) where N = 256 by default
 *   softmax:  length-1024 vector
 *   conv2d:   (1 x 3 x 32 x 32) input × (8 x 3 x 3 x 3) filter
 *
 * Used by `examples/candle-ops/` to demonstrate the heavy compute path
 * in the browser (beyond the trivial 4-element add). Numbers compare
 * against the JS reference baseline in the demo's UI.
 */
export function runCandleOps(matmul_n: number): any;

/**
 * JS-bridge entry — `runChart(spec)` takes a JSON-encoded ChartSpec and
 * returns the cell outputs (one Image entry with SVG content).
 */
export function runChart(spec_json: string): any;

/**
 * JS-bridge entry — `runPolarsSql(sql, csv)` parses `csv` into a LazyFrame,
 * registers it as table `data`, evaluates the SQL, and returns the resulting
 * frame rendered back to CSV.
 *
 * Used by the demo workbook to prove an end-to-end Polars round trip in
 * the browser (P2.5 gate).
 */
export function runPolarsSql(sql: string, csv: string): any;

/**
 * JS-bridge entry — `runPolarsSqlIpc(sql, tables)` registers each entry
 * in `tables` as a Polars table by name (table name = map key) and
 * runs the SQL against the resulting context. Each value is parsed
 * as a complete Arrow IPC stream.
 *
 * Used by `<wb-memory>` cell dispatch on the JS side. Cells reference
 * memory tables in `reads=`; the runtime client looks up the registered
 * IPC bytes and threads them into RunCellRequest.memoryTables, which
 * the JS dispatcher passes here.
 *
 * Pipeline (native, post-toolchain-fix):
 *   bytes → polars::io::ipc::IpcStreamReader → DataFrame.lazy()
 *         → registered in SQLContext under the table name
 *
 * Polars `ipc` feature is enabled in Cargo.toml; the C-deps it pulls
 * in (zstd-sys, lz4) compile via Homebrew LLVM's wasm32 backend
 * (configured in .cargo/config.toml). No CSV bridge intermediate.
 *
 * Returns the result frame as CSV plus a table output stub.
 *
 * Caveat: today's JS-side `appendMemory` does naive byte concatenation
 * of IPC streams. A correctly-formed Arrow IPC stream has one schema
 * message + batches + EOS; concatenating two streams produces
 * `<stream1><stream2>` and arrow-rs's StreamReader reads up to the
 * first EOS only, losing rows from later appends. Right fix is
 * host-driven complete-stream replacement on save (host owns the
 * source of truth and re-serializes), or a Rust-side proper IPC
 * append that strips intermediate schemas + EOS markers. Tracked
 * separately as task #17.
 */
export function runPolarsSqlIpc(sql: string, tables: any): any;

export function runPolarsSqlIpcHandles(sql: string, table_handles: any): any;

/**
 * JS-bridge entry — `runRhai(source, params?)` returns the cell outputs.
 * `params` is an optional JSON object whose keys are bound as variables
 * in the Rhai scope before eval. This is how upstream cell outputs and
 * workbook inputs reach a Rhai cell.
 */
export function runRhai(source: string, params: any): any;

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

export interface InitOutput {
    readonly memory: WebAssembly.Memory;
    readonly ageDecryptToBytes: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly ageDecryptToHandle: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly ageDecryptWithIdentitiesToHandle: (a: number, b: number, c: number, d: number) => void;
    readonly appendArrowIpc: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly arrowDecodeToJsonRows: (a: number, b: number, c: number) => void;
    readonly arrowEncodeJsonRows: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly build_info: () => number;
    readonly candleSmokeTest: (a: number) => void;
    readonly destroyRuntime: (a: number, b: number) => void;
    readonly handleDispose: (a: number) => number;
    readonly handleExport: (a: number, b: number) => void;
    readonly handleSha256: (a: number, b: number) => void;
    readonly handleSize: (a: number) => number;
    readonly imageToTensorRgb: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
    readonly initRuntime: (a: number, b: number) => void;
    readonly on_load: () => void;
    readonly onnxFree: (a: number) => void;
    readonly onnxLoad: (a: number, b: number, c: number) => void;
    readonly onnxRun: (a: number, b: number, c: number) => void;
    readonly prollyCheckout: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly prollyDelete: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
    readonly prollyGet: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly prollyHead: (a: number, b: number, c: number) => void;
    readonly prollyInit: (a: number, b: number, c: number) => void;
    readonly prollyKeys: (a: number, b: number, c: number) => void;
    readonly prollyLog: (a: number, b: number, c: number) => void;
    readonly prollySet: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
    readonly prollyTruncateTo: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly runCandleOps: (a: number, b: number) => void;
    readonly runChart: (a: number, b: number, c: number) => void;
    readonly runPolarsSql: (a: number, b: number, c: number, d: number, e: number) => void;
    readonly runPolarsSqlIpc: (a: number, b: number, c: number, d: number) => void;
    readonly runPolarsSqlIpcHandles: (a: number, b: number, c: number, d: number) => void;
    readonly runRhai: (a: number, b: number, c: number, d: number) => void;
    readonly pauseRuntime: (a: number, b: number) => void;
    readonly ffi_path_compile: (a: number) => number;
    readonly ffi_select: (a: number, b: number) => number;
    readonly ffi_select_with_compiled_path: (a: number, b: number) => number;
    readonly rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
    readonly rust_zstd_wasm_shim_free: (a: number) => void;
    readonly rust_zstd_wasm_shim_malloc: (a: number) => number;
    readonly rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
    readonly rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
    readonly rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
    readonly rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
    readonly rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
    readonly rust_lz4_wasm_shim_calloc: (a: number, b: number) => number;
    readonly rust_lz4_wasm_shim_free: (a: number) => void;
    readonly rust_lz4_wasm_shim_malloc: (a: number) => number;
    readonly rust_lz4_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
    readonly rust_lz4_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
    readonly rust_lz4_wasm_shim_memmove: (a: number, b: number, c: number) => number;
    readonly rust_lz4_wasm_shim_memset: (a: number, b: number, c: number) => number;
    readonly __wbindgen_export: (a: number, b: number) => number;
    readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
    readonly __wbindgen_export3: (a: number) => void;
    readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
    readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
    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>;
