common

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignClaudeToolResults

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

AlignClaudeToolResults orders tool_result blocks by the preceding tool_use IDs, preserving non-result content blocks at their existing indexes. 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 BuildClaudeOutputFormatDescription

func BuildClaudeOutputFormatDescription(format ojson.Result) string

BuildClaudeOutputFormatDescription builds a short system prompt instruction preserving the schema name and description when output_config.format carries the JSON schema natively. It returns "" when no description is present.

func BuildClaudeStructuredOutputInstruction

func BuildClaudeStructuredOutputInstruction(format ojson.Result) string

BuildClaudeStructuredOutputInstruction formats structured output settings (from Chat Completions response_format or Responses text.format) as explicit instructions to inject into Claude's system prompt.

func ClaudeDocumentHeader

func ClaudeDocumentHeader(part ojson.Result) string

ClaudeDocumentHeader returns a formatted metadata header for optional title and context fields on a Claude document block, or "" when neither is set.

func ClaudeDocumentTextBlock

func ClaudeDocumentTextBlock(part ojson.Result) (string, bool)

ClaudeDocumentTextBlock formats a Claude plain-text document block (source.type == "text") into text preserving optional title and context. Returns ("", false) when the source is not a text source or carries no text.

func ClaudeInputTokensJSON

func ClaudeInputTokensJSON(count int64) []byte

func ClaudeMessageSystemReminderText

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

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

func ClaudeOutputFormatSchema

func ClaudeOutputFormatSchema(modelName string, format ojson.Result) (ojson.Result, bool)

ClaudeOutputFormatSchema returns the schema object of a json_schema structured output setting (from Chat Completions response_format or Responses text.format) so the caller can set Claude's output_config.format directly on its *ojson.Doc. It returns false for non-json_schema formats, missing/non-object schemas, and legacy Claude models without native structured outputs, which keep the system prompt instruction fallback.

func CodexReplaySignatureForTarget

func CodexReplaySignatureForTarget(modelName, rawSignature string) (string, bool)

