@yeaft/webchat-agent 1.0.22 → 1.0.23
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 +1 -1
- package/yeaft/web-bridge.js +37 -10
package/package.json
CHANGED
package/yeaft/web-bridge.js
CHANGED
|
@@ -433,6 +433,32 @@ function buildVpPromptPayload(vpId, envelope) {
|
|
|
433
433
|
return { text, prompt, promptParts };
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
+
function buildPendingRescueEnvelope({ sessionId, taskId = null, threadId = 'main', followUpId, leftover, replayText, replayParts = null }) {
|
|
437
|
+
const leftoverIsInternal = Boolean(leftover?.internal);
|
|
438
|
+
const leftoverInjectedBy = leftoverIsInternal && typeof leftover?.injectedBy === 'string'
|
|
439
|
+
? leftover.injectedBy
|
|
440
|
+
: null;
|
|
441
|
+
return {
|
|
442
|
+
sessionId,
|
|
443
|
+
taskId,
|
|
444
|
+
trigger: 'pending_rescue',
|
|
445
|
+
msg: {
|
|
446
|
+
id: followUpId,
|
|
447
|
+
from: leftoverIsInternal && leftover.senderVpId ? leftover.senderVpId : 'user',
|
|
448
|
+
role: leftoverIsInternal ? 'assistant' : 'user',
|
|
449
|
+
text: replayText,
|
|
450
|
+
meta: {
|
|
451
|
+
rescuedFrom: 'pendingQueries',
|
|
452
|
+
threadId,
|
|
453
|
+
...(leftoverInjectedBy ? { injectedBy: leftoverInjectedBy } : {}),
|
|
454
|
+
...(leftoverIsInternal && leftover.senderVpId ? { senderVpId: leftover.senderVpId } : {}),
|
|
455
|
+
...(leftoverIsInternal && leftover.sourceThreadId ? { sourceThreadId: leftover.sourceThreadId } : {}),
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
...(Array.isArray(replayParts) && replayParts.length > 0 ? { _promptParts: replayParts } : {}),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
436
462
|
export function visibleInboundThreadId(envelope, fallbackThreadId = 'main') {
|
|
437
463
|
const meta = envelope?.msg?.meta || {};
|
|
438
464
|
if (
|
|
@@ -1350,6 +1376,9 @@ async function routeEnvelopeToVpThread(sessionId, vpId, envelope) {
|
|
|
1350
1376
|
originalText: text,
|
|
1351
1377
|
originalParts: Array.isArray(envelope?._promptParts) ? envelope._promptParts : null,
|
|
1352
1378
|
internal: isInternalAppend,
|
|
1379
|
+
injectedBy: isInternalAppend ? injectedBy : null,
|
|
1380
|
+
senderVpId: isInternalAppend ? (envelope?.msg?.meta?.senderVpId || envelope?.msg?.from || null) : null,
|
|
1381
|
+
sourceThreadId: isInternalAppend ? visibleInboundThreadId(envelope, thread.threadId) : null,
|
|
1353
1382
|
});
|
|
1354
1383
|
persistInboundMessageOnceByMsgId({
|
|
1355
1384
|
msgId: envelope?.msg?.id,
|
|
@@ -1534,18 +1563,15 @@ function ensureDriverRunning(sessionId, vpId, threadId = 'main') {
|
|
|
1534
1563
|
: null;
|
|
1535
1564
|
if (!replayText && !replayParts) continue;
|
|
1536
1565
|
const followUpId = `followup_${Date.now().toString(36)}_${randomUUID().slice(0, 8)}`;
|
|
1537
|
-
const followUpEnvelope = {
|
|
1566
|
+
const followUpEnvelope = buildPendingRescueEnvelope({
|
|
1538
1567
|
sessionId,
|
|
1539
1568
|
taskId: envelope?.taskId || null,
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
},
|
|
1547
|
-
...(replayParts ? { _promptParts: replayParts } : {}),
|
|
1548
|
-
};
|
|
1569
|
+
threadId: thread.threadId,
|
|
1570
|
+
followUpId,
|
|
1571
|
+
leftover,
|
|
1572
|
+
replayText,
|
|
1573
|
+
replayParts,
|
|
1574
|
+
});
|
|
1549
1575
|
const followUpTurnId = `${randomUUID().slice(0, 8)}:${vpId}`;
|
|
1550
1576
|
inbox.push({ envelope: followUpEnvelope, turnId: followUpTurnId, thread });
|
|
1551
1577
|
try {
|
|
@@ -5260,6 +5286,7 @@ export async function handleYeaftMcpReload(msg = {}) {
|
|
|
5260
5286
|
export const __testHooks = {
|
|
5261
5287
|
loadVisibleGroupHistoryPage,
|
|
5262
5288
|
persistInboundMessageOnceByMsgId,
|
|
5289
|
+
buildPendingRescueEnvelope,
|
|
5263
5290
|
setSessionForTest(nextSession) {
|
|
5264
5291
|
session = nextSession || null;
|
|
5265
5292
|
},
|