Documentation
¶
Index ¶
- Constants
- Variables
- func APIKeyFromContext(ctx context.Context) string
- func APIKeyModelIsCompat(req cliproxyexecutor.Request) bool
- func AccessProviderFromContext(ctx context.Context) string
- func AllocateClaudeMCPToolAlias(secret, original string, reserved map[string]bool) (string, bool)
- func AppendAPIResponseChunk(ctx context.Context, cfg *config.Config, chunk []byte)
- func AppendAPIWebsocketResponse(ctx context.Context, cfg *config.Config, payload []byte)
- func AppendCodexAPIWebsocketResponse(ctx context.Context, cfg *config.Config, payload []byte)
- func ApplyClaudeCredentialMetadata(payload []byte, auth *cliproxyauth.Auth, sessionID string) ([]byte, string, error)
- func ApplyClaudeDefaultDeviceProfileHeaders(r *http.Request, cfg *config.Config)
- func ApplyClaudeDeviceProfileHeaders(r *http.Request, profile ClaudeDeviceProfile)
- func ApplyClaudeLegacyDeviceHeaders(r *http.Request, ginHeaders http.Header, cfg *config.Config, ...)
- func ApplyGeminiInteractionsRequestHeaders(req *http.Request, headers http.Header)
- func ApplyGeminiInteractionsRevisionHeader(req *http.Request)
- func ApplyGeminiInteractionsThinking(body []byte, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) ([]byte, error)
- func ApplyMediaPayloadConfig(cfg *config.Config, executor, model, protocol string, body []byte, ...) ([]byte, string, error)
- func ApplyPatchOriginalRequest(req cliproxyexecutor.Request, opts cliproxyexecutor.Options) []byte
- func ApplyPatchRequested(original []byte) bool
- func ApplyPatchTranslationError(param any) error
- func ApplyPayloadConfigWithRequest(cfg *config.Config, model, protocol, fromProtocol, root string, ...) []byte
- func ApplyPayloadConfigWithRequestForExecutor(cfg *config.Config, targetExecutor, model, protocol, fromProtocol, root string, ...) []byte
- func ApplyPayloadConfigWithRequestTracked(cfg *config.Config, model, protocol, fromProtocol, root string, ...) ([]byte, bool)
- func ApplyPayloadConfigWithRoot(cfg *config.Config, model, protocol, root string, payload, original []byte, ...) []byte
- func ApplyPayloadConfigWithTrackedPaths(cfg *config.Config, model, protocol, fromProtocol, root string, ...) ([]byte, map[string]bool)
- func ApplyPayloadConfigWithTrackedPathsForExecutor(cfg *config.Config, targetExecutor, model, protocol, fromProtocol, root string, ...) ([]byte, map[string]bool)
- func ApplyRequestThinking(body []byte, req cliproxyexecutor.Request, opts cliproxyexecutor.Options, ...) ([]byte, error)
- func ApplyThinkingWithSourcePayload(body, currentSourcePayload, originalSourcePayload []byte, ...) ([]byte, error)
- func AugmentClaudeBuiltinToolRegistry(body []byte, registry map[string]bool) map[string]bool
- func BeginClaudeContinuity(credentialIdentity, sessionID string, isNewPromptTurn bool, ...) (key string, sequence uint64, ...)
- func BeginClaudeDiagnostics(credentialIdentity, sessionID string) (key string, sequence uint64, previousMessageID string)
- func BuildAntigravityCompactionResponse(modelName, capsule string, inputTokens, outputTokens, totalTokens int) []byte
- func BuildAntigravityCompactionStreamChunks(modelName, capsule string, inputTokens, outputTokens, totalTokens int) [][]byte
- func BuildDevinClientMetadataBytes(sessionToken, deviceSeed, osName string) []byte
- func BuildDevinGetChatMessageRequest(sessionToken string, deviceSeed string, chatModelUID string, ...) []byte
- func BuildDevinUpstreamLogBody(interactionsPayload []byte, isInteractionsSource bool, chatModelUID string, ...) []byte
- func BuildDevinUpstreamResponseLogBody(respLog *DevinUpstreamResponseLog, interactionsJSON []byte) []byte
- func BuildOpenAIUsageJSON(count int64) []byte
- func BuildResponsesCompactionResponseFromSummary(modelName string, summaryPayload []byte) ([]byte, error)
- func BuildResponsesCompactionStreamChunksFromResponse(modelName string, compactionPayload []byte) ([][]byte, error)
- func CachedSessionID(apiKey string) string
- func CachedSessionIDRequired(ctx context.Context, apiKey string) (string, error)
- func CachedUserID(apiKey string) string
- func CachedUserIDRequired(ctx context.Context, apiKey string) (string, error)
- func CanFinalizeResponseStream(param any) bool
- func CaptureTranslatedClaudeStreamError(responseFormat sdktranslator.Format, lines [][]byte, retainedErr *error, ...)
- func ClaudeAgentSessionUUID(headers http.Header, originalPayload, translatedPayload []byte, ...) string
- func ClaudeAgentSessionUUIDForRequest(headers http.Header, originalPayload, translatedPayload []byte, ...) string
- func ClaudeCLIAuthIdentitySeed(auth *cliproxyauth.Auth) string
- func ClaudeCodeExecutionScope(ctx context.Context, payload []byte, headers http.Header) (string, bool)
- func ClaudeCredentialAccountUUID(auth *cliproxyauth.Auth) string
- func ClaudeDeterministicPromptID(seed string) string
- func ClaudeDeviceProfileStabilizationEnabled(cfg *config.Config) bool
- func ClaudeExecutionMetadataFromContext(ctx context.Context) bool
- func ClaudeHeadersIndicateUnifiedRateLimitRejection(headers http.Header) bool
- func ClaudeMCPAliasWordCount() int
- func ClaudeMCPToolAlias(secret, original string, attempt uint32) string
- func ClaudeModelLacksToolSearch(model string) bool
- func ClaudePayloadHas1hTTL(payload []byte) bool
- func ClaudeRequestHasExecutionMetadata(metadataSets ...map[string]any) bool
- func ClaudeSessionDatePinExpiryForTest(sessionID string) time.Time
- func ClaudeSessionDatePinKey(sessionID string) string
- func ClaudeSessionIDFromContext(ctx context.Context) string
- func ClaudeSubagentRequests1h(headers http.Header, body []byte) bool
- func CodexPromptCacheKey(modelName string, userScope string) string
- func CommitClaudeContinuity(key string, sequence uint64, messageID, requestID string, promptIDs ...string)
- func CommitClaudeDiagnostics(key string, sequence uint64, messageID string)
- func CountClaudeInputTokens(payload []byte) (int64, error)
- func CountOpenAIChatTokens(enc tokenizer.Codec, payload []byte) (int64, error)
- func CreditsUsed(ctx context.Context) bool
- func DecodeDevinToolCallID(id string) string
- func DefaultClaudeVersion(cfg *config.Config) string
- func DeleteJSONField(body []byte, key string) []byte
- func DerivedAntigravitySessionID(metadataSets ...map[string]any) string
- func DerivedSessionID(metadataSets ...map[string]any) string
- func DerivedSessionUUID(provider string, metadataSets ...map[string]any) string
- func DevinPayloadDefaultsSource(native, interactions []byte) []byte
- func DevinQuotaRetryAfter(resetAtSignal string, now time.Time) *time.Duration
- func DropForeignResponsesCompactionItems(payload []byte, provider string) []byte
- func DropGeminiTrailingThoughtOnlyContent(payload []byte, path string) []byte
- func EmitWebSocketResponseEvent(ctx context.Context, opts cliproxyexecutor.Options, auth *cliproxyauth.Auth, ...)
- func EncodeDevinToolCallID(id string) string
- func EndApplyPatchStream(ctx context.Context, param any, reporter *UsageReporter, ...) bool
- func EnsureClaudeCLIFingerprintIdentity(auth *cliproxyauth.Auth, seed string, synthesizeMissing bool) error
- func EnsureClaudeCredentialDevicePoolRequired(ctx context.Context, auth *cliproxyauth.Auth) ([]string, error)
- func EnsureGeminiBoundaryUserContent(payload []byte, path string) []byte
- func EnsureGeminiLeadingUserContent(payload []byte, path string) []byte
- func EnsureGeminiTrailingUserContent(payload []byte, path string) []byte
- func EnsureResponsesUsageDetails(payload []byte) []byte
- func EnsureSessionContext(ctx context.Context, opts cliproxyexecutor.Options, payload []byte) context.Context
- func ExecutorTypeName(executor any) string
- func ExpandAntigravityCompactionCapsules(payload []byte) ([]byte, error)
- func ExpandResponsesCompactionCapsules(req *cliproxyexecutor.Request, opts *cliproxyexecutor.Options, provider string) error
- func ExpireClaudeDiagnosticsForTest(expireContinuity bool, pinExpiryOffset *time.Duration)
- func ExtractAntigravitySummaryText(respPayload []byte) (string, error)
- func ExtractClaudeBillingTags(body []byte) (prevReq, promptID string)
- func ExtractClaudeCodeAgentID(ctx context.Context, headers http.Header) string
- func ExtractClaudeCodeSessionID(ctx context.Context, payload []byte, headers http.Header) string
- func ExtractResponsesCompactionUsage(payload []byte) (inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens int)
- func ExtractStreamJSONPayload(line []byte) []byte
- func FetchXAINPMLatestVersion(ctx context.Context, client *http.Client) (string, error)
- func FilterSSEUsageMetadata(payload []byte) []byte
- func FinalizeApplyPatchStream(param any) [][]byte
- func FinalizeDevinPayload(wire []byte, finalize PayloadFinalizer) ([]byte, []byte, error)
- func FinalizePayload(ctx context.Context, body []byte) []byte
- func GeminiInteractionsSSEDone(frame []byte) bool
- func GeminiInteractionsSSEPayload(frame []byte) []byte
- func GenerateDevinDeviceFingerprint(seed string) string
- func GenerateDevinSentryTrace() string
- func GenerateFakeUserID() string
- func GenerateFakeUserIDWithSessionID(sessionID string) string
- func GetXAIClientVersion() string
- func HasCodexMultiAgentV2NamespaceConflict(payload []byte) bool
- func HasDevinEffortSuffix(model string) bool
- func HasMeaningfulCodexOutputDelta(eventData []byte) bool
- func HasResponsesCompactionItem(payload []byte) bool
- func HasResponsesCompactionTrigger(payload []byte) bool
- func HasResponsesCompactionTriggerRequest(req cliproxyexecutor.Request, opts cliproxyexecutor.Options) bool
- func HeaderValueCaseInsensitive(headers http.Header, name string) string
- func HeaderValuesCaseInsensitive(headers http.Header, name string) []string
- func IncomingHeadersFromContext(ctx context.Context) http.Header
- func InitializeApplyPatchStream(ctx context.Context, from, to sdktranslator.Format, model string, ...)
- func InjectClaudeBillingTags(body []byte, prevReq, promptID string) []byte
- func IsAnthropicUpstreamURL(u *url.URL) bool
- func IsApplyPatchUpstreamTool(original []byte, name string) bool
- func IsChatTokenEvent(payload []byte) bool
- func IsClaudeCodeUserAgent(userAgent string) bool
- func IsClaudeMCPToolName(name string) bool
- func IsClaudeNewPromptTurn(body []byte) bool
- func IsClaudeProbeOrHelperRequest(body []byte) bool
- func IsClaudeServerToolType(toolType string) bool
- func IsClaudeSubagentRequest(headers http.Header, body []byte) bool
- func IsClaudeTokenEvent(payload []byte) bool
- func IsCodexTerminalEmptyIncomplete(eventData []byte, outputItemsCount int, sawOutputDelta bool) bool
- func IsCodexUserAgent(headers http.Header) bool
- func IsGeminiTokenEvent(payload []byte) bool
- func IsGoogleVertexHost(baseURL string) bool
- func IsModelSubstituted(requested, served string) bool
- func IsNativeCodexRequest(body []byte, opts cliproxyexecutor.Options) bool
- func IsResponsesTokenEvent(payload []byte) bool
- func IsValidClaudePromptID(id string) bool
- func IsValidUserID(userID string) bool
- func IsVertexOpenAPIModel(model string) bool
- func IterateStreamLines(payload []byte, fn func(line []byte))
- func JSONPayload(line []byte) []byte
- func JoinRawJSONArray(items [][]byte) []byte
- func JoinRawJSONStrings(items []string) []byte
- func LogWithRequestID(ctx context.Context) *log.Entry
- func LookupClaudeSessionDatePin(sessionID string, retention time.Duration) string
- func MapStainlessArch() string
- func MapStainlessOS() string
- func MarkCreditsUsed(ctx context.Context)
- func MergeStreamUsageDetail(existing, update usage.Detail) usage.Detail
- func NewDevinHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, ...) (clientOut *http.Client)
- func NewProxyAwareHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, ...) (clientOut *http.Client)
- func NewUtlsHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, ...) (clientOut *http.Client)
- func NextDevinSessionTurnIndex(sessionID string) int
- func NormalizeApplyPatchResponsesRequest(body []byte, original ...[]byte) ([]byte, error)
- func NormalizeClaudeToolCallIDs(body []byte) []byte
- func NormalizeCodexToolIntegerTypes(body []byte, headers http.Header) []byte
- func NormalizeCodexToolSchemas(body []byte) []byte
- func NormalizeKimiResponsesInput(body []byte) ([]byte, error)
- func NormalizeOpenAIMaxTokens(payload []byte, useMaxCompletionTokens bool) []byte
- func NormalizeOpenAIToolResultsTextOnly(payload []byte) []byte
- func NormalizeThinkingLevel(level string, budgetTokens int) string
- func NormalizeVertexOpenAPIModel(model string) string
- func ObfuscateSensitiveWords(payload []byte, matcher *SensitiveWordMatcher) []byte
- func ObfuscateSensitiveWordsInSystemInstruction(payload []byte, matcher *SensitiveWordMatcher) []byte
- func ObserveChatTokenEvent(reporter *UsageReporter, payload []byte)
- func ObserveClaudeTokenEvent(reporter *UsageReporter, payload []byte)
- func ObserveGeminiTokenEvent(reporter *UsageReporter, payload []byte)
- func ObserveMergedStreamUsage(buffer *StreamUsageBuffer, update usage.Detail)
- func ObservePluginExecutorStreamTTFT(protocol string, reporter *UsageReporter, payload []byte)
- func ObservePluginExecutorStreamUsage(protocol string, payload []byte, buffer *StreamUsageBuffer)
- func ObserveResponsesTokenEvent(reporter *UsageReporter, payload []byte)
- func OptimizeCodexMultiAgentV2Request(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) ([]byte, bool)
- func OptimizeCodexMultiAgentV2RequestForAuth(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config, ...) ([]byte, bool)
- func OverrideXAINPMRegistryURLForTest(url string) func()
- func ParseAntigravityStreamUsage(line []byte) (usage.Detail, bool)
- func ParseAntigravityUsage(data []byte) usage.Detail
- func ParseClaudeRateLimitReset(headers http.Header, now time.Time) *time.Duration
- func ParseClaudeRateLimitResetForError(headers http.Header, body []byte, now time.Time) *time.Duration
- func ParseClaudeStreamUsage(line []byte) (usage.Detail, bool)
- func ParseClaudeUsage(data []byte) usage.Detail
- func ParseCodexImageToolUsage(data []byte) (usage.Detail, bool)
- func ParseCodexQuotaEventHeaders(payload []byte) http.Header
- func ParseCodexUsage(data []byte) (usage.Detail, bool)
- func ParseDevinResponseDimensionGroups(groups ...[]byte) (promptTokens, completionTokens, cachedTokens int64, found bool)
- func ParseDevinTrailerError(payload []byte) (statusCode int, err error)
- func ParseGeminiStreamUsage(line []byte) (usage.Detail, bool)
- func ParseGeminiUsage(data []byte) usage.Detail
- func ParseInteractionsStreamUsage(line []byte) (usage.Detail, bool)
- func ParseInteractionsUsage(data []byte) usage.Detail
- func ParseOpenAIStreamUsage(line []byte) (usage.Detail, bool)
- func ParseOpenAIUsage(data []byte) usage.Detail
- func ParsePluginExecutorResponseUsage(protocol string, payload []byte) usage.Detail
- func ParseRetryDelay(errorBody []byte) (*time.Duration, error)
- func PatchResponsesCompactionStreamUsage(chunk []byte, ...) []byte
- func PayloadRequestPath(opts cliproxyexecutor.Options) string
- func PayloadRequestedModel(opts cliproxyexecutor.Options, fallback string) string
- func PinClaudeSessionDate(key, sessionID, date string, retention time.Duration) string
- func PrepareAntigravityCompactionSummaryPayload(payload []byte, modelName string) []byte
- func PrepareClaudeCLIFingerprintAuth(auth *cliproxyauth.Auth, seed string, synthesizeMissing bool) (*cliproxyauth.Auth, error)
- func ProviderSessionUUID(provider string, metadataSets ...map[string]any) string
- func PublishTranslatedClaudeStreamFailure(ctx context.Context, retainedErr error, reporter *UsageReporter, ...) bool
- func ReadConnectFrame(r io.Reader) (flag byte, payload []byte, err error)
- func RecognizedAntigravityCompactionCapsule(encryptedContent string) bool
- func RecordAPIRequest(ctx context.Context, cfg *config.Config, info UpstreamRequestLog)
- func RecordAPIResponseError(ctx context.Context, cfg *config.Config, err error)
- func RecordAPIResponseMetadata(ctx context.Context, cfg *config.Config, status int, headers http.Header)
- func RecordAPIWebsocketError(ctx context.Context, cfg *config.Config, stage string, err error)
- func RecordAPIWebsocketHandshake(ctx context.Context, cfg *config.Config, status int, headers http.Header)
- func RecordAPIWebsocketRequest(ctx context.Context, cfg *config.Config, info UpstreamRequestLog)
- func RecordAPIWebsocketUpgradeRejection(ctx context.Context, cfg *config.Config, info UpstreamRequestLog, status int, ...)
- func RecordApplyPatchStreamFailure(ctx context.Context, param any, reporter *UsageReporter, gatewayErr error) bool
- func RecordApplyPatchStreamFailureWithUsage(ctx context.Context, param any, reporter *UsageReporter, ...) bool
- func RecordClaudeWebSearchResults(sessionKey string, data []byte, ttl time.Duration, limit int)
- func RecordClaudeWebSearchResultsContext(ctx context.Context, sessionKey string, data []byte, ttl time.Duration, ...)
- func RefreshAuthViaHome(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth) (*cliproxyauth.Auth, bool, error)
- func ResetClaudeDeviceProfileCache()
- func ResetClaudeDiagnosticsForTest()
- func ResetDevinSessionTurnIndex(sessionID string)
- func ResolveAntigravityGroundingURLs(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, ...) []byte
- func ResolveDevinChatModelUID(rawModel string, thinkingLevel string, budgetTokens int) string
- func ResolveKimiBaseURL(auth *cliproxyauth.Auth) string
- func ResolveKimiChatURL(auth *cliproxyauth.Auth) string
- func ResolveKimiClaudeBaseURL(auth *cliproxyauth.Auth) string
- func ResolveKimiResponsesURL(auth *cliproxyauth.Auth) string
- func ResponsesCompactionSourcePayload(req cliproxyexecutor.Request, opts cliproxyexecutor.Options) []byte
- func ResponsesHasToolSearch(payload []byte) bool
- func RestoreClaudeWebSearchResults(body []byte, sessionKey string, ttl ...time.Duration) []byte
- func RestoreClaudeWebSearchResultsContext(ctx context.Context, body []byte, sessionKey string, ttl ...time.Duration) []byte
- func RestoreCodexMultiAgentV2Response(payload []byte, optimized bool) []byte
- func RestoreDevinToolCallIDs(prompts []DevinPrompt)
- func RewriteCodexMultiAgentV2Input(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) []byte
- func RewriteCodexOrphanDelegationInput(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) []byte
- func RewriteCodexSpawnAgentDescription(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) []byte
- func SanitizeCodexInputItemIDs(body []byte) []byte
- func SanitizeDevinSystemPrompt(prompt string, matcher *SensitiveWordMatcher) string
- func SanitizeGeminiInteractionsUnsupportedInputIDs(body []byte) []byte
- func SanitizeMetaWebSearchTools(body []byte) []byte
- func SealAntigravityCompaction(summary, modelName string) (string, error)
- func SetBoolIfDifferent(payload []byte, path string, value bool) []byte
- func SetCodexCache(key string, cache CodexCache)
- func SetCodexCacheBestEffort(ctx context.Context, key string, cache CodexCache) bool
- func SetCodexCacheRequired(ctx context.Context, key string, cache CodexCache) error
- func SetRawIfDifferent(payload []byte, path string, value []byte) []byte
- func SetStringIfDifferent(payload []byte, path, value string) []byte
- func SetXAIClientVersionForTest(version string) func()
- func SetXAIVersionRefreshedHookForTest(ch chan struct{}) func()
- func ShouldExecuteVertexOpenAPI(auth *cliproxyauth.Auth, model string) bool
- func ShouldNormalizeOpenAIToolResultsForModel(compat *config.OpenAICompatibility, upstreamModel, requestedModel string) bool
- func ShouldUseMaxCompletionTokensForModel(compat *config.OpenAICompatibility, upstreamModel, requestedModel string) bool
- func StableClaudeCLIAccountUUID(seed string) string
- func StableClaudeCLIDeviceID(seed string) string
- func StartXAIVersionUpdater(ctx context.Context, proxyURL string)
- func StopApplyPatchStream(ctx context.Context, param any, reporter *UsageReporter, ...) bool
- func StopApplyPatchStreamWithUsage(ctx context.Context, param any, reporter *UsageReporter, ...) bool
- func StopTranslatedClaudeStream(ctx context.Context, retainedErr *error, reporter *UsageReporter, ...) bool
- func StripClaudeBillingTags(body []byte) []byte
- func StripResponsesToolSearch(payload []byte) []byte
- func StripUsageMetadataFromJSON(rawJSON []byte) ([]byte, bool)
- func StripVertexOpenAIResponsesToolCallIDs(payload []byte, sourceFormat string) []byte
- func SummarizeErrorBody(contentType string, body []byte) string
- func TokenizerForModel(model string) (tokenizer.Codec, error)
- func TranslateGeminiInteractionsRequestBody(ctx context.Context, cfg *config.Config, model string, payload []byte, ...) ([]byte, error)
- func TranslateGeminiInteractionsRequestPair(ctx context.Context, cfg *config.Config, model string, payload []byte, ...) (original, working []byte, err error)
- func TranslateRequestEnvelopePairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) (original, working []byte, err error)
- func TranslateRequestEnvelopeWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) sdktranslator.RequestEnvelope
- func TranslateRequestPairReturningError(ctx context.Context, headers http.Header, cfg *config.Config, ...) ([]byte, []byte, error)
- func TranslateRequestPairWithAPIKeyModelCompatibility(ctx context.Context, headers http.Header, cfg *config.Config, ...) (original, working []byte)
- func TranslateRequestPairWithAPIKeyModelCompatibilityAndUpdateIntent(ctx context.Context, headers http.Header, cfg *config.Config, ...) (original, working []byte, updatesChanged bool, err error)
- func TranslateRequestPairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) (original, working []byte)
- func TranslateRequestReturningError(ctx context.Context, headers http.Header, cfg *config.Config, ...) ([]byte, error)
- func TranslateRequestWithAPIKeyModelCompatibility(ctx context.Context, headers http.Header, cfg *config.Config, ...) []byte
- func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent(ctx context.Context, headers http.Header, cfg *config.Config, ...) ([]byte, bool, error)
- func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntentForExecutor(ctx context.Context, headers http.Header, cfg *config.Config, ...) ([]byte, bool, error)
- func TranslateRequestWithAPIKeyModelCompatibilityForExecutor(ctx context.Context, headers http.Header, cfg *config.Config, ...) []byte
- func TranslateRequestWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) []byte
- func TranslateRequestWithCodexMultiAgentV2ForExecutor(ctx context.Context, headers http.Header, cfg *config.Config, ...) []byte
- func TranslateStreamWithClaudeInputTokens(ctx context.Context, upstreamFormat, responseFormat sdktranslator.Format, ...) [][]byte
- func TranslatedClaudeErrorPayload(responseFormat sdktranslator.Format, out []byte) (string, bool)
- func TranslatedClaudeStreamErrorPayload(responseFormat sdktranslator.Format, lines [][]byte) (string, bool)
- func UnsealAntigravityCompaction(encryptedContent string) (string, error)
- func ValidateResponsesCompactionSummaryStatus(summaryPayload []byte) error
- func VertexAPIKeyOpenAPIBaseURL(baseURL, version, projectID, location string) string
- func VertexAuthBaseURL(auth *cliproxyauth.Auth) string
- func VertexAuthProjectID(auth *cliproxyauth.Auth) string
- func VertexOpenAPIHostBaseURL(location string) string
- func VertexOpenAPILocation(auth *cliproxyauth.Auth, defaultLocation string) string
- func VertexServiceAccountOpenAPIBaseURL(baseURL, version, projectID, location string) string
- func WebsocketUpgradeRequestURL(rawURL string) string
- func WithAntigravityConnectionTrace(req *http.Request, auth *cliproxyauth.Auth, operation string) *http.Request
- func WithAntigravityHTTPClientTrace(client *http.Client, auth *cliproxyauth.Auth, operation string) *http.Client
- func WithClaudeContinuityContext(ctx context.Context, cc *ClaudeContinuityContext) context.Context
- func WithClaudeExecutionMetadata(ctx context.Context, present bool) context.Context
- func WithClaudeSessionID(ctx context.Context, sessionID string) context.Context
- func WithIncomingHeaders(ctx context.Context, headers http.Header) context.Context
- func WithPayloadFinalizer(ctx context.Context, finalize PayloadFinalizer) context.Context
- func WrapConnectEnvelope(protoBytes []byte) []byte
- func WrapConnectEnvelopeWithFlag(flag byte, protoBytes []byte) []byte
- type AntigravityInteractionsState
- type ApplyPatchResponsesState
- func (s *ApplyPatchResponsesState) Active() bool
- func (s *ApplyPatchResponsesState) AddDispatcher(name, namespace string)
- func (s *ApplyPatchResponsesState) Finish() error
- func (s *ApplyPatchResponsesState) FinishStream() ([][]byte, error)
- func (s *ApplyPatchResponsesState) RememberDispatcherArguments(event []byte)
- func (s *ApplyPatchResponsesState) RememberDispatcherEvent(event []byte)
- func (s *ApplyPatchResponsesState) Stream(line []byte) ([][]byte, error)
- func (s *ApplyPatchResponsesState) Transform(event []byte) ([][]byte, error)
- type ClaudeCodeRequestDetection
- type ClaudeContinuityContext
- type ClaudeDeviceProfile
- type ClaudeInputTokenState
- type CodexCache
- type CodexSSEScanner
- func (s *CodexSSEScanner) Bytes() []byte
- func (s *CodexSSEScanner) Err() error
- func (s *CodexSSEScanner) HeldBytes() int
- func (s *CodexSSEScanner) HeldLines() int
- func (s *CodexSSEScanner) RawBytes() int
- func (s *CodexSSEScanner) RawLines() int
- func (s *CodexSSEScanner) Scan() bool
- func (s *CodexSSEScanner) SetAssembly(on bool)
- func (s *CodexSSEScanner) SetBudgetChecker(fn func(line []byte, heldLines int, heldBytes int) bool)
- func (s *CodexSSEScanner) SetOnLine(fn func(line []byte))
- type DevinFrameResult
- type DevinImage
- type DevinImageLogItem
- type DevinPrompt
- type DevinPromptLogItem
- type DevinQuotaPeriod
- type DevinTool
- type DevinToolCall
- type DevinToolCallDelta
- type DevinToolLogItem
- type DevinUpstreamRequestLog
- type DevinUpstreamResponseLog
- type DevinUsage
- type PayloadFinalizer
- type SensitiveWordMatcher
- type StreamResponseModelObserver
- type StreamUsageBuffer
- func (b *StreamUsageBuffer) Detail() (usage.Detail, bool)
- func (b *StreamUsageBuffer) Observe(detail usage.Detail, ok bool)
- func (b *StreamUsageBuffer) ObserveClaudeStream(line []byte)
- func (b *StreamUsageBuffer) ObserveOpenAIStream(line []byte)
- func (b *StreamUsageBuffer) Publish(ctx context.Context, reporter *UsageReporter) bool
- func (b *StreamUsageBuffer) PublishFailure(ctx context.Context, reporter *UsageReporter, errs ...error) bool
- func (b *StreamUsageBuffer) ResponseModel() string
- type TransportCache
- func (c *TransportCache[K]) CloseKey(key K) bool
- func (c *TransportCache[K]) CloseMatching(predicate func(key K) bool) int
- func (c *TransportCache[K]) Contains(key K) bool
- func (c *TransportCache[K]) Get(key K, build func() (*http.Transport, error)) (*http.Transport, error)
- func (c *TransportCache[K]) Len() int
- func (c *TransportCache[K]) Purge()
- type UTF8SplitBuffer
- type UpstreamRequestLog
- type UsageReporter
- func (r *UsageReporter) AccessProvider() string
- func (r *UsageReporter) EnsurePublished(ctx context.Context)
- func (r *UsageReporter) IsFirstPacketSet() bool
- func (r *UsageReporter) IsNativeKey() bool
- func (r *UsageReporter) IsResponseModelFinal() bool
- func (r *UsageReporter) IsTTFTSet() bool
- func (r *UsageReporter) MarkFirstResponseByte()
- func (r *UsageReporter) ObserveResponse(resp *http.Response)
- func (r *UsageReporter) ObserveResponseModel(payload []byte)
- func (r *UsageReporter) ObserveResponsePacketOnly(resp *http.Response)
- func (r *UsageReporter) ObserveTokenEvent(isToken bool)
- func (r *UsageReporter) Publish(ctx context.Context, detail usage.Detail)
- func (r *UsageReporter) PublishAdditionalModel(ctx context.Context, model string, detail usage.Detail)
- func (r *UsageReporter) PublishFailure(ctx context.Context, errs ...error)
- func (r *UsageReporter) PublishFailureWithDetail(ctx context.Context, detail usage.Detail, errs ...error)
- func (r *UsageReporter) RecordFirstPacket()
- func (r *UsageReporter) RequestID() string
- func (r *UsageReporter) ResponseModel() string
- func (r *UsageReporter) SetResponseModel(model string)
- func (r *UsageReporter) SetSessionHierarchy(sessionID, parentSessionID string)
- func (r *UsageReporter) SetStream(stream bool)
- func (r *UsageReporter) SetTranslatedReasoningEffort(payload []byte, format string)
- func (r *UsageReporter) SetUpstreamModel(model string)
- func (r *UsageReporter) StartResponseTTFT()
- func (r *UsageReporter) TraceID() string
- func (r *UsageReporter) TrackFailure(ctx context.Context, errPtr *error)
- func (r *UsageReporter) TrackHTTPClient(client *http.Client) *http.Client
- func (r *UsageReporter) TrackHTTPClientRoundTripOnly(client *http.Client) *http.Client
- func (r *UsageReporter) UpdateAccessTokenFingerprint(auth *cliproxyauth.Auth)
- func (r *UsageReporter) UpstreamModel() string
Constants ¶
const ( ClaudeCodeSessionHeader = "X-Claude-Code-Session-Id" ClaudeCodeAgentHeader = "X-Claude-Code-Agent-Id" ClaudeCodeMainAgentID = "main" )
const ( // ConnectFlagData marks an uncompressed Connect-proto data frame. ConnectFlagData byte = 0x00 // ConnectFlagCompressed marks a gzipped Connect-proto frame. ConnectFlagCompressed byte = 0x01 // ConnectFlagEndStream marks the terminal Connect-proto trailer frame. ConnectFlagEndStream byte = 0x02 // DevinDefaultBaseURL is the default upstream Codeium/Devin endpoint. DevinDefaultBaseURL = "https://server.codeium.com" // DevinChatPath is the Connect-RPC endpoint for chat completions. DevinChatPath = "/exa.api_server_pb.ApiServerService/GetChatMessage" // DevinDefaultClientName is the client identifier declared in metadata. DevinDefaultClientName = "chisel" // DevinDefaultClientVersion is the client version declared in metadata. DevinDefaultClientVersion = "3000.10.21" // DevinFingerprintHexLen is the mandatory 732-hex-character length for metadata #31. DevinFingerprintHexLen = 732 // DevinDefaultMaxTokens is the fallback max completion tokens. DevinDefaultMaxTokens = 128000 )
const ( // GeminiInteractionsAPIRevision is the Api-Revision header required for the Interactions API. GeminiInteractionsAPIRevision = "2026-05-20" // StreamScannerBuffer sets the scanner buffer capacity for streaming response chunks (50MB). StreamScannerBuffer = 52_428_800 )
const ( // DefaultXAIFallbackClientVersion is the stable Grok CLI version used when npm // registry resolution fails. dist-tag latest is 1.0.46; 1.0.50 is the alpha tag. DefaultXAIFallbackClientVersion = "1.0.46" // XAIClientVersionServerFloor is the minimum Grok CLI version cli-chat-proxy accepts. // Older clients are rejected with HTTP 426 (#6249). XAIClientVersionServerFloor = "1.0.13" // XAIVersionRefreshInterval is the periodic interval to check for Grok CLI updates from npm. XAIVersionRefreshInterval = 3 * time.Hour // XAIVersionFetchTimeout is the maximum duration for a single npm registry lookup. XAIVersionFetchTimeout = 10 * time.Second )
const ApplyPatchUpstreamErrorMessage = "Invalid apply_patch tool arguments received from upstream."
ApplyPatchUpstreamErrorMessage deliberately excludes upstream JSON and patch text.
const ( // CodexEmptyIncompleteStreamMessage is the error message emitted when upstream ChatGPT Codex // terminates with response.incomplete having 0 output tokens and 0 content output. CodexEmptyIncompleteStreamMessage = "stream error: upstream terminated with incomplete empty response (0 tokens)" )
const DefaultTransportCacheCapacity = 64
DefaultTransportCacheCapacity bounds how many transports a TransportCache keeps alive at once. Every cached transport owns an independent connection pool, so an unbounded cache would let idle sockets and the goroutines managing them grow without limit whenever keys churn, for example when a credential's proxy is rotated through the management API or when an SDK embedder supplies a freshly built base transport per request.
Variables ¶
var (
ClaudeDeviceProfileBeforeCandidateStore func(ClaudeDeviceProfile)
)
Functions ¶
func APIKeyFromContext ¶
func APIKeyModelIsCompat ¶
func APIKeyModelIsCompat(req cliproxyexecutor.Request) bool
APIKeyModelIsCompat reports whether the selected API-key model enables compatibility handling for Claude thinking blocks.
func AccessProviderFromContext ¶ added in v8.0.24
AccessProviderFromContext extracts the client authentication provider identifier from the context.
func AllocateClaudeMCPToolAlias ¶
AllocateClaudeMCPToolAlias picks an alias that is not already reserved. Attempts are capped at the wordlist size so names that sanitize to the same suffix cannot spin forever. ok is false only when every one-word tool ID for this semantic is already reserved.
func AppendAPIResponseChunk ¶
AppendAPIResponseChunk appends an upstream response chunk to Gin context for request logging.
func AppendAPIWebsocketResponse ¶
AppendAPIWebsocketResponse stores an upstream websocket response frame in Gin context.
func AppendCodexAPIWebsocketResponse ¶
AppendCodexAPIWebsocketResponse stores a codex upstream websocket response frame and merges any quota event headers carried by the frame into the request log.
func ApplyClaudeCredentialMetadata ¶
func ApplyClaudeCredentialMetadata(payload []byte, auth *cliproxyauth.Auth, sessionID string) ([]byte, string, error)
ApplyClaudeCredentialMetadata rewrites the identity exception shared by native and cloaked OAuth requests.
func ApplyClaudeDeviceProfileHeaders ¶
func ApplyClaudeDeviceProfileHeaders(r *http.Request, profile ClaudeDeviceProfile)
func ApplyGeminiInteractionsRequestHeaders ¶ added in v8.0.21
ApplyGeminiInteractionsRequestHeaders forwards any incoming Api-Revision header to upstream requests.
func ApplyGeminiInteractionsRevisionHeader ¶ added in v8.0.21
ApplyGeminiInteractionsRevisionHeader sets the default Api-Revision header on outgoing HTTP requests.
func ApplyGeminiInteractionsThinking ¶ added in v8.0.21
func ApplyGeminiInteractionsThinking(body []byte, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) ([]byte, error)
ApplyGeminiInteractionsThinking applies thinking/reasoning configuration to the interactions payload.
func ApplyMediaPayloadConfig ¶ added in v8.0.14
func ApplyMediaPayloadConfig(cfg *config.Config, executor, model, protocol string, body []byte, contentType string, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) ([]byte, string, error)
ApplyMediaPayloadConfig exposes multipart fields as JSON business values. File parts use {filename, content_type, data} with base64 data; framing stays opaque.
func ApplyPatchOriginalRequest ¶ added in v8.0.9
func ApplyPatchOriginalRequest(req cliproxyexecutor.Request, opts cliproxyexecutor.Options) []byte
ApplyPatchOriginalRequest retains source declarations when SDK callers omit OriginalRequest.
func ApplyPatchRequested ¶ added in v8.0.9
ApplyPatchRequested resolves only original winning custom declarations.
func ApplyPatchTranslationError ¶ added in v8.0.9
ApplyPatchTranslationError consumes only the optional translator error state.
func ApplyPayloadConfigWithRequest ¶
func ApplyPayloadConfigWithRequest(cfg *config.Config, model, protocol, fromProtocol, root string, payload, original []byte, requestedModel string, requestPath string, headers http.Header) []byte
ApplyPayloadConfigWithRequest applies payload config using source protocol and request header gates.
func ApplyPayloadConfigWithRequestForExecutor ¶ added in v8.0.6
func ApplyPayloadConfigWithRequestForExecutor(cfg *config.Config, targetExecutor, model, protocol, fromProtocol, root string, payload, original []byte, requestedModel string, requestPath string, headers http.Header) []byte
ApplyPayloadConfigWithRequestForExecutor applies payload config with explicit target executor context.
func ApplyPayloadConfigWithRequestTracked ¶
func ApplyPayloadConfigWithRequestTracked(cfg *config.Config, model, protocol, fromProtocol, root string, payload, original []byte, requestedModel string, requestPath string, headers http.Header, trackedPath string) ([]byte, bool)
ApplyPayloadConfigWithRequestTracked applies payload config and reports whether an applied rule targeted trackedPath or one of its descendants.
func ApplyPayloadConfigWithRoot ¶
func ApplyPayloadConfigWithRoot(cfg *config.Config, model, protocol, root string, payload, original []byte, requestedModel string, requestPath string) []byte
ApplyPayloadConfigWithRoot behaves like applyPayloadConfig but treats all parameter paths as relative to the provided root path and restricts matches to the given protocol when supplied. Defaults are checked against the original payload when provided. requestedModel carries the client-visible model name before alias resolution so payload rules can target aliases precisely. requestPath is the inbound HTTP request path (when available) used for endpoint-scoped gates.
func ApplyPayloadConfigWithTrackedPaths ¶
func ApplyPayloadConfigWithTrackedPaths(cfg *config.Config, model, protocol, fromProtocol, root string, payload, original []byte, requestedModel string, requestPath string, headers http.Header, trackedPaths ...string) ([]byte, map[string]bool)
ApplyPayloadConfigWithTrackedPaths applies payload config and reports which tracked paths (or their descendants) were targeted by an applied rule.
func ApplyPayloadConfigWithTrackedPathsForExecutor ¶ added in v8.0.6
func ApplyPayloadConfigWithTrackedPathsForExecutor(cfg *config.Config, targetExecutor, model, protocol, fromProtocol, root string, payload, original []byte, requestedModel string, requestPath string, headers http.Header, trackedPaths ...string) ([]byte, map[string]bool)
ApplyPayloadConfigWithTrackedPathsForExecutor applies payload config with target executor awareness. When headers indicate a Codex client and the target executor is not Codex or Codex WebSocket, it normalizes tool parameter integer types to satisfy client-side integer deserialization (#6237). For Codex and Codex WebSocket targets, integer normalization is skipped (#6244).
func ApplyRequestThinking ¶
func ApplyRequestThinking(body []byte, req cliproxyexecutor.Request, opts cliproxyexecutor.Options, fromFormat, toFormat, provider string, normalizedUpdatesChanged ...bool) ([]byte, error)
ApplyRequestThinking preserves the registry lookup path unless the auth manager bound authoritative model capabilities to this execution attempt.
func ApplyThinkingWithSourcePayload ¶
func ApplyThinkingWithSourcePayload(body, currentSourcePayload, originalSourcePayload []byte, model, fromFormat, toFormat, providerKey string) ([]byte, error)
ApplyThinkingWithSourcePayload preserves summary visibility from the original client payload while applying thinking configuration to its translated target payload. currentSourcePayload is the payload that was translated, while originalSourcePayload retains intent removed by an earlier interceptor.
func BeginClaudeContinuity ¶
func BeginClaudeContinuity(credentialIdentity, sessionID string, isNewPromptTurn bool, explicitPromptID string) (key string, sequence uint64, previousMessageID, previousRequestID, promptID string)
BeginClaudeContinuity starts one request generation for a stable credential identity and Claude conversation. It tracks the previous upstream message ID, previous upstream request ID (cc_prev_req), and active prompt ID (cc_prompt_id). If explicitPromptID is provided and valid, it is adopted. Otherwise if isNewPromptTurn is true (or if no prompt ID exists), a fresh UUIDv4 is generated.
func BeginClaudeDiagnostics ¶
func BeginClaudeDiagnostics(credentialIdentity, sessionID string) (key string, sequence uint64, previousMessageID string)
BeginClaudeDiagnostics starts one request generation for a stable credential identity and Claude conversation. It returns the last successfully completed upstream message ID, if any. Only a SHA-256 digest of the credential identity and session is retained as the cache key, so access-token rotation does not interrupt continuity.
func BuildAntigravityCompactionResponse ¶
func BuildAntigravityCompactionResponse(modelName, capsule string, inputTokens, outputTokens, totalTokens int) []byte
BuildAntigravityCompactionResponse creates JSON response for non-stream response.compaction.
func BuildAntigravityCompactionStreamChunks ¶
func BuildAntigravityCompactionStreamChunks(modelName, capsule string, inputTokens, outputTokens, totalTokens int) [][]byte
BuildAntigravityCompactionStreamChunks creates SSE frames for compaction stream response.
func BuildDevinClientMetadataBytes ¶
BuildDevinClientMetadataBytes constructs the serialized bytes for Field 1 (ClientMetadata).
func BuildDevinGetChatMessageRequest ¶
func BuildDevinGetChatMessageRequest( sessionToken string, deviceSeed string, chatModelUID string, systemPrompt string, prompts []DevinPrompt, tools []DevinTool, temperature *float64, maxTokens int, sessionID string, cascadeID string, matcher *SensitiveWordMatcher, ) []byte
BuildDevinGetChatMessageRequest encodes an entire GetChatMessageRequest protobuf payload.
func BuildDevinUpstreamLogBody ¶
func BuildDevinUpstreamLogBody( interactionsPayload []byte, isInteractionsSource bool, chatModelUID string, systemPrompt string, prompts []DevinPrompt, tools []DevinTool, temp *float64, maxTokens int, sessionID string, cascadeID string, ) []byte
BuildDevinUpstreamLogBody formats the intermediate interactions and the decoded Devin request into a clear, aligned log body without synthetic wrapping.
func BuildDevinUpstreamResponseLogBody ¶
func BuildDevinUpstreamResponseLogBody(respLog *DevinUpstreamResponseLog, interactionsJSON []byte) []byte
BuildDevinUpstreamResponseLogBody formats the decoded Devin response and the intermediate interactions into a clear, aligned log body.
func BuildOpenAIUsageJSON ¶
BuildOpenAIUsageJSON returns a minimal usage structure understood by downstream translators.
func BuildResponsesCompactionResponseFromSummary ¶ added in v8.0.35
func BuildResponsesCompactionResponseFromSummary(modelName string, summaryPayload []byte) ([]byte, error)
BuildResponsesCompactionResponseFromSummary seals summary text from an OpenAI Responses payload into a response.compaction payload.
func BuildResponsesCompactionStreamChunksFromResponse ¶ added in v8.0.35
func BuildResponsesCompactionStreamChunksFromResponse(modelName string, compactionPayload []byte) ([][]byte, error)
BuildResponsesCompactionStreamChunksFromResponse converts a sealed response.compaction payload into SSE stream chunks.
func CachedSessionID ¶
CachedSessionID returns a stable session UUID per apiKey, refreshing the TTL on each access.
func CachedSessionIDRequired ¶
CachedSessionIDRequired returns a stable session UUID per apiKey for request-time paths.
func CachedUserID ¶
func CachedUserIDRequired ¶
CachedUserIDRequired returns a stable fake user ID per apiKey for request-time paths.
func CanFinalizeResponseStream ¶ added in v8.0.16
CanFinalizeResponseStream reports whether EOF can safely synthesize the source terminator.
func CaptureTranslatedClaudeStreamError ¶ added in v8.0.29
func CaptureTranslatedClaudeStreamError(responseFormat sdktranslator.Format, lines [][]byte, retainedErr *error, buildErr func(string) error)
CaptureTranslatedClaudeStreamError retains the first SSE error event payload so failure usage and terminal StreamChunk.Err can be emitted after any trailing usage chunk.
func ClaudeAgentSessionUUID ¶
func ClaudeAgentSessionUUID(headers http.Header, originalPayload, translatedPayload []byte, metadataSets ...map[string]any) string
ClaudeAgentSessionUUID maps the downstream agent conversation to one stable UUID, preserving native Claude Code session signals.
func ClaudeAgentSessionUUIDForRequest ¶
func ClaudeAgentSessionUUIDForRequest(headers http.Header, originalPayload, translatedPayload []byte, confirmedClaudeCode bool, metadataSets ...map[string]any) string
ClaudeAgentSessionUUIDForRequest preserves Claude-specific session signals only for a confirmed native caller. Other callers use protocol session fields, execution metadata, or the stable derived conversation root.
func ClaudeCLIAuthIdentitySeed ¶
func ClaudeCLIAuthIdentitySeed(auth *cliproxyauth.Auth) string
ClaudeCLIAuthIdentitySeed returns a stable credential identity that does not rotate with delegated-provider access tokens.
func ClaudeCodeExecutionScope ¶
func ClaudeCodeExecutionScope(ctx context.Context, payload []byte, headers http.Header) (string, bool)
ClaudeCodeExecutionScope returns the stable root-session and agent identity used by Codex execution state.
func ClaudeCredentialAccountUUID ¶
func ClaudeCredentialAccountUUID(auth *cliproxyauth.Auth) string
ClaudeCredentialAccountUUID returns the selected upstream credential's account UUID.
func ClaudeDeterministicPromptID ¶
ClaudeDeterministicPromptID generates a deterministic RFC 4122 UUIDv4 from a seed string.
func ClaudeExecutionMetadataFromContext ¶
ClaudeExecutionMetadataFromContext retrieves whether execution metadata was present from ctx.
func ClaudeHeadersIndicateUnifiedRateLimitRejection ¶
ClaudeHeadersIndicateUnifiedRateLimitRejection reports whether response headers explicitly declare an Anthropic shared 5h or 7d rate-limit rejection. An overage-only or Fable-only rejection remains model-scoped when shared subscription windows are not rejected (status "allowed", "allowed_warning", or unexhausted when omitted).
func ClaudeMCPAliasWordCount ¶
func ClaudeMCPAliasWordCount() int
ClaudeMCPAliasWordCount is the BIP-39 English dictionary size used for the virtual server pair and the one-word tool ID.
func ClaudeMCPToolAlias ¶
ClaudeMCPToolAlias derives a Claude Code-style MCP tool name. Aliases from one caller share a virtual server component. The tool component combines a stable keyed ID with a truncated semantic suffix so the model can distinguish tools by name while the request-local symbol table restores the exact original. A higher attempt linearly probes the next word when a collision must be avoided. Server and tool IDs use BIP-39 English words so weak models are less likely to drift high-entropy Base32 fragments.
func ClaudeModelLacksToolSearch ¶ added in v8.0.24
ClaudeModelLacksToolSearch reports Anthropic models that predate tool search. Unknown names, including third-party models, are treated as supported.
func ClaudePayloadHas1hTTL ¶
ClaudePayloadHas1hTTL reports whether the request payload contains any cache_control block with ttl set to "1h".
func ClaudeRequestHasExecutionMetadata ¶
ClaudeRequestHasExecutionMetadata reports whether the request explicitly carried an internal execution session metadata key.
func ClaudeSessionDatePinExpiryForTest ¶ added in v8.0.32
ClaudeSessionDatePinExpiryForTest returns the expiry of the retained date pin for a session, or the zero time when no pin exists.
func ClaudeSessionDatePinKey ¶ added in v8.0.32
ClaudeSessionDatePinKey returns the credential-independent store key for a session date pin, or "" for an empty session ID.
func ClaudeSessionIDFromContext ¶
ClaudeSessionIDFromContext retrieves the Claude session ID from ctx, if present.
func ClaudeSubagentRequests1h ¶
ClaudeSubagentRequests1h reports whether a subagent request explicitly requests 1h cache TTL either via a cache_control block with ttl="1h" in the payload or via extended-cache-ttl-2025-04-11 in incoming Anthropic-Beta headers.
func CodexPromptCacheKey ¶
CodexPromptCacheKey builds the Home KV key for a model/user prompt cache.
func CommitClaudeContinuity ¶
func CommitClaudeContinuity(key string, sequence uint64, messageID, requestID string, promptIDs ...string)
CommitClaudeContinuity advances continuity only after a response completes. It commits the upstream message ID (msg_01...), request ID (req_01...), and prompt ID (cc_prompt_id). A non-empty messageID is required so incomplete/truncated streams do not advance sequence.
func CommitClaudeDiagnostics ¶
CommitClaudeDiagnostics advances continuity only after a response completes. A response from an older concurrently-started request cannot overwrite a newer committed generation, including after TTL expiry or capacity eviction.
func CountClaudeInputTokens ¶
CountClaudeInputTokens estimates tokens for a Claude request with the O200kBase tokenizer.
func CountOpenAIChatTokens ¶
CountOpenAIChatTokens approximates prompt tokens for OpenAI chat completions payloads.
func CreditsUsed ¶
CreditsUsed returns true if the request used AI credits.
func DecodeDevinToolCallID ¶ added in v8.0.23
DecodeDevinToolCallID removes exactly one canonical encoding layer. Ordinary legal IDs, malformed encodings and arbitrary base64-looking IDs stay intact.
func DefaultClaudeVersion ¶
DefaultClaudeVersion returns the version string (e.g. "2.1.280") from the current baseline device profile. It extracts the version from the User-Agent.
func DeleteJSONField ¶
DeleteJSONField removes a top-level or nested JSON field from a payload.
func DerivedAntigravitySessionID ¶
DerivedAntigravitySessionID maps a derived session identity to Antigravity's negative decimal format.
func DerivedSessionID ¶
DerivedSessionID returns the first context-derived session identity in metadata order.
func DerivedSessionUUID ¶
DerivedSessionUUID maps a derived session identity to a provider-scoped stable UUID.
func DevinPayloadDefaultsSource ¶ added in v8.0.14
DevinPayloadDefaultsSource maps caller field presence to the native business view so defaults can replace built-in values without replacing caller values.
func DevinQuotaRetryAfter ¶ added in v8.0.32
DevinQuotaRetryAfter converts an observed quota reset timestamp (stored in auth Quota.Signals by the executor's Refresh path) into a retry delay. It returns nil unless the signal parses and is strictly in the future within a plausible daily/weekly horizon, in which case the caller should leave the cooldown duration to the conductor's credential backoff.
func DropForeignResponsesCompactionItems ¶ added in v8.0.35
DropForeignResponsesCompactionItems removes compaction items whose encrypted_content does not use the CPA capsule prefix.
func DropGeminiTrailingThoughtOnlyContent ¶ added in v8.0.24
DropGeminiTrailingThoughtOnlyContent removes trailing model turns made only of thought parts, keeping at least one turn. Such a tail comes from a replayed trailing reasoning item; dropping it avoids relying only on the synthetic empty user turn, which did not prevent Antigravity (#6530) or Vertex (#6630) from rejecting the request as ending with a model turn.
func EmitWebSocketResponseEvent ¶
func EmitWebSocketResponseEvent(ctx context.Context, opts cliproxyexecutor.Options, auth *cliproxyauth.Auth, provider, model string, payload []byte)
EmitWebSocketResponseEvent delivers an upstream WebSocket response frame to any configured observer.
func EncodeDevinToolCallID ¶ added in v8.0.23
EncodeDevinToolCallID reserves a namespace so native IDs cannot collide with encoded IDs. Empty deltas remain empty until upstream supplies the call ID.
func EndApplyPatchStream ¶ added in v8.0.9
func EndApplyPatchStream(ctx context.Context, param any, reporter *UsageReporter, out chan<- cliproxyexecutor.StreamChunk, gatewayErr error) bool
EndApplyPatchStream checks EOF before any synthetic success or usage publication.
func EnsureClaudeCLIFingerprintIdentity ¶
func EnsureClaudeCLIFingerprintIdentity(auth *cliproxyauth.Auth, seed string, synthesizeMissing bool) error
EnsureClaudeCLIFingerprintIdentity prepares auth.Metadata so the shared ApplyClaudeCredentialMetadata path can run.
When synthesizeMissing is false (real OAuth), this is a no-op: missing account or device data must surface as credential errors. When synthesizeMissing is true (fingerprint-profile=claude-code-cli on API keys), missing account_uuid / device pool are filled with stable values derived from seed. Callers that hold a shared Auth must use PrepareClaudeCLIFingerprintAuth instead.
func EnsureClaudeCredentialDevicePoolRequired ¶
func EnsureClaudeCredentialDevicePoolRequired(ctx context.Context, auth *cliproxyauth.Auth) ([]string, error)
EnsureClaudeCredentialDevicePoolRequired initializes a credential pool locally, or coordinates it through Home KV when the selected auth is a remote dispatch clone.
func EnsureGeminiBoundaryUserContent ¶
EnsureGeminiBoundaryUserContent ensures that the contents array at the given path both starts and ends with a user turn when sending to Gemini/Antigravity upstreams.
func EnsureGeminiLeadingUserContent ¶
EnsureGeminiLeadingUserContent ensures that the contents array at the given path starts with a user turn when sending to Gemini/Antigravity upstreams.
func EnsureGeminiTrailingUserContent ¶
EnsureGeminiTrailingUserContent ensures that the contents array at the given path ends with a user turn when sending to Gemini/Antigravity upstreams. If the final turn contains a functionResponse, it is preserved without appending an empty user turn because upstream expects the model to generate the response. A model-role functionResponse turn carrying nested media is the exception: Antigravity rejects it as the final turn with 400 INVALID_ARGUMENT (#6524).
func EnsureResponsesUsageDetails ¶
EnsureResponsesUsageDetails ensures that Responses usage objects contain output_tokens_details (defaulting reasoning_tokens to 0) and input_tokens_details (defaulting cached_tokens to 0). It supports plain JSON payloads, single-line SSE data: lines, and multi-line SSE frames (e.g. event: ...\ndata: ...).
func EnsureSessionContext ¶
func EnsureSessionContext(ctx context.Context, opts cliproxyexecutor.Options, payload []byte) context.Context
EnsureSessionContext ensures that ctx carries the internal session identity for $CPA-SESSION-ID expansion in custom headers.
func ExecutorTypeName ¶
func ExpandAntigravityCompactionCapsules ¶
ExpandAntigravityCompactionCapsules expands compaction items in input into developer context.
func ExpandResponsesCompactionCapsules ¶ added in v8.0.35
func ExpandResponsesCompactionCapsules(req *cliproxyexecutor.Request, opts *cliproxyexecutor.Options, provider string) error
ExpandResponsesCompactionCapsules drops foreign compaction items and expands recognized CPA compaction capsules in req and opts.
func ExpireClaudeDiagnosticsForTest ¶ added in v8.0.32
ExpireClaudeDiagnosticsForTest expires continuity entries and retained date pins without waiting for wall-clock TTLs. Pin expiry is relative to now.
func ExtractAntigravitySummaryText ¶
ExtractAntigravitySummaryText extracts summary text from Antigravity or Responses response.
func ExtractClaudeBillingTags ¶
ExtractClaudeBillingTags extracts existing cc_prev_req and cc_prompt_id values from a billing header in system text, if present.
func ExtractClaudeCodeAgentID ¶
ExtractClaudeCodeAgentID resolves the Claude Code agent ID and uses a stable sentinel for the root agent.
func ExtractClaudeCodeSessionID ¶
ExtractClaudeCodeSessionID resolves a Claude Code session ID, preferring X-Claude-Code-Session-Id over payload metadata.
func ExtractResponsesCompactionUsage ¶ added in v8.0.35
func ExtractResponsesCompactionUsage(payload []byte) (inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens int)
ExtractResponsesCompactionUsage extracts usage counters from an OpenAI Responses summary payload.
func ExtractStreamJSONPayload ¶
ExtractStreamJSONPayload extracts SSE data/json payload from a raw line.
func FetchXAINPMLatestVersion ¶ added in v8.0.20
FetchXAINPMLatestVersion performs a single request to the npm registry to query the latest version of @xai-official/grok. The returned version is a strict numeric semver at or above XAIClientVersionServerFloor.
func FilterSSEUsageMetadata ¶
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 FinalizeApplyPatchStream ¶ added in v8.0.9
FinalizeApplyPatchStream notifies request-local state of a transport ending. It must never manufacture a successful protocol terminator.
func FinalizeDevinPayload ¶ added in v8.0.14
func FinalizeDevinPayload(wire []byte, finalize PayloadFinalizer) ([]byte, []byte, error)
FinalizeDevinPayload projects the already-normalized protobuf business fields to JSON for user rules, then replaces only those fields in the wire message.
func FinalizePayload ¶ added in v8.0.14
FinalizePayload runs immediately before serialization or transport framing.
func GeminiInteractionsSSEDone ¶ added in v8.0.21
GeminiInteractionsSSEDone reports whether the SSE frame signals stream completion.
func GeminiInteractionsSSEPayload ¶ added in v8.0.21
GeminiInteractionsSSEPayload extracts SSE data payload from raw SSE frames.
func GenerateDevinDeviceFingerprint ¶
GenerateDevinDeviceFingerprint generates a 732-character hex device fingerprint. When seed is empty, it generates a cryptographically random 732-character hex string per request (matching native devin-cli). When seed is provided, it derives a deterministic 732-character hex fingerprint.
func GenerateDevinSentryTrace ¶
func GenerateDevinSentryTrace() string
GenerateDevinSentryTrace generates a Sentry distributed tracing header in the format: "<32-hex-trace-id>-<16-hex-span-id>-1"
func GenerateFakeUserID ¶
func GenerateFakeUserID() string
func GetXAIClientVersion ¶ added in v8.0.20
func GetXAIClientVersion() string
GetXAIClientVersion returns the current Grok CLI client version. If the background updater has fetched a newer acceptable version from npm, it returns that version; otherwise it returns DefaultXAIFallbackClientVersion.
func HasCodexMultiAgentV2NamespaceConflict ¶
HasCodexMultiAgentV2NamespaceConflict reports whether the request defines the reserved optimized namespace, which must remain untouched.
func HasDevinEffortSuffix ¶
HasDevinEffortSuffix reports whether the model name already ends with a known Devin effort suffix.
func HasMeaningfulCodexOutputDelta ¶
HasMeaningfulCodexOutputDelta reports whether an event carries non-empty generated content (such as non-empty text, reasoning, or function call arguments delta).
func HasResponsesCompactionItem ¶
HasResponsesCompactionItem checks whether input contains a compaction item.
func HasResponsesCompactionTrigger ¶
HasResponsesCompactionTrigger checks whether input contains a compaction_trigger item.
func HasResponsesCompactionTriggerRequest ¶ added in v8.0.35
func HasResponsesCompactionTriggerRequest(req cliproxyexecutor.Request, opts cliproxyexecutor.Options) bool
HasResponsesCompactionTriggerRequest reports whether req.Payload or opts.OriginalRequest contains a compaction_trigger item.
func HeaderValueCaseInsensitive ¶
HeaderValueCaseInsensitive returns the first non-empty header value matching name case-insensitively.
func HeaderValuesCaseInsensitive ¶
HeaderValuesCaseInsensitive returns all non-empty header values matching name case-insensitively.
func IncomingHeadersFromContext ¶
IncomingHeadersFromContext retrieves incoming HTTP headers from ctx, if present.
func InitializeApplyPatchStream ¶ added in v8.0.9
func InitializeApplyPatchStream(ctx context.Context, from, to sdktranslator.Format, model string, original, effective []byte, param *any)
InitializeApplyPatchStream prepares optional canonical state even for an empty EOF. An empty source has no progress events and does not opt native Codex into bridging.
func InjectClaudeBillingTags ¶
InjectClaudeBillingTags appends cc_prev_req and cc_prompt_id to the billing header in body if present.
func IsAnthropicUpstreamURL ¶
IsAnthropicUpstreamURL reports whether a resolved request targets Anthropic's first-party API origin. Claude-specific body, header, HTTP, and TLS behavior must all use this gate so they cannot drift onto custom ports or userinfo URLs.
func IsApplyPatchUpstreamTool ¶ added in v8.0.9
IsApplyPatchUpstreamTool preserves the original declaration's provenance.
func IsChatTokenEvent ¶
IsChatTokenEvent reports whether the given OpenAI-compatible Chat Completions SSE or JSON chunk carries substantive output token content (such as text delta, reasoning content, or tool call arguments). It filters out container metadata, role announcements, and empty delta frames.
func IsClaudeCodeUserAgent ¶ added in v8.0.34
IsClaudeCodeUserAgent reports whether userAgent identifies a Claude Code CLI client.
func IsClaudeMCPToolName ¶
IsClaudeMCPToolName reports whether name follows Claude Code's MCP tool convention and contains only characters accepted by Anthropic tool names.
func IsClaudeNewPromptTurn ¶
IsClaudeNewPromptTurn inspects the request messages to determine whether this request starts a new user prompt turn (requiring a new cc_prompt_id) versus a tool continuation step (which reuses the current cc_prompt_id).
func IsClaudeProbeOrHelperRequest ¶
IsClaudeProbeOrHelperRequest reports whether the request is a minimal probe/preflight (max_tokens: 1) or an automated title generation helper, which in native Claude Code do not emit cc_prompt_id or cc_prev_req.
func IsClaudeServerToolType ¶
IsClaudeServerToolType reports whether a typed declaration is a recognized Anthropic-operated tool. Client-defined type:"custom" declarations are not server tools and must remain eligible for MCP aliasing.
func IsClaudeSubagentRequest ¶
IsClaudeSubagentRequest reports whether the incoming request originates from or represents a Claude Code subagent.
func IsClaudeTokenEvent ¶
IsClaudeTokenEvent reports whether an Anthropic Messages SSE chunk carries substantive output token content (such as text delta, thinking delta, or tool input delta). It filters out message_start, ping, content_block_stop, and empty containers.
func IsCodexTerminalEmptyIncomplete ¶
func IsCodexTerminalEmptyIncomplete(eventData []byte, outputItemsCount int, sawOutputDelta bool) bool
IsCodexTerminalEmptyIncomplete reports whether a response.incomplete event represents an upstream silent abort where explicitly zero output tokens were generated and zero output content (no output items and no non-empty output deltas) was produced.
func IsCodexUserAgent ¶ added in v8.0.5
IsCodexUserAgent reports whether headers contain a User-Agent indicating a Codex client.
func IsGeminiTokenEvent ¶
IsGeminiTokenEvent reports whether a Google Gemini / Antigravity streaming chunk carries substantive output token content (such as text parts, thought traces, or function calls). It filters out metadata-only chunks (e.g. standalone usageMetadata) and empty parts.
func IsGoogleVertexHost ¶ added in v8.0.34
IsGoogleVertexHost reports whether baseURL is empty or points to Google's official aiplatform.googleapis.com domain.
func IsModelSubstituted ¶
IsModelSubstituted reports whether the upstream served a model other than the requested one for any provider; dated aliases and snapshot pins are accepted.
func IsNativeCodexRequest ¶
func IsNativeCodexRequest(body []byte, opts cliproxyexecutor.Options) bool
IsNativeCodexRequest checks the client dialect for use inside Codex executors.
func IsResponsesTokenEvent ¶
IsResponsesTokenEvent reports whether the given OpenAI/xAI Responses API WebSocket or SSE event payload carries an actual output token, reasoning trace, tool call argument, or multimodal delta, according to the official Responses API streaming / websocket specification plus Codex-compatible private events.
func IsValidClaudePromptID ¶
IsValidClaudePromptID verifies whether an explicit prompt ID adheres to strict RFC 4122 UUIDv4 semantics.
func IsValidUserID ¶
func IsVertexOpenAPIModel ¶ added in v8.0.34
IsVertexOpenAPIModel reports whether the given model identifier targets a non-Google Vertex partner or open model (MaaS) served by endpoints/openapi.
func IterateStreamLines ¶
IterateStreamLines splits payload by newline and invokes fn for non-empty lines.
func JSONPayload ¶
func JoinRawJSONArray ¶
JoinRawJSONArray joins validated raw JSON array items without re-encoding them.
func JoinRawJSONStrings ¶
JoinRawJSONStrings joins raw JSON array items held as strings.
func LogWithRequestID ¶
logWithRequestID returns a logrus Entry with request_id field populated from context. If no request ID is found in context, it returns the standard logger.
func LookupClaudeSessionDatePin ¶ added in v8.0.32
LookupClaudeSessionDatePin returns the retained pinned date for a session without creating or refreshing it. Non-positive retention returns "".
func MapStainlessArch ¶
func MapStainlessArch() string
func MapStainlessOS ¶
func MapStainlessOS() string
func MarkCreditsUsed ¶
MarkCreditsUsed flags the request as having used AI credits for billing.
func MergeStreamUsageDetail ¶
MergeStreamUsageDetail merges existing stream usage with a newer update.
func NewDevinHTTPClient ¶
func NewDevinHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) (clientOut *http.Client)
NewDevinHTTPClient creates an HTTP client customized for Devin Connect-RPC upstream. Suppresses automatic Accept-Encoding: gzip while preserving connection reuse across requests.
func NewProxyAwareHTTPClient ¶
func NewProxyAwareHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) (clientOut *http.Client)
NewProxyAwareHTTPClient creates an HTTP client with proper proxy configuration priority: 1. Use the execution-scoped request proxy if configured (highest priority) 2. Use auth.ProxyURL if configured 3. Use cfg.ProxyURL if auth proxy is not configured 4. Use RoundTripper from context if none are configured
Parameters:
- ctx: The context containing optional RoundTripper
- cfg: The application configuration
- auth: The authentication information
- timeout: The client timeout (0 means no timeout)
Returns:
- *http.Client: An HTTP client with configured proxy or transport
func NewUtlsHTTPClient ¶
func NewUtlsHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) (clientOut *http.Client)
NewUtlsHTTPClient creates an HTTP client using provider-specific TLS fingerprints for protected hosts. It uses Claude Code's Node/OpenSSL profile for Anthropic and a Chrome profile for ChatGPT, with a standard-transport fallback for other hosts.
func NextDevinSessionTurnIndex ¶
NextDevinSessionTurnIndex returns the next 0-based request ordinal for a session (Field 15.2). In native devin-cli, the counter is process-scoped per session: First request in a session returns 0 (which is omitted on the wire). Subsequent requests return 1, 2, 3... monotonically.
func NormalizeApplyPatchResponsesRequest ¶ added in v8.0.9
NormalizeApplyPatchResponsesRequest opts a non-Codex executor into the patch contract.
func NormalizeClaudeToolCallIDs ¶ added in v8.0.23
NormalizeClaudeToolCallIDs repairs only client tool ID fields. Existing legal IDs (including Devin encodings) are never re-encoded. Legacy collisions get a deterministic underscore-prefixed alias, without a process-wide ledger.
func NormalizeCodexToolIntegerTypes ¶ added in v8.0.5
NormalizeCodexToolIntegerTypes normalizes specified tool parameter declarations from number to integer for Codex clients across supported tool formats.
func NormalizeCodexToolSchemas ¶
NormalizeCodexToolSchemas inspects function tools in a Codex request payload and simplifies pure constant union combinations (e.g. large oneOf branch sets representing enums with descriptions, as emitted by MCP servers) into semantically equivalent enum lists, and sanitizes unsupported schema patterns. It does not normalize tool integer types because upstream OpenAI Codex models strictly validate reserved tool schemas (e.g. collaboration.wait_agent).
func NormalizeKimiResponsesInput ¶ added in v8.0.5
NormalizeKimiResponsesInput normalizes the input array for Kimi Responses API requests. When parallel function calls are emitted, Kimi requires all corresponding tool outputs to follow immediately without intervening non-tool messages (e.g. developer/user messages). This function defers intervening non-tool items until all outputs for the current batch of function calls have been emitted, keeping the outputs contiguous.
func NormalizeOpenAIMaxTokens ¶
NormalizeOpenAIMaxTokens normalizes max_tokens and max_completion_tokens according to the model's preference. When useMaxCompletionTokens is true, it ensures max_completion_tokens is set and max_tokens is removed. When useMaxCompletionTokens is false, it ensures max_tokens is used and max_completion_tokens is removed.
func NormalizeOpenAIToolResultsTextOnly ¶
NormalizeOpenAIToolResultsTextOnly converts tool message content to strings and strips relayed tool result images for text-only compatibility models. Text parts are preserved and image parts are replaced with a short marker.
func NormalizeThinkingLevel ¶
NormalizeThinkingLevel converts numeric budgets or loose effort strings to canonical Devin efforts.
func NormalizeVertexOpenAPIModel ¶ added in v8.0.34
NormalizeVertexOpenAPIModel normalizes a Vertex model identifier into the "<publisher>/<model>" form expected by Vertex's endpoints/openapi route while preserving any thinking suffix.
func ObfuscateSensitiveWords ¶
func ObfuscateSensitiveWords(payload []byte, matcher *SensitiveWordMatcher) []byte
ObfuscateSensitiveWords processes the payload and obfuscates sensitive words in system blocks and message content.
func ObfuscateSensitiveWordsInSystemInstruction ¶
func ObfuscateSensitiveWordsInSystemInstruction(payload []byte, matcher *SensitiveWordMatcher) []byte
ObfuscateSensitiveWordsInSystemInstruction obfuscates sensitive words in an Antigravity system instruction.
func ObserveChatTokenEvent ¶
func ObserveChatTokenEvent(reporter *UsageReporter, payload []byte)
ObserveChatTokenEvent inspects an OpenAI Chat Completions chunk and records TTFT if the frame represents the first meaningful token event. It records first-packet arrival time as fallback and returns immediately with zero allocations once effective token TTFT is set.
func ObserveClaudeTokenEvent ¶
func ObserveClaudeTokenEvent(reporter *UsageReporter, payload []byte)
ObserveClaudeTokenEvent inspects an Anthropic Messages SSE chunk and records TTFT if the frame represents the first meaningful token event. It records first-packet arrival time as fallback and returns immediately with zero allocations once effective token TTFT is set.
func ObserveGeminiTokenEvent ¶
func ObserveGeminiTokenEvent(reporter *UsageReporter, payload []byte)
ObserveGeminiTokenEvent inspects a Google Gemini / Antigravity streaming chunk and records TTFT if the frame represents the first meaningful token event. It records first-packet arrival time as fallback and returns immediately with zero allocations once effective token TTFT is set.
func ObserveMergedStreamUsage ¶
func ObserveMergedStreamUsage(buffer *StreamUsageBuffer, update usage.Detail)
ObserveMergedStreamUsage updates buffer with merged usage details.
func ObservePluginExecutorStreamTTFT ¶
func ObservePluginExecutorStreamTTFT(protocol string, reporter *UsageReporter, payload []byte)
ObservePluginExecutorStreamTTFT inspects a streaming payload and records TTFT on the reporter.
func ObservePluginExecutorStreamUsage ¶
func ObservePluginExecutorStreamUsage(protocol string, payload []byte, buffer *StreamUsageBuffer)
ObservePluginExecutorStreamUsage parses streaming chunks and updates a stream usage buffer.
func ObserveResponsesTokenEvent ¶
func ObserveResponsesTokenEvent(reporter *UsageReporter, payload []byte)
ObserveResponsesTokenEvent inspects a Responses API frame payload and records TTFT if the frame represents the first meaningful token event. It records the first packet arrival time as a fallback and exits immediately with zero allocations once effective token TTFT is set.
func OptimizeCodexMultiAgentV2Request ¶
func OptimizeCodexMultiAgentV2Request(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) ([]byte, bool)
OptimizeCodexMultiAgentV2Request rewrites an eligible spawn_agent request and reports whether the collaboration namespace was renamed for upstream use.
func OptimizeCodexMultiAgentV2RequestForAuth ¶
func OptimizeCodexMultiAgentV2RequestForAuth(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config, auth *cliproxyauth.Auth, isCompat bool) ([]byte, bool)
OptimizeCodexMultiAgentV2RequestForAuth applies the standard Codex MultiAgentV2 request optimization and uses the execution attempt's resolved compatibility flag to convert agent_message items into portable message/user input, proactively stripping author, recipient, and internal passthrough metadata.
func OverrideXAINPMRegistryURLForTest ¶ added in v8.0.20
func OverrideXAINPMRegistryURLForTest(url string) func()
OverrideXAINPMRegistryURLForTest overrides the npm registry URL for testing purposes.
func ParseAntigravityUsage ¶
func ParseClaudeRateLimitReset ¶
ParseClaudeRateLimitReset inspects Anthropic response headers for shared and Fable-specific unified rate-limit and standard Retry-After reset information, returning the conservative cooldown duration including a bounded non-negative random grace period. If no valid future reset information is present, it returns nil.
func ParseClaudeRateLimitResetForError ¶ added in v8.0.33
func ParseClaudeRateLimitResetForError(headers http.Header, body []byte, now time.Time) *time.Duration
ParseClaudeRateLimitResetForError is ParseClaudeRateLimitReset with one narrow, body-aware exception. An explicit per-minute rate-limit error carries no quota window, so an unclassified unified reset must not stretch its short Retry-After into an hours-long cooldown. The exception applies only when the body is exactly one complete per-minute message, no status header declares a quota window, and Retry-After is a single unambiguous value usable by the downstream deadline filter. Every other input keeps the conservative header-only result.
func ParseClaudeUsage ¶
func ParseCodexQuotaEventHeaders ¶
ParseCodexQuotaEventHeaders converts one Codex websocket quota event into the same bounded header representation used by HTTP usage observations. Codex sends additional_rate_limits as an object on the websocket path, while the /wham/usage probe exposes the equivalent data as an array; both forms are normalized into namespaced X-Codex headers here.
The websocket payload identifies each additional limit only by limit name ("GPT-5.3-Codex-Spark"), while HTTP responses namespace the same limit by a short name (x-codex-bengalfox-*). The two forms therefore cannot produce identical header names; the X-Codex-Additional- prefix marks the websocket origin, and the snapshot-replacement semantics in QuotaState keep the two spellings from accumulating side by side.
func ParseDevinResponseDimensionGroups ¶
func ParseDevinResponseDimensionGroups(groups ...[]byte) (promptTokens, completionTokens, cachedTokens int64, found bool)
ParseDevinResponseDimensionGroups parses Field 28 (ResponseDimensionGroups) entries to extract Token Usage metrics: input_tokens, output_tokens, cached_input_tokens. Accepts one or more group payloads (each corresponding to a Field 28 value), or an outer envelope containing Tag 28.
func ParseDevinTrailerError ¶
ParseDevinTrailerError inspects Connect-RPC EOS trailer frames and maps error status codes.
func ParseGeminiUsage ¶
func ParseInteractionsUsage ¶
func ParseOpenAIUsage ¶
func ParsePluginExecutorResponseUsage ¶
ParsePluginExecutorResponseUsage extracts token usage from a non-streaming plugin executor response.
func ParseRetryDelay ¶
ParseRetryDelay extracts the retry delay from a Google API 429 error response.
func PatchResponsesCompactionStreamUsage ¶ added in v8.0.35
func PatchResponsesCompactionStreamUsage(chunk []byte, inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens int) []byte
PatchResponsesCompactionStreamUsage updates usage counters on a compaction SSE chunk.
func PayloadRequestPath ¶
func PayloadRequestPath(opts cliproxyexecutor.Options) string
func PayloadRequestedModel ¶
func PayloadRequestedModel(opts cliproxyexecutor.Options, fallback string) string
func PinClaudeSessionDate ¶ added in v8.0.12
PinClaudeSessionDate returns the calendar date pinned for a session, recording date on the first call and returning the pinned value on later calls. A non-positive retention keeps the legacy continuity-scoped pin, whose lifetime follows claudeDiagnosticsTTL. A positive retention stores the pin separately under a session-only key, so continuity expiry or a credential switch cannot re-anchor it before the retention expires. An unknown continuity key returns date unchanged, matching per-request dates.
func PrepareAntigravityCompactionSummaryPayload ¶
PrepareAntigravityCompactionSummaryPayload prepares a payload for non-stream Antigravity summary generation.
func PrepareClaudeCLIFingerprintAuth ¶
func PrepareClaudeCLIFingerprintAuth(auth *cliproxyauth.Auth, seed string, synthesizeMissing bool) (*cliproxyauth.Auth, error)
PrepareClaudeCLIFingerprintAuth returns the auth object that should receive ApplyClaudeCredentialMetadata. Synthesized API-key / delegated-provider identity is written to a clone so the shared credential metadata map is not mutated on the request path.
func ProviderSessionUUID ¶
ProviderSessionUUID prefers a long-lived execution session and falls back to the derived identity.
func PublishTranslatedClaudeStreamFailure ¶ added in v8.0.29
func PublishTranslatedClaudeStreamFailure(ctx context.Context, retainedErr error, reporter *UsageReporter, streamUsage *StreamUsageBuffer) bool
PublishTranslatedClaudeStreamFailure publishes failure usage with buffered stream usage when a translated Claude stream retained an SSE error event.
func ReadConnectFrame ¶
ReadConnectFrame reads a single framed message from a Connect-proto stream.
func RecognizedAntigravityCompactionCapsule ¶ added in v8.0.22
RecognizedAntigravityCompactionCapsule reports whether encrypted content uses the CPA capsule prefix.
func RecordAPIRequest ¶
func RecordAPIRequest(ctx context.Context, cfg *config.Config, info UpstreamRequestLog)
RecordAPIRequest stores the upstream request metadata in Gin context for request logging.
func RecordAPIResponseError ¶
RecordAPIResponseError adds an error entry for the latest attempt when no HTTP response is available.
func RecordAPIResponseMetadata ¶
func RecordAPIResponseMetadata(ctx context.Context, cfg *config.Config, status int, headers http.Header)
RecordAPIResponseMetadata captures upstream response status/header information for the latest attempt.
func RecordAPIWebsocketError ¶
RecordAPIWebsocketError stores an upstream websocket error event in Gin context.
func RecordAPIWebsocketHandshake ¶
func RecordAPIWebsocketHandshake(ctx context.Context, cfg *config.Config, status int, headers http.Header)
RecordAPIWebsocketHandshake stores the upstream websocket handshake response metadata.
func RecordAPIWebsocketRequest ¶
func RecordAPIWebsocketRequest(ctx context.Context, cfg *config.Config, info UpstreamRequestLog)
RecordAPIWebsocketRequest stores an upstream websocket request event in Gin context.
func RecordAPIWebsocketUpgradeRejection ¶
func RecordAPIWebsocketUpgradeRejection(ctx context.Context, cfg *config.Config, info UpstreamRequestLog, status int, headers http.Header, body []byte)
RecordAPIWebsocketUpgradeRejection stores a rejected websocket upgrade as an HTTP attempt.
func RecordApplyPatchStreamFailure ¶ added in v8.0.9
func RecordApplyPatchStreamFailure(ctx context.Context, param any, reporter *UsageReporter, gatewayErr error) bool
RecordApplyPatchStreamFailure records validation before delivery can be canceled.
func RecordApplyPatchStreamFailureWithUsage ¶ added in v8.0.17
func RecordApplyPatchStreamFailureWithUsage(ctx context.Context, param any, reporter *UsageReporter, streamUsage *StreamUsageBuffer, gatewayErr error) bool
RecordApplyPatchStreamFailureWithUsage records validation with buffered upstream usage.
func RecordClaudeWebSearchResults ¶ added in v8.0.34
RecordClaudeWebSearchResults stores the web_search_tool_result blocks of a Claude response for sessionKey. data is either a complete Messages response or SSE text (one or more lines); the result block arrives whole in its content_block_start event.
func RecordClaudeWebSearchResultsContext ¶ added in v8.0.35
func RecordClaudeWebSearchResultsContext(ctx context.Context, sessionKey string, data []byte, ttl time.Duration, limit int)
RecordClaudeWebSearchResultsContext stores the web_search_tool_result blocks of a Claude response for sessionKey using ctx for Home KV operations.
func RefreshAuthViaHome ¶
func RefreshAuthViaHome(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth) (*cliproxyauth.Auth, bool, error)
RefreshAuthViaHome replaces local refresh logic when home control plane integration is enabled. It returns (updatedAuth, true, nil) when home refresh succeeds; (nil, true, err) when home is enabled but refresh fails; and (nil, false, nil) when home is disabled.
func ResetClaudeDeviceProfileCache ¶
func ResetClaudeDeviceProfileCache()
func ResetClaudeDiagnosticsForTest ¶
func ResetClaudeDiagnosticsForTest()
ResetClaudeDiagnosticsForTest resets in-memory continuity state for test isolation.
func ResetDevinSessionTurnIndex ¶
func ResetDevinSessionTurnIndex(sessionID string)
ResetDevinSessionTurnIndex clears the session counter (used for testing or explicit session reset).
func ResolveAntigravityGroundingURLs ¶
func ResolveAntigravityGroundingURLs(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, payload []byte) []byte
ResolveAntigravityGroundingURLs replaces Vertex Search redirect URLs in grounding chunks with their target URLs.
func ResolveDevinChatModelUID ¶
ResolveDevinChatModelUID resolves a model identifier into a valid upstream Devin chat_model_uid. It prioritizes dynamic catalog metadata from devin_models.json, automatically clamps requested efforts to supported levels, applies sensible default efforts for thinking models, and ensures bare non-thinking models remain bare.
func ResolveKimiBaseURL ¶
func ResolveKimiBaseURL(auth *cliproxyauth.Auth) string
ResolveKimiBaseURL resolves the upstream API base URL for Kimi API requests based on auth.
func ResolveKimiChatURL ¶
func ResolveKimiChatURL(auth *cliproxyauth.Auth) string
ResolveKimiChatURL resolves the upstream URL for Kimi Chat Completions requests.
func ResolveKimiClaudeBaseURL ¶
func ResolveKimiClaudeBaseURL(auth *cliproxyauth.Auth) string
ResolveKimiClaudeBaseURL resolves the base URL for Kimi Claude Messages delegation.
func ResolveKimiResponsesURL ¶
func ResolveKimiResponsesURL(auth *cliproxyauth.Auth) string
ResolveKimiResponsesURL resolves the upstream URL for Kimi Responses API requests.
func ResponsesCompactionSourcePayload ¶ added in v8.0.35
func ResponsesCompactionSourcePayload(req cliproxyexecutor.Request, opts cliproxyexecutor.Options) []byte
ResponsesCompactionSourcePayload selects the source payload containing the compaction trigger or request history.
func ResponsesHasToolSearch ¶ added in v8.0.24
ResponsesHasToolSearch reports whether a Responses payload carries a client tool_search declaration or tool_search history items.
func RestoreClaudeWebSearchResults ¶ added in v8.0.34
RestoreClaudeWebSearchResults fills assistant web_search_tool_result blocks whose content is missing or empty with the content stored for sessionKey. Blocks that already carry content, and blocks without a stored entry, are left unchanged.
func RestoreClaudeWebSearchResultsContext ¶ added in v8.0.35
func RestoreClaudeWebSearchResultsContext(ctx context.Context, body []byte, sessionKey string, ttl ...time.Duration) []byte
RestoreClaudeWebSearchResultsContext fills assistant web_search_tool_result blocks whose content is missing or empty with the content stored for sessionKey using ctx for Home KV operations.
func RestoreCodexMultiAgentV2Response ¶
RestoreCodexMultiAgentV2Response restores optimized collaboration namespace values before an upstream response is translated and returned to the client.
func RestoreDevinToolCallIDs ¶ added in v8.0.23
func RestoreDevinToolCallIDs(prompts []DevinPrompt)
RestoreDevinToolCallIDs runs before protobuf construction and user payload rules, keeping assistant calls and tool results in the upstream namespace.
func RewriteCodexMultiAgentV2Input ¶
func RewriteCodexMultiAgentV2Input(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) []byte
RewriteCodexMultiAgentV2Input converts official Codex multi-agent input into standard Responses API messages when multi-agent v2 optimization is enabled.
func RewriteCodexOrphanDelegationInput ¶
func RewriteCodexOrphanDelegationInput(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) []byte
RewriteCodexOrphanDelegationInput converts orphan Codex delegation outputs into standard user messages when orphan delegation compatibility is enabled and the request carries the X-Openai-Subagent: collab_spawn header.
func RewriteCodexSpawnAgentDescription ¶
func RewriteCodexSpawnAgentDescription(ctx context.Context, headers http.Header, payload []byte, cfg *config.Config) []byte
RewriteCodexSpawnAgentDescription optimizes spawn_agent definitions for official Codex clients when multi-agent v2 optimization is enabled.
func SanitizeCodexInputItemIDs ¶
SanitizeCodexInputItemIDs normalizes supported input item IDs for Codex, removes encrypted reasoning items whose IDs exceed the Codex limit, and deterministically shortens other overlong input item IDs.
func SanitizeDevinSystemPrompt ¶
func SanitizeDevinSystemPrompt(prompt string, matcher *SensitiveWordMatcher) string
SanitizeDevinSystemPrompt strips Claude Code attribution and CLI identity headers (referencing Antigravity conventions), and applies zero-width obfuscation for configured sensitive words.
func SanitizeGeminiInteractionsUnsupportedInputIDs ¶ added in v8.0.21
SanitizeGeminiInteractionsUnsupportedInputIDs aligns input step IDs with the official Gemini Interactions API schema: - `function_call` (FunctionCallStep) requires `id` and rejects `call_id` - `function_result` (FunctionResultStep) requires `call_id` and rejects `id` - other steps and content parts do not support `id`
func SanitizeMetaWebSearchTools ¶ added in v8.0.3
SanitizeMetaWebSearchTools strips unsupported fields from web_search tool definitions for Meta Muse upstreams. Specifically, Meta rejects search_content_types when tool type is "web_search" (it is only accepted on "web_search_preview" tools).
func SealAntigravityCompaction ¶
SealAntigravityCompaction encrypts summary data into an opaque capsule using AES-GCM.
func SetBoolIfDifferent ¶
SetBoolIfDifferent updates path only when its value is not already the canonical JSON boolean. Values with another JSON type are still normalized.
func SetCodexCache ¶
func SetCodexCache(key string, cache CodexCache)
SetCodexCache stores a cache entry.
func SetCodexCacheBestEffort ¶
func SetCodexCacheBestEffort(ctx context.Context, key string, cache CodexCache) bool
SetCodexCacheBestEffort stores a cache entry without failing completed responses.
func SetCodexCacheRequired ¶
func SetCodexCacheRequired(ctx context.Context, key string, cache CodexCache) error
SetCodexCacheRequired stores a cache entry for request-time paths.
func SetRawIfDifferent ¶
SetRawIfDifferent updates path only when the existing raw JSON is identical.
func SetStringIfDifferent ¶
SetStringIfDifferent updates path only when its value is not already the canonical JSON string. Values with another JSON type are still normalized.
func SetXAIClientVersionForTest ¶ added in v8.0.20
func SetXAIClientVersionForTest(version string) func()
SetXAIClientVersionForTest sets the cached Grok CLI version directly for testing purposes.
func SetXAIVersionRefreshedHookForTest ¶ added in v8.0.20
func SetXAIVersionRefreshedHookForTest(ch chan struct{}) func()
SetXAIVersionRefreshedHookForTest receives one signal after each refresh attempt.
func ShouldExecuteVertexOpenAPI ¶ added in v8.0.34
func ShouldExecuteVertexOpenAPI(auth *cliproxyauth.Auth, model string) bool
ShouldExecuteVertexOpenAPI reports whether the request should be routed through Vertex AI's OpenAI-compatible endpoints/openapi route.
func ShouldNormalizeOpenAIToolResultsForModel ¶
func ShouldNormalizeOpenAIToolResultsForModel(compat *config.OpenAICompatibility, upstreamModel, requestedModel string) bool
ShouldNormalizeOpenAIToolResultsForModel reports whether the selected model explicitly excludes image input through its input-modalities configuration.
func ShouldUseMaxCompletionTokensForModel ¶
func ShouldUseMaxCompletionTokensForModel(compat *config.OpenAICompatibility, upstreamModel, requestedModel string) bool
ShouldUseMaxCompletionTokensForModel reports whether the resolved model under an OpenAI compatibility configuration has use-max-completion-tokens set to true.
func StableClaudeCLIAccountUUID ¶
StableClaudeCLIAccountUUID returns a deterministic UUIDv5 account ID derived from a seed.
func StableClaudeCLIDeviceID ¶
StableClaudeCLIDeviceID returns a deterministic device ID derived from a seed.
func StartXAIVersionUpdater ¶ added in v8.0.20
StartXAIVersionUpdater starts a background goroutine that periodically refreshes the Grok CLI version from npm. A later call cancels the previous goroutine and binds the new service context and proxy URL. It executes a single fetch on startup and then polls every 3 hours without multiple retries on failure.
func StopApplyPatchStream ¶ added in v8.0.9
func StopApplyPatchStream(ctx context.Context, param any, reporter *UsageReporter, out chan<- cliproxyexecutor.StreamChunk, gatewayErr error) bool
StopApplyPatchStream propagates a retained failure after its one translated frame. The caller supplies its existing sanitized gateway status error.
func StopApplyPatchStreamWithUsage ¶ added in v8.0.17
func StopApplyPatchStreamWithUsage(ctx context.Context, param any, reporter *UsageReporter, streamUsage *StreamUsageBuffer, out chan<- cliproxyexecutor.StreamChunk, gatewayErr error) bool
StopApplyPatchStreamWithUsage propagates a retained failure with buffered upstream usage.
func StopTranslatedClaudeStream ¶ added in v8.0.29
func StopTranslatedClaudeStream(ctx context.Context, retainedErr *error, reporter *UsageReporter, streamUsage *StreamUsageBuffer, out chan<- cliproxyexecutor.StreamChunk) bool
StopTranslatedClaudeStream publishes failure usage and propagates a terminal StreamChunk.Err once after a translated Claude stream emitted an SSE error event.
func StripClaudeBillingTags ¶
StripClaudeBillingTags removes cc_prev_req and cc_prompt_id from the billing header in body.
func StripResponsesToolSearch ¶ added in v8.0.24
StripResponsesToolSearch removes client tool_search declarations and every tool_search_call/tool_search_output input item, so the Claude translator produces the same output it did before tool_search support. Hosted declarations are left for the translator. An unchanged payload is returned as is.
func StripUsageMetadataFromJSON ¶
StripUsageMetadataFromJSON drops usageMetadata unless finishReason is present (terminal). It handles both formats: - Aistudio: candidates.0.finishReason - Antigravity: response.candidates.0.finishReason
func StripVertexOpenAIResponsesToolCallIDs ¶
StripVertexOpenAIResponsesToolCallIDs removes OpenAI Responses call IDs that Vertex rejects in Gemini functionCall/functionResponse payloads.
func SummarizeErrorBody ¶
func TokenizerForModel ¶
TokenizerForModel returns a tokenizer codec suitable for an OpenAI-style model id.
func TranslateGeminiInteractionsRequestBody ¶ added in v8.0.21
func TranslateGeminiInteractionsRequestBody(ctx context.Context, cfg *config.Config, model string, payload []byte, opts cliproxyexecutor.Options, stream, isCompat bool) ([]byte, error)
TranslateGeminiInteractionsRequestBody translates a request payload to FormatInteractions.
func TranslateGeminiInteractionsRequestPair ¶ added in v8.0.21
func TranslateGeminiInteractionsRequestPair(ctx context.Context, cfg *config.Config, model string, payload []byte, opts cliproxyexecutor.Options, stream, isCompat bool) (original, working []byte, err error)
TranslateGeminiInteractionsRequestPair translates the working payload and the payload-config baseline. Identical inputs are translated once, including plugin hooks. The baseline is captured before model and thinking mutations, and the working buffer is a separate copy so those mutations cannot change it.
func TranslateRequestEnvelopePairWithCodexMultiAgentV2 ¶
func TranslateRequestEnvelopePairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, req sdktranslator.RequestEnvelope, originalPayload, requestPayload []byte) (original, working []byte, err error)
TranslateRequestEnvelopePairWithCodexMultiAgentV2 translates the baseline and working payload while preserving request-scoped metadata in req. The returned error is the one for the working payload, which is the payload sent upstream; a failure of the baseline alone never rejects a working payload that translated.
func TranslateRequestEnvelopeWithCodexMultiAgentV2 ¶
func TranslateRequestEnvelopeWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, req sdktranslator.RequestEnvelope) sdktranslator.RequestEnvelope
TranslateRequestEnvelopeWithCodexMultiAgentV2 normalizes official Codex multi-agent input while preserving the complete request envelope.
func TranslateRequestPairReturningError ¶ added in v8.0.20
func TranslateRequestPairReturningError(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, originalPayload, requestPayload []byte, stream, isCompat bool) ([]byte, []byte, error)
TranslateRequestPairReturningError reports a content part the target cannot represent.
func TranslateRequestPairWithAPIKeyModelCompatibility ¶
func TranslateRequestPairWithAPIKeyModelCompatibility(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, originalPayload, requestPayload []byte, stream, isCompat bool) (original, working []byte)
TranslateRequestPairWithAPIKeyModelCompatibility avoids translating identical inputs twice while retaining separate buffers and invoking plugins once per input.
func TranslateRequestPairWithAPIKeyModelCompatibilityAndUpdateIntent ¶
func TranslateRequestPairWithAPIKeyModelCompatibilityAndUpdateIntent(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, originalPayload, requestPayload []byte, stream, isCompat bool) (original, working []byte, updatesChanged bool, err error)
TranslateRequestPairWithAPIKeyModelCompatibilityAndUpdateIntent returns the normalizer decision for the working payload, not for the baseline payload, and the working payload's error for a content part the target cannot represent. A baseline failure alone is ignored.
func TranslateRequestPairWithCodexMultiAgentV2 ¶
func TranslateRequestPairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, originalPayload, requestPayload []byte, stream bool) (original, working []byte)
TranslateRequestPairWithCodexMultiAgentV2 translates the untouched baseline payload and the working payload that later stages mutate in place. Executors normally assign the original payload to the request before translating, so the same input is translated once, including plugin hooks, then copied into a separate working buffer. This avoids duplicate plugin side effects and a full extra pass over payloads that can reach tens of megabytes.
func TranslateRequestReturningError ¶ added in v8.0.20
func TranslateRequestReturningError(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, payload []byte, stream, isCompat bool) ([]byte, error)
TranslateRequestReturningError reports a content part the target cannot represent.
func TranslateRequestWithAPIKeyModelCompatibility ¶
func TranslateRequestWithAPIKeyModelCompatibility(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, payload []byte, stream, isCompat bool) []byte
TranslateRequestWithAPIKeyModelCompatibility applies compatibility-aware request translators when a configured API-key model enables compatibility mode.
func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent ¶
func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, payload []byte, stream, isCompat bool) ([]byte, bool, error)
TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent returns the plugin normalizer's request-scoped update decision for Responses targets.
func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntentForExecutor ¶ added in v8.0.7
func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntentForExecutor(ctx context.Context, headers http.Header, cfg *config.Config, targetExecutor string, from, to sdktranslator.Format, model string, payload []byte, stream, isCompat bool) ([]byte, bool, error)
TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntentForExecutor translates a request while applying client schema compatibility for the actual target executor.
func TranslateRequestWithAPIKeyModelCompatibilityForExecutor ¶ added in v8.0.7
func TranslateRequestWithAPIKeyModelCompatibilityForExecutor(ctx context.Context, headers http.Header, cfg *config.Config, targetExecutor string, from, to sdktranslator.Format, model string, payload []byte, stream, isCompat bool) []byte
TranslateRequestWithAPIKeyModelCompatibilityForExecutor applies compatibility-aware request translation while preserving the actual target executor's schema policy.
func TranslateRequestWithCodexMultiAgentV2 ¶
func TranslateRequestWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, payload []byte, stream bool) []byte
TranslateRequestWithCodexMultiAgentV2 normalizes official Codex multi-agent input before translating it to a non-Codex target protocol.
func TranslateRequestWithCodexMultiAgentV2ForExecutor ¶ added in v8.0.7
func TranslateRequestWithCodexMultiAgentV2ForExecutor(ctx context.Context, headers http.Header, cfg *config.Config, targetExecutor string, from, to sdktranslator.Format, model string, payload []byte, stream bool) []byte
TranslateRequestWithCodexMultiAgentV2ForExecutor applies Codex client compatibility while respecting the actual target executor identity.
func TranslateStreamWithClaudeInputTokens ¶
func TranslateStreamWithClaudeInputTokens( ctx context.Context, upstreamFormat, responseFormat sdktranslator.Format, model string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, param *any, state *ClaudeInputTokenState, ) [][]byte
TranslateStreamWithClaudeInputTokens translates a stream chunk and estimates Claude message_start input usage once.
func TranslatedClaudeErrorPayload ¶ added in v8.0.29
func TranslatedClaudeErrorPayload(responseFormat sdktranslator.Format, out []byte) (string, bool)
TranslatedClaudeErrorPayload returns the raw JSON payload when a non-streaming translation to Claude format produced a terminal error object instead of a message.
func TranslatedClaudeStreamErrorPayload ¶ added in v8.0.29
func TranslatedClaudeStreamErrorPayload(responseFormat sdktranslator.Format, lines [][]byte) (string, bool)
TranslatedClaudeStreamErrorPayload returns the raw JSON data payload when a translated Claude SSE chunk contains an error event.
func UnsealAntigravityCompaction ¶
UnsealAntigravityCompaction decrypts and validates an opaque capsule.
func ValidateResponsesCompactionSummaryStatus ¶ added in v8.0.35
ValidateResponsesCompactionSummaryStatus ensures the upstream summary response finished with status "completed".
func VertexAPIKeyOpenAPIBaseURL ¶ added in v8.0.34
VertexAPIKeyOpenAPIBaseURL builds the OpenAI-compatible base URL for a third-party Vertex-compatible API-key credential.
func VertexAuthBaseURL ¶ added in v8.0.34
func VertexAuthBaseURL(auth *cliproxyauth.Auth) string
VertexAuthBaseURL extracts an optional custom base_url from a Vertex credential.
func VertexAuthProjectID ¶ added in v8.0.34
func VertexAuthProjectID(auth *cliproxyauth.Auth) string
VertexAuthProjectID extracts an optional project_id from a Vertex credential.
func VertexOpenAPIHostBaseURL ¶ added in v8.0.34
VertexOpenAPIHostBaseURL returns the Vertex regional or global host URL.
func VertexOpenAPILocation ¶ added in v8.0.34
func VertexOpenAPILocation(auth *cliproxyauth.Auth, defaultLocation string) string
VertexOpenAPILocation returns the target Vertex location for OpenAPI requests, preferring an explicit openapi_location override on the credential.
func VertexServiceAccountOpenAPIBaseURL ¶ added in v8.0.34
VertexServiceAccountOpenAPIBaseURL builds the OpenAI-compatible base URL for a Vertex service-account credential (.../v1/projects/{project}/locations/{location}/endpoints/openapi).
func WebsocketUpgradeRequestURL ¶
WebsocketUpgradeRequestURL converts a websocket URL back to its HTTP handshake URL for logging.
func WithAntigravityConnectionTrace ¶ added in v8.0.11
func WithAntigravityConnectionTrace(req *http.Request, auth *cliproxyauth.Auth, operation string) *http.Request
WithAntigravityConnectionTrace reports upstream connection reuse only in debug mode. It preserves existing trace hooks and never logs URLs, headers, or credential material.
func WithAntigravityHTTPClientTrace ¶ added in v8.0.11
func WithAntigravityHTTPClientTrace(client *http.Client, auth *cliproxyauth.Auth, operation string) *http.Client
WithAntigravityHTTPClientTrace traces each actual request, including redirects. The client copy keeps the original pooled transport and client settings.
func WithClaudeContinuityContext ¶
func WithClaudeContinuityContext(ctx context.Context, cc *ClaudeContinuityContext) context.Context
WithClaudeContinuityContext attaches a mutable ClaudeContinuityContext to ctx.
func WithClaudeExecutionMetadata ¶
WithClaudeExecutionMetadata attaches whether the request had an explicit execution session metadata to ctx.
func WithClaudeSessionID ¶
WithClaudeSessionID attaches a known Claude session ID to ctx.
func WithIncomingHeaders ¶
WithIncomingHeaders attaches incoming HTTP headers to ctx.
func WithPayloadFinalizer ¶ added in v8.0.14
func WithPayloadFinalizer(ctx context.Context, finalize PayloadFinalizer) context.Context
WithPayloadFinalizer carries the final barrier through shared request builders.
func WrapConnectEnvelope ¶
WrapConnectEnvelope wraps raw payload bytes into a standard 5-byte Connect envelope: [1 byte flag: 0x00] + [4 byte big-endian length] + [payload].
func WrapConnectEnvelopeWithFlag ¶
WrapConnectEnvelopeWithFlag wraps payload bytes with an explicit Connect flag.
Types ¶
type AntigravityInteractionsState ¶ added in v8.0.14
type AntigravityInteractionsState struct {
// contains filtered or unexported fields
}
AntigravityInteractionsState tracks a single request, including streamed steps. The cache namespace is computed before continuation rewriting and payload rules.
func PrepareAntigravityInteractions ¶ added in v8.0.14
func PrepareAntigravityInteractions(auth *cliproxyauth.Auth, req cliproxyexecutor.Request, opts cliproxyexecutor.Options, model string, body []byte) (*AntigravityInteractionsState, []byte)
PrepareAntigravityInteractions restores only a matching tool-result suffix. Explicit continuation always wins, including an explicitly empty field.
func (*AntigravityInteractionsState) Observe ¶ added in v8.0.14
func (s *AntigravityInteractionsState) Observe(payload []byte)
Observe records only completed requires_action interactions, never failed or truncated streams. Stream events may carry steps outside the final snapshot.
type ApplyPatchResponsesState ¶ added in v8.0.9
type ApplyPatchResponsesState struct {
Bridge *translatorcommon.ApplyPatchResponsesBridge
// contains filtered or unexported fields
}
ApplyPatchResponsesState is owned explicitly by a non-native executor, never inferred from the wire format or a configured function schema. Supporting state stays request-local.
func NewApplyPatchResponsesState ¶ added in v8.0.9
func NewApplyPatchResponsesState(source sdktranslator.Format, original, declarations []byte) *ApplyPatchResponsesState
func (*ApplyPatchResponsesState) Active ¶ added in v8.0.9
func (s *ApplyPatchResponsesState) Active() bool
Active reports whether this explicitly non-native state owns a winning patch declaration.
func (*ApplyPatchResponsesState) AddDispatcher ¶ added in v8.0.9
func (s *ApplyPatchResponsesState) AddDispatcher(name, namespace string)
AddDispatcher marks only xAI folded namespaces that contain a winning custom patch.
func (*ApplyPatchResponsesState) Finish ¶ added in v8.0.9
func (s *ApplyPatchResponsesState) Finish() error
Finish validates source response closure independently of completed tool input. Common Finish remains argument-only because it also runs inside terminal conversion.
func (*ApplyPatchResponsesState) FinishStream ¶ added in v8.0.9
func (s *ApplyPatchResponsesState) FinishStream() ([][]byte, error)
FinishStream emits the local failure once on EOF without a validated completion.
func (*ApplyPatchResponsesState) RememberDispatcherArguments ¶ added in v8.0.9
func (s *ApplyPatchResponsesState) RememberDispatcherArguments(event []byte)
RememberDispatcherArguments keeps full snapshots on every matched candidate, including unnamed calls. The common bridge retains all identity/type contradictions until acquisition.
func (*ApplyPatchResponsesState) RememberDispatcherEvent ¶ added in v8.0.9
func (s *ApplyPatchResponsesState) RememberDispatcherEvent(event []byte)
RememberDispatcherEvent retains upstream evidence before namespace restoration. A wrapper alone never proves dispatcher provenance: only a declared dispatcher name does.
type ClaudeCodeRequestDetection ¶
type ClaudeCodeRequestDetection struct {
Confirmed bool
StrongSignals bool
NativeClient bool
XAppCLI bool
UserAgent bool
BetasPresent bool
MetadataUserID bool
HelperProfile bool
Entrypoint string
Subclient string
AgentSDKVersion string
}
ClaudeCodeRequestDetection records the strong signals and first-party subclient identity used to distinguish an official Claude Code request from a client that only copied its User-Agent.
func DetectClaudeCodeRequest ¶
func DetectClaudeCodeRequest(headers http.Header, payload []byte, countTokens bool, configs ...*config.Config) ClaudeCodeRequestDetection
DetectClaudeCodeRequest first mirrors CCH's strong-signal contract, then applies CPA's native-client policy. Standard Messages requests require all four strong signals; count_tokens omits metadata.user_id. A separate narrow profile recognizes measured native Haiku helper requests that intentionally omit claude-code-20250219. Generic sdk-ts/sdk-py Agent SDK entrypoints remain unconfirmed and receive CLI cloaking.
type ClaudeContinuityContext ¶
type ClaudeContinuityContext struct {
Key string
Sequence uint64
PreviousMessageID string
PreviousRequestID string
PromptID string
// PinnedDate is the calendar date this session was first seen on. The
// cloaked currentDate reminder reuses it so the reminder text stays
// byte-stable within a session even when the local date flips mid-session.
PinnedDate string
Initialized bool
}
ClaudeContinuityContext holds request-scoped continuity state across cloaking and execution.
func ClaudeContinuityContextFromContext ¶
func ClaudeContinuityContextFromContext(ctx context.Context) *ClaudeContinuityContext
ClaudeContinuityContextFromContext retrieves the ClaudeContinuityContext from ctx, if present.
type ClaudeDeviceProfile ¶
type ClaudeDeviceProfile struct {
UserAgent string
PackageVersion string
RuntimeVersion string
OS string
Arch string
// contains filtered or unexported fields
}
func ResolveClaudeDeviceProfile ¶
func ResolveClaudeDeviceProfile(auth *cliproxyauth.Auth, apiKey string, headers http.Header, cfg *config.Config) ClaudeDeviceProfile
func ResolveClaudeDeviceProfileRequired ¶
func ResolveClaudeDeviceProfileRequired(ctx context.Context, auth *cliproxyauth.Auth, apiKey string, headers http.Header, cfg *config.Config) (ClaudeDeviceProfile, error)
ResolveClaudeDeviceProfileRequired resolves a stable Claude Code device profile for request-time paths.
type ClaudeInputTokenState ¶
type ClaudeInputTokenState struct {
// contains filtered or unexported fields
}
ClaudeInputTokenState tracks the one-time input token update for a translated Claude stream.
func NewClaudeInputTokenState ¶
func NewClaudeInputTokenState(sourceFormat, upstreamFormat, responseFormat sdktranslator.Format, originalRequest []byte) *ClaudeInputTokenState
NewClaudeInputTokenState creates request-scoped state for translated Claude input token usage.
type CodexCache ¶
func ClaudeCodePromptCache ¶
func ClaudeCodePromptCache(ctx context.Context, modelName string, payload []byte, headers http.Header) (CodexCache, bool, error)
ClaudeCodePromptCache derives a deterministic upstream prompt_cache_key for one Claude Code agent.
func GetCodexCache ¶
func GetCodexCache(key string) (CodexCache, bool)
GetCodexCache retrieves a cached entry, returning ok=false if not found or expired.
func GetCodexCacheRequired ¶
GetCodexCacheRequired retrieves a cached entry for request-time paths.
type CodexSSEScanner ¶ added in v8.0.28
type CodexSSEScanner struct {
// contains filtered or unexported fields
}
CodexSSEScanner reads an upstream Responses SSE stream line by line, as bufio.Scanner does, but delivers an event whose data the upstream split across several "data:" lines as one "data:" line. In SSE an event's data may span several data lines, joined with "\n". Taking each data line as a whole event instead cuts such an event: on a split response.completed the stream ends at the first fragment and the rest is never read.
Every event on this path is one JSON value. A data line that is complete JSON on its own, or cannot start JSON at all (an empty value, [DONE]), is delivered byte-for-byte as read with no lookahead, which keeps upstreams that omit the blank line between events working as before. A data line that opens a JSON object or array without completing it starts an event that collects the following data lines until one of these:
- their joined value closes its outermost object or array;
- a blank line ends the event;
- the stream ends;
- the collected bytes would exceed the line limit.
A completed event is delivered compacted onto one line. One that never becomes valid JSON is delivered as the same multi-line data field, so it still fails downstream. The first such event in a stream gets one warning that describes its framing without any of its bytes.
The scanner merges data lines and nothing else. It holds only the data lines of an event being collected and delivers every other line the moment it reads it, in the order read. A comment, id: or retry: line inside such an event therefore comes before the event's data instead of between its pieces, which SSE treats alike: an event's fields take effect when it is dispatched. The blank line or over-limit line that ends a collection follows the event's data.
SetAssembly(false) makes the scanner read exactly as bufio.Scanner does, for a caller that budgets every upstream line while it holds a stream.
func NewCodexSSEScanner ¶ added in v8.0.28
NewCodexSSEScanner returns a CodexSSEScanner over r, with assembly on. maxBytes bounds one line, as bufio.Scanner.Buffer does, and also the data lines collected for one event.
func (*CodexSSEScanner) Bytes ¶ added in v8.0.28
func (s *CodexSSEScanner) Bytes() []byte
Bytes returns the current line. It stays valid until the next call to Scan.
func (*CodexSSEScanner) Err ¶ added in v8.0.28
func (s *CodexSSEScanner) Err() error
Err returns the error that stopped the scan, as bufio.Scanner does.
func (*CodexSSEScanner) HeldBytes ¶ added in v8.0.28
func (s *CodexSSEScanner) HeldBytes() int
HeldBytes returns how many bytes are currently held in an incomplete event.
func (*CodexSSEScanner) HeldLines ¶ added in v8.0.28
func (s *CodexSSEScanner) HeldLines() int
HeldLines returns how many data lines are currently held in an incomplete event.
func (*CodexSSEScanner) RawBytes ¶ added in v8.0.28
func (s *CodexSSEScanner) RawBytes() int
RawBytes returns the total bytes of physical upstream lines consumed to produce the current event.
func (*CodexSSEScanner) RawLines ¶ added in v8.0.28
func (s *CodexSSEScanner) RawLines() int
RawLines returns the count of physical upstream lines consumed to produce the current event.
func (*CodexSSEScanner) Scan ¶ added in v8.0.28
func (s *CodexSSEScanner) Scan() bool
Scan advances to the next line, or to the next assembled event data line.
func (*CodexSSEScanner) SetAssembly ¶ added in v8.0.28
func (s *CodexSSEScanner) SetAssembly(on bool)
SetAssembly turns event assembly on or off. While it is off, no data line starts a collection and every line is delivered as read, exactly as bufio.Scanner delivers it. An event already being collected is still completed.
func (*CodexSSEScanner) SetBudgetChecker ¶ added in v8.0.28
func (s *CodexSSEScanner) SetBudgetChecker(fn func(line []byte, heldLines int, heldBytes int) bool)
SetBudgetChecker sets an optional callback invoked on each raw line read while an event is being held. If it returns true, the scanner yields from Scan() with an empty payload to signal that the caller should release buffering, while preserving the held assembly state for subsequent Scan() calls.
func (*CodexSSEScanner) SetOnLine ¶ added in v8.0.28
func (s *CodexSSEScanner) SetOnLine(fn func(line []byte))
SetOnLine sets a callback invoked for every physical line read from upstream.
type DevinFrameResult ¶
type DevinFrameResult struct {
OutputID string
Timestamp uint64
ContentText string
DeltaTokens uint64
StopReason uint64 // 2/4=stop, 10=tool_calls
ToolCallDeltas []DevinToolCallDelta
ThinkingText string
DeltaSignature []byte
DeltaSignatureType string
Latency float64
MessageID string
Usage *DevinUsage
ResponseDimensionGroups [][]byte
UnknownFieldNumbers []int
}
DevinFrameResult represents decoded content from a single Connect-proto frame.
func ParseDevinFrame ¶
func ParseDevinFrame(payload []byte) (DevinFrameResult, error)
ParseDevinFrame extracts deltas, tool calls, thinking, signatures, and usage from a single response frame.
type DevinImage ¶
DevinImage represents an image attachment in a DevinPrompt (Prompt #10).
type DevinImageLogItem ¶
DevinImageLogItem represents an image attached to a prompt in the request log.
type DevinPrompt ¶
type DevinPrompt struct {
MessageID string
Source int // 1=user, 2=assistant, 4=tool
Content string
Images []DevinImage
ToolCalls []DevinToolCall
ToolCallID string // For source=4 (tool result)
OriginalToolCallID string // Retained when downgraded from source=4 to source=1
IsOrphanedTool bool // Explicit flag marking downgraded tool results
DroppedPart string // Type of a user media part Devin cannot send; never put on the wire
Thinking string
Signature []byte
SignatureType string
}
DevinPrompt represents a single turn in the request history (repeated Field 3).
func CheckDevinUserTurns ¶ added in v8.0.20
func CheckDevinUserTurns(prompts []DevinPrompt) ([]DevinPrompt, error)
CheckDevinUserTurns applies the shared user-turn policy to the parsed prompts. Devin can only receive inline images, so a user prompt that dropped media it cannot fetch or carry (a remote uri, audio, video, a document) is refused with an unsupported content part error when its whole user turn has nothing else to send. A tool result or real text in the same turn keeps the turn alive; the emptied prompt is then removed so that no empty user prompt, and no placeholder standing in for the media, reaches upstream.
type DevinPromptLogItem ¶
type DevinPromptLogItem struct {
ID string `json:"id,omitempty"`
Source int `json:"source"`
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
SignatureType string `json:"signature_type,omitempty"`
ToolCalls []DevinToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
Images []DevinImageLogItem `json:"images,omitempty"`
}
DevinPromptLogItem represents a single prompt item in the request log.
type DevinQuotaPeriod ¶ added in v8.0.32
type DevinQuotaPeriod int
DevinQuotaPeriod identifies an account-wide Devin usage quota window.
const ( // DevinQuotaPeriodNone means the error is not an account-wide // daily/weekly usage quota exhaustion. DevinQuotaPeriodNone DevinQuotaPeriod = iota // DevinQuotaPeriodDaily marks daily usage quota exhaustion. DevinQuotaPeriodDaily // DevinQuotaPeriodWeekly marks weekly usage quota exhaustion. DevinQuotaPeriodWeekly )
func DevinUsageQuotaExhaustionPeriod ¶ added in v8.0.32
func DevinUsageQuotaExhaustionPeriod(message string) DevinQuotaPeriod
DevinUsageQuotaExhaustionPeriod reports whether the upstream error message explicitly says the account-wide daily or weekly usage quota has been exhausted (issue #6690). Matching is deliberately narrow: the period word, "quota", and "exhausted" must all be present, so monthly ACU messages, generic rate limits, and transient capacity errors never match and stay on the short per-model backoff path. If the message somehow names both periods, weekly wins because it is the longer window.
type DevinToolCall ¶
DevinToolCall represents a tool call in a ChatMessagePrompt.
type DevinToolCallDelta ¶
type DevinToolCallDelta struct {
ID string
Name string
Arguments string
InvalidJSONStr string
InvalidJSONErr string
IsCustomToolCall bool
}
DevinToolCallDelta represents a streaming tool call chunk from response Field 6.
type DevinToolLogItem ¶
type DevinToolLogItem struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters,omitempty"`
}
DevinToolLogItem represents a tool declared in the request log.
type DevinUpstreamRequestLog ¶
type DevinUpstreamRequestLog struct {
Model string `json:"model"`
SessionID string `json:"session_id,omitempty"`
CascadeID string `json:"cascade_id,omitempty"`
SystemPrompt string `json:"system_prompt,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Prompts []DevinPromptLogItem `json:"prompts,omitempty"`
Tools []DevinToolLogItem `json:"tools,omitempty"`
}
DevinUpstreamRequestLog represents the human-readable JSON representation of GetChatMessageRequest for request logs.
type DevinUpstreamResponseLog ¶
type DevinUpstreamResponseLog struct {
Status string `json:"status,omitempty"`
FramesCount int `json:"frames_count"`
Content string `json:"content,omitempty"`
Thinking string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
SignatureType string `json:"signature_type,omitempty"`
ToolCalls []DevinToolCall `json:"tool_calls,omitempty"`
Usage *DevinUsage `json:"usage,omitempty"`
UnknownFields []int `json:"unknown_fields,omitempty"`
}
DevinUpstreamResponseLog represents the decoded response frames from Devin Connect-RPC.
type DevinUsage ¶
type DevinUsage struct {
PromptTokens int64 `json:"prompt_tokens"`
CompletionTokens int64 `json:"completion_tokens"`
CachedTokens int64 `json:"cached_tokens"`
CacheWriteTokens int64 `json:"cache_write_tokens,omitempty"`
StatusCode uint64 `json:"status_code,omitempty"`
RequestID string `json:"request_id,omitempty"`
ModelName string `json:"model_name,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
DevinUsage captures token accounting from response Field 7.
type PayloadFinalizer ¶ added in v8.0.14
PayloadFinalizer applies user rules to a fully prepared business payload. Each rebuilt attempt must start from the unconfigured body, not a previous result.
func NewPayloadFinalizer ¶ added in v8.0.14
func NewPayloadFinalizer(cfg *config.Config, executor, model, protocol, root string, original []byte, req cliproxyexecutor.Request, opts cliproxyexecutor.Options) PayloadFinalizer
NewPayloadFinalizer snapshots matching context before built-in request mutations.
type SensitiveWordMatcher ¶
type SensitiveWordMatcher struct {
// contains filtered or unexported fields
}
SensitiveWordMatcher holds the compiled regex for matching sensitive words.
func BuildSensitiveWordMatcher ¶
func BuildSensitiveWordMatcher(words []string) *SensitiveWordMatcher
BuildSensitiveWordMatcher compiles a regex from the word list. Words are sorted by length (longest first) for proper matching.
func (*SensitiveWordMatcher) Matches ¶
func (m *SensitiveWordMatcher) Matches(text string) bool
Matches reports whether the text contains any of the configured sensitive words.
func (*SensitiveWordMatcher) ObfuscateText ¶
func (m *SensitiveWordMatcher) ObfuscateText(text string) string
ObfuscateText replaces all sensitive words in the text.
type StreamResponseModelObserver ¶
type StreamResponseModelObserver struct {
// contains filtered or unexported fields
}
StreamResponseModelObserver accumulates streaming chunks using a bounded buffer and extracts complete SSE lines or events to observe the response model, ensuring extraction does not depend on network chunk boundaries.
func NewStreamResponseModelObserver ¶
func NewStreamResponseModelObserver(reporter *UsageReporter) *StreamResponseModelObserver
NewStreamResponseModelObserver creates an observer for tracking response models from arbitrary streaming network chunks.
func (*StreamResponseModelObserver) Feed ¶
func (o *StreamResponseModelObserver) Feed(chunk []byte)
Feed ingests a raw chunk of bytes from a stream, splitting into lines and events.
func (*StreamResponseModelObserver) Finish ¶
func (o *StreamResponseModelObserver) Finish()
Finish flushes any pending buffered line or event at the end of the stream.
type StreamUsageBuffer ¶
type StreamUsageBuffer struct {
// contains filtered or unexported fields
}
StreamUsageBuffer keeps the latest usage detail observed in a stream.
func (*StreamUsageBuffer) Detail ¶
func (b *StreamUsageBuffer) Detail() (usage.Detail, bool)
Detail returns the latest observed usage detail.
func (*StreamUsageBuffer) Observe ¶
func (b *StreamUsageBuffer) Observe(detail usage.Detail, ok bool)
Observe records detail when ok is true, allowing the final stream usage to win.
func (*StreamUsageBuffer) ObserveClaudeStream ¶
func (b *StreamUsageBuffer) ObserveClaudeStream(line []byte)
ObserveClaudeStream records and merges usage from a Claude SSE line.
func (*StreamUsageBuffer) ObserveOpenAIStream ¶
func (b *StreamUsageBuffer) ObserveOpenAIStream(line []byte)
ObserveOpenAIStream records response-tier state and the latest usage from an OpenAI-style stream while avoiding JSON parsing for irrelevant chunks.
func (*StreamUsageBuffer) Publish ¶
func (b *StreamUsageBuffer) Publish(ctx context.Context, reporter *UsageReporter) bool
Publish emits the latest observed usage detail, if any.
func (*StreamUsageBuffer) PublishFailure ¶
func (b *StreamUsageBuffer) PublishFailure(ctx context.Context, reporter *UsageReporter, errs ...error) bool
PublishFailure emits the latest observed usage detail together with failure details.
func (*StreamUsageBuffer) ResponseModel ¶
func (b *StreamUsageBuffer) ResponseModel() string
ResponseModel returns the latest model observed in the stream buffer.
type TransportCache ¶
type TransportCache[K comparable] struct { // contains filtered or unexported fields }
TransportCache memoizes HTTP transports under a comparable key using a bounded LRU. Evicting an entry closes its idle connections so neither the pool nor its background goroutines outlive the cache entry.
The key type is generic so callers can mix value identity (a normalized proxy URL) with pointer identity (a base transport supplied by the caller) without the cache retaining either beyond the LRU window.
func NewTransportCache ¶
func NewTransportCache[K comparable](capacity int) *TransportCache[K]
NewTransportCache returns a cache holding at most capacity transports. A non-positive capacity falls back to DefaultTransportCacheCapacity.
func (*TransportCache[K]) CloseKey ¶
func (c *TransportCache[K]) CloseKey(key K) bool
CloseKey removes the transport cached under key (if present) and closes its idle connections. Returns true if the entry was found and closed.
func (*TransportCache[K]) CloseMatching ¶
func (c *TransportCache[K]) CloseMatching(predicate func(key K) bool) int
CloseMatching removes and closes idle connections for every cached transport whose key satisfies predicate. Returns the number of closed transports.
func (*TransportCache[K]) Contains ¶
func (c *TransportCache[K]) Contains(key K) bool
Contains reports whether key exists in the cache.
func (*TransportCache[K]) Get ¶
func (c *TransportCache[K]) Get(key K, build func() (*http.Transport, error)) (*http.Transport, error)
Get returns the transport cached under key, calling build on the first use of that key. Concurrent callers observe the same instance.
A build error is propagated without being cached, so a later call can retry and a failed lookup never occupies a cache slot. build must not call back into the same cache.
func (*TransportCache[K]) Len ¶
func (c *TransportCache[K]) Len() int
Len reports how many transports the cache currently holds.
func (*TransportCache[K]) Purge ¶
func (c *TransportCache[K]) Purge()
Purge drops every entry and closes the idle connections it was holding.
type UTF8SplitBuffer ¶
type UTF8SplitBuffer struct {
// contains filtered or unexported fields
}
UTF8SplitBuffer buffers incomplete UTF-8 byte sequences across chunk boundaries.
func (*UTF8SplitBuffer) Feed ¶
func (b *UTF8SplitBuffer) Feed(chunk []byte) string
Feed consumes a byte chunk, prepending any pending remainder, and returns complete UTF-8 strings.
type UpstreamRequestLog ¶
type UpstreamRequestLog struct {
URL string
Method string
Headers http.Header
Body []byte
Provider string
AuthID string
AuthLabel string
AuthType string
AuthValue string
}
UpstreamRequestLog captures the outbound upstream request details for logging.
type UsageReporter ¶
type UsageReporter struct {
// contains filtered or unexported fields
}
func NewExecutorUsageReporter ¶
func NewExecutorUsageReporter(ctx context.Context, executor usageExecutor, model string, auth *cliproxyauth.Auth) *UsageReporter
func NewUsageReporter ¶
func NewUsageReporter(ctx context.Context, provider, model string, auth *cliproxyauth.Auth) *UsageReporter
func (*UsageReporter) AccessProvider ¶ added in v8.0.24
func (r *UsageReporter) AccessProvider() string
AccessProvider identifies the client request authentication provider.
func (*UsageReporter) EnsurePublished ¶
func (r *UsageReporter) EnsurePublished(ctx context.Context)
ensurePublished guarantees that a usage record is emitted exactly once. It is safe to call multiple times; only the first call wins due to once.Do. This is used to ensure request counting even when upstream responses do not include any usage fields (tokens), especially for streaming paths.
func (*UsageReporter) IsFirstPacketSet ¶
func (r *UsageReporter) IsFirstPacketSet() bool
func (*UsageReporter) IsNativeKey ¶ added in v8.0.24
func (r *UsageReporter) IsNativeKey() bool
IsNativeKey reports whether the client API key was authenticated by CPA's native config provider.
func (*UsageReporter) IsResponseModelFinal ¶
func (r *UsageReporter) IsResponseModelFinal() bool
IsResponseModelFinal reports whether the response model was already finalized by a terminal event.
func (*UsageReporter) IsTTFTSet ¶
func (r *UsageReporter) IsTTFTSet() bool
func (*UsageReporter) MarkFirstResponseByte ¶
func (r *UsageReporter) MarkFirstResponseByte()
func (*UsageReporter) ObserveResponse ¶
func (r *UsageReporter) ObserveResponse(resp *http.Response)
func (*UsageReporter) ObserveResponseModel ¶
func (r *UsageReporter) ObserveResponseModel(payload []byte)
ObserveResponseModel stores the model reported by an upstream response or event and ignores payloads without one; the substitution warning is emitted at publish time.
func (*UsageReporter) ObserveResponsePacketOnly ¶
func (r *UsageReporter) ObserveResponsePacketOnly(resp *http.Response)
func (*UsageReporter) ObserveTokenEvent ¶
func (r *UsageReporter) ObserveTokenEvent(isToken bool)
ObserveTokenEvent records the first packet fallback time on the first frame, and if isToken is true, records the effective TTFT. It uses a fast-path read check to return immediately with zero write lock contention once TTFT is set or when subsequent non-token metadata frames arrive after the first packet.
func (*UsageReporter) Publish ¶
func (r *UsageReporter) Publish(ctx context.Context, detail usage.Detail)
func (*UsageReporter) PublishAdditionalModel ¶
func (*UsageReporter) PublishFailure ¶
func (r *UsageReporter) PublishFailure(ctx context.Context, errs ...error)
func (*UsageReporter) PublishFailureWithDetail ¶
func (*UsageReporter) RecordFirstPacket ¶
func (r *UsageReporter) RecordFirstPacket()
RecordFirstPacket records the arrival time of the first packet/chunk from upstream as a fallback.
func (*UsageReporter) RequestID ¶
func (r *UsageReporter) RequestID() string
RequestID returns the execution instance request ID for this reporter.
func (*UsageReporter) ResponseModel ¶
func (r *UsageReporter) ResponseModel() string
ResponseModel returns the latest model reported by the upstream response.
func (*UsageReporter) SetResponseModel ¶
func (r *UsageReporter) SetResponseModel(model string)
SetResponseModel sets the reported model directly if valid and not already marked final.
func (*UsageReporter) SetSessionHierarchy ¶
func (r *UsageReporter) SetSessionHierarchy(sessionID, parentSessionID string)
SetSessionHierarchy sets the explicit session and parent session identifiers. Callers should invoke this method before Publish or EnsurePublished on the request thread.
func (*UsageReporter) SetStream ¶
func (r *UsageReporter) SetStream(stream bool)
SetStream records whether the request was executed in streaming mode.
func (*UsageReporter) SetTranslatedReasoningEffort ¶
func (r *UsageReporter) SetTranslatedReasoningEffort(payload []byte, format string)
func (*UsageReporter) SetUpstreamModel ¶
func (r *UsageReporter) SetUpstreamModel(model string)
SetUpstreamModel records the upstream model expected to be served when it differs from the requested model (e.g. due to provider-specific mapping or canonicalization). Model substitution detection compares the response against this upstream model, while usage accounting preserves the client's requested model.
func (*UsageReporter) StartResponseTTFT ¶
func (r *UsageReporter) StartResponseTTFT()
func (*UsageReporter) TraceID ¶
func (r *UsageReporter) TraceID() string
TraceID returns the parent inbound request ID for this reporter.
func (*UsageReporter) TrackFailure ¶
func (r *UsageReporter) TrackFailure(ctx context.Context, errPtr *error)
func (*UsageReporter) TrackHTTPClient ¶
func (r *UsageReporter) TrackHTTPClient(client *http.Client) *http.Client
func (*UsageReporter) TrackHTTPClientRoundTripOnly ¶
func (r *UsageReporter) TrackHTTPClientRoundTripOnly(client *http.Client) *http.Client
TrackHTTPClientRoundTripOnly records the TTFT start time upon sending the request and captures first-packet arrival fallback on initial body reads, while keeping effective TTFT unset. This allows protocol-aware streaming executors (like Codex SSE) to mark effective TTFT explicitly upon receiving substantive token events, while preserving first-packet fallback metrics for non-2xx error bodies or keepalive streams.
func (*UsageReporter) UpdateAccessTokenFingerprint ¶
func (r *UsageReporter) UpdateAccessTokenFingerprint(auth *cliproxyauth.Auth)
UpdateAccessTokenFingerprint records the token version actually used upstream.
func (*UsageReporter) UpstreamModel ¶
func (r *UsageReporter) UpstreamModel() string
UpstreamModel returns the expected upstream model, or an empty string if not explicitly set.
Source Files
¶
- antigravity_compaction.go
- antigravity_connection_trace.go
- antigravity_grounding_urls.go
- antigravity_interactions_state.go
- apply_patch.go
- apply_patch_responses.go
- cache_helpers.go
- chat_ttft_helpers.go
- claude_builtin_tools.go
- claude_cli_identity_seed.go
- claude_client_detection.go
- claude_code_session.go
- claude_credential_identity.go
- claude_device_profile.go
- claude_diagnostics.go
- claude_input_tokens.go
- claude_json_prefilter.go
- claude_mcp_alias.go
- claude_mcp_alias_wordlist.go
- claude_ratelimit.go
- claude_tool_search_model.go
- claude_ttft_helpers.go
- claude_upstream.go
- claude_web_search_results.go
- cloak_obfuscate.go
- cloak_utils.go
- codex_input_ids.go
- codex_multi_agent_v2.go
- codex_native.go
- codex_quota.go
- codex_sse_scanner.go
- codex_terminal_incomplete.go
- codex_tool_schema.go
- cpa_session.go
- derived_session.go
- devin_models.go
- devin_payload.go
- devin_quota.go
- devin_user_turn.go
- devin_wire.go
- gemini_content_turns.go
- gemini_interactions.go
- gemini_ttft_helpers.go
- home_refresh.go
- json_retry_helpers.go
- kimi_responses.go
- logging_helpers.go
- meta_tools.go
- model_capabilities.go
- openai_compat_max_tokens.go
- openai_compat_tool_results.go
- payload_finalizer.go
- payload_helpers.go
- payload_media.go
- payload_mutations.go
- plugin_executor_usage.go
- proxy_helpers.go
- response_model.go
- responses_tool_search.go
- responses_ttft_helpers.go
- responses_usage_helpers.go
- session_id_cache.go
- stream_response_model_observer.go
- thinking.go
- thinking_providers.go
- token_helpers.go
- tool_call_ids.go
- transport_cache.go
- usage_helpers.go
- user_id_cache.go
- utls_client.go
- utls_handshake_timeout.go
- vertex_openapi.go
- vertex_payload_helpers.go
- websocket_observer_helpers.go
- xai_version.go