32 lines
788 B
Go
32 lines
788 B
Go
|
|
package agent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
type capabilityRouteDecision struct {
|
||
|
|
NeedSkills bool `json:"need_skills"`
|
||
|
|
SelectedTools []string `json:"selected_tools"`
|
||
|
|
SelectedSkills []string `json:"selected_skills"`
|
||
|
|
Reason string `json:"reason"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func parseCapabilityRoute(raw string) (capabilityRouteDecision, error) {
|
||
|
|
raw = normalizeJSON(raw)
|
||
|
|
start := strings.Index(raw, "{")
|
||
|
|
end := strings.LastIndex(raw, "}")
|
||
|
|
if start < 0 || end < start {
|
||
|
|
return capabilityRouteDecision{}, fmt.Errorf("no json object found")
|
||
|
|
}
|
||
|
|
raw = raw[start : end+1]
|
||
|
|
|
||
|
|
var out capabilityRouteDecision
|
||
|
|
if err := json.Unmarshal([]byte(raw), &out); err != nil {
|
||
|
|
return capabilityRouteDecision{}, err
|
||
|
|
}
|
||
|
|
out.Reason = strings.TrimSpace(out.Reason)
|
||
|
|
return out, nil
|
||
|
|
}
|