data

package
v0.260430.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTemplateCacheTTL = 12 * time.Hour // Default TTL for template cache
View Source
const DefaultTemplateHTTPTimeout = 30 * time.Second // Default HTTP timeout for fetching templates
View Source
const TemplateCacheFileName = "provider_template.json"
View Source
const TemplateGitHubURL = "https://raw.githubusercontent.com/tingly-dev/tingly-box/main/internal/data/providers.json"

Variables

This section is empty.

Functions

func ValidateTemplate

func ValidateTemplate(tmpl *ProviderTemplate) error

ValidateTemplate validates a provider template

Types

type CapabilitySchema

type CapabilitySchema struct {
	BuiltIn      bool         `json:"built_in"`
	ToolType     string       `json:"tool_type,omitempty"`
	ToolName     string       `json:"tool_name,omitempty"`
	DocURL       string       `json:"doc_url,omitempty"`
	ResultFormat ResultFormat `json:"result_format,omitempty"`
}

type ModelInfo added in v0.260430.1

type ModelInfo struct {
	ID        string `json:"id"`
	Context   int    `json:"context,omitempty"`
	MaxOutput int    `json:"max_output,omitempty"`
}

ModelInfo represents detailed information about a model

type ModelList

type ModelList struct {
	Provider    string   `yaml:"provider"`
	UUID        string   `yaml:"uuid"`
	APIBase     string   `yaml:"api_base"`
	Models      []string `yaml:"models"`
	LastUpdated string   `yaml:"last_updated"`
}

ModelList represents the models available for a specific provider (kept for backward compatibility)

type ModelListManager

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

ModelListManager manages models for different providers using SQLite database

func NewProviderModelManager

func NewProviderModelManager(configDir string) (*ModelListManager, error)

NewProviderModelManager creates a new provider model manager with database backing

func (*ModelListManager) GetAllProviders

func (mm *ModelListManager) GetAllProviders() []string

GetAllProviders returns all provider UUIDs that have models

func (*ModelListManager) GetModels

func (mm *ModelListManager) GetModels(uid string) []string

GetModels returns models for a provider by reading from database

func (*ModelListManager) GetProviderInfo

func (mm *ModelListManager) GetProviderInfo(uid string) (apiBase string, lastUpdated string, exists bool)

GetProviderInfo returns basic info about a provider by reading from database

func (*ModelListManager) HasModels

func (mm *ModelListManager) HasModels(providerUUID string) bool

HasModels checks if a provider has models in the database

func (*ModelListManager) RemoveProvider

func (mm *ModelListManager) RemoveProvider(providerUUID string) error

RemoveProvider removes a provider's models from the database

func (*ModelListManager) SaveModels

func (mm *ModelListManager) SaveModels(provider *typ.Provider, apiBase string, models []string) error

SaveModels saves models for a provider by UUID to the database

type NamingRules added in v0.260430.1

type NamingRules struct {
	KeyFormat      string `json:"key_format"`
	SlugRule1      string `json:"slug_rule_1,omitempty"`
	SlugRule2      string `json:"slug_rule_2,omitempty"`
	SlugRule3      string `json:"slug_rule_3,omitempty"`
	Variant        string `json:"variant,omitempty"`
	RequiredFields struct {
		CanonicalDomain string `json:"canonical_domain"`
		VendorFamily    string `json:"vendor_family"`
		Region          string `json:"region"`
		Plan            string `json:"plan"`
		ModelsSchema    string `json:"models_schema"`
	} `json:"required_fields"`
}

NamingRules defines the naming conventions for provider IDs

type ProviderTemplate

