feat: support auto-compact for "exceeds the available context size" errors
Browse filesAdd error handler for alternative context overflow format used by some
API providers. This ensures auto-compact triggers regardless of the
specific error wording.
- src/services/api/errors.ts +16 -0
src/services/api/errors.ts
CHANGED
|
@@ -573,6 +573,22 @@ export function getAssistantMessageFromError(
|
|
| 573 |
})
|
| 574 |
}
|
| 575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
// Check for PDF page limit errors
|
| 577 |
if (
|
| 578 |
error instanceof Error &&
|
|
|
|
| 573 |
})
|
| 574 |
}
|
| 575 |
|
| 576 |
+
// Handle "exceeds the available context size" errors (alternative format used by some API providers)
|
| 577 |
+
// This error format is functionally equivalent to "prompt is too long" and should trigger auto-compact
|
| 578 |
+
if (
|
| 579 |
+
error instanceof Error &&
|
| 580 |
+
error.message.toLowerCase().includes('exceeds the available context size')
|
| 581 |
+
) {
|
| 582 |
+
// Content stays generic (UI matches on exact string). The raw error with
|
| 583 |
+
// token counts goes into errorDetails — reactive compact's retry loop
|
| 584 |
+
// parses the gap from there via getPromptTooLongTokenGap.
|
| 585 |
+
return createAssistantAPIErrorMessage({
|
| 586 |
+
content: PROMPT_TOO_LONG_ERROR_MESSAGE,
|
| 587 |
+
error: 'invalid_request',
|
| 588 |
+
errorDetails: error.message,
|
| 589 |
+
})
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
// Check for PDF page limit errors
|
| 593 |
if (
|
| 594 |
error instanceof Error &&
|