httpclient

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpclient provides a memstore.Store implementation that talks to a memstored daemon over HTTP. It is the daemon-mode client for memstore-mcp and the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackfillFeedbackResult

type BackfillFeedbackResult struct {
	Sessions int `json:"sessions"`
	Rated    int `json:"rated"`
	Errors   int `json:"errors"`
}

BackfillFeedbackResult mirrors httpapi.BackfillResult.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements memstore.Store by calling the memstored HTTP API.

func New

func New(baseURL, apiKey string) *Client

New creates a client pointing at the given memstored base URL. If apiKey is non-empty, it is sent as Bearer token on every request.

func NewWithOptions

func NewWithOptions(baseURL, apiKey string, opts ClientOptions) (*Client, error)

NewWithOptions is New with TLS configuration applied. Returns an error if the TLS config in opts cannot be loaded (bad cert path, malformed PEM).

func (*Client) ActiveCount

func (c *Client) ActiveCount(ctx context.Context) (int64, error)

func (*Client) BackfillFeedback

func (c *Client) BackfillFeedback(ctx context.Context) (*BackfillFeedbackResult, error)

BackfillFeedback triggers a full backfill of fact feedback scores on the daemon.

func (*Client) Breakdown

func (c *Client) Breakdown(ctx context.Context) (memstore.FactBreakdown, error)

func (*Client) BySubject

func (c *Client) BySubject(ctx context.Context, subject string, onlyActive bool) ([]memstore.Fact, error)

func (*Client) Close

func (c *Client) Close() error

Close is a no-op for the HTTP client — there is no local resource to release.

func (*Client) Confirm

func (c *Client) Confirm(ctx context.Context, id int64) error

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, id int64) error
func (c *Client) DeleteLink(ctx context.Context, linkID int64) error

func (*Client) EmbedFacts

func (c *Client) EmbedFacts(_ context.Context, _ int) (int, error)

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, content, subject string) (bool, error)

func (*Client) FactChunks

func (c *Client) FactChunks(_ context.Context, _ int64) ([]memstore.FactChunk, error)

func (*Client) Get

func (c *Client) Get(ctx context.Context, id int64) (*memstore.Fact, error)
func (c *Client) GetLink(ctx context.Context, linkID int64) (*memstore.Link, error)
func (c *Client) GetLinks(ctx context.Context, factID int64, direction memstore.LinkDirection, linkTypes ...string) ([]memstore.Link, error)

func (*Client) GetPendingHints

func (c *Client) GetPendingHints(ctx context.Context, sessionID, cwd string) ([]memstore.ContextHint, error)

GetPendingHints returns unconsumed context hints matching sessionID or cwd (OR semantics). Either may be empty; pass both for maximum coverage.

func (*Client) History

func (c *Client) History(ctx context.Context, id int64, subject string) ([]memstore.HistoryEntry, error)

func (*Client) Insert

func (c *Client) Insert(ctx context.Context, f memstore.Fact) (int64, error)

func (*Client) InsertBatch

func (c *Client) InsertBatch(ctx context.Context, facts []memstore.Fact) error

func (*Client) LinkFacts

func (c *Client) LinkFacts(ctx context.Context, sourceID, targetID int64, linkType string, bidirectional bool, label string, metadata map[string]any) (int64, error)

func (*Client) List

func (c *Client) List(ctx context.Context, opts memstore.QueryOpts) ([]memstore.Fact, error)

func (*Client) ListSubsystems

func (c *Client) ListSubsystems(ctx context.Context, subject string) ([]string, error)

func (*Client) MarkEmbedFailed

func (c *Client) MarkEmbedFailed(_ context.Context, _ int64, _ string) error

func (*Client) MarkHintConsumed

func (c *Client) MarkHintConsumed(ctx context.Context, hintID int64) error

MarkHintConsumed marks a context hint as consumed so it is not re-injected.

func (*Client) NeedingEmbedding

func (c *Client) NeedingEmbedding(_ context.Context, _ int) ([]memstore.Fact, error)

func (*Client) PostHint

func (c *Client) PostHint(ctx context.Context, hint memstore.ContextHint) error

PostHint stores a context hint on the daemon. Used by the Stop hook to emit a "store your decisions" nudge after a session crosses a turn threshold without storing anything.

func (*Client) PostSessionHook

func (c *Client) PostSessionHook(ctx context.Context, rawPayload json.RawMessage) error

PostSessionHook forwards a raw Claude Code Stop hook payload to the daemon.

func (*Client) PostSessionTranscript

func (c *Client) PostSessionTranscript(ctx context.Context, sessionID, cwd, persona, content string) error

PostSessionTranscript forwards a JSONL session transcript to the daemon. persona is the OS-level user who ran the session; the daemon uses it as the subject for user/preference-scoped session summaries. Pass an empty string to let the daemon fall back to its routing default.

func (*Client) RecordFeedback

func (c *Client) RecordFeedback(ctx context.Context, fb memstore.ContextFeedback) error

RecordFeedback posts context feedback to the daemon. Implements the minimal subset of memstore.SessionStore needed by memstore-mcp for memory_rate_context.

func (*Client) RecordInjection

func (c *Client) RecordInjection(ctx context.Context, sessionID, refID, refType string, rank int) error

RecordInjection records that a ref was injected into a session (dedup log). rank is the 0-based position of the item in the candidate list; -1 if unknown.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, opts memstore.SearchOpts) ([]memstore.SearchResult, error)

func (*Client) SearchBatch

func (c *Client) SearchBatch(ctx context.Context, queries []string, opts memstore.SearchOpts) ([][]memstore.SearchResult, error)

func (*Client) SearchFTS

