 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package claude provides request translation functionality for Claude Code API compatibility. This package handles the conversion of Claude Code API requests into Gemini CLI-compatible JSON format, transforming message contents, system instructions, and tool declarations into the format expected by Gemini CLI API clients. It performs JSON data transformation to ensure compatibility between Claude Code API format and Gemini CLI API's expected format.
Package claude provides response translation functionality for Claude Code API compatibility. This package handles the conversion of backend client responses into Claude Code-compatible Server-Sent Events (SSE) format, implementing a sophisticated state machine that manages different response types including text content, thinking processes, and function calls. The translation ensures proper sequencing of SSE events and maintains state across multiple response chunks to provide a seamless streaming experience.
Index ¶
- func ClaudeTokenCount(ctx context.Context, count int64) string
- func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) []byte
- func ConvertGeminiCLIResponseToClaude(_ context.Context, _ string, ...) []string
- func ConvertGeminiCLIResponseToClaudeNonStream(_ context.Context, _ string, ...) string
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertClaudeRequestToCLI ¶
ConvertClaudeRequestToCLI parses and transforms a Claude Code API request into Gemini CLI API format. It extracts the model name, system instruction, message contents, and tool declarations from the raw JSON request and returns them in the format expected by the Gemini CLI API. The function performs the following transformations: 1. Extracts the model information from the request 2. Restructures the JSON to match Gemini CLI API format 3. Converts system instructions to the expected format 4. Maps message contents with proper role transformations 5. Handles tool declarations and tool choices 6. Maps generation configuration parameters
Parameters:
- modelName: The name of the model to use for the request
- rawJSON: The raw JSON request data from the Claude Code API
- stream: A boolean indicating if the request is for a streaming response (unused in current implementation)
Returns:
- []byte: The transformed request data in Gemini CLI API format
func ConvertGeminiCLIResponseToClaude ¶
func ConvertGeminiCLIResponseToClaude(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
ConvertGeminiCLIResponseToClaude performs sophisticated streaming response format conversion. This function implements a complex state machine that translates backend client responses into Claude Code-compatible Server-Sent Events (SSE) format. It manages different response types and handles state transitions between content blocks, thinking processes, and function calls.
Response type states: 0=none, 1=content, 2=thinking, 3=function The function maintains state across multiple calls to ensure proper SSE event sequencing.
Parameters:
- ctx: The context for the request, used for cancellation and timeout handling
- modelName: The name of the model being used for the response (unused in current implementation)
- rawJSON: The raw JSON response from the Gemini CLI API
- param: A pointer to a parameter object for maintaining state between calls
Returns:
- []string: A slice of strings, each containing a Claude Code-compatible JSON response
func ConvertGeminiCLIResponseToClaudeNonStream ¶
func ConvertGeminiCLIResponseToClaudeNonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string
ConvertGeminiCLIResponseToClaudeNonStream converts a non-streaming Gemini CLI response to a non-streaming Claude response.
Parameters:
- ctx: The context for the request.
- modelName: The name of the model.
- rawJSON: The raw JSON response from the Gemini CLI API.
- param: A pointer to a parameter object for the conversion.
Returns:
- string: A Claude-compatible JSON response.
Types ¶
type Params ¶
type Params struct {
	HasFirstResponse bool // Indicates if the initial message_start event has been sent
	ResponseType     int  // Current response type: 0=none, 1=content, 2=thinking, 3=function
	ResponseIndex    int  // Index counter for content blocks in the streaming response
}
    Params holds parameters for response conversion and maintains state across streaming chunks. This structure tracks the current state of the response translation process to ensure proper sequencing of SSE events and transitions between different content types.