databasesql

package module
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package databasesql provides a database/sql driver implementation for AgentPG.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver implements driver.Driver using database/sql.

func New

func New(db *sql.DB, connStr string) *Driver

New creates a new database/sql driver using the provided connection. The connStr is required for creating listener connections.

func (*Driver) BeginTx

func (d *Driver) BeginTx(ctx context.Context) (*sql.Tx, error)

BeginTx starts a new transaction.

func (*Driver) Close

func (d *Driver) Close() error

Close closes the driver and releases resources.

func (*Driver) CommitTx

func (d *Driver) CommitTx(ctx context.Context, tx *sql.Tx) error

CommitTx commits a transaction.

func (*Driver) DB

func (d *Driver) DB() *sql.DB

DB returns the underlying database connection.

func (*Driver) Listener

func (d *Driver) Listener() driver.Listener

Listener returns the listener for LISTEN/NOTIFY. Uses lib/pq for LISTEN/NOTIFY support.

func (*Driver) RollbackTx

func (d *Driver) RollbackTx(ctx context.Context, tx *sql.Tx) error

RollbackTx rolls back a transaction.

func (*Driver) Store

func (d *Driver) Store() driver.Store[*sql.Tx]

Store returns the store interface for database operations.

type Listener

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

Listener implements driver.Listener using lib/pq.

func NewListener

func NewListener(connStr string) *Listener

NewListener creates a new Listener using the provided connection string.

func (*Listener) Close

func (l *Listener) Close() error

Close stops listening and releases resources.

func (*Listener) Listen

func (l *Listener) Listen(ctx context.Context, channels ...string) error

Listen starts listening for notifications on the specified channels.

func (*Listener) Notifications

func (l *Listener) Notifications() <-chan driver.Notification

Notifications returns a channel for receiving notifications.

type Store

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

Store implements driver.Store using database/sql.

func (*Store) ArchiveMessage

func (s *Store) ArchiveMessage(ctx context.Context, compactionEventID, messageID, sessionID uuid.UUID, originalMessage map[string]any) error

func (*Store) CancelRun added in v0.3.1

func (s *Store) CancelRun(ctx context.Context, id uuid.UUID) (bool, string, string, error)

CancelRun atomically cancels a run and all its child runs via stored procedure.

func (*Store) ClaimRuns

func (s *Store) ClaimRuns(ctx context.Context, instanceID string, maxCount int, runMode string) ([]*driver.Run, error)

func (*Store) ClaimToolExecutions

func (s *Store) ClaimToolExecutions(ctx context.Context, instanceID string, maxCount int) ([]*driver.ToolExecution, error)

func (*Store) CompleteToolExecution

func (s *Store) CompleteToolExecution(ctx context.Context, id uuid.UUID, output string, isError bool, errorMsg string) error

func (*Store) CompleteToolsAndContinueRun

func (s *Store) CompleteToolsAndContinueRun(ctx context.Context, sessionID, runID uuid.UUID, contentBlocks []driver.ContentBlock) (*driver.Message, error)

func (*Store) CreateAgent

func (s *Store) CreateAgent(ctx context.Context, agent *driver.AgentDefinition) (*driver.AgentDefinition, error)

func (*Store) CreateCompactionEvent

func (s *Store) CreateCompactionEvent(ctx context.Context, params driver.CreateCompactionEventParams) (*driver.CompactionEvent, error)

func (*Store) CreateContentBlocks

func (s *Store) CreateContentBlocks(ctx context.Context, messageID uuid.UUID, blocks []driver.ContentBlock) error

func (*Store) CreateIteration

func (s *Store) CreateIteration(ctx context.Context, params driver.CreateIterationParams) (*driver.Iteration, error)

func (*Store) CreateMessage

func (s *Store) CreateMessage(ctx context.Context, params driver.CreateMessageParams) (*driver.Message, error)

func (*Store) CreateRun

func (s *Store) CreateRun(ctx context.Context, params driver.CreateRunParams) (*driver.Run, error)

func (*Store) CreateRunTx

func (s *Store) CreateRunTx(ctx context.Context, tx *sql.Tx, params driver.CreateRunParams) (*driver.Run, error)

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, params driver.CreateSessionParams) (*driver.Session, error)

func (*Store) CreateSessionTx

func (s *Store) CreateSessionTx(ctx context.Context, tx *sql.Tx, params driver.CreateSessionParams) (*driver.Session, error)

func (*Store) CreateToolExecution

func (s *Store) CreateToolExecution(ctx context.Context, params driver.CreateToolExecutionParams) (*driver.ToolExecution, error)

func (*Store) CreateToolExecutions

func (s *Store) CreateToolExecutions(ctx context.Context, params []driver.CreateToolExecutionParams) ([]*driver.ToolExecution, error)

func (*Store) CreateToolExecutionsAndUpdateRunState

