mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
Add SqlCopilotRepository implementing the Repository Protocol's session lifecycle (create_session/get_session) and compare_and_advance as a real DB-level version-CAS: a single UPDATE ... WHERE version=base_version, with rowcount==0 disambiguated into NotFoundError (missing session) vs ConflictError (stale version). A UNIQUE(session_id, seq) collision on conversation items during compare_and_advance is caught and mapped to ConflictError, making the DB the seq authority. Remaining Repository methods (checkpoints/runs/test-inputs/list_conversation) are stubbed with NotImplementedError, deferred to Task 5. Tested against SQLite in-memory: create/get round-trip, CAS version bump, stale-version conflict leaving the row unchanged, missing-session NotFoundError, and duplicate-seq ConflictError.