probe

package
v0.260801.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 20 Imported by: 0

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func E2EMessage

func E2EMessage(mode E2EMode, customMsg string) string

E2EMessage returns the probe message body based on test mode, with an optional caller-provided override.

func ScenarioEndpoint

func ScenarioEndpoint(scenario string) (endpoint string, apiStyle protocol.APIStyle)

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 E2EData

type E2EData = ProbeResult

E2EData is an alias to ProbeResult — the canonical SDK-level probe result. Aliased so service-layer Response wrappers and swagger registrations can keep referring to the historical E2EData name.

type E2EMode

type E2EMode string

E2EMode defines the test mode.

const (
	E2EModeSimple    E2EMode = "simple"
	E2EModeStreaming E2EMode = "streaming"
	E2EModeTool      E2EMode = "tool"
)

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

	TestMode E2EMode `json:"test_mode" binding:"required"`

	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"`
}

E2ERequest represents a Probe V2 request.

type E2EResponseChunk

type E2EResponseChunk struct {
	Type      string `json:"type"` // content, error, done
	Content   string `json:"content,omitempty"`
	Error     string `json:"error,omitempty"`
	LatencyMs int64  `json:"latency_ms,omitempty"`

	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
}

E2EResponseChunk represents a streaming response chunk.

type E2EService

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

E2EService 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 NewE2EService

func NewE2EService(cfg *config.Config, pool *client.ClientPool) *E2EService

NewE2EService constructs a E2EService.

func (*E2EService) Probe

func (e *E2EService) Probe(ctx context.Context, req *E2ERequest) (*E2EData, error)

Probe performs a non-streaming probe against the target described by req.

func (*E2EService) ProbeProviderWithSDK

func (e *E2EService) ProbeProviderWithSDK(ctx context.Context, provider *typ.Provider, model, message string, testMode E2EMode) (*E2EData, error)

ProbeProviderWithSDK runs an SDK probe by dispatching a minimal request through the provider's real-traffic client methods. Public because the server's provider onboarding path (testProviderConnectivity) reuses it.

func (*E2EService) ProbeStream

func (e *E2EService) ProbeStream(ctx context.Context, req *E2ERequest) (*E2EData, error)

ProbeStream performs a streaming probe against the target described by req.

type E2ETarget

type E2ETarget string

E2ETarget defines the target type for probe.

const (
	E2ETargetRule           E2ETarget = "rule"
	E2ETargetProvider       E2ETarget = "provider"
	E2ETargetProviderConfig E2ETarget = "provider_config"
)

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 LightweightService

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

LightweightService 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 NewLightweightService

func NewLightweightService(pool *client.ClientPool) *LightweightService

NewLightweightService constructs a LightweightService backed by the given client pool.

func (*LightweightService) Probe

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 ProbeProviderRequest

type ProbeProviderRequest 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" description:"API style" example:"openai"`
	Token    string `json:"token" binding:"required" description:"API token to test" example:"sk-..."`
}

ProbeProviderRequest represents the request to probe/test a provider's API key and connectivity.

type ProbeProviderResponseData

type ProbeProviderResponseData struct {
	Provider     string `json:"provider" example:"openai"`
	APIBase      string `json:"api_base" example:"https://api.openai.com/v1"`
	APIStyle     string `json:"api_style" example:"openai"`
	Valid        bool   `json:"valid" example:"true"`
	Message      string `json:"message" example:"API key is valid and accessible"`
	TestResult   string `json:"test_result" example:"models_endpoint_success"`
	ResponseTime int64  `json:"response_time_ms" example:"250"`
	ModelsCount  int    `json:"models_count,omitempty" example:"150"`
}

ProbeProviderResponseData represents the data returned from provider probing.

type ProbeRequest

type ProbeRequest struct {
	Provider string `json:"provider" binding:"required" description:"Provider UUID to test against" example:"550e8400-e29b-41d4-a716-446655440000"`
	Model    string `json:"model" binding:"required" description:"Model name to test against" example:"gpt-4-latest"`
}

ProbeRequest represents the request to probe/test a provider and model.

type ProbeResult added in v0.260611.1

type ProbeResult struct {
	// Basic fields
	Success      bool   `json:"success"`
	Message      string `json:"message,omitempty"`
	Content      string `json:"content,omitempty"`
	LatencyMs    int64  `json:"latency_ms"`
	ModelsCount  int    `json:"models_count,omitempty"`
	ErrorMessage string `json:"error_message,omitempty"`

	// Streaming mode indicator
	Stream bool `json:"stream,omitempty"`

	// Token usage
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`

	// Tool calls (for tool mode)
	ToolCalls []ProbeToolCall `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"`
}

ProbeResult 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 ProbeToolCall added in v0.260611.1

type ProbeToolCall struct {
	ID    string                 `json:"id"`
	Name  string                 `json:"name"`
	Input map[string]interface{} `json:"input"`
}

ProbeToolCall represents a tool call in a probe response.

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a probe-request validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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