Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@r1-runtime/kernel

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@r1-runtime/kernel - npm Package Compare versions

Comparing version
0.3.1
to
0.3.2
+6
dist/kernel/src/index.d.ts
export type { KernelRequest, KernelResponse } from './protocol';
export { Router } from './router';
export type { KernelHandler, KernelPlugin } from './router';
export { VFS } from './vfs';
export { WasmOrchestrator } from './wasm-orchestrator';
//# sourceMappingURL=index.d.ts.map
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
export {};
//# sourceMappingURL=kernel.worker.d.ts.map
{"version":3,"file":"kernel.worker.d.ts","sourceRoot":"","sources":["../../../src/kernel.worker.ts"],"names":[],"mappings":""}
/**
* Represents a request sent from the main thread to the Kernel Worker.
*/
export interface KernelRequest {
/** Unique nanoid used to match the response back to this request */
id: string;
/** Command name, e.g. 'IPC_INVOKE' or 'VFS_READ' */
type: string;
/** JSON-serialisable payload */
payload: unknown;
}
/**
* Represents a response sent from the Kernel Worker back to the main thread.
*/
export interface KernelResponse {
/** Matches the request id */
id: string;
/** The result data. Undefined if an error occurred. */
payload?: unknown;
/** The error string. Undefined on success. */
error?: string;
}
/**
* Represents a request from Worker back to Main Thread to execute a restricted Web API.
*/
export interface MainThreadCall {
id: string;
type: 'MAIN_THREAD_CALL';
payload: {
api: string;
method: string;
args: any;
};
}
//# sourceMappingURL=protocol.d.ts.map
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/protocol.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,EAAE,EAAE,MAAM,CAAC;IACX,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,uDAAuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE;QACP,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,GAAG,CAAC;KACX,CAAC;CACH"}
import { KernelRequest, KernelResponse } from './protocol';
/** A function that handles a specific message type in the Worker */
export type KernelHandler = (payload: any) => Promise<unknown>;
/** Interface for Kernel Plugins */
export interface KernelPlugin {
name: string;
getCommands(): Map<string, KernelHandler>;
}
/**
* Routes incoming KernelRequests to the appropriate registered handler.
* Supports hierarchical naming (e.g., 'fs:read_file') and plugins.
*/
export declare class Router {
private handlers;
/**
* Register a new message handler for a specific message type.
*/
register(type: string, handler: KernelHandler): void;
/**
* Register a plugin, adding all its commands to the router prefixing them with plugin name.
*/
use(plugin: KernelPlugin): void;
/**
* Process an incoming request, route it to the handler, and return a response.
* Guaranteed to never throw; it always returns a KernelResponse envelope.
*/
handle(request: KernelRequest): Promise<KernelResponse>;
}
//# sourceMappingURL=router.d.ts.map
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEhE,oEAAoE;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/D,mCAAmC;AACnC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC3C;AAED;;;GAGG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAoC;IAEpD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAOpD;;OAEG;IACH,GAAG,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAO/B;;;OAGG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;CAwB9D"}
import { KernelPlugin, KernelHandler } from './router';
import { VFS } from './vfs';
export declare class SQLitePlugin implements KernelPlugin {
name: string;
private sqlite3;
private dbs;
private vfs;
constructor(vfs: VFS);
/**
* Lazy-load SQLite WASM
*/
private initSqlite;
getCommands(): Map<string, KernelHandler>;
private getDb;
private normalizePath;
}
//# sourceMappingURL=sqlite-plugin.d.ts.map
{"version":3,"file":"sqlite-plugin.d.ts","sourceRoot":"","sources":["../../../src/sqlite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAuB5B,qBAAa,YAAa,YAAW,YAAY;IAC/C,IAAI,SAAgB;IACpB,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,GAAG,CAAM;gBAEL,GAAG,EAAE,GAAG;IAIpB;;OAEG;YACW,UAAU;IAyBxB,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;IA8EzC,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,aAAa;CAItB"}
/**
* A Virtual File System wrapper combining an instant synchronous memory cache
* with asynchronous background OPFS (Origin Private File System) persistence.
* Designed purely for the Kernel Web Worker.
*/
export declare class VFS {
private cache;
private rootHandle?;
private isInit;
/**
* Must be called exactly once before any VFS operations.
* Acquires the OPFS root and deeply scans it to pre-warm the memory cache.
*/
init(): Promise<void>;
/** Check if a file or directory exists in the virtual filesystem */
exists(path: string): boolean;
/** Read bytes instantly from cache. Throws if not found. */
read(path: string): Uint8Array;
/** Helper to read UTF-8 strings */
readText(path: string): string;
/** List all absolute file or directory paths immediately under a given directory */
list(dir: string): string[];
/**
* Writes data. Updates in-memory immediately, writes to disk async.
* Automatically resolves missing parent directories.
*/
write(path: string, data: Uint8Array): Promise<void>;
/** Helper to write UTF-8 strings */
writeText(path: string, text: string): Promise<void>;
/** Emulates directory creation. In this architecture, writes auto-create parents, so this is just for strict APIs. */
mkdir(dir: string): Promise<void>;
/** Deletes a file. Removes from cache immediately, deletes from OPFS async. */
delete(path: string): Promise<void>;
private checkStorageQuota;
getStorageInfo(): Promise<{
usedBytes: number;
quotaBytes: number;
percentUsed: number;
isPersisted: boolean;
} | null>;
private assertInit;
stat(path: string): {
size: number;
};
/** Normalizes paths to /style format (absolute, no trailing slash unless root) */
static normalize(path: string): string;
private normalize;
/**
* Deep scans an OPFS DirectoryHandle and populates the Memory Cache recursively.
*/
private scanDirectory;
/**
* Traverses segment path to get the *parent directory* FileSystemDirectoryHandle.
* Required because OPFS works rigidly hierarchy-by-hierarchy.
* e.g., for `/docs/text/abc.txt`, returns the handle for `/docs/text/`.
*/
private resolvePath;
}
//# sourceMappingURL=vfs.d.ts.map
{"version":3,"file":"vfs.d.ts","sourceRoot":"","sources":["../../../src/vfs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,GAAG;IACd,OAAO,CAAC,KAAK,CAAiC;IAC9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FS } from './vfs';
export declare class WasiShim {
private vfs;
private fds;
private nextFd;
private memory?;
private heapStart;
private heapPtr;
private heapLimit;
constructor(vfs: VFS);
private static ALL_RIGHTS;
setMemory(memory: WebAssembly.Memory): void;
getImports(): WebAssembly.Imports;
private fd_write;
private fd_fdstat_get;
private fd_read;
private fd_close;
private fd_seek;
private fd_tell;
private fd_filestat_get;
private fd_filestat_set_size;
private fd_sync;
private path_filestat_get;
private path_rename;
private path_open;
private path_create_directory;
private strcmp;
private strlen;
private memmove;
private memset;
private memcpy;
private memcmp;
private strncmp;
private strcspn;
private strspn;
private strrchr;
private memchr;
private localtime_r;
private realloc;
}
export declare function createWasiImports(vfs: VFS): WebAssembly.Imports;
//# sourceMappingURL=wasi-shim.d.ts.map
{"version":3,"file":"wasi-shim.d.ts","sourceRoot":"","sources":["../../../src/wasi-shim.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAW5B,qBAAa,QAAQ;IACnB,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,GAAG,CAAyD;IACpE,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,MAAM,CAAC,CAAqB;IACpC,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,SAAS,CAAa;gBAElB,GAAG,EAAE,GAAG;IAYpB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuB;IAEhD,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM;IAUpC,UAAU,IAAI,WAAW,CAAC,OAAO;IAqGjC,OAAO,CAAC,QAAQ;IA4ChB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,OAAO;IAkCf,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,OAAO;IAiCf,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,eAAe;IAwBvB,OAAO,CAAC,oBAAoB;IAuB5B,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,iBAAiB;IAyBzB,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,SAAS;IA+CjB,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,MAAM;IA6Bd,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,MAAM;IAOd,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,MAAM;IAUd,OAAO,CAAC,OAAO;IAWf,OAAO,CAAC,OAAO;IAoBf,OAAO,CAAC,MAAM;IAoBd,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,WAAW;IAmCnB,OAAO,CAAC,OAAO;CAGhB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAAC,OAAO,CAG/D"}
import { VFS } from './vfs';
import { Router } from './router';
/**
* WasmOrchestrator runs exclusively inside the Kernel Web Worker.
* It is responsible for fetching, evaluating, holding, and gracefully proxying
* executions into `.wasm` modules deployed via the Module Registry mapping.
*/
export declare class WasmOrchestrator {
private modules;
private vfs;
private router;
private onEvent;
constructor(vfs: VFS, router: Router, onEvent: (event: string, payload: any) => void);
private readString;
/**
* Instantiates a WASM module and caches it in memory under `name`.
* Unloads any currently mapped instance holding that `name`.
* @param name - Module identifier string mapping (e.g. 'my-app')
* @param url - URL to either raw `.wasm` (Phase 4) or `.js` glue (Phase 5)
*/
loadModule(name: string, url: string): Promise<void>;
/**
* Auto-discovers exported functions and registers them in the kernel router.
*/
private registerModuleCommands;
/**
* Evaluates an exported WebAssembly function and wraps panics cleanly.
* If invoking using complex JS Objects, the Serde JSON contract automatically translates strings seamlessly.
*/
callFunction(moduleName: string, fnName: string, args?: unknown[]): any;
private parseResponse;
/**
* Dropping references allows the V8 garbage collector to evict WebAssembly memory.
*/
unloadModule(name: string): void;
}
//# sourceMappingURL=wasm-orchestrator.d.ts.map
{"version":3,"file":"wasm-orchestrator.d.ts","sourceRoot":"","sources":["../../../src/wasm-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAQvC;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAsC;IACrD,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAwC;gBAE3C,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI;IAMpF,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyS1D;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoB9B;;;OAGG;IACH,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,GAAG;IAwF3E,OAAO,CAAC,aAAa;IAkBrB;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAOjC"}
+1
-1
{
"name": "@r1-runtime/kernel",
"version": "0.3.1",
"version": "0.3.2",
"description": "Core OS-like kernel for R1 — WASM orchestration, VFS, and WASI shim.",

@@ -5,0 +5,0 @@ "type": "module",

/** A function that handles a specific message type in the Worker */
export declare type KernelHandler = (payload: any) => Promise<unknown>;
/** Interface for Kernel Plugins */
export declare interface KernelPlugin {
name: string;
getCommands(): Map<string, KernelHandler>;
}
/**
* Represents a request sent from the main thread to the Kernel Worker.
*/
export declare interface KernelRequest {
/** Unique nanoid used to match the response back to this request */
id: string;
/** Command name, e.g. 'IPC_INVOKE' or 'VFS_READ' */
type: string;
/** JSON-serialisable payload */
payload: unknown;
}
/**
* Represents a response sent from the Kernel Worker back to the main thread.
*/
export declare interface KernelResponse {
/** Matches the request id */
id: string;
/** The result data. Undefined if an error occurred. */
payload?: unknown;
/** The error string. Undefined on success. */
error?: string;
}
/**
* Routes incoming KernelRequests to the appropriate registered handler.
* Supports hierarchical naming (e.g., 'fs:read_file') and plugins.
*/
export declare class Router {
private handlers;
/**
* Register a new message handler for a specific message type.
*/
register(type: string, handler: KernelHandler): void;
/**
* Register a plugin, adding all its commands to the router prefixing them with plugin name.
*/
use(plugin: KernelPlugin): void;
/**
* Process an incoming request, route it to the handler, and return a response.
* Guaranteed to never throw; it always returns a KernelResponse envelope.
*/
handle(request: KernelRequest): Promise<KernelResponse>;
}
/**
* A Virtual File System wrapper combining an instant synchronous memory cache
* with asynchronous background OPFS (Origin Private File System) persistence.
* Designed purely for the Kernel Web Worker.
*/
export declare class VFS {
private cache;
private rootHandle?;
private isInit;
/**
* Must be called exactly once before any VFS operations.
* Acquires the OPFS root and deeply scans it to pre-warm the memory cache.
*/
init(): Promise<void>;
/** Check if a file or directory exists in the virtual filesystem */
exists(path: string): boolean;
/** Read bytes instantly from cache. Throws if not found. */
read(path: string): Uint8Array;
/** Helper to read UTF-8 strings */
readText(path: string): string;
/** List all absolute file or directory paths immediately under a given directory */
list(dir: string): string[];
/**
* Writes data. Updates in-memory immediately, writes to disk async.
* Automatically resolves missing parent directories.
*/
write(path: string, data: Uint8Array): Promise<void>;
/** Helper to write UTF-8 strings */
writeText(path: string, text: string): Promise<void>;
/** Emulates directory creation. In this architecture, writes auto-create parents, so this is just for strict APIs. */
mkdir(dir: string): Promise<void>;
/** Deletes a file. Removes from cache immediately, deletes from OPFS async. */
delete(path: string): Promise<void>;
private checkStorageQuota;
getStorageInfo(): Promise<{
usedBytes: number;
quotaBytes: number;
percentUsed: number;
isPersisted: boolean;
} | null>;
private assertInit;
stat(path: string): {
size: number;
};
/** Normalizes paths to /style format (absolute, no trailing slash unless root) */
static normalize(path: string): string;
private normalize;
/**
* Deep scans an OPFS DirectoryHandle and populates the Memory Cache recursively.
*/
private scanDirectory;
/**
* Traverses segment path to get the *parent directory* FileSystemDirectoryHandle.
* Required because OPFS works rigidly hierarchy-by-hierarchy.
* e.g., for `/docs/text/abc.txt`, returns the handle for `/docs/text/`.
*/
private resolvePath;
}
/**
* WasmOrchestrator runs exclusively inside the Kernel Web Worker.
* It is responsible for fetching, evaluating, holding, and gracefully proxying
* executions into `.wasm` modules deployed via the Module Registry mapping.
*/
export declare class WasmOrchestrator {
private modules;
private vfs;
private router;
private onEvent;
constructor(vfs: VFS, router: Router, onEvent: (event: string, payload: any) => void);
private readString;
/**
* Instantiates a WASM module and caches it in memory under `name`.
* Unloads any currently mapped instance holding that `name`.
* @param name - Module identifier string mapping (e.g. 'my-app')
* @param url - URL to either raw `.wasm` (Phase 4) or `.js` glue (Phase 5)
*/
loadModule(name: string, url: string): Promise<void>;
/**
* Auto-discovers exported functions and registers them in the kernel router.
*/
private registerModuleCommands;
/**
* Evaluates an exported WebAssembly function and wraps panics cleanly.
* If invoking using complex JS Objects, the Serde JSON contract automatically translates strings seamlessly.
*/
callFunction(moduleName: string, fnName: string, args?: unknown[]): any;
private parseResponse;
/**
* Dropping references allows the V8 garbage collector to evict WebAssembly memory.
*/
unloadModule(name: string): void;
}
export { }