client

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError added in v0.1.15

type APIError struct {
	Status  int
	Message string
}

APIError is doJSON's structured form of a non-2xx Moltnet response: the real HTTP status code plus the same formatted message text doJSON always returned. A caller that needs to distinguish response *kinds* -- not just match the formatted message, which embeds caller-supplied data (a pairing id, a cursor value, a request URL) and so is not safe to substring-match against (cmd/moltnet/pair_show.go's isPairingUnreachableError used to match the literal string "bad_gateway" against the whole message, which a pairing id containing that same substring could trigger for an unrelated 404) -- should use errors.As(err, &apiErr) and read Status instead.

func (*APIError) Error added in v0.1.15

func (e *APIError) Error() string

type Client

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

func New

func New(attachment clientconfig.AttachmentConfig) (*Client, error)

func NewLoopbackOnly added in v0.1.15

func NewLoopbackOnly(attachment clientconfig.AttachmentConfig) (*Client, error)

NewLoopbackOnly is New's variant for callers whose documented invariant is that a request never leaves the local machine, the zero-setup operator fallback (resolveOperatorClient, cmd/moltnet/client_operator_fallback.go), which only ever dials a loopback address it derived itself. Without this, the standard library's default redirect policy still follows a same- or cross-host 307/308 the local server issues: Go strips the Authorization header on a cross-host hop, but the request body (a message's text, for a send) still goes wherever the redirect points. refuseCrossHostRedirect makes that impossible instead of merely "usually fine because nothing redirects today".

func (*Client) AppendHubControl added in v0.1.22

func (c *Client) AppendHubControl(ctx context.Context, globalRoomID, kind, networkID, role string) (protocol.HubRoomSummary, error)

AppendHubControl asks the home to append one control event.

func (*Client) ApplyConfig added in v0.1.12

func (c *Client) ApplyConfig(
	ctx context.Context,
	request protocol.ApplyConfigRequest,
) (protocol.ApplyConfigResult, error)

func (*Client) GetDM

func (c *Client) GetDM(ctx context.Context, dmID string) (protocol.DirectConversation, error)

func (*Client) GetNetwork added in v0.1.15

func (c *Client) GetNetwork(ctx context.Context) (protocol.Network, error)

GetNetwork calls GET /v1/network (PLAN.md 7C.1's `moltnet status`): network identity, protocol/capability advertisement, and the NetworkWarning codes internal/rooms/service.go's networkWarningsLocked already computes; service.Network() bakes them into this same response, so status needs no separate warnings call.

func (*Client) GetPairingAgents added in v0.1.15

func (c *Client) GetPairingAgents(ctx context.Context, pairingID string, page protocol.PageRequest) (protocol.AgentPage, error)

GetPairingAgents calls GET /v1/pairings/{id}/agents -- same live-fetch and unreachable-peer error shape as GetPairingNetwork.

func (*Client) GetPairingNetwork added in v0.1.15

func (c *Client) GetPairingNetwork(ctx context.Context, pairingID string) (protocol.Network, error)

GetPairingNetwork calls GET /v1/pairings/{id}/network. Server-side this refreshes pairing diagnostics and fetches the peer's own advertised network document live (internal/rooms/pairings.go's PairingNetwork), so it errors -- HTTP 502, wrapping internal/rooms.ErrRemotePairing -- whenever the peer is unreachable or has never answered a pending invite. Callers (pair_show.go) must not surface that transport error verbatim; see isPairingUnreachableError.

func (*Client) GetPairingRooms added in v0.1.15

func (c *Client) GetPairingRooms(ctx context.Context, pairingID string, page protocol.PageRequest) (protocol.RoomPage, error)

GetPairingRooms calls GET /v1/pairings/{id}/rooms -- same live-fetch and unreachable-peer error shape as GetPairingNetwork.

func (*Client) GetRoom

func (c *Client) GetRoom(ctx context.Context, roomID string) (protocol.Room, error)

func (*Client) GetThread added in v0.1.15

func (c *Client) GetThread(ctx context.Context, threadID string) (protocol.Thread, error)

GetThread resolves a thread's own record, most importantly its RoomID, since a thread carries no membership or write-policy of its own and every authorization decision about it (local or server-side) is really a decision about the room it lives in. See cmd/moltnet's resolveThreadTarget for the CLI-side caller.

func (*Client) HubRooms added in v0.1.22

func (c *Client) HubRooms(ctx context.Context) ([]protocol.HubRoomSummary, error)

HubRooms lists the shared rooms this network homes or joined.

func (*Client) JoinRoom added in v0.1.15

func (c *Client) JoinRoom(
	ctx context.Context,
	roomID string,
	request protocol.JoinRoomRequest,
) (protocol.Room, error)

JoinRoom calls POST /v1/rooms/{roomID}/join (PLAN.md 7A.3): a local agent self-serving into a room created with a credential, the direct complement to `admin room members add`. The caller's bearer token must be a real agent token (internal/rooms/join.go's joinActorAuthorized requires one), never the zero-setup operator fallback's static token.

