provider

package
v1.261119.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MPL-2.0 Imports: 23 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 provider handles CRUD and model-management HTTP endpoints for AI provider configurations. Business logic (token masking, dual-mode endpoint resolution, model cache fallback) lives here; routing metadata is in routes.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateProviderRequest

type CreateProviderRequest 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" description:"API style" example:"openai"`
	APIBaseOpenAI    string `` /* 150-byte string literal not displayed */
	APIBaseAnthropic string `` /* 153-byte string literal not displayed */
	Token            string `json:"token" description:"API token" example:"sk-..."`
	NoKeyRequired    bool   `json:"no_key_required" description:"Whether provider requires no API key" example:"false"`
	Enabled          bool   `json:"enabled" description:"Whether provider is enabled" example:"true"`
	ProxyURL         string `` /* 153-byte string literal not displayed */
	AuthType         string `` /* 136-byte string literal not displayed */
	// Credential carries multi-field cloud credentials for auth types
	// aws_sigv4 (AWS Bedrock), azure_key (Azure OpenAI), and gcp_sa (GCP Vertex).
	// Ignored for api_key/oauth/vmodel. See ai.CredentialSchema for the field keys.
	Credential map[string]string `json:"credential,omitempty" description:"Cloud credential fields (aws_sigv4/azure_key/gcp_sa)"`
}

CreateProviderRequest represents the request to add a new provider.

type CreateProviderResponse

type CreateProviderResponse struct {
	Success bool        `json:"success" example:"true"`
	Message string      `json:"message" example:"Provider added successfully"`
	Data    interface{} `json:"data"`
}

CreateProviderResponse represents the response for adding a provider.

type DeleteProviderResponse

type DeleteProviderResponse struct {
	Success bool   `json:"success" example:"true"`
	Message string `json:"message" example:"Provider deleted successfully"`
}

DeleteProviderResponse represents the response for deleting a provider.

type ExportProviderResponse

type ExportProviderResponse struct {
	Success bool   `json:"success" example:"true"`
	Message string `json:"message" example:"Provider exported successfully"`
	Data    struct {
		Format string `json:"format" example:"base64"`
		Data   string `json:"data" description:"Base64 or JSONL encoded provider export data" example:"TGB64:1.0:..."`
	} `json:"data"`
}

ExportProviderResponse represents the response for exporting a single provider.

type FetchProviderModelsResponse

type FetchProviderModelsResponse struct {
	Success bool        `json:"success" example:"true"`
	Message string      `json:"message" example:"Successfully fetched 150 models for provider openai"`
	Data    interface{} `json:"data"`
}

FetchProviderModelsResponse represents the response for fetching provider models.

type Handler

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

Handler handles provider HTTP requests.

func NewHandler

func NewHandler(cfg *config.Config, qm providerquota.Manager) *Handler

NewHandler creates a Handler. quotaManager may be nil when quota support is not configured.

func (*Handler) CreateProvider

func (h *Handler) CreateProvider(c *gin.Context)

CreateProvider adds a new provider.

func (*Handler) DeleteProvider

func (h *Handler) DeleteProvider(c *gin.Context)

DeleteProvider removes a provider by UUID.

func (*Handler) ExportProvider

func (h *Handler) ExportProvider(c *gin.Context)

ExportProvider exports a single provider (identified by the required "uuid" query parameter) as base64/JSONL encoded data (see internal/dataio). Format defaults to base64 and is selected via the "format" query parameter ("base64" or "jsonl").

func (*Handler) GetProvider

func (h *Handler) GetProvider(c *gin.Context)

GetProvider returns details for a specific provider by UUID.

func (*Handler) GetProviderModelsByUUID

func (h *Handler) GetProviderModelsByUUID(c *gin.Context)

GetProviderModelsByUUID returns the model list for a provider, falling back through DB cache → VModel static list → provider API → template. The template is a pure last-resort fallback (used only when every earlier source is empty); it is never merged into a non-empty list, since the embedded snapshot can list models the upstream has since retired.

func (*Handler) GetProviders

func (h *Handler) GetProviders(c *gin.Context)

