import type { IHostConfigResponse } from "@streamlit/lib/src/hostComm/types"; import type { EmscriptenFile, EmscriptenFileUrl, HttpRequest, HttpResponse, PyodideArchive, PyodideArchiveUrl, StreamlitConfig } from "./types"; export interface StliteKernelOptions { /** * The file path on the Pyodide File System (Emscripten FS) to be set as a target of the `run` command. */ entrypoint: string; /** * A list of package names to be install at the booting-up phase. */ requirements: string[]; /** * Files to mount. */ files: Record; /** * Archives to unpack and mount. */ archives: Array; /** * The URL of `pyodide.js` or `pyodide.mjs` to be loaded in the worker. * If not specified, the default one is used. */ pyodideUrl?: string; /** * */ wheelBaseUrl?: string; /** * If specified, the worker restores the site-packages directories from this archive file * and skip installing the wheels and required packages. */ mountedSitePackagesSnapshotFilePath?: string; /** * In the original Streamlit, the `hostConfig` endpoint returns a value of this type * and the frontend app fetches it (https://github.com/streamlit/streamlit/blob/1.30.0/frontend/app/src/connection/WebsocketConnection.tsx#L696-L703) * and passes it to the `onHostConfigResp` callback to configure the app (https://github.com/streamlit/streamlit/blob/1.30.0/frontend/app/src/App.tsx#L393-L415). * Instead, in stlite, this value can be configured through this property, * which is passed to the `ConnectionManager` class to call `onHostConfigResp` from it. * One of the usages in stlite is to configure the `allowedOrigins` property * for VSCode extension to use the iframe messaging to solve the problem of https://github.com/whitphx/stlite/issues/519 * by sending the `SET_PAGE_LINK_BASE_URL` message to the app in a WebView panel to override the URL scheme of the links. * Note that Streamlit's iframe messaging referred to here is different from the iframe messaging mechanism implemented for the iframe embedded on stlite sharing. */ hostConfigResponse?: IHostConfigResponse; /** * The `pathname` that will be used as both * a base path of the custom component URLs * ana the path of the main page in MPA. * * If not specified, the value of `window.location.pathname` at the time of the class initialization is used. * This default is good enough for most cases, however, * it may be a problem if the server is configured to return the main page even if the URL is pointing to the subpath. * In such a setting, problems like https://github.com/whitphx/stlite/issues/171 may happen, * so explicitly setting `basePath` is recommended. */ basePath?: string; /** * Streamlit configurations described in https://docs.streamlit.io/library/advanced-features/configuration. * These values can be configured through this property as key-value pairs. * The keys are the same as the ones passed to the `streamlit run` shell command as `--` options (flags). * For example, `--logger.level info` is passed as `{ "logger.level": "info" }`. */ streamlitConfig?: StreamlitConfig; onProgress?: (message: string) => void; onLoad?: () => void; onError?: (error: Error) => void; } export declare class StliteKernel { private _isDisposed; private _worker; private _loaded; private _workerInitData; readonly basePath: string; readonly hostConfigResponse: IHostConfigResponse; private onProgress; private onLoad; private onError; constructor(options: StliteKernelOptions); get loaded(): Promise; connectWebSocket(path: string): Promise; sendWebSocketMessage(payload: Uint8Array): Promise; private handleWebSocketMessage; onWebSocketMessage(handler: (payload: Uint8Array | string) => void): void; sendHttpRequest(request: HttpRequest): Promise; writeFile(path: string, data: string | ArrayBufferView, opts?: Record): Promise; renameFile(oldPath: string, newPath: string): Promise; unlink(path: string): Promise; install(requirements: string[]): Promise; private _asyncPostMessage; /** * Process a message coming from the pyodide web worker. * * @param msg The worker message to process. */ private _processWorkerMessage; /** * Return whether the kernel is disposed. */ get isDisposed(): boolean; /** * Dispose the kernel. */ dispose(): void; }