util

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: 11 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

View Source
var SchemaMapKeywords = [...]string{
	"properties",
	"$defs",
	"definitions",
	"patternProperties",
	"dependentSchemas",
	"dependencies",
}

SchemaMapKeywords lists JSON Schema keywords whose values are maps of subschemas.

View Source
var SchemaValueKeywords = [...]string{
	"items",
	"prefixItems",
	"contains",
	"additionalProperties",
	"propertyNames",
	"unevaluatedProperties",
	"unevaluatedItems",
	"additionalItems",
	"contentSchema",
	"anyOf",
	"oneOf",
	"allOf",
	"not",
	"if",
	"then",
	"else",
}

SchemaValueKeywords lists JSON Schema keywords with a single nested subschema or a slice of subschemas.

Functions

func GeminiClaudeToolUseID

func GeminiClaudeToolUseID(callID, name, argsRaw string) string

GeminiClaudeToolUseID returns a stable Claude-facing ID for a provider-native Gemini function call. The opaque ID lets the executor recover the exact provider call from its replay ledger instead of trusting client-mutated args.

func GetGJSONBytesNoCopy

func GetGJSONBytesNoCopy(data []byte, path string) gjson.Result

GetGJSONBytesNoCopy returns a GJSON result that may reference data directly. Callers must not retain the result or mutate data while using it.

func HasUnsupportedUnicodePropertyEscape

func HasUnsupportedUnicodePropertyEscape(pattern string) bool

HasUnsupportedUnicodePropertyEscape reports whether a regular expression string contains a construct that strict upstream JSON Schema validators reject when they compile "pattern" values on the way to a provider.

Two constructs are known to fail, both of which Anthropic's own API accepts verbatim (it does not validate pattern values), so they only surface after the request is translated or forwarded:

  • Unicode property escapes (\p{...} or \P{...}): Python's built-in re module, and validators relying on it, fail with "bad escape \p".
  • The octal NUL escape (\0): validators that re-serialize or normalize the schema reject it with "is not a 'regex'", while the equivalent \x00 spelling is accepted. Claude Code's built-in Artifact tool emits \0 in its NUL guards (e.g. "^[^\0]*$" on the upload_asset file_paths item).

Dropping the attribute is safe: the client validates its own input locally, so removing an upstream-side pattern constraint does not make a call succeed that would otherwise have been rejected by the tool.

func IsClaudeCodeAttributionSystemText

func IsClaudeCodeAttributionSystemText(text string) bool

IsClaudeCodeAttributionSystemText reports whether text is the Claude Code attribution block that carries per-request billing and prompt fingerprint data.

func IsGeminiClaudeToolUseID

func IsGeminiClaudeToolUseID(id string) bool

IsGeminiClaudeToolUseID reports whether id belongs to the reserved Claude-facing Gemini provenance namespace.

func NormalizeClaudeToolInputSchema

func NormalizeClaudeToolInputSchema(schema []byte) []byte

NormalizeClaudeToolInputSchema makes a JSON Schema compatible with Claude's requirement that a tool input schema is an object without root-level unions.

func ParseGJSONBytesNoCopy

func ParseGJSONBytesNoCopy(data []byte) gjson.Result

ParseGJSONBytesNoCopy parses data into a GJSON result that references data directly. gjson.ParseBytes copies the whole document, which is prohibitive for multi-megabyte payloads. Callers must not retain the result or mutate data while using it.

func SanitizeClaudeFunctionName

func SanitizeClaudeFunctionName(name string) string

SanitizeClaudeFunctionName ensures a function or tool name conforms to Claude's requirements: ^[a-zA-Z0-9_-]{1,64}$. Non-conforming characters (including dots and colons commonly emitted by MCP tools) are replaced with '_'.

func SanitizeClaudeToolID

func SanitizeClaudeToolID(id string) string

SanitizeClaudeToolID ensures the given id conforms to Claude's tool_use.id regex ^[a-zA-Z0-9_-]+$. Non-conforming characters are replaced with '_'; an empty result gets a generated fallback.

func StripClaudeCodeAttributionSystem

func StripClaudeCodeAttributionSystem(payload []byte) []byte

StripClaudeCodeAttributionSystem removes Claude Code billing/CCH attribution blocks from a Messages body. Other system content is kept. Providers such as Kimi and Antigravity may treat this block as prompt text, so callers use this helper when the active policy has not explicitly opted into a full CLI profile.

Types

This section is empty.

Jump to

Keyboard shortcuts

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