@@ -15,6 +15,7 @@ import (
15
15
"time"
16
16
17
17
"github.com/acorn-io/broadcaster"
18
+ "github.com/acorn-io/gptscript/pkg/builtin"
18
19
"github.com/acorn-io/gptscript/pkg/loader"
19
20
"github.com/acorn-io/gptscript/pkg/runner"
20
21
"github.com/acorn-io/gptscript/pkg/types"
@@ -85,12 +86,30 @@ var (
85
86
type execKey struct {}
86
87
87
88
func (s * Server ) list (rw http.ResponseWriter , req * http.Request ) {
89
+ rw .Header ().Set ("Content-Type" , "application/json" )
90
+ enc := json .NewEncoder (rw )
91
+ enc .SetIndent ("" , " " )
92
+
88
93
path := filepath .Join ("." , req .URL .Path )
94
+ if req .URL .Path == "/sys" {
95
+ _ = enc .Encode (builtin .SysProgram ())
96
+ return
97
+ } else if strings .HasSuffix (path , ".gpt" ) {
98
+ prg , err := loader .Program (req .Context (), path , "" )
99
+ if err != nil {
100
+ http .Error (rw , err .Error (), http .StatusInternalServerError )
101
+ return
102
+ }
103
+ _ = enc .Encode (prg )
104
+ return
105
+ }
106
+
89
107
files , err := os .ReadDir (path )
90
108
if err != nil {
91
109
http .Error (rw , err .Error (), http .StatusInternalServerError )
92
110
return
93
111
}
112
+
94
113
var result []string
95
114
for _ , file := range files {
96
115
if file .IsDir () && ! strings .HasPrefix (file .Name (), "." ) {
@@ -100,8 +119,6 @@ func (s *Server) list(rw http.ResponseWriter, req *http.Request) {
100
119
}
101
120
}
102
121
103
- enc := json .NewEncoder (rw )
104
- enc .SetIndent ("" , " " )
105
122
_ = enc .Encode (result )
106
123
}
107
124
@@ -186,7 +203,7 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
186
203
case http .MethodPost :
187
204
s .run (rw , req )
188
205
case http .MethodGet :
189
- if strings .Contains (strings .ToLower (req .Header .Get ("Connection" )), "upgrade" ) {
206
+ if req . URL . Path == "/" && strings .Contains (strings .ToLower (req .Header .Get ("Connection" )), "upgrade" ) {
190
207
err := s .melody .HandleRequest (rw , req )
191
208
if err != nil {
192
209
http .Error (rw , err .Error (), http .StatusInternalServerError )
@@ -244,7 +261,7 @@ func (s *Session) Stop(output string, err error) {
244
261
e := Event {
245
262
Event : runner.Event {
246
263
Time : time .Now (),
247
- Type : "runEnd " ,
264
+ Type : "runFinish " ,
248
265
},
249
266
RunID : s .id ,
250
267
Input : s .input ,
0 commit comments