Expose governance APIs for workflow selection/termination and allow login pages to read registration policy without admin credentials. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"chat-agent-system/internal/workflowdef"
|
|
)
|
|
|
|
type workflowCatalogItem struct {
|
|
Key string `json:"key"`
|
|
Name string `json:"name"`
|
|
LatestVersion int `json:"latest_version"`
|
|
ProductDomain string `json:"product_domain,omitempty"`
|
|
}
|
|
|
|
func (s *Server) handleWorkflowCatalog(w http.ResponseWriter, r *http.Request) {
|
|
if s.wfDefSvc == nil || !s.wfDefSvc.Available() {
|
|
http.Error(w, `{"error":"ERR_NOT_AVAILABLE","message":"workflow catalog unavailable"}`, http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
defs, err := s.wfDefSvc.Store().ListProjectSelectableDefinitions(r.Context())
|
|
if err != nil {
|
|
http.Error(w, `{"error":"ERR_INTERNAL","message":"`+err.Error()+`"}`, http.StatusInternalServerError)
|
|
return
|
|
}
|
|
items := make([]workflowCatalogItem, 0, len(workflowdef.OfficialWorkflowKeys()))
|
|
seen := map[string]bool{}
|
|
for _, d := range defs {
|
|
if !workflowdef.IsOfficialWorkflowKey(d.Key) || seen[d.Key] {
|
|
continue
|
|
}
|
|
seen[d.Key] = true
|
|
name := d.Name
|
|
if name == "" {
|
|
name = workflowdef.OfficialWorkflowName(d.Key)
|
|
}
|
|
items = append(items, workflowCatalogItem{
|
|
Key: d.Key,
|
|
Name: name,
|
|
LatestVersion: d.LatestPublishedVersion,
|
|
ProductDomain: d.ProductDomain,
|
|
})
|
|
}
|
|
for _, key := range workflowdef.OfficialWorkflowKeys() {
|
|
if seen[key] {
|
|
continue
|
|
}
|
|
items = append(items, workflowCatalogItem{
|
|
Key: key,
|
|
Name: workflowdef.OfficialWorkflowName(key),
|
|
})
|
|
}
|
|
writeJSONResponse(w, http.StatusOK, map[string]any{"workflows": items})
|
|
}
|