store

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 10 Imported by: 0 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

View Source
const BeeAgentID = "bee"

BeeAgentID is the agent_id value used for bee brain session tracking.

Variables

This section is empty.

Functions

func InitDB

func InitDB(dbPath string) (*sql.DB, error)

Types

type BatchMsg

type BatchMsg struct {
	ID            string
	SessionKey    string
	Platform      string
	Content       string
	Raw           string
	PlatformMsgID string
	MessageTime   int64
	Status        string // "received" or "merged"
	MergedInto    string // non-empty only when Status == "merged"
}

BatchMsg is a single row for a bulk insert via CreateBatch.

type ClaimedMessage

type ClaimedMessage struct {
	ID         string
	SessionKey string
	Platform   string
	Content    string
}

CreateBatch inserts multiple message rows in a single transaction using ClaimedMessage is a bee_platform_messages row claimed by the Feeder.

type ExecutionStore

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

func NewExecutionStore

func NewExecutionStore(db *sql.DB) *ExecutionStore

func (*ExecutionStore) Create

func (s *ExecutionStore) Create(workerID, triggerInput, sessionID string) (model.WorkerExecution, error)

func (*ExecutionStore) CreateBeeExecution

func (s *ExecutionStore) CreateBeeExecution(sessionID, triggerInput string) (model.WorkerExecution, error)

func (*ExecutionStore) GetByID

func (s *ExecutionStore) GetByID(id string) (model.WorkerExecution, error)

func (*ExecutionStore) GetBySessionID

func (s *ExecutionStore) GetBySessionID(sessionID string) (model.WorkerExecution, error)

func (*ExecutionStore) GetLogsByID

func (s *ExecutionStore) GetLogsByID(id string) (*model.WorkerExecution, error)

GetLogsByID returns an execution's metadata and full logs. Returns (nil, nil) if execution not found.

func (*ExecutionStore) List

func (s *ExecutionStore) List() ([]model.WorkerExecution, error)

func (*ExecutionStore) ListBeeExecutions

func (s *ExecutionStore) ListBeeExecutions(limit int) ([]model.WorkerExecution, error)

ListBeeExecutions returns the bee's own execution history (worker_id IS NULL).

func (*ExecutionStore) ListBySessionID

func (s *ExecutionStore) ListBySessionID(sessionID string) ([]model.WorkerExecution, error)

func (*ExecutionStore) ListByWorkerID

func (s *ExecutionStore) ListByWorkerID(workerID string) ([]model.WorkerExecution, error)

func (*ExecutionStore) ListRecent

func (s *ExecutionStore) ListRecent(limit int) ([]model.WorkerExecution, error)

ListRecent returns the most recent executions (all types).

func (*ExecutionStore) UpdateLogs

func (s *ExecutionStore) UpdateLogs(id string, logs string) error

func (*ExecutionStore) UpdatePID

func (s *ExecutionStore) UpdatePID(id string, pid int) error

func (*ExecutionStore) UpdateResult

func (s *ExecutionStore) UpdateResult(id string, result string, status model.ExecutionStatus) error

func (*ExecutionStore) UpdateStatus

func (s *ExecutionStore) UpdateStatus(id string, status model.ExecutionStatus) error

type InboundMessage

type InboundMessage struct {
	ID         string
	Content    string
	ReceivedAt int64
}

InboundMessage is a non-merged bee_platform_messages row for display in chat history.

type LocalReply

type LocalReply struct {
	ID         string `json:"id"`
	SessionKey string `json:"session_key"`
	Content    string `json:"content"`
	CreatedAt  int64  `json:"created_at"`
}

LocalReply is a row from the local_replies table.

type LocalReplyStore

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

LocalReplyStore manages the local_replies table.

func NewLocalReplyStore

func NewLocalReplyStore(db *sql.DB) *LocalReplyStore

NewLocalReplyStore constructs a LocalReplyStore.

func (*LocalReplyStore) Create

func (s *LocalReplyStore) Create(ctx context.Context, id, sessionKey, content string) error

Create inserts a new reply row.

