/** * Write-Behind Sync Queue * * 로컬 DB에 저장된 메모리를 원격 서버로 일괄 push합니다. * 로컬 DB = 캐시, 원격 서버 = Single Source of Truth. */ import type { MemoryDatabase } from '../db/database.js'; import type { A2AClient } from './client.js'; import type { MemoryCategory, MemoryTier } from '../types/index.js'; export interface SyncedItem { localId: string; remoteId: string; } export interface QueueFlushResult { pushed: number; failed: number; errors: string[]; duration: number; /** 동기화 성공한 항목의 local→remote ID 매핑 */ syncedItems: SyncedItem[]; } export interface FlushOptions { timeoutMs?: number; maxRetries?: number; } /** * #68 (ADR-050): tombstone flush 예산. * * backend에 bulk delete가 없어(`DELETE /{memory_id}` 단건뿐) 건당 1 HTTP다. * 처리량은 왕복 지연이 아니라 **RPM 한도**(prod X-RateLimit-Limit: 100)에 묶이므로, * concurrency를 크게 올려도 429 벽에 더 빨리 닿을 뿐 총량은 같다. */ export interface TombstoneFlushOptions { /** 0 = 무제한(레거시 동작) */ timeoutMs?: number; /** 이번 실행에서 처리할 최대 건수. 남은 건 durable하므로 다음 세션이 이어받는다 */ limit?: number; /** 동시 DELETE 수 — 왕복 지연만 덮는 수준으로 (RPM이 병목이라 크게 올릴 이유가 없다) */ concurrency?: number; } export interface TombstoneFlushResult { deleted: number; errors: string[]; /** 이번에 처리하지 못하고 남은 네트워크 대상 수 (다음 세션 이월) */ remaining: number; /** 예산 소진 또는 rate limit 도달로 중단했는가 */ stopped: boolean; } /** * 로컬 category를 서버 호환 category로 변환 */ export declare function mapCategory(category: string): MemoryCategory; /** * 로컬 tier를 서버 호환 tier로 변환 */ export declare function mapTier(tier: string): MemoryTier; export declare class SyncQueue { private db; private client; constructor(db: MemoryDatabase, client: A2AClient); /** * 메모리를 sync 대기 상태로 설정 (~1ms) */ enqueue(memoryId: string): void; /** * pending 메모리를 배치로 일괄 push (100개씩) * 중복 제거: pending 내부 중복만 제거 (서버 측에서 synced 대비 중복은 처리) * * Parent-Child FK 안전: * 1단계 — Parent (parentId 없는 항목) push → remote_id 획득 * 2단계 — Children의 parentId를 remote parent_id로 변환 후 push */ flush(options?: FlushOptions): Promise; /** * 배치 단위 push 공통 로직 * parentRemoteMap: push 성공 시 local_id→remote_id 매핑 업데이트 (Phase 1→Phase 2 전달용) */ private pushBatches; /** * 미동기화 tombstone을 원격 서버에서 삭제 */ flushTombstones(options?: TombstoneFlushOptions): Promise; /** * 대기 중인 메모리 수 */ getPendingCount(): number; } //# sourceMappingURL=queue.d.ts.map