- Deduplication: removes consecutive identical tool_call+tool_result pairs - Purge-errors: removes failed/empty tool results - Transform orchestrator runs strategies in sequence pre-payload - Wired into turn.ts before buildMessagesPayload - Clean-room reimplementation (AGPL reference: behavior only)
28 lines
811 B
TypeScript
28 lines
811 B
TypeScript
// Per-chat session state for DCP.
|
|
// Tracks last transform timestamp and message count to avoid re-processing.
|
|
|
|
interface ChatDcpState {
|
|
lastTransformAt: number;
|
|
lastMessageCount: number;
|
|
}
|
|
|
|
const chatStates = new Map<string, ChatDcpState>();
|
|
|
|
export function getDcpState(chatId: string): ChatDcpState | undefined {
|
|
return chatStates.get(chatId);
|
|
}
|
|
|
|
export function setDcpState(chatId: string, messageCount: number): void {
|
|
chatStates.set(chatId, { lastTransformAt: Date.now(), lastMessageCount: messageCount });
|
|
}
|
|
|
|
export function clearDcpState(chatId: string): void {
|
|
chatStates.delete(chatId);
|
|
}
|
|
|
|
export function shouldTransform(chatId: string, messageCount: number): boolean {
|
|
const state = chatStates.get(chatId);
|
|
if (!state) return true;
|
|
return state.lastMessageCount !== messageCount;
|
|
}
|