| 20 | |
| 21 | /** Check if any message or system prompt has Anthropic cache_control markers */ |
| 22 | export function hasCacheControl(messages: any[], system?: any): boolean { |
| 23 | if (Array.isArray(system)) { |
| 24 | if (system.some((s: any) => s.cache_control)) return true; |
| 25 | } |
| 26 | if (typeof system === 'object' && system?.cache_control) return true; |
| 27 | for (const msg of messages || []) { |
| 28 | if (Array.isArray(msg.content)) { |
| 29 | if (msg.content.some((block: any) => block.cache_control)) return true; |
| 30 | } |
| 31 | } |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | function tokenCount(...values: any[]): number { |
| 36 | for (const value of values) { |