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
- func NotifyToBridge(b *Bridge, sessionID string, notification string) error
- func StreamToBridge(b *Bridge, sessionID string, text string) error
- type Bridge
- func (b *Bridge) Broadcast(msg Message)
- func (b *Bridge) OnMessage(fn func(sessionID string, msg Message))
- func (b *Bridge) Port() int
- func (b *Bridge) Send(sessionID string, msg Message) error
- func (b *Bridge) Sessions() []string
- func (b *Bridge) Start(ctx context.Context) error
- func (b *Bridge) Stop() error
- type BridgePermissionPrompter
- type HandshakePayload
- type Message
- type MessageType
- type Session
Constants ¶
const DefaultPermissionTimeout = 2 * time.Minute
DefaultPermissionTimeout is how long to wait for an IDE permission response.
const DefaultPort = 19836
DefaultPort is the default WebSocket server port.
const MaxPortRetries = 5
MaxPortRetries is the number of sequential ports to try if the default is in use.
const ProtocolVersion = "1.0"
ProtocolVersion is the current bridge protocol version.
const SessionCleanupTimeout = 30 * time.Second
SessionCleanupTimeout is the duration after which dropped sessions are cleaned up.
Variables ¶
This section is empty.
Functions ¶
func NotifyToBridge ¶
NotifyToBridge sends a notification message to the IDE session.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge is the WebSocket server for IDE integration.
func NewBridge ¶
NewBridge creates a new Bridge on the given port. If port is 0, DefaultPort is used.
func (*Bridge) OnMessage ¶
OnMessage sets the callback invoked when a message is received from any session.
func (*Bridge) Port ¶
Port returns the port the bridge is configured to listen on. After Start, this reflects the actual bound port.
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.
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" )