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
- func AdminLoginLink(db *sql.DB, owner string) http.HandlerFunc
- func BatchEvents(db *sql.DB) http.HandlerFunc
- func ClaimDeviceRequest(db *sql.DB, ownerUserID string) http.HandlerFunc
- func Context(db *sql.DB, owner string) http.HandlerFunc
- func CreateDeviceRequest(db *sql.DB) http.HandlerFunc
- func CreateInvite(db *sql.DB, owner string) http.HandlerFunc
- func CreateLoginLink(db *sql.DB, owner string) http.HandlerFunc
- func DecideDeviceRequest(db *sql.DB, approve bool) http.HandlerFunc
- func DownloadsHandler(dir string) http.HandlerFunc
- func EnsureProject(db *sql.DB, ownerUserID string) http.HandlerFunc
- func EnsureSession(db *sql.DB, ownerUserID string) http.HandlerFunc
- func EventHandler(db *sql.DB, owner string) http.HandlerFunc
- func EvidenceAssertionHandler(db *sql.DB, owner string) http.HandlerFunc
- func EvidenceHandler(db *sql.DB, owner string) http.HandlerFunc
- func GetSessionHandler(db *sql.DB, owner string) http.HandlerFunc
- func Health(db *sql.DB, latest func() string) http.HandlerFunc
- func ListDeviceRequests(db *sql.DB) http.HandlerFunc
- func ListDevices(db *sql.DB, ownerUserID string) http.HandlerFunc
- func ListInvites(db *sql.DB, owner string) http.HandlerFunc
- func ListProjects(db *sql.DB, ownerUserID string) http.HandlerFunc
- func ListSessionsHandler(db *sql.DB, owner string) http.HandlerFunc
- func ListUISessions(db *sql.DB, owner string) http.HandlerFunc
- func LoginPath(code string) string
- func MemoriesHandler(db *sql.DB, owner string) http.HandlerFunc
- func MemoryHandler(db *sql.DB, owner string) http.HandlerFunc
- func OverviewHandler(db *sql.DB, owner string, emb *embedding.Service) http.HandlerFunc
- func ProjectHandler(db *sql.DB, owner string) http.HandlerFunc
- func QueryDevices(ctx context.Context, db *sql.DB, ownerUserID string) ([]model.Device, error)
- func RegisterDevice(db *sql.DB, ownerUserID string) http.HandlerFunc
- func RevokeDeviceHandler(db *sql.DB, owner string) http.HandlerFunc
- func RevokeInvite(db *sql.DB, owner string) http.HandlerFunc
- func RevokeUISessionHandler(db *sql.DB, owner string) http.HandlerFunc
- func RotateMCPToken(db *sql.DB) http.HandlerFunc
- func Search(db *sql.DB, ownerUserID string) http.HandlerFunc
- func ServeDownload(dir string) http.HandlerFunc
- func SessionEventsHandler(db *sql.DB, owner string) http.HandlerFunc
- func SessionInfoHandler() http.HandlerFunc
- func SyncReportHandler(db *sql.DB) http.HandlerFunc
- func SyncStatus(db *sql.DB) http.HandlerFunc
- func UILogin(db *sql.DB) http.HandlerFunc
- func UILogout(db *sql.DB) http.HandlerFunc
- type ClientDownload
- type CreatedInvite
- type DeviceStatus
- type EventDetail
- type Invite
- type LoginLinkResponse
- type MCPTokenResponse
- type MemoryDetail
- type Overview
- type ProjectDetail
- type ProjectLocation
- type SessionDetail
- type SourceInfo
- type UISessionInfo
- type UnfinishedSession
Constants ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
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.
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 ¶
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.