Documentation
¶
Index ¶
- Constants
- Variables
- type AIBlock
- type AIBlockMode
- type AIBlockStatus
- type AIBlockStore
- type AIBlockType
- type AIConversation
- type Activity
- type ActivityLevel
- type ActivityType
- type AgentMetrics
- type AgentSessionStats
- type AgentStatsStore
- type Attachment
- type BM25Result
- type BM25SearchOptions
- type BlockEvent
- type CostStats
- type CreateAIBlock
- type CreateRouterFeedback
- type DailyCostData
- type DeleteAIConversation
- type DeleteAgentMetrics
- type DeleteAttachment
- type DeleteEpisodicMemory
- type DeleteIdentityProvider
- type DeleteInbox
- type DeleteInstanceSetting
- type DeleteMemo
- type DeleteMemoRelation
- type DeleteReaction
- type DeleteSchedule
- type DeleteToolMetrics
- type DeleteUser
- type Driver
- type EpisodicMemory
- type FindAIBlock
- type FindAIConversation
- type FindActivity
- type FindAgentMetrics
- type FindAttachment
- type FindEpisodicMemory
- type FindIdentityProvider
- type FindInbox
- type FindInstanceSetting
- type FindMemo
- type FindMemoEmbedding
- type FindMemoPayload
- type FindMemoRelation
- type FindMemosWithoutEmbedding
- type FindPromptVersionMetrics
- type FindReaction
- type FindRouterFeedback
- type FindRouterWeight
- type FindSchedule
- type FindToolMetrics
- type FindUser
- type FindUserPreferences
- type FindUserSetting
- type GetRouterStats
- type IdentityProvider
- type Inbox
- type InboxStatus
- type InstanceSetting
- type Memo
- type MemoEmbedding
- type MemoRelation
- type MemoRelationType
- type MemoWithScore
- type PATQueryResult
- type PromptExperimentSummary
- type PromptVersionMetrics
- type Reaction
- type RefreshTokenQueryResult
- type Role
- type RouterFeedback
- type RouterStats
- type RouterWeight
- type RowStatus
- type Schedule
- type ScheduleService
- type SecurityAuditEvent
- type SecurityAuditStore
- type SessionStats
- type Store
- func (s *Store) AddUserPersonalAccessToken(ctx context.Context, userID int32, ...) error
- func (s *Store) AddUserRefreshToken(ctx context.Context, userID int32, ...) error
- func (s *Store) AddUserWebhook(ctx context.Context, userID int32, ...) error
- func (s *Store) AppendEvent(ctx context.Context, blockID int64, event BlockEvent) error
- func (s *Store) AppendEventsBatch(ctx context.Context, blockID int64, events []BlockEvent) error
- func (s *Store) AppendUserInput(ctx context.Context, blockID int64, input UserInput) error
- func (s *Store) ArchiveInactiveBranches(ctx context.Context, conversationID int32, targetPath string, archivedAt int64) error
- func (s *Store) BM25Search(ctx context.Context, opts *BM25SearchOptions) ([]*BM25Result, error)
- func (s *Store) Close() error
- func (s *Store) CompleteBlock(ctx context.Context, blockID int64, assistantContent string, ...) error
- func (s *Store) CreateAIBlock(ctx context.Context, create *CreateAIBlock) (*AIBlock, error)
- func (s *Store) CreateAIBlockWithRound(ctx context.Context, create *CreateAIBlock) (*AIBlock, error)
- func (s *Store) CreateAIConversation(ctx context.Context, create *AIConversation) (*AIConversation, error)
- func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error)
- func (s *Store) CreateAttachment(ctx context.Context, create *Attachment) (*Attachment, error)
- func (s *Store) CreateEpisodicMemory(ctx context.Context, create *EpisodicMemory) (*EpisodicMemory, error)
- func (s *Store) CreateIdentityProvider(ctx context.Context, create *storepb.IdentityProvider) (*storepb.IdentityProvider, error)
- func (s *Store) CreateInbox(ctx context.Context, create *Inbox) (*Inbox, error)
- func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error)
- func (s *Store) CreateSchedule(ctx context.Context, create *Schedule) (*Schedule, error)
- func (s *Store) CreateUser(ctx context.Context, create *User) (*User, error)
- func (s *Store) DeleteAIBlock(ctx context.Context, id int64) error
- func (s *Store) DeleteAIConversation(ctx context.Context, delete *DeleteAIConversation) error
- func (s *Store) DeleteAgentMetrics(ctx context.Context, delete *DeleteAgentMetrics) error
- func (s *Store) DeleteAttachment(ctx context.Context, delete *DeleteAttachment) error
- func (s *Store) DeleteBranch(ctx context.Context, blockID int64, cascade bool) error
- func (s *Store) DeleteEpisodicMemory(ctx context.Context, delete *DeleteEpisodicMemory) error
- func (s *Store) DeleteIdentityProvider(ctx context.Context, delete *DeleteIdentityProvider) error
- func (s *Store) DeleteInbox(ctx context.Context, delete *DeleteInbox) error
- func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error
- func (s *Store) DeleteMemoEmbedding(ctx context.Context, memoID int32) error
- func (s *Store) DeleteMemoRelation(ctx context.Context, delete *DeleteMemoRelation) error
- func (s *Store) DeleteReaction(ctx context.Context, delete *DeleteReaction) error
- func (s *Store) DeleteSchedule(ctx context.Context, delete *DeleteSchedule) error
- func (s *Store) DeleteToolMetrics(ctx context.Context, delete *DeleteToolMetrics) error
- func (s *Store) DeleteUser(ctx context.Context, delete *DeleteUser) error
- func (s *Store) FindMemosWithoutEmbedding(ctx context.Context, find *FindMemosWithoutEmbedding) ([]*Memo, error)
- func (s *Store) ForkBlock(ctx context.Context, parentID int64, reason string, ...) (*AIBlock, error)
- func (s *Store) GetAIBlock(ctx context.Context, id int64) (*AIBlock, error)
- func (s *Store) GetActivePath(ctx context.Context, conversationID int32) ([]*AIBlock, error)
- func (s *Store) GetActivity(ctx context.Context, find *FindActivity) (*Activity, error)
- func (s *Store) GetAttachment(ctx context.Context, find *FindAttachment) (*Attachment, error)
- func (s *Store) GetCurrentSchemaVersion() (string, error)
- func (s *Store) GetDriver() Driver
- func (s *Store) GetIdentityProvider(ctx context.Context, find *FindIdentityProvider) (*storepb.IdentityProvider, error)
- func (s *Store) GetInstanceBasicSetting(ctx context.Context) (*storepb.InstanceBasicSetting, error)
- func (s *Store) GetInstanceGeneralSetting(ctx context.Context) (*storepb.InstanceGeneralSetting, error)
- func (s *Store) GetInstanceMemoRelatedSetting(ctx context.Context) (*storepb.InstanceMemoRelatedSetting, error)
- func (s *Store) GetInstanceSetting(ctx context.Context, find *FindInstanceSetting) (*storepb.InstanceSetting, error)
- func (s *Store) GetInstanceStorageSetting(ctx context.Context) (*storepb.InstanceStorageSetting, error)
- func (s *Store) GetLatestAIBlock(ctx context.Context, conversationID int32) (*AIBlock, error)
- func (s *Store) GetMemo(ctx context.Context, find *FindMemo) (*Memo, error)
- func (s *Store) GetMemoEmbedding(ctx context.Context, memoID int32, model string) (*MemoEmbedding, error)
- func (s *Store) GetPendingAIBlocks(ctx context.Context) ([]*AIBlock, error)
- func (s *Store) GetReaction(ctx context.Context, find *FindReaction) (*Reaction, error)
- func (s *Store) GetSchedule(ctx context.Context, find *FindSchedule) (*Schedule, error)
- func (s *Store) GetUser(ctx context.Context, find *FindUser) (*User, error)
- func (s *Store) GetUserByPATHash(ctx context.Context, tokenHash string) (*PATQueryResult, error)
- func (s *Store) GetUserPersonalAccessTokens(ctx context.Context, userID int32) ([]*storepb.PersonalAccessTokensUserSetting_PersonalAccessToken, error)
- func (s *Store) GetUserPreferences(ctx context.Context, find *FindUserPreferences) (*UserPreferences, error)
- func (s *Store) GetUserRefreshTokenByID(ctx context.Context, userID int32, tokenID string) (*storepb.RefreshTokensUserSetting_RefreshToken, error)
- func (s *Store) GetUserRefreshTokens(ctx context.Context, userID int32) ([]*storepb.RefreshTokensUserSetting_RefreshToken, error)
- func (s *Store) GetUserSetting(ctx context.Context, find *FindUserSetting) (*storepb.UserSetting, error)
- func (s *Store) GetUserWebhooks(ctx context.Context, userID int32) ([]*storepb.WebhooksUserSetting_Webhook, error)
- func (s *Store) ListAIBlocks(ctx context.Context, find *FindAIBlock) ([]*AIBlock, error)
- func (s *Store) ListAIConversations(ctx context.Context, find *FindAIConversation) ([]*AIConversation, error)
- func (s *Store) ListActiveUserIDs(ctx context.Context, cutoff time.Time) ([]int32, error)
- func (s *Store) ListActivities(ctx context.Context, find *FindActivity) ([]*Activity, error)
- func (s *Store) ListAgentMetrics(ctx context.Context, find *FindAgentMetrics) ([]*AgentMetrics, error)
- func (s *Store) ListAttachments(ctx context.Context, find *FindAttachment) ([]*Attachment, error)
- func (s *Store) ListChildBlocks(ctx context.Context, parentID int64) ([]*AIBlock, error)
- func (s *Store) ListEpisodicMemories(ctx context.Context, find *FindEpisodicMemory) ([]*EpisodicMemory, error)
- func (s *Store) ListIdentityProviders(ctx context.Context, find *FindIdentityProvider) ([]*storepb.IdentityProvider, error)
- func (s *Store) ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error)
- func (s *Store) ListInstanceSettings(ctx context.Context, find *FindInstanceSetting) ([]*storepb.InstanceSetting, error)
- func (s *Store) ListMemoEmbeddings(ctx context.Context, find *FindMemoEmbedding) ([]*MemoEmbedding, error)
- func (s *Store) ListMemoRelations(ctx context.Context, find *FindMemoRelation) ([]*MemoRelation, error)
- func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
- func (s *Store) ListReactions(ctx context.Context, find *FindReaction) ([]*Reaction, error)
- func (s *Store) ListSchedules(ctx context.Context, find *FindSchedule) ([]*Schedule, error)
- func (s *Store) ListToolMetrics(ctx context.Context, find *FindToolMetrics) ([]*ToolMetrics, error)
- func (s *Store) ListUserSettings(ctx context.Context, find *FindUserSetting) ([]*storepb.UserSetting, error)
- func (s *Store) ListUsers(ctx context.Context, find *FindUser) ([]*User, error)
- func (s *Store) Migrate(ctx context.Context) error
- func (s *Store) RemoveUserPersonalAccessToken(ctx context.Context, userID int32, tokenID string) error
- func (s *Store) RemoveUserRefreshToken(ctx context.Context, userID int32, tokenID string) error
- func (s *Store) RemoveUserWebhook(ctx context.Context, userID int32, webhookID string) error
- func (s *Store) UpdateAIBlock(ctx context.Context, update *UpdateAIBlock) (*AIBlock, error)
- func (s *Store) UpdateAIBlockStatus(ctx context.Context, blockID int64, status AIBlockStatus) error
- func (s *Store) UpdateAIConversation(ctx context.Context, update *UpdateAIConversation) (*AIConversation, error)
- func (s *Store) UpdateAttachment(ctx context.Context, update *UpdateAttachment) error
- func (s *Store) UpdateIdentityProvider(ctx context.Context, update *UpdateIdentityProviderV1) (*storepb.IdentityProvider, error)
- func (s *Store) UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error)
- func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error
- func (s *Store) UpdatePATLastUsed(ctx context.Context, userID int32, tokenID string, ...) error
- func (s *Store) UpdateSchedule(ctx context.Context, update *UpdateSchedule) error
- func (s *Store) UpdateUser(ctx context.Context, update *UpdateUser) (*User, error)
- func (s *Store) UpdateUserWebhook(ctx context.Context, userID int32, ...) error
- func (s *Store) UpsertAgentMetrics(ctx context.Context, upsert *UpsertAgentMetrics) (*AgentMetrics, error)
- func (s *Store) UpsertInstanceSetting(ctx context.Context, upsert *storepb.InstanceSetting) (*storepb.InstanceSetting, error)
- func (s *Store) UpsertMemoEmbedding(ctx context.Context, embedding *MemoEmbedding) (*MemoEmbedding, error)
- func (s *Store) UpsertMemoRelation(ctx context.Context, create *MemoRelation) (*MemoRelation, error)
- func (s *Store) UpsertReaction(ctx context.Context, upsert *Reaction) (*Reaction, error)
- func (s *Store) UpsertToolMetrics(ctx context.Context, upsert *UpsertToolMetrics) (*ToolMetrics, error)
- func (s *Store) UpsertUserPreferences(ctx context.Context, upsert *UpsertUserPreferences) (*UserPreferences, error)
- func (s *Store) UpsertUserSetting(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error)
- func (s *Store) VectorSearch(ctx context.Context, opts *VectorSearchOptions) ([]*MemoWithScore, error)
- type TitleSource
- type TokenUsage
- type ToolMetrics
- type UpdateAIBlock
- type UpdateAIConversation
- type UpdateAttachment
- type UpdateIdentityProvider
- type UpdateIdentityProviderV1
- type UpdateInbox
- type UpdateMemo
- type UpdateSchedule
- type UpdateUser
- type UpsertAgentMetrics
- type UpsertPromptVersionMetrics
- type UpsertRouterWeight
- type UpsertToolMetrics
- type UpsertUserPreferences
- type User
- type UserCostSettings
- type UserInput
- type UserPreferences
- type UserSetting
- type VectorSearchOptions
- type Visibility
Constants ¶
const ( // MigrateFilePrefix is the prefix for migration files. // Migration files use timestamp format: YYYYMMDDHHMMSS_description.sql MigrateFilePrefix = "" // LatestSchemaFileName is the name of the latest schema file. // This file is used to initialize fresh installations with the current schema. LatestSchemaFileName = "LATEST.sql" // MigrateDirName is the subdirectory containing migration files. MigrateDirName = "migrate" // SchemaDirName is the subdirectory containing the base schema file. SchemaDirName = "schema" )
const DefaultContentLengthLimit = 8 * 1024
DefaultContentLengthLimit is the default limit of content length in bytes. 8KB.
const (
SystemBotID int32 = 0
)
Variables ¶
var DefaultReactions = []string{"👍", "👎", "❤️", "🎉", "😄", "😕", "😢", "😡"}
DefaultReactions is the default reactions for memo related setting.
var ( SystemBot = &User{ ID: SystemBotID, Username: "system_bot", Role: RoleAdmin, Email: "", Nickname: "Bot", } )
Functions ¶
This section is empty.
Types ¶
type AIBlock ¶ added in v0.94.0
type AIBlock struct {
ID int64
UID string
ConversationID int32
RoundNumber int32
BlockType AIBlockType
Mode AIBlockMode
UserInputs []UserInput
AssistantContent string
AssistantTimestamp int64
EventStream []BlockEvent
SessionStats *SessionStats
CCSessionID string
Status AIBlockStatus
Metadata map[string]any
ParentBlockID *int64 // Parent block ID for tree branching (null for root blocks)
BranchPath string // Branch path for ordering (e.g., "0/1/3")
// Token usage statistics (P1-A006: LLM Stats Collection)
TokenUsage *TokenUsage
// Cost estimation (ai-block-fields-extension)
CostEstimate int64 // In milli-cents (1/1000 of a US cent)
ModelVersion string // LLM model used (e.g., "deepseek-chat")
UserFeedback string // User feedback: "thumbs_up", "thumbs_down", or custom
RegenerationCount int32 // Number of times this block was regenerated
ErrorMessage string // Error message if status = ERROR
ArchivedAt *int64 // Timestamp when block was archived (null if active)
CreatedTs int64
UpdatedTs int64
}
AIBlock represents a conversation block (round)
type AIBlockMode ¶ added in v0.94.0
type AIBlockMode string
AIBlockMode represents the AI mode
const ( AIBlockModeNormal AIBlockMode = "normal" AIBlockModeGeek AIBlockMode = "geek" AIBlockModeEvolution AIBlockMode = "evolution" )
type AIBlockStatus ¶ added in v0.94.0
type AIBlockStatus string
AIBlockStatus represents the block status
const ( AIBlockStatusPending AIBlockStatus = "pending" AIBlockStatusStreaming AIBlockStatus = "streaming" AIBlockStatusCompleted AIBlockStatus = "completed" AIBlockStatusError AIBlockStatus = "error" )
type AIBlockStore ¶ added in v0.94.0
type AIBlockStore interface {
// CreateBlock creates a new block
CreateBlock(ctx context.Context, create *CreateAIBlock) (*AIBlock, error)
// GetBlock retrieves a block by ID
GetBlock(ctx context.Context, id int64) (*AIBlock, error)
// ListBlocks retrieves blocks for a conversation
ListBlocks(ctx context.Context, find *FindAIBlock) ([]*AIBlock, error)
// UpdateBlock updates a block
UpdateBlock(ctx context.Context, update *UpdateAIBlock) (*AIBlock, error)
// AppendUserInput appends a user input to an existing block
AppendUserInput(ctx context.Context, blockID int64, input UserInput) error
// AppendEvent appends an event to the event stream
AppendEvent(ctx context.Context, blockID int64, event BlockEvent) error
// AppendEventsBatch appends multiple events to the event stream in a single query
AppendEventsBatch(ctx context.Context, blockID int64, events []BlockEvent) error
// UpdateStatus updates the block status
UpdateStatus(ctx context.Context, blockID int64, status AIBlockStatus) error
// DeleteBlock deletes a block
DeleteBlock(ctx context.Context, id int64) error
// GetLatestBlock retrieves the latest block for a conversation
GetLatestBlock(ctx context.Context, conversationID int32) (*AIBlock, error)
// GetPendingBlocks retrieves all pending/streaming blocks for cleanup
GetPendingBlocks(ctx context.Context) ([]*AIBlock, error)
// ForkBlock creates a new block as a branch from an existing block.
// The new block inherits the parent's conversation. User inputs can be optionally replaced.
// If replaceUserInputs is nil, inherits parent's user inputs.
// If replaceUserInputs is provided, uses the new user inputs (for message editing).
ForkBlock(ctx context.Context, parentID int64, reason string, replaceUserInputs []UserInput) (*AIBlock, error)
// ListChildBlocks lists all direct children of a block.
ListChildBlocks(ctx context.Context, parentID int64) ([]*AIBlock, error)
// GetActivePath retrieves the currently active branch path for a conversation.
GetActivePath(ctx context.Context, conversationID int32) ([]*AIBlock, error)
// DeleteBranch deletes a block and all its descendants.
DeleteBranch(ctx context.Context, blockID int64, cascade bool) error
// ArchiveInactiveBranches archives blocks not on the active branch path.
// This sets archived_at timestamp for blocks that don't match the target path.
ArchiveInactiveBranches(ctx context.Context, conversationID int32, targetPath string, archivedAt int64) error
}
AIBlockStore defines the interface for block storage operations
type AIBlockType ¶ added in v0.94.0
type AIBlockType string
AIBlockType represents the block type
const ( AIBlockTypeMessage AIBlockType = "message" AIBlockTypeContextSeparator AIBlockType = "context_separator" )
type AIConversation ¶
type AIConversation struct {
UID string
Title string
TitleSource TitleSource // Indicates how the title was created
ParrotID string
RowStatus RowStatus
CreatedTs int64
UpdatedTs int64
ID int32
CreatorID int32
Pinned bool
BlockCount int32 // Number of blocks in this conversation (populated by ListAIConversations with JOIN)
}
type Activity ¶
type Activity struct {
Payload *storepb.ActivityPayload
Type ActivityType
Level ActivityLevel
CreatedTs int64
ID int32
CreatorID int32
}
type ActivityLevel ¶
type ActivityLevel string
const (
ActivityLevelInfo ActivityLevel = "INFO"
)
func (ActivityLevel) String ¶
func (l ActivityLevel) String() string
type ActivityType ¶
type ActivityType string
const (
ActivityTypeMemoComment ActivityType = "MEMO_COMMENT"
)
func (ActivityType) String ¶
func (t ActivityType) String() string
type AgentMetrics ¶
type AgentMetrics struct {
HourBucket time.Time
AgentType string
Errors string
ID int64
RequestCount int64
SuccessCount int64
LatencySumMs int64
LatencyP50Ms int32
LatencyP95Ms int32
}
AgentMetrics represents hourly aggregated metrics for an agent type.
type AgentSessionStats ¶ added in v0.93.0
type AgentSessionStats struct {
ID int64
SessionID string
ConversationID int64
UserID int32
AgentType string
StartedAt time.Time
EndedAt time.Time
TotalDurationMs int64
ThinkingDurationMs int64
ToolDurationMs int64
GenerationDurationMs int64
InputTokens int32
OutputTokens int32
CacheWriteTokens int32
CacheReadTokens int32
TotalTokens int32
TotalCostUSD float64
ToolCallCount int32
ToolsUsed []string
FilesModified int32
FilePaths []string
ModelUsed string
IsError bool
ErrorMessage string
CreatedAt time.Time
UpdatedAt time.Time
}
AgentSessionStats represents a session statistics record for storage. AgentSessionStats 表示会话统计数据的存储记录。
type AgentStatsStore ¶ added in v0.93.0
type AgentStatsStore interface {
// SaveSessionStats saves a session statistics record.
SaveSessionStats(ctx context.Context, stats *AgentSessionStats) error
// GetSessionStats retrieves stats by session ID.
GetSessionStats(ctx context.Context, sessionID string) (*AgentSessionStats, error)
// ListSessionStats retrieves stats for a user with pagination.
ListSessionStats(ctx context.Context, userID int32, limit, offset int) ([]*AgentSessionStats, int64, error)
// GetDailyCostUsage retrieves total cost for a user in a date range.
GetDailyCostUsage(ctx context.Context, userID int32, startDate, endDate time.Time) (float64, error)
// GetCostStats retrieves aggregated cost statistics.
GetCostStats(ctx context.Context, userID int32, days int) (*CostStats, error)
// GetUserCostSettings retrieves or creates user cost settings.
GetUserCostSettings(ctx context.Context, userID int32) (*UserCostSettings, error)
// SetUserCostSettings updates user cost settings.
SetUserCostSettings(ctx context.Context, settings *UserCostSettings) error
}
AgentStatsStore defines the interface for session statistics persistence. AgentStatsStore 定义会话统计持久化的接口。
type Attachment ¶
type Attachment struct {
Payload *storepb.AttachmentPayload
MemoUID *string
MemoID *int32
Type string
FilePath string
RowStatus string
Filename string
UID string
OCRText string
ExtractedText string
ThumbnailPath string
Reference string
Blob []byte
CreatedTs int64
Size int64
UpdatedTs int64
StorageType storepb.AttachmentStorageType
ID int32
CreatorID int32
}
type BM25Result ¶
BM25Result represents a BM25 search result with relevance score.
type BM25SearchOptions ¶
BM25SearchOptions represents the options for BM25 full-text search.
func (*BM25SearchOptions) Validate ¶
func (o *BM25SearchOptions) Validate() error
Validate validates the BM25SearchOptions.
type BlockEvent ¶ added in v0.94.0
type BlockEvent struct {
Type string `json:"type"` // "thinking", "tool_use", "tool_result", "answer", "error"
Content string `json:"content,omitempty"`
Timestamp int64 `json:"timestamp"`
Meta map[string]any `json:"meta,omitempty"`
}
BlockEvent represents an event in the event stream
type CostStats ¶ added in v0.93.0
type CostStats struct {
TotalCostUSD float64
DailyAverageUSD float64
SessionCount int64
MostExpensiveSession *AgentSessionStats
DailyBreakdown []*DailyCostData
}
CostStats represents aggregated cost statistics for a user. CostStats 表示用户的聚合成本统计。
type CreateAIBlock ¶ added in v0.94.0
type CreateAIBlock struct {
UID string
ConversationID int32
BlockType AIBlockType
Mode AIBlockMode
UserInputs []UserInput
Metadata map[string]any
CCSessionID string
Status AIBlockStatus
ParentBlockID *int64 // Parent block ID for forking (null for new root)
// New fields for block extensions
TokenUsage *TokenUsage
CostEstimate int64
ModelVersion string
CreatedTs int64
UpdatedTs int64
}
CreateAIBlock represents the input for creating a block
type CreateRouterFeedback ¶ added in v0.94.0
type CreateRouterFeedback struct {
UserID int32
Input string
Predicted string
Actual string
Feedback string
Timestamp int64
Source string
}
CreateRouterFeedback specifies data for creating a router feedback entry.
type DailyCostData ¶ added in v0.93.0
DailyCostData represents cost data for a single day. DailyCostData 表示单日的成本数据。
type DeleteAIConversation ¶
type DeleteAIConversation struct {
ID int32
}
type DeleteAgentMetrics ¶
DeleteAgentMetrics specifies the conditions for deleting agent metrics.
type DeleteAttachment ¶
type DeleteEpisodicMemory ¶
DeleteEpisodicMemory specifies the conditions for deleting episodic memories.
type DeleteIdentityProvider ¶
type DeleteIdentityProvider struct {
ID int32
}
type DeleteInbox ¶
type DeleteInbox struct {
ID int32
}
DeleteInbox specifies which inbox item to delete.
type DeleteInstanceSetting ¶
type DeleteInstanceSetting struct {
Name string
}
type DeleteMemo ¶
type DeleteMemo struct {
ID int32
}
type DeleteMemoRelation ¶
type DeleteMemoRelation struct {
MemoID *int32
RelatedMemoID *int32
Type *MemoRelationType
}
type DeleteReaction ¶
type DeleteReaction struct {
ID int32
}
type DeleteSchedule ¶
type DeleteSchedule struct {
ID int32
}
DeleteSchedule is the delete request for schedule.
type DeleteToolMetrics ¶
DeleteToolMetrics specifies the conditions for deleting tool metrics.
type DeleteUser ¶
type DeleteUser struct {
ID int32
}
type Driver ¶
type Driver interface {
GetDB() *sql.DB
Close() error
IsInitialized(ctx context.Context) (bool, error)
// Activity model related methods.
CreateActivity(ctx context.Context, create *Activity) (*Activity, error)
ListActivities(ctx context.Context, find *FindActivity) ([]*Activity, error)
// Attachment model related methods.
CreateAttachment(ctx context.Context, create *Attachment) (*Attachment, error)
ListAttachments(ctx context.Context, find *FindAttachment) ([]*Attachment, error)
UpdateAttachment(ctx context.Context, update *UpdateAttachment) error
DeleteAttachment(ctx context.Context, delete *DeleteAttachment) error
// Memo model related methods.
CreateMemo(ctx context.Context, create *Memo) (*Memo, error)
ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
UpdateMemo(ctx context.Context, update *UpdateMemo) error
DeleteMemo(ctx context.Context, delete *DeleteMemo) error
// UpdateMemoEmbedding updates the embedding vector for a memo.
UpdateMemoEmbedding(ctx context.Context, id int32, embedding []float32) error
// SearchMemosByVector performs semantic search using vector similarity.
// Returns memos and their similarity scores.
SearchMemosByVector(ctx context.Context, embedding []float32, limit int) ([]*Memo, []float32, error)
// MemoRelation model related methods.
UpsertMemoRelation(ctx context.Context, create *MemoRelation) (*MemoRelation, error)
ListMemoRelations(ctx context.Context, find *FindMemoRelation) ([]*MemoRelation, error)
DeleteMemoRelation(ctx context.Context, delete *DeleteMemoRelation) error
// InstanceSetting model related methods.
UpsertInstanceSetting(ctx context.Context, upsert *InstanceSetting) (*InstanceSetting, error)
ListInstanceSettings(ctx context.Context, find *FindInstanceSetting) ([]*InstanceSetting, error)
DeleteInstanceSetting(ctx context.Context, delete *DeleteInstanceSetting) error
// User model related methods.
CreateUser(ctx context.Context, create *User) (*User, error)
UpdateUser(ctx context.Context, update *UpdateUser) (*User, error)
ListUsers(ctx context.Context, find *FindUser) ([]*User, error)
DeleteUser(ctx context.Context, delete *DeleteUser) error
// UserSetting model related methods.
UpsertUserSetting(ctx context.Context, upsert *UserSetting) (*UserSetting, error)
ListUserSettings(ctx context.Context, find *FindUserSetting) ([]*UserSetting, error)
GetUserByPATHash(ctx context.Context, tokenHash string) (*PATQueryResult, error)
// IdentityProvider model related methods.
CreateIdentityProvider(ctx context.Context, create *IdentityProvider) (*IdentityProvider, error)
ListIdentityProviders(ctx context.Context, find *FindIdentityProvider) ([]*IdentityProvider, error)
UpdateIdentityProvider(ctx context.Context, update *UpdateIdentityProvider) (*IdentityProvider, error)
DeleteIdentityProvider(ctx context.Context, delete *DeleteIdentityProvider) error
// Inbox model related methods.
CreateInbox(ctx context.Context, create *Inbox) (*Inbox, error)
ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error)
UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error)
DeleteInbox(ctx context.Context, delete *DeleteInbox) error
// Reaction model related methods.
UpsertReaction(ctx context.Context, create *Reaction) (*Reaction, error)
ListReactions(ctx context.Context, find *FindReaction) ([]*Reaction, error)
GetReaction(ctx context.Context, find *FindReaction) (*Reaction, error)
DeleteReaction(ctx context.Context, delete *DeleteReaction) error
// MemoEmbedding model related methods.
UpsertMemoEmbedding(ctx context.Context, embedding *MemoEmbedding) (*MemoEmbedding, error)
ListMemoEmbeddings(ctx context.Context, find *FindMemoEmbedding) ([]*MemoEmbedding, error)
DeleteMemoEmbedding(ctx context.Context, memoID int32) error
FindMemosWithoutEmbedding(ctx context.Context, find *FindMemosWithoutEmbedding) ([]*Memo, error)
VectorSearch(ctx context.Context, opts *VectorSearchOptions) ([]*MemoWithScore, error)
BM25Search(ctx context.Context, opts *BM25SearchOptions) ([]*BM25Result, error)
// Schedule model related methods.
CreateSchedule(ctx context.Context, create *Schedule) (*Schedule, error)
ListSchedules(ctx context.Context, find *FindSchedule) ([]*Schedule, error)
UpdateSchedule(ctx context.Context, update *UpdateSchedule) error
DeleteSchedule(ctx context.Context, delete *DeleteSchedule) error
// AIConversation model related methods.
CreateAIConversation(ctx context.Context, create *AIConversation) (*AIConversation, error)
ListAIConversations(ctx context.Context, find *FindAIConversation) ([]*AIConversation, error)
UpdateAIConversation(ctx context.Context, update *UpdateAIConversation) (*AIConversation, error)
DeleteAIConversation(ctx context.Context, delete *DeleteAIConversation) error
// AIBlock model related methods (Unified Block Model).
CreateAIBlock(ctx context.Context, create *CreateAIBlock) (*AIBlock, error)
GetAIBlock(ctx context.Context, id int64) (*AIBlock, error)
ListAIBlocks(ctx context.Context, find *FindAIBlock) ([]*AIBlock, error)
UpdateAIBlock(ctx context.Context, update *UpdateAIBlock) (*AIBlock, error)
DeleteAIBlock(ctx context.Context, id int64) error
AppendUserInput(ctx context.Context, blockID int64, input UserInput) error
AppendEvent(ctx context.Context, blockID int64, event BlockEvent) error
AppendEventsBatch(ctx context.Context, blockID int64, events []BlockEvent) error
UpdateAIBlockStatus(ctx context.Context, blockID int64, status AIBlockStatus) error
GetLatestAIBlock(ctx context.Context, conversationID int32) (*AIBlock, error)
GetPendingAIBlocks(ctx context.Context) ([]*AIBlock, error)
CreateAIBlockWithRound(ctx context.Context, create *CreateAIBlock) (*AIBlock, error)
// CompleteBlock atomically marks a block as completed with content and stats.
CompleteBlock(ctx context.Context, blockID int64, assistantContent string, sessionStats *SessionStats) error
// EpisodicMemory model related methods.
CreateEpisodicMemory(ctx context.Context, create *EpisodicMemory) (*EpisodicMemory, error)
ListEpisodicMemories(ctx context.Context, find *FindEpisodicMemory) ([]*EpisodicMemory, error)
ListActiveUserIDs(ctx context.Context, cutoff time.Time) ([]int32, error)
DeleteEpisodicMemory(ctx context.Context, delete *DeleteEpisodicMemory) error
// UserPreferences model related methods.
UpsertUserPreferences(ctx context.Context, upsert *UpsertUserPreferences) (*UserPreferences, error)
GetUserPreferences(ctx context.Context, find *FindUserPreferences) (*UserPreferences, error)
// AgentMetrics model related methods.
UpsertAgentMetrics(ctx context.Context, upsert *UpsertAgentMetrics) (*AgentMetrics, error)
ListAgentMetrics(ctx context.Context, find *FindAgentMetrics) ([]*AgentMetrics, error)
DeleteAgentMetrics(ctx context.Context, delete *DeleteAgentMetrics) error
// ToolMetrics model related methods.
UpsertToolMetrics(ctx context.Context, upsert *UpsertToolMetrics) (*ToolMetrics, error)
ListToolMetrics(ctx context.Context, find *FindToolMetrics) ([]*ToolMetrics, error)
DeleteToolMetrics(ctx context.Context, delete *DeleteToolMetrics) error
// ========== Tree Branching Methods (tree-conversation-branching) ==========
// ForkBlock creates a new block as a branch from an existing block.
// The new block inherits the parent's conversation. User inputs can be optionally replaced.
// If replaceUserInputs is nil, inherits parent's user inputs.
// If replaceUserInputs is provided, uses the new user inputs (for message editing).
ForkBlock(ctx context.Context, parentID int64, reason string, replaceUserInputs []UserInput) (*AIBlock, error)
// ListChildBlocks lists all direct children of a block.
ListChildBlocks(ctx context.Context, parentID int64) ([]*AIBlock, error)
// GetActivePath retrieves the currently active branch path for a conversation.
GetActivePath(ctx context.Context, conversationID int32) ([]*AIBlock, error)
// DeleteBranch deletes a block and all its descendants.
DeleteBranch(ctx context.Context, blockID int64, cascade bool) error
// ArchiveInactiveBranches archives blocks not on the active branch path.
ArchiveInactiveBranches(ctx context.Context, conversationID int32, targetPath string, archivedAt int64) error
// AgentStatsStore provides session statistics persistence.
AgentStatsStore() AgentStatsStore
// SecurityAuditStore provides security audit logging.
SecurityAuditStore() SecurityAuditStore
}
Driver is an interface for store driver. It contains all methods that store database driver should implement.
type EpisodicMemory ¶
type EpisodicMemory struct {
Timestamp time.Time
AgentType string
UserInput string
Outcome string
Summary string
ID int64
CreatedTs int64
UserID int32
Importance float32
}
EpisodicMemory represents an episodic memory record for AI learning.
type FindAIBlock ¶ added in v0.94.0
type FindAIBlock struct {
ID *int64
UID *string
ConversationID *int32
Status *AIBlockStatus
Mode *AIBlockMode
CCSessionID *string
ParentBlockID *int64 // Filter by parent block (for branch queries)
}
FindAIBlock represents the filter for finding blocks
type FindAIConversation ¶
type FindActivity ¶
type FindActivity struct {
ID *int32
Type *ActivityType
}
type FindAgentMetrics ¶
type FindAgentMetrics struct {
AgentType *string
StartTime *time.Time
EndTime *time.Time
Limit int
}
FindAgentMetrics specifies the conditions for finding agent metrics.
type FindAttachment ¶
type FindEpisodicMemory ¶
type FindEpisodicMemory struct {
ID *int64
UserID *int32
AgentType *string
Query *string // For text search in user_input and summary
Limit int
Offset int
}
FindEpisodicMemory specifies the conditions for finding episodic memories.
type FindIdentityProvider ¶
type FindIdentityProvider struct {
ID *int32
}
type FindInbox ¶
type FindInbox struct {
ID *int32
SenderID *int32
ReceiverID *int32
Status *InboxStatus
MessageType *storepb.InboxMessage_Type
// Pagination
Limit *int
Offset *int
}
FindInbox specifies filter criteria for querying inbox items.
type FindInstanceSetting ¶
type FindInstanceSetting struct {
Name string
}
type FindMemoEmbedding ¶
FindMemoEmbedding is the find condition for memo embeddings.
type FindMemoPayload ¶
type FindMemoRelation ¶
type FindMemoRelation struct {
MemoID *int32
RelatedMemoID *int32
Type *MemoRelationType
MemoFilter *string
}
type FindMemosWithoutEmbedding ¶
type FindMemosWithoutEmbedding struct {
Model string // Embedding model to check
Limit int // Maximum number of memos to return
}
FindMemosWithoutEmbedding is the find condition for memos without embeddings.
type FindPromptVersionMetrics ¶
type FindPromptVersionMetrics struct {
AgentType *string
PromptVersion *string
StartTime *time.Time
EndTime *time.Time
Limit int
}
FindPromptVersionMetrics specifies the conditions for finding prompt version metrics.
type FindReaction ¶
type FindRouterFeedback ¶ added in v0.94.0
type FindRouterFeedback struct {
UserID *int32
StartTime *int64
EndTime *int64
Feedback *string
Limit int
}
FindRouterFeedback specifies conditions for finding router feedback.
type FindRouterWeight ¶ added in v0.94.0
FindRouterWeight specifies conditions for finding router weights.
type FindSchedule ¶
type FindSchedule struct {
ID *int32
UID *string
CreatorID *int32
// Time range filters
StartTs *int64
EndTs *int64
// Status filter
RowStatus *RowStatus
// P1: Schedule query mode
// 0 = AUTO (auto-select based on query type)
// 1 = STANDARD (return schedules with any part in range)
// 2 = STRICT (return only schedules completely in range)
QueryMode *int32
// Pagination
Limit *int
Offset *int
}
FindSchedule is the find condition for schedule.
type FindToolMetrics ¶
FindToolMetrics specifies the conditions for finding tool metrics.
type FindUserPreferences ¶
type FindUserPreferences struct {
UserID *int32
}
FindUserPreferences specifies the conditions for finding user preferences.
type FindUserSetting ¶
type FindUserSetting struct {
UserID *int32
Key storepb.UserSetting_Key
}
type GetRouterStats ¶ added in v0.94.0
GetRouterStats specifies parameters for router statistics.
type IdentityProvider ¶
type Inbox ¶
type Inbox struct {
Message *storepb.InboxMessage
Status InboxStatus
CreatedTs int64
ID int32
SenderID int32
ReceiverID int32
}
Inbox represents a notification in a user's inbox. It connects activities to users who should be notified.
type InboxStatus ¶
type InboxStatus string
InboxStatus represents the status of an inbox notification.
const ( // UNREAD indicates the notification has not been read by the user. UNREAD InboxStatus = "UNREAD" // ARCHIVED indicates the notification has been archived/dismissed by the user. ARCHIVED InboxStatus = "ARCHIVED" )
func (InboxStatus) String ¶
func (s InboxStatus) String() string
type InstanceSetting ¶
type MemoEmbedding ¶
type MemoEmbedding struct {
Model string
Embedding []float32
CreatedTs int64
UpdatedTs int64
ID int32
MemoID int32
}
MemoEmbedding represents the vector embedding of a memo.
type MemoRelation ¶
type MemoRelation struct {
Type MemoRelationType
MemoID int32
RelatedMemoID int32
}
type MemoRelationType ¶
type MemoRelationType string
const ( // MemoRelationReference is the type for a reference memo relation. MemoRelationReference MemoRelationType = "REFERENCE" // MemoRelationComment is the type for a comment memo relation. MemoRelationComment MemoRelationType = "COMMENT" )
type MemoWithScore ¶
type MemoWithScore struct {
Memo *Memo
Score float32 // Similarity score (0-1, higher is more similar)
}
MemoWithScore represents a vector search result with similarity score.
type PATQueryResult ¶
type PATQueryResult struct {
User *User
PAT *storepb.PersonalAccessTokensUserSetting_PersonalAccessToken
UserID int32
}
PATQueryResult contains the result of querying a PAT by hash.
type PromptExperimentSummary ¶
type PromptExperimentSummary struct {
AgentType string
ControlVersion string
TreatmentVersion string
Recommendation string
ControlRequests int64
TreatmentRequests int64
ControlSuccessRate float64
TreatmentSuccessRate float64
ControlAvgLatencyMs int64
TreatmentAvgLatencyMs int64
ImprovementRate float64
IsStatisticallySignificant bool
}
PromptExperimentSummary represents aggregated metrics for an A/B experiment. Used for comparing control vs treatment performance.
type PromptVersionMetrics ¶
type PromptVersionMetrics struct {
HourBucket time.Time
AgentType string
PromptVersion string
ID int64
RequestCount int64
SuccessCount int64
AvgLatencyMs int64
UserSatisfaction float32
}
PromptVersionMetrics represents metrics for a specific prompt version in an A/B experiment. This enables comparison of prompt performance across versions.
type RefreshTokenQueryResult ¶
type RefreshTokenQueryResult struct {
RefreshToken *storepb.RefreshTokensUserSetting_RefreshToken
UserID int32
}
RefreshTokenQueryResult contains the result of querying a refresh token.
type RouterFeedback ¶ added in v0.94.0
type RouterFeedback struct {
ID int64 `json:"id"`
UserID int32 `json:"user_id"`
Input string `json:"input"`
Predicted string `json:"predicted"` // What the router predicted (as Intent string)
Actual string `json:"actual"` // What the user actually wanted
Feedback string `json:"feedback"` // FeedbackType: positive, rephrase, switch
Timestamp int64 `json:"timestamp"`
Source string `json:"source"` // "rule", "history", "llm"
}
RouterFeedback represents a single feedback event for a routing decision.
type RouterStats ¶ added in v0.94.0
type RouterStats struct {
TotalPredictions int64 `json:"total_predictions"`
CorrectCount int64 `json:"correct_count"`
IncorrectCount int64 `json:"incorrect_count"`
Accuracy float64 `json:"accuracy"`
ByIntent map[string]int64 `json:"by_intent"`
BySource map[string]int64 `json:"by_source"`
LastUpdated int64 `json:"last_updated"`
}
RouterStats represents routing accuracy statistics.
type RouterWeight ¶ added in v0.94.0
type RouterWeight struct {
UserID int32 `json:"user_id"`
Category string `json:"category"` // "schedule", "memo", "amazing"
Keyword string `json:"keyword"`
Weight int `json:"weight"`
CreatedTs int64 `json:"created_ts"`
UpdatedTs int64 `json:"updated_ts"`
}
RouterWeight represents a weight adjustment for a keyword.
type Schedule ¶
type Schedule struct {
EndTs *int64
Payload *string
Reminders *string
RecurrenceEndTs *int64
RecurrenceRule *string
Timezone string
Title string
Description string
Location string
RowStatus RowStatus
UID string
StartTs int64
UpdatedTs int64
CreatedTs int64
ID int32
CreatorID int32
AllDay bool
}
Schedule is the object representing a schedule.
func (*Schedule) ConflictWith ¶
ConflictWith checks if this schedule conflicts with another.
func (*Schedule) GetDuration ¶
GetDuration returns the duration of the schedule.
func (*Schedule) IsActiveAt ¶
IsActiveAt checks if the schedule is active at the given time.
func (*Schedule) ParseEndTime ¶
ParseEndTime parses the schedule end time to time.Time.
func (*Schedule) ParseStartTime ¶
ParseStartTime parses the schedule start time to time.Time.
type ScheduleService ¶
type ScheduleService interface {
CreateSchedule(ctx context.Context, create *Schedule) (*Schedule, error)
ListSchedules(ctx context.Context, find *FindSchedule) ([]*Schedule, error)
UpdateSchedule(ctx context.Context, update *UpdateSchedule) error
DeleteSchedule(ctx context.Context, delete *DeleteSchedule) error
}
ScheduleService is the interface for schedule-related operations.
type SecurityAuditEvent ¶ added in v0.93.0
type SecurityAuditEvent struct {
ID int64
SessionID string
UserID int32
AgentType string
OperationType string
OperationName string
RiskLevel string
CommandInput string
CommandMatchedPattern string
ActionTaken string
Reason string
FilePath string
ToolID string
OccurredAt time.Time
}
SecurityAuditEvent represents a security-related event for audit logging. SecurityAuditEvent 表示安全相关事件的审计日志。
type SecurityAuditStore ¶ added in v0.93.0
type SecurityAuditStore interface {
// LogSecurityEvent saves a security event.
LogSecurityEvent(ctx context.Context, event *SecurityAuditEvent) error
// ListSecurityEvents retrieves security events for a user with pagination.
ListSecurityEvents(ctx context.Context, userID int32, limit, offset int) ([]*SecurityAuditEvent, int64, error)
// ListSecurityEventsByRisk retrieves events filtered by risk level.
ListSecurityEventsByRisk(ctx context.Context, userID int32, riskLevel string, limit, offset int) ([]*SecurityAuditEvent, int64, error)
}
SecurityAuditStore defines the interface for security audit logging. SecurityAuditStore 定义安全审计日志的接口。
type SessionStats ¶ added in v0.94.0
type SessionStats struct {
SessionID string `json:"session_id"`
UserID int32 `json:"user_id"`
AgentType string `json:"agent_type"`
TotalDurationMs int64 `json:"total_duration_ms"`
ThinkingDurationMs int64 `json:"thinking_duration_ms"`
ToolDurationMs int64 `json:"tool_duration_ms"`
GenerationDurationMs int64 `json:"generation_duration_ms"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheWriteTokens int `json:"cache_write_tokens"`
CacheReadTokens int `json:"cache_read_tokens"`
TotalTokens int `json:"total_tokens"`
TotalCostUsd float64 `json:"total_cost_usd"`
ToolCallCount int `json:"tool_call_count"`
ToolsUsed []string `json:"tools_used,omitempty"`
FilesModified int `json:"files_modified"`
FilePaths []string `json:"file_paths,omitempty"`
ModelUsed string `json:"model_used,omitempty"`
IsError bool `json:"is_error"`
ErrorMessage string `json:"error_message,omitempty"`
}
SessionStats represents session statistics (compatible with agent_session_stats)
type Store ¶
type Store struct {
// Store services
AgentStatsStore AgentStatsStore // session statistics persistence
SecurityAuditStore SecurityAuditStore // security audit logging
// contains filtered or unexported fields
}
Store provides database access to all raw objects.
func (*Store) AddUserPersonalAccessToken ¶
func (s *Store) AddUserPersonalAccessToken(ctx context.Context, userID int32, token *storepb.PersonalAccessTokensUserSetting_PersonalAccessToken) error
AddUserPersonalAccessToken adds a new PAT for the user.
func (*Store) AddUserRefreshToken ¶
func (s *Store) AddUserRefreshToken(ctx context.Context, userID int32, token *storepb.RefreshTokensUserSetting_RefreshToken) error
AddUserRefreshToken adds a new refresh token for the user.
func (*Store) AddUserWebhook ¶
func (s *Store) AddUserWebhook(ctx context.Context, userID int32, webhook *storepb.WebhooksUserSetting_Webhook) error
AddUserWebhook adds a new webhook for the user.
func (*Store) AppendEvent ¶ added in v0.94.0
func (*Store) AppendEventsBatch ¶ added in v0.94.0
func (*Store) AppendUserInput ¶ added in v0.94.0
func (*Store) ArchiveInactiveBranches ¶ added in v0.94.0
func (*Store) BM25Search ¶
func (s *Store) BM25Search(ctx context.Context, opts *BM25SearchOptions) ([]*BM25Result, error)
BM25Search performs full-text search using BM25 ranking.
func (*Store) CompleteBlock ¶ added in v0.94.0
func (*Store) CreateAIBlock ¶ added in v0.94.0
AIBlock methods (Unified Block Model). AIMessage functions removed: ALL IN Block!
func (*Store) CreateAIBlockWithRound ¶ added in v0.94.0
func (*Store) CreateAIConversation ¶
func (s *Store) CreateAIConversation(ctx context.Context, create *AIConversation) (*AIConversation, error)
func (*Store) CreateActivity ¶
func (*Store) CreateAttachment ¶
func (s *Store) CreateAttachment(ctx context.Context, create *Attachment) (*Attachment, error)
func (*Store) CreateEpisodicMemory ¶
func (s *Store) CreateEpisodicMemory(ctx context.Context, create *EpisodicMemory) (*EpisodicMemory, error)
func (*Store) CreateIdentityProvider ¶
func (s *Store) CreateIdentityProvider(ctx context.Context, create *storepb.IdentityProvider) (*storepb.IdentityProvider, error)
func (*Store) CreateInbox ¶
CreateInbox creates a new inbox notification.
func (*Store) CreateMemo ¶
func (*Store) CreateSchedule ¶
CreateSchedule creates a new schedule.
func (*Store) CreateUser ¶
func (*Store) DeleteAIBlock ¶ added in v0.94.0
func (*Store) DeleteAIConversation ¶
func (s *Store) DeleteAIConversation(ctx context.Context, delete *DeleteAIConversation) error
func (*Store) DeleteAgentMetrics ¶
func (s *Store) DeleteAgentMetrics(ctx context.Context, delete *DeleteAgentMetrics) error
func (*Store) DeleteAttachment ¶
func (s *Store) DeleteAttachment(ctx context.Context, delete *DeleteAttachment) error
func (*Store) DeleteBranch ¶ added in v0.94.0
func (*Store) DeleteEpisodicMemory ¶
func (s *Store) DeleteEpisodicMemory(ctx context.Context, delete *DeleteEpisodicMemory) error
func (*Store) DeleteIdentityProvider ¶
func (s *Store) DeleteIdentityProvider(ctx context.Context, delete *DeleteIdentityProvider) error
func (*Store) DeleteInbox ¶
func (s *Store) DeleteInbox(ctx context.Context, delete *DeleteInbox) error
DeleteInbox permanently removes an inbox item.
func (*Store) DeleteMemo ¶
func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error
func (*Store) DeleteMemoEmbedding ¶
DeleteMemoEmbedding deletes a memo embedding.
func (*Store) DeleteMemoRelation ¶
func (s *Store) DeleteMemoRelation(ctx context.Context, delete *DeleteMemoRelation) error
func (*Store) DeleteReaction ¶
func (s *Store) DeleteReaction(ctx context.Context, delete *DeleteReaction) error
func (*Store) DeleteSchedule ¶
func (s *Store) DeleteSchedule(ctx context.Context, delete *DeleteSchedule) error
DeleteSchedule deletes a schedule.
func (*Store) DeleteToolMetrics ¶
func (s *Store) DeleteToolMetrics(ctx context.Context, delete *DeleteToolMetrics) error
func (*Store) DeleteUser ¶
func (s *Store) DeleteUser(ctx context.Context, delete *DeleteUser) error
func (*Store) FindMemosWithoutEmbedding ¶
func (s *Store) FindMemosWithoutEmbedding(ctx context.Context, find *FindMemosWithoutEmbedding) ([]*Memo, error)
FindMemosWithoutEmbedding finds memos that don't have embeddings for the specified model.
func (*Store) GetAIBlock ¶ added in v0.94.0
func (*Store) GetActivePath ¶ added in v0.94.0
func (*Store) GetActivity ¶
func (*Store) GetAttachment ¶
func (s *Store) GetAttachment(ctx context.Context, find *FindAttachment) (*Attachment, error)
func (*Store) GetCurrentSchemaVersion ¶
func (*Store) GetIdentityProvider ¶
func (s *Store) GetIdentityProvider(ctx context.Context, find *FindIdentityProvider) (*storepb.IdentityProvider, error)
func (*Store) GetInstanceBasicSetting ¶
func (*Store) GetInstanceGeneralSetting ¶
func (*Store) GetInstanceMemoRelatedSetting ¶
func (*Store) GetInstanceSetting ¶
func (s *Store) GetInstanceSetting(ctx context.Context, find *FindInstanceSetting) (*storepb.InstanceSetting, error)
func (*Store) GetInstanceStorageSetting ¶
func (*Store) GetLatestAIBlock ¶ added in v0.94.0
func (*Store) GetMemoEmbedding ¶
func (s *Store) GetMemoEmbedding(ctx context.Context, memoID int32, model string) (*MemoEmbedding, error)
GetMemoEmbedding gets the embedding of a specific memo.
func (*Store) GetPendingAIBlocks ¶ added in v0.94.0
func (*Store) GetReaction ¶
func (*Store) GetSchedule ¶
GetSchedule gets a schedule by uid.
func (*Store) GetUserByPATHash ¶
GetUserByPATHash finds a user by PAT hash.
func (*Store) GetUserPersonalAccessTokens ¶
func (s *Store) GetUserPersonalAccessTokens(ctx context.Context, userID int32) ([]*storepb.PersonalAccessTokensUserSetting_PersonalAccessToken, error)
GetUserPersonalAccessTokens returns the PATs of the user.
func (*Store) GetUserPreferences ¶
func (s *Store) GetUserPreferences(ctx context.Context, find *FindUserPreferences) (*UserPreferences, error)
func (*Store) GetUserRefreshTokenByID ¶
func (s *Store) GetUserRefreshTokenByID(ctx context.Context, userID int32, tokenID string) (*storepb.RefreshTokensUserSetting_RefreshToken, error)
GetUserRefreshTokenByID returns a specific refresh token.
func (*Store) GetUserRefreshTokens ¶
func (s *Store) GetUserRefreshTokens(ctx context.Context, userID int32) ([]*storepb.RefreshTokensUserSetting_RefreshToken, error)
GetUserRefreshTokens returns the refresh tokens of the user.
func (*Store) GetUserSetting ¶
func (s *Store) GetUserSetting(ctx context.Context, find *FindUserSetting) (*storepb.UserSetting, error)
func (*Store) GetUserWebhooks ¶
func (s *Store) GetUserWebhooks(ctx context.Context, userID int32) ([]*storepb.WebhooksUserSetting_Webhook, error)
GetUserWebhooks returns the webhooks of the user.
func (*Store) ListAIBlocks ¶ added in v0.94.0
func (*Store) ListAIConversations ¶
func (s *Store) ListAIConversations(ctx context.Context, find *FindAIConversation) ([]*AIConversation, error)
func (*Store) ListActiveUserIDs ¶
func (*Store) ListActivities ¶
func (*Store) ListAgentMetrics ¶
func (s *Store) ListAgentMetrics(ctx context.Context, find *FindAgentMetrics) ([]*AgentMetrics, error)
func (*Store) ListAttachments ¶
func (s *Store) ListAttachments(ctx context.Context, find *FindAttachment) ([]*Attachment, error)
func (*Store) ListChildBlocks ¶ added in v0.94.0
func (*Store) ListEpisodicMemories ¶
func (s *Store) ListEpisodicMemories(ctx context.Context, find *FindEpisodicMemory) ([]*EpisodicMemory, error)
func (*Store) ListIdentityProviders ¶
func (s *Store) ListIdentityProviders(ctx context.Context, find *FindIdentityProvider) ([]*storepb.IdentityProvider, error)
func (*Store) ListInboxes ¶
ListInboxes retrieves inbox items matching the filter criteria.
func (*Store) ListInstanceSettings ¶
func (s *Store) ListInstanceSettings(ctx context.Context, find *FindInstanceSetting) ([]*storepb.InstanceSetting, error)
func (*Store) ListMemoEmbeddings ¶
func (s *Store) ListMemoEmbeddings(ctx context.Context, find *FindMemoEmbedding) ([]*MemoEmbedding, error)
ListMemoEmbeddings lists memo embeddings.
func (*Store) ListMemoRelations ¶
func (s *Store) ListMemoRelations(ctx context.Context, find *FindMemoRelation) ([]*MemoRelation, error)
func (*Store) ListReactions ¶
func (*Store) ListSchedules ¶
ListSchedules lists schedules with filter.
func (*Store) ListToolMetrics ¶
func (s *Store) ListToolMetrics(ctx context.Context, find *FindToolMetrics) ([]*ToolMetrics, error)
func (*Store) ListUserSettings ¶
func (s *Store) ListUserSettings(ctx context.Context, find *FindUserSetting) ([]*storepb.UserSetting, error)
func (*Store) Migrate ¶
Migrate migrates the database schema to the latest version. It checks the current schema version and applies any necessary migrations. It also seeds the database with initial data if in demo mode.
func (*Store) RemoveUserPersonalAccessToken ¶
func (s *Store) RemoveUserPersonalAccessToken(ctx context.Context, userID int32, tokenID string) error
RemoveUserPersonalAccessToken removes a PAT from the user.
func (*Store) RemoveUserRefreshToken ¶
RemoveUserRefreshToken removes a refresh token from the user.
func (*Store) RemoveUserWebhook ¶
RemoveUserWebhook removes the webhook of the user.
func (*Store) UpdateAIBlock ¶ added in v0.94.0
func (*Store) UpdateAIBlockStatus ¶ added in v0.94.0
func (*Store) UpdateAIConversation ¶
func (s *Store) UpdateAIConversation(ctx context.Context, update *UpdateAIConversation) (*AIConversation, error)
func (*Store) UpdateAttachment ¶
func (s *Store) UpdateAttachment(ctx context.Context, update *UpdateAttachment) error
func (*Store) UpdateIdentityProvider ¶
func (s *Store) UpdateIdentityProvider(ctx context.Context, update *UpdateIdentityProviderV1) (*storepb.IdentityProvider, error)
func (*Store) UpdateInbox ¶
UpdateInbox updates an existing inbox item.
func (*Store) UpdateMemo ¶
func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error
func (*Store) UpdatePATLastUsed ¶
func (s *Store) UpdatePATLastUsed(ctx context.Context, userID int32, tokenID string, lastUsed *timestamppb.Timestamp) error
UpdatePATLastUsed updates the last_used_at timestamp of a PAT.
func (*Store) UpdateSchedule ¶
func (s *Store) UpdateSchedule(ctx context.Context, update *UpdateSchedule) error
UpdateSchedule updates a schedule.
func (*Store) UpdateUser ¶
func (*Store) UpdateUserWebhook ¶
func (s *Store) UpdateUserWebhook(ctx context.Context, userID int32, webhook *storepb.WebhooksUserSetting_Webhook) error
UpdateUserWebhook updates an existing webhook for the user.
func (*Store) UpsertAgentMetrics ¶
func (s *Store) UpsertAgentMetrics(ctx context.Context, upsert *UpsertAgentMetrics) (*AgentMetrics, error)
func (*Store) UpsertInstanceSetting ¶
func (s *Store) UpsertInstanceSetting(ctx context.Context, upsert *storepb.InstanceSetting) (*storepb.InstanceSetting, error)
func (*Store) UpsertMemoEmbedding ¶
func (s *Store) UpsertMemoEmbedding(ctx context.Context, embedding *MemoEmbedding) (*MemoEmbedding, error)
UpsertMemoEmbedding inserts or updates a memo embedding.
func (*Store) UpsertMemoRelation ¶
func (s *Store) UpsertMemoRelation(ctx context.Context, create *MemoRelation) (*MemoRelation, error)
func (*Store) UpsertReaction ¶
func (*Store) UpsertToolMetrics ¶
func (s *Store) UpsertToolMetrics(ctx context.Context, upsert *UpsertToolMetrics) (*ToolMetrics, error)
func (*Store) UpsertUserPreferences ¶
func (s *Store) UpsertUserPreferences(ctx context.Context, upsert *UpsertUserPreferences) (*UserPreferences, error)
func (*Store) UpsertUserSetting ¶
func (s *Store) UpsertUserSetting(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error)
func (*Store) VectorSearch ¶
func (s *Store) VectorSearch(ctx context.Context, opts *VectorSearchOptions) ([]*MemoWithScore, error)
VectorSearch performs vector similarity search.
type TitleSource ¶ added in v0.94.0
type TitleSource string
TitleSource indicates how the conversation title was created. - "default": System default (e.g., "New Chat" or truncated first message) - "auto": AI-generated title based on conversation content - "user": User-provided title (manual edit)
const ( TitleSourceDefault TitleSource = "default" TitleSourceAuto TitleSource = "auto" TitleSourceUser TitleSource = "user" )
type TokenUsage ¶ added in v0.94.0
type TokenUsage struct {
PromptTokens int32 `json:"prompt_tokens"`
CompletionTokens int32 `json:"completion_tokens"`
TotalTokens int32 `json:"total_tokens"`
CacheReadTokens int32 `json:"cache_read_tokens,omitempty"`
CacheWriteTokens int32 `json:"cache_write_tokens,omitempty"`
}
TokenUsage represents detailed token usage for a single block or LLM call. Added for P1-A006: LLM Stats Collection for Normal Mode.
type ToolMetrics ¶
type ToolMetrics struct {
HourBucket time.Time
ToolName string
ID int64
CallCount int64
SuccessCount int64
LatencySumMs int64
}
ToolMetrics represents hourly aggregated metrics for a tool.
type UpdateAIBlock ¶ added in v0.94.0
type UpdateAIBlock struct {
ID int64
UserInputs *[]UserInput // Replace user inputs
AssistantContent *string // Update AI response
EventStream *[]BlockEvent // Replace event stream
SessionStats *SessionStats // Update session stats
CCSessionID *string // Update CC session ID
Status *AIBlockStatus // Update status
Metadata map[string]any // Merge metadata
UpdatedTs *int64 // Update timestamp
// New fields for block extensions
TokenUsage *TokenUsage // Update token usage
CostEstimate *int64 // Update cost estimate
ModelVersion *string // Update model version
UserFeedback *string // Update user feedback
RegenerationCount *int32 // Update regeneration count
ErrorMessage *string // Update error message
ArchivedAt *int64 // Archive this block
}
UpdateAIBlock represents the input for updating a block
type UpdateAIConversation ¶
type UpdateAttachment ¶
type UpdateIdentityProvider ¶
type UpdateIdentityProviderV1 ¶
type UpdateIdentityProviderV1 struct {
Name *string
IdentifierFilter *string
Config *storepb.IdentityProviderConfig
ID int32
Type storepb.IdentityProvider_Type
}
type UpdateInbox ¶
type UpdateInbox struct {
Status InboxStatus
ID int32
}
UpdateInbox contains fields that can be updated for an inbox item.
type UpdateMemo ¶
type UpdateMemo struct {
UID *string
CreatedTs *int64
UpdatedTs *int64
RowStatus *RowStatus
Content *string
Visibility *Visibility
Pinned *bool
Payload *storepb.MemoPayload
ID int32
}
type UpdateSchedule ¶
type UpdateSchedule struct {
StartTs *int64
EndTs *int64
CreatedTs *int64
UpdatedTs *int64
RowStatus *RowStatus
Title *string
UID *string
Description *string
Payload *string
Location *string
AllDay *bool
Timezone *string
RecurrenceRule *string
RecurrenceEndTs *int64
Reminders *string
ID int32
}
UpdateSchedule is the update request for schedule.
type UpdateUser ¶
type UpsertAgentMetrics ¶
type UpsertAgentMetrics struct {
HourBucket time.Time
AgentType string
Errors string
RequestCount int64
SuccessCount int64
LatencySumMs int64
LatencyP50Ms int32
LatencyP95Ms int32
}
UpsertAgentMetrics specifies the data for upserting agent metrics.
type UpsertPromptVersionMetrics ¶
type UpsertPromptVersionMetrics struct {
HourBucket time.Time
AgentType string
PromptVersion string
RequestCount int64
SuccessCount int64
AvgLatencyMs int64
}
UpsertPromptVersionMetrics specifies the data for upserting prompt version metrics.
type UpsertRouterWeight ¶ added in v0.94.0
UpsertRouterWeight specifies data for upserting router weights.
type UpsertToolMetrics ¶
type UpsertToolMetrics struct {
HourBucket time.Time
ToolName string
CallCount int64
SuccessCount int64
LatencySumMs int64
}
UpsertToolMetrics specifies the data for upserting tool metrics.
type UpsertUserPreferences ¶
UpsertUserPreferences specifies the data for upserting user preferences.
type UserCostSettings ¶ added in v0.93.0
type UserCostSettings struct {
UserID int32
DailyBudgetUSD *float64 // NULL = unlimited
PerSessionThresholdUSD float64
AlertEnabled bool
AlertEmail bool
AlertInApp bool
BudgetResetAt *time.Time
}
UserCostSettings represents user-specific cost control settings. UserCostSettings 表示用户特定的成本控制设置。
type UserInput ¶ added in v0.94.0
type UserInput struct {
Content string `json:"content"`
Timestamp int64 `json:"timestamp"`
Metadata map[string]any `json:"metadata,omitempty"`
}
UserInput represents a single user input in the block
type UserPreferences ¶
UserPreferences represents user preferences for AI personalization.
type UserSetting ¶
type UserSetting struct {
Value string
UserID int32
Key storepb.UserSetting_Key
}
type VectorSearchOptions ¶
type VectorSearchOptions struct {
Vector []float32
Limit int
UserID int32
CreatedAfter int64 // Optional: only search memos created after this timestamp
MaxCandidates int // Optional: maximum candidates to fetch (default: limit * 10)
}
VectorSearchOptions represents the options for vector search.
func (*VectorSearchOptions) Validate ¶
func (o *VectorSearchOptions) Validate() error
Validate validates the VectorSearchOptions.
type Visibility ¶
type Visibility string
Visibility is the type of a visibility.
const ( // Public is the PUBLIC visibility. Public Visibility = "PUBLIC" // Protected is the PROTECTED visibility. Protected Visibility = "PROTECTED" // Private is the PRIVATE visibility. Private Visibility = "PRIVATE" )
func (Visibility) String ¶
func (v Visibility) String() string
Source Files
¶
- activity.go
- agent_metrics.go
- agent_stats.go
- ai_block.go
- ai_conversation.go
- attachment.go
- cache.go
- common.go
- driver.go
- episodic_memory.go
- idp.go
- inbox.go
- instance_setting.go
- memo.go
- memo_embedding.go
- memo_relation.go
- migrator.go
- reaction.go
- router_feedback.go
- schedule.go
- store.go
- user.go
- user_preferences.go
- user_setting.go