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
Add session ID tracking for model requests and usage analytics
Dane Schneider9b0cab48e937
diff --git a/app/cli/lib/repl.go b/app/cli/lib/repl.goindex 9a6bc464..c618b004 100644--- a/app/cli/lib/repl.go+++ b/app/cli/lib/repl.go@@ -143,8 +143,8 @@ func ExecPlandexCommand(args []string) (string, error) {}type ExecPlandexCommandParams struct {- Args []stringDisableSuggestions bool+ SessionId string}func ExecPlandexCommandWithParams(args []string, params ExecPlandexCommandParams) (string, error) {@@ -179,6 +179,10 @@ func ExecPlandexCommandWithParams(args []string, params ExecPlandexCommandParams"GLAMOUR_STYLE="+glamourStyle,"PLANDEX_SKIP_UPGRADE=1",)++ if params.SessionId != "" {+ env = append(env, "PLANDEX_REPL_SESSION_ID="+params.SessionId)+ }}if params.DisableSuggestions {diff --git a/app/cli/plan_exec/tell.go b/app/cli/plan_exec/tell.goindex a7619f13..c9f64f8c 100644--- a/app/cli/plan_exec/tell.go+++ b/app/cli/plan_exec/tell.go@@ -157,6 +157,7 @@ func TellPlan(OpenAIOrgId: openAIOrgId,IsImplementationOfChat: isImplementationOfChat,IsGitRepo: isGitRepo,+ SessionId: os.Getenv("PLANDEX_REPL_SESSION_ID"),}, stream.OnStreamPlan)term.StopSpinner()diff --git a/app/server/db/data_models.go b/app/server/db/data_models.goindex 366e0deb..c0e0dd54 100644--- a/app/server/db/data_models.go+++ b/app/server/db/data_models.go@@ -296,19 +296,20 @@ type repoLock struct {}type ModelPack struct {- Id string `db:"id"`- OrgId string `db:"org_id"`- Name string `db:"name"`- Description string `db:"description"`- Planner shared.PlannerRoleConfig `db:"planner"`- Coder *shared.ModelRoleConfig `db:"coder"`- PlanSummary shared.ModelRoleConfig `db:"plan_summary"`- Builder shared.ModelRoleConfig `db:"builder"`- Namer shared.ModelRoleConfig `db:"namer"`- CommitMsg shared.ModelRoleConfig `db:"commit_msg"`- ExecStatus shared.ModelRoleConfig `db:"exec_status"`- Architect *shared.ModelRoleConfig `db:"context_loader"`- CreatedAt time.Time `db:"created_at"`+ Id string `db:"id"`+ OrgId string `db:"org_id"`+ Name string `db:"name"`+ Description string `db:"description"`+ Planner shared.PlannerRoleConfig `db:"planner"`+ Coder *shared.ModelRoleConfig `db:"coder"`+ PlanSummary shared.ModelRoleConfig `db:"plan_summary"`+ Builder shared.ModelRoleConfig `db:"builder"`+ WholeFileBuilder *shared.ModelRoleConfig `db:"whole_file_builder"`+ Namer shared.ModelRoleConfig `db:"namer"`+ CommitMsg shared.ModelRoleConfig `db:"commit_msg"`+ ExecStatus shared.ModelRoleConfig `db:"exec_status"`+ Architect *shared.ModelRoleConfig `db:"context_loader"`+ CreatedAt time.Time `db:"created_at"`}func (modelPack *ModelPack) ToApi() *shared.ModelPack {@@ -453,21 +454,22 @@ func (context *Context) ToApi() *shared.Context {}type ConvoMessage struct {- Id string `json:"id"`- OrgId string `json:"orgId"`- PlanId string `json:"planId"`- UserId string `json:"userId"`- Role string `json:"role"`- Tokens int `json:"tokens"`- Num int `json:"num"`- Message string `json:"message"`- Stopped bool `json:"stopped"`- Subtask *Subtask `json:"subtask,omitempty"`- AddedSubtasks []*Subtask `json:"addedSubtasks,omitempty"`- RemovedSubtasks []string `json:"removedSubtasks,omitempty"`- Flags shared.ConvoMessageFlags `json:"flags"`- ActivatedPaths map[string]bool `json:"activatedPaths,omitempty"`- CreatedAt time.Time `json:"createdAt"`+ Id string `json:"id"`+ OrgId string `json:"orgId"`+ PlanId string `json:"planId"`+ UserId string `json:"userId"`+ Role string `json:"role"`+ Tokens int `json:"tokens"`+ Num int `json:"num"`+ Message string `json:"message"`+ Stopped bool `json:"stopped"`+ Subtask *Subtask `json:"subtask,omitempty"`+ AddedSubtasks []*Subtask `json:"addedSubtasks,omitempty"`+ RemovedSubtasks []string `json:"removedSubtasks,omitempty"`+ Flags shared.ConvoMessageFlags `json:"flags"`+ ActivatedPaths map[string]bool `json:"activatePaths,omitempty"`+ ActivatedPathsOrdered []string `json:"activatePathsOrdered,omitempty"`+ CreatedAt time.Time `json:"createdAt"`}func (msg *ConvoMessage) ToApi() *shared.ConvoMessage {diff --git a/app/shared/req_res.go b/app/shared/req_res.goindex c51bbb5f..78f7df83 100644--- a/app/shared/req_res.go+++ b/app/shared/req_res.go@@ -4,6 +4,7 @@ import ("time""github.com/sashabaranov/go-openai"+ "github.com/shopspring/decimal")type CreateEmailVerificationRequest struct {@@ -137,6 +138,7 @@ type TellPlanRequest struct {ProjectPaths map[string]bool `json:"projectPaths"`IsImplementationOfChat bool `json:"isImplementationOfChat"`IsGitRepo bool `json:"isGitRepo"`+ SessionId string `json:"sessionId"`}type BuildPlanRequest struct {@@ -147,6 +149,7 @@ type BuildPlanRequest struct {OpenAIBase string `json:"openAIBase"`OpenAIOrgId string `json:"openAIOrgId"`ProjectPaths map[string]bool `json:"projectPaths"`+ SessionId string `json:"sessionId"`}const NoBuildsErr string = "No builds"@@ -182,6 +185,7 @@ type LoadContextParams struct {ApiKeys map[string]string `json:"apiKeys"`OpenAIBase string `json:"openAIBase"`OpenAIOrgId string `json:"openAIOrgId"`+ SessionId string `json:"sessionId"`}type LoadContextRequest []*LoadContextParams@@ -299,6 +303,7 @@ type ApplyPlanRequest struct {ApiKeys map[string]string `json:"apiKeys"`OpenAIBase string `json:"openAIBase"`OpenAIOrgId string `json:"openAIOrgId"`+ SessionId string `json:"sessionId"`}type RenamePlanRequest struct {@@ -312,12 +317,33 @@ type GetBuildStatusResponse struct {// Cloud requests and responsestype CreditsLogRequest struct {- PageSize int `json:"pageSize"`- Page int `json:"page"`+ TransactionType CreditsTransactionType `json:"transactionType"`+ PlanId string `json:"planId"`+ SessionId string `json:"sessionId"`+ DayStart *time.Time `json:"dayStart"`+ Month bool `json:"month"`}type CreditsLogResponse struct {- Transactions []*CreditsTransaction `json:"transactions"`- NumPages int `json:"numPages"`- NumPagesMax bool `json:"numPagesMax"`+ Transactions []*CreditsTransaction `json:"transactions"`+ NumPages int `json:"numPages"`+ NumPagesMax bool `json:"numPagesMax"`+ MonthStart time.Time `json:"monthStart"`+ PlanNamesById map[string]string `json:"planNamesById"`+}++type CreditsSummaryResponse struct {+ Balance decimal.Decimal `json:"balance"`++ TotalSpend decimal.Decimal `json:"totalSpend"`++ MonthStart time.Time `json:"monthStart"`++ ByPlanId map[string]decimal.Decimal `json:"byPlanId"`+ PlanNamesById map[string]string `json:"planNamesById"`++ ByModelName map[string]decimal.Decimal `json:"byModelName"`+ ByPurpose map[string]decimal.Decimal `json:"byPurpose"`++ CacheSavings decimal.Decimal `json:"cacheSavings"`}