channel

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PriceRatioMin = pricing.PlatformPriceRatioMin
	PriceRatioMax = pricing.PlatformPriceRatioMax
)

PriceRatioMin / PriceRatioMax 是公共 channel 计费倍率的合法区间。 0 合法(settler 归一到原价 1.0);上界 1000 防止误填把成本放大到离谱。

Variables

This section is empty.

Functions

func ListProviderTypes added in v0.0.2

func ListProviderTypes() []int

ListProviderTypes returns all channel type IDs that represent real, user-selectable providers: every key in newAPIConstant.ChannelTypeNames except the sentinel ChannelTypeUnknown (0) and ChannelTypeDummy (terminal count marker). The result is sorted in ascending order so callers get a stable UI ordering.

Types

type AdminChannelCreateInput added in v0.0.13

type AdminChannelCreateInput struct {
	Name                string
	PublicDisplayName   string
	Status              int
	Type                int
	Key                 string
	BaseURL             string
	Models              []string
	ModelMapping        map[string]string
	Weight              uint
	Priority            int
	UseLegacyAdaptor    bool
	SupportedAPITypes   string
	Endpoints           string
	PassthroughEnabled  bool
	SystemPrompt        string
	SystemPromptInInput bool
	RoleMapping         string
	ProxyURL            string
	ParamOverride       string
	HeaderOverride      string
	Tag                 string
	Remark              string
	Setting             string
	Organization        string
	APIVersion          string
	TestModel           string
	AutoBan             int
	StatusCodeMapping   string
	OtherSettings       string
	DisableKeepalive    bool
	Resilience          models.ChannelResilience
	PriceRatio          float64
	Free                bool
	Limit               models.ChannelLimit
	Affinity            models.ChannelAffinity
}

type BatchEditRequest added in v0.0.15

type BatchEditRequest struct {
	IDs    []int64        `json:"ids" binding:"required"`
	Fields map[string]any `json:"fields" binding:"required"`
}

type BatchEditResponse added in v0.0.15

type BatchEditResponse struct {
	UpdatedCount int    `json:"updated_count"`
	UpdatedIDs   []uint `json:"updated_ids"`
}

type ChannelBatchEditor added in v0.0.15

type ChannelBatchEditor struct {
	Bus    app.EventBus
	Logger *zap.Logger
}

func (ChannelBatchEditor) Edit added in v0.0.15

func (e ChannelBatchEditor) Edit(
	ctx context.Context,
	daoCtx dao.Context,
	ids []uint,
	patch ChannelPatch,
) ([]models.Channel, error)

type ChannelPatch added in v0.0.15

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

func ParseChannelPatch added in v0.0.15

func ParseChannelPatch(fields map[string]any) (ChannelPatch, error)

func (ChannelPatch) Apply added in v0.0.15

func (patch ChannelPatch) Apply(channel *models.Channel) error

func (ChannelPatch) Assignments added in v0.0.15

func (patch ChannelPatch) Assignments() map[string]any

func (ChannelPatch) Empty added in v0.0.15

func (patch ChannelPatch) Empty() bool

type CreateRequest

type CreateRequest struct {
	Name                string                    `json:"name" binding:"required"`
	PublicDisplayName   string                    `json:"public_display_name"`
	Type                int                       `json:"type"`
	Key                 string                    `json:"key"`
	BaseURL             string                    `json:"base_url"`
	Models              string                    `json:"models"`
	ModelMapping        string                    `json:"model_mapping"`
	Weight              uint                      `json:"weight"`
	Priority            int                       `json:"priority"`
	UseLegacyAdaptor    bool                      `json:"use_legacy_adaptor"`
	SupportedAPITypes   string                    `json:"supported_api_types"`
	Endpoints           string                    `json:"endpoints"`
	PassthroughEnabled  bool                      `json:"passthrough_enabled"`
	SystemPrompt        string                    `json:"system_prompt"`
	SystemPromptInInput bool                      `json:"system_prompt_in_input"`
	RoleMapping         string                    `json:"role_mapping"`
	ProxyURL            string                    `json:"proxy_url"`
	ParamOverride       string                    `json:"param_override"`
	HeaderOverride      string                    `json:"header_override"`
	Tag                 string                    `json:"tag"`
	Remark              string                    `json:"remark"`
	Setting             string                    `json:"setting"`
	Organization        string                    `json:"organization"`
	ApiVersion          string                    `json:"api_version"`
	TestModel           string                    `json:"test_model"`
	AutoBan             int                       `json:"auto_ban"`
	StatusCodeMapping   string                    `json:"status_code_mapping"`
	OtherSettings       string                    `json:"other_settings"`
	Resilience          *models.ChannelResilience `json:"resilience,omitempty"`
	PriceRatio          *float64                  `json:"price_ratio,omitempty"`
	Free                *bool                     `json:"free,omitempty"`
	Limit               *models.ChannelLimit      `json:"limit,omitempty"`
	Affinity            *models.ChannelAffinity   `json:"affinity,omitempty"`
	DisableKeepalive    bool                      `json:"disable_keepalive"`
}

type DataFlowResponse added in v0.0.8

