M0:神识 Go 网关骨架(IR 入站/SSE 出站/stub 适配器/服务令牌/健康检查)及测试与镜像

This commit is contained in:
chenxin committed 2026-08-21 22:01:41 +08:00
1 parent 7ef3a15061
commit f3058a64c3
10 files changed
+514

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
// 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
}