@naylence/agent-sdk 0.3.5 → 0.3.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.
@@ -15606,7 +15606,8 @@
15606
15606
  if (g.__ENV__ && typeof g.__ENV__ === 'object')
15607
15607
  Object.assign(out, g.__ENV__);
15608
15608
  try {
15609
- // @ts-ignore -- import.meta is only available in ESM builds
15609
+ // import.meta is only available in ESM builds
15610
+ // @ts-ignore
15610
15611
  const ie = (typeof ({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) }) !== 'undefined' && undefined) || undefined;
15611
15612
  if (ie && typeof ie === 'object')
15612
15613
  Object.assign(out, ie);
@@ -15674,12 +15675,12 @@
15674
15675
  // --- END ENV SHIM ---
15675
15676
 
15676
15677
  // This file is auto-generated during build - do not edit manually
15677
- // Generated from package.json version: 0.3.6
15678
+ // Generated from package.json version: 0.3.7
15678
15679
  /**
15679
15680
  * The package version, injected at build time.
15680
15681
  * @internal
15681
15682
  */
15682
- const VERSION$1 = '0.3.6';
15683
+ const VERSION$1 = '0.3.7';
15683
15684
 
15684
15685
  /**
15685
15686
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -17275,6 +17276,50 @@
17275
17276
  });
17276
17277
  }
17277
17278
 
17279
+ function isModuleNotFoundError(error) {
17280
+ if (!(error instanceof Error)) {
17281
+ return false;
17282
+ }
17283
+ const message = error.message || '';
17284
+ if (message.includes('Cannot find module') ||
17285
+ message.includes('ERR_MODULE_NOT_FOUND') ||
17286
+ message.includes('MODULE_NOT_FOUND')) {
17287
+ return true;
17288
+ }
17289
+ const code = error.code;
17290
+ if (typeof code === 'string') {
17291
+ return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
17292
+ }
17293
+ return false;
17294
+ }
17295
+ /**
17296
+ * Wraps a dynamic import loader and enriches "module not found" failures with an actionable error message.
17297
+ */
17298
+ async function safeImport(loader, dependencyNameOrOptions, maybeOptions) {
17299
+ const options = typeof dependencyNameOrOptions === 'string'
17300
+ ? { dependencyName: dependencyNameOrOptions, ...(maybeOptions ?? {}) }
17301
+ : dependencyNameOrOptions;
17302
+ const dependencyName = options.dependencyName;
17303
+ try {
17304
+ return await loader();
17305
+ }
17306
+ catch (error) {
17307
+ if (isModuleNotFoundError(error)) {
17308
+ const message = options.helpMessage ??
17309
+ `Missing optional dependency "${dependencyName}". Install it to enable this feature.`;
17310
+ const enrichedError = new Error(message);
17311
+ try {
17312
+ enrichedError.cause = error;
17313
+ }
17314
+ catch {
17315
+ // Ignore environments that do not support attaching a cause.
17316
+ }
17317
+ throw enrichedError;
17318
+ }
17319
+ throw error;
17320
+ }
17321
+ }
17322
+
17278
17323
  /**
17279
17324
  * flow_controller.ts - credit window management with cooperative back-pressure.
17280
17325
  *
@@ -18209,50 +18254,6 @@
18209
18254
  return SecretSource.normalize(value);
18210
18255
  }
18211
18256
 
18212
- function isModuleNotFoundError(error) {
18213
- if (!(error instanceof Error)) {
18214
- return false;
18215
- }
18216
- const message = error.message || '';
18217
- if (message.includes('Cannot find module') ||
18218
- message.includes('ERR_MODULE_NOT_FOUND') ||
18219
- message.includes('MODULE_NOT_FOUND')) {
18220
- return true;
18221
- }
18222
- const code = error.code;
18223
- if (typeof code === 'string') {
18224
- return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
18225
- }
18226
- return false;
18227
- }
18228
- /**
18229
- * Wraps a dynamic import loader and enriches "module not found" failures with an actionable error message.
18230
- */
18231
- async function safeImport(loader, dependencyNameOrOptions, maybeOptions) {
18232
- const options = typeof dependencyNameOrOptions === 'string'
18233
- ? { dependencyName: dependencyNameOrOptions, ...(maybeOptions ?? {}) }
18234
- : dependencyNameOrOptions;
18235
- const dependencyName = options.dependencyName;
18236
- try {
18237
- return await loader();
18238
- }
18239
- catch (error) {
18240
- if (isModuleNotFoundError(error)) {
18241
- const message = options.helpMessage ??
18242
- `Missing optional dependency "${dependencyName}". Install it to enable this feature.`;
18243
- const enrichedError = new Error(message);
18244
- try {
18245
- enrichedError.cause = error;
18246
- }
18247
- catch {
18248
- // Ignore environments that do not support attaching a cause.
18249
- }
18250
- throw enrichedError;
18251
- }
18252
- throw error;
18253
- }
18254
- }
18255
-
18256
18257
  const indexedDBConfigSchema = object({
18257
18258
  type: literal('IndexedDBStorageProvider')
18258
18259
  .default('IndexedDBStorageProvider'),
@@ -21831,9 +21832,6 @@
21831
21832
  this.ackDoneSince = new Map();
21832
21833
  this.replyDoneSince = new Map();
21833
21834
  this.pendingAckDispatches = new Set();
21834
- this.recentlyHandled = new Map();
21835
- this.recentlyHandledOrder = [];
21836
- this.recentlyHandledTtlMs = 60000;
21837
21835
  this.isPreparingToStop = false;
21838
21836
  this.shutdownRequestedAtMs = null;
21839
21837
  this.shutdownRetryGraceMs = 1000;
@@ -22055,22 +22053,6 @@
22055
22053
  }
22056
22054
  }
