Documentation
¶
Index ¶
- Constants
- Variables
- func APIKeyFromContext(ctx context.Context) string
- func APIKeyModelIsCompat(req cliproxyexecutor.Request) bool
- 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 ApplyClaudeDeviceProfileHeaders(r *http.Request, profile ClaudeDeviceProfile)
- func ApplyClaudeLegacyDeviceHeaders(r *http.Request, ginHeaders http.Header, cfg *config.Config)
- func ApplyPayloadConfigWithRequest(cfg *config.Config, model, protocol, fromProtocol, root string, ...) []byte
- 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 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 CachedSessionID(apiKey string) string
- func CachedUserID(apiKey string) string
- 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 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 ClaudePayloadHas1hTTL(payload []byte) bool
- func ClaudeRequestHasExecutionMetadata(metadataSets ...map[string]any) bool
- func ClaudeSessionDatePinKey(sessionID string) string
- func ClaudeSessionIDFromContext(ctx context.Context) string
- func ClaudeSubagentRequests1h(headers http.Header, body []byte) bool
- func CommitClaudeContinuity(key string, sequence uint64, messageID, requestID string, promptIDs ...string)
- func CommitClaudeDiagnostics(key string, sequence uint64, messageID string)
- func CountOpenAIChatTokens(enc tokenizer.Codec, payload []byte) (int64, error)
- func CreditsUsed(ctx context.Context) bool
- func DefaultClaudeVersion(cfg *config.Config) string
- func DerivedAntigravitySessionID(metadataSets ...map[string]any) string
- func DerivedSessionID(metadataSets ...map[string]any) string
- func DerivedSessionUUID(provider string, metadataSets ...map[string]any) string
- func DropGeminiTrailingThoughtOnlyContent(payload []byte, path string) []byte
- 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 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 FilterSSEUsageMetadata(payload []byte) []byte
- func GenerateDevinDeviceFingerprint(seed string) string
- func GenerateDevinSentryTrace() string
- func GenerateFakeUserID() string
- func HasDevinEffortSuffix(model string) bool
- func HasMeaningfulCodexOutputDelta(eventData []byte) bool
- func HasResponsesCompactionItem(payload []byte) bool
- func HasResponsesCompactionTrigger(payload []byte) 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 InjectClaudeBillingTags(body []byte, prevReq, promptID string) []byte
- func IsChatTokenEvent(payload []byte) 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 IsCodexModelSubstituted(requested, served string) bool
- func IsCodexTerminalEmptyIncomplete(eventData []byte, outputItemsCount int, sawOutputDelta bool) bool
- func IsGeminiTerminalStreamChunk(chunk []byte) bool
- func IsGeminiTokenEvent(payload []byte) 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 JSONPayload(line []byte) []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 NewDevinHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, ...) *http.Client
- func NewProxyAwareHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, ...) *http.Client
- func NewUtlsHTTPClient(cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) *http.Client
- func NextDevinSessionTurnIndex(sessionID string) int
- func NormalizeClaudeToolChoice(model string, payload []byte) []byte
- func NormalizeCodexToolSchemas(body []byte) []byte
- func NormalizeOpenAIMaxTokens(payload []byte, useMaxCompletionTokens bool) []byte
- func NormalizeOpenAIToolResultsTextOnly(payload []byte) []byte
- func NormalizeThinkingLevel(level string, budgetTokens int) string
- func ObfuscateSensitiveWords(payload []byte, matcher *SensitiveWordMatcher) []byte
- func ObserveChatTokenEvent(reporter *UsageReporter, payload []byte)
- func ObserveClaudeTokenEvent(reporter *UsageReporter, payload []byte)
- func ObserveGeminiTokenEvent(reporter *UsageReporter, payload []byte)
- 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 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 ParseGeminiCLIStreamUsage(line []byte) (usage.Detail, bool)
- func ParseGeminiCLIUsage(data []byte) usage.Detail
- 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 PayloadRequestPath(opts cliproxyexecutor.Options) string
- func PayloadRequestedModel(opts cliproxyexecutor.Options, fallback string) string
- func PinClaudeSessionDate(key, sessionID, date string, retention time.Duration) string
- func PrepareAntigravityClaudeStructuredOutput(model string, payload []byte) ([]byte, bool)
- func PrepareAntigravityCompactionSummaryPayload(payload []byte, modelName string) []byte
- func ProviderSessionUUID(provider string, metadataSets ...map[string]any) string
- func ReadConnectFrame(r io.Reader) (flag byte, payload []byte, err error)
- 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 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 RestoreCodexMultiAgentV2Response(payload []byte, optimized bool) []byte
- 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 SealAntigravityCompaction(summary, modelName string) (string, error)
- func SetBoolIfDifferent(payload []byte, path string, value bool) []byte
- func SetCodexCache(key string, cache CodexCache)
- func SetRawIfDifferent(payload []byte, path string, value []byte) []byte
- func SetStringIfDifferent(payload []byte, path, value string) []byte
- func SharedProxyTransport(scope, raw string) (*http.Transport, proxyutil.Mode, error)
- func ShouldCloak(cloakMode string, userAgent string) bool
- func ShouldNormalizeOpenAIToolResultsForModel(compat *config.OpenAICompatibility, upstreamModel, requestedModel string) bool
- func ShouldUseMaxCompletionTokensForModel(compat *config.OpenAICompatibility, upstreamModel, requestedModel string) bool
- func StopTranslatedClaudeStream(ctx context.Context, retainedErr *error, reporter *UsageReporter, ...) bool
- func StopTranslatedClaudeStreamWithDetail(ctx context.Context, retainedErr *error, reporter *UsageReporter, ...) bool
- func StripClaudeBillingTags(body []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 TranslateRequestEnvelopePairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) (original, working []byte)
- func TranslateRequestEnvelopeWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) sdktranslator.RequestEnvelope
- 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)
- func TranslateRequestPairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, ...) (original, working []byte)
- 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)
- func TranslateRequestWithCodexMultiAgentV2(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 WebsocketUpgradeRequestURL(rawURL string) string
- 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 WrapConnectEnvelope(protoBytes []byte) []byte
- func WrapConnectEnvelopeWithFlag(flag byte, protoBytes []byte) []byte
- type ClaudeContinuityContext
- type ClaudeDeviceProfile
- type ClaudeInputTokenState
- type CodexCache
- type DevinFrameResult
- type DevinImage
- type DevinImageLogItem
- type DevinPrompt
- type DevinPromptLogItem
- type DevinTool
- type DevinToolCall
- type DevinToolCallDelta
- type DevinToolLogItem
- type DevinUpstreamRequestLog
- type DevinUpstreamResponseLog
- type DevinUsage
- type SensitiveWordMatcher
- type StreamResponseModelObserver
- 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) EnsurePublished(ctx context.Context)
- func (r *UsageReporter) IsFirstPacketSet() bool
- func (r *UsageReporter) IsResponseModelFinal() bool
- func (r *UsageReporter) IsTTFTSet() bool
- func (r *UsageReporter) MarkFirstResponseByte()
- func (r *UsageReporter) ObserveCodexResponseModel(payload []byte)
- 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) SetEffectiveServiceTier(payload []byte)
- func (r *UsageReporter) SetResponseModel(model string)
- func (r *UsageReporter) SetSessionHierarchy(sessionID, parentSessionID string)
- func (r *UsageReporter) SetStream(stream bool)
- 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) 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 ClaudeCodeDoingTasks = `` /* 3327-byte string literal not displayed */
ClaudeCodeDoingTasks is the task guidance section. Corresponds to getSimpleDoingTasksSection() (non-ant version) in prompts.ts.
const ClaudeCodeIntro = `` /* 373-byte string literal not displayed */
ClaudeCodeIntro is the first system block after billing header and agent identifier. Corresponds to getSimpleIntroSection() in prompts.ts.
const ClaudeCodeOutputEfficiency = `` /* 732-byte string literal not displayed */
ClaudeCodeOutputEfficiency is the output efficiency section. Corresponds to getOutputEfficiencySection() (non-ant version) in prompts.ts.
const ClaudeCodeSystem = `` /* 1255-byte string literal not displayed */
ClaudeCodeSystem is the system instructions section. Corresponds to getSimpleSystemSection() in prompts.ts.
const ClaudeCodeSystemReminderSection = `` /* 347-byte string literal not displayed */
ClaudeCodeSystemReminderSection corresponds to getSystemRemindersSection() in prompts.ts.
const ClaudeCodeToneAndStyle = `` /* 551-byte string literal not displayed */
ClaudeCodeToneAndStyle is the tone and style guidance section. Corresponds to getSimpleToneAndStyleSection() in prompts.ts.
const ( // CodexEmptyIncompleteStreamMessage is the error message emitted when upstream ChatGPT Codex // terminates with response.incomplete having 0 output tokens and 0 content output. // Ported from upstream CLIProxyAPI internal/runtime/executor/helps/codex_terminal_incomplete.go. 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 ¶ added in v0.0.49
func APIKeyModelIsCompat(req cliproxyexecutor.Request) bool
APIKeyModelIsCompat reports whether the selected API-key model enables compatibility handling for Claude thinking blocks.
func AllocateClaudeMCPToolAlias ¶ added in v0.0.25
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 ¶ added in v0.0.28
AppendCodexAPIWebsocketResponse stores a codex upstream websocket response frame and merges any quota event headers carried by the frame into the request log.
func ApplyClaudeDeviceProfileHeaders ¶
func ApplyClaudeDeviceProfileHeaders(r *http.Request, profile ClaudeDeviceProfile)
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 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 (for example, "request" for Gemini CLI) 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 ¶ added in v0.0.39
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/ancestors) were targeted by an applied rule. Ported from upstream CLIProxyAPI (parity: de4aa600280e).
func ApplyRequestThinking ¶ added in v0.0.40
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 (e.g., a home-dispatched model_info carrying the real Thinking levels). Without it, home-dispatched models unknown to the local registry fall back to the user-defined path, which can rewrite a level-based config into a budget.
Ported from upstream CLIProxyAPI (internal/runtime/executor/helps/ model_capabilities.go): preserves summary visibility resolved across source translation and request normalization.
func ApplyThinkingWithSourcePayload ¶ added in v0.0.49
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
func BuildAntigravityCompactionResponse(modelName, capsule string, inputTokens, outputTokens, totalTokens int) []byte
BuildAntigravityCompactionResponse creates JSON response for non-stream response.compaction.
func BuildAntigravityCompactionStreamChunks ¶ added in v0.0.39
func BuildAntigravityCompactionStreamChunks(modelName, capsule string, inputTokens, outputTokens, totalTokens int) [][]byte
BuildAntigravityCompactionStreamChunks creates SSE frames for compaction stream response.
func BuildDevinClientMetadataBytes ¶ added in v0.0.39
BuildDevinClientMetadataBytes constructs the serialized bytes for Field 1 (ClientMetadata).
func BuildDevinGetChatMessageRequest ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 CachedSessionID ¶
CachedSessionID returns a stable session UUID per apiKey, refreshing the TTL on each access.
func CachedUserID ¶
func CaptureTranslatedClaudeStreamError ¶ added in v0.0.56
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 ¶ added in v0.0.39
func ClaudeAgentSessionUUID(headers http.Header, originalPayload, translatedPayload []byte, metadataSets ...map[string]any) string
ClaudeAgentSessionUUID resolves the stable Claude session UUID used for upstream request continuity (upstream 086ad91bd970).
func ClaudeAgentSessionUUIDForRequest ¶ added in v0.0.39
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 ClaudeDeterministicPromptID ¶ added in v0.0.39
ClaudeDeterministicPromptID derives a stable RFC 4122 UUIDv4 prompt ID from a seed, used when a request has no prior continuity state to persist (upstream 086ad91bd970).
func ClaudeExecutionMetadataFromContext ¶ added in v0.0.39
ClaudeExecutionMetadataFromContext retrieves whether execution metadata was present from ctx.
func ClaudeHeadersIndicateUnifiedRateLimitRejection ¶ added in v0.0.42
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 ¶ added in v0.0.25
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 ¶ added in v0.0.25
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 ClaudePayloadHas1hTTL ¶ added in v0.0.39
ClaudePayloadHas1hTTL reports whether the payload carries any cache_control block with ttl="1h" (tools, system, or message content blocks).
func ClaudeRequestHasExecutionMetadata ¶ added in v0.0.39
ClaudeRequestHasExecutionMetadata reports whether the request explicitly carried an internal execution session metadata key.
func ClaudeSessionDatePinKey ¶ added in v0.0.56
ClaudeSessionDatePinKey returns the credential-independent store key for a session date pin, or "" for an empty session ID.
func ClaudeSessionIDFromContext ¶ added in v0.0.39
ClaudeSessionIDFromContext retrieves the Claude session ID from ctx, if present.
func ClaudeSubagentRequests1h ¶ added in v0.0.39
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 CommitClaudeContinuity ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 CountOpenAIChatTokens ¶
CountOpenAIChatTokens approximates prompt tokens for OpenAI chat completions payloads.
func CreditsUsed ¶
CreditsUsed returns true if the request used AI credits.
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 DerivedAntigravitySessionID ¶ added in v0.0.22
DerivedAntigravitySessionID maps a derived session identity to Antigravity's negative decimal format.
func DerivedSessionID ¶ added in v0.0.22
DerivedSessionID returns the first context-derived session identity in metadata order.
func DerivedSessionUUID ¶ added in v0.0.22
DerivedSessionUUID maps a derived session identity to a provider-scoped stable UUID.
func DropGeminiTrailingThoughtOnlyContent ¶ added in v0.0.56
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 EnsureGeminiBoundaryUserContent ¶ added in v0.0.39
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 ¶ added in v0.0.25
EnsureGeminiLeadingUserContent prepends an empty user turn when the contents array starts with a model turn. Valid user-first payloads are returned unchanged.
func EnsureGeminiTrailingUserContent ¶ added in v0.0.39
EnsureGeminiTrailingUserContent appends an empty user turn when the contents array ends with a model turn. A trailing turn that contains a functionResponse is preserved because upstream expects the model to answer it. Ported from upstream commit 5dc428f39270.
func EnsureResponsesUsageDetails ¶ added in v0.0.25
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 ¶ added in v0.0.39
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 and for executor-side session/cascade resolution. Ported from upstream CLIProxyAPI internal/runtime/executor/helps/cpa_session.go (v7.3.3).
func ExecutorTypeName ¶ added in v0.0.42
ExecutorTypeName returns the concrete executor type name for usage records.
func ExpandAntigravityCompactionCapsules ¶ added in v0.0.39
ExpandAntigravityCompactionCapsules expands compaction items in input into developer context.
func ExtractAntigravitySummaryText ¶ added in v0.0.39
ExtractAntigravitySummaryText extracts summary text from Antigravity or Responses response.
func ExtractClaudeBillingTags ¶ added in v0.0.39
ExtractClaudeBillingTags extracts existing cc_prev_req and cc_prompt_id values from a billing header in system text, if present.
func ExtractClaudeCodeAgentID ¶ added in v0.0.39
ExtractClaudeCodeAgentID resolves the Claude Code agent ID and uses a stable sentinel for the root agent.
func ExtractClaudeCodeSessionID ¶ added in v0.0.39
ExtractClaudeCodeSessionID resolves a Claude Code session ID, preferring X-Claude-Code-Session-Id over payload metadata. Ported from upstream CLIProxyAPI claude_code_session.go (parity: 086ad91bd970).
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 GenerateDevinDeviceFingerprint ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 HasDevinEffortSuffix ¶ added in v0.0.39
HasDevinEffortSuffix reports whether the model name already ends with a known Devin effort suffix.
func HasMeaningfulCodexOutputDelta ¶ added in v0.0.39
HasMeaningfulCodexOutputDelta reports whether an event carries non-empty generated content (such as non-empty text, reasoning, or function call arguments delta).
func HasResponsesCompactionItem ¶ added in v0.0.39
HasResponsesCompactionItem checks whether input contains a compaction item.
func HasResponsesCompactionTrigger ¶ added in v0.0.39
HasResponsesCompactionTrigger checks whether input contains a compaction_trigger item.
func HeaderValueCaseInsensitive ¶ added in v0.0.39
HeaderValueCaseInsensitive returns the first non-empty header value matching name case-insensitively.
func HeaderValuesCaseInsensitive ¶ added in v0.0.39
HeaderValuesCaseInsensitive returns all non-empty header values matching name case-insensitively.
func IncomingHeadersFromContext ¶ added in v0.0.39
IncomingHeadersFromContext retrieves incoming HTTP headers from ctx, if present.
func InjectClaudeBillingTags ¶ added in v0.0.39
InjectClaudeBillingTags appends cc_prev_req and cc_prompt_id to the billing header in body if present.
func IsChatTokenEvent ¶ added in v0.0.30
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 IsClaudeMCPToolName ¶ added in v0.0.25
IsClaudeMCPToolName reports whether name follows Claude Code's MCP tool convention and contains only characters accepted by Anthropic tool names.
func IsClaudeNewPromptTurn ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.50
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. Ported from upstream CLIProxyAPI (helps/claude_builtin_tools.go).
func IsClaudeSubagentRequest ¶ added in v0.0.39
IsClaudeSubagentRequest reports whether the incoming request originates from or represents a Claude Code subagent.
func IsClaudeTokenEvent ¶ added in v0.0.30
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 IsCodexModelSubstituted ¶ added in v0.0.42
IsCodexModelSubstituted reports whether the upstream served a model other than the requested one; a dated alias pins a snapshot of the same model and is accepted.
func IsCodexTerminalEmptyIncomplete ¶ added in v0.0.39
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 IsGeminiTerminalStreamChunk ¶ added in v0.0.56
IsGeminiTerminalStreamChunk recognizes terminal output from Gemini stream translators, in any of the shapes a Gemini-family executor can emit: an SSE [DONE] marker, a Responses terminal event, a Claude message_stop, or a chunk that already carries a finish reason.
func IsGeminiTokenEvent ¶ added in v0.0.30
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 IsModelSubstituted ¶ added in v0.0.42
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 ¶ added in v0.0.39
func IsNativeCodexRequest(body []byte, opts cliproxyexecutor.Options) bool
IsNativeCodexRequest checks the client dialect for use inside Codex executors.
Ported from upstream CLIProxyAPI internal/runtime/executor/helps/codex_native.go (f702bc1ac263).
func IsResponsesTokenEvent ¶ added in v0.0.30
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 ¶ added in v0.0.39
IsValidClaudePromptID verifies whether an explicit prompt ID adheres to strict RFC 4122 UUIDv4 semantics.
func IsValidUserID ¶
func JSONPayload ¶
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 v0.0.56
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 NewDevinHTTPClient ¶ added in v0.0.39
func NewDevinHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) *http.Client
NewDevinHTTPClient creates an HTTP client customized for Devin Connect-RPC upstream. Suppresses automatic Accept-Encoding: gzip while preserving connection reuse across requests. Ported from upstream CLIProxyAPI helps/proxy_helpers.go (f1f5506c0b49, 86de823daa50).
func NewProxyAwareHTTPClient ¶
func NewProxyAwareHTTPClient(ctx context.Context, cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) *http.Client
NewProxyAwareHTTPClient creates an HTTP client with proper proxy configuration priority: 1. Use auth.ProxyURL if configured (highest priority) 2. Use cfg.ProxyURL if auth proxy is not configured 3. Use RoundTripper from context if neither 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(cfg *config.Config, auth *cliproxyauth.Auth, timeout time.Duration) *http.Client
NewUtlsHTTPClient creates an HTTP client using utls Chrome TLS fingerprint. Use this for Claude API requests to match real Claude Code's TLS behavior. Falls back to standard transport for non-HTTPS requests.
func NextDevinSessionTurnIndex ¶ added in v0.0.39
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 NormalizeClaudeToolChoice ¶ added in v0.0.57
NormalizeClaudeToolChoice downgrades forced tool use on Claude 5.5 to auto.
Call it with the routed upstream model once the model is on the payload and before thinking preparation, so the request the API receives is the one the thinking stage and the signed history were prepared against. User payload rules run afterwards on the Claude path and stay authoritative: they see the downgraded value and can still force a choice on purpose.
Every other model keeps its payload unchanged, byte for byte.
func NormalizeCodexToolSchemas ¶ added in v0.0.45
NormalizeCodexToolSchemas inspects function tools in a Codex request payload and strips regex `pattern` attributes that strict upstream validators reject.
func NormalizeOpenAIMaxTokens ¶ added in v0.0.42
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 ¶ added in v0.0.41
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 ¶ added in v0.0.39
NormalizeThinkingLevel converts numeric budgets or loose effort strings to canonical Devin efforts.
func ObfuscateSensitiveWords ¶
func ObfuscateSensitiveWords(payload []byte, matcher *SensitiveWordMatcher) []byte
ObfuscateSensitiveWords processes the payload and obfuscates sensitive words in system blocks and message content.
func ObserveChatTokenEvent ¶ added in v0.0.30
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 ¶ added in v0.0.30
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 ¶ added in v0.0.30
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 ObserveResponsesTokenEvent ¶ added in v0.0.30
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 ¶ added in v0.0.25
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 ¶ added in v0.0.25
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 ParseAntigravityUsage ¶
func ParseClaudeRateLimitReset ¶ added in v0.0.42
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 v0.0.56
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 ¶ added in v0.0.28
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
ParseDevinTrailerError inspects Connect-RPC EOS trailer frames and maps error status codes.
func ParseGeminiCLIUsage ¶
func ParseGeminiUsage ¶
func ParseInteractionsStreamUsage ¶ added in v0.0.39
ParseInteractionsStreamUsage extracts a usage.Detail from a single interactions stream event payload (SSE data line or raw JSON), reporting false when no token fields are present. Ported from upstream CLIProxyAPI helps/usage_helpers.go (f94752762bb9 at v7.3.3).
func ParseInteractionsUsage ¶ added in v0.0.39
ParseInteractionsUsage extracts a usage.Detail from an intermediate interactions JSON payload (non-streaming interaction document or a streaming interaction.completed event). Ported from upstream CLIProxyAPI helps/usage_helpers.go (f94752762bb9 at v7.3.3); adapted to the local usage.Detail, which has no TokenBreakdown field.
func ParseOpenAIUsage ¶
func PayloadRequestPath ¶
func PayloadRequestPath(opts cliproxyexecutor.Options) string
func PayloadRequestedModel ¶
func PayloadRequestedModel(opts cliproxyexecutor.Options, fallback string) string
func PinClaudeSessionDate ¶ added in v0.0.56
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 PrepareAntigravityClaudeStructuredOutput ¶ added in v0.0.57
PrepareAntigravityClaudeStructuredOutput replaces native output schemas with best-effort prompt instructions for Claude 5.5, which rejects forced tool use (upstream 1d45a5f33290).
Call it inside the Antigravity request build, after the payload rules have run and before schema sanitization: the conversion is the last word for the three native-output paths it rewrites, which is where upstream leaves it too. The boolean tells the request builder not to restore VALIDATED tool mode.
func PrepareAntigravityCompactionSummaryPayload ¶ added in v0.0.39
PrepareAntigravityCompactionSummaryPayload prepares a payload for non-stream Antigravity summary generation.
func ProviderSessionUUID ¶ added in v0.0.22
ProviderSessionUUID prefers a long-lived execution session and falls back to the derived identity.
func ReadConnectFrame ¶ added in v0.0.39
ReadConnectFrame reads a single framed message from a Connect-proto stream.
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 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 ¶ added in v0.0.39
func ResetClaudeDiagnosticsForTest()
ResetClaudeDiagnosticsForTest resets in-memory continuity state for test isolation.
func ResetDevinSessionTurnIndex ¶ added in v0.0.39
func ResetDevinSessionTurnIndex(sessionID string)
ResetDevinSessionTurnIndex clears the session counter (used for testing or explicit session reset).
func ResolveAntigravityGroundingURLs ¶ added in v0.0.41
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. Ported from upstream CLIProxyAPI v7.3.6 (internal/runtime/executor/helps/antigravity_grounding_urls.go).
func ResolveDevinChatModelUID ¶ added in v0.0.39
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 ¶ added in v0.0.44
func ResolveKimiBaseURL(auth *cliproxyauth.Auth) string
ResolveKimiBaseURL resolves the upstream API base URL for Kimi API requests based on auth.
func ResolveKimiChatURL ¶ added in v0.0.44
func ResolveKimiChatURL(auth *cliproxyauth.Auth) string
ResolveKimiChatURL resolves the upstream URL for Kimi Chat Completions requests.
func ResolveKimiClaudeBaseURL ¶ added in v0.0.44
func ResolveKimiClaudeBaseURL(auth *cliproxyauth.Auth) string
ResolveKimiClaudeBaseURL resolves the base URL for Kimi Claude Messages delegation.
func ResolveKimiResponsesURL ¶ added in v0.0.39
func ResolveKimiResponsesURL(auth *cliproxyauth.Auth) string
ResolveKimiResponsesURL resolves the upstream URL for Kimi Responses API requests.
func RestoreCodexMultiAgentV2Response ¶ added in v0.0.25
RestoreCodexMultiAgentV2Response restores optimized collaboration namespace values before an upstream response is translated and returned to the client.
func RewriteCodexMultiAgentV2Input ¶ added in v0.0.25
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 ¶ added in v0.0.39
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. Ported from upstream CLIProxyAPI (291cfb87efac).
func RewriteCodexSpawnAgentDescription ¶ added in v0.0.25
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 ¶ added in v0.0.25
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 ¶ added in v0.0.39
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 SealAntigravityCompaction ¶ added in v0.0.39
SealAntigravityCompaction encrypts summary data into an opaque capsule using AES-GCM.
func SetBoolIfDifferent ¶ added in v0.0.39
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 SetRawIfDifferent ¶ added in v0.0.39
SetRawIfDifferent updates path only when the existing raw JSON is identical.
func SetStringIfDifferent ¶ added in v0.0.39
SetStringIfDifferent updates path only when its value is not already the canonical JSON string. Values with another JSON type are still normalized. Ported from upstream CLIProxyAPI internal/runtime/executor/helps/payload_mutations.go.
func SharedProxyTransport ¶ added in v0.0.25
SharedProxyTransport returns a stable transport for one credential scope and proxy setting. It preserves Go's standard connection-pool settings; callers must treat the result as read-only and clone it before changing protocol behavior.
func ShouldCloak ¶
ShouldCloak determines if request should be cloaked based on config and client User-Agent. Returns true if cloaking should be applied.
func ShouldNormalizeOpenAIToolResultsForModel ¶ added in v0.0.41
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 ¶ added in v0.0.42
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.
Ported from upstream CLIProxyAPI internal/runtime/executor/helps/openai_compat_max_tokens.go (690f4f3116b6).
func StopTranslatedClaudeStream ¶ added in v0.0.56
func StopTranslatedClaudeStream(ctx context.Context, retainedErr *error, reporter *UsageReporter, out chan<- cliproxyexecutor.StreamChunk) bool
func StopTranslatedClaudeStreamWithDetail ¶ added in v0.0.56
func StopTranslatedClaudeStreamWithDetail(ctx context.Context, retainedErr *error, reporter *UsageReporter, detail usage.Detail, 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 ¶ added in v0.0.39
StripClaudeBillingTags removes cc_prev_req and cc_prompt_id from the billing header in body.
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 TranslateRequestEnvelopePairWithCodexMultiAgentV2 ¶ added in v0.0.41
func TranslateRequestEnvelopePairWithCodexMultiAgentV2(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, req sdktranslator.RequestEnvelope, originalPayload, requestPayload []byte) (original, working []byte)
TranslateRequestEnvelopePairWithCodexMultiAgentV2 translates the baseline and working payload while preserving request-scoped metadata in req.
func TranslateRequestEnvelopeWithCodexMultiAgentV2 ¶ added in v0.0.41
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 TranslateRequestPairWithAPIKeyModelCompatibility ¶ added in v0.0.49
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 stateful plugin invocations.
func TranslateRequestPairWithAPIKeyModelCompatibilityAndUpdateIntent ¶ added in v0.0.49
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)
TranslateRequestPairWithAPIKeyModelCompatibilityAndUpdateIntent returns the normalizer decision for the working payload, not for the baseline payload.
func TranslateRequestPairWithCodexMultiAgentV2 ¶ added in v0.0.41
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 both translations would rescan the same bytes and produce the same result. Built-in request translation is deterministic, so that case is translated once and duplicated when no plugin hooks are installed. Hooks retain two invocations because they may have request-scoped output or side effects. This removes a full extra pass over payloads that can reach tens of megabytes.
func TranslateRequestWithAPIKeyModelCompatibility ¶ added in v0.0.43
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. Ported from upstream CLIProxyAPI (helps/codex_multi_agent_v2.go). The upstream claude->interactions branch is omitted: no local interactions translator exists.
func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent ¶ added in v0.0.49
func TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent(ctx context.Context, headers http.Header, cfg *config.Config, from, to sdktranslator.Format, model string, payload []byte, stream, isCompat bool) ([]byte, bool)
TranslateRequestWithAPIKeyModelCompatibilityAndUpdateIntent returns the plugin normalizer's request-scoped update decision for Responses targets.
func TranslateRequestWithCodexMultiAgentV2 ¶ added in v0.0.25
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 TranslateStreamWithClaudeInputTokens ¶ added in v0.0.21
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 v0.0.56
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 v0.0.56
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 ¶ added in v0.0.39
UnsealAntigravityCompaction decrypts and validates an opaque capsule.
func WebsocketUpgradeRequestURL ¶
WebsocketUpgradeRequestURL converts a websocket URL back to its HTTP handshake URL for logging.
func WithClaudeContinuityContext ¶ added in v0.0.39
func WithClaudeContinuityContext(ctx context.Context, cc *ClaudeContinuityContext) context.Context
WithClaudeContinuityContext attaches a mutable ClaudeContinuityContext to ctx.
func WithClaudeExecutionMetadata ¶ added in v0.0.39
WithClaudeExecutionMetadata attaches whether the request had an explicit execution session metadata to ctx.
func WithClaudeSessionID ¶ added in v0.0.39
WithClaudeSessionID attaches a known Claude session ID to ctx.
func WithIncomingHeaders ¶ added in v0.0.39
WithIncomingHeaders attaches incoming HTTP headers to ctx.
func WrapConnectEnvelope ¶ added in v0.0.39
WrapConnectEnvelope wraps raw payload bytes into a standard 5-byte Connect envelope: [1 byte flag: 0x00] + [4 byte big-endian length] + [payload].
func WrapConnectEnvelopeWithFlag ¶ added in v0.0.39
WrapConnectEnvelopeWithFlag wraps payload bytes with an explicit Connect flag.
Types ¶
type ClaudeContinuityContext ¶ added in v0.0.39
type ClaudeContinuityContext struct {
Key string
Sequence uint64
PreviousMessageID string
PreviousRequestID string
PromptID string
Initialized bool
}
ClaudeContinuityContext holds request-scoped continuity state across cloaking and execution.
func ClaudeContinuityContextFromContext ¶ added in v0.0.39
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
type ClaudeInputTokenState ¶ added in v0.0.21
type ClaudeInputTokenState struct {
// contains filtered or unexported fields
}
ClaudeInputTokenState tracks the one-time input token update for a translated Claude stream.
func NewClaudeInputTokenState ¶ added in v0.0.21
func NewClaudeInputTokenState(sourceFormat, upstreamFormat, responseFormat sdktranslator.Format, originalRequest []byte) *ClaudeInputTokenState
NewClaudeInputTokenState creates request-scoped state for translated Claude input token usage.
type CodexCache ¶
func GetCodexCache ¶
func GetCodexCache(key string) (CodexCache, bool)
GetCodexCache retrieves a cached entry, returning ok=false if not found or expired.
type DevinFrameResult ¶ added in v0.0.39
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 ¶ added in v0.0.39
func ParseDevinFrame(payload []byte) (DevinFrameResult, error)
ParseDevinFrame extracts deltas, tool calls, thinking, signatures, and usage from a single response frame.
type DevinImage ¶ added in v0.0.39
DevinImage represents an image attachment in a DevinPrompt (Prompt #10).
type DevinImageLogItem ¶ added in v0.0.39
DevinImageLogItem represents an image attached to a prompt in the request log.
type DevinPrompt ¶ added in v0.0.39
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 (upstream b6fe4f20)
IsOrphanedTool bool // Explicit flag marking downgraded tool results (upstream b6fe4f20)
Thinking string
Signature []byte
SignatureType string
}
DevinPrompt represents a single turn in the request history (repeated Field 3).
type DevinPromptLogItem ¶ added in v0.0.39
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 DevinToolCall ¶ added in v0.0.39
DevinToolCall represents a tool call in a ChatMessagePrompt.
type DevinToolCallDelta ¶ added in v0.0.39
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. Upstream 9e10db53 dropped the slot Index in favor of call-ID aggregation and added the custom-tool-call fields (invalid_json_str/invalid_json_err/is_custom_tool_call).
type DevinToolLogItem ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
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"` // usage field 4 (upstream 9e10db53)
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 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 ¶ added in v0.0.39
func (m *SensitiveWordMatcher) Matches(text string) bool
Matches reports whether the text contains any of the configured sensitive words. Ported from upstream CLIProxyAPI helps/cloak_obfuscate.go (f94752762bb9).
func (*SensitiveWordMatcher) ObfuscateText ¶ added in v0.0.39
func (m *SensitiveWordMatcher) ObfuscateText(text string) string
ObfuscateText replaces all sensitive words in the text. Ported from upstream CLIProxyAPI helps/cloak_obfuscate.go (f94752762bb9).
type StreamResponseModelObserver ¶ added in v0.0.42
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 ¶ added in v0.0.42
func NewStreamResponseModelObserver(reporter *UsageReporter) *StreamResponseModelObserver
NewStreamResponseModelObserver creates an observer for tracking response models from arbitrary streaming network chunks.
func (*StreamResponseModelObserver) Feed ¶ added in v0.0.42
func (o *StreamResponseModelObserver) Feed(chunk []byte)
Feed ingests a raw chunk of bytes from a stream, splitting into lines and events.
func (*StreamResponseModelObserver) Finish ¶ added in v0.0.42
func (o *StreamResponseModelObserver) Finish()
Finish flushes any pending buffered line or event at the end of the stream.
type TransportCache ¶ added in v0.0.39
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.
Ported from upstream CLIProxyAPI helps/transport_cache.go (v7.3.3), including the lifecycle hardening from commit d5397905f09e.
func NewTransportCache ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
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 ¶ added in v0.0.39
func (c *TransportCache[K]) Contains(key K) bool
Contains reports whether key exists in the cache.
func (*TransportCache[K]) Get ¶ added in v0.0.39
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 ¶ added in v0.0.39
func (c *TransportCache[K]) Len() int
Len reports how many transports the cache currently holds.
func (*TransportCache[K]) Purge ¶ added in v0.0.39
func (c *TransportCache[K]) Purge()
Purge drops every entry and closes the idle connections it was holding.
type UTF8SplitBuffer ¶ added in v0.0.39
type UTF8SplitBuffer struct {
// contains filtered or unexported fields
}
UTF8SplitBuffer buffers incomplete UTF-8 byte sequences across chunk boundaries.
func (*UTF8SplitBuffer) Feed ¶ added in v0.0.39
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 ¶ added in v0.0.42
func NewExecutorUsageReporter(ctx context.Context, executor usageExecutor, model string, auth *cliproxyauth.Auth) *UsageReporter
NewExecutorUsageReporter builds a reporter whose provider is taken from the executor's Identifier, mirroring the upstream constructor (upstream 959067ed).
func NewUsageReporter ¶
func NewUsageReporter(ctx context.Context, provider, model string, auth *cliproxyauth.Auth) *UsageReporter
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 ¶ added in v0.0.30
func (r *UsageReporter) IsFirstPacketSet() bool
func (*UsageReporter) IsResponseModelFinal ¶ added in v0.0.42
func (r *UsageReporter) IsResponseModelFinal() bool
IsResponseModelFinal reports whether the response model was already finalized by a terminal event.
func (*UsageReporter) IsTTFTSet ¶ added in v0.0.30
func (r *UsageReporter) IsTTFTSet() bool
func (*UsageReporter) MarkFirstResponseByte ¶ added in v0.0.30
func (r *UsageReporter) MarkFirstResponseByte()
func (*UsageReporter) ObserveCodexResponseModel ¶ added in v0.0.42
func (r *UsageReporter) ObserveCodexResponseModel(payload []byte)
ObserveCodexResponseModel stores the model reported by a codex upstream event and ignores payloads without one; the substitution warning is emitted at publish time.
func (*UsageReporter) ObserveResponse ¶ added in v0.0.30
func (r *UsageReporter) ObserveResponse(resp *http.Response)
func (*UsageReporter) ObserveResponseModel ¶ added in v0.0.42
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. Ported from upstream e9463ff5a795.
func (*UsageReporter) ObserveResponsePacketOnly ¶ added in v0.0.30
func (r *UsageReporter) ObserveResponsePacketOnly(resp *http.Response)
func (*UsageReporter) ObserveTokenEvent ¶ added in v0.0.30
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 ¶ added in v0.0.56
func (r *UsageReporter) PublishFailureWithDetail(ctx context.Context, detail usage.Detail, errs ...error)
PublishFailureWithDetail records a failure alongside usage statistics.
func (*UsageReporter) RecordFirstPacket ¶ added in v0.0.30
func (r *UsageReporter) RecordFirstPacket()
RecordFirstPacket records the arrival time of the first packet/chunk from upstream as a fallback.
func (*UsageReporter) RequestID ¶ added in v0.0.49
func (r *UsageReporter) RequestID() string
RequestID returns the execution instance request ID for this reporter.
func (*UsageReporter) ResponseModel ¶ added in v0.0.42
func (r *UsageReporter) ResponseModel() string
ResponseModel returns the latest model reported by the upstream response.
func (*UsageReporter) SetEffectiveServiceTier ¶ added in v0.0.56
func (r *UsageReporter) SetEffectiveServiceTier(payload []byte)
SetEffectiveServiceTier captures the service tier of the final outbound payload, after protocol translation and payload defaults or overrides, so the usage record names the tier the upstream was actually asked to serve. The client-requested tier is not recorded separately: the local reporter has no such field and no sink consumes one.
func (*UsageReporter) SetResponseModel ¶ added in v0.0.42
func (r *UsageReporter) SetResponseModel(model string)
SetResponseModel sets the reported model directly if valid and not already marked final.
func (*UsageReporter) SetSessionHierarchy ¶ added in v0.0.39
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 ¶ added in v0.0.30
func (r *UsageReporter) SetStream(stream bool)
SetStream records whether the request was executed in streaming mode.
func (*UsageReporter) SetUpstreamModel ¶ added in v0.0.42
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 ¶ added in v0.0.30
func (r *UsageReporter) StartResponseTTFT()
func (*UsageReporter) TraceID ¶ added in v0.0.49
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 ¶ added in v0.0.30
func (r *UsageReporter) TrackHTTPClient(client *http.Client) *http.Client
func (*UsageReporter) TrackHTTPClientRoundTripOnly ¶ added in v0.0.30
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) UpstreamModel ¶ added in v0.0.42
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_grounding_urls.go
- antigravity_structured_output.go
- cache_helpers.go
- chat_ttft_helpers.go
- claude_builtin_tools.go
- claude_code_session.go
- claude_device_profile.go
- claude_diagnostics.go
- claude_input_tokens.go
- claude_mcp_alias.go
- claude_mcp_alias_wordlist.go
- claude_ratelimit.go
- claude_system_prompt.go
- claude_tool_choice.go
- claude_ttft_helpers.go
- cloak_obfuscate.go
- cloak_utils.go
- codex_input_ids.go
- codex_multi_agent_v2.go
- codex_native.go
- codex_quota.go
- codex_terminal_incomplete.go
- codex_tool_schema.go
- derived_session.go
- devin_models.go
- devin_session.go
- devin_wire.go
- gemini_content_turns.go
- gemini_stream_terminal.go
- gemini_ttft_helpers.go
- home_refresh.go
- kimi_responses.go
- logging_helpers.go
- model_capabilities.go
- openai_compat_max_tokens.go
- openai_compat_tool_results.go
- payload_helpers.go
- payload_mutations.go
- proxy_helpers.go
- response_model.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
- transport_cache.go
- usage_helpers.go
- user_id_cache.go
- utls_client.go
- vertex_payload_helpers.go