@@ -17,7 +17,7 @@ const NODE_IMPORT_CACHE_MATERIALIZE_TIMEOUT_MS_ENV: &str =
1717 "AGENTOS_NODE_IMPORT_CACHE_MATERIALIZE_TIMEOUT_MS" ;
1818const NODE_IMPORT_CACHE_SCHEMA_VERSION : & str = "1" ;
1919const NODE_IMPORT_CACHE_LOADER_VERSION : & str = "8" ;
20- const NODE_IMPORT_CACHE_ASSET_VERSION : & str = "71 " ;
20+ const NODE_IMPORT_CACHE_ASSET_VERSION : & str = "78 " ;
2121const NODE_IMPORT_CACHE_DIR_PREFIX : & str = "agentos-node-import-cache" ;
2222const DEFAULT_NODE_IMPORT_CACHE_MATERIALIZE_TIMEOUT : Duration = Duration :: from_secs ( 30 ) ;
2323const PYODIDE_DIST_DIR : & str = "pyodide-dist" ;
@@ -9228,17 +9228,24 @@ function decodeBase64ToUint8Array(value) {
92289228 return bytes;
92299229}
92309230
9231- function readKernelStdinChunk(maxBytes) {
9231+ function readKernelStdinChunk(maxBytes, timeoutMs = 10 ) {
92329232 const requestedLength = Math.max(1, Number(maxBytes) >>> 0);
9233+ const numericTimeoutMs = Number(timeoutMs);
9234+ const blocking = !Number.isFinite(numericTimeoutMs) || numericTimeoutMs >= 0xffffffff;
9235+ const deadline = blocking ? 0 : Date.now() + Math.max(0, numericTimeoutMs);
92339236 while (true) {
9234- const response = callSyncRpc('__kernel_stdin_read', [requestedLength, 10]);
9237+ const waitMs = blocking ? 10 : Math.max(0, Math.min(10, deadline - Date.now()));
9238+ const response = callSyncRpc('__kernel_stdin_read', [requestedLength, waitMs]);
92359239 if (response && typeof response.dataBase64 === 'string') {
92369240 return Buffer.from(response.dataBase64, 'base64');
92379241 }
92389242 if (response && response.done === true) {
92399243 return null;
92409244 }
9241- Atomics.wait(syntheticWaitArray, 0, 0, 10);
9245+ if (!blocking && Date.now() >= deadline) {
9246+ return Buffer.alloc(0);
9247+ }
9248+ Atomics.wait(syntheticWaitArray, 0, 0, blocking ? 10 : Math.max(0, Math.min(10, deadline - Date.now())));
92429249 }
92439250}
92449251
@@ -12380,7 +12387,12 @@ const hostUserImport = {
1238012387 },
1238112388 isatty(fd, retBoolPtr) {
1238212389 const descriptor = Number(fd) >>> 0;
12383- const isTerminal = descriptor <= 2 ? 0 : 0;
12390+ let isTerminal = 0;
12391+ try {
12392+ isTerminal = callSyncRpc('__kernel_isatty', [descriptor]) === true ? 1 : 0;
12393+ } catch {
12394+ isTerminal = 0;
12395+ }
1238412396 return writeGuestUint32(retBoolPtr, isTerminal);
1238512397 },
1238612398 getpwuid(uid, bufPtr, bufLen, retLenPtr) {
@@ -12393,6 +12405,67 @@ const hostUserImport = {
1239312405 },
1239412406};
1239512407
12408+ const hostTtyImport = {
12409+ isatty(fd) {
12410+ try {
12411+ const result = callSyncRpc('__kernel_isatty', [Number(fd) >>> 0]);
12412+ return result === true || result === 1 ? 1 : 0;
12413+ } catch (error) {
12414+ process?.stderr?.write?.(`WARN host_tty.isatty failed: ${error?.stack || error}\n`);
12415+ return 0;
12416+ }
12417+ },
12418+ get_size(fd, colsPtr, rowsPtr) {
12419+ try {
12420+ if (!(instanceMemory instanceof WebAssembly.Memory)) {
12421+ return WASI_ERRNO_FAULT;
12422+ }
12423+ const size = callSyncRpc('__kernel_tty_size', [Number(fd) >>> 0]);
12424+ if (!size || typeof size !== 'object') {
12425+ return WASI_ERRNO_FAULT;
12426+ }
12427+ const colsValue = Array.isArray(size) ? size[0] : size.cols;
12428+ const rowsValue = Array.isArray(size) ? size[1] : size.rows;
12429+ const cols = Math.max(0, Math.min(0xffff, Number(colsValue) >>> 0));
12430+ const rows = Math.max(0, Math.min(0xffff, Number(rowsValue) >>> 0));
12431+ const view = new DataView(instanceMemory.buffer);
12432+ view.setUint16(Number(colsPtr) >>> 0, cols, true);
12433+ view.setUint16(Number(rowsPtr) >>> 0, rows, true);
12434+ return WASI_ERRNO_SUCCESS;
12435+ } catch (error) {
12436+ process?.stderr?.write?.(`WARN host_tty.get_size failed: ${error?.stack || error}\n`);
12437+ return WASI_ERRNO_FAULT;
12438+ }
12439+ },
12440+ set_raw_mode(enabled) {
12441+ try {
12442+ callSyncRpc('__pty_set_raw_mode', [Number(enabled) !== 0]);
12443+ return WASI_ERRNO_SUCCESS;
12444+ } catch (error) {
12445+ process?.stderr?.write?.(`WARN host_tty.set_raw_mode failed: ${error?.stack || error}\n`);
12446+ return WASI_ERRNO_FAULT;
12447+ }
12448+ },
12449+ read(ptr, len, timeoutMs = 10) {
12450+ try {
12451+ if (!(instanceMemory instanceof WebAssembly.Memory)) {
12452+ return 0;
12453+ }
12454+ const requestedLength = Math.max(1, Number(len) >>> 0);
12455+ const chunk = readKernelStdinChunk(requestedLength, Number(timeoutMs) >>> 0);
12456+ if (!chunk || chunk.length === 0) {
12457+ return 0;
12458+ }
12459+ const written = Math.min(chunk.length, requestedLength);
12460+ new Uint8Array(instanceMemory.buffer).set(chunk.subarray(0, written), Number(ptr) >>> 0);
12461+ return written >>> 0;
12462+ } catch (error) {
12463+ process?.stderr?.write?.(`WARN host_tty.read failed: ${error?.stack || error}\n`);
12464+ return 0;
12465+ }
12466+ },
12467+ };
12468+
1239612469const HOST_FS_MODE_REGULAR = 0o100644;
1239712470const HOST_FS_MODE_CHARACTER = 0o020666;
1239812471const HOST_FS_MODE_FIFO = 0o010600;
@@ -12874,7 +12947,7 @@ wasiImport.fd_read = (fd, iovs, iovsLen, nreadPtr) => {
1287412947 const sidecarManagedProcess =
1287512948 typeof process?.env?.AGENTOS_SANDBOX_ROOT === 'string' &&
1287612949 process.env.AGENTOS_SANDBOX_ROOT.length > 0;
12877- if (sidecarManagedProcess || KERNEL_STDIO_SYNC_RPC ) {
12950+ if (typeof callSyncRpc === 'function' ) {
1287812951 try {
1287912952 const requestedLength = (() => {
1288012953 if (!(instanceMemory instanceof WebAssembly.Memory)) {
@@ -12888,7 +12961,7 @@ wasiImport.fd_read = (fd, iovs, iovsLen, nreadPtr) => {
1288812961 }
1288912962 return total >>> 0;
1289012963 })();
12891- const chunk = readKernelStdinChunk(requestedLength);
12964+ const chunk = readKernelStdinChunk(requestedLength, 0xffffffff );
1289212965 if (!chunk || chunk.length === 0) {
1289312966 return writeGuestUint32(nreadPtr, 0);
1289412967 }
@@ -13637,6 +13710,7 @@ const instance = new WebAssembly.Instance(module, {
1363713710 : limitedHostProcessImport,
1363813711 host_net: permissionTier === 'full' ? hostNetImport : undefined,
1363913712 host_user: hostUserImport,
13713+ host_tty: hostTtyImport,
1364013714 host_fs: hostFsImport,
1364113715});
1364213716
0 commit comments