@nextera.one/axis-server-sdk 2.3.10 → 2.3.13
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-C5LdnkOB.d.ts → index-B0HcQRif.d.ts} +6 -5
- package/dist/{index-Bquulp8S.d.mts → index-C5NXMEth.d.mts} +6 -5
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +324 -247
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +323 -247
- package/dist/index.mjs.map +1 -1
- package/dist/sensors/index.d.mts +1 -1
- package/dist/sensors/index.d.ts +1 -1
- package/dist/sensors/index.js +324 -247
- package/dist/sensors/index.js.map +1 -1
- package/dist/sensors/index.mjs +323 -247
- package/dist/sensors/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/sensors/index.mjs
CHANGED
|
@@ -450,6 +450,31 @@ var init_capsule_policy_decorator = __esm({
|
|
|
450
450
|
|
|
451
451
|
// src/decorators/intent-policy.decorator.ts
|
|
452
452
|
import "reflect-metadata";
|
|
453
|
+
function appendRequiredProof(target, propertyKey, proof) {
|
|
454
|
+
const existing = propertyKey !== void 0 ? Reflect.getMetadata(
|
|
455
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
456
|
+
target,
|
|
457
|
+
propertyKey
|
|
458
|
+
) ?? [] : Reflect.getMetadata(
|
|
459
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
460
|
+
target
|
|
461
|
+
) ?? [];
|
|
462
|
+
const merged = existing.includes(proof) ? existing : [...existing, proof];
|
|
463
|
+
if (propertyKey !== void 0) {
|
|
464
|
+
Reflect.defineMetadata(
|
|
465
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
466
|
+
merged,
|
|
467
|
+
target,
|
|
468
|
+
propertyKey
|
|
469
|
+
);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
Reflect.defineMetadata(
|
|
473
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
474
|
+
merged,
|
|
475
|
+
target
|
|
476
|
+
);
|
|
477
|
+
}
|
|
453
478
|
function Sensitivity(level) {
|
|
454
479
|
return ((target, propertyKey) => {
|
|
455
480
|
if (propertyKey !== void 0) {
|
|
@@ -498,56 +523,12 @@ function RequiredProof(proofs) {
|
|
|
498
523
|
}
|
|
499
524
|
function Capsule() {
|
|
500
525
|
return ((target, propertyKey) => {
|
|
501
|
-
|
|
502
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
503
|
-
target,
|
|
504
|
-
propertyKey
|
|
505
|
-
) ?? [] : Reflect.getMetadata(
|
|
506
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
507
|
-
target
|
|
508
|
-
) ?? [];
|
|
509
|
-
const merged = existing.includes("CAPSULE") ? existing : [...existing, "CAPSULE"];
|
|
510
|
-
if (propertyKey !== void 0) {
|
|
511
|
-
Reflect.defineMetadata(
|
|
512
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
513
|
-
merged,
|
|
514
|
-
target,
|
|
515
|
-
propertyKey
|
|
516
|
-
);
|
|
517
|
-
} else {
|
|
518
|
-
Reflect.defineMetadata(
|
|
519
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
520
|
-
merged,
|
|
521
|
-
target
|
|
522
|
-
);
|
|
523
|
-
}
|
|
526
|
+
appendRequiredProof(target, propertyKey, "CAPSULE");
|
|
524
527
|
});
|
|
525
528
|
}
|
|
526
529
|
function Witness() {
|
|
527
530
|
return ((target, propertyKey) => {
|
|
528
|
-
|
|
529
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
530
|
-
target,
|
|
531
|
-
propertyKey
|
|
532
|
-
) ?? [] : Reflect.getMetadata(
|
|
533
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
534
|
-
target
|
|
535
|
-
) ?? [];
|
|
536
|
-
const merged = existing.includes("WITNESS") ? existing : [...existing, "WITNESS"];
|
|
537
|
-
if (propertyKey !== void 0) {
|
|
538
|
-
Reflect.defineMetadata(
|
|
539
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
540
|
-
merged,
|
|
541
|
-
target,
|
|
542
|
-
propertyKey
|
|
543
|
-
);
|
|
544
|
-
} else {
|
|
545
|
-
Reflect.defineMetadata(
|
|
546
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
547
|
-
merged,
|
|
548
|
-
target
|
|
549
|
-
);
|
|
550
|
-
}
|
|
531
|
+
appendRequiredProof(target, propertyKey, "WITNESS");
|
|
551
532
|
});
|
|
552
533
|
}
|
|
553
534
|
function Axis() {
|
|
@@ -557,31 +538,37 @@ function Axis() {
|
|
|
557
538
|
}
|
|
558
539
|
function AxisPublic() {
|
|
559
540
|
return (target, propertyKey, descriptor) => {
|
|
560
|
-
if (
|
|
541
|
+
if (propertyKey !== void 0) {
|
|
561
542
|
Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target, propertyKey);
|
|
543
|
+
appendRequiredProof(target, propertyKey, "NONE");
|
|
562
544
|
return descriptor;
|
|
563
545
|
}
|
|
564
546
|
Reflect.defineMetadata(AXIS_PUBLIC_KEY, true, target);
|
|
547
|
+
appendRequiredProof(target, void 0, "NONE");
|
|
565
548
|
return target;
|
|
566
549
|
};
|
|
567
550
|
}
|
|
568
551
|
function AxisAuthorized() {
|
|
569
552
|
return (target, propertyKey, descriptor) => {
|
|
570
|
-
if (
|
|
553
|
+
if (propertyKey !== void 0) {
|
|
571
554
|
Reflect.defineMetadata(AXIS_AUTHORIZED_KEY, true, target, propertyKey);
|
|
555
|
+
appendRequiredProof(target, propertyKey, "AUTHORIZED");
|
|
572
556
|
return descriptor;
|
|
573
557
|
}
|
|
574
558
|
Reflect.defineMetadata(AXIS_AUTHORIZED_KEY, true, target);
|
|
559
|
+
appendRequiredProof(target, void 0, "AUTHORIZED");
|
|
575
560
|
return target;
|
|
576
561
|
};
|
|
577
562
|
}
|
|
578
563
|
function AxisAnonymous() {
|
|
579
564
|
return (target, propertyKey, descriptor) => {
|
|
580
|
-
if (
|
|
565
|
+
if (propertyKey !== void 0) {
|
|
581
566
|
Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target, propertyKey);
|
|
567
|
+
appendRequiredProof(target, propertyKey, "ANONYMOUS");
|
|
582
568
|
return descriptor;
|
|
583
569
|
}
|
|
584
570
|
Reflect.defineMetadata(AXIS_ANONYMOUS_KEY, true, target);
|
|
571
|
+
appendRequiredProof(target, void 0, "ANONYMOUS");
|
|
585
572
|
return target;
|
|
586
573
|
};
|
|
587
574
|
}
|
|
@@ -2521,6 +2508,146 @@ var init_axis_error = __esm({
|
|
|
2521
2508
|
}
|
|
2522
2509
|
});
|
|
2523
2510
|
|
|
2511
|
+
// src/engine/intent-builtins.ts
|
|
2512
|
+
function isBuiltinIntent(intent) {
|
|
2513
|
+
return BUILTIN_INTENTS.has(intent);
|
|
2514
|
+
}
|
|
2515
|
+
function isChainExecIntent(intent) {
|
|
2516
|
+
return intent === "CHAIN.EXEC" || intent === "axis.chain.exec";
|
|
2517
|
+
}
|
|
2518
|
+
function isIntentExecIntent(intent) {
|
|
2519
|
+
return intent === "INTENT.EXEC" || intent === "axis.intent.exec";
|
|
2520
|
+
}
|
|
2521
|
+
function routeSystemBuiltinIntent(intent, body, encoder) {
|
|
2522
|
+
if (intent === "system.ping" || intent === "public.ping") {
|
|
2523
|
+
return {
|
|
2524
|
+
ok: true,
|
|
2525
|
+
effect: "pong",
|
|
2526
|
+
headers: /* @__PURE__ */ new Map([[100, encoder.encode("AXIS_BACKEND_V1")]]),
|
|
2527
|
+
body: encoder.encode(
|
|
2528
|
+
JSON.stringify({
|
|
2529
|
+
status: "ok",
|
|
2530
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2531
|
+
version: "1.0.0"
|
|
2532
|
+
})
|
|
2533
|
+
)
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
if (intent === "system.time") {
|
|
2537
|
+
const ts = Date.now().toString();
|
|
2538
|
+
return {
|
|
2539
|
+
ok: true,
|
|
2540
|
+
effect: "time",
|
|
2541
|
+
body: encoder.encode(
|
|
2542
|
+
JSON.stringify({
|
|
2543
|
+
ts,
|
|
2544
|
+
iso: (/* @__PURE__ */ new Date()).toISOString()
|
|
2545
|
+
})
|
|
2546
|
+
)
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
if (intent === "system.echo") {
|
|
2550
|
+
return {
|
|
2551
|
+
ok: true,
|
|
2552
|
+
effect: "echo",
|
|
2553
|
+
body
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
return void 0;
|
|
2557
|
+
}
|
|
2558
|
+
var BUILTIN_INTENTS;
|
|
2559
|
+
var init_intent_builtins = __esm({
|
|
2560
|
+
"src/engine/intent-builtins.ts"() {
|
|
2561
|
+
BUILTIN_INTENTS = /* @__PURE__ */ new Set([
|
|
2562
|
+
"system.ping",
|
|
2563
|
+
"public.ping",
|
|
2564
|
+
"system.time",
|
|
2565
|
+
"system.echo",
|
|
2566
|
+
"CHAIN.EXEC",
|
|
2567
|
+
"axis.chain.exec",
|
|
2568
|
+
"INTENT.EXEC",
|
|
2569
|
+
"axis.intent.exec"
|
|
2570
|
+
]);
|
|
2571
|
+
}
|
|
2572
|
+
});
|
|
2573
|
+
|
|
2574
|
+
// src/engine/intent-proof-policy.ts
|
|
2575
|
+
import "reflect-metadata";
|
|
2576
|
+
function mergeProofKinds(...proofGroups) {
|
|
2577
|
+
const merged = /* @__PURE__ */ new Set();
|
|
2578
|
+
for (const proofs of proofGroups) {
|
|
2579
|
+
for (const proof of proofs ?? []) {
|
|
2580
|
+
merged.add(proof);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
return Array.from(merged);
|
|
2584
|
+
}
|
|
2585
|
+
function accessProofKinds(isPublic, isAnonymous, isAuthorized) {
|
|
2586
|
+
const proofs = [];
|
|
2587
|
+
if (isPublic) proofs.push("NONE");
|
|
2588
|
+
if (isAnonymous) proofs.push("ANONYMOUS");
|
|
2589
|
+
if (isAuthorized) proofs.push("AUTHORIZED");
|
|
2590
|
+
return proofs;
|
|
2591
|
+
}
|
|
2592
|
+
function resolveIntentProofPolicy(proto, methodName) {
|
|
2593
|
+
const methodProof = Reflect.getMetadata(
|
|
2594
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
2595
|
+
proto,
|
|
2596
|
+
methodName
|
|
2597
|
+
);
|
|
2598
|
+
const classProof = Reflect.getMetadata(
|
|
2599
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
2600
|
+
proto.constructor
|
|
2601
|
+
);
|
|
2602
|
+
const isPublicMethod = Reflect.getMetadata(
|
|
2603
|
+
AXIS_PUBLIC_KEY,
|
|
2604
|
+
proto,
|
|
2605
|
+
methodName
|
|
2606
|
+
);
|
|
2607
|
+
const isPublicClass = Reflect.getMetadata(
|
|
2608
|
+
AXIS_PUBLIC_KEY,
|
|
2609
|
+
proto.constructor
|
|
2610
|
+
);
|
|
2611
|
+
const isAnonymousMethod = Reflect.getMetadata(
|
|
2612
|
+
AXIS_ANONYMOUS_KEY,
|
|
2613
|
+
proto,
|
|
2614
|
+
methodName
|
|
2615
|
+
);
|
|
2616
|
+
const isAnonymousClass = Reflect.getMetadata(
|
|
2617
|
+
AXIS_ANONYMOUS_KEY,
|
|
2618
|
+
proto.constructor
|
|
2619
|
+
);
|
|
2620
|
+
const isAuthorizedMethod = Reflect.getMetadata(
|
|
2621
|
+
AXIS_AUTHORIZED_KEY,
|
|
2622
|
+
proto,
|
|
2623
|
+
methodName
|
|
2624
|
+
);
|
|
2625
|
+
const isAuthorizedClass = Reflect.getMetadata(
|
|
2626
|
+
AXIS_AUTHORIZED_KEY,
|
|
2627
|
+
proto.constructor
|
|
2628
|
+
);
|
|
2629
|
+
const methodPolicyProof = mergeProofKinds(
|
|
2630
|
+
methodProof,
|
|
2631
|
+
accessProofKinds(isPublicMethod, isAnonymousMethod, isAuthorizedMethod)
|
|
2632
|
+
);
|
|
2633
|
+
const classPolicyProof = mergeProofKinds(
|
|
2634
|
+
classProof,
|
|
2635
|
+
accessProofKinds(isPublicClass, isAnonymousClass, isAuthorizedClass)
|
|
2636
|
+
);
|
|
2637
|
+
const requiredProof = methodPolicyProof.length ? methodPolicyProof : classPolicyProof;
|
|
2638
|
+
return {
|
|
2639
|
+
requiredProof,
|
|
2640
|
+
isPublic: requiredProof.includes("NONE"),
|
|
2641
|
+
isAnonymous: requiredProof.includes("ANONYMOUS"),
|
|
2642
|
+
isAuthorized: requiredProof.includes("AUTHORIZED")
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
var init_intent_proof_policy = __esm({
|
|
2646
|
+
"src/engine/intent-proof-policy.ts"() {
|
|
2647
|
+
init_intent_policy_decorator();
|
|
2648
|
+
}
|
|
2649
|
+
});
|
|
2650
|
+
|
|
2524
2651
|
// src/engine/intent.router.ts
|
|
2525
2652
|
var intent_router_exports = {};
|
|
2526
2653
|
__export(intent_router_exports, {
|
|
@@ -2591,7 +2718,7 @@ function normalizeChainConfig(decoratorConfig, intentConfig) {
|
|
|
2591
2718
|
...intentConfig
|
|
2592
2719
|
};
|
|
2593
2720
|
}
|
|
2594
|
-
var import_dto_schema,
|
|
2721
|
+
var import_dto_schema, IntentRouter;
|
|
2595
2722
|
var init_intent_router = __esm({
|
|
2596
2723
|
"src/engine/intent.router.ts"() {
|
|
2597
2724
|
init_handler_sensors_decorator();
|
|
@@ -2611,7 +2738,9 @@ var init_intent_router = __esm({
|
|
|
2611
2738
|
init_cce_pipeline();
|
|
2612
2739
|
init_axis_error();
|
|
2613
2740
|
init_constants();
|
|
2614
|
-
|
|
2741
|
+
init_intent_builtins();
|
|
2742
|
+
init_intent_proof_policy();
|
|
2743
|
+
IntentRouter = class _IntentRouter {
|
|
2615
2744
|
constructor(dependencyResolver, observerDispatcher, sensorRegistry) {
|
|
2616
2745
|
this.logger = createAxisLogger(_IntentRouter.name);
|
|
2617
2746
|
this.decoder = new TextDecoder();
|
|
@@ -2642,12 +2771,6 @@ var init_intent_router = __esm({
|
|
|
2642
2771
|
this.intentContracts = /* @__PURE__ */ new Map();
|
|
2643
2772
|
/** Per-intent required proof kinds */
|
|
2644
2773
|
this.intentRequiredProof = /* @__PURE__ */ new Map();
|
|
2645
|
-
/** Intents flagged as public (no auth required) */
|
|
2646
|
-
this.publicIntents = /* @__PURE__ */ new Set();
|
|
2647
|
-
/** Intents flagged as anonymous-session accessible */
|
|
2648
|
-
this.anonymousIntents = /* @__PURE__ */ new Set();
|
|
2649
|
-
/** Intents flagged as authorized-session accessible */
|
|
2650
|
-
this.authorizedIntents = /* @__PURE__ */ new Set();
|
|
2651
2774
|
/** Per-intent rate limit config */
|
|
2652
2775
|
this.intentRateLimits = /* @__PURE__ */ new Map();
|
|
2653
2776
|
/** CCE handler registry */
|
|
@@ -2678,10 +2801,10 @@ var init_intent_router = __esm({
|
|
|
2678
2801
|
}
|
|
2679
2802
|
has(intent) {
|
|
2680
2803
|
const resolved = this.resolveIntentAlias(intent);
|
|
2681
|
-
return this.handlers.has(resolved) ||
|
|
2804
|
+
return this.handlers.has(resolved) || isBuiltinIntent(resolved);
|
|
2682
2805
|
}
|
|
2683
2806
|
getRegisteredIntents() {
|
|
2684
|
-
return [...
|
|
2807
|
+
return [...BUILTIN_INTENTS, ...this.handlers.keys()];
|
|
2685
2808
|
}
|
|
2686
2809
|
getIntentEntry(intent) {
|
|
2687
2810
|
const resolved = this.resolveIntentAlias(intent);
|
|
@@ -2690,7 +2813,7 @@ var init_intent_router = __esm({
|
|
|
2690
2813
|
schema: this.intentSchemas.get(resolved),
|
|
2691
2814
|
validators: this.intentValidators.get(resolved),
|
|
2692
2815
|
hasSensors: this.intentSensors.has(resolved),
|
|
2693
|
-
builtin:
|
|
2816
|
+
builtin: isBuiltinIntent(resolved),
|
|
2694
2817
|
kind: this.intentKinds.get(resolved),
|
|
2695
2818
|
chain: this.intentChains.get(resolved),
|
|
2696
2819
|
capsulePolicy: this.intentCapsulePolicies.get(resolved),
|
|
@@ -2712,6 +2835,9 @@ var init_intent_router = __esm({
|
|
|
2712
2835
|
* @param {any} handler - The handler function or object
|
|
2713
2836
|
*/
|
|
2714
2837
|
register(intent, handler) {
|
|
2838
|
+
if (this.handlers.has(intent)) {
|
|
2839
|
+
this.logger.warn(`Intent ${intent} is already registered; replacing handler`);
|
|
2840
|
+
}
|
|
2715
2841
|
this.handlers.set(intent, handler);
|
|
2716
2842
|
if (typeof handler === "function" && handler.name) {
|
|
2717
2843
|
this.intentHandlerRefs.set(intent, handler.name);
|
|
@@ -2822,128 +2948,7 @@ var init_intent_router = __esm({
|
|
|
2822
2948
|
frame
|
|
2823
2949
|
});
|
|
2824
2950
|
let effect;
|
|
2825
|
-
|
|
2826
|
-
this.logger.debug("PING received");
|
|
2827
|
-
effect = {
|
|
2828
|
-
ok: true,
|
|
2829
|
-
effect: "pong",
|
|
2830
|
-
headers: /* @__PURE__ */ new Map([
|
|
2831
|
-
[100, new TextEncoder().encode("AXIS_BACKEND_V1")]
|
|
2832
|
-
]),
|
|
2833
|
-
body: new TextEncoder().encode(
|
|
2834
|
-
JSON.stringify({
|
|
2835
|
-
status: "ok",
|
|
2836
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2837
|
-
version: "1.0.0"
|
|
2838
|
-
})
|
|
2839
|
-
)
|
|
2840
|
-
};
|
|
2841
|
-
} else if (intent === "system.time") {
|
|
2842
|
-
const ts = Date.now().toString();
|
|
2843
|
-
effect = {
|
|
2844
|
-
ok: true,
|
|
2845
|
-
effect: "time",
|
|
2846
|
-
body: new TextEncoder().encode(
|
|
2847
|
-
JSON.stringify({
|
|
2848
|
-
ts,
|
|
2849
|
-
iso: (/* @__PURE__ */ new Date()).toISOString()
|
|
2850
|
-
})
|
|
2851
|
-
)
|
|
2852
|
-
};
|
|
2853
|
-
} else if (intent === "system.echo") {
|
|
2854
|
-
effect = {
|
|
2855
|
-
ok: true,
|
|
2856
|
-
effect: "echo",
|
|
2857
|
-
body: frame.body
|
|
2858
|
-
};
|
|
2859
|
-
} else if (intent === "CHAIN.EXEC" || intent === "axis.chain.exec") {
|
|
2860
|
-
const chainRequest = this.parseChainRequestBody(frame.body);
|
|
2861
|
-
effect = await this.executeChainRequest(frame, chainRequest);
|
|
2862
|
-
} else if (intent === "INTENT.EXEC" || intent === "axis.intent.exec") {
|
|
2863
|
-
const execBody = this.parseIntentExecBody(frame.body);
|
|
2864
|
-
const innerIntent = execBody.intent;
|
|
2865
|
-
const innerArgs = execBody.args || {};
|
|
2866
|
-
if (!innerIntent) {
|
|
2867
|
-
throw new Error("INTENT.EXEC missing inner intent");
|
|
2868
|
-
}
|
|
2869
|
-
this.logger.debug(`EXEC: routing to inner intent '${innerIntent}'`);
|
|
2870
|
-
const innerHeaders = new Map(frame.headers);
|
|
2871
|
-
innerHeaders.set(TLV_INTENT, this.encoder.encode(innerIntent));
|
|
2872
|
-
const inlineCapsule = this.toInlineCapsuleRecord(execBody.capsule);
|
|
2873
|
-
const capsuleId = this.extractInlineCapsuleId(inlineCapsule);
|
|
2874
|
-
if (capsuleId) {
|
|
2875
|
-
innerHeaders.set(TLV_CAPSULE, this.encoder.encode(capsuleId));
|
|
2876
|
-
innerHeaders.set(TLV_PROOF_REF, this.encoder.encode(capsuleId));
|
|
2877
|
-
}
|
|
2878
|
-
const innerFrame = withAxisExecutionContext(
|
|
2879
|
-
{
|
|
2880
|
-
...frame,
|
|
2881
|
-
headers: innerHeaders,
|
|
2882
|
-
body: this.encodeJson(innerArgs)
|
|
2883
|
-
},
|
|
2884
|
-
mergeAxisExecutionContext(getAxisExecutionContext(frame), {
|
|
2885
|
-
metaIntent: "INTENT.EXEC",
|
|
2886
|
-
actorId: this.getActorIdFromFrame(frame),
|
|
2887
|
-
inlineCapsule
|
|
2888
|
-
}) || {}
|
|
2889
|
-
);
|
|
2890
|
-
effect = await this.route(innerFrame);
|
|
2891
|
-
} else {
|
|
2892
|
-
const handler = this.handlers.get(intent);
|
|
2893
|
-
if (!handler) {
|
|
2894
|
-
throw new Error(`Intent not found: ${intent}`);
|
|
2895
|
-
}
|
|
2896
|
-
const sensorBindings = this.intentSensors.get(intent);
|
|
2897
|
-
if (sensorBindings && sensorBindings.length > 0) {
|
|
2898
|
-
await this.runIntentSensors(sensorBindings, intent, frame, "before");
|
|
2899
|
-
}
|
|
2900
|
-
const decoder = this.intentDecoders.get(intent);
|
|
2901
|
-
let decodedBody = frame.body;
|
|
2902
|
-
if (decoder) {
|
|
2903
|
-
try {
|
|
2904
|
-
decodedBody = decoder(Buffer.from(frame.body));
|
|
2905
|
-
} catch (decodeErr) {
|
|
2906
|
-
throw new Error(
|
|
2907
|
-
`IntentBody decode failed for ${intent}: ${decodeErr.message}`
|
|
2908
|
-
);
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
this.enforceCapsulePolicy(
|
|
2912
|
-
intent,
|
|
2913
|
-
frame,
|
|
2914
|
-
decodedBody,
|
|
2915
|
-
this.getEffectiveCapsulePolicy(intent, frame)
|
|
2916
|
-
);
|
|
2917
|
-
if (typeof handler === "function") {
|
|
2918
|
-
const resultBody = decoder ? await handler(decodedBody, frame.headers) : await handler(frame.body, frame.headers);
|
|
2919
|
-
effect = {
|
|
2920
|
-
ok: true,
|
|
2921
|
-
effect: "complete",
|
|
2922
|
-
body: resultBody
|
|
2923
|
-
};
|
|
2924
|
-
} else {
|
|
2925
|
-
if (typeof handler.handle === "function") {
|
|
2926
|
-
effect = await handler.handle(frame);
|
|
2927
|
-
} else if (typeof handler.execute === "function") {
|
|
2928
|
-
const bodyRes = decoder ? await handler.execute(decodedBody, frame.headers) : await handler.execute(frame.body, frame.headers);
|
|
2929
|
-
effect = {
|
|
2930
|
-
ok: true,
|
|
2931
|
-
effect: "complete",
|
|
2932
|
-
body: bodyRes
|
|
2933
|
-
};
|
|
2934
|
-
} else {
|
|
2935
|
-
throw new Error(
|
|
2936
|
-
`Handler for ${intent} does not implement handle or execute`
|
|
2937
|
-
);
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
if (sensorBindings && sensorBindings.length > 0) {
|
|
2941
|
-
await this.runIntentSensors(sensorBindings, intent, frame, "after", {
|
|
2942
|
-
decodedBody,
|
|
2943
|
-
effect
|
|
2944
|
-
});
|
|
2945
|
-
}
|
|
2946
|
-
}
|
|
2951
|
+
effect = await this.routeResolvedIntent(intent, frame);
|
|
2947
2952
|
await this.emitIntentObservers(observerBindings, {
|
|
2948
2953
|
event: "intent.completed",
|
|
2949
2954
|
timestamp: Date.now(),
|
|
@@ -2968,6 +2973,134 @@ var init_intent_router = __esm({
|
|
|
2968
2973
|
throw e;
|
|
2969
2974
|
}
|
|
2970
2975
|
}
|
|
2976
|
+
/**
|
|
2977
|
+
* Dispatches a resolved canonical intent to the correct execution path.
|
|
2978
|
+
* This keeps route() focused on observer/error lifecycle concerns.
|
|
2979
|
+
*/
|
|
2980
|
+
async routeResolvedIntent(intent, frame) {
|
|
2981
|
+
const builtinEffect = routeSystemBuiltinIntent(
|
|
2982
|
+
intent,
|
|
2983
|
+
frame.body,
|
|
2984
|
+
this.encoder
|
|
2985
|
+
);
|
|
2986
|
+
if (builtinEffect) {
|
|
2987
|
+
if (intent === "system.ping" || intent === "public.ping") {
|
|
2988
|
+
this.logger.debug("PING received");
|
|
2989
|
+
}
|
|
2990
|
+
return builtinEffect;
|
|
2991
|
+
}
|
|
2992
|
+
if (isChainExecIntent(intent)) {
|
|
2993
|
+
const chainRequest = this.parseChainRequestBody(frame.body);
|
|
2994
|
+
return this.executeChainRequest(frame, chainRequest);
|
|
2995
|
+
}
|
|
2996
|
+
if (isIntentExecIntent(intent)) {
|
|
2997
|
+
return this.routeIntentExec(frame);
|
|
2998
|
+
}
|
|
2999
|
+
return this.routeRegisteredIntent(intent, frame);
|
|
3000
|
+
}
|
|
3001
|
+
/**
|
|
3002
|
+
* Handles INTENT.EXEC by building an inner frame and routing it normally.
|
|
3003
|
+
* The recursive route call is intentional so sensors/observers/policies for
|
|
3004
|
+
* the inner intent stay identical to a direct request.
|
|
3005
|
+
*/
|
|
3006
|
+
async routeIntentExec(frame) {
|
|
3007
|
+
const execBody = this.parseIntentExecBody(frame.body);
|
|
3008
|
+
const innerIntent = execBody.intent;
|
|
3009
|
+
const innerArgs = execBody.args || {};
|
|
3010
|
+
if (!innerIntent) {
|
|
3011
|
+
throw new Error("INTENT.EXEC missing inner intent");
|
|
3012
|
+
}
|
|
3013
|
+
this.logger.debug(`EXEC: routing to inner intent '${innerIntent}'`);
|
|
3014
|
+
const innerHeaders = new Map(frame.headers);
|
|
3015
|
+
innerHeaders.set(TLV_INTENT, this.encoder.encode(innerIntent));
|
|
3016
|
+
const inlineCapsule = this.toInlineCapsuleRecord(execBody.capsule);
|
|
3017
|
+
const capsuleId = this.extractInlineCapsuleId(inlineCapsule);
|
|
3018
|
+
if (capsuleId) {
|
|
3019
|
+
innerHeaders.set(TLV_CAPSULE, this.encoder.encode(capsuleId));
|
|
3020
|
+
innerHeaders.set(TLV_PROOF_REF, this.encoder.encode(capsuleId));
|
|
3021
|
+
}
|
|
3022
|
+
const innerFrame = withAxisExecutionContext(
|
|
3023
|
+
{
|
|
3024
|
+
...frame,
|
|
3025
|
+
headers: innerHeaders,
|
|
3026
|
+
body: this.encodeJson(innerArgs)
|
|
3027
|
+
},
|
|
3028
|
+
mergeAxisExecutionContext(getAxisExecutionContext(frame), {
|
|
3029
|
+
metaIntent: "INTENT.EXEC",
|
|
3030
|
+
actorId: this.getActorIdFromFrame(frame),
|
|
3031
|
+
inlineCapsule
|
|
3032
|
+
}) || {}
|
|
3033
|
+
);
|
|
3034
|
+
return this.route(innerFrame);
|
|
3035
|
+
}
|
|
3036
|
+
/**
|
|
3037
|
+
* Executes an app-registered intent: before sensors, body decode, capsule
|
|
3038
|
+
* policy, handler invocation, then after sensors.
|
|
3039
|
+
*/
|
|
3040
|
+
async routeRegisteredIntent(intent, frame) {
|
|
3041
|
+
const handler = this.handlers.get(intent);
|
|
3042
|
+
if (!handler) {
|
|
3043
|
+
throw new Error(`Intent not found: ${intent}`);
|
|
3044
|
+
}
|
|
3045
|
+
const sensorBindings = this.intentSensors.get(intent);
|
|
3046
|
+
if (sensorBindings && sensorBindings.length > 0) {
|
|
3047
|
+
await this.runIntentSensors(sensorBindings, intent, frame, "before");
|
|
3048
|
+
}
|
|
3049
|
+
const decoder = this.intentDecoders.get(intent);
|
|
3050
|
+
const decodedBody = this.decodeIntentBody(intent, frame, decoder);
|
|
3051
|
+
this.enforceCapsulePolicy(
|
|
3052
|
+
intent,
|
|
3053
|
+
frame,
|
|
3054
|
+
decodedBody,
|
|
3055
|
+
this.getEffectiveCapsulePolicy(intent, frame)
|
|
3056
|
+
);
|
|
3057
|
+
const effect = await this.invokeRegisteredHandler(
|
|
3058
|
+
intent,
|
|
3059
|
+
handler,
|
|
3060
|
+
frame,
|
|
3061
|
+
decoder,
|
|
3062
|
+
decodedBody
|
|
3063
|
+
);
|
|
3064
|
+
if (sensorBindings && sensorBindings.length > 0) {
|
|
3065
|
+
await this.runIntentSensors(sensorBindings, intent, frame, "after", {
|
|
3066
|
+
decodedBody,
|
|
3067
|
+
effect
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
return effect;
|
|
3071
|
+
}
|
|
3072
|
+
decodeIntentBody(intent, frame, decoder) {
|
|
3073
|
+
if (!decoder) return frame.body;
|
|
3074
|
+
try {
|
|
3075
|
+
return decoder(Buffer.from(frame.body));
|
|
3076
|
+
} catch (decodeErr) {
|
|
3077
|
+
throw new Error(
|
|
3078
|
+
`IntentBody decode failed for ${intent}: ${decodeErr.message}`
|
|
3079
|
+
);
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
async invokeRegisteredHandler(intent, handler, frame, decoder, decodedBody) {
|
|
3083
|
+
if (typeof handler === "function") {
|
|
3084
|
+
const resultBody = decoder ? await handler(decodedBody, frame.headers) : await handler(frame.body, frame.headers);
|
|
3085
|
+
return {
|
|
3086
|
+
ok: true,
|
|
3087
|
+
effect: "complete",
|
|
3088
|
+
body: resultBody
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3091
|
+
if (typeof handler.handle === "function") {
|
|
3092
|
+
return handler.handle(frame);
|
|
3093
|
+
}
|
|
3094
|
+
if (typeof handler.execute === "function") {
|
|
3095
|
+
const bodyRes = decoder ? await handler.execute(decodedBody, frame.headers) : await handler.execute(frame.body, frame.headers);
|
|
3096
|
+
return {
|
|
3097
|
+
ok: true,
|
|
3098
|
+
effect: "complete",
|
|
3099
|
+
body: bodyRes
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
throw new Error(`Handler for ${intent} does not implement handle or execute`);
|
|
3103
|
+
}
|
|
2971
3104
|
logIntent(intent, start, ok, error) {
|
|
2972
3105
|
const diff = process.hrtime(start);
|
|
2973
3106
|
const ms = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(2);
|
|
@@ -3061,54 +3194,9 @@ var init_intent_router = __esm({
|
|
|
3061
3194
|
if (contract) {
|
|
3062
3195
|
this.intentContracts.set(intent, contract);
|
|
3063
3196
|
}
|
|
3064
|
-
const
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
methodName
|
|
3068
|
-
);
|
|
3069
|
-
const classProof = Reflect.getMetadata(
|
|
3070
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
3071
|
-
proto.constructor
|
|
3072
|
-
);
|
|
3073
|
-
const requiredProof = methodProof ?? classProof;
|
|
3074
|
-
if (requiredProof && requiredProof.length > 0) {
|
|
3075
|
-
this.intentRequiredProof.set(intent, requiredProof);
|
|
3076
|
-
}
|
|
3077
|
-
const isPublicMethod = Reflect.getMetadata(
|
|
3078
|
-
AXIS_PUBLIC_KEY,
|
|
3079
|
-
proto,
|
|
3080
|
-
methodName
|
|
3081
|
-
);
|
|
3082
|
-
const isPublicClass = Reflect.getMetadata(
|
|
3083
|
-
AXIS_PUBLIC_KEY,
|
|
3084
|
-
proto.constructor
|
|
3085
|
-
);
|
|
3086
|
-
if (isPublicMethod || isPublicClass) {
|
|
3087
|
-
this.publicIntents.add(intent);
|
|
3088
|
-
}
|
|
3089
|
-
const isAnonMethod = Reflect.getMetadata(
|
|
3090
|
-
AXIS_ANONYMOUS_KEY,
|
|
3091
|
-
proto,
|
|
3092
|
-
methodName
|
|
3093
|
-
);
|
|
3094
|
-
const isAnonClass = Reflect.getMetadata(
|
|
3095
|
-
AXIS_ANONYMOUS_KEY,
|
|
3096
|
-
proto.constructor
|
|
3097
|
-
);
|
|
3098
|
-
if (isAnonMethod || isAnonClass) {
|
|
3099
|
-
this.anonymousIntents.add(intent);
|
|
3100
|
-
}
|
|
3101
|
-
const isAuthorizedMethod = Reflect.getMetadata(
|
|
3102
|
-
AXIS_AUTHORIZED_KEY,
|
|
3103
|
-
proto,
|
|
3104
|
-
methodName
|
|
3105
|
-
);
|
|
3106
|
-
const isAuthorizedClass = Reflect.getMetadata(
|
|
3107
|
-
AXIS_AUTHORIZED_KEY,
|
|
3108
|
-
proto.constructor
|
|
3109
|
-
);
|
|
3110
|
-
if (isAuthorizedMethod || isAuthorizedClass) {
|
|
3111
|
-
this.authorizedIntents.add(intent);
|
|
3197
|
+
const proofPolicy = resolveIntentProofPolicy(proto, methodName);
|
|
3198
|
+
if (proofPolicy.requiredProof.length > 0) {
|
|
3199
|
+
this.intentRequiredProof.set(intent, proofPolicy.requiredProof);
|
|
3112
3200
|
}
|
|
3113
3201
|
const rateLimit = Reflect.getMetadata(
|
|
3114
3202
|
AXIS_RATE_LIMIT_KEY,
|
|
@@ -3130,13 +3218,13 @@ var init_intent_router = __esm({
|
|
|
3130
3218
|
return this.intentRequiredProof.get(this.resolveIntentAlias(intent));
|
|
3131
3219
|
}
|
|
3132
3220
|
isPublic(intent) {
|
|
3133
|
-
return this.
|
|
3221
|
+
return this.getRequiredProof(intent)?.includes("NONE") ?? false;
|
|
3134
3222
|
}
|
|
3135
3223
|
isAnonymous(intent) {
|
|
3136
|
-
return this.
|
|
3224
|
+
return this.getRequiredProof(intent)?.includes("ANONYMOUS") ?? false;
|
|
3137
3225
|
}
|
|
3138
3226
|
isAuthorized(intent) {
|
|
3139
|
-
return this.
|
|
3227
|
+
return this.getRequiredProof(intent)?.includes("AUTHORIZED") ?? false;
|
|
3140
3228
|
}
|
|
3141
3229
|
getRateLimit(intent) {
|
|
3142
3230
|
return this.intentRateLimits.get(this.resolveIntentAlias(intent));
|
|
@@ -3157,7 +3245,7 @@ var init_intent_router = __esm({
|
|
|
3157
3245
|
}
|
|
3158
3246
|
/** The system/builtin intents (ping, time, echo, chain, intent.exec). */
|
|
3159
3247
|
getSystemIntents() {
|
|
3160
|
-
return [...
|
|
3248
|
+
return [...BUILTIN_INTENTS];
|
|
3161
3249
|
}
|
|
3162
3250
|
/** True if every intent in the handler is public, or any one is public — returns true if ANY intent is @AxisPublic. */
|
|
3163
3251
|
isHandlerPublic(handlerName) {
|
|
@@ -3230,7 +3318,7 @@ var init_intent_router = __esm({
|
|
|
3230
3318
|
* canonical intent. Existing exact intent names always win.
|
|
3231
3319
|
*/
|
|
3232
3320
|
resolveIntentAlias(intent) {
|
|
3233
|
-
if (this.handlers.has(intent) ||
|
|
3321
|
+
if (this.handlers.has(intent) || isBuiltinIntent(intent)) {
|
|
3234
3322
|
return intent;
|
|
3235
3323
|
}
|
|
3236
3324
|
const separator = "...";
|
|
@@ -3754,18 +3842,6 @@ var init_intent_router = __esm({
|
|
|
3754
3842
|
this.intentSchemas.set(meta.intent, schema);
|
|
3755
3843
|
}
|
|
3756
3844
|
};
|
|
3757
|
-
/** Intents handled inline in route() — not in `handlers` map */
|
|
3758
|
-
_IntentRouter.BUILTIN_INTENTS = /* @__PURE__ */ new Set([
|
|
3759
|
-
"system.ping",
|
|
3760
|
-
"public.ping",
|
|
3761
|
-
"system.time",
|
|
3762
|
-
"system.echo",
|
|
3763
|
-
"CHAIN.EXEC",
|
|
3764
|
-
"axis.chain.exec",
|
|
3765
|
-
"INTENT.EXEC",
|
|
3766
|
-
"axis.intent.exec"
|
|
3767
|
-
]);
|
|
3768
|
-
IntentRouter = _IntentRouter;
|
|
3769
3845
|
}
|
|
3770
3846
|
});
|
|
3771
3847
|
|