1+ // Package executor provides runtime execution capabilities for various AI service providers.
2+ // This file implements the Gemini CLI executor that talks to Cloud Code Assist endpoints
3+ // using OAuth credentials from auth metadata.
14package executor
25
36import (
@@ -29,11 +32,11 @@ import (
2932const (
3033 codeAssistEndpoint = "https://cloudcode-pa.googleapis.com"
3134 codeAssistVersion = "v1internal"
32- geminiOauthClientID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
33- geminiOauthClientSecret = "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"
35+ geminiOAuthClientID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com"
36+ geminiOAuthClientSecret = "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"
3437)
3538
36- var geminiOauthScopes = []string {
39+ var geminiOAuthScopes = []string {
3740 "https://www.googleapis.com/auth/cloud-platform" ,
3841 "https://www.googleapis.com/auth/userinfo.email" ,
3942 "https://www.googleapis.com/auth/userinfo.profile" ,
@@ -44,14 +47,24 @@ type GeminiCLIExecutor struct {
4447 cfg * config.Config
4548}
4649
50+ // NewGeminiCLIExecutor creates a new Gemini CLI executor instance.
51+ //
52+ // Parameters:
53+ // - cfg: The application configuration
54+ //
55+ // Returns:
56+ // - *GeminiCLIExecutor: A new Gemini CLI executor instance
4757func NewGeminiCLIExecutor (cfg * config.Config ) * GeminiCLIExecutor {
4858 return & GeminiCLIExecutor {cfg : cfg }
4959}
5060
61+ // Identifier returns the executor identifier.
5162func (e * GeminiCLIExecutor ) Identifier () string { return "gemini-cli" }
5263
64+ // PrepareRequest prepares the HTTP request for execution (no-op for Gemini CLI).
5365func (e * GeminiCLIExecutor ) PrepareRequest (_ * http.Request , _ * cliproxyauth.Auth ) error { return nil }
5466
67+ // Execute performs a non-streaming request to the Gemini CLI API.
5568func (e * GeminiCLIExecutor ) Execute (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (resp cliproxyexecutor.Response , err error ) {
5669 tokenSource , baseTokenData , err := prepareGeminiCLITokenSource (ctx , e .cfg , auth )
5770 if err != nil {
@@ -189,6 +202,7 @@ func (e *GeminiCLIExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth
189202 return resp , err
190203}
191204
205+ // ExecuteStream performs a streaming request to the Gemini CLI API.
192206func (e * GeminiCLIExecutor ) ExecuteStream (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (stream <- chan cliproxyexecutor.StreamChunk , err error ) {
193207 tokenSource , baseTokenData , err := prepareGeminiCLITokenSource (ctx , e .cfg , auth )
194208 if err != nil {
@@ -309,7 +323,7 @@ func (e *GeminiCLIExecutor) ExecuteStream(ctx context.Context, auth *cliproxyaut
309323 }()
310324 if opts .Alt == "" {
311325 scanner := bufio .NewScanner (resp .Body )
312- scanner .Buffer (nil , 52_428_800 ) // 50MB
326+ scanner .Buffer (nil , streamScannerBuffer )
313327 var param any
314328 for scanner .Scan () {
315329 line := scanner .Bytes ()
@@ -371,6 +385,7 @@ func (e *GeminiCLIExecutor) ExecuteStream(ctx context.Context, auth *cliproxyaut
371385 return nil , err
372386}
373387
388+ // CountTokens counts tokens for the given request using the Gemini CLI API.
374389func (e * GeminiCLIExecutor ) CountTokens (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (cliproxyexecutor.Response , error ) {
375390 tokenSource , baseTokenData , err := prepareGeminiCLITokenSource (ctx , e .cfg , auth )
376391 if err != nil {
@@ -471,9 +486,8 @@ func (e *GeminiCLIExecutor) CountTokens(ctx context.Context, auth *cliproxyauth.
471486 return cliproxyexecutor.Response {}, newGeminiStatusErr (lastStatus , lastBody )
472487}
473488
474- func (e * GeminiCLIExecutor ) Refresh (ctx context.Context , auth * cliproxyauth.Auth ) (* cliproxyauth.Auth , error ) {
475- log .Debugf ("gemini cli executor: refresh called" )
476- _ = ctx
489+ // Refresh refreshes the authentication credentials (no-op for Gemini CLI).
490+ func (e * GeminiCLIExecutor ) Refresh (_ context.Context , auth * cliproxyauth.Auth ) (* cliproxyauth.Auth , error ) {
477491 return auth , nil
478492}
479493
@@ -515,9 +529,9 @@ func prepareGeminiCLITokenSource(ctx context.Context, cfg *config.Config, auth *
515529 }
516530
517531 conf := & oauth2.Config {
518- ClientID : geminiOauthClientID ,
519- ClientSecret : geminiOauthClientSecret ,
520- Scopes : geminiOauthScopes ,
532+ ClientID : geminiOAuthClientID ,
533+ ClientSecret : geminiOAuthClientSecret ,
534+ Scopes : geminiOAuthScopes ,
521535 Endpoint : google .Endpoint ,
522536 }
523537
0 commit comments