@@ -19,27 +19,27 @@ import (
1919 "github.com/tidwall/sjson"
2020)
2121
22- // AistudioExecutor routes AI Studio requests through a websocket-backed transport.
23- type AistudioExecutor struct {
22+ // AIStudioExecutor routes AI Studio requests through a websocket-backed transport.
23+ type AIStudioExecutor struct {
2424 provider string
2525 relay * wsrelay.Manager
2626 cfg * config.Config
2727}
2828
29- // NewAistudioExecutor constructs a websocket executor for the provider name.
30- func NewAistudioExecutor (cfg * config.Config , provider string , relay * wsrelay.Manager ) * AistudioExecutor {
31- return & AistudioExecutor {provider : strings .ToLower (provider ), relay : relay , cfg : cfg }
29+ // NewAIStudioExecutor constructs a websocket executor for the provider name.
30+ func NewAIStudioExecutor (cfg * config.Config , provider string , relay * wsrelay.Manager ) * AIStudioExecutor {
31+ return & AIStudioExecutor {provider : strings .ToLower (provider ), relay : relay , cfg : cfg }
3232}
3333
34- // Identifier returns the provider key served by this executor .
35- func (e * AistudioExecutor ) Identifier () string { return e . provider }
34+ // Identifier returns the logical provider key for routing .
35+ func (e * AIStudioExecutor ) Identifier () string { return "aistudio" }
3636
3737// PrepareRequest is a no-op because websocket transport already injects headers.
38- func (e * AistudioExecutor ) PrepareRequest (_ * http.Request , _ * cliproxyauth.Auth ) error {
38+ func (e * AIStudioExecutor ) PrepareRequest (_ * http.Request , _ * cliproxyauth.Auth ) error {
3939 return nil
4040}
4141
42- func (e * AistudioExecutor ) Execute (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (resp cliproxyexecutor.Response , err error ) {
42+ func (e * AIStudioExecutor ) Execute (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (resp cliproxyexecutor.Response , err error ) {
4343 reporter := newUsageReporter (ctx , e .Identifier (), req .Model , auth )
4444 defer reporter .trackFailure (ctx , & err )
4545
@@ -66,14 +66,14 @@ func (e *AistudioExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth,
6666 Method : http .MethodPost ,
6767 Headers : wsReq .Headers .Clone (),
6868 Body : bytes .Clone (body .payload ),
69- Provider : e .provider ,
69+ Provider : e .Identifier () ,
7070 AuthID : authID ,
7171 AuthLabel : authLabel ,
7272 AuthType : authType ,
7373 AuthValue : authValue ,
7474 })
7575
76- wsResp , err := e .relay .NonStream (ctx , e . provider , wsReq )
76+ wsResp , err := e .relay .NonStream (ctx , authID , wsReq )
7777 if err != nil {
7878 recordAPIResponseError (ctx , e .cfg , err )
7979 return resp , err
@@ -92,7 +92,7 @@ func (e *AistudioExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth,
9292 return resp , nil
9393}
9494
95- func (e * AistudioExecutor ) ExecuteStream (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (stream <- chan cliproxyexecutor.StreamChunk , err error ) {
95+ func (e * AIStudioExecutor ) ExecuteStream (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (stream <- chan cliproxyexecutor.StreamChunk , err error ) {
9696 reporter := newUsageReporter (ctx , e .Identifier (), req .Model , auth )
9797 defer reporter .trackFailure (ctx , & err )
9898
@@ -118,13 +118,13 @@ func (e *AistudioExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth
118118 Method : http .MethodPost ,
119119 Headers : wsReq .Headers .Clone (),
120120 Body : bytes .Clone (body .payload ),
121- Provider : e .provider ,
121+ Provider : e .Identifier () ,
122122 AuthID : authID ,
123123 AuthLabel : authLabel ,
124124 AuthType : authType ,
125125 AuthValue : authValue ,
126126 })
127- wsStream , err := e .relay .Stream (ctx , e . provider , wsReq )
127+ wsStream , err := e .relay .Stream (ctx , authID , wsReq )
128128 if err != nil {
129129 recordAPIResponseError (ctx , e .cfg , err )
130130 return nil , err
@@ -151,7 +151,7 @@ func (e *AistudioExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth
151151 case wsrelay .MessageTypeStreamChunk :
152152 if len (event .Payload ) > 0 {
153153 appendAPIResponseChunk (ctx , e .cfg , bytes .Clone (event .Payload ))
154- filtered := filterAistudioUsageMetadata (event .Payload )
154+ filtered := filterAIStudioUsageMetadata (event .Payload )
155155 if detail , ok := parseGeminiStreamUsage (filtered ); ok {
156156 reporter .publish (ctx , detail )
157157 }
@@ -188,7 +188,7 @@ func (e *AistudioExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth
188188 return stream , nil
189189}
190190
191- func (e * AistudioExecutor ) CountTokens (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (cliproxyexecutor.Response , error ) {
191+ func (e * AIStudioExecutor ) CountTokens (ctx context.Context , auth * cliproxyauth.Auth , req cliproxyexecutor.Request , opts cliproxyexecutor.Options ) (cliproxyexecutor.Response , error ) {
192192 _ , body , err := e .translateRequest (req , opts , false )
193193 if err != nil {
194194 return cliproxyexecutor.Response {}, err
@@ -215,13 +215,13 @@ func (e *AistudioExecutor) CountTokens(ctx context.Context, auth *cliproxyauth.A
215215 Method : http .MethodPost ,
216216 Headers : wsReq .Headers .Clone (),
217217 Body : bytes .Clone (body .payload ),
218- Provider : e .provider ,
218+ Provider : e .Identifier () ,
219219 AuthID : authID ,
220220 AuthLabel : authLabel ,
221221 AuthType : authType ,
222222 AuthValue : authValue ,
223223 })
224- resp , err := e .relay .NonStream (ctx , e . provider , wsReq )
224+ resp , err := e .relay .NonStream (ctx , authID , wsReq )
225225 if err != nil {
226226 recordAPIResponseError (ctx , e .cfg , err )
227227 return cliproxyexecutor.Response {}, err
@@ -241,7 +241,7 @@ func (e *AistudioExecutor) CountTokens(ctx context.Context, auth *cliproxyauth.A
241241 return cliproxyexecutor.Response {Payload : []byte (translated )}, nil
242242}
243243
244- func (e * AistudioExecutor ) Refresh (ctx context.Context , auth * cliproxyauth.Auth ) (* cliproxyauth.Auth , error ) {
244+ func (e * AIStudioExecutor ) Refresh (ctx context.Context , auth * cliproxyauth.Auth ) (* cliproxyauth.Auth , error ) {
245245 _ = ctx
246246 return auth , nil
247247}
@@ -252,7 +252,7 @@ type translatedPayload struct {
252252 toFormat sdktranslator.Format
253253}
254254
255- func (e * AistudioExecutor ) translateRequest (req cliproxyexecutor.Request , opts cliproxyexecutor.Options , stream bool ) ([]byte , translatedPayload , error ) {
255+ func (e * AIStudioExecutor ) translateRequest (req cliproxyexecutor.Request , opts cliproxyexecutor.Options , stream bool ) ([]byte , translatedPayload , error ) {
256256 from := opts .SourceFormat
257257 to := sdktranslator .FromString ("gemini" )
258258 payload := sdktranslator .TranslateRequest (from , to , req .Model , bytes .Clone (req .Payload ), stream )
@@ -275,7 +275,7 @@ func (e *AistudioExecutor) translateRequest(req cliproxyexecutor.Request, opts c
275275 return payload , translatedPayload {payload : payload , action : action , toFormat : to }, nil
276276}
277277
278- func (e * AistudioExecutor ) buildEndpoint (model , action , alt string ) string {
278+ func (e * AIStudioExecutor ) buildEndpoint (model , action , alt string ) string {
279279 base := fmt .Sprintf ("%s/%s/models/%s:%s" , glEndpoint , glAPIVersion , model , action )
280280 if action == "streamGenerateContent" {
281281 if alt == "" {
@@ -289,9 +289,9 @@ func (e *AistudioExecutor) buildEndpoint(model, action, alt string) string {
289289 return base
290290}
291291
292- // filterAistudioUsageMetadata removes usageMetadata from intermediate SSE events so that
292+ // filterAIStudioUsageMetadata removes usageMetadata from intermediate SSE events so that
293293// only the terminal chunk retains token statistics.
294- func filterAistudioUsageMetadata (payload []byte ) []byte {
294+ func filterAIStudioUsageMetadata (payload []byte ) []byte {
295295 if len (payload ) == 0 {
296296 return payload
297297 }
0 commit comments