@bpmsoftwaresolutions/ai-engine-client 1.1.62 → 1.1.63

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +211 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmsoftwaresolutions/ai-engine-client",
3
- "version": "1.1.62",
3
+ "version": "1.1.63",
4
4
  "description": "Thin npm client for the AI Engine operator and retrieval APIs",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -106,6 +106,31 @@ function normalizeMessageKind(value) {
106
106
  });
107
107
  }
108
108
 
109
+ function normalizeConnectionFirstMessageKind(value, transferKind) {
110
+ const text = cleanText(value);
111
+ if (!text) {
112
+ return normalizeMessageKind(transferKind === 'handoff' ? 'handoff' : 'request');
113
+ }
114
+ const normalized = text.toLowerCase();
115
+ const aliases = {
116
+ connection_request: 'request',
117
+ connection_accepted: 'response',
118
+ connection_acceptance: 'response',
119
+ handoff_request: 'handoff',
120
+ handoff_acceptance: 'response',
121
+ handoff_response: 'response',
122
+ acceptance: 'response',
123
+ decline: 'response',
124
+ };
125
+ const candidate = aliases[normalized] || text;
126
+ try {
127
+ return normalizeMessageKind(candidate);
128
+ } catch (error) {
129
+ void error;
130
+ return normalizeMessageKind(transferKind === 'handoff' ? 'handoff' : 'request');
131
+ }
132
+ }
133
+
109
134
  function normalizeTransferKind(value) {
110
135
  return normalizeEnum(value, AGENT_COMMUNICATION_TRANSFER_KINDS, 'upstream_remediation', 'transfer_kind', {
111
136
  remediation_request: 'upstream_remediation',
@@ -379,7 +404,7 @@ function buildEligibilityError(message, details = {}) {
379
404
  }
380
405
 
381
406
  export class AIEngineClient {
382
- constructor({ baseUrl, accessToken, tokenProvider, apiKey, clientId, actorId, fetchImpl, timeoutMs } = {}) {
407
+ constructor({ baseUrl, accessToken, tokenProvider, apiKey, clientId, actorId, agentSessionId, fetchImpl, timeoutMs } = {}) {
383
408
  if (!baseUrl) throw new Error('baseUrl is required.');
384
409
  this.baseUrl = trimTrailingSlash(baseUrl);
385
410
  this.accessToken = accessToken || null;
@@ -387,6 +412,7 @@ export class AIEngineClient {
387
412
  this.apiKey = apiKey || null;
388
413
  this.clientId = clientId || null;
389
414
  this.actorId = actorId || 'sdk:npm-ai-engine-client';
415
+ this.agentSessionId = cleanText(agentSessionId) || null;
390
416
  this.fetchImpl = fetchImpl || globalThis.fetch;
391
417
  this.timeoutMs = timeoutMs || DEFAULT_TIMEOUT_MS;
392
418
  this.clientVersion = AI_ENGINE_CLIENT_VERSION;
@@ -495,6 +521,7 @@ export class AIEngineClient {
495
521
  stopCoordinationPingPong: (request) => this.stopCoordinationPingPong(request),
496
522
  checkCoordinationPingPongPreflight: (request) => this.checkCoordinationPingPongPreflight(request),
497
523
  connectToTransferChannel: (request) => this.connectToTransferChannel(request),
524
+ startAgentConnection: (request) => this.startAgentConnection(request),
498
525
  respondToMessageWatch: (request) => this.respondToMessageWatch(request),
499
526
  };
500
527
  this.collaboration = {
@@ -506,6 +533,7 @@ export class AIEngineClient {
506
533
  beginImplementation: (request) => this.beginCollaborationImplementation(request),
507
534
  requestClosure: (request) => this.requestCollaborationClosure(request),
508
535
  openAgentChannel: (request) => this.openAgentChannel(request),
536
+ startAgentConnection: (request) => this.startAgentConnection(request),
509
537
  acceptAgentChannel: (request) => this.acceptAgentChannel(request),
510
538
  postAgentHeartbeat: (request) => this.postAgentHeartbeat(request),
511
539
  postAgentMessage: (request) => this.postAgentMessage(request),
@@ -545,6 +573,9 @@ export class AIEngineClient {
545
573
  apiKey: options.apiKey || process.env.AI_ENGINE_API_KEY || null,
546
574
  clientId: options.clientId || process.env.AI_ENGINE_CLIENT_ID || null,
547
575
  actorId: options.actorId || process.env.AI_ENGINE_ACTOR_ID || 'sdk:npm-ai-engine-client',
576
+ agentSessionId: options.agentSessionId || process.env.GOVERNANCE_SESSION_ID || process.env.AI_ENGINE_SESSION_ID || null,
577
+ fetchImpl: options.fetchImpl || null,
578
+ timeoutMs: options.timeoutMs,
548
579
  });
549
580
  }
550
581
 
@@ -1034,7 +1065,7 @@ export class AIEngineClient {
1034
1065
  participant_role: cleanText(participant_role) || cleanText(participantRole),
1035
1066
  current_phase: cleanText(current_phase) || cleanText(currentPhase),
1036
1067
  current_task_summary: cleanText(current_task_summary) || cleanText(currentTaskSummary),
1037
- agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
1068
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId) || this.agentSessionId,
1038
1069
  actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
1039
1070
  observed_at: cleanText(observed_at) || cleanText(observedAt),
1040
1071
  metadata: isPlainObject(metadata) ? metadata : {},
@@ -1080,7 +1111,7 @@ export class AIEngineClient {
1080
1111
  participant_role: cleanText(participant_role) || cleanText(participantRole),
1081
1112
  current_phase: cleanText(current_phase) || cleanText(currentPhase),
1082
1113
  current_task_summary: cleanText(current_task_summary) || cleanText(currentTaskSummary),
1083
- agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
1114
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId) || this.agentSessionId,
1084
1115
  actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
1085
1116
  observed_at: cleanText(observed_at) || cleanText(observedAt),
1086
1117
  metadata: isPlainObject(metadata) ? metadata : {},
@@ -1212,7 +1243,7 @@ export class AIEngineClient {
1212
1243
  proposal_id: cleanText(proposal_id) || cleanText(proposalId) || cleanText(collaboration_proposal_id) || cleanText(collaborationProposalId),
1213
1244
  mode: cleanText(mode) || 'communication_participant',
1214
1245
  participant_label: cleanText(participant_label) || cleanText(participantLabel) || cleanText(participant_role_key) || cleanText(participantRoleKey),
1215
- agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
1246
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId) || this.agentSessionId,
1216
1247
  actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
1217
1248
  phase: cleanText(current_phase) || cleanText(currentPhase) || cleanText(phase),
1218
1249
  current_task_summary: cleanText(current_task_summary) || cleanText(currentTaskSummary),
@@ -1231,6 +1262,169 @@ export class AIEngineClient {
1231
1262
  return this.connectToTransferChannel(request);
1232
1263
  }
1233
1264
 
1265
+ async startAgentConnection({
1266
+ workflowRunId,
1267
+ workflow_run_id,
1268
+ upstreamAgent,
1269
+ upstream_agent,
1270
+ upstreamAgentSessionId,
1271
+ upstream_agent_session_id,
1272
+ upstreamAgentId,
1273
+ upstream_agent_id,
1274
+ upstreamRole,
1275
+ upstream_role,
1276
+ recipientMode,
1277
+ recipient_mode,
1278
+ purpose,
1279
+ objective,
1280
+ mode = 'handoff',
1281
+ firstMessage = {},
1282
+ first_message = {},
1283
+ expectedMessageKind,
1284
+ expected_message_kind,
1285
+ participantRole,
1286
+ participant_role,
1287
+ participantLabel,
1288
+ participant_label,
1289
+ senderAgentSessionId,
1290
+ sender_agent_session_id,
1291
+ senderActorSessionId,
1292
+ sender_actor_session_id,
1293
+ cleanupPolicy,
1294
+ cleanup_policy,
1295
+ staleAfterSeconds = 300,
1296
+ stale_after_seconds,
1297
+ operatorNudge,
1298
+ operator_nudge,
1299
+ metadata = {},
1300
+ } = {}) {
1301
+ const normalizedFirstMessage = isPlainObject(firstMessage) ? firstMessage : isPlainObject(first_message) ? first_message : {};
1302
+ const normalizedTransferKind = normalizeTransferKind(cleanText(mode) || 'handoff');
1303
+ let normalizedWorkflowRunId = cleanText(workflow_run_id) || cleanText(workflowRunId);
1304
+ if (!normalizedWorkflowRunId) {
1305
+ try {
1306
+ const status = await this.currentWorkflowStatus();
1307
+ normalizedWorkflowRunId =
1308
+ cleanText(status?.workflow_run_id)
1309
+ || cleanText(status?.workflowRunId)
1310
+ || cleanText(status?.current_workflow_run_id)
1311
+ || cleanText(status?.currentWorkflowRunId)
1312
+ || cleanText(status?.summary?.workflow_run_id)
1313
+ || cleanText(status?.summary?.workflowRunId)
1314
+ || cleanText(status?.summary?.current_workflow_run_id)
1315
+ || cleanText(status?.summary?.currentWorkflowRunId);
1316
+ } catch (error) {
1317
+ void error;
1318
+ }
1319
+ }
1320
+ if (!normalizedWorkflowRunId) {
1321
+ throw new Error('workflow_run_id is required to start an agent connection.');
1322
+ }
1323
+ const normalizedUpstreamAgent = cleanText(upstream_agent) || cleanText(upstreamAgent) || cleanText(upstream_agent_session_id) || cleanText(upstreamAgentSessionId) || cleanText(upstream_agent_id) || cleanText(upstreamAgentId);
1324
+ const normalizedRecipientMode = cleanText(recipient_mode) || cleanText(recipientMode) || (normalizedUpstreamAgent ? 'agent_session' : 'role');
1325
+ const normalizedParticipantRole = cleanText(participant_role) || cleanText(participantRole) || 'downstream';
1326
+ const normalizedParticipantLabel = cleanText(participant_label) || cleanText(participantLabel) || normalizedParticipantRole;
1327
+ const normalizedSenderAgentSessionId = cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId;
1328
+ const normalizedSenderActorSessionId = cleanText(sender_actor_session_id) || cleanText(senderActorSessionId);
1329
+ const normalizedFirstMessageKind = normalizeConnectionFirstMessageKind(
1330
+ cleanText(normalizedFirstMessage.kind) || cleanText(normalizedFirstMessage.message_kind) || cleanText(normalizedFirstMessage.messageKind),
1331
+ normalizedTransferKind,
1332
+ );
1333
+ const normalizedExpectedMessageKind = cleanText(expected_message_kind) || cleanText(expectedMessageKind) || 'connection_accepted';
1334
+ const normalizedObjective = cleanText(objective) || cleanText(purpose) || cleanText(normalizedFirstMessage.body) || cleanText(normalizedFirstMessage.body_markdown) || cleanText(normalizedFirstMessage.bodyMarkdown) || 'Establish governed coordination.';
1335
+ const transferResult = await this.transferWorkPacket({
1336
+ workflowRunId: normalizedWorkflowRunId,
1337
+ transferKind: normalizedTransferKind,
1338
+ objective: normalizedObjective,
1339
+ requestedOutcome: cleanText(purpose) || normalizedObjective,
1340
+ target: {
1341
+ intent: normalizedTransferKind,
1342
+ recipient_mode: normalizedRecipientMode,
1343
+ preferred_agent_session_id: normalizedUpstreamAgent,
1344
+ preferred_role_key: cleanText(upstream_role) || cleanText(upstreamRole),
1345
+ },
1346
+ artifacts: [],
1347
+ issues: [],
1348
+ expectedEvidence: [],
1349
+ preferredModes: ['inline_payload', 'bundle', 'artifact_refs'],
1350
+ capabilities: {},
1351
+ senderAgentSessionId: normalizedSenderAgentSessionId,
1352
+ senderActorSessionId: normalizedSenderActorSessionId,
1353
+ subject: cleanText(purpose) || normalizedObjective,
1354
+ bodyMarkdown:
1355
+ cleanText(normalizedFirstMessage.body_markdown)
1356
+ || cleanText(normalizedFirstMessage.bodyMarkdown)
1357
+ || cleanText(normalizedFirstMessage.body)
1358
+ || `Connection request: ${normalizedObjective}`,
1359
+ cleanupPolicy: cleanText(cleanup_policy) || cleanText(cleanupPolicy),
1360
+ messageKind: normalizedFirstMessageKind,
1361
+ message_kind: normalizedFirstMessageKind,
1362
+ metadata: isPlainObject(metadata) ? metadata : {},
1363
+ });
1364
+ const transferChannel = transferResult.communication_transfer_channel || {};
1365
+ const connection = await this.connectToTransferChannel({
1366
+ transferChannelId: transferChannel.transfer_channel_id || transferChannel.channel_id || transferResult.channel_id,
1367
+ workTransferPacketId: transferResult.work_transfer_packet?.work_transfer_packet_id || transferResult.packet_id || transferResult.transfer_packet_id,
1368
+ workflowRunId: normalizedWorkflowRunId,
1369
+ participantRole: normalizedParticipantRole,
1370
+ expectedPeerRole: cleanText(upstream_role) || cleanText(upstreamRole) || 'upstream',
1371
+ expectedMessageKind: normalizedExpectedMessageKind,
1372
+ proposalId: transferResult.transfer_negotiation?.proposal_id,
1373
+ mode: 'communication_participant',
1374
+ participantLabel: normalizedParticipantLabel,
1375
+ senderAgentSessionId: normalizedSenderAgentSessionId,
1376
+ senderActorSessionId: normalizedSenderActorSessionId,
1377
+ currentPhase: 'channel_ready',
1378
+ currentTaskSummary: cleanText(purpose) || normalizedObjective,
1379
+ expectedPayload: {
1380
+ purpose: cleanText(purpose) || normalizedObjective,
1381
+ first_message_kind: normalizedFirstMessageKind,
1382
+ first_message_body:
1383
+ cleanText(normalizedFirstMessage.body_markdown)
1384
+ || cleanText(normalizedFirstMessage.bodyMarkdown)
1385
+ || cleanText(normalizedFirstMessage.body)
1386
+ || null,
1387
+ },
1388
+ lastSeenMessageId: transferResult.communication_message?.agent_message_id,
1389
+ staleAfterSeconds: stale_after_seconds ?? staleAfterSeconds,
1390
+ operatorNudge:
1391
+ cleanText(operator_nudge)
1392
+ || cleanText(operatorNudge)
1393
+ || `upstream, please send ${normalizedExpectedMessageKind}.`,
1394
+ observedAt: transferResult.communication_message?.created_at || transferResult.transfer_receipt?.created_at,
1395
+ metadata: {
1396
+ ...(isPlainObject(metadata) ? metadata : {}),
1397
+ start_agent_connection: true,
1398
+ },
1399
+ });
1400
+ const handshake = connection.handshake || {};
1401
+ const status = connection.connected ? 'waiting' : (connection.stop_reason ? 'failed' : 'waiting');
1402
+ const transferPacketId = transferResult.work_transfer_packet?.work_transfer_packet_id || transferResult.transfer_receipt?.transfer_packet_id || transferResult.packet_id || null;
1403
+ const channelId = connection.channel_id || transferChannel.transfer_channel_id || transferChannel.channel_id || null;
1404
+ return {
1405
+ status,
1406
+ channel_id: channelId,
1407
+ transfer_packet_id: transferPacketId,
1408
+ correlation_id: connection.correlation_id || handshake.correlation_id || null,
1409
+ handshake_state: connection.handshake_state || handshake.handshake_state || null,
1410
+ waiting_side: connection.waiting_on || connection.expected_from || handshake.waiting_side || null,
1411
+ expected_message: connection.expected_message_kind || handshake.expected_message_kind || normalizedExpectedMessageKind,
1412
+ last_heartbeat_at: handshake.last_heartbeat_at || connection.collaboration_heartbeat?.observed_at || null,
1413
+ last_receipt_id: handshake.last_receipt_id || transferResult.transfer_receipt?.receipt_id || null,
1414
+ operator_nudge: connection.operator_nudge || handshake.operator_nudge || null,
1415
+ handshake,
1416
+ connection,
1417
+ transfer: transferResult,
1418
+ first_message: {
1419
+ kind: normalizedFirstMessageKind,
1420
+ body: cleanText(normalizedFirstMessage.body_markdown) || cleanText(normalizedFirstMessage.bodyMarkdown) || cleanText(normalizedFirstMessage.body) || null,
1421
+ },
1422
+ transfer_channel: transferChannel,
1423
+ transfer_receipt: transferResult.transfer_receipt || null,
1424
+ communication_message: transferResult.communication_message || null,
1425
+ };
1426
+ }
1427
+
1234
1428
  async _resolveMessageWatchId(request = {}) {
1235
1429
  const directWatchId = cleanText(request.message_watch_id) || cleanText(request.messageWatchId) || cleanText(request.watch_id) || cleanText(request.watchId);
1236
1430
  if (directWatchId) {
@@ -1335,7 +1529,7 @@ export class AIEngineClient {
1335
1529
  workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
1336
1530
  participant_role: cleanText(participant_role) || cleanText(participantRole) || cleanText(role),
1337
1531
  activity_state: cleanText(activity_state) || cleanText(activityState) || 'active',
1338
- agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
1532
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId) || this.agentSessionId,
1339
1533
  actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
1340
1534
  current_phase: cleanText(current_phase) || cleanText(currentPhase) || cleanText(phase),
1341
1535
  current_task_summary: cleanText(current_task_summary) || cleanText(currentTaskSummary),
@@ -1460,7 +1654,7 @@ export class AIEngineClient {
1460
1654
  message_watch_id: cleanText(message_watch_id) || cleanText(messageWatchId) || cleanText(watch_id) || cleanText(watchId),
1461
1655
  expected_message_kind: cleanText(expected_message_kind) || cleanText(expectedMessageKind),
1462
1656
  sender_role: cleanText(sender_role) || cleanText(senderRole) || cleanText(participant_role) || cleanText(participantRole),
1463
- sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
1657
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId,
1464
1658
  sender_actor_session_id: cleanText(sender_actor_session_id) || cleanText(senderActorSessionId),
1465
1659
  message_kind: cleanText(message_kind) || cleanText(messageKind),
1466
1660
  body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
@@ -1636,7 +1830,7 @@ export class AIEngineClient {
1636
1830
  return this._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/collaboration/request-closure`, {
1637
1831
  method: 'POST',
1638
1832
  body: {
1639
- sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
1833
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId,
1640
1834
  sender_actor_session_id: cleanText(sender_actor_session_id) || cleanText(senderActorSessionId),
1641
1835
  closure_reason: cleanText(closure_reason) || cleanText(closureReason),
1642
1836
  evidence_refs: Array.isArray(evidence_refs) ? evidence_refs : evidenceRefs,
@@ -1831,6 +2025,8 @@ export class AIEngineClient {
1831
2025
  sender_agent_session_id,
1832
2026
  senderActorSessionId,
1833
2027
  sender_actor_session_id,
2028
+ messageKind,
2029
+ message_kind,
1834
2030
  subject,
1835
2031
  bodyMarkdown,
1836
2032
  body_markdown,
@@ -1873,8 +2069,9 @@ export class AIEngineClient {
1873
2069
  estimated_payload_kb: Number(estimated_payload_kb ?? estimatedPayloadKb ?? 0) || undefined,
1874
2070
  requires_receipts: Boolean(requires_receipts ?? requiresReceipts),
1875
2071
  supports_hash_validation: Boolean(supports_hash_validation ?? supportsHashValidation),
1876
- sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
2072
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId,
1877
2073
  sender_actor_session_id: cleanText(sender_actor_session_id) || cleanText(senderActorSessionId),
2074
+ message_kind: cleanText(message_kind) || cleanText(messageKind),
1878
2075
  subject: cleanText(subject),
1879
2076
  body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
1880
2077
  parent_thread_id: cleanText(parent_thread_id) || cleanText(parentThreadId),
@@ -2045,7 +2242,7 @@ export class AIEngineClient {
2045
2242
  transfer_channel_id: normalizedTransferChannelId,
2046
2243
  workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
2047
2244
  body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
2048
- sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
2245
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId,
2049
2246
  sender_role: cleanText(sender_role) || cleanText(senderRole),
2050
2247
  recipient_agent_session_id: cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
2051
2248
  recipient_role: cleanText(recipient_role) || cleanText(recipientRole) || cleanText(role),
@@ -2097,7 +2294,7 @@ export class AIEngineClient {
2097
2294
  transfer_channel_id: normalizedTransferChannelId,
2098
2295
  workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
2099
2296
  body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
2100
- sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
2297
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId,
2101
2298
  sender_role: cleanText(sender_role) || cleanText(senderRole),
2102
2299
  recipient_agent_session_id: cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
2103
2300
  recipient_role: cleanText(recipient_role) || cleanText(recipientRole) || cleanText(role) || cleanText(participant_role) || cleanText(participantRole),
@@ -2524,7 +2721,7 @@ export class AIEngineClient {
2524
2721
  body: {
2525
2722
  communication_thread_id: cleanText(communication_thread_id) || cleanText(communicationThreadId) || cleanText(threadId),
2526
2723
  communication_bundle_id: cleanText(communication_bundle_id) || cleanText(communicationBundleId),
2527
- sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
2724
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || this.agentSessionId,
2528
2725
  recipient_agent_session_id: cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
2529
2726
  recipient_role_key: cleanText(recipient_role_key) || cleanText(recipientRoleKey),
2530
2727
  message_kind: normalizeMessageKind(cleanText(message_kind) || cleanText(messageKind)),
@@ -2814,7 +3011,7 @@ export class AIEngineClient {
2814
3011
  receipt_type: normalizeTransferReceiptType(cleanText(receipt_type) || cleanText(receiptType) || 'delivery_receipt'),
2815
3012
  receipt_status: cleanText(receipt_status) || cleanText(receiptStatus) || 'recorded',
2816
3013
  actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
2817
- agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
3014
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId) || this.agentSessionId,
2818
3015
  claim_id: cleanText(claim_id) || cleanText(claimId),
2819
3016
  evidence_ref: cleanText(evidence_ref) || cleanText(evidenceRef),
2820
3017
  evidence_sha256: cleanText(evidence_sha256) || cleanText(evidenceSha256),
@@ -2996,7 +3193,7 @@ export class AIEngineClient {
2996
3193
  body: {
2997
3194
  workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
2998
3195
  title: cleanText(title),
2999
- agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
3196
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId) || this.agentSessionId,
3000
3197
  handoff_kind: cleanText(handoff_kind) || cleanText(handoffKind) || 'general',
3001
3198
  handoff_priority: cleanText(handoff_priority) || cleanText(handoffPriority) || 'normal',
3002
3199
  summary_text: cleanText(summary_text) || cleanText(summaryText),
@@ -5605,6 +5802,7 @@ export class AIEngineClient {
5605
5802
  const resolvedHeaders = {
5606
5803
  accept: accept || 'application/json',
5607
5804
  'x-actor-id': this.actorId,
5805
+ ...(this.agentSessionId ? { 'x-agent-session-id': this.agentSessionId } : {}),
5608
5806
  'x-ai-engine-client-version': this.clientVersion,
5609
5807
  'x-ai-engine-client-capabilities': this.clientCapabilities.join(','),
5610
5808
  ...(isJsonBody(body) ? { 'content-type': 'application/json' } : {}),