Documentation
¶
Overview ¶
Package claude provides request translation functionality for Claude Code API compatibility. It handles parsing and transforming Claude Code API requests into the internal client format, extracting model information, system instructions, message contents, and tool declarations. The package also performs JSON data cleaning and transformation to ensure compatibility between Claude Code API format and the internal client's expected format.
Package claude provides response translation functionality for Codex to Claude Code API compatibility. This package handles the conversion of Codex API 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 ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool) []byte
- func ConvertCodexResponseToClaude(_ context.Context, _ string, ...) []string
- func ConvertCodexResponseToClaudeNonStream(_ context.Context, _ string, originalRequestRawJSON, _ []byte, rawJSON []byte, ...) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaudeTokenCount ¶ added in v6.2.33
func ConvertClaudeRequestToCodex ¶
ConvertClaudeRequestToCodex parses and transforms a Claude Code API request into the internal client 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 internal client. The function performs the following transformations: 1. Sets up a template with the model name and Codex instructions 2. Processes system messages and converts them to input content 3. Transforms message contents (text, tool_use, tool_result) to appropriate formats 4. Converts tools declarations to the expected format 5. Adds additional configuration parameters for the Codex API 6. Prepends a special instruction message to override system instructions
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 internal client format
func ConvertCodexResponseToClaude ¶
func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any) []string
ConvertCodexResponseToClaude performs sophisticated streaming response format conversion. This function implements a complex state machine that translates Codex API 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 Codex 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 ConvertCodexResponseToClaudeNonStream ¶
func ConvertCodexResponseToClaudeNonStream(_ context.Context, _ string, originalRequestRawJSON, _ []byte, rawJSON []byte, _ *any) string
ConvertCodexResponseToClaudeNonStream converts a non-streaming Codex response to a non-streaming Claude Code response. This function processes the complete Codex response and transforms it into a single Claude Code-compatible JSON response. It handles message content, tool calls, reasoning content, and usage metadata, combining all the information into a single response that matches the Claude Code API format.
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 Codex API
- param: A pointer to a parameter object for the conversion (unused in current implementation)
Returns:
- string: A Claude Code-compatible JSON response containing all message content and metadata
Types ¶
This section is empty.