@ricsam/isolate 0.1.4 → 0.1.6

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 (80) hide show
  1. package/README.md +45 -2
  2. package/dist/cjs/internal/async-context/index.cjs +401 -0
  3. package/dist/cjs/internal/async-context/index.cjs.map +10 -0
  4. package/dist/cjs/internal/client/connection.cjs +175 -123
  5. package/dist/cjs/internal/client/connection.cjs.map +3 -3
  6. package/dist/cjs/internal/console/index.cjs +2 -2
  7. package/dist/cjs/internal/console/index.cjs.map +2 -2
  8. package/dist/cjs/internal/core/index.cjs +22 -6
  9. package/dist/cjs/internal/core/index.cjs.map +3 -3
  10. package/dist/cjs/internal/crypto/index.cjs +2 -2
  11. package/dist/cjs/internal/crypto/index.cjs.map +2 -2
  12. package/dist/cjs/internal/daemon/connection.cjs +77 -12
  13. package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
  14. package/dist/cjs/internal/encoding/index.cjs.map +1 -1
  15. package/dist/cjs/internal/fetch/index.cjs +119 -18
  16. package/dist/cjs/internal/fetch/index.cjs.map +3 -3
  17. package/dist/cjs/internal/fetch/stream-state.cjs.map +1 -1
  18. package/dist/cjs/internal/fs/index.cjs +2 -2
  19. package/dist/cjs/internal/fs/index.cjs.map +2 -2
  20. package/dist/cjs/internal/module-loader/bundle.cjs +277 -1
  21. package/dist/cjs/internal/module-loader/bundle.cjs.map +3 -3
  22. package/dist/cjs/internal/path/index.cjs.map +1 -1
  23. package/dist/cjs/internal/playwright/index.cjs +2 -2
  24. package/dist/cjs/internal/playwright/index.cjs.map +2 -2
  25. package/dist/cjs/internal/runtime/index.cjs +78 -6
  26. package/dist/cjs/internal/runtime/index.cjs.map +3 -3
  27. package/dist/cjs/internal/test-environment/index.cjs +2 -2
  28. package/dist/cjs/internal/test-environment/index.cjs.map +2 -2
  29. package/dist/cjs/internal/timers/index.cjs +42 -7
  30. package/dist/cjs/internal/timers/index.cjs.map +3 -3
  31. package/dist/cjs/internal/typecheck/isolate-types.cjs +36 -1
  32. package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
  33. package/dist/cjs/package.json +1 -1
  34. package/dist/mjs/internal/async-context/index.mjs +361 -0
  35. package/dist/mjs/internal/async-context/index.mjs.map +10 -0
  36. package/dist/mjs/internal/client/connection.mjs +176 -123
  37. package/dist/mjs/internal/client/connection.mjs.map +3 -3
  38. package/dist/mjs/internal/console/index.mjs +2 -2
  39. package/dist/mjs/internal/console/index.mjs.map +2 -2
  40. package/dist/mjs/internal/core/index.mjs +22 -6
  41. package/dist/mjs/internal/core/index.mjs.map +3 -3
  42. package/dist/mjs/internal/crypto/index.mjs +2 -2
  43. package/dist/mjs/internal/crypto/index.mjs.map +2 -2
  44. package/dist/mjs/internal/daemon/connection.mjs +77 -12
  45. package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
  46. package/dist/mjs/internal/encoding/index.mjs.map +1 -1
  47. package/dist/mjs/internal/fetch/index.mjs +119 -18
  48. package/dist/mjs/internal/fetch/index.mjs.map +3 -3
  49. package/dist/mjs/internal/fetch/stream-state.mjs.map +1 -1
  50. package/dist/mjs/internal/fs/index.mjs +2 -2
  51. package/dist/mjs/internal/fs/index.mjs.map +2 -2
  52. package/dist/mjs/internal/module-loader/bundle.mjs +277 -1
  53. package/dist/mjs/internal/module-loader/bundle.mjs.map +3 -3
  54. package/dist/mjs/internal/path/index.mjs.map +1 -1
  55. package/dist/mjs/internal/playwright/index.mjs +2 -2
  56. package/dist/mjs/internal/playwright/index.mjs.map +2 -2
  57. package/dist/mjs/internal/runtime/index.mjs +78 -6
  58. package/dist/mjs/internal/runtime/index.mjs.map +3 -3
  59. package/dist/mjs/internal/test-environment/index.mjs +2 -2
  60. package/dist/mjs/internal/test-environment/index.mjs.map +2 -2
  61. package/dist/mjs/internal/timers/index.mjs +42 -7
  62. package/dist/mjs/internal/timers/index.mjs.map +3 -3
  63. package/dist/mjs/internal/typecheck/isolate-types.mjs +36 -1
  64. package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
  65. package/dist/mjs/package.json +1 -1
  66. package/dist/types/internal/async-context/index.d.ts +5 -0
  67. package/dist/types/internal/console/index.d.ts +1 -1
  68. package/dist/types/internal/core/index.d.ts +2 -2
  69. package/dist/types/internal/crypto/index.d.ts +1 -1
  70. package/dist/types/internal/daemon/types.d.ts +1 -0
  71. package/dist/types/internal/encoding/index.d.ts +1 -1
  72. package/dist/types/internal/fetch/index.d.ts +1 -1
  73. package/dist/types/internal/fetch/stream-state.d.ts +1 -1
  74. package/dist/types/internal/fs/index.d.ts +1 -1
  75. package/dist/types/internal/path/index.d.ts +1 -1
  76. package/dist/types/internal/playwright/index.d.ts +1 -1
  77. package/dist/types/internal/test-environment/index.d.ts +1 -1
  78. package/dist/types/internal/timers/index.d.ts +1 -1
  79. package/dist/types/internal/typecheck/isolate-types.d.ts +2 -2
  80. package/package.json +8 -3
