Documentation
¶
Index ¶
- Constants
- func ClearGatewayConfigCache()
- func MergeOAuthAccountHeader(headers map[string]string, provider *schema.Provider, authType string) map[string]string
- type BillingPolicy
- type ConfigRedisSync
- func (s *ConfigRedisSync) DeleteAlias(ctx context.Context, alias string) error
- func (s *ConfigRedisSync) GetModelCodesByProvider(ctx context.Context, providerID string) ([]string, error)
- func (s *ConfigRedisSync) SyncAlias(ctx context.Context, alias string, modelCode string) error
- func (s *ConfigRedisSync) SyncAliasesByModelId(ctx context.Context, modelId string, modelCode string, enabled int) error
- func (s *ConfigRedisSync) SyncAllToRedis(ctx context.Context) error
- func (s *ConfigRedisSync) SyncModelByCode(ctx context.Context, modelCode string) error
- func (s *ConfigRedisSync) SyncModelCodeChange(ctx context.Context, modelID, oldModelCode, newModelCode string) error
- func (s *ConfigRedisSync) SyncModelDisable(ctx context.Context, modelID, modelCode string, tenantCodes ...string) error
- func (s *ConfigRedisSync) SyncModelEnable(ctx context.Context, modelID, modelCode string) error
- func (s *ConfigRedisSync) SyncProviderID(ctx context.Context, providerID string) error
- type DataPermission
- func (a *DataPermission) Create(ctx context.Context, formItem *schema.DataPermissionForm) (*schema.DataPermission, error)
- func (a *DataPermission) CreateByOwner(ctx context.Context, dataType, dataId, tenant string) error
- func (a *DataPermission) Delete(ctx context.Context, id string) error
- func (a *DataPermission) DeleteByTypeAndDataId(ctx context.Context, dataType, dataId string) error
- func (a *DataPermission) Get(ctx context.Context, id string) (*schema.DataPermission, error)
- func (a *DataPermission) HasReadPermission(ctx context.Context, dataType, dataId string) (bool, error)
- func (a *DataPermission) Query(ctx context.Context, params schema.DataPermissionQueryParam) (*schema.DataPermissionQueryResult, error)
- func (a *DataPermission) Update(ctx context.Context, id string, formItem *schema.DataPermissionForm) error
- type Endpoint
- func (e *Endpoint) Create(ctx context.Context, formItem *schema.EndpointForm) (*schema.Endpoint, error)
- func (e *Endpoint) Delete(ctx context.Context, id string) error
- func (e *Endpoint) Get(ctx context.Context, id string) (*schema.Endpoint, error)
- func (e *Endpoint) Query(ctx context.Context, params schema.EndpointQueryParam) (*schema.EndpointQueryResult, error)
- func (e *Endpoint) QueryEndpointsByModelCode(ctx context.Context, modelCode string) (schema.Endpoints, error)
- func (e *Endpoint) QueryEndpointsByModelID(ctx context.Context, modelID string) (schema.Endpoints, error)
- func (e *Endpoint) QueryEndpointsByProviderID(ctx context.Context, providerID string) (schema.Endpoints, error)
- func (e *Endpoint) SelectEndpoint(ctx context.Context, modelCode string) (*schema.Endpoint, error)
- func (e *Endpoint) Test(ctx context.Context, formItem *schema.EndpointForm) (*schema.EndpointTestResult, error)
- func (e *Endpoint) TestByID(ctx context.Context, id string) (*schema.EndpointTestResult, error)
- func (e *Endpoint) ToggleEnabled(ctx context.Context, id string, formItem *schema.EndpointEnabledForm) error
- func (e *Endpoint) Update(ctx context.Context, id string, formItem *schema.EndpointForm) error
- type EndpointConfig
- type GatewayConfig
- type GatewaySync
- func (s *GatewaySync) GetGatewayApiKeys(ctx context.Context, apiKey string) ([]HTTPApiKeyItem, error)
- func (s *GatewaySync) GetGatewayConfig(ctx context.Context, modelCode string) (*GatewayConfig, error)
- func (s *GatewaySync) GetGatewayPolicies(ctx context.Context, modelCode string) ([]HTTPPolicyItem, error)
- type HTTPApiKeyItem
- type HTTPPolicyItem
- type HTTPPolicyValue
- type Model
- func (m *Model) Create(ctx context.Context, formItem *schema.ModelForm) (*schema.ModelCreateResult, error)
- func (m *Model) Delete(ctx context.Context, id string) error
- func (m *Model) Get(ctx context.Context, id string) (*schema.Model, error)
- func (m *Model) Query(ctx context.Context, params schema.ModelQueryParam) (*schema.ModelQueryResult, error)
- func (m *Model) Sync(ctx context.Context, id string) error
- func (m *Model) ToggleEnabled(ctx context.Context, id string, formItem *schema.ModelEnabledForm) error
- func (m *Model) Update(ctx context.Context, id string, formItem *schema.ModelForm) error
- type ModelAlias
- func (m *ModelAlias) Create(ctx context.Context, formItem *schema.ModelAliasForm) (*schema.ModelAlias, error)
- func (m *ModelAlias) Delete(ctx context.Context, id string) error
- func (m *ModelAlias) Get(ctx context.Context, id string) (*schema.ModelAlias, error)
- func (m *ModelAlias) Query(ctx context.Context, params schema.ModelAliasQueryParam) (*schema.ModelAliasQueryResult, error)
- func (m *ModelAlias) Update(ctx context.Context, id string, formItem *schema.ModelAliasForm) error
- type ModelCatalog
- func (m *ModelCatalog) Create(ctx context.Context, formItem *schema.ModelCatalogForm) (*schema.ModelCatalog, error)
- func (m *ModelCatalog) Delete(ctx context.Context, modelID string) error
- func (m *ModelCatalog) Get(ctx context.Context, modelID string) (*schema.ModelCatalog, error)
- func (m *ModelCatalog) GetBySlug(ctx context.Context, slug string) (*schema.ModelCatalog, error)
- func (m *ModelCatalog) Publish(ctx context.Context, modelID string, formItem *schema.ModelCatalogPublishForm) error
- func (m *ModelCatalog) Query(ctx context.Context, params schema.ModelCatalogQueryParam) (*schema.ModelCatalogQueryResult, error)
- func (m *ModelCatalog) QueryPublic(ctx context.Context, limit int) (schema.ModelCatalogs, error)
- func (m *ModelCatalog) Update(ctx context.Context, modelID string, formItem *schema.ModelCatalogForm) error
- type ModelCatalogI18n
- func (m *ModelCatalogI18n) BatchUpsert(ctx context.Context, formItem *schema.ModelCatalogI18nBatchForm) error
- func (m *ModelCatalogI18n) Create(ctx context.Context, formItem *schema.ModelCatalogI18nForm) (*schema.ModelCatalogI18n, error)
- func (m *ModelCatalogI18n) Delete(ctx context.Context, modelID, locale string) error
- func (m *ModelCatalogI18n) Get(ctx context.Context, modelID, locale string) (*schema.ModelCatalogI18n, error)
- func (m *ModelCatalogI18n) Query(ctx context.Context, params schema.ModelCatalogI18nQueryParam) (*schema.ModelCatalogI18nQueryResult, error)
- func (m *ModelCatalogI18n) QueryByModelID(ctx context.Context, modelID string) (schema.ModelCatalogI18ns, error)
- func (m *ModelCatalogI18n) Update(ctx context.Context, modelID, locale string, ...) error
- type ModelConfig
- type ModelPriceVersion
- func (m *ModelPriceVersion) Create(ctx context.Context, formItem *schema.ModelPriceVersionForm) (*schema.ModelPriceVersion, error)
- func (m *ModelPriceVersion) Deactivate(ctx context.Context, id string) error
- func (m *ModelPriceVersion) Delete(ctx context.Context, id string) error
- func (m *ModelPriceVersion) Get(ctx context.Context, id string) (*schema.ModelPriceVersion, error)
- func (m *ModelPriceVersion) GetCurrentPrice(ctx context.Context, modelID, currency string) (*schema.ModelPriceVersion, error)
- func (m *ModelPriceVersion) Query(ctx context.Context, params schema.ModelPriceVersionQueryParam) (*schema.ModelPriceVersionQueryResult, error)
- func (m *ModelPriceVersion) QueryByModelID(ctx context.Context, modelID string) (schema.ModelPriceVersions, error)
- func (m *ModelPriceVersion) Update(ctx context.Context, id string, formItem *schema.ModelPriceVersionForm) error
- type OAuthStartResult
- type OAuthTokenResult
- type Provider
- func (p *Provider) CompleteOAuthFlow(ctx context.Context, formItem *schema.OAuthCompleteForm) (*OAuthTokenResult, error)
- func (p *Provider) Create(ctx context.Context, formItem *schema.ProviderForm) (*schema.Provider, error)
- func (p *Provider) Delete(ctx context.Context, id string) error
- func (p *Provider) FetchModels(ctx context.Context, providerID string, formItem *schema.FetchModelsForm) (*schema.FetchModelsResult, error)
- func (p *Provider) Get(ctx context.Context, id string) (*schema.Provider, error)
- func (p *Provider) GetQuota(ctx context.Context, providerID string) (*schema.ProviderQuotaResult, error)
- func (p *Provider) PollOAuthStatus(ctx context.Context, state string) (*OAuthTokenResult, error)
- func (p *Provider) Query(ctx context.Context, params schema.ProviderQueryParam) (*schema.ProviderQueryResult, error)
- func (p *Provider) StartOAuthFlow(ctx context.Context, providerName string) (*OAuthStartResult, error)
- func (p *Provider) Update(ctx context.Context, id string, formItem *schema.ProviderForm) error
- type ProviderConfig
- type ResolvedEndpoint
- type TokenRefresher
Constants ¶
const ( RedisKeyConfigModelVersions = "aigw:config:model_versions" RedisKeyConfigAliasPrefix = "aigw:config:alias:" RedisKeyConfigModelAliasesPrefix = "aigw:config:model_aliases:" )
Variables ¶
This section is empty.
Functions ¶
func MergeOAuthAccountHeader ¶ added in v0.3.0
func MergeOAuthAccountHeader(headers map[string]string, provider *schema.Provider, authType string) map[string]string
MergeOAuthAccountHeader injects Chatgpt-Account-Id for oauth_token endpoints when the provider OAuth credential carries an account_id. Existing header values win.
Types ¶
type BillingPolicy ¶
type ConfigRedisSync ¶
type ConfigRedisSync struct {
RedisClient *redis.Client
EndpointDAL *dal.Endpoint
ModelDAL *dal.Model
ModelAliasDAL *dal.ModelAlias
}
func (*ConfigRedisSync) DeleteAlias ¶
func (s *ConfigRedisSync) DeleteAlias(ctx context.Context, alias string) error
DeleteAlias removes a single alias mapping from Redis and updates the reverse index.
func (*ConfigRedisSync) GetModelCodesByProvider ¶
func (s *ConfigRedisSync) GetModelCodesByProvider(ctx context.Context, providerID string) ([]string, error)
GetModelCodesByProvider queries model codes referencing the given provider ID.
func (*ConfigRedisSync) SyncAlias ¶
SyncAlias synchronizes a single alias mapping to Redis: aigw:config:alias:{alias} → modelCode. It also maintains the reverse index: aigw:config:model_aliases:{modelCode} → Set[aliases].
func (*ConfigRedisSync) SyncAliasesByModelId ¶
func (s *ConfigRedisSync) SyncAliasesByModelId(ctx context.Context, modelId string, modelCode string, enabled int) error
SyncAliasesByModelId re-syncs all aliases for a given model ID to Redis. If the model is disabled (enabled=0), it deletes all alias keys instead.
func (*ConfigRedisSync) SyncAllToRedis ¶
func (s *ConfigRedisSync) SyncAllToRedis(ctx context.Context) error
SyncAllToRedis synchronizes all active endpoints, model versions, and tenant bindings to Redis.
func (*ConfigRedisSync) SyncModelByCode ¶
func (s *ConfigRedisSync) SyncModelByCode(ctx context.Context, modelCode string) error
func (*ConfigRedisSync) SyncModelCodeChange ¶
func (s *ConfigRedisSync) SyncModelCodeChange(ctx context.Context, modelID, oldModelCode, newModelCode string) error
SyncModelCodeChange handles updating tenant-related cache keys in Redis when a model's code changes.
func (*ConfigRedisSync) SyncModelDisable ¶
func (s *ConfigRedisSync) SyncModelDisable(ctx context.Context, modelID, modelCode string, tenantCodes ...string) error
SyncModelDisable handles removing model code from associated tenants' allowed model sets and deleting provider whitelist caches.
func (*ConfigRedisSync) SyncModelEnable ¶
func (s *ConfigRedisSync) SyncModelEnable(ctx context.Context, modelID, modelCode string) error
SyncModelEnable handles adding model code back to associated tenants' allowed model sets and rebuilding endpoint whitelist caches.
func (*ConfigRedisSync) SyncProviderID ¶
func (s *ConfigRedisSync) SyncProviderID(ctx context.Context, providerID string) error
SyncProviderID synchronizes all models affected by the provider ID.
type DataPermission ¶
type DataPermission struct {
Trans *util.Trans
DataPermissionDAL *dal.DataPermission
}
Data permission management
func (*DataPermission) Create ¶
func (a *DataPermission) Create(ctx context.Context, formItem *schema.DataPermissionForm) (*schema.DataPermission, error)
Create a new data permission in the data access object.
func (*DataPermission) CreateByOwner ¶
func (a *DataPermission) CreateByOwner(ctx context.Context, dataType, dataId, tenant string) error
CreateByOwner creates a data permission record for the resource owner.
func (*DataPermission) Delete ¶
func (a *DataPermission) Delete(ctx context.Context, id string) error
Delete the specified data permission from the data access object.
func (*DataPermission) DeleteByTypeAndDataId ¶
func (a *DataPermission) DeleteByTypeAndDataId(ctx context.Context, dataType, dataId string) error
DeleteByTypeAndDataId deletes data permissions by type and data ID.
func (*DataPermission) Get ¶
func (a *DataPermission) Get(ctx context.Context, id string) (*schema.DataPermission, error)
Get the specified data permission from the data access object.
func (*DataPermission) HasReadPermission ¶
func (a *DataPermission) HasReadPermission(ctx context.Context, dataType, dataId string) (bool, error)
HasReadPermission checks if the current user has read permission for a specific data item.
func (*DataPermission) Query ¶
func (a *DataPermission) Query(ctx context.Context, params schema.DataPermissionQueryParam) (*schema.DataPermissionQueryResult, error)
Query data permissions from the data access object based on the provided parameters and options.
func (*DataPermission) Update ¶
func (a *DataPermission) Update(ctx context.Context, id string, formItem *schema.DataPermissionForm) error
Update the specified data permission in the data access object.
type Endpoint ¶
type Endpoint struct {
Trans *util.Trans
EndpointDAL *dal.Endpoint
DataPermissionBIZ *DataPermission
ModelDAL *dal.Model
ProviderDAL *dal.Provider
ConfigRedisSync *ConfigRedisSync
RedisClient *redis.Client
AuditLogBIZ *opsBiz.AuditLog
}
Endpoint business logic layer
func (*Endpoint) Create ¶
func (e *Endpoint) Create(ctx context.Context, formItem *schema.EndpointForm) (*schema.Endpoint, error)
Create a new endpoint.
func (*Endpoint) Query ¶
func (e *Endpoint) Query(ctx context.Context, params schema.EndpointQueryParam) (*schema.EndpointQueryResult, error)
Query endpoints.
func (*Endpoint) QueryEndpointsByModelCode ¶
func (e *Endpoint) QueryEndpointsByModelCode(ctx context.Context, modelCode string) (schema.Endpoints, error)
QueryEndpointsByModelCode queries enabled endpoints by model code (for routing). Joins endpoint -> model -> provider and filters all three to enabled + not deleted.
func (*Endpoint) QueryEndpointsByModelID ¶
func (e *Endpoint) QueryEndpointsByModelID(ctx context.Context, modelID string) (schema.Endpoints, error)
QueryEndpointsByModelID queries endpoints associated with a given Model ID (only enabled endpoints).
func (*Endpoint) QueryEndpointsByProviderID ¶
func (e *Endpoint) QueryEndpointsByProviderID(ctx context.Context, providerID string) (schema.Endpoints, error)
QueryEndpointsByProviderID queries endpoints associated with a given Provider ID (only enabled endpoints).
func (*Endpoint) SelectEndpoint ¶
SelectEndpoint selects the best enabled endpoint for a given model code, applying priority-based failover and weighted load balancing within the same priority group.
func (*Endpoint) Test ¶
func (e *Endpoint) Test(ctx context.Context, formItem *schema.EndpointForm) (*schema.EndpointTestResult, error)
Test 临时测试草稿端点配置
func (*Endpoint) ToggleEnabled ¶
func (e *Endpoint) ToggleEnabled(ctx context.Context, id string, formItem *schema.EndpointEnabledForm) error
ToggleEnabled updates only the enabled status of an endpoint and re-syncs the routing config to Redis.
type EndpointConfig ¶
type EndpointConfig struct {
ID string `json:"id"`
Code string `json:"code"`
Provider string `json:"provider"`
URL string `json:"url"`
RealModel string `json:"real_model"`
APIKey string `json:"api_key,omitempty"`
AuthType string `json:"auth_type,omitempty"`
Protocol string `json:"protocol,omitempty"`
Timeout string `json:"timeout,omitempty"`
Priority int `json:"priority"`
Weight int `json:"weight"`
Headers map[string]string `json:"headers,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type GatewayConfig ¶
type GatewayConfig struct {
Models map[string]ModelConfig `json:"models"`
Providers map[string]ProviderConfig `json:"providers"`
Fallbacks map[string][]string `json:"fallbacks"`
Aliases map[string]string `json:"aliases,omitempty"`
}
type GatewaySync ¶
type GatewaySync struct {
DB *gorm.DB
EndpointDAL *dal.Endpoint
ModelDAL *dal.Model
ModelAliasDAL *dal.ModelAlias
}
func (*GatewaySync) GetGatewayApiKeys ¶
func (s *GatewaySync) GetGatewayApiKeys(ctx context.Context, apiKey string) ([]HTTPApiKeyItem, error)
GetGatewayApiKeys 获取 API 密钥配置(支持单 key 查询)
func (*GatewaySync) GetGatewayConfig ¶
func (s *GatewaySync) GetGatewayConfig(ctx context.Context, modelCode string) (*GatewayConfig, error)
GetGatewayConfig 获取大模型、端点及 Provider 路由配置
func (*GatewaySync) GetGatewayPolicies ¶
func (s *GatewaySync) GetGatewayPolicies(ctx context.Context, modelCode string) ([]HTTPPolicyItem, error)
GetGatewayPolicies 获取治理策略及计费策略
type HTTPApiKeyItem ¶
type HTTPPolicyItem ¶
type HTTPPolicyItem struct {
Scope string `json:"scope"` // "user:userID", "tenant:tenantCode", "model:modelCode", "global"
Model string `json:"model"` // model_code or "*"
Value *HTTPPolicyValue `json:"value"`
}
type HTTPPolicyValue ¶
type HTTPPolicyValue struct {
LoadBalancePolicy *policySchema.PolicyLoadbalanceForm `json:"load_balance_policy,omitempty"`
InvocationPolicy *policySchema.PolicyInvocationForm `json:"invocation_policy,omitempty"`
LimitPolicies []*policySchema.PolicyLimitForm `json:"limit_policies,omitempty"`
RoutePolicies []*policySchema.PolicyRouteForm `json:"route_policies,omitempty"`
CircuitBreakPolicies []*policySchema.PolicyCircuitBreakForm `json:"circuit_break_policies,omitempty"`
TaggingPolicies []*policySchema.PolicyTaggingForm `json:"tagging_policies,omitempty"`
Billing *BillingPolicy `json:"billing,omitempty"`
}
type Model ¶
type Model struct {
Trans *util.Trans
ModelDAL *dal.Model
DataPermissionBIZ *DataPermission
ConfigRedisSync *ConfigRedisSync
PolicyRedisSync *policyBiz.PolicyRedisSync
PolicyInvocationBIZ *policyBiz.PolicyInvocation
PolicyCircuitBreakBIZ *policyBiz.PolicyCircuitBreak
RedisClient *redis.Client
AuditLogBIZ *opsBiz.AuditLog
}
Model business logic layer
func (*Model) Create ¶
func (m *Model) Create(ctx context.Context, formItem *schema.ModelForm) (*schema.ModelCreateResult, error)
Create a new model.
func (*Model) Query ¶
func (m *Model) Query(ctx context.Context, params schema.ModelQueryParam) (*schema.ModelQueryResult, error)
Query models.
func (*Model) ToggleEnabled ¶
func (m *Model) ToggleEnabled(ctx context.Context, id string, formItem *schema.ModelEnabledForm) error
ToggleEnabled updates only the enabled status of a model and re-syncs Redis. It replicates the enabled-change side effects of Update: SyncModelByCode plus SyncModelEnable/SyncModelDisable (which handle tenant binding relationships). model_code is not changed by a toggle, so no SyncModelCodeChange is needed.
type ModelAlias ¶
type ModelAlias struct {
Trans *util.Trans
ModelAliasDAL *dal.ModelAlias
ModelDAL *dal.Model
ConfigRedisSync *ConfigRedisSync
}
ModelAlias business logic layer
func (*ModelAlias) Create ¶
func (m *ModelAlias) Create(ctx context.Context, formItem *schema.ModelAliasForm) (*schema.ModelAlias, error)
Create a new model alias.
func (*ModelAlias) Delete ¶
func (m *ModelAlias) Delete(ctx context.Context, id string) error
Delete the specified model alias.
func (*ModelAlias) Get ¶
func (m *ModelAlias) Get(ctx context.Context, id string) (*schema.ModelAlias, error)
Get the specified model alias.
func (*ModelAlias) Query ¶
func (m *ModelAlias) Query(ctx context.Context, params schema.ModelAliasQueryParam) (*schema.ModelAliasQueryResult, error)
Query model aliases.
func (*ModelAlias) Update ¶
func (m *ModelAlias) Update(ctx context.Context, id string, formItem *schema.ModelAliasForm) error
Update the specified model alias.
type ModelCatalog ¶
type ModelCatalog struct {
Trans *util.Trans
ModelCatalogDAL *dal.ModelCatalog
ModelCatalogI18nDAL *dal.ModelCatalogI18n
AuditLogBIZ *opsBiz.AuditLog
}
ModelCatalog business logic layer
func (*ModelCatalog) Create ¶
func (m *ModelCatalog) Create(ctx context.Context, formItem *schema.ModelCatalogForm) (*schema.ModelCatalog, error)
Create a new model catalog.
func (*ModelCatalog) Delete ¶
func (m *ModelCatalog) Delete(ctx context.Context, modelID string) error
Delete the specified model catalog.
func (*ModelCatalog) Get ¶
func (m *ModelCatalog) Get(ctx context.Context, modelID string) (*schema.ModelCatalog, error)
Get the specified model catalog.
func (*ModelCatalog) GetBySlug ¶
func (m *ModelCatalog) GetBySlug(ctx context.Context, slug string) (*schema.ModelCatalog, error)
GetBySlug gets a model catalog by slug.
func (*ModelCatalog) Publish ¶
func (m *ModelCatalog) Publish(ctx context.Context, modelID string, formItem *schema.ModelCatalogPublishForm) error
Publish publishes a model catalog (sets visibility and published_at).
func (*ModelCatalog) Query ¶
func (m *ModelCatalog) Query(ctx context.Context, params schema.ModelCatalogQueryParam) (*schema.ModelCatalogQueryResult, error)
Query model catalogs.
func (*ModelCatalog) QueryPublic ¶
func (m *ModelCatalog) QueryPublic(ctx context.Context, limit int) (schema.ModelCatalogs, error)
QueryPublic queries public available model catalogs.
func (*ModelCatalog) Update ¶
func (m *ModelCatalog) Update(ctx context.Context, modelID string, formItem *schema.ModelCatalogForm) error
Update the specified model catalog.
type ModelCatalogI18n ¶
type ModelCatalogI18n struct {
Trans *util.Trans
ModelCatalogI18nDAL *dal.ModelCatalogI18n
ModelCatalogDAL *dal.ModelCatalog
}
ModelCatalogI18n business logic layer
func (*ModelCatalogI18n) BatchUpsert ¶
func (m *ModelCatalogI18n) BatchUpsert(ctx context.Context, formItem *schema.ModelCatalogI18nBatchForm) error
BatchUpsert batch upserts i18n entries for a model.
func (*ModelCatalogI18n) Create ¶
func (m *ModelCatalogI18n) Create(ctx context.Context, formItem *schema.ModelCatalogI18nForm) (*schema.ModelCatalogI18n, error)
Create creates a new i18n entry.
func (*ModelCatalogI18n) Delete ¶
func (m *ModelCatalogI18n) Delete(ctx context.Context, modelID, locale string) error
Delete deletes a specific i18n entry.
func (*ModelCatalogI18n) Get ¶
func (m *ModelCatalogI18n) Get(ctx context.Context, modelID, locale string) (*schema.ModelCatalogI18n, error)
Get gets a specific i18n entry.
func (*ModelCatalogI18n) Query ¶
func (m *ModelCatalogI18n) Query(ctx context.Context, params schema.ModelCatalogI18nQueryParam) (*schema.ModelCatalogI18nQueryResult, error)
Query model catalog i18n entries.
func (*ModelCatalogI18n) QueryByModelID ¶
func (m *ModelCatalogI18n) QueryByModelID(ctx context.Context, modelID string) (schema.ModelCatalogI18ns, error)
QueryByModelID gets all i18n entries for a model.
func (*ModelCatalogI18n) Update ¶
func (m *ModelCatalogI18n) Update(ctx context.Context, modelID, locale string, formItem *schema.ModelCatalogI18nForm) error
Update updates an i18n entry.
type ModelConfig ¶
type ModelConfig struct {
RequestTypes []string `json:"request_types"`
Endpoints []EndpointConfig `json:"endpoints"`
}
type ModelPriceVersion ¶
type ModelPriceVersion struct {
Trans *util.Trans
ModelPriceVersionDAL *dal.ModelPriceVersion
ModelCatalogDAL *dal.ModelCatalog
AuditLogBIZ *opsBiz.AuditLog
}
ModelPriceVersion business logic layer
func (*ModelPriceVersion) Create ¶
func (m *ModelPriceVersion) Create(ctx context.Context, formItem *schema.ModelPriceVersionForm) (*schema.ModelPriceVersion, error)
Create a new model price version.
func (*ModelPriceVersion) Deactivate ¶
func (m *ModelPriceVersion) Deactivate(ctx context.Context, id string) error
Deactivate deactivates a price version.
func (*ModelPriceVersion) Delete ¶
func (m *ModelPriceVersion) Delete(ctx context.Context, id string) error
Delete the specified model price version.
func (*ModelPriceVersion) Get ¶
func (m *ModelPriceVersion) Get(ctx context.Context, id string) (*schema.ModelPriceVersion, error)
Get the specified model price version.
func (*ModelPriceVersion) GetCurrentPrice ¶
func (m *ModelPriceVersion) GetCurrentPrice(ctx context.Context, modelID, currency string) (*schema.ModelPriceVersion, error)
GetCurrentPrice gets the currently effective price for a model.
func (*ModelPriceVersion) Query ¶
func (m *ModelPriceVersion) Query(ctx context.Context, params schema.ModelPriceVersionQueryParam) (*schema.ModelPriceVersionQueryResult, error)
Query model price versions.
func (*ModelPriceVersion) QueryByModelID ¶
func (m *ModelPriceVersion) QueryByModelID(ctx context.Context, modelID string) (schema.ModelPriceVersions, error)
QueryByModelID queries all price versions for a model.
func (*ModelPriceVersion) Update ¶
func (m *ModelPriceVersion) Update(ctx context.Context, id string, formItem *schema.ModelPriceVersionForm) error
Update the specified model price version.
type OAuthStartResult ¶
type OAuthStartResult struct {
URL string `json:"url"`
UserCode string `json:"user_code,omitempty"`
State string `json:"state"`
// Flow is "device_code" (xAI) or "authorization_code" (Codex).
Flow string `json:"flow,omitempty"`
}
OAuthStartResult carries the details returned to the frontend so it can open the authorization page and finish the flow (poll for xAI, paste callback for Codex).
type OAuthTokenResult ¶
type OAuthTokenResult struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenEndpoint string `json:"token_endpoint"`
BaseURL string `json:"base_url"`
AccountID string `json:"account_id,omitempty"`
Email string `json:"email,omitempty"`
SubscriptionActiveUntil string `json:"subscription_active_until,omitempty"`
Provider string `json:"provider,omitempty"`
}
type Provider ¶
type Provider struct {
Trans *util.Trans
Cache cachex.Cacher
ProviderDAL *dal.Provider
EndpointDAL *dal.Endpoint
DataPermissionBIZ *DataPermission
ConfigRedisSync *ConfigRedisSync
AuditLogBIZ *opsBiz.AuditLog
}
Provider business logic layer
func (*Provider) CompleteOAuthFlow ¶ added in v0.3.0
func (p *Provider) CompleteOAuthFlow(ctx context.Context, formItem *schema.OAuthCompleteForm) (*OAuthTokenResult, error)
CompleteOAuthFlow finishes authorization-code OAuth (Codex) using the pasted callback URL.
func (*Provider) Create ¶
func (p *Provider) Create(ctx context.Context, formItem *schema.ProviderForm) (*schema.Provider, error)
Create a new provider.
func (*Provider) FetchModels ¶
func (p *Provider) FetchModels(ctx context.Context, providerID string, formItem *schema.FetchModelsForm) (*schema.FetchModelsResult, error)
FetchModels calls the upstream provider's /v1/models API and returns the model list.
func (*Provider) GetQuota ¶ added in v0.4.0
func (p *Provider) GetQuota(ctx context.Context, providerID string) (*schema.ProviderQuotaResult, error)
GetQuota fetches live upstream usage/quota for an oauth provider (xAI / Codex).
func (*Provider) PollOAuthStatus ¶
func (*Provider) Query ¶
func (p *Provider) Query(ctx context.Context, params schema.ProviderQueryParam) (*schema.ProviderQueryResult, error)
func (*Provider) StartOAuthFlow ¶
func (p *Provider) StartOAuthFlow(ctx context.Context, providerName string) (*OAuthStartResult, error)
StartOAuthFlow starts an upstream provider OAuth binding flow. xAI uses device-code; Codex uses authorization-code + PKCE with manual callback paste.
type ProviderConfig ¶
type ResolvedEndpoint ¶
type ResolvedEndpoint struct {
ID string `json:"id,omitempty"`
Code string `json:"code,omitempty"`
Description string `json:"description,omitempty"`
RealModel string `json:"real_model"`
ProviderName string `json:"provider_name"`
ProviderProtocol string `json:"provider_protocol"`
APIKey string `json:"api_key"`
URL string `json:"url"`
Timeout int64 `json:"timeout"` // 毫秒
MaxRetries int `json:"max_retries"`
Priority int `json:"priority"`
Weight int `json:"weight"`
Headers map[string]string `json:"headers,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
RequestTypes []string `json:"request_types,omitempty"`
ContextLength int64 `json:"context_length,omitempty"`
MaxOutputTokens int64 `json:"max_output_tokens,omitempty"`
InputPrice *float64 `json:"input_price,omitempty"`
OutputPrice *float64 `json:"output_price,omitempty"`
CachedPrice *float64 `json:"cached_price,omitempty"`
CacheCreationPrice *float64 `json:"cache_creation_price,omitempty"`
}
type TokenRefresher ¶
type TokenRefresher struct {
DB *gorm.DB
RedisSync *ConfigRedisSync
InstanceID string
}
func NewTokenRefresher ¶
func NewTokenRefresher(db *gorm.DB, redisSync *ConfigRedisSync) *TokenRefresher
func (*TokenRefresher) StartCronLoop ¶
func (r *TokenRefresher) StartCronLoop(ctx context.Context)
StartCronLoop starts the background cron loop to refresh expiring OAuth endpoints