mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-10-23 16:15:46 +08:00
- 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
38 lines
1.2 KiB
Go
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)
|
|
}
|