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