@naylence/agent-sdk 0.3.5-test.101 → 0.3.5-test.102

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.
@@ -15674,12 +15674,12 @@
15674
15674
  // --- END ENV SHIM ---
15675
15675
 
15676
15676
  // This file is auto-generated during build - do not edit manually
15677
- // Generated from package.json version: 0.3.6
15677
+ // Generated from package.json version: 0.3.6-test.107
15678
15678
  /**
15679
15679
  * The package version, injected at build time.
15680
15680
  * @internal
15681
15681
  */
15682
- const VERSION$1 = '0.3.6';
15682
+ const VERSION$1 = '0.3.6-test.107';
15683
15683
 
15684
15684
  /**
15685
15685
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -17275,6 +17275,50 @@
17275
17275
  });
17276
17276
  }
17277
17277
 
17278
+ function isModuleNotFoundError(error) {
17279
+ if (!(error instanceof Error)) {
17280
+ return false;
17281
+ }
17282
+ const message = error.message || '';
17283
+ if (message.includes('Cannot find module') ||
17284
+ message.includes('ERR_MODULE_NOT_FOUND') ||
17285
+ message.includes('MODULE_NOT_FOUND')) {
17286
+ return true;
17287
+ }
17288
+ const code = error.code;
17289
+ if (typeof code === 'string') {
17290
+ return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
17291
+ }
17292
+ return false;
17293
+ }
17294
+ /**
17295
+ * Wraps a dynamic import loader and enriches "module not found" failures with an actionable error message.
17296
+ */
17297
+ async function safeImport(loader, dependencyNameOrOptions, maybeOptions) {
17298
+ const options = typeof dependencyNameOrOptions === 'string'
17299
+ ? { dependencyName: dependencyNameOrOptions, ...(maybeOptions ?? {}) }
17300
+ : dependencyNameOrOptions;
17301
+ const dependencyName = options.dependencyName;
17302
+ try {
17303
+ return await loader();
17304
+ }
17305
+ catch (error) {
17306
+ if (isModuleNotFoundError(error)) {
17307
+ const message = options.helpMessage ??
17308
+ `Missing optional dependency "${dependencyName}". Install it to enable this feature.`;
17309
+ const enrichedError = new Error(message);
17310
+ try {
17311
+ enrichedError.cause = error;
17312
+ }
17313
+ catch {
17314
+ // Ignore environments that do not support attaching a cause.
17315
+ }
17316
+ throw enrichedError;
17317
+ }
17318
+ throw error;
17319
+ }
17320
+ }
17321
+
17278
17322
  /**
17279
17323
  * flow_controller.ts - credit window management with cooperative back-pressure.
17280
17324
  *
@@ -18209,50 +18253,6 @@
18209
18253
  return SecretSource.normalize(value);
18210
18254
  }
18211
18255
 
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
18256
  const indexedDBConfigSchema = object({
18257
18257
  type: literal('IndexedDBStorageProvider')
18258
18258
  .default('IndexedDBStorageProvider'),
@@ -22312,9 +22312,9 @@
22312
22312
  });
22313
22313
  await this.markDoneSince(this.replyFutures, trackedEnvelope.originalEnvelope.id, this.replyDoneSince);
22314
22314
  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
- }
22315
+ // Note: ACK is already sent in onCorrelatedMessage (lines 655-657)
22316
+ // when the reply envelope is first delivered. No need to send it again here.
22317
+ // Removing this duplicate sendAck call fixes the duplicate DeliveryAck bug.
22318
22318
  for (const handler of this.eventHandlers) {
22319
22319
  await handler.onEnvelopeReplied?.(trackedEnvelope, envelope);
22320
22320
  }
@@ -24652,6 +24652,7 @@
24652
24652
  local_node_id: this.localNodeId,
24653
24653
  target_node_id: this.targetNodeId ?? null,
24654
24654
  inbox_capacity: preferredCapacity,
24655
+ passive: config.passive ?? false,
24655
24656
  timestamp: new Date().toISOString(),
24656
24657
  });
24657
24658
  this.onMsg = (event) => {
@@ -25492,6 +25493,20 @@
25492
25493
  await connector.start(this.wrappedHandler);
25493
25494
  this.connector = connector;
25494
25495
  const callbackGrants = this.node.gatherSupportedCallbackGrants();
25496
+ logger$Z.debug('callback_grants_before_augmentation', {
25497
+ count: callbackGrants.length,
25498
+ types: callbackGrants.map(g => g.type),
25499
+ });
25500
+ // Check if we should create a broadcast callback grant before processing connection grants
25501
+ // This prevents adding duplicate broadcast grants
25502
+ const shouldAddBroadcastGrant = this.shouldAdvertiseBroadcastGrant(grant, callbackGrants);
25503
+ const broadcastCallbackGrant = shouldAddBroadcastGrant
25504
+ ? this.createBroadcastCallbackGrant(grant)
25505
+ : null;
25506
+ logger$Z.debug('broadcast_callback_grant_check', {
25507
+ should_add: shouldAddBroadcastGrant,
25508
+ grant_created: !!broadcastCallbackGrant,
25509
+ });
25495
25510
  // Include admission client's connection grants as callback grants
25496
25511
  // This ensures DirectAdmissionClient grants are available for grant selection
25497
25512
  if (welcome.frame.connectionGrants && Array.isArray(welcome.frame.connectionGrants)) {
@@ -25501,16 +25516,31 @@
25501
25516
  const isDuplicate = callbackGrants.some(existing => JSON.stringify(existing) === JSON.stringify(grant));
25502
25517
  if (!isDuplicate) {
25503
25518
  callbackGrants.push(grant);
25519
+ logger$Z.debug('added_connection_grant_as_callback', {
25520
+ type: grant.type,
25521
+ });
25522
+ }
25523
+ else {
25524
+ logger$Z.debug('skipped_duplicate_connection_grant', {
25525
+ type: grant.type,
25526
+ });
25504
25527
  }
25505
25528
  }
25506
25529
  }
25507
25530
  }
25508
- if (this.shouldAdvertiseBroadcastGrant(grant, callbackGrants)) {
25509
- const augmented = this.createBroadcastCallbackGrant(grant);
25510
- if (augmented) {
25511
- callbackGrants.push(augmented);
25512
- }
25531
+ // Add broadcast grant after connection grants to ensure we don't duplicate
25532
+ // any broadcast grants that may have been in connectionGrants
25533
+ if (broadcastCallbackGrant && this.shouldAdvertiseBroadcastGrant(grant, callbackGrants)) {
25534
+ callbackGrants.push(broadcastCallbackGrant);
25535
+ logger$Z.debug('added_broadcast_callback_grant');
25536
+ }
25537
+ else if (broadcastCallbackGrant) {
25538
+ logger$Z.debug('skipped_duplicate_broadcast_callback_grant');
25513
25539
  }
25540
+ logger$Z.debug('callback_grants_after_augmentation', {
25541
+ count: callbackGrants.length,
25542
+ types: callbackGrants.map(g => g.type),
25543
+ });
25514
25544
  const attachInfo = await this.attachClient.attach(this.node, this.outboundOriginType, connector, welcome.frame, this.wrappedHandler, this.getKeys() ?? undefined, callbackGrants);
25515
25545
  this.targetSystemId = attachInfo.targetSystemId ?? null;
25516
25546
  if (this.targetSystemId) {
@@ -27306,15 +27336,29 @@
27306
27336
  constructor(options = {}) {
27307
27337
  this.buffer = [];
27308
27338
  this.inHandshake = false;
27339
+ this.expectedSystemId = null;
27309
27340
  this.timeoutMs = options.timeoutMs ?? 10000;
27310
27341
  this.attachmentKeyValidator = options.attachmentKeyValidator;
27311
27342
  this.replicaStickinessManager = options.replicaStickinessManager ?? null;
27312
27343
  }
27313
27344
  async attach(node, originType, connector, welcomeFrame, finalHandler, keys, callbackGrants) {
27314
27345
  this.inHandshake = true;
27346
+ this.expectedSystemId = welcomeFrame.systemId;
27315
27347
  const interimHandler = async (envelope, context) => {
27316
27348
  if (this.inHandshake) {
27317
- this.buffer.push(envelope);
27349
+ // Filter: only buffer frames related to our systemId or frames without systemId info
27350
+ const frameSystemId = envelope.frame?.systemId;
27351
+ if (!frameSystemId || frameSystemId === this.expectedSystemId) {
27352
+ this.buffer.push(envelope);
27353
+ }
27354
+ else {
27355
+ // Silently ignore frames from other agents during concurrent handshakes
27356
+ logger$W.debug('handshake_ignoring_frame_from_different_system', {
27357
+ frame_type: envelope.frame.type,
27358
+ frame_system_id: frameSystemId,
27359
+ expected_system_id: this.expectedSystemId,
27360
+ });
27361
+ }
27318
27362
  return null;
27319
27363
  }
27320
27364
  return finalHandler(envelope, context);
@@ -27441,6 +27485,7 @@
27441
27485
  parent_id: ackFrame.targetSystemId,
27442
27486
  });
27443
27487
  this.inHandshake = false;
27488
+ this.expectedSystemId = null;
27444
27489
  await connector.replaceHandler(finalHandler);
27445
27490
  while (this.buffer.length > 0) {
27446
27491
  const bufferedEnvelope = this.buffer.shift();
@@ -27517,9 +27562,20 @@
27517
27562
  if (envelope.frame.type === 'NodeAttachAck') {
27518
27563
  return envelope;
27519
27564
  }
27520
- logger$W.error('unexpected_frame_during_handshake', {
27521
- frame_type: envelope.frame.type,
27522
- });
27565
+ // NodeAttach frames during handshake are expected in multi-agent scenarios
27566
+ // where multiple agents attach concurrently to the same channel
27567
+ if (envelope.frame.type === 'NodeAttach') {
27568
+ logger$W.debug('handshake_ignoring_concurrent_attach', {
27569
+ frame_type: envelope.frame.type,
27570
+ frame_system_id: envelope.frame?.systemId ?? 'unknown',
27571
+ });
27572
+ }
27573
+ else {
27574
+ // Other unexpected frames are still logged as errors
27575
+ logger$W.error('unexpected_frame_during_handshake', {
27576
+ frame_type: envelope.frame.type,
27577
+ });
27578
+ }
27523
27579
  }
27524
27580
  await delay$2(HANDSHAKE_POLL_INTERVAL_MS);
27525
27581
  }
@@ -43127,6 +43183,7 @@
43127
43183
  inboxCapacity,
43128
43184
  localNodeId,
43129
43185
  initialTargetNodeId: resolvedTarget,
43186
+ passive: normalized.passive,
43130
43187
  };
43131
43188
  const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
43132
43189
  if (options.authorization) {
@@ -43165,6 +43222,9 @@
43165
43222
  if (normalizedLocalNodeId) {
43166
43223
  normalized.localNodeId = normalizedLocalNodeId;
43167
43224
  }
43225
+ if (typeof candidate.passive === 'boolean') {
43226
+ normalized.passive = candidate.passive;
43227
+ }
43168
43228
  if (typeof candidate.flowControl === 'boolean') {
43169
43229
  normalized.flowControl = candidate.flowControl;
43170
43230
  }
@@ -44508,11 +44568,19 @@
44508
44568
  ? Math.floor(initialWindowCandidate)
44509
44569
  : undefined;
44510
44570
  const initialTargetNodeId = this._normalizeNodeId(targetCandidate) ?? targetSystemId;
44571
+ const passive = typeof passiveCandidate === 'boolean' ? passiveCandidate : true;
44572
+ logger$o.debug('broadcast_channel_listener_building_connector_config', {
44573
+ system_id: systemId,
44574
+ channel_name: channelName,
44575
+ passive,
44576
+ has_base_config: !!baseConfig,
44577
+ passive_candidate: passiveCandidate,
44578
+ });
44511
44579
  return {
44512
44580
  type: BROADCAST_CHANNEL_CONNECTOR_TYPE,
44513
44581
  channelName,
44514
44582
  inboxCapacity,
44515
- passive: typeof passiveCandidate === 'boolean' ? passiveCandidate : true,
44583
+ passive,
44516
44584
  initialWindow,
44517
44585
  localNodeId,
44518
44586
  initialTargetNodeId,