type ProviderTemplate struct {
	// Core identification
	ID      string `json:"id"`
	Name    string `json:"name"`
	Alias   string `json:"alias,omitempty"` // Display name with locale information
	Status  string `json:"status"`          // "active", "deprecated", etc.
	Valid   bool   `json:"valid"`
	Website string `json:"website"`

	// NEW: Structured metadata (Schema V2)
	CanonicalDomain string `json:"canonical_domain"` // API host (e.g., "api.anthropic.com")
	VendorFamily    string `json:"vendor_family"`    // Vendor aggregation key (e.g., "anthropic", "alibaba")
	Region          string `json:"region"`           // "cn" | "intl" | "global"
	Plan            string `json:"plan"`             // "standard" | "coding" | "oauth"

	Description string `json:"description"`

	// Documentation
	APIDoc     string `json:"api_doc"`
	ModelDoc   string `json:"model_doc"`
	PricingDoc string `json:"pricing_doc"`

	// API endpoints
	BaseURLOpenAI    string `json:"base_url_openai,omitempty"`
	BaseURLAnthropic string `json:"base_url_anthropic,omitempty"`

	// CHANGED: Models now include context/max_output directly (Schema V2)
	Models []ModelInfo `json:"models"`

	SupportsModelsEndpoint bool `json:"supports_models_endpoint"`

	// Authentication
	AuthType      string `json:"auth_type,omitempty"`      // "oauth", "key"
	OAuthProvider string `json:"oauth_provider,omitempty"` // OAuth provider type for oauth type providers

	// Capabilities
	WebSearchSchema string `json:"web_search_schema,omitempty"` // Reference to capability schema for web_search
	Icon            string `json:"icon,omitempty"`              // Icon identifier (e.g., "openai", "anthropic") for Lobe Icons

	// Capacity configuration for TacticCapacityBased load balancing
	// TotalCapacity is the total seat count for this provider (shared across all models)
	TotalCapacity *int `json:"total_capacity,omitempty"`
	// DefaultModelCapacity is the default seat count per model (template)
	// Each model inherits this unless overridden
	DefaultModelCapacity *int `json:"default_model_capacity,omitempty"`
	// ModelCapacities allows per-model capacity overrides
	ModelCapacities map[string]int `json:"model_capacities,omitempty"` // model name -> capacity
}

ProviderTemplate represents a predefined provider configuration template

type ProviderTemplateRegistry

type ProviderTemplateRegistry struct {
	SchemaVersion     int                          `json:"_schema_version"`
	NamingRules       *NamingRules                 `json:"_naming_rules,omitempty"`
	Providers         map[string]*ProviderTemplate `json:"providers"`
	CapabilitySchemas map[string]*CapabilitySchema `json:"capability_schemas,omitempty"`
	Version           string                       `json:"version"`
	LastUpdated       string                       `json:"last_updated"`
}

ProviderTemplateRegistry represents the provider template registry structure from GitHub

type ResultFormat

type ResultFormat struct {
	Type        string                 `json:"type"`
	Description string                 `json:"description,omitempty"`
	Structure   map[string]interface{} `json:"structure,omitempty"`
}

ResultFormat describes how to format tool results

type TemplateCacheData

type TemplateCacheData struct {
	Registry ProviderTemplateRegistry `json:"registry"`
	CachedAt time.Time                `json:"cached_at"`
	Version  string                   `json:"version"`
	ETag     string                   `json:"etag,omitempty"`
}

TemplateCacheData represents the cache file structure

type TemplateManager

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

TemplateManager manages provider templates with -tier fallback

func NewDefaultTemplateManager

func NewDefaultTemplateManager() *TemplateManager

func NewEmbeddedOnlyTemplateManager

func NewEmbeddedOnlyTemplateManager() *TemplateManager

NewEmbeddedOnlyTemplateManager creates a template manager that only uses embedded templates This is useful for development, testing, or offline scenarios

func NewTemplateManager

func NewTemplateManager(githubURL string) *TemplateManager

NewTemplateManager creates a new template manager with default preference. If githubURL is empty, only embedded templates will be used (no GitHub sync).

func NewTemplateManagerWithPreference

