@execbox/quickjs 0.1.1 → 0.2.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.
@@ -5395,10 +5395,23 @@ function injectProviders(context, providers, signal, trustedHostErrorKey, onTool
5395
5395
  function createToolHandle(context, providerName, safeToolName, signal, trustedHostErrorKey, onToolCall) {
5396
5396
  return context.newFunction(safeToolName, (...args) => {
5397
5397
  const deferred = context.newPromise();
5398
- const input = args[0] === void 0 ? void 0 : context.dump(args[0]);
5399
5398
  const disposeDeferred = () => {
5400
5399
  if (context.alive && deferred.alive) deferred.dispose();
5401
5400
  };
5401
+ let input;
5402
+ try {
5403
+ input = args[0] === void 0 ? void 0 : fromGuestHandle(context, args[0]);
5404
+ } catch (error) {
5405
+ const executeError = isExecuteFailure(error) ? error : new ExecuteFailure("serialization_error", "Guest code passed a non-serializable tool input");
5406
+ const errorHandle = createGuestErrorHandle(context, executeError.code, executeError.message, trustedHostErrorKey);
5407
+ try {
5408
+ deferred.reject(errorHandle);
5409
+ return deferred.handle;
5410
+ } finally {
5411
+ errorHandle.dispose();
5412
+ queueMicrotask(disposeDeferred);
5413
+ }
5414
+ }
5402
5415
  const onAbort = () => {
5403
5416
  signal.removeEventListener("abort", onAbort);
5404
5417
  if (!context.alive || !deferred.alive) {
@@ -5467,6 +5480,7 @@ function createToolHandle(context, providerName, safeToolName, signal, trustedHo
5467
5480
  */
5468
5481
  async function runQuickJsSession(request, options = {}) {
5469
5482
  const loadModule = async () => {
5483
+ if (options.module) return options.module;
5470
5484
  return options.loadModule ? await options.loadModule() : await loadDefaultModule();
5471
5485
  };
5472
5486
  const maxLogChars = options.maxLogChars ?? DEFAULT_MAX_LOG_CHARS;
@@ -5559,4 +5573,4 @@ Object.defineProperty(exports, 'runQuickJsSession', {
5559
5573
  return runQuickJsSession;
5560
5574
  }
5561
5575
  });
5562
- //# sourceMappingURL=runner-CYXIVOmJ.cjs.map
5576
+ //# sourceMappingURL=runner-DhOZH9xz.cjs.map