mirror of
https://github.com/githubhjs/CLIProxyAPIPlus.git
synced 2026-07-14 10:35:24 +00:00
feat(executor): add HttpRequest method with credential injection for GitHub Copilot and Kiro executors
This commit is contained in:
@@ -63,9 +63,37 @@ func NewGitHubCopilotExecutor(cfg *config.Config) *GitHubCopilotExecutor {
|
|||||||
func (e *GitHubCopilotExecutor) Identifier() string { return githubCopilotAuthType }
|
func (e *GitHubCopilotExecutor) Identifier() string { return githubCopilotAuthType }
|
||||||
|
|
||||||
// PrepareRequest implements ProviderExecutor.
|
// PrepareRequest implements ProviderExecutor.
|
||||||
func (e *GitHubCopilotExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error {
|
func (e *GitHubCopilotExecutor) PrepareRequest(req *http.Request, auth *cliproxyauth.Auth) error {
|
||||||
|
if req == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
ctx := req.Context()
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = context.Background()
|
||||||
|
}
|
||||||
|
apiToken, errToken := e.ensureAPIToken(ctx, auth)
|
||||||
|
if errToken != nil {
|
||||||
|
return errToken
|
||||||
|
}
|
||||||
|
e.applyHeaders(req, apiToken)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// HttpRequest injects GitHub Copilot credentials into the request and executes it.
|
||||||
|
func (e *GitHubCopilotExecutor) HttpRequest(ctx context.Context, auth *cliproxyauth.Auth, req *http.Request) (*http.Response, error) {
|
||||||
|
if req == nil {
|
||||||
|
return nil, fmt.Errorf("github-copilot executor: request is nil")
|
||||||
|
}
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = req.Context()
|
||||||
|
}
|
||||||
|
httpReq := req.WithContext(ctx)
|
||||||
|
if errPrepare := e.PrepareRequest(httpReq, auth); errPrepare != nil {
|
||||||
|
return nil, errPrepare
|
||||||
|
}
|
||||||
|
httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0)
|
||||||
|
return httpClient.Do(httpReq)
|
||||||
|
}
|
||||||
|
|
||||||
// Execute handles non-streaming requests to GitHub Copilot.
|
// Execute handles non-streaming requests to GitHub Copilot.
|
||||||
func (e *GitHubCopilotExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (resp cliproxyexecutor.Response, err error) {
|
func (e *GitHubCopilotExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (resp cliproxyexecutor.Response, err error) {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/usage"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/usage"
|
||||||
sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator"
|
sdktranslator "github.com/router-for-me/CLIProxyAPI/v6/sdk/translator"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -218,7 +217,48 @@ func NewKiroExecutor(cfg *config.Config) *KiroExecutor {
|
|||||||
func (e *KiroExecutor) Identifier() string { return "kiro" }
|
func (e *KiroExecutor) Identifier() string { return "kiro" }
|
||||||
|
|
||||||
// PrepareRequest prepares the HTTP request before execution.
|
// PrepareRequest prepares the HTTP request before execution.
|
||||||
func (e *KiroExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error { return nil }
|
func (e *KiroExecutor) PrepareRequest(req *http.Request, auth *cliproxyauth.Auth) error {
|
||||||
|
if req == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
accessToken, _ := kiroCredentials(auth)
|
||||||
|
if strings.TrimSpace(accessToken) == "" {
|
||||||
|
return statusErr{code: http.StatusUnauthorized, msg: "missing access token"}
|
||||||
|
}
|
||||||
|
if isIDCAuth(auth) {
|
||||||
|
req.Header.Set("User-Agent", kiroIDEUserAgent)
|
||||||
|
req.Header.Set("X-Amz-User-Agent", kiroIDEAmzUserAgent)
|
||||||
|
req.Header.Set("x-amzn-kiro-agent-mode", kiroIDEAgentModeSpec)
|
||||||
|
} else {
|
||||||
|
req.Header.Set("User-Agent", kiroUserAgent)
|
||||||
|
req.Header.Set("X-Amz-User-Agent", kiroFullUserAgent)
|
||||||
|
}
|
||||||
|
req.Header.Set("Amz-Sdk-Request", "attempt=1; max=3")
|
||||||
|
req.Header.Set("Amz-Sdk-Invocation-Id", uuid.New().String())
|
||||||
|
req.Header.Set("Authorization", "Bearer "+accessToken)
|
||||||
|
var attrs map[string]string
|
||||||
|
if auth != nil {
|
||||||
|
attrs = auth.Attributes
|
||||||
|
}
|
||||||
|
util.ApplyCustomHeadersFromAttrs(req, attrs)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// HttpRequest injects Kiro credentials into the request and executes it.
|
||||||
|
func (e *KiroExecutor) HttpRequest(ctx context.Context, auth *cliproxyauth.Auth, req *http.Request) (*http.Response, error) {
|
||||||
|
if req == nil {
|
||||||
|
return nil, fmt.Errorf("kiro executor: request is nil")
|
||||||
|
}
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = req.Context()
|
||||||
|
}
|
||||||
|
httpReq := req.WithContext(ctx)
|
||||||
|
if errPrepare := e.PrepareRequest(httpReq, auth); errPrepare != nil {
|
||||||
|
return nil, errPrepare
|
||||||
|
}
|
||||||
|
httpClient := newProxyAwareHTTPClient(ctx, e.cfg, auth, 0)
|
||||||
|
return httpClient.Do(httpReq)
|
||||||
|
}
|
||||||
|
|
||||||
// Execute sends the request to Kiro API and returns the response.
|
// Execute sends the request to Kiro API and returns the response.
|
||||||
// Supports automatic token refresh on 401/403 errors.
|
// Supports automatic token refresh on 401/403 errors.
|
||||||
@@ -1852,7 +1892,6 @@ func (e *KiroExecutor) extractEventTypeFromBytes(headers []byte) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Response building functions moved to internal/translator/kiro/claude/kiro_claude_response.go
|
// NOTE: Response building functions moved to internal/translator/kiro/claude/kiro_claude_response.go
|
||||||
// The executor now uses kiroclaude.BuildClaudeResponse() and kiroclaude.ExtractThinkingFromContent() instead
|
// The executor now uses kiroclaude.BuildClaudeResponse() and kiroclaude.ExtractThinkingFromContent() instead
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user