Documentation
¶
Overview ¶
Package memoryclient is the runtime-side client to the daemon's agent_messages table. Mirrors the legacy pkg/memory.Store API surface so pkg/agent/service.go's chat path and pkg/memory's compactor can swap stores for the daemon client without changing call sites.
Like notesclient, the daemon scopes every call to the JWT's agent_ref, so empty ref on the wire makes the daemon read the agent identity from the bearer token.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) AppendAssistantStub(ctx context.Context, sessionID string) (int64, error)
- func (c *Client) Close() error
- func (c *Client) DeleteSession(ctx context.Context, sessionID string) error
- func (c *Client) GetMessages(ctx context.Context, sessionID string) ([]fantasy.Message, error)
- func (c *Client) LastAssistantMessage(ctx context.Context, sessionID string) (StoredMessage, error)
- func (c *Client) ListMessages(ctx context.Context, sessionID string) ([]StoredMessage, error)
- func (c *Client) ListSessions(ctx context.Context) ([]SessionInfo, error)
- func (c *Client) ReplaceMessages(ctx context.Context, sessionID string, msgs []StoredMessage) error
- func (c *Client) SaveMessage(ctx context.Context, sessionID, role, content string) (int64, error)
- func (c *Client) UpdateBranches(ctx context.Context, id int64, content, branchesJSON string, active int) error
- type Config
- type Fake
- func (f *Fake) AppendAssistantStub(ctx context.Context, sessionID string) (int64, error)
- func (f *Fake) CountMessages(_ context.Context, sessionID string) (int, error)
- func (f *Fake) DeleteSession(_ context.Context, sessionID string) error
- func (f *Fake) GetMessages(_ context.Context, sessionID string) ([]fantasy.Message, error)
- func (f *Fake) LastAssistantMessage(_ context.Context, sessionID string) (StoredMessage, error)
- func (f *Fake) ListMessages(_ context.Context, sessionID string) ([]StoredMessage, error)
- func (f *Fake) ListSessions(_ context.Context) ([]SessionInfo, error)
- func (f *Fake) ReplaceMessages(_ context.Context, sessionID string, msgs []StoredMessage) error
- func (f *Fake) SaveMessage(_ context.Context, sessionID, role, content string) (int64, error)
- func (f *Fake) UpdateBranches(_ context.Context, id int64, content, branchesJSON string, active int) error
- type SessionInfo
- type StoredMessage
Constants ¶
const ( EnvDaemonURL = "OTTERSD_URL" //nolint:gosec // G101: env var name, not a credential value EnvAgentToken = "OTTERS_AGENT_TOKEN" )
Variables ¶
var ErrNotConfigured = errors.New(
"memoryclient: OTTERSD_URL and OTTERS_AGENT_TOKEN must both be set",
)
ErrNotConfigured is returned when both env vars aren't set.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AppendAssistantStub ¶
AppendAssistantStub inserts a placeholder assistant row with content = "[]" and returns its id. The streaming chat loop holds onto the id and updates the row via UpdateBranches as deltas arrive.
func (*Client) DeleteSession ¶
DeleteSession removes one session's messages. Idempotent.
func (*Client) GetMessages ¶
GetMessages returns the LLM-facing history for sessionID, expanded into fantasy.Message form. Assistant rows carrying JSON parts are flattened into the (assistant, tool) sequence providers expect — same conversion as the legacy memory.Store.
func (*Client) LastAssistantMessage ¶
LastAssistantMessage returns the most recent assistant row for sessionID, or sql.ErrNoRows if none exists. The sentinel matches memory.Store's contract so callers can errors.Is against the same value.
func (*Client) ListMessages ¶
ListMessages returns the timestamped raw rows for sessionID, suitable for UI/diagnostic rendering. No part expansion.
func (*Client) ListSessions ¶
func (c *Client) ListSessions(ctx context.Context) ([]SessionInfo, error)
ListSessions enumerates the agent's sessions.
func (*Client) ReplaceMessages ¶
func (c *Client) ReplaceMessages( ctx context.Context, sessionID string, msgs []StoredMessage, ) error
ReplaceMessages atomically replaces every message for sessionID with the supplied list. Used by the compactor after slide/ summarize collapses the in-memory history.
Each message's Content is plain text for user/system rows and JSON-encoded parts for assistant rows; this client passes them through verbatim — the runtime decides the shape.
func (*Client) SaveMessage ¶
SaveMessage appends one message row at the tail. Mirrors memory.Store.SaveMessage. The returned id is the daemon's primary key; callers that don't need it (most do not) can discard it.
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is an in-memory implementation of the MemoryStore / CompactorStore surfaces used by the runtime's agent service and compactor. Test-only — production code uses *Client over gRPC to the daemon.
func (*Fake) AppendAssistantStub ¶
func (*Fake) CountMessages ¶
CountMessages mirrors the test helper that used to live on memory.Store. Counts rows for sessionID regardless of role.
func (*Fake) DeleteSession ¶
func (*Fake) GetMessages ¶
func (*Fake) LastAssistantMessage ¶
func (*Fake) ListMessages ¶
func (*Fake) ListSessions ¶
func (f *Fake) ListSessions(_ context.Context) ([]SessionInfo, error)
func (*Fake) ReplaceMessages ¶
func (*Fake) SaveMessage ¶
type SessionInfo ¶
SessionInfo mirrors pkg/memory.SessionInfo.