@@ -15,6 +15,7 @@ import (
15
15
"path/filepath"
16
16
"runtime"
17
17
"sort"
18
+ "strconv"
18
19
"strings"
19
20
"time"
20
21
@@ -137,7 +138,8 @@ var tools = map[string]types.Tool{
137
138
Arguments : types .ObjectSchema (
138
139
"url" , "The URL to POST to" ,
139
140
"content" , "The content to POST" ,
140
- "contentType" , "The \" content type\" of the content such as application/json or text/plain" ),
141
+ "contentType" , "The \" content type\" of the content such as application/json or text/plain" ,
142
+ "includeResponse" , "true/false, include POST response to output. Default false" ),
141
143
},
142
144
BuiltinFunc : SysHTTPPost ,
143
145
},
@@ -622,14 +624,16 @@ func SysHTTPHtml2Text(ctx context.Context, env []string, input string, progress
622
624
623
625
func SysHTTPPost (ctx context.Context , _ []string , input string , _ chan <- string ) (_ string , err error ) {
624
626
var params struct {
625
- URL string `json:"url,omitempty"`
626
- Content string `json:"content,omitempty"`
627
- ContentType string `json:"contentType,omitempty"`
627
+ URL string `json:"url,omitempty"`
628
+ Content string `json:"content,omitempty"`
629
+ ContentType string `json:"contentType,omitempty"`
630
+ IncludeResponse string `json:"includeResponse,omitempty"`
628
631
}
629
632
if err := json .Unmarshal ([]byte (input ), & params ); err != nil {
630
633
return invalidArgument (input , err ), nil
631
634
}
632
635
636
+ includeResponse , _ := strconv .ParseBool (params .IncludeResponse )
633
637
params .URL = fixQueries (params .URL )
634
638
635
639
req , err := http .NewRequestWithContext (ctx , http .MethodPost , params .URL , strings .NewReader (params .Content ))
@@ -648,11 +652,30 @@ func SysHTTPPost(ctx context.Context, _ []string, input string, _ chan<- string)
648
652
}
649
653
defer resp .Body .Close ()
650
654
651
- _ , _ = io .ReadAll (resp .Body )
655
+ var (
656
+ rawData []byte
657
+ outputData string
658
+ )
659
+
660
+ rawData , err = io .ReadAll (resp .Body )
661
+ if includeResponse && err != nil {
662
+ rawData = []byte (err .Error ())
663
+ }
664
+ if includeResponse {
665
+ outputData = strings .TrimSpace (string (rawData ))
666
+ }
667
+
652
668
if resp .StatusCode > 399 {
669
+ if includeResponse && len (outputData ) > 0 {
670
+ return fmt .Sprintf ("Failed to post URL %s: %s (cause: %s)" , params .URL , resp .Status , outputData ), nil
671
+ }
653
672
return fmt .Sprintf ("Failed to post URL %s: %s" , params .URL , resp .Status ), nil
654
673
}
655
674
675
+ if includeResponse && len (outputData ) > 0 {
676
+ return outputData , nil
677
+ }
678
+
656
679
return fmt .Sprintf ("Wrote %d to %s" , len ([]byte (params .Content )), params .URL ), nil
657
680
}
658
681
0 commit comments