func (*LocalReplyStore) DeleteBySession

func (s *LocalReplyStore) DeleteBySession(ctx context.Context, sessionKey string) error

DeleteBySession removes all replies for the given session key.

func (*LocalReplyStore) ListBySession

func (s *LocalReplyStore) ListBySession(ctx context.Context, sessionKey string) ([]LocalReply, error)

ListBySession returns all replies for a session key ordered by created_at.

type LocalSession

type LocalSession struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	CreatedAt int64  `json:"created_at"`
	UpdatedAt int64  `json:"updated_at"`
}

LocalSession is a row from the local_sessions table.

type LocalSessionStore

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

LocalSessionStore manages the local_sessions table.

func NewLocalSessionStore

func NewLocalSessionStore(db *sql.DB) *LocalSessionStore

NewLocalSessionStore constructs a LocalSessionStore.

func (*LocalSessionStore) Create

func (s *LocalSessionStore) Create(ctx context.Context, id, name string) error

Create inserts a new local session.

func (*LocalSessionStore) Delete

func (s *LocalSessionStore) Delete(ctx context.Context, id string) error

Delete removes a session by ID.

func (*LocalSessionStore) List

List returns all sessions ordered by updated_at descending.

func (*LocalSessionStore) TouchUpdatedAt

func (s *LocalSessionStore) TouchUpdatedAt(ctx context.Context, id string) error

TouchUpdatedAt bumps updated_at to now for the given session. Called by the HTTP handler on every message send so the session list stays sorted by activity.

type Memory

type Memory struct {
	Key       string `json:"key"`
	Value     string `json:"value"`
	UpdatedAt int64  `json:"updated_at"`
}

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore(db *sql.DB) *MemoryStore

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(scope, key string) error

func (*MemoryStore) Get

func (s *MemoryStore) Get(scope, key string) (*Memory, error)

func (*MemoryStore) ListByScope

func (s *MemoryStore) ListByScope(scope string, limit int) ([]Memory, error)

func (*MemoryStore) Save

func (s *MemoryStore) Save(scope, key, value string) error

type MessageStore

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

MessageStore persists platform messages to the bee_platform_messages table.

func NewMessageStore

func NewMessageStore(db *sql.DB) *MessageStore

NewMessageStore constructs a MessageStore.

func (*MessageStore) ClaimBatch

func (s *MessageStore) ClaimBatch(ctx context.Context, batchSize int) ([]ClaimedMessage, error)

ClaimBatch atomically selects up to batchSize 'received' messages and marks them 'feeding'.

func (*MessageStore) CountReceived

func (s *MessageStore) CountReceived(ctx context.Context) (int, error)

CountReceived returns the number of messages with status 'received'.

func (*MessageStore) Create

func (s *MessageStore) Create(ctx context.Context, id, sessionKey, platform, content, raw, platformMsgID string, messageTime int64) (bool, error)

Create inserts a new message record with status "received". Returns inserted=false (no error) when platform_msg_id is non-empty and already exists. If platform_msg_id is empty, the insert always proceeds (no dedup). messageTime is stored as received_at; pass 0 to use server time.

func (*MessageStore) CreateBatch

func (s *MessageStore) CreateBatch(ctx context.Context, msgs []BatchMsg) (int64, error)

INSERT OR IGNORE. Returns the number of rows actually inserted. MessageTime is used as received_at; falls back to time.Now().UnixMilli() if zero.

func (*MessageStore) DeleteBySessionKey

func (s *MessageStore) DeleteBySessionKey(ctx context.Context, sessionKey string) error

DeleteBySessionKey removes all bee_platform_messages for the given session key.

func (*MessageStore) GetByID

func (s *MessageStore) GetByID(ctx context.Context, id string) (StoredMessage, error)

GetByID fetches the platform, session_key, and raw fields for a single message.

func (*MessageStore) ListBySessionKey

func (s *MessageStore) ListBySessionKey(ctx context.Context, sessionKey string) ([]InboundMessage, error)

ListBySessionKey returns all non-merged messages for a session, ordered by received_at ASC.

