Help us shape the future of Go! Take the 2026 Go Developer Survey

executor

package
v0.0.0-...-e4647ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

Package executor provides runtime execution capabilities for various AI service providers. This file implements the AI Studio executor that routes requests through a websocket-backed transport for the AI Studio provider.

Package executor provides runtime execution capabilities for various AI service providers. This file implements the Antigravity executor that proxies requests to the antigravity upstream using OAuth credentials.

Package executor provides runtime execution capabilities for various AI service providers. This file implements the Gemini CLI executor that talks to Cloud Code Assist endpoints using OAuth credentials from auth metadata.

Package executor provides runtime execution capabilities for various AI service providers. It includes stateless executors that handle API requests, streaming responses, token counting, and authentication refresh for different AI service providers.

Package executor provides runtime execution capabilities for various AI service providers. This file implements the Vertex AI Gemini executor that talks to Google Vertex AI endpoints using service account credentials or API keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyReasoningEffortMetadata

func ApplyReasoningEffortMetadata(payload []byte, metadata map[string]any, model, field string, allowCompat bool) []byte

ApplyReasoningEffortMetadata applies reasoning effort overrides from metadata to the given JSON path. Metadata values take precedence over any existing field when the model supports thinking, intentionally overwriting caller-provided values to honor suffix/default metadata priority.

func ApplyThinkingMetadata

func ApplyThinkingMetadata(payload []byte, metadata map[string]any, model string) []byte

ApplyThinkingMetadata applies thinking config from model suffix metadata (e.g., (high), (8192)) for standard Gemini format payloads. It normalizes the budget when the model supports thinking.

func ApplyThinkingMetadataCLI

func ApplyThinkingMetadataCLI(payload []byte, metadata map[string]any, model string) []byte

ApplyThinkingMetadataCLI applies thinking config from model suffix metadata (e.g., (high), (8192)) for Gemini CLI format payloads (nested under "request"). It normalizes the budget when the model supports thinking.

func FetchAntigravityModels

func FetchAntigravityModels(ctx context.Context, auth *cliproxyauth.Auth, cfg *config.Config) []*registry.ModelInfo

FetchAntigravityModels retrieves available models using the supplied auth.

func FilterSSEUsageMetadata

func FilterSSEUsageMetadata(payload []byte) []byte

FilterSSEUsageMetadata removes usageMetadata from SSE events that are not terminal (finishReason != "stop"). Stop chunks are left untouched. This function is shared between aistudio and antigravity executors.

func NormalizeReasoningEffortLevel

func NormalizeReasoningEffortLevel(payload []byte, model string) []byte

NormalizeReasoningEffortLevel validates and normalizes the reasoning_effort or reasoning.effort field for level-based thinking models.

func NormalizeThinkingConfig

func NormalizeThinkingConfig(payload []byte, model string, allowCompat bool) []byte

NormalizeThinkingConfig normalizes thinking-related fields in the payload based on model capabilities. For models without thinking support, it strips reasoning fields. For models with level-based thinking, it validates and normalizes the reasoning effort level. For models with numeric budget thinking, it strips the effort string fields.

func StripThinkingFields

func StripThinkingFields(payload []byte, effortOnly bool) []byte

StripThinkingFields removes thinking-related fields from the payload for models that do not support thinking. If effortOnly is true, only removes effort string fields (for models using numeric budgets).

func StripUsageMetadataFromJSON

func StripUsageMetadataFromJSON(rawJSON []byte) ([]byte, bool)

StripUsageMetadataFromJSON drops usageMetadata unless finishReason is present (terminal). It handles both formats: - Aistudio: candidates.0.finishReason - Antigravity: response.candidates.0.finishReason

func ValidateThinkingConfig

func ValidateThinkingConfig(payload []byte, model string) error

ValidateThinkingConfig checks for unsupported reasoning levels on level-based models. Returns a statusErr with 400 when an unsupported level is supplied to avoid silently downgrading requests.

Types

type AIStudioExecutor

type AIStudioExecutor struct {
	// contains filtered or unexported fields
}

