Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
fixes for proxying. move cors stuff into cloud for now.
Dane Schneider21dc7ab680e8
diff --git a/app/server/main.go b/app/server/main.goindex 6c3e094e..033f2b8c 100644--- a/app/server/main.go+++ b/app/server/main.go@@ -15,8 +15,8 @@ func main() {r := mux.NewRouter()routes.AddHealthRoutes(r)routes.AddApiRoutes(r)-+ routes.AddProxyableApiRoutes(r)setup.MustLoadIp()setup.MustInitDb()- setup.StartServer(r)+ setup.StartServer(r, nil)}diff --git a/app/server/model/plan/state.go b/app/server/model/plan/state.goindex 93a1e7ea..8c68c4ac 100644--- a/app/server/model/plan/state.go+++ b/app/server/model/plan/state.go@@ -83,6 +83,8 @@ func CreateActivePlan(orgId, userId, planId, branch, prompt string, buildOnly, a}func DeleteActivePlan(orgId, userId, planId, branch string) {+ log.Printf("Deleting active plan %s - %s - %s\n", planId, branch, orgId)+ctx, cancelFn := context.WithCancel(context.Background())repoLockId, err := db.LockRepo(@@ -115,10 +117,14 @@ func DeleteActivePlan(orgId, userId, planId, branch string) {}activePlans.Delete(strings.Join([]string{planId, branch}, "|"))++ log.Printf("Deleted active plan %s - %s - %s\n", planId, branch, orgId)}func UpdateActivePlan(planId, branch string, fn func(*types.ActivePlan)) {+ log.Printf("Updating active plan %s - %s\n", planId, branch)activePlans.Update(strings.Join([]string{planId, branch}, "|"), fn)+ log.Printf("Updated active plan %s - %s\n", planId, branch)}func SubscribePlan(planId, branch string) (string, chan string) {diff --git a/app/server/routes/routes.go b/app/server/routes/routes.goindex 4ce45301..21cd2297 100644--- a/app/server/routes/routes.go+++ b/app/server/routes/routes.go@@ -54,6 +54,14 @@ func AddApiRoutesWithPrefix(r *mux.Router, prefix string) {addApiRoutes(r, prefix)}+func AddProxyableApiRoutes(r *mux.Router) {+ addProxyableApiRoutes(r, "")+}++func AddProxyableApiRoutesWithPrefix(r *mux.Router, prefix string) {+ addProxyableApiRoutes(r, prefix)+}+func addApiRoutes(r *mux.Router, prefix string) {r.HandleFunc(prefix+"/accounts/email_verifications", handlers.CreateEmailVerificationHandler).Methods("POST")r.HandleFunc(prefix+"/accounts/email_verifications/check_pin", handlers.CheckEmailPinHandler).Methods("POST")@@ -94,14 +102,6 @@ func addApiRoutes(r *mux.Router, prefix string) {r.HandleFunc(prefix+"/plans/{planId}", handlers.GetPlanHandler).Methods("GET")r.HandleFunc(prefix+"/plans/{planId}", handlers.DeletePlanHandler).Methods("DELETE")- r.HandleFunc(prefix+"/plans/{planId}/{branch}/tell", handlers.TellPlanHandler).Methods("POST")-- r.HandleFunc(prefix+"/plans/{planId}/{branch}/respond_missing_file", handlers.RespondMissingFileHandler).Methods("POST")-- r.HandleFunc(prefix+"/plans/{planId}/{branch}/build", handlers.BuildPlanHandler).Methods("PATCH")- r.HandleFunc(prefix+"/plans/{planId}/{branch}/connect", handlers.ConnectPlanHandler).Methods("PATCH")- r.HandleFunc(prefix+"/plans/{planId}/{branch}/stop", handlers.StopPlanHandler).Methods("DELETE")-r.HandleFunc(prefix+"/plans/{planId}/{branch}/current_plan", handlers.CurrentPlanHandler).Methods("GET")r.HandleFunc(prefix+"/plans/{planId}/{branch}/apply", handlers.ApplyPlanHandler).Methods("PATCH")r.HandleFunc(prefix+"/plans/{planId}/archive", handlers.ArchivePlanHandler).Methods("PATCH")@@ -132,6 +132,9 @@ func addApiRoutes(r *mux.Router, prefix string) {r.HandleFunc(prefix+"/plans/{planId}/{branch}/status", handlers.GetPlanStatusHandler).Methods("GET")+ r.HandleFunc(prefix+"/plans/{planId}/{branch}/tell", handlers.TellPlanHandler).Methods("POST")+ r.HandleFunc(prefix+"/plans/{planId}/{branch}/build", handlers.BuildPlanHandler).Methods("PATCH")+r.HandleFunc(prefix+"/custom_models", handlers.ListCustomModelsHandler).Methods("GET")r.HandleFunc(prefix+"/custom_models", handlers.CreateCustomModelHandler).Methods("POST")r.HandleFunc(prefix+"/custom_models/{modelId}", handlers.DeleteAvailableModelHandler).Methods("DELETE")@@ -146,11 +149,18 @@ func addApiRoutes(r *mux.Router, prefix string) {r.HandleFunc(prefix+"/file_map", handlers.GetFileMapHandler).Methods("POST")r.HandleFunc(prefix+"/plans/{planId}/{branch}/load_cached_file_map", handlers.LoadCachedFileMapHandler).Methods("POST")- r.HandleFunc(prefix+"/plans/{planId}/{branch}/auto_load_context", handlers.AutoLoadContextHandler).Methods("POST")-r.HandleFunc(prefix+"/plans/{planId}/config", handlers.GetPlanConfigHandler).Methods("GET")r.HandleFunc(prefix+"/plans/{planId}/config", handlers.UpdatePlanConfigHandler).Methods("PUT")r.HandleFunc(prefix+"/default_plan_config", handlers.GetDefaultPlanConfigHandler).Methods("GET")r.HandleFunc(prefix+"/default_plan_config", handlers.UpdateDefaultPlanConfigHandler).Methods("PUT")}++func addProxyableApiRoutes(r *mux.Router, prefix string) {+ r.HandleFunc(prefix+"/plans/{planId}/{branch}/connect", handlers.ConnectPlanHandler).Methods("PATCH")+ r.HandleFunc(prefix+"/plans/{planId}/{branch}/stop", handlers.StopPlanHandler).Methods("DELETE")++ r.HandleFunc(prefix+"/plans/{planId}/{branch}/respond_missing_file", handlers.RespondMissingFileHandler).Methods("POST")++ r.HandleFunc(prefix+"/plans/{planId}/{branch}/auto_load_context", handlers.AutoLoadContextHandler).Methods("POST")+}diff --git a/app/server/setup/setup.go b/app/server/setup/setup.goindex 2050a896..4fadf4f0 100644--- a/app/server/setup/setup.go+++ b/app/server/setup/setup.go@@ -2,7 +2,6 @@ package setupimport ("context"- "fmt""log""net/http""os"@@ -12,8 +11,6 @@ import ("plandex-server/model/plan""syscall""time"-- "github.com/rs/cors")func MustLoadIp() {@@ -61,7 +58,7 @@ func loggingMiddleware(next http.Handler) http.Handler {})}-func StartServer(handler http.Handler) {+func StartServer(handler http.Handler, configureFn func(handler http.Handler) http.Handler) {if os.Getenv("GOENV") == "development" {log.Println("In development mode.")}@@ -88,21 +85,8 @@ func StartServer(handler http.Handler) {// Apply the maxBytesMiddleware to limit request size to 100 MBhandler = maxBytesMiddleware(handler, 100<<20) // 100 MB limit- // Enable CORS based on environment- if os.Getenv("GOENV") == "development" {- handler = cors.New(cors.Options{- AllowedOrigins: []string{"*"},- AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},- AllowedHeaders: []string{"Content-Type", "Authorization"},- AllowCredentials: true,- }).Handler(handler)- } else {- handler = cors.New(cors.Options{- AllowedOrigins: []string{fmt.Sprintf("https://%s.plandex.ai", os.Getenv("APP_SUBDOMAIN"))},- AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},- AllowedHeaders: []string{"Content-Type", "Authorization"},- AllowCredentials: true,- }).Handler(handler)+ if configureFn != nil {+ handler = configureFn(handler)}server := &http.Server{