tensorlake 0.5.131 → 0.5.133

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +27 -0
  2. package/dist/applications/index.cjs +492 -708
  3. package/dist/applications/index.cjs.map +1 -1
  4. package/dist/applications/index.d.cts +3 -3
  5. package/dist/applications/index.d.ts +3 -3
  6. package/dist/applications/index.js +493 -713
  7. package/dist/applications/index.js.map +1 -1
  8. package/dist/function-agent/main.cjs +5 -2
  9. package/dist/function-agent/main.cjs.map +1 -1
  10. package/dist/function-agent/main.js +6 -3
  11. package/dist/function-agent/main.js.map +1 -1
  12. package/dist/function-executor/main.cjs +6 -3
  13. package/dist/function-executor/main.cjs.map +1 -1
  14. package/dist/function-executor/main.js +7 -4
  15. package/dist/function-executor/main.js.map +1 -1
  16. package/dist/index.cjs +121 -418
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +8 -22
  19. package/dist/index.d.ts +8 -22
  20. package/dist/index.js +122 -423
  21. package/dist/index.js.map +1 -1
  22. package/dist/native-worker.cjs +1 -0
  23. package/dist/native-worker.cjs.map +1 -1
  24. package/dist/native-worker.js +1 -0
  25. package/dist/native-worker.js.map +1 -1
  26. package/dist/{remote-DRCCuRth.d.cts → remote-D95Y6Czr.d.cts} +1 -1
  27. package/dist/{remote-0dzBqScB.d.ts → remote-omwTzbfj.d.ts} +1 -1
  28. package/dist/{sandbox-image-Bf5bcxtO.d.cts → sandbox-image-ChzWDeZy.d.cts} +2 -0
  29. package/dist/{sandbox-image-Bf5bcxtO.d.ts → sandbox-image-ChzWDeZy.d.ts} +2 -0
  30. package/dist/sandbox-image.cjs +476 -453
  31. package/dist/sandbox-image.cjs.map +1 -1
  32. package/dist/sandbox-image.d.cts +1 -1
  33. package/dist/sandbox-image.d.ts +1 -1
  34. package/dist/sandbox-image.js +475 -456
  35. package/dist/sandbox-image.js.map +1 -1
  36. package/package.json +8 -8
  37. package/runtime/function-executor/manifest.json +14 -14
  38. package/runtime/function-executor/package/dist/function-executor/main.js +7 -4
  39. package/runtime/function-executor/package/dist/function-executor/main.js.map +1 -1
  40. package/runtime/function-executor/package/dist/native-worker.cjs +1 -0
  41. package/runtime/function-executor/package/dist/native-worker.cjs.map +1 -1
  42. package/runtime/function-executor/package/npm-shrinkwrap.json +2 -12
  43. package/runtime/function-executor/package/package.json +1 -2
  44. package/runtime/typescript-function-runner/manifest.json +13 -13
  45. package/runtime/typescript-function-runner/package/dist/function-agent/main.js +6 -3
  46. package/runtime/typescript-function-runner/package/dist/function-agent/main.js.map +1 -1
  47. package/runtime/typescript-function-runner/package/dist/native-worker.cjs +1 -0
  48. package/runtime/typescript-function-runner/package/dist/native-worker.cjs.map +1 -1
  49. package/runtime/typescript-function-runner/package/npm-shrinkwrap.json +20 -29
  50. package/runtime/typescript-function-runner/package/package.json +7 -7
