@execbox/quickjs 0.2.0 → 0.3.0

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 (53) hide show
  1. package/README.md +21 -5
  2. package/dist/index.cjs +610 -7
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +19 -4
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.ts +19 -4
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +607 -4
  9. package/dist/index.js.map +1 -1
  10. package/dist/processEntry.cjs +17 -0
  11. package/dist/processEntry.cjs.map +1 -0
  12. package/dist/processEntry.d.cts +5 -0
  13. package/dist/processEntry.d.ts +5 -0
  14. package/dist/processEntry.js +18 -0
  15. package/dist/processEntry.js.map +1 -0
  16. package/dist/protocolEndpoint-A1JBvHG_.cjs +147 -0
  17. package/dist/protocolEndpoint-A1JBvHG_.cjs.map +1 -0
  18. package/dist/protocolEndpoint-CDGgtfFu.js +142 -0
  19. package/dist/protocolEndpoint-CDGgtfFu.js.map +1 -0
  20. package/dist/runner/index.cjs +1 -1
  21. package/dist/runner/index.d.cts +16 -78
  22. package/dist/runner/index.d.cts.map +1 -1
  23. package/dist/runner/index.d.ts +16 -78
  24. package/dist/runner/index.d.ts.map +1 -1
  25. package/dist/runner/index.js +1 -1
  26. package/dist/runner/protocolEndpoint.cjs +3 -137
  27. package/dist/runner/protocolEndpoint.d.cts +4 -0
  28. package/dist/runner/protocolEndpoint.d.cts.map +1 -1
  29. package/dist/runner/protocolEndpoint.d.ts +4 -0
  30. package/dist/runner/protocolEndpoint.d.ts.map +1 -1
  31. package/dist/runner/protocolEndpoint.js +3 -137
  32. package/dist/{runner-B4UG88h1.js → runner-CteKTaPD.js} +93 -10
  33. package/dist/runner-CteKTaPD.js.map +1 -0
  34. package/dist/{runner-DhOZH9xz.cjs → runner-DRt0kpEk.cjs} +140 -9
  35. package/dist/{runner-B4UG88h1.js.map → runner-DRt0kpEk.cjs.map} +1 -1
  36. package/dist/types-BeVqrcj8.d.ts +71 -0
  37. package/dist/types-BeVqrcj8.d.ts.map +1 -0
  38. package/dist/types-CnNmLawC.d.cts +71 -0
  39. package/dist/types-CnNmLawC.d.cts.map +1 -0
  40. package/dist/workerEntry.cjs +19 -0
  41. package/dist/workerEntry.cjs.map +1 -0
  42. package/dist/workerEntry.d.cts +5 -0
  43. package/dist/workerEntry.d.ts +5 -0
  44. package/dist/workerEntry.js +20 -0
  45. package/dist/workerEntry.js.map +1 -0
  46. package/package.json +16 -7
  47. package/dist/runner/protocolEndpoint.cjs.map +0 -1
  48. package/dist/runner/protocolEndpoint.js.map +0 -1
  49. package/dist/runner-DhOZH9xz.cjs.map +0 -1
  50. package/dist/types-BB8mb_-T.d.cts +0 -14
  51. package/dist/types-BB8mb_-T.d.cts.map +0 -1
  52. package/dist/types-D7uau0GM.d.ts +0 -14
  53. package/dist/types-D7uau0GM.d.ts.map +0 -1
@@ -28,6 +28,20 @@ function getExecutionTimeoutMessage() {
28
28
  return EXECUTION_TIMEOUT_MESSAGE;
29
29
  }
30
30
  /**
31
+ * Creates the canonical timeout failure result used for preflight cancellation.
32
+ */
33
+ function createTimeoutExecuteResult(durationMs = 0) {
34
+ return {
35
+ durationMs,
36
+ error: {
37
+ code: "timeout",
38
+ message: getExecutionTimeoutMessage()
39
+ },
40
+ logs: [],
41
+ ok: false
42
+ };
43
+ }
44
+ /**
31
45
  * Normalizes an unknown thrown value into a human-readable message.
32
46
  */
