handler

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 27 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 handler — context packs and MCP token management.

Package handler — device requests: join by administrator approval instead of an invite.

Package handler — device registration and listing.

Package handler — event batch ingestion and project/session management.

Package handler — health check endpoint.

Package handler — session HTTP endpoints (logic lives in package sessions).

Package handler — read endpoints behind the web UI: overview, project detail, single events, memories and client sync reports.

Index

Constants

View Source
const (
	// MaxBatchEvents bounds events per batch request.
	MaxBatchEvents = 1000
	// MaxBatchBytes bounds the batch request body.
	MaxBatchBytes = 16 << 20
)

Variables

This section is empty.

Functions

func AdminLoginLink(db *sql.DB, owner string) http.HandlerFunc

AdminLoginLink handles POST /api/v1/admin/login-links: {"role"} — a link for signing in another browser.

func BatchEvents

func BatchEvents(db *sql.DB) http.HandlerFunc

BatchEvents handles POST /api/v1/events/batch — idempotent by event_id.

The whole batch is written in one transaction and the response (the ACK) is only sent after it commits, so an acknowledged event survives a server restart. Per-event problems are reported in receipts and do not fail the rest of the batch.

func ClaimDeviceRequest

func ClaimDeviceRequest(db *sql.DB, ownerUserID string) http.HandlerFunc

ClaimDeviceRequest handles POST /api/v1/device-requests/claim (no auth; the claim secret is the credential). Pending: 202. Approved: 200 with the device token, once. Denied: 403. Expired or already claimed: 410.

func Context

func Context(db *sql.DB, owner string) http.HandlerFunc

Context handles POST /api/v1/context: the bounded context agents receive at session start and on prompts.

func CreateDeviceRequest

func CreateDeviceRequest(db *sql.DB) http.HandlerFunc

CreateDeviceRequest handles POST /api/v1/device-requests (no auth). It only records a pending request; the claim secret in the response is the one credential that can later fetch the token.

func CreateInvite

func CreateInvite(db *sql.DB, owner string) http.HandlerFunc

CreateInvite handles POST /api/v1/admin/invites: {"note", "ttl_hours"}.

func CreateLoginLink(db *sql.DB, owner string) http.HandlerFunc

CreateLoginLink handles POST /api/v1/ui/login-links (device token).

func DecideDeviceRequest

func DecideDeviceRequest(db *sql.DB, approve bool) http.HandlerFunc

DecideDeviceRequest handles POST /api/v1/admin/device-requests/{id}/approve and /deny.

func DownloadsHandler

func DownloadsHandler(dir string) http.HandlerFunc

DownloadsHandler handles GET /api/v1/admin/downloads.

func EnsureProject

func EnsureProject(db *sql.DB, ownerUserID string) http.HandlerFunc

EnsureProject handles POST /api/v1/projects.

Idempotent: a request with a canonical Git identity matches an existing project with that identity; otherwise it matches by name among projects without one. Projects are never merged automatically.

func EnsureSession

func EnsureSession(db *sql.DB, ownerUserID string) http.HandlerFunc

EnsureSession handles POST /api/v1/sessions — idempotent by (device_id, agent_type, native_session_id). It also records the project location on this device when one is given.

func EventHandler

func EventHandler(db *sql.DB, owner string) http.HandlerFunc

EventHandler handles GET /api/v1/events/{id}.

func EvidenceAssertionHandler added in v0.1.4

func EvidenceAssertionHandler(db *sql.DB, owner string) http.HandlerFunc

func EvidenceHandler added in v0.1.4

func EvidenceHandler(db *sql.DB, owner string) http.HandlerFunc

EvidenceHandler exposes retained versions and direct relation state. It does not fetch remote articles or follow links into another project.

func GetSessionHandler

func GetSessionHandler(db *sql.DB, owner string) http.HandlerFunc

GetSessionHandler handles GET /api/v1/sessions/{id}.

func Health

func Health(db *sql.DB, latest func() string) http.HandlerFunc

Health handles GET /api/v1/health — no auth required. latest returns the latest release seen ("" when unknown).

func ListDeviceRequests

func ListDeviceRequests(db *sql.DB) http.HandlerFunc

ListDeviceRequests handles GET /api/v1/admin/device-requests.

func ListDevices

func ListDevices(db *sql.DB, ownerUserID string) http.HandlerFunc

ListDevices handles GET /api/v1/devices — requires auth.

func ListInvites

func ListInvites(db *sql.DB, owner string) http.HandlerFunc

ListInvites handles GET /api/v1/admin/invites.

func ListProjects

func ListProjects(db *sql.DB, ownerUserID string) http.HandlerFunc

ListProjects handles GET /api/v1/projects.

func ListSessionsHandler

func ListSessionsHandler(db *sql.DB, owner string) http.HandlerFunc

ListSessionsHandler handles GET /api/v1/sessions.

func ListUISessions

func ListUISessions(db *sql.DB, owner string) http.HandlerFunc

ListUISessions handles GET /api/v1/admin/ui-sessions (active ones).