GetProviders lists all configured providers with masked credentials.

func (*Handler) ImportProviders

func (h *Handler) ImportProviders(c *gin.Context)

ImportProviders imports providers from base64/JSONL encoded export data. Registered at /provider-import (see routes.go); only providers are imported — dataio export/import no longer carries rule data.

func (*Handler) RegisterRoutes added in v1.261002.1

func (h *Handler) RegisterRoutes(rt *module.Routes)

func (*Handler) ToggleProvider

func (h *Handler) ToggleProvider(c *gin.Context)

ToggleProvider enables or disables a provider.

func (*Handler) UpdateProvider

func (h *Handler) UpdateProvider(c *gin.Context)

UpdateProvider updates an existing provider by UUID.

func (*Handler) UpdateProviderModelsByUUID

func (h *Handler) UpdateProviderModelsByUUID(c *gin.Context)

UpdateProviderModelsByUUID force-refreshes and returns the model list for the given provider (the manual "refresh models" action). It re-queries upstream, falling back to the embedded template just like the read path — so providers whose /models endpoint is unsupported (e.g. Codex) still return their catalog instead of an empty list.

type ImportProvidersRequest

type ImportProvidersRequest struct {
	Data string `json:"data" binding:"required" description:"Base64 encoded provider export data" example:"TGB64:1.0:..."`
}

ImportProvidersRequest represents a request to import providers from a base64/JSONL encoded export bundle (see internal/dataio). Every imported provider is always created with a freshly minted UUID.

type ImportProvidersResponse

type ImportProvidersResponse struct {
	Success bool   `json:"success" example:"true"`
	Message string `json:"message" example:"Providers imported successfully"`
	Data    struct {
		ProvidersCreated int                  `json:"providers_created" example:"1"`
		Providers        []ProviderImportInfo `json:"providers,omitempty"`
	} `json:"data"`
}

ImportProvidersResponse represents the response for importing providers.

type ModelCacheSource

type ModelCacheSource string

ModelCacheSource identifies where the model list was sourced from.

const (
	ModelCacheSourceDB       ModelCacheSource = "db"
	ModelCacheSourceAPI      ModelCacheSource = "api"
	ModelCacheSourceTemplate ModelCacheSource = "template"
	ModelCacheSourceVModel   ModelCacheSource = "vmodel"
)

type ProviderImportInfo

type ProviderImportInfo struct {
	UUID   string `json:"uuid" example:"123e4567-e89b-12d3-a456-426614174000"`
	Name   string `json:"name" example:"openai"`
	Action string `json:"action" example:"created"`
	// Renamed is true when Name was auto-suffixed because it collided with
	// an already-existing provider name.
	Renamed bool `json:"renamed" example:"false"`
}

ProviderImportInfo contains basic information about an imported provider.

type ProviderModelInfo

type ProviderModelInfo struct {
	Models      []string             `json:"models" example:"gpt-3.5-turbo,gpt-4"`
	StarModels  []string             `json:"star_models" example:"gpt-4"`
	CustomModel []string             `json:"custom_model" example:"custom-gpt-model"`
	APIBase     string               `json:"api_base" example:"https://api.openai.com/v1"`
	LastUpdated string               `json:"last_updated,omitempty" example:"2024-01-15 10:30:00"`
	Source      ModelCacheSource     `json:"source,omitempty" example:"db"`
	ExpiresAt   time.Time            `json:"expiresAt,omitempty" example:"2024-01-15T11:30:00Z"`
	Quota       *quota.ProviderUsage `json:"quota,omitempty"`
}

ProviderModelInfo represents model information for a specific provider.

type ProviderModelsResponse

type ProviderModelsResponse struct {
	Success bool              `json:"success" example:"true"`
	Message string            `json:"message" example:"Provider models successfully"`
	Data    ProviderModelInfo `json:"data"`
}

ProviderModelsResponse represents the response for getting provider models.

type ProviderResponse

