@annals/agent-mesh 0.18.6 → 0.19.0
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/dist/index.js +55 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1508,10 +1508,7 @@ var BridgeManager = class {
|
|
|
1508
1508
|
}
|
|
1509
1509
|
async dispatchWithLocalQueue(opts) {
|
|
1510
1510
|
const { msg, handle, requestKey } = opts;
|
|
1511
|
-
const { session_id, request_id, content, attachments, client_id, with_files
|
|
1512
|
-
if (file_upload_offer) {
|
|
1513
|
-
this.registerPendingUpload(file_upload_offer, session_id, request_id);
|
|
1514
|
-
}
|
|
1511
|
+
const { session_id, request_id, content, attachments, client_id, with_files } = msg;
|
|
1515
1512
|
const state = this.requestDispatches.get(requestKey);
|
|
1516
1513
|
if (!state) return;
|
|
1517
1514
|
try {
|
|
@@ -1833,6 +1830,11 @@ var BridgeManager = class {
|
|
|
1833
1830
|
log.info(`WebRTC transfer registered: transfer=${offer.transfer_id.slice(0, 8)}... (${(zipBuffer.length / 1024).toFixed(1)} KB in memory)`);
|
|
1834
1831
|
}
|
|
1835
1832
|
handleRtcSignalRelay(msg) {
|
|
1833
|
+
if (msg.signal_type === "prepare-upload") {
|
|
1834
|
+
const offer = JSON.parse(msg.payload);
|
|
1835
|
+
this.registerPendingUpload(offer, "pre-upload", "pre-upload");
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1836
1838
|
const downloadEntry = this.pendingTransfers.get(msg.transfer_id);
|
|
1837
1839
|
if (downloadEntry) {
|
|
1838
1840
|
downloadEntry.targetAgentId = msg.from_agent_id;
|
|
@@ -4167,8 +4169,7 @@ async function asyncChat(opts) {
|
|
|
4167
4169
|
},
|
|
4168
4170
|
body: JSON.stringify({
|
|
4169
4171
|
message: opts.message,
|
|
4170
|
-
mode: "async"
|
|
4171
|
-
...opts.fileUploadOffer ? { file_upload_offer: opts.fileUploadOffer } : {}
|
|
4172
|
+
mode: "async"
|
|
4172
4173
|
}),
|
|
4173
4174
|
signal: opts.signal
|
|
4174
4175
|
});
|
|
@@ -4238,8 +4239,7 @@ async function streamChat(opts) {
|
|
|
4238
4239
|
"Content-Type": "application/json"
|
|
4239
4240
|
},
|
|
4240
4241
|
body: JSON.stringify({
|
|
4241
|
-
message: opts.message
|
|
4242
|
-
...opts.fileUploadOffer ? { file_upload_offer: opts.fileUploadOffer } : {}
|
|
4242
|
+
message: opts.message
|
|
4243
4243
|
}),
|
|
4244
4244
|
signal: opts.signal
|
|
4245
4245
|
});
|
|
@@ -4376,8 +4376,6 @@ function registerChatCommand(program2) {
|
|
|
4376
4376
|
log.banner(`Chat with ${agentName}`);
|
|
4377
4377
|
console.log(`${GRAY}Type your message and press Enter. /upload <path> to send a file. /quit to exit.${RESET}
|
|
4378
4378
|
`);
|
|
4379
|
-
let pendingUploadOffer;
|
|
4380
|
-
let pendingUploadZipBuffer;
|
|
4381
4379
|
const rl = createInterface4({
|
|
4382
4380
|
input: process.stdin,
|
|
4383
4381
|
output: process.stdout,
|
|
@@ -4414,20 +4412,33 @@ function registerChatCommand(program2) {
|
|
|
4414
4412
|
}
|
|
4415
4413
|
try {
|
|
4416
4414
|
const prepared = prepareUploadFile(filePath);
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4415
|
+
const prepRes = await fetch(`${opts.baseUrl}/api/agents/${agentId}/rtc-signal`, {
|
|
4416
|
+
method: "POST",
|
|
4417
|
+
headers: {
|
|
4418
|
+
Authorization: `Bearer ${token}`,
|
|
4419
|
+
"Content-Type": "application/json"
|
|
4420
|
+
},
|
|
4421
|
+
body: JSON.stringify({
|
|
4422
|
+
transfer_id: prepared.offer.transfer_id,
|
|
4423
|
+
signal_type: "prepare-upload",
|
|
4424
|
+
payload: JSON.stringify(prepared.offer)
|
|
4425
|
+
})
|
|
4426
|
+
});
|
|
4427
|
+
if (!prepRes.ok) {
|
|
4428
|
+
log.error(`Failed to signal upload: HTTP ${prepRes.status}`);
|
|
4429
|
+
rl.prompt();
|
|
4430
|
+
return;
|
|
4431
|
+
}
|
|
4432
|
+
await sleep5(500);
|
|
4433
|
+
await chatWebrtcUpload(agentId, prepared.offer, prepared.zipBuffer, token, opts.baseUrl);
|
|
4434
|
+
log.info(`File uploaded. Type a message to continue.`);
|
|
4420
4435
|
} catch (err) {
|
|
4421
|
-
log.error(`
|
|
4436
|
+
log.error(`Upload failed: ${err.message}`);
|
|
4422
4437
|
}
|
|
4423
4438
|
rl.prompt();
|
|
4424
4439
|
return;
|
|
4425
4440
|
}
|
|
4426
4441
|
console.log("");
|
|
4427
|
-
const uploadOffer = pendingUploadOffer;
|
|
4428
|
-
const uploadZipBuffer = pendingUploadZipBuffer;
|
|
4429
|
-
pendingUploadOffer = void 0;
|
|
4430
|
-
pendingUploadZipBuffer = void 0;
|
|
4431
4442
|
try {
|
|
4432
4443
|
await streamChat({
|
|
4433
4444
|
agentId,
|
|
@@ -4435,12 +4446,8 @@ function registerChatCommand(program2) {
|
|
|
4435
4446
|
token,
|
|
4436
4447
|
baseUrl: opts.baseUrl,
|
|
4437
4448
|
showThinking: opts.thinking,
|
|
4438
|
-
mode
|
|
4439
|
-
fileUploadOffer: uploadOffer
|
|
4449
|
+
mode
|
|
4440
4450
|
});
|
|
4441
|
-
if (uploadOffer && uploadZipBuffer) {
|
|
4442
|
-
await chatWebrtcUpload(agentId, uploadOffer, uploadZipBuffer, token, opts.baseUrl);
|
|
4443
|
-
}
|
|
4444
4451
|
} catch (err) {
|
|
4445
4452
|
if (abortController.signal.aborted) return;
|
|
4446
4453
|
log.error(err.message);
|
|
@@ -5433,6 +5440,23 @@ function prepareFileForUpload(filePath) {
|
|
|
5433
5440
|
zipBuffer: Buffer.from(zipBuffer)
|
|
5434
5441
|
};
|
|
5435
5442
|
}
|
|
5443
|
+
async function sendPrepareUpload(agentId, offer, token) {
|
|
5444
|
+
const res = await fetch(`${DEFAULT_BASE_URL4}/api/agents/${agentId}/rtc-signal`, {
|
|
5445
|
+
method: "POST",
|
|
5446
|
+
headers: {
|
|
5447
|
+
Authorization: `Bearer ${token}`,
|
|
5448
|
+
"Content-Type": "application/json"
|
|
5449
|
+
},
|
|
5450
|
+
body: JSON.stringify({
|
|
5451
|
+
transfer_id: offer.transfer_id,
|
|
5452
|
+
signal_type: "prepare-upload",
|
|
5453
|
+
payload: JSON.stringify(offer)
|
|
5454
|
+
})
|
|
5455
|
+
});
|
|
5456
|
+
if (!res.ok) {
|
|
5457
|
+
throw new Error(`prepare-upload signal failed: HTTP ${res.status}`);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5436
5460
|
async function webrtcUpload(agentId, offer, zipBuffer, token, json) {
|
|
5437
5461
|
if (!json) {
|
|
5438
5462
|
log.info(`[WebRTC] Uploading file (${(offer.zip_size / 1024).toFixed(1)} KB)...`);
|
|
@@ -5527,8 +5551,7 @@ async function asyncCall(opts) {
|
|
|
5527
5551
|
body: JSON.stringify({
|
|
5528
5552
|
task_description: opts.taskDescription,
|
|
5529
5553
|
mode: "async",
|
|
5530
|
-
...opts.withFiles ? { with_files: true } : {}
|
|
5531
|
-
...opts.uploadOffer ? { file_upload_offer: opts.uploadOffer } : {}
|
|
5554
|
+
...opts.withFiles ? { with_files: true } : {}
|
|
5532
5555
|
}),
|
|
5533
5556
|
signal: opts.signal
|
|
5534
5557
|
});
|
|
@@ -5647,8 +5670,7 @@ async function streamCall(opts) {
|
|
|
5647
5670
|
},
|
|
5648
5671
|
body: JSON.stringify({
|
|
5649
5672
|
task_description: opts.taskDescription,
|
|
5650
|
-
...opts.withFiles ? { with_files: true } : {}
|
|
5651
|
-
...opts.uploadOffer ? { file_upload_offer: opts.uploadOffer } : {}
|
|
5673
|
+
...opts.withFiles ? { with_files: true } : {}
|
|
5652
5674
|
}),
|
|
5653
5675
|
signal: opts.signal
|
|
5654
5676
|
});
|
|
@@ -5831,6 +5853,11 @@ ${content}`;
|
|
|
5831
5853
|
const timeoutMs = parseInt(opts.timeout || "300", 10) * 1e3;
|
|
5832
5854
|
const abortController = new AbortController();
|
|
5833
5855
|
const timer = setTimeout(() => abortController.abort(), timeoutMs);
|
|
5856
|
+
if (uploadOffer && uploadZipBuffer) {
|
|
5857
|
+
await sendPrepareUpload(id, uploadOffer, token);
|
|
5858
|
+
await sleep6(500);
|
|
5859
|
+
await webrtcUpload(id, uploadOffer, uploadZipBuffer, token, opts.json);
|
|
5860
|
+
}
|
|
5834
5861
|
const callOpts = {
|
|
5835
5862
|
id,
|
|
5836
5863
|
name,
|
|
@@ -5840,20 +5867,13 @@ ${content}`;
|
|
|
5840
5867
|
json: opts.json,
|
|
5841
5868
|
outputFile: opts.outputFile,
|
|
5842
5869
|
signal: abortController.signal,
|
|
5843
|
-
withFiles: opts.withFiles
|
|
5844
|
-
uploadOffer
|
|
5870
|
+
withFiles: opts.withFiles
|
|
5845
5871
|
};
|
|
5846
5872
|
let result;
|
|
5847
5873
|
if (opts.stream) {
|
|
5848
|
-
if (uploadOffer && uploadZipBuffer) {
|
|
5849
|
-
void webrtcUpload(id, uploadOffer, uploadZipBuffer, token, opts.json);
|
|
5850
|
-
}
|
|
5851
5874
|
result = await streamCall(callOpts);
|
|
5852
5875
|
} else {
|
|
5853
5876
|
result = await asyncCall(callOpts);
|
|
5854
|
-
if (uploadOffer && uploadZipBuffer) {
|
|
5855
|
-
await webrtcUpload(id, uploadOffer, uploadZipBuffer, token, opts.json);
|
|
5856
|
-
}
|
|
5857
5877
|
}
|
|
5858
5878
|
clearTimeout(timer);
|
|
5859
5879
|
if (opts.rate && result.callId) {
|