client

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: 13 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 client calls a Lagrange server's HTTP API with a personal API key (lgk_…). The CLI and the MCP server use it; the API itself is described at /api/openapi.yaml.

Index

Constants

View Source
const AnsweredByKey = "https://threeagents.dev/ext/answered-by/v1"

AnsweredByKey is the message metadata key that says who answered from the inbox.

Variables

This section is empty.

Functions

func ShortState

func ShortState(s string) string

ShortState turns "TASK_STATE_INPUT_REQUIRED" into "input-required".

func StatusOf

func StatusOf(err error) int

StatusOf returns the HTTP status of an API error, or 0.

func Waiting

func Waiting(s a2a.TaskState) bool

Waiting reports whether a task state waits for someone.

Types

type Address

type Address struct {
	Handle      string          `json:"handle"`
	Kind        string          `json:"kind"`
	DisplayName string          `json:"displayName"`
	Description string          `json:"description"`
	Online      bool            `json:"online"`
	Card        json.RawMessage `json:"card,omitempty"`
}

Address is an agent or a person.

type Answer

type Answer struct {
	Text     string         `json:"text,omitempty"`
	Data     map[string]any `json:"data,omitempty"`
	Decision string         `json:"decision,omitempty"`
}

Answer is the answer to a task waiting for input.

type Client

type Client struct {
	// Server is the base URL, e.g. https://lagrange.example.com.
	Server string
	// Key is a personal API key.
	Key string
	// HTTP is the client to use; nil means one with a 30-second timeout.
	HTTP *http.Client
}

Client calls one server as one key.

func New

func New(server, key string) *Client

New returns a client for server with key.

func (*Client) Addresses

func (c *Client) Addresses(ctx context.Context) ([]*Address, error)

Addresses lists the addresses the workspace can reach.

func (*Client) Answer

func (c *Client) Answer(ctx context.Context, id string, a *Answer) error

Answer answers a task waiting for input.

func (*Client) ConnectTelegram

func (c *Client) ConnectTelegram(ctx context.Context, token string) (*Telegram, error)

ConnectTelegram checks a bot token from @BotFather, connects the bot (replacing any other) and returns the link that pairs it.

func (*Client) CreateAgent

func (c *Client) CreateAgent(ctx context.Context, handle string) (string, error)

CreateAgent creates an agent address and returns its first tunnel token.

func (*Client) DisconnectTelegram

func (c *Client) DisconnectTelegram(ctx context.Context) error

DisconnectTelegram removes the bot.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body, out any) error

Do calls method path with body as JSON and decodes the answer into out (if not nil).

func (*Client) Follow

func (c *Client) Follow(ctx context.Context, id string, wait, poll time.Duration, stop func(*Task) bool) (*Task, bool, error)

Follow polls a task every poll (zero: one second) until stop says so or wait runs out, and returns the task as it last saw it, and whether stop said so.

func (*Client) Me

func (c *Client) Me(ctx context.Context) (*Me, error)

Me returns who the key acts as.

func (*Client) MintToken

func (c *Client) MintToken(ctx context.Context, handle, label string) (string, error)

MintToken mints a tunnel token for an agent address.

func (*Client) PairTelegram

func (c *Client) PairTelegram(ctx context.Context) (*Telegram, error)

PairTelegram makes a new pairing link.

func (*Client) Run

func (c *Client) Run(ctx context.Context, id string) (*RunDetail, error)

Run returns one run with its tasks.

func (*Client) Runs

func (c *Client) Runs(ctx context.Context, f RunFilter) ([]*Run, error)

Runs lists runs, newest first.

func (*Client) Send

func (c *Client) Send(ctx context.Context, m *Send) (*SendResult, error)

Send sends a message and returns the task it started (or continued), or the address's direct answer.

func (*Client) SetTelegramLevel

func (c *Client) SetTelegramLevel(ctx context.Context, level string) (*Telegram, error)

SetTelegramLevel sets what the bot sends besides questions: "questions" or "milestones".

func (*Client) Task

func (c *Client) Task(ctx context.Context, id string) (*Task, error)

Task returns one task.

func (*Client) Telegram

func (c *Client) Telegram(ctx context.Context) (*Telegram, error)

Telegram returns the person's Telegram connection.

func (*Client) TestTelegram

func (c *Client) TestTelegram(ctx context.Context) error

TestTelegram sends a test message to the paired chat.

func (*Client) Waiting

func (c *Client) Waiting(ctx context.Context) ([]*Wait, error)

Waiting lists the workspace's tasks waiting for an answer, longest wait first.

type Error

type Error struct {
	Status  int
	Message string
}

Error is an error answer from the server.

func (*Error) Error

func (e *Error) Error() string

type File

type File struct {
	Name      string `json:"name,omitempty"`
	MediaType string `json:"mediaType,omitempty"` // guessed from the name or content if empty
	Data      []byte `json:"data,omitempty"`
	URL       string `json:"url,omitempty"`
}

File is a file in a message: its bytes, or a URL the recipient fetches. The request carries the bytes base64-encoded, and is limited to 8 MB.

type Login

type Login struct {
	Key       string `json:"key"`
	Workspace string `json:"workspace"`
	Role      string `json:"role"`
	Server    string `json:"server"`
}

Login is a key from `lagrange login`.

func ClaimLogin

func ClaimLogin(ctx context.Context, server, code, verifier string) (*Login, error)

ClaimLogin trades a `lagrange login` code and its PKCE verifier for a key. It needs no key.

func PasswordLogin

