probe

package
v0.260604.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MPL-2.0 Imports: 12 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 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.

func ValidateE2ERequest

func ValidateE2ERequest(req *E2ERequest) error

ValidateE2ERequest validates a probe v2 request payload.

Types

type E2EData

type E2EData = client.ProbeResult

E2EData is an alias to client.ProbeResult — the canonical SDK-level probe result. Aliased so service-layer Response wrappers and swagger registrations can reference a name in this package without re-importing internal/client.

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

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, selectFromRoutes SelectServiceFn) *E2EService

NewE2EService constructs a E2EService. selectFromRoutes is required and receives the smart-routing decision when probing a rule target.

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 a non-streaming SDK probe. 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 SelectServiceFn

type SelectServiceFn func(matched []*loadbalance.Service, rule *typ.Rule) (*loadbalance.Service, error)

SelectServiceFn picks one load-balanced service from a set of smart-routing matches. This is the single piece of behaviour E2EService borrows from the server-side load balancer; passed as a callback to avoid an internal/probe -> internal/server import cycle.

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