@holokai/neuron-sdk 0.6.0 → 0.7.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.
package/dist/index.mjs CHANGED
@@ -572,13 +572,16 @@ var TransportError = class extends Error {
572
572
  };
573
573
 
574
574
  // src/lease-runner.ts
575
- var TerminalFailure = class extends Error {
576
- constructor(reason, code) {
575
+ var HandlerFailure = class extends Error {
576
+ constructor(reason, code, details, kind = "terminal") {
577
577
  super(reason);
578
578
  this.reason = reason;
579
579
  this.code = code;
580
- this.name = "TerminalFailure";
580
+ this.details = details;
581
+ this.name = "HandlerFailure";
582
+ this.kind = kind;
581
583
  }
584
+ kind;
582
585
  };
583
586
  var DEFAULT_PROGRESS_TIMEOUT_MS = 5e3;
584
587
  function validateInput(zod, validator, jsonSchema, data) {
@@ -586,10 +589,7 @@ function validateInput(zod, validator, jsonSchema, data) {
586
589
  const result = zod.safeParse(data);
587
590
  return result.success ? { ok: true, value: result.data } : { ok: false, errors: result.error.issues };
588
591
  }
589
- const errors = validator.validate(
590
- jsonSchema,
591
- data
592
- );
592
+ const errors = validator.validate(jsonSchema, data);
593
593
  return errors === null ? { ok: true, value: data } : { ok: false, errors };
594
594
  }
595
595
  async function runLease(opts) {
@@ -619,7 +619,13 @@ async function runLease(opts) {
619
619
  return;
620
620
  }
621
621
  const parsedInput = inputCheck.value;
622
- const reporter = makeProgressReporter(transport, lease.leaseId, logger, signal, progressTimeoutMs);
622
+ const reporter = makeProgressReporter(
623
+ transport,
624
+ lease.leaseId,
625
+ logger,
626
+ signal,
627
+ progressTimeoutMs
628
+ );
623
629
  const ctx = {
624
630
  task: lease.task,
625
631
  leaseId: lease.leaseId,
@@ -627,7 +633,7 @@ async function runLease(opts) {
627
633
  log: scopedLogger(logger, lease),
628
634
  progress: reporter.progress,
629
635
  fail: (reason, opts2) => {
630
- throw new TerminalFailure(reason, opts2?.code);
636
+ throw new HandlerFailure(reason, opts2?.code, opts2?.details, opts2?.kind);
631
637
  }
632
638
  };
633
639
  let output;
@@ -647,13 +653,16 @@ async function runLease(opts) {
647
653
  );
648
654
  return;
649
655
  }
650
- if (err instanceof TerminalFailure) {
656
+ if (err instanceof HandlerFailure) {
651
657
  await sendNack(
652
658
  transport,
653
659
  lease.leaseId,
654
- "terminal",
660
+ err.kind,
655
661
  err.reason,
656
- { code: err.code ?? "HANDLER_TERMINAL" },
662
+ {
663
+ code: err.code ?? (err.kind === "terminal" ? "HANDLER_TERMINAL" : "HANDLER_RETRYABLE"),
664
+ ...err.details !== void 0 ? { details: err.details } : {}
665
+ },
657
666
  logger
658
667
  );
659
668
  return;
@@ -1244,6 +1253,6 @@ var Neuron = class extends EventEmitter {
1244
1253
  };
1245
1254
  var SSE_EVENT_NAMES = SSE_EVENT;
1246
1255
 
1247
- export { HttpTransport, Neuron, SSE_EVENT_NAMES, SchemaValidator, ShutdownError, TransportError, WorkerPool, defineCapability, toPlanShape, toRegistrationCapability };
1256
+ export { HandlerFailure, HttpTransport, Neuron, SSE_EVENT_NAMES, SchemaValidator, ShutdownError, TransportError, WorkerPool, defineCapability, toPlanShape, toRegistrationCapability };
1248
1257
  //# sourceMappingURL=index.mjs.map
1249
1258
  //# sourceMappingURL=index.mjs.map