Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

Merge fixes for cloud-credit-hooks

David Weirichf90046b0182e
diff --cc app/server/handlers/accounts.go
index 927d971b,2f533ad1..4850af97
--- a/app/server/handlers/accounts.go
+++ b/app/server/handlers/accounts.go
@@@ -87,65 -67,17 +67,17 @@@ func CreateAccountHandler(w http.Respon
return
}
+ user := res.User
userId := user.Id
+ token := res.Token
+ orgId := res.OrgId
- // create auth token
- token, authTokenId, err := db.CreateAuthToken(userId, false, tx)
-
- if err != nil {
- log.Printf("Error creating auth token: %v\n", err)
- http.Error(w, "Error creating auth token: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- // update email verification with user and auth token ids
- _, err = tx.Exec("UPDATE email_verifications SET user_id = $1, auth_token_id = $2 WHERE id = $3", userId, authTokenId, emailVerificationId)
-
- if err != nil {
- log.Printf("Error updating email verification: %v\n", err)
- http.Error(w, "Error updating email verification: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- // add to org matching domain if one exists and auto add domain users is true for that org
- org, err := db.GetOrgForDomain(domain)
-
- if err != nil {
- log.Printf("Error getting org for domain: %v\n", err)
- http.Error(w, "Error getting org for domain: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- if org != nil && org.AutoAddDomainUsers {
- // get org owner role id
- orgOwnerRoleId, err := db.GetOrgOwnerRoleId()
-
- if err != nil {
- log.Printf("Error getting org owner role: %v\n", err)
- http.Error(w, "Error getting org owner role: "+err.Error(), http.StatusInternalServerError)
- return
- }
-
- err = db.CreateOrgUser(org.Id, userId, orgOwnerRoleId, tx)
-
- if err != nil {
- log.Printf("Error adding org user: %v\n", err)
- http.Error(w, "Error adding org user: "+err.Error(), http.StatusInternalServerError)
- return
- }
- }
-
- var orgId string
- if org != nil {
- orgId = org.Id
- }
-
- err = hooks.ExecHook(tx, hooks.CreateAccount, hooks.HookParams{
- W: w,
- User: &user,
- apiErr := hooks.ExecHook(hooks.CreateAccount, hooks.HookParams{
++ apiErr := hooks.ExecHook(tx, hooks.CreateAccount, hooks.HookParams{
+ User: user,
OrgId: orgId,
})
- if err != nil {
+ if apiErr != nil {
+ WriteApiError(w, *apiErr)
return
}
diff --cc app/server/handlers/plans_crud.go
index 03562e95,1c9c30f3..0c54cfac
--- a/app/server/handlers/plans_crud.go
+++ b/app/server/handlers/plans_crud.go
@@@ -40,8 -40,9 +40,9 @@@ func CreatePlanHandler(w http.ResponseW
return
}
- err := hooks.ExecHook(nil, hooks.WillCreatePlan, hooks.HookParams{W: w, User: auth.User})
- if err != nil {
- apiErr := hooks.ExecHook(hooks.WillCreatePlan, hooks.HookParams{User: auth.User})
++ apiErr := hooks.ExecHook(nil, hooks.WillCreatePlan, hooks.HookParams{User: auth.User})
+ if apiErr != nil {
+ WriteApiError(w, *apiErr)
return
}
diff --cc app/server/handlers/plans_exec.go
index 607374d8,bf4c97cd..b0bf50a6
--- a/app/server/handlers/plans_exec.go
+++ b/app/server/handlers/plans_exec.go
@@@ -62,8 -62,7 +62,7 @@@ func TellPlanHandler(w http.ResponseWri
return
}
- err = hooks.ExecHook(nil, hooks.WillTellPlan, hooks.HookParams{
- W: w,
- apiErr := hooks.ExecHook(hooks.WillTellPlan, hooks.HookParams{
++ apiErr := hooks.ExecHook(nil, hooks.WillTellPlan, hooks.HookParams{
User: auth.User,
Plan: plan,
})
diff --cc app/server/hooks/hooks.go
index 91792c64,fac1fb62..ed6f621c
--- a/app/server/hooks/hooks.go
+++ b/app/server/hooks/hooks.go
@@@ -1,32 -1,46 +1,53 @@@
package hooks
import (
- "net/http"
"plandex-server/db"
+ "github.com/jmoiron/sqlx"
"github.com/plandex/plandex/shared"
)
const (
- CreateAccount = "create_account"
- WillCreatePlan = "will_create_plan"
- WillTellPlan = "will_tell_plan"
- WillExecPlan = "will_exec_plan"
+ CreateAccount = "create_account"
+ WillCreatePlan = "will_create_plan"
+ WillTellPlan = "will_tell_plan"
+ WillExecPlan = "will_exec_plan"
+ WillSendModelRequest = "will_send_model_request"
+ DidSendModelRequest = "did_send_model_request"
+
+ CreateOrg = "create_org"
)
+ type WillSendModelRequestParams struct {
+ InputTokens int
+ OutputTokens int
+ ModelName string
+ }
+
+ type DidSendModelRequestParams struct {
+ InputTokens int
+ OutputTokens int
+ ModelName string
+ ModelProvider shared.ModelProvider
+ ModelRole shared.ModelRole
+ ModelPackName string
+ Purpose string
+ }
+
++type CreateHookRequestParams struct {
++ Org *db.Org
++}
++
type HookParams struct {
- W http.ResponseWriter
- User *db.User
- OrgId string
- Org *db.Org
- Plan *db.Plan
- StreamDoneCh chan *shared.ApiError
+ User *db.User
+ OrgId string
+ Plan *db.Plan
+
+ WillSendModelRequestParams *WillSendModelRequestParams
+ DidSendModelRequestParams *DidSendModelRequestParams
}
- type Hook func(tx *sqlx.Tx, params HookParams) error
-type Hook func(params HookParams) *shared.ApiError
++type Hook func(tx *sqlx.Tx, params HookParams) *shared.ApiError
var hooks = make(map[string]Hook)
@@@ -34,7 -48,7 +55,7 @@@ func RegisterHook(name string, hook Hoo
hooks[name] = hook
}
- func ExecHook(tx *sqlx.Tx, name string, params HookParams) error {
-func ExecHook(name string, params HookParams) *shared.ApiError {
++func ExecHook(tx *sqlx.Tx, name string, params HookParams) *shared.ApiError {
hook, ok := hooks[name]
if !ok {
return nil
diff --cc app/server/model/plan/tell_exec.go
index 471bd381,5452d326..1de6f29d
--- a/app/server/model/plan/tell_exec.go
+++ b/app/server/model/plan/tell_exec.go
@@@ -68,13 -68,12 +68,12 @@@ func execTellPlan
}
if missingFileResponse == "" {
- err := hooks.ExecHook(nil, hooks.WillExecPlan, hooks.HookParams{
- User: auth.User,
- Plan: plan,
- StreamDoneCh: active.StreamDoneCh,
- apiErr := hooks.ExecHook(hooks.WillExecPlan, hooks.HookParams{
++ apiErr := hooks.ExecHook(nil, hooks.WillExecPlan, hooks.HookParams{
+ User: auth.User,
+ Plan: plan,
})
- if err != nil {
+ if apiErr != nil {
return
}
}