@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.d.mts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +22 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -13
- package/dist/index.mjs.map +1 -1
- package/dist/ipc.d.mts +1 -1
- package/dist/ipc.d.ts +1 -1
- package/dist/{transport-Va7tTRVO.d.mts → transport-BhFVHvR7.d.mts} +13 -7
- package/dist/{transport-Va7tTRVO.d.ts → transport-BhFVHvR7.d.ts} +13 -7
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { J as JsonSchema, C as Capability, a as CapabilityHandleOptions, S as ServerToNeuronFrame, N as NeuronLogger, T as Transport, A as AuthCallback, H as Handler, b as CapabilityRegistration, c as TransportCallbacks, d as ClientFrame, P as PostPath } from './transport-
|
|
2
|
-
export { e as HandlerContext, f as HeartbeatInFlightEntry, L as LeasePayload,
|
|
1
|
+
import { J as JsonSchema, C as Capability, a as CapabilityHandleOptions, S as ServerToNeuronFrame, N as NeuronLogger, T as Transport, A as AuthCallback, H as Handler, b as CapabilityRegistration, c as TransportCallbacks, d as ClientFrame, P as PostPath } from './transport-BhFVHvR7.mjs';
|
|
2
|
+
export { e as HandlerContext, f as HandlerFailureOptions, g as HeartbeatInFlightEntry, L as LeasePayload, h as TaskPayload } from './transport-BhFVHvR7.mjs';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ErrorObject } from 'ajv';
|
|
@@ -426,4 +426,18 @@ declare class SchemaValidator {
|
|
|
426
426
|
validate(schema: JsonSchema | undefined, data: unknown): ErrorObject[] | null;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
|
|
429
|
+
/**
|
|
430
|
+
* The exception `ctx.fail()` throws to short-circuit the handler with a
|
|
431
|
+
* nack. Caught by the runner; consumers should not catch it. Exported so a
|
|
432
|
+
* wrapper around a handler can raise one for a refusal the handler answered
|
|
433
|
+
* as data.
|
|
434
|
+
*/
|
|
435
|
+
declare class HandlerFailure extends Error {
|
|
436
|
+
readonly reason: string;
|
|
437
|
+
readonly code?: string | undefined;
|
|
438
|
+
readonly details?: unknown | undefined;
|
|
439
|
+
readonly kind: 'terminal' | 'retryable';
|
|
440
|
+
constructor(reason: string, code?: string | undefined, details?: unknown | undefined, kind?: 'terminal' | 'retryable');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export { AuthCallback, Capability, type CapabilityDef, type CapabilityDefInit, CapabilityHandleOptions, type CapabilityPlanShape, CapabilityRegistration, Handler, HandlerFailure, HttpTransport, type HttpTransportOptions, Neuron, type NeuronEvents, NeuronLogger, type NeuronOptions, SSE_EVENT_NAMES, SchemaValidator, ServerToNeuronFrame, ShutdownError, Transport, TransportCallbacks, TransportError, WorkerPool, defineCapability, toPlanShape, toRegistrationCapability };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { J as JsonSchema, C as Capability, a as CapabilityHandleOptions, S as ServerToNeuronFrame, N as NeuronLogger, T as Transport, A as AuthCallback, H as Handler, b as CapabilityRegistration, c as TransportCallbacks, d as ClientFrame, P as PostPath } from './transport-
|
|
2
|
-
export { e as HandlerContext, f as HeartbeatInFlightEntry, L as LeasePayload,
|
|
1
|
+
import { J as JsonSchema, C as Capability, a as CapabilityHandleOptions, S as ServerToNeuronFrame, N as NeuronLogger, T as Transport, A as AuthCallback, H as Handler, b as CapabilityRegistration, c as TransportCallbacks, d as ClientFrame, P as PostPath } from './transport-BhFVHvR7.js';
|
|
2
|
+
export { e as HandlerContext, f as HandlerFailureOptions, g as HeartbeatInFlightEntry, L as LeasePayload, h as TaskPayload } from './transport-BhFVHvR7.js';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ErrorObject } from 'ajv';
|
|
@@ -426,4 +426,18 @@ declare class SchemaValidator {
|
|
|
426
426
|
validate(schema: JsonSchema | undefined, data: unknown): ErrorObject[] | null;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
|
|
429
|
+
/**
|
|
430
|
+
* The exception `ctx.fail()` throws to short-circuit the handler with a
|
|
431
|
+
* nack. Caught by the runner; consumers should not catch it. Exported so a
|
|
432
|
+
* wrapper around a handler can raise one for a refusal the handler answered
|
|
433
|
+
* as data.
|
|
434
|
+
*/
|
|
435
|
+
declare class HandlerFailure extends Error {
|
|
436
|
+
readonly reason: string;
|
|
437
|
+
readonly code?: string | undefined;
|
|
438
|
+
readonly details?: unknown | undefined;
|
|
439
|
+
readonly kind: 'terminal' | 'retryable';
|
|
440
|
+
constructor(reason: string, code?: string | undefined, details?: unknown | undefined, kind?: 'terminal' | 'retryable');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export { AuthCallback, Capability, type CapabilityDef, type CapabilityDefInit, CapabilityHandleOptions, type CapabilityPlanShape, CapabilityRegistration, Handler, HandlerFailure, HttpTransport, type HttpTransportOptions, Neuron, type NeuronEvents, NeuronLogger, type NeuronOptions, SSE_EVENT_NAMES, SchemaValidator, ServerToNeuronFrame, ShutdownError, Transport, TransportCallbacks, TransportError, WorkerPool, defineCapability, toPlanShape, toRegistrationCapability };
|
package/dist/index.js
CHANGED
|
@@ -579,13 +579,16 @@ var TransportError = class extends Error {
|
|
|
579
579
|
};
|
|
580
580
|
|
|
581
581
|
// src/lease-runner.ts
|
|
582
|
-
var
|
|
583
|
-
constructor(reason, code) {
|
|
582
|
+
var HandlerFailure = class extends Error {
|
|
583
|
+
constructor(reason, code, details, kind = "terminal") {
|
|
584
584
|
super(reason);
|
|
585
585
|
this.reason = reason;
|
|
586
586
|
this.code = code;
|
|
587
|
-
this.
|
|
587
|
+
this.details = details;
|
|
588
|
+
this.name = "HandlerFailure";
|
|
589
|
+
this.kind = kind;
|
|
588
590
|
}
|
|
591
|
+
kind;
|
|
589
592
|
};
|
|
590
593
|
var DEFAULT_PROGRESS_TIMEOUT_MS = 5e3;
|
|
591
594
|
function validateInput(zod, validator, jsonSchema, data) {
|
|
@@ -593,10 +596,7 @@ function validateInput(zod, validator, jsonSchema, data) {
|
|
|
593
596
|
const result = zod.safeParse(data);
|
|
594
597
|
return result.success ? { ok: true, value: result.data } : { ok: false, errors: result.error.issues };
|
|
595
598
|
}
|
|
596
|
-
const errors = validator.validate(
|
|
597
|
-
jsonSchema,
|
|
598
|
-
data
|
|
599
|
-
);
|
|
599
|
+
const errors = validator.validate(jsonSchema, data);
|
|
600
600
|
return errors === null ? { ok: true, value: data } : { ok: false, errors };
|
|
601
601
|
}
|
|
602
602
|
async function runLease(opts) {
|
|
@@ -626,7 +626,13 @@ async function runLease(opts) {
|
|
|
626
626
|
return;
|
|
627
627
|
}
|
|
628
628
|
const parsedInput = inputCheck.value;
|
|
629
|
-
const reporter = makeProgressReporter(
|
|
629
|
+
const reporter = makeProgressReporter(
|
|
630
|
+
transport,
|
|
631
|
+
lease.leaseId,
|
|
632
|
+
logger,
|
|
633
|
+
signal,
|
|
634
|
+
progressTimeoutMs
|
|
635
|
+
);
|
|
630
636
|
const ctx = {
|
|
631
637
|
task: lease.task,
|
|
632
638
|
leaseId: lease.leaseId,
|
|
@@ -634,7 +640,7 @@ async function runLease(opts) {
|
|
|
634
640
|
log: scopedLogger(logger, lease),
|
|
635
641
|
progress: reporter.progress,
|
|
636
642
|
fail: (reason, opts2) => {
|
|
637
|
-
throw new
|
|
643
|
+
throw new HandlerFailure(reason, opts2?.code, opts2?.details, opts2?.kind);
|
|
638
644
|
}
|
|
639
645
|
};
|
|
640
646
|
let output;
|
|
@@ -654,13 +660,16 @@ async function runLease(opts) {
|
|
|
654
660
|
);
|
|
655
661
|
return;
|
|
656
662
|
}
|
|
657
|
-
if (err instanceof
|
|
663
|
+
if (err instanceof HandlerFailure) {
|
|
658
664
|
await sendNack(
|
|
659
665
|
transport,
|
|
660
666
|
lease.leaseId,
|
|
661
|
-
|
|
667
|
+
err.kind,
|
|
662
668
|
err.reason,
|
|
663
|
-
{
|
|
669
|
+
{
|
|
670
|
+
code: err.code ?? (err.kind === "terminal" ? "HANDLER_TERMINAL" : "HANDLER_RETRYABLE"),
|
|
671
|
+
...err.details !== void 0 ? { details: err.details } : {}
|
|
672
|
+
},
|
|
664
673
|
logger
|
|
665
674
|
);
|
|
666
675
|
return;
|
|
@@ -1251,6 +1260,7 @@ var Neuron = class extends eventemitter3.EventEmitter {
|
|
|
1251
1260
|
};
|
|
1252
1261
|
var SSE_EVENT_NAMES = SSE_EVENT;
|
|
1253
1262
|
|
|
1263
|
+
exports.HandlerFailure = HandlerFailure;
|
|
1254
1264
|
exports.HttpTransport = HttpTransport;
|
|
1255
1265
|
exports.Neuron = Neuron;
|
|
1256
1266
|
exports.SSE_EVENT_NAMES = SSE_EVENT_NAMES;
|