memoryclient

package
v1.0.0-alpha.42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: MIT Imports: 17 Imported by: 0

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

View Source
const (
	EnvDaemonURL = "OTTERSD_URL"
	//nolint:gosec // G101: env var name, not a credential value
	EnvAgentToken = "OTTERS_AGENT_TOKEN"
)

Variables

View Source
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 New

func New(cfg Config) *Client

func (*Client) AppendAssistantStub

func (c *Client) AppendAssistantStub(ctx context.Context, sessionID string) (int64, error)

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) Close

func (c *Client) Close() error

func (*Client) DeleteSession

func (c *Client) DeleteSession(ctx context.Context, sessionID string) error

DeleteSession removes one session's messages. Idempotent.

func (*Client) GetMessages

func (c *Client) GetMessages(ctx context.Context, sessionID string) ([]fantasy.Message, error)

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

func (c *Client) LastAssistantMessage(ctx context.Context, sessionID string) (StoredMessage, error)

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

func (c *Client) ListMessages(ctx context.Context, sessionID string) ([]StoredMessage, error)

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

func (c *Client) SaveMessage(ctx context.Context, sessionID, role, content string) (int64, error)

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.

func (*Client) UpdateBranches

func (c *Client) UpdateBranches(
	ctx context.Context, id int64, content, branchesJSON string, active int,
) error

UpdateBranches rewrites one assistant row's content + branches + active. Mirrors memory.Store.UpdateBranches.

type Config

type Config struct {
	URL   string
	Token string
}

func FromEnv

func FromEnv() (Config, bool)

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 NewFake

func NewFake() *Fake

NewFake returns a fresh in-memory store ready to use.

func (*Fake) AppendAssistantStub

func (f *Fake) AppendAssistantStub(ctx context.Context, sessionID string) (int64, error)

func (*Fake) CountMessages

func (f *Fake) CountMessages(_ context.Context, sessionID string) (int, error)

CountMessages mirrors the test helper that used to live on memory.Store. Counts rows for sessionID regardless of role.

func (*Fake) DeleteSession

func (f *Fake) DeleteSession(_ context.Context, sessionID string) error

func (*Fake) GetMessages

func (f *Fake) GetMessages(_ context.Context, sessionID string) ([]fantasy.Message, error)

func (*Fake) LastAssistantMessage

func (f *Fake) LastAssistantMessage(_ context.Context, sessionID string) (StoredMessage, error)

func (*Fake) ListMessages

func (f *Fake) ListMessages(_ context.Context, sessionID string) ([]StoredMessage, error)

func (*Fake) ListSessions

func (f *Fake) ListSessions(_ context.Context) ([]SessionInfo, error)

func (*Fake) ReplaceMessages

func (f *Fake) ReplaceMessages(_ context.Context, sessionID string, msgs []StoredMessage) error

func (*Fake) SaveMessage

func (f *Fake) SaveMessage(_ context.Context, sessionID, role, content string) (int64, error)

func (*Fake) UpdateBranches

func (f *Fake) UpdateBranches(_ context.Context, id int64, content, branchesJSON string, active int) error

type SessionInfo

type SessionInfo struct {
	ID           string
	MessageCount int
	LastActive   time.Time
}

SessionInfo mirrors pkg/memory.SessionInfo.

type StoredMessage

type StoredMessage struct {
	ID           int64
	Role         string
	Content      string
	BranchesJSON string
	ActiveBranch int
	CreatedAt    time.Time
}

StoredMessage mirrors pkg/memory.StoredMessage — the timestamp- bearing shape returned by ListMessages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL