fix(core): report retry timeouts clearly

This commit is contained in:
Patrick Wozniak
2026-06-02 10:30:32 +02:00
parent e760a760fe
commit 221677b5ba
2 changed files with 15 additions and 2 deletions
+12 -2
View File
@@ -113,6 +113,14 @@ function abortError(message = "The operation was aborted"): DOMException {
return new DOMException(message, "AbortError")
}
function timeoutError(timeoutMs: number | undefined): Error {
return new Error(
timeoutMs === undefined
? "Command Code API request timed out"
: `Command Code API request timed out after ${timeoutMs}ms`,
)
}
function successStopReason(reason: TerminalReason): StopReason {
if (reason === "length" || reason === "toolUse") return reason
return "stop"
@@ -486,8 +494,9 @@ export function createStreamCommandCode(deps: CoreDependencies) {
})
} catch (fetchError: unknown) {
if (controller.signal.aborted) throw abortError("Aborted")
if (attemptTimedOut && attempt < maxRetries) {
continue retryLoop
if (attemptTimedOut) {
if (attempt < maxRetries) continue retryLoop
throw timeoutError(timeoutMs)
}
throw fetchError
}
@@ -582,6 +591,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
if (waitMs > 0) await delay(waitMs, controller.signal)
continue retryLoop
}
if (attemptTimedOut) throw timeoutError(timeoutMs)
throw streamError
}