22057
22055
  else {
22058
- const wasRecentlyHandled = await this.lock.runExclusive(async () => this.wasRecentlyHandled(envelope.id));
22059
- if (wasRecentlyHandled) {
22060
- logger$12.debug('tracker_duplicate_envelope_recently_handled', {
22061
- envp_id: envelope.id,
22062
- });
22063
- return new TrackedEnvelope({
22064
- timeoutAtMs: 0,
22065
- overallTimeoutAtMs: 0,
22066
- expectedResponseType: envelope.rtype ?? FameResponseType.NONE,
22067
- createdAtMs: Date.now(),
22068
- status: EnvelopeStatus.HANDLED,
22069
- mailboxType: MailboxType.INBOX,
22070
- originalEnvelope: envelope,
22071
- serviceName: inboxName,
22072
- });
22073
- }
22074
22056
  tracked = new TrackedEnvelope({
22075
22057
  timeoutAtMs: 0,
22076
22058
  overallTimeoutAtMs: 0,
@@ -22092,12 +22074,8 @@
22092
22074
  async onEnvelopeHandled(envelope) {
22093
22075
  const inbox = this.ensureInbox();
22094
22076
  envelope.status = EnvelopeStatus.HANDLED;
22077
+ // Delete the envelope from inbox to prevent growth
22095
22078
  await inbox.delete(envelope.originalEnvelope.id);
22096
- await this.lock.runExclusive(async () => {
22097
- this.markRecentlyHandled(envelope.originalEnvelope.id);
22098
- });
22099
- // Preserve handled envelope to prevent duplicate redelivery during shutdown drains.
22100
- // await inbox.set(envelope.originalEnvelope.id, envelope);
22101
22079
  }
22102
22080
  async onEnvelopeHandleFailed(inboxName, envelope, context, error, isFinalFailure = false) {
22103
22081
  const inbox = this.ensureInbox();
@@ -22312,9 +22290,9 @@
22312
22290
  });
22313
22291
  await this.markDoneSince(this.replyFutures, trackedEnvelope.originalEnvelope.id, this.replyDoneSince);
22314
22292
  await this.markDoneSince(this.ackFutures, trackedEnvelope.originalEnvelope.id, this.ackDoneSince);
22315
- if (envelope.rtype && Boolean(envelope.rtype & FameResponseType.ACK)) {
22316
- await this.sendAck(envelope);
22317
- }
22293
+ // Note: ACK is already sent in onCorrelatedMessage (lines 655-657)
22294
+ // when the reply envelope is first delivered. No need to send it again here.
22295
+ // Removing this duplicate sendAck call fixes the duplicate DeliveryAck bug.
22318
22296
  for (const handler of this.eventHandlers) {
22319
22297
  await handler.onEnvelopeReplied?.(trackedEnvelope, envelope);
22320
22298
  }
@@ -22464,8 +22442,6 @@
22464
22442
  }
22465
22443
  this.streamDone.clear();
22466
22444
  this.correlationToEnvelope.clear();
22467
- this.recentlyHandled.clear();
22468
- this.recentlyHandledOrder.length = 0;
22469
22445
  return values;
22470
22446
  });
22471
22447
  for (const timer of timers) {
@@ -23047,39 +23023,6 @@
23047
23023
  this.pendingAckDispatches.delete(ackDispatch);
23048
23024
  }
23049
23025
  }
