@yeaft/webchat-agent 1.0.476 → 1.0.478
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/local-runtime/server/context.js +25 -0
- package/local-runtime/server/handlers/agent-output.js +29 -1
- package/local-runtime/version.json +1 -1
- package/local-runtime/web/app.bundle.js +90 -145
- package/local-runtime/web/app.bundle.js.gz +0 -0
- package/local-runtime/web/index.html +1 -1
- package/package.json +1 -1
- package/yeaft/debug-trace.js +39 -362
- package/yeaft/engine.js +16 -9
- package/yeaft/sessions/session-crud.js +27 -27
- package/yeaft/web-bridge.js +43 -6
|
@@ -181,6 +181,31 @@ export function registerYeaftDebugRequest({ agentId, requestId, sessionId, clien
|
|
|
181
181
|
return true;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Advance one strictly ordered debug-detail chunk. The correlation is consumed
|
|
186
|
+
* only after the complete sequence arrives; each accepted frame renews its TTL.
|
|
187
|
+
*/
|
|
188
|
+
export function advanceYeaftDebugRequestChunk({ agentId, requestId, sessionId, chunkIndex, chunkCount }) {
|
|
189
|
+
if (!agentId || !requestId) return null;
|
|
190
|
+
const now = Date.now();
|
|
191
|
+
pruneYeaftDebugRequests(now);
|
|
192
|
+
const key = yeaftDebugRequestKey(agentId, requestId);
|
|
193
|
+
const pending = pendingYeaftDebugRequests.get(key);
|
|
194
|
+
if (!pending || (sessionId && pending.sessionId !== sessionId)) return null;
|
|
195
|
+
const expectedIndex = pending.nextChunkIndex ?? 0;
|
|
196
|
+
const expectedCount = pending.chunkCount ?? chunkCount;
|
|
197
|
+
if (chunkIndex !== expectedIndex || chunkCount !== expectedCount) {
|
|
198
|
+
pendingYeaftDebugRequests.delete(key);
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
pending.nextChunkIndex = expectedIndex + 1;
|
|
202
|
+
pending.chunkCount = chunkCount;
|
|
203
|
+
pending.expiresAt = now + YEAFT_DEBUG_REQUEST_TTL_MS;
|
|
204
|
+
const complete = pending.nextChunkIndex === chunkCount;
|
|
205
|
+
if (complete) pendingYeaftDebugRequests.delete(key);
|
|
206
|
+
return { pending, complete };
|
|
207
|
+
}
|
|
208
|
+
|
|
184
209
|
/**
|
|
185
210
|
* Consume a matching, unexpired correlation exactly once.
|
|
186
211
|
* @param {{agentId:string, requestId:string, sessionId?:string|null}} response
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from 'crypto';
|
|
|
2
2
|
import { messageDb, sessionUiMetadataDb, yeaftProjectDb, yeaftSessionDb } from '../database.js';
|
|
3
3
|
import { transaction } from '../db/connection.js';
|
|
4
4
|
import { broadcastAgentList, broadcastSessionCatalog, forwardToClients, sendToAgent, sendToWebClient } from '../ws-utils.js';
|
|
5
|
-
import { consumeYeaftDebugRequest, webClients, previewFiles } from '../context.js';
|
|
5
|
+
import { advanceYeaftDebugRequestChunk, consumeYeaftDebugRequest, webClients, previewFiles } from '../context.js';
|
|
6
6
|
import { CONFIG } from '../config.js';
|
|
7
7
|
import { yeaftAssetStore } from '../yeaft-asset-store.js';
|
|
8
8
|
import { recordPerfTraceEvent } from '../perf-trace.js';
|
|
@@ -1021,6 +1021,34 @@ export async function handleAgentOutput(agentId, agent, msg) {
|
|
|
1021
1021
|
break;
|
|
1022
1022
|
}
|
|
1023
1023
|
|
|
1024
|
+
case 'yeaft_debug_history_chunk': {
|
|
1025
|
+
const chunkIndex = Number(msg.chunkIndex);
|
|
1026
|
+
const chunkCount = Number(msg.chunkCount);
|
|
1027
|
+
const validChunk = Number.isSafeInteger(chunkIndex) && Number.isSafeInteger(chunkCount)
|
|
1028
|
+
&& chunkCount > 1 && chunkIndex >= 0 && chunkIndex < chunkCount
|
|
1029
|
+
&& typeof msg.data === 'string' && Buffer.byteLength(msg.data, 'utf8') <= 512 * 1024;
|
|
1030
|
+
if (!validChunk) break;
|
|
1031
|
+
// Advance only a strict 0..N-1 sequence. An out-of-order "final" frame
|
|
1032
|
+
// cannot consume a valid request, and every accepted frame renews the TTL.
|
|
1033
|
+
const advanced = advanceYeaftDebugRequestChunk({
|
|
1034
|
+
agentId, requestId: msg.requestId, sessionId: msg.sessionId,
|
|
1035
|
+
chunkIndex, chunkCount,
|
|
1036
|
+
});
|
|
1037
|
+
const pending = advanced?.pending || null;
|
|
1038
|
+
const targetClient = pending ? webClients.get(pending.clientId) : null;
|
|
1039
|
+
const ownerMatches = CONFIG.skipAuth || (
|
|
1040
|
+
pending?.userId === agent.ownerId && targetClient?.userId === pending.userId
|
|
1041
|
+
);
|
|
1042
|
+
if (targetClient?.authenticated && ownerMatches) {
|
|
1043
|
+
await sendToWebClient(targetClient, {
|
|
1044
|
+
type: 'yeaft_debug_history_chunk', agentId,
|
|
1045
|
+
requestId: msg.requestId, sessionId: msg.sessionId,
|
|
1046
|
+
chunkIndex, chunkCount, data: msg.data,
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
break;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1024
1052
|
case 'yeaft_debug_history': {
|
|
1025
1053
|
// Debug history is request/Turn scoped and may contain raw provider or
|
|
1026
1054
|
// tool payloads. The Server registered this Agent + requestId after the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.478"}
|