Files
CLIProxyAPI/sdk/cliproxy/executor/websocket_input.go
Luis Pater 6331b38bba feat(openai): support response.interrupt in responses websocket handling
- Intercept and process `response.interrupt` control frames immediately on the downstream websocket reader
- Forward interrupts to active upstream Codex websocket sessions without starting a new turn or rewriting payload fields
- Support canceling in-flight HTTP turns via local interrupt handling
- Allow session-staged Home credentials to authorize interrupts

Closes: #6456
2026-10-08 21:32:26 +08:00

44 lines
1.4 KiB
Go

package executor
import (
"context"
"errors"
)
// ErrNoActiveUpstreamWebsocket means response.interrupt has no live upstream socket.
var ErrNoActiveUpstreamWebsocket = errors.New("no active upstream websocket for response.interrupt")
// 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)
}