func PasswordLogin(ctx context.Context, server, email, password, workspace, name string) (*Login, error)

PasswordLogin makes an API key with an email and a password, for a machine without a browser: it logs in (a session cookie), makes a key named name in workspace (its slug; empty: the person's first workspace) with their role there, and logs the session out. Accounts that sign in only with GitHub or Google can't use it.

type Me

type Me struct {
	User struct {
		ID     int64  `json:"id"`
		Email  string `json:"email"`
		Name   string `json:"name"`
		Handle string `json:"handle"`
	} `json:"user"`
	Key struct {
		Workspace string `json:"workspace"`
		Role      string `json:"role"`
	} `json:"key"`
}

Me is who a key acts as.

type Result

type Result struct {
	TaskID    string `json:"taskId"`
	ContextID string `json:"contextId,omitempty"`
	State     string `json:"state" jsonschema:"submitted, working, input-required, auth-required, completed, failed, canceled or rejected"`
	// Done is true once the task reached a final state.
	Done bool `json:"done"`
	// Text is the latest status message and any text artifacts.
	Text string `json:"text,omitempty"`
	// Data holds structured parts of the answer.
	Data       []any  `json:"data,omitempty"`
	AnsweredBy string `json:"answeredBy,omitempty"`
	// WaitingOn is the address a waiting task waits for.
	WaitingOn string `json:"waitingOn,omitempty"`
	Note      string `json:"note,omitempty"`
}

Result is a task's state and what it answered, flattened for people, scripts and models.

func MessageResult

func MessageResult(m *a2a.Message) *Result

MessageResult flattens a direct answer that started no task.

func ResultOf

func ResultOf(t *a2a.Task) *Result

ResultOf flattens an A2A task.

type Run

type Run struct {
	ID string `json:"id"`
	// ContextID is the root task's context: Send into it to continue the conversation.
	ContextID    string    `json:"contextId,omitempty"`
	Title        string    `json:"title"`
	Outcome      string    `json:"outcome,omitempty"`
	Starter      string    `json:"starter"`
	Recipient    string    `json:"recipient"`
	State        string    `json:"state"`
	Waiting      []string  `json:"waiting"`
	Participants []string  `json:"participants"`
	Tasks        int       `json:"tasks"`
	StartedAt    time.Time `json:"startedAt"`
	UpdatedAt    time.Time `json:"updatedAt"`
	// Cost is what the run's agents reported spending on it, in Currency.
	Cost     float64 `json:"cost,omitempty"`
	Currency string  `json:"currency,omitempty"`
	// Report is the run's latest situation report (lagrange/report), if it has one.
	Report *report.Report `json:"report,omitempty"`
}

Run is a root task and everything it caused.

type RunDetail

type RunDetail struct {
	Run   *Run    `json:"run"`
	Tasks []*Task `json:"tasks"`
}

RunDetail is a run with its tasks.

type RunFilter

type RunFilter struct {
	Q, Status, Participant, WaitingOn string
	Limit                             int
}

RunFilter narrows Runs. Empty fields don't filter.

type Send

type Send struct {
	To        string         `json:"to"`
	Text      string         `json:"text,omitempty"`
	Data      map[string]any `json:"data,omitempty"`
	Files     []File         `json:"files,omitempty"`
	TaskID    string         `json:"taskId,omitempty"`
	ContextID string         `json:"contextId,omitempty"`
	// Tags are recorded with the task in the activity log (data.tags), for clients
	// to group and label tasks: up to 16 short strings.
	Tags map[string]string `json:"tags,omitempty"`
	// Metadata is the message's metadata, e.g. {"acpSettings": {"model": "opus"}}
	// for a coding agent that lets senders pick its model.
	Metadata map[string]any `json:"metadata,omitempty"`
}

Send is a message to an address.

type SendResult

type SendResult struct {
	Task    *a2a.Task
	Message *a2a.Message
}

SendResult is what an address answered: a task to follow, or a plain message.

type Task

type Task struct {
	ID           string    `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       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"`
}

Task is a task as the API shows it, with the full A2A task.

func (*Task) Result

func (t *Task) Result() *Result

Result flattens the task.

func (*Task) WaitsOn

func (t *Task) WaitsOn() string

WaitsOn returns who a waiting task waits for: the person it was addressed to (awaiting), or else its sender, whom the agent asked.

type Telegram

type Telegram struct {
	Connected    bool   `json:"connected"`
	BotUsername  string `json:"botUsername,omitempty"`
	Paired       bool   `json:"paired"`
	ChatUsername string `json:"chatUsername,omitempty"`
	// PairLink opens the bot with a fresh pairing code (only right after Connect or Pair).
	PairLink      string     `json:"pairLink,omitempty"`
	PairExpiresAt *time.Time `json:"pairExpiresAt,omitempty"`
	// Level is "questions" or "milestones".
	Level      string     `json:"level,omitempty"`
	MutedUntil *time.Time `json:"mutedUntil,omitempty"`
}

Telegram is the key's person's Telegram bot connection. It never carries the token.

type Wait

type Wait struct {
	Task        *Task     `json:"task"`
	RunID       string    `json:"runId"`
	Who         string    `json:"who"`
	Asker       string    `json:"asker"`
	Person      bool      `json:"person"`
	Since       time.Time `json:"since"`
	Reminders   int       `json:"reminders"`
	EscalatedTo string    `json:"escalatedTo,omitempty"`
}

Wait is a task waiting for an answer.

Jump to

Keyboard shortcuts

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