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.
This commit is contained in:
KernelDeimos
2025-11-04 22:27:19 -05:00
committed by Eric Dubé
parent b853383c6e
commit d7ea6769cb

View File

@@ -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;