mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-09 18:29:39 +00:00
fix case where opencode wasn't retrying
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { NamedError } from "@opencode-ai/util/error"
|
||||
import { MessageV2 } from "./message-v2"
|
||||
|
||||
export namespace SessionRetry {
|
||||
@@ -51,4 +52,22 @@ export namespace SessionRetry {
|
||||
|
||||
return Math.min(RETRY_INITIAL_DELAY * Math.pow(RETRY_BACKOFF_FACTOR, attempt - 1), RETRY_MAX_DELAY_NO_HEADERS)
|
||||
}
|
||||
|
||||
export function retryable(error: ReturnType<NamedError["toObject"]>) {
|
||||
if (MessageV2.APIError.isInstance(error)) {
|
||||
if (!error.data.isRetryable) return undefined
|
||||
return error.data.message.includes("Overloaded") ? "Provider is overloaded" : error.data.message
|
||||
}
|
||||
|
||||
if (typeof error.data?.message === "string") {
|
||||
try {
|
||||
const json = JSON.parse(error.data.message)
|
||||
if (json.type === "error" && json.error?.type === "too_many_requests") {
|
||||
return "Too Many Requests"
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user