@@ -224,6 +224,7 @@ port.on("message", (message) => {
224
224
  return;
225
225
  }
226
226
  if (message.type === "release") {
227
+ handles.get(message.handleId)?.value?.close?.();
227
228
  handles.delete(message.handleId);
228
229
  for (const stream of streams.values()) {
229
230
  if (stream.handleId === message.handleId) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../node_modules/tsup/assets/cjs_shims.js","../lib/libc.cjs","../src/native-worker.ts","../src/native-binding.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","// Read the ELF interpreter, rather than generating a process-wide diagnostic\n// report. Both supported Linux architectures use little-endian ELF64. Reads\n// are bounded to the header, program headers, and interpreter pathname.\nfunction detectLinuxLibc(fs, executable = process.execPath) {\n const override = process.env.TENSORLAKE_NODE_LIBC;\n if (override != null) {\n if (override === \"gnu\" || override === \"musl\") return override;\n throw new Error(\"TENSORLAKE_NODE_LIBC must be 'gnu' or 'musl'.\");\n }\n\n let fd;\n try {\n fd = fs.openSync(executable, \"r\");\n function read(size, offset) {\n if (!Number.isSafeInteger(offset) || offset < 0) {\n throw new Error(\"Invalid ELF offset\");\n }\n const buffer = Buffer.alloc(size);\n let count = 0;\n while (count < size) {\n const bytes = fs.readSync(fd, buffer, count, size - count, offset + count);\n if (bytes === 0) throw new Error(\"Truncated ELF executable\");\n count += bytes;\n }\n return buffer;\n }\n\n const header = read(64, 0);\n if (header.readUInt32BE(0) !== 0x7f454c46 || header[4] !== 2 || header[5] !== 1) {\n throw new Error(\"Expected a little-endian ELF64 executable\");\n }\n const entrySize = header.readUInt16LE(54);\n const count = header.readUInt16LE(56);\n if (entrySize !== 56 || count === 0 || count > 128) {\n throw new Error(\"Unsupported ELF program headers\");\n }\n const entries = read(entrySize * count, Number(header.readBigUInt64LE(32)));\n for (let i = 0; i < count; i++) {\n const offset = i * entrySize;\n if (entries.readUInt32LE(offset) !== 3) continue; // PT_INTERP\n const size = Number(entries.readBigUInt64LE(offset + 32));\n if (size < 2 || size > 4096) throw new Error(\"Invalid ELF interpreter size\");\n const interpreter = read(size, Number(entries.readBigUInt64LE(offset + 8)));\n if (interpreter[size - 1] !== 0) throw new Error(\"Unterminated ELF interpreter\");\n const name = interpreter.subarray(0, -1).toString(\"utf8\").split(\"/\").at(-1);\n if (name.startsWith(\"ld-musl-\")) return \"musl\";\n if (name.startsWith(\"ld-linux-\")) return \"gnu\";\n throw new Error(\"Unrecognized ELF interpreter\");\n }\n throw new Error(\"No ELF interpreter (statically linked executable)\");\n } catch (cause) {\n throw new Error(\n \"Unable to detect Linux libc from the Node executable. Set TENSORLAKE_NODE_LIBC to 'gnu' or 'musl' for a nonstandard runtime.\",\n { cause },\n );\n } finally {\n if (fd != null) fs.closeSync(fd);\n }\n}\n\nmodule.exports = { detectLinuxLibc };\n","import { parentPort } from \"node:worker_threads\";\nimport { loadNative } from \"./native-binding.js\";\nimport type {\n WorkerRequest,\n WorkerResponse,\n} from \"./native-worker-protocol.js\";\n\nconst port = parentPort!;\n// This module is only a worker entrypoint. All platform detection, dlopen and\n// native object construction happen in this isolate.\nconst binding = loadNative<Record<string, any>>();\nconst handles = new Map<number, { value?: any; error?: unknown }>();\ninterface StreamState {\n cancel?: () => void;\n handleId?: number;\n ack?: () => void;\n}\nconst streams = new Map<number, StreamState>();\n\nfunction getHandle(id: number): any {\n const entry = handles.get(id);\n if (!entry) throw new Error(\"Tensorlake native handle has been released\");\n if (entry.error) throw entry.error;\n return entry.value;\n}\n\n/** Structured clone turns Buffers into Uint8Arrays; napi expects Buffers. */\nfunction nativeArgs(value: any): any {\n if (value instanceof Uint8Array)\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength);\n if (Array.isArray(value)) return value.map(nativeArgs);\n if (value && typeof value === \"object\")\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, nativeArgs(v)]),\n );\n return value;\n}\n\nfunction send(message: WorkerResponse): void {\n port.postMessage(message);\n}\n\nport.on(\"message\", (message: WorkerRequest) => {\n if (message.type === \"create\") {\n try {\n const { kind, args, id } = message.handle;\n const ctor = binding[kind];\n if (typeof ctor !== \"function\")\n throw new Error(\n `native binding does not export ${kind}; rebuild with 'npm run build:native'`,\n );\n const value =\n message.parentId === undefined\n ? new ctor(...args)\n : getHandle(message.parentId).connectProxy(...args);\n handles.set(id, { value });\n } catch (error) {\n handles.set(message.handle.id, { error });\n }\n return;\n }\n if (message.type === \"release\") {\n handles.delete(message.handleId);\n for (const stream of streams.values()) {\n if (stream.handleId === message.handleId) {\n stream.cancel?.();\n stream.ack?.();\n }\n }\n return;\n }\n if (message.type === \"cancel\" || message.type === \"ack\") {\n const stream = streams.get(message.id);\n if (message.type === \"cancel\") stream?.cancel?.();\n stream?.ack?.();\n if (stream) stream.ack = undefined;\n return;\n }\n if (message.type === \"call\") void invoke(message);\n});\n\nasync function invoke(\n message: Extract<WorkerRequest, { type: \"call\" }>,\n): Promise<void> {\n try {\n const target =\n message.handleId === undefined ? binding : getHandle(message.handleId);\n const args = nativeArgs(message.args);\n let stream: StreamState | undefined;\n if (message.stream) {\n stream = { handleId: message.handleId };\n const state = stream;\n streams.set(message.id, stream);\n args.push(\n (value: string) =>\n new Promise<void>((resolve) => {\n state.ack = resolve;\n send({ type: \"event\", id: message.id, value });\n }),\n );\n }\n const call = target[message.method](...args);\n if (stream) stream.cancel = call.cancel;\n const value = await (stream ? call.result : call);\n send({ type: \"result\", id: message.id, value });\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n send({\n type: \"error\",\n id: message.id,\n error: { name: error.name, message: error.message, stack: error.stack },\n });\n } finally {\n streams.get(message.id)?.ack?.();\n streams.delete(message.id);\n }\n}\n","import { detectLinuxLibc } from \"../lib/libc.cjs\";\nimport * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\ninterface RuntimeReport {\n header?: {\n glibcVersionRuntime?: string;\n };\n}\n\ninterface TargetOptions {\n libc?: \"gnu\" | \"musl\";\n report?: RuntimeReport;\n}\n\ninterface NativeBindingPathOptions extends TargetOptions {\n packageRoot?: string;\n platform?: NodeJS.Platform;\n arch?: string;\n}\n\nconst NATIVE_PACKAGES: Readonly<Record<string, string>> = {\n \"darwin-arm64\": \"tensorlake-native-darwin-arm64\",\n \"linux-arm64\": \"tensorlake-native-linux-arm64-gnu\",\n \"linux-arm64-musl\": \"tensorlake-native-linux-arm64-musl\",\n \"linux-x64\": \"tensorlake-native-linux-x64-gnu\",\n \"linux-x64-musl\": \"tensorlake-native-linux-x64-musl\",\n \"win32-x64\": \"tensorlake-native-win32-x64\",\n};\n\nfunction packageRoot(): string {\n const parent = fileURLToPath(new URL(\"../\", import.meta.url));\n if (fs.existsSync(path.join(parent, \"package.json\"))) return parent;\n const grandparent = fileURLToPath(new URL(\"../../\", import.meta.url));\n if (fs.existsSync(path.join(grandparent, \"package.json\"))) return grandparent;\n return parent;\n}\n\nlet cachedLinuxLibc: \"gnu\" | \"musl\" | undefined;\n\nfunction linuxLibcFamily(options: TargetOptions): \"gnu\" | \"musl\" {\n if (options.libc != null) return options.libc;\n if (options.report != null) {\n return options.report.header?.glibcVersionRuntime ? \"gnu\" : \"musl\";\n }\n if (cachedLinuxLibc != null) return cachedLinuxLibc;\n\n cachedLinuxLibc = detectLinuxLibc(fs);\n return cachedLinuxLibc;\n}\n\nexport function nativeTargetId(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string {\n const target = `${platform}-${arch}`;\n if (platform !== \"linux\") return target;\n if (options.libc == null && options.report == null && platform !== process.platform) {\n return target;\n }\n return linuxLibcFamily(options) === \"musl\" ? `${target}-musl` : target;\n}\n\nexport function nativeBindingPath(options: NativeBindingPathOptions = {}): string {\n const platform = options.platform ?? process.platform;\n const arch = options.arch ?? process.arch;\n return path.join(\n options.packageRoot ?? packageRoot(),\n \"dist\",\n \"native\",\n nativeTargetId(platform, arch, options),\n \"tensorlake-node.node\",\n );\n}\n\nexport function nativePackageName(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string | undefined {\n return NATIVE_PACKAGES[nativeTargetId(platform, arch, options)];\n}\n\nexport function loadNative<T>(): T {\n const target = nativeTargetId();\n const bindingPath = nativeBindingPath();\n const require = createRequire(import.meta.url);\n\n // Local source builds stage the addon here. Published packages intentionally\n // omit this directory and resolve the platform-specific optional dependency.\n if (fs.existsSync(bindingPath)) return require(bindingPath) as T;\n\n const packageName = nativePackageName();\n if (!packageName) {\n throw new Error(\n `Tensorlake does not provide a native binding for ${target}.`,\n );\n }\n\n let packageEntry: string;\n try {\n packageEntry = require.resolve(packageName);\n } catch (cause) {\n throw new Error(\n `Missing native binding package ${packageName} for ${target}. Reinstall tensorlake without omitting optional dependencies, and install dependencies on the machine where they will run.`,\n { cause },\n );\n }\n return require(packageEntry) as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAKM,kBAOO;AAZb;AAAA;AAAA;AAKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;AAAA;AAAA;;;ACZ9D;AAAA,iBAAAA,UAAAC,SAAA;AAAA;AAAA;AAGA,aAASC,iBAAgBC,KAAI,aAAa,QAAQ,UAAU;AAC1D,YAAM,WAAW,QAAQ,IAAI;AAC7B,UAAI,YAAY,MAAM;AACpB,YAAI,aAAa,SAAS,aAAa,OAAQ,QAAO;AACtD,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AAEA,UAAI;AACJ,UAAI;AAEF,YAASC,QAAT,SAAc,MAAM,QAAQ;AAC1B,cAAI,CAAC,OAAO,cAAc,MAAM,KAAK,SAAS,GAAG;AAC/C,kBAAM,IAAI,MAAM,oBAAoB;AAAA,UACtC;AACA,gBAAM,SAAS,OAAO,MAAM,IAAI;AAChC,cAAIC,SAAQ;AACZ,iBAAOA,SAAQ,MAAM;AACnB,kBAAM,QAAQF,IAAG,SAAS,IAAI,QAAQE,QAAO,OAAOA,QAAO,SAASA,MAAK;AACzE,gBAAI,UAAU,EAAG,OAAM,IAAI,MAAM,0BAA0B;AAC3D,YAAAA,UAAS;AAAA,UACX;AACA,iBAAO;AAAA,QACT;AAZS,mBAAAD;AADT,aAAKD,IAAG,SAAS,YAAY,GAAG;AAehC,cAAM,SAASC,MAAK,IAAI,CAAC;AACzB,YAAI,OAAO,aAAa,CAAC,MAAM,cAAc,OAAO,CAAC,MA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,QAAQ,aAAa,SAAY,UAAU,UAAU,QAAQ,QAAQ;AACvE,UAAM,OAAO,WAAW,QAAQ,IAAI;AACpC,QAAI;AACJ,QAAI,QAAQ,QAAQ;AAClB,eAAS,EAAE,UAAU,QAAQ,SAAS;AACtC,YAAM,QAAQ;AACd,cAAQ,IAAI,QAAQ,IAAI,MAAM;AAC9B,WAAK;AAAA,QACH,CAACC,WACC,IAAI,QAAc,CAAC,YAAY;AAC7B,gBAAM,MAAM;AACZ,eAAK,EAAE,MAAM,SAAS,IAAI,QAAQ,IAAI,OAAAA,OAAM,CAAC;AAAA,QAC/C,CAAC;AAAA,MACL;AAAA,IACF;AACA,UAAM,OAAO,OAAO,QAAQ,MAAM,EAAE,GAAG,IAAI;AAC3C,QAAI,OAAQ,QAAO,SAAS,KAAK;AACjC,UAAM,QAAQ,OAAO,SAAS,KAAK,SAAS;AAC5C,SAAK,EAAE,MAAM,UAAU,IAAI,QAAQ,IAAI,MAAM,CAAC;AAAA,EAChD,SAAS,OAAO;AACd,UAAM,QAAQ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACtE,SAAK;AAAA,MACH,MAAM;AAAA,MACN,IAAI,QAAQ;AAAA,MACZ,OAAO,EAAE,MAAM,MAAM,MAAM,SAAS,MAAM,SAAS,OAAO,MAAM,MAAM;AAAA,IACxE,CAAC;AAAA,EACH,UAAE;AACA,YAAQ,IAAI,QAAQ,EAAE,GAAG,MAAM;AAC/B,YAAQ,OAAO,QAAQ,EAAE;AAAA,EAC3B;AACF;","names":["exports","module","detectLinuxLibc","fs","read","count","path","require","value"]}
1
+ {"version":3,"sources":["../node_modules/tsup/assets/cjs_shims.js","../lib/libc.cjs","../src/native-worker.ts","../src/native-binding.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","// Read the ELF interpreter, rather than generating a process-wide diagnostic\n// report. Both supported Linux architectures use little-endian ELF64. Reads\n// are bounded to the header, program headers, and interpreter pathname.\nfunction detectLinuxLibc(fs, executable = process.execPath) {\n const override = process.env.TENSORLAKE_NODE_LIBC;\n if (override != null) {\n if (override === \"gnu\" || override === \"musl\") return override;\n throw new Error(\"TENSORLAKE_NODE_LIBC must be 'gnu' or 'musl'.\");\n }\n\n let fd;\n try {\n fd = fs.openSync(executable, \"r\");\n function read(size, offset) {\n if (!Number.isSafeInteger(offset) || offset < 0) {\n throw new Error(\"Invalid ELF offset\");\n }\n const buffer = Buffer.alloc(size);\n let count = 0;\n while (count < size) {\n const bytes = fs.readSync(fd, buffer, count, size - count, offset + count);\n if (bytes === 0) throw new Error(\"Truncated ELF executable\");\n count += bytes;\n }\n return buffer;\n }\n\n const header = read(64, 0);\n if (header.readUInt32BE(0) !== 0x7f454c46 || header[4] !== 2 || header[5] !== 1) {\n throw new Error(\"Expected a little-endian ELF64 executable\");\n }\n const entrySize = header.readUInt16LE(54);\n const count = header.readUInt16LE(56);\n if (entrySize !== 56 || count === 0 || count > 128) {\n throw new Error(\"Unsupported ELF program headers\");\n }\n const entries = read(entrySize * count, Number(header.readBigUInt64LE(32)));\n for (let i = 0; i < count; i++) {\n const offset = i * entrySize;\n if (entries.readUInt32LE(offset) !== 3) continue; // PT_INTERP\n const size = Number(entries.readBigUInt64LE(offset + 32));\n if (size < 2 || size > 4096) throw new Error(\"Invalid ELF interpreter size\");\n const interpreter = read(size, Number(entries.readBigUInt64LE(offset + 8)));\n if (interpreter[size - 1] !== 0) throw new Error(\"Unterminated ELF interpreter\");\n const name = interpreter.subarray(0, -1).toString(\"utf8\").split(\"/\").at(-1);\n if (name.startsWith(\"ld-musl-\")) return \"musl\";\n if (name.startsWith(\"ld-linux-\")) return \"gnu\";\n throw new Error(\"Unrecognized ELF interpreter\");\n }\n throw new Error(\"No ELF interpreter (statically linked executable)\");\n } catch (cause) {\n throw new Error(\n \"Unable to detect Linux libc from the Node executable. Set TENSORLAKE_NODE_LIBC to 'gnu' or 'musl' for a nonstandard runtime.\",\n { cause },\n );\n } finally {\n if (fd != null) fs.closeSync(fd);\n }\n}\n\nmodule.exports = { detectLinuxLibc };\n","import { parentPort } from \"node:worker_threads\";\nimport { loadNative } from \"./native-binding.js\";\nimport type {\n WorkerRequest,\n WorkerResponse,\n} from \"./native-worker-protocol.js\";\n\nconst port = parentPort!;\n// This module is only a worker entrypoint. All platform detection, dlopen and\n// native object construction happen in this isolate.\nconst binding = loadNative<Record<string, any>>();\nconst handles = new Map<number, { value?: any; error?: unknown }>();\ninterface StreamState {\n cancel?: () => void;\n handleId?: number;\n ack?: () => void;\n}\nconst streams = new Map<number, StreamState>();\n\nfunction getHandle(id: number): any {\n const entry = handles.get(id);\n if (!entry) throw new Error(\"Tensorlake native handle has been released\");\n if (entry.error) throw entry.error;\n return entry.value;\n}\n\n/** Structured clone turns Buffers into Uint8Arrays; napi expects Buffers. */\nfunction nativeArgs(value: any): any {\n if (value instanceof Uint8Array)\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength);\n if (Array.isArray(value)) return value.map(nativeArgs);\n if (value && typeof value === \"object\")\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, nativeArgs(v)]),\n );\n return value;\n}\n\nfunction send(message: WorkerResponse): void {\n port.postMessage(message);\n}\n\nport.on(\"message\", (message: WorkerRequest) => {\n if (message.type === \"create\") {\n try {\n const { kind, args, id } = message.handle;\n const ctor = binding[kind];\n if (typeof ctor !== \"function\")\n throw new Error(\n `native binding does not export ${kind}; rebuild with 'npm run build:native'`,\n );\n const value =\n message.parentId === undefined\n ? new ctor(...args)\n : getHandle(message.parentId).connectProxy(...args);\n handles.set(id, { value });\n } catch (error) {\n handles.set(message.handle.id, { error });\n }\n return;\n }\n if (message.type === \"release\") {\n // Cloud clients own cancellation for buffered requests as well as streams.\n handles.get(message.handleId)?.value?.close?.();\n handles.delete(message.handleId);\n for (const stream of streams.values()) {\n if (stream.handleId === message.handleId) {\n stream.cancel?.();\n stream.ack?.();\n }\n }\n return;\n }\n if (message.type === \"cancel\" || message.type === \"ack\") {\n const stream = streams.get(message.id);\n if (message.type === \"cancel\") stream?.cancel?.();\n stream?.ack?.();\n if (stream) stream.ack = undefined;\n return;\n }\n if (message.type === \"call\") void invoke(message);\n});\n\nasync function invoke(\n message: Extract<WorkerRequest, { type: \"call\" }>,\n): Promise<void> {\n try {\n const target =\n message.handleId === undefined ? binding : getHandle(message.handleId);\n const args = nativeArgs(message.args);\n let stream: StreamState | undefined;\n if (message.stream) {\n stream = { handleId: message.handleId };\n const state = stream;\n streams.set(message.id, stream);\n args.push(\n (value: string) =>\n new Promise<void>((resolve) => {\n state.ack = resolve;\n send({ type: \"event\", id: message.id, value });\n }),\n );\n }\n const call = target[message.method](...args);\n if (stream) stream.cancel = call.cancel;\n const value = await (stream ? call.result : call);\n send({ type: \"result\", id: message.id, value });\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n send({\n type: \"error\",\n id: message.id,\n error: { name: error.name, message: error.message, stack: error.stack },\n });\n } finally {\n streams.get(message.id)?.ack?.();\n streams.delete(message.id);\n }\n}\n","import { detectLinuxLibc } from \"../lib/libc.cjs\";\nimport * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\ninterface RuntimeReport {\n header?: {\n glibcVersionRuntime?: string;\n };\n}\n\ninterface TargetOptions {\n libc?: \"gnu\" | \"musl\";\n report?: RuntimeReport;\n}\n\ninterface NativeBindingPathOptions extends TargetOptions {\n packageRoot?: string;\n platform?: NodeJS.Platform;\n arch?: string;\n}\n\nconst NATIVE_PACKAGES: Readonly<Record<string, string>> = {\n \"darwin-arm64\": \"tensorlake-native-darwin-arm64\",\n \"linux-arm64\": \"tensorlake-native-linux-arm64-gnu\",\n \"linux-arm64-musl\": \"tensorlake-native-linux-arm64-musl\",\n \"linux-x64\": \"tensorlake-native-linux-x64-gnu\",\n \"linux-x64-musl\": \"tensorlake-native-linux-x64-musl\",\n \"win32-x64\": \"tensorlake-native-win32-x64\",\n};\n\nfunction packageRoot(): string {\n const parent = fileURLToPath(new URL(\"../\", import.meta.url));\n if (fs.existsSync(path.join(parent, \"package.json\"))) return parent;\n const grandparent = fileURLToPath(new URL(\"../../\", import.meta.url));\n if (fs.existsSync(path.join(grandparent, \"package.json\"))) return grandparent;\n return parent;\n}\n\nlet cachedLinuxLibc: \"gnu\" | \"musl\" | undefined;\n\nfunction linuxLibcFamily(options: TargetOptions): \"gnu\" | \"musl\" {\n if (options.libc != null) return options.libc;\n if (options.report != null) {\n return options.report.header?.glibcVersionRuntime ? \"gnu\" : \"musl\";\n }\n if (cachedLinuxLibc != null) return cachedLinuxLibc;\n\n cachedLinuxLibc = detectLinuxLibc(fs);\n return cachedLinuxLibc;\n}\n\nexport function nativeTargetId(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string {\n const target = `${platform}-${arch}`;\n if (platform !== \"linux\") return target;\n if (options.libc == null && options.report == null && platform !== process.platform) {\n return target;\n }\n return linuxLibcFamily(options) === \"musl\" ? `${target}-musl` : target;\n}\n\nexport function nativeBindingPath(options: NativeBindingPathOptions = {}): string {\n const platform = options.platform ?? process.platform;\n const arch = options.arch ?? process.arch;\n return path.join(\n options.packageRoot ?? packageRoot(),\n \"dist\",\n \"native\",\n nativeTargetId(platform, arch, options),\n \"tensorlake-node.node\",\n );\n}\n\nexport function nativePackageName(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string | undefined {\n return NATIVE_PACKAGES[nativeTargetId(platform, arch, options)];\n}\n\nexport function loadNative<T>(): T {\n const target = nativeTargetId();\n const bindingPath = nativeBindingPath();\n const require = createRequire(import.meta.url);\n\n // Local source builds stage the addon here. Published packages intentionally\n // omit this directory and resolve the platform-specific optional dependency.\n if (fs.existsSync(bindingPath)) return require(bindingPath) as T;\n\n const packageName = nativePackageName();\n if (!packageName) {\n throw new Error(\n `Tensorlake does not provide a native binding for ${target}.`,\n );\n }\n\n let packageEntry: string;\n try {\n packageEntry = require.resolve(packageName);\n } catch (cause) {\n throw new Error(\n `Missing native binding package ${packageName} for ${target}. Reinstall tensorlake without omitting optional dependencies, and install dependencies on the machine where they will run.`,\n { cause },\n );\n }\n return require(packageEntry) as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAKM,kBAOO;AAZb;AAAA;AAAA;AAKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;AAAA;AAAA;;;ACZ9D;AAAA,iBAAAA,UAAAC,SAAA;AAAA;AAAA;AAGA,aAASC,iBAAgBC,KAAI,aAAa,QAAQ,UAAU;AAC1D,YAAM,WAAW,QAAQ,IAAI;AAC7B,UAAI,YAAY,MAAM;AACpB,YAAI,aAAa,SAAS,aAAa,OAAQ,QAAO;AACtD,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AAEA,UAAI;AACJ,UAAI;AAEF,YAASC,QAAT,SAAc,MAAM,QAAQ;AAC1B,cAAI,CAAC,OAAO,cAAc,MAAM,KAAK,SAAS,GAAG;AAC/C,kBAAM,IAAI,MAAM,oBAAoB;AAAA,UACtC;AACA,gBAAM,SAAS,OAAO,MAAM,IAAI;AAChC,cAAIC,SAAQ;AACZ,iBAAOA,SAAQ,MAAM;AACn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ACH,UAAE;AACA,YAAQ,IAAI,QAAQ,EAAE,GAAG,MAAM;AAC/B,YAAQ,OAAO,QAAQ,EAAE;AAAA,EAC3B;AACF;","names":["exports","module","detectLinuxLibc","fs","read","count","path","require","value"]}
@@ -222,6 +222,7 @@ port.on("message", (message) => {
222
222
  return;
223
223
  }
224
224
  if (message.type === "release") {
225
+ handles.get(message.handleId)?.value?.close?.();
225
226
  handles.delete(message.handleId);
226
227
  for (const stream of streams.values()) {
227
228
  if (stream.handleId === message.handleId) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../node_modules/tsup/assets/esm_shims.js","../lib/libc.cjs","../src/native-worker.ts","../src/native-binding.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","// Read the ELF interpreter, rather than generating a process-wide diagnostic\n// report. Both supported Linux architectures use little-endian ELF64. Reads\n// are bounded to the header, program headers, and interpreter pathname.\nfunction detectLinuxLibc(fs, executable = process.execPath) {\n const override = process.env.TENSORLAKE_NODE_LIBC;\n if (override != null) {\n if (override === \"gnu\" || override === \"musl\") return override;\n throw new Error(\"TENSORLAKE_NODE_LIBC must be 'gnu' or 'musl'.\");\n }\n\n let fd;\n try {\n fd = fs.openSync(executable, \"r\");\n function read(size, offset) {\n if (!Number.isSafeInteger(offset) || offset < 0) {\n throw new Error(\"Invalid ELF offset\");\n }\n const buffer = Buffer.alloc(size);\n let count = 0;\n while (count < size) {\n const bytes = fs.readSync(fd, buffer, count, size - count, offset + count);\n if (bytes === 0) throw new Error(\"Truncated ELF executable\");\n count += bytes;\n }\n return buffer;\n }\n\n const header = read(64, 0);\n if (header.readUInt32BE(0) !== 0x7f454c46 || header[4] !== 2 || header[5] !== 1) {\n throw new Error(\"Expected a little-endian ELF64 executable\");\n }\n const entrySize = header.readUInt16LE(54);\n const count = header.readUInt16LE(56);\n if (entrySize !== 56 || count === 0 || count > 128) {\n throw new Error(\"Unsupported ELF program headers\");\n }\n const entries = read(entrySize * count, Number(header.readBigUInt64LE(32)));\n for (let i = 0; i < count; i++) {\n const offset = i * entrySize;\n if (entries.readUInt32LE(offset) !== 3) continue; // PT_INTERP\n const size = Number(entries.readBigUInt64LE(offset + 32));\n if (size < 2 || size > 4096) throw new Error(\"Invalid ELF interpreter size\");\n const interpreter = read(size, Number(entries.readBigUInt64LE(offset + 8)));\n if (interpreter[size - 1] !== 0) throw new Error(\"Unterminated ELF interpreter\");\n const name = interpreter.subarray(0, -1).toString(\"utf8\").split(\"/\").at(-1);\n if (name.startsWith(\"ld-musl-\")) return \"musl\";\n if (name.startsWith(\"ld-linux-\")) return \"gnu\";\n throw new Error(\"Unrecognized ELF interpreter\");\n }\n throw new Error(\"No ELF interpreter (statically linked executable)\");\n } catch (cause) {\n throw new Error(\n \"Unable to detect Linux libc from the Node executable. Set TENSORLAKE_NODE_LIBC to 'gnu' or 'musl' for a nonstandard runtime.\",\n { cause },\n );\n } finally {\n if (fd != null) fs.closeSync(fd);\n }\n}\n\nmodule.exports = { detectLinuxLibc };\n","import { parentPort } from \"node:worker_threads\";\nimport { loadNative } from \"./native-binding.js\";\nimport type {\n WorkerRequest,\n WorkerResponse,\n} from \"./native-worker-protocol.js\";\n\nconst port = parentPort!;\n// This module is only a worker entrypoint. All platform detection, dlopen and\n// native object construction happen in this isolate.\nconst binding = loadNative<Record<string, any>>();\nconst handles = new Map<number, { value?: any; error?: unknown }>();\ninterface StreamState {\n cancel?: () => void;\n handleId?: number;\n ack?: () => void;\n}\nconst streams = new Map<number, StreamState>();\n\nfunction getHandle(id: number): any {\n const entry = handles.get(id);\n if (!entry) throw new Error(\"Tensorlake native handle has been released\");\n if (entry.error) throw entry.error;\n return entry.value;\n}\n\n/** Structured clone turns Buffers into Uint8Arrays; napi expects Buffers. */\nfunction nativeArgs(value: any): any {\n if (value instanceof Uint8Array)\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength);\n if (Array.isArray(value)) return value.map(nativeArgs);\n if (value && typeof value === \"object\")\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, nativeArgs(v)]),\n );\n return value;\n}\n\nfunction send(message: WorkerResponse): void {\n port.postMessage(message);\n}\n\nport.on(\"message\", (message: WorkerRequest) => {\n if (message.type === \"create\") {\n try {\n const { kind, args, id } = message.handle;\n const ctor = binding[kind];\n if (typeof ctor !== \"function\")\n throw new Error(\n `native binding does not export ${kind}; rebuild with 'npm run build:native'`,\n );\n const value =\n message.parentId === undefined\n ? new ctor(...args)\n : getHandle(message.parentId).connectProxy(...args);\n handles.set(id, { value });\n } catch (error) {\n handles.set(message.handle.id, { error });\n }\n return;\n }\n if (message.type === \"release\") {\n handles.delete(message.handleId);\n for (const stream of streams.values()) {\n if (stream.handleId === message.handleId) {\n stream.cancel?.();\n stream.ack?.();\n }\n }\n return;\n }\n if (message.type === \"cancel\" || message.type === \"ack\") {\n const stream = streams.get(message.id);\n if (message.type === \"cancel\") stream?.cancel?.();\n stream?.ack?.();\n if (stream) stream.ack = undefined;\n return;\n }\n if (message.type === \"call\") void invoke(message);\n});\n\nasync function invoke(\n message: Extract<WorkerRequest, { type: \"call\" }>,\n): Promise<void> {\n try {\n const target =\n message.handleId === undefined ? binding : getHandle(message.handleId);\n const args = nativeArgs(message.args);\n let stream: StreamState | undefined;\n if (message.stream) {\n stream = { handleId: message.handleId };\n const state = stream;\n streams.set(message.id, stream);\n args.push(\n (value: string) =>\n new Promise<void>((resolve) => {\n state.ack = resolve;\n send({ type: \"event\", id: message.id, value });\n }),\n );\n }\n const call = target[message.method](...args);\n if (stream) stream.cancel = call.cancel;\n const value = await (stream ? call.result : call);\n send({ type: \"result\", id: message.id, value });\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n send({\n type: \"error\",\n id: message.id,\n error: { name: error.name, message: error.message, stack: error.stack },\n });\n } finally {\n streams.get(message.id)?.ack?.();\n streams.delete(message.id);\n }\n}\n","import { detectLinuxLibc } from \"../lib/libc.cjs\";\nimport * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\ninterface RuntimeReport {\n header?: {\n glibcVersionRuntime?: string;\n };\n}\n\ninterface TargetOptions {\n libc?: \"gnu\" | \"musl\";\n report?: RuntimeReport;\n}\n\ninterface NativeBindingPathOptions extends TargetOptions {\n packageRoot?: string;\n platform?: NodeJS.Platform;\n arch?: string;\n}\n\nconst NATIVE_PACKAGES: Readonly<Record<string, string>> = {\n \"darwin-arm64\": \"tensorlake-native-darwin-arm64\",\n \"linux-arm64\": \"tensorlake-native-linux-arm64-gnu\",\n \"linux-arm64-musl\": \"tensorlake-native-linux-arm64-musl\",\n \"linux-x64\": \"tensorlake-native-linux-x64-gnu\",\n \"linux-x64-musl\": \"tensorlake-native-linux-x64-musl\",\n \"win32-x64\": \"tensorlake-native-win32-x64\",\n};\n\nfunction packageRoot(): string {\n const parent = fileURLToPath(new URL(\"../\", import.meta.url));\n if (fs.existsSync(path.join(parent, \"package.json\"))) return parent;\n const grandparent = fileURLToPath(new URL(\"../../\", import.meta.url));\n if (fs.existsSync(path.join(grandparent, \"package.json\"))) return grandparent;\n return parent;\n}\n\nlet cachedLinuxLibc: \"gnu\" | \"musl\" | undefined;\n\nfunction linuxLibcFamily(options: TargetOptions): \"gnu\" | \"musl\" {\n if (options.libc != null) return options.libc;\n if (options.report != null) {\n return options.report.header?.glibcVersionRuntime ? \"gnu\" : \"musl\";\n }\n if (cachedLinuxLibc != null) return cachedLinuxLibc;\n\n cachedLinuxLibc = detectLinuxLibc(fs);\n return cachedLinuxLibc;\n}\n\nexport function nativeTargetId(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string {\n const target = `${platform}-${arch}`;\n if (platform !== \"linux\") return target;\n if (options.libc == null && options.report == null && platform !== process.platform) {\n return target;\n }\n return linuxLibcFamily(options) === \"musl\" ? `${target}-musl` : target;\n}\n\nexport function nativeBindingPath(options: NativeBindingPathOptions = {}): string {\n const platform = options.platform ?? process.platform;\n const arch = options.arch ?? process.arch;\n return path.join(\n options.packageRoot ?? packageRoot(),\n \"dist\",\n \"native\",\n nativeTargetId(platform, arch, options),\n \"tensorlake-node.node\",\n );\n}\n\nexport function nativePackageName(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string | undefined {\n return NATIVE_PACKAGES[nativeTargetId(platform, arch, options)];\n}\n\nexport function loadNative<T>(): T {\n const target = nativeTargetId();\n const bindingPath = nativeBindingPath();\n const require = createRequire(import.meta.url);\n\n // Local source builds stage the addon here. Published packages intentionally\n // omit this directory and resolve the platform-specific optional dependency.\n if (fs.existsSync(bindingPath)) return require(bindingPath) as T;\n\n const packageName = nativePackageName();\n if (!packageName) {\n throw new Error(\n `Tensorlake does not provide a native binding for ${target}.`,\n );\n }\n\n let packageEntry: string;\n try {\n packageEntry = require.resolve(packageName);\n } catch (cause) {\n throw new Error(\n `Missing native binding package ${packageName} for ${target}. Reinstall tensorlake without omitting optional dependencies, and install dependencies on the machine where they will run.`,\n { cause },\n );\n }\n return require(packageEntry) as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAF9B;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAGA,aAASA,iBAAgBC,KAAI,aAAa,QAAQ,UAAU;AAC1D,YAAM,WAAW,QAAQ,IAAI;AAC7B,UAAI,YAAY,MAAM;AACpB,YAAI,aAAa,SAAS,aAAa,OAAQ,QAAO;AACtD,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AAEA,UAAI;AACJ,UAAI;AAEF,YAASC,QAAT,SAAc,MAAM,QAAQ;AAC1B,cAAI,CAAC,OAAO,cAAc,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AAA,MACN,IAAI,QAAQ;AAAA,MACZ,OAAO,EAAE,MAAM,MAAM,MAAM,SAAS,MAAM,SAAS,OAAO,MAAM,MAAM;AAAA,IACxE,CAAC;AAAA,EACH,UAAE;AACA,YAAQ,IAAI,QAAQ,EAAE,GAAG,MAAM;AAC/B,YAAQ,OAAO,QAAQ,EAAE;AAAA,EAC3B;AACF;","names":["detectLinuxLibc","fs","read","count","path","fileURLToPath","require","value"]}
1
+ {"version":3,"sources":["../node_modules/tsup/assets/esm_shims.js","../lib/libc.cjs","../src/native-worker.ts","../src/native-binding.ts"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","// Read the ELF interpreter, rather than generating a process-wide diagnostic\n// report. Both supported Linux architectures use little-endian ELF64. Reads\n// are bounded to the header, program headers, and interpreter pathname.\nfunction detectLinuxLibc(fs, executable = process.execPath) {\n const override = process.env.TENSORLAKE_NODE_LIBC;\n if (override != null) {\n if (override === \"gnu\" || override === \"musl\") return override;\n throw new Error(\"TENSORLAKE_NODE_LIBC must be 'gnu' or 'musl'.\");\n }\n\n let fd;\n try {\n fd = fs.openSync(executable, \"r\");\n function read(size, offset) {\n if (!Number.isSafeInteger(offset) || offset < 0) {\n throw new Error(\"Invalid ELF offset\");\n }\n const buffer = Buffer.alloc(size);\n let count = 0;\n while (count < size) {\n const bytes = fs.readSync(fd, buffer, count, size - count, offset + count);\n if (bytes === 0) throw new Error(\"Truncated ELF executable\");\n count += bytes;\n }\n return buffer;\n }\n\n const header = read(64, 0);\n if (header.readUInt32BE(0) !== 0x7f454c46 || header[4] !== 2 || header[5] !== 1) {\n throw new Error(\"Expected a little-endian ELF64 executable\");\n }\n const entrySize = header.readUInt16LE(54);\n const count = header.readUInt16LE(56);\n if (entrySize !== 56 || count === 0 || count > 128) {\n throw new Error(\"Unsupported ELF program headers\");\n }\n const entries = read(entrySize * count, Number(header.readBigUInt64LE(32)));\n for (let i = 0; i < count; i++) {\n const offset = i * entrySize;\n if (entries.readUInt32LE(offset) !== 3) continue; // PT_INTERP\n const size = Number(entries.readBigUInt64LE(offset + 32));\n if (size < 2 || size > 4096) throw new Error(\"Invalid ELF interpreter size\");\n const interpreter = read(size, Number(entries.readBigUInt64LE(offset + 8)));\n if (interpreter[size - 1] !== 0) throw new Error(\"Unterminated ELF interpreter\");\n const name = interpreter.subarray(0, -1).toString(\"utf8\").split(\"/\").at(-1);\n if (name.startsWith(\"ld-musl-\")) return \"musl\";\n if (name.startsWith(\"ld-linux-\")) return \"gnu\";\n throw new Error(\"Unrecognized ELF interpreter\");\n }\n throw new Error(\"No ELF interpreter (statically linked executable)\");\n } catch (cause) {\n throw new Error(\n \"Unable to detect Linux libc from the Node executable. Set TENSORLAKE_NODE_LIBC to 'gnu' or 'musl' for a nonstandard runtime.\",\n { cause },\n );\n } finally {\n if (fd != null) fs.closeSync(fd);\n }\n}\n\nmodule.exports = { detectLinuxLibc };\n","import { parentPort } from \"node:worker_threads\";\nimport { loadNative } from \"./native-binding.js\";\nimport type {\n WorkerRequest,\n WorkerResponse,\n} from \"./native-worker-protocol.js\";\n\nconst port = parentPort!;\n// This module is only a worker entrypoint. All platform detection, dlopen and\n// native object construction happen in this isolate.\nconst binding = loadNative<Record<string, any>>();\nconst handles = new Map<number, { value?: any; error?: unknown }>();\ninterface StreamState {\n cancel?: () => void;\n handleId?: number;\n ack?: () => void;\n}\nconst streams = new Map<number, StreamState>();\n\nfunction getHandle(id: number): any {\n const entry = handles.get(id);\n if (!entry) throw new Error(\"Tensorlake native handle has been released\");\n if (entry.error) throw entry.error;\n return entry.value;\n}\n\n/** Structured clone turns Buffers into Uint8Arrays; napi expects Buffers. */\nfunction nativeArgs(value: any): any {\n if (value instanceof Uint8Array)\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength);\n if (Array.isArray(value)) return value.map(nativeArgs);\n if (value && typeof value === \"object\")\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, nativeArgs(v)]),\n );\n return value;\n}\n\nfunction send(message: WorkerResponse): void {\n port.postMessage(message);\n}\n\nport.on(\"message\", (message: WorkerRequest) => {\n if (message.type === \"create\") {\n try {\n const { kind, args, id } = message.handle;\n const ctor = binding[kind];\n if (typeof ctor !== \"function\")\n throw new Error(\n `native binding does not export ${kind}; rebuild with 'npm run build:native'`,\n );\n const value =\n message.parentId === undefined\n ? new ctor(...args)\n : getHandle(message.parentId).connectProxy(...args);\n handles.set(id, { value });\n } catch (error) {\n handles.set(message.handle.id, { error });\n }\n return;\n }\n if (message.type === \"release\") {\n // Cloud clients own cancellation for buffered requests as well as streams.\n handles.get(message.handleId)?.value?.close?.();\n handles.delete(message.handleId);\n for (const stream of streams.values()) {\n if (stream.handleId === message.handleId) {\n stream.cancel?.();\n stream.ack?.();\n }\n }\n return;\n }\n if (message.type === \"cancel\" || message.type === \"ack\") {\n const stream = streams.get(message.id);\n if (message.type === \"cancel\") stream?.cancel?.();\n stream?.ack?.();\n if (stream) stream.ack = undefined;\n return;\n }\n if (message.type === \"call\") void invoke(message);\n});\n\nasync function invoke(\n message: Extract<WorkerRequest, { type: \"call\" }>,\n): Promise<void> {\n try {\n const target =\n message.handleId === undefined ? binding : getHandle(message.handleId);\n const args = nativeArgs(message.args);\n let stream: StreamState | undefined;\n if (message.stream) {\n stream = { handleId: message.handleId };\n const state = stream;\n streams.set(message.id, stream);\n args.push(\n (value: string) =>\n new Promise<void>((resolve) => {\n state.ack = resolve;\n send({ type: \"event\", id: message.id, value });\n }),\n );\n }\n const call = target[message.method](...args);\n if (stream) stream.cancel = call.cancel;\n const value = await (stream ? call.result : call);\n send({ type: \"result\", id: message.id, value });\n } catch (cause) {\n const error = cause instanceof Error ? cause : new Error(String(cause));\n send({\n type: \"error\",\n id: message.id,\n error: { name: error.name, message: error.message, stack: error.stack },\n });\n } finally {\n streams.get(message.id)?.ack?.();\n streams.delete(message.id);\n }\n}\n","import { detectLinuxLibc } from \"../lib/libc.cjs\";\nimport * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\ninterface RuntimeReport {\n header?: {\n glibcVersionRuntime?: string;\n };\n}\n\ninterface TargetOptions {\n libc?: \"gnu\" | \"musl\";\n report?: RuntimeReport;\n}\n\ninterface NativeBindingPathOptions extends TargetOptions {\n packageRoot?: string;\n platform?: NodeJS.Platform;\n arch?: string;\n}\n\nconst NATIVE_PACKAGES: Readonly<Record<string, string>> = {\n \"darwin-arm64\": \"tensorlake-native-darwin-arm64\",\n \"linux-arm64\": \"tensorlake-native-linux-arm64-gnu\",\n \"linux-arm64-musl\": \"tensorlake-native-linux-arm64-musl\",\n \"linux-x64\": \"tensorlake-native-linux-x64-gnu\",\n \"linux-x64-musl\": \"tensorlake-native-linux-x64-musl\",\n \"win32-x64\": \"tensorlake-native-win32-x64\",\n};\n\nfunction packageRoot(): string {\n const parent = fileURLToPath(new URL(\"../\", import.meta.url));\n if (fs.existsSync(path.join(parent, \"package.json\"))) return parent;\n const grandparent = fileURLToPath(new URL(\"../../\", import.meta.url));\n if (fs.existsSync(path.join(grandparent, \"package.json\"))) return grandparent;\n return parent;\n}\n\nlet cachedLinuxLibc: \"gnu\" | \"musl\" | undefined;\n\nfunction linuxLibcFamily(options: TargetOptions): \"gnu\" | \"musl\" {\n if (options.libc != null) return options.libc;\n if (options.report != null) {\n return options.report.header?.glibcVersionRuntime ? \"gnu\" : \"musl\";\n }\n if (cachedLinuxLibc != null) return cachedLinuxLibc;\n\n cachedLinuxLibc = detectLinuxLibc(fs);\n return cachedLinuxLibc;\n}\n\nexport function nativeTargetId(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string {\n const target = `${platform}-${arch}`;\n if (platform !== \"linux\") return target;\n if (options.libc == null && options.report == null && platform !== process.platform) {\n return target;\n }\n return linuxLibcFamily(options) === \"musl\" ? `${target}-musl` : target;\n}\n\nexport function nativeBindingPath(options: NativeBindingPathOptions = {}): string {\n const platform = options.platform ?? process.platform;\n const arch = options.arch ?? process.arch;\n return path.join(\n options.packageRoot ?? packageRoot(),\n \"dist\",\n \"native\",\n nativeTargetId(platform, arch, options),\n \"tensorlake-node.node\",\n );\n}\n\nexport function nativePackageName(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch,\n options: TargetOptions = {},\n): string | undefined {\n return NATIVE_PACKAGES[nativeTargetId(platform, arch, options)];\n}\n\nexport function loadNative<T>(): T {\n const target = nativeTargetId();\n const bindingPath = nativeBindingPath();\n const require = createRequire(import.meta.url);\n\n // Local source builds stage the addon here. Published packages intentionally\n // omit this directory and resolve the platform-specific optional dependency.\n if (fs.existsSync(bindingPath)) return require(bindingPath) as T;\n\n const packageName = nativePackageName();\n if (!packageName) {\n throw new Error(\n `Tensorlake does not provide a native binding for ${target}.`,\n );\n }\n\n let packageEntry: string;\n try {\n packageEntry = require.resolve(packageName);\n } catch (cause) {\n throw new Error(\n `Missing native binding package ${packageName} for ${target}. Reinstall tensorlake without omitting optional dependencies, and install dependencies on the machine where they will run.`,\n { cause },\n );\n }\n return require(packageEntry) as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAF9B;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAGA,aAASA,iBAAgBC,KAAI,aAAa,QAAQ,UAAU;AAC1D,YAAM,WAAW,QAAQ,IAAI;AAC7B,UAAI,YAAY,MAAM;AACpB,YAAI,aAAa,SAAS,aAAa,OAAQ,QAAO;AACtD,cAAM,IAAI,MAAM,+CAA+C;AAAA,MACjE;AAEA,UAAI;AACJ,UAAI;AAEF,YAASC,QAAT,SAAc,MAAM,QAAQ;AAC1B,cAAI,CAAC,OAAO,cAA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I,MAAM,OAAO,KAAK,CAAC;AACtE,SAAK;AAAA,MACH,MAAM;AAAA,MACN,IAAI,QAAQ;AAAA,MACZ,OAAO,EAAE,MAAM,MAAM,MAAM,SAAS,MAAM,SAAS,OAAO,MAAM,MAAM;AAAA,IACxE,CAAC;AAAA,EACH,UAAE;AACA,YAAQ,IAAI,QAAQ,EAAE,GAAG,MAAM;AAC/B,YAAQ,OAAO,QAAQ,EAAE;AAAA,EAC3B;AACF;","names":["detectLinuxLibc","fs","read","count","path","fileURLToPath","require","value"]}
@@ -1,4 +1,4 @@
1
- import { C as CloudClientOptions, A as ApplicationManifest, F as FileSystem, a as ApplicationSummary, R as RequestInput, b as RequestOutput, I as Image } from './sandbox-image-Bf5bcxtO.cjs';
1
+ import { C as CloudClientOptions, A as ApplicationManifest, F as FileSystem, a as ApplicationSummary, R as RequestInput, b as RequestOutput, I as Image } from './sandbox-image-ChzWDeZy.cjs';
2
2
 
3
3
  declare class APIClient {
4
4
  private readonly cloudClient;
@@ -1,4 +1,4 @@
1
- import { C as CloudClientOptions, A as ApplicationManifest, F as FileSystem, a as ApplicationSummary, R as RequestInput, b as RequestOutput, I as Image } from './sandbox-image-Bf5bcxtO.js';
1
+ import { C as CloudClientOptions, A as ApplicationManifest, F as FileSystem, a as ApplicationSummary, R as RequestInput, b as RequestOutput, I as Image } from './sandbox-image-ChzWDeZy.js';
2
2
 
3
3
  declare class APIClient {
4
4
  private readonly cloudClient;
@@ -5,7 +5,9 @@ interface CloudClientOptions {
5
5
  organizationId?: string;
6
6
  projectId?: string;
7
7
  namespace?: string;
8
+ /** Maximum transient retries for safe reads. Mutations only replay when Rust proves they were not delivered. */
8
9
  maxRetries?: number;
10
+ /** Initial transient retry delay in milliseconds; exponential backoff is capped at 15 seconds. */
9
11
  retryBackoffMs?: number;
10
12
  }
11
13
  interface RequestInput {
@@ -5,7 +5,9 @@ interface CloudClientOptions {
5
5
  organizationId?: string;
6
6
  projectId?: string;
7
7
  namespace?: string;
8
+ /** Maximum transient retries for safe reads. Mutations only replay when Rust proves they were not delivered. */
8
9
  maxRetries?: number;
10
+ /** Initial transient retry delay in milliseconds; exponential backoff is capped at 15 seconds. */
9
11
  retryBackoffMs?: number;
10
12
  }
11
13
  interface RequestInput {