schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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

Overview

Package schema wraps bifrost's provider-agnostic chat schema with the helpers context-guru components need: token accounting, deep-clone for fail-open snapshots, tool-result iteration, and byte-preservation for lossless round-trips of provider-specific fields.

Components operate directly on *schemas.BifrostChatRequest (see package components); this package is the small toolbox around that type, not a competing model. Wire<->schema conversion lives in the host adapters — the bifrost proxy gets it for free from bifrost's transport, the AuthBridge plugin uses FromOpenAIBytes/FromAnthropicBytes (added in P3).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockText

func BlockText(b schemas.ChatContentBlock) string

BlockText returns the text payload of a content block, or "" if the block carries no text (image/audio/file/refusal).

func CloneMessages

func CloneMessages(in []schemas.ChatMessage) []schemas.ChatMessage

CloneMessages deep-copies a message slice via JSON round-trip. Used to snapshot a request before a component runs so the pipeline can restore it on error/panic or when a component fails the never-worse gate. JSON round-trip is safe because bifrost's content types implement custom (Un)MarshalJSON that preserve cache_control/citations/cachePoint.

func MessageText

func MessageText(m schemas.ChatMessage) string

MessageText returns the concatenated text of a message, handling both the string-content and block-content representations.

func MessagesTokens

func MessagesTokens(req *schemas.BifrostChatRequest) int

MessagesTokens estimates the token cost of a request's messages by counting the message CONTENT text — what the model actually reads — not the JSON envelope. This is the signal the never-worse gate needs: control metadata like cache_control adds envelope bytes but no model-visible tokens, so a cache-injection Reformat must not look "worse" for adding it.

func Rewritable

func Rewritable(m schemas.ChatMessage) bool

Rewritable reports whether m's content can be safely replaced with a plain text string (via SetMessageText) without losing data. It is false when the message carries any non-text content block — image/audio/file/refusal, or a block type bifrost does not model (e.g. Anthropic tool_result, whose payload lives in fields MessageText never reads). Those bytes would vanish on a text-only rewrite and were never stashed, so components must skip such messages. String content and all-text block content are rewritable.

func SetMessageText

func SetMessageText(m *schemas.ChatMessage, text string)

SetMessageText replaces a message's content with a single text string, collapsing any block structure. Components that rewrite a whole message's text (e.g. cmdfilter, offload markers) use this.

func TextTokens

func TextTokens(s string) int

TextTokens counts tokens in a raw string via the shared tokenizer.

Types

type Provider

type Provider = schemas.ModelProvider

Provider identifies the wire dialect a request arrived in. It drives provider-specific behaviour (e.g. cache_control is Anthropic-family) and how the adapter renders bytes back out.

Jump to

Keyboard shortcuts

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