feat(transport): negotiate bounded automatic message chunking

This commit is contained in:
cabbage committed 2026-11-09 08:50:51 +00:00
1 parent 474afb3484
commit 8acffac985
20 files changed
+1332 -38

No files matched your search

+10 -3
View File
@@ -9,11 +9,12 @@ import (
"github.com/coder/websocket"
"github.com/rvbox/rvbox/internal/agentproto"
"github.com/rvbox/rvbox/internal/agentwire"
)
var ErrUnexpectedMessage = errors.New("agent transport received a non-binary WebSocket message")
type WebSocketTransport struct{ connection *websocket.Conn }
type WebSocketTransport struct{ connection *agentwire.Conn }
func DialWebSocket(ctx context.Context, address string, client *http.Client) (*WebSocketTransport, error) {
return DialWebSocketWithLimits(ctx, address, client, agentproto.DefaultLimits())
@@ -30,11 +31,17 @@ func DialWebSocketWithLimits(ctx context.Context, address string, client *http.C
if readLimit > math.MaxInt64-1 {
return nil, fmt.Errorf("invalid WebSocket envelope limit: %d", readLimit)
}
connection, _, err := websocket.Dial(ctx, address, &websocket.DialOptions{HTTPClient: client, CompressionMode: websocket.CompressionDisabled})
raw, _, err := websocket.Dial(ctx, address, &websocket.DialOptions{
HTTPClient: client, CompressionMode: websocket.CompressionDisabled, Subprotocols: []string{agentwire.Subprotocol},
})
if err != nil {
return nil, err
}
connection.SetReadLimit(int64(readLimit))
connection, err := agentwire.Wrap(raw, readLimit, nil)
if err != nil {
_ = raw.CloseNow()
return nil, err
}
return &WebSocketTransport{connection: connection}, nil
}