client

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 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 client wraps the MemSpace server HTTP API for client-side use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStatus

func IsStatus(err error, status int) bool

IsStatus reports whether err is an HTTPError with the given status.

func PrivateHost

func PrivateHost(host string) bool

PrivateHost reports whether host is a loopback, private, link-local or CGNAT address, or a single-label / .local / .lan / .internal / .home.arpa name.

func Retryable

func Retryable(err error) bool

Retryable reports whether a failed request may succeed later unchanged: network failures, timeouts, 5xx, 429 and auth problems (the user can fix a revoked token without losing spooled events).

Types

type Client

type Client struct {
	ServerURL  string
	Token      string
	HTTPClient *http.Client
}

Client is an HTTP client for the MemSpace server.

func New

func New(serverURL, token string) *Client

New creates a Client. Token may be empty for unauthenticated calls.

func (*Client) BatchEvents

func (c *Client) BatchEvents(ctx context.Context, projectID string, events []model.Event) (*model.BatchEventsResponse, error)

BatchEvents uploads a batch of events for one project.

func (*Client) ClaimDevice

func (c *Client) ClaimDevice(ctx context.Context, claimToken string) (*model.DeviceRequestStatus, error)

ClaimDevice polls a device request. Status is "pending", "approved" (with the device token), "denied", "expired" (also when already claimed) or "unknown".

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, reqBody, respBody any) error

Do sends a JSON request to path and decodes the JSON response.

func (*Client) EmbeddingStatus

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

EmbeddingStatus returns the state of semantic search on the server.

func (*Client) EnsureProject

func (c *Client) EnsureProject(ctx context.Context, name, gitIdentity string) (string, error)

EnsureProject idempotently resolves a project by Git identity or name.

func (*Client) EnsureSession

EnsureSession idempotently resolves a session.

func (*Client) Health

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

func (*Client) Register

func (c *Client) Register(ctx context.Context, name, platform, invite string) (deviceID, token string, err error)

Register calls POST /api/v1/devices with a one-time invite and returns the device id and token.

func (*Client) ReportSync

func (c *Client) ReportSync(ctx context.Context, rep model.SyncReport) (string, error)

ReportSync sends the local spool state (POST /api/v1/sync/report) and returns the server's version ("" from servers that do not report it).

func (*Client) RequestDevice

func (c *Client) RequestDevice(ctx context.Context, name, platform, version string) (*model.DeviceRequestCreated, error)

RequestDevice asks to join without an invite; an administrator approves the request (POST /api/v1/device-requests).

func (*Client) RotateMCPToken

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

RotateMCPToken issues a new read-only MCP token for this device.

func (*Client) Search

Search runs a full-text search.

func (*Client) ServerVersion

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

Health calls GET /api/v1/health (no auth required). ServerVersion returns the version the server reports ("" for servers that predate reporting it).

func (*Client) SyncStatus

func (c *Client) SyncStatus(ctx context.Context) (*model.SyncStatusResponse, error)

SyncStatus returns the server's view of this device.

type EmbeddingStatus

type EmbeddingStatus struct {
	Enabled bool `json:"enabled"`
	Active  *struct {
		Model   string `json:"model"`
		Docs    int    `json:"docs_embedded"`
		Pending int    `json:"docs_pending"`
	} `json:"active_space"`
	Building *struct {
		Model   string `json:"model"`
		Docs    int    `json:"docs_embedded"`
		Pending int    `json:"docs_pending"`
	} `json:"building_space"`
	LastError string `json:"last_error"`
}

EmbeddingStatus describes the server's semantic index.

type HTTPError

type HTTPError struct {
	Status  int
	Message string
}

HTTPError is a non-2xx response from the server.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Jump to

Keyboard shortcuts

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