Documentation
¶
Overview ¶
Package passthroughparse decodes the raw request and response bodies of a passthrough call into Bifrost's typed request/response schemas, so passthrough traffic can be logged and rendered like any other request. Routing is shared with the providers' passthrough usage extractors (each provider's ClassifyPassthroughPath and vertex.PassthroughWireFormat), so a path is classified the same way for billing and for logging.
Everything here is a pure transformation of the bytes it is handed: no network, no logging, no shared state. It is meant to run off the request path (the logging plugin calls it from its batch writer).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InferRequestType ¶
func InferRequestType(provider schemas.ModelProvider, model, method, path string, stream bool) schemas.RequestType
InferRequestType returns the request type a passthrough call addresses from its route alone (base provider, model, method, path) without reading either body, or "" when the route has no typed equivalent. stream selects the streaming variant where one exists. It is cheap enough for the request path: a few string suffix checks.
func SummarizeMultipart ¶
SummarizeMultipart turns a multipart/form-data body into the JSON of its MultipartSummary. It returns ok=false when contentType is not multipart or the body does not read as one, so the caller can keep its previous behaviour (no body logged).
It runs on the request path (PreLLMHook, content logging on), so it never copies or decodes file parts: the body is already in memory, and each part's extent is found with bytes.Index on the delimiter, which skips file contents at memchr speed instead of streaming them through a reader.
Types ¶
type Input ¶
type Input struct {
Provider schemas.ModelProvider // base provider type; custom providers pass their BaseProviderType
Model string // resolved model (from the path or the body's "model" field)
Method string
Path string // stripped request path, as in PassthroughLogParams.Path
StatusCode int // upstream status; error bodies (>= 400) are never parsed as responses
RequestBody []byte
ResponseBody []byte
Stream bool
}
Input is one passthrough call as the logging plugin recorded it.
type MultipartFile ¶
type MultipartFile struct {
Field string `json:"field"`
Filename string `json:"filename,omitempty"`
ContentType string `json:"content_type,omitempty"`
Bytes int64 `json:"bytes"`
}
MultipartFile describes one file part of a multipart body.
type MultipartSummary ¶
type MultipartSummary struct {
Fields map[string]any `json:"fields"` // a string, or a []string for a repeated field
Files []MultipartFile `json:"files,omitempty"`
Truncated bool `json:"truncated,omitempty"` // some field text was cut or left out to bound the summary
}
MultipartSummary is the loggable form of a multipart/form-data passthrough body (audio transcriptions, image edits): its text fields as sent, and only the name, type and size of each file part. File contents are never kept.
type Result ¶
type Result struct {
RequestType schemas.RequestType // the inner kind the path addresses, e.g. ChatCompletionRequest
Request *schemas.BifrostRequest
Response *schemas.BifrostResponse
}
Result is the typed view of a passthrough call. Request and Response are independent: either can be nil when its body was absent or did not decode, and the other is still usable.
func Parse ¶
Parse decodes a passthrough call on a best-effort basis. It returns (nil, nil) for routes with no typed equivalent (unsupported providers, list/retrieve calls, Bedrock agent routes), so the caller keeps the raw bodies only. A non-nil error describes a body that matched a known route but failed to decode; the Result alongside it still carries whichever side did decode. Parse never panics: a converter that panics on an unexpected body is reported as an error for that side.