Files
CLIProxyAPI/sdk/cliproxy/executor/websocket_input.go
Luis Pater 42c9680eee feat(executor): support duplex streaming for codex websockets
- Implement `streamCodexDuplex` to handle bidirectional WebSocket interactions for Codex
- Support steering continuations (`response.steer`) and queued creations (`response.create`, `response.append`)
- Preserve response settings and state transitions across steering updates and automatic successors
- Isolate connection-level failures with `codexDuplexConnectionError` to prevent unnecessary credential cooldowns

Closes: #5968
2026-09-20 00:02:10 +08:00

38 lines
1.2 KiB
Go

package executor
import "context"
// WebsocketInput is a frame from the single downstream reader. Err terminates
// the connection; Payload is owned by the receiver and must not be replayed.
type WebsocketInput struct {
Payload []byte
Err error
}
type websocketInputKey struct{}
func WithWebsocketInput(ctx context.Context, input <-chan WebsocketInput) context.Context {
return context.WithValue(ctx, websocketInputKey{}, input)
}
func WebsocketInputFromContext(ctx context.Context) <-chan WebsocketInput {
if ctx == nil {
return nil
}
input, _ := ctx.Value(websocketInputKey{}).(<-chan WebsocketInput)
return input
}
// WithWebsocketAuthCheck supplies the live account-state check for a bound
// connection. It may reject further frames but never select another account.
type websocketAuthCheckKey struct{}
func WithWebsocketAuthCheck(ctx context.Context, check func(string) bool) context.Context {
return context.WithValue(ctx, websocketAuthCheckKey{}, check)
}
func WebsocketAuthEnabled(ctx context.Context, authID string) bool {
if ctx == nil {
return true
}
check, _ := ctx.Value(websocketAuthCheckKey{}).(func(string) bool)
return check == nil || check(authID)
}