schema

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataPermissionTypeProvider = "provider"
	DataPermissionTypeModel    = "model"
)

Data permission type constants

View Source
const (
	ModelCatalogStatusAvailable = "available"
	ModelCatalogStatusPaused    = "paused"

	ModelCatalogVisibilityPublic  = "public"
	ModelCatalogVisibilityPrivate = "private"
)
View Source
const (
	ModelPriceStatusActive   = "active"
	ModelPriceStatusInactive = "inactive"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiKeyItem

type ApiKeyItem struct {
	Value       string `json:"value"`
	Description string `json:"description"`
}

ApiKeyItem represents a single API key with optional description.

type DataPermission

type DataPermission struct {
	ID         string          `json:"id" gorm:"type:varchar(20);primaryKey;<-:create;comment:ID;"`
	Type       string          `json:"type" gorm:"type:varchar(50);not null;uniqueIndex:uniq_data_permission;index:idx_type;comment:数据类型(表名);"`
	DataId     string          `json:"data_id" gorm:"type:varchar(20);not null;uniqueIndex:uniq_data_permission;index:idx_data_id;comment:数据ID;"`
	User       string          `json:"user" gorm:"type:varchar(50);not null;uniqueIndex:uniq_data_permission;index:idx_user;comment:用户;"`
	Tenant     string          `json:"tenant" gorm:"type:varchar(50);not null;uniqueIndex:uniq_data_permission;comment:租户;"`
	Role       string          `json:"role" gorm:"type:varchar(20);not null;uniqueIndex:uniq_data_permission;comment:角色编码;"`
	Permission uint            `json:"permission" gorm:"type:int unsigned;not null;default:0;comment:数据权限位 - 格式(read,write,delete);"`
	Creator    string          `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	CreatedAt  time.Time       `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt  time.Time       `json:"updated_at,omitempty" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
	Deleted    string          `json:"-" gorm:"type:varchar(20);not null;default:'0';uniqueIndex:uniq_data_permission;comment:逻辑删除标识;"`
	DeletedAt  *gorm.DeletedAt `json:"-" gorm:"type:datetime;default:null;comment:删除时间;"`
}

Data permission management

func (DataPermission) TableName

func (a DataPermission) TableName() string

type DataPermissionForm

type DataPermissionForm struct {
	Type       string `json:"type" binding:"required,max=50"`    // Data type (table name)
	DataId     string `json:"data_id" binding:"required,max=20"` // Data ID
	User       string `json:"user" binding:"required,max=50"`    // User
	Tenant     string `json:"tenant" binding:"required,max=50"`  // Tenant
	Role       string `json:"role" binding:"required,max=20"`    // Role code
	Permission uint   `json:"permission"`                        // Data permission bits - format(read,write,delete)
}

Defining the data structure for creating a `DataPermission` struct.

func (*DataPermissionForm) FillTo

func (a *DataPermissionForm) FillTo(dataPermission *DataPermission) error

Convert `DataPermissionForm` to `DataPermission` object.

func (*DataPermissionForm) Validate

func (a *DataPermissionForm) Validate() error

A validation function for the `DataPermissionForm` struct.

type DataPermissionQueryOptions

type DataPermissionQueryOptions struct {
	util.QueryOptions
}

Defining the query options for the `DataPermission` struct.

type DataPermissionQueryParam

type DataPermissionQueryParam struct {
	util.PaginationParam
	Type   string `form:"type"`    // Data type (application/service)
	DataId string `form:"data_id"` // Data ID
	User   string `form:"user"`    // User
}

Defining the query parameters for the `DataPermission` struct.

type DataPermissionQueryResult

type DataPermissionQueryResult struct {
	Data       DataPermissions
	PageResult *util.PaginationResult
}

Defining the query result for the `DataPermission` struct.

type DataPermissions

type DataPermissions []*DataPermission

Defining the slice of `DataPermission` struct.

type Endpoint

type Endpoint struct {
	ID                 string          `json:"id" gorm:"type:char(20);primaryKey;comment:主键ID (XID);"`
	Code               string          `json:"code" gorm:"type:varchar(128);not null;uniqueIndex:uniq_endpoint_code_deleted,priority:1;comment:端点唯一编码;"`
	ModelID            string          `` /* 139-byte string literal not displayed */
	ProviderID         string          `` /* 148-byte string literal not displayed */
	URL                string          `json:"url" gorm:"type:varchar(1024);not null;comment:上游 API 地址;"`
	AuthType           string          `json:"auth_type" gorm:"type:varchar(64);default:'api_key';comment:认证类型: api_key, oauth_token;"`
	ApiKey             string          `` /* 130-byte string literal not displayed */
	Protocol           string          `json:"protocol,omitempty" gorm:"type:varchar(64);default:null;comment:可选,覆盖 provider 级别的 protocol;"`
	RealModel          string          `json:"real_model,omitempty" gorm:"type:varchar(128);default:null;comment:可选,覆盖 model 级别的 real_model;"`
	Priority           int             `json:"priority" gorm:"type:int;not null;default:0;comment:故障转移顺序,数字越小越优先;"`
	Weight             int             `json:"weight" gorm:"type:int;not null;default:1;comment:负载均衡权重;"`
	Enabled            int             `json:"enabled" gorm:"type:int;not null;default:0;comment:启用状态: 0-未启用,1-启用;"`
	Headers            json.RawMessage `json:"headers,omitempty" gorm:"type:json;default:null;comment:自定义请求头,如 {\"X-Custom-Header\": \"value\"};"`
	Metadata           json.RawMessage `json:"metadata,omitempty" gorm:"type:json;default:null;comment:元数据,用于存储标签等额外信息;"`
	InputPrice         *float64        `` /* 127-byte string literal not displayed */
	OutputPrice        *float64        `` /* 128-byte string literal not displayed */
	CachedPrice        *float64        `` /* 134-byte string literal not displayed */
	CacheCreationPrice *float64        `` /* 142-byte string literal not displayed */
	Description        string          `json:"description" gorm:"type:varchar(10240);default:null;comment:备注描述;"`
	Creator            string          `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	Modifier           string          `json:"modifier" gorm:"type:varchar(255);default:null;comment:修改者;"`
	CreatedAt          time.Time       `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt          time.Time       `json:"updated_at" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
	Deleted            string          `` /* 194-byte string literal not displayed */
	DeletedAt          *gorm.DeletedAt `json:"-" gorm:"type:datetime;default:null;comment:逻辑删除时间;"`
	StatusPoints       []StatusPoint   `json:"status_points" gorm:"-"` // Recent status points

	// 关联查询
	Model    *Model    `json:"model,omitempty" gorm:"foreignKey:ModelID;references:ID"`
	Provider *Provider `json:"provider,omitempty" gorm:"foreignKey:ProviderID;references:ID"`
}

Endpoint defines an upstream endpoint belonging to a provider.

func (*Endpoint) TableName

func (e *Endpoint) TableName() string

type EndpointEnabledForm

type EndpointEnabledForm struct {
	Enabled int `json:"enabled"` // Enable status: 0-disabled, 1-enabled
}

EndpointEnabledForm toggles the enabled status of an endpoint.

func (*EndpointEnabledForm) Validate

func (e *EndpointEnabledForm) Validate() error

type EndpointForm

type EndpointForm struct {
	Code               string          `json:"code" binding:"required,max=128"`       // Endpoint unique code
	ProviderID         string          `json:"provider_id" binding:"required,max=20"` // Associated provider ID
	ModelID            string          `json:"model_id" binding:"required,max=20"`    // Associated Model ID
	URL                string          `json:"url" binding:"required,max=512"`        // Upstream API address
	ApiKey             string          `json:"api_key"`                               // Optional, overrides provider-level api_key (api_key type only)
	AuthType           string          `json:"auth_type"`                             // Auth type: api_key, oauth_token
	Protocol           string          `json:"protocol"`                              // Optional, overrides provider-level protocol
	RealModel          string          `json:"real_model"`                            // Optional, overrides model-level real_model
	Priority           int             `json:"priority"`                              // Failover priority
	Weight             int             `json:"weight"`                                // Load balancing weight
	Enabled            int             `json:"enabled"`                               // Enable status: 0-disabled, 1-enabled
	Headers            json.RawMessage `json:"headers"`                               // Custom HTTP headers
	Metadata           json.RawMessage `json:"metadata"`                              // Metadata
	InputPrice         *float64        `json:"input_price"`                           // Input price (CNY/M Tokens)
	OutputPrice        *float64        `json:"output_price"`                          // Output price (CNY/M Tokens)
	CachedPrice        *float64        `json:"cached_price"`                          // Cached price (CNY/M Tokens)
	CacheCreationPrice *float64        `json:"cache_creation_price"`                  // Cache creation price (CNY/M Tokens)
	Description        string          `json:"description"`                           // Description
}

EndpointForm defines the form for creating/updating an Endpoint.

func (*EndpointForm) FillTo

func (e *EndpointForm) FillTo(endpoint *Endpoint) error

func (*EndpointForm) Validate

func (e *EndpointForm) Validate() error

type EndpointQueryOptions

type EndpointQueryOptions struct {
	util.QueryOptions
}

EndpointQueryOptions defines the query options for Endpoint.

type EndpointQueryParam

type EndpointQueryParam struct {
	util.PaginationParam
	ProviderID string `form:"provider_id"` // Filter by provider ID
	ModelID    string `form:"model_id"`    // Filter by model ID
	LikeURL    string `form:"url"`         // URL (like)
	Priority   int    `form:"priority"`    // Filter by priority
	Enabled    *int   `form:"enabled"`     // Filter by enabled status
}

EndpointQueryParam defines the query parameters for Endpoint.

type EndpointQueryResult

type EndpointQueryResult struct {
	Data       Endpoints
	PageResult *util.PaginationResult
}

EndpointQueryResult defines the query result for Endpoint.

type EndpointTestResult

type EndpointTestResult struct {
	Success   bool   `json:"success"`
	LatencyMs int64  `json:"latency_ms"`
	Message   string `json:"message"`
	Detail    string `json:"detail"`
}

EndpointTestResult defines the result for the endpoint connectivity test.

type Endpoints

type Endpoints []*Endpoint

Endpoints defines a slice of Endpoint.

type FetchModelsForm

type FetchModelsForm struct {
	BaseURL string `json:"base_url"` // Upstream base URL, e.g., https://api.openai.com (optional if provider has url)
	APIKey  string `json:"api_key"`  // API key to use (optional, defaults to provider's first key)
}

FetchModelsForm defines the request form for fetching models from upstream provider.

func (*FetchModelsForm) Validate

func (f *FetchModelsForm) Validate() error

type FetchModelsResult

type FetchModelsResult struct {
	Models []UpstreamModel `json:"models"`
}

FetchModelsResult defines the response for the fetch models API.

type GetCurrentPriceQuery

type GetCurrentPriceQuery struct {
	ModelID  string `form:"model_id" binding:"required"` // Model ID
	Currency string `form:"currency"`                    // Currency (default CNY)
}

GetCurrentPriceQuery 查询当前生效的价格版本

type Model

type Model struct {
	ID                 string          `json:"id" gorm:"type:char(20);primaryKey;comment:主键ID (XID);"`
	ModelName          string          `json:"model_name" gorm:"type:varchar(128);not null;uniqueIndex:uniq_model_name;comment:模型名称;"`
	ModelCode          string          `json:"model_code" gorm:"type:varchar(64);not null;uniqueIndex:uniq_model_code_deleted,priority:1;comment:模型唯一编码;"`
	SpaceCode          string          `json:"space_code" gorm:"type:varchar(255);not null;comment:模型空间编码;"`
	RequestTypes       string          `` /* 130-byte string literal not displayed */
	ContextLength      int             `json:"context_length" gorm:"type:bigint;not null;default:128000;comment:最大上下文窗口(Tokens);"`
	MaxOutputTokens    int             `json:"max_output_tokens" gorm:"type:bigint;not null;default:8192;comment:最大输出Token;"`
	Owner              string          `json:"owner,omitempty" gorm:"type:varchar(64);default:null;comment:模型所属企业/厂商,如 OpenAI, Google, DeepSeek;"`
	Abilities          string          `` /* 127-byte string literal not displayed */
	Enabled            int             `json:"enabled" gorm:"type:int;not null;default:0;comment:启用状态: 0-未启用,1-启用;"`
	InputPrice         float64         `json:"input_price" gorm:"type:decimal(10,6);not null;default:3.000000;comment:输入价格(元/百万 Tokens);"`
	OutputPrice        float64         `json:"output_price" gorm:"type:decimal(10,6);not null;default:10.000000;comment:输出价格(元/百万 Tokens);"`
	CachedPrice        float64         `json:"cached_price" gorm:"type:decimal(10,6);not null;default:1.000000;comment:缓存命中价格(元/百万 Tokens);"`
	CacheCreationPrice float64         `` /* 130-byte string literal not displayed */
	Description        string          `json:"description" gorm:"type:varchar(255);default:null;comment:备注描述;"`
	Extra              *string         `json:"extra,omitempty" gorm:"type:json;default:null;comment:其他信息;"`
	Creator            string          `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	Modifier           string          `json:"modifier" gorm:"type:varchar(255);default:null;comment:修改者;"`
	CreatedAt          time.Time       `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt          time.Time       `json:"updated_at" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
	StatusPoints       []StatusPoint   `json:"status_points" gorm:"-"` // Recent status points
	Deleted            string          ``                              /* 128-byte string literal not displayed */
	DeletedAt          *gorm.DeletedAt `json:"-" gorm:"type:datetime;default:null;comment:逻辑删除时间;"`
}

Model defines the LLM model from user's perspective.

func (*Model) TableName

func (m *Model) TableName() string

type ModelAlias

type ModelAlias struct {
	ID          string          `json:"id" gorm:"type:varchar(20);primaryKey;<-:create;comment:ID;"`
	SpaceCode   string          `json:"space_code" gorm:"type:varchar(255);not null;uniqueIndex:uniq_model_alias_space_alias;comment:模型空间编码;"`
	Alias       string          `json:"alias" gorm:"type:varchar(255);not null;uniqueIndex:uniq_model_alias_space_alias;comment:模型别名;"`
	ModelId     string          `json:"model_id" gorm:"type:varchar(20);not null;comment:所属模型ID;"`
	Description *string         `json:"description,omitempty" gorm:"type:varchar(255);default:null;comment:备注;"`
	CreatedAt   time.Time       `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt   time.Time       `json:"updated_at,omitempty" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
	Deleted     string          `json:"-" gorm:"type:varchar(20);not null;default:'0';uniqueIndex:uniq_model_alias_space_alias;comment:逻辑删除标识;"`
	DeletedAt   *gorm.DeletedAt `json:"-" gorm:"type:datetime;default:null;comment:逻辑删除时间;"`
	Model       *Model          `json:"model,omitempty" gorm:"foreignKey:ModelId;references:ID"` // Model association
}

ModelAlias defines an alias for a model.

func (*ModelAlias) TableName

func (m *ModelAlias) TableName() string

type ModelAliasForm

type ModelAliasForm struct {
	SpaceCode   string  `json:"space_code" binding:"required,max=255"` // Space code
	Alias       string  `json:"alias" binding:"required,max=255"`      // Model alias
	ModelId     string  `json:"model_id" binding:"required,max=20"`    // Model ID
	Description *string `json:"description"`                           // Description
}

ModelAliasForm defines the form for creating/updating a ModelAlias.

func (*ModelAliasForm) FillTo

func (m *ModelAliasForm) FillTo(alias *ModelAlias) error

func (*ModelAliasForm) Validate

func (m *ModelAliasForm) Validate() error

type ModelAliasQueryOptions

type ModelAliasQueryOptions struct {
	util.QueryOptions
}

ModelAliasQueryOptions defines the query options for ModelAlias.

type ModelAliasQueryParam

type ModelAliasQueryParam struct {
	util.PaginationParam
	SpaceCode string `form:"space_code"` // Space code
	Alias     string `form:"alias"`      // Model alias
	ModelId   string `form:"model_id"`   // Model ID
}

ModelAliasQueryParam defines the query parameters for ModelAlias.

type ModelAliasQueryResult

type ModelAliasQueryResult struct {
	Data       ModelAliases
	PageResult *util.PaginationResult
}

ModelAliasQueryResult defines the query result for ModelAlias.

type ModelAliases

type ModelAliases []*ModelAlias

ModelAliases defines a slice of ModelAlias.

type ModelCatalog

type ModelCatalog struct {
	ModelID          string     `json:"model_id" gorm:"type:varchar(191);primaryKey;comment:模型ID,关联 model.model_code 或自定义标识;"`
	ModelCode        string     `` /* 138-byte string literal not displayed */
	Slug             string     `` /* 126-byte string literal not displayed */
	Status           string     `` /* 135-byte string literal not displayed */
	Visibility       string     `` /* 137-byte string literal not displayed */
	LogoURL          string     `json:"logo_url" gorm:"type:varchar(1024);not null;default:'';comment:模型 Logo URL;"`
	ContextLength    *int64     `json:"context_length" gorm:"type:bigint;default:null;comment:最大上下文窗口(Tokens);"`
	KnowledgeCutoff  *time.Time `json:"knowledge_cutoff" gorm:"type:date;default:null;comment:知识截止日期;"`
	InputModalities  *string    `json:"input_modalities,omitempty" gorm:"type:json;default:null;comment:支持的输入模态,如 [\"text\",\"image\"];"`
	OutputModalities *string    `json:"output_modalities,omitempty" gorm:"type:json;default:null;comment:支持的输出模态,如 [\"text\"];"`
	Capabilities     *string    `` /* 136-byte string literal not displayed */
	Featured         bool       `json:"featured" gorm:"not null;default:false;index:idx_mc_public_list,priority:3;comment:是否精选推荐;"`
	SortWeight       int64      `` /* 138-byte string literal not displayed */
	PublishedAt      *time.Time `json:"published_at" gorm:"type:datetime;default:null;index:idx_mc_public_list,priority:5;comment:首次发布时间;"`
	Creator          string     `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	Modifier         string     `json:"modifier" gorm:"type:varchar(255);default:null;comment:修改者;"`
	CreatedAt        time.Time  `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt        time.Time  `json:"updated_at" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
}

ModelCatalog 面向用户的模型目录,与内部 Model 表形成互补。 Model 表面向运维管理(内部编码、端点关联、价格),ModelCatalog 面向终端用户展示(国际化描述、SEO、能力标签、排序权重)。

func (ModelCatalog) TableName

func (ModelCatalog) TableName() string

type ModelCatalogForm

type ModelCatalogForm struct {
	ModelID          string     `json:"model_id" binding:"required,max=191"` // Model ID
	ModelCode        string     `json:"model_code" binding:"max=64"`         // Link to admin model
	Slug             string     `json:"slug" binding:"required,max=191"`     // URL slug
	Status           string     `json:"status" binding:"required,oneof=available paused"`
	Visibility       string     `json:"visibility" binding:"required,oneof=public private"`
	LogoURL          string     `json:"logo_url" binding:"max=1024"` // Logo URL
	ContextLength    *int64     `json:"context_length"`              // Context window
	KnowledgeCutoff  *time.Time `json:"knowledge_cutoff"`            // Knowledge cutoff
	InputModalities  *string    `json:"input_modalities"`            // Input modalities
	OutputModalities *string    `json:"output_modalities"`           // Output modalities
	Capabilities     *string    `json:"capabilities"`                // Capabilities
	Featured         *bool      `json:"featured"`                    // Featured
	SortWeight       *int64     `json:"sort_weight"`                 // Sort weight
}

ModelCatalogForm defines the form for creating/updating a ModelCatalog.

func (*ModelCatalogForm) FillTo

func (a *ModelCatalogForm) FillTo(catalog *ModelCatalog) error

func (*ModelCatalogForm) Validate

func (a *ModelCatalogForm) Validate() error

type ModelCatalogI18n

type ModelCatalogI18n struct {
	ModelID          string    `json:"model_id" gorm:"type:varchar(191);primaryKey;comment:模型ID,关联 model_catalog.model_id;"`
	Locale           string    `json:"locale" gorm:"type:varchar(16);primaryKey;comment:语言区域,如 zh-CN, en-US;"`
	DisplayName      string    `json:"display_name" gorm:"type:varchar(255);not null;comment:模型展示名称;"`
	ShortDescription string    `json:"short_description" gorm:"type:varchar(512);not null;default:'';comment:短描述,用于列表展示;"`
	LongDescription  *string   `json:"long_description" gorm:"type:text;default:null;comment:长描述,支持 Markdown,用于详情页;"`
	SEOTitle         string    `json:"seo_title" gorm:"type:varchar(255);not null;default:'';comment:SEO 标题;"`
	SEODescription   string    `json:"seo_description" gorm:"type:varchar(512);not null;default:'';comment:SEO 描述;"`
	Tags             *string   `json:"tags,omitempty" gorm:"type:json;default:null;comment:展示标签,如 [\"最新\",\"高性价比\"];"`
	Creator          string    `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	Modifier         string    `json:"modifier" gorm:"type:varchar(255);default:null;comment:修改者;"`
	CreatedAt        time.Time `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt        time.Time `json:"updated_at" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
}

ModelCatalogI18n 模型目录多语言内容表,为 ModelCatalog 提供国际化描述、SEO 信息和展示标签。

func (ModelCatalogI18n) TableName

func (ModelCatalogI18n) TableName() string

type ModelCatalogI18nBatchForm

type ModelCatalogI18nBatchForm struct {
	ModelID string                 `json:"model_id" binding:"required,max=191"` // Model ID
	Entries []ModelCatalogI18nForm `json:"entries" binding:"required,dive"`     // I18n entries
}

ModelCatalogI18nBatchForm defines the batch form for upserting i18n entries for a model.

func (*ModelCatalogI18nBatchForm) Validate

func (a *ModelCatalogI18nBatchForm) Validate() error

type ModelCatalogI18nForm

type ModelCatalogI18nForm struct {
	ModelID          string  `json:"model_id" binding:"required,max=191"`     // Model ID
	Locale           string  `json:"locale" binding:"required,max=16"`        // Locale
	DisplayName      string  `json:"display_name" binding:"required,max=255"` // Display name
	ShortDescription string  `json:"short_description" binding:"max=512"`     // Short description
	LongDescription  *string `json:"long_description"`                        // Long description (Markdown)
	SEOTitle         string  `json:"seo_title" binding:"max=255"`             // SEO title
	SEODescription   string  `json:"seo_description" binding:"max=512"`       // SEO description
	Tags             *string `json:"tags"`                                    // Display tags
}

ModelCatalogI18nForm defines the form for creating/updating a ModelCatalogI18n.

func (*ModelCatalogI18nForm) FillTo

func (a *ModelCatalogI18nForm) FillTo(i18n *ModelCatalogI18n) error

func (*ModelCatalogI18nForm) Validate

func (a *ModelCatalogI18nForm) Validate() error

type ModelCatalogI18nQueryOptions

type ModelCatalogI18nQueryOptions struct {
	util.QueryOptions
}

ModelCatalogI18nQueryOptions defines the query options for ModelCatalogI18n.

type ModelCatalogI18nQueryParam

type ModelCatalogI18nQueryParam struct {
	util.PaginationParam
	ModelID string `form:"model_id"` // Filter by model ID
	Locale  string `form:"locale"`   // Filter by locale
}

ModelCatalogI18nQueryParam defines the query parameters for ModelCatalogI18n.

type ModelCatalogI18nQueryResult

type ModelCatalogI18nQueryResult struct {
	Data       ModelCatalogI18ns
	PageResult *util.PaginationResult
}

ModelCatalogI18nQueryResult defines the query result for ModelCatalogI18n.

type ModelCatalogI18ns

type ModelCatalogI18ns []*ModelCatalogI18n

ModelCatalogI18ns defines a slice of ModelCatalogI18n.

type ModelCatalogMetric

type ModelCatalogMetric struct {
	Window        string  `json:"window"`         // Time window: "1h", "24h", "7d"
	Availability  float64 `json:"availability"`   // Availability rate (0-1)
	SuccessRate   float64 `json:"success_rate"`   // Success rate (0-1)
	TtftP50Ms     float64 `json:"ttft_p50_ms"`    // TTFT p50 in milliseconds
	TtftP95Ms     float64 `json:"ttft_p95_ms"`    // TTFT p95 in milliseconds
	ResponseSpeed float64 `json:"response_speed"` // Response speed (tokens per second)
	SampleCount   int64   `json:"sample_count"`   // Number of samples/requests
	UpdatedAt     string  `json:"updated_at"`     // Last update time
}

ModelCatalogMetric represents model service metrics from Prometheus

type ModelCatalogMetricResponse

type ModelCatalogMetricResponse []ModelCatalogMetric

ModelCatalogMetricResponse is the response for metrics API

type ModelCatalogPublishForm

type ModelCatalogPublishForm struct {
	Visibility  string     `json:"visibility" binding:"required,oneof=public private"` // Visibility
	PublishedAt *time.Time `json:"published_at"`                                       // Publish time (defaults to now)
}

ModelCatalogPublishForm defines the form for publishing a model catalog.

func (*ModelCatalogPublishForm) Validate

func (a *ModelCatalogPublishForm) Validate() error

type ModelCatalogQueryOptions

type ModelCatalogQueryOptions struct {
	util.QueryOptions
}

ModelCatalogQueryOptions defines the query options for ModelCatalog.

type ModelCatalogQueryParam

type ModelCatalogQueryParam struct {
	util.PaginationParam
	LikeSlug   string `form:"slug"`       // Slug (like)
	Status     string `form:"status"`     // Filter by status
	Visibility string `form:"visibility"` // Filter by visibility
	Featured   *bool  `form:"featured"`   // Filter by featured
	ModelCode  string `form:"model_code"` // Filter by model_code
}

ModelCatalogQueryParam defines the query parameters for ModelCatalog.

type ModelCatalogQueryResult

type ModelCatalogQueryResult struct {
	Data       ModelCatalogs
	PageResult *util.PaginationResult
}

ModelCatalogQueryResult defines the query result for ModelCatalog.

type ModelCatalogs

type ModelCatalogs []*ModelCatalog

ModelCatalogs defines a slice of ModelCatalog.

type ModelCreateResult added in v0.8.0

type ModelCreateResult struct {
	*Model
	AppliedSeeds []string `json:"applied_seeds,omitempty"`
	SkippedSeeds []string `json:"skipped_seeds,omitempty"`
}

ModelCreateResult is returned by model create so the client can tell which recommended policies were actually applied.

type ModelEnabledForm

type ModelEnabledForm struct {
	Enabled int `json:"enabled"` // Enable status: 0-disabled, 1-enabled
}

ModelEnabledForm toggles the enabled status of a model.

func (*ModelEnabledForm) Validate

func (m *ModelEnabledForm) Validate() error

type ModelForm

type ModelForm struct {
	ModelName             string  `json:"model_name" binding:"required,max=128"` // Client-facing model name
	ModelCode             string  `json:"model_code" binding:"required,max=64"`  // Internal model code
	SpaceCode             string  `json:"space_code" binding:"required,max=255"` // Space code
	RequestTypes          string  `json:"request_types" binding:"required"`      // Model RequestTypes JSON
	ContextLength         int     `json:"context_length"`                        // Max context window
	MaxOutputTokens       int     `json:"max_output_tokens"`                     // Max output tokens
	Abilities             string  `json:"abilities"`                             // Model Abilities JSON
	Owner                 string  `json:"owner"`                                 // Model owner
	Enabled               int     `json:"enabled"`                               // Enable status
	InputPrice            float64 `json:"input_price"`                           // Input price (CNY/M Tokens)
	OutputPrice           float64 `json:"output_price"`                          // Output price (CNY/M Tokens)
	CachedPrice           float64 `json:"cached_price"`                          // Cached price (CNY/M Tokens)
	CacheCreationPrice    float64 `json:"cache_creation_price"`                  // Cache creation price (CNY/M Tokens)
	Extra                 *string `json:"extra"`                                 // Extra info
	Description           string  `json:"description"`                           // Description
	ApplyInvocationSeed   bool    `json:"apply_invocation_seed"`                 // Copy the recommended invocation seed on create
	ApplyCircuitBreakSeed bool    `json:"apply_circuit_break_seed"`              // Copy the recommended circuit-break seed on create
}

ModelForm defines the form for creating/updating a Model.

func (*ModelForm) FillTo

func (m *ModelForm) FillTo(model *Model) error

func (*ModelForm) Validate

func (m *ModelForm) Validate() error

type ModelPriceVersion

type ModelPriceVersion struct {
	ID                 string     `json:"id" gorm:"type:char(20);primaryKey;<-:create;comment:主键ID (XID);"`
	ModelID            string     `` /* 180-byte string literal not displayed */
	Currency           string     `json:"currency" gorm:"type:varchar(8);not null;default:CNY;comment:计价货币,如 CNY, USD;"`
	InputPrice         float64    `json:"input_price" gorm:"type:decimal(10,6);not null;comment:输入价格(元/百万 Tokens);"`
	OutputPrice        float64    `json:"output_price" gorm:"type:decimal(10,6);not null;comment:输出价格(元/百万 Tokens);"`
	CachedPrice        *float64   `json:"cached_price" gorm:"type:decimal(10,6);default:null;comment:缓存命中价格(元/百万 Tokens);"`
	CacheCreationPrice *float64   `json:"cache_creation_price" gorm:"type:decimal(10,6);default:null;comment:缓存创建价格(元/百万 Tokens);"`
	EffectiveFrom      time.Time  `` /* 160-byte string literal not displayed */
	EffectiveUntil     *time.Time `` /* 143-byte string literal not displayed */
	Status             string     `` /* 134-byte string literal not displayed */
	PublishedByUser    string     `json:"published_by_user" gorm:"type:varchar(255);default:null;comment:发布人;"`
	PublishedAt        time.Time  `json:"published_at" gorm:"type:datetime;not null;comment:发布时间;"`
	Creator            string     `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	Modifier           string     `json:"modifier" gorm:"type:varchar(255);default:null;comment:修改者;"`
	CreatedAt          time.Time  `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt          time.Time  `json:"updated_at" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
}

ModelPriceVersion 模型价格版本表,支持价格版本化管理和生效区间控制。 与 Model/Endpoint 上的直接价格字段互补:Model 价格用于网关实时计算,PriceVersion 用于 Portal 展示和历史追溯。

func (ModelPriceVersion) TableName

func (ModelPriceVersion) TableName() string

type ModelPriceVersionForm

type ModelPriceVersionForm struct {
	ModelID            string     `json:"model_id" binding:"required,max=191"` // Model ID
	Currency           string     `json:"currency" binding:"required,max=8"`   // Currency
	InputPrice         float64    `json:"input_price" binding:"min=0"`         // 输入价格(元/百万 Tokens)
	OutputPrice        float64    `json:"output_price" binding:"min=0"`        // 输出价格(元/百万 Tokens)
	CachedPrice        *float64   `json:"cached_price"`                        // 缓存命中价格(元/百万 Tokens)
	CacheCreationPrice *float64   `json:"cache_creation_price"`                // 缓存创建价格(元/百万 Tokens)
	EffectiveFrom      time.Time  `json:"effective_from" binding:"required"`   // Effective from
	EffectiveUntil     *time.Time `json:"effective_until"`                     // Effective until
}

ModelPriceVersionForm defines the form for creating/updating a ModelPriceVersion.

func (*ModelPriceVersionForm) FillTo

func (a *ModelPriceVersionForm) FillTo(version *ModelPriceVersion) error

func (*ModelPriceVersionForm) Validate

func (a *ModelPriceVersionForm) Validate() error

type ModelPriceVersionQueryOptions

type ModelPriceVersionQueryOptions struct {
	util.QueryOptions
}

ModelPriceVersionQueryOptions defines the query options for ModelPriceVersion.

type ModelPriceVersionQueryParam

type ModelPriceVersionQueryParam struct {
	util.PaginationParam
	ModelID  string `form:"model_id"` // Filter by model ID
	Status   string `form:"status"`   // Filter by status
	Currency string `form:"currency"` // Filter by currency
}

ModelPriceVersionQueryParam defines the query parameters for ModelPriceVersion.

type ModelPriceVersionQueryResult

type ModelPriceVersionQueryResult struct {
	Data       ModelPriceVersions
	PageResult *util.PaginationResult
}

ModelPriceVersionQueryResult defines the query result for ModelPriceVersion.

type ModelPriceVersions

type ModelPriceVersions []*ModelPriceVersion

ModelPriceVersions defines a slice of ModelPriceVersion.

type ModelQueryOptions

type ModelQueryOptions struct {
	util.QueryOptions
}

ModelQueryOptions defines the query options for Model.

type ModelQueryParam

type ModelQueryParam struct {
	util.PaginationParam
	LikeName  string `form:"model_name"` // Model name (like)
	ModelCode string `form:"model_code"` // Model code (exact)
	SpaceCode string `form:"space_code"` // Space code
}

ModelQueryParam defines the query parameters for Model.

type ModelQueryResult

type ModelQueryResult struct {
	Data       Models
	PageResult *util.PaginationResult
}

ModelQueryResult defines the query result for Model.

type Models

type Models []*Model

Models defines a slice of Model.

type OAuthCompleteForm added in v0.3.0

type OAuthCompleteForm struct {
	Provider    string `json:"provider" binding:"required"`
	State       string `json:"state" binding:"required"`
	CallbackURL string `json:"callback_url" binding:"required"`
}

OAuthCompleteForm is the request body for finishing authorization-code OAuth flows (e.g. Codex) by submitting the browser callback URL.

func (*OAuthCompleteForm) Validate added in v0.3.0

func (f *OAuthCompleteForm) Validate() error

type OAuthCredential

type OAuthCredential struct {
	RefreshToken  string     `json:"refresh_token,omitempty"`
	TokenEndpoint string     `json:"token_endpoint,omitempty"`
	ExpiresAt     *time.Time `json:"expires_at,omitempty"`
	// AccountID is Codex/ChatGPT account id used as Chatgpt-Account-Id header.
	AccountID string `json:"account_id,omitempty"`
	// Email is the upstream account email snapshot (non-secret).
	Email string `json:"email,omitempty"`
	// SubscriptionActiveUntil is Codex plan renewal time display/snapshot
	// (e.g. "2026/8/28 01:21:08"), extracted from id_token claims.
	SubscriptionActiveUntil string `json:"subscription_active_until,omitempty"`
}

OAuthCredential holds the OAuth secrets and refresh metadata for a provider, persisted as a single JSON column. access_token itself lives in ApiKeys; the upstream base URL lives in the Provider.URL column.

type Provider

type Provider struct {
	ID          string          `json:"id" gorm:"type:char(20);primaryKey;comment:主键ID (XID);"`
	Code        string          `json:"code" gorm:"type:varchar(128);not null;uniqueIndex:uniq_provider_code,priority:1;comment:Provider唯一标识;"`
	Name        string          `json:"name" gorm:"type:varchar(128);not null;comment:Provider名称;"`
	Protocol    string          `json:"protocol" gorm:"type:varchar(64);not null;comment:协议类型,决定使用哪个 ProviderFactory;"`
	URL         string          `json:"url" gorm:"type:varchar(1024);default:null;comment:供应商 API 基础地址;"`
	AuthType    string          `json:"auth_type" gorm:"type:varchar(64);default:'api_key';comment:认证类型: api_key, oauth_token;"`
	ApiKeys     json.RawMessage `json:"api_keys,omitempty" gorm:"type:json;default:null;comment:上游API认证密钥列表;"`
	OAuth       json.RawMessage `json:"oauth,omitempty" gorm:"type:json;default:null;comment:OAuth 凭证(refresh_token/token_endpoint/expires_at);"`
	LockOwner   string          `json:"-" gorm:"type:varchar(128);default:null;comment:OAuth 刷新分布式锁持有者实例ID;"`
	LockedUntil *time.Time      `json:"-" gorm:"type:datetime;default:null;comment:OAuth 刷新分布式锁过期时间;"`
	Enabled     int             `json:"enabled" gorm:"type:int;not null;default:0;comment:启用状态: 0-未启用,1-启用;"`
	Description string          `json:"description" gorm:"type:varchar(255);default:null;comment:备注描述;"`
	Creator     string          `json:"creator" gorm:"type:varchar(255);default:null;comment:创建者;"`
	Modifier    string          `json:"modifier" gorm:"type:varchar(255);default:null;comment:修改者;"`
	CreatedAt   time.Time       `json:"created_at" gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间;"`
	UpdatedAt   time.Time       `json:"updated_at" gorm:"type:timestamp;default:CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间;"`
	Deleted     string          `json:"-" gorm:"type:varchar(20);not null;default:'0';uniqueIndex:uniq_provider_code,priority:2;comment:逻辑删除标识;"`
	DeletedAt   *gorm.DeletedAt `json:"-" gorm:"type:datetime;default:null;comment:逻辑删除时间;"`
}

Provider defines the upstream LLM provider (e.g., OpenAI, Anthropic).

func (*Provider) GetApiKeys

func (p *Provider) GetApiKeys() []ApiKeyItem

GetApiKeys deserializes the JSON api_keys field into an ApiKeyItem slice.

func (*Provider) GetOAuth

func (p *Provider) GetOAuth() *OAuthCredential

GetOAuth deserializes the JSON oauth field into an OAuthCredential.

func (*Provider) TableName

func (p *Provider) TableName() string

type ProviderForm

type ProviderForm struct {
	Code        string           `json:"code" binding:"required,max=128"`    // Provider unique code
	Name        string           `json:"name" binding:"required,max=128"`    // Provider display name
	Protocol    string           `json:"protocol" binding:"required,max=64"` // Protocol type: openai / anthropic / ...
	URL         string           `json:"url"`                                // Provider API base URL
	ApiKeys     []ApiKeyItem     `json:"api_keys"`                           // Upstream API key list
	AuthType    string           `json:"auth_type"`                          // Auth type: api_key, oauth_token
	OAuth       *OAuthCredential `json:"oauth"`                              // OAuth credential (refresh_token/token_endpoint/expires_at)
	Enabled     int              `json:"enabled"`                            // Enable status: 0-disabled, 1-enabled
	Description string           `json:"description"`                        // Description
}

ProviderForm defines the form for creating/updating a Provider.

func (*ProviderForm) FillTo

func (p *ProviderForm) FillTo(provider *Provider) error

func (*ProviderForm) Validate

func (p *ProviderForm) Validate() error

type ProviderQueryOptions

type ProviderQueryOptions struct {
	util.QueryOptions
}

ProviderQueryOptions defines the query options for Provider.

type ProviderQueryParam

type ProviderQueryParam struct {
	util.PaginationParam
	LikeCode string `form:"code"` // Code (like)
	LikeName string `form:"name"` // Name (like)
}

ProviderQueryParam defines the query parameters for Provider.

type ProviderQueryResult

type ProviderQueryResult struct {
	Data       Providers
	PageResult *util.PaginationResult
}

ProviderQueryResult defines the query result for Provider.

type ProviderQuotaResult added in v0.4.0

type ProviderQuotaResult struct {
	Provider                string                `json:"provider"` // codex | xai
	Plan                    string                `json:"plan,omitempty"`
	SubscriptionActiveUntil string                `json:"subscription_active_until,omitempty"`
	Windows                 []ProviderQuotaWindow `json:"windows"`
	Extras                  map[string]any        `json:"extras,omitempty"`
}

ProviderQuotaResult is the unified quota/usage response for oauth providers.

type ProviderQuotaWindow added in v0.4.0

type ProviderQuotaWindow struct {
	ID               string   `json:"id"`
	Label            string   `json:"label"`
	UsedPercent      *float64 `json:"used_percent,omitempty"`
	RemainingPercent *float64 `json:"remaining_percent,omitempty"`
	ResetAt          string   `json:"reset_at,omitempty"`
	ResetLabel       string   `json:"reset_label,omitempty"`
	// Optional amount labels for billing-style quotas (xAI).
	AmountLabel string `json:"amount_label,omitempty"`
}

ProviderQuotaWindow is one usage window / credit bucket.

type Providers

type Providers []*Provider

Providers defines a slice of Provider.

type StatusPoint

type StatusPoint struct {
	SuccessCount int64  `json:"success_count"`
	FailCount    int64  `json:"fail_count"`
	StartTime    string `json:"start_time"`
	EndTime      string `json:"end_time"`
}

StatusPoint 最近状态时间点的成功失败数

type UpstreamModel

type UpstreamModel struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	OwnedBy string `json:"owned_by"`
}

UpstreamModel represents a single model returned by the upstream /v1/models API.

Jump to

Keyboard shortcuts

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