@nextera.one/axis-server-sdk 2.3.12 → 2.3.14
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_6djkZB.d.ts → index-B0HcQRif.d.ts} +5 -4
- package/dist/{index-DZdmfbDZ.d.mts → index-C5NXMEth.d.mts} +5 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +294 -220
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +294 -221
- 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 +294 -220
- package/dist/sensors/index.js.map +1 -1
- package/dist/sensors/index.mjs +294 -221
- package/dist/sensors/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/sensors/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { n as AccessProfileResolverSensor, $ as BodyBudgetSensor, a2 as CapabilityEnforcementSensor, a7 as ChunkHashSensor, aa as EntropySensor, ac as ExecutionTimeoutSensor, ae as FrameBudgetSensor, af as FrameHeaderSanitySensor, ag as HeaderTLVLimitSensor, ak as IntentAllowlistSensor, an as IntentRegistrySensor, ap as LawArticlePresenceMode, aq as LawArticlePresenceSensor, ar as LawArticlePresenceSensorOptions, as as LawEvaluationSensor, ay as ProofPresenceSensor, az as ProtocolStrictSensor, aB as ReceiptPolicySensor, aG as RiskGateSensor, aH as RiskGateSensorOptions, aJ as RiskSignalCollector, aL as SchemaValidationSensor, aN as StreamScopeSensor, aO as TLVParseSensor, aR as TickAuthCapsuleRef, aS as TickAuthSensor, aT as TickAuthSensorOptions, aU as TickAuthVerifier, b3 as TpsSensor, b4 as TpsSensorOptions, b5 as VarintHardeningSensor } from '../index-
|
|
1
|
+
export { n as AccessProfileResolverSensor, $ as BodyBudgetSensor, a2 as CapabilityEnforcementSensor, a7 as ChunkHashSensor, aa as EntropySensor, ac as ExecutionTimeoutSensor, ae as FrameBudgetSensor, af as FrameHeaderSanitySensor, ag as HeaderTLVLimitSensor, ak as IntentAllowlistSensor, an as IntentRegistrySensor, ap as LawArticlePresenceMode, aq as LawArticlePresenceSensor, ar as LawArticlePresenceSensorOptions, as as LawEvaluationSensor, ay as ProofPresenceSensor, az as ProtocolStrictSensor, aB as ReceiptPolicySensor, aG as RiskGateSensor, aH as RiskGateSensorOptions, aJ as RiskSignalCollector, aL as SchemaValidationSensor, aN as StreamScopeSensor, aO as TLVParseSensor, aR as TickAuthCapsuleRef, aS as TickAuthSensor, aT as TickAuthSensorOptions, aU as TickAuthVerifier, b3 as TpsSensor, b4 as TpsSensorOptions, b5 as VarintHardeningSensor } from '../index-C5NXMEth.mjs';
|
|
2
2
|
import '../axis-sensor-BLUemDiZ.mjs';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '@nextera.one/axis-protocol';
|
package/dist/sensors/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { n as AccessProfileResolverSensor, $ as BodyBudgetSensor, a2 as CapabilityEnforcementSensor, a7 as ChunkHashSensor, aa as EntropySensor, ac as ExecutionTimeoutSensor, ae as FrameBudgetSensor, af as FrameHeaderSanitySensor, ag as HeaderTLVLimitSensor, ak as IntentAllowlistSensor, an as IntentRegistrySensor, ap as LawArticlePresenceMode, aq as LawArticlePresenceSensor, ar as LawArticlePresenceSensorOptions, as as LawEvaluationSensor, ay as ProofPresenceSensor, az as ProtocolStrictSensor, aB as ReceiptPolicySensor, aG as RiskGateSensor, aH as RiskGateSensorOptions, aJ as RiskSignalCollector, aL as SchemaValidationSensor, aN as StreamScopeSensor, aO as TLVParseSensor, aR as TickAuthCapsuleRef, aS as TickAuthSensor, aT as TickAuthSensorOptions, aU as TickAuthVerifier, b3 as TpsSensor, b4 as TpsSensorOptions, b5 as VarintHardeningSensor } from '../index-
|
|
1
|
+
export { n as AccessProfileResolverSensor, $ as BodyBudgetSensor, a2 as CapabilityEnforcementSensor, a7 as ChunkHashSensor, aa as EntropySensor, ac as ExecutionTimeoutSensor, ae as FrameBudgetSensor, af as FrameHeaderSanitySensor, ag as HeaderTLVLimitSensor, ak as IntentAllowlistSensor, an as IntentRegistrySensor, ap as LawArticlePresenceMode, aq as LawArticlePresenceSensor, ar as LawArticlePresenceSensorOptions, as as LawEvaluationSensor, ay as ProofPresenceSensor, az as ProtocolStrictSensor, aB as ReceiptPolicySensor, aG as RiskGateSensor, aH as RiskGateSensorOptions, aJ as RiskSignalCollector, aL as SchemaValidationSensor, aN as StreamScopeSensor, aO as TLVParseSensor, aR as TickAuthCapsuleRef, aS as TickAuthSensor, aT as TickAuthSensorOptions, aU as TickAuthVerifier, b3 as TpsSensor, b4 as TpsSensorOptions, b5 as VarintHardeningSensor } from '../index-B0HcQRif.js';
|
|
2
2
|
import '../axis-sensor-BLUemDiZ.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
import '@nextera.one/axis-protocol';
|
package/dist/sensors/index.js
CHANGED
|
@@ -2438,20 +2438,70 @@ var init_axis_error = __esm({
|
|
|
2438
2438
|
}
|
|
2439
2439
|
});
|
|
2440
2440
|
|
|
2441
|
-
// src/engine/intent.
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
IntentRouter: () => IntentRouter
|
|
2445
|
-
});
|
|
2446
|
-
function observerRefKey(ref) {
|
|
2447
|
-
return typeof ref === "string" ? ref : ref.name;
|
|
2441
|
+
// src/engine/intent-builtins.ts
|
|
2442
|
+
function isBuiltinIntent(intent) {
|
|
2443
|
+
return BUILTIN_INTENTS.has(intent);
|
|
2448
2444
|
}
|
|
2449
|
-
function
|
|
2450
|
-
return
|
|
2445
|
+
function isChainExecIntent(intent) {
|
|
2446
|
+
return intent === "CHAIN.EXEC" || intent === "axis.chain.exec";
|
|
2451
2447
|
}
|
|
2452
|
-
function
|
|
2453
|
-
return
|
|
2448
|
+
function isIntentExecIntent(intent) {
|
|
2449
|
+
return intent === "INTENT.EXEC" || intent === "axis.intent.exec";
|
|
2454
2450
|
}
|
|
2451
|
+
function routeSystemBuiltinIntent(intent, body, encoder) {
|
|
2452
|
+
if (intent === "system.ping" || intent === "public.ping") {
|
|
2453
|
+
return {
|
|
2454
|
+
ok: true,
|
|
2455
|
+
effect: "pong",
|
|
2456
|
+
headers: /* @__PURE__ */ new Map([[100, encoder.encode("AXIS_BACKEND_V1")]]),
|
|
2457
|
+
body: encoder.encode(
|
|
2458
|
+
JSON.stringify({
|
|
2459
|
+
status: "ok",
|
|
2460
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2461
|
+
version: "1.0.0"
|
|
2462
|
+
})
|
|
2463
|
+
)
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
if (intent === "system.time") {
|
|
2467
|
+
const ts = Date.now().toString();
|
|
2468
|
+
return {
|
|
2469
|
+
ok: true,
|
|
2470
|
+
effect: "time",
|
|
2471
|
+
body: encoder.encode(
|
|
2472
|
+
JSON.stringify({
|
|
2473
|
+
ts,
|
|
2474
|
+
iso: (/* @__PURE__ */ new Date()).toISOString()
|
|
2475
|
+
})
|
|
2476
|
+
)
|
|
2477
|
+
};
|
|
2478
|
+
}
|
|
2479
|
+
if (intent === "system.echo") {
|
|
2480
|
+
return {
|
|
2481
|
+
ok: true,
|
|
2482
|
+
effect: "echo",
|
|
2483
|
+
body
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
return void 0;
|
|
2487
|
+
}
|
|
2488
|
+
var BUILTIN_INTENTS;
|
|
2489
|
+
var init_intent_builtins = __esm({
|
|
2490
|
+
"src/engine/intent-builtins.ts"() {
|
|
2491
|
+
BUILTIN_INTENTS = /* @__PURE__ */ new Set([
|
|
2492
|
+
"system.ping",
|
|
2493
|
+
"public.ping",
|
|
2494
|
+
"system.time",
|
|
2495
|
+
"system.echo",
|
|
2496
|
+
"CHAIN.EXEC",
|
|
2497
|
+
"axis.chain.exec",
|
|
2498
|
+
"INTENT.EXEC",
|
|
2499
|
+
"axis.intent.exec"
|
|
2500
|
+
]);
|
|
2501
|
+
}
|
|
2502
|
+
});
|
|
2503
|
+
|
|
2504
|
+
// src/engine/intent-proof-policy.ts
|
|
2455
2505
|
function mergeProofKinds(...proofGroups) {
|
|
2456
2506
|
const merged = /* @__PURE__ */ new Set();
|
|
2457
2507
|
for (const proofs of proofGroups) {
|
|
@@ -2468,6 +2518,81 @@ function accessProofKinds(isPublic, isAnonymous, isAuthorized) {
|
|
|
2468
2518
|
if (isAuthorized) proofs.push("AUTHORIZED");
|
|
2469
2519
|
return proofs;
|
|
2470
2520
|
}
|
|
2521
|
+
function resolveIntentProofPolicy(proto, methodName) {
|
|
2522
|
+
const methodProof = Reflect.getMetadata(
|
|
2523
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
2524
|
+
proto,
|
|
2525
|
+
methodName
|
|
2526
|
+
);
|
|
2527
|
+
const classProof = Reflect.getMetadata(
|
|
2528
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
2529
|
+
proto.constructor
|
|
2530
|
+
);
|
|
2531
|
+
const isPublicMethod = Reflect.getMetadata(
|
|
2532
|
+
AXIS_PUBLIC_KEY,
|
|
2533
|
+
proto,
|
|
2534
|
+
methodName
|
|
2535
|
+
);
|
|
2536
|
+
const isPublicClass = Reflect.getMetadata(
|
|
2537
|
+
AXIS_PUBLIC_KEY,
|
|
2538
|
+
proto.constructor
|
|
2539
|
+
);
|
|
2540
|
+
const isAnonymousMethod = Reflect.getMetadata(
|
|
2541
|
+
AXIS_ANONYMOUS_KEY,
|
|
2542
|
+
proto,
|
|
2543
|
+
methodName
|
|
2544
|
+
);
|
|
2545
|
+
const isAnonymousClass = Reflect.getMetadata(
|
|
2546
|
+
AXIS_ANONYMOUS_KEY,
|
|
2547
|
+
proto.constructor
|
|
2548
|
+
);
|
|
2549
|
+
const isAuthorizedMethod = Reflect.getMetadata(
|
|
2550
|
+
AXIS_AUTHORIZED_KEY,
|
|
2551
|
+
proto,
|
|
2552
|
+
methodName
|
|
2553
|
+
);
|
|
2554
|
+
const isAuthorizedClass = Reflect.getMetadata(
|
|
2555
|
+
AXIS_AUTHORIZED_KEY,
|
|
2556
|
+
proto.constructor
|
|
2557
|
+
);
|
|
2558
|
+
const methodPolicyProof = mergeProofKinds(
|
|
2559
|
+
methodProof,
|
|
2560
|
+
accessProofKinds(isPublicMethod, isAnonymousMethod, isAuthorizedMethod)
|
|
2561
|
+
);
|
|
2562
|
+
const classPolicyProof = mergeProofKinds(
|
|
2563
|
+
classProof,
|
|
2564
|
+
accessProofKinds(isPublicClass, isAnonymousClass, isAuthorizedClass)
|
|
2565
|
+
);
|
|
2566
|
+
const requiredProof = methodPolicyProof.length ? methodPolicyProof : classPolicyProof;
|
|
2567
|
+
return {
|
|
2568
|
+
requiredProof,
|
|
2569
|
+
isPublic: requiredProof.includes("NONE"),
|
|
2570
|
+
isAnonymous: requiredProof.includes("ANONYMOUS"),
|
|
2571
|
+
isAuthorized: requiredProof.includes("AUTHORIZED")
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
var import_reflect_metadata12;
|
|
2575
|
+
var init_intent_proof_policy = __esm({
|
|
2576
|
+
"src/engine/intent-proof-policy.ts"() {
|
|
2577
|
+
import_reflect_metadata12 = require("reflect-metadata");
|
|
2578
|
+
init_intent_policy_decorator();
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2581
|
+
|
|
2582
|
+
// src/engine/intent.router.ts
|
|
2583
|
+
var intent_router_exports = {};
|
|
2584
|
+
__export(intent_router_exports, {
|
|
2585
|
+
IntentRouter: () => IntentRouter
|
|
2586
|
+
});
|
|
2587
|
+
function observerRefKey(ref) {
|
|
2588
|
+
return typeof ref === "string" ? ref : ref.name;
|
|
2589
|
+
}
|
|
2590
|
+
function sensorRefKey(ref) {
|
|
2591
|
+
return typeof ref === "string" ? ref : ref.name;
|
|
2592
|
+
}
|
|
2593
|
+
function sensorBindingKey(binding) {
|
|
2594
|
+
return `${binding.when}:${sensorRefKey(binding.ref)}`;
|
|
2595
|
+
}
|
|
2471
2596
|
function mergeIntentSensorBindings(...sensorGroups) {
|
|
2472
2597
|
const merged = /* @__PURE__ */ new Map();
|
|
2473
2598
|
for (const group of sensorGroups) {
|
|
@@ -2523,7 +2648,7 @@ function normalizeChainConfig(decoratorConfig, intentConfig) {
|
|
|
2523
2648
|
...intentConfig
|
|
2524
2649
|
};
|
|
2525
2650
|
}
|
|
2526
|
-
var import_axis_protocol4, import_dto_schema,
|
|
2651
|
+
var import_axis_protocol4, import_dto_schema, IntentRouter;
|
|
2527
2652
|
var init_intent_router = __esm({
|
|
2528
2653
|
"src/engine/intent.router.ts"() {
|
|
2529
2654
|
import_axis_protocol4 = require("@nextera.one/axis-protocol");
|
|
@@ -2544,7 +2669,9 @@ var init_intent_router = __esm({
|
|
|
2544
2669
|
init_cce_pipeline();
|
|
2545
2670
|
init_axis_error();
|
|
2546
2671
|
init_constants();
|
|
2547
|
-
|
|
2672
|
+
init_intent_builtins();
|
|
2673
|
+
init_intent_proof_policy();
|
|
2674
|
+
IntentRouter = class _IntentRouter {
|
|
2548
2675
|
constructor(dependencyResolver, observerDispatcher, sensorRegistry) {
|
|
2549
2676
|
this.logger = createAxisLogger(_IntentRouter.name);
|
|
2550
2677
|
this.decoder = new TextDecoder();
|
|
@@ -2575,12 +2702,6 @@ var init_intent_router = __esm({
|
|
|
2575
2702
|
this.intentContracts = /* @__PURE__ */ new Map();
|
|
2576
2703
|
/** Per-intent required proof kinds */
|
|
2577
2704
|
this.intentRequiredProof = /* @__PURE__ */ new Map();
|
|
2578
|
-
/** Intents flagged as public (no auth required) */
|
|
2579
|
-
this.publicIntents = /* @__PURE__ */ new Set();
|
|
2580
|
-
/** Intents flagged as anonymous-session accessible */
|
|
2581
|
-
this.anonymousIntents = /* @__PURE__ */ new Set();
|
|
2582
|
-
/** Intents flagged as authorized-session accessible */
|
|
2583
|
-
this.authorizedIntents = /* @__PURE__ */ new Set();
|
|
2584
2705
|
/** Per-intent rate limit config */
|
|
2585
2706
|
this.intentRateLimits = /* @__PURE__ */ new Map();
|
|
2586
2707
|
/** CCE handler registry */
|
|
@@ -2611,10 +2732,10 @@ var init_intent_router = __esm({
|
|
|
2611
2732
|
}
|
|
2612
2733
|
has(intent) {
|
|
2613
2734
|
const resolved = this.resolveIntentAlias(intent);
|
|
2614
|
-
return this.handlers.has(resolved) ||
|
|
2735
|
+
return this.handlers.has(resolved) || isBuiltinIntent(resolved);
|
|
2615
2736
|
}
|
|
2616
2737
|
getRegisteredIntents() {
|
|
2617
|
-
return [...
|
|
2738
|
+
return [...BUILTIN_INTENTS, ...this.handlers.keys()];
|
|
2618
2739
|
}
|
|
2619
2740
|
getIntentEntry(intent) {
|
|
2620
2741
|
const resolved = this.resolveIntentAlias(intent);
|
|
@@ -2623,7 +2744,7 @@ var init_intent_router = __esm({
|
|
|
2623
2744
|
schema: this.intentSchemas.get(resolved),
|
|
2624
2745
|
validators: this.intentValidators.get(resolved),
|
|
2625
2746
|
hasSensors: this.intentSensors.has(resolved),
|
|
2626
|
-
builtin:
|
|
2747
|
+
builtin: isBuiltinIntent(resolved),
|
|
2627
2748
|
kind: this.intentKinds.get(resolved),
|
|
2628
2749
|
chain: this.intentChains.get(resolved),
|
|
2629
2750
|
capsulePolicy: this.intentCapsulePolicies.get(resolved),
|
|
@@ -2645,6 +2766,9 @@ var init_intent_router = __esm({
|
|
|
2645
2766
|
* @param {any} handler - The handler function or object
|
|
2646
2767
|
*/
|
|
2647
2768
|
register(intent, handler) {
|
|
2769
|
+
if (this.handlers.has(intent)) {
|
|
2770
|
+
this.logger.warn(`Intent ${intent} is already registered; replacing handler`);
|
|
2771
|
+
}
|
|
2648
2772
|
this.handlers.set(intent, handler);
|
|
2649
2773
|
if (typeof handler === "function" && handler.name) {
|
|
2650
2774
|
this.intentHandlerRefs.set(intent, handler.name);
|
|
@@ -2729,9 +2853,14 @@ var init_intent_router = __esm({
|
|
|
2729
2853
|
* Routes a decoded AXIS frame to the appropriate handler.
|
|
2730
2854
|
*
|
|
2731
2855
|
* **Precedence:**
|
|
2732
|
-
* 1.
|
|
2733
|
-
* 2.
|
|
2734
|
-
* 3.
|
|
2856
|
+
* 1. SDK meta-intents (`CHAIN.EXEC`, `INTENT.EXEC`)
|
|
2857
|
+
* 2. Dynamically registered handlers from modules
|
|
2858
|
+
* 3. Simple SDK built-in fallback (`system.ping`, `public.ping`, `system.time`, `system.echo`)
|
|
2859
|
+
*
|
|
2860
|
+
* Registered app handlers intentionally win over simple built-ins. This lets
|
|
2861
|
+
* applications attach sensors, rate limits, and custom responses to intents
|
|
2862
|
+
* like `system.ping` while keeping a default fallback for apps that do not
|
|
2863
|
+
* register their own handler.
|
|
2735
2864
|
*
|
|
2736
2865
|
* @param {AxisFrame} frame - The validated and decoded binary frame
|
|
2737
2866
|
* @returns {Promise<AxisEffect>} The resulting effect of the execution
|
|
@@ -2755,128 +2884,7 @@ var init_intent_router = __esm({
|
|
|
2755
2884
|
frame
|
|
2756
2885
|
});
|
|
2757
2886
|
let effect;
|
|
2758
|
-
|
|
2759
|
-
this.logger.debug("PING received");
|
|
2760
|
-
effect = {
|
|
2761
|
-
ok: true,
|
|
2762
|
-
effect: "pong",
|
|
2763
|
-
headers: /* @__PURE__ */ new Map([
|
|
2764
|
-
[100, new TextEncoder().encode("AXIS_BACKEND_V1")]
|
|
2765
|
-
]),
|
|
2766
|
-
body: new TextEncoder().encode(
|
|
2767
|
-
JSON.stringify({
|
|
2768
|
-
status: "ok",
|
|
2769
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2770
|
-
version: "1.0.0"
|
|
2771
|
-
})
|
|
2772
|
-
)
|
|
2773
|
-
};
|
|
2774
|
-
} else if (intent === "system.time") {
|
|
2775
|
-
const ts = Date.now().toString();
|
|
2776
|
-
effect = {
|
|
2777
|
-
ok: true,
|
|
2778
|
-
effect: "time",
|
|
2779
|
-
body: new TextEncoder().encode(
|
|
2780
|
-
JSON.stringify({
|
|
2781
|
-
ts,
|
|
2782
|
-
iso: (/* @__PURE__ */ new Date()).toISOString()
|
|
2783
|
-
})
|
|
2784
|
-
)
|
|
2785
|
-
};
|
|
2786
|
-
} else if (intent === "system.echo") {
|
|
2787
|
-
effect = {
|
|
2788
|
-
ok: true,
|
|
2789
|
-
effect: "echo",
|
|
2790
|
-
body: frame.body
|
|
2791
|
-
};
|
|
2792
|
-
} else if (intent === "CHAIN.EXEC" || intent === "axis.chain.exec") {
|
|
2793
|
-
const chainRequest = this.parseChainRequestBody(frame.body);
|
|
2794
|
-
effect = await this.executeChainRequest(frame, chainRequest);
|
|
2795
|
-
} else if (intent === "INTENT.EXEC" || intent === "axis.intent.exec") {
|
|
2796
|
-
const execBody = this.parseIntentExecBody(frame.body);
|
|
2797
|
-
const innerIntent = execBody.intent;
|
|
2798
|
-
const innerArgs = execBody.args || {};
|
|
2799
|
-
if (!innerIntent) {
|
|
2800
|
-
throw new Error("INTENT.EXEC missing inner intent");
|
|
2801
|
-
}
|
|
2802
|
-
this.logger.debug(`EXEC: routing to inner intent '${innerIntent}'`);
|
|
2803
|
-
const innerHeaders = new Map(frame.headers);
|
|
2804
|
-
innerHeaders.set(import_axis_protocol.TLV_INTENT, this.encoder.encode(innerIntent));
|
|
2805
|
-
const inlineCapsule = this.toInlineCapsuleRecord(execBody.capsule);
|
|
2806
|
-
const capsuleId = this.extractInlineCapsuleId(inlineCapsule);
|
|
2807
|
-
if (capsuleId) {
|
|
2808
|
-
innerHeaders.set(import_axis_protocol.TLV_CAPSULE, this.encoder.encode(capsuleId));
|
|
2809
|
-
innerHeaders.set(import_axis_protocol.TLV_PROOF_REF, this.encoder.encode(capsuleId));
|
|
2810
|
-
}
|
|
2811
|
-
const innerFrame = withAxisExecutionContext(
|
|
2812
|
-
{
|
|
2813
|
-
...frame,
|
|
2814
|
-
headers: innerHeaders,
|
|
2815
|
-
body: this.encodeJson(innerArgs)
|
|
2816
|
-
},
|
|
2817
|
-
mergeAxisExecutionContext(getAxisExecutionContext(frame), {
|
|
2818
|
-
metaIntent: "INTENT.EXEC",
|
|
2819
|
-
actorId: this.getActorIdFromFrame(frame),
|
|
2820
|
-
inlineCapsule
|
|
2821
|
-
}) || {}
|
|
2822
|
-
);
|
|
2823
|
-
effect = await this.route(innerFrame);
|
|
2824
|
-
} else {
|
|
2825
|
-
const handler = this.handlers.get(intent);
|
|
2826
|
-
if (!handler) {
|
|
2827
|
-
throw new Error(`Intent not found: ${intent}`);
|
|
2828
|
-
}
|
|
2829
|
-
const sensorBindings = this.intentSensors.get(intent);
|
|
2830
|
-
if (sensorBindings && sensorBindings.length > 0) {
|
|
2831
|
-
await this.runIntentSensors(sensorBindings, intent, frame, "before");
|
|
2832
|
-
}
|
|
2833
|
-
const decoder = this.intentDecoders.get(intent);
|
|
2834
|
-
let decodedBody = frame.body;
|
|
2835
|
-
if (decoder) {
|
|
2836
|
-
try {
|
|
2837
|
-
decodedBody = decoder(Buffer.from(frame.body));
|
|
2838
|
-
} catch (decodeErr) {
|
|
2839
|
-
throw new Error(
|
|
2840
|
-
`IntentBody decode failed for ${intent}: ${decodeErr.message}`
|
|
2841
|
-
);
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
this.enforceCapsulePolicy(
|
|
2845
|
-
intent,
|
|
2846
|
-
frame,
|
|
2847
|
-
decodedBody,
|
|
2848
|
-
this.getEffectiveCapsulePolicy(intent, frame)
|
|
2849
|
-
);
|
|
2850
|
-
if (typeof handler === "function") {
|
|
2851
|
-
const resultBody = decoder ? await handler(decodedBody, frame.headers) : await handler(frame.body, frame.headers);
|
|
2852
|
-
effect = {
|
|
2853
|
-
ok: true,
|
|
2854
|
-
effect: "complete",
|
|
2855
|
-
body: resultBody
|
|
2856
|
-
};
|
|
2857
|
-
} else {
|
|
2858
|
-
if (typeof handler.handle === "function") {
|
|
2859
|
-
effect = await handler.handle(frame);
|
|
2860
|
-
} else if (typeof handler.execute === "function") {
|
|
2861
|
-
const bodyRes = decoder ? await handler.execute(decodedBody, frame.headers) : await handler.execute(frame.body, frame.headers);
|
|
2862
|
-
effect = {
|
|
2863
|
-
ok: true,
|
|
2864
|
-
effect: "complete",
|
|
2865
|
-
body: bodyRes
|
|
2866
|
-
};
|
|
2867
|
-
} else {
|
|
2868
|
-
throw new Error(
|
|
2869
|
-
`Handler for ${intent} does not implement handle or execute`
|
|
2870
|
-
);
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
if (sensorBindings && sensorBindings.length > 0) {
|
|
2874
|
-
await this.runIntentSensors(sensorBindings, intent, frame, "after", {
|
|
2875
|
-
decodedBody,
|
|
2876
|
-
effect
|
|
2877
|
-
});
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2887
|
+
effect = await this.routeResolvedIntent(intent, frame);
|
|
2880
2888
|
await this.emitIntentObservers(observerBindings, {
|
|
2881
2889
|
event: "intent.completed",
|
|
2882
2890
|
timestamp: Date.now(),
|
|
@@ -2901,6 +2909,137 @@ var init_intent_router = __esm({
|
|
|
2901
2909
|
throw e;
|
|
2902
2910
|
}
|
|
2903
2911
|
}
|
|
2912
|
+
/**
|
|
2913
|
+
* Dispatches a resolved canonical intent to the correct execution path.
|
|
2914
|
+
* This keeps route() focused on observer/error lifecycle concerns.
|
|
2915
|
+
*/
|
|
2916
|
+
async routeResolvedIntent(intent, frame) {
|
|
2917
|
+
if (isChainExecIntent(intent)) {
|
|
2918
|
+
const chainRequest = this.parseChainRequestBody(frame.body);
|
|
2919
|
+
return this.executeChainRequest(frame, chainRequest);
|
|
2920
|
+
}
|
|
2921
|
+
if (isIntentExecIntent(intent)) {
|
|
2922
|
+
return this.routeIntentExec(frame);
|
|
2923
|
+
}
|
|
2924
|
+
if (this.handlers.has(intent)) {
|
|
2925
|
+
return this.routeRegisteredIntent(intent, frame);
|
|
2926
|
+
}
|
|
2927
|
+
const builtinEffect = routeSystemBuiltinIntent(
|
|
2928
|
+
intent,
|
|
2929
|
+
frame.body,
|
|
2930
|
+
this.encoder
|
|
2931
|
+
);
|
|
2932
|
+
if (builtinEffect) {
|
|
2933
|
+
if (intent === "system.ping" || intent === "public.ping") {
|
|
2934
|
+
this.logger.debug("PING received");
|
|
2935
|
+
}
|
|
2936
|
+
return builtinEffect;
|
|
2937
|
+
}
|
|
2938
|
+
return this.routeRegisteredIntent(intent, frame);
|
|
2939
|
+
}
|
|
2940
|
+
/**
|
|
2941
|
+
* Handles INTENT.EXEC by building an inner frame and routing it normally.
|
|
2942
|
+
* The recursive route call is intentional so sensors/observers/policies for
|
|
2943
|
+
* the inner intent stay identical to a direct request.
|
|
2944
|
+
*/
|
|
2945
|
+
async routeIntentExec(frame) {
|
|
2946
|
+
const execBody = this.parseIntentExecBody(frame.body);
|
|
2947
|
+
const innerIntent = execBody.intent;
|
|
2948
|
+
const innerArgs = execBody.args || {};
|
|
2949
|
+
if (!innerIntent) {
|
|
2950
|
+
throw new Error("INTENT.EXEC missing inner intent");
|
|
2951
|
+
}
|
|
2952
|
+
this.logger.debug(`EXEC: routing to inner intent '${innerIntent}'`);
|
|
2953
|
+
const innerHeaders = new Map(frame.headers);
|
|
2954
|
+
innerHeaders.set(import_axis_protocol.TLV_INTENT, this.encoder.encode(innerIntent));
|
|
2955
|
+
const inlineCapsule = this.toInlineCapsuleRecord(execBody.capsule);
|
|
2956
|
+
const capsuleId = this.extractInlineCapsuleId(inlineCapsule);
|
|
2957
|
+
if (capsuleId) {
|
|
2958
|
+
innerHeaders.set(import_axis_protocol.TLV_CAPSULE, this.encoder.encode(capsuleId));
|
|
2959
|
+
innerHeaders.set(import_axis_protocol.TLV_PROOF_REF, this.encoder.encode(capsuleId));
|
|
2960
|
+
}
|
|
2961
|
+
const innerFrame = withAxisExecutionContext(
|
|
2962
|
+
{
|
|
2963
|
+
...frame,
|
|
2964
|
+
headers: innerHeaders,
|
|
2965
|
+
body: this.encodeJson(innerArgs)
|
|
2966
|
+
},
|
|
2967
|
+
mergeAxisExecutionContext(getAxisExecutionContext(frame), {
|
|
2968
|
+
metaIntent: "INTENT.EXEC",
|
|
2969
|
+
actorId: this.getActorIdFromFrame(frame),
|
|
2970
|
+
inlineCapsule
|
|
2971
|
+
}) || {}
|
|
2972
|
+
);
|
|
2973
|
+
return this.route(innerFrame);
|
|
2974
|
+
}
|
|
2975
|
+
/**
|
|
2976
|
+
* Executes an app-registered intent: before sensors, body decode, capsule
|
|
2977
|
+
* policy, handler invocation, then after sensors.
|
|
2978
|
+
*/
|
|
2979
|
+
async routeRegisteredIntent(intent, frame) {
|
|
2980
|
+
const handler = this.handlers.get(intent);
|
|
2981
|
+
if (!handler) {
|
|
2982
|
+
throw new Error(`Intent not found: ${intent}`);
|
|
2983
|
+
}
|
|
2984
|
+
const sensorBindings = this.intentSensors.get(intent);
|
|
2985
|
+
if (sensorBindings && sensorBindings.length > 0) {
|
|
2986
|
+
await this.runIntentSensors(sensorBindings, intent, frame, "before");
|
|
2987
|
+
}
|
|
2988
|
+
const decoder = this.intentDecoders.get(intent);
|
|
2989
|
+
const decodedBody = this.decodeIntentBody(intent, frame, decoder);
|
|
2990
|
+
this.enforceCapsulePolicy(
|
|
2991
|
+
intent,
|
|
2992
|
+
frame,
|
|
2993
|
+
decodedBody,
|
|
2994
|
+
this.getEffectiveCapsulePolicy(intent, frame)
|
|
2995
|
+
);
|
|
2996
|
+
const effect = await this.invokeRegisteredHandler(
|
|
2997
|
+
intent,
|
|
2998
|
+
handler,
|
|
2999
|
+
frame,
|
|
3000
|
+
decoder,
|
|
3001
|
+
decodedBody
|
|
3002
|
+
);
|
|
3003
|
+
if (sensorBindings && sensorBindings.length > 0) {
|
|
3004
|
+
await this.runIntentSensors(sensorBindings, intent, frame, "after", {
|
|
3005
|
+
decodedBody,
|
|
3006
|
+
effect
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
return effect;
|
|
3010
|
+
}
|
|
3011
|
+
decodeIntentBody(intent, frame, decoder) {
|
|
3012
|
+
if (!decoder) return frame.body;
|
|
3013
|
+
try {
|
|
3014
|
+
return decoder(Buffer.from(frame.body));
|
|
3015
|
+
} catch (decodeErr) {
|
|
3016
|
+
throw new Error(
|
|
3017
|
+
`IntentBody decode failed for ${intent}: ${decodeErr.message}`
|
|
3018
|
+
);
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
async invokeRegisteredHandler(intent, handler, frame, decoder, decodedBody) {
|
|
3022
|
+
if (typeof handler === "function") {
|
|
3023
|
+
const resultBody = decoder ? await handler(decodedBody, frame.headers) : await handler(frame.body, frame.headers);
|
|
3024
|
+
return {
|
|
3025
|
+
ok: true,
|
|
3026
|
+
effect: "complete",
|
|
3027
|
+
body: resultBody
|
|
3028
|
+
};
|
|
3029
|
+
}
|
|
3030
|
+
if (typeof handler.handle === "function") {
|
|
3031
|
+
return handler.handle(frame);
|
|
3032
|
+
}
|
|
3033
|
+
if (typeof handler.execute === "function") {
|
|
3034
|
+
const bodyRes = decoder ? await handler.execute(decodedBody, frame.headers) : await handler.execute(frame.body, frame.headers);
|
|
3035
|
+
return {
|
|
3036
|
+
ok: true,
|
|
3037
|
+
effect: "complete",
|
|
3038
|
+
body: bodyRes
|
|
3039
|
+
};
|
|
3040
|
+
}
|
|
3041
|
+
throw new Error(`Handler for ${intent} does not implement handle or execute`);
|
|
3042
|
+
}
|
|
2904
3043
|
logIntent(intent, start, ok, error) {
|
|
2905
3044
|
const diff = process.hrtime(start);
|
|
2906
3045
|
const ms = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(2);
|
|
@@ -2994,62 +3133,9 @@ var init_intent_router = __esm({
|
|
|
2994
3133
|
if (contract) {
|
|
2995
3134
|
this.intentContracts.set(intent, contract);
|
|
2996
3135
|
}
|
|
2997
|
-
const
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
methodName
|
|
3001
|
-
);
|
|
3002
|
-
const classProof = Reflect.getMetadata(
|
|
3003
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
3004
|
-
proto.constructor
|
|
3005
|
-
);
|
|
3006
|
-
const isPublicMethod = Reflect.getMetadata(
|
|
3007
|
-
AXIS_PUBLIC_KEY,
|
|
3008
|
-
proto,
|
|
3009
|
-
methodName
|
|
3010
|
-
);
|
|
3011
|
-
const isPublicClass = Reflect.getMetadata(
|
|
3012
|
-
AXIS_PUBLIC_KEY,
|
|
3013
|
-
proto.constructor
|
|
3014
|
-
);
|
|
3015
|
-
const isAnonMethod = Reflect.getMetadata(
|
|
3016
|
-
AXIS_ANONYMOUS_KEY,
|
|
3017
|
-
proto,
|
|
3018
|
-
methodName
|
|
3019
|
-
);
|
|
3020
|
-
const isAnonClass = Reflect.getMetadata(
|
|
3021
|
-
AXIS_ANONYMOUS_KEY,
|
|
3022
|
-
proto.constructor
|
|
3023
|
-
);
|
|
3024
|
-
const isAuthorizedMethod = Reflect.getMetadata(
|
|
3025
|
-
AXIS_AUTHORIZED_KEY,
|
|
3026
|
-
proto,
|
|
3027
|
-
methodName
|
|
3028
|
-
);
|
|
3029
|
-
const isAuthorizedClass = Reflect.getMetadata(
|
|
3030
|
-
AXIS_AUTHORIZED_KEY,
|
|
3031
|
-
proto.constructor
|
|
3032
|
-
);
|
|
3033
|
-
const methodPolicyProof = mergeProofKinds(
|
|
3034
|
-
methodProof,
|
|
3035
|
-
accessProofKinds(isPublicMethod, isAnonMethod, isAuthorizedMethod)
|
|
3036
|
-
);
|
|
3037
|
-
const classPolicyProof = mergeProofKinds(
|
|
3038
|
-
classProof,
|
|
3039
|
-
accessProofKinds(isPublicClass, isAnonClass, isAuthorizedClass)
|
|
3040
|
-
);
|
|
3041
|
-
const requiredProof = methodPolicyProof.length ? methodPolicyProof : classPolicyProof;
|
|
3042
|
-
if (requiredProof.length > 0) {
|
|
3043
|
-
this.intentRequiredProof.set(intent, requiredProof);
|
|
3044
|
-
}
|
|
3045
|
-
if (requiredProof.includes("NONE")) {
|
|
3046
|
-
this.publicIntents.add(intent);
|
|
3047
|
-
}
|
|
3048
|
-
if (requiredProof.includes("ANONYMOUS")) {
|
|
3049
|
-
this.anonymousIntents.add(intent);
|
|
3050
|
-
}
|
|
3051
|
-
if (requiredProof.includes("AUTHORIZED")) {
|
|
3052
|
-
this.authorizedIntents.add(intent);
|
|
3136
|
+
const proofPolicy = resolveIntentProofPolicy(proto, methodName);
|
|
3137
|
+
if (proofPolicy.requiredProof.length > 0) {
|
|
3138
|
+
this.intentRequiredProof.set(intent, proofPolicy.requiredProof);
|
|
3053
3139
|
}
|
|
3054
3140
|
const rateLimit = Reflect.getMetadata(
|
|
3055
3141
|
AXIS_RATE_LIMIT_KEY,
|
|
@@ -3071,13 +3157,13 @@ var init_intent_router = __esm({
|
|
|
3071
3157
|
return this.intentRequiredProof.get(this.resolveIntentAlias(intent));
|
|
3072
3158
|
}
|
|
3073
3159
|
isPublic(intent) {
|
|
3074
|
-
return this.
|
|
3160
|
+
return this.getRequiredProof(intent)?.includes("NONE") ?? false;
|
|
3075
3161
|
}
|
|
3076
3162
|
isAnonymous(intent) {
|
|
3077
|
-
return this.
|
|
3163
|
+
return this.getRequiredProof(intent)?.includes("ANONYMOUS") ?? false;
|
|
3078
3164
|
}
|
|
3079
3165
|
isAuthorized(intent) {
|
|
3080
|
-
return this.
|
|
3166
|
+
return this.getRequiredProof(intent)?.includes("AUTHORIZED") ?? false;
|
|
3081
3167
|
}
|
|
3082
3168
|
getRateLimit(intent) {
|
|
3083
3169
|
return this.intentRateLimits.get(this.resolveIntentAlias(intent));
|
|
@@ -3098,7 +3184,7 @@ var init_intent_router = __esm({
|
|
|
3098
3184
|
}
|
|
3099
3185
|
/** The system/builtin intents (ping, time, echo, chain, intent.exec). */
|
|
3100
3186
|
getSystemIntents() {
|
|
3101
|
-
return [...
|
|
3187
|
+
return [...BUILTIN_INTENTS];
|
|
3102
3188
|
}
|
|
3103
3189
|
/** True if every intent in the handler is public, or any one is public — returns true if ANY intent is @AxisPublic. */
|
|
3104
3190
|
isHandlerPublic(handlerName) {
|
|
@@ -3171,7 +3257,7 @@ var init_intent_router = __esm({
|
|
|
3171
3257
|
* canonical intent. Existing exact intent names always win.
|
|
3172
3258
|
*/
|
|
3173
3259
|
resolveIntentAlias(intent) {
|
|
3174
|
-
if (this.handlers.has(intent) ||
|
|
3260
|
+
if (this.handlers.has(intent) || isBuiltinIntent(intent)) {
|
|
3175
3261
|
return intent;
|
|
3176
3262
|
}
|
|
3177
3263
|
const separator = "...";
|
|
@@ -3695,18 +3781,6 @@ var init_intent_router = __esm({
|
|
|
3695
3781
|
this.intentSchemas.set(meta.intent, schema);
|
|
3696
3782
|
}
|
|
3697
3783
|
};
|
|
3698
|
-
/** Intents handled inline in route() — not in `handlers` map */
|
|
3699
|
-
_IntentRouter.BUILTIN_INTENTS = /* @__PURE__ */ new Set([
|
|
3700
|
-
"system.ping",
|
|
3701
|
-
"public.ping",
|
|
3702
|
-
"system.time",
|
|
3703
|
-
"system.echo",
|
|
3704
|
-
"CHAIN.EXEC",
|
|
3705
|
-
"axis.chain.exec",
|
|
3706
|
-
"INTENT.EXEC",
|
|
3707
|
-
"axis.intent.exec"
|
|
3708
|
-
]);
|
|
3709
|
-
IntentRouter = _IntentRouter;
|
|
3710
3784
|
}
|
|
3711
3785
|
});
|
|
3712
3786
|
|