Improves ping response validation robustness

Enhances API ping check to handle multiple text content blocks

Modifies response text extraction to:
- Process all text content blocks
- Support multiple text segments
- Normalize and validate ping response more comprehensively

Increases reliability of API connection verification
This commit is contained in:
AlexKucera committed 2025-10-31 13:17:36 +01:00
1 parent d31cec0383
commit d5af2a08ce
1 file changed
+7 -1
+7 -1
View File
@@ -408,8 +408,14 @@ export class AnthropicClient {
// Validate that the assistant actually returned "ping" // Validate that the assistant actually returned "ping"
// This ensures the API is working correctly, not just returning a 2xx status // This ensures the API is working correctly, not just returning a 2xx status
// Check all content blocks (not just first) in case of multiple text blocks
// Normalize to tolerate punctuation and quotes (e.g., "ping.", ""ping"") // Normalize to tolerate punctuation and quotes (e.g., "ping.", ""ping"")
const returnedText = (response.content?.[0]?.text || '').trim().toLowerCase(); const returnedText = (response.content || [])
.filter(c => c && c.type === 'text' && typeof c.text === 'string')
.map(c => c.text)
.join(' ')
.trim()
.toLowerCase();
const normalized = returnedText.replace(/^[^a-z]+|[^a-z]+$/g, '').replace(/\s+/g, ''); const normalized = returnedText.replace(/^[^a-z]+|[^a-z]+$/g, '').replace(/\s+/g, '');
const isValid = normalized === 'ping'; const isValid = normalized === 'ping';