Documentation
¶
Index ¶
- func AlignClaudeToolResults(content ojson.Result, toolUseIDs []string) ojson.Result
- func AppendSSEEventBytes(out []byte, event string, payload []byte, trailingNewlines int) []byte
- func AppendSSEEventString(out []byte, event, payload string, trailingNewlines int) []byte
- func BuildClaudeOutputFormatDescription(format ojson.Result) string
- func BuildClaudeStructuredOutputInstruction(format ojson.Result) string
- func ClaudeDocumentHeader(part ojson.Result) string
- func ClaudeDocumentTextBlock(part ojson.Result) (string, bool)
- func ClaudeInputTokensJSON(count int64) []byte
- func ClaudeMessageSystemReminderText(content ojson.Result) (string, bool)
- func ClaudeOutputFormatSchema(modelName string, format ojson.Result) (ojson.Result, bool)
- func CodexReplaySignatureForTarget(modelName, rawSignature string) (string, bool)
- func ConvertJSONNodeKeys(node ojson.Result, transform func(string) string) []byte
- func CountSendableGeminiParts(parts [][]byte) int
- func ExpandClaudeContentDocument(part ojson.Result, emitText func(string), ...) bool
- func GeminiPartIsSendable(part []byte) bool
- func GeminiTokenCountJSON(count int64) []byte
- func InteractionsAttachmentType(part ojson.Result) string
- func IsHTTPURL(value string) bool
- func IsInteractionsInstructionStep(step ojson.Result, inherited bool) bool
- func JoinRawArray(items [][]byte) []byte
- func NewRawArrayItems(capacity int64) [][]byte
- func ResolveCodexReplayTargetModel(modelName string, rawPayload []byte) string
- func SSEEventData(event string, payload []byte) []byte
- func SetRawArrayItems(data []byte, path string, items [][]byte) []byte
- func SetRawArrayItemsDoc(doc *ojson.Doc, path string, items [][]byte)
- func SetStringWithoutHTMLEscape(data []byte, path, value string) ([]byte, error)
- func SetStringWithoutHTMLEscapeDoc(doc *ojson.Doc, path, value string) error
- func SystemReminderText(text string) string
- func VisibleCodexCommentary(ctx context.Context) bool
- func WithVisibleCodexCommentary(ctx context.Context, enabled bool) context.Context
- type ClaudeMessageAccumulator
- type UnsupportedPartError
- type UserRun
- type UserTurnDrops
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlignClaudeToolResults ¶
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 AppendSSEEventString ¶
func BuildClaudeOutputFormatDescription ¶
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 ¶
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 ¶
ClaudeDocumentHeader returns a formatted metadata header for optional title and context fields on a Claude document block, or "" when neither is set.
func ClaudeDocumentTextBlock ¶
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 ClaudeMessageSystemReminderText ¶
ClaudeMessageSystemReminderText converts a Claude message-level system value into ordinary user-visible reminder text for non-Claude upstream formats.
func ClaudeOutputFormatSchema ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 InteractionsAttachmentType ¶
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 IsInteractionsInstructionStep ¶
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 NewRawArrayItems ¶
NewRawArrayItems creates a raw item slice sized for the expected input.
func ResolveCodexReplayTargetModel ¶
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 ¶
SSEEventData builds one complete SSE frame. Each frame carries its own blank-line terminator so concatenated frames stay separable downstream.
func SetRawArrayItems ¶
SetRawArrayItems replaces an empty JSON array at path with raw items. The single-item path avoids allocating an intermediate joined array.
func SetRawArrayItemsDoc ¶
SetRawArrayItemsDoc replaces a JSON array at path in doc with raw items.
func SetStringWithoutHTMLEscape ¶
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 ¶
SetStringWithoutHTMLEscapeDoc sets a string field in an ojson.Doc without escaping HTML characters (<, >, &).
func SystemReminderText ¶
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 ¶
VisibleCodexCommentary reports the per-request display policy. The environment fallback supports SDK-only users and existing deployments of the opt-in mode.
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.
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.