@@ -51,6 +51,17 @@ type Client interface {
5151
5252 // Helper methods
5353 RefreshToolsForServer (serverName string , groupKind string , tools ... * v1alpha2.MCPTool ) error
54+
55+ // LangGraph Checkpoint methods
56+ StoreCheckpoint (checkpoint * LangGraphCheckpoint ) error
57+ StoreCheckpointWrites (writes []* LangGraphCheckpointWrite ) error
58+ ListCheckpoints (userID , threadID , checkpointNS string , checkpointID * string , limit int ) ([]* LangGraphCheckpointTuple , error )
59+ DeleteCheckpoint (userID , threadID string ) error
60+ }
61+
62+ type LangGraphCheckpointTuple struct {
63+ Checkpoint * LangGraphCheckpoint
64+ Writes []* LangGraphCheckpointWrite
5465}
5566
5667type clientImpl struct {
@@ -481,3 +492,89 @@ func (c *clientImpl) ListPushNotifications(taskID string) ([]*protocol.TaskPushN
481492func (c * clientImpl ) DeletePushNotification (taskID string ) error {
482493 return delete [PushNotification ](c .db , Clause {Key : "task_id" , Value : taskID })
483494}
495+
496+ // StoreCheckpoint stores a LangGraph checkpoint and its writes atomically
497+ func (c * clientImpl ) StoreCheckpoint (checkpoint * LangGraphCheckpoint ) error {
498+ err := save (c .db , checkpoint )
499+ if err != nil {
500+ return fmt .Errorf ("failed to store checkpoint: %w" , err )
501+ }
502+
503+ return nil
504+ }
505+
506+ func (c * clientImpl ) StoreCheckpointWrites (writes []* LangGraphCheckpointWrite ) error {
507+ return c .db .Transaction (func (tx * gorm.DB ) error {
508+ for _ , write := range writes {
509+ if err := save (tx , write ); err != nil {
510+ return fmt .Errorf ("failed to store checkpoint write: %w" , err )
511+ }
512+ }
513+ return nil
514+ })
515+ }
516+
517+ // ListCheckpoints lists checkpoints for a thread, optionally filtered by beforeCheckpointID
518+ func (c * clientImpl ) ListCheckpoints (userID , threadID , checkpointNS string , checkpointID * string , limit int ) ([]* LangGraphCheckpointTuple , error ) {
519+
520+ var checkpointTuples []* LangGraphCheckpointTuple
521+ if err := c .db .Transaction (func (tx * gorm.DB ) error {
522+ query := c .db .Where (
523+ "user_id = ? AND thread_id = ? AND checkpoint_ns = ?" ,
524+ userID , threadID , checkpointNS ,
525+ )
526+
527+ if checkpointID != nil {
528+ query = query .Where ("checkpoint_id = ?" , * checkpointID )
529+ } else {
530+ query = query .Order ("checkpoint_id DESC" )
531+ }
532+
533+ // Apply limit
534+ if limit > 0 {
535+ query = query .Limit (limit )
536+ }
537+
538+ var checkpoints []LangGraphCheckpoint
539+ err := query .Find (& checkpoints ).Error
540+ if err != nil {
541+ return fmt .Errorf ("failed to list checkpoints: %w" , err )
542+ }
543+
544+ for _ , checkpoint := range checkpoints {
545+ var writes []* LangGraphCheckpointWrite
546+ if err := tx .Where (
547+ "user_id = ? AND thread_id = ? AND checkpoint_ns = ? AND checkpoint_id = ?" ,
548+ userID , threadID , checkpointNS , checkpoint .CheckpointID ,
549+ ).Order ("task_id, write_idx" ).Find (& writes ).Error ; err != nil {
550+ return fmt .Errorf ("failed to get checkpoint writes: %w" , err )
551+ }
552+ checkpointTuples = append (checkpointTuples , & LangGraphCheckpointTuple {
553+ Checkpoint : & checkpoint ,
554+ Writes : writes ,
555+ })
556+ }
557+ return nil
558+ }); err != nil {
559+ return nil , fmt .Errorf ("failed to list checkpoints: %w" , err )
560+ }
561+ return checkpointTuples , nil
562+ }
563+
564+ // DeleteCheckpoint deletes a checkpoint and its writes atomically
565+ func (c * clientImpl ) DeleteCheckpoint (userID , threadID string ) error {
566+ clauses := []Clause {
567+ {Key : "user_id" , Value : userID },
568+ {Key : "thread_id" , Value : threadID },
569+ }
570+ return c .db .Transaction (func (tx * gorm.DB ) error {
571+ if err := delete [LangGraphCheckpoint ](tx , clauses ... ); err != nil {
572+ return fmt .Errorf ("failed to delete checkpoint: %w" , err )
573+ }
574+ if err := delete [LangGraphCheckpointWrite ](tx , clauses ... ); err != nil {
575+ return fmt .Errorf ("failed to delete checkpoint writes: %w" , err )
576+ }
577+ return nil
578+ })
579+
580+ }
0 commit comments