bridge

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package bridge defines the agent-to-agent protocol that allows OK instances to discover each other and share tasks. Multiple OK agents on a local network (or same machine) can form an ad-hoc team without any central server — pure peer-to-peer.

Discovery: mDNS (Bonjour/avahi) on port 9463. Each agent announces its name, capabilities, and current load. Discovery is zero-config.

Communication: HTTP/JSON over the same port. Agents RPC each other with task requests, returning results as streaming NDJSON.

Security: local-network only (bind 127.0.0.1 or LAN interface). Shared secret (from ~/.ok/agent-secret) prevents unauthorized peers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOrCreateSecret

func LoadOrCreateSecret() string

LoadOrCreateSecret returns the agent's shared secret (for peer auth). Creates one on first run. Errors are logged to stderr; a best-effort secret is always returned (bridge is optional, so startup is never blocked by a missing secret).

Types

type AgentInfo

type AgentInfo struct {
	ID       string    `json:"id"`
	Name     string    `json:"name"`
	Version  string    `json:"version"`
	Model    string    `json:"model"`
	Load     int       `json:"load"` // 0-100
	Tags     []string  `json:"tags"` // desktop, server, coding, personal
	Addr     string    `json:"addr"` // ip:port
	LastSeen time.Time `json:"-"`
}

AgentInfo describes an agent on the network.

type Bridge

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

Bridge manages agent-to-agent connections.

func NewBridge

func NewBridge(secret string, port int, onTask func(ctx context.Context, task string) (<-chan string, error)) *Bridge

NewBridge creates an agent bridge. If port is 0, the system picks a random available port (read via ListenerAddr after Start). Default port is 9463.

func (*Bridge) Peers

func (b *Bridge) Peers() []AgentInfo

Peers returns currently known peers.

func (*Bridge) SendTask

func (b *Bridge) SendTask(ctx context.Context, peerAddr, task string) (<-chan TaskResponse, error)

SendTask sends a task to a peer and returns the streaming result.

func (*Bridge) Start

func (b *Bridge) Start() error

Start begins listening and announcing.

func (*Bridge) Stop

func (b *Bridge) Stop()

Stop shuts down the bridge.

type TaskRequest

type TaskRequest struct {
	From    string `json:"from"`
	Task    string `json:"task"`
	Timeout int    `json:"timeout_sec"`
}

TaskRequest is sent from one agent to another.

type TaskResponse

type TaskResponse struct {
	Seq        int    `json:"seq"`
	Text       string `json:"text,omitempty"`
	Done       bool   `json:"done"`
	Error      string `json:"error,omitempty"`
	TokenUsage int    `json:"tokens,omitempty"`
}

TaskResponse is the streaming result.

Jump to

Keyboard shortcuts

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