func (*MessageStore) MarkBeeProcessed

func (s *MessageStore) MarkBeeProcessed(ctx context.Context, ids []string) error

MarkBeeProcessed sets status to 'bee_processed' for the given message IDs.

func (*MessageStore) MarkMerged

func (s *MessageStore) MarkMerged(ctx context.Context, primaryID string, mergedIDs []string) error

MarkMerged sets primaryID status to "merged" and records merged_into on all mergedIDs.

func (*MessageStore) ResetFeedingBatch

func (s *MessageStore) ResetFeedingBatch(ctx context.Context, ids []string) error

ResetFeedingBatch restores 'feeding' messages back to 'received'.

func (*MessageStore) ResetFeedingToReceived

func (s *MessageStore) ResetFeedingToReceived(ctx context.Context) ([]string, error)

ResetFeedingToReceived resets all messages stuck in 'feeding' back to 'received'. Returns the IDs of affected rows so the caller can delete orphaned pending tasks.

func (*MessageStore) SetStatus

func (s *MessageStore) SetStatus(ctx context.Context, id, status string) error

SetStatus updates the status of a single message.

func (*MessageStore) UpdateStatusBatch

func (s *MessageStore) UpdateStatusBatch(ctx context.Context, ids []string, status string) error

UpdateStatusBatch sets the same status on all provided message IDs.

type SessionStore

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

SessionStore persists session context to the session_contexts table.

func NewSessionStore

func NewSessionStore(db *sql.DB) *SessionStore

NewSessionStore constructs a SessionStore.

func (*SessionStore) ClearSessionContexts

func (s *SessionStore) ClearSessionContexts(ctx context.Context, sessionKey string) error

ClearSessionContexts deletes all session_contexts rows for sessionKey, resetting session state for bee and all workers under that key.

func (*SessionStore) GetSessionContext

func (s *SessionStore) GetSessionContext(ctx context.Context, sessionKey, agentID string) (string, error)

GetSessionContext returns the session_id for (sessionKey, agentID). Returns ("", nil) when no row exists — this is normal for the first message, not a database error. Returns non-nil error only on database failure.

func (*SessionStore) UpsertSessionContext

func (s *SessionStore) UpsertSessionContext(ctx context.Context, sessionKey, agentID, sessionID string) error

UpsertSessionContext writes or overwrites the session_id for (sessionKey, agentID).

type StoredMessage

type StoredMessage struct {
	Platform   string
	SessionKey string
	Raw        string
}

StoredMessage is the subset of bee_platform_messages fields needed by platform senders.

type TaskStore

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

TaskStore handles persistence for bee tasks.

func NewTaskStore

func NewTaskStore(db *sql.DB) *TaskStore

NewTaskStore creates a TaskStore backed by db.

func (*TaskStore) CancelBySessionKey

func (s *TaskStore) CancelBySessionKey(ctx context.Context, sessionKey string) (int64, error)

CancelBySessionKey cancels all pending/running tasks for a given session. Returns the number of tasks cancelled.

func (*TaskStore) CancelByWorkerID

func (s *TaskStore) CancelByWorkerID(ctx context.Context, workerID string) error

CancelByWorkerID cancels all pending/running tasks for a given worker.

func (*TaskStore) CancelTask

func (s *TaskStore) CancelTask(ctx context.Context, taskID string) error

CancelTask sets a task status to cancelled.

func (*TaskStore) ClaimDueTasks

func (s *TaskStore) ClaimDueTasks(ctx context.Context, nowMS int64) ([]model.ClaimedTask, error)

ClaimDueTasks atomically selects all pending tasks that are due at or before nowMS, marks them running (immediate/countdown) or advances their next_run_at (scheduled), and returns them joined with their source platform_message data.

func (*TaskStore) CompleteScheduledTask

func (s *TaskStore) CompleteScheduledTask(ctx context.Context, taskID string) (bool, error)

CompleteScheduledTask resets a scheduled task back to pending so it can be picked up again by the next cron cycle. If the task has been cancelled, the status is preserved and the method returns false.

