@@ -19,6 +19,7 @@ import (
1919 "github.com/gptscript-ai/gptscript/pkg/loader"
2020 "github.com/gptscript-ai/gptscript/pkg/runner"
2121 "github.com/gptscript-ai/gptscript/pkg/types"
22+ "github.com/gptscript-ai/gptscript/static"
2223 "github.com/olahol/melody"
2324 "github.com/rs/cors"
2425)
@@ -169,10 +170,10 @@ func (s *Server) run(rw http.ResponseWriter, req *http.Request) {
169170 }
170171
171172 id := fmt .Sprint (atomic .AddInt64 (& execID , 1 ))
172- ctx := context .WithValue (req .Context (), execKey {}, id )
173173 if req .URL .Query ().Has ("async" ) {
174+ ctx := context .WithValue (s .ctx , execKey {}, id )
174175 go func () {
175- _ , _ = runner .Run (s . ctx , prg , os .Environ (), string (body ))
176+ _ , _ = runner .Run (ctx , prg , os .Environ (), string (body ))
176177 }()
177178 rw .Header ().Set ("Content-Type" , "application/json" )
178179 err := json .NewEncoder (rw ).Encode (map [string ]any {
@@ -182,6 +183,7 @@ func (s *Server) run(rw http.ResponseWriter, req *http.Request) {
182183 http .Error (rw , err .Error (), http .StatusInternalServerError )
183184 }
184185 } else {
186+ ctx := context .WithValue (req .Context (), execKey {}, id )
185187 out , err := runner .Run (ctx , prg , os .Environ (), string (body ))
186188 if err == nil {
187189 _ , _ = rw .Write ([]byte (out ))
@@ -228,6 +230,18 @@ func (s *Server) Connect(session *melody.Session) {
228230}
229231
230232func (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+
231245 switch req .Method {
232246 case http .MethodPost :
233247 s .run (rw , req )
0 commit comments