buster/packages/ai/src/tools/shared/cleanup-state.ts

13 lines
416 B
TypeScript

/**
* Cleanup helper to clear tool state after execution
* Helps prevent memory leaks during long-running streaming sessions
*/
export function cleanupState(state: Record<string, unknown>): void {
// Clear all properties except toolCallId (might be needed for logging)
Object.keys(state).forEach((key) => {
if (key !== 'toolCallId' && key !== 'isFinalizing') {
state[key] = undefined;
}
});
}