activity

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 14 Imported by: ? 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 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

View Source
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.

View Source
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.

View Source
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 Filter

type Filter func(*Entry) bool

Filter decides which entries a reader sees.

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log writes and reads entries.

func New

func New(db *pg.DB) *Log

New returns a log on db.

func (*Log) Add

func (l *Log) Add(ctx context.Context, e *Entry) error

Add appends e and notifies listeners. Seq and At are filled in.

func (*Log) AddExchange

func (l *Log) AddExchange(ctx context.Context, x *Exchange) error

AddExchange stores x. ID is filled in.

func (*Log) Between

func (l *Log) Between(ctx context.Context, a, b string, limit int) ([]*Entry, error)

Between returns the newest plain message exchanges between two addresses, either way round, oldest first.

func (*Log) Exchanges

func (l *Log) Exchanges(ctx context.Context, taskIDs, contextIDs []string) ([]*Exchange, error)

Exchanges returns the exchanges of the given tasks (or with them as parent) and contexts, oldest first.

func (*Log) Get

func (l *Log) Get(ctx context.Context, seq int64) (*Entry, error)

Get returns the entry with seq, or nil.

func (*Log) Handler

func (l *Log) Handler(next http.Handler, base func(*http.Request) Exchange) http.Handler

Handler records every exchange served by next. base is called before next with the request, to name the parties.

func (*Log) Last

func (l *Log) Last(ctx context.Context) (int64, error)

Last returns the latest seq, or 0.

func (*Log) LastUsage

func (l *Log) LastUsage(ctx context.Context, recipient, contextID string) (*Entry, error)

LastUsage returns the latest usage entry of recipient's session contextID, or nil.

func (*Log) Messages

func (l *Log) Messages(ctx context.Context, handles []string, limit int) ([]*Entry, error)

Messages returns the newest plain message exchanges from or to one of handles that weren't made from a task.

func (*Log) Run

func (l *Log) Run(ctx context.Context, taskIDs []string) ([]*Entry, error)

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) Since

func (l *Log) Since(ctx context.Context, seq int64, limit int) ([]*Entry, error)

Since returns up to limit entries after seq, 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

func (l *Log) Stream(w http.ResponseWriter, r *http.Request, keep Filter)

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) Task

func (l *Log) Task(ctx context.Context, taskID string) ([]*Entry, error)

Task returns every entry of a task, oldest first.

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.

Jump to

Keyboard shortcuts

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