@nextera.one/axis-server-sdk 2.3.12 → 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-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 +283 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +283 -218
- 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 +283 -217
- package/dist/sensors/index.js.map +1 -1
- package/dist/sensors/index.mjs +283 -218
- package/dist/sensors/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2364,21 +2364,71 @@ var init_axis_error = __esm({
|
|
|
2364
2364
|
}
|
|
2365
2365
|
});
|
|
2366
2366
|
|
|
2367
|
-
// src/engine/intent.
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
IntentRouter: () => IntentRouter
|
|
2371
|
-
});
|
|
2372
|
-
import { decodeChainEnvelope, decodeChainRequest } from "@nextera.one/axis-protocol";
|
|
2373
|
-
function observerRefKey(ref) {
|
|
2374
|
-
return typeof ref === "string" ? ref : ref.name;
|
|
2367
|
+
// src/engine/intent-builtins.ts
|
|
2368
|
+
function isBuiltinIntent(intent) {
|
|
2369
|
+
return BUILTIN_INTENTS.has(intent);
|
|
2375
2370
|
}
|
|
2376
|
-
function
|
|
2377
|
-
return
|
|
2371
|
+
function isChainExecIntent(intent) {
|
|
2372
|
+
return intent === "CHAIN.EXEC" || intent === "axis.chain.exec";
|
|
2378
2373
|
}
|
|
2379
|
-
function
|
|
2380
|
-
return
|
|
2374
|
+
function isIntentExecIntent(intent) {
|
|
2375
|
+
return intent === "INTENT.EXEC" || intent === "axis.intent.exec";
|
|
2376
|
+
}
|
|
2377
|
+
function routeSystemBuiltinIntent(intent, body, encoder) {
|
|
2378
|
+
if (intent === "system.ping" || intent === "public.ping") {
|
|
2379
|
+
return {
|
|
2380
|
+
ok: true,
|
|
2381
|
+
effect: "pong",
|
|
2382
|
+
headers: /* @__PURE__ */ new Map([[100, encoder.encode("AXIS_BACKEND_V1")]]),
|
|
2383
|
+
body: encoder.encode(
|
|
2384
|
+
JSON.stringify({
|
|
2385
|
+
status: "ok",
|
|
2386
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2387
|
+
version: "1.0.0"
|
|
2388
|
+
})
|
|
2389
|
+
)
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
if (intent === "system.time") {
|
|
2393
|
+
const ts = Date.now().toString();
|
|
2394
|
+
return {
|
|
2395
|
+
ok: true,
|
|
2396
|
+
effect: "time",
|
|
2397
|
+
body: encoder.encode(
|
|
2398
|
+
JSON.stringify({
|
|
2399
|
+
ts,
|
|
2400
|
+
iso: (/* @__PURE__ */ new Date()).toISOString()
|
|
2401
|
+
})
|
|
2402
|
+
)
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
if (intent === "system.echo") {
|
|
2406
|
+
return {
|
|
2407
|
+
ok: true,
|
|
2408
|
+
effect: "echo",
|
|
2409
|
+
body
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
return void 0;
|
|
2381
2413
|
}
|
|
2414
|
+
var BUILTIN_INTENTS;
|
|
2415
|
+
var init_intent_builtins = __esm({
|
|
2416
|
+
"src/engine/intent-builtins.ts"() {
|
|
2417
|
+
BUILTIN_INTENTS = /* @__PURE__ */ new Set([
|
|
2418
|
+
"system.ping",
|
|
2419
|
+
"public.ping",
|
|
2420
|
+
"system.time",
|
|
2421
|
+
"system.echo",
|
|
2422
|
+
"CHAIN.EXEC",
|
|
2423
|
+
"axis.chain.exec",
|
|
2424
|
+
"INTENT.EXEC",
|
|
2425
|
+
"axis.intent.exec"
|
|
2426
|
+
]);
|
|
2427
|
+
}
|
|
2428
|
+
});
|
|
2429
|
+
|
|
2430
|
+
// src/engine/intent-proof-policy.ts
|
|
2431
|
+
import "reflect-metadata";
|
|
2382
2432
|
function mergeProofKinds(...proofGroups) {
|
|
2383
2433
|
const merged = /* @__PURE__ */ new Set();
|
|
2384
2434
|
for (const proofs of proofGroups) {
|
|
@@ -2395,6 +2445,80 @@ function accessProofKinds(isPublic, isAnonymous, isAuthorized) {
|
|
|
2395
2445
|
if (isAuthorized) proofs.push("AUTHORIZED");
|
|
2396
2446
|
return proofs;
|
|
2397
2447
|
}
|
|
2448
|
+
function resolveIntentProofPolicy(proto, methodName) {
|
|
2449
|
+
const methodProof = Reflect.getMetadata(
|
|
2450
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
2451
|
+
proto,
|
|
2452
|
+
methodName
|
|
2453
|
+
);
|
|
2454
|
+
const classProof = Reflect.getMetadata(
|
|
2455
|
+
REQUIRED_PROOF_METADATA_KEY,
|
|
2456
|
+
proto.constructor
|
|
2457
|
+
);
|
|
2458
|
+
const isPublicMethod = Reflect.getMetadata(
|
|
2459
|
+
AXIS_PUBLIC_KEY,
|
|
2460
|
+
proto,
|
|
2461
|
+
methodName
|
|
2462
|
+
);
|
|
2463
|
+
const isPublicClass = Reflect.getMetadata(
|
|
2464
|
+
AXIS_PUBLIC_KEY,
|
|
2465
|
+
proto.constructor
|
|
2466
|
+
);
|
|
2467
|
+
const isAnonymousMethod = Reflect.getMetadata(
|
|
2468
|
+
AXIS_ANONYMOUS_KEY,
|
|
2469
|
+
proto,
|
|
2470
|
+
methodName
|
|
2471
|
+
);
|
|
2472
|
+
const isAnonymousClass = Reflect.getMetadata(
|
|
2473
|
+
AXIS_ANONYMOUS_KEY,
|
|
2474
|
+
proto.constructor
|
|
2475
|
+
);
|
|
2476
|
+
const isAuthorizedMethod = Reflect.getMetadata(
|
|
2477
|
+
AXIS_AUTHORIZED_KEY,
|
|
2478
|
+
proto,
|
|
2479
|
+
methodName
|
|
2480
|
+
);
|
|
2481
|
+
const isAuthorizedClass = Reflect.getMetadata(
|
|
2482
|
+
AXIS_AUTHORIZED_KEY,
|
|
2483
|
+
proto.constructor
|
|
2484
|
+
);
|
|
2485
|
+
const methodPolicyProof = mergeProofKinds(
|
|
2486
|
+
methodProof,
|
|
2487
|
+
accessProofKinds(isPublicMethod, isAnonymousMethod, isAuthorizedMethod)
|
|
2488
|
+
);
|
|
2489
|
+
const classPolicyProof = mergeProofKinds(
|
|
2490
|
+
classProof,
|
|
2491
|
+
accessProofKinds(isPublicClass, isAnonymousClass, isAuthorizedClass)
|
|
2492
|
+
);
|
|
2493
|
+
const requiredProof = methodPolicyProof.length ? methodPolicyProof : classPolicyProof;
|
|
2494
|
+
return {
|
|
2495
|
+
requiredProof,
|
|
2496
|
+
isPublic: requiredProof.includes("NONE"),
|
|
2497
|
+
isAnonymous: requiredProof.includes("ANONYMOUS"),
|
|
2498
|
+
isAuthorized: requiredProof.includes("AUTHORIZED")
|
|
2499
|
+
};
|
|
2500
|
+
}
|
|
2501
|
+
var init_intent_proof_policy = __esm({
|
|
2502
|
+
"src/engine/intent-proof-policy.ts"() {
|
|
2503
|
+
init_intent_policy_decorator();
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
|
|
2507
|
+
// src/engine/intent.router.ts
|
|
2508
|
+
var intent_router_exports = {};
|
|
2509
|
+
__export(intent_router_exports, {
|
|
2510
|
+
IntentRouter: () => IntentRouter
|
|
2511
|
+
});
|
|
2512
|
+
import { decodeChainEnvelope, decodeChainRequest } from "@nextera.one/axis-protocol";
|
|
2513
|
+
function observerRefKey(ref) {
|
|
2514
|
+
return typeof ref === "string" ? ref : ref.name;
|
|
2515
|
+
}
|
|
2516
|
+
function sensorRefKey(ref) {
|
|
2517
|
+
return typeof ref === "string" ? ref : ref.name;
|
|
2518
|
+
}
|
|
2519
|
+
function sensorBindingKey(binding) {
|
|
2520
|
+
return `${binding.when}:${sensorRefKey(binding.ref)}`;
|
|
2521
|
+
}
|
|
2398
2522
|
function mergeIntentSensorBindings(...sensorGroups) {
|
|
2399
2523
|
const merged = /* @__PURE__ */ new Map();
|
|
2400
2524
|
for (const group of sensorGroups) {
|
|
@@ -2450,7 +2574,7 @@ function normalizeChainConfig(decoratorConfig, intentConfig) {
|
|
|
2450
2574
|
...intentConfig
|
|
2451
2575
|
};
|
|
2452
2576
|
}
|
|
2453
|
-
var import_dto_schema,
|
|
2577
|
+
var import_dto_schema, IntentRouter;
|
|
2454
2578
|
var init_intent_router = __esm({
|
|
2455
2579
|
"src/engine/intent.router.ts"() {
|
|
2456
2580
|
init_handler_sensors_decorator();
|
|
@@ -2470,7 +2594,9 @@ var init_intent_router = __esm({
|
|
|
2470
2594
|
init_cce_pipeline();
|
|
2471
2595
|
init_axis_error();
|
|
2472
2596
|
init_constants();
|
|
2473
|
-
|
|
2597
|
+
init_intent_builtins();
|
|
2598
|
+
init_intent_proof_policy();
|
|
2599
|
+
IntentRouter = class _IntentRouter {
|
|
2474
2600
|
constructor(dependencyResolver, observerDispatcher, sensorRegistry) {
|
|
2475
2601
|
this.logger = createAxisLogger(_IntentRouter.name);
|
|
2476
2602
|
this.decoder = new TextDecoder();
|
|
@@ -2501,12 +2627,6 @@ var init_intent_router = __esm({
|
|
|
2501
2627
|
this.intentContracts = /* @__PURE__ */ new Map();
|
|
2502
2628
|
/** Per-intent required proof kinds */
|
|
2503
2629
|
this.intentRequiredProof = /* @__PURE__ */ new Map();
|
|
2504
|
-
/** Intents flagged as public (no auth required) */
|
|
2505
|
-
this.publicIntents = /* @__PURE__ */ new Set();
|
|
2506
|
-
/** Intents flagged as anonymous-session accessible */
|
|
2507
|
-
this.anonymousIntents = /* @__PURE__ */ new Set();
|
|
2508
|
-
/** Intents flagged as authorized-session accessible */
|
|
2509
|
-
this.authorizedIntents = /* @__PURE__ */ new Set();
|
|
2510
2630
|
/** Per-intent rate limit config */
|
|
2511
2631
|
this.intentRateLimits = /* @__PURE__ */ new Map();
|
|
2512
2632
|
/** CCE handler registry */
|
|
@@ -2537,10 +2657,10 @@ var init_intent_router = __esm({
|
|
|
2537
2657
|
}
|
|
2538
2658
|
has(intent) {
|
|
2539
2659
|
const resolved = this.resolveIntentAlias(intent);
|
|
2540
|
-
return this.handlers.has(resolved) ||
|
|
2660
|
+
return this.handlers.has(resolved) || isBuiltinIntent(resolved);
|
|
2541
2661
|
}
|
|
2542
2662
|
getRegisteredIntents() {
|
|
2543
|
-
return [...
|
|
2663
|
+
return [...BUILTIN_INTENTS, ...this.handlers.keys()];
|
|
2544
2664
|
}
|
|
2545
2665
|
getIntentEntry(intent) {
|
|
2546
2666
|
const resolved = this.resolveIntentAlias(intent);
|
|
@@ -2549,7 +2669,7 @@ var init_intent_router = __esm({
|
|
|
2549
2669
|
schema: this.intentSchemas.get(resolved),
|
|
2550
2670
|
validators: this.intentValidators.get(resolved),
|
|
2551
2671
|
hasSensors: this.intentSensors.has(resolved),
|
|
2552
|
-
builtin:
|
|
2672
|
+
builtin: isBuiltinIntent(resolved),
|
|
2553
2673
|
kind: this.intentKinds.get(resolved),
|
|
2554
2674
|
chain: this.intentChains.get(resolved),
|
|
2555
2675
|
capsulePolicy: this.intentCapsulePolicies.get(resolved),
|
|
@@ -2571,6 +2691,9 @@ var init_intent_router = __esm({
|
|
|
2571
2691
|
* @param {any} handler - The handler function or object
|
|
2572
2692
|
*/
|
|
2573
2693
|
register(intent, handler) {
|
|
2694
|
+
if (this.handlers.has(intent)) {
|
|
2695
|
+
this.logger.warn(`Intent ${intent} is already registered; replacing handler`);
|
|
2696
|
+
}
|
|
2574
2697
|
this.handlers.set(intent, handler);
|
|
2575
2698
|
if (typeof handler === "function" && handler.name) {
|
|
2576
2699
|
this.intentHandlerRefs.set(intent, handler.name);
|
|
@@ -2681,128 +2804,7 @@ var init_intent_router = __esm({
|
|
|
2681
2804
|
frame
|
|
2682
2805
|
});
|
|
2683
2806
|
let effect;
|
|
2684
|
-
|
|
2685
|
-
this.logger.debug("PING received");
|
|
2686
|
-
effect = {
|
|
2687
|
-
ok: true,
|
|
2688
|
-
effect: "pong",
|
|
2689
|
-
headers: /* @__PURE__ */ new Map([
|
|
2690
|
-
[100, new TextEncoder().encode("AXIS_BACKEND_V1")]
|
|
2691
|
-
]),
|
|
2692
|
-
body: new TextEncoder().encode(
|
|
2693
|
-
JSON.stringify({
|
|
2694
|
-
status: "ok",
|
|
2695
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2696
|
-
version: "1.0.0"
|
|
2697
|
-
})
|
|
2698
|
-
)
|
|
2699
|
-
};
|
|
2700
|
-
} else if (intent === "system.time") {
|
|
2701
|
-
const ts = Date.now().toString();
|
|
2702
|
-
effect = {
|
|
2703
|
-
ok: true,
|
|
2704
|
-
effect: "time",
|
|
2705
|
-
body: new TextEncoder().encode(
|
|
2706
|
-
JSON.stringify({
|
|
2707
|
-
ts,
|
|
2708
|
-
iso: (/* @__PURE__ */ new Date()).toISOString()
|
|
2709
|
-
})
|
|
2710
|
-
)
|
|
2711
|
-
};
|
|
2712
|
-
} else if (intent === "system.echo") {
|
|
2713
|
-
effect = {
|
|
2714
|
-
ok: true,
|
|
2715
|
-
effect: "echo",
|
|
2716
|
-
body: frame.body
|
|
2717
|
-
};
|
|
2718
|
-
} else if (intent === "CHAIN.EXEC" || intent === "axis.chain.exec") {
|
|
2719
|
-
const chainRequest = this.parseChainRequestBody(frame.body);
|
|
2720
|
-
effect = await this.executeChainRequest(frame, chainRequest);
|
|
2721
|
-
} else if (intent === "INTENT.EXEC" || intent === "axis.intent.exec") {
|
|
2722
|
-
const execBody = this.parseIntentExecBody(frame.body);
|
|
2723
|
-
const innerIntent = execBody.intent;
|
|
2724
|
-
const innerArgs = execBody.args || {};
|
|
2725
|
-
if (!innerIntent) {
|
|
2726
|
-
throw new Error("INTENT.EXEC missing inner intent");
|
|
2727
|
-
}
|
|
2728
|
-
this.logger.debug(`EXEC: routing to inner intent '${innerIntent}'`);
|
|
2729
|
-
const innerHeaders = new Map(frame.headers);
|
|
2730
|
-
innerHeaders.set(TLV_INTENT, this.encoder.encode(innerIntent));
|
|
2731
|
-
const inlineCapsule = this.toInlineCapsuleRecord(execBody.capsule);
|
|
2732
|
-
const capsuleId = this.extractInlineCapsuleId(inlineCapsule);
|
|
2733
|
-
if (capsuleId) {
|
|
2734
|
-
innerHeaders.set(TLV_CAPSULE, this.encoder.encode(capsuleId));
|
|
2735
|
-
innerHeaders.set(TLV_PROOF_REF, this.encoder.encode(capsuleId));
|
|
2736
|
-
}
|
|
2737
|
-
const innerFrame = withAxisExecutionContext(
|
|
2738
|
-
{
|
|
2739
|
-
...frame,
|
|
2740
|
-
headers: innerHeaders,
|
|
2741
|
-
body: this.encodeJson(innerArgs)
|
|
2742
|
-
},
|
|
2743
|
-
mergeAxisExecutionContext(getAxisExecutionContext(frame), {
|
|
2744
|
-
metaIntent: "INTENT.EXEC",
|
|
2745
|
-
actorId: this.getActorIdFromFrame(frame),
|
|
2746
|
-
inlineCapsule
|
|
2747
|
-
}) || {}
|
|
2748
|
-
);
|
|
2749
|
-
effect = await this.route(innerFrame);
|
|
2750
|
-
} else {
|
|
2751
|
-
const handler = this.handlers.get(intent);
|
|
2752
|
-
if (!handler) {
|
|
2753
|
-
throw new Error(`Intent not found: ${intent}`);
|
|
2754
|
-
}
|
|
2755
|
-
const sensorBindings = this.intentSensors.get(intent);
|
|
2756
|
-
if (sensorBindings && sensorBindings.length > 0) {
|
|
2757
|
-
await this.runIntentSensors(sensorBindings, intent, frame, "before");
|
|
2758
|
-
}
|
|
2759
|
-
const decoder = this.intentDecoders.get(intent);
|
|
2760
|
-
let decodedBody = frame.body;
|
|
2761
|
-
if (decoder) {
|
|
2762
|
-
try {
|
|
2763
|
-
decodedBody = decoder(Buffer.from(frame.body));
|
|
2764
|
-
} catch (decodeErr) {
|
|
2765
|
-
throw new Error(
|
|
2766
|
-
`IntentBody decode failed for ${intent}: ${decodeErr.message}`
|
|
2767
|
-
);
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
this.enforceCapsulePolicy(
|
|
2771
|
-
intent,
|
|
2772
|
-
frame,
|
|
2773
|
-
decodedBody,
|
|
2774
|
-
this.getEffectiveCapsulePolicy(intent, frame)
|
|
2775
|
-
);
|
|
2776
|
-
if (typeof handler === "function") {
|
|
2777
|
-
const resultBody = decoder ? await handler(decodedBody, frame.headers) : await handler(frame.body, frame.headers);
|
|
2778
|
-
effect = {
|
|
2779
|
-
ok: true,
|
|
2780
|
-
effect: "complete",
|
|
2781
|
-
body: resultBody
|
|
2782
|
-
};
|
|
2783
|
-
} else {
|
|
2784
|
-
if (typeof handler.handle === "function") {
|
|
2785
|
-
effect = await handler.handle(frame);
|
|
2786
|
-
} else if (typeof handler.execute === "function") {
|
|
2787
|
-
const bodyRes = decoder ? await handler.execute(decodedBody, frame.headers) : await handler.execute(frame.body, frame.headers);
|
|
2788
|
-
effect = {
|
|
2789
|
-
ok: true,
|
|
2790
|
-
effect: "complete",
|
|
2791
|
-
body: bodyRes
|
|
2792
|
-
};
|
|
2793
|
-
} else {
|
|
2794
|
-
throw new Error(
|
|
2795
|
-
`Handler for ${intent} does not implement handle or execute`
|
|
2796
|
-
);
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
if (sensorBindings && sensorBindings.length > 0) {
|
|
2800
|
-
await this.runIntentSensors(sensorBindings, intent, frame, "after", {
|
|
2801
|
-
decodedBody,
|
|
2802
|
-
effect
|
|
2803
|
-
});
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2807
|
+
effect = await this.routeResolvedIntent(intent, frame);
|
|
2806
2808
|
await this.emitIntentObservers(observerBindings, {
|
|
2807
2809
|
event: "intent.completed",
|
|
2808
2810
|
timestamp: Date.now(),
|
|
@@ -2827,6 +2829,134 @@ var init_intent_router = __esm({
|
|
|
2827
2829
|
throw e;
|
|
2828
2830
|
}
|
|
2829
2831
|
}
|
|
2832
|
+
/**
|
|
2833
|
+
* Dispatches a resolved canonical intent to the correct execution path.
|
|
2834
|
+
* This keeps route() focused on observer/error lifecycle concerns.
|
|
2835
|
+
*/
|
|
2836
|
+
async routeResolvedIntent(intent, frame) {
|
|
2837
|
+
const builtinEffect = routeSystemBuiltinIntent(
|
|
2838
|
+
intent,
|
|
2839
|
+
frame.body,
|
|
2840
|
+
this.encoder
|
|
2841
|
+
);
|
|
2842
|
+
if (builtinEffect) {
|
|
2843
|
+
if (intent === "system.ping" || intent === "public.ping") {
|
|
2844
|
+
this.logger.debug("PING received");
|
|
2845
|
+
}
|
|
2846
|
+
return builtinEffect;
|
|
2847
|
+
}
|
|
2848
|
+
if (isChainExecIntent(intent)) {
|
|
2849
|
+
const chainRequest = this.parseChainRequestBody(frame.body);
|
|
2850
|
+
return this.executeChainRequest(frame, chainRequest);
|
|
2851
|
+
}
|
|
2852
|
+
if (isIntentExecIntent(intent)) {
|
|
2853
|
+
return this.routeIntentExec(frame);
|
|
2854
|
+
}
|
|
2855
|
+
return this.routeRegisteredIntent(intent, frame);
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Handles INTENT.EXEC by building an inner frame and routing it normally.
|
|
2859
|
+
* The recursive route call is intentional so sensors/observers/policies for
|
|
2860
|
+
* the inner intent stay identical to a direct request.
|
|
2861
|
+
*/
|
|
2862
|
+
async routeIntentExec(frame) {
|
|
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
|
+
return this.route(innerFrame);
|
|
2891
|
+
}
|
|
2892
|
+
/**
|
|
2893
|
+
* Executes an app-registered intent: before sensors, body decode, capsule
|
|
2894
|
+
* policy, handler invocation, then after sensors.
|
|
2895
|
+
*/
|
|
2896
|
+
async routeRegisteredIntent(intent, frame) {
|
|
2897
|
+
const handler = this.handlers.get(intent);
|
|
2898
|
+
if (!handler) {
|
|
2899
|
+
throw new Error(`Intent not found: ${intent}`);
|
|
2900
|
+
}
|
|
2901
|
+
const sensorBindings = this.intentSensors.get(intent);
|
|
2902
|
+
if (sensorBindings && sensorBindings.length > 0) {
|
|
2903
|
+
await this.runIntentSensors(sensorBindings, intent, frame, "before");
|
|
2904
|
+
}
|
|
2905
|
+
const decoder = this.intentDecoders.get(intent);
|
|
2906
|
+
const decodedBody = this.decodeIntentBody(intent, frame, decoder);
|
|
2907
|
+
this.enforceCapsulePolicy(
|
|
2908
|
+
intent,
|
|
2909
|
+
frame,
|
|
2910
|
+
decodedBody,
|
|
2911
|
+
this.getEffectiveCapsulePolicy(intent, frame)
|
|
2912
|
+
);
|
|
2913
|
+
const effect = await this.invokeRegisteredHandler(
|
|
2914
|
+
intent,
|
|
2915
|
+
handler,
|
|
2916
|
+
frame,
|
|
2917
|
+
decoder,
|
|
2918
|
+
decodedBody
|
|
2919
|
+
);
|
|
2920
|
+
if (sensorBindings && sensorBindings.length > 0) {
|
|
2921
|
+
await this.runIntentSensors(sensorBindings, intent, frame, "after", {
|
|
2922
|
+
decodedBody,
|
|
2923
|
+
effect
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
return effect;
|
|
2927
|
+
}
|
|
2928
|
+
decodeIntentBody(intent, frame, decoder) {
|
|
2929
|
+
if (!decoder) return frame.body;
|
|
2930
|
+
try {
|
|
2931
|
+
return decoder(Buffer.from(frame.body));
|
|
2932
|
+
} catch (decodeErr) {
|
|
2933
|
+
throw new Error(
|
|
2934
|
+
`IntentBody decode failed for ${intent}: ${decodeErr.message}`
|
|
2935
|
+
);
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
async invokeRegisteredHandler(intent, handler, frame, decoder, decodedBody) {
|
|
2939
|
+
if (typeof handler === "function") {
|
|
2940
|
+
const resultBody = decoder ? await handler(decodedBody, frame.headers) : await handler(frame.body, frame.headers);
|
|
2941
|
+
return {
|
|
2942
|
+
ok: true,
|
|
2943
|
+
effect: "complete",
|
|
2944
|
+
body: resultBody
|
|
2945
|
+
};
|
|
2946
|
+
}
|
|
2947
|
+
if (typeof handler.handle === "function") {
|
|
2948
|
+
return handler.handle(frame);
|
|
2949
|
+
}
|
|
2950
|
+
if (typeof handler.execute === "function") {
|
|
2951
|
+
const bodyRes = decoder ? await handler.execute(decodedBody, frame.headers) : await handler.execute(frame.body, frame.headers);
|
|
2952
|
+
return {
|
|
2953
|
+
ok: true,
|
|
2954
|
+
effect: "complete",
|
|
2955
|
+
body: bodyRes
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
throw new Error(`Handler for ${intent} does not implement handle or execute`);
|
|
2959
|
+
}
|
|
2830
2960
|
logIntent(intent, start, ok, error) {
|
|
2831
2961
|
const diff = process.hrtime(start);
|
|
2832
2962
|
const ms = (diff[0] * 1e3 + diff[1] / 1e6).toFixed(2);
|
|
@@ -2920,62 +3050,9 @@ var init_intent_router = __esm({
|
|
|
2920
3050
|
if (contract) {
|
|
2921
3051
|
this.intentContracts.set(intent, contract);
|
|
2922
3052
|
}
|
|
2923
|
-
const
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
methodName
|
|
2927
|
-
);
|
|
2928
|
-
const classProof = Reflect.getMetadata(
|
|
2929
|
-
REQUIRED_PROOF_METADATA_KEY,
|
|
2930
|
-
proto.constructor
|
|
2931
|
-
);
|
|
2932
|
-
const isPublicMethod = Reflect.getMetadata(
|
|
2933
|
-
AXIS_PUBLIC_KEY,
|
|
2934
|
-
proto,
|
|
2935
|
-
methodName
|
|
2936
|
-
);
|
|
2937
|
-
const isPublicClass = Reflect.getMetadata(
|
|
2938
|
-
AXIS_PUBLIC_KEY,
|
|
2939
|
-
proto.constructor
|
|
2940
|
-
);
|
|
2941
|
-
const isAnonMethod = Reflect.getMetadata(
|
|
2942
|
-
AXIS_ANONYMOUS_KEY,
|
|
2943
|
-
proto,
|
|
2944
|
-
methodName
|
|
2945
|
-
);
|
|
2946
|
-
const isAnonClass = Reflect.getMetadata(
|
|
2947
|
-
AXIS_ANONYMOUS_KEY,
|
|
2948
|
-
proto.constructor
|
|
2949
|
-
);
|
|
2950
|
-
const isAuthorizedMethod = Reflect.getMetadata(
|
|
2951
|
-
AXIS_AUTHORIZED_KEY,
|
|
2952
|
-
proto,
|
|
2953
|
-
methodName
|
|
2954
|
-
);
|
|
2955
|
-
const isAuthorizedClass = Reflect.getMetadata(
|
|
2956
|
-
AXIS_AUTHORIZED_KEY,
|
|
2957
|
-
proto.constructor
|
|
2958
|
-
);
|
|
2959
|
-
const methodPolicyProof = mergeProofKinds(
|
|
2960
|
-
methodProof,
|
|
2961
|
-
accessProofKinds(isPublicMethod, isAnonMethod, isAuthorizedMethod)
|
|
2962
|
-
);
|
|
2963
|
-
const classPolicyProof = mergeProofKinds(
|
|
2964
|
-
classProof,
|
|
2965
|
-
accessProofKinds(isPublicClass, isAnonClass, isAuthorizedClass)
|
|
2966
|
-
);
|
|
2967
|
-
const requiredProof = methodPolicyProof.length ? methodPolicyProof : classPolicyProof;
|
|
2968
|
-
if (requiredProof.length > 0) {
|
|
2969
|
-
this.intentRequiredProof.set(intent, requiredProof);
|
|
2970
|
-
}
|
|
2971
|
-
if (requiredProof.includes("NONE")) {
|
|
2972
|
-
this.publicIntents.add(intent);
|
|
2973
|
-
}
|
|
2974
|
-
if (requiredProof.includes("ANONYMOUS")) {
|
|
2975
|
-
this.anonymousIntents.add(intent);
|
|
2976
|
-
}
|
|
2977
|
-
if (requiredProof.includes("AUTHORIZED")) {
|
|
2978
|
-
this.authorizedIntents.add(intent);
|
|
3053
|
+
const proofPolicy = resolveIntentProofPolicy(proto, methodName);
|
|
3054
|
+
if (proofPolicy.requiredProof.length > 0) {
|
|
3055
|
+
this.intentRequiredProof.set(intent, proofPolicy.requiredProof);
|
|
2979
3056
|
}
|
|
2980
3057
|
const rateLimit = Reflect.getMetadata(
|
|
2981
3058
|
AXIS_RATE_LIMIT_KEY,
|
|
@@ -2997,13 +3074,13 @@ var init_intent_router = __esm({
|
|
|
2997
3074
|
return this.intentRequiredProof.get(this.resolveIntentAlias(intent));
|
|
2998
3075
|
}
|
|
2999
3076
|
isPublic(intent) {
|
|
3000
|
-
return this.
|
|
3077
|
+
return this.getRequiredProof(intent)?.includes("NONE") ?? false;
|
|
3001
3078
|
}
|
|
3002
3079
|
isAnonymous(intent) {
|
|
3003
|
-
return this.
|
|
3080
|
+
return this.getRequiredProof(intent)?.includes("ANONYMOUS") ?? false;
|
|
3004
3081
|
}
|
|
3005
3082
|
isAuthorized(intent) {
|
|
3006
|
-
return this.
|
|
3083
|
+
return this.getRequiredProof(intent)?.includes("AUTHORIZED") ?? false;
|
|
3007
3084
|
}
|
|
3008
3085
|
getRateLimit(intent) {
|
|
3009
3086
|
return this.intentRateLimits.get(this.resolveIntentAlias(intent));
|
|
@@ -3024,7 +3101,7 @@ var init_intent_router = __esm({
|
|
|
3024
3101
|
}
|
|
3025
3102
|
/** The system/builtin intents (ping, time, echo, chain, intent.exec). */
|
|
3026
3103
|
getSystemIntents() {
|
|
3027
|
-
return [...
|
|
3104
|
+
return [...BUILTIN_INTENTS];
|
|
3028
3105
|
}
|
|
3029
3106
|
/** True if every intent in the handler is public, or any one is public — returns true if ANY intent is @AxisPublic. */
|
|
3030
3107
|
isHandlerPublic(handlerName) {
|
|
@@ -3097,7 +3174,7 @@ var init_intent_router = __esm({
|
|
|
3097
3174
|
* canonical intent. Existing exact intent names always win.
|
|
3098
3175
|
*/
|
|
3099
3176
|
resolveIntentAlias(intent) {
|
|
3100
|
-
if (this.handlers.has(intent) ||
|
|
3177
|
+
if (this.handlers.has(intent) || isBuiltinIntent(intent)) {
|
|
3101
3178
|
return intent;
|
|
3102
3179
|
}
|
|
3103
3180
|
const separator = "...";
|
|
@@ -3621,18 +3698,6 @@ var init_intent_router = __esm({
|
|
|
3621
3698
|
this.intentSchemas.set(meta.intent, schema);
|
|
3622
3699
|
}
|
|
3623
3700
|
};
|
|
3624
|
-
/** Intents handled inline in route() — not in `handlers` map */
|
|
3625
|
-
_IntentRouter.BUILTIN_INTENTS = /* @__PURE__ */ new Set([
|
|
3626
|
-
"system.ping",
|
|
3627
|
-
"public.ping",
|
|
3628
|
-
"system.time",
|
|
3629
|
-
"system.echo",
|
|
3630
|
-
"CHAIN.EXEC",
|
|
3631
|
-
"axis.chain.exec",
|
|
3632
|
-
"INTENT.EXEC",
|
|
3633
|
-
"axis.intent.exec"
|
|
3634
|
-
]);
|
|
3635
|
-
IntentRouter = _IntentRouter;
|
|
3636
3701
|
}
|
|
3637
3702
|
});
|
|
3638
3703
|
|