fix(v5): recognize conversation depth errors (#2957)
Backport of #2881.\n\nOriginal commit: f68e52251c
Co-authored-by: Felipe Bermudez <felipeberm@gmail.com>
This commit is contained in:
parent
b28bc84904
commit
b33a7f7b1c
3 changed files with 44 additions and 2 deletions
5
.changeset/deep-conversations-start.md
Normal file
5
.changeset/deep-conversations-start.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@docsearch/react": patch
|
||||
---
|
||||
|
||||
Recognize current Agent Studio conversation-depth error messages.
|
||||
|
|
@ -10,10 +10,47 @@ import {
|
|||
getSearchToolQueries,
|
||||
isAIToolPart,
|
||||
isAlgoliaMCPSearchOutputPart,
|
||||
isThreadDepthError,
|
||||
sanitizeMessagesForRequest,
|
||||
getMessageContent,
|
||||
} from '../ai';
|
||||
|
||||
describe('isThreadDepthError', () => {
|
||||
it('detects AI-217 regardless of casing', () => {
|
||||
expect(isThreadDepthError(new Error('AI-217: limit reached'))).toBe(true);
|
||||
expect(isThreadDepthError(new Error('prefix ai-217 suffix'))).toBe(true);
|
||||
});
|
||||
|
||||
it('detects conversation depth phrasing', () => {
|
||||
expect(
|
||||
isThreadDepthError(
|
||||
new Error(
|
||||
"You've hit the max conversation depth (4 messages), start a new conversation."
|
||||
)
|
||||
)
|
||||
).toBe(true);
|
||||
expect(
|
||||
isThreadDepthError(new Error('Maximum conversation depth reached.'))
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('detects conversation depth in a JSON-shaped error message', () => {
|
||||
expect(
|
||||
isThreadDepthError(
|
||||
new Error(
|
||||
JSON.stringify({ message: 'Maximum conversation depth reached.' })
|
||||
)
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('ignores unrelated errors', () => {
|
||||
expect(isThreadDepthError()).toBe(false);
|
||||
expect(isThreadDepthError(new Error('Network failed'))).toBe(false);
|
||||
expect(isThreadDepthError(new Error('AI-214: rate limit'))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
function message(id: string, parts: AIMessagePart[]): AIMessage {
|
||||
return {
|
||||
id,
|
||||
|
|
|
|||
|
|
@ -122,11 +122,11 @@ export const getMessageContent = (message: AIMessage | null): string =>
|
|||
.map((part) => part.text)
|
||||
.join('\n\n');
|
||||
|
||||
/** Helper function to check if error is a thread depth error (AI-217). */
|
||||
/** Helper function to check if an error reports the conversation depth limit. */
|
||||
export function isThreadDepthError(error?: Error): boolean {
|
||||
if (!error) return false;
|
||||
|
||||
return error.message?.includes('AI-217') || false;
|
||||
return /(?:ai-217|conversation\s+depth)/i.test(error.message ?? '');
|
||||
}
|
||||
|
||||
export const EMPTY_TOOLS: Readonly<ToolCalls> = Object.freeze({});
|
||||
|
|
|
|||
Loading…
Reference in a new issue