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
tying up auto-continue
Dane Schneider9ada37ae885b
diff --git a/app/cli/api/errors.go b/app/cli/api/errors.goindex add9455d..9ce5ae62 100644--- a/app/cli/api/errors.go+++ b/app/cli/api/errors.go@@ -2,7 +2,6 @@ package apiimport ("encoding/json"- "fmt""log""net/http""plandex/auth"@@ -37,7 +36,7 @@ func refreshTokenIfNeeded(apiErr *shared.ApiError) (bool, *shared.ApiError) {if apiErr.Type == shared.ApiErrorTypeInvalidToken {err := auth.RefreshInvalidToken()if err != nil {- return false, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: fmt.Sprintf("error refreshing invalid token")}+ return false, &shared.ApiError{Type: shared.ApiErrorTypeOther, Msg: "error refreshing invalid token"}}return true, nil}diff --git a/app/server/handlers/plans_crud.go b/app/server/handlers/plans_crud.goindex 5ba73190..4647719a 100644--- a/app/server/handlers/plans_crud.go+++ b/app/server/handlers/plans_crud.go@@ -14,8 +14,6 @@ import ("github.com/plandex/plandex/shared")-const TrialMaxPlans = 10-func CreatePlanHandler(w http.ResponseWriter, r *http.Request) {log.Println("Received request for CreatePlanHandler")@@ -49,13 +47,13 @@ func CreatePlanHandler(w http.ResponseWriter, r *http.Request) {}if user.IsTrial {- if user.NumNonDraftPlans >= TrialMaxPlans {+ if user.NumNonDraftPlans >= types.TrialMaxPlans {writeApiError(w, shared.ApiError{Type: shared.ApiErrorTypeTrialPlansExceeded,Status: http.StatusForbidden,Msg: "User has reached max number of free trial plans",TrialPlansExceededError: &shared.TrialPlansExceededError{- MaxPlans: TrialMaxPlans,+ MaxPlans: types.TrialMaxPlans,},})returndiff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.goindex 0cd7b235..b68c8815 100644--- a/app/server/handlers/plans_exec.go+++ b/app/server/handlers/plans_exec.go@@ -69,13 +69,13 @@ func TellPlanHandler(w http.ResponseWriter, r *http.Request) {}if user.IsTrial {- if plan.TotalMessages >= TrialMaxMessages {+ if plan.TotalMessages >= types.TrialMaxMessages {writeApiError(w, shared.ApiError{Type: shared.ApiErrorTypeTrialMessagesExceeded,Status: http.StatusForbidden,Msg: "Free trial message limit exceeded",TrialMessagesExceededError: &shared.TrialMessagesExceededError{- MaxMessages: TrialMaxMessages,+ MaxMessages: types.TrialMaxMessages,},})returndiff --git a/app/server/model/plan/build.go b/app/server/model/plan/build.goindex d940c002..300f53c8 100644--- a/app/server/model/plan/build.go+++ b/app/server/model/plan/build.go@@ -6,6 +6,7 @@ import ("fmt""log""math"+ "net/http""plandex-server/db""plandex-server/model""plandex-server/model/prompts"@@ -108,7 +109,11 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuilerr := <-errChif err != nil {log.Printf("Error building plan %s: %v\n", planId, err)- activePlan.StreamDoneCh <- err+ activePlan.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: err.Error(),+ }return}}@@ -128,7 +133,11 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuilerr := db.StorePlanResult(planRes)if err != nil {log.Printf("Error storing plan result: %v\n", err)- activePlan.StreamDoneCh <- err+ activePlan.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error storing plan result: " + err.Error(),+ }return}@@ -154,7 +163,11 @@ func execPlanBuild(currentOrgId string, activePlan *types.ActivePlan, activeBuilactiveBuild.Error = err- activePlan.StreamDoneCh <- err+ activePlan.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: err.Error(),+ }if err != nil {log.Printf("Error storing plan error result: %v\n", err)diff --git a/app/server/model/plan/state.go b/app/server/model/plan/state.goindex 1861d0b4..edb1c571 100644--- a/app/server/model/plan/state.go+++ b/app/server/model/plan/state.go@@ -25,7 +25,7 @@ func CreateActivePlan(planId, prompt string) *types.ActivePlan {if err == nil {log.Printf("Plan %s stream completed successfully", planId)- err = db.SetPlanStatus(planId, shared.PlanStatusFinished, "")+ err := db.SetPlanStatus(planId, shared.PlanStatusFinished, "")if err != nil {log.Printf("Error setting plan %s status to ready: %v\n", planId, err)}@@ -33,7 +33,7 @@ func CreateActivePlan(planId, prompt string) *types.ActivePlan {} else {log.Printf("Error streaming plan %s: %v\n", planId, err)- err = db.SetPlanStatus(planId, shared.PlanStatusError, err.Error())+ err := db.SetPlanStatus(planId, shared.PlanStatusError, err.Msg)if err != nil {log.Printf("Error setting plan %s status to error: %v\n", planId, err)}diff --git a/app/server/model/plan/tell.go b/app/server/model/plan/tell.goindex 1822fba8..2604e0b8 100644--- a/app/server/model/plan/tell.go+++ b/app/server/model/plan/tell.go@@ -4,6 +4,8 @@ import ("errors""fmt""log"+ "net/http"+ "os""strings""time"@@ -47,11 +49,32 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqcurrentUserId := auth.User.IdcurrentOrgId := auth.OrgId+ if os.Getenv("IS_CLOUD") != "" {+ if auth.User.IsTrial {+ if plan.TotalMessages >= types.TrialMaxMessages {+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeTrialMessagesExceeded,+ Status: http.StatusForbidden,+ Msg: "Free trial message limit exceeded",+ TrialMessagesExceededError: &shared.TrialMessagesExceededError{+ MaxMessages: types.TrialMaxMessages,+ },+ }+ return+ }+ }+ }+planId := plan.Iderr := db.SetPlanStatus(planId, shared.PlanStatusReplying, "")if err != nil {log.Printf("Error setting plan %s status to replying: %v\n", planId, err)- active.StreamDoneCh <- fmt.Errorf("error setting plan status to replying: %v", err)+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error setting plan status to replying",+ }+return}@@ -154,7 +177,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqfor i := 0; i < 4; i++ {err := <-errChif err != nil {- active.StreamDoneCh <- fmt.Errorf("error getting plan, context, convo, or summaries: %v", err)+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error getting plan, context, convo, or summaries",+ }return}}@@ -174,7 +201,12 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqif err != nil {err = fmt.Errorf("error formatting model modelContext: %v", err)log.Println(err)- active.StreamDoneCh <- err++ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error formatting model modelContext",+ }return}@@ -192,7 +224,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqif err != nil {err = fmt.Errorf("error getting number of tokens in prompt: %v", err)log.Println(err)- active.StreamDoneCh <- err+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error getting number of tokens in prompt",+ }return}@@ -209,7 +245,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReq// token limit already exceeded before adding conversationerr := fmt.Errorf("token limit exceeded before adding conversation")log.Printf("Error: %v\n", err)- active.StreamDoneCh <- err+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Token limit exceeded before adding conversation",+ }return}@@ -253,7 +293,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqif !ok {err := fmt.Errorf("conversation summary timestamp not found in conversation")log.Printf("Error: %v\n", err)- active.StreamDoneCh <- err+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Conversation summary timestamp not found in conversation",+ }return}@@ -275,7 +319,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqif summary == nil {err := errors.New("couldn't get under token limit with conversation summary")log.Printf("Error: %v\n", err)- active.StreamDoneCh <- err+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Couldn't get under token limit with conversation summary",+ }return}}@@ -289,8 +337,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReq}} else {if (tokensBeforeConvo + summary.Tokens) > shared.MaxTokens {- err := fmt.Errorf("token limit still exceeded after summarizing conversation")- active.StreamDoneCh <- err+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Token limit still exceeded after summarizing conversation",+ }return}summarizedToMessageId = summary.LatestConvoMessageId@@ -346,7 +397,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqlog.Println("Token limit exceeded")}- active.StreamDoneCh <- err+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error creating proposal GPT4 stream",+ }return}@@ -373,7 +428,11 @@ func execTellPlan(plan *db.Plan, auth *types.ServerAuth, req *shared.TellPlanReqonError := func(streamErr error, storeDesc bool, convoMessageId, commitMsg string) {log.Printf("\nStream error: %v\n", streamErr)- active.StreamDoneCh <- streamErr+ active.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Stream error: " + streamErr.Error(),+ }storedMessage := falsestoredDesc := falsediff --git a/app/server/types/active_plan.go b/app/server/types/active_plan.goindex 199bc8dc..99d7adec 100644--- a/app/server/types/active_plan.go+++ b/app/server/types/active_plan.go@@ -3,6 +3,7 @@ package typesimport ("context""encoding/json"+ "net/http""plandex-server/db""github.com/google/uuid"@@ -32,7 +33,7 @@ type ActivePlan struct {NumTokens intPromptMessageNum intBuildQueuesByPath map[string][]*ActiveBuild- StreamDoneCh chan error+ StreamDoneCh chan *shared.ApiErrorstreamCh chan stringsubscriptions map[string]chan string@@ -53,7 +54,7 @@ func NewActivePlan(planId, prompt string) *ActivePlan {BuiltFiles: map[string]bool{},streamCh: make(chan string),- StreamDoneCh: make(chan error),+ StreamDoneCh: make(chan *shared.ApiError),subscriptions: map[string]chan string{},}@@ -76,7 +77,11 @@ func NewActivePlan(planId, prompt string) *ActivePlan {func (ap *ActivePlan) Stream(msg shared.StreamMessage) {msgJson, err := json.Marshal(msg)if err != nil {- ap.StreamDoneCh <- err+ ap.StreamDoneCh <- &shared.ApiError{+ Type: shared.ApiErrorTypeOther,+ Status: http.StatusInternalServerError,+ Msg: "Error marshalling stream message: " + err.Error(),+ }return}ap.streamCh <- string(msgJson)diff --git a/app/server/types/trial.go b/app/server/types/trial.gonew file mode 100644index 00000000..86604657--- /dev/null+++ b/app/server/types/trial.go@@ -0,0 +1,4 @@+package types++const TrialMaxMessages = 15+const TrialMaxPlans = 10diff --git a/app/shared/auth.go b/app/shared/auth.goindex 83f5dad9..8d7bf1d8 100644--- a/app/shared/auth.go+++ b/app/shared/auth.go@@ -12,7 +12,8 @@ const (ApiErrorTypeTrialPlansExceeded ApiErrorType = "trial_plans_exceeded"ApiErrorTypeTrialMessagesExceeded ApiErrorType = "trial_messages_exceeded"ApiErrorTypeTrialActionNotAllowed ApiErrorType = "trial_action_not_allowed"- ApiErrorTypeOther ApiErrorType = "other"++ ApiErrorTypeOther ApiErrorType = "other")type TrialPlansExceededError struct {diff --git a/app/shared/stream.go b/app/shared/stream.goindex a8f21156..c6ea3c1f 100644--- a/app/shared/stream.go+++ b/app/shared/stream.go@@ -26,5 +26,5 @@ type StreamMessage struct {ReplyChunk string `json:"replyChunk,omitempty"`BuildInfo *BuildInfo `json:"planTokenCount,omitempty"`Description *ConvoMessageDescription `json:"description,omitempty"`- Error string `json:"error,omitempty"`+ Error *ApiError `json:"error,omitempty"`}