Skip to content

Commit a387cd8

Browse files
authored
enhance: pretty-print JSON arguments for OpenAPI operations (#808)
Signed-off-by: Grant Linville <[email protected]>
1 parent 1226edb commit a387cd8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/types/toolstring.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ func ToSysDisplayString(id string, args map[string]string) (string, error) {
7979
return "", nil
8080
case "sys.openapi":
8181
if os.Getenv("GPTSCRIPT_OPENAPI_REVAMP") == "true" && args["operation"] != "" {
82-
return fmt.Sprintf("Running API operation `%s` with arguments %s", args["operation"], args["args"]), nil
82+
// Pretty print the JSON by unmarshaling and marshaling it
83+
var jsonArgs map[string]any
84+
if err := json.Unmarshal([]byte(args["args"]), &jsonArgs); err != nil {
85+
return "", err
86+
}
87+
jsonPretty, err := json.MarshalIndent(jsonArgs, "", " ")
88+
if err != nil {
89+
return "", err
90+
}
91+
return fmt.Sprintf("Running API operation `%s` with arguments %s", args["operation"], string(jsonPretty)), nil
8392
}
8493
fallthrough
8594
default:

0 commit comments

Comments
 (0)