Add retry status model extraction helper

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-11 17:53:21 +09:00
parent 70edea2d7f
commit aa6b635783
+47 -15
View File
@@ -1,19 +1,51 @@
export function normalizeRetryStatusMessage(message: string): string { const RETRY_COUNTDOWN_PATTERN = /\[\s*retrying\s+in[^\]]*\]/gi
return message
.replace(/\[retrying in [^\]]*attempt\s*#\d+\]/gi, "[retrying]") function collapseWhitespace(value: string): string {
.replace(/retrying in\s+[^(]*attempt\s*#\d+/gi, "retrying") return value.toLowerCase().replace(/\s+/g, " ").trim()
.replace(/\s+/g, " ")
.trim()
.toLowerCase()
} }
export function extractRetryAttempt(statusAttempt: unknown, message: string): string { export function extractRetryAttempt(attempt: number | undefined, message: string): number | "?" {
if (typeof statusAttempt === "number" && Number.isFinite(statusAttempt)) { if (typeof attempt === "number" && Number.isFinite(attempt)) {
return String(statusAttempt) return attempt
} }
const attemptMatch = message.match(/attempt\s*#\s*(\d+)/i)
if (attemptMatch?.[1]) { const parsedAttempt = message.match(/attempt\s*#\s*(\d+)/i)?.[1]
return attemptMatch[1] return parsedAttempt ? Number.parseInt(parsedAttempt, 10) : "?"
} }
return "?"
export function extractRetryStatusModel(message: string): string | undefined {
return message.match(/model\s+([a-z0-9._/-]+)(?=\s+(?:are|is)\b)/i)?.[1]?.toLowerCase()
}
export function normalizeRetryStatusMessage(message: string): string {
const normalizedMessage = collapseWhitespace(message.replace(RETRY_COUNTDOWN_PATTERN, " "))
if (!normalizedMessage) {
return "retry"
}
if (/all\s+credentials\s+for\s+model|cool(?:ing)?\s+down|cooldown|exhausted\s+your\s+capacity/.test(normalizedMessage)) {
return "cooldown"
}
if (/too\s+many\s+requests/.test(normalizedMessage)) {
return "too-many-requests"
}
if (/quota\s+will\s+reset\s+after|quota\s*exceeded/.test(normalizedMessage)) {
return "quota"
}
if (/usage\s+limit\s+has\s+been\s+reached|limit\s+reached/.test(normalizedMessage)) {
return "usage-limit"
}
if (/rate\s+limit/.test(normalizedMessage)) {
return "rate-limit"
}
if (/service.?unavailable|temporarily.?unavailable|overloaded/.test(normalizedMessage)) {
return "service-unavailable"
}
return normalizedMessage
} }