func NewTemplateManagerWithPreference(githubURL string, preference TemplateSourcePreference) *TemplateManager

NewTemplateManagerWithPreference creates a new template manager with specified source preference. If githubURL is empty, only embedded templates will be used (no GitHub sync).

func (*TemplateManager) FetchTemplates added in v0.260409.1540

func (tm *TemplateManager) FetchTemplates(ctx context.Context) (*ProviderTemplateRegistry, error)

FetchTemplates fetches templates from URL (http://, https://, or file://)

func (*TemplateManager) GetAllTemplates

func (tm *TemplateManager) GetAllTemplates() map[string]*ProviderTemplate

GetAllTemplates returns all templates

func (*TemplateManager) GetMaxTokensForModel

func (tm *TemplateManager) GetMaxTokensForModel(provider, model string) int

GetMaxTokensForModel returns the maximum allowed tokens for a specific model using the provider templates. If templates are not available, falls back to the global default. It checks in order: 1. Exact match in Models array (ModelInfo.MaxOutput) 2. ModelCapacities override (for capacity-based limits) 3. Global default

func (*TemplateManager) GetMaxTokensForModelByProvider

func (tm *TemplateManager) GetMaxTokensForModelByProvider(provider *typ.Provider, model string) int

GetMaxTokensForModelByProvider returns the maximum allowed tokens for a specific model using the provider templates matched by APIBase or OAuthProvider. This is the preferred method as it correctly matches templates regardless of user-defined provider name.

func (*TemplateManager) GetModelsForProvider

func (tm *TemplateManager) GetModelsForProvider(provider *typ.Provider) ([]string, TemplateSource, error)

GetModelsForProvider returns models for a provider using template-only hierarchy: 1. GitHub/embedded templates with models list Note: API-based model fetching is now handled by the client layer (client.ModelLister) This method only returns static models from templates

func (*TemplateManager) GetTemplate

func (tm *TemplateManager) GetTemplate(id string) (*ProviderTemplate, error)

GetTemplate returns a provider template by ID

func (*TemplateManager) GetVersion

func (tm *TemplateManager) GetVersion() string

GetVersion returns the current template version

func (*TemplateManager) GetWebSearchSchemaForProvider

func (tm *TemplateManager) GetWebSearchSchemaForProvider(provider *typ.Provider) *CapabilitySchema

GetWebSearchSchemaForProvider returns the web search capability schema for a provider Returns nil if the provider doesn't have web_search_schema defined or the schema doesn't exist

func (*TemplateManager) Initialize

func (tm *TemplateManager) Initialize(ctx context.Context) error

Initialize loads templates according to the source preference: - PreferenceDefault: Cache -> GitHub -> Embedded - PreferenceEmbedded: Embedded only (no network requests) - PreferenceEmbeddedFirst: Embedded -> Cache -> GitHub

func (*TemplateManager) ProviderHasBuiltInWebSearch

func (tm *TemplateManager) ProviderHasBuiltInWebSearch(provider *typ.Provider) bool

ProviderHasBuiltInWebSearch checks if a provider has built-in web_search capability Returns true if the provider has a web_search_schema with BuiltIn=true

type TemplateSource

type TemplateSource int

TemplateSource tracks where templates were loaded from

const (
	// TemplateSourceGitHub - From GitHub templates
	TemplateSourceGitHub TemplateSource = iota
	// TemplateSourceLocal - From local embedded templates
	TemplateSourceLocal
)

type TemplateSourcePreference

type TemplateSourcePreference int

TemplateSourcePreference defines the priority order for loading templates

const (
	// PreferenceDefault: Cache -> GitHub -> Embedded
	PreferenceDefault TemplateSourcePreference = iota
	// PreferenceEmbedded: Embedded only (no network requests)
	PreferenceEmbedded
	// PreferenceEmbeddedFirst: Embedded -> Cache -> GitHub
	PreferenceEmbeddedFirst
)

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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