@execbox/quickjs 0.2.0 → 0.2.1

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 (34) hide show
  1. package/README.md +4 -2
  2. package/dist/index.cjs +68 -5
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +5 -1
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.ts +5 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +65 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/runner/index.cjs +1 -1
  11. package/dist/runner/index.d.cts +8 -77
  12. package/dist/runner/index.d.cts.map +1 -1
  13. package/dist/runner/index.d.ts +8 -77
  14. package/dist/runner/index.d.ts.map +1 -1
  15. package/dist/runner/index.js +1 -1
  16. package/dist/runner/protocolEndpoint.cjs +5 -1
  17. package/dist/runner/protocolEndpoint.cjs.map +1 -1
  18. package/dist/runner/protocolEndpoint.d.cts +4 -0
  19. package/dist/runner/protocolEndpoint.d.cts.map +1 -1
  20. package/dist/runner/protocolEndpoint.d.ts +4 -0
  21. package/dist/runner/protocolEndpoint.d.ts.map +1 -1
  22. package/dist/runner/protocolEndpoint.js +5 -1
  23. package/dist/runner/protocolEndpoint.js.map +1 -1
  24. package/dist/{runner-DhOZH9xz.cjs → runner-BqkDnP0t.cjs} +108 -1
  25. package/dist/{runner-DhOZH9xz.cjs.map → runner-BqkDnP0t.cjs.map} +1 -1
  26. package/dist/{runner-B4UG88h1.js → runner-CVaY4RVQ.js} +67 -2
  27. package/dist/{runner-B4UG88h1.js.map → runner-CVaY4RVQ.js.map} +1 -1
  28. package/dist/{types-BB8mb_-T.d.cts → types-BXi8Lqtk.d.ts} +6 -2
  29. package/dist/types-BXi8Lqtk.d.ts.map +1 -0
  30. package/dist/{types-D7uau0GM.d.ts → types-CVE2n2LY.d.cts} +6 -2
  31. package/dist/types-CVE2n2LY.d.cts.map +1 -0
  32. package/package.json +15 -6
  33. package/dist/types-BB8mb_-T.d.cts.map +0 -1
  34. 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,42 @@ 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
+ }
5229
5290
 
5230
5291
  //#endregion
5231
5292
  //#region src/quickjsBridge.ts
@@ -5282,6 +5343,10 @@ function toGuestHandle(context, value) {
5282
5343
 
5283
5344
  //#endregion
5284
5345
  //#region src/runner/index.ts
5346
+ /**
5347
+ * @packageDocumentation
5348
+ * Public API for the `@execbox/quickjs/runner` entrypoint.
5349
+ */
5285
5350
  const DEFAULT_MEMORY_LIMIT_BYTES = 64 * 1024 * 1024;
5286
5351
  const DEFAULT_TIMEOUT_MS = 5e3;
5287
5352
  const DEFAULT_MAX_LOG_LINES = 100;
@@ -5567,5 +5632,5 @@ async function runQuickJsSession(request, options = {}) {
5567
5632
  }
5568
5633
 
5569
5634
  //#endregion
5570
- export { runQuickJsSession as t };
5571
- //# sourceMappingURL=runner-B4UG88h1.js.map
5635
+ export { createExecutionContext as a, normalizeThrownMessage as c, isJsonSerializable as i, ExecuteFailure as n, createTimeoutExecuteResult as o, isExecuteFailure as r, getExecutionTimeoutMessage as s, runQuickJsSession as t };
5636
+ //# sourceMappingURL=runner-CVaY4RVQ.js.map