@@ -66,7 +66,7 @@ __export(exports_console, {
66
66
  setupConsole: () => setupConsole
67
67
  });
68
68
  module.exports = __toCommonJS(exports_console);
69
- var import_isolated_vm = __toESM(require("isolated-vm"));
69
+ var import_isolated_vm = __toESM(require("@ricsam/isolated-vm"));
70
70
  async function setupConsole(context, options) {
71
71
  const opts = options ?? {};
72
72
  const timers = new Map;
@@ -503,4 +503,4 @@ async function setupConsole(context, options) {
503
503
  };
504
504
  }
505
505
 
506
- //# debugId=5FE17BFAA79E0DE064756E2164756E21
506
+ //# debugId=81BA159AA25332A264756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/internal/console/index.ts"],
4
4
  "sourcesContent": [
5
- "import ivm from \"isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n * Output is pre-formatted as stdout strings (like Node.js console) inside the sandbox.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n stdout: string;\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n stdout: string;\n location?: {\n url?: string;\n lineNumber?: number;\n columnNumber?: number;\n };\n timestamp: number;\n }\n | { type: \"dir\"; stdout: string; groupDepth: number }\n | { type: \"table\"; stdout: string; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n stdout: string;\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; stdout: string; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; stdout: string; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\n */\nexport interface ConsoleHandle {\n dispose(): void;\n reset(): void;\n getTimers(): Map<string, number>;\n getCounters(): Map<string, number>;\n getGroupDepth(): number;\n}\n\n\n/**\n * Setup console API in an isolated-vm context\n *\n * Injects console.log, console.warn, console.error, console.info, console.debug,\n * console.trace, console.dir, console.table, console.time, console.timeEnd,\n * console.timeLog, console.count, console.countReset, console.group,\n * console.groupCollapsed, console.groupEnd, console.clear, console.assert\n *\n * @example\n * const handle = await setupConsole(context, {\n * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\n * });\n */\nexport async function setupConsole(\n context: ivm.Context,\n options?: ConsoleOptions\n): Promise<ConsoleHandle> {\n const opts = options ?? {};\n\n // State management\n const timers = new Map<string, number>();\n const counters = new Map<string, number>();\n let groupDepth = 0;\n\n const global = context.global;\n\n // Log-level methods (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n stdout,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"dir\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"table\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((stdout: string, stack: string) => {\n opts.onEntry?.({\n type: \"trace\",\n stdout,\n stack,\n groupDepth,\n });\n })\n );\n\n // Timing methods\n global.setSync(\n \"__console_time\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n timers.set(l, performance.now());\n })\n );\n\n global.setSync(\n \"__console_timeEnd\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n timers.delete(l);\n opts.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\n }\n })\n );\n\n global.setSync(\n \"__console_timeLog\",\n new ivm.Callback((label: string, duration: number, stdout: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const actualDuration = performance.now() - start;\n opts.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration: actualDuration,\n stdout,\n groupDepth,\n });\n }\n })\n );\n\n // Counting methods\n global.setSync(\n \"__console_count\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const count = (counters.get(l) ?? 0) + 1;\n counters.set(l, count);\n opts.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\n })\n );\n\n global.setSync(\n \"__console_countReset\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n counters.delete(l);\n opts.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"assert\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // Inject console object with Node.js-style formatting\n context.evalSync(`\n // Format a single value for console output (Node.js style)\n function __formatForConsole(value, options = {}) {\n const { depth = 2, currentDepth = 0, seen = new WeakSet(), inObject = false } = options;\n\n // Handle null/undefined\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n\n // Handle primitives\n const type = typeof value;\n if (type === 'string') {\n // Strings: quoted when inside objects/arrays, raw when top-level console.log arg\n return inObject ? \"'\" + value.replace(/'/g, \"\\\\\\\\'\") + \"'\" : value;\n }\n if (type === 'number' || type === 'boolean') {\n return String(value);\n }\n if (type === 'bigint') {\n return value.toString() + 'n';\n }\n if (type === 'symbol') {\n return value.toString();\n }\n if (type === 'function') {\n const name = value.name || '(anonymous)';\n return '[Function: ' + name + ']';\n }\n\n // Handle objects\n if (type === 'object') {\n // Handle circular references BEFORE depth check (Node.js behavior)\n if (seen.has(value)) {\n return '[Circular]';\n }\n seen.add(value);\n\n // Check depth limit\n if (currentDepth >= depth) {\n if (Array.isArray(value)) return '[Array]';\n return '[Object]';\n }\n\n const nextOptions = { depth, currentDepth: currentDepth + 1, seen, inObject: true };\n\n // Handle Error objects\n if (value instanceof Error) {\n let result = value.name + ': ' + value.message;\n if (value.stack) {\n // Get stack lines after the first line (which is the error message)\n const stackLines = value.stack.split('\\\\n').slice(1);\n if (stackLines.length > 0) {\n result += '\\\\n' + stackLines.join('\\\\n');\n }\n }\n return result;\n }\n\n // Handle Response objects\n if (typeof Response !== 'undefined' && value instanceof Response) {\n return 'Response { status: ' + value.status + ', statusText: ' + __formatForConsole(value.statusText, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Request objects\n if (typeof Request !== 'undefined' && value instanceof Request) {\n return 'Request { method: ' + __formatForConsole(value.method, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Headers objects\n if (typeof Headers !== 'undefined' && value instanceof Headers) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Headers { ' + entries.join(', ') + ' }';\n }\n\n // Handle URLSearchParams objects\n if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) {\n const entries = [];\n for (const [k, v] of value) {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n }\n return entries.length === 0\n ? 'URLSearchParams {}'\n : 'URLSearchParams { ' + entries.join(', ') + ' }';\n }\n\n // Handle URL objects\n if (typeof URL !== 'undefined' && value instanceof URL) {\n const entries = [\n 'href: ' + __formatForConsole(value.href, nextOptions),\n 'origin: ' + __formatForConsole(value.origin, nextOptions),\n 'protocol: ' + __formatForConsole(value.protocol, nextOptions),\n 'username: ' + __formatForConsole(value.username, nextOptions),\n 'password: ' + __formatForConsole(value.password, nextOptions),\n 'host: ' + __formatForConsole(value.host, nextOptions),\n 'hostname: ' + __formatForConsole(value.hostname, nextOptions),\n 'port: ' + __formatForConsole(value.port, nextOptions),\n 'pathname: ' + __formatForConsole(value.pathname, nextOptions),\n 'search: ' + __formatForConsole(value.search, nextOptions),\n 'searchParams: ' + __formatForConsole(value.searchParams, nextOptions),\n 'hash: ' + __formatForConsole(value.hash, nextOptions),\n ];\n return 'URL { ' + entries.join(', ') + ' }';\n }\n\n // Handle Date objects\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n // Handle RegExp\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n // Handle Map\n if (value instanceof Map) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Map(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle Set\n if (value instanceof Set) {\n const entries = [];\n value.forEach((v) => {\n entries.push(__formatForConsole(v, nextOptions));\n });\n return 'Set(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle ArrayBuffer and TypedArrays\n if (value instanceof ArrayBuffer) {\n return 'ArrayBuffer { byteLength: ' + value.byteLength + ' }';\n }\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const typedArray = value;\n const name = typedArray.constructor.name;\n const length = typedArray.length;\n if (length <= 10) {\n const items = Array.from(typedArray).map(v => __formatForConsole(v, nextOptions));\n return name + '(' + length + ') [ ' + items.join(', ') + ' ]';\n }\n return name + '(' + length + ') [ ... ]';\n }\n\n // Handle Promise\n if (value instanceof Promise) {\n return 'Promise { <pending> }';\n }\n\n // Handle arrays\n if (Array.isArray(value)) {\n if (value.length === 0) return '[]';\n const items = value.map(item => __formatForConsole(item, nextOptions));\n return '[ ' + items.join(', ') + ' ]';\n }\n\n // Handle plain objects\n const keys = Object.keys(value);\n if (keys.length === 0) return '{}';\n const entries = keys.map(key => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : __formatForConsole(key, nextOptions);\n return formattedKey + ': ' + __formatForConsole(value[key], nextOptions);\n });\n return '{ ' + entries.join(', ') + ' }';\n }\n\n return String(value);\n }\n\n // Format multiple args with space separation (like console.log)\n function __formatArgs(args) {\n return args.map((arg, i) => __formatForConsole(arg, { inObject: false })).join(' ');\n }\n\n // Format data for console.table - creates ASCII table\n function __formatTable(data, columns) {\n if (data === null || data === undefined) {\n return __formatForConsole(data);\n }\n\n // Convert to array of objects\n let rows = [];\n let headers = new Set();\n\n if (Array.isArray(data)) {\n rows = data.map((item, index) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n return { __index: index, ...item };\n }\n return { __index: index, Values: item };\n });\n headers.add('Values');\n } else if (typeof data === 'object') {\n Object.keys(data).forEach(key => {\n const item = data[key];\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n rows.push({ __index: key, ...item });\n } else {\n rows.push({ __index: key, Values: item });\n headers.add('Values');\n }\n });\n } else {\n return __formatForConsole(data);\n }\n\n // Filter headers by columns if provided\n let headerList = ['(index)', ...headers];\n headerList = headerList.filter(h => h !== '__index');\n if (columns && Array.isArray(columns)) {\n headerList = ['(index)', ...columns.filter(c => headers.has(c))];\n }\n\n // Calculate column widths\n const colWidths = {};\n headerList.forEach(h => {\n colWidths[h] = h === '(index)' ? 7 : h.length;\n });\n rows.forEach(row => {\n headerList.forEach(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n colWidths[h] = Math.max(colWidths[h], formatted.length);\n });\n });\n\n // Build table\n const sep = '+' + headerList.map(h => '-'.repeat(colWidths[h] + 2)).join('+') + '+';\n const headerRow = '|' + headerList.map(h => ' ' + h.padEnd(colWidths[h]) + ' ').join('|') + '|';\n\n const dataRows = rows.map(row => {\n return '|' + headerList.map(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n return ' ' + formatted.padEnd(colWidths[h]) + ' ';\n }).join('|') + '|';\n });\n\n return [sep, headerRow, sep, ...dataRows, sep].join('\\\\n');\n }\n\n globalThis.console = {\n log: (...args) => __console_log(__formatArgs(args)),\n warn: (...args) => __console_warn(__formatArgs(args)),\n error: (...args) => __console_error(__formatArgs(args)),\n debug: (...args) => __console_debug(__formatArgs(args)),\n info: (...args) => __console_info(__formatArgs(args)),\n trace: (...args) => {\n const err = new Error();\n const stack = err.stack || '';\n // Remove the first two lines (Error and the trace call itself)\n const stackLines = stack.split('\\\\n').slice(2).join('\\\\n');\n __console_trace(__formatArgs(args), 'Trace' + (args.length > 0 ? ': ' + __formatArgs(args) : '') + '\\\\n' + stackLines);\n },\n dir: (value, options) => __console_dir(__formatForConsole(value, { depth: options?.depth ?? 2, inObject: true })),\n table: (data, columns) => __console_table(__formatTable(data, columns)),\n time: __console_time,\n timeEnd: __console_timeEnd,\n timeLog: (label, ...args) => __console_timeLog(label ?? 'default', 0, __formatArgs(args)),\n count: __console_count,\n countReset: __console_countReset,\n group: __console_group,\n groupCollapsed: __console_groupCollapsed,\n groupEnd: __console_groupEnd,\n clear: __console_clear,\n assert: (condition, ...args) => {\n if (!condition) {\n const msg = args.length > 0 ? __formatArgs(args) : 'console.assert';\n __console_assert('Assertion failed: ' + msg);\n }\n },\n };\n `);\n\n return {\n dispose() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n reset() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n getTimers() {\n return new Map(timers);\n },\n getCounters() {\n return new Map(counters);\n },\n getGroupDepth() {\n return groupDepth;\n },\n };\n}\n"
5
+ "import ivm from \"@ricsam/isolated-vm\";\n\n/**\n * Console entry types for structured console output.\n * Each entry type captures the specific data needed to render like DevTools.\n * Output is pre-formatted as stdout strings (like Node.js console) inside the sandbox.\n */\nexport type ConsoleEntry =\n | {\n type: \"output\";\n level: \"log\" | \"warn\" | \"error\" | \"info\" | \"debug\";\n stdout: string;\n groupDepth: number;\n }\n | {\n /** Browser console output (from Playwright page, not sandbox) */\n type: \"browserOutput\";\n level: string;\n stdout: string;\n location?: {\n url?: string;\n lineNumber?: number;\n columnNumber?: number;\n };\n timestamp: number;\n }\n | { type: \"dir\"; stdout: string; groupDepth: number }\n | { type: \"table\"; stdout: string; groupDepth: number }\n | { type: \"time\"; label: string; duration: number; groupDepth: number }\n | {\n type: \"timeLog\";\n label: string;\n duration: number;\n stdout: string;\n groupDepth: number;\n }\n | { type: \"count\"; label: string; count: number; groupDepth: number }\n | { type: \"countReset\"; label: string; groupDepth: number }\n | { type: \"assert\"; stdout: string; groupDepth: number }\n | {\n type: \"group\";\n label: string;\n collapsed: boolean;\n groupDepth: number;\n }\n | { type: \"groupEnd\"; groupDepth: number }\n | { type: \"clear\" }\n | { type: \"trace\"; stdout: string; stack: string; groupDepth: number };\n\n/**\n * Console options with a single structured callback.\n */\nexport interface ConsoleOptions {\n /**\n * Callback invoked for each console operation.\n * Receives a structured entry with all data needed to render the output.\n */\n onEntry?: (entry: ConsoleEntry) => void;\n}\n\n/**\n * Console handle for accessing internal state.\n */\nexport interface ConsoleHandle {\n dispose(): void;\n reset(): void;\n getTimers(): Map<string, number>;\n getCounters(): Map<string, number>;\n getGroupDepth(): number;\n}\n\n\n/**\n * Setup console API in an isolated-vm context\n *\n * Injects console.log, console.warn, console.error, console.info, console.debug,\n * console.trace, console.dir, console.table, console.time, console.timeEnd,\n * console.timeLog, console.count, console.countReset, console.group,\n * console.groupCollapsed, console.groupEnd, console.clear, console.assert\n *\n * @example\n * const handle = await setupConsole(context, {\n * onEntry: (entry) => {\n * if (entry.type === 'output') {\n * console.log(`[${entry.level}]`, ...entry.args);\n * }\n * }\n * });\n */\nexport async function setupConsole(\n context: ivm.Context,\n options?: ConsoleOptions\n): Promise<ConsoleHandle> {\n const opts = options ?? {};\n\n // State management\n const timers = new Map<string, number>();\n const counters = new Map<string, number>();\n let groupDepth = 0;\n\n const global = context.global;\n\n // Log-level methods (output type)\n const logLevels = [\"log\", \"warn\", \"error\", \"debug\", \"info\"] as const;\n\n for (const level of logLevels) {\n global.setSync(\n `__console_${level}`,\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"output\",\n level,\n stdout,\n groupDepth,\n });\n })\n );\n }\n\n // dir method\n global.setSync(\n \"__console_dir\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"dir\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // table method\n global.setSync(\n \"__console_table\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"table\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // trace method (includes stack)\n global.setSync(\n \"__console_trace\",\n new ivm.Callback((stdout: string, stack: string) => {\n opts.onEntry?.({\n type: \"trace\",\n stdout,\n stack,\n groupDepth,\n });\n })\n );\n\n // Timing methods\n global.setSync(\n \"__console_time\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n timers.set(l, performance.now());\n })\n );\n\n global.setSync(\n \"__console_timeEnd\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const duration = performance.now() - start;\n timers.delete(l);\n opts.onEntry?.({\n type: \"time\",\n label: l,\n duration,\n groupDepth,\n });\n }\n })\n );\n\n global.setSync(\n \"__console_timeLog\",\n new ivm.Callback((label: string, duration: number, stdout: string) => {\n const l = label ?? \"default\";\n const start = timers.get(l);\n if (start !== undefined) {\n const actualDuration = performance.now() - start;\n opts.onEntry?.({\n type: \"timeLog\",\n label: l,\n duration: actualDuration,\n stdout,\n groupDepth,\n });\n }\n })\n );\n\n // Counting methods\n global.setSync(\n \"__console_count\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n const count = (counters.get(l) ?? 0) + 1;\n counters.set(l, count);\n opts.onEntry?.({\n type: \"count\",\n label: l,\n count,\n groupDepth,\n });\n })\n );\n\n global.setSync(\n \"__console_countReset\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n counters.delete(l);\n opts.onEntry?.({\n type: \"countReset\",\n label: l,\n groupDepth,\n });\n })\n );\n\n // Grouping methods\n global.setSync(\n \"__console_group\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: false,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupCollapsed\",\n new ivm.Callback((label?: string) => {\n const l = label ?? \"default\";\n opts.onEntry?.({\n type: \"group\",\n label: l,\n collapsed: true,\n groupDepth,\n });\n groupDepth++;\n })\n );\n\n global.setSync(\n \"__console_groupEnd\",\n new ivm.Callback(() => {\n if (groupDepth > 0) {\n groupDepth--;\n }\n opts.onEntry?.({\n type: \"groupEnd\",\n groupDepth,\n });\n })\n );\n\n // Other methods\n global.setSync(\n \"__console_clear\",\n new ivm.Callback(() => {\n opts.onEntry?.({ type: \"clear\" });\n })\n );\n\n global.setSync(\n \"__console_assert\",\n new ivm.Callback((stdout: string) => {\n opts.onEntry?.({\n type: \"assert\",\n stdout,\n groupDepth,\n });\n })\n );\n\n // Inject console object with Node.js-style formatting\n context.evalSync(`\n // Format a single value for console output (Node.js style)\n function __formatForConsole(value, options = {}) {\n const { depth = 2, currentDepth = 0, seen = new WeakSet(), inObject = false } = options;\n\n // Handle null/undefined\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n\n // Handle primitives\n const type = typeof value;\n if (type === 'string') {\n // Strings: quoted when inside objects/arrays, raw when top-level console.log arg\n return inObject ? \"'\" + value.replace(/'/g, \"\\\\\\\\'\") + \"'\" : value;\n }\n if (type === 'number' || type === 'boolean') {\n return String(value);\n }\n if (type === 'bigint') {\n return value.toString() + 'n';\n }\n if (type === 'symbol') {\n return value.toString();\n }\n if (type === 'function') {\n const name = value.name || '(anonymous)';\n return '[Function: ' + name + ']';\n }\n\n // Handle objects\n if (type === 'object') {\n // Handle circular references BEFORE depth check (Node.js behavior)\n if (seen.has(value)) {\n return '[Circular]';\n }\n seen.add(value);\n\n // Check depth limit\n if (currentDepth >= depth) {\n if (Array.isArray(value)) return '[Array]';\n return '[Object]';\n }\n\n const nextOptions = { depth, currentDepth: currentDepth + 1, seen, inObject: true };\n\n // Handle Error objects\n if (value instanceof Error) {\n let result = value.name + ': ' + value.message;\n if (value.stack) {\n // Get stack lines after the first line (which is the error message)\n const stackLines = value.stack.split('\\\\n').slice(1);\n if (stackLines.length > 0) {\n result += '\\\\n' + stackLines.join('\\\\n');\n }\n }\n return result;\n }\n\n // Handle Response objects\n if (typeof Response !== 'undefined' && value instanceof Response) {\n return 'Response { status: ' + value.status + ', statusText: ' + __formatForConsole(value.statusText, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Request objects\n if (typeof Request !== 'undefined' && value instanceof Request) {\n return 'Request { method: ' + __formatForConsole(value.method, nextOptions) + ', url: ' + __formatForConsole(value.url, nextOptions) + ' }';\n }\n\n // Handle Headers objects\n if (typeof Headers !== 'undefined' && value instanceof Headers) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Headers { ' + entries.join(', ') + ' }';\n }\n\n // Handle URLSearchParams objects\n if (typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams) {\n const entries = [];\n for (const [k, v] of value) {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n }\n return entries.length === 0\n ? 'URLSearchParams {}'\n : 'URLSearchParams { ' + entries.join(', ') + ' }';\n }\n\n // Handle URL objects\n if (typeof URL !== 'undefined' && value instanceof URL) {\n const entries = [\n 'href: ' + __formatForConsole(value.href, nextOptions),\n 'origin: ' + __formatForConsole(value.origin, nextOptions),\n 'protocol: ' + __formatForConsole(value.protocol, nextOptions),\n 'username: ' + __formatForConsole(value.username, nextOptions),\n 'password: ' + __formatForConsole(value.password, nextOptions),\n 'host: ' + __formatForConsole(value.host, nextOptions),\n 'hostname: ' + __formatForConsole(value.hostname, nextOptions),\n 'port: ' + __formatForConsole(value.port, nextOptions),\n 'pathname: ' + __formatForConsole(value.pathname, nextOptions),\n 'search: ' + __formatForConsole(value.search, nextOptions),\n 'searchParams: ' + __formatForConsole(value.searchParams, nextOptions),\n 'hash: ' + __formatForConsole(value.hash, nextOptions),\n ];\n return 'URL { ' + entries.join(', ') + ' }';\n }\n\n // Handle Date objects\n if (value instanceof Date) {\n return value.toISOString();\n }\n\n // Handle RegExp\n if (value instanceof RegExp) {\n return value.toString();\n }\n\n // Handle Map\n if (value instanceof Map) {\n const entries = [];\n value.forEach((v, k) => {\n entries.push(__formatForConsole(k, nextOptions) + ' => ' + __formatForConsole(v, nextOptions));\n });\n return 'Map(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle Set\n if (value instanceof Set) {\n const entries = [];\n value.forEach((v) => {\n entries.push(__formatForConsole(v, nextOptions));\n });\n return 'Set(' + value.size + ') { ' + entries.join(', ') + ' }';\n }\n\n // Handle ArrayBuffer and TypedArrays\n if (value instanceof ArrayBuffer) {\n return 'ArrayBuffer { byteLength: ' + value.byteLength + ' }';\n }\n if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {\n const typedArray = value;\n const name = typedArray.constructor.name;\n const length = typedArray.length;\n if (length <= 10) {\n const items = Array.from(typedArray).map(v => __formatForConsole(v, nextOptions));\n return name + '(' + length + ') [ ' + items.join(', ') + ' ]';\n }\n return name + '(' + length + ') [ ... ]';\n }\n\n // Handle Promise\n if (value instanceof Promise) {\n return 'Promise { <pending> }';\n }\n\n // Handle arrays\n if (Array.isArray(value)) {\n if (value.length === 0) return '[]';\n const items = value.map(item => __formatForConsole(item, nextOptions));\n return '[ ' + items.join(', ') + ' ]';\n }\n\n // Handle plain objects\n const keys = Object.keys(value);\n if (keys.length === 0) return '{}';\n const entries = keys.map(key => {\n const formattedKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : __formatForConsole(key, nextOptions);\n return formattedKey + ': ' + __formatForConsole(value[key], nextOptions);\n });\n return '{ ' + entries.join(', ') + ' }';\n }\n\n return String(value);\n }\n\n // Format multiple args with space separation (like console.log)\n function __formatArgs(args) {\n return args.map((arg, i) => __formatForConsole(arg, { inObject: false })).join(' ');\n }\n\n // Format data for console.table - creates ASCII table\n function __formatTable(data, columns) {\n if (data === null || data === undefined) {\n return __formatForConsole(data);\n }\n\n // Convert to array of objects\n let rows = [];\n let headers = new Set();\n\n if (Array.isArray(data)) {\n rows = data.map((item, index) => {\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n return { __index: index, ...item };\n }\n return { __index: index, Values: item };\n });\n headers.add('Values');\n } else if (typeof data === 'object') {\n Object.keys(data).forEach(key => {\n const item = data[key];\n if (item !== null && typeof item === 'object' && !Array.isArray(item)) {\n Object.keys(item).forEach(k => headers.add(k));\n rows.push({ __index: key, ...item });\n } else {\n rows.push({ __index: key, Values: item });\n headers.add('Values');\n }\n });\n } else {\n return __formatForConsole(data);\n }\n\n // Filter headers by columns if provided\n let headerList = ['(index)', ...headers];\n headerList = headerList.filter(h => h !== '__index');\n if (columns && Array.isArray(columns)) {\n headerList = ['(index)', ...columns.filter(c => headers.has(c))];\n }\n\n // Calculate column widths\n const colWidths = {};\n headerList.forEach(h => {\n colWidths[h] = h === '(index)' ? 7 : h.length;\n });\n rows.forEach(row => {\n headerList.forEach(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n colWidths[h] = Math.max(colWidths[h], formatted.length);\n });\n });\n\n // Build table\n const sep = '+' + headerList.map(h => '-'.repeat(colWidths[h] + 2)).join('+') + '+';\n const headerRow = '|' + headerList.map(h => ' ' + h.padEnd(colWidths[h]) + ' ').join('|') + '|';\n\n const dataRows = rows.map(row => {\n return '|' + headerList.map(h => {\n const key = h === '(index)' ? '__index' : h;\n const val = row[key];\n const formatted = val !== undefined ? __formatForConsole(val, { depth: 1, inObject: true }) : '';\n return ' ' + formatted.padEnd(colWidths[h]) + ' ';\n }).join('|') + '|';\n });\n\n return [sep, headerRow, sep, ...dataRows, sep].join('\\\\n');\n }\n\n globalThis.console = {\n log: (...args) => __console_log(__formatArgs(args)),\n warn: (...args) => __console_warn(__formatArgs(args)),\n error: (...args) => __console_error(__formatArgs(args)),\n debug: (...args) => __console_debug(__formatArgs(args)),\n info: (...args) => __console_info(__formatArgs(args)),\n trace: (...args) => {\n const err = new Error();\n const stack = err.stack || '';\n // Remove the first two lines (Error and the trace call itself)\n const stackLines = stack.split('\\\\n').slice(2).join('\\\\n');\n __console_trace(__formatArgs(args), 'Trace' + (args.length > 0 ? ': ' + __formatArgs(args) : '') + '\\\\n' + stackLines);\n },\n dir: (value, options) => __console_dir(__formatForConsole(value, { depth: options?.depth ?? 2, inObject: true })),\n table: (data, columns) => __console_table(__formatTable(data, columns)),\n time: __console_time,\n timeEnd: __console_timeEnd,\n timeLog: (label, ...args) => __console_timeLog(label ?? 'default', 0, __formatArgs(args)),\n count: __console_count,\n countReset: __console_countReset,\n group: __console_group,\n groupCollapsed: __console_groupCollapsed,\n groupEnd: __console_groupEnd,\n clear: __console_clear,\n assert: (condition, ...args) => {\n if (!condition) {\n const msg = args.length > 0 ? __formatArgs(args) : 'console.assert';\n __console_assert('Assertion failed: ' + msg);\n }\n },\n };\n `);\n\n return {\n dispose() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n reset() {\n timers.clear();\n counters.clear();\n groupDepth = 0;\n },\n getTimers() {\n return new Map(timers);\n },\n getCounters() {\n return new Map(counters);\n },\n getGroupDepth() {\n return groupDepth;\n },\n };\n}\n"
6
6
  ],
