mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
- 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
44 lines
1.4 KiB
Go
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)
|
|
}
|