fix(token-limit): normalize detection across providers
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
const TOKEN_LIMIT_ERROR_NAMES = new Set([
|
||||
"contextlengtherror",
|
||||
])
|
||||
import { isRetryableModelError } from "../../shared/model-error-classifier"
|
||||
|
||||
const TOKEN_LIMIT_KEYWORDS = [
|
||||
const TOKEN_LIMIT_FALLBACK_PATTERNS = [
|
||||
"prompt is too long",
|
||||
"is too long",
|
||||
"context_length_exceeded",
|
||||
@@ -11,16 +9,29 @@ const TOKEN_LIMIT_KEYWORDS = [
|
||||
"too many tokens",
|
||||
]
|
||||
|
||||
const TOKEN_LIMIT_ERROR_NAMES = new Set([
|
||||
"contextlengtherror",
|
||||
"context_length_exceeded",
|
||||
])
|
||||
|
||||
export function isTokenLimitError(error: { name?: string; message?: string } | undefined): boolean {
|
||||
if (!error) return false
|
||||
|
||||
if (error.name && TOKEN_LIMIT_ERROR_NAMES.has(error.name.toLowerCase())) {
|
||||
return true
|
||||
const isRetryable = isRetryableModelError({
|
||||
name: error.name,
|
||||
message: error.message,
|
||||
})
|
||||
|
||||
if (!isRetryable && error.name) {
|
||||
const errorNameLower = error.name.toLowerCase()
|
||||
if (TOKEN_LIMIT_ERROR_NAMES.has(errorNameLower)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if (error.message) {
|
||||
const lower = error.message.toLowerCase()
|
||||
return TOKEN_LIMIT_KEYWORDS.some((keyword) => lower.includes(keyword))
|
||||
return TOKEN_LIMIT_FALLBACK_PATTERNS.some((pattern) => lower.includes(pattern))
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user