23050
- markRecentlyHandled(envelopeId) {
23051
- const now = Date.now();
23052
- this.recentlyHandled.set(envelopeId, now);
23053
- this.recentlyHandledOrder.push(envelopeId);
23054
- this.trimRecentlyHandled(now);
23055
- }
23056
- wasRecentlyHandled(envelopeId) {
23057
- const now = Date.now();
23058
- const timestamp = this.recentlyHandled.get(envelopeId);
23059
- if (timestamp === undefined) {
23060
- return false;
23061
- }
23062
- if (now - timestamp > this.recentlyHandledTtlMs) {
23063
- this.recentlyHandled.delete(envelopeId);
23064
- return false;
23065
- }
23066
- return true;
23067
- }
23068
- trimRecentlyHandled(now) {
23069
- while (this.recentlyHandledOrder.length > 0) {
23070
- const candidate = this.recentlyHandledOrder[0];
23071
- const timestamp = this.recentlyHandled.get(candidate);
23072
- if (timestamp === undefined) {
23073
- this.recentlyHandledOrder.shift();
23074
- continue;
23075
- }
23076
- if (now - timestamp <= this.recentlyHandledTtlMs) {
23077
- break;
23078
- }
23079
- this.recentlyHandled.delete(candidate);
23080
- this.recentlyHandledOrder.shift();
23081
- }
23082
- }
23083
23026
  getShutdownRetryDeferDelay(nowMs) {
23084
23027
  if (!this.isPreparingToStop || this.shutdownRequestedAtMs === null) {
23085
23028
  return null;
@@ -24573,7 +24516,8 @@
24573
24516
  };
24574
24517
  let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAsyncConnector {
24575
24518
  static generateConnectorId() {
24576
- const globalCrypto = globalThis.crypto;
24519
+ const globalCrypto = globalThis
24520
+ .crypto;
24577
24521
  if (globalCrypto?.randomUUID) {
24578
24522
  return globalCrypto.randomUUID();
24579
24523
  }
@@ -24628,7 +24572,8 @@
24628
24572
  this.listenerRegistered = false;
24629
24573
  this.visibilityChangeListenerRegistered = false;
24630
24574
  this.channelName =
24631
- typeof config.channelName === 'string' && config.channelName.trim().length > 0
24575
+ typeof config.channelName === 'string' &&
24576
+ config.channelName.trim().length > 0
24632
24577
  ? config.channelName.trim()
24633
24578
  : DEFAULT_CHANNEL$7;
24634
24579
  const preferredCapacity = typeof config.inboxCapacity === 'number' &&
@@ -24652,6 +24597,7 @@
24652
24597
  local_node_id: this.localNodeId,
24653
24598
  target_node_id: this.targetNodeId ?? null,
24654
24599
  inbox_capacity: preferredCapacity,
24600
+ passive: config.passive ?? false,
24655
24601
  timestamp: new Date().toISOString(),
24656
24602
  });
24657
24603
  this.onMsg = (event) => {
@@ -24669,7 +24615,8 @@
24669
24615
  channel: this.channelName,
24670
24616
  connector_id: this.connectorId,
24671
24617
  message_type: message && typeof message === 'object'
24672
- ? message.constructor?.name ?? typeof message
24618
+ ? (message.constructor
24619
+ ?.name ?? typeof message)
24673
24620
  : typeof message,
24674
24621
  has_sender_id: Boolean(message?.senderId),
24675
24622
  has_sender_node_id: Boolean(message?.senderNodeId),
@@ -24899,7 +24846,9 @@
24899
24846
  timestamp: new Date().toISOString(),
24900
24847
  });
24901
24848
  }
24902
- if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
24849
+ if (this.visibilityChangeListenerRegistered &&
24850
+ this.visibilityChangeHandler &&
24851
+ typeof document !== 'undefined') {
24903
24852
  document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
24904
24853
  this.visibilityChangeListenerRegistered = false;
24905
24854
  this.visibilityChangeHandler = undefined;
@@ -24927,7 +24876,7 @@
24927
24876
  return rawOrEnvelope;
24928
24877
  }
