fix(prompt-vars): 消除变量目录里与全局变量撞名导致的前端 key 重复
goals 内置 agent 的变量目录里定义了 Now,seed 进 agent_prompt_vars 后,
withGlobalVars 又追加了同名的全局 runtime 变量,getAgent 返回两条 Now →
前端 variables.map 的 key={v.name} 重复,React 报错并可能丢/重渲子节点。
- withGlobalVars: 追加全局变量前剔除同名的库内条目,全局(权威 runtime 定义)
胜出,保证返回列表名字唯一。对所有现存库立即生效,无需迁移。
- db.go: 从 goals 内置目录删掉冗余的 Now(已是全局变量);扩展既有清理 DELETE
一并清掉旧库残留的 'Now' 行(已发版→DB 改动带迁移)。
- 新增 withGlobalVars 去重回归测试。
go build / go vet / go test ./server 全绿。
This commit is contained in:
1 parent
1de7a383cc
commit
9fad543168
3 files changed
+78
-3
No files matched your search
+15
-1
@@ -2008,8 +2008,22 @@ var globalPromptVars = []db.PromptVar{
|
||||
|
||||
// withGlobalVars appends the universal runtime vars onto an agent's own catalog,
|
||||
// so validation / the UI variable list / preview all recognize {{.Now}} etc.
|
||||
// A stored catalog entry that collides with a global name is dropped: the global
|
||||
// runtime var is authoritative (it's what the render path actually resolves), and
|
||||
// this keeps the returned list name-unique so the UI never sees duplicate keys.
|
||||
func withGlobalVars(vars []db.PromptVar) []db.PromptVar {
|
||||
return append(append([]db.PromptVar{}, vars...), globalPromptVars...)
|
||||
globalNames := make(map[string]bool, len(globalPromptVars))
|
||||
for _, g := range globalPromptVars {
|
||||
globalNames[g.Name] = true
|
||||
}
|
||||
out := make([]db.PromptVar, 0, len(vars)+len(globalPromptVars))
|
||||
for _, v := range vars {
|
||||
if globalNames[v.Name] {
|
||||
continue // shadowed by the authoritative global runtime var
|
||||
}
|
||||
out = append(out, v)
|
||||
}
|
||||
return append(out, globalPromptVars...)
|
||||
}
|
||||
|
||||
// validateTemplate parses the template and rejects any {{.Var}} not in the catalog.
|
||||
|
||||
Reference in new issue
Block a user