func (c *Client) SearchFTS(ctx context.Context, query string, opts memstore.SearchOpts) ([]memstore.SearchResult, error)

func (*Client) SetEmbedding

func (c *Client) SetEmbedding(_ context.Context, _ int64, _ []float32) error

func (*Client) SetFactVectors

func (c *Client) SetFactVectors(_ context.Context, _ int64, _ memstore.FactVectors) error

func (*Client) Supersede

func (c *Client) Supersede(ctx context.Context, oldID, newID int64) error

func (*Client) SyncDocuments

func (c *Client) SyncDocuments(ctx context.Context, repoURL string, entries []DocSyncEntry) (*DocSyncResult, error)

SyncDocuments posts the manifest for one repo identity (repoURL "" = loose files) and returns the delta. Orphaned documents are deleted server-side.

func (*Client) Touch

func (c *Client) Touch(ctx context.Context, ids []int64) error
func (c *Client) UpdateLink(ctx context.Context, linkID int64, label string, metadata map[string]any) error

func (*Client) UpdateMetadata

func (c *Client) UpdateMetadata(ctx context.Context, id int64, patch map[string]any) error

func (*Client) UploadDocument

func (c *Client) UploadDocument(ctx context.Context, up DocUpload) (*DocUploadResult, error)

UploadDocument ships one file. The daemon hashes, verifies, chunks, and stores; a hash mismatch or unroutable file comes back as an error.

func (*Client) WhoAmI

func (c *Client) WhoAmI(ctx context.Context) (memstore.WhoAmIResponse, error)

WhoAmI reports what the client's credential may do, as computed by the daemon. Callers should read the Allows field rather than Scopes: the implication rules live server-side precisely so a client does not reimplement them.

A daemon predating the endpoint returns 404, which surfaces as an error. Callers that use this to shape optional behaviour should treat any error as "unknown" and fall back to their configured default, not as "no permissions" -- a network blip must not silently strip capability.

type ClientOptions

type ClientOptions struct {
	TLSCAFile         string
	TLSClientCertFile string
	TLSClientKeyFile  string
}

ClientOptions configures TLS behavior for outbound requests to memstored.

TLSCAFile is added to the system trust store (not a replacement). Use it to trust a self-signed memstored cert without modifying the OS root store.

TLSClientCertFile / TLSClientKeyFile are presented during the TLS handshake when memstored is configured with --tls-client-ca-file (mTLS). Both must be set together or neither.

func ClientOptionsFromConfig

func ClientOptionsFromConfig(cfg memstore.AppConfig) ClientOptions

ClientOptionsFromConfig pulls client-side TLS knobs out of an AppConfig.

func (ClientOptions) HasTLSConfig

func (o ClientOptions) HasTLSConfig() bool

HasTLSConfig reports whether any TLS-related field is set.

type DocSkip

type DocSkip struct {
	Path   string `json:"path"`
	Reason string `json:"reason"`
}

DocSkip is one refused manifest entry with the daemon's reason.

type DocSyncEntry

type DocSyncEntry struct {
	Path   string `json:"path"`
	SHA256 string `json:"sha256"` // hex
	Size   int64  `json:"size"`
}

DocSyncEntry is one manifest line: a file the client can see.

type DocSyncResult

type DocSyncResult struct {
	Need      []string  `json:"need"`
	Skip      []DocSkip `json:"skip"`
	Orphaned  []string  `json:"orphaned"`
	Unchanged int       `json:"unchanged"`
}

DocSyncResult is the daemon's manifest delta.

type DocUpload

type DocUpload struct {
	RepoURL string
	Commit  string
	Path    string
	Content []byte
	SHA256  string // hex of Content
	Mtime   *time.Time
	Dirty   bool
}

DocUpload is one file's bytes plus the client-asserted provenance.

type DocUploadResult

type DocUploadResult struct {
	ID       int64  `json:"id"`
	Chunks   int    `json:"chunks"`
	Strategy string `json:"strategy"`
}

DocUploadResult reports what the daemon stored.

type HTTPError

type HTTPError struct {
	Code    int
	Message string
}

HTTPError represents an error response from the daemon.

func (*HTTPError) Error

func (e *HTTPError) Error() string

func (*HTTPError) Unwrap

func (e *HTTPError) Unwrap() error

Unwrap maps a 404 onto memstore.ErrNotFound so errors.Is works the same against the daemon as it does in-process. The MCP server runs over this client in the deployed configuration, and it routes a miss and a store failure to different channels (#165); without this the daemon collapses that distinction at the network boundary.

type HTTPGenerator

type HTTPGenerator struct {
	// contains filtered or unexported fields
}

HTTPGenerator implements memstore.Generator and memstore.JSONGenerator by calling the memstored /v1/generate endpoints. This keeps Ollama access server-side so clients don't need direct Ollama connectivity.

func NewHTTPGenerator

func NewHTTPGenerator(baseURL, apiKey string) *HTTPGenerator

NewHTTPGenerator creates a generator that talks to memstored.

func NewHTTPGeneratorWithOptions

func NewHTTPGeneratorWithOptions(baseURL, apiKey string, opts ClientOptions) (*HTTPGenerator, error)

NewHTTPGeneratorWithOptions is NewHTTPGenerator with TLS configuration.

func (*HTTPGenerator) Generate

func (g *HTTPGenerator) Generate(ctx context.Context, prompt string) (string, error)

func (*HTTPGenerator) GenerateJSON

func (g *HTTPGenerator) GenerateJSON(ctx context.Context, prompt string) (string, error)

func (*HTTPGenerator) Model

func (g *HTTPGenerator) Model() string

Model returns "remote" since the actual model is determined server-side.

Jump to

Keyboard shortcuts

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