Documentation
¶
Overview ¶
Package model defines the core data structures shared across the server.
Index ¶
- Constants
- func BuildVersion() string
- func FormatTime(t time.Time) string
- func IsRelease(v string) bool
- func ReleaseDownloadURL(v, asset string) string
- type BatchEventsRequest
- type BatchEventsResponse
- type Device
- type DeviceRequestClaim
- type DeviceRequestCreate
- type DeviceRequestCreated
- type DeviceRequestStatus
- type EnsureProjectRequest
- type EnsureProjectResponse
- type EnsureSessionRequest
- type EnsureSessionResponse
- type Event
- type EventPage
- type EventReceipt
- type EventRecord
- type LocationInput
- type Project
- type ProjectLocation
- type RegisterDeviceRequest
- type RegisterDeviceResponse
- type SearchRequest
- type SearchResponse
- type SearchResult
- type Session
- type SessionInfo
- type SyncReport
- type SyncReportResponse
- type SyncStatusResponse
- type User
Constants ¶
const ( ReceiptAccepted = "accepted" ReceiptDuplicate = "duplicate" ReceiptError = "error" )
Receipt statuses.
const ( // CodeInvalid: the event itself is malformed; retrying cannot succeed. CodeInvalid = "invalid" // CodeUnknownSession: session_id does not exist for this device/project. // The client should re-resolve the session and retry. CodeUnknownSession = "unknown_session" // CodeInternal: a server-side failure; retry later. CodeInternal = "internal" )
Receipt error codes tell the client whether retrying can help.
const ( ScopeCurrentProject = "current_project" ScopeSelectedProjects = "selected_projects" ScopeAllProjects = "all_projects" )
Search scopes.
const HighlightMarks = "marks"
HighlightMarks requests private-use snippet markers.
const ReleaseRepo = "chux0519/memspace"
ReleaseRepo is the GitHub repository that publishes release binaries.
const TimeFormat = "2006-01-02T15:04:05.000000000Z"
TimeFormat is how timestamps are stored in SQLite: UTC with a fixed-width fraction, so that text comparison and ORDER BY match chronological order. (time.RFC3339Nano trims trailing zeros and would sort "…:00Z" after "…:00.1Z".) time.Parse(time.RFC3339Nano, …) reads it back.
Variables ¶
This section is empty.
Functions ¶
func BuildVersion ¶
func BuildVersion() string
BuildVersion describes the running binary: its module version, or the VCS revision for development builds.
func IsRelease ¶
IsRelease reports whether v is a tagged release version (v1.2.3 or v1.2.3-rc.1), not a development build or a Go pseudo-version.
func ReleaseDownloadURL ¶
ReleaseDownloadURL is where a release asset is published: for version v when it is a release, else the latest release.
Types ¶
type BatchEventsRequest ¶
type BatchEventsRequest struct {
ProjectID string `json:"project_id"`
Events []Event `json:"events"`
}
BatchEventsRequest is the body for POST /api/v1/events/batch.
type BatchEventsResponse ¶
type BatchEventsResponse struct {
Accepted int `json:"accepted"`
Duplicate int `json:"duplicate"`
Errors int `json:"errors"`
Receipts []EventReceipt `json:"receipts"`
}
BatchEventsResponse summarizes a batch upload.
type Device ¶
type Device struct {
DeviceID string `json:"device_id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Platform string `json:"platform"`
CreatedAt time.Time `json:"created_at"`
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
RevokedAt *time.Time `json:"revoked_at,omitempty"`
}
Device represents a registered client machine.
type DeviceRequestClaim ¶
type DeviceRequestClaim struct {
ClaimToken string `json:"claim_token"`
}
DeviceRequestClaim is the body for POST /api/v1/device-requests/claim.
type DeviceRequestCreate ¶
type DeviceRequestCreate struct {
Name string `json:"name"`
Platform string `json:"platform"`
ClientVersion string `json:"client_version,omitempty"`
}
DeviceRequestCreate is the body for POST /api/v1/device-requests: ask to join without an invite, pending an administrator's approval.
type DeviceRequestCreated ¶
type DeviceRequestCreated struct {
RequestID string `json:"request_id"`
UserCode string `json:"user_code"`
ClaimToken string `json:"claim_token"`
ExpiresAt time.Time `json:"expires_at"`
}
DeviceRequestCreated is the response: the code to show for comparison and the claim secret only this device holds.
type DeviceRequestStatus ¶
type DeviceRequestStatus struct {
Status string `json:"status"`
ExpiresAt time.Time `json:"expires_at"`
DeviceID string `json:"device_id,omitempty"`
Name string `json:"name,omitempty"`
Token string `json:"token,omitempty"`
}
DeviceRequestStatus answers a claim: pending, approved (with the device token, returned once), denied, expired or claimed.
type EnsureProjectRequest ¶
type EnsureProjectRequest struct {
Name string `json:"name"`
CanonicalGitIdentity *string `json:"canonical_git_identity,omitempty"`
}
EnsureProjectRequest lets a device ensure a project exists before posting events.
type EnsureProjectResponse ¶
type EnsureProjectResponse struct {
ProjectID string `json:"project_id"`
Created bool `json:"created"`
}
EnsureProjectResponse returns the existing or newly created project id.
type EnsureSessionRequest ¶
type EnsureSessionRequest struct {
ProjectID string `json:"project_id"`
AgentType string `json:"agent_type"`
NativeSessionID string `json:"native_session_id"`
StartedAt *time.Time `json:"started_at,omitempty"`
Location *LocationInput `json:"location,omitempty"`
}
EnsureSessionRequest lets a device ensure a session exists before posting events. Idempotent by (device, agent_type, native_session_id).
type EnsureSessionResponse ¶
type EnsureSessionResponse struct {
SessionID string `json:"session_id"`
ProjectID string `json:"project_id"`
LocationID *string `json:"location_id,omitempty"`
Created bool `json:"created"`
}
EnsureSessionResponse returns the existing or newly created session id. ProjectID is the project the session belongs to, which wins over the requested one if the session already existed.
type Event ¶
type Event struct {
EventID string `json:"event_id"`
SessionID *string `json:"session_id,omitempty"`
ProjectID string `json:"project_id"`
DeviceID string `json:"device_id"`
EventType string `json:"event_type"`
OccurredAt time.Time `json:"occurred_at"`
ReceivedAt time.Time `json:"received_at"`
SequenceNumber *int64 `json:"sequence_number,omitempty"`
PayloadJSON string `json:"payload_json"`
ContentHash *string `json:"content_hash,omitempty"`
SchemaVersion int `json:"schema_version"`
}
Event is the append-only raw record of something an agent did.
type EventPage ¶
type EventPage struct {
Events []EventRecord `json:"events"`
// Next is the cursor for the following page; empty at the end.
Next string `json:"next,omitempty"`
}
EventPage is a page of a session's event timeline.
type EventReceipt ¶
type EventReceipt struct {
EventID string `json:"event_id"`
Status string `json:"status"` // accepted | duplicate | error
Code string `json:"code,omitempty"`
Error string `json:"error,omitempty"`
}
EventReceipt is the per-event result of a batch upload.
type EventRecord ¶
type EventRecord struct {
EventID string `json:"event_id"`
EventType string `json:"event_type"`
OccurredAt time.Time `json:"occurred_at"`
Payload json.RawMessage `json:"payload"`
}
EventRecord is one stored event, for timelines.
type LocationInput ¶
type LocationInput struct {
AbsolutePath string `json:"absolute_path"`
GitBranch *string `json:"git_branch,omitempty"`
GitHead *string `json:"git_head,omitempty"`
}
LocationInput describes where on the calling device the project lives.
type Project ¶
type Project struct {
ProjectID string `json:"project_id"`
UserID string `json:"user_id"`
Name string `json:"name"`
CanonicalGitIdentity *string `json:"canonical_git_identity,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Project is identity independent of absolute path.
type ProjectLocation ¶
type ProjectLocation struct {
LocationID string `json:"location_id"`
ProjectID string `json:"project_id"`
DeviceID string `json:"device_id"`
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 records where a project lives on a specific device.
type RegisterDeviceRequest ¶
type RegisterDeviceRequest struct {
Name string `json:"name"`
Platform string `json:"platform"`
InviteCode string `json:"invite_code"`
}
RegisterDeviceRequest is the body for POST /api/v1/devices.
type RegisterDeviceResponse ¶
type RegisterDeviceResponse struct {
DeviceID string `json:"device_id"`
Token string `json:"token"` // plaintext, shown only at registration
}
RegisterDeviceResponse returns the plain token once; the client must store it.
type SearchRequest ¶
type SearchRequest struct {
Query string `json:"query"`
Scope string `json:"scope,omitempty"`
ProjectID string `json:"project_id,omitempty"`
GitIdentity string `json:"git_identity,omitempty"`
ProjectName string `json:"project_name,omitempty"`
ProjectIDs []string `json:"project_ids,omitempty"`
SessionID string `json:"session_id,omitempty"`
Kinds []string `json:"kinds,omitempty"`
AgentTypes []string `json:"agent_types,omitempty"`
DeviceIDs []string `json:"device_ids,omitempty"`
Since *time.Time `json:"since,omitempty"`
Until *time.Time `json:"until,omitempty"`
Limit int `json:"limit,omitempty"`
// Mode: "" (hybrid when semantic search is available), "keyword" or
// "semantic".
Mode string `json:"mode,omitempty"`
// Highlight selects snippet match markers: "" for [brackets], or
// HighlightMarks for U+E000…U+E001 (used by the web UI).
Highlight string `json:"highlight,omitempty"`
}
SearchRequest is the body of POST /api/v1/search.
With scope current_project (the default), the project is identified by project_id, or by git_identity / project_name as a client derives them from its working directory.
type SearchResponse ¶
type SearchResponse struct {
Results []SearchResult `json:"results"`
Scope string `json:"scope"`
ProjectIDs []string `json:"project_ids,omitempty"`
Note string `json:"note,omitempty"`
}
SearchResponse lists hits, best first.
type SearchResult ¶
type SearchResult struct {
DocID int64 `json:"doc_id"`
Kind string `json:"kind"`
RefID string `json:"ref_id"`
ProjectID string `json:"project_id"`
ProjectName string `json:"project_name"`
SessionID string `json:"session_id,omitempty"`
AgentType string `json:"agent_type,omitempty"`
DeviceID string `json:"device_id,omitempty"`
DeviceName string `json:"device_name,omitempty"`
OccurredAt time.Time `json:"occurred_at"`
Title string `json:"title,omitempty"`
Snippet string `json:"snippet"`
Score float64 `json:"score"`
// Match is "all" when every query term matched, "any" for partial matches.
Match string `json:"match"`
// MatchedTerms of TotalTerms query terms occur in the document.
MatchedTerms int `json:"matched_terms"`
TotalTerms int `json:"total_terms"`
// Similarity is the cosine similarity to the query when the document
// was found by semantic search (0 otherwise).
Similarity float64 `json:"similarity,omitempty"`
}
SearchResult is one hit, traceable to its source (kind + ref_id).
type Session ¶
type Session struct {
SessionID string `json:"session_id"`
ProjectID string `json:"project_id"`
LocationID *string `json:"location_id,omitempty"`
DeviceID string `json:"device_id"`
AgentType string `json:"agent_type"`
NativeSessionID string `json:"native_session_id"`
StartedAt time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at,omitempty"`
Status string `json:"status"`
}
Session is one agent run scoped to a project + device + location.
type SessionInfo ¶
type SessionInfo struct {
SessionID string `json:"session_id"`
ProjectID string `json:"project_id"`
ProjectName string `json:"project_name"`
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
AgentType string `json:"agent_type"`
NativeSessionID string `json:"native_session_id"`
Status string `json:"status"`
StartedAt time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at,omitempty"`
LastEventAt *time.Time `json:"last_event_at,omitempty"`
EventCount int `json:"event_count"`
Objective string `json:"objective,omitempty"`
LatestRequest string `json:"latest_request,omitempty"`
}
SessionInfo describes a session for listings.
type SyncReport ¶
type SyncReport struct {
Pending int64 `json:"pending"`
Dead int64 `json:"dead"`
Dropped int64 `json:"dropped"`
OldestPending *time.Time `json:"oldest_pending_at,omitempty"`
ClientVersion string `json:"client_version,omitempty"`
// UpgradeTarget and UpgradeError describe a failed automatic upgrade
// to the server's version (empty when there is none).
UpgradeTarget string `json:"upgrade_target,omitempty"`
UpgradeError string `json:"upgrade_error,omitempty"`
}
SyncReport is what a client reports about its local spool after a sync (POST /api/v1/sync/report), so the server can show unsent backlogs.
type SyncReportResponse ¶ added in v0.1.3
type SyncReportResponse struct {
ServerVersion string `json:"server_version"`
}
SyncReportResponse answers a sync report. Servers before v0.1.3 answer 204 without a body.
type SyncStatusResponse ¶
type SyncStatusResponse struct {
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
EventsTotal int64 `json:"events_total"`
LastEventReceivedAt *time.Time `json:"last_event_received_at,omitempty"`
LastEventOccurredAt *time.Time `json:"last_event_occurred_at,omitempty"`
SessionsTotal int64 `json:"sessions_total"`
}
SyncStatusResponse is the server's view of the calling device's uploads.