fix: log mid-stream errors to transcript, notes on retrieving

This commit is contained in:
cpacker
2025-10-27 18:45:04 -07:00
parent 6969208403
commit 8ff2cc4d22
3 changed files with 29 additions and 0 deletions

View File

@@ -198,6 +198,27 @@ export function onChunk(
b: Buffers,
chunk: Letta.agents.LettaStreamingResponse,
) {
// TODO remove once SDK v1 has proper typing for in-stream errors
// Check for streaming error objects (not typed in SDK but emitted by backend)
// These are emitted when LLM errors occur during streaming (rate limits, timeouts, etc.)
const chunkAny = chunk as any;
if (chunkAny.error && !chunk.messageType) {
const errorId = `err-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
const errorMsg = chunkAny.error.message || "An error occurred";
const errorDetail = chunkAny.error.detail || "";
const fullErrorText = errorDetail
? `${errorMsg}: ${errorDetail}`
: errorMsg;
b.byId.set(errorId, {
kind: "error",
id: errorId,
text: `${fullErrorText}`,
});
b.order.push(errorId);
return;
}
switch (chunk.messageType) {
case "reasoning_message": {
const id = chunk.otid;