type DataFlowResponse struct {
	ChannelID        uint              `json:"channel_id"`
	ResolvedProtocol string            `json:"resolved_protocol"`
	Steps            []DataFlowStepDTO `json:"steps"`
}

type DataFlowStepDTO added in v0.0.8

type DataFlowStepDTO struct {
	Key       string `json:"key"`
	Title     string `json:"title"`
	ConfigRef string `json:"config_ref"`
	Active    bool   `json:"active"`
	Detail    string `json:"detail,omitempty"`
}

type ExportFilter added in v0.0.13

type ExportFilter struct {
	Search string `json:"search"`
	Type   string `json:"type"`
	Status string `json:"status"`
}

type ExportRequest added in v0.0.13

type ExportRequest = channelfile.ExportRequest[ExportFilter]

type FetchModelsRequest

type FetchModelsRequest struct {
	BaseURL   string `json:"base_url"`
	Key       string `json:"key" binding:"required"`
	Type      int    `json:"type"`
	Endpoints string `json:"endpoints"`
	ProxyURL  string `json:"proxy_url"`
	AgentID   string `json:"agent_id"`
}

type FetchModelsResponse

type FetchModelsResponse struct {
	Models []string `json:"models"`
	Error  string   `json:"error,omitempty"`
}

type Handler

type Handler struct {
	Hub interface {
		Call(agentID string, method string, params any, timeout time.Duration) (json.RawMessage, error)
		IsOnline(agentID string) bool
	}
	// MasterListen is the master server's listen address (e.g. ":8140" or
	// "0.0.0.0:8140"). Used by the local channel test path to construct a
	// loopback URL (http://127.0.0.1:<port>/...) so the test request hits
	// master's own relay routes without going through any reverse proxy.
	MasterListen string

	// AgentStore is the embedded agent's cache store. When set, the local
	// channel test path calls SetToken on it to warm the __system_test__
	// token (apply-if-present push semantics do not warm new tokens).
	// This field is set by the master server after setupEmbeddedAgent completes.
	// Unused (nil) when the local path is not used (remote agent tests).
	AgentStore app.Store
}

func (*Handler) BatchEdit added in v0.0.15

func (h *Handler) BatchEdit(c *app.Context, req BatchEditRequest) (BatchEditResponse, error)

func (*Handler) Create

func (h *Handler) Create(c *app.Context, req CreateRequest) (api.Created[models.Channel], error)

func (*Handler) DataFlow added in v0.0.8

func (h *Handler) DataFlow(c *app.Context, req api.IDPathRequest) (DataFlowResponse, error)

DataFlow 返回某 channel 的请求处理链路自描述(只读,不计费,不落 usage_log)。

func (*Handler) Delete

func (h *Handler) Delete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)

func (*Handler) ExportHTTP added in v0.0.13

func (h *Handler) ExportHTTP(adapter *api.Adapter) gin.HandlerFunc

func (*Handler) FetchModels

func (h *Handler) FetchModels(c *app.Context, req FetchModelsRequest) (FetchModelsResponse, error)

func (*Handler) Get

func (h *Handler) Get(c *app.Context, req api.IDPathRequest) (models.Channel, error)

func (*Handler) ImportHTTP added in v0.0.13

func (h *Handler) ImportHTTP(adapter *api.Adapter) gin.HandlerFunc

func (*Handler) List

func (*Handler) Test

func (h *Handler) Test(c *app.Context, req TestRequest) (TestResponse, error)

func (*Handler) Types

func (h *Handler) Types(_ *app.Context, _ api.EmptyRequest) ([]TypeMeta, error)

func (*Handler) Update

func (h *Handler) Update(c *app.Context, req UpdateRequest) (models.Channel, error)

type ListRequest

type ListRequest struct {
	api.PaginationQuery
	Search string `form:"search"`
	Type   string `form:"type"`
	Status string `form:"status"`
}

type TestRequest

type TestRequest struct {
	ID           string `uri:"id" binding:"required"`
	Model        string `json:"model"`
	EndpointType string `json:"endpoint_type"`
	Stream       bool   `json:"stream"`
	AgentID      string `json:"agent_id"`
}

type TestResponse

type TestResponse struct {
	Success    bool    `json:"success"`
	StatusCode int     `json:"status_code,omitempty"`
	Response   string  `json:"response,omitempty"`
	Error      string  `json:"error,omitempty"`
	TimeCost   float64 `json:"time_cost"`
	Model      string  `json:"model"`
}

type TokenSetter

type TokenSetter interface {
	SetToken(token *models.Token)
}

TokenSetter is the subset of app.Store needed for system-test token warm-up.

type TypeMeta

type TypeMeta struct {
	ID      int    `json:"id"`
	Name    string `json:"name"`
	I18nKey string `json:"i18n_key"`
}

type UpdateRequest

type UpdateRequest struct {
	ID     string         `uri:"id" binding:"required"`
	Fields map[string]any `json:"-"`
}

func (*UpdateRequest) SetBodyMap

func (r *UpdateRequest) SetBodyMap(fields map[string]any)

Jump to

Keyboard shortcuts

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