Documentation
¶
Index ¶
- Constants
- func InitDB(dbPath string) (*sql.DB, error)
- type BatchMsg
- type ClaimedMessage
- type ExecutionStore
- func (s *ExecutionStore) Create(workerID, triggerInput, sessionID string) (model.WorkerExecution, error)
- func (s *ExecutionStore) CreateBeeExecution(sessionID, triggerInput string) (model.WorkerExecution, error)
- func (s *ExecutionStore) GetByID(id string) (model.WorkerExecution, error)
- func (s *ExecutionStore) GetBySessionID(sessionID string) (model.WorkerExecution, error)
- func (s *ExecutionStore) List() ([]model.WorkerExecution, error)
- func (s *ExecutionStore) ListBeeExecutions(limit int) ([]model.WorkerExecution, error)
- func (s *ExecutionStore) ListBySessionID(sessionID string) ([]model.WorkerExecution, error)
- func (s *ExecutionStore) ListByWorkerID(workerID string) ([]model.WorkerExecution, error)
- func (s *ExecutionStore) ListRecent(limit int) ([]model.WorkerExecution, error)
- func (s *ExecutionStore) ReadLog(id string) (string, error)
- func (s *ExecutionStore) UpdatePID(id string, pid int) error
- func (s *ExecutionStore) UpdateResult(id string, result string, status model.ExecutionStatus) error
- func (s *ExecutionStore) UpdateStatus(id string, status model.ExecutionStatus) error
- func (s *ExecutionStore) WriteLog(id string, startedAt *int64, content string) (string, error)
- type InboundMessage
- type LocalReply
- type LocalReplyStore
- type LocalSession
- type LocalSessionStore
- func (s *LocalSessionStore) Create(ctx context.Context, id, name string) error
- func (s *LocalSessionStore) Delete(ctx context.Context, id string) error
- func (s *LocalSessionStore) List(ctx context.Context) ([]LocalSession, error)
- func (s *LocalSessionStore) TouchUpdatedAt(ctx context.Context, id string) error
- type Memory
- type MemoryStore
- type MessageStore
- func (s *MessageStore) ClaimBatch(ctx context.Context, batchSize int) ([]ClaimedMessage, error)
- func (s *MessageStore) CountReceived(ctx context.Context) (int, error)
- func (s *MessageStore) Create(ctx context.Context, ...) (bool, error)
- func (s *MessageStore) CreateBatch(ctx context.Context, msgs []BatchMsg) (int64, error)
- func (s *MessageStore) DeleteBySessionKey(ctx context.Context, sessionKey string) error
- func (s *MessageStore) GetByID(ctx context.Context, id string) (StoredMessage, error)
- func (s *MessageStore) ListBySessionKey(ctx context.Context, sessionKey string) ([]InboundMessage, error)
- func (s *MessageStore) MarkBeeProcessed(ctx context.Context, ids []string) error
- func (s *MessageStore) MarkMerged(ctx context.Context, primaryID string, mergedIDs []string) error
- func (s *MessageStore) ResetFeedingBatch(ctx context.Context, ids []string) error
- func (s *MessageStore) ResetFeedingToReceived(ctx context.Context) ([]string, error)
- func (s *MessageStore) RollbackWithRetry(ctx context.Context, ids []string, maxRetries int) error
- func (s *MessageStore) SetStatus(ctx context.Context, id, status string) error
- func (s *MessageStore) UpdateStatusBatch(ctx context.Context, ids []string, status string) error
- type SessionAgent
- type SessionStore
- func (s *SessionStore) ClearSessionContexts(ctx context.Context, sessionKey string) error
- func (s *SessionStore) DeleteWorkerSessionContext(ctx context.Context, sessionKey, workerID string) error
- func (s *SessionStore) GetSessionContext(ctx context.Context, sessionKey, agentID string) (string, error)
- func (s *SessionStore) ListSessionContexts(ctx context.Context, sessionKey string) ([]SessionAgent, error)
- func (s *SessionStore) UpsertSessionContext(ctx context.Context, sessionKey, agentID, sessionID string) error
- type StoredMessage
- type TaskFilter
- type TaskStore
- func (s *TaskStore) CancelBySessionKey(ctx context.Context, sessionKey string) (int64, error)
- func (s *TaskStore) CancelByWorkerID(ctx context.Context, workerID string) error
- func (s *TaskStore) CancelTask(ctx context.Context, taskID string) error
- func (s *TaskStore) ClaimDueTasks(ctx context.Context, nowMS int64) ([]model.ClaimedTask, error)
- func (s *TaskStore) CompleteScheduledTask(ctx context.Context, taskID string) (bool, error)
- func (s *TaskStore) CountAllByStatus(ctx context.Context) (map[string]int, error)
- func (s *TaskStore) CountPendingByWorkerID(ctx context.Context, workerID string) (int, error)
- func (s *TaskStore) CountScheduledActive(ctx context.Context) (int, error)
- func (s *TaskStore) Create(ctx context.Context, t model.Task) (string, error)
- func (s *TaskStore) DeletePendingByMessageIDs(ctx context.Context, messageIDs []string) error
- func (s *TaskStore) FailTask(ctx context.Context, taskID string) error
- func (s *TaskStore) GetByID(ctx context.Context, id string) (model.Task, error)
- func (s *TaskStore) GetTaskByExecutionID(ctx context.Context, executionID string) (*model.Task, error)
- func (s *TaskStore) List(ctx context.Context, f TaskFilter) ([]model.Task, error)
- func (s *TaskStore) ListByMessageID(ctx context.Context, messageID, status, taskType string) ([]model.Task, error)
- func (s *TaskStore) ListBySessionKey(ctx context.Context, sessionKey, status, taskType string) ([]model.Task, error)
- func (s *TaskStore) ResetRunningToPending(ctx context.Context) (int64, error)
- func (s *TaskStore) SetExecution(ctx context.Context, taskID, executionID, status string) error
- func (s *TaskStore) UpdateNextRunAt(ctx context.Context, taskID string, nextRunAt int64) error
- func (s *TaskStore) UpdateStatus(ctx context.Context, taskID, status string) error
- type WorkerStore
- func (s *WorkerStore) CountByStatus() (map[string]int, error)
- func (s *WorkerStore) Create(w model.Worker) (model.Worker, error)
- func (s *WorkerStore) Delete(id string) error
- func (s *WorkerStore) GetByID(id string) (model.Worker, error)
- func (s *WorkerStore) List() ([]model.Worker, error)
- func (s *WorkerStore) Update(w model.Worker) (model.Worker, error)
- func (s *WorkerStore) UpdateStatus(id string, status model.WorkerStatus) error
Constants ¶
const BeeAgentID = "bee"
BeeAgentID is the agent_id value used for bee brain session tracking.
Variables ¶
This section is empty.
Functions ¶
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
RetryCount int
}
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, logsDir string) *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) 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) ReadLog ¶ added in v0.0.5
func (s *ExecutionStore) ReadLog(id string) (string, error)
ReadLog returns the log content for an execution, reading from its log file. Returns an empty string (no error) when no log has been written yet.
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 ¶
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 ¶
func (s *LocalSessionStore) List(ctx context.Context) ([]LocalSession, error)
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 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) 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 ¶
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 ¶
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) RollbackWithRetry ¶ added in v0.0.2
RollbackWithRetry increments retry_count for each message and resets status to 'received' for messages below maxRetries, or 'failed' for those that have reached the limit. Callers determine which IDs are permanently failed from their in-memory ClaimedMessage.RetryCount values (see Feeder.rollback).
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 ¶
UpdateStatusBatch sets the same status on all provided message IDs.
type SessionAgent ¶ added in v0.0.2
type SessionAgent struct {
AgentID string
AgentType string // "bee" or "worker"
Name string // worker name, "bee", or "(deleted)"
UpdatedAt int64
}
SessionAgent represents one agent's session context entry, enriched with a human-readable name.
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) DeleteWorkerSessionContext ¶ added in v0.0.2
func (s *SessionStore) DeleteWorkerSessionContext(ctx context.Context, sessionKey, workerID string) error
DeleteWorkerSessionContext removes the session context row for one worker. Deleting a non-existent row is not an error.
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) ListSessionContexts ¶ added in v0.0.2
func (s *SessionStore) ListSessionContexts(ctx context.Context, sessionKey string) ([]SessionAgent, error)
ListSessionContexts returns all agents with session contexts for sessionKey, ordered by updated_at DESC. Worker names are resolved via LEFT JOIN; deleted workers appear as "(deleted)". AgentType is derived in Go from AgentID.
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 ¶
StoredMessage is the subset of bee_platform_messages fields needed by platform senders.
type TaskFilter ¶ added in v0.0.2
type TaskFilter struct {
MessageID string
SessionKey string
WorkerID string
Status string // comma-separated, e.g. "pending,running"
Type string // comma-separated, e.g. "immediate,countdown"
}
TaskFilter specifies filtering criteria for List. message_id and session_key are mutually exclusive. At least one of message_id, session_key, or worker_id must be non-empty.
type TaskStore ¶
type TaskStore struct {
// contains filtered or unexported fields
}
TaskStore handles persistence for bee tasks.
func NewTaskStore ¶
NewTaskStore creates a TaskStore backed by db.
func (*TaskStore) CancelBySessionKey ¶
CancelBySessionKey cancels all pending/running tasks for a given session. Returns the number of tasks cancelled.
func (*TaskStore) CancelByWorkerID ¶
CancelByWorkerID cancels all pending/running tasks for a given worker.
func (*TaskStore) CancelTask ¶
CancelTask sets a task status to cancelled.
func (*TaskStore) ClaimDueTasks ¶
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 ¶
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 ¶
CountAllByStatus returns a map of task status to count across all tasks.
func (*TaskStore) CountPendingByWorkerID ¶
CountPendingByWorkerID returns the number of pending tasks for a given worker.
func (*TaskStore) CountScheduledActive ¶
CountScheduledActive returns the number of pending scheduled tasks.
func (*TaskStore) DeletePendingByMessageIDs ¶
DeletePendingByMessageIDs removes pending tasks belonging to the given message IDs.
func (*TaskStore) FailTask ¶
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) 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) List ¶ added in v0.0.2
List returns tasks matching the given filter. If session_key is set, tasks are joined with bee_platform_messages to resolve the session. Results are ordered by created_at DESC.
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 ¶
ResetRunningToPending resets all running tasks back to pending.
func (*TaskStore) SetExecution ¶
SetExecution writes execution_id and status back to a task.
func (*TaskStore) UpdateNextRunAt ¶
UpdateNextRunAt sets next_run_at for a scheduled task after dispatch.
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) Delete ¶
func (s *WorkerStore) Delete(id string) error
func (*WorkerStore) UpdateStatus ¶
func (s *WorkerStore) UpdateStatus(id string, status model.WorkerStatus) error