@@ -19,6 +19,7 @@ import (
19
19
"github.com/gptscript-ai/gptscript/pkg/loader"
20
20
"github.com/gptscript-ai/gptscript/pkg/runner"
21
21
"github.com/gptscript-ai/gptscript/pkg/types"
22
+ "github.com/gptscript-ai/gptscript/static"
22
23
"github.com/olahol/melody"
23
24
"github.com/rs/cors"
24
25
)
@@ -169,10 +170,10 @@ func (s *Server) run(rw http.ResponseWriter, req *http.Request) {
169
170
}
170
171
171
172
id := fmt .Sprint (atomic .AddInt64 (& execID , 1 ))
172
- ctx := context .WithValue (req .Context (), execKey {}, id )
173
173
if req .URL .Query ().Has ("async" ) {
174
+ ctx := context .WithValue (s .ctx , execKey {}, id )
174
175
go func () {
175
- _ , _ = runner .Run (s . ctx , prg , os .Environ (), string (body ))
176
+ _ , _ = runner .Run (ctx , prg , os .Environ (), string (body ))
176
177
}()
177
178
rw .Header ().Set ("Content-Type" , "application/json" )
178
179
err := json .NewEncoder (rw ).Encode (map [string ]any {
@@ -182,6 +183,7 @@ func (s *Server) run(rw http.ResponseWriter, req *http.Request) {
182
183
http .Error (rw , err .Error (), http .StatusInternalServerError )
183
184
}
184
185
} else {
186
+ ctx := context .WithValue (req .Context (), execKey {}, id )
185
187
out , err := runner .Run (ctx , prg , os .Environ (), string (body ))
186
188
if err == nil {
187
189
_ , _ = rw .Write ([]byte (out ))
@@ -228,6 +230,18 @@ func (s *Server) Connect(session *melody.Session) {
228
230
}
229
231
230
232
func (s * Server ) ServeHTTP (rw http.ResponseWriter , req * http.Request ) {
233
+ if strings .HasPrefix (req .URL .Path , "/ui" ) {
234
+ path := req .URL .Path
235
+ if path == "/ui" || path == "/ui/" {
236
+ path = "/ui/index.html"
237
+ }
238
+ if _ , err := fs .Stat (static .UI , path [1 :]); errors .Is (err , fs .ErrNotExist ) {
239
+ path = "/ui/index.html"
240
+ }
241
+ http .ServeFileFS (rw , req , static .UI , path )
242
+ return
243
+ }
244
+
231
245
switch req .Method {
232
246
case http .MethodPost :
233
247
s .run (rw , req )
0 commit comments