( messages: Message[], sinceUuid: string | undefined, )
| 107 | } |
| 108 | |
| 109 | function countToolCallsSince( |
| 110 | messages: Message[], |
| 111 | sinceUuid: string | undefined, |
| 112 | ): number { |
| 113 | let toolCallCount = 0 |
| 114 | let foundStart = sinceUuid === null || sinceUuid === undefined |
| 115 | |
| 116 | for (const message of messages) { |
| 117 | if (!foundStart) { |
| 118 | if (message.uuid === sinceUuid) { |
| 119 | foundStart = true |
| 120 | } |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | if (message.type === 'assistant') { |
| 125 | const content = message.message.content |
| 126 | if (Array.isArray(content)) { |
| 127 | toolCallCount += count(content, block => block.type === 'tool_use') |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return toolCallCount |
| 133 | } |
| 134 | |
| 135 | export function shouldExtractMemory(messages: Message[]): boolean { |
| 136 | // Check if we've met the initialization threshold |
no test coverage detected