func LoginPath

func LoginPath(code string) string

LoginPath is the UI route that redeems a login code.

func MemoriesHandler

func MemoriesHandler(db *sql.DB, owner string) http.HandlerFunc

MemoriesHandler handles GET /api/v1/memories.

func MemoryHandler

func MemoryHandler(db *sql.DB, owner string) http.HandlerFunc

MemoryHandler handles GET /api/v1/memories/{id}.

func OverviewHandler

func OverviewHandler(db *sql.DB, owner string, emb *embedding.Service) http.HandlerFunc

OverviewHandler handles GET /api/v1/overview.

func ProjectHandler

func ProjectHandler(db *sql.DB, owner string) http.HandlerFunc

ProjectHandler handles GET /api/v1/projects/{id}.

func QueryDevices

func QueryDevices(ctx context.Context, db *sql.DB, ownerUserID string) ([]model.Device, error)

QueryDevices lists the owner's devices, newest first.

func RegisterDevice

func RegisterDevice(db *sql.DB, ownerUserID string) http.HandlerFunc

RegisterDevice handles POST /api/v1/devices.

It needs no token, but it does need a single-use invite created by the server operator: the returned token grants full access to the owner's memory. The invite is consumed in the same transaction that creates the device, so one invite can never register two devices.

func RevokeDeviceHandler

func RevokeDeviceHandler(db *sql.DB, owner string) http.HandlerFunc

RevokeDeviceHandler handles POST /api/v1/admin/devices/{id}/revoke. The device's events stay; its token, MCP token and UI sessions stop working.

func RevokeInvite

func RevokeInvite(db *sql.DB, owner string) http.HandlerFunc

RevokeInvite handles DELETE /api/v1/admin/invites/{id} (unused invites).

func RevokeUISessionHandler

func RevokeUISessionHandler(db *sql.DB, owner string) http.HandlerFunc

RevokeUISessionHandler handles DELETE /api/v1/admin/ui-sessions/{id}.

func RotateMCPToken

func RotateMCPToken(db *sql.DB) http.HandlerFunc

RotateMCPToken handles POST /api/v1/devices/mcp-token.

func Search(db *sql.DB, ownerUserID string) http.HandlerFunc

Search handles POST /api/v1/search.

func ServeDownload

func ServeDownload(dir string) http.HandlerFunc

ServeDownload handles GET /downloads/{name}: client binaries, without authentication (they are the open-source client; a device still needs approval to register). Only names matching memspace-<os>-<arch> are served. A binary not in dir (or with no dir) redirects to the GitHub release of this server's version, so clients match the server; dir is a mirror for networks without access to GitHub.

func SessionEventsHandler

func SessionEventsHandler(db *sql.DB, owner string) http.HandlerFunc

SessionEventsHandler handles GET /api/v1/sessions/{id}/events, paginated by an opaque cursor over (occurred_at, event_id).

func SessionInfoHandler

func SessionInfoHandler() http.HandlerFunc

SessionInfoHandler handles GET /api/v1/ui/session: who is signed in.

func SyncReportHandler

func SyncReportHandler(db *sql.DB) http.HandlerFunc

SyncReportHandler handles POST /api/v1/sync/report.

func SyncStatus

func SyncStatus(db *sql.DB) http.HandlerFunc

SyncStatus handles GET /api/v1/sync/status for the calling device.

func UILogin

func UILogin(db *sql.DB) http.HandlerFunc

UILogin handles POST /api/v1/ui/login: {"code": "..."} → session cookie.

func UILogout

func UILogout(db *sql.DB) http.HandlerFunc

UILogout handles POST /api/v1/ui/logout.

Types

type ClientDownload

type ClientDownload struct {
	Name string `json:"name"` // e.g. memspace-darwin-arm64
	OS   string `json:"os"`
	Arch string `json:"arch"`
	Size int64  `json:"size"`
}

ClientDownload is a client binary offered for new devices.

func ListDownloads

func ListDownloads(dir string) []ClientDownload

ListDownloads lists client binaries in dir (empty when dir is "").

type CreatedInvite

type CreatedInvite struct {
	Code      string    `json:"code"`
	Note      string    `json:"note"`
	ExpiresAt time.Time `json:"expires_at"`
}

CreatedInvite is the response to creating an invite (code shown once).

type DeviceStatus

type DeviceStatus struct {
	model.Device
	EventsTotal   int64      `json:"events_total"`
	Events24h     int64      `json:"events_24h"`
	SpoolPending  *int64     `json:"spool_pending,omitempty"`
	SpoolDead     *int64     `json:"spool_dead,omitempty"`
	SpoolDropped  *int64     `json:"spool_dropped,omitempty"`
	OldestPending *time.Time `json:"spool_oldest_pending_at,omitempty"`
	ReportedAt    *time.Time `json:"spool_reported_at,omitempty"`
	ClientVersion string     `json:"client_version,omitempty"`
	UpgradeTarget string     `json:"upgrade_target,omitempty"`
	UpgradeError  string     `json:"upgrade_error,omitempty"`
}

