@bpmsoftwaresolutions/ai-engine-client 1.1.44 → 1.1.47

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 +732 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmsoftwaresolutions/ai-engine-client",
3
- "version": "1.1.44",
3
+ "version": "1.1.47",
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
@@ -1,5 +1,5 @@
1
1
  const DEFAULT_TIMEOUT_MS = 30000;
2
- export const AI_ENGINE_CLIENT_VERSION = '1.1.44';
2
+ export const AI_ENGINE_CLIENT_VERSION = '1.1.47';
3
3
  export const GOVERNED_MUTATION_REQUIRED_CAPABILITIES = [
4
4
  'executeVerifiedMutation',
5
5
  'post_mutation_verification',
@@ -20,6 +20,99 @@ export const LOGA_INTERACTION_CONTRACT = 'loga-choreography/v1';
20
20
  export const LOGA_NAVIGATION_CONTRACT = 'loga-navigation/v1';
21
21
  export const LOGA_PROJECTION_WORKFLOW = 'loga-document-projection';
22
22
  export const TASK_BOUND_SUBSTRATE_EXECUTION_POLICY = 'task_bound_substrate_execution/v1';
23
+ export const AGENT_COMMUNICATION_CONTRACT_VERSION = 'v1';
24
+ export const AGENT_COMMUNICATION_THREAD_TYPES = ['request', 'review', 'handoff', 'coordination', 'task', 'escalation'];
25
+ export const AGENT_COMMUNICATION_MESSAGE_KINDS = [
26
+ 'request',
27
+ 'response',
28
+ 'review',
29
+ 'handoff',
30
+ 'blocker',
31
+ 'evidence',
32
+ 'decision_request',
33
+ 'task_request',
34
+ 'review_request',
35
+ 'evidence_response',
36
+ ];
37
+ export const AGENT_COMMUNICATION_TRANSFER_KINDS = [
38
+ 'upstream_remediation',
39
+ 'review_request',
40
+ 'handoff',
41
+ 'coordination',
42
+ 'evidence_delivery',
43
+ ];
44
+ export const AGENT_COMMUNICATION_TRANSFER_MODES = ['bundle', 'artifact_refs', 'inline_payload'];
45
+ export const AGENT_COMMUNICATION_TRANSFER_LIFECYCLE_STATES = [
46
+ 'created',
47
+ 'delivered',
48
+ 'accepted',
49
+ 'in_progress',
50
+ 'responded',
51
+ 'closed',
52
+ 'failed',
53
+ 'superseded',
54
+ ];
55
+ export const AGENT_COMMUNICATION_TRANSFER_RECEIPT_TYPES = [
56
+ 'delivery_receipt',
57
+ 'acceptance_receipt',
58
+ 'evidence_receipt',
59
+ 'closure_receipt',
60
+ 'failure_receipt',
61
+ ];
62
+ export const AGENT_COMMUNICATION_RECIPIENT_MODES = ['role', 'agent_session'];
63
+
64
+ function normalizeEnum(value, allowed, defaultValue, fieldName, aliases = {}) {
65
+ const text = cleanText(value);
66
+ if (!text) return defaultValue;
67
+ let normalized = text.toLowerCase();
68
+ if (Object.prototype.hasOwnProperty.call(aliases, normalized)) {
69
+ normalized = aliases[normalized];
70
+ }
71
+ if (!allowed.includes(normalized)) {
72
+ throw new Error(`${fieldName} must be one of ${allowed.join(', ')}.`);
73
+ }
74
+ return normalized;
75
+ }
76
+
77
+ function normalizeThreadType(value) {
78
+ return normalizeEnum(value, AGENT_COMMUNICATION_THREAD_TYPES, 'coordination', 'thread_type', {
79
+ task_request: 'request',
80
+ task: 'request',
81
+ review_request: 'review',
82
+ handoff_request: 'handoff',
83
+ });
84
+ }
85
+
86
+ function normalizeMessageKind(value) {
87
+ return normalizeEnum(value, AGENT_COMMUNICATION_MESSAGE_KINDS, 'request', 'message_kind', {
88
+ task: 'request',
89
+ note: 'request',
90
+ update: 'response',
91
+ });
92
+ }
93
+
94
+ function normalizeTransferKind(value) {
95
+ return normalizeEnum(value, AGENT_COMMUNICATION_TRANSFER_KINDS, 'upstream_remediation', 'transfer_kind', {
96
+ remediation_request: 'upstream_remediation',
97
+ review: 'review_request',
98
+ });
99
+ }
100
+
101
+ function normalizeTransferMode(value) {
102
+ return normalizeEnum(value, AGENT_COMMUNICATION_TRANSFER_MODES, 'inline_payload', 'transfer_mode');
103
+ }
104
+
105
+ function normalizeTransferLifecycleStatus(value) {
106
+ return normalizeEnum(value, AGENT_COMMUNICATION_TRANSFER_LIFECYCLE_STATES, 'created', 'lifecycle_status');
107
+ }
108
+
109
+ function normalizeTransferReceiptType(value) {
110
+ return normalizeEnum(value, AGENT_COMMUNICATION_TRANSFER_RECEIPT_TYPES, 'delivery_receipt', 'receipt_type');
111
+ }
112
+
113
+ function normalizeRecipientMode(value) {
114
+ return normalizeEnum(value, AGENT_COMMUNICATION_RECIPIENT_MODES, 'role', 'recipient_mode');
115
+ }
23
116
 
24
117
  function trimTrailingSlash(value) {
25
118
  return String(value || '').replace(/\/+$/, '');
@@ -310,6 +403,28 @@ export class AIEngineClient {
310
403
  getThread: (threadId) => this.getCommunicationThread(threadId),
311
404
  listInbox: (request) => this.listCommunicationInbox(request),
312
405
  sendMessage: (request) => this.sendCommunicationMessage(request),
406
+ getCommunicationCapabilities: (request) => this.getCommunicationCapabilities(request),
407
+ getDeploymentCapabilities: (request) => this.getDeploymentCapabilities(request),
408
+ bootstrap: (request) => this.bootstrapCommunication(request),
409
+ negotiateTransfer: (request) => this.negotiateCommunicationTransfer(request),
410
+ resolveCommunicationTarget: (request) => this.resolveCommunicationTarget(request),
411
+ createEvidencePacket: (request) => this.createCommunicationEvidencePacket(request),
412
+ transferWorkPacket: (request) => this.transferWorkPacket(request),
413
+ listFrictionTaxonomy: (request) => this.listCommunicationFrictionTaxonomy(request),
414
+ recordFrictionEvent: (request) => this.recordCommunicationFrictionEvent(request),
415
+ createTransferReceipt: (request) => this.recordCommunicationTransferReceipt(request),
416
+ acceptTransferPacket: (request) => this.acceptCommunicationTransferPacket(request),
417
+ closeTransferPacket: (request) => this.closeCommunicationTransferPacket(request),
418
+ getTransferHealth: (request) => this.getCommunicationTransferHealth(request),
419
+ createBundle: (request) => this.createCommunicationBundle(request),
420
+ getBundle: (bundleId) => this.getCommunicationBundle(bundleId),
421
+ listBundles: (request) => this.listCommunicationBundles(request),
422
+ addBundleItem: (request) => this.addCommunicationBundleItem(request),
423
+ uploadBundle: (request) => this.uploadCommunicationBundle(request),
424
+ attachBundleToMessage: (request) => this.attachCommunicationBundleToMessage(request),
425
+ recordBundleReceipt: (request) => this.recordCommunicationBundleReceipt(request),
426
+ recordBundleCleanupEvent: (request) => this.recordCommunicationBundleCleanupEvent(request),
427
+ claimBundle: (request) => this.claimCommunicationBundle(request),
313
428
  acceptMessage: (messageId) => this.acceptCommunicationMessage(messageId),
314
429
  respondWithEvidence: (request) => this.respondToCommunicationMessage(request),
315
430
  attachEvidence: (request) => this.attachCommunicationMessageEvidence(request),
@@ -493,6 +608,250 @@ export class AIEngineClient {
493
608
  });
494
609
  }
495
610
 
611
+ async getCommunicationCapabilities() {
612
+ return this._request('/api/agent-communications/capabilities');
613
+ }
614
+
615
+ async getDeploymentCapabilities() {
616
+ return this._request('/api/agent-communications/deployment-capabilities');
617
+ }
618
+
619
+ async bootstrapCommunication() {
620
+ return this._request('/api/agent-communications/bootstrap');
621
+ }
622
+
623
+ async negotiateCommunicationTransfer({
624
+ preferredModes,
625
+ preferred_modes,
626
+ preferred,
627
+ capabilities = {},
628
+ estimatedPayloadKb,
629
+ estimated_payload_kb,
630
+ requiresReceipts = true,
631
+ requires_receipts = true,
632
+ supportsHashValidation = true,
633
+ supports_hash_validation = true,
634
+ transferKind,
635
+ transfer_kind,
636
+ workflowRunId,
637
+ workflow_run_id,
638
+ } = {}) {
639
+ const normalizedPreferredModes = Array.isArray(preferred_modes)
640
+ ? preferred_modes
641
+ : (Array.isArray(preferredModes) ? preferredModes : (Array.isArray(preferred) ? preferred : ['bundle', 'artifact_refs', 'inline_payload']));
642
+ return this._request('/api/agent-communications/transfers/negotiate', {
643
+ method: 'POST',
644
+ body: {
645
+ preferred_modes: normalizedPreferredModes.map((mode) => normalizeTransferMode(mode)),
646
+ capabilities: isPlainObject(capabilities) ? capabilities : {},
647
+ estimated_payload_kb: Number(estimated_payload_kb ?? estimatedPayloadKb ?? 0) || undefined,
648
+ requires_receipts: Boolean(requires_receipts ?? requiresReceipts),
649
+ supports_hash_validation: Boolean(supports_hash_validation ?? supportsHashValidation),
650
+ transfer_kind: normalizeTransferKind(transfer_kind ?? transferKind ?? 'upstream_remediation'),
651
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
652
+ },
653
+ });
654
+ }
655
+
656
+ async resolveCommunicationTarget({
657
+ intent,
658
+ transferKind,
659
+ transfer_kind,
660
+ recipientMode,
661
+ recipient_mode,
662
+ preferredRoleKey,
663
+ preferred_role_key,
664
+ preferredAgentSessionId,
665
+ preferred_agent_session_id,
666
+ workflowRunId,
667
+ workflow_run_id,
668
+ } = {}) {
669
+ return this._request('/api/agent-communications/targets/resolve', {
670
+ method: 'POST',
671
+ body: {
672
+ intent: cleanText(intent) || cleanText(transfer_kind) || cleanText(transferKind),
673
+ recipient_mode: normalizeRecipientMode(recipient_mode ?? recipientMode ?? 'role'),
674
+ preferred_role_key: cleanText(preferred_role_key) || cleanText(preferredRoleKey),
675
+ preferred_agent_session_id: cleanText(preferred_agent_session_id) || cleanText(preferredAgentSessionId),
676
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
677
+ },
678
+ });
679
+ }
680
+
681
+ async createCommunicationEvidencePacket({
682
+ workflowRunId,
683
+ workflow_run_id,
684
+ transferKind,
685
+ transfer_kind,
686
+ objective,
687
+ requestedOutcome,
688
+ requested_outcome,
689
+ artifacts = [],
690
+ artifactRefs,
691
+ artifact_refs,
692
+ issues = [],
693
+ issueRefs,
694
+ issue_refs,
695
+ expectedEvidence = [],
696
+ expected_evidence,
697
+ metadata = {},
698
+ } = {}) {
699
+ return this._request('/api/agent-communications/evidence-packets', {
700
+ method: 'POST',
701
+ body: {
702
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
703
+ transfer_kind: normalizeTransferKind(transfer_kind ?? transferKind ?? 'upstream_remediation'),
704
+ objective: cleanText(objective),
705
+ requested_outcome: cleanText(requested_outcome) || cleanText(requestedOutcome),
706
+ artifacts: Array.isArray(artifacts) ? artifacts : (Array.isArray(artifact_refs) ? artifact_refs : (Array.isArray(artifactRefs) ? artifactRefs : [])),
707
+ issues: Array.isArray(issues) ? issues : (Array.isArray(issue_refs) ? issue_refs : (Array.isArray(issueRefs) ? issueRefs : [])),
708
+ expected_evidence: Array.isArray(expected_evidence) ? expected_evidence : (Array.isArray(expectedEvidence) ? expectedEvidence : []),
709
+ metadata: isPlainObject(metadata) ? metadata : {},
710
+ },
711
+ });
712
+ }
713
+
714
+ async listCommunicationFrictionTaxonomy({
715
+ categoryGroup,
716
+ category_group,
717
+ isActive,
718
+ is_active,
719
+ } = {}) {
720
+ return this._request('/api/agent-communications/friction-taxonomy', {
721
+ query: {
722
+ category_group: cleanText(category_group) || cleanText(categoryGroup),
723
+ is_active: is_active !== undefined ? String(Boolean(is_active)) : (isActive !== undefined ? String(Boolean(isActive)) : undefined),
724
+ },
725
+ });
726
+ }
727
+
728
+ async recordCommunicationFrictionEvent({
729
+ workflowRunId,
730
+ workflow_run_id,
731
+ workTransferPacketId,
732
+ work_transfer_packet_id,
733
+ communicationThreadId,
734
+ communication_thread_id,
735
+ communicationMessageId,
736
+ communication_message_id,
737
+ taxonomyKey,
738
+ taxonomy_key,
739
+ frictionType,
740
+ friction_type,
741
+ severity,
742
+ observedBehavior,
743
+ observed_behavior,
744
+ attemptedAction,
745
+ attempted_action,
746
+ resolutionPath,
747
+ resolution_path,
748
+ missingSurfaceKey,
749
+ missing_surface_key,
750
+ promotionCandidate,
751
+ promotion_candidate,
752
+ repeatedCount,
753
+ repeated_count,
754
+ metadata = {},
755
+ } = {}) {
756
+ return this._request('/api/agent-communications/friction-events', {
757
+ method: 'POST',
758
+ body: {
759
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
760
+ work_transfer_packet_id: cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId),
761
+ communication_thread_id: cleanText(communication_thread_id) || cleanText(communicationThreadId),
762
+ communication_message_id: cleanText(communication_message_id) || cleanText(communicationMessageId),
763
+ taxonomy_key: cleanText(taxonomy_key) || cleanText(taxonomyKey) || 'enum_drift',
764
+ friction_type: cleanText(friction_type) || cleanText(frictionType) || 'discovery',
765
+ severity: cleanText(severity) || 'warning',
766
+ observed_behavior: cleanText(observed_behavior) || cleanText(observedBehavior),
767
+ attempted_action: cleanText(attempted_action) || cleanText(attemptedAction),
768
+ resolution_path: cleanText(resolution_path) || cleanText(resolutionPath),
769
+ missing_surface_key: cleanText(missing_surface_key) || cleanText(missingSurfaceKey),
770
+ promotion_candidate: Boolean(promotion_candidate ?? promotionCandidate),
771
+ repeated_count: Number(repeated_count ?? repeatedCount ?? 1) || 1,
772
+ metadata: isPlainObject(metadata) ? metadata : {},
773
+ },
774
+ });
775
+ }
776
+
777
+ async transferWorkPacket({
778
+ workflowRunId,
779
+ workflow_run_id,
780
+ transferKind,
781
+ transfer_kind,
782
+ objective,
783
+ requestedOutcome,
784
+ requested_outcome,
785
+ target = {},
786
+ artifacts = [],
787
+ issues = [],
788
+ expectedEvidence = [],
789
+ preferredModes,
790
+ preferred_modes,
791
+ preferred,
792
+ capabilities = {},
793
+ estimatedPayloadKb,
794
+ estimated_payload_kb,
795
+ requiresReceipts = true,
796
+ requires_receipts = true,
797
+ supportsHashValidation = true,
798
+ supports_hash_validation = true,
799
+ senderAgentSessionId,
800
+ sender_agent_session_id,
801
+ senderActorSessionId,
802
+ sender_actor_session_id,
803
+ subject,
804
+ bodyMarkdown,
805
+ body_markdown,
806
+ parentThreadId,
807
+ parent_thread_id,
808
+ recipientMode,
809
+ recipient_mode,
810
+ recipientRoleKey,
811
+ recipient_role_key,
812
+ recipientAgentSessionId,
813
+ recipient_agent_session_id,
814
+ cleanupPolicy,
815
+ cleanup_policy,
816
+ } = {}) {
817
+ const normalizedTarget = isPlainObject(target) ? target : {};
818
+ const normalizedWorkflowRunId = cleanText(workflow_run_id) || cleanText(workflowRunId);
819
+ const normalizedTransferKind = normalizeTransferKind(transfer_kind ?? transferKind ?? 'upstream_remediation');
820
+ const normalizedPreferredModes = Array.isArray(preferred_modes)
821
+ ? preferred_modes
822
+ : (Array.isArray(preferredModes) ? preferredModes : (Array.isArray(preferred) ? preferred : ['bundle', 'artifact_refs', 'inline_payload']));
823
+ const normalizedTargetMode = cleanText(normalizedTarget.recipient_mode) || cleanText(normalizedTarget.recipientMode) || cleanText(recipient_mode) || cleanText(recipientMode) || 'role';
824
+ return this._request('/api/agent-communications/work-transfers', {
825
+ method: 'POST',
826
+ body: {
827
+ workflow_run_id: normalizedWorkflowRunId,
828
+ transfer_kind: normalizedTransferKind,
829
+ objective: cleanText(objective),
830
+ requested_outcome: cleanText(requested_outcome) || cleanText(requestedOutcome),
831
+ target: {
832
+ intent: cleanText(normalizedTarget.intent) || normalizedTransferKind,
833
+ recipient_mode: normalizeRecipientMode(normalizedTargetMode),
834
+ preferred_role_key: cleanText(normalizedTarget.preferred_role_key) || cleanText(normalizedTarget.preferredRoleKey) || cleanText(recipient_role_key) || cleanText(recipientRoleKey),
835
+ preferred_agent_session_id: cleanText(normalizedTarget.preferred_agent_session_id) || cleanText(normalizedTarget.preferredAgentSessionId) || cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
836
+ },
837
+ artifacts: Array.isArray(artifacts) ? artifacts : [],
838
+ issues: Array.isArray(issues) ? issues : [],
839
+ expected_evidence: Array.isArray(expectedEvidence) ? expectedEvidence : [],
840
+ preferred_modes: normalizedPreferredModes.map((mode) => normalizeTransferMode(mode)),
841
+ capabilities: isPlainObject(capabilities) ? capabilities : {},
842
+ estimated_payload_kb: Number(estimated_payload_kb ?? estimatedPayloadKb ?? 0) || undefined,
843
+ requires_receipts: Boolean(requires_receipts ?? requiresReceipts),
844
+ supports_hash_validation: Boolean(supports_hash_validation ?? supportsHashValidation),
845
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
846
+ sender_actor_session_id: cleanText(sender_actor_session_id) || cleanText(senderActorSessionId),
847
+ subject: cleanText(subject),
848
+ body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
849
+ parent_thread_id: cleanText(parent_thread_id) || cleanText(parentThreadId),
850
+ cleanup_policy: cleanText(cleanup_policy) || cleanText(cleanupPolicy),
851
+ },
852
+ });
853
+ }
854
+
496
855
  async openCommunicationThread({
497
856
  workflowRunId,
498
857
  workflow_run_id,
@@ -513,7 +872,7 @@ export class AIEngineClient {
513
872
  body: {
514
873
  workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
515
874
  parent_thread_id: cleanText(parent_thread_id) || cleanText(parentThreadId),
516
- thread_type: cleanText(thread_type) || cleanText(threadType),
875
+ thread_type: normalizeThreadType(cleanText(thread_type) || cleanText(threadType)),
517
876
  subject: cleanText(subject),
518
877
  objective: cleanText(objective),
519
878
  created_by_agent_session_id: cleanText(created_by_agent_session_id) || cleanText(createdByAgentSessionId),
@@ -548,6 +907,8 @@ export class AIEngineClient {
548
907
  communicationThreadId,
549
908
  communication_thread_id,
550
909
  threadId,
910
+ communicationBundleId,
911
+ communication_bundle_id,
551
912
  senderAgentSessionId,
552
913
  sender_agent_session_id,
553
914
  recipientAgentSessionId,
@@ -570,10 +931,11 @@ export class AIEngineClient {
570
931
  method: 'POST',
571
932
  body: {
572
933
  communication_thread_id: cleanText(communication_thread_id) || cleanText(communicationThreadId) || cleanText(threadId),
934
+ communication_bundle_id: cleanText(communication_bundle_id) || cleanText(communicationBundleId),
573
935
  sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId),
574
936
  recipient_agent_session_id: cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
575
937
  recipient_role_key: cleanText(recipient_role_key) || cleanText(recipientRoleKey),
576
- message_kind: cleanText(message_kind) || cleanText(messageKind),
938
+ message_kind: normalizeMessageKind(cleanText(message_kind) || cleanText(messageKind)),
577
939
  message_status: cleanText(message_status) || cleanText(messageStatus) || 'sent',
578
940
  body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
579
941
  payload: isPlainObject(payload) ? payload : {},
@@ -586,6 +948,373 @@ export class AIEngineClient {
586
948
  });
587
949
  }
588
950
 
951
+ async createCommunicationBundle({
952
+ workflowRunId,
953
+ workflow_run_id,
954
+ communicationThreadId,
955
+ communication_thread_id,
956
+ threadId,
957
+ sourceAgentSessionId,
958
+ source_agent_session_id,
959
+ sourceActorSessionId,
960
+ source_actor_session_id,
961
+ recipientAgentSessionId,
962
+ recipient_agent_session_id,
963
+ recipientRoleKey,
964
+ recipient_role_key,
965
+ bundleKind,
966
+ bundle_kind,
967
+ cleanupPolicy,
968
+ cleanup_policy,
969
+ manifest = {},
970
+ manifestSha256,
971
+ manifest_sha256,
972
+ blobUri,
973
+ blob_uri,
974
+ blobSha256,
975
+ blob_sha256,
976
+ blobContainerName,
977
+ blob_container_name,
978
+ blobObjectKey,
979
+ blob_object_key,
980
+ metadata = {},
981
+ } = {}) {
982
+ return this._request('/api/agent-communications/bundles', {
983
+ method: 'POST',
984
+ body: {
985
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
986
+ communication_thread_id: cleanText(communication_thread_id) || cleanText(communicationThreadId) || cleanText(threadId),
987
+ source_agent_session_id: cleanText(source_agent_session_id) || cleanText(sourceAgentSessionId),
988
+ source_actor_session_id: cleanText(source_actor_session_id) || cleanText(sourceActorSessionId),
989
+ recipient_agent_session_id: cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
990
+ recipient_role_key: cleanText(recipient_role_key) || cleanText(recipientRoleKey),
991
+ bundle_kind: cleanText(bundle_kind) || cleanText(bundleKind) || 'transfer',
992
+ cleanup_policy: cleanText(cleanup_policy) || cleanText(cleanupPolicy) || 'cleanup_after_receipt',
993
+ manifest: isPlainObject(manifest) ? manifest : {},
994
+ manifest_sha256: cleanText(manifest_sha256) || cleanText(manifestSha256),
995
+ blob_uri: cleanText(blob_uri) || cleanText(blobUri),
996
+ blob_sha256: cleanText(blob_sha256) || cleanText(blobSha256),
997
+ blob_container_name: cleanText(blob_container_name) || cleanText(blobContainerName),
998
+ blob_object_key: cleanText(blob_object_key) || cleanText(blobObjectKey),
999
+ metadata: isPlainObject(metadata) ? metadata : {},
1000
+ },
1001
+ });
1002
+ }
1003
+
1004
+ async getCommunicationBundle(bundleId) {
1005
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(bundleId)}`);
1006
+ }
1007
+
1008
+ async listCommunicationBundles({ workflowRunId, workflow_run_id } = {}) {
1009
+ return this._request('/api/agent-communications/bundles', {
1010
+ query: { workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId) },
1011
+ });
1012
+ }
1013
+
1014
+ async addCommunicationBundleItem({
1015
+ communicationBundleId,
1016
+ communication_bundle_id,
1017
+ itemOrder,
1018
+ item_order,
1019
+ itemKind,
1020
+ item_kind,
1021
+ itemRef,
1022
+ item_ref,
1023
+ itemName,
1024
+ item_name,
1025
+ itemSha256,
1026
+ item_sha256,
1027
+ required,
1028
+ metadata = {},
1029
+ } = {}) {
1030
+ const normalizedBundleId = cleanText(communication_bundle_id) || cleanText(communicationBundleId);
1031
+ if (!normalizedBundleId) throw new Error('communication_bundle_id is required.');
1032
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(normalizedBundleId)}/items`, {
1033
+ method: 'POST',
1034
+ body: {
1035
+ item_order: Number(item_order ?? itemOrder ?? 0),
1036
+ item_kind: cleanText(item_kind) || cleanText(itemKind) || 'artifact',
1037
+ item_ref: cleanText(item_ref) || cleanText(itemRef),
1038
+ item_name: cleanText(item_name) || cleanText(itemName),
1039
+ item_sha256: cleanText(item_sha256) || cleanText(itemSha256),
1040
+ required: required !== undefined ? Boolean(required) : true,
1041
+ metadata: isPlainObject(metadata) ? metadata : {},
1042
+ },
1043
+ });
1044
+ }
1045
+
1046
+ async uploadCommunicationBundle({
1047
+ communicationBundleId,
1048
+ communication_bundle_id,
1049
+ blobUri,
1050
+ blob_uri,
1051
+ blobSha256,
1052
+ blob_sha256,
1053
+ blobContainerName,
1054
+ blob_container_name,
1055
+ blobObjectKey,
1056
+ blob_object_key,
1057
+ manifest = {},
1058
+ manifestSha256,
1059
+ manifest_sha256,
1060
+ uploadedAt,
1061
+ uploaded_at,
1062
+ } = {}) {
1063
+ const normalizedBundleId = cleanText(communication_bundle_id) || cleanText(communicationBundleId);
1064
+ if (!normalizedBundleId) throw new Error('communication_bundle_id is required.');
1065
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(normalizedBundleId)}/upload`, {
1066
+ method: 'POST',
1067
+ body: {
1068
+ blob_uri: cleanText(blob_uri) || cleanText(blobUri),
1069
+ blob_sha256: cleanText(blob_sha256) || cleanText(blobSha256),
1070
+ blob_container_name: cleanText(blob_container_name) || cleanText(blobContainerName),
1071
+ blob_object_key: cleanText(blob_object_key) || cleanText(blobObjectKey),
1072
+ manifest: isPlainObject(manifest) ? manifest : {},
1073
+ manifest_sha256: cleanText(manifest_sha256) || cleanText(manifestSha256),
1074
+ uploaded_at: cleanText(uploaded_at) || cleanText(uploadedAt),
1075
+ },
1076
+ });
1077
+ }
1078
+
1079
+ async attachCommunicationBundleToMessage({
1080
+ communicationBundleId,
1081
+ communication_bundle_id,
1082
+ agentMessageId,
1083
+ agent_message_id,
1084
+ messageId,
1085
+ messageStatus,
1086
+ message_status,
1087
+ } = {}) {
1088
+ const normalizedBundleId = cleanText(communication_bundle_id) || cleanText(communicationBundleId);
1089
+ if (!normalizedBundleId) throw new Error('communication_bundle_id is required.');
1090
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(normalizedBundleId)}/attach-to-message`, {
1091
+ method: 'POST',
1092
+ body: {
1093
+ agent_message_id: cleanText(agent_message_id) || cleanText(agentMessageId) || cleanText(messageId),
1094
+ message_status: cleanText(message_status) || cleanText(messageStatus),
1095
+ },
1096
+ });
1097
+ }
1098
+
1099
+ async recordCommunicationBundleReceipt({
1100
+ communicationBundleId,
1101
+ communication_bundle_id,
1102
+ recipientAgentSessionId,
1103
+ recipient_agent_session_id,
1104
+ recipientActorSessionId,
1105
+ recipient_actor_session_id,
1106
+ receiptStatus,
1107
+ receipt_status,
1108
+ manifestSha256,
1109
+ manifest_sha256,
1110
+ blobSha256,
1111
+ blob_sha256,
1112
+ fetchedItemCount,
1113
+ fetched_item_count,
1114
+ explicitlyAcceptedItemCount,
1115
+ explicitly_accepted_item_count,
1116
+ allRequiredItemsFetched,
1117
+ all_required_items_fetched,
1118
+ checksumsVerified,
1119
+ checksums_verified,
1120
+ receipt = {},
1121
+ metadata = {},
1122
+ } = {}) {
1123
+ const normalizedBundleId = cleanText(communication_bundle_id) || cleanText(communicationBundleId);
1124
+ if (!normalizedBundleId) throw new Error('communication_bundle_id is required.');
1125
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(normalizedBundleId)}/receipts`, {
1126
+ method: 'POST',
1127
+ body: {
1128
+ recipient_agent_session_id: cleanText(recipient_agent_session_id) || cleanText(recipientAgentSessionId),
1129
+ recipient_actor_session_id: cleanText(recipient_actor_session_id) || cleanText(recipientActorSessionId),
1130
+ receipt_status: cleanText(receipt_status) || cleanText(receiptStatus) || 'received',
1131
+ manifest_sha256: cleanText(manifest_sha256) || cleanText(manifestSha256),
1132
+ blob_sha256: cleanText(blob_sha256) || cleanText(blobSha256),
1133
+ fetched_item_count: Number(fetched_item_count ?? fetchedItemCount ?? 0),
1134
+ explicitly_accepted_item_count: Number(explicitly_accepted_item_count ?? explicitlyAcceptedItemCount ?? 0),
1135
+ all_required_items_fetched: Boolean(all_required_items_fetched ?? allRequiredItemsFetched ?? false),
1136
+ checksums_verified: Boolean(checksums_verified ?? checksumsVerified ?? false),
1137
+ receipt: isPlainObject(receipt) ? receipt : {},
1138
+ metadata: isPlainObject(metadata) ? metadata : {},
1139
+ },
1140
+ });
1141
+ }
1142
+
1143
+ async recordCommunicationBundleCleanupEvent({
1144
+ communicationBundleId,
1145
+ communication_bundle_id,
1146
+ cleanupStatus,
1147
+ cleanup_status,
1148
+ cleanupReason,
1149
+ cleanup_reason,
1150
+ blobUri,
1151
+ blob_uri,
1152
+ deletedAt,
1153
+ deleted_at,
1154
+ errorMessage,
1155
+ error_message,
1156
+ metadata = {},
1157
+ } = {}) {
1158
+ const normalizedBundleId = cleanText(communication_bundle_id) || cleanText(communicationBundleId);
1159
+ if (!normalizedBundleId) throw new Error('communication_bundle_id is required.');
1160
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(normalizedBundleId)}/cleanup-events`, {
1161
+ method: 'POST',
1162
+ body: {
1163
+ cleanup_status: cleanText(cleanup_status) || cleanText(cleanupStatus) || 'cleanup_failed',
1164
+ cleanup_reason: cleanText(cleanup_reason) || cleanText(cleanupReason),
1165
+ blob_uri: cleanText(blob_uri) || cleanText(blobUri),
1166
+ deleted_at: cleanText(deleted_at) || cleanText(deletedAt),
1167
+ error_message: cleanText(error_message) || cleanText(errorMessage),
1168
+ metadata: isPlainObject(metadata) ? metadata : {},
1169
+ },
1170
+ });
1171
+ }
1172
+
1173
+ async claimCommunicationBundle({
1174
+ communicationBundleId,
1175
+ communication_bundle_id,
1176
+ claimedAt,
1177
+ claimed_at,
1178
+ } = {}) {
1179
+ const normalizedBundleId = cleanText(communication_bundle_id) || cleanText(communicationBundleId);
1180
+ if (!normalizedBundleId) throw new Error('communication_bundle_id is required.');
1181
+ return this._request(`/api/agent-communications/bundles/${encodeURIComponent(normalizedBundleId)}/claim`, {
1182
+ method: 'POST',
1183
+ body: {
1184
+ claimed_at: cleanText(claimed_at) || cleanText(claimedAt),
1185
+ },
1186
+ });
1187
+ }
1188
+
1189
+ async recordCommunicationTransferReceipt({
1190
+ workTransferPacketId,
1191
+ work_transfer_packet_id,
1192
+ receiptType,
1193
+ receipt_type,
1194
+ receiptStatus,
1195
+ receipt_status,
1196
+ actorSessionId,
1197
+ actor_session_id,
1198
+ agentSessionId,
1199
+ agent_session_id,
1200
+ claimId,
1201
+ claim_id,
1202
+ evidenceRef,
1203
+ evidence_ref,
1204
+ evidenceSha256,
1205
+ evidence_sha256,
1206
+ evidence = {},
1207
+ manifestSha256,
1208
+ manifest_sha256,
1209
+ closureReason,
1210
+ closure_reason,
1211
+ failureReason,
1212
+ failure_reason,
1213
+ lifecycleStatus,
1214
+ lifecycle_status,
1215
+ metadata = {},
1216
+ } = {}) {
1217
+ const normalizedPacketId = cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId);
1218
+ if (!normalizedPacketId) throw new Error('work_transfer_packet_id is required.');
1219
+ return this._request(`/api/agent-communications/transfers/${encodeURIComponent(normalizedPacketId)}/receipts`, {
1220
+ method: 'POST',
1221
+ body: {
1222
+ receipt_type: normalizeTransferReceiptType(cleanText(receipt_type) || cleanText(receiptType) || 'delivery_receipt'),
1223
+ receipt_status: cleanText(receipt_status) || cleanText(receiptStatus) || 'recorded',
1224
+ actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
1225
+ agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
1226
+ claim_id: cleanText(claim_id) || cleanText(claimId),
1227
+ evidence_ref: cleanText(evidence_ref) || cleanText(evidenceRef),
1228
+ evidence_sha256: cleanText(evidence_sha256) || cleanText(evidenceSha256),
1229
+ evidence: isPlainObject(evidence) ? evidence : {},
1230
+ manifest_sha256: cleanText(manifest_sha256) || cleanText(manifestSha256),
1231
+ closure_reason: cleanText(closure_reason) || cleanText(closureReason),
1232
+ failure_reason: cleanText(failure_reason) || cleanText(failureReason),
1233
+ lifecycle_status: cleanText(lifecycle_status) || cleanText(lifecycleStatus),
1234
+ metadata: isPlainObject(metadata) ? metadata : {},
1235
+ },
1236
+ });
1237
+ }
1238
+
1239
+ async acceptCommunicationTransferPacket({
1240
+ workTransferPacketId,
1241
+ work_transfer_packet_id,
1242
+ acceptedByAgentSessionId,
1243
+ accepted_by_agent_session_id,
1244
+ acceptedByActorSessionId,
1245
+ accepted_by_actor_session_id,
1246
+ acceptedByClaimId,
1247
+ accepted_by_claim_id,
1248
+ advanceToInProgress,
1249
+ advance_to_in_progress,
1250
+ metadata = {},
1251
+ } = {}) {
1252
+ const normalizedPacketId = cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId);
1253
+ if (!normalizedPacketId) throw new Error('work_transfer_packet_id is required.');
1254
+ return this._request(`/api/agent-communications/transfers/${encodeURIComponent(normalizedPacketId)}/accept`, {
1255
+ method: 'POST',
1256
+ body: {
1257
+ accepted_by_agent_session_id: cleanText(accepted_by_agent_session_id) || cleanText(acceptedByAgentSessionId),
1258
+ accepted_by_actor_session_id: cleanText(accepted_by_actor_session_id) || cleanText(acceptedByActorSessionId),
1259
+ accepted_by_claim_id: cleanText(accepted_by_claim_id) || cleanText(acceptedByClaimId),
1260
+ advance_to_in_progress: Boolean(advance_to_in_progress ?? advanceToInProgress),
1261
+ metadata: isPlainObject(metadata) ? metadata : {},
1262
+ },
1263
+ });
1264
+ }
1265
+
1266
+ async closeCommunicationTransferPacket({
1267
+ workTransferPacketId,
1268
+ work_transfer_packet_id,
1269
+ closureStatus,
1270
+ closure_status,
1271
+ closureReason,
1272
+ closure_reason,
1273
+ failureReason,
1274
+ failure_reason,
1275
+ closedByAgentSessionId,
1276
+ closed_by_agent_session_id,
1277
+ closedByActorSessionId,
1278
+ closed_by_actor_session_id,
1279
+ closedByClaimId,
1280
+ closed_by_claim_id,
1281
+ evidence = {},
1282
+ evidenceManifestSha256,
1283
+ evidence_manifest_sha256,
1284
+ metadata = {},
1285
+ } = {}) {
1286
+ const normalizedPacketId = cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId);
1287
+ if (!normalizedPacketId) throw new Error('work_transfer_packet_id is required.');
1288
+ return this._request(`/api/agent-communications/transfers/${encodeURIComponent(normalizedPacketId)}/close`, {
1289
+ method: 'POST',
1290
+ body: {
1291
+ closure_status: normalizeTransferLifecycleStatus(cleanText(closure_status) || cleanText(closureStatus) || 'closed'),
1292
+ closure_reason: cleanText(closure_reason) || cleanText(closureReason),
1293
+ failure_reason: cleanText(failure_reason) || cleanText(failureReason),
1294
+ closed_by_agent_session_id: cleanText(closed_by_agent_session_id) || cleanText(closedByAgentSessionId),
1295
+ closed_by_actor_session_id: cleanText(closed_by_actor_session_id) || cleanText(closedByActorSessionId),
1296
+ closed_by_claim_id: cleanText(closed_by_claim_id) || cleanText(closedByClaimId),
1297
+ evidence: isPlainObject(evidence) ? evidence : {},
1298
+ evidence_manifest_sha256: cleanText(evidence_manifest_sha256) || cleanText(evidenceManifestSha256),
1299
+ metadata: isPlainObject(metadata) ? metadata : {},
1300
+ },
1301
+ });
1302
+ }
1303
+
1304
+ async getCommunicationTransferHealth({
1305
+ workflowRunId,
1306
+ workflow_run_id,
1307
+ workTransferPacketId,
1308
+ work_transfer_packet_id,
1309
+ } = {}) {
1310
+ return this._request('/api/agent-communications/transfers/health', {
1311
+ query: {
1312
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
1313
+ work_transfer_packet_id: cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId),
1314
+ },
1315
+ });
1316
+ }
1317
+
589
1318
  async acceptCommunicationMessage(messageId) {
590
1319
  return this._request(`/api/agent-communications/messages/${encodeURIComponent(messageId)}/accept`, {
591
1320
  method: 'POST',