update agent
This commit is contained in:
parent
1737419aed
commit
d83f2eb749
@ -70,13 +70,28 @@ func (s *Server) handleConfigUIState(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
root, _ := readUIRootConfig(s.agentCfg.ConfigPath)
|
root, _ := readUIRootConfig(s.agentCfg.ConfigPath)
|
||||||
|
|
||||||
// Force templates/instances-only view.
|
// Force templates/instances-only view.
|
||||||
|
// templates = union(current templates, built-in templates)
|
||||||
|
tplKeys := map[string]bool{}
|
||||||
|
for k := range root.Templates {
|
||||||
|
tplKeys[k] = true
|
||||||
|
}
|
||||||
|
for k := range uiTemplates() {
|
||||||
|
tplKeys[k] = true
|
||||||
|
}
|
||||||
|
mergedTpls := make([]string, 0, len(tplKeys))
|
||||||
|
for k := range tplKeys {
|
||||||
|
mergedTpls = append(mergedTpls, k)
|
||||||
|
}
|
||||||
|
sort.Strings(mergedTpls)
|
||||||
|
|
||||||
resp := map[string]any{
|
resp := map[string]any{
|
||||||
"ok": true,
|
"ok": true,
|
||||||
"global": root.Global,
|
"global": root.Global,
|
||||||
"queue": root.Queue,
|
"queue": root.Queue,
|
||||||
"instances": root.Instances,
|
"instances": root.Instances,
|
||||||
"templates": sortedKeys(uiTemplates()),
|
"templates": mergedTpls,
|
||||||
}
|
}
|
||||||
writeJSON(w, http.StatusOK, resp)
|
writeJSON(w, http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
@ -145,7 +160,18 @@ func (s *Server) planUIConfig(req uiPlanRequest) (uiPlanResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
warnings := []string{}
|
warnings := []string{}
|
||||||
tpls := uiTemplates()
|
|
||||||
|
// Allow both built-in templates and templates already present in the current config.
|
||||||
|
// Merge rule: keep existing templates as-is; add built-in templates if missing.
|
||||||
|
tpls := map[string]any{}
|
||||||
|
for k, v := range cur.Templates {
|
||||||
|
tpls[k] = v
|
||||||
|
}
|
||||||
|
for k, v := range uiTemplates() {
|
||||||
|
if _, ok := tpls[k]; !ok {
|
||||||
|
tpls[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
seen := map[string]bool{}
|
seen := map[string]bool{}
|
||||||
for i := range req.Instances {
|
for i := range req.Instances {
|
||||||
@ -239,6 +265,11 @@ func readUIRootConfig(path string) (uiRootConfig, error) {
|
|||||||
b, err := os.ReadFile(path)
|
b, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
// Return a well-formed empty state.
|
||||||
|
out.Instances = []UIInstance{}
|
||||||
|
out.Global = map[string]any{}
|
||||||
|
out.Queue = map[string]any{}
|
||||||
|
out.Templates = map[string]any{}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
@ -253,6 +284,9 @@ func readUIRootConfig(path string) (uiRootConfig, error) {
|
|||||||
if out.Queue == nil {
|
if out.Queue == nil {
|
||||||
out.Queue = map[string]any{}
|
out.Queue = map[string]any{}
|
||||||
}
|
}
|
||||||
|
if out.Templates == nil {
|
||||||
|
out.Templates = map[string]any{}
|
||||||
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user