33
47
  function normalizeThrownMessage(error) {
@@ -39,6 +53,17 @@ function normalizeThrownMessage(error) {
39
53
  return String(error);
40
54
  }
41
55
  /**
56
+ * Builds the standard tool execution context passed to resolved tool wrappers.
57
+ */
58
+ function createExecutionContext(signal, providerName, safeToolName, originalToolName) {
59
+ return {
60
+ originalToolName,
61
+ providerName,
62
+ safeToolName,
63
+ signal
64
+ };
65
+ }
66
+ /**
42
67
  * Truncates captured logs to the configured line and character limits.
43
68
  */
44
69
  function truncateLogs(logs, maxLogLines, maxLogChars) {
@@ -5226,6 +5251,66 @@ var ExecuteFailure = class extends Error {
5226
5251
  function isExecuteFailure(value) {
5227
5252
  return value instanceof ExecuteFailure;
5228
5253
  }
5254
+ /**
5255
+ * Returns whether a value can be serialized through the JSON-only host/guest boundary.
5256
+ */
5257
+ function isJsonSerializable(value, active = /* @__PURE__ */ new Set(), memo = /* @__PURE__ */ new WeakSet()) {
5258
+ if (value === null) return true;
5259
+ switch (typeof value) {
5260
+ case "string":
5261
+ case "boolean": return true;
5262
+ case "number": return Number.isFinite(value);
5263
+ case "bigint":
5264
+ case "function":
5265
+ case "symbol":
5266
+ case "undefined": return false;
5267
+ case "object": {
5268
+ const objectValue = value;
5269
+ if (memo.has(objectValue)) return true;
5270
+ if (active.has(objectValue)) return false;
5271
+ active.add(objectValue);
5272
+ let isSerializable = false;
5273
+ try {
5274
+ if (Array.isArray(value)) {
5275
+ isSerializable = value.every((item) => isJsonSerializable(item, active, memo));
5276
+ return isSerializable;
5277
+ }
5278
+ const prototype = Object.getPrototypeOf(value);
5279
+ if (prototype !== Object.prototype && prototype !== null) return false;
5280
+ isSerializable = Object.values(value).every((item) => isJsonSerializable(item, active, memo));
5281
+ return isSerializable;
5282
+ } finally {
5283
+ active.delete(objectValue);
5284
+ if (isSerializable) memo.add(objectValue);
5285
+ }
5286
+ }
5287
+ }
5288
+ return false;
5289
+ }
5290
+
5291
+ //#endregion
5292
+ //#region ../core/src/runtimeOptions.ts
5293
+ /**
5294
+ * Default runtime limits shared across the built-in executor implementations.
5295
+ */
5296
+ const DEFAULT_EXECUTOR_RUNTIME_OPTIONS = {
5297
+ maxLogChars: 64e3,
5298
+ maxLogLines: 100,
5299
+ memoryLimitBytes: 64 * 1024 * 1024,
5300
+ timeoutMs: 5e3
5301
+ };
5302
+ /**
5303
+ * Resolves executor runtime limits by applying explicit overrides on top of a
5304
+ * base options object and finally the shared defaults.
5305
+ */
5306
+ function resolveExecutorRuntimeOptions(options = {}, overrides = {}) {
5307
+ return {
5308
+ maxLogChars: overrides.maxLogChars ?? options.maxLogChars ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.maxLogChars,
5309
+ maxLogLines: overrides.maxLogLines ?? options.maxLogLines ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.maxLogLines,
5310
+ memoryLimitBytes: overrides.memoryLimitBytes ?? options.memoryLimitBytes ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.memoryLimitBytes,
5311
+ timeoutMs: overrides.timeoutMs ?? options.timeoutMs ?? DEFAULT_EXECUTOR_RUNTIME_OPTIONS.timeoutMs
5312
+ };
5313
+ }
5229
5314
 
5230
5315
  //#endregion
5231
5316
  //#region src/quickjsBridge.ts
@@ -5282,10 +5367,10 @@ function toGuestHandle(context, value) {
5282
5367
 
5283
5368
  //#endregion
5284
5369
  //#region src/runner/index.ts
5285
- const DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
5286
- const DEFAULT_TIMEOUT_MS = 5e3;
5287
- const DEFAULT_MAX_LOG_LINES = 100;
5288
- const DEFAULT_MAX_LOG_CHARS = 64e3;
5370
+ /**
5371
+ * @packageDocumentation
5372
+ * Public API for the `@execbox/quickjs/runner` entrypoint.
5373
+ */
5289
5374
  const loadDefaultModule = (0, quickjs_emscripten.memoizePromiseFactory)(() => (0, quickjs_emscripten.newQuickJSWASMModule)(quickjs_emscripten.RELEASE_SYNC));
5290
5375
  /**
5291
5376
  * Converts unexpected executor failures into stable public result errors.
@@ -5479,14 +5564,12 @@ function createToolHandle(context, providerName, safeToolName, signal, trustedHo
5479
5564
  * Runs one QuickJS-backed execution session using a transport-neutral tool callback.
5480
5565
  */
5481
5566
  async function runQuickJsSession(request, options = {}) {
5567
+ const runtimeOptions = resolveExecutorRuntimeOptions(options);
5482
5568
  const loadModule = async () => {
5483
5569
  if (options.module) return options.module;
5484
5570
  return options.loadModule ? await options.loadModule() : await loadDefaultModule();
5485
5571
  };
5486
- const maxLogChars = options.maxLogChars ?? DEFAULT_MAX_LOG_CHARS;
5487
- const maxLogLines = options.maxLogLines ?? DEFAULT_MAX_LOG_LINES;
5488
- const memoryLimitBytes = options.memoryLimitBytes ?? DEFAULT_MEMORY_LIMIT_BYTES;
5489
- const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
5572
+ const { maxLogChars, maxLogLines, memoryLimitBytes, timeoutMs } = runtimeOptions;
5490
5573
  const startedAt = Date.now();
5491
5574
  const logs = [];
5492
5575
  const abortController = new AbortController();
@@ -5567,10 +5650,58 @@ async function runQuickJsSession(request, options = {}) {
5567
5650
  }
5568
5651
 
5569
5652
  //#endregion
5653
+ Object.defineProperty(exports, 'ExecuteFailure', {
5654
+ enumerable: true,
5655
+ get: function () {
5656
+ return ExecuteFailure;
5657
+ }
5658
+ });
5659
+ Object.defineProperty(exports, 'createExecutionContext', {
5660
+ enumerable: true,
5661
+ get: function () {
5662
+ return createExecutionContext;
5663
+ }
5664
+ });
5665
+ Object.defineProperty(exports, 'createTimeoutExecuteResult', {
5666
+ enumerable: true,
5667
+ get: function () {
5668
+ return createTimeoutExecuteResult;
5669
+ }
5670
+ });
5671
+ Object.defineProperty(exports, 'getExecutionTimeoutMessage', {
5672
+ enumerable: true,
5673
+ get: function () {
5674
+ return getExecutionTimeoutMessage;
5675
+ }
5676
+ });
5677
+ Object.defineProperty(exports, 'isExecuteFailure', {
5678
+ enumerable: true,
5679
+ get: function () {
5680
+ return isExecuteFailure;
5681
+ }
5682
+ });
5683
+ Object.defineProperty(exports, 'isJsonSerializable', {
5684
+ enumerable: true,
5685
+ get: function () {
5686
+ return isJsonSerializable;
5687
+ }
5688
+ });
5689
+ Object.defineProperty(exports, 'normalizeThrownMessage', {
5690
+ enumerable: true,
5691
+ get: function () {
5692
+ return normalizeThrownMessage;
5693
+ }
5694
+ });
5695
+ Object.defineProperty(exports, 'resolveExecutorRuntimeOptions', {
5696
+ enumerable: true,
5697
+ get: function () {
5698
+ return resolveExecutorRuntimeOptions;
5699
+ }
5700
+ });
5570
5701
  Object.defineProperty(exports, 'runQuickJsSession', {
5571
5702
  enumerable: true,
5572
5703
  get: function () {
5573
5704
  return runQuickJsSession;
5574
5705
  }
5575
5706
  });
5576
- //# sourceMappingURL=runner-DhOZH9xz.cjs.map
5707
+ //# sourceMappingURL=runner-DRt0kpEk.cjs.map