24929
24878
  _isWildcardTarget() {
24930
- return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
24879
+ return (this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined');
24931
24880
  }
24932
24881
  _shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
24933
24882
  if (this._isWildcardTarget()) {
@@ -24947,7 +24896,9 @@
24947
24896
  return true;
24948
24897
  }
24949
24898
  const expectedSender = this.targetNodeId;
24950
- if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
24899
+ if (expectedSender &&
24900
+ expectedSender !== '*' &&
24901
+ senderNodeId !== expectedSender) {
24951
24902
  logger$_.debug('broadcast_channel_message_rejected', {
24952
24903
  channel: this.channelName,
24953
24904
  connector_id: this.connectorId,
@@ -25139,14 +25090,16 @@
25139
25090
  type,
25140
25091
  purpose,
25141
25092
  };
25142
- const channelValue = candidate.channelName ?? candidate['channel_name'];
25093
+ const channelValue = candidate.channelName ??
25094
+ candidate['channel_name'];
25143
25095
  if (channelValue !== undefined) {
25144
25096
  if (typeof channelValue !== 'string' || channelValue.trim().length === 0) {
25145
25097
  throw new TypeError('BroadcastChannelConnectionGrant "channelName" must be a non-empty string when provided');
25146
25098
  }
25147
25099
  result.channelName = channelValue.trim();
25148
25100
  }
25149
- const inboxValue = candidate.inboxCapacity ?? candidate['inbox_capacity'];
25101
+ const inboxValue = candidate.inboxCapacity ??
25102
+ candidate['inbox_capacity'];
25150
25103
  if (inboxValue !== undefined) {
25151
25104
  if (typeof inboxValue !== 'number' ||
25152
25105
  !Number.isFinite(inboxValue) ||
@@ -25155,7 +25108,8 @@
25155
25108
  }
25156
25109
  result.inboxCapacity = Math.floor(inboxValue);
25157
25110
  }
25158
- const windowValue = candidate.initialWindow ?? candidate['initial_window'];
25111
+ const windowValue = candidate.initialWindow ??
25112
+ candidate['initial_window'];
25159
25113
  if (windowValue !== undefined) {
25160
25114
  if (typeof windowValue !== 'number' ||
25161
25115
  !Number.isFinite(windowValue) ||
@@ -25492,25 +25446,56 @@
25492
25446
  await connector.start(this.wrappedHandler);
25493
25447
  this.connector = connector;
25494
25448
  const callbackGrants = this.node.gatherSupportedCallbackGrants();
25449
+ logger$Z.debug('callback_grants_before_augmentation', {
25450
+ count: callbackGrants.length,
25451
+ types: callbackGrants.map((g) => g.type),
25452
+ });
25453
+ // Check if we should create a broadcast callback grant before processing connection grants
25454
+ // This prevents adding duplicate broadcast grants
25455
+ const shouldAddBroadcastGrant = this.shouldAdvertiseBroadcastGrant(grant, callbackGrants);
25456
+ const broadcastCallbackGrant = shouldAddBroadcastGrant
25457
+ ? this.createBroadcastCallbackGrant(grant)
25458
+ : null;
25459
+ logger$Z.debug('broadcast_callback_grant_check', {
25460
+ should_add: shouldAddBroadcastGrant,
25461
+ grant_created: !!broadcastCallbackGrant,
25462
+ });
25495
25463
  // Include admission client's connection grants as callback grants
25496
25464
  // This ensures DirectAdmissionClient grants are available for grant selection
25497
- if (welcome.frame.connectionGrants && Array.isArray(welcome.frame.connectionGrants)) {
25465
+ if (welcome.frame.connectionGrants &&
25466
+ Array.isArray(welcome.frame.connectionGrants)) {
25498
25467
  for (const grant of welcome.frame.connectionGrants) {
25499
25468
  if (grant && typeof grant === 'object') {
25500
25469
  // Avoid duplicates by checking if grant already exists
25501
- const isDuplicate = callbackGrants.some(existing => JSON.stringify(existing) === JSON.stringify(grant));
25470
+ const isDuplicate = callbackGrants.some((existing) => JSON.stringify(existing) === JSON.stringify(grant));
25502
25471
  if (!isDuplicate) {
25503
25472
  callbackGrants.push(grant);
25473
+ logger$Z.debug('added_connection_grant_as_callback', {
25474
+ type: grant.type,
25475
+ });
25476
+ }
25477
+ else {
25478
+ logger$Z.debug('skipped_duplicate_connection_grant', {
25479
+ type: grant.type,
25480
+ });
25504
25481
  }
25505
25482
  }
25506
25483
  }
25507
25484
  }
25508
- if (this.shouldAdvertiseBroadcastGrant(grant, callbackGrants)) {
25509
- const augmented = this.createBroadcastCallbackGrant(grant);
25510
- if (augmented) {
25511
- callbackGrants.push(augmented);
25512
- }
25485
+ // Add broadcast grant after connection grants to ensure we don't duplicate
25486
+ // any broadcast grants that may have been in connectionGrants
25487
+ if (broadcastCallbackGrant &&
25488
+ this.shouldAdvertiseBroadcastGrant(grant, callbackGrants)) {
25489
+ callbackGrants.push(broadcastCallbackGrant);
25490
+ logger$Z.debug('added_broadcast_callback_grant');
25513
25491
  }
25492
+ else if (broadcastCallbackGrant) {
25493
+ logger$Z.debug('skipped_duplicate_broadcast_callback_grant');
25494
+ }
25495
+ logger$Z.debug('callback_grants_after_augmentation', {
25496
+ count: callbackGrants.length,
25497
+ types: callbackGrants.map((g) => g.type),
25498
+ });
25514
25499
  const attachInfo = await this.attachClient.attach(this.node, this.outboundOriginType, connector, welcome.frame, this.wrappedHandler, this.getKeys() ?? undefined, callbackGrants);
25515
25500
  this.targetSystemId = attachInfo.targetSystemId ?? null;
25516
25501
  if (this.targetSystemId) {
@@ -25751,7 +25736,8 @@
25751
25736
  continue;
25752
25737
  }
25753
25738
  // Reset ack time if just resumed from pause (prevents immediate timeout)
25754
- if (previousState === ConnectorState.PAUSED && currentState === ConnectorState.STARTED) {
25739
+ if (previousState === ConnectorState.PAUSED &&
25740
+ currentState === ConnectorState.STARTED) {
25755
25741
  logger$Z.debug('connector_just_resumed_resetting_ack_time', {
25756
25742
  previous_state: previousState,
25757
25743
  current_state: currentState,
@@ -27306,15 +27292,30 @@
27306
27292
  constructor(options = {}) {
27307
27293
  this.buffer = [];
27308
27294
  this.inHandshake = false;
27295
+ this.expectedSystemId = null;
27309
27296
  this.timeoutMs = options.timeoutMs ?? 10000;
27310
27297
  this.attachmentKeyValidator = options.attachmentKeyValidator;
27311
27298
  this.replicaStickinessManager = options.replicaStickinessManager ?? null;
27312
27299
  }
27313
27300
  async attach(node, originType, connector, welcomeFrame, finalHandler, keys, callbackGrants) {
27314
27301
  this.inHandshake = true;
27302
+ this.expectedSystemId = welcomeFrame.systemId;
27315
27303
  const interimHandler = async (envelope, context) => {
27316
27304
  if (this.inHandshake) {
27317
- this.buffer.push(envelope);
27305
+ // Filter: only buffer frames related to our systemId or frames without systemId info
27306
+ const frameSystemId = envelope.frame
27307
+ ?.systemId;
27308
+ if (!frameSystemId || frameSystemId === this.expectedSystemId) {
27309
+ this.buffer.push(envelope);
27310
+ }
27311
+ else {
27312
+ // Silently ignore frames from other agents during concurrent handshakes
27313
+ logger$W.debug('handshake_ignoring_frame_from_different_system', {
27314
+ frame_type: envelope.frame.type,
27315
+ frame_system_id: frameSystemId,
27316
+ expected_system_id: this.expectedSystemId,
27317
+ });
27318
+ }
27318
27319
  return null;
27319
27320
  }
27320
27321
  return finalHandler(envelope, context);
@@ -27441,6 +27442,7 @@
27441
27442
  parent_id: ackFrame.targetSystemId,
27442
27443
  });
27443
27444
  this.inHandshake = false;
27445
+ this.expectedSystemId = null;
27444
27446
  await connector.replaceHandler(finalHandler);
27445
27447
  while (this.buffer.length > 0) {
27446
27448
  const bufferedEnvelope = this.buffer.shift();
@@ -27498,7 +27500,8 @@
27498
27500
  const deadline = Date.now() + this.timeoutMs;
27499
27501
  while (Date.now() < deadline) {
27500
27502
  // Allow both STARTED and PAUSED states (PAUSED = tab hidden but connection alive)
27501
- if (connector.state !== ConnectorState.STARTED && connector.state !== ConnectorState.PAUSED) {
27503
+ if (connector.state !== ConnectorState.STARTED &&
27504
+ connector.state !== ConnectorState.PAUSED) {
27502
27505
  let errorMessage = 'Connector closed while waiting for NodeAttachAck';
27503
27506
  if (connector.closeCode !== undefined) {
27504
27507
  errorMessage += ` (code=${connector.closeCode}`;
@@ -27517,9 +27520,21 @@
27517
27520
  if (envelope.frame.type === 'NodeAttachAck') {
27518
27521
  return envelope;
27519
27522
  }
27520
- logger$W.error('unexpected_frame_during_handshake', {
27521
- frame_type: envelope.frame.type,
27522
- });
27523
+ // NodeAttach frames during handshake are expected in multi-agent scenarios
27524
+ // where multiple agents attach concurrently to the same channel
27525
+ if (envelope.frame.type === 'NodeAttach') {
27526
+ logger$W.debug('handshake_ignoring_concurrent_attach', {
27527
+ frame_type: envelope.frame.type,
27528
+ frame_system_id: envelope.frame?.systemId ??
27529
+ 'unknown',
27530
+ });
27531
+ }
27532
+ else {
27533
+ // Other unexpected frames are still logged as errors
27534
+ logger$W.error('unexpected_frame_during_handshake', {
27535
+ frame_type: envelope.frame.type,
27536
+ });
27537
+ }
27523
27538
  }
27524
27539
  await delay$2(HANDSHAKE_POLL_INTERVAL_MS);
27525
27540
  }
@@ -28235,7 +28250,8 @@
28235
28250
  else if (options &&
28236
28251
  typeof options === 'object' &&
28237
28252
  'encoding' in options &&
28238
- typeof options.encoding === 'string') {
28253
+ typeof options.encoding ===
28254
+ 'string') {
28239
28255
  encoding = options.encoding;
28240
28256
  }
28241
28257
  const data = fsBinding.readFileUtf8(pathOrDescriptor, 0);
@@ -35057,7 +35073,8 @@
35057
35073
  this.listenerRegistered = false;
35058
35074
  this.visibilityChangeListenerRegistered = false;
35059
35075
  this.channelName =
35060
- typeof config.channelName === 'string' && config.channelName.trim().length > 0
35076
+ typeof config.channelName === 'string' &&
35077
+ config.channelName.trim().length > 0
35061
35078
  ? config.channelName.trim()
35062
35079
  : DEFAULT_CHANNEL$6;
35063
35080
  const preferredCapacity = typeof config.inboxCapacity === 'number' &&
@@ -35096,7 +35113,8 @@
35096
35113
  channel: this.channelName,
35097
35114
  connector_id: this.connectorId,
35098
35115
  message_type: message && typeof message === 'object'
35099
- ? message.constructor?.name ?? typeof message
35116
+ ? (message.constructor
35117
+ ?.name ?? typeof message)
35100
35118
  : typeof message,
35101
35119
  has_sender_id: Boolean(message?.senderId),
35102
35120
  has_sender_node_id: Boolean(message?.senderNodeId),
@@ -35105,7 +35123,8 @@
35105
35123
  return;
35106
35124
  }
35107
35125
  const busMessage = message;
35108
- const senderId = typeof busMessage.senderId === 'string' && busMessage.senderId.length > 0
35126
+ const senderId = typeof busMessage.senderId === 'string' &&
35127
+ busMessage.senderId.length > 0
35109
35128
  ? busMessage.senderId
35110
35129
  : null;
35111
35130
  const senderNodeId = InPageConnector.normalizeNodeId(busMessage.senderNodeId);
@@ -35356,7 +35375,9 @@
35356
35375
  timestamp: new Date().toISOString(),
35357
35376
  });
35358
35377
  }
35359
- if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
35378
+ if (this.visibilityChangeListenerRegistered &&
35379
+ this.visibilityChangeHandler &&
35380
+ typeof document !== 'undefined') {
35360
35381
  document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
35361
35382
  this.visibilityChangeListenerRegistered = false;
35362
35383
  this.visibilityChangeHandler = undefined;
@@ -35373,7 +35394,7 @@
35373
35394
  return rawOrEnvelope;
35374
35395
  }
35375
35396
  _isWildcardTarget() {
35376
- return this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined';
35397
+ return (this.targetNodeId === '*' || typeof this.targetNodeId === 'undefined');
35377
35398
  }
35378
35399
  _shouldAcceptMessageFromBus(senderNodeId, targetNodeId) {
35379
35400
  if (this._isWildcardTarget()) {
@@ -35393,7 +35414,9 @@
35393
35414
  return true;
35394
35415
  }
35395
35416
  const expectedSender = this.targetNodeId;
35396
- if (expectedSender && expectedSender !== '*' && senderNodeId !== expectedSender) {
35417
+ if (expectedSender &&
35418
+ expectedSender !== '*' &&
35419
+ senderNodeId !== expectedSender) {
35397
35420
  logger$G.debug('inpage_message_rejected', {
35398
35421
  channel: this.channelName,
35399
35422
  connector_id: this.connectorId,
@@ -35760,8 +35783,8 @@
35760
35783
  }
35761
35784
  }
35762
35785
 
35763
- const DEFAULT_UNCONFIGURED_MESSAGE = "Trust store is not configured. Set FAME_CA_CERTS to a PEM value, a file path, a data URI, or an HTTPS bundle URL.";
35764
- const TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE = "TrustStoreProviderFactory";
35786
+ const DEFAULT_UNCONFIGURED_MESSAGE = 'Trust store is not configured. Set FAME_CA_CERTS to a PEM value, a file path, a data URI, or an HTTPS bundle URL.';
35787
+ const TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE = 'TrustStoreProviderFactory';
35765
35788
  class TrustStoreProviderFactory extends AbstractResourceFactory {
35766
35789
  createUnconfiguredProvider(reason) {
35767
35790
  return new NoopTrustStoreProvider(reason ?? DEFAULT_UNCONFIGURED_MESSAGE);
@@ -39372,7 +39395,8 @@
39372
39395
  const hasSignature = Boolean(envelope.sec?.sig);
39373
39396
  if (!hasSignature) {
39374
39397
  const nodeSid = node.sid;
39375
- const envelopeSid = envelope.sid;
39398
+ const envelopeSid = envelope
39399
+ .sid;
39376
39400
  const isLocalUnsignedSelfEnvelope = localContext.originType === DeliveryOriginType.LOCAL &&
39377
39401
  typeof nodeSid === 'string' &&
39378
39402
  nodeSid.length > 0 &&
@@ -42352,14 +42376,16 @@
42352
42376
  type,
42353
42377
  purpose,
42354
42378
  };
42355
- const channelValue = candidate.channelName ?? candidate['channel_name'];
42379
+ const channelValue = candidate.channelName ??
42380
+ candidate['channel_name'];
42356
42381
  if (channelValue !== undefined) {
42357
42382
  if (typeof channelValue !== 'string' || channelValue.trim().length === 0) {
42358
42383
  throw new TypeError('InPageConnectionGrant "channelName" must be a non-empty string when provided');
42359
42384
  }
42360
42385
  result.channelName = channelValue.trim();
42361
42386
  }
42362
- const inboxValue = candidate.inboxCapacity ?? candidate['inbox_capacity'];
42387
+ const inboxValue = candidate.inboxCapacity ??
42388
+ candidate['inbox_capacity'];
42363
42389
  if (inboxValue !== undefined) {
42364
42390
  if (typeof inboxValue !== 'number' ||
42365
42391
  !Number.isFinite(inboxValue) ||
@@ -42897,7 +42923,8 @@
42897
42923
  const normalized = this._normalizeConfig(config);
42898
42924
  const options = (factoryArgs[0] ?? {});
42899
42925
  const normalizedLocalNodeFromConfig = this._normalizeNodeId(normalized.localNodeId);
42900
- const localNodeId = this._normalizeNodeId(options.localNodeId) ?? normalizedLocalNodeFromConfig;
42926
+ const localNodeId = this._normalizeNodeId(options.localNodeId) ??
42927
+ normalizedLocalNodeFromConfig;
42901
42928
  if (!localNodeId) {
42902
42929
  throw new Error('InPageConnectorFactory requires a localNodeId from config or create() options');
42903
42930
  }
@@ -43073,10 +43100,12 @@
43073
43100
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
43074
43101
  };
43075
43102
  const channelCandidate = record.channelName ?? record['channel_name'];
43076
- if (typeof channelCandidate === 'string' && channelCandidate.trim().length > 0) {
43103
+ if (typeof channelCandidate === 'string' &&
43104
+ channelCandidate.trim().length > 0) {
43077
43105
  config.channelName = channelCandidate.trim();
43078
43106
  }
43079
- const inboxCandidate = record.inboxCapacity ?? record['inbox_capacity'];
43107
+ const inboxCandidate = record.inboxCapacity ??
43108
+ record['inbox_capacity'];
43080
43109
  if (typeof inboxCandidate === 'number' &&
43081
43110
  Number.isFinite(inboxCandidate) &&
43082
43111
  inboxCandidate > 0) {
@@ -43100,9 +43129,11 @@
43100
43129
  throw new Error('BroadcastChannelConnectorFactory requires a configuration');
43101
43130
  }
43102
43131
  const normalized = this._normalizeConfig(config);
43103
- const options = (factoryArgs[0] ?? {});
43132
+ const options = (factoryArgs[0] ??
43133
+ {});
43104
43134
  const normalizedLocalNodeFromConfig = this._normalizeNodeId(normalized.localNodeId);
43105
- const localNodeId = this._normalizeNodeId(options.localNodeId) ?? normalizedLocalNodeFromConfig;
43135
+ const localNodeId = this._normalizeNodeId(options.localNodeId) ??
43136
+ normalizedLocalNodeFromConfig;
43106
43137
  if (!localNodeId) {
43107
43138
  throw new Error('BroadcastChannelConnectorFactory requires a localNodeId from config or create() options');
43108
43139
  }
@@ -43127,6 +43158,7 @@
43127
43158
  inboxCapacity,
43128
43159
  localNodeId,
43129
43160
  initialTargetNodeId: resolvedTarget,
43161
+ passive: normalized.passive,
43130
43162
  };
43131
43163
  const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
43132
43164
  if (options.authorization) {
@@ -43165,6 +43197,9 @@
43165
43197
  if (normalizedLocalNodeId) {
43166
43198
  normalized.localNodeId = normalizedLocalNodeId;
43167
43199
  }
43200
+ if (typeof candidate.passive === 'boolean') {
43201
+ normalized.passive = candidate.passive;
43202
+ }
43168
43203
  if (typeof candidate.flowControl === 'boolean') {
43169
43204
  normalized.flowControl = candidate.flowControl;
43170
43205
  }
@@ -43590,7 +43625,9 @@
43590
43625
  typeof channelCandidate === 'string' && channelCandidate.trim().length > 0
43591
43626
  ? channelCandidate.trim()
43592
43627
  : DEFAULT_CHANNEL$3;
43593
- const normalizedCapacity = typeof inboxCandidate === 'number' && Number.isFinite(inboxCandidate) && inboxCandidate > 0
43628
+ const normalizedCapacity = typeof inboxCandidate === 'number' &&
43629
+ Number.isFinite(inboxCandidate) &&
43630
+ inboxCandidate > 0
43594
43631
  ? Math.floor(inboxCandidate)
43595
43632
  : DEFAULT_INBOX_CAPACITY$3;
43596
43633
  this._inboxCapacity = normalizedCapacity;
@@ -43865,7 +43902,8 @@
43865
43902
  if (grant.type === INPAGE_CONNECTION_GRANT_TYPE) {
43866
43903
  return inPageGrantToConnectorConfig(grant);
43867
43904
  }
43868
- if (typeof grant?.toConnectorConfig === 'function') {
43905
+ if (typeof grant
43906
+ ?.toConnectorConfig === 'function') {
43869
43907
  return grant.toConnectorConfig();
43870
43908
  }
43871
43909
  throw new Error(`Unsupported grant type: ${grant.type}`);
@@ -44019,7 +44057,9 @@
44019
44057
  : DEFAULT_CHANNEL$2;
44020
44058
  const rawInbox = record.inboxCapacity ?? record['inbox_capacity'];
44021
44059
  let inboxCapacity = DEFAULT_INBOX_CAPACITY$2;
44022
- if (typeof rawInbox === 'number' && Number.isFinite(rawInbox) && rawInbox > 0) {
44060
+ if (typeof rawInbox === 'number' &&
44061
+ Number.isFinite(rawInbox) &&
44062
+ rawInbox > 0) {
44023
44063
  inboxCapacity = Math.floor(rawInbox);
44024
44064
  }
44025
44065
  else if (typeof rawInbox === 'string') {
@@ -44047,9 +44087,7 @@
44047
44087
  }
44048
44088
  async create(config, ...factoryArgs) {
44049
44089
  const normalized = normalizeConfig$r(config);
44050
- const [{ InPageListener }] = await Promise.all([
44051
- getInPageListenerModule(),
44052
- ]);
44090
+ const [{ InPageListener }] = await Promise.all([getInPageListenerModule()]);
44053
44091
  return new InPageListener({
44054
44092
  channelName: normalized.channelName,
44055
44093
  inboxCapacity: normalized.inboxCapacity,
@@ -44067,9 +44105,7 @@
44067
44105
  const logger$o = getLogger('naylence.fame.connector.broadcast_channel_listener');
44068
44106
  const DEFAULT_CHANNEL$1 = 'naylence-fabric';
44069
44107
  const DEFAULT_INBOX_CAPACITY$1 = 2048;
44070
- const RESPONSE_TYPE_MASK = FameResponseType.ACK |
44071
- FameResponseType.REPLY |
44072
- FameResponseType.STREAM;
44108
+ const RESPONSE_TYPE_MASK = FameResponseType.ACK | FameResponseType.REPLY | FameResponseType.STREAM;
44073
44109
  const isBrowserEnvironment$1 = () => typeof window !== 'undefined' &&
44074
44110
  typeof BroadcastChannel !== 'undefined' &&
44075
44111
  typeof MessageEvent !== 'undefined';
@@ -44283,9 +44319,7 @@
44283
44319
  return null;
44284
44320
  }
44285
44321
  })();
44286
- if (error instanceof ZodError &&
44287
- decoded &&
44288
- decoded.length > 0) {
44322
+ if (error instanceof ZodError && decoded && decoded.length > 0) {
44289
44323
  try {
44290
44324
  const reparsed = JSON.parse(decoded);
44291
44325
  const candidate = reparsed.rtype;
@@ -44508,11 +44542,19 @@
44508
44542
  ? Math.floor(initialWindowCandidate)
44509
44543
  : undefined;
44510
44544
  const initialTargetNodeId = this._normalizeNodeId(targetCandidate) ?? targetSystemId;
44545
+ const passive = typeof passiveCandidate === 'boolean' ? passiveCandidate : true;
44546
+ logger$o.debug('broadcast_channel_listener_building_connector_config', {
44547
+ system_id: systemId,
44548
+ channel_name: channelName,
44549
+ passive,
44550
+ has_base_config: !!baseConfig,
44551
+ passive_candidate: passiveCandidate,
44552
+ });
44511
44553
  return {
44512
44554
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
44513
44555
  channelName,
44514
44556
  inboxCapacity,
44515
- passive: typeof passiveCandidate === 'boolean' ? passiveCandidate : true,
44557
+ passive,
44516
44558
  initialWindow,
44517
44559
  localNodeId,
44518
44560
  initialTargetNodeId,
@@ -44625,7 +44667,9 @@
44625
44667
  : DEFAULT_CHANNEL;
44626
44668
  const rawInbox = record.inboxCapacity ?? record['inbox_capacity'];
44627
44669
  let inboxCapacity = DEFAULT_INBOX_CAPACITY;
44628
- if (typeof rawInbox === 'number' && Number.isFinite(rawInbox) && rawInbox > 0) {
44670
+ if (typeof rawInbox === 'number' &&
44671
+ Number.isFinite(rawInbox) &&
44672
+ rawInbox > 0) {
44629
44673
  inboxCapacity = Math.floor(rawInbox);
44630
44674
  }
44631
44675
  else if (typeof rawInbox === 'string') {
@@ -48111,19 +48155,23 @@
48111
48155
  normalized.clientSecretConfig = normalizeSecretSource(clientSecretSource);
48112
48156
  }
48113
48157
  const audienceCandidate = candidate.audience ?? candidate.aud;
48114
- if (typeof audienceCandidate === 'string' && audienceCandidate.trim().length > 0) {
48158
+ if (typeof audienceCandidate === 'string' &&
48159
+ audienceCandidate.trim().length > 0) {
48115
48160
  normalized.audience = audienceCandidate.trim();
48116
48161
  }
48117
48162
  const codeChallengeMethod = candidate.codeChallengeMethod ?? candidate.code_challenge_method;
48118
- if (typeof codeChallengeMethod === 'string' && codeChallengeMethod.trim().length > 0) {
48163
+ if (typeof codeChallengeMethod === 'string' &&
48164
+ codeChallengeMethod.trim().length > 0) {
48119
48165
  normalized.codeChallengeMethod = codeChallengeMethod.trim();
48120
48166
  }
48121
48167
  const codeVerifierLength = candidate.codeVerifierLength ?? candidate.code_verifier_length;
48122
- if (typeof codeVerifierLength === 'number' && Number.isFinite(codeVerifierLength)) {
48168
+ if (typeof codeVerifierLength === 'number' &&
48169
+ Number.isFinite(codeVerifierLength)) {
48123
48170
  normalized.codeVerifierLength = codeVerifierLength;
48124
48171
  }
48125
48172
  const clockSkewSeconds = candidate.clockSkewSeconds ?? candidate.clock_skew_seconds;
48126
- if (typeof clockSkewSeconds === 'number' && Number.isFinite(clockSkewSeconds)) {
48173
+ if (typeof clockSkewSeconds === 'number' &&
48174
+ Number.isFinite(clockSkewSeconds)) {
48127
48175
  normalized.clockSkewSeconds = clockSkewSeconds;
48128
48176
  }
48129
48177
  const loginHintParam = candidate.loginHintParam ?? candidate.login_hint_param;
@@ -48168,8 +48216,8 @@
48168
48216
  options.audience = normalized.audience;
48169
48217
  }
48170
48218
  if (normalized.codeChallengeMethod) {
48171
- options.codeChallengeMethod = normalized.codeChallengeMethod
48172
- .toUpperCase();
48219
+ options.codeChallengeMethod =
48220
+ normalized.codeChallengeMethod.toUpperCase();
48173
48221
  }
48174
48222
  if (normalized.codeVerifierLength) {
48175
48223
  options.codeVerifierLength = normalized.codeVerifierLength;
@@ -49926,14 +49974,14 @@
49926
49974
 
49927
49975
  const FACTORY_META$d = {
49928
49976
  base: TRUST_STORE_PROVIDER_FACTORY_BASE_TYPE,
49929
- key: "NoopTrustStoreProvider",
49977
+ key: 'NoopTrustStoreProvider',
49930
49978
  isDefault: true,
49931
49979
  priority: 10,
49932
49980
  };
49933
49981
  class NoopTrustStoreProviderFactory extends TrustStoreProviderFactory {
49934
49982
  constructor() {
49935
49983
  super(...arguments);
49936
- this.type = "NoopTrustStoreProvider";
49984
+ this.type = 'NoopTrustStoreProvider';
49937
49985
  this.isDefault = true;
49938
49986
  this.priority = 10;
49939
49987
  }
@@ -53327,8 +53375,7 @@
53327
53375
  const scopes = normalizeScopes(camel.scopes) ??
53328
53376
  normalizeScopes(snake.scopes ?? snake.scope) ??
53329
53377
  DEFAULT_SCOPES.slice();
53330
- const audience = coerceString(camel.audience) ??
53331
- coerceString(snake.audience ?? snake.aud);
53378
+ const audience = coerceString(camel.audience) ?? coerceString(snake.audience ?? snake.aud);
53332
53379
  const fetchImpl = (camel.fetchImpl ?? snake.fetch_impl);
53333
53380
  const clockSkewSeconds = coerceNumber(camel.clockSkewSeconds) ??
53334
53381
  coerceNumber(snake.clock_skew_seconds) ??