func (*TaskStore) CountAllByStatus

func (s *TaskStore) CountAllByStatus(ctx context.Context) (map[string]int, error)

CountAllByStatus returns a map of task status to count across all tasks.

func (*TaskStore) CountPendingByWorkerID

func (s *TaskStore) CountPendingByWorkerID(ctx context.Context, workerID string) (int, error)

CountPendingByWorkerID returns the number of pending tasks for a given worker.

func (*TaskStore) CountScheduledActive

func (s *TaskStore) CountScheduledActive(ctx context.Context) (int, error)

CountScheduledActive returns the number of pending scheduled tasks.

func (*TaskStore) Create

func (s *TaskStore) Create(ctx context.Context, t model.Task) (string, error)

Create inserts a new task and returns its generated ID.

func (*TaskStore) DeletePendingByMessageIDs

func (s *TaskStore) DeletePendingByMessageIDs(ctx context.Context, messageIDs []string) error

DeletePendingByMessageIDs removes pending tasks belonging to the given message IDs.

func (*TaskStore) FailTask

func (s *TaskStore) FailTask(ctx context.Context, taskID string) error

FailTask marks a task as failed. For scheduled tasks with a cron expression, it resets to pending instead so the task retries on the next scheduled run. Called by the dispatcher when a worker process exits abnormally.

func (*TaskStore) GetByID

func (s *TaskStore) GetByID(ctx context.Context, id string) (model.Task, error)

GetByID fetches a single task by ID.

func (*TaskStore) GetTaskByExecutionID

func (s *TaskStore) GetTaskByExecutionID(ctx context.Context, executionID string) (*model.Task, error)

GetTaskByExecutionID returns the task with the given execution_id, or nil if not found.

func (*TaskStore) ListByMessageID

func (s *TaskStore) ListByMessageID(ctx context.Context, messageID, status, taskType string) ([]model.Task, error)

ListByMessageID returns tasks for a given message, optionally filtered by status and/or type.

func (*TaskStore) ListBySessionKey

func (s *TaskStore) ListBySessionKey(ctx context.Context, sessionKey, status, taskType string) ([]model.Task, error)

ListBySessionKey returns tasks whose originating message belongs to the given session. status and taskType support comma-separated values (e.g., "pending,running"); empty means all.

func (*TaskStore) ResetRunningToPending

func (s *TaskStore) ResetRunningToPending(ctx context.Context) (int64, error)

ResetRunningToPending resets all running tasks back to pending.

func (*TaskStore) SetExecution

func (s *TaskStore) SetExecution(ctx context.Context, taskID, executionID, status string) error

SetExecution writes execution_id and status back to a task.

func (*TaskStore) UpdateNextRunAt

func (s *TaskStore) UpdateNextRunAt(ctx context.Context, taskID string, nextRunAt int64) error

UpdateNextRunAt sets next_run_at for a scheduled task after dispatch.

func (*TaskStore) UpdateStatus

func (s *TaskStore) UpdateStatus(ctx context.Context, taskID, status string) error

UpdateStatus sets only the status of a task. Unlike SetExecution, it does not touch execution_id.

type WorkerStore

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

func NewWorkerStore

func NewWorkerStore(db *sql.DB) *WorkerStore

func (*WorkerStore) CountByStatus

func (s *WorkerStore) CountByStatus() (map[string]int, error)

CountByStatus returns a map of worker status to count.

func (*WorkerStore) Create

func (s *WorkerStore) Create(w model.Worker) (model.Worker, error)

func (*WorkerStore) Delete

func (s *WorkerStore) Delete(id string) error

func (*WorkerStore) GetByID

func (s *WorkerStore) GetByID(id string) (model.Worker, error)

func (*WorkerStore) List

func (s *WorkerStore) List() ([]model.Worker, error)

func (*WorkerStore) Update

func (s *WorkerStore) Update(w model.Worker) (model.Worker, error)

func (*WorkerStore) UpdateStatus

func (s *WorkerStore) UpdateStatus(id string, status model.WorkerStatus) error

Jump to

Keyboard shortcuts

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