common

package
v7.2.149 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignClaudeToolResults added in v7.2.142

func AlignClaudeToolResults(content gjson.Result, toolUseIDs []string) gjson.Result

AlignClaudeToolResults orders tool_result blocks by the preceding tool_use IDs. Other content blocks retain their relative order after the tool results. If a complete one-to-one match is unavailable, the original content is returned.

func AppendSSEEventBytes

func AppendSSEEventBytes(out []byte, event string, payload []byte, trailingNewlines int) []byte

func AppendSSEEventString

func AppendSSEEventString(out []byte, event, payload string, trailingNewlines int) []byte

func AttachCacheControl added in v7.2.55

func AttachCacheControl(dst []byte, src gjson.Result) []byte

AttachCacheControl copies a Claude-compatible cache_control object from src onto dst. Returns dst unchanged when cache_control is missing or not an object.

func AttachMessageCacheControl added in v7.2.55

func AttachMessageCacheControl(msg []byte, src gjson.Result) []byte

AttachMessageCacheControl applies message-level cache_control onto the last content block. Part-level cache_control wins when the last block already has one. String content is promoted to a content array so Claude can accept cache_control.

func ClaudeInputTokensJSON

func ClaudeInputTokensJSON(count int64) []byte

func ClaudeMessageSystemReminderText added in v7.2.30

func ClaudeMessageSystemReminderText(content gjson.Result) (string, bool)

ClaudeMessageSystemReminderText converts a Claude message-level system value into ordinary user-visible reminder text for non-Claude upstream formats.

func DeriveClaudeUserID added in v7.2.140

func DeriveClaudeUserID(rawJSON []byte) string

DeriveClaudeUserID returns a stable value for the Claude request field metadata.user_id. It preserves any caller-supplied metadata.user_id or OpenAI Chat Completions user field, then derives a deterministic value from stable client signals (prompt_cache_key, session_id, conversation_id, first user message content, and model/system instructions). The same conversation therefore gets the same user_id on every worker and every turn, while different conversations get different values.

func GeminiTokenCountJSON

func GeminiTokenCountJSON(count int64) []byte

func GenerateClaudeToolCallID added in v7.2.133

func GenerateClaudeToolCallID() string

GenerateClaudeToolCallID generates a random tool use ID prefixed with toolu_ using rejection sampling to guarantee a uniform distribution across the 62 alphanumeric characters.

func InteractionsUsage added in v7.2.51

func InteractionsUsage(root gjson.Result) gjson.Result

func IsGeminiThoughtPart added in v7.2.131

func IsGeminiThoughtPart(part gjson.Result) bool

IsGeminiThoughtPart reports whether a Gemini part contains hidden model thought.

func JoinRawArray added in v7.2.89

func JoinRawArray(items [][]byte) []byte

func MergeAdjacentGeminiContents added in v7.2.147

func MergeAdjacentGeminiContents(contents [][]byte) [][]byte

MergeAdjacentGeminiContents merges consecutive user Content turns. Mid-conversation system messages in Claude requests are downgraded to user reminder turns. When followed or preceded by other user turns or tool results, their parts are merged into a single user turn. Consecutive model turns are strictly kept unmerged to avoid shifting part indices and breaking cryptographic thought signatures and reasoning replay.

func NewRawArrayItems added in v7.2.89

func NewRawArrayItems(capacity int64) [][]byte

NewRawArrayItems creates a raw item slice sized for the expected input.

func NormalizeOpenAIFileData added in v7.2.90

func NormalizeOpenAIFileData(filename, fallbackMIMEType, fileData string) (mimeType, data string, ok bool)

NormalizeOpenAIFileData returns the MIME type and raw base64 payload for OpenAI file content.

func RequestModelName added in v7.2.117

func RequestModelName(originalRequestRawJSON, requestRawJSON []byte) string

RequestModelName returns the model name from the original request, falling back to the translated request when the original request is unavailable.

func SSEEventData

func SSEEventData(event string, payload []byte) []byte

func SetRawArrayItems added in v7.2.89

func SetRawArrayItems(data []byte, path string, items [][]byte) []byte

SetRawArrayItems replaces an empty JSON array at path with raw items. The single-item path avoids allocating an intermediate joined array.

func SetResponsesToolCallIdentity added in v7.2.126

func SetResponsesToolCallIdentity(item []byte, name, namespace, itemPath string) []byte

SetResponsesToolCallIdentity writes a resolved Responses tool name and namespace.

Types

type ClaudeMessageAccumulator added in v7.2.121

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

ClaudeMessageAccumulator groups consecutive Claude messages by role.

func NewClaudeMessageAccumulator added in v7.2.121

func NewClaudeMessageAccumulator(capacity int) *ClaudeMessageAccumulator

NewClaudeMessageAccumulator creates an accumulator sized for the expected messages.

func (*ClaudeMessageAccumulator) Append added in v7.2.121

func (a *ClaudeMessageAccumulator) Append(message []byte)

Append adds one Claude-shaped message to the current role turn.

func (*ClaudeMessageAccumulator) Flush added in v7.2.121

func (a *ClaudeMessageAccumulator) Flush()

Flush closes the current role turn while keeping accumulated messages.

func (*ClaudeMessageAccumulator) Messages added in v7.2.121

func (a *ClaudeMessageAccumulator) Messages() [][]byte

Messages flushes the final turn and returns all accumulated messages.

Jump to

Keyboard shortcuts

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