Documentation
¶
Overview ¶
Package platform assembles a Lagrange server: Postgres, the directory, the relay executor in a2a-go cluster mode, the tunnel endpoint, the API and the web app, all on one HTTP handler.
Routes:
/a/{handle}/.well-known/agent-card.json the address's agent card (also at /a/{handle})
/a/{handle}/rpc A2A JSON-RPC for the address
/a/{handle}/... A2A HTTP+JSON (REST) for the address
/t/{handle}/... raw HTTP to an agent whose tunnel exposes it
/tunnel agents connect here (WebSocket)
/registry/agents registry-compatible search of addresses
/api/... the web app's API (session cookie)
/healthz liveness
/ the web app
Index ¶
- Constants
- type AddressView
- type AuthMethods
- type Config
- type Conversation
- type Delivery
- type InputView
- type InviteView
- type OAuthProfile
- type OAuthProvider
- type Platform
- type ProfileView
- type ProviderView
- type Run
- type RunDetail
- type SessionView
- type TaskView
- type Viewer
- type ViewerWorkspace
- type WaitPolicy
- type WaitView
- type Webhook
Constants ¶
const ( // SignupInvite lets only invited people join (the default). SignupInvite = "invite" // SignupOpen lets anyone create an account. SignupOpen = "open" )
Signup modes (Config.Signup).
const SessionCookie = "lagrange_session"
SessionCookie holds a person's web session.
const WorkspaceHeader = "Lagrange-Workspace"
WorkspaceHeader names the workspace a request acts in (its slug). The event stream, which can't set headers, takes ?workspace= instead. Without either, a request acts in the caller's oldest workspace.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressView ¶
type AddressView struct {
*directory.Address
Card *a2a.AgentCard `json:"card"`
CardURL string `json:"cardUrl"`
Online bool `json:"online"`
// External addresses belong to another workspace: they show because they talked to
// this one.
External bool `json:"external,omitempty"`
Stats mailbox.Stats `json:"stats"`
Sessions []SessionView `json:"sessions"`
}
AddressView is an address as the web app sees it.
type AuthMethods ¶
type AuthMethods struct {
// Signup is "open" (anyone) or "invite" (invited people only).
Signup string `json:"signup"`
// Email: the server sends email, so login links, resets and verification work.
Email bool `json:"email"`
Providers []ProviderView `json:"providers"`
}
AuthMethods is how people can sign in on this server.
type Config ¶
type Config struct {
// DatabaseURL is the Postgres connection URL.
DatabaseURL string
// PublicURL is how clients reach this server, for example https://lagrange.example.com.
// Agent cards and tunnel commands use it.
PublicURL string
// Admin creates the first user on start, unless a user with this email exists.
AdminEmail, AdminPassword, AdminName, AdminHandle string
// WorkerID names this replica in the work queue (default: hostname).
WorkerID string
// Web is the built web app (index.html at the root). Nil serves a placeholder page.
Web fs.FS
// AllowPrivatePush lets push notifications go to private and loopback addresses.
// Only for local development and tests.
AllowPrivatePush bool
// Dev enables development-only endpoints, such as POST /api/dev/reset.
Dev bool
// DevSeed is a command (split on spaces, no shell) that seeds a dev server: it runs
// from start to Close, and "reset to seed" restarts it with LAGRANGE_SEED=1 after
// emptying the server. It gets LAGRANGE_SERVER, LAGRANGE_ADMIN_EMAIL and
// LAGRANGE_ADMIN_PASSWORD. Needs Dev.
DevSeed string
// Queue tunes the work queue; zero values are the defaults.
Queue pg.WorkQueueConfig
// WaitTick is how often the team's wait policy (reminders, escalations, cancels) is
// applied (default 30s).
WaitTick time.Duration
// WebhookTick is how often webhook events are fanned out and sent (default 1s).
WebhookTick time.Duration
// WebhookRetryBase is the first webhook retry delay (default 10s).
WebhookRetryBase time.Duration
// EventPoll is how often subscribers poll for task events (default 100ms).
EventPoll time.Duration
// Email sends notifications by email (notify.ParseSMTP). Nil: no email; Slack still works.
// Without email, signups aren't verified and login links and password resets are off.
Email notify.Email
// Signup is SignupInvite (default: only invited people join) or SignupOpen.
Signup string
// OAuth providers people can log in with (GitHubProvider, GoogleProvider).
OAuth []*OAuthProvider
// TrustProxy: the server runs behind a reverse proxy, so the client address is the
// last X-Forwarded-For entry (for rate limits).
TrustProxy bool
// TelegramAPIBase replaces https://api.telegram.org for every bot. Tests only.
TelegramAPIBase string
// TelegramTick is how often Telegram follows the activity log (default 1s), and
// TelegramPoll the bots' long-poll timeout (default 50s).
TelegramTick, TelegramPoll time.Duration
// AuthRateLimit is how many login, signup and link requests a client may make per
// minute (default 30; negative: no limit).
AuthRateLimit int
Logger *slog.Logger
}
Config configures a server.
type Conversation ¶
type Conversation struct {
A string `json:"a"`
B string `json:"b"`
Tasks int `json:"tasks"`
Messages int `json:"messages"`
Waiting int `json:"waiting"`
LastAt time.Time `json:"lastAt"`
// Last is the latest thing said, and LastFrom who said it.
Last string `json:"last"`
LastFrom string `json:"lastFrom"`
}
Conversation sums up what two addresses said to each other. A and B are sorted.
type Delivery ¶
type Delivery struct {
ID int64 `json:"id"`
EventID string `json:"eventId"`
Type string `json:"type"`
Status string `json:"status"`
Attempts int `json:"attempts"`
LastStatus *int `json:"lastStatus,omitempty"`
LastError string `json:"lastError,omitempty"`
NextAt *time.Time `json:"nextAt,omitempty"`
CreatedAt time.Time `json:"createdAt"`
DeliveredAt *time.Time `json:"deliveredAt,omitempty"`
Payload json.RawMessage `json:"payload"`
}
Delivery is one event sent (or being sent) to a webhook.
type InputView ¶
type InputView struct {
ID string `json:"id,omitempty"`
Schema json.RawMessage `json:"schema"`
}
InputView is a structured input request, for rendering a form.
type InviteView ¶
type InviteView struct {
Email string `json:"email"`
InvitedBy string `json:"invitedBy"`
Workspace string `json:"workspace"`
Role string `json:"role"`
// Existing means the email already has an account: they log in to join.
Existing bool `json:"existing"`
// Link is returned to whoever created the invitation, to share it themselves.
Link string `json:"link,omitempty"`
// Emailed says the server sent the link by email.
Emailed bool `json:"emailed"`
}
InviteView is an invitation as its link shows it.
type OAuthProfile ¶
type OAuthProfile struct {
// Subject is the provider's stable account ID.
Subject string
Email string
// EmailVerified: the provider vouches that the person owns Email.
EmailVerified bool
Name string
// Login is a username to suggest a handle from.
Login string
}
OAuthProfile is the account a person signed in with.
type OAuthProvider ¶
type OAuthProvider struct {
// Name is the provider's ID in URLs and in the identities table, such as "github".
Name string
// Label is what the login button says.
Label string
// Config holds the client and endpoints. The platform sets RedirectURL to
// <PublicURL>/api/auth/<Name>/callback.
Config oauth2.Config
// Profile reads the signed-in account with a client that carries its token.
Profile func(ctx context.Context, c *http.Client) (*OAuthProfile, error)
}
OAuthProvider logs people in with an account elsewhere (GitHub, Google).
func GitHubProvider ¶
func GitHubProvider(clientID, secret string) *OAuthProvider
GitHubProvider logs in with GitHub (an OAuth app with callback <PublicURL>/api/auth/github/callback).
func GoogleProvider ¶
func GoogleProvider(clientID, secret string) *OAuthProvider
GoogleProvider logs in with Google (an OAuth client with redirect URI <PublicURL>/api/auth/google/callback).
type Platform ¶
type Platform struct {
DB *pg.DB
Directory *directory.Directory
Links *relay.Links
Activity *activity.Log
Mailbox *mailbox.Mailbox
Tasks *pg.TaskStore
Relay *relay.Relay
Notify *notify.Notifier
Webhooks *webhook.Dispatcher
Telegram *telegram.Service
// A2A is the a2a-go request handler that serves every address.
A2A a2asrv.RequestHandler
Tunnels *tunnel.Server
// contains filtered or unexported fields
}
Platform is a running server.
func (*Platform) Card ¶
Card returns the platform's card for an address: the agent's own card with the platform's interfaces, or a card describing a person.
func (*Platform) Close ¶
func (p *Platform) Close()
Close stops taking work, hands running tasks back to the queue for another replica (or the next start), and closes the database.
func (*Platform) Reset ¶
Reset deletes every agent address (with its tokens) and all traffic: tasks, runs, activity, recorded HTTP, decision links. People, their logins and their settings stay. Connected tunnels are dropped. Only for development (Config.Dev).
func (*Platform) TunnelCommand ¶
TunnelCommand is the command that connects an agent to this server.
type ProfileView ¶
type ProfileView struct {
Handle string `json:"handle"`
Kind string `json:"kind"`
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
CardURL string `json:"cardUrl"`
Card *a2a.AgentCard `json:"card"`
Access string `json:"access"`
Online bool `json:"online"`
// Workspace is the name of an agent's workspace.
Workspace string `json:"workspace,omitempty"`
// Check is the card as served here, graded by the registry's linter.
Check lint.Report `json:"check"`
Viewer *Viewer `json:"viewer,omitempty"`
}
ProfileView is what anyone may see about an address, and for a signed-in visitor, how each of their workspaces stands with it.
type ProviderView ¶
ProviderView is an OAuth provider as the login page shows it.
type Run ¶
type Run struct {
// ID is the root task's ID, or msg-<seq> for a plain message exchange.
ID string `json:"id"`
// ContextID is the root task's A2A context: send into it (POST /api/send with
// contextId) to continue the conversation the run started.
ContextID string `json:"contextId,omitempty"`
Title string `json:"title"`
// Outcome is how the run ended, in words: the root task's last answer, or a plain
// message's reply. Empty while it runs.
Outcome string `json:"outcome,omitempty"`
Starter string `json:"starter"`
Recipient string `json:"recipient"`
// State is the root task's state ("TASK_STATE_COMPLETED"), or "message".
State string `json:"state"`
Waiting []string `json:"waiting"`
Participants []string `json:"participants"`
Tasks int `json:"tasks"`
Entries int `json:"entries"`
StartedAt time.Time `json:"startedAt"`
UpdatedAt time.Time `json:"updatedAt"`
// WaitingSince is when the longest-waiting task in the run started waiting.
WaitingSince *time.Time `json:"waitingSince,omitempty"`
// Archived runs are hidden from the list unless asked for (?archived=1).
Archived bool `json:"archived,omitempty"`
// Hidden counts the run's tasks inside other workspaces, which this one doesn't see.
Hidden int `json:"hidden,omitempty"`
// Cost is what the run's agents reported spending on it (usage entries, see
// lagrange/acp), in Currency. Zero when no agent reports usage.
Cost float64 `json:"cost,omitempty"`
Currency string `json:"currency,omitempty"`
// Report is the latest situation report the root task published (lagrange/report).
Report *report.Report `json:"report,omitempty"`
}
Run summarizes a run for the runs list.
type RunDetail ¶
type RunDetail struct {
Run *Run `json:"run"`
Tasks []*TaskView `json:"tasks"`
Entries []*activity.Entry `json:"entries"`
Exchanges []*activity.Exchange `json:"exchanges"`
}
RunDetail is everything recorded for a run.
type SessionView ¶
type SessionView struct {
ID string `json:"id"`
Capacity int `json:"capacity"`
Agent string `json:"agent"`
Expose bool `json:"expose"`
Connected time.Time `json:"connected"`
}
SessionView is a connected tunnel.
type TaskView ¶
type TaskView struct {
ID a2a.TaskID `json:"id"`
ContextID string `json:"contextId"`
State string `json:"state"`
Sender string `json:"sender"`
Recipient string `json:"recipient"`
ParentTaskID string `json:"parentTaskId,omitempty"`
Summary string `json:"summary"`
// Status is what the task's latest status says, in words (empty while it waits on a person).
Status string `json:"status,omitempty"`
Awaiting string `json:"awaiting,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Task *a2a.Task `json:"task,omitempty"`
Input *InputView `json:"input,omitempty"`
Challenge *credentials.Challenge `json:"challenge,omitempty"`
// Questions are the multiple-choice questions the task asks (lagrange/ask), and
// Approval says it asks to approve or reject; both only while it waits for input.
Questions []ask.Question `json:"questions,omitempty"`
Approval bool `json:"approval,omitempty"`
}
TaskView is a task as the web app sees it.
type Viewer ¶
type Viewer struct {
Handle string `json:"handle"`
Workspaces []ViewerWorkspace `json:"workspaces"`
}
Viewer is the signed-in visitor of a public page.
type ViewerWorkspace ¶
type ViewerWorkspace struct {
Slug string `json:"slug"`
Name string `json:"name"`
Role string `json:"role"`
Status string `json:"status"`
}
ViewerWorkspace is how one of the visitor's workspaces stands with the address: "in" (the address is part of it), a connection's status, or "" (no connection).
type WaitPolicy ¶
type WaitPolicy struct {
RemindAfter *int64 `json:"remindAfter"`
EscalateAfter *int64 `json:"escalateAfter"`
EscalateTo string `json:"escalateTo"`
CancelAfter *int64 `json:"cancelAfter"`
}
WaitPolicy is a workspace's rules for waiting tasks. Delays are in seconds; nil is off.
type WaitView ¶
type WaitView struct {
Task *TaskView `json:"task"`
RunID string `json:"runId"`
Who string `json:"who"`
Asker string `json:"asker"`
// Person is true when who is a person (reminders and escalations reach people only).
Person bool `json:"person"`
Since time.Time `json:"since"`
Reminders int `json:"reminders"`
RemindedAt *time.Time `json:"remindedAt,omitempty"`
EscalatedTo string `json:"escalatedTo,omitempty"`
EscalatedAt *time.Time `json:"escalatedAt,omitempty"`
// The policy's next steps for this wait, if any.
RemindAt *time.Time `json:"remindAt,omitempty"`
EscalateAt *time.Time `json:"escalateAt,omitempty"`
CancelAt *time.Time `json:"cancelAt,omitempty"`
}
WaitView is a waiting task on the waiting board.
type Webhook ¶
type Webhook struct {
ID int64 `json:"id"`
URL string `json:"url"`
Description string `json:"description"`
Events []string `json:"events"`
Active bool `json:"active"`
CreatedAt time.Time `json:"createdAt"`
// Delivered and Failed count the last day's deliveries.
Delivered int `json:"delivered"`
Failed int `json:"failed"`
Pending int `json:"pending"`
}
Webhook is an endpoint of a workspace, without its secret.