Documentation
¶
Index ¶
- Constants
- func RoutingWalkKey(r *models.ModelRouting) string
- type CandidatesResponse
- type CreateRequest
- type EffectiveWeight
- type GetResponse
- type Handler
- func (h *Handler) Candidates(c *app.Context, _ struct{}) (CandidatesResponse, error)
- func (h *Handler) Create(c *app.Context, req CreateRequest) (models.ModelRouting, error)
- func (h *Handler) Delete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)
- func (h *Handler) Get(c *app.Context, req api.IDPathRequest) (GetResponse, error)
- func (h *Handler) List(c *app.Context, req ListRequest) (api.PaginatedResponse[models.ModelRouting], error)
- func (h *Handler) PortalCreate(c *app.Context, req CreateRequest) (models.ModelRouting, error)
- func (h *Handler) PortalDelete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)
- func (h *Handler) PortalGet(c *app.Context, req api.IDPathRequest) (GetResponse, error)
- func (h *Handler) PortalGlobalRoutingNames(c *app.Context, _ struct{}) (RoutingNamesResp, error)
- func (h *Handler) PortalList(c *app.Context, req ListRequest) (api.PaginatedResponse[models.ModelRouting], error)
- func (h *Handler) PortalUpdate(c *app.Context, req UpdateRequest) (models.ModelRouting, error)
- func (h *Handler) Preview(c *app.Context, req PreviewRequest) (PreviewResponse, error)
- func (h *Handler) TokenCreate(c *app.Context, req TokenRoutingCreateRequest) (models.ModelRouting, error)
- func (h *Handler) TokenDelete(c *app.Context, req TokenRoutingPathRequest) (api.StatusResponse, error)
- func (h *Handler) TokenGet(c *app.Context, req TokenRoutingPathRequest) (GetResponse, error)
- func (h *Handler) TokenList(c *app.Context, req TokenRoutingListRequest) (api.PaginatedResponse[models.ModelRouting], error)
- func (h *Handler) TokenPreview(c *app.Context, req TokenRoutingPreviewRequest) (PreviewResponse, error)
- func (h *Handler) TokenUpdate(c *app.Context, req TokenRoutingUpdateRequest) (models.ModelRouting, error)
- func (h *Handler) Update(c *app.Context, req UpdateRequest) (models.ModelRouting, error)
- type ListRequest
- type MemberInput
- type PreviewNode
- type PreviewRequest
- type PreviewResponse
- type RoutingNamesResp
- type RoutingTargetFinder
- type RoutingWalkIssue
- type RoutingWalkNode
- type RoutingWalkNodeKind
- type RoutingWalkRequest
- type RoutingWalkRoute
- type TokenRoutingCreateRequest
- type TokenRoutingListRequest
- type TokenRoutingPathRequest
- type TokenRoutingPreviewRequest
- type TokenRoutingUpdateRequest
- type UpdateRequest
Constants ¶
const RoutingWalkMaxDepth = 5
Variables ¶
This section is empty.
Functions ¶
func RoutingWalkKey ¶ added in v0.0.15
func RoutingWalkKey(r *models.ModelRouting) string
RoutingWalkKey returns a stable path identity for a concrete routing row.
Types ¶
type CandidatesResponse ¶
type CandidatesResponse struct {
Models []string `json:"models"`
GlobalRoutings []string `json:"global_routings"`
}
CandidatesResponse 是 admin 端 GET /admin/model-routings/candidates 的响应。 user portal 改用 RoutingNamesResp(见 PortalGlobalRoutingNames)。
type CreateRequest ¶
type EffectiveWeight ¶
EffectiveWeight 表示某个真实 model 的最终权重百分比。
type GetResponse ¶
type GetResponse struct {
models.ModelRouting
ExpandedModels []string `json:"expanded_models"`
}
GetResponse 在 ModelRouting 基础上附加展开后的真实模型名列表。
type Handler ¶
Handler 是 model-routings 的 admin 路由处理器。
func (*Handler) Candidates ¶
func (h *Handler) Candidates(c *app.Context, _ struct{}) (CandidatesResponse, error)
func (*Handler) Create ¶
func (h *Handler) Create(c *app.Context, req CreateRequest) (models.ModelRouting, error)
func (*Handler) Delete ¶
func (h *Handler) Delete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)
func (*Handler) Get ¶
func (h *Handler) Get(c *app.Context, req api.IDPathRequest) (GetResponse, error)
func (*Handler) List ¶
func (h *Handler) List(c *app.Context, req ListRequest) (api.PaginatedResponse[models.ModelRouting], error)
func (*Handler) PortalCreate ¶
func (h *Handler) PortalCreate(c *app.Context, req CreateRequest) (models.ModelRouting, error)
PortalCreate 强制 scope=user, user_id=current,忽略客户端传入的这两个字段。
func (*Handler) PortalDelete ¶
func (h *Handler) PortalDelete(c *app.Context, req api.IDPathRequest) (api.StatusResponse, error)
PortalDelete 仅允许删除自己的 routing。
func (*Handler) PortalGet ¶
func (h *Handler) PortalGet(c *app.Context, req api.IDPathRequest) (GetResponse, error)
PortalGet 返回单条 routing;越权访问其他用户的 routing 返回 404 (404 而非 403:避免泄露 routing 是否存在的信息)。
func (*Handler) PortalGlobalRoutingNames ¶
func (h *Handler) PortalGlobalRoutingNames(c *app.Context, _ struct{}) (RoutingNamesResp, error)
PortalGlobalRoutingNames 返回所有 enabled global routing 名(升序)。 用户作用域的 routing 不在此处暴露——它们由 PortalList 列出。 真实 model 候选不再由后端计算:前端用所选 token 直接调 /v1/models 取得, 与运行时过滤逻辑(internal/agent/relay/models.go:33)共用同一真相源。
func (*Handler) PortalList ¶
func (h *Handler) PortalList(c *app.Context, req ListRequest) (api.PaginatedResponse[models.ModelRouting], error)
PortalList 列出当前用户可管理的 routings: scope=user + user_id=current(不含 global,global 只读,不在 portal 管理范围)。
func (*Handler) PortalUpdate ¶
func (h *Handler) PortalUpdate(c *app.Context, req UpdateRequest) (models.ModelRouting, error)
PortalUpdate 仅允许更新自己的 routing;scope/user_id/id 字段被剥离,不可被客户端修改。
func (*Handler) Preview ¶
func (h *Handler) Preview(c *app.Context, req PreviewRequest) (PreviewResponse, error)
func (*Handler) TokenCreate ¶ added in v0.0.13
func (h *Handler) TokenCreate(c *app.Context, req TokenRoutingCreateRequest) (models.ModelRouting, error)
func (*Handler) TokenDelete ¶ added in v0.0.13
func (h *Handler) TokenDelete(c *app.Context, req TokenRoutingPathRequest) (api.StatusResponse, error)
func (*Handler) TokenGet ¶ added in v0.0.13
func (h *Handler) TokenGet(c *app.Context, req TokenRoutingPathRequest) (GetResponse, error)
func (*Handler) TokenList ¶ added in v0.0.13
func (h *Handler) TokenList(c *app.Context, req TokenRoutingListRequest) (api.PaginatedResponse[models.ModelRouting], error)
func (*Handler) TokenPreview ¶ added in v0.0.13
func (h *Handler) TokenPreview(c *app.Context, req TokenRoutingPreviewRequest) (PreviewResponse, error)
func (*Handler) TokenUpdate ¶ added in v0.0.13
func (h *Handler) TokenUpdate(c *app.Context, req TokenRoutingUpdateRequest) (models.ModelRouting, error)
func (*Handler) Update ¶
func (h *Handler) Update(c *app.Context, req UpdateRequest) (models.ModelRouting, error)
type ListRequest ¶
type MemberInput ¶
type PreviewNode ¶
type PreviewNode struct {
Ref string `json:"ref"`
Kind string `json:"kind"` // model | routing | invalid
Scope string `json:"scope,omitempty"` // routing 节点的 scope
Priority int `json:"priority"`
Weight int `json:"weight"`
EffectivePct float64 `json:"effective_pct"`
Children []PreviewNode `json:"children,omitempty"`
Error string `json:"error,omitempty"` // not_found | disabled | cycle | max_depth
}
PreviewNode 是预览树的一个节点。 kind=routing 时是中间节点(含 children),kind=model 时是叶子。
type PreviewRequest ¶
type PreviewRequest struct {
Members []MemberInput `json:"members" binding:"required"`
SelfName string `json:"self_name"`
SelfScope string `json:"self_scope"`
SelfUserID uint `json:"self_user_id"`
}
type PreviewResponse ¶
type PreviewResponse struct {
Root PreviewNode `json:"root"`
EffectiveWeights []EffectiveWeight `json:"effective_weights"`
Warnings []string `json:"warnings"`
}
PreviewResponse 是 preview 接口的响应结构。
type RoutingNamesResp ¶
type RoutingNamesResp struct {
Names []string `json:"names"`
}
RoutingNamesResp 是 PortalGlobalRoutingNames 的响应:仅含 enabled global routing 名称(升序)。
type RoutingTargetFinder ¶ added in v0.0.15
type RoutingTargetFinder interface {
FindEnabledRouting(ref string) (RoutingWalkRoute, bool, error)
FindDisabledRouting(ref string) (RoutingWalkRoute, bool, error)
HasRealModel(ref string) bool
}
RoutingTargetFinder is the strategy boundary between pure traversal and the caller's indexes/parsing policy. Marketplace uses strict JSON parsing; administrator preview keeps its existing best-effort behavior.
type RoutingWalkIssue ¶ added in v0.0.15
type RoutingWalkIssue string
const ( RoutingWalkIssueCycle RoutingWalkIssue = "cycle" RoutingWalkIssueMaxDepth RoutingWalkIssue = "max_depth" RoutingWalkIssueDisabled RoutingWalkIssue = "disabled" RoutingWalkIssueNotFound RoutingWalkIssue = "not_found" )
type RoutingWalkNode ¶ added in v0.0.15
type RoutingWalkNode struct {
Ref string
Kind RoutingWalkNodeKind
RouteKey string
Scope string
Priority int
Weight int
EffectivePercent float64
Children []RoutingWalkNode
Issue RoutingWalkIssue
}
RoutingWalkNode is the shared internal traversal result. It deliberately retains administrator diagnostics; ordinary marketplace responses must map it into their own allowlist DTO instead of serializing this type.
func WalkRoutingDestinations ¶ added in v0.0.15
func WalkRoutingDestinations( request RoutingWalkRequest, targets RoutingTargetFinder, ) ([]RoutingWalkNode, error)
WalkRoutingDestinations traverses all priority groups deterministically. The effective percentage is retained solely for the administrator preview; the marketplace visitor ignores it and exposes every possible terminal offer.
type RoutingWalkNodeKind ¶ added in v0.0.15
type RoutingWalkNodeKind string
const ( RoutingWalkNodeModel RoutingWalkNodeKind = "model" RoutingWalkNodeRouting RoutingWalkNodeKind = "routing" RoutingWalkNodeInvalid RoutingWalkNodeKind = "invalid" )
type RoutingWalkRequest ¶ added in v0.0.15
type RoutingWalkRequest struct {
RootRouteKey string
Members []models.RoutingMember
}
type RoutingWalkRoute ¶ added in v0.0.15
type RoutingWalkRoute struct {
Key string
Scope string
Members []models.RoutingMember
}
RoutingWalkRoute is the minimum routing definition needed by the pure walk. Key identifies the concrete route row, so a user route and global route with the same name do not become a false cycle.
type TokenRoutingCreateRequest ¶ added in v0.0.13
type TokenRoutingCreateRequest struct {
TokenID string `uri:"id" binding:"required" json:"-"`
Name string `json:"name" binding:"required"`
Members []MemberInput `json:"members" binding:"required"`
Enabled bool `json:"enabled"`
Remark string `json:"remark"`
BodyScope *string `json:"scope"`
BodyUserID *uint `json:"user_id"`
BodyTokenID *uint `json:"token_id"`
}
type TokenRoutingListRequest ¶ added in v0.0.13
type TokenRoutingListRequest struct {
api.PaginationQuery
TokenID string `uri:"id" binding:"required"`
Q string `form:"q"`
}
type TokenRoutingPathRequest ¶ added in v0.0.13
type TokenRoutingPreviewRequest ¶ added in v0.0.13
type TokenRoutingPreviewRequest struct {
TokenID string `uri:"id" binding:"required" json:"-"`
PreviewRequest
BodyScope *string `json:"scope"`
BodyUserID *uint `json:"user_id"`
BodyTokenID *uint `json:"token_id"`
}
type TokenRoutingUpdateRequest ¶ added in v0.0.13
type TokenRoutingUpdateRequest struct {
TokenRoutingPathRequest
Fields map[string]any `json:"-"`
}
func (*TokenRoutingUpdateRequest) SetBodyMap ¶ added in v0.0.13
func (r *TokenRoutingUpdateRequest) SetBodyMap(fs map[string]any)
type UpdateRequest ¶
type UpdateRequest struct {
ID string `uri:"id" binding:"required"`
Fields map[string]any `json:"-"`
}
func (*UpdateRequest) SetBodyMap ¶
func (r *UpdateRequest) SetBodyMap(fs map[string]any)