Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/mvl/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SetError() {

func Package() Logger {
_, p, _, _ := runtime.Caller(1)
_, suffix, _ := strings.Cut(p, "gptscript/")
_, suffix, _ := strings.Cut(p, "gptscript")
i := strings.LastIndex(suffix, "/")
if i > 0 {
return New(suffix[:i])
Expand Down
18 changes: 15 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ func New(model engine.Model, opts ...Options) (*Server, error) {

opt := complete(opts)
r, err := runner.New(model, runner.Options{
MonitorFactory: &SessionFactory{
events: events,
},
MonitorFactory: NewSessionFactory(events),
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -84,6 +82,14 @@ var (

type execKey struct{}

func ContextWithNewID(ctx context.Context) context.Context {
return context.WithValue(ctx, execKey{}, fmt.Sprint(atomic.AddInt64(&execID, 1)))
}

func IDFromContext(ctx context.Context) string {
return ctx.Value(execKey{}).(string)
}

func (s *Server) list(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(rw)
Expand Down Expand Up @@ -276,6 +282,12 @@ type SessionFactory struct {
events *broadcaster.Broadcaster[Event]
}

func NewSessionFactory(events *broadcaster.Broadcaster[Event]) *SessionFactory {
return &SessionFactory{
events: events,
}
}

func (s SessionFactory) Start(ctx context.Context, prg *types.Program, env []string, input string) (runner.Monitor, error) {
id, _ := ctx.Value(execKey{}).(string)

Expand Down