From 236beefb708a6cd91b673978ddf4ebf045a9844c Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Sat, 23 May 2026 16:59:20 +0900 Subject: feat: key fallback using agent models[] hierarchy, background tool modes, copy truncation - Agent rate-limit fallback now iterates through agent's configured models[] in strict order - Frontend sends agentModels with each /chat request; backend uses buildFallbackSequence() - Emits notice event on fallback so chat shows which key failed and what's being tried next - Child agents inherit parent's agentModels for fallback - Added statusCode propagation from AI SDK errors for programmatic 429 detection - Copy button truncates all tool results at 300 chars (was 200 for 4 specific tools) - run_shell, summon, youtube_transcribe: background mode support - summon: blocking mode by default with getResult callback --- packages/core/src/agent/agent.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'packages/core/src/agent') diff --git a/packages/core/src/agent/agent.ts b/packages/core/src/agent/agent.ts index 6f1a5a4..bf9b22f 100644 --- a/packages/core/src/agent/agent.ts +++ b/packages/core/src/agent/agent.ts @@ -311,8 +311,15 @@ export class Agent { allToolCalls.push(toolCall); yield { type: "tool-call", toolCall }; } else if (event.type === "error") { + const errRecord = event.error as unknown as Record; + const statusCode = + typeof errRecord.statusCode === "number" ? errRecord.statusCode : undefined; const errorMsg = formatError(event.error, this.config); - yield { type: "error", error: errorMsg }; + yield { + type: "error", + error: errorMsg, + ...(statusCode !== undefined ? { statusCode } : {}), + }; this.status = "error"; yield { type: "status", status: "error" }; return; @@ -471,8 +478,11 @@ export class Agent { yield { type: "done", message: assistantMessage }; } catch (err) { + const errRecord = err as unknown as Record; + const statusCode = + typeof errRecord.statusCode === "number" ? errRecord.statusCode : undefined; const errorMsg = formatError(err, this.config); - yield { type: "error", error: errorMsg }; + yield { type: "error", error: errorMsg, ...(statusCode !== undefined ? { statusCode } : {}) }; this.status = "error"; yield { type: "status", status: "error" }; return; -- cgit v1.2.3