database

package
v0.0.0-...-791b03a Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseMessages

func ParseMessages(messages []Event) ([]*protocol.Message, error)

func ParseTasks

func ParseTasks(tasks []Task) ([]*protocol.Task, error)

Types

type Agent

type Agent struct {
	ID        string         `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`

	Type string `gorm:"not null" json:"type"`
	// Config is optional and may be nil for some agent types.
	// For agent types that require configuration, this field should be populated.
	// For agent types that do not require configuration, this field should be nil.
	Config *adk.AgentConfig `gorm:"type:json" json:"config"`
}

Agent represents an agent configuration

func (Agent) TableName

func (Agent) TableName() string

TableName methods to match Python table names

type AgentMemorySearchResult

type AgentMemorySearchResult struct {
	Memory
	Score float64 `gorm:"column:score" json:"score"`
}

AgentMemorySearchResult is the result of a vector similarity search over Memory (e.g. SELECT *, 1 - (embedding <=> ?) as score).

type Client

type Client interface {
	// Store methods
	StoreFeedback(feedback *Feedback) error
	StoreSession(session *Session) error
	StoreAgent(agent *Agent) error
	StoreTask(task *protocol.Task) error
	StorePushNotification(config *protocol.TaskPushNotificationConfig) error
	StoreToolServer(toolServer *ToolServer) (*ToolServer, error)
	StoreEvents(messages ...*Event) error

	// Delete methods
	DeleteSession(sessionID string, userID string) error
	DeleteAgent(agentID string) error
	DeleteToolServer(serverName string, groupKind string) error
	DeleteTask(taskID string) error
	DeletePushNotification(taskID string) error
	DeleteToolsForServer(serverName string, groupKind string) error

	// Get methods
	GetSession(sessionID string, userID string) (*Session, error)
	GetAgent(name string) (*Agent, error)
	GetTask(id string) (*protocol.Task, error)
	GetTool(name string) (*Tool, error)
	GetToolServer(name string) (*ToolServer, error)
	GetPushNotification(taskID string, configID string) (*protocol.TaskPushNotificationConfig, error)

	// List methods
	ListTools() ([]Tool, error)
	ListFeedback(userID string) ([]Feedback, error)
	ListTasksForSession(sessionID string) ([]*protocol.Task, error)
	ListSessions(userID string) ([]Session, error)
	ListSessionsForAgent(agentID string, userID string) ([]Session, error)
	ListAgents() ([]Agent, error)
	ListToolServers() ([]ToolServer, error)
	ListToolsForServer(serverName string, groupKind string) ([]Tool, error)
	ListEventsForSession(sessionID, userID string, options QueryOptions) ([]*Event, error)
	ListPushNotifications(taskID string) ([]*protocol.TaskPushNotificationConfig, error)

	// Helper methods
	RefreshToolsForServer(serverName string, groupKind string, tools ...*v1alpha2.MCPTool) error

	// LangGraph Checkpoint methods
	StoreCheckpoint(checkpoint *LangGraphCheckpoint) error
	StoreCheckpointWrites(writes []*LangGraphCheckpointWrite) error
	ListCheckpoints(userID, threadID, checkpointNS string, checkpointID *string, limit int) ([]*LangGraphCheckpointTuple, error)
	DeleteCheckpoint(userID, threadID string) error

	// CrewAI methods
	StoreCrewAIMemory(memory *CrewAIAgentMemory) error
	SearchCrewAIMemoryByTask(userID, threadID, taskDescription string, limit int) ([]*CrewAIAgentMemory, error)
	ResetCrewAIMemory(userID, threadID string) error
	StoreCrewAIFlowState(state *CrewAIFlowState) error
	GetCrewAIFlowState(userID, threadID string) (*CrewAIFlowState, error)

	// Agent memory (vector search) methods
	StoreAgentMemory(memory *Memory) error
	StoreAgentMemories(memories []*Memory) error
	SearchAgentMemory(agentName, userID string, embedding pgvector.Vector, limit int) ([]AgentMemorySearchResult, error)
	ListAgentMemories(agentName, userID string) ([]Memory, error)
	DeleteAgentMemory(agentName, userID string) error
	PruneExpiredMemories() error
}

type CrewAIAgentMemory

