/**
 * Passive turn sync — sends conversation pairs to Mem0 for server-side extraction.
 * Buffers user and assistant messages, syncs as pairs.
 */
export class TurnSync {
    provider;
    userId;
    inflight = false;
    lastUserText = '';
    constructor(provider, userId) {
        this.provider = provider;
        this.userId = userId;
    }
    /** Buffer a message. When we have a user+assistant pair, sync it. */
    onMessage(role, text) {
        if (role === 'user') {
            this.lastUserText = text;
            return;
        }
        if (role === 'assistant' && text && this.lastUserText) {
            this.sync(this.lastUserText, text);
            this.lastUserText = '';
        }
    }
    sync(userContent, assistantContent) {
        if (this.inflight)
            return;
        this.inflight = true;
        this.provider
            .add([
            { role: 'user', content: userContent },
            { role: 'assistant', content: assistantContent },
        ], { userId: this.userId })
            .catch(() => { })
            .finally(() => {
            this.inflight = false;
        });
    }
}
//# sourceMappingURL=sync.js.map