From d7ea6769cb47a97ccf4b743e343ea42712eab0cd Mon Sep 17 00:00:00 2001 From: KernelDeimos <7225168+KernelDeimos@users.noreply.github.com> Date: Tue, 4 Nov 2025 22:27:19 -0500 Subject: [PATCH] fix: check if system_prompts is an empty array It was assumpted that `system_prompts[0]` could not be undefined which is not accurate because sometimes there are no system prompts. --- src/backend/src/modules/puterai/ClaudeService.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/src/modules/puterai/ClaudeService.js b/src/backend/src/modules/puterai/ClaudeService.js index b5d11e7f..187f74e0 100644 --- a/src/backend/src/modules/puterai/ClaudeService.js +++ b/src/backend/src/modules/puterai/ClaudeService.js @@ -128,7 +128,11 @@ class ClaudeService extends BaseService { [system_prompts, messages] = Messages.extract_and_remove_system_messages(messages); // Apply the cache control tag to all content blocks - if (system_prompts[0].cache_control && system_prompts[0]?.content) { + if ( + system_prompts.length > 0 && + system_prompts[0].cache_control && + system_prompts[0]?.content + ) { system_prompts[0].content = system_prompts[0].content.map(prompt => { prompt.cache_control = system_prompts[0].cache_control; return prompt;