Documentation
¶
Overview ¶
Package probe contains the decoupled, server-independent half of the probe subsystem: request types, result/data types, in-memory cache, the E2E and Lightweight strategies, and pure helpers. The Adaptive strategy still lives in internal/server because it remains coupled to *Server; it will be moved in a follow-up once that coupling is broken.
Two result types answer two different questions and are deliberately NOT unified:
- Result (alias E2EData) — SDK-level truth for one real round-trip through the production client methods. Carries normalized token Usage, lifted tool calls, and the routing journey. Returned by the E2E prober.
- LightweightProbeResponseData — a per-endpoint connectivity matrix (OPTIONS / models / chat / responses success+latency). Advisory only, no usage, never blocks onboarding. Returned by the Lightweight prober.
Both probers share the low-level SDK dispatch helpers (probeOpenAIChat, probeOptions, …). A probe never invents a model: if the request omits one and the provider record carries none, resolution fails explicitly rather than guessing.
Index ¶
- func E2EMessage(tool bool, customMsg string) string
- func ScenarioEndpoint(scenario string) (endpoint string, apiStyle protocol.APIStyle)
- func ValidateE2ERequest(req *E2ERequest) error
- type CurlData
- type E2EData
- type E2EProber
- type E2ERequest
- func (req *E2ERequest) Customized() bool
- func (req *E2ERequest) HasRawRequest() bool
- func (req *E2ERequest) ResolveAxes() (stream, tool bool)
- func (req *E2ERequest) ResolveClientStyle(providerStyle protocol.APIStyle) protocol.APIStyle
- func (req *E2ERequest) ResolveOpenAIEndpointOverride() string
- func (req *E2ERequest) WireProtocol() ProbeProtocol
- type E2ETarget
- type LightProber
- type LightweightProbeRequest
- type LightweightProbeResponseData
- type ProbeProtocol
- type Result
- type ThinkingLevel
- type ToolCall
- type ValidationError
- type VisionChannel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func E2EMessage ¶
E2EMessage returns the probe message body: a caller-provided override when given, otherwise a default message chosen by whether the probe attaches tools.
func ScenarioEndpoint ¶
ScenarioEndpoint returns the API endpoint and api-style for a scenario name. The endpoint path preserves the full scenario (including any "base:profile" suffix, e.g. "claude_code:p1"), while the api-style is resolved from the base scenario so profiled scenarios map to the correct SDK.
func ValidateE2ERequest ¶
func ValidateE2ERequest(req *E2ERequest) error
ValidateE2ERequest validates a probe v2 request payload.
Types ¶
type CurlData ¶ added in v0.260827.1
type CurlData struct {
Command string `json:"command" example:"curl -N http://localhost:9999/tingly/openai/v1/chat/completions …"`
Method string `json:"method" example:"POST"`
URL string `json:"url" example:"http://localhost:9999/tingly/openai/v1/chat/completions"`
// Headers maps header name → value with the secret as a placeholder env
// var ($TB_API_KEY through TB, $UPSTREAM_API_KEY direct upstream).
Headers map[string]string `json:"headers"`
// Body is the exact JSON body the probe would send (same param builders
// the SDK helpers use).
Body string `json:"body"`
// KeyEnvVar names the placeholder used in Headers/Command, so callers can
// render a substitution hint.
KeyEnvVar string `json:"key_env_var" example:"$TB_API_KEY"`
}
CurlData is the constructed (never executed) equivalent of a probe request, returned by POST /api/v2/probe/curl. Request carries the structured pieces; Command is the copy-pasteable rendering.
type E2EData ¶
type E2EData = Result
E2EData is an alias to Result — the canonical SDK-level probe result. Aliased so service-layer Response wrappers and swagger registrations can keep referring to the historical E2EData name.
type E2EProber ¶ added in v0.260813.1
type E2EProber struct {
// contains filtered or unexported fields
}
E2EProber runs SDK-level end-to-end probes against a rule, a saved provider, or an inline provider config. It is independent of *Server and is wired in NewServer.
func NewE2EProber ¶ added in v0.260813.1
func NewE2EProber(cfg *config.Config, pool *client.ClientPool) *E2EProber
NewE2EProber constructs a E2EProber.
func (*E2EProber) BuildCurl ¶ added in v0.260827.1
BuildCurl constructs the curl equivalent of a probe request without executing it. It resolves the target exactly like Probe (loopback or direct upstream) and reuses the same param builders, so the generated body cannot drift from what a real probe sends.
func (*E2EProber) Probe ¶ added in v0.260813.1
Probe performs an SDK probe against the target described by req. It serves all probe shapes — non-stream/stream × plain/tool — the stream decision is made inside the SDK helpers from req.ResolveAxes(). Only the narrow direct-endpoint capability-check shape is cached; everything else dispatches for real.
type E2ERequest ¶
type E2ERequest struct {
TargetType E2ETarget `json:"target_type" binding:"required"`
Scenario string `json:"scenario,omitempty" example:"anthropic"`
RuleUUID string `json:"rule_uuid,omitempty" binding:"required_if=TargetType rule"`
ProviderUUID string `json:"provider_uuid,omitempty" binding:"required_if=TargetType provider"`
Model string `json:"model,omitempty" binding:"required_if=TargetType provider"`
Name string `json:"name,omitempty"`
APIBase string `json:"api_base,omitempty"`
APIStyle string `json:"api_style,omitempty"`
Token string `json:"token,omitempty"`
// Stream and Tool are the orthogonal axes describing the probe shape.
// nil normalizes to false. Tool does NOT force either stream value — both
// combinations are valid (non-stream lifts structured tool_calls; stream
// keeps raw chunks).
Stream *bool `json:"stream,omitempty" example:"true"`
Tool *bool `json:"tool,omitempty" example:"false"`
Message string `json:"message,omitempty"`
// Direct skips the TB loopback and calls the upstream provider directly.
// Only meaningful for target_type="provider". Use this to isolate whether
// a failure is in the upstream provider or in TB's own middleware stack.
Direct bool `json:"direct,omitempty"`
// Protocol forces the client-side wire protocol: openai_chat,
// openai_responses, or anthropic_v1. No "auto" value — empty (default)
// keeps the provider's primary protocol (its APIStyle, plus the Codex
// OAuth → Responses default for OpenAI providers). For dual-base
// providers the matching dual URL is selected; for through-TB probes the
// loopback speaks the requested protocol and TB's transform pipeline
// handles the upstream exactly as production traffic does.
// Rule targets accept any protocol too: the probe sends what a real client
// choosing it would send to /tingly/{scenario}, and TB's answer is the
// result (e.g. TB's Responses handler rejects scenarios without the
// OpenAI transport). Empty keeps the scenario's default (ScenarioEndpoint).
Protocol ProbeProtocol `json:"protocol,omitempty" example:"openai_responses"`
// Thinking sets the extended-thinking effort for the probe. Orthogonal to
// Stream/Tool — composes with both streaming and non-streaming probes. "none"
// (and the empty string, the default) sends no thinking param; "low"/
// "medium"/"high"/"max" map to each provider's native thinking knob via
// internal/protocol/thinking. Used to verify a model/provider actually
// returns reasoning tokens before trusting it with a rule.
Thinking ThinkingLevel `json:"thinking,omitempty" example:"medium"`
// Vision attaches the canonical probe image (internal/protocol/vision) to
// the request: "user" puts it in the user message, "tool" returns it from
// a synthetic tool round — the two channels of issue #1606. "none" (and
// the empty string, the default) sends no image. Orthogonal to Stream and
// Protocol. A vision-capable route answers the fixture prompt with "red";
// any other answer reveals a drop or corruption along the path. Not
// supported for Google-style targets.
Vision VisionChannel `json:"vision,omitempty" example:"user"`
// Request is a raw client request body in one of the three client
// protocols (RequestProtocol says which) — what a real client would send
// TB. The probe parses it with the same SDK decoders TB's handlers use
// for inbound traffic, fills in what the target decides (model; Anthropic
// max_tokens when absent) and sends it on that protocol's wire, so text,
// images, tools and tool results, cache breakpoints, thinking — anything
// the protocol accepts — travel as-is. Through TB, TB's own transform
// chain converts it to the upstream exactly as for production traffic.
// A raw request replaces the fixture: Message and the Tool / Vision /
// Thinking knobs (which only shape the fixture) are rejected alongside
// it; Stream still applies. The probe speaks RequestProtocol on the wire
// for every target (Protocol, if given, must agree).
Request json.RawMessage `json:"request,omitempty" swaggertype:"object"`
RequestProtocol ProbeProtocol `json:"request_protocol,omitempty" example:"anthropic_v1"`
// Flags is a per-request rule-flag overlay (Bench page). Only the keys
// present are applied; each replaces the value resolved from rule +
// scenario inheritance for this one request, and nothing is persisted.
// Keys and value types are validated against typ.RuleFlagRegistry().
// Through-TB only: flags are TB middleware, so a direct probe cannot
// carry them (rejected, never silently ignored). Travels to the loopback
// handler in the X-Tingly-Probe-Flags header.
Flags typ.FlagOverlay `json:"flags,omitempty" swaggertype:"object"`
// Headers sets or overrides HTTP headers on the outgoing probe request
// (an empty value removes the header). Applied by a probe-only round
// tripper after the SDK built the request, so it wins over the SDK's
// own headers and the probe pins; the rendered cURL applies the same.
Headers map[string]string `json:"headers,omitempty"`
}
E2ERequest represents a Probe V2 request.
func (*E2ERequest) Customized ¶ added in v0.260924.1
func (req *E2ERequest) Customized() bool
Customized reports whether the request departs from the plain fixture shape (raw request, flag overlay, header overrides). Such probes are never served from the endpoint capability cache — the whole point of customizing a probe is to watch what that exact request does.
func (*E2ERequest) HasRawRequest ¶ added in v0.260924.1
func (req *E2ERequest) HasRawRequest() bool
HasRawRequest reports whether the probe sends a caller-supplied request instead of the fixture.
func (*E2ERequest) ResolveAxes ¶ added in v0.260827.1
func (req *E2ERequest) ResolveAxes() (stream, tool bool)
ResolveAxes returns the effective stream/tool decisions (nil → false).
func (*E2ERequest) ResolveClientStyle ¶ added in v0.260827.1
func (req *E2ERequest) ResolveClientStyle(providerStyle protocol.APIStyle) protocol.APIStyle
ResolveClientStyle returns the client-side API style the probe should speak, after applying the protocol override (if any) to the provider's own style. Returns the provider style unchanged for "", google, and unsupported combinations — callers decide whether that is an error.
func (*E2ERequest) ResolveOpenAIEndpointOverride ¶ added in v0.260827.1
func (req *E2ERequest) ResolveOpenAIEndpointOverride() string
ResolveOpenAIEndpointOverride translates Protocol into the endpointOverride consumed by resolveOpenAIProbeEndpoint ("chat"/"responses", or "" to keep the provider's default).
func (*E2ERequest) WireProtocol ¶ added in v0.260924.1
func (req *E2ERequest) WireProtocol() ProbeProtocol
WireProtocol is the client protocol the probe speaks: the raw request's protocol when one is given, else the Protocol override, else "" (the target's primary protocol).
type LightProber ¶ added in v0.260813.1
type LightProber struct {
// contains filtered or unexported fields
}
LightProber runs the optional "Test Connection" probe used when a user adds an API key. It pokes OPTIONS, /models, /chat/completions, and /responses and returns a per-endpoint report; results are advisory only and do not block onboarding. Independent of *Server.
func NewLightProber ¶ added in v0.260813.1
func NewLightProber(pool *client.ClientPool) *LightProber
NewLightProber constructs a LightProber backed by the given client pool.
func (*LightProber) Probe ¶ added in v0.260813.1
func (l *LightProber) Probe(ctx context.Context, provider *typ.Provider) *LightweightProbeResponseData
Probe runs every applicable sub-probe for the provider and returns a populated LightweightProbeResponseData. Never returns an error — partial failure is encoded in the per-endpoint fields and the Valid summary.
type LightweightProbeRequest ¶
type LightweightProbeRequest struct {
Name string `json:"name" binding:"required" description:"Provider name" example:"openai"`
APIBase string `json:"api_base" binding:"required" description:"API base URL" example:"https://api.openai.com/v1"`
APIStyle string `json:"api_style" binding:"required,oneof=openai anthropic google" description:"API style" example:"openai"`
Token string `json:"token" binding:"required" description:"API token to test" example:"sk-..."`
AuthType string `json:"auth_type,omitempty" description:"Auth type (e.g., api_key, oauth)" example:"api_key"`
}
LightweightProbeRequest represents a lightweight probe request for key validation.
type LightweightProbeResponseData ¶
type LightweightProbeResponseData struct {
Valid bool `json:"valid" example:"true"`
Message string `json:"message" example:"Connection test completed"`
OptionsSuccess bool `json:"options_success" example:"true"`
OptionsMessage string `json:"options_message,omitempty" example:"OPTIONS request successful"`
OptionsResponseTime int64 `json:"options_response_time_ms,omitempty" example:"45"`
ModelsSuccess bool `json:"models_success" example:"true"`
ModelsMessage string `json:"models_message,omitempty" example:"Models endpoint accessible"`
ModelsResponseTime int64 `json:"models_response_time_ms,omitempty" example:"250"`
ModelsCount int `json:"models_count,omitempty" example:"150"`
ChatSuccess bool `json:"chat_success,omitempty" example:"true"`
ChatMessage string `json:"chat_message,omitempty" example:"Chat endpoint accessible"`
ChatResponseTime int64 `json:"chat_response_time_ms,omitempty" example:"180"`
ResponsesSuccess bool `json:"responses_success,omitempty" example:"true"`
ResponsesMessage string `json:"responses_message,omitempty" example:"Responses API endpoint accessible"`
ResponsesResponseTime int64 `json:"responses_response_time_ms,omitempty" example:"200"`
Provider string `json:"provider" example:"openai"`
APIBase string `json:"api_base" example:"https://api.openai.com/v1"`
APIStyle string `json:"api_style" example:"openai"`
Warning string `json:"warning,omitempty" example:"Models endpoint not supported for this provider type"`
}
LightweightProbeResponseData represents the data returned from lightweight probing.
type ProbeProtocol ¶ added in v0.260827.1
type ProbeProtocol string
ProbeProtocol is a concrete client-side wire protocol for a probe. There is deliberately no "auto" value — the panel always speaks a concrete protocol, defaulting to the provider's primary one (ResolveProbeProtocol).
const ( // ProtocolOpenAIChat probes via OpenAI Chat Completions. ProtocolOpenAIChat ProbeProtocol = "openai_chat" // ProtocolOpenAIResponses probes via the OpenAI Responses API. ProtocolOpenAIResponses ProbeProtocol = "openai_responses" // ProtocolAnthropic probes via the Anthropic Messages API. ProtocolAnthropic ProbeProtocol = "anthropic_v1" )
func (ProbeProtocol) Family ¶ added in v0.260827.1
func (p ProbeProtocol) Family() protocol.APIStyle
ProtocolFamily maps a ProbeProtocol onto the client API style it implies.
type Result ¶ added in v0.260813.1
type Result struct {
// Basic fields
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Content string `json:"content,omitempty"`
LatencyMs int64 `json:"latency_ms"`
ErrorMessage string `json:"error_message,omitempty"`
// Request-echo axes — the exact stream/tool/direct/protocol/thinking
// combination that produced this result. Stream is redundant with the
// caller's test_mode but kept explicit so consumers don't have to infer the
// response shape from Content; the rest let a consumer reopening a stored
// result restore the control state that produced it (the frontend probe
// dialog does not persist axes, so the echo is the only source).
Stream bool `json:"stream,omitempty"`
Tool bool `json:"tool,omitempty"`
Direct bool `json:"direct,omitempty"`
Protocol ProbeProtocol `json:"protocol,omitempty"`
Thinking ThinkingLevel `json:"thinking,omitempty"`
Vision VisionChannel `json:"vision,omitempty"`
// Usage is the normalized token usage for the probe round-trip, parsed via
// internal/protocol/usage from each provider's native usage struct. It uses
// the canonical protocol.TokenUsage shape (input_tokens / output_tokens /
// cache_read_tokens / cache_write_tokens / reasoning_tokens / system_tokens)
// — the same vocabulary the rest of the codebase emits and the frontend
// renders. Nil for cache hits, Google probes (out of scope), and providers
// that don't report usage (notably most streaming responses unless usage is
// requested).
Usage *protocol.TokenUsage `json:"usage,omitempty"`
// Tool calls lifted out of the response (tool mode only). Empty for
// non-tool probes and for providers whose tool calls couldn't be extracted.
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
// Request URL (for debugging)
RequestURL string `json:"request_url,omitempty"`
// Routing trace — populated for TB-loopback probes (provider and rule targets).
// Empty for direct probes and provider_config probes.
SelectedProvider string `json:"selected_provider,omitempty"`
SelectedProviderUUID string `json:"selected_provider_uuid,omitempty"`
SelectedModel string `json:"selected_model,omitempty"`
RoutingSource string `json:"routing_source,omitempty"`
MatchedSmartRule *int `json:"matched_smart_rule,omitempty"` // nil = none, ≥0 = index
// Execution-level facts — the real upstream endpoint TB used, the matched
// rule, and the flags it applied. Populated for TB-loopback probes.
UpstreamAPI string `json:"upstream_api,omitempty"`
UpstreamURL string `json:"upstream_url,omitempty"`
MatchedRule string `json:"matched_rule,omitempty"`
MatchedRuleDesc string `json:"matched_rule_desc,omitempty"`
AppliedFlags string `json:"applied_flags,omitempty"`
}
Result is the canonical SDK-level probe result, shared by the E2E and lightweight probe strategies. It doubles as the JSON payload returned by the probe HTTP endpoints (exposed under the E2EData alias).
type ThinkingLevel ¶ added in v0.260813.2
ThinkingLevel is the probe-facing subset of the canonical thinking-effort ladder (internal/protocol/thinking). Orthogonal to the Stream/Tool axes — composes with both streaming and non-streaming probes. "none" (and the empty string) send no thinking param; the other levels map to each provider's native thinking knob (Anthropic budget_tokens, OpenAI reasoning_effort, Gemini thinking_budget) via thinking.BudgetMapping / the effort value.
Mirrors the rule flag's thinking_effort options (.design/rule-flags.md): low/medium/high/max. "minimal"/"xhigh" are deliberately excluded — outside a handful of the newest OpenAI/Anthropic models they collapse onto low/high/max anyway, so probing them wouldn't exercise anything the low/high/max probes don't already cover.
const ( ThinkingNone ThinkingLevel = "none" ThinkingLow ThinkingLevel = thinking.LevelLow ThinkingMedium ThinkingLevel = thinking.LevelMedium ThinkingHigh ThinkingLevel = thinking.LevelHigh ThinkingMax ThinkingLevel = thinking.LevelMax )
type ToolCall ¶ added in v0.260813.1
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Input map[string]any `json:"input"`
}
ToolCall represents a tool call in a probe response.
type ValidationError ¶
ValidationError represents a probe-request validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type VisionChannel ¶ added in v0.260827.1
type VisionChannel string
VisionChannel identifies where an image rides in a request: the user message or a tool-result turn. These are exactly the two rows of the issue #1606 control matrix — user-channel images and tool-channel images fail independently, so a vision check must be able to exercise each.
const ( // VisionNone sends no image (the default; "" normalizes to this). VisionNone VisionChannel = "none" // VisonUser puts the image in the user message content. VisonUser VisionChannel = "user" // VisionTool returns the image from a synthetic tool round // (assistant tool call → tool result carrying the image), the shape // agent frameworks use for screenshots. VisionTool VisionChannel = "tool" )
func (VisionChannel) Enabled ¶ added in v0.260827.1
func (c VisionChannel) Enabled() bool
Enabled reports whether the channel carries an image. "" and "none" both mean "send no image".