7
7
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GA0RhB;AAAA,EAED,OAAO;AAAA,IACL,OAAO,GAAG;AAAA,MACR,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,MACf,aAAa;AAAA;AAAA,IAEf,KAAK,GAAG;AAAA,MACN,OAAO,MAAM;AAAA,MACb,SAAS,MAAM;AAAA,MACf,aAAa;AAAA;AAAA,IAEf,SAAS,GAAG;AAAA,MACV,OAAO,IAAI,IAAI,MAAM;AAAA;AAAA,IAEvB,WAAW,GAAG;AAAA,MACZ,OAAO,IAAI,IAAI,QAAQ;AAAA;AAAA,IAEzB,aAAa,GAAG;AAAA,MACd,OAAO;AAAA;AAAA,EAEX;AAAA;",
8
- "debugId": "5FE17BFAA79E0DE064756E2164756E21",
8
+ "debugId": "81BA159AA25332A264756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -75,7 +75,7 @@ __export(exports_core, {
75
75
  cleanupUnmarshaledHandles: () => cleanupUnmarshaledHandles
76
76
  });
77
77
  module.exports = __toCommonJS(exports_core);
78
- var import_isolated_vm = __toESM(require("isolated-vm"));
78
+ var import_isolated_vm = __toESM(require("@ricsam/isolated-vm"));
79
79
  var import_node_fs = require("node:fs");