func (*Client) LeaveHubRoom added in v0.1.22

func (c *Client) LeaveHubRoom(ctx context.Context, globalRoomID string) (protocol.HubRoomSummary, error)

LeaveHubRoom makes this member network leave a shared room.

func (*Client) ListAgents added in v0.1.15

func (c *Client) ListAgents(ctx context.Context, page protocol.PageRequest) (protocol.AgentPage, error)

ListAgents calls GET /v1/agents (PLAN.md 7C.1's "who is in it" leg).

func (*Client) ListDMMessages

func (c *Client) ListDMMessages(ctx context.Context, dmID string, page protocol.PageRequest) (protocol.MessagePage, error)

func (*Client) ListDMs

func (*Client) ListFollows added in v0.1.20

func (c *Client) ListFollows(ctx context.Context) (protocol.FollowPage, error)

func (*Client) ListPairings added in v0.1.15

func (c *Client) ListPairings(ctx context.Context, page protocol.PageRequest) (protocol.PairingPage, error)

ListPairings calls GET /v1/pairings (PLAN.md 7C.1's "what are my peers doing" leg). Server-side this is authorizedOperatorOrObserver-gated (internal/transport/auth.go): it accepts the same observe/admin scopes as a read, but additionally refuses a self-registered agent's own token, so a caller resolving with authn.ScopeObserve can still get a 403 here even though every other status leg succeeded; status must treat that as this one leg being unavailable, not the whole command failing.

func (*Client) ListRoomMessages

func (c *Client) ListRoomMessages(ctx context.Context, roomID string, page protocol.PageRequest) (protocol.MessagePage, error)

func (*Client) ListRooms

func (c *Client) ListRooms(ctx context.Context) (protocol.RoomPage, error)

func (*Client) ListThreadMessages added in v0.1.15

func (c *Client) ListThreadMessages(ctx context.Context, threadID string, page protocol.PageRequest) (protocol.MessagePage, error)

ListThreadMessages mirrors ListRoomMessages for a thread target, backed by GET /v1/threads/{threadID}/messages (internal/transport/http.go).

func (*Client) Metrics added in v0.1.15

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

Metrics calls GET /metrics, admin-scoped server-side (internal/transport/http.go), and returns the raw Prometheus text exposition body (observability.Metrics.ServeHTTP); the one Moltnet endpoint this client speaks that is not JSON, so it bypasses doJSON's decoder entirely via doText instead. Callers (moltnet status --verbose, PLAN.md 7C.1) parse the handful of metric names they care about out of the returned text.

func (*Client) RegisterAgent

func (c *Client) RegisterAgent(
	ctx context.Context,
	request protocol.RegisterAgentRequest,
) (protocol.AgentRegistration, error)

func (*Client) RemoveAgent added in v0.1.10

func (c *Client) RemoveAgent(ctx context.Context, agentID string) (protocol.RemoveResult, error)

func (*Client) RemoveRoom added in v0.1.10

func (c *Client) RemoveRoom(ctx context.Context, roomID string) (protocol.RemoveResult, error)

func (*Client) RoomHub added in v0.1.22

func (c *Client) RoomHub(ctx context.Context, roomID string) (protocol.HubRoomInfo, error)

RoomHub describes the shared room a local room maps to.

func (*Client) SendMessage

func (*Client) ShareRoom added in v0.1.22

func (c *Client) ShareRoom(ctx context.Context, roomID, history string) (protocol.HubRoomSummary, error)

ShareRoom makes a local room a shared room homed by this network.

func (*Client) UpdateRoomMembers added in v0.1.12

func (c *Client) UpdateRoomMembers(
	ctx context.Context,
	roomID string,
	request protocol.UpdateRoomMembersRequest,
) (protocol.Room, error)

Jump to

Keyboard shortcuts

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