From 1a51fdb73adc828d40352df9f865cb60fe0cec1e Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Tue, 20 Aug 2024 12:04:33 -0400 Subject: [PATCH 1/2] enhance: pretty-print JSON arguments for OpenAPI operations Signed-off-by: Grant Linville --- pkg/types/toolstring.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/types/toolstring.go b/pkg/types/toolstring.go index 9d6d765b..10f39c8e 100644 --- a/pkg/types/toolstring.go +++ b/pkg/types/toolstring.go @@ -79,7 +79,16 @@ func ToSysDisplayString(id string, args map[string]string) (string, error) { return "", nil case "sys.openapi": if os.Getenv("GPTSCRIPT_OPENAPI_REVAMP") == "true" && args["operation"] != "" { - return fmt.Sprintf("Running API operation `%s` with arguments %s", args["operation"], args["args"]), nil + // Pretty print the JSON by unmarshaling and marshaling it + var jsonArgs map[string]interface{} + if err := json.Unmarshal([]byte(args["args"]), &jsonArgs); err != nil { + return "", err + } + jsonPretty, err := json.MarshalIndent(jsonArgs, "", " ") + if err != nil { + return "", err + } + return fmt.Sprintf("Running API operation `%s` with arguments %s", args["operation"], string(jsonPretty)), nil } fallthrough default: From 260bbead45487d0e2766043d8978156b7f9632f6 Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Tue, 20 Aug 2024 12:14:09 -0400 Subject: [PATCH 2/2] PR feedback Signed-off-by: Grant Linville --- pkg/types/toolstring.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/types/toolstring.go b/pkg/types/toolstring.go index 10f39c8e..086ad043 100644 --- a/pkg/types/toolstring.go +++ b/pkg/types/toolstring.go @@ -80,7 +80,7 @@ func ToSysDisplayString(id string, args map[string]string) (string, error) { case "sys.openapi": if os.Getenv("GPTSCRIPT_OPENAPI_REVAMP") == "true" && args["operation"] != "" { // Pretty print the JSON by unmarshaling and marshaling it - var jsonArgs map[string]interface{} + var jsonArgs map[string]any if err := json.Unmarshal([]byte(args["args"]), &jsonArgs); err != nil { return "", err }