DeviceStatus is a device with its upload activity and last spool report.

func DeviceStatuses

func DeviceStatuses(ctx context.Context, db *sql.DB, owner string) ([]DeviceStatus, error)

DeviceStatuses lists the owner's devices with activity and spool reports.

type EventDetail

type EventDetail struct {
	Event   model.EventRecord  `json:"event"`
	Session *model.SessionInfo `json:"session,omitempty"`
}

EventDetail is the body of GET /api/v1/events/{id}.

type Invite

type Invite struct {
	ID         string     `json:"id"` // hash of the code
	Note       string     `json:"note"`
	Status     string     `json:"status"` // pending | used | expired | revoked
	CreatedAt  time.Time  `json:"created_at"`
	ExpiresAt  time.Time  `json:"expires_at"`
	UsedAt     *time.Time `json:"used_at,omitempty"`
	DeviceID   string     `json:"device_id,omitempty"`
	DeviceName string     `json:"device_name,omitempty"`
}

Invite is an invite as listed to admins; the code itself is shown only when created.

type LoginLinkResponse

type LoginLinkResponse struct {
	Code      string    `json:"code"`
	Path      string    `json:"path"` // append to the server URL
	ExpiresAt time.Time `json:"expires_at"`
}

LoginLinkResponse carries a new login code (shown once).

type MCPTokenResponse

type MCPTokenResponse struct {
	Token string `json:"token"`
}

MCPTokenResponse returns a newly issued read-only MCP token (shown once).

type MemoryDetail

type MemoryDetail struct {
	Memory  memory.Memory `json:"memory"`
	Sources []SourceInfo  `json:"sources"`
}

MemoryDetail is the body of GET /api/v1/memories/{id}.

type Overview

type Overview struct {
	Counts struct {
		Projects   int64 `json:"projects"`
		Devices    int64 `json:"devices"`
		Sessions7d int64 `json:"sessions_7d"`
		Events24h  int64 `json:"events_24h"`
		EventsAll  int64 `json:"events_total"`
		Memories   int64 `json:"memories"`
	} `json:"counts"`
	Devices        []DeviceStatus      `json:"devices"`
	RecentSessions []model.SessionInfo `json:"recent_sessions"`
	Unfinished     []UnfinishedSession `json:"unfinished"`
	LatestMemories []memory.Memory     `json:"latest_memories"`
	Embedding      embedding.Status    `json:"embedding"`
	Jobs           map[string]int64    `json:"jobs"`
}

Overview is the body of GET /api/v1/overview.

type ProjectDetail

type ProjectDetail struct {
	Project   model.Project       `json:"project"`
	Locations []ProjectLocation   `json:"locations"`
	Sessions  []model.SessionInfo `json:"sessions"`
	Stats     struct {
		Sessions int64      `json:"sessions"`
		Events   int64      `json:"events"`
		Memories int64      `json:"memories"`
		LastAt   *time.Time `json:"last_activity_at,omitempty"`
	} `json:"stats"`
}

ProjectDetail is the body of GET /api/v1/projects/{id}.

type ProjectLocation

type ProjectLocation struct {
	DeviceID       string    `json:"device_id"`
	DeviceName     string    `json:"device_name"`
	AbsolutePath   string    `json:"absolute_path"`
	GitBranch      string    `json:"git_branch,omitempty"`
	GitHead        string    `json:"git_head,omitempty"`
	LastObservedAt time.Time `json:"last_observed_at"`
}

ProjectLocation is where a project lives on a device.

type SessionDetail

type SessionDetail struct {
	Session model.SessionInfo `json:"session"`
	Summary *summary.Summary  `json:"summary,omitempty"`
}

SessionDetail is the body of GET /api/v1/sessions/{id}.

type SourceInfo

type SourceInfo struct {
	memory.SourceRef
	EventType  string    `json:"event_type,omitempty"`
	OccurredAt time.Time `json:"occurred_at,omitempty"`
	Summary    string    `json:"summary,omitempty"`
	SessionID  string    `json:"session_id,omitempty"`
	Missing    bool      `json:"missing,omitempty"`
}

SourceInfo describes a memory's source for display.

type UISessionInfo

type UISessionInfo struct {
	ID         string    `json:"id"`
	Role       string    `json:"role"`
	UserAgent  string    `json:"user_agent"`
	DeviceName string    `json:"device_name,omitempty"`
	CreatedAt  time.Time `json:"created_at"`
	LastSeenAt time.Time `json:"last_seen_at"`
	ExpiresAt  time.Time `json:"expires_at"`
	Current    bool      `json:"current"`
}

UISessionInfo is a browser session as listed to admins.

type UnfinishedSession

type UnfinishedSession struct {
	Session    model.SessionInfo `json:"session"`
	Unresolved int               `json:"unresolved"`
	NextSteps  []string          `json:"next_steps"`
}

UnfinishedSession is recent work that did not end cleanly.

Jump to

Keyboard shortcuts

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