internal

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 14 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 internal provides shared middleware functionality for OpenTelemetry tracers.

Package internal provides shared utilities for OpenTelemetry middleware tracers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(getMiddlewareTracer TracerRouter, log logger.Logger) func(*http.Request, NextMiddleware) (*http.Response, error)

Middleware creates a shared OpenTelemetry middleware that uses the provided router to determine which tracer to use for each endpoint. An optional logger can be provided for debug and error logging. If nil, logging is disabled.

func NormalizeClaudeToolChoice added in v0.15.0

func NormalizeClaudeToolChoice(value any) any

NormalizeClaudeToolChoice maps Claude's tool_choice onto the OpenAI vocabulary, returning nil for unrecognized values.

func NormalizeClaudeTools added in v0.15.0

func NormalizeClaudeTools(value any) []any

NormalizeClaudeTools converts user-defined tools into the OpenAI Chat Completions shape for metadata.tools. Built-in server-side tools (web_search, computer, bash, ...) pass through untouched: they aren't function-like, so a fabricated function name or schema would misrepresent them.

func SetJSONAttr

func SetJSONAttr(span trace.Span, key string, value any) error

SetJSONAttr is a helper function to set JSON attributes on spans

func ToInt64

func ToInt64(v any) (bool, int64)

ToInt64 converts various numeric types to int64

Types

type BufferedReader

type BufferedReader struct {
	// contains filtered or unexported fields
}

BufferedReader saves data read from the readCloser and triggers an action when fully read or closed.

func NewBufferedReader

func NewBufferedReader(src io.ReadCloser, onDone func(io.Reader, error)) *BufferedReader

NewBufferedReader calls onDone with buffered data and any read error when fully read, failed, or closed.

func (*BufferedReader) Close

func (r *BufferedReader) Close() error

Close closes the underlying reader and triggers the onDone callback.

func (*BufferedReader) Read

func (r *BufferedReader) Read(p []byte) (int, error)

type ClaudeStreamAccumulator added in v0.11.0

type ClaudeStreamAccumulator struct {
	// contains filtered or unexported fields
}

ClaudeStreamAccumulator incrementally reduces Claude Messages API stream events into one assistant message and merged usage data.

func NewClaudeStreamAccumulator added in v0.11.0

func NewClaudeStreamAccumulator() *ClaudeStreamAccumulator

NewClaudeStreamAccumulator creates an empty Claude stream accumulator.

func (*ClaudeStreamAccumulator) Add added in v0.11.0

func (a *ClaudeStreamAccumulator) Add(event map[string]any) bool

Add consumes one decoded Claude event. It reports whether the event contains generated text, reasoning, or tool-input content suitable for TTFT.

func (*ClaudeStreamAccumulator) ContextManagement added in v0.14.0

func (a *ClaudeStreamAccumulator) ContextManagement() map[string]any

ContextManagement returns the context_management field from the stream's message events, if present. This reports which context-editing strategies actually fired during the request (e.g. applied_edits), distinct from the request-side context_management config captured before the stream starts.

func (*ClaudeStreamAccumulator) Model added in v0.11.0

func (a *ClaudeStreamAccumulator) Model() string

Model returns the model resolved from message_start, if present.

func (*ClaudeStreamAccumulator) Output added in v0.11.0

func (a *ClaudeStreamAccumulator) Output() []map[string]any

Output returns the accumulated assistant message, or nil when no content blocks were observed.

func (*ClaudeStreamAccumulator) StopReason added in v0.11.0

func (a *ClaudeStreamAccumulator) StopReason() any

StopReason returns the final provider stop reason, if present.

func (*ClaudeStreamAccumulator) Usage added in v0.11.0

func (a *ClaudeStreamAccumulator) Usage() map[string]any

Usage returns the merged usage fields from message_start and message_delta.

type MiddlewareTracer

type MiddlewareTracer interface {
	StartSpan(ctx context.Context, start time.Time, request io.Reader) (context.Context, trace.Span, error)
	TagSpan(span trace.Span, response io.Reader) error
}

MiddlewareTracer adds tracing to API requests by parsing bodies of the request and response.

type NextMiddleware

type NextMiddleware = func(req *http.Request) (*http.Response, error)

NextMiddleware represents the next middleware to run in the client middleware chain.

type TracerRouter

type TracerRouter func(path string) MiddlewareTracer

TracerRouter maps URL paths to specific tracers for different endpoints.

Jump to

Keyboard shortcuts

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