Documentation
¶
Index ¶
- Variables
- func SessionKeyFromContext(ctx context.Context) string
- func WithSessionKey(ctx context.Context, key string) context.Context
- type EntStore
- func (s *EntStore) AppendMessage(key string, msg Message) error
- func (s *EntStore) Client() *ent.Client
- func (s *EntStore) Close() error
- func (s *EntStore) CompactMessages(key string, upToIndex int, summary string) error
- func (s *EntStore) Create(session *Session) error
- func (s *EntStore) Delete(key string) error
- func (s *EntStore) Get(key string) (*Session, error)
- func (s *EntStore) GetChecksum(name string) ([]byte, error)
- func (s *EntStore) GetSalt(name string) ([]byte, error)
- func (s *EntStore) MigrateSecrets(ctx context.Context, reencryptFn func([]byte) ([]byte, error), ...) (err error)
- func (s *EntStore) SetChecksum(name string, checksum []byte) error
- func (s *EntStore) SetSalt(name string, salt []byte) error
- func (s *EntStore) Update(session *Session) error
- type Message
- type Session
- type Store
- type StoreOption
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SessionKeyFromContext ¶
SessionKeyFromContext extracts the session key from context.
Types ¶
type EntStore ¶
type EntStore struct {
// contains filtered or unexported fields
}
EntStore implements Store using entgo.io
func NewEntStore ¶
func NewEntStore(dbPath string, opts ...StoreOption) (*EntStore, error)
NewEntStore creates a new ent-backed session store
func NewEntStoreWithClient ¶
func NewEntStoreWithClient(client *ent.Client, opts ...StoreOption) *EntStore
NewEntStoreWithClient creates a new ent-backed session store using an existing ent.Client. This avoids opening a second database connection when the client is already available (e.g., from the bootstrap process). Schema migration is assumed to be already complete.
func (*EntStore) AppendMessage ¶
AppendMessage adds a message to session history
func (*EntStore) Close ¶
Close closes the ent client and underlying database connection. When the client was provided externally via NewEntStoreWithClient, only the ent client is closed; the raw DB connection is managed by the caller.
func (*EntStore) CompactMessages ¶
CompactMessages replaces messages up to (and including) upToIndex with a single summary message. This achieves compaction: the original messages are removed and replaced by a condensed version, preserving recent context.
func (*EntStore) GetChecksum ¶
GetChecksum retrieves the passphrase checksum by name
func (*EntStore) MigrateSecrets ¶
func (s *EntStore) MigrateSecrets(ctx context.Context, reencryptFn func([]byte) ([]byte, error), newSalt, newChecksum []byte) (err error)
MigrateSecrets performs the secret migration using callbacks to avoid import cycles. reencryptFn typically decrypts with old key and encrypts with new key.
func (*EntStore) SetChecksum ¶
SetChecksum stores the passphrase checksum by name
type Message ¶
type Message struct {
Role types.MessageRole `json:"role"` // "user", "assistant", "tool"
Content string `json:"content"`
Timestamp time.Time `json:"timestamp"`
ToolCalls []ToolCall `json:"toolCalls,omitempty"`
Author string `json:"author,omitempty"` // ADK agent name for multi-agent routing
}
Message represents a single message in conversation history
type Session ¶
type Session struct {
Key string `json:"key"`
AgentID string `json:"agentId,omitempty"`
ChannelType string `json:"channelType,omitempty"`
ChannelID string `json:"channelId,omitempty"`
History []Message `json:"history"`
Metadata map[string]string `json:"metadata,omitempty"`
Model string `json:"model,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Session represents a conversation session
type Store ¶
type Store interface {
// Create creates a new session
Create(session *Session) error
// Get retrieves a session by key
Get(key string) (*Session, error)
// Update updates an existing session
Update(session *Session) error
// Delete removes a session
Delete(key string) error
// AppendMessage adds a message to session history
AppendMessage(key string, msg Message) error
// Close closes the store
Close() error
// GetSalt retrieves the encryption salt for LocalCryptoProvider
GetSalt(name string) ([]byte, error)
// SetSalt stores the encryption salt for LocalCryptoProvider
SetSalt(name string, salt []byte) error
}
Store defines the interface for session storage
type StoreOption ¶
type StoreOption func(*EntStore)
StoreOption defines the functional option pattern for EntStore
func WithMaxHistoryTurns ¶
func WithMaxHistoryTurns(n int) StoreOption
WithMaxHistoryTurns limits the number of messages kept per session.
func WithPassphrase ¶
func WithPassphrase(passphrase string) StoreOption
WithPassphrase sets the encryption passphrase for the database.