Documentation
¶
Overview ¶
Package activity is the platform's event log: every task created, every state change, artifact and plain message, every message waiting in a mailbox, and every tunnel that connects or drops. The web app builds its live graph, inbox and replay from it, and Stream serves it as Server-Sent Events.
Index ¶
- Constants
- type Entry
- type Exchange
- type Filter
- type Log
- func (l *Log) Add(ctx context.Context, e *Entry) error
- func (l *Log) AddExchange(ctx context.Context, x *Exchange) error
- func (l *Log) Between(ctx context.Context, a, b string, limit int) ([]*Entry, error)
- func (l *Log) Exchanges(ctx context.Context, taskIDs, contextIDs []string) ([]*Exchange, error)
- func (l *Log) Get(ctx context.Context, seq int64) (*Entry, error)
- func (l *Log) Handler(next http.Handler, base func(*http.Request) Exchange) http.Handler
- func (l *Log) Last(ctx context.Context) (int64, error)
- func (l *Log) LastUsage(ctx context.Context, recipient, contextID string) (*Entry, error)
- func (l *Log) Messages(ctx context.Context, handles []string, limit int) ([]*Entry, error)
- func (l *Log) Run(ctx context.Context, taskIDs []string) ([]*Entry, error)
- func (l *Log) Since(ctx context.Context, seq int64, limit int) ([]*Entry, error)
- func (l *Log) SinceFor(ctx context.Context, seq int64, limit int, handles []string) ([]*Entry, error)
- func (l *Log) Stream(w http.ResponseWriter, r *http.Request, keep Filter)
- func (l *Log) Task(ctx context.Context, taskID string) ([]*Entry, error)
- func (l *Log) Transport(rt http.RoundTripper, base Exchange) http.RoundTripper
Constants ¶
const ( // KindTask is a task state change; the first one for a task is its creation. KindTask = "task" // KindArtifact is an artifact (or a chunk of one) produced by a task. KindArtifact = "artifact" // KindMessage is a plain message answer: an exchange that created no task. KindMessage = "message" // KindInput is a message that continues a task: an answer to its question, or more // input from the sender. KindInput = "input" // KindQueued means a task is waiting in the recipient's mailbox (agent offline or busy). KindQueued = "queued" // KindDelivered means a queued task reached the agent. KindDelivered = "delivered" // KindPresence reports an agent's tunnel sessions and capacity. KindPresence = "presence" // KindAddress means an address was created, changed or removed. KindAddress = "address" // KindUsage is an agent's usage report for its session (tokens in context and // cost so far, cumulative over the context): {"usage": {"used", "size", "cost"}}. KindUsage = "usage" )
Kinds of entry.
const ( // DirIn is a call to an address, at /a/<handle>. DirIn = "in" // DirOut is the relay's call to the agent behind an address. DirOut = "out" // DirPush is a push notification or webhook delivered through /t/<handle>. DirPush = "push" )
Directions of an exchange.
const MaxBody = 64 << 10
MaxBody caps each stored request and response body.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Seq int64 `json:"seq"`
At time.Time `json:"at"`
Kind string `json:"kind"`
TaskID string `json:"taskId,omitempty"`
ParentTaskID string `json:"parentTaskId,omitempty"`
ContextID string `json:"contextId,omitempty"`
Sender string `json:"sender,omitempty"`
Recipient string `json:"recipient,omitempty"`
State string `json:"state,omitempty"`
Summary string `json:"summary,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
Entry is one line of the log.
type Exchange ¶
type Exchange struct {
ID int64 `json:"id"`
At time.Time `json:"at"`
Direction string `json:"direction"`
TaskID string `json:"taskId,omitempty"`
ParentTaskID string `json:"parentTaskId,omitempty"`
ContextID string `json:"contextId,omitempty"`
Sender string `json:"sender,omitempty"`
Recipient string `json:"recipient,omitempty"`
Method string `json:"method"`
URL string `json:"url"`
Status int `json:"status"`
DurationMS int64 `json:"durationMs"`
// Headers holds the "request" and "response" headers that are safe to keep.
Headers map[string]map[string]string `json:"headers,omitempty"`
Request string `json:"request"`
Response string `json:"response"`
Truncated bool `json:"truncated,omitempty"`
Error string `json:"error,omitempty"`
}
Exchange is one HTTP request and its response, as the platform carried it.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log writes and reads entries.
func (*Log) AddExchange ¶
AddExchange stores x. ID is filled in.
func (*Log) Between ¶
Between returns the newest plain message exchanges between two addresses, either way round, oldest first.
func (*Log) Exchanges ¶
Exchanges returns the exchanges of the given tasks (or with them as parent) and contexts, oldest first.
func (*Log) Handler ¶
Handler records every exchange served by next. base is called before next with the request, to name the parties.
func (*Log) LastUsage ¶
LastUsage returns the latest usage entry of recipient's session contextID, or nil.
func (*Log) Messages ¶
Messages returns the newest plain message exchanges from or to one of handles that weren't made from a task.
func (*Log) Run ¶
Run returns the entries of the given tasks and of the calls made from them (messages and child tasks name them as parent), oldest first.
func (*Log) SinceFor ¶
func (l *Log) SinceFor(ctx context.Context, seq int64, limit int, handles []string) ([]*Entry, error)
SinceFor is Since for the entries from or to one of handles.
func (*Log) Stream ¶
Stream serves the log as Server-Sent Events, starting after ?since=<seq> or the Last-Event-ID header (so browsers resume where they left off), or at the end of the log when neither is given. Each event's id is its seq. Only entries keep accepts are sent; keep may be nil.
func (*Log) Transport ¶
func (l *Log) Transport(rt http.RoundTripper, base Exchange) http.RoundTripper
Transport records every exchange sent through rt, starting from base (direction, parties and, if known, the task). Streaming responses are recorded when they end.