@bpmsoftwaresolutions/ai-engine-client 1.1.83 → 1.1.86

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.
@@ -0,0 +1,273 @@
1
+ import { cleanText, isPlainObject } from '../utils/communication.js';
2
+
3
+ function normalizeTransferChannelId(request = {}) {
4
+ return cleanText(request.transfer_channel_id) || cleanText(request.transferChannelId) || cleanText(request.channel_id) || cleanText(request.channelId);
5
+ }
6
+
7
+ export function createCollaborationDomain(client) {
8
+ return {
9
+ reviewCollaborationProposal: (request) => reviewCollaborationProposal(client, request),
10
+ reviseCollaborationProposal: (request) => reviseCollaborationProposal(client, request),
11
+ postCollaborationProposal: (request) => postCollaborationProposal(client, request),
12
+ acceptCollaborationProposal: (request) => acceptCollaborationProposal(client, request),
13
+ assignCollaborationOwnership: (request) => assignCollaborationOwnership(client, request),
14
+ raiseCollaborationBlocker: (request) => raiseCollaborationBlocker(client, request),
15
+ resolveCollaborationBlocker: (request) => resolveCollaborationBlocker(client, request),
16
+ postCollaborationHeartbeat: (request) => postCollaborationHeartbeat(client, request),
17
+ beginCollaborationImplementation: (request) => beginCollaborationImplementation(client, request),
18
+ requestCollaborationClosure: (request) => requestCollaborationClosure(client, request),
19
+ };
20
+ }
21
+
22
+ export async function reviewCollaborationProposal(client, request = {}) {
23
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
24
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
25
+ const normalizedProposalId = cleanText(request.collaboration_proposal_id) || cleanText(request.collaborationProposalId) || cleanText(request.proposal_id) || cleanText(request.proposalId);
26
+ if (!normalizedProposalId) throw new Error('collaboration_proposal_id is required.');
27
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/collaboration/review-proposal`, {
28
+ method: 'POST',
29
+ body: {
30
+ collaboration_proposal_id: normalizedProposalId,
31
+ decision: cleanText(request.decision) || 'accept',
32
+ next_owner: cleanText(request.next_owner) || cleanText(request.nextOwner),
33
+ phase: cleanText(request.phase) || cleanText(request.current_phase) || cleanText(request.currentPhase),
34
+ decision_reason: cleanText(request.decision_reason) || cleanText(request.decisionReason),
35
+ evidence_refs: Array.isArray(request.evidence_refs) ? request.evidence_refs : (Array.isArray(request.evidenceRefs) ? request.evidenceRefs : []),
36
+ reviewer_role: cleanText(request.reviewer_role) || cleanText(request.reviewerRole) || cleanText(request.participant_role) || cleanText(request.participantRole),
37
+ reviewer_agent_session_id: cleanText(request.reviewer_agent_session_id) || cleanText(request.reviewerAgentSessionId) || cleanText(request.sender_agent_session_id) || cleanText(request.senderAgentSessionId),
38
+ reviewer_actor_session_id: cleanText(request.reviewer_actor_session_id) || cleanText(request.reviewerActorSessionId) || cleanText(request.sender_actor_session_id) || cleanText(request.senderActorSessionId),
39
+ reviewed_by_claim_id: cleanText(request.reviewed_by_claim_id) || cleanText(request.reviewedByClaimId) || cleanText(request.claim_id) || cleanText(request.claimId),
40
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
41
+ },
42
+ });
43
+ }
44
+
45
+ export async function reviseCollaborationProposal(client, request = {}) {
46
+ const normalizedProposalId = cleanText(request.revision_of_proposal_id) || cleanText(request.revisionOfProposalId) || cleanText(request.proposal_id) || cleanText(request.proposalId);
47
+ if (!normalizedProposalId) throw new Error('revision_of_proposal_id is required.');
48
+ return client._request(`/api/agent-communications/collaboration-proposals/${encodeURIComponent(normalizedProposalId)}/revise`, {
49
+ method: 'POST',
50
+ body: {
51
+ transfer_channel_id: cleanText(request.transfer_channel_id) || cleanText(request.transferChannelId),
52
+ work_transfer_packet_id: cleanText(request.work_transfer_packet_id) || cleanText(request.workTransferPacketId),
53
+ workflow_run_id: cleanText(request.workflow_run_id) || cleanText(request.workflowRunId),
54
+ proposal_kind: cleanText(request.proposal_kind) || cleanText(request.proposalKind) || 'implementation_update',
55
+ participant_role: cleanText(request.participant_role) || cleanText(request.participantRole) || 'downstream',
56
+ proposal_summary: cleanText(request.proposal_summary) || cleanText(request.proposalSummary),
57
+ revision_of_proposal_id: normalizedProposalId,
58
+ proposer_agent_session_id: cleanText(request.proposer_agent_session_id) || cleanText(request.proposerAgentSessionId) || cleanText(request.revised_by_agent_session_id) || cleanText(request.revisedByAgentSessionId),
59
+ proposer_actor_session_id: cleanText(request.proposer_actor_session_id) || cleanText(request.proposerActorSessionId) || cleanText(request.revised_by_actor_session_id) || cleanText(request.revisedByActorSessionId),
60
+ current_phase: cleanText(request.current_phase) || cleanText(request.currentPhase),
61
+ expected_next_update: cleanText(request.expected_next_update) || cleanText(request.expectedNextUpdate),
62
+ expected_next_update_at: cleanText(request.expected_next_update_at) || cleanText(request.expectedNextUpdateAt),
63
+ required_evidence: Array.isArray(request.required_evidence) ? request.required_evidence : (Array.isArray(request.requiredEvidence) ? request.requiredEvidence : []),
64
+ response_schema: isPlainObject(request.response_schema) ? request.response_schema : (isPlainObject(request.responseSchema) ? request.responseSchema : {}),
65
+ blocker_summary: cleanText(request.blocker_summary) || cleanText(request.blockerSummary),
66
+ revision_number: Number(request.revision_number ?? request.revisionNumber ?? 2) || 2,
67
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
68
+ },
69
+ });
70
+ }
71
+
72
+ export async function postCollaborationProposal(client, request = {}) {
73
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
74
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
75
+ const {
76
+ workTransferPacketId,
77
+ work_transfer_packet_id,
78
+ workflowRunId,
79
+ workflow_run_id,
80
+ proposalKind,
81
+ proposal_kind,
82
+ proposalState,
83
+ proposal_state,
84
+ participantRole,
85
+ participant_role,
86
+ proposalSummary,
87
+ proposal_summary,
88
+ currentPhase,
89
+ current_phase,
90
+ expectedNextUpdate,
91
+ expected_next_update,
92
+ expectedNextUpdateAt,
93
+ expected_next_update_at,
94
+ requiredEvidence = [],
95
+ required_evidence = [],
96
+ responseSchema = {},
97
+ response_schema = {},
98
+ blockerSummary,
99
+ blocker_summary,
100
+ blockerReason,
101
+ blocker_reason,
102
+ revisionOfProposalId,
103
+ revision_of_proposal_id,
104
+ revisionNumber = 1,
105
+ revision_number,
106
+ proposerAgentSessionId,
107
+ proposer_agent_session_id,
108
+ proposerActorSessionId,
109
+ proposer_actor_session_id,
110
+ metadata = {},
111
+ } = request;
112
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/proposals`, {
113
+ method: 'POST',
114
+ body: {
115
+ work_transfer_packet_id: cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId),
116
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
117
+ proposal_kind: cleanText(proposal_kind) || cleanText(proposalKind),
118
+ proposal_state: cleanText(proposal_state) || cleanText(proposalState) || 'proposed',
119
+ participant_role: cleanText(participant_role) || cleanText(participantRole),
120
+ proposal_summary: cleanText(proposal_summary) || cleanText(proposalSummary),
121
+ current_phase: cleanText(current_phase) || cleanText(currentPhase),
122
+ expected_next_update: cleanText(expected_next_update) || cleanText(expectedNextUpdate),
123
+ expected_next_update_at: expected_next_update_at || expectedNextUpdateAt,
124
+ required_evidence: Array.isArray(required_evidence) ? required_evidence : requiredEvidence,
125
+ response_schema: isPlainObject(response_schema) ? response_schema : responseSchema,
126
+ blocker_summary: cleanText(blocker_summary) || cleanText(blockerSummary) || cleanText(blocker_reason) || cleanText(blockerReason),
127
+ revision_of_proposal_id: cleanText(revision_of_proposal_id) || cleanText(revisionOfProposalId),
128
+ revision_number: Number(revision_number ?? revisionNumber ?? 1),
129
+ proposer_agent_session_id: cleanText(proposer_agent_session_id) || cleanText(proposerAgentSessionId) || client.agentSessionId,
130
+ proposer_actor_session_id: cleanText(proposer_actor_session_id) || cleanText(proposerActorSessionId),
131
+ metadata: isPlainObject(metadata) ? metadata : {},
132
+ },
133
+ });
134
+ }
135
+
136
+ export async function acceptCollaborationProposal(client, request = {}) {
137
+ const normalizedProposalId = cleanText(request.proposal_id) || cleanText(request.proposalId);
138
+ if (!normalizedProposalId) throw new Error('collaboration_proposal_id is required.');
139
+ return client._request(`/api/agent-communications/collaboration-proposals/${encodeURIComponent(normalizedProposalId)}/accept`, {
140
+ method: 'POST',
141
+ body: {
142
+ transfer_channel_id: cleanText(request.transfer_channel_id) || cleanText(request.transferChannelId),
143
+ work_transfer_packet_id: cleanText(request.work_transfer_packet_id) || cleanText(request.workTransferPacketId),
144
+ workflow_run_id: cleanText(request.workflow_run_id) || cleanText(request.workflowRunId),
145
+ collaboration_proposal_id: normalizedProposalId,
146
+ decision_role: cleanText(request.decision_role) || cleanText(request.decisionRole) || 'upstream',
147
+ decision_summary: cleanText(request.decision_summary) || cleanText(request.decisionSummary) || 'Proposal accepted.',
148
+ decision_reason: cleanText(request.decision_reason) || cleanText(request.decisionReason),
149
+ decision_agent_session_id: cleanText(request.decision_agent_session_id) || cleanText(request.decisionAgentSessionId) || client.agentSessionId,
150
+ decision_actor_session_id: cleanText(request.decision_actor_session_id) || cleanText(request.decisionActorSessionId),
151
+ evidence_refs: Array.isArray(request.evidence_refs) ? request.evidence_refs : (Array.isArray(request.evidenceRefs) ? request.evidenceRefs : []),
152
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
153
+ },
154
+ });
155
+ }
156
+
157
+ export async function assignCollaborationOwnership(client, request = {}) {
158
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
159
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
160
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/ownership-assignments`, {
161
+ method: 'POST',
162
+ body: {
163
+ work_transfer_packet_id: cleanText(request.work_transfer_packet_id) || cleanText(request.workTransferPacketId),
164
+ workflow_run_id: cleanText(request.workflow_run_id) || cleanText(request.workflowRunId),
165
+ participant_role: cleanText(request.participant_role) || cleanText(request.participantRole),
166
+ owner_agent_session_id: cleanText(request.owner_agent_session_id) || cleanText(request.ownerAgentSessionId),
167
+ owner_actor_session_id: cleanText(request.owner_actor_session_id) || cleanText(request.ownerActorSessionId),
168
+ owner_label: cleanText(request.owner_label) || cleanText(request.ownerLabel),
169
+ assignment_state: cleanText(request.assignment_state) || cleanText(request.assignmentState) || 'assigned',
170
+ assignment_reason: cleanText(request.assignment_reason) || cleanText(request.assignmentReason),
171
+ current_phase: cleanText(request.current_phase) || cleanText(request.currentPhase),
172
+ assigned_by_agent_session_id: cleanText(request.assigned_by_agent_session_id) || cleanText(request.assignedByAgentSessionId) || client.agentSessionId,
173
+ assigned_by_actor_session_id: cleanText(request.assigned_by_actor_session_id) || cleanText(request.assignedByActorSessionId),
174
+ resolved_at: request.resolved_at || request.resolvedAt,
175
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
176
+ },
177
+ });
178
+ }
179
+
180
+ export async function raiseCollaborationBlocker(client, request = {}) {
181
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
182
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
183
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/collaboration/raise-blocker`, {
184
+ method: 'POST',
185
+ body: {
186
+ blocker_kind: cleanText(request.blocker_kind) || cleanText(request.blockerKind),
187
+ blocker_summary: cleanText(request.blocker_summary) || cleanText(request.blockerSummary),
188
+ blocked_side: cleanText(request.blocked_side) || cleanText(request.blockedSide),
189
+ blocker_details: cleanText(request.blocker_details) || cleanText(request.blockerDetails),
190
+ expected_next_update: cleanText(request.expected_next_update) || cleanText(request.expectedNextUpdate),
191
+ participant_role: cleanText(request.participant_role) || cleanText(request.participantRole),
192
+ next_owner: cleanText(request.next_owner) || cleanText(request.nextOwner),
193
+ phase: cleanText(request.current_phase) || cleanText(request.currentPhase) || cleanText(request.phase),
194
+ reviewer_agent_session_id: cleanText(request.reviewer_agent_session_id) || cleanText(request.reviewerAgentSessionId),
195
+ reviewer_actor_session_id: cleanText(request.reviewer_actor_session_id) || cleanText(request.reviewerActorSessionId),
196
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
197
+ },
198
+ });
199
+ }
200
+
201
+ export async function resolveCollaborationBlocker(client, request = {}) {
202
+ const normalizedBlockerId = cleanText(request.blocker_id) || cleanText(request.blockerId);
203
+ if (!normalizedBlockerId) throw new Error('blocker_id is required.');
204
+ return client._request(`/api/agent-communications/collaboration-blockers/${encodeURIComponent(normalizedBlockerId)}/resolve`, {
205
+ method: 'POST',
206
+ body: {
207
+ blocker_state: cleanText(request.blocker_state) || cleanText(request.blockerState) || 'resolved',
208
+ resolution_summary: cleanText(request.resolution_summary) || cleanText(request.resolutionSummary),
209
+ resolved_by_agent_session_id: cleanText(request.resolved_by_agent_session_id) || cleanText(request.resolvedByAgentSessionId),
210
+ resolved_by_actor_session_id: cleanText(request.resolved_by_actor_session_id) || cleanText(request.resolvedByActorSessionId),
211
+ resolved_at: request.resolved_at || request.resolvedAt,
212
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
213
+ },
214
+ });
215
+ }
216
+
217
+ export async function postCollaborationHeartbeat(client, request = {}) {
218
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
219
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
220
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/heartbeats`, {
221
+ method: 'POST',
222
+ body: {
223
+ work_transfer_packet_id: cleanText(request.work_transfer_packet_id) || cleanText(request.workTransferPacketId),
224
+ workflow_run_id: cleanText(request.workflow_run_id) || cleanText(request.workflowRunId),
225
+ participant_role: cleanText(request.participant_role) || cleanText(request.participantRole),
226
+ activity_state: cleanText(request.activity_state) || cleanText(request.activityState) || 'active',
227
+ current_phase: cleanText(request.current_phase) || cleanText(request.currentPhase),
228
+ current_task_summary: cleanText(request.current_task_summary) || cleanText(request.currentTaskSummary),
229
+ is_active: Boolean(request.is_active ?? request.isActive ?? true),
230
+ agent_session_id: cleanText(request.agent_session_id) || cleanText(request.agentSessionId) || client.agentSessionId,
231
+ actor_session_id: cleanText(request.actor_session_id) || cleanText(request.actorSessionId),
232
+ observed_at: request.observed_at || request.observedAt,
233
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
234
+ },
235
+ });
236
+ }
237
+
238
+ export async function beginCollaborationImplementation(client, request = {}) {
239
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
240
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
241
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/collaboration/begin-implementation`, {
242
+ method: 'POST',
243
+ body: {
244
+ participant_role: cleanText(request.participant_role) || cleanText(request.participantRole) || cleanText(request.owner_role_key) || cleanText(request.ownerRoleKey),
245
+ owner_label: cleanText(request.owner_label) || cleanText(request.ownerLabel) || cleanText(request.owner_role_key) || cleanText(request.ownerRoleKey),
246
+ expected_update_cadence: cleanText(request.expected_update_cadence) || cleanText(request.expectedUpdateCadence),
247
+ phase: cleanText(request.current_phase) || cleanText(request.currentPhase) || cleanText(request.phase),
248
+ current_task_summary: cleanText(request.current_task_summary) || cleanText(request.currentTaskSummary),
249
+ owner_agent_session_id: cleanText(request.owner_agent_session_id) || cleanText(request.ownerAgentSessionId),
250
+ owner_actor_session_id: cleanText(request.owner_actor_session_id) || cleanText(request.ownerActorSessionId),
251
+ assigned_by_agent_session_id: cleanText(request.assigned_by_agent_session_id) || cleanText(request.assignedByAgentSessionId),
252
+ assigned_by_actor_session_id: cleanText(request.assigned_by_actor_session_id) || cleanText(request.assignedByActorSessionId),
253
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
254
+ },
255
+ });
256
+ }
257
+
258
+ export async function requestCollaborationClosure(client, request = {}) {
259
+ const normalizedTransferChannelId = normalizeTransferChannelId(request);
260
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
261
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/collaboration/request-closure`, {
262
+ method: 'POST',
263
+ body: {
264
+ sender_agent_session_id: cleanText(request.sender_agent_session_id) || cleanText(request.senderAgentSessionId) || client.agentSessionId,
265
+ sender_actor_session_id: cleanText(request.sender_actor_session_id) || cleanText(request.senderActorSessionId),
266
+ closure_reason: cleanText(request.closure_reason) || cleanText(request.closureReason),
267
+ evidence_refs: Array.isArray(request.evidence_refs) ? request.evidence_refs : (Array.isArray(request.evidenceRefs) ? request.evidenceRefs : []),
268
+ failure_reason: cleanText(request.failure_reason) || cleanText(request.failureReason),
269
+ phase: cleanText(request.current_phase) || cleanText(request.currentPhase) || cleanText(request.phase),
270
+ metadata: isPlainObject(request.metadata) ? request.metadata : {},
271
+ },
272
+ });
273
+ }
@@ -0,0 +1,270 @@
1
+ import { cleanText, isPlainObject } from '../utils/communication.js';
2
+
3
+ export function createMessageWatchDomain(client) {
4
+ return {
5
+ startMessageWatch: (request) => startMessageWatch(client, request),
6
+ acknowledgeExpectedMessage: (request) => acknowledgeExpectedMessage(client, request),
7
+ expireMessageWatch: (request) => expireMessageWatch(client, request),
8
+ respondToMessageWatch: (request) => respondToMessageWatch(client, request),
9
+ acceptAgentChannel: (request) => acceptAgentChannel(client, request),
10
+ resolveMessageWatchId: (request) => resolveMessageWatchId(client, request),
11
+ };
12
+ }
13
+
14
+ export async function resolveMessageWatchId(client, {
15
+ transferChannelId,
16
+ transfer_channel_id,
17
+ channelId,
18
+ channel_id,
19
+ workTransferPacketId,
20
+ work_transfer_packet_id,
21
+ messageWatchId,
22
+ message_watch_id,
23
+ watchId,
24
+ watch_id,
25
+ } = {}) {
26
+ let normalizedWatchId = cleanText(message_watch_id) || cleanText(messageWatchId) || cleanText(watch_id) || cleanText(watchId);
27
+ if (!normalizedWatchId) {
28
+ normalizedWatchId = await client._resolveMessageWatchId({
29
+ transfer_channel_id,
30
+ transferChannelId,
31
+ channel_id,
32
+ channelId,
33
+ work_transfer_packet_id,
34
+ workTransferPacketId,
35
+ });
36
+ }
37
+ return normalizedWatchId;
38
+ }
39
+
40
+ export async function startMessageWatch(client, {
41
+ transferChannelId,
42
+ transfer_channel_id,
43
+ channelId,
44
+ channel_id,
45
+ workTransferPacketId,
46
+ work_transfer_packet_id,
47
+ workflowRunId,
48
+ workflow_run_id,
49
+ watchingAgentRole,
50
+ watching_agent_role,
51
+ expectedFromRole,
52
+ expected_from_role,
53
+ expectedMessageKind,
54
+ expected_message_kind,
55
+ watchType,
56
+ watch_type,
57
+ watchingAgentSessionId,
58
+ watching_agent_session_id,
59
+ watchingActorSessionId,
60
+ watching_actor_session_id,
61
+ expectedPayload,
62
+ expected_payload,
63
+ lastSeenMessageId,
64
+ last_seen_message_id,
65
+ lastCheckedAt,
66
+ last_checked_at,
67
+ staleAfterSeconds,
68
+ stale_after_seconds,
69
+ currentStatus,
70
+ current_status,
71
+ operatorNudge,
72
+ operator_nudge,
73
+ blockedReason,
74
+ blocked_reason,
75
+ metadata = {},
76
+ } = {}) {
77
+ const normalizedTransferChannelId = cleanText(transfer_channel_id) || cleanText(transferChannelId) || cleanText(channel_id) || cleanText(channelId);
78
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
79
+ let normalizedPacketId = cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId);
80
+ if (!normalizedPacketId) {
81
+ try {
82
+ const status = await client.getCommunicationChannelStatus({ transferChannelId: normalizedTransferChannelId });
83
+ normalizedPacketId = cleanText(status?.packet_id || status?.packetId || status?.work_transfer_packet_id);
84
+ } catch (error) {
85
+ void error;
86
+ }
87
+ }
88
+ if (!normalizedPacketId) throw new Error('work_transfer_packet_id is required.');
89
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/message-watches`, {
90
+ method: 'POST',
91
+ body: {
92
+ work_transfer_packet_id: normalizedPacketId,
93
+ workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
94
+ watching_agent_role: cleanText(watching_agent_role) || cleanText(watchingAgentRole),
95
+ expected_from_role: cleanText(expected_from_role) || cleanText(expectedFromRole),
96
+ expected_message_kind: cleanText(expected_message_kind) || cleanText(expectedMessageKind),
97
+ watch_type: cleanText(watch_type) || cleanText(watchType) || 'expected_peer_message',
98
+ watching_agent_session_id: cleanText(watching_agent_session_id) || cleanText(watchingAgentSessionId) || client.agentSessionId,
99
+ watching_actor_session_id: cleanText(watching_actor_session_id) || cleanText(watchingActorSessionId),
100
+ expected_payload: isPlainObject(expected_payload) ? expected_payload : (isPlainObject(expectedPayload) ? expectedPayload : {}),
101
+ last_seen_message_id: cleanText(last_seen_message_id) || cleanText(lastSeenMessageId),
102
+ last_checked_at: last_checked_at || lastCheckedAt,
103
+ stale_after_seconds: stale_after_seconds ?? staleAfterSeconds,
104
+ current_status: cleanText(current_status) || cleanText(currentStatus),
105
+ operator_nudge: cleanText(operator_nudge) || cleanText(operatorNudge),
106
+ blocked_reason: cleanText(blocked_reason) || cleanText(blockedReason),
107
+ metadata: isPlainObject(metadata) ? metadata : {},
108
+ },
109
+ });
110
+ }
111
+
112
+ export async function acknowledgeExpectedMessage(client, {
113
+ messageWatchId,
114
+ message_watch_id,
115
+ watchId,
116
+ watch_id,
117
+ transferChannelId,
118
+ transfer_channel_id,
119
+ channelId,
120
+ channel_id,
121
+ observedMessageId,
122
+ observed_message_id,
123
+ observedMessageKind,
124
+ observed_message_kind,
125
+ lastCheckedAt,
126
+ last_checked_at,
127
+ operatorNudge,
128
+ operator_nudge,
129
+ metadata = {},
130
+ } = {}) {
131
+ const normalizedWatchId = await resolveMessageWatchId(client, {
132
+ transferChannelId,
133
+ transfer_channel_id,
134
+ channelId,
135
+ channel_id,
136
+ messageWatchId,
137
+ message_watch_id,
138
+ watchId,
139
+ watch_id,
140
+ });
141
+ if (!normalizedWatchId) throw new Error('message_watch_id is required.');
142
+ return client._request(`/api/agent-communications/message-watches/${encodeURIComponent(normalizedWatchId)}/acknowledge-message`, {
143
+ method: 'POST',
144
+ body: {
145
+ observed_message_id: cleanText(observed_message_id) || cleanText(observedMessageId),
146
+ observed_message_kind: cleanText(observed_message_kind) || cleanText(observedMessageKind),
147
+ last_checked_at: last_checked_at || lastCheckedAt,
148
+ operator_nudge: cleanText(operator_nudge) || cleanText(operatorNudge),
149
+ metadata: isPlainObject(metadata) ? metadata : {},
150
+ },
151
+ });
152
+ }
153
+
154
+ export async function expireMessageWatch(client, {
155
+ messageWatchId,
156
+ message_watch_id,
157
+ watchId,
158
+ watch_id,
159
+ transferChannelId,
160
+ transfer_channel_id,
161
+ channelId,
162
+ channel_id,
163
+ blockedReason,
164
+ blocked_reason,
165
+ lastCheckedAt,
166
+ last_checked_at,
167
+ metadata = {},
168
+ } = {}) {
169
+ const normalizedWatchId = await resolveMessageWatchId(client, {
170
+ transferChannelId,
171
+ transfer_channel_id,
172
+ channelId,
173
+ channel_id,
174
+ messageWatchId,
175
+ message_watch_id,
176
+ watchId,
177
+ watch_id,
178
+ });
179
+ if (!normalizedWatchId) throw new Error('message_watch_id is required.');
180
+ return client._request(`/api/agent-communications/message-watches/${encodeURIComponent(normalizedWatchId)}/expire`, {
181
+ method: 'POST',
182
+ body: {
183
+ blocked_reason: cleanText(blocked_reason) || cleanText(blockedReason),
184
+ last_checked_at: last_checked_at || lastCheckedAt,
185
+ metadata: isPlainObject(metadata) ? metadata : {},
186
+ },
187
+ });
188
+ }
189
+
190
+ export async function respondToMessageWatch(client, {
191
+ transferChannelId,
192
+ transfer_channel_id,
193
+ channelId,
194
+ channel_id,
195
+ messageWatchId,
196
+ message_watch_id,
197
+ watchId,
198
+ watch_id,
199
+ expectedMessageKind,
200
+ expected_message_kind,
201
+ senderRole,
202
+ sender_role,
203
+ participantRole,
204
+ participant_role,
205
+ senderAgentSessionId,
206
+ sender_agent_session_id,
207
+ senderActorSessionId,
208
+ sender_actor_session_id,
209
+ messageKind,
210
+ message_kind,
211
+ bodyMarkdown,
212
+ body_markdown,
213
+ evidenceRefs,
214
+ evidence_refs,
215
+ payload = {},
216
+ metadata = {},
217
+ } = {}) {
218
+ const normalizedTransferChannelId = cleanText(transfer_channel_id) || cleanText(transferChannelId) || cleanText(channel_id) || cleanText(channelId);
219
+ if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
220
+ return client._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/message-watches/respond`, {
221
+ method: 'POST',
222
+ body: {
223
+ message_watch_id: cleanText(message_watch_id) || cleanText(messageWatchId) || cleanText(watch_id) || cleanText(watchId),
224
+ expected_message_kind: cleanText(expected_message_kind) || cleanText(expectedMessageKind),
225
+ sender_role: cleanText(sender_role) || cleanText(senderRole) || cleanText(participant_role) || cleanText(participantRole),
226
+ sender_agent_session_id: cleanText(sender_agent_session_id) || cleanText(senderAgentSessionId) || client.agentSessionId,
227
+ sender_actor_session_id: cleanText(sender_actor_session_id) || cleanText(senderActorSessionId),
228
+ message_kind: cleanText(message_kind) || cleanText(messageKind),
229
+ body_markdown: cleanText(body_markdown) || cleanText(bodyMarkdown),
230
+ evidence_refs: Array.isArray(evidence_refs) ? evidence_refs : Array.isArray(evidenceRefs) ? evidenceRefs : [],
231
+ payload: isPlainObject(payload) ? payload : {},
232
+ metadata: isPlainObject(metadata) ? metadata : {},
233
+ },
234
+ });
235
+ }
236
+
237
+ export async function acceptAgentChannel(client, {
238
+ messageWatchId,
239
+ message_watch_id,
240
+ watchId,
241
+ watch_id,
242
+ observedMessageId,
243
+ observed_message_id,
244
+ observedMessageKind,
245
+ observed_message_kind,
246
+ expectedMessageKind,
247
+ expected_message_kind,
248
+ transferChannelId,
249
+ transfer_channel_id,
250
+ channelId,
251
+ channel_id,
252
+ lastCheckedAt,
253
+ last_checked_at,
254
+ operatorNudge,
255
+ operator_nudge,
256
+ metadata = {},
257
+ } = {}) {
258
+ const normalizedWatchId = cleanText(message_watch_id) || cleanText(messageWatchId) || cleanText(watch_id) || cleanText(watchId) || await resolveMessageWatchId(client, { transfer_channel_id, transferChannelId, channel_id, channelId });
259
+ if (!normalizedWatchId) throw new Error('message_watch_id is required.');
260
+ return client._request(`/api/agent-communications/message-watches/${encodeURIComponent(normalizedWatchId)}/acknowledge`, {
261
+ method: 'POST',
262
+ body: {
263
+ observed_message_id: cleanText(observed_message_id) || cleanText(observedMessageId),
264
+ observed_message_kind: cleanText(observed_message_kind) || cleanText(observedMessageKind) || cleanText(expected_message_kind) || cleanText(expectedMessageKind),
265
+ last_checked_at: last_checked_at || lastCheckedAt,
266
+ operator_nudge: cleanText(operator_nudge) || cleanText(operatorNudge),
267
+ metadata: isPlainObject(metadata) ? metadata : {},
268
+ },
269
+ });
270
+ }