@@ -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
},
@@ -616,14 +618,16 @@ func SysHTTPHtml2Text(ctx context.Context, env []string, input string, progress
616
618
617
619
func SysHTTPPost (ctx context.Context , _ []string , input string , _ chan <- string ) (_ string , err error ) {
618
620
var params struct {
619
- URL string `json:"url,omitempty"`
620
- Content string `json:"content,omitempty"`
621
- ContentType string `json:"contentType,omitempty"`
621
+ URL string `json:"url,omitempty"`
622
+ Content string `json:"content,omitempty"`
623
+ ContentType string `json:"contentType,omitempty"`
624
+ IncludeResponse string `json:"includeResponse,omitempty"`
622
625
}
623
626
if err := json .Unmarshal ([]byte (input ), & params ); err != nil {
624
627
return invalidArgument (input , err ), nil
625
628
}
626
629
630
+ includeResponse , _ := strconv .ParseBool (params .IncludeResponse )
627
631
params .URL = fixQueries (params .URL )
628
632
629
633
req , err := http .NewRequestWithContext (ctx , http .MethodPost , params .URL , strings .NewReader (params .Content ))
@@ -642,11 +646,30 @@ func SysHTTPPost(ctx context.Context, _ []string, input string, _ chan<- string)
642
646
}
643
647
defer resp .Body .Close ()
644
648
645
- _ , _ = io .ReadAll (resp .Body )
649
+ var (
650
+ rawData []byte
651
+ outputData string
652
+ )
653
+
654
+ rawData , err = io .ReadAll (resp .Body )
655
+ if includeResponse && err != nil {
656
+ rawData = []byte (err .Error ())
657
+ }
658
+ if includeResponse {
659
+ outputData = strings .TrimSpace (string (rawData ))
660
+ }
661
+
646
662
if resp .StatusCode > 399 {
663
+ if includeResponse && len (outputData ) > 0 {
664
+ return fmt .Sprintf ("Failed to post URL %s: %s (cause: %s)" , params .URL , resp .Status , outputData ), nil
665
+ }
647
666
return fmt .Sprintf ("Failed to post URL %s: %s" , params .URL , resp .Status ), nil
648
667
}
649
668
669
+ if includeResponse && len (outputData ) > 0 {
670
+ return outputData , nil
671
+ }
672
+
650
673
return fmt .Sprintf ("Wrote %d to %s" , len ([]byte (params .Content )), params .URL ), nil
651
674
}
652
675
0 commit comments