@@ -637,13 +637,11 @@ func (api *API) taskSend(rw http.ResponseWriter, r *http.Request) {
637
637
}
638
638
639
639
var reqBody struct {
640
- Body struct {
641
- Content string `json:"content"`
642
- Type string `json:"type"`
643
- }`json:"body"`
640
+ Content string `json:"content"`
641
+ Type string `json:"type"`
644
642
}
645
- reqBody .Body . Content = req .Input
646
- reqBody .Body . Type = "user"
643
+ reqBody .Content = req .Input
644
+ reqBody .Type = "user"
647
645
648
646
req ,err := agentapiNewRequest (ctx ,http .MethodPost ,appURL ,"message" ,reqBody )
649
647
if err != nil {
@@ -666,6 +664,24 @@ func (api *API) taskSend(rw http.ResponseWriter, r *http.Request) {
666
664
Detail :fmt .Sprintf ("Upstream status: %d; Body: %s" ,resp .StatusCode ,body ),
667
665
})
668
666
}
667
+
668
+ // {"$schema":"http://localhost:3284/schemas/MessageResponseBody.json","ok":true}
669
+ // {"$schema":"http://localhost:3284/schemas/ErrorModel.json","title":"Unprocessable Entity","status":422,"detail":"validation failed","errors":[{"location":"body.type","value":"oof"}]}
670
+ var respBody map [string ]any
671
+ if err := json .NewDecoder (resp .Body ).Decode (& respBody );err != nil {
672
+ return httperror .NewResponseError (http .StatusBadGateway , codersdk.Response {
673
+ Message :"Failed to decode task app response body." ,
674
+ Detail :err .Error (),
675
+ })
676
+ }
677
+
678
+ if v ,ok := respBody ["status" ].(string );! ok || v != "ok" {
679
+ return httperror .NewResponseError (http .StatusBadGateway , codersdk.Response {
680
+ Message :"Task app rejected the message." ,
681
+ Detail :fmt .Sprintf ("Upstream response: %v" ,respBody ),
682
+ })
683
+ }
684
+
669
685
return nil
670
686
});err != nil {
671
687
httperror .WriteResponseError (ctx ,rw ,err )
@@ -851,10 +867,9 @@ func agentapiDoStatusRequest(ctx context.Context, client *http.Client, appURL *u
851
867
})
852
868
}
853
869
870
+ // {"$schema":"http://localhost:3284/schemas/StatusResponseBody.json","status":"stable"}
854
871
var respBody struct {
855
- Body struct {
856
- Status string `json:"status"`
857
- }`json:"body"`
872
+ Status string `json:"status"`
858
873
}
859
874
860
875
if err := json .NewDecoder (resp .Body ).Decode (& respBody );err != nil {
@@ -864,5 +879,5 @@ func agentapiDoStatusRequest(ctx context.Context, client *http.Client, appURL *u
864
879
})
865
880
}
866
881
867
- return respBody .Body . Status ,nil
882
+ return respBody .Status ,nil
868
883
}