M4 收口:神识用户面与计量闭环——BYOK/配额三段式/usage 落库/Anthropic+Gemini 适配器/神识阁
- 神识 Go:store 双实现(PG 自动建表+60s 就绪重试 / 内存回退)承载 usage_logs·byok_keys·quota_balances;BYOK 密钥库(AES-GCM 加密、API 脱敏、撤回即失效、主密钥未配置 fail-closed);配额三段式(预扣 max_tokens 钳位 1M→结算实际 token→全败幂等退款,HJ-2004);计量归属(IR user_id→usage_logs,/me/usage 用户维度聚合+配额总览,/admin/usage/sample 对账抽样);Anthropic/Gemini 出站适配器(SSE 解析、system 提升、用量映射);stub 端点补名修复计量空 endpoint - IR 契约:user_id/byok_key_id 双端同步(Go types.go + Py types.py) - 灵台:runs.owner_id(迁移 005,server_default 兼容存量)经 kernel 全链透传为 IR user_id;shenshi_client 扩展用户面方法(X-Hunjing-User-Id 代理,Echo 桩带内存实现);/me/byok-keys 登记·列表·撤回与 /me/usage 端点(4 用例) - 前端神识阁(/models 重建):偏好(生成参数表单)/自带密钥(登记加密保存、脱敏列表、撤回二次确认)/用量(聚合表+配额进度条)三区;me API 库+mock+5 用例;侧栏恢复入口 - 配置与部署:.env.example 增 SHENSHI_DATABASE_URL/SHENSHI_BYOK_MASTER_KEY/SHENSHI_USER_BUDGET_TOKENS;compose 神识容器接自有库(init-shenshi.sql 预建 hunjing_shenshi,与灵台不共库共表) - 证据:Go 34 用例(BYOK 独占/配额拒绝/结算退款/归属聚合)、后端 532、前端 210、BFF 4 全绿;跨进程 E2E 四场景(灵台 HttpShenshiClient→真 Go 神识:登记脱敏/BYOK 独占不可达整体失败/用量归属聚合/撤回即失效)通过;rewrite-plan M4 标记完成、能力矩阵神识行升已验证
This commit is contained in:
1 parent
462d570751
commit
144415247e
51 files changed
+3533
-90
No files matched your search
@@ -54,19 +54,14 @@ func New() *Registry {
|
||||
}
|
||||
specs := loadSpecs()
|
||||
if len(specs) == 0 {
|
||||
r.Register("chat", Endpoint{Type: "stub", Adaptor: transform.StubAdaptor{}, Priority: 100, UpstreamModel: "stub"})
|
||||
r.Register("chat", Endpoint{Name: "stub", Type: "stub", Adaptor: transform.StubAdaptor{}, Priority: 100, UpstreamModel: "stub"})
|
||||
return r
|
||||
}
|
||||
for _, spec := range specs {
|
||||
if spec.Type != "openai_compatible" && spec.Type != "local" {
|
||||
adaptor, ok := BuildAdaptor(spec)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
adaptor := &transform.OpenAICompatAdaptor{
|
||||
EndpointName: spec.Name,
|
||||
BaseURL: spec.BaseURL,
|
||||
APIKey: spec.APIKey,
|
||||
UpstreamModel: spec.Model,
|
||||
}
|
||||
cred := spec.Name
|
||||
if spec.APIKey != "" {
|
||||
cred = spec.Name + ":" + fmt.Sprintf("%x", len(spec.APIKey)) // 不落密钥原文,仅指纹
|
||||
@@ -79,6 +74,29 @@ func New() *Registry {
|
||||
return r
|
||||
}
|
||||
|
||||
// BuildAdaptor 按端点类型构造出站适配器(契约词典 §14.2;BYOK 动态候选复用)。
|
||||
func BuildAdaptor(spec EndpointSpec) (transform.Adaptor, bool) {
|
||||
switch spec.Type {
|
||||
case "openai_compatible", "local":
|
||||
return &transform.OpenAICompatAdaptor{
|
||||
EndpointName: spec.Name, BaseURL: spec.BaseURL,
|
||||
APIKey: spec.APIKey, UpstreamModel: spec.Model,
|
||||
}, true
|
||||
case "anthropic":
|
||||
return &transform.AnthropicAdaptor{
|
||||
EndpointName: spec.Name, BaseURL: spec.BaseURL,
|
||||
APIKey: spec.APIKey, UpstreamModel: spec.Model,
|
||||
}, true
|
||||
case "gemini":
|
||||
return &transform.GeminiAdaptor{
|
||||
EndpointName: spec.Name, BaseURL: spec.BaseURL,
|
||||
APIKey: spec.APIKey, UpstreamModel: spec.Model,
|
||||
}, true
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
func loadSpecs() []EndpointSpec {
|
||||
raw := os.Getenv("SHENSHI_ENDPOINTS")
|
||||
if raw == "" {
|
||||
|
||||
Reference in new issue
Block a user