mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-13 14:16:08 +00:00
refactor(store): split AgentStore and SessionStore into focused sub-interfaces
AgentStore (27 methods) → 4 sub-interfaces: - AgentCRUDStore (10): core CRUD operations - AgentAccessStore (5): sharing and access control - AgentContextStore (8): agent-level and per-user context files - AgentProfileStore (4): user-agent profiles and instances SessionStore (33 methods) → 3 sub-interfaces: - SessionCoreStore (16): lifecycle, messages, history - SessionMetadataStore (13): tokens, timing, calibration - SessionListingStore (4): search, list, discovery Both use composed interfaces for backward compatibility (same pattern as TeamStore split). No implementation changes.
This commit is contained in:
1 parent
7382aceb7e
commit
25a123fef9
2 files changed
+44
-20
No files matched your search
@@ -311,8 +311,8 @@ type UserAgentOverrideData struct {
|
||||
Model string `json:"model,omitempty"`
|
||||
}
|
||||
|
||||
// AgentStore manages agents and access control.
|
||||
type AgentStore interface {
|
||||
// AgentCRUDStore manages core agent CRUD operations.
|
||||
type AgentCRUDStore interface {
|
||||
Create(ctx context.Context, agent *AgentData) error
|
||||
GetByKey(ctx context.Context, agentKey string) (*AgentData, error)
|
||||
GetByID(ctx context.Context, id uuid.UUID) (*AgentData, error)
|
||||
@@ -322,36 +322,45 @@ type AgentStore interface {
|
||||
Update(ctx context.Context, id uuid.UUID, updates map[string]any) error
|
||||
Delete(ctx context.Context, id uuid.UUID) error
|
||||
List(ctx context.Context, ownerID string) ([]AgentData, error)
|
||||
GetDefault(ctx context.Context) (*AgentData, error) // agent with is_default=true, or first available
|
||||
GetDefault(ctx context.Context) (*AgentData, error)
|
||||
}
|
||||
|
||||
// Access control
|
||||
// AgentAccessStore manages agent sharing and access control.
|
||||
type AgentAccessStore interface {
|
||||
ShareAgent(ctx context.Context, agentID uuid.UUID, userID, role, grantedBy string) error
|
||||
RevokeShare(ctx context.Context, agentID uuid.UUID, userID string) error
|
||||
ListShares(ctx context.Context, agentID uuid.UUID) ([]AgentShareData, error)
|
||||
CanAccess(ctx context.Context, agentID uuid.UUID, userID string) (bool, string, error) // (allowed, role, err)
|
||||
CanAccess(ctx context.Context, agentID uuid.UUID, userID string) (bool, string, error)
|
||||
ListAccessible(ctx context.Context, userID string) ([]AgentData, error)
|
||||
}
|
||||
|
||||
// Agent-level context files
|
||||
// AgentContextStore manages agent-level and per-user context files and overrides.
|
||||
type AgentContextStore interface {
|
||||
GetAgentContextFiles(ctx context.Context, agentID uuid.UUID) ([]AgentContextFileData, error)
|
||||
SetAgentContextFile(ctx context.Context, agentID uuid.UUID, fileName, content string) error
|
||||
|
||||
// Propagate agent-level file content to all existing user instances that have this file.
|
||||
// Returns count of updated user rows.
|
||||
PropagateContextFile(ctx context.Context, agentID uuid.UUID, fileName string) (int, error)
|
||||
|
||||
// Per-user context files + overrides
|
||||
GetUserContextFiles(ctx context.Context, agentID uuid.UUID, userID string) ([]UserContextFileData, error)
|
||||
SetUserContextFile(ctx context.Context, agentID uuid.UUID, userID, fileName, content string) error
|
||||
DeleteUserContextFile(ctx context.Context, agentID uuid.UUID, userID, fileName string) error
|
||||
GetUserOverride(ctx context.Context, agentID uuid.UUID, userID string) (*UserAgentOverrideData, error)
|
||||
SetUserOverride(ctx context.Context, override *UserAgentOverrideData) error
|
||||
}
|
||||
|
||||
// User-agent profiles + instances
|
||||
// AgentProfileStore manages user-agent profiles and instances.
|
||||
type AgentProfileStore interface {
|
||||
GetOrCreateUserProfile(ctx context.Context, agentID uuid.UUID, userID, workspace, channel string) (isNew bool, effectiveWorkspace string, err error)
|
||||
EnsureUserProfile(ctx context.Context, agentID uuid.UUID, userID string) error
|
||||
ListUserInstances(ctx context.Context, agentID uuid.UUID) ([]UserInstanceData, error)
|
||||
UpdateUserProfileMetadata(ctx context.Context, agentID uuid.UUID, userID string, metadata map[string]string) error
|
||||
}
|
||||
|
||||
// AgentStore composes all agent sub-interfaces for backward compatibility.
|
||||
// New code should depend on the specific sub-interface it needs.
|
||||
type AgentStore interface {
|
||||
AgentCRUDStore
|
||||
AgentAccessStore
|
||||
AgentContextStore
|
||||
AgentProfileStore
|
||||
}
|
||||
|
||||
// UserInstanceData represents a user instance for a predefined agent.
|
||||
|
||||
@@ -86,10 +86,9 @@ type SessionListRichResult struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// SessionStore manages conversation sessions.
|
||||
type SessionStore interface {
|
||||
// SessionCoreStore manages session lifecycle, messages, and history.
|
||||
type SessionCoreStore interface {
|
||||
GetOrCreate(ctx context.Context, key string) *SessionData
|
||||
// Get returns the session if it exists (cache or DB), nil otherwise. Never creates.
|
||||
Get(ctx context.Context, key string) *SessionData
|
||||
AddMessage(ctx context.Context, key string, msg providers.Message)
|
||||
GetHistory(ctx context.Context, key string) []providers.Message
|
||||
@@ -98,6 +97,15 @@ type SessionStore interface {
|
||||
GetLabel(ctx context.Context, key string) string
|
||||
SetLabel(ctx context.Context, key, label string)
|
||||
SetAgentInfo(ctx context.Context, key string, agentUUID uuid.UUID, userID string)
|
||||
TruncateHistory(ctx context.Context, key string, keepLast int)
|
||||
SetHistory(ctx context.Context, key string, msgs []providers.Message)
|
||||
Reset(ctx context.Context, key string)
|
||||
Delete(ctx context.Context, key string) error
|
||||
Save(ctx context.Context, key string) error
|
||||
}
|
||||
|
||||
// SessionMetadataStore manages session metadata, token tracking, and calibration.
|
||||
type SessionMetadataStore interface {
|
||||
UpdateMetadata(ctx context.Context, key, model, provider, channel string)
|
||||
AccumulateTokens(ctx context.Context, key string, input, output int64)
|
||||
IncrementCompaction(ctx context.Context, key string)
|
||||
@@ -111,13 +119,20 @@ type SessionStore interface {
|
||||
GetContextWindow(ctx context.Context, key string) int
|
||||
SetLastPromptTokens(ctx context.Context, key string, tokens, msgCount int)
|
||||
GetLastPromptTokens(ctx context.Context, key string) (tokens, msgCount int)
|
||||
TruncateHistory(ctx context.Context, key string, keepLast int)
|
||||
SetHistory(ctx context.Context, key string, msgs []providers.Message)
|
||||
Reset(ctx context.Context, key string)
|
||||
Delete(ctx context.Context, key string) error
|
||||
}
|
||||
|
||||
// SessionListingStore manages session listing, search, and discovery.
|
||||
type SessionListingStore interface {
|
||||
List(ctx context.Context, agentID string) []SessionInfo
|
||||
ListPaged(ctx context.Context, opts SessionListOpts) SessionListResult
|
||||
ListPagedRich(ctx context.Context, opts SessionListOpts) SessionListRichResult
|
||||
Save(ctx context.Context, key string) error
|
||||
LastUsedChannel(ctx context.Context, agentID string) (channel, chatID string)
|
||||
}
|
||||
|
||||
// SessionStore composes all session sub-interfaces for backward compatibility.
|
||||
// New code should depend on the specific sub-interface it needs.
|
||||
type SessionStore interface {
|
||||
SessionCoreStore
|
||||
SessionMetadataStore
|
||||
SessionListingStore
|
||||
}
|
||||
Reference in new issue
Block a user