CodexReplaySignatureForTarget returns the exact value that may be written as a Responses reasoning encrypted_content for the Codex-format upstream serving modelName, or false when rawSignature must not replay there. Positively detected families must match the target family exactly (an unmapped target defaults to the Codex GPT family, mirroring the Codex translators' purpose) and go through the shared compatibility normalization, so cache-prefixed values such as "gpt#..." are stripped to their native payload instead of being forwarded verbatim. Grok has no detectable envelope, so it falls back to its shape inspector keyed on the target.

func ConvertJSONNodeKeys

func ConvertJSONNodeKeys(node ojson.Result, transform func(string) string) []byte

ConvertJSONNodeKeys recursively transforms every JSON object key in node using transform while preserving root/nested arrays, multi-key objects inside arrays, empty containers, and literal keys containing path metacharacters.

func CountSendableGeminiParts

func CountSendableGeminiParts(parts [][]byte) int

CountSendableGeminiParts counts the parts for which GeminiPartIsSendable holds.

func ExpandClaudeContentDocument

func ExpandClaudeContentDocument(
	part ojson.Result,
	emitText func(string),
	convertImage func(ojson.Result) ([]byte, bool),
	emitImage func([]byte),
	onImageDrop func(),
) bool

ExpandClaudeContentDocument walks a Claude document block with source.type == "content", converting nested text and image blocks. An optional title/context header is emitted before the first converted item only if at least one item succeeds. Returns true if any item was emitted.

func GeminiPartIsSendable

func GeminiPartIsSendable(part []byte) bool

GeminiPartIsSendable reports whether a Gemini part gives the model something to read. A text part that is empty or only whitespace does not.

func GeminiTokenCountJSON

func GeminiTokenCountJSON(count int64) []byte

func InteractionsAttachmentType

func InteractionsAttachmentType(part ojson.Result) string

InteractionsAttachmentType names the type of an Interactions content part that carries an attachment, or returns "" for text and for parts that name nothing. It is the type reported when a translation cannot send the part.

func IsHTTPURL

func IsHTTPURL(value string) bool

IsHTTPURL reports whether value is an absolute http or https URL with a host.

func IsInteractionsInstructionStep

func IsInteractionsInstructionStep(step ojson.Result, inherited bool) bool

IsInteractionsInstructionStep reports whether an Interactions step carries developer or system content rather than user content. The step's own role decides, falling back to its type; a step that names neither inherits the answer from the wrapper it sits in. Instruction content is still sent, but it closes the open user turn and never keeps an emptied one alive.

func JoinRawArray

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

func NewRawArrayItems

func NewRawArrayItems(capacity int64) [][]byte

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

func ResolveCodexReplayTargetModel

func ResolveCodexReplayTargetModel(modelName string, rawPayload []byte) string

ResolveCodexReplayTargetModel returns the model name to use for reasoning signature family checks, falling back to the client-supplied "model" field in rawPayload when modelName is an unmapped upstream deployment alias for a Responses-native model family (Meta Muse, Grok, or GPT).

func SSEEventData

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

SSEEventData builds one complete SSE frame. Each frame carries its own blank-line terminator so concatenated frames stay separable downstream.

func SetRawArrayItems

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 SetRawArrayItemsDoc

func SetRawArrayItemsDoc(doc *ojson.Doc, path string, items [][]byte)

SetRawArrayItemsDoc replaces a JSON array at path in doc with raw items.

func SetStringWithoutHTMLEscape

func SetStringWithoutHTMLEscape(data []byte, path, value string) ([]byte, error)

SetStringWithoutHTMLEscape sets a string field in a JSON payload without escaping HTML characters (<, >, &). Standard ojson.Set/SetBytes delegates string values containing quotes or special characters to encoding/json.Marshal, which unconditionally escapes <, >, & to \u003c, \u003e, \u0026.

func SetStringWithoutHTMLEscapeDoc

func SetStringWithoutHTMLEscapeDoc(doc *ojson.Doc, path, value string) error

SetStringWithoutHTMLEscapeDoc sets a string field in an ojson.Doc without escaping HTML characters (<, >, &).

func SystemReminderText

func SystemReminderText(text string) string

SystemReminderText wraps text in the <system-reminder> envelope so non-Claude upstream formats treat demoted mid-session system or developer instructions as system directives rather than user speech.

func VisibleCodexCommentary

func VisibleCodexCommentary(ctx context.Context) bool

VisibleCodexCommentary reports the per-request display policy. The environment fallback supports SDK-only users and existing deployments of the opt-in mode.

func WithVisibleCodexCommentary

func WithVisibleCodexCommentary(ctx context.Context, enabled bool) context.Context

WithVisibleCodexCommentary snapshots the display policy for one request.

Types

type ClaudeMessageAccumulator

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

ClaudeMessageAccumulator groups consecutive Claude messages by role.

func NewClaudeMessageAccumulator

func NewClaudeMessageAccumulator(capacity int) *ClaudeMessageAccumulator

NewClaudeMessageAccumulator creates an accumulator sized for the expected messages.

func (*ClaudeMessageAccumulator) Append

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

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

func (*ClaudeMessageAccumulator) Flush

func (a *ClaudeMessageAccumulator) Flush()

Flush closes the current role turn while keeping accumulated messages.

func (*ClaudeMessageAccumulator) Messages

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

Messages flushes the final turn and returns all accumulated messages.

type UnsupportedPartError

type UnsupportedPartError struct {
	Type string
}

UnsupportedPartError is a request-scoped rejection. The part type was present and this translation has no equivalent, so the request must not be sent with that part removed.

func (*UnsupportedPartError) Error

func (e *UnsupportedPartError) Error() string

func (*UnsupportedPartError) IsRequestScoped

func (e *UnsupportedPartError) IsRequestScoped() bool

func (*UnsupportedPartError) StatusCode

func (e *UnsupportedPartError) StatusCode() int

type UserRun

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

UserRun follows the consecutive user content that a target merges into one user turn. Add records content that keeps the turn alive, Drop records a part that could not be sent, and End closes the turn when model content starts or the input ends. Every method is a no-op on a nil receiver, so callers can pass nil for content that is not user content.

func (*UserRun) Add

func (r *UserRun) Add()

Add records one sendable item in the current user turn.

func (*UserRun) Drop

func (r *UserRun) Drop(partType string)

Drop records a part of the current user turn that cannot be sent.

func (*UserRun) End

func (r *UserRun) End()

End closes the current user turn.

func (*UserRun) Err

func (r *UserRun) Err() error

Err returns the refusal for the first emptied user turn, or nil.

type UserTurnDrops

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

UserTurnDrops is the shared policy for a part a translation cannot send: text or any other sendable part beside it still goes out, but a user turn left with nothing to send is refused rather than forwarded empty. The decision is made per user turn, so earlier or later turns, system prompts and developer prompts can never hide an emptied user turn.

func (*UserTurnDrops) Drop

func (d *UserTurnDrops) Drop(partType string)

Drop records a part of the current user turn that cannot be sent. The first type recorded within a turn is the one reported.

func (*UserTurnDrops) EndTurn

func (d *UserTurnDrops) EndTurn(sendable int)

EndTurn closes the current user turn. sendable is the number of parts the turn contributed to the translated request. A turn that dropped a part and contributed nothing is remembered; a later turn never clears it.

func (*UserTurnDrops) Err

func (d *UserTurnDrops) Err() error

Err returns the refusal for the first emptied user turn, or nil.

Jump to

Keyboard shortcuts

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