type CrewAIAgentMemory struct {
	UserID    string         `gorm:"primaryKey;not null" json:"user_id"`
	ThreadID  string         `gorm:"primaryKey;not null" json:"thread_id"`
	CreatedAt time.Time      `gorm:"autoCreateTime;index:idx_crewai_memory_list" json:"created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	// MemoryData contains JSON serialized memory data including task_description, score, metadata, datetime
	MemoryData string `gorm:"type:text;not null" json:"memory_data"`
}

CrewAIAgentMemory represents long-term memory for CrewAI agents

func (CrewAIAgentMemory) TableName

func (CrewAIAgentMemory) TableName() string

type CrewAIFlowState

type CrewAIFlowState struct {
	UserID     string         `gorm:"primaryKey;not null" json:"user_id"`
	ThreadID   string         `gorm:"primaryKey;not null" json:"thread_id"`
	MethodName string         `gorm:"primaryKey;not null" json:"method_name"`
	CreatedAt  time.Time      `gorm:"autoCreateTime;index:idx_crewai_flow_state_list" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	// StateData contains JSON serialized flow state data
	StateData string `gorm:"type:text;not null" json:"state_data"`
}

CrewAIFlowState represents flow state for CrewAI flows

func (CrewAIFlowState) TableName

func (CrewAIFlowState) TableName() string

type Event

type Event struct {
	ID        string         `gorm:"primaryKey;not null" json:"id"`
	SessionID string         `gorm:"index" json:"session_id"`
	UserID    string         `gorm:"primaryKey;not null" json:"user_id"`
	CreatedAt time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`

	Data string `gorm:"type:text;not null" json:"data"` // JSON serialized protocol.Message
}

func (*Event) Parse

func (m *Event) Parse() (protocol.Message, error)

func (Event) TableName

func (Event) TableName() string

type Feedback

type Feedback struct {
	gorm.Model
	UserID       string             `gorm:"not null;index" json:"user_id"`
	MessageID    uint               `gorm:"index;constraint:OnDelete:CASCADE" json:"message_id"`
	IsPositive   bool               `gorm:"default:false" json:"is_positive"`
	FeedbackText string             `gorm:"not null" json:"feedback_text"`
	IssueType    *FeedbackIssueType `json:"issue_type,omitempty"`
}

Feedback represents user feedback on agent responses

func (Feedback) TableName

func (Feedback) TableName() string

type FeedbackIssueType

type FeedbackIssueType string

FeedbackIssueType represents the category of feedback issue

const (
	FeedbackIssueTypeInstructions FeedbackIssueType = "instructions" // Did not follow instructions
	FeedbackIssueTypeFactual      FeedbackIssueType = "factual"      // Not factually correct
	FeedbackIssueTypeIncomplete   FeedbackIssueType = "incomplete"   // Incomplete response
	FeedbackIssueTypeTool         FeedbackIssueType = "tool"         // Should have run the tool
)

type LangGraphCheckpoint

type LangGraphCheckpoint struct {
	UserID             string         `gorm:"primaryKey;not null" json:"user_id"`
	ThreadID           string         `gorm:"primaryKey;not null" json:"thread_id"`
	CheckpointNS       string         `gorm:"primaryKey;not null;default:''" json:"checkpoint_ns"`
	CheckpointID       string         `gorm:"primaryKey;not null" json:"checkpoint_id"`
	ParentCheckpointID *string        `gorm:"index" json:"parent_checkpoint_id,omitempty"`
	CreatedAt          time.Time      `gorm:"autoCreateTime;index:idx_lgcp_list" json:"created_at"`
	UpdatedAt          time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt          gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Metadata           string         `gorm:"type:text;not null" json:"metadata"`   // JSON serialized metadata
	Checkpoint         string         `gorm:"type:text;not null" json:"checkpoint"` // JSON serialized checkpoint
	CheckpointType     string         `gorm:"not null" json:"checkpoint_type"`
	Version            int            `gorm:"default:1" json:"version"`
}

LangGraphCheckpoint represents a LangGraph checkpoint

func (LangGraphCheckpoint) TableName

func (LangGraphCheckpoint) TableName() string

type LangGraphCheckpointTuple

type LangGraphCheckpointTuple struct {
	Checkpoint *LangGraphCheckpoint
	Writes     []*LangGraphCheckpointWrite
}

type LangGraphCheckpointWrite

type LangGraphCheckpointWrite struct {
	UserID       string         `gorm:"primaryKey;not null" json:"user_id"`
	ThreadID     string         `gorm:"primaryKey;not null" json:"thread_id"`
	CheckpointNS string         `gorm:"primaryKey;not null;default:''" json:"checkpoint_ns"`
	CheckpointID string         `gorm:"primaryKey;not null" json:"checkpoint_id"`
	WriteIdx     int            `gorm:"primaryKey;not null" json:"write_idx"`
	Value        string         `gorm:"type:text;not null" json:"value"` // JSON serialized value
	ValueType    string         `gorm:"not null" json:"value_type"`
	Channel      string         `gorm:"not null" json:"channel"`
	TaskID       string         `gorm:"not null" json:"task_id"`
	CreatedAt    time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt    time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt    gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

LangGraphCheckpointWrite represents a write operation for a checkpoint

func (LangGraphCheckpointWrite) TableName

func (LangGraphCheckpointWrite) TableName() string

type Memory

type Memory struct {
	// ID is a UUID generated by the application layer before insert, ensuring
	// compatibility with both Postgres and SQLite/libSQL backends.
	ID          string          `gorm:"primaryKey" json:"id"`
	AgentName   string          `gorm:"index:idx_memory_agent_user,composite:agent_name" json:"agent_name"`
	UserID      string          `gorm:"index:idx_memory_agent_user,composite:user_id" json:"user_id"`
	Content     string          `gorm:"type:text" json:"content"`
	Embedding   pgvector.Vector `gorm:"type:vector(768)" json:"embedding"`
	Metadata    string          `gorm:"type:text" json:"metadata"`
	CreatedAt   time.Time       `gorm:"autoCreateTime" json:"created_at"`
	ExpiresAt   *time.Time      `gorm:"index" json:"expires_at,omitempty"`
	AccessCount int             `gorm:"default:0" json:"access_count"`
}

Memory represents a memory/session embedding with TTL support

func (*Memory) BeforeCreate

func (m *Memory) BeforeCreate(tx *gorm.DB) error

BeforeCreate generates a UUID for the Memory ID if one has not been set, making ID generation database-agnostic (works for both Postgres and SQLite).

func (Memory) TableName

func (Memory) TableName() string

type PushNotification

type PushNotification struct {
	ID        string         `gorm:"primaryKey;not null" json:"id"`
	TaskID    string         `gorm:"not null;index" json:"task_id"`
	CreatedAt time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Data      string         `gorm:"type:text;not null" json:"data"` // JSON serialized push notification config
}

func (PushNotification) TableName

func (PushNotification) TableName() string

type QueryOptions

type QueryOptions struct {
	Limit    int
	After    time.Time
	OrderAsc bool // When true, order results by created_at ASC (chronological). Default is DESC (newest first).
}

type Session

type Session struct {
	ID        string         `gorm:"primaryKey;not null" json:"id"`
	Name      *string        `gorm:"index" json:"name,omitempty"`
	UserID    string         `gorm:"primaryKey" json:"user_id"`
	CreatedAt time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`

	AgentID *string `gorm:"index" json:"agent_id"`
}

