Documentation
¶
Overview ¶
Package parsercommon holds small helpers shared by the in-tree protocol parser plugins (a2a-parser, mcp-parser, inference-parser). Lives under internal/ so only packages under authlib/plugins/ can import it — third-party plugins are expected to either depend on the public pipeline surface or roll their own parsing. The contents here are stable but intentionally undocumented as a public API.
Index ¶
Constants ¶
const DebugBodyMax = 512
DebugBodyMax caps how many characters of a body/content string a parser writes into debug logs. Large enough to capture a short user message or a tool_call response verbatim, small enough to keep log lines tractable.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JSONRPCRequest ¶
type JSONRPCRequest struct {
Method string `json:"method"`
ID any `json:"id"`
Params map[string]any `json:"params"`
}
JSONRPCRequest is the minimal JSON-RPC 2.0 request shape the a2a and mcp parsers decode. Fields intentionally match the permissive `any`-typed variant of the protocol: the parsers never re-emit these on the wire so strict typing here would only cost flexibility.
func (*JSONRPCRequest) MapParam ¶
func (r *JSONRPCRequest) MapParam(key string) map[string]any
MapParam returns the Params[key] value cast to map[string]any, or nil if absent / wrong type.
func (*JSONRPCRequest) StringParam ¶
func (r *JSONRPCRequest) StringParam(key string) string
StringParam returns the Params[key] value cast to string, or "" if absent / wrong type.
type Kind ¶
type Kind uint8
Kind is a bitmask naming which sub-kinds the provider populated. A zero on a set bit is "reported zero"; a zero on an unset bit is "not exposed."
type TokenUsage ¶
type TokenUsage struct {
Input int // uncached prompt tokens
CacheRead int // prompt tokens served from cache
CacheWrite int // prompt tokens written to cache
Output int // generated completion tokens
Reasoning int // reasoning-only output (subset of Output)
ReportedTotal int // provider's own total_tokens if reported, else 0
Present Kind // which sub-kinds the provider reported
}
TokenUsage is the provider-neutral token accounting shape. Parsers normalize their wire format into these fields before publishing via Fill, and set Present to name which sub-kinds the wire carried.
func (TokenUsage) Fill ¶
func (u TokenUsage) Fill(ext *pipeline.InferenceExtension)
Fill writes the split counters, the Present bitmask, and the derived legacy aggregates onto ext. TotalTokens prefers the provider's own reported total when present — a gateway that reports only total_tokens (with prompt/completion zero) would otherwise record 0 here.
func (TokenUsage) PromptTotal ¶
func (u TokenUsage) PromptTotal() int
PromptTotal is the sum of all prompt-side sub-kinds.
func (TokenUsage) Total ¶
func (u TokenUsage) Total() int
Total is PromptTotal + Output. Reasoning is a subset of Output and intentionally not added.