(history: readonly ContextMessage[], options?: ProjectOptions)
| 97 | | { readonly kind: 'whitespace_text_dropped'; readonly role: string }; |
| 98 | |
| 99 | export function project(history: readonly ContextMessage[], options?: ProjectOptions): Message[] { |
| 100 | let result = mergeAdjacentUserMessages(history, options?.onAnomaly); |
| 101 | if (options?.dedupeDuplicateToolCalls === true) { |
| 102 | result = dedupeDuplicateToolCalls(result, options.onAnomaly); |
| 103 | } |
| 104 | result = repairToolExchangeAdjacency(result, options); |
| 105 | if (options?.mergeConsecutiveAssistants === true) { |
| 106 | result = mergeConsecutiveAssistantMessages(result, options.onAnomaly); |
| 107 | } |
| 108 | if (options?.dropOrphanResults === true) { |
| 109 | result = dropOrphanToolResults(result, options.onAnomaly); |
| 110 | } |
| 111 | if (options?.dropLeadingNonUser === true) { |
| 112 | result = dropLeadingNonUserMessages(result, options.onAnomaly); |
| 113 | } |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | // Strict providers (Anthropic) require every assistant `tool_use` to be answered |
| 118 | // by a matching `tool_result` in the immediately following message(s). A |
no test coverage detected