@bpmsoftwaresolutions/ai-engine-client 1.1.60 → 1.1.62
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.
- package/package.json +2 -1
- package/src/index.js +236 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bpmsoftwaresolutions/ai-engine-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.62",
|
|
4
4
|
"description": "Thin npm client for the AI Engine operator and retrieval APIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
".": "./src/index.js"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
+
"package.json",
|
|
14
15
|
"src",
|
|
15
16
|
"README.md",
|
|
16
17
|
"examples"
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
1
5
|
const DEFAULT_TIMEOUT_MS = 30000;
|
|
2
|
-
|
|
6
|
+
const PACKAGE_JSON_PATH = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
|
|
7
|
+
|
|
8
|
+
function readPackageVersion() {
|
|
9
|
+
const packageJson = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'));
|
|
10
|
+
const version = String(packageJson.version || '').trim();
|
|
11
|
+
if (!version) {
|
|
12
|
+
throw new Error(`Missing package version in ${PACKAGE_JSON_PATH}.`);
|
|
13
|
+
}
|
|
14
|
+
return version;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const AI_ENGINE_CLIENT_VERSION = readPackageVersion();
|
|
3
18
|
export const GOVERNED_MUTATION_REQUIRED_CAPABILITIES = [
|
|
4
19
|
'executeVerifiedMutation',
|
|
5
20
|
'post_mutation_verification',
|
|
@@ -437,6 +452,12 @@ export class AIEngineClient {
|
|
|
437
452
|
acceptTransferPacket: (request) => this.acceptCommunicationTransferPacket(request),
|
|
438
453
|
closeTransferPacket: (request) => this.closeCommunicationTransferPacket(request),
|
|
439
454
|
getTransferHealth: (request) => this.getCommunicationTransferHealth(request),
|
|
455
|
+
openAgentChannel: (request) => this.openAgentChannel(request),
|
|
456
|
+
acceptAgentChannel: (request) => this.acceptAgentChannel(request),
|
|
457
|
+
postAgentHeartbeat: (request) => this.postAgentHeartbeat(request),
|
|
458
|
+
postAgentMessage: (request) => this.postAgentMessage(request),
|
|
459
|
+
acknowledgeAgentMessage: (request) => this.acknowledgeAgentMessage(request),
|
|
460
|
+
closeAgentChannel: (request) => this.closeAgentChannel(request),
|
|
440
461
|
createBundle: (request) => this.createCommunicationBundle(request),
|
|
441
462
|
getBundle: (bundleId) => this.getCommunicationBundle(bundleId),
|
|
442
463
|
listBundles: (request) => this.listCommunicationBundles(request),
|
|
@@ -484,6 +505,12 @@ export class AIEngineClient {
|
|
|
484
505
|
raiseBlocker: (request) => this.raiseCollaborationBlocker(request),
|
|
485
506
|
beginImplementation: (request) => this.beginCollaborationImplementation(request),
|
|
486
507
|
requestClosure: (request) => this.requestCollaborationClosure(request),
|
|
508
|
+
openAgentChannel: (request) => this.openAgentChannel(request),
|
|
509
|
+
acceptAgentChannel: (request) => this.acceptAgentChannel(request),
|
|
510
|
+
postAgentHeartbeat: (request) => this.postAgentHeartbeat(request),
|
|
511
|
+
postAgentMessage: (request) => this.postAgentMessage(request),
|
|
512
|
+
acknowledgeAgentMessage: (request) => this.acknowledgeAgentMessage(request),
|
|
513
|
+
closeAgentChannel: (request) => this.closeAgentChannel(request),
|
|
487
514
|
whoIsOnline: (request) => this.whoIsOnline(request),
|
|
488
515
|
findOnlineParticipant: (request) => this.findOnlineParticipant(request),
|
|
489
516
|
listCommunicationChannels: (request) => this.listCommunicationChannels(request),
|
|
@@ -1164,10 +1191,20 @@ export class AIEngineClient {
|
|
|
1164
1191
|
} = {}) {
|
|
1165
1192
|
const normalizedTransferChannelId = cleanText(transfer_channel_id) || cleanText(transferChannelId) || cleanText(channel_id) || cleanText(channelId);
|
|
1166
1193
|
if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
|
|
1194
|
+
let normalizedPacketId = cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId) || cleanText(packet_id) || cleanText(packetId);
|
|
1195
|
+
if (!normalizedPacketId) {
|
|
1196
|
+
try {
|
|
1197
|
+
const status = await this.getCommunicationChannelStatus({ transferChannelId: normalizedTransferChannelId });
|
|
1198
|
+
normalizedPacketId = cleanText(status?.packet_id || status?.packetId || status?.work_transfer_packet_id);
|
|
1199
|
+
} catch (error) {
|
|
1200
|
+
void error;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (!normalizedPacketId) throw new Error('work_transfer_packet_id is required.');
|
|
1167
1204
|
return this._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/connect`, {
|
|
1168
1205
|
method: 'POST',
|
|
1169
1206
|
body: {
|
|
1170
|
-
work_transfer_packet_id:
|
|
1207
|
+
work_transfer_packet_id: normalizedPacketId,
|
|
1171
1208
|
workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
|
|
1172
1209
|
participant_role: cleanText(participant_role) || cleanText(participantRole),
|
|
1173
1210
|
expected_peer_role: cleanText(expected_peer_role) || cleanText(expectedPeerRole),
|
|
@@ -1190,6 +1227,203 @@ export class AIEngineClient {
|
|
|
1190
1227
|
});
|
|
1191
1228
|
}
|
|
1192
1229
|
|
|
1230
|
+
async openAgentChannel(request = {}) {
|
|
1231
|
+
return this.connectToTransferChannel(request);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
async _resolveMessageWatchId(request = {}) {
|
|
1235
|
+
const directWatchId = cleanText(request.message_watch_id) || cleanText(request.messageWatchId) || cleanText(request.watch_id) || cleanText(request.watchId);
|
|
1236
|
+
if (directWatchId) {
|
|
1237
|
+
return directWatchId;
|
|
1238
|
+
}
|
|
1239
|
+
const normalizedTransferChannelId = cleanText(request.transfer_channel_id) || cleanText(request.transferChannelId) || cleanText(request.channel_id) || cleanText(request.channelId);
|
|
1240
|
+
if (!normalizedTransferChannelId) return null;
|
|
1241
|
+
try {
|
|
1242
|
+
const watches = await this._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/message-watches`);
|
|
1243
|
+
const watchRows = Array.isArray(watches?.message_watches) ? watches.message_watches.filter((row) => row && typeof row === 'object') : [];
|
|
1244
|
+
watchRows.sort((a, b) => String(b.updated_at || b.created_at || '').localeCompare(String(a.updated_at || a.created_at || '')));
|
|
1245
|
+
const activeWatch = watchRows.find((watch) => ['watching', 'waiting', 'stale', 'blocked', 'active'].includes(String(watch.current_status || '').trim().toLowerCase()));
|
|
1246
|
+
return cleanText((activeWatch || watchRows[0] || {}).message_watch_id);
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
void error;
|
|
1249
|
+
return null;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
async acceptAgentChannel({
|
|
1254
|
+
messageWatchId,
|
|
1255
|
+
message_watch_id,
|
|
1256
|
+
watchId,
|
|
1257
|
+
watch_id,
|
|
1258
|
+
observedMessageId,
|
|
1259
|
+
observed_message_id,
|
|
1260
|
+
observedMessageKind,
|
|
1261
|
+
observed_message_kind,
|
|
1262
|
+
expectedMessageKind,
|
|
1263
|
+
expected_message_kind,
|
|
1264
|
+
transferChannelId,
|
|
1265
|
+
transfer_channel_id,
|
|
1266
|
+
channelId,
|
|
1267
|
+
channel_id,
|
|
1268
|
+
lastCheckedAt,
|
|
1269
|
+
last_checked_at,
|
|
1270
|
+
operatorNudge,
|
|
1271
|
+
operator_nudge,
|
|
1272
|
+
metadata = {},
|
|
1273
|
+
} = {}) {
|
|
1274
|
+
const normalizedWatchId = cleanText(message_watch_id) || cleanText(messageWatchId) || cleanText(watch_id) || cleanText(watchId) || await this._resolveMessageWatchId({ transfer_channel_id, transferChannelId, channel_id, channelId });
|
|
1275
|
+
if (!normalizedWatchId) throw new Error('message_watch_id is required.');
|
|
1276
|
+
return this._request(`/api/agent-communications/message-watches/${encodeURIComponent(normalizedWatchId)}/acknowledge`, {
|
|
1277
|
+
method: 'POST',
|
|
1278
|
+
body: {
|
|
1279
|
+
observed_message_id: cleanText(observed_message_id) || cleanText(observedMessageId),
|
|
1280
|
+
observed_message_kind: cleanText(observed_message_kind) || cleanText(observedMessageKind) || cleanText(expected_message_kind) || cleanText(expectedMessageKind),
|
|
1281
|
+
last_checked_at: last_checked_at || lastCheckedAt,
|
|
1282
|
+
operator_nudge: cleanText(operator_nudge) || cleanText(operatorNudge),
|
|
1283
|
+
metadata: isPlainObject(metadata) ? metadata : {},
|
|
1284
|
+
},
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
async postAgentHeartbeat({
|
|
1289
|
+
transferChannelId,
|
|
1290
|
+
transfer_channel_id,
|
|
1291
|
+
channelId,
|
|
1292
|
+
channel_id,
|
|
1293
|
+
workTransferPacketId,
|
|
1294
|
+
work_transfer_packet_id,
|
|
1295
|
+
packetId,
|
|
1296
|
+
packet_id,
|
|
1297
|
+
workflowRunId,
|
|
1298
|
+
workflow_run_id,
|
|
1299
|
+
participantRole,
|
|
1300
|
+
participant_role,
|
|
1301
|
+
role,
|
|
1302
|
+
activityState,
|
|
1303
|
+
activity_state,
|
|
1304
|
+
agentSessionId,
|
|
1305
|
+
agent_session_id,
|
|
1306
|
+
actorSessionId,
|
|
1307
|
+
actor_session_id,
|
|
1308
|
+
currentPhase,
|
|
1309
|
+
current_phase,
|
|
1310
|
+
phase,
|
|
1311
|
+
currentTaskSummary,
|
|
1312
|
+
current_task_summary,
|
|
1313
|
+
isActive,
|
|
1314
|
+
is_active,
|
|
1315
|
+
observedAt,
|
|
1316
|
+
observed_at,
|
|
1317
|
+
metadata = {},
|
|
1318
|
+
} = {}) {
|
|
1319
|
+
const normalizedTransferChannelId = cleanText(transfer_channel_id) || cleanText(transferChannelId) || cleanText(channel_id) || cleanText(channelId);
|
|
1320
|
+
if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
|
|
1321
|
+
let normalizedPacketId = cleanText(work_transfer_packet_id) || cleanText(workTransferPacketId) || cleanText(packet_id) || cleanText(packetId);
|
|
1322
|
+
if (!normalizedPacketId) {
|
|
1323
|
+
try {
|
|
1324
|
+
const status = await this.getCommunicationChannelStatus({ transferChannelId: normalizedTransferChannelId });
|
|
1325
|
+
normalizedPacketId = cleanText(status?.packet_id || status?.packetId || status?.work_transfer_packet_id);
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
void error;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
if (!normalizedPacketId) throw new Error('work_transfer_packet_id is required.');
|
|
1331
|
+
return this._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/heartbeats`, {
|
|
1332
|
+
method: 'POST',
|
|
1333
|
+
body: {
|
|
1334
|
+
work_transfer_packet_id: normalizedPacketId,
|
|
1335
|
+
workflow_run_id: cleanText(workflow_run_id) || cleanText(workflowRunId),
|
|
1336
|
+
participant_role: cleanText(participant_role) || cleanText(participantRole) || cleanText(role),
|
|
1337
|
+
activity_state: cleanText(activity_state) || cleanText(activityState) || 'active',
|
|
1338
|
+
agent_session_id: cleanText(agent_session_id) || cleanText(agentSessionId),
|
|
1339
|
+
actor_session_id: cleanText(actor_session_id) || cleanText(actorSessionId),
|
|
1340
|
+
current_phase: cleanText(current_phase) || cleanText(currentPhase) || cleanText(phase),
|
|
1341
|
+
current_task_summary: cleanText(current_task_summary) || cleanText(currentTaskSummary),
|
|
1342
|
+
is_active: is_active ?? isActive ?? true,
|
|
1343
|
+
observed_at: observed_at || observedAt,
|
|
1344
|
+
metadata: isPlainObject(metadata) ? metadata : {},
|
|
1345
|
+
},
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
async postAgentMessage(request = {}) {
|
|
1350
|
+
return this._sendAgentCommsMessage(request);
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
async acknowledgeAgentMessage({
|
|
1354
|
+
transferChannelId,
|
|
1355
|
+
transfer_channel_id,
|
|
1356
|
+
channelId,
|
|
1357
|
+
channel_id,
|
|
1358
|
+
messageWatchId,
|
|
1359
|
+
message_watch_id,
|
|
1360
|
+
watchId,
|
|
1361
|
+
watch_id,
|
|
1362
|
+
messageId,
|
|
1363
|
+
message_id,
|
|
1364
|
+
messageKind,
|
|
1365
|
+
message_kind,
|
|
1366
|
+
observedMessageId,
|
|
1367
|
+
observed_message_id,
|
|
1368
|
+
observedMessageKind,
|
|
1369
|
+
observed_message_kind,
|
|
1370
|
+
operatorNudge,
|
|
1371
|
+
operator_nudge,
|
|
1372
|
+
metadata = {},
|
|
1373
|
+
} = {}) {
|
|
1374
|
+
const normalizedWatchId = cleanText(message_watch_id) || cleanText(messageWatchId) || cleanText(watch_id) || cleanText(watchId) || await this._resolveMessageWatchId({ transfer_channel_id, transferChannelId, channel_id, channelId });
|
|
1375
|
+
if (!normalizedWatchId) throw new Error('message_watch_id is required.');
|
|
1376
|
+
return this._request(`/api/agent-communications/message-watches/${encodeURIComponent(normalizedWatchId)}/acknowledge-message`, {
|
|
1377
|
+
method: 'POST',
|
|
1378
|
+
body: {
|
|
1379
|
+
observed_message_id: cleanText(observed_message_id) || cleanText(observedMessageId) || cleanText(message_id) || cleanText(messageId),
|
|
1380
|
+
observed_message_kind: cleanText(observed_message_kind) || cleanText(observedMessageKind) || cleanText(message_kind) || cleanText(messageKind),
|
|
1381
|
+
operator_nudge: cleanText(operator_nudge) || cleanText(operatorNudge),
|
|
1382
|
+
metadata: isPlainObject(metadata) ? metadata : {},
|
|
1383
|
+
},
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
async closeAgentChannel({
|
|
1388
|
+
transferChannelId,
|
|
1389
|
+
transfer_channel_id,
|
|
1390
|
+
channelId,
|
|
1391
|
+
channel_id,
|
|
1392
|
+
closureStatus,
|
|
1393
|
+
closure_status,
|
|
1394
|
+
closureReason,
|
|
1395
|
+
closure_reason,
|
|
1396
|
+
failureReason,
|
|
1397
|
+
failure_reason,
|
|
1398
|
+
evidence = {},
|
|
1399
|
+
evidenceManifestSha256,
|
|
1400
|
+
evidence_manifest_sha256,
|
|
1401
|
+
closedByAgentSessionId,
|
|
1402
|
+
closed_by_agent_session_id,
|
|
1403
|
+
closedByActorSessionId,
|
|
1404
|
+
closed_by_actor_session_id,
|
|
1405
|
+
closedByClaimId,
|
|
1406
|
+
closed_by_claim_id,
|
|
1407
|
+
metadata = {},
|
|
1408
|
+
} = {}) {
|
|
1409
|
+
const normalizedTransferChannelId = cleanText(transfer_channel_id) || cleanText(transferChannelId) || cleanText(channel_id) || cleanText(channelId);
|
|
1410
|
+
if (!normalizedTransferChannelId) throw new Error('transfer_channel_id is required.');
|
|
1411
|
+
return this._request(`/api/agent-communications/transfer-channels/${encodeURIComponent(normalizedTransferChannelId)}/close`, {
|
|
1412
|
+
method: 'POST',
|
|
1413
|
+
body: {
|
|
1414
|
+
closure_status: cleanText(closure_status) || cleanText(closureStatus) || 'closed',
|
|
1415
|
+
closure_reason: cleanText(closure_reason) || cleanText(closureReason),
|
|
1416
|
+
failure_reason: cleanText(failure_reason) || cleanText(failureReason),
|
|
1417
|
+
evidence: isPlainObject(evidence) ? evidence : {},
|
|
1418
|
+
evidence_manifest_sha256: cleanText(evidence_manifest_sha256) || cleanText(evidenceManifestSha256),
|
|
1419
|
+
closed_by_agent_session_id: cleanText(closed_by_agent_session_id) || cleanText(closedByAgentSessionId),
|
|
1420
|
+
closed_by_actor_session_id: cleanText(closed_by_actor_session_id) || cleanText(closedByActorSessionId),
|
|
1421
|
+
closed_by_claim_id: cleanText(closed_by_claim_id) || cleanText(closedByClaimId),
|
|
1422
|
+
metadata: isPlainObject(metadata) ? metadata : {},
|
|
1423
|
+
},
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1193
1427
|
async respondToMessageWatch({
|
|
1194
1428
|
transferChannelId,
|
|
1195
1429
|
transfer_channel_id,
|