bridge

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package bridge provides a WebSocket server for bidirectional IDE communication. It implements the WebSocket protocol (RFC 6455) using only the Go standard library.

Index

Constants

View Source
const DefaultPermissionTimeout = 2 * time.Minute

DefaultPermissionTimeout is how long to wait for an IDE permission response.

View Source
const DefaultPort = 19836

DefaultPort is the default WebSocket server port.

View Source
const MaxPortRetries = 5

MaxPortRetries is the number of sequential ports to try if the default is in use.

View Source
const ProtocolVersion = "1.0"

ProtocolVersion is the current bridge protocol version.

View Source
const SessionCleanupTimeout = 30 * time.Second

SessionCleanupTimeout is the duration after which dropped sessions are cleaned up.

Variables

This section is empty.

Functions

func NotifyToBridge

func NotifyToBridge(b *Bridge, sessionID string, notification string) error

NotifyToBridge sends a notification message to the IDE session.

func StreamToBridge

func StreamToBridge(b *Bridge, sessionID string, text string) error

StreamToBridge sends agent response text to the IDE session in real-time. It wraps the text as a MsgChat message with the text as payload.

Types

type Bridge

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

Bridge is the WebSocket server for IDE integration.

func NewBridge

func NewBridge(port int) *Bridge

NewBridge creates a new Bridge on the given port. If port is 0, DefaultPort is used.

func (*Bridge) Broadcast

func (b *Bridge) Broadcast(msg Message)

Broadcast sends a message to all connected sessions.

func (*Bridge) OnMessage

func (b *Bridge) OnMessage(fn func(sessionID string, msg Message))

OnMessage sets the callback invoked when a message is received from any session.

func (*Bridge) Port

func (b *Bridge) Port() int

Port returns the port the bridge is configured to listen on. After Start, this reflects the actual bound port.

func (*Bridge) Send

func (b *Bridge) Send(sessionID string, msg Message) error

Send sends a message to a specific session by ID.

func (*Bridge) Sessions

func (b *Bridge) Sessions() []string

Sessions returns a snapshot of current session IDs.

func (*Bridge) Start

func (b *Bridge) Start(ctx context.Context) error

Start begins listening for WebSocket connections. It tries the configured port and up to MaxPortRetries sequential ports if the port is already in use.

func (*Bridge) Stop

func (b *Bridge) Stop() error

Stop gracefully shuts down the bridge server and cleans up all sessions.

type BridgePermissionPrompter

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

BridgePermissionPrompter implements agent.PermissionPrompter by forwarding permission requests to the IDE over the WebSocket bridge.

func NewBridgePermissionPrompter

func NewBridgePermissionPrompter(b *Bridge, sessionID string) *BridgePermissionPrompter

NewBridgePermissionPrompter creates a prompter that forwards permission requests to the given bridge session.

func (*BridgePermissionPrompter) HandleResponse

func (p *BridgePermissionPrompter) HandleResponse(msgID string, payload json.RawMessage)

HandleResponse should be called when a permission response message arrives from the IDE. It matches the message ID to a pending request and delivers the result.

func (*BridgePermissionPrompter) Prompt

func (p *BridgePermissionPrompter) Prompt(toolName string, operation string) (bool, error)

Prompt sends a tool_permission message to the IDE and waits for the response. Returns (true, nil) if approved, (false, nil) if denied, or error on timeout.

type HandshakePayload

type HandshakePayload struct {
	ClientType      string `json:"client_type"`
	SessionID       string `json:"session_id"`
	ProtocolVersion string `json:"protocol_version"`
}

HandshakePayload is exchanged during the initial WebSocket handshake message.

type Message

type Message struct {
	Type      MessageType     `json:"type"`
	ID        string          `json:"id"`
	SessionID string          `json:"session_id,omitempty"`
	Payload   json.RawMessage `json:"payload"`
}

Message is the JSON envelope for all bridge communication.

type MessageType

type MessageType string

MessageType represents the type of a bridge message.

const (
	MsgChat           MessageType = "chat"
	MsgToolPermission MessageType = "tool_permission"
	MsgStatus         MessageType = "status"
	MsgError          MessageType = "error"
	MsgNotification   MessageType = "notification"
)

type Session

type Session struct {
	ID         string
	ClientType string

	CreatedAt time.Time
	// contains filtered or unexported fields
}

Session represents a connected IDE client session.

Jump to

Keyboard shortcuts

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