@cadenza.io/service 2.17.13 → 2.17.15

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.
@@ -382,16 +382,16 @@ function normalizeServiceTransportConfig(value) {
382
382
  }
383
383
  function normalizeServiceTransportDescriptor(value) {
384
384
  const raw = value ?? {};
385
- const uuid5 = normalizeString(raw.uuid);
385
+ const uuid6 = normalizeString(raw.uuid);
386
386
  const serviceInstanceId = normalizeString(
387
387
  raw.serviceInstanceId ?? raw.service_instance_id
388
388
  );
389
389
  const config = normalizeServiceTransportConfig(raw);
390
- if (!uuid5 || !serviceInstanceId || !config) {
390
+ if (!uuid6 || !serviceInstanceId || !config) {
391
391
  return null;
392
392
  }
393
393
  return {
394
- uuid: uuid5,
394
+ uuid: uuid6,
395
395
  serviceInstanceId,
396
396
  role: config.role,
397
397
  origin: config.origin,
@@ -453,14 +453,14 @@ function normalizeTransportArray(value, serviceInstanceId) {
453
453
  }
454
454
  function normalizeServiceInstanceDescriptor(value) {
455
455
  const raw = value ?? {};
456
- const uuid5 = normalizeString2(raw.uuid);
456
+ const uuid6 = normalizeString2(raw.uuid);
457
457
  const serviceName = normalizeString2(raw.serviceName ?? raw.service_name);
458
- if (!uuid5 || !serviceName) {
458
+ if (!uuid6 || !serviceName) {
459
459
  return null;
460
460
  }
461
- const transports = normalizeTransportArray(raw.transports, uuid5);
461
+ const transports = normalizeTransportArray(raw.transports, uuid6);
462
462
  return {
463
- uuid: uuid5,
463
+ uuid: uuid6,
464
464
  serviceName,
465
465
  numberOfRunningGraphs: Math.max(
466
466
  0,
@@ -491,6 +491,22 @@ function getRouteableTransport(instance, role, protocol) {
491
491
  return selectTransportForRole(instance.transports ?? [], role, protocol);
492
492
  }
493
493
 
494
+ // src/utils/delegation.ts
495
+ import { v4 as uuid2 } from "uuid";
496
+ function ensureDelegationContextMetadata(input) {
497
+ const context = input && typeof input === "object" ? { ...input } : {};
498
+ const metadata = context.__metadata && typeof context.__metadata === "object" ? { ...context.__metadata } : {};
499
+ const deputyExecId = typeof metadata.__deputyExecId === "string" && metadata.__deputyExecId.length > 0 ? metadata.__deputyExecId : typeof context.__deputyExecId === "string" && context.__deputyExecId.length > 0 ? context.__deputyExecId : uuid2();
500
+ return {
501
+ ...context,
502
+ __deputyExecId: deputyExecId,
503
+ __metadata: {
504
+ ...metadata,
505
+ __deputyExecId: deputyExecId
506
+ }
507
+ };
508
+ }
509
+
494
510
  // src/utils/readiness.ts
495
511
  function evaluateDependencyReadiness(input) {
496
512
  const missedHeartbeats = Math.max(
@@ -903,15 +919,15 @@ var ServiceRegistry = class _ServiceRegistry {
903
919
  if (!serviceInstance) {
904
920
  return false;
905
921
  }
906
- const uuid5 = serviceInstance.uuid;
922
+ const uuid6 = serviceInstance.uuid;
907
923
  const serviceName = serviceInstance.serviceName;
908
924
  const deleted = Boolean(
909
925
  ctx.deleted ?? ctx.serviceInstance?.deleted ?? ctx.data?.deleted
910
926
  );
911
- if (uuid5 === this.serviceInstanceId) return;
927
+ if (uuid6 === this.serviceInstanceId) return;
912
928
  if (deleted) {
913
- const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid5);
914
- const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid5) ?? -1;
929
+ const existingInstance = this.instances.get(serviceName)?.find((instance) => instance.uuid === uuid6);
930
+ const indexToDelete = this.instances.get(serviceName)?.findIndex((i) => i.uuid === uuid6) ?? -1;
915
931
  if (indexToDelete >= 0 && existingInstance) {
916
932
  this.instances.get(serviceName)?.splice(indexToDelete, 1);
917
933
  for (const transport of existingInstance.transports) {
@@ -923,13 +939,13 @@ var ServiceRegistry = class _ServiceRegistry {
923
939
  if (this.instances.get(serviceName)?.length === 0) {
924
940
  this.instances.delete(serviceName);
925
941
  }
926
- this.unregisterDependee(uuid5, serviceName);
942
+ this.unregisterDependee(uuid6, serviceName);
927
943
  return;
928
944
  }
929
945
  if (!this.instances.has(serviceName))
930
946
  this.instances.set(serviceName, []);
931
947
  const instances = this.instances.get(serviceName);
932
- const existing = instances.find((i) => i.uuid === uuid5);
948
+ const existing = instances.find((i) => i.uuid === uuid6);
933
949
  if (existing) {
934
950
  Object.assign(existing, {
935
951
  ...serviceInstance,
@@ -939,7 +955,7 @@ var ServiceRegistry = class _ServiceRegistry {
939
955
  } else {
940
956
  instances.push(serviceInstance);
941
957
  }
942
- const trackedInstance = existing ?? instances.find((instance) => instance.uuid === uuid5);
958
+ const trackedInstance = existing ?? instances.find((instance) => instance.uuid === uuid6);
943
959
  if (trackedInstance) {
944
960
  const snapshot = this.resolveRuntimeStatusSnapshot(
945
961
  trackedInstance.numberOfRunningGraphs ?? 0,
@@ -952,7 +968,7 @@ var ServiceRegistry = class _ServiceRegistry {
952
968
  trackedInstance.reportedAt = trackedInstance.reportedAt ?? (/* @__PURE__ */ new Date()).toISOString();
953
969
  }
954
970
  if (!serviceInstance.isBootstrapPlaceholder) {
955
- this.reconcileBootstrapPlaceholderInstance(serviceName, uuid5, emit);
971
+ this.reconcileBootstrapPlaceholderInstance(serviceName, uuid6, emit);
956
972
  }
957
973
  if (this.serviceName === serviceName) {
958
974
  return false;
@@ -978,7 +994,7 @@ var ServiceRegistry = class _ServiceRegistry {
978
994
  if (!clientCreated) {
979
995
  emit("meta.service_registry.dependee_registered", {
980
996
  serviceName,
981
- serviceInstanceId: uuid5,
997
+ serviceInstanceId: uuid6,
982
998
  serviceTransportId: trackedTransport.uuid,
983
999
  serviceOrigin: trackedTransport.origin,
984
1000
  transportProtocols: trackedTransport.protocols,
@@ -992,7 +1008,7 @@ var ServiceRegistry = class _ServiceRegistry {
992
1008
  } else {
993
1009
  emit("meta.service_registry.routeable_transport_missing", {
994
1010
  serviceName,
995
- serviceInstanceId: uuid5,
1011
+ serviceInstanceId: uuid6,
996
1012
  requiredRole: this.getRoutingTransportRole(),
997
1013
  isFrontend: this.isFrontend
998
1014
  });
@@ -1116,8 +1132,7 @@ var ServiceRegistry = class _ServiceRegistry {
1116
1132
  this.handleGlobalSignalRegistrationTask = CadenzaService.createMetaTask(
1117
1133
  "Handle global Signal Registration",
1118
1134
  (ctx) => {
1119
- const { signalToTaskMaps } = ctx;
1120
- const sortedSignalToTaskMap = signalToTaskMaps.sort(
1135
+ const sortedSignalToTaskMap = this.normalizeSignalMaps(ctx).sort(
1121
1136
  (a, b) => {
1122
1137
  if (a.deleted && !b.deleted) return -1;
1123
1138
  if (!a.deleted && b.deleted) return 1;
@@ -1355,22 +1370,14 @@ var ServiceRegistry = class _ServiceRegistry {
1355
1370
  },
1356
1371
  ctx.inquiryOptions ?? ctx.__inquiryOptions ?? {}
1357
1372
  );
1358
- const signalToTaskMaps = (inquiryResult.signalToTaskMaps ?? []).filter((m) => !!m.isGlobal).map((m) => ({
1359
- signalName: m.signalName,
1360
- serviceName: m.serviceName,
1361
- deleted: !!m.deleted
1362
- }));
1363
- const intentToTaskMaps = (inquiryResult.intentToTaskMaps ?? []).map(
1364
- (m) => ({
1365
- intentName: m.intentName,
1366
- taskName: m.taskName,
1367
- taskVersion: m.taskVersion ?? 1,
1368
- serviceName: m.serviceName,
1369
- deleted: !!m.deleted
1370
- })
1373
+ const signalToTaskMaps = this.normalizeSignalMaps(
1374
+ inquiryResult
1375
+ ).filter((m) => !!m.isGlobal);
1376
+ const intentToTaskMaps = this.normalizeIntentMaps(
1377
+ inquiryResult
1371
1378
  );
1372
- const serviceInstances = (inquiryResult.serviceInstances ?? []).map((instance) => normalizeServiceInstanceDescriptor(instance)).filter(
1373
- (instance) => !!instance && !!instance.isActive && !instance.isNonResponsive && !instance.isBlocked
1379
+ const serviceInstances = this.normalizeServiceInstancesFromSync(
1380
+ inquiryResult
1374
1381
  );
1375
1382
  return {
1376
1383
  ...ctx,
@@ -1455,6 +1462,9 @@ var ServiceRegistry = class _ServiceRegistry {
1455
1462
  this.getBalancedInstance = CadenzaService.createMetaTask(
1456
1463
  "Get balanced instance",
1457
1464
  (context, emit) => {
1465
+ if (context.__remoteRoutineName !== void 0) {
1466
+ context = ensureDelegationContextMetadata(context);
1467
+ }
1458
1468
  const {
1459
1469
  __serviceName,
1460
1470
  __triedInstances,
@@ -2193,9 +2203,47 @@ var ServiceRegistry = class _ServiceRegistry {
2193
2203
  buildRemoteIntentDeputyKey(map) {
2194
2204
  return `${map.intentName}|${map.serviceName}|${map.taskName}|${map.taskVersion ?? 1}`;
2195
2205
  }
2206
+ readArrayPayload(ctx, keys) {
2207
+ for (const key of keys) {
2208
+ const value = ctx?.[key];
2209
+ if (Array.isArray(value)) {
2210
+ return value;
2211
+ }
2212
+ }
2213
+ if (Array.isArray(ctx?.rows)) {
2214
+ return ctx.rows;
2215
+ }
2216
+ if (Array.isArray(ctx?.data)) {
2217
+ return ctx.data;
2218
+ }
2219
+ return [];
2220
+ }
2221
+ normalizeSignalMaps(ctx) {
2222
+ return this.readArrayPayload(ctx, [
2223
+ "signalToTaskMaps",
2224
+ "signal_to_task_maps",
2225
+ "signalToTaskMap",
2226
+ "signal_to_task_map"
2227
+ ]).map((map) => ({
2228
+ signalName: String(
2229
+ map.signalName ?? map.signal_name ?? ""
2230
+ ).trim(),
2231
+ serviceName: String(
2232
+ map.serviceName ?? map.service_name ?? ""
2233
+ ).trim(),
2234
+ isGlobal: Boolean(map.isGlobal ?? map.is_global ?? false),
2235
+ deleted: Boolean(map.deleted)
2236
+ })).filter((map) => map.signalName && map.serviceName);
2237
+ }
2196
2238
  normalizeIntentMaps(ctx) {
2197
- if (Array.isArray(ctx.intentToTaskMaps)) {
2198
- return ctx.intentToTaskMaps.map((m) => ({
2239
+ const arrayPayload = this.readArrayPayload(ctx, [
2240
+ "intentToTaskMaps",
2241
+ "intent_to_task_maps",
2242
+ "intentToTaskMap",
2243
+ "intent_to_task_map"
2244
+ ]);
2245
+ if (arrayPayload.length > 0) {
2246
+ return arrayPayload.map((m) => ({
2199
2247
  intentName: m.intentName ?? m.intent_name,
2200
2248
  serviceName: m.serviceName ?? m.service_name,
2201
2249
  taskName: m.taskName ?? m.task_name,
@@ -2203,7 +2251,7 @@ var ServiceRegistry = class _ServiceRegistry {
2203
2251
  deleted: !!m.deleted
2204
2252
  })).filter((m) => m.intentName && m.serviceName && m.taskName);
2205
2253
  }
2206
- const single = ctx.intentToTaskMap ?? ctx.data ?? (ctx.intentName ? ctx : void 0);
2254
+ const single = ctx.intentToTaskMap ?? ctx.intent_to_task_map ?? ctx.data ?? (ctx.intentName ? ctx : void 0);
2207
2255
  if (!single) return [];
2208
2256
  const normalized = {
2209
2257
  intentName: single.intentName ?? single.intent_name,
@@ -2216,6 +2264,40 @@ var ServiceRegistry = class _ServiceRegistry {
2216
2264
  return [];
2217
2265
  return [normalized];
2218
2266
  }
2267
+ normalizeServiceInstancesFromSync(ctx) {
2268
+ const rawTransports = this.readArrayPayload(ctx, [
2269
+ "serviceInstanceTransports",
2270
+ "service_instance_transports",
2271
+ "serviceInstanceTransport",
2272
+ "service_instance_transport"
2273
+ ]).map((transport) => normalizeServiceTransportDescriptor(transport)).filter(
2274
+ (transport) => !!transport && !transport.deleted
2275
+ );
2276
+ const transportsByInstance = /* @__PURE__ */ new Map();
2277
+ for (const transport of rawTransports) {
2278
+ if (!transportsByInstance.has(transport.serviceInstanceId)) {
2279
+ transportsByInstance.set(transport.serviceInstanceId, []);
2280
+ }
2281
+ transportsByInstance.get(transport.serviceInstanceId).push(transport);
2282
+ }
2283
+ return this.readArrayPayload(ctx, [
2284
+ "serviceInstances",
2285
+ "service_instances",
2286
+ "serviceInstance",
2287
+ "service_instance"
2288
+ ]).map(
2289
+ (instance) => normalizeServiceInstanceDescriptor({
2290
+ ...instance,
2291
+ transports: Array.isArray(instance?.transports) && instance.transports.length > 0 ? instance.transports : transportsByInstance.get(
2292
+ String(
2293
+ instance?.uuid ?? instance?.serviceInstanceId ?? instance?.service_instance_id ?? ""
2294
+ ).trim()
2295
+ ) ?? []
2296
+ })
2297
+ ).filter(
2298
+ (instance) => !!instance && !!instance.isActive && !instance.isNonResponsive && !instance.isBlocked
2299
+ );
2300
+ }
2219
2301
  registerRemoteIntentDeputy(map) {
2220
2302
  if (!this.serviceName || map.serviceName === this.serviceName) {
2221
2303
  return;
@@ -3134,7 +3216,7 @@ var ServiceRegistry = class _ServiceRegistry {
3134
3216
 
3135
3217
  // src/graph/definition/SignalTransmissionTask.ts
3136
3218
  import { Task as Task2 } from "@cadenza.io/core";
3137
- import { v4 as uuid2 } from "uuid";
3219
+ import { v4 as uuid3 } from "uuid";
3138
3220
  var SignalTransmissionTask = class extends Task2 {
3139
3221
  /**
3140
3222
  * Constructs a new instance of the class and initializes it with the provided parameters.
@@ -3163,7 +3245,7 @@ var SignalTransmissionTask = class extends Task2 {
3163
3245
  */
3164
3246
  constructor(name, signalName, serviceName, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = true, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
3165
3247
  const taskFunction = (context) => {
3166
- context.__routineExecId = uuid2();
3248
+ context.__routineExecId = uuid3();
3167
3249
  return context;
3168
3250
  };
3169
3251
  super(
@@ -3343,6 +3425,8 @@ var RestController = class _RestController {
3343
3425
  if (delegateCtx.__remoteRoutineName === void 0) {
3344
3426
  return;
3345
3427
  }
3428
+ const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
3429
+ const deputyExecId = normalizedDelegateCtx.__metadata.__deputyExecId;
3346
3430
  fetchDiagnostics.delegationRequests++;
3347
3431
  fetchDiagnostics.updatedAt = Date.now();
3348
3432
  let resultContext;
@@ -3354,7 +3438,7 @@ var RestController = class _RestController {
3354
3438
  "Content-Type": "application/json"
3355
3439
  },
3356
3440
  method: "POST",
3357
- body: JSON.stringify(delegateCtx)
3441
+ body: JSON.stringify(normalizedDelegateCtx)
3358
3442
  },
3359
3443
  3e4
3360
3444
  );
@@ -3365,14 +3449,11 @@ var RestController = class _RestController {
3365
3449
  resultContext = {
3366
3450
  __error: `Error: ${error}`,
3367
3451
  errored: true,
3368
- ...delegateCtx,
3369
- ...delegateCtx.__metadata
3452
+ ...normalizedDelegateCtx,
3453
+ ...normalizedDelegateCtx.__metadata
3370
3454
  };
3371
3455
  } finally {
3372
- emit(
3373
- `meta.fetch.delegated:${delegateCtx.__metadata.__deputyExecId}`,
3374
- resultContext
3375
- );
3456
+ emit(`meta.fetch.delegated:${deputyExecId}`, resultContext);
3376
3457
  }
3377
3458
  return resultContext;
3378
3459
  },
@@ -4051,11 +4132,12 @@ var SocketController = class _SocketController {
4051
4132
  CadenzaService.emit("meta.socket.handshake", ctx);
4052
4133
  });
4053
4134
  ws.on("delegation", (ctx, callback) => {
4054
- const deputyExecId = ctx.__metadata.__deputyExecId;
4135
+ const delegationCtx = ensureDelegationContextMetadata(ctx);
4136
+ const deputyExecId = delegationCtx.__metadata.__deputyExecId;
4055
4137
  CadenzaService.createEphemeralMetaTask(
4056
4138
  "Resolve delegation",
4057
- (delegationCtx) => {
4058
- callback(delegationCtx);
4139
+ (delegationCtx2) => {
4140
+ callback(delegationCtx2);
4059
4141
  },
4060
4142
  "Resolves a delegation request using client callback.",
4061
4143
  { register: false }
@@ -4078,8 +4160,8 @@ var SocketController = class _SocketController {
4078
4160
  `meta.node.graph_completed:${deputyExecId}`
4079
4161
  ).emitsOnFail(`meta.socket.progress_failed:${deputyExecId}`);
4080
4162
  CadenzaService.emit("meta.socket.delegation_requested", {
4081
- ...ctx,
4082
- __name: ctx.__remoteRoutineName
4163
+ ...delegationCtx,
4164
+ __name: delegationCtx.__remoteRoutineName
4083
4165
  });
4084
4166
  });
4085
4167
  ws.on("signal", (ctx, callback) => {
@@ -4699,9 +4781,10 @@ var SocketController = class _SocketController {
4699
4781
  if (delegateCtx.__remoteRoutineName === void 0) {
4700
4782
  return;
4701
4783
  }
4702
- delete delegateCtx.__isSubMeta;
4703
- delete delegateCtx.__broadcast;
4704
- const deputyExecId = delegateCtx.__metadata?.__deputyExecId;
4784
+ const normalizedDelegateCtx = ensureDelegationContextMetadata(delegateCtx);
4785
+ delete normalizedDelegateCtx.__isSubMeta;
4786
+ delete normalizedDelegateCtx.__broadcast;
4787
+ const deputyExecId = normalizedDelegateCtx.__metadata?.__deputyExecId;
4705
4788
  const requestSentAt = Date.now();
4706
4789
  if (deputyExecId) {
4707
4790
  runtimeHandle.pendingDelegationIds.add(deputyExecId);
@@ -4710,8 +4793,8 @@ var SocketController = class _SocketController {
4710
4793
  try {
4711
4794
  const resultContext = await runtimeHandle.emitWhenReady?.(
4712
4795
  "delegation",
4713
- delegateCtx,
4714
- delegateCtx.__timeout ?? 6e4
4796
+ normalizedDelegateCtx,
4797
+ normalizedDelegateCtx.__timeout ?? 6e4
4715
4798
  ) ?? {
4716
4799
  errored: true,
4717
4800
  __error: "Socket delegation returned no response"
@@ -5576,7 +5659,7 @@ var DatabaseController = class _DatabaseController {
5576
5659
  };
5577
5660
 
5578
5661
  // src/Cadenza.ts
5579
- import { v4 as uuid3 } from "uuid";
5662
+ import { v4 as uuid4 } from "uuid";
5580
5663
 
5581
5664
  // src/graph/controllers/GraphSyncController.ts
5582
5665
  var ACTOR_TASK_METADATA = /* @__PURE__ */ Symbol.for("@cadenza.io/core/actor-task-meta");
@@ -6684,7 +6767,7 @@ var CadenzaService = class {
6684
6767
  (transport) => !!transport
6685
6768
  ).map((transport) => ({
6686
6769
  ...transport,
6687
- uuid: uuid3()
6770
+ uuid: uuid4()
6688
6771
  }));
6689
6772
  }
6690
6773
  static createBootstrapTransport(serviceInstanceId, role, endpoint) {
@@ -6928,7 +7011,7 @@ var CadenzaService = class {
6928
7011
  }
6929
7012
  for (const responder of responders) {
6930
7013
  const { task, descriptor } = responder;
6931
- const inquiryId = uuid3();
7014
+ const inquiryId = uuid4();
6932
7015
  startTimeByTask.set(task, Date.now());
6933
7016
  const resolverTask = this.createEphemeralMetaTask(
6934
7017
  `Resolve inquiry ${inquiry} for ${descriptor.localTaskName}`,
@@ -7419,7 +7502,7 @@ var CadenzaService = class {
7419
7502
  this.bootstrap();
7420
7503
  this.validateName(serviceName);
7421
7504
  this.validateServiceName(serviceName);
7422
- const serviceId = options.customServiceId ?? uuid3();
7505
+ const serviceId = options.customServiceId ?? uuid4();
7423
7506
  this.serviceRegistry.serviceName = serviceName;
7424
7507
  this.serviceRegistry.serviceInstanceId = serviceId;
7425
7508
  this.setHydrationResults(options.hydration);
@@ -8253,7 +8336,7 @@ import {
8253
8336
  } from "@cadenza.io/core";
8254
8337
 
8255
8338
  // src/ssr/createSSRInquiryBridge.ts
8256
- import { v4 as uuid4 } from "uuid";
8339
+ import { v4 as uuid5 } from "uuid";
8257
8340
  function ensureFetch() {
8258
8341
  if (typeof globalThis.fetch !== "function") {
8259
8342
  throw new Error("SSR inquiry bridge requires global fetch support.");
@@ -8342,7 +8425,7 @@ function createSSRInquiryBridge(options = {}) {
8342
8425
  __remoteRoutineName: remoteRoutineName,
8343
8426
  __metadata: {
8344
8427
  ...context.__metadata ?? {},
8345
- __deputyExecId: uuid4()
8428
+ __deputyExecId: uuid5()
8346
8429
  }
8347
8430
  }),
8348
8431
  signal