refactor(executor): remove ClientAdapter and legacy fallback logic
Browse files- Deleted `ClientAdapter` implementation and associated fallback methods.
- Removed legacy executor logic from `codex`, `claude`, `gemini`, and `qwen` executors.
- Simplified `handlers` by eliminating `UnwrapError` handling and related dependencies.
- Cleaned up `model_registry` by removing logic associated with suspended clients.
- Updated `.gitignore` to ignore `.serena/` directory.
- .gitignore +2 -1
- internal/api/handlers/handlers.go +2 -17
- internal/registry/model_registry.go +14 -13
- internal/runtime/executor/claude_executor.go +3 -9
- internal/runtime/executor/client_executor.go +0 -185
- internal/runtime/executor/codex_executor.go +2 -6
- internal/runtime/executor/gemini_executor.go +2 -8
- internal/runtime/executor/qwen_executor.go +2 -6
.gitignore
CHANGED
|
@@ -10,4 +10,5 @@ auths/*
|
|
| 10 |
AGENTS.md
|
| 11 |
CLAUDE.md
|
| 12 |
*.exe
|
| 13 |
-
temp/*
|
|
|
|
|
|
| 10 |
AGENTS.md
|
| 11 |
CLAUDE.md
|
| 12 |
*.exe
|
| 13 |
+
temp/*
|
| 14 |
+
.serena/
|
internal/api/handlers/handlers.go
CHANGED
|
@@ -10,7 +10,6 @@ import (
|
|
| 10 |
"github.com/gin-gonic/gin"
|
| 11 |
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
| 12 |
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
| 13 |
-
"github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/executor"
|
| 14 |
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
| 15 |
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
| 16 |
coreexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
|
|
@@ -150,9 +149,6 @@ func (h *BaseAPIHandler) ExecuteWithAuthManager(ctx context.Context, handlerType
|
|
| 150 |
}
|
| 151 |
resp, err := h.AuthManager.Execute(ctx, providers, req, opts)
|
| 152 |
if err != nil {
|
| 153 |
-
if msg, ok := executor.UnwrapError(err); ok {
|
| 154 |
-
return nil, msg
|
| 155 |
-
}
|
| 156 |
return nil, &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: err}
|
| 157 |
}
|
| 158 |
return cloneBytes(resp.Payload), nil
|
|
@@ -177,9 +173,6 @@ func (h *BaseAPIHandler) ExecuteCountWithAuthManager(ctx context.Context, handle
|
|
| 177 |
}
|
| 178 |
resp, err := h.AuthManager.ExecuteCount(ctx, providers, req, opts)
|
| 179 |
if err != nil {
|
| 180 |
-
if msg, ok := executor.UnwrapError(err); ok {
|
| 181 |
-
return nil, msg
|
| 182 |
-
}
|
| 183 |
return nil, &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: err}
|
| 184 |
}
|
| 185 |
return cloneBytes(resp.Payload), nil
|
|
@@ -208,11 +201,7 @@ func (h *BaseAPIHandler) ExecuteStreamWithAuthManager(ctx context.Context, handl
|
|
| 208 |
chunks, err := h.AuthManager.ExecuteStream(ctx, providers, req, opts)
|
| 209 |
if err != nil {
|
| 210 |
errChan := make(chan *interfaces.ErrorMessage, 1)
|
| 211 |
-
|
| 212 |
-
errChan <- msg
|
| 213 |
-
} else {
|
| 214 |
-
errChan <- &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: err}
|
| 215 |
-
}
|
| 216 |
close(errChan)
|
| 217 |
return nil, errChan
|
| 218 |
}
|
|
@@ -223,11 +212,7 @@ func (h *BaseAPIHandler) ExecuteStreamWithAuthManager(ctx context.Context, handl
|
|
| 223 |
defer close(errChan)
|
| 224 |
for chunk := range chunks {
|
| 225 |
if chunk.Err != nil {
|
| 226 |
-
|
| 227 |
-
errChan <- msg
|
| 228 |
-
} else {
|
| 229 |
-
errChan <- &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: chunk.Err}
|
| 230 |
-
}
|
| 231 |
return
|
| 232 |
}
|
| 233 |
if len(chunk.Payload) > 0 {
|
|
|
|
| 10 |
"github.com/gin-gonic/gin"
|
| 11 |
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
| 12 |
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
|
|
|
| 13 |
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
| 14 |
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
| 15 |
coreexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
|
|
|
|
| 149 |
}
|
| 150 |
resp, err := h.AuthManager.Execute(ctx, providers, req, opts)
|
| 151 |
if err != nil {
|
|
|
|
|
|
|
|
|
|
| 152 |
return nil, &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: err}
|
| 153 |
}
|
| 154 |
return cloneBytes(resp.Payload), nil
|
|
|
|
| 173 |
}
|
| 174 |
resp, err := h.AuthManager.ExecuteCount(ctx, providers, req, opts)
|
| 175 |
if err != nil {
|
|
|
|
|
|
|
|
|
|
| 176 |
return nil, &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: err}
|
| 177 |
}
|
| 178 |
return cloneBytes(resp.Payload), nil
|
|
|
|
| 201 |
chunks, err := h.AuthManager.ExecuteStream(ctx, providers, req, opts)
|
| 202 |
if err != nil {
|
| 203 |
errChan := make(chan *interfaces.ErrorMessage, 1)
|
| 204 |
+
errChan <- &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: err}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
close(errChan)
|
| 206 |
return nil, errChan
|
| 207 |
}
|
|
|
|
| 212 |
defer close(errChan)
|
| 213 |
for chunk := range chunks {
|
| 214 |
if chunk.Err != nil {
|
| 215 |
+
errChan <- &interfaces.ErrorMessage{StatusCode: http.StatusInternalServerError, Error: chunk.Err}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
return
|
| 217 |
}
|
| 218 |
if len(chunk.Payload) > 0 {
|
internal/registry/model_registry.go
CHANGED
|
@@ -393,23 +393,24 @@ func (r *ModelRegistry) GetModelProviders(modelID string) []string {
|
|
| 393 |
count int
|
| 394 |
}
|
| 395 |
providers := make([]providerCount, 0, len(registration.Providers))
|
| 396 |
-
suspendedByProvider := make(map[string]int)
|
| 397 |
-
if registration.SuspendedClients != nil {
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
}
|
| 404 |
for name, count := range registration.Providers {
|
| 405 |
if count <= 0 {
|
| 406 |
continue
|
| 407 |
}
|
| 408 |
-
adjusted := count - suspendedByProvider[name]
|
| 409 |
-
if adjusted <= 0 {
|
| 410 |
-
|
| 411 |
-
}
|
| 412 |
-
providers = append(providers, providerCount{name: name, count: adjusted})
|
|
|
|
| 413 |
}
|
| 414 |
if len(providers) == 0 {
|
| 415 |
return nil
|
|
|
|
| 393 |
count int
|
| 394 |
}
|
| 395 |
providers := make([]providerCount, 0, len(registration.Providers))
|
| 396 |
+
// suspendedByProvider := make(map[string]int)
|
| 397 |
+
// if registration.SuspendedClients != nil {
|
| 398 |
+
// for clientID := range registration.SuspendedClients {
|
| 399 |
+
// if provider, ok := r.clientProviders[clientID]; ok && provider != "" {
|
| 400 |
+
// suspendedByProvider[provider]++
|
| 401 |
+
// }
|
| 402 |
+
// }
|
| 403 |
+
// }
|
| 404 |
for name, count := range registration.Providers {
|
| 405 |
if count <= 0 {
|
| 406 |
continue
|
| 407 |
}
|
| 408 |
+
// adjusted := count - suspendedByProvider[name]
|
| 409 |
+
// if adjusted <= 0 {
|
| 410 |
+
// continue
|
| 411 |
+
// }
|
| 412 |
+
// providers = append(providers, providerCount{name: name, count: adjusted})
|
| 413 |
+
providers = append(providers, providerCount{name: name, count: count})
|
| 414 |
}
|
| 415 |
if len(providers) == 0 {
|
| 416 |
return nil
|
internal/runtime/executor/claude_executor.go
CHANGED
|
@@ -38,9 +38,7 @@ func (e *ClaudeExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) e
|
|
| 38 |
|
| 39 |
func (e *ClaudeExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 40 |
apiKey, baseURL := claudeCreds(auth)
|
| 41 |
-
|
| 42 |
-
return NewClientAdapter("claude").Execute(ctx, auth, req, opts)
|
| 43 |
-
}
|
| 44 |
if baseURL == "" {
|
| 45 |
baseURL = "https://api.anthropic.com"
|
| 46 |
}
|
|
@@ -114,9 +112,7 @@ func (e *ClaudeExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, r
|
|
| 114 |
|
| 115 |
func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 116 |
apiKey, baseURL := claudeCreds(auth)
|
| 117 |
-
|
| 118 |
-
return NewClientAdapter("claude").ExecuteStream(ctx, auth, req, opts)
|
| 119 |
-
}
|
| 120 |
if baseURL == "" {
|
| 121 |
baseURL = "https://api.anthropic.com"
|
| 122 |
}
|
|
@@ -177,9 +173,7 @@ func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.A
|
|
| 177 |
|
| 178 |
func (e *ClaudeExecutor) CountTokens(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 179 |
apiKey, baseURL := claudeCreds(auth)
|
| 180 |
-
|
| 181 |
-
return NewClientAdapter("claude").Execute(ctx, auth, req, opts)
|
| 182 |
-
}
|
| 183 |
if baseURL == "" {
|
| 184 |
baseURL = "https://api.anthropic.com"
|
| 185 |
}
|
|
|
|
| 38 |
|
| 39 |
func (e *ClaudeExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 40 |
apiKey, baseURL := claudeCreds(auth)
|
| 41 |
+
|
|
|
|
|
|
|
| 42 |
if baseURL == "" {
|
| 43 |
baseURL = "https://api.anthropic.com"
|
| 44 |
}
|
|
|
|
| 112 |
|
| 113 |
func (e *ClaudeExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 114 |
apiKey, baseURL := claudeCreds(auth)
|
| 115 |
+
|
|
|
|
|
|
|
| 116 |
if baseURL == "" {
|
| 117 |
baseURL = "https://api.anthropic.com"
|
| 118 |
}
|
|
|
|
| 173 |
|
| 174 |
func (e *ClaudeExecutor) CountTokens(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 175 |
apiKey, baseURL := claudeCreds(auth)
|
| 176 |
+
|
|
|
|
|
|
|
| 177 |
if baseURL == "" {
|
| 178 |
baseURL = "https://api.anthropic.com"
|
| 179 |
}
|
internal/runtime/executor/client_executor.go
DELETED
|
@@ -1,185 +0,0 @@
|
|
| 1 |
-
package executor
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"context"
|
| 5 |
-
"errors"
|
| 6 |
-
"fmt"
|
| 7 |
-
"net/http"
|
| 8 |
-
"sync"
|
| 9 |
-
|
| 10 |
-
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
| 11 |
-
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
| 12 |
-
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/executor"
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
// ClientAdapter bridges legacy stateful clients to the new ProviderExecutor contract.
|
| 16 |
-
type ClientAdapter struct {
|
| 17 |
-
provider string
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
// NewClientAdapter creates a new adapter for the specified provider key.
|
| 21 |
-
func NewClientAdapter(provider string) *ClientAdapter {
|
| 22 |
-
return &ClientAdapter{provider: provider}
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
// Identifier implements cliproxyauth.ProviderExecutor.
|
| 26 |
-
func (a *ClientAdapter) Identifier() string {
|
| 27 |
-
return a.provider
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
// PrepareRequest implements optional request preparation hook (no-op for legacy clients).
|
| 31 |
-
func (a *ClientAdapter) PrepareRequest(req *http.Request, auth *cliproxyauth.Auth) error { return nil }
|
| 32 |
-
|
| 33 |
-
// Execute implements cliproxyauth.ProviderExecutor.
|
| 34 |
-
func (a *ClientAdapter) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 35 |
-
client, mutex, err := resolveLegacyClient(auth)
|
| 36 |
-
if err != nil {
|
| 37 |
-
return cliproxyexecutor.Response{}, err
|
| 38 |
-
}
|
| 39 |
-
unlock := lock(mutex)
|
| 40 |
-
defer unlock()
|
| 41 |
-
|
| 42 |
-
// Support special actions via request metadata (e.g., countTokens)
|
| 43 |
-
if req.Metadata != nil {
|
| 44 |
-
if action, _ := req.Metadata["action"].(string); action == "countTokens" {
|
| 45 |
-
if tc, ok := any(client).(interface {
|
| 46 |
-
SendRawTokenCount(ctx context.Context, modelName string, rawJSON []byte, alt string) ([]byte, *interfaces.ErrorMessage)
|
| 47 |
-
}); ok {
|
| 48 |
-
payload, errMsg := tc.SendRawTokenCount(ctx, req.Model, req.Payload, opts.Alt)
|
| 49 |
-
if errMsg != nil {
|
| 50 |
-
return cliproxyexecutor.Response{}, errorFromMessage(errMsg)
|
| 51 |
-
}
|
| 52 |
-
return cliproxyexecutor.Response{Payload: payload}, nil
|
| 53 |
-
}
|
| 54 |
-
return cliproxyexecutor.Response{}, fmt.Errorf("legacy client does not support countTokens")
|
| 55 |
-
}
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
payload, errMsg := client.SendRawMessage(ctx, req.Model, req.Payload, opts.Alt)
|
| 59 |
-
if errMsg != nil {
|
| 60 |
-
return cliproxyexecutor.Response{}, errorFromMessage(errMsg)
|
| 61 |
-
}
|
| 62 |
-
return cliproxyexecutor.Response{Payload: payload}, nil
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
// ExecuteStream implements cliproxyauth.ProviderExecutor.
|
| 66 |
-
func (a *ClientAdapter) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 67 |
-
client, mutex, err := resolveLegacyClient(auth)
|
| 68 |
-
if err != nil {
|
| 69 |
-
return nil, err
|
| 70 |
-
}
|
| 71 |
-
unlock := lock(mutex)
|
| 72 |
-
|
| 73 |
-
dataCh, errCh := client.SendRawMessageStream(ctx, req.Model, req.Payload, opts.Alt)
|
| 74 |
-
if dataCh == nil {
|
| 75 |
-
unlock()
|
| 76 |
-
if errCh != nil {
|
| 77 |
-
if msg := <-errCh; msg != nil {
|
| 78 |
-
return nil, errorFromMessage(msg)
|
| 79 |
-
}
|
| 80 |
-
}
|
| 81 |
-
return nil, errors.New("stream not available")
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
out := make(chan cliproxyexecutor.StreamChunk)
|
| 85 |
-
go func() {
|
| 86 |
-
defer close(out)
|
| 87 |
-
defer unlock()
|
| 88 |
-
for chunk := range dataCh {
|
| 89 |
-
if chunk == nil {
|
| 90 |
-
continue
|
| 91 |
-
}
|
| 92 |
-
out <- cliproxyexecutor.StreamChunk{Payload: chunk}
|
| 93 |
-
}
|
| 94 |
-
if errCh != nil {
|
| 95 |
-
if msg, ok := <-errCh; ok && msg != nil {
|
| 96 |
-
out <- cliproxyexecutor.StreamChunk{Err: errorFromMessage(msg)}
|
| 97 |
-
}
|
| 98 |
-
}
|
| 99 |
-
}()
|
| 100 |
-
return out, nil
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
func (e *ClientAdapter) CountTokens(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 104 |
-
return cliproxyexecutor.Response{Payload: []byte{}}, nil
|
| 105 |
-
}
|
| 106 |
-
|
| 107 |
-
// Refresh delegates to the legacy client's refresh logic when available.
|
| 108 |
-
func (a *ClientAdapter) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*cliproxyauth.Auth, error) {
|
| 109 |
-
client, _, err := resolveLegacyClient(auth)
|
| 110 |
-
if err != nil {
|
| 111 |
-
return nil, err
|
| 112 |
-
}
|
| 113 |
-
if refresher, ok := client.(interface{ RefreshTokens(context.Context) error }); ok {
|
| 114 |
-
if errRefresh := refresher.RefreshTokens(ctx); errRefresh != nil {
|
| 115 |
-
return nil, errRefresh
|
| 116 |
-
}
|
| 117 |
-
}
|
| 118 |
-
return auth, nil
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
// legacyClient defines the minimum surface required from the historical clients.
|
| 122 |
-
type legacyClient interface {
|
| 123 |
-
SendRawMessage(ctx context.Context, modelName string, rawJSON []byte, alt string) ([]byte, *interfaces.ErrorMessage)
|
| 124 |
-
SendRawMessageStream(ctx context.Context, modelName string, rawJSON []byte, alt string) (<-chan []byte, <-chan *interfaces.ErrorMessage)
|
| 125 |
-
GetRequestMutex() *sync.Mutex
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
func resolveLegacyClient(auth *cliproxyauth.Auth) (legacyClient, *sync.Mutex, error) {
|
| 129 |
-
if auth == nil {
|
| 130 |
-
return nil, nil, fmt.Errorf("legacy adapter: auth is nil")
|
| 131 |
-
}
|
| 132 |
-
client, ok := auth.Runtime.(legacyClient)
|
| 133 |
-
if !ok || client == nil {
|
| 134 |
-
return nil, nil, fmt.Errorf("legacy adapter: runtime client missing for %s", auth.ID)
|
| 135 |
-
}
|
| 136 |
-
return client, client.GetRequestMutex(), nil
|
| 137 |
-
}
|
| 138 |
-
|
| 139 |
-
func lock(mutex *sync.Mutex) func() {
|
| 140 |
-
if mutex == nil {
|
| 141 |
-
return func() {}
|
| 142 |
-
}
|
| 143 |
-
mutex.Lock()
|
| 144 |
-
return func() {
|
| 145 |
-
mutex.Unlock()
|
| 146 |
-
}
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
func errorFromMessage(msg *interfaces.ErrorMessage) error {
|
| 150 |
-
if msg == nil {
|
| 151 |
-
return nil
|
| 152 |
-
}
|
| 153 |
-
return legacyError{message: msg}
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
type legacyError struct {
|
| 157 |
-
message *interfaces.ErrorMessage
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
func (e legacyError) Error() string {
|
| 161 |
-
if e.message == nil {
|
| 162 |
-
return "legacy client error"
|
| 163 |
-
}
|
| 164 |
-
if e.message.Error != nil {
|
| 165 |
-
return e.message.Error.Error()
|
| 166 |
-
}
|
| 167 |
-
return fmt.Sprintf("legacy client error: status %d", e.message.StatusCode)
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
// StatusCode implements executor.StatusError, exposing HTTP-like status.
|
| 171 |
-
func (e legacyError) StatusCode() int {
|
| 172 |
-
if e.message != nil {
|
| 173 |
-
return e.message.StatusCode
|
| 174 |
-
}
|
| 175 |
-
return 0
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
// UnwrapError extracts the legacy interfaces.ErrorMessage from adapter errors.
|
| 179 |
-
func UnwrapError(err error) (*interfaces.ErrorMessage, bool) {
|
| 180 |
-
var legacy legacyError
|
| 181 |
-
if errors.As(err, &legacy) {
|
| 182 |
-
return legacy.message, true
|
| 183 |
-
}
|
| 184 |
-
return nil, false
|
| 185 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal/runtime/executor/codex_executor.go
CHANGED
|
@@ -41,9 +41,7 @@ func (e *CodexExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) er
|
|
| 41 |
|
| 42 |
func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 43 |
apiKey, baseURL := codexCreds(auth)
|
| 44 |
-
|
| 45 |
-
return NewClientAdapter("codex").Execute(ctx, auth, req, opts)
|
| 46 |
-
}
|
| 47 |
if baseURL == "" {
|
| 48 |
baseURL = "https://chatgpt.com/backend-api/codex"
|
| 49 |
}
|
|
@@ -136,9 +134,7 @@ func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, re
|
|
| 136 |
|
| 137 |
func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 138 |
apiKey, baseURL := codexCreds(auth)
|
| 139 |
-
|
| 140 |
-
return NewClientAdapter("codex").ExecuteStream(ctx, auth, req, opts)
|
| 141 |
-
}
|
| 142 |
if baseURL == "" {
|
| 143 |
baseURL = "https://chatgpt.com/backend-api/codex"
|
| 144 |
}
|
|
|
|
| 41 |
|
| 42 |
func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 43 |
apiKey, baseURL := codexCreds(auth)
|
| 44 |
+
|
|
|
|
|
|
|
| 45 |
if baseURL == "" {
|
| 46 |
baseURL = "https://chatgpt.com/backend-api/codex"
|
| 47 |
}
|
|
|
|
| 134 |
|
| 135 |
func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 136 |
apiKey, baseURL := codexCreds(auth)
|
| 137 |
+
|
|
|
|
|
|
|
| 138 |
if baseURL == "" {
|
| 139 |
baseURL = "https://chatgpt.com/backend-api/codex"
|
| 140 |
}
|
internal/runtime/executor/gemini_executor.go
CHANGED
|
@@ -40,10 +40,7 @@ func (e *GeminiExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) e
|
|
| 40 |
|
| 41 |
func (e *GeminiExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 42 |
apiKey, bearer := geminiCreds(auth)
|
| 43 |
-
|
| 44 |
-
// Fallback to legacy client
|
| 45 |
-
return NewClientAdapter("gemini").Execute(ctx, auth, req, opts)
|
| 46 |
-
}
|
| 47 |
reporter := newUsageReporter(ctx, e.Identifier(), req.Model, auth)
|
| 48 |
|
| 49 |
// Official Gemini API via API key or OAuth bearer
|
|
@@ -102,10 +99,7 @@ func (e *GeminiExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, r
|
|
| 102 |
|
| 103 |
func (e *GeminiExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 104 |
apiKey, bearer := geminiCreds(auth)
|
| 105 |
-
|
| 106 |
-
// Fallback to legacy streaming
|
| 107 |
-
return NewClientAdapter("gemini").ExecuteStream(ctx, auth, req, opts)
|
| 108 |
-
}
|
| 109 |
reporter := newUsageReporter(ctx, e.Identifier(), req.Model, auth)
|
| 110 |
|
| 111 |
from := opts.SourceFormat
|
|
|
|
| 40 |
|
| 41 |
func (e *GeminiExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 42 |
apiKey, bearer := geminiCreds(auth)
|
| 43 |
+
|
|
|
|
|
|
|
|
|
|
| 44 |
reporter := newUsageReporter(ctx, e.Identifier(), req.Model, auth)
|
| 45 |
|
| 46 |
// Official Gemini API via API key or OAuth bearer
|
|
|
|
| 99 |
|
| 100 |
func (e *GeminiExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 101 |
apiKey, bearer := geminiCreds(auth)
|
| 102 |
+
|
|
|
|
|
|
|
|
|
|
| 103 |
reporter := newUsageReporter(ctx, e.Identifier(), req.Model, auth)
|
| 104 |
|
| 105 |
from := opts.SourceFormat
|
internal/runtime/executor/qwen_executor.go
CHANGED
|
@@ -40,9 +40,7 @@ func (e *QwenExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) err
|
|
| 40 |
|
| 41 |
func (e *QwenExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 42 |
token, baseURL := qwenCreds(auth)
|
| 43 |
-
|
| 44 |
-
return NewClientAdapter("qwen").Execute(ctx, auth, req, opts)
|
| 45 |
-
}
|
| 46 |
if baseURL == "" {
|
| 47 |
baseURL = "https://portal.qwen.ai/v1"
|
| 48 |
}
|
|
@@ -88,9 +86,7 @@ func (e *QwenExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req
|
|
| 88 |
|
| 89 |
func (e *QwenExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 90 |
token, baseURL := qwenCreds(auth)
|
| 91 |
-
|
| 92 |
-
return NewClientAdapter("qwen").ExecuteStream(ctx, auth, req, opts)
|
| 93 |
-
}
|
| 94 |
if baseURL == "" {
|
| 95 |
baseURL = "https://portal.qwen.ai/v1"
|
| 96 |
}
|
|
|
|
| 40 |
|
| 41 |
func (e *QwenExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (cliproxyexecutor.Response, error) {
|
| 42 |
token, baseURL := qwenCreds(auth)
|
| 43 |
+
|
|
|
|
|
|
|
| 44 |
if baseURL == "" {
|
| 45 |
baseURL = "https://portal.qwen.ai/v1"
|
| 46 |
}
|
|
|
|
| 86 |
|
| 87 |
func (e *QwenExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (<-chan cliproxyexecutor.StreamChunk, error) {
|
| 88 |
token, baseURL := qwenCreds(auth)
|
| 89 |
+
|
|
|
|
|
|
|
| 90 |
if baseURL == "" {
|
| 91 |
baseURL = "https://portal.qwen.ai/v1"
|
| 92 |
}
|