47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
// Package route 维护逻辑模型/能力槽位到候选端点的路由注册表。
|
|
// M0 为单一 stub 端点的静态表;候选迭代、健康冷却与故障切换按
|
|
// docs/architecture/shenshi-gateway.md §4 于 M4 落地。
|
|
package route
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"hunjing/shenshi/internal/transform"
|
|
)
|
|
|
|
// Endpoint 一个可路由的出站端点:类型 + 适配器实例。
|
|
type Endpoint struct {
|
|
Type string
|
|
Adaptor transform.Adaptor
|
|
Priority int
|
|
}
|
|
|
|
// Registry 槽位 → 候选端点列表(按 Priority 升序尝试)。
|
|
type Registry struct {
|
|
bySlot map[string][]Endpoint
|
|
}
|
|
|
|
// New 构建注册表并登记默认端点。
|
|
func New() *Registry {
|
|
r := &Registry{bySlot: make(map[string][]Endpoint)}
|
|
r.Register("chat", Endpoint{Type: "stub", Adaptor: transform.StubAdaptor{}, Priority: 100})
|
|
return r
|
|
}
|
|
|
|
// Register 登记端点到指定能力槽位(契约词典 §14.1 model_slot 取值)。
|
|
func (r *Registry) Register(slot string, ep Endpoint) {
|
|
r.bySlot[slot] = append(r.bySlot[slot], ep)
|
|
}
|
|
|
|
// Resolve 返回槽位的候选端点;无候选即错误(HJ-2001 语义)。
|
|
func (r *Registry) Resolve(slot string) ([]Endpoint, error) {
|
|
if slot == "" {
|
|
slot = "chat"
|
|
}
|
|
eps := r.bySlot[slot]
|
|
if len(eps) == 0 {
|
|
return nil, fmt.Errorf("槽位 %s 无可用端点", slot)
|
|
}
|
|
return eps, nil
|
|
}
|