Package model/provider
Go module github.com/bide-ai/bide; all packages.
github.com/bide-ai/bide/model/provider · pkg.go.dev · Stability: core
Package provider is the kit a model adapter is built from: HTTP error classification, SSE framing, a cap on a streamed reply, Retry-After parsing, and the tool-result codec.
Constants
const DefaultMaxResponseBytes = 32 << 20: DefaultMaxResponseBytes is the most bytes of one streamed model reply an adapter reads unless it is configured otherwise (each adapter's WithMaxResponseBytes).const MaxSSELine = 32 << 20: MaxSSELine is the longest SSE line NewSSEScanner reads.
Functions
func ClassifyHTTPError(provider string, resp *http.Response) error: ClassifyHTTPError turns a non-2xx model response into the appropriate SDK error.func ClassifyStreamError(provider string, data []byte) error: ClassifyStreamError turns an error object a provider sends inside a 200 stream (an OpenAI or Gemini data line holding {"error":{...}}, an Anthropic "error" event) into an SDK error.func EncodeToolResultOr(c ToolResultCodec, raw json.RawMessage) string: EncodeToolResultOr applies the codec to raw and returns the result.func LimitResponse(body io.ReadCloser, max int64) io.ReadCloser: LimitResponse returns body limited to max bytes (DefaultMaxResponseBytes when max <= 0): once the reply has more, a read returns the bytes up to the limit and an error wrapping agent.ErrResponseTooLarge, which SSEReadError passes on.func NewSSEScanner(body io.Reader) *bufio.Scanner: NewSSEScanner returns a bufio.Scanner over an SSE stream body with the default 64KB line cap raised to MaxSSELine.func ParseRetryAfter(s string) time.Duration: ParseRetryAfter parses an HTTP Retry-After header value.func SSEPayload(line string) (string, bool): SSEPayload extracts the data payload from one raw SSE line.func SSEReadError(provider string, err error) error: SSEReadError wraps a failed read of a model's SSE stream (the Err of a NewSSEScanner scanner) as an agent.ErrModel.
type JSONToolResultCodec
go
type JSONToolResultCodec struct{}JSONToolResultCodec is the default codec: it passes the canonical JSON through unchanged.
Methods
func (JSONToolResultCodec) EncodeToolResult(raw json.RawMessage) (string, error): EncodeToolResult returns the JSON bytes as a string, unchanged.
type ToolResultCodec
go
type ToolResultCodec interface {
EncodeToolResult(raw json.RawMessage) (string, error)
}ToolResultCodec renders a tool result's canonical JSON bytes into the string content that is sent to the model.