@nextera.one/axis-server-sdk 2.2.4 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1152,6 +1152,7 @@ var init_axis_chain_executor = __esm({
1152
1152
  timestamp: startedAt,
1153
1153
  chainId: envelope.chainId,
1154
1154
  stepId: step.stepId,
1155
+ handler: step.handler,
1155
1156
  intent: step.intent,
1156
1157
  envelope,
1157
1158
  step,
@@ -1186,6 +1187,7 @@ var init_axis_chain_executor = __esm({
1186
1187
  timestamp: finishedAt,
1187
1188
  chainId: envelope.chainId,
1188
1189
  stepId: step.stepId,
1190
+ handler: step.handler,
1189
1191
  intent: step.intent,
1190
1192
  effect,
1191
1193
  envelope,
@@ -1200,6 +1202,7 @@ var init_axis_chain_executor = __esm({
1200
1202
  timestamp: finishedAt,
1201
1203
  chainId: envelope.chainId,
1202
1204
  stepId: step.stepId,
1205
+ handler: step.handler,
1203
1206
  intent: step.intent,
1204
1207
  envelope,
1205
1208
  step,
@@ -1214,6 +1217,7 @@ var init_axis_chain_executor = __esm({
1214
1217
  timestamp: finishedAt,
1215
1218
  chainId: envelope.chainId,
1216
1219
  stepId: step.stepId,
1220
+ handler: step.handler,
1217
1221
  intent: step.intent,
1218
1222
  effect,
1219
1223
  envelope,
@@ -1244,6 +1248,7 @@ var init_axis_chain_executor = __esm({
1244
1248
  timestamp: finishedAt,
1245
1249
  chainId: envelope.chainId,
1246
1250
  stepId: step.stepId,
1251
+ handler: step.handler,
1247
1252
  intent: step.intent,
1248
1253
  error: error.message,
1249
1254
  envelope,
@@ -2462,6 +2467,8 @@ var init_intent_router = __esm({
2462
2467
  this.handlers = /* @__PURE__ */ new Map();
2463
2468
  /** Per-intent sensor refs (resolved through SensorRegistry at call time) */
2464
2469
  this.intentSensors = /* @__PURE__ */ new Map();
2470
+ /** Per-intent handler identifier (e.g. UsersHandler.usersPage) */
2471
+ this.intentHandlerRefs = /* @__PURE__ */ new Map();
2465
2472
  /** Per-intent body decoders */
2466
2473
  this.intentDecoders = /* @__PURE__ */ new Map();
2467
2474
  /** Per-intent TLV schemas */
@@ -2537,6 +2544,16 @@ var init_intent_router = __esm({
2537
2544
  */
2538
2545
  register(intent, handler) {
2539
2546
  this.handlers.set(intent, handler);
2547
+ if (typeof handler === "function" && handler.name) {
2548
+ this.intentHandlerRefs.set(intent, handler.name);
2549
+ } else if (handler && typeof handler === "object") {
2550
+ const objectName = handler.constructor?.name;
2551
+ if (objectName) {
2552
+ this.intentHandlerRefs.set(intent, `${objectName}.handle`);
2553
+ }
2554
+ } else {
2555
+ this.intentHandlerRefs.set(intent, `intent:${intent}`);
2556
+ }
2540
2557
  }
2541
2558
  /**
2542
2559
  * Automatically registers all `@Intent`-decorated methods from a handler instance.
@@ -2567,6 +2584,10 @@ var init_intent_router = __esm({
2567
2584
  } else {
2568
2585
  this.register(intentName, fn);
2569
2586
  }
2587
+ this.intentHandlerRefs.set(
2588
+ intentName,
2589
+ `${instance.constructor.name}.${String(route.methodName)}`
2590
+ );
2570
2591
  this.registerIntentMeta(
2571
2592
  intentName,
2572
2593
  proto,
@@ -2607,15 +2628,18 @@ var init_intent_router = __esm({
2607
2628
  async route(frame) {
2608
2629
  const start = process.hrtime();
2609
2630
  let intent = "unknown";
2631
+ let handlerRef;
2610
2632
  try {
2611
2633
  const intentBytes = frame.headers.get(TLV_INTENT);
2612
2634
  if (!intentBytes) throw new Error("Missing intent");
2613
2635
  intent = this.decoder.decode(intentBytes);
2636
+ handlerRef = this.intentHandlerRefs.get(intent);
2614
2637
  const observerBindings = this.getObservers(intent);
2615
2638
  await this.emitIntentObservers(observerBindings, {
2616
2639
  event: "intent.received",
2617
2640
  timestamp: Date.now(),
2618
2641
  intent,
2642
+ handler: handlerRef,
2619
2643
  frame
2620
2644
  });
2621
2645
  let effect;
@@ -2745,6 +2769,7 @@ var init_intent_router = __esm({
2745
2769
  event: "intent.completed",
2746
2770
  timestamp: Date.now(),
2747
2771
  intent,
2772
+ handler: handlerRef,
2748
2773
  frame,
2749
2774
  effect,
2750
2775
  metadata: effect.metadata
@@ -2756,6 +2781,7 @@ var init_intent_router = __esm({
2756
2781
  event: "intent.failed",
2757
2782
  timestamp: Date.now(),
2758
2783
  intent,
2784
+ handler: handlerRef,
2759
2785
  frame,
2760
2786
  error: e.message
2761
2787
  });
@@ -2922,8 +2948,11 @@ var init_intent_router = __esm({
2922
2948
  return this.intentRateLimits.get(intent);
2923
2949
  }
2924
2950
  async emitIntentObservers(bindings, context) {
2925
- if (!this.observerDispatcher || bindings.length === 0) return;
2926
- await this.observerDispatcher.dispatch(bindings, context);
2951
+ if (!this.observerDispatcher) return;
2952
+ await this.observerDispatcher.dispatch(
2953
+ bindings.length > 0 ? bindings : void 0,
2954
+ context
2955
+ );
2927
2956
  }
2928
2957
  async runIntentSensors(sensorBindings, intent, frame, stage, extras) {
2929
2958
  for (const binding of sensorBindings) {
@@ -8129,6 +8158,61 @@ var init_disk_upload_file_store = __esm({
8129
8158
  function unique(values) {
8130
8159
  return Array.from(new Set(values));
8131
8160
  }
8161
+ function matchesObserverIntent(intents, intent) {
8162
+ if (!intents || intents.length === 0) {
8163
+ return true;
8164
+ }
8165
+ if (!intent) {
8166
+ return false;
8167
+ }
8168
+ return intents.includes(intent);
8169
+ }
8170
+ function normalizeHandlerToken(value) {
8171
+ return value.trim().toLowerCase();
8172
+ }
8173
+ function matchesObserverHandler(handlers, handler) {
8174
+ if (!handlers || handlers.length === 0) {
8175
+ return true;
8176
+ }
8177
+ if (!handler) {
8178
+ return false;
8179
+ }
8180
+ const normalizedHandler = normalizeHandlerToken(handler);
8181
+ return handlers.some((candidate) => {
8182
+ if (!candidate) {
8183
+ return false;
8184
+ }
8185
+ const normalizedCandidate = normalizeHandlerToken(candidate);
8186
+ return normalizedHandler === normalizedCandidate || normalizedHandler.endsWith(`.${normalizedCandidate}`) || normalizedHandler.startsWith(`${normalizedCandidate}.`) || normalizedCandidate.endsWith(`.${normalizedHandler}`) || normalizedCandidate.startsWith(`${normalizedHandler}.`);
8187
+ });
8188
+ }
8189
+ function observerRefKey2(ref) {
8190
+ return typeof ref === "string" ? ref : ref.name || "(anonymous)";
8191
+ }
8192
+ function mergeBindingRefs(...bindingGroups) {
8193
+ const merged = /* @__PURE__ */ new Map();
8194
+ for (const bindings of bindingGroups) {
8195
+ for (const binding of bindings) {
8196
+ for (const ref of binding.refs) {
8197
+ const key = observerRefKey2(ref);
8198
+ const current = merged.get(key);
8199
+ if (!current) {
8200
+ merged.set(key, {
8201
+ refs: [ref],
8202
+ tags: binding.tags ? [...new Set(binding.tags)] : void 0,
8203
+ events: binding.events ? [...new Set(binding.events)] : void 0
8204
+ });
8205
+ continue;
8206
+ }
8207
+ current.tags = Array.from(
8208
+ /* @__PURE__ */ new Set([...current.tags || [], ...binding.tags || []])
8209
+ );
8210
+ current.events = current.events === void 0 || binding.events === void 0 ? void 0 : Array.from(/* @__PURE__ */ new Set([...current.events || [], ...binding.events]));
8211
+ }
8212
+ }
8213
+ }
8214
+ return Array.from(merged.values());
8215
+ }
8132
8216
  var ObserverDispatcherService;
8133
8217
  var init_observer_dispatcher_service = __esm({
8134
8218
  "src/engine/observer-dispatcher.service.ts"() {
@@ -8139,9 +8223,20 @@ var init_observer_dispatcher_service = __esm({
8139
8223
  this.logger = createAxisLogger(_ObserverDispatcherService.name);
8140
8224
  }
8141
8225
  async dispatch(bindings, context) {
8142
- if (!bindings || bindings.length === 0) return;
8226
+ const explicitBindings = bindings || [];
8227
+ const implicitRegistrations = this.getImplicitRegistrations();
8228
+ if (!explicitBindings.length && implicitRegistrations.length === 0) {
8229
+ return;
8230
+ }
8143
8231
  const invoked = /* @__PURE__ */ new Set();
8144
- for (const binding of bindings) {
8232
+ const implicitBindings = implicitRegistrations.map(
8233
+ (registration) => ({
8234
+ refs: [registration.instance.constructor],
8235
+ events: registration.events
8236
+ })
8237
+ );
8238
+ const merged = mergeBindingRefs(explicitBindings, implicitBindings);
8239
+ for (const binding of merged) {
8145
8240
  if (binding.events && binding.events.length > 0 && !binding.events.includes(context.event)) {
8146
8241
  continue;
8147
8242
  }
@@ -8152,6 +8247,9 @@ var init_observer_dispatcher_service = __esm({
8152
8247
  continue;
8153
8248
  }
8154
8249
  if (invoked.has(registration.name)) continue;
8250
+ if (!matchesObserverIntent(registration.intents, context.intent) || !matchesObserverHandler(registration.handlers, context.handler)) {
8251
+ continue;
8252
+ }
8155
8253
  if (registration.events && registration.events.length > 0 && !registration.events.includes(context.event)) {
8156
8254
  continue;
8157
8255
  }
@@ -8177,6 +8275,9 @@ var init_observer_dispatcher_service = __esm({
8177
8275
  }
8178
8276
  }
8179
8277
  }
8278
+ getImplicitRegistrations() {
8279
+ return this.registry.list();
8280
+ }
8180
8281
  };
8181
8282
  }
8182
8283
  });