func (s *Store) CreateToolExecutionsAndUpdateRunState(ctx context.Context, params []driver.CreateToolExecutionParams, runID uuid.UUID, state driver.RunState, runUpdates map[string]any) ([]*driver.ToolExecution, error)

func (*Store) DeleteAgent

func (s *Store) DeleteAgent(ctx context.Context, id uuid.UUID) error

func (*Store) DeleteMessage

func (s *Store) DeleteMessage(ctx context.Context, id uuid.UUID) error

func (*Store) DeleteRunMessages added in v0.3.1

func (s *Store) DeleteRunMessages(ctx context.Context, runID uuid.UUID) (int, error)

DeleteRunMessages deletes all messages and content blocks for a run.

func (*Store) DeleteStaleInstances

func (s *Store) DeleteStaleInstances(ctx context.Context, ttl time.Duration) (int, error)

func (*Store) DeleteTool

func (s *Store) DeleteTool(ctx context.Context, name string) error

func (*Store) DiscardToolExecution

func (s *Store) DiscardToolExecution(ctx context.Context, id uuid.UUID, errorMsg string) error

func (*Store) GetAgent

func (s *Store) GetAgent(ctx context.Context, id uuid.UUID) (*driver.AgentDefinition, error)

func (*Store) GetAgentByName

func (s *Store) GetAgentByName(ctx context.Context, name string, metadata map[string]any) (*driver.AgentDefinition, error)

func (*Store) GetAllInstanceActiveCounts

func (s *Store) GetAllInstanceActiveCounts(ctx context.Context) (map[string][2]int, error)

GetAllInstanceActiveCounts returns the active run and tool counts for all instances. Returns a map of instance ID to [activeRuns, activeTools].

func (*Store) GetCompactionEvents

func (s *Store) GetCompactionEvents(ctx context.Context, sessionID uuid.UUID, limit int) ([]*driver.CompactionEvent, error)

func (*Store) GetCompactionStats

func (s *Store) GetCompactionStats(ctx context.Context) (*driver.CompactionStats, error)

func (*Store) GetContentBlocks

func (s *Store) GetContentBlocks(ctx context.Context, messageID uuid.UUID) ([]driver.ContentBlock, error)

func (*Store) GetInstance

func (s *Store) GetInstance(ctx context.Context, instanceID string) (*driver.Instance, error)

func (*Store) GetInstanceActiveCounts

func (s *Store) GetInstanceActiveCounts(ctx context.Context, instanceID string) (activeRuns, activeTools int, err error)

GetInstanceActiveCounts returns the active run and tool counts for an instance. Counts are calculated on-the-fly by querying runs and tool_executions tables.

func (*Store) GetInstanceTools

func (s *Store) GetInstanceTools(ctx context.Context, instanceID string) ([]string, error)

func (*Store) GetIteration

func (s *Store) GetIteration(ctx context.Context, id uuid.UUID) (*driver.Iteration, error)

func (*Store) GetIterationsByRun

func (s *Store) GetIterationsByRun(ctx context.Context, runID uuid.UUID) ([]*driver.Iteration, error)

func (*Store) GetIterationsForPoll

func (s *Store) GetIterationsForPoll(ctx context.Context, instanceID string, pollInterval time.Duration, maxCount int) ([]*driver.Iteration, error)

func (*Store) GetLeader

func (s *Store) GetLeader(ctx context.Context) (string, error)

func (*Store) GetMessage

func (s *Store) GetMessage(ctx context.Context, id uuid.UUID) (*driver.Message, error)

func (*Store) GetMessages

func (s *Store) GetMessages(ctx context.Context, sessionID uuid.UUID, limit int) ([]*driver.Message, error)

func (*Store) GetMessagesByRun

func (s *Store) GetMessagesByRun(ctx context.Context, runID uuid.UUID) ([]*driver.Message, error)

func (*Store) GetMessagesForRunContext

func (s *Store) GetMessagesForRunContext(ctx context.Context, runID uuid.UUID) ([]*driver.Message, error)

func (*Store) GetMessagesWithRunInfo

func (s *Store) GetMessagesWithRunInfo(ctx context.Context, sessionID uuid.UUID, limit int) ([]*driver.MessageWithRunInfo, error)

func (*Store) GetMetadataValues

func (s *Store) GetMetadataValues(ctx context.Context, key string) ([]driver.MetadataValue, error)

func (*Store) GetPendingToolExecutionsForRun

func (s *Store) GetPendingToolExecutionsForRun(ctx context.Context, runID uuid.UUID) ([]*driver.ToolExecution, error)

func (*Store) GetRun

func (s *Store) GetRun(ctx context.Context, id uuid.UUID) (*driver.Run, error)

func (*Store) GetRunsBySession

func (s *Store) GetRunsBySession(ctx context.Context, sessionID uuid.UUID, limit int) ([]*driver.Run, error)

func (*Store) GetSession

func (s *Store) GetSession(ctx context.Context, id uuid.UUID) (*driver.Session, error)

