storage

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	Alias  string `json:"alias"`
	NodeID string `json:"node_id"`
}

type DAG

type DAG struct {
	// contains filtered or unexported fields
}

DAG is a conversation stored as a directed acyclic graph.

func NewDAG

func NewDAG(dbPath string, sessionID string) (*DAG, error)

NewDAG opens or creates a conversation DAG for the given session.

func NewDAGFromStore

func NewDAGFromStore(store Store, sessionID string) *DAG

NewDAGFromStore creates a DAG using an existing store.

func (*DAG) Append

func (d *DAG) Append(parentID string, role string, content string) (*DAGNode, error)

Append adds a new node as a child of the given parent and advances the head.

func (*DAG) Branches

func (d *DAG) Branches(nodeID string) ([]*DAGNode, error)

Branches returns all child nodes. If nodeID is empty, returns session roots.

func (*DAG) Close

func (d *DAG) Close() error

Close closes the underlying store.

func (*DAG) Fork

func (d *DAG) Fork(nodeID string) (*DAGNode, error)

Fork creates a new branch from the given node.

func (*DAG) Head

func (d *DAG) Head() (*DAGNode, error)

Head returns the most recent node in the current branch.

func (*DAG) History

func (d *DAG) History(nodeID string) ([]*DAGNode, error)

History returns the linear path from root to the given node.

func (*DAG) Prune

func (d *DAG) Prune(nodeID string) error

Prune removes a node and all its descendants.

func (*DAG) SetHead

func (d *DAG) SetHead(nodeID string) error

SetHead moves the head pointer to a specific node.

type DAGNode

type DAGNode struct {
	ID        string
	ParentID  string
	Role      string
	Content   string
	Model     string
	CreatedAt time.Time
	Metadata  map[string]string
}

DAGNode is a single message in the conversation DAG.

type Node

type Node struct {
	ID                  string          `json:"id"`
	ParentID            string          `json:"parent_id,omitempty"`
	RootID              string          `json:"root_id,omitempty"`
	Sequence            int             `json:"sequence"`
	NodeType            NodeType        `json:"node_type"`
	Content             string          `json:"content"`
	Provider            string          `json:"provider,omitempty"`
	Model               string          `json:"model,omitempty"`
	TokensIn            int             `json:"tokens_in,omitempty"`
	TokensOut           int             `json:"tokens_out,omitempty"`
	TokensCacheRead     int             `json:"tokens_cache_read,omitempty"`
	TokensCacheCreation int             `json:"tokens_cache_creation,omitempty"`
	TokensReasoning     int             `json:"tokens_reasoning,omitempty"`
	LatencyMs           int             `json:"latency_ms,omitempty"`
	StopReason          string          `json:"stop_reason,omitempty"`
	OutputGroupID       string          `json:"output_group_id,omitempty"`
	Status              string          `json:"status,omitempty"`
	Title               string          `json:"title,omitempty"`
	SystemPrompt        string          `json:"system_prompt,omitempty"`
	CreatedAt           time.Time       `json:"created_at"`
	Metadata            json.RawMessage `json:"metadata,omitempty"`
}

type NodeType

type NodeType string
const (
	NodeTypeUser       NodeType = "user"
	NodeTypeAssistant  NodeType = "assistant"
	NodeTypeSystem     NodeType = "system"
	NodeTypeToolCall   NodeType = "tool_call"
	NodeTypeToolResult NodeType = "tool_result"
)

type SQLiteStore

type SQLiteStore struct {
	// contains filtered or unexported fields
}

func Open

func Open(path string) (*SQLiteStore, error)

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

func (*SQLiteStore) CreateAlias

func (s *SQLiteStore) CreateAlias(ctx context.Context, alias, nodeID string) error

func (*SQLiteStore) CreateNode

func (s *SQLiteStore) CreateNode(ctx context.Context, node *Node) error

func (*SQLiteStore) DeleteAlias

func (s *SQLiteStore) DeleteAlias(ctx context.Context, alias string) error

func (*SQLiteStore) DeleteNode

func (s *SQLiteStore) DeleteNode(ctx context.Context, id string) error

func (*SQLiteStore) GetAncestors

func (s *SQLiteStore) GetAncestors(ctx context.Context, id string) ([]*Node, error)

func (*SQLiteStore) GetNode

func (s *SQLiteStore) GetNode(ctx context.Context, id string) (*Node, error)

func (*SQLiteStore) GetNodeByAlias

func (s *SQLiteStore) GetNodeByAlias(ctx context.Context, alias string) (*Node, error)

func (*SQLiteStore) GetNodeByPrefix

func (s *SQLiteStore) GetNodeByPrefix(ctx context.Context, prefix string) (*Node, error)

func (*SQLiteStore) GetNodeChildren

func (s *SQLiteStore) GetNodeChildren(ctx context.Context, id string) ([]*Node, error)

func (*SQLiteStore) GetOrphanedToolUses

func (s *SQLiteStore) GetOrphanedToolUses(ctx context.Context, rootID string) ([]string, error)

func (*SQLiteStore) GetSubtree

func (s *SQLiteStore) GetSubtree(ctx context.Context, id string) ([]*Node, error)

func (*SQLiteStore) IndexToolIDs

func (s *SQLiteStore) IndexToolIDs(ctx context.Context, nodeID string, toolIDs []string, role string) error

func (*SQLiteStore) ListAliases

func (s *SQLiteStore) ListAliases(ctx context.Context, nodeID string) ([]Alias, error)

func (*SQLiteStore) ListRootNodes

func (s *SQLiteStore) ListRootNodes(ctx context.Context) ([]*Node, error)

func (*SQLiteStore) UpdateNode

func (s *SQLiteStore) UpdateNode(ctx context.Context, node *Node) error

type Store

type Store interface {
	CreateNode(ctx context.Context, node *Node) error
	GetNode(ctx context.Context, id string) (*Node, error)
	GetNodeByPrefix(ctx context.Context, prefix string) (*Node, error)
	GetNodeChildren(ctx context.Context, id string) ([]*Node, error)
	GetSubtree(ctx context.Context, id string) ([]*Node, error)
	GetAncestors(ctx context.Context, id string) ([]*Node, error)
	ListRootNodes(ctx context.Context) ([]*Node, error)
	UpdateNode(ctx context.Context, node *Node) error
	DeleteNode(ctx context.Context, id string) error
	CreateAlias(ctx context.Context, alias, nodeID string) error
	DeleteAlias(ctx context.Context, alias string) error
	GetNodeByAlias(ctx context.Context, alias string) (*Node, error)
	ListAliases(ctx context.Context, nodeID string) ([]Alias, error)
	IndexToolIDs(ctx context.Context, nodeID string, toolIDs []string, role string) error
	GetOrphanedToolUses(ctx context.Context, rootID string) ([]string, error)
	Close() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL