parsercommon

package
v0.0.0-...-4ef879c Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 1 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

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

View Source
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

func Truncate

func Truncate(s string, max int) string

Truncate clips s to max characters, appending "..." when truncated. Shared across parsers for consistent debug-log body formatting.

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."

const (
	KindInput Kind = 1 << iota
	KindCacheRead
	KindCacheWrite
	KindOutput
	KindReasoning
)

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.

Jump to

Keyboard shortcuts

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