80
80
  var import_node_path = __toESM(require("node:path"));
81
81
  var import_node_module = require("node:module");
@@ -1752,6 +1752,16 @@ async function injectAbortController(context) {
1752
1752
  (function() {
1753
1753
  // Use WeakMap for private state (similar to Blob pattern)
1754
1754
  const _abortSignalState = new WeakMap();
1755
+ const __wrapAsyncContextCallback = (callback) => (
1756
+ typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.wrapCallback
1757
+ ? globalThis.__isolateAsyncContextInternals.wrapCallback(callback, { type: 'isolate.abort' })
1758
+ : callback
1759
+ );
1760
+ const __releaseAsyncContextCallback = (callback) => (
1761
+ typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.releaseCallback
1762
+ ? globalThis.__isolateAsyncContextInternals.releaseCallback(callback)
1763
+ : false
1764
+ );
1755
1765
 
1756
1766
  class AbortSignal {
1757
1767
  constructor() {
@@ -1800,7 +1810,8 @@ async function injectAbortController(context) {
1800
1810
  if (type !== 'abort') return;
1801
1811
  const state = _abortSignalState.get(this);
1802
1812
  if (state) {
1803
- state.listeners.push(listener);
1813
+ const wrapped = __wrapAsyncContextCallback(listener);
1814
+ state.listeners.push({ original: listener, wrapped });
1804
1815
  }
1805
1816
  }
1806
1817
 
@@ -1808,8 +1819,13 @@ async function injectAbortController(context) {
1808
1819
  if (type !== 'abort') return;
1809
1820
  const state = _abortSignalState.get(this);
1810
1821
  if (state) {
1811
- const idx = state.listeners.indexOf(listener);
1812
- if (idx !== -1) state.listeners.splice(idx, 1);
1822
+ const idx = state.listeners.findIndex((entry) => (
1823
+ entry.original === listener || entry.wrapped === listener
1824
+ ));
1825
+ if (idx !== -1) {
1826
+ __releaseAsyncContextCallback(state.listeners[idx].wrapped);
1827
+ state.listeners.splice(idx, 1);
1828
+ }
1813
1829
  }
1814
1830
  }
1815
1831
 
@@ -1821,7 +1837,7 @@ async function injectAbortController(context) {
1821
1837
  const event = { type: 'abort', target: this };
1822
1838
  for (const listener of state.listeners) {
1823
1839
  try {
1824
- listener(event);
1840
+ listener.wrapped(event);
1825
1841
  } catch (e) {
1826
1842
  // Ignore listener errors
1827
1843
  }
@@ -2742,4 +2758,4 @@ async function injectStreams(context, _stateMap) {
2742
2758
  context.evalSync(streamsCode);
2743
2759
  }
2744
2760
 
2745
- //# debugId=A3C860CFA455830664756E2164756E21
2761
+ //# debugId=42B699410F9B400664756E2164756E21