func (Session) TableName

func (Session) TableName() string

type Task

type Task struct {
	ID        string         `gorm:"primaryKey;not null" json:"id"`
	CreatedAt time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Data      string         `gorm:"type:text;not null" json:"data"` // JSON serialized task data
	SessionID string         `gorm:"index" json:"session_id"`
}

func (*Task) Parse

func (t *Task) Parse() (protocol.Task, error)

func (Task) TableName

func (Task) TableName() string

type Tool

type Tool struct {
	ID          string         `gorm:"primaryKey;not null" json:"id"`
	ServerName  string         `gorm:"primaryKey;not null" json:"server_name"`
	GroupKind   string         `gorm:"primaryKey;not null" json:"group_kind"`
	CreatedAt   time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Description string         `json:"description"`
}

Tool represents a single tool that can be used by an agent

func (Tool) TableName

func (Tool) TableName() string

type ToolServer

type ToolServer struct {
	CreatedAt     time.Time      `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt     time.Time      `gorm:"autoUpdateTime" json:"updated_at"`
	DeletedAt     gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Name          string         `gorm:"primaryKey;not null" json:"name"`
	GroupKind     string         `gorm:"primaryKey;not null" json:"group_kind"`
	Description   string         `json:"description"`
	LastConnected *time.Time     `json:"last_connected,omitempty"`
}

ToolServer represents a tool server that provides tools

func (ToolServer) TableName

func (ToolServer) TableName() string

Jump to

Keyboard shortcuts

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