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
Update hooks to use a transaction
David Weirich4207d81b3fbe
diff --git a/app/server/db/data_models.go b/app/server/db/data_models.goindex a8234aec..92264de8 100644--- a/app/server/db/data_models.go+++ b/app/server/db/data_models.go@@ -28,7 +28,6 @@ type Org struct {AutoAddDomainUsers bool `db:"auto_add_domain_users"`OwnerId string `db:"owner_id"`IsTrial bool `db:"is_trial"`- StripeCustomerId *string `db:"stripe_customer_id"`CreatedAt time.Time `db:"created_at"`UpdatedAt time.Time `db:"updated_at"`diff --git a/app/server/handlers/accounts.go b/app/server/handlers/accounts.goindex 51dbb889..927d971b 100644--- a/app/server/handlers/accounts.go+++ b/app/server/handlers/accounts.go@@ -140,7 +140,7 @@ func CreateAccountHandler(w http.ResponseWriter, r *http.Request) {orgId = org.Id}- err = hooks.ExecHook(hooks.CreateAccount, hooks.HookParams{+ err = hooks.ExecHook(tx, hooks.CreateAccount, hooks.HookParams{W: w,User: &user,OrgId: orgId,diff --git a/app/server/handlers/orgs.go b/app/server/handlers/orgs.goindex 1c0e1fa4..3e111f7f 100644--- a/app/server/handlers/orgs.go+++ b/app/server/handlers/orgs.go@@ -128,7 +128,7 @@ func CreateOrgHandler(w http.ResponseWriter, r *http.Request) {}}- err = hooks.ExecHook(hooks.CreateOrg, hooks.HookParams{+ err = hooks.ExecHook(tx, hooks.CreateOrg, hooks.HookParams{W: w,User: auth.User,Org: org,diff --git a/app/server/handlers/plans_crud.go b/app/server/handlers/plans_crud.goindex c89e8af2..03562e95 100644--- a/app/server/handlers/plans_crud.go+++ b/app/server/handlers/plans_crud.go@@ -40,7 +40,7 @@ func CreatePlanHandler(w http.ResponseWriter, r *http.Request) {return}- err := hooks.ExecHook(hooks.WillCreatePlan, hooks.HookParams{W: w, User: auth.User})+ err := hooks.ExecHook(nil, hooks.WillCreatePlan, hooks.HookParams{W: w, User: auth.User})if err != nil {return}diff --git a/app/server/handlers/plans_exec.go b/app/server/handlers/plans_exec.goindex 4b6b17f4..607374d8 100644--- a/app/server/handlers/plans_exec.go+++ b/app/server/handlers/plans_exec.go@@ -62,7 +62,7 @@ func TellPlanHandler(w http.ResponseWriter, r *http.Request) {return}- err = hooks.ExecHook(hooks.WillTellPlan, hooks.HookParams{+ err = hooks.ExecHook(nil, hooks.WillTellPlan, hooks.HookParams{W: w,User: auth.User,Plan: plan,diff --git a/app/server/hooks/hooks.go b/app/server/hooks/hooks.goindex 59636383..91792c64 100644--- a/app/server/hooks/hooks.go+++ b/app/server/hooks/hooks.go@@ -4,6 +4,7 @@ import ("net/http""plandex-server/db"+ "github.com/jmoiron/sqlx""github.com/plandex/plandex/shared")@@ -25,7 +26,7 @@ type HookParams struct {StreamDoneCh chan *shared.ApiError}-type Hook func(params HookParams) error+type Hook func(tx *sqlx.Tx, params HookParams) errorvar hooks = make(map[string]Hook)@@ -33,10 +34,10 @@ func RegisterHook(name string, hook Hook) {hooks[name] = hook}-func ExecHook(name string, params HookParams) error {+func ExecHook(tx *sqlx.Tx, name string, params HookParams) error {hook, ok := hooks[name]if !ok {return nil}- return hook(params)+ return hook(tx, params)}diff --git a/app/server/model/plan/tell_exec.go b/app/server/model/plan/tell_exec.goindex 72317857..471bd381 100644--- a/app/server/model/plan/tell_exec.go+++ b/app/server/model/plan/tell_exec.go@@ -68,7 +68,7 @@ func execTellPlan(}if missingFileResponse == "" {- err := hooks.ExecHook(hooks.WillExecPlan, hooks.HookParams{+ err := hooks.ExecHook(nil, hooks.WillExecPlan, hooks.HookParams{User: auth.User,Plan: plan,StreamDoneCh: active.StreamDoneCh,