routecore

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRouteNotConfigured  = errors.New("route is not configured")
	ErrStaticRouteReadOnly = errors.New("static route is read-only")
)
View Source
var ErrInvalidRouteID = errors.New("invalid route id")

ErrInvalidRouteID marks a route id that cannot be addressed as a single Admin API path segment. It is a client-correctable input error; callers should map it to a 400, not a 500.

Functions

func DecodeStoredAgentRouteConfig

func DecodeStoredAgentRouteConfig(data []byte) (any, error)

func GenerateRouteID added in v0.4.1

func GenerateRouteID(prefix, serviceID, pathPrefix string) string

GenerateRouteID builds a deterministic, slash-free route id of the form "<prefix>:<service_id>:<path-slug>".

The id is fully predictable from (prefix, serviceID, pathPrefix) so callers can compute it by hand and cross-reference a route before it is applied (e.g. in a virtual key's allowed_route_ids). prefix is the protocol tag (e.g. "acp" or "mcp"). Both prefix and serviceID are assumed slash-free (service ids are already constrained to a single Admin API path segment); ValidateRouteID guards the final result regardless.

Because no disambiguating suffix is appended, two routes on the same service whose path prefixes slugify to the same value collide on id; that collision surfaces as a duplicate-id error at create/validate time, at which point the operator sets an explicit id.

func ValidateRouteID added in v0.4.1

func ValidateRouteID(id string) error

ValidateRouteID rejects route ids that cannot be addressed as a single Admin API path segment. Route ids are used verbatim in "/admin/<proto>/routes/{id}", so a slash (raw or escaped) would break GET/PUT/DELETE routing.

Types

type AgentRouteConfig

type AgentRouteConfig struct {
	ID           string           `json:"id"`
	Kind         RouteKind        `json:"kind"`
	Protocol     RouteProtocol    `json:"protocol"`
	Description  string           `json:"description,omitempty"`
	Disabled     bool             `json:"disabled"`
	AuthPolicy   RouteAuthPolicy  `json:"auth_policy"`
	MatchPolicy  RouteMatchPolicy `json:"match_policy"`
	TargetPolicy json.RawMessage  `json:"target_policy"`
	CreatedAt    time.Time        `json:"created_at"`
	UpdatedAt    time.Time        `json:"updated_at"`
}

func MatchManagers

func MatchManagers(ctx context.Context, r *http.Request, managers ...*AgentRouteConfigManager) (AgentRouteConfig, bool, error)

func MatchRouteConfigs

func MatchRouteConfigs(routes []AgentRouteConfig, r *http.Request) (AgentRouteConfig, bool)

func (AgentRouteConfig) Fingerprint added in v0.3.0

func (c AgentRouteConfig) Fingerprint() string

Fingerprint returns a cheap version string for the route config used as the runtime resolver materializer key. UpdatedAt is bumped on every Create/Update, so it changes whenever the stored config changes. This is a secondary cache signal only: the route resolvers also explicitly Invalidate on every mutation, so the fingerprint exists to self-heal any resolver that missed invalidation. Avoid marshaling the whole config here; this runs on every matched request.

type AgentRouteConfigManager

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

func NewAgentRouteConfigManager

func NewAgentRouteConfigManager(store configstore.ConfigStore) *AgentRouteConfigManager

func (*AgentRouteConfigManager) Create

func (*AgentRouteConfigManager) Delete

func (m *AgentRouteConfigManager) Delete(ctx context.Context, routeID string) error

func (*AgentRouteConfigManager) Get

func (*AgentRouteConfigManager) InitStaticRoutes

func (m *AgentRouteConfigManager) InitStaticRoutes(routes []AgentRouteConfig)

func (*AgentRouteConfigManager) IsStatic

func (m *AgentRouteConfigManager) IsStatic(routeID string) bool

func (*AgentRouteConfigManager) List

func (*AgentRouteConfigManager) Match

Match resolves the most specific route config whose MatchPolicy accepts the request.

func (*AgentRouteConfigManager) Refresh added in v0.3.0

func (m *AgentRouteConfigManager) Refresh(ctx context.Context) error

func (*AgentRouteConfigManager) Reset

func (m *AgentRouteConfigManager) Reset()

func (*AgentRouteConfigManager) Update

func (m *AgentRouteConfigManager) Update(ctx context.Context, routeID string, route AgentRouteConfig) error

type RouteAuthPolicy

type RouteAuthPolicy struct {
	RequireVirtualKey bool `json:"require_virtual_key"`
}

type RouteKind

type RouteKind string
const (
	RouteKindLLM RouteKind = "llm"
	RouteKindMCP RouteKind = "mcp"
	RouteKindACP RouteKind = "acp"
)

type RouteListOptions

type RouteListOptions struct {
	Tag       string
	TagPrefix string
}

type RouteMatchPolicy

type RouteMatchPolicy struct {
	Host       string   `json:"host,omitempty"`
	PathPrefix string   `json:"path_prefix,omitempty"`
	Methods    []string `json:"methods,omitempty"`
}

RouteMatchPolicy contains transport-facing match fields for binding requests to a route.

type RouteProtocol

type RouteProtocol string
const (
	RouteProtocolOpenAI    RouteProtocol = "openai"
	RouteProtocolAnthropic RouteProtocol = "anthropic"
	RouteProtocolCC        RouteProtocol = "cc"
	RouteProtocolMCP       RouteProtocol = "mcp"
	RouteProtocolACP       RouteProtocol = "acp"
)

type RouteTargetPolicyKind

type RouteTargetPolicyKind string
const (
	RouteTargetPolicyKindDirectProvider RouteTargetPolicyKind = "direct-provider"
	RouteTargetPolicyKindLogicalModel   RouteTargetPolicyKind = "logical-model"
	RouteTargetPolicyKindMCPService     RouteTargetPolicyKind = "mcp-service"
	RouteTargetPolicyKindACPService     RouteTargetPolicyKind = "acp-service"
)

Jump to

Keyboard shortcuts

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