AIStudioExecutor routes AI Studio requests through a websocket-backed transport.

func NewAIStudioExecutor

func NewAIStudioExecutor(cfg *config.Config, provider string, relay *wsrelay.Manager) *AIStudioExecutor

NewAIStudioExecutor creates a new AI Studio executor instance.

Parameters:

  • cfg: The application configuration
  • provider: The provider name
  • relay: The websocket relay manager

Returns:

  • *AIStudioExecutor: A new AI Studio executor instance

func (*AIStudioExecutor) CountTokens

CountTokens counts tokens for the given request using the AI Studio API.

func (*AIStudioExecutor) Execute

Execute performs a non-streaming request to the AI Studio API.

func (*AIStudioExecutor) ExecuteStream

ExecuteStream performs a streaming request to the AI Studio API.

func (*AIStudioExecutor) Identifier

func (e *AIStudioExecutor) Identifier() string

Identifier returns the executor identifier.

func (*AIStudioExecutor) PrepareRequest

func (e *AIStudioExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest prepares the HTTP request for execution (no-op for AI Studio).

func (*AIStudioExecutor) Refresh

Refresh refreshes the authentication credentials (no-op for AI Studio).

type AntigravityExecutor

type AntigravityExecutor struct {
	// contains filtered or unexported fields
}

AntigravityExecutor proxies requests to the antigravity upstream.

func NewAntigravityExecutor

func NewAntigravityExecutor(cfg *config.Config) *AntigravityExecutor

NewAntigravityExecutor creates a new Antigravity executor instance.

Parameters:

  • cfg: The application configuration

Returns:

  • *AntigravityExecutor: A new Antigravity executor instance

func (*AntigravityExecutor) CountTokens

CountTokens counts tokens for the given request using the Antigravity API.

func (*AntigravityExecutor) Execute

Execute performs a non-streaming request to the Antigravity API.

func (*AntigravityExecutor) ExecuteStream

ExecuteStream performs a streaming request to the Antigravity API.

func (*AntigravityExecutor) Identifier

func (e *AntigravityExecutor) Identifier() string

Identifier returns the executor identifier.

func (*AntigravityExecutor) PrepareRequest

func (e *AntigravityExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest prepares the HTTP request for execution (no-op for Antigravity).

func (*AntigravityExecutor) Refresh

Refresh refreshes the authentication credentials using the refresh token.

type ClaudeExecutor

type ClaudeExecutor struct {
	// contains filtered or unexported fields
}

ClaudeExecutor is a stateless executor for Anthropic Claude over the messages API. If api_key is unavailable on auth, it falls back to legacy via ClientAdapter.

func NewClaudeExecutor

func NewClaudeExecutor(cfg *config.Config) *ClaudeExecutor

func (*ClaudeExecutor) Execute

func (*ClaudeExecutor) ExecuteStream

func (*ClaudeExecutor) Identifier

func (e *ClaudeExecutor) Identifier() string

func (*ClaudeExecutor) PrepareRequest

func (e *ClaudeExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

func (*ClaudeExecutor) Refresh

type CodexExecutor

type CodexExecutor struct {
	// contains filtered or unexported fields
}

CodexExecutor is a stateless executor for Codex (OpenAI Responses API entrypoint). If api_key is unavailable on auth, it falls back to legacy via ClientAdapter.

func NewCodexExecutor

func NewCodexExecutor(cfg *config.Config) *CodexExecutor

func (*CodexExecutor) Execute

func (*CodexExecutor) ExecuteStream

func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (stream <-chan cliproxyexecutor.StreamChunk, err error)

func (*CodexExecutor) Identifier

func (e *CodexExecutor) Identifier() string

func (*CodexExecutor) PrepareRequest

func (e *CodexExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

func (*CodexExecutor) Refresh

func (e *CodexExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*cliproxyauth.Auth, error)

type CopilotExecutor

type CopilotExecutor struct {
	// contains filtered or unexported fields
}

CopilotExecutor is a stateless executor for GitHub Copilot using OpenAI-compatible chat completions.

func NewCopilotExecutor

func NewCopilotExecutor(cfg *config.Config) *CopilotExecutor

func (*CopilotExecutor) CountTokens

CountTokens returns the token count for the given request

func (*CopilotExecutor) Execute

func (*CopilotExecutor) ExecuteStream

func (*CopilotExecutor) Identifier

func (e *CopilotExecutor) Identifier() string

func (*CopilotExecutor) PrepareRequest

func (e *CopilotExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

func (*CopilotExecutor) Refresh

Refresh refreshes the Copilot token using the stored GitHub token

type GeminiCLIExecutor

type GeminiCLIExecutor struct {
	// contains filtered or unexported fields
}

GeminiCLIExecutor talks to the Cloud Code Assist endpoint using OAuth credentials from auth metadata.

func NewGeminiCLIExecutor

func NewGeminiCLIExecutor(cfg *config.Config) *GeminiCLIExecutor

NewGeminiCLIExecutor creates a new Gemini CLI executor instance.

Parameters:

  • cfg: The application configuration

Returns:

  • *GeminiCLIExecutor: A new Gemini CLI executor instance

func (*GeminiCLIExecutor) CountTokens

CountTokens counts tokens for the given request using the Gemini CLI API.

func (*GeminiCLIExecutor) Execute

Execute performs a non-streaming request to the Gemini CLI API.

func (*GeminiCLIExecutor) ExecuteStream

ExecuteStream performs a streaming request to the Gemini CLI API.

func (*GeminiCLIExecutor) Identifier

func (e *GeminiCLIExecutor) Identifier() string

Identifier returns the executor identifier.

func (*GeminiCLIExecutor) PrepareRequest

func (e *GeminiCLIExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest prepares the HTTP request for execution (no-op for Gemini CLI).

func (*GeminiCLIExecutor) Refresh

Refresh refreshes the authentication credentials (no-op for Gemini CLI).

type GeminiExecutor

type GeminiExecutor struct {
	// contains filtered or unexported fields
}

GeminiExecutor is a stateless executor for the official Gemini API using API keys. It handles both API key and OAuth bearer token authentication, supporting both regular and streaming requests to the Google Generative Language API.

func NewGeminiExecutor

func NewGeminiExecutor(cfg *config.Config) *GeminiExecutor

NewGeminiExecutor creates a new Gemini executor instance.

Parameters:

  • cfg: The application configuration

Returns:

  • *GeminiExecutor: A new Gemini executor instance

func (*GeminiExecutor) CountTokens

CountTokens counts tokens for the given request using the Gemini API.

func (*GeminiExecutor) Execute

Execute performs a non-streaming request to the Gemini API. It translates the request to Gemini format, sends it to the API, and translates the response back to the requested format.

Parameters:

  • ctx: The context for the request
  • auth: The authentication information
  • req: The request to execute
  • opts: Additional execution options

Returns:

  • cliproxyexecutor.Response: The response from the API
  • error: An error if the request fails

func (*GeminiExecutor) ExecuteStream

ExecuteStream performs a streaming request to the Gemini API.

func (*GeminiExecutor) Identifier

func (e *GeminiExecutor) Identifier() string

Identifier returns the executor identifier.

func (*GeminiExecutor) PrepareRequest

func (e *GeminiExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest prepares the HTTP request for execution (no-op for Gemini).

func (*GeminiExecutor) Refresh

Refresh refreshes the authentication credentials (no-op for Gemini API key).

type GeminiVertexExecutor

type GeminiVertexExecutor struct {
	// contains filtered or unexported fields
}

GeminiVertexExecutor sends requests to Vertex AI Gemini endpoints using service account credentials.

func NewGeminiVertexExecutor

func NewGeminiVertexExecutor(cfg *config.Config) *GeminiVertexExecutor

NewGeminiVertexExecutor creates a new Vertex AI Gemini executor instance.

Parameters:

  • cfg: The application configuration

Returns:

  • *GeminiVertexExecutor: A new Vertex AI Gemini executor instance

func (*GeminiVertexExecutor) CountTokens

CountTokens counts tokens for the given request using the Vertex AI API.

func (*GeminiVertexExecutor) Execute

Execute performs a non-streaming request to the Vertex AI API.

func (*GeminiVertexExecutor) ExecuteStream

ExecuteStream performs a streaming request to the Vertex AI API.

func (*GeminiVertexExecutor) Identifier

func (e *GeminiVertexExecutor) Identifier() string

Identifier returns the executor identifier.

func (*GeminiVertexExecutor) PrepareRequest

func (e *GeminiVertexExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest prepares the HTTP request for execution (no-op for Vertex).

func (*GeminiVertexExecutor) Refresh

Refresh refreshes the authentication credentials (no-op for Vertex).

type IFlowExecutor

type IFlowExecutor struct {
	// contains filtered or unexported fields
}

IFlowExecutor executes OpenAI-compatible chat completions against the iFlow API using API keys derived from OAuth.

func NewIFlowExecutor

func NewIFlowExecutor(cfg *config.Config) *IFlowExecutor

NewIFlowExecutor constructs a new executor instance.

func (*IFlowExecutor) Execute

Execute performs a non-streaming chat completion request.

func (*IFlowExecutor) ExecuteStream

func (e *IFlowExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (stream <-chan cliproxyexecutor.StreamChunk, err error)

ExecuteStream performs a streaming chat completion request.

func (*IFlowExecutor) Identifier

func (e *IFlowExecutor) Identifier() string

Identifier returns the provider key.

func (*IFlowExecutor) PrepareRequest

func (e *IFlowExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest implements ProviderExecutor but requires no preprocessing.

func (*IFlowExecutor) Refresh

func (e *IFlowExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*cliproxyauth.Auth, error)

Refresh refreshes OAuth tokens or cookie-based API keys and updates the stored API key.

type OpenAICompatExecutor

type OpenAICompatExecutor struct {
	// contains filtered or unexported fields
}

OpenAICompatExecutor implements a stateless executor for OpenAI-compatible providers. It performs request/response translation and executes against the provider base URL using per-auth credentials (API key) and per-auth HTTP transport (proxy) from context.

func NewOpenAICompatExecutor

func NewOpenAICompatExecutor(provider string, cfg *config.Config) *OpenAICompatExecutor

NewOpenAICompatExecutor creates an executor bound to a provider key (e.g., "openrouter").

func (*OpenAICompatExecutor) CountTokens

func (*OpenAICompatExecutor) Execute

func (*OpenAICompatExecutor) ExecuteStream

func (*OpenAICompatExecutor) Identifier

func (e *OpenAICompatExecutor) Identifier() string

Identifier implements cliproxyauth.ProviderExecutor.

func (*OpenAICompatExecutor) PrepareRequest

func (e *OpenAICompatExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

PrepareRequest is a no-op for now (credentials are added via headers at execution time).

func (*OpenAICompatExecutor) Refresh

Refresh is a no-op for API-key based compatibility providers.

type QwenExecutor

type QwenExecutor struct {
	// contains filtered or unexported fields
}

QwenExecutor is a stateless executor for Qwen Code using OpenAI-compatible chat completions. If access token is unavailable, it falls back to legacy via ClientAdapter.

func NewQwenExecutor

func NewQwenExecutor(cfg *config.Config) *QwenExecutor

func (*QwenExecutor) Execute

func (*QwenExecutor) ExecuteStream

func (e *QwenExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) (stream <-chan cliproxyexecutor.StreamChunk, err error)

func (*QwenExecutor) Identifier

func (e *QwenExecutor) Identifier() string

func (*QwenExecutor) PrepareRequest

func (e *QwenExecutor) PrepareRequest(_ *http.Request, _ *cliproxyauth.Auth) error

func (*QwenExecutor) Refresh

func (e *QwenExecutor) Refresh(ctx context.Context, auth *cliproxyauth.Auth) (*cliproxyauth.Auth, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL