From d5af2a08ce041fbc0bb376b0d958733c31f0c48f Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 31 Oct 2025 13:17:36 +0100 Subject: [PATCH] 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 --- api/anthropicClient.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/anthropicClient.ts b/api/anthropicClient.ts index a800984..02601c6 100644 --- a/api/anthropicClient.ts +++ b/api/anthropicClient.ts @@ -408,8 +408,14 @@ export class AnthropicClient { // Validate that the assistant actually returned "ping" // 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"") - 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 isValid = normalized === 'ping';