func (*Store) GetStaleInstances

func (s *Store) GetStaleInstances(ctx context.Context, ttl time.Duration) ([]string, error)

func (*Store) GetStuckPendingToolsRuns

func (s *Store) GetStuckPendingToolsRuns(ctx context.Context, limit int) ([]*driver.Run, error)

func (*Store) GetStuckRuns

func (s *Store) GetStuckRuns(ctx context.Context, timeout time.Duration, maxRescueAttempts, limit int) ([]*driver.Run, error)

func (*Store) GetTool

func (s *Store) GetTool(ctx context.Context, name string) (*driver.ToolDefinition, error)

func (*Store) GetToolExecution

func (s *Store) GetToolExecution(ctx context.Context, id uuid.UUID) (*driver.ToolExecution, error)

func (*Store) GetToolExecutionsByIteration

func (s *Store) GetToolExecutionsByIteration(ctx context.Context, iterationID uuid.UUID) ([]*driver.ToolExecution, error)

func (*Store) GetToolExecutionsByRun

func (s *Store) GetToolExecutionsByRun(ctx context.Context, runID uuid.UUID) ([]*driver.ToolExecution, error)

func (*Store) IsLeader

func (s *Store) IsLeader(ctx context.Context, instanceID string) (bool, error)

func (*Store) ListAgents

func (s *Store) ListAgents(ctx context.Context, params driver.ListAgentsParams) ([]*driver.AgentDefinition, int, error)

func (*Store) ListInstances

func (s *Store) ListInstances(ctx context.Context) ([]*driver.Instance, error)

func (*Store) ListRuns

func (s *Store) ListRuns(ctx context.Context, params driver.ListRunsParams) ([]*driver.Run, int, error)

func (*Store) ListSessions

func (s *Store) ListSessions(ctx context.Context, params driver.ListSessionsParams) ([]*driver.Session, int, error)

func (*Store) ListToolExecutions

func (s *Store) ListToolExecutions(ctx context.Context, params driver.ListToolExecutionsParams) ([]*driver.ToolExecution, int, error)

func (*Store) ListTools

func (s *Store) ListTools(ctx context.Context) ([]*driver.ToolDefinition, error)

func (*Store) RefreshLeader

func (s *Store) RefreshLeader(ctx context.Context, instanceID string, ttl time.Duration) error

func (*Store) RegisterInstance

func (s *Store) RegisterInstance(ctx context.Context, params driver.RegisterInstanceParams) error

func (*Store) RegisterInstanceTool

func (s *Store) RegisterInstanceTool(ctx context.Context, instanceID, toolName string) error

func (*Store) ReleaseLeader

func (s *Store) ReleaseLeader(ctx context.Context, instanceID string) error

func (*Store) RescueRun

func (s *Store) RescueRun(ctx context.Context, id uuid.UUID) error

func (*Store) RetryToolExecution

func (s *Store) RetryToolExecution(ctx context.Context, id uuid.UUID, scheduledAt time.Time, lastError string) error

func (*Store) SnoozeToolExecution

func (s *Store) SnoozeToolExecution(ctx context.Context, id uuid.UUID, scheduledAt time.Time) error

func (*Store) TryAcquireLeader

func (s *Store) TryAcquireLeader(ctx context.Context, instanceID string, ttl time.Duration) (bool, error)

func (*Store) UnregisterInstance

func (s *Store) UnregisterInstance(ctx context.Context, instanceID string) error

func (*Store) UnregisterInstanceTool

func (s *Store) UnregisterInstanceTool(ctx context.Context, instanceID, toolName string) error

func (*Store) UpdateAgent

func (s *Store) UpdateAgent(ctx context.Context, agent *driver.AgentDefinition) error

func (*Store) UpdateHeartbeat

func (s *Store) UpdateHeartbeat(ctx context.Context, instanceID string) error

func (*Store) UpdateIteration

func (s *Store) UpdateIteration(ctx context.Context, id uuid.UUID, updates map[string]any) error

func (*Store) UpdateMessage

func (s *Store) UpdateMessage(ctx context.Context, id uuid.UUID, updates map[string]any) error

func (*Store) UpdateRun

func (s *Store) UpdateRun(ctx context.Context, id uuid.UUID, updates map[string]any) error

func (*Store) UpdateRunState

func (s *Store) UpdateRunState(ctx context.Context, id uuid.UUID, state driver.RunState, updates map[string]any) error

func (*Store) UpdateSession

func (s *Store) UpdateSession(ctx context.Context, id uuid.UUID, updates map[string]any) error

func (*Store) UpdateToolExecution

func (s *Store) UpdateToolExecution(ctx context.Context, id uuid.UUID, updates map[string]any) error

func (*Store) UpsertTool

func (s *Store) UpsertTool(ctx context.Context, tool *driver.ToolDefinition) error

Jump to

Keyboard shortcuts

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