type ProviderResponse struct {
	UUID             string            `json:"uuid" example:"0123456789ABCDEF"`
	Name             string            `json:"name" example:"openai"`
	APIBase          string            `json:"api_base" example:"https://api.openai.com/v1"`
	APIStyle         string            `json:"api_style" example:"openai"`
	APIBaseOpenAI    string            `json:"api_base_openai,omitempty" example:"https://api.example.com/v1"`
	APIBaseAnthropic string            `json:"api_base_anthropic,omitempty" example:"https://api.example.com"`
	Token            string            `json:"token" example:"sk-***...***"` // Only populated for api_key auth type
	NoKeyRequired    bool              `json:"no_key_required" example:"false"`
	Enabled          bool              `json:"enabled" example:"true"`
	ProxyURL         string            `json:"proxy_url,omitempty" example:"http://localhost:7890"`
	AuthType         string            `json:"auth_type,omitempty" example:"api_key"` // api_key, oauth, vmodel, aws_sigv4, azure_key, gcp_sa
	OAuthDetail      *typ.OAuthDetail  `json:"oauth_detail,omitempty"`                // OAuth credentials (only for oauth auth type)
	VModelDetail     *typ.VModelDetail `json:"vmodel_detail,omitempty"`               // Virtual-model config (only for vmodel auth type)
	Credential       map[string]string `json:"credential,omitempty"`                  // Multi-field cloud credentials (only for aws_sigv4/azure_key/gcp_sa)
	Source           string            `json:"source,omitempty" example:"user"`       // "user" (default) or "builtin"
	Limits           *ai.Limits        `json:"limits,omitempty"`                      // Account concurrency/usage limits (see .design/routing-limits.md)
}

ProviderResponse represents a provider configuration with masked token.

type ProvidersResponse

type ProvidersResponse struct {
	Success bool               `json:"success" example:"true"`
	Data    []ProviderResponse `json:"data"`
}

ProvidersResponse represents the response for listing providers.

type ToggleProviderResponse

type ToggleProviderResponse struct {
	Success bool   `json:"success" example:"true"`
	Message string `json:"message" example:"Provider openai enabled successfully"`
	Data    struct {
		Enabled bool `json:"enabled" example:"true"`
	} `json:"data"`
}

ToggleProviderResponse represents the response for toggling a provider.

type UpdateProviderRequest

type UpdateProviderRequest struct {
	Name             *string `json:"name,omitempty" description:"New provider name"`
	APIBase          *string `json:"api_base,omitempty" description:"New API base URL"`
	APIStyle         *string `json:"api_style,omitempty" description:"New API style"`
	APIBaseOpenAI    *string `json:"api_base_openai,omitempty" description:"New dual-mode OpenAI-compatible base URL (empty string clears it)"`
	APIBaseAnthropic *string `json:"api_base_anthropic,omitempty" description:"New dual-mode Anthropic-compatible base URL (empty string clears it)"`
	Token            *string `json:"token,omitempty" description:"New API token"`
	NoKeyRequired    *bool   `json:"no_key_required,omitempty" description:"Whether provider requires no API key"`
	Enabled          *bool   `json:"enabled,omitempty" description:"New enabled status"`
	ProxyURL         *string `json:"proxy_url,omitempty" description:"HTTP or SOCKS proxy URL"`
	// Credential replaces the full multi-field credential bundle for cloud auth
	// types (aws_sigv4/azure_key/gcp_sa). Omit (null) to leave it unchanged; the
	// edit UI resends the complete map since the read path returns it in full.
	Credential map[string]string `json:"credential,omitempty" description:"Replacement cloud credential fields (aws_sigv4/azure_key/gcp_sa)"`
	// Limits replaces the account's concurrency/usage limits. Omit (null) to
	// leave them unchanged; an empty object clears them.
	Limits *ai.Limits `json:"limits,omitempty" description:"Account concurrency/usage limits (empty object clears)"`
}

UpdateProviderRequest represents the request to update a provider.

type UpdateProviderResponse

type UpdateProviderResponse struct {
	Success bool             `json:"success" example:"true"`
	Message string           `json:"message" example:"Provider updated successfully"`
	Data    ProviderResponse `json:"data"`
}

UpdateProviderResponse represents the response for updating a provider.

Jump to

Keyboard shortcuts

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