MCPcopy Index your code
hub / github.com/continuedev/continue / pruneLastMessage

Function pruneLastMessage

extensions/cli/src/compaction.ts:195–220  ·  view source on GitHub ↗
(
  chatHistory: ChatHistoryItem[],
)

Source from the content-addressed store, hash-verified

193 * @returns The pruned chat history ending with assistant or tool message
194 */
195export function pruneLastMessage(
196 chatHistory: ChatHistoryItem[],
197): ChatHistoryItem[] {
198 if (chatHistory.length === 0) {
199 return chatHistory;
200 }
201
202 if (chatHistory.length === 1) {
203 // Only one message - always return empty array
204 return [];
205 }
206
207 const secondToLastIndex = chatHistory.length - 2;
208 const secondToLastItem = chatHistory[secondToLastIndex];
209
210 if (
211 secondToLastItem.message.role === "assistant" &&
212 (secondToLastItem.message as any).toolCalls?.length > 0
213 ) {
214 return chatHistory.slice(0, -2);
215 } else if (secondToLastItem.message.role === "user") {
216 return chatHistory.slice(0, -2);
217 }
218
219 return chatHistory.slice(0, -1);
220}
221
222export function getHistoryForLLM(
223 fullHistory: ChatHistoryItem[],

Callers 3

compactChatHistoryFunction · 0.85
processStreamingResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected