Skip to content

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

Refactor client initialization to return auth vars

Dane Schneiderab177d637471
diff --git a/app/server/handlers/client_helper.go b/app/server/handlers/client_helper.go
index 29cf5488..ae6ca9a3 100644
--- a/app/server/handlers/client_helper.go
+++ b/app/server/handlers/client_helper.go
@@ -3,6 +3,7 @@ package handlers
import (
"log"
"net/http"
+ "os"
"plandex-server/db"
"plandex-server/hooks"
"plandex-server/model"
@@ -21,7 +22,12 @@ type initClientsParams struct {
plan *db.Plan
}
-func initClients(params initClientsParams) map[string]model.ClientInfo {
+type initClientsResult struct {
+ clients map[string]model.ClientInfo
+ authVars map[string]string
+}
+
+func initClients(params initClientsParams) initClientsResult {
w := params.w
var authVars map[string]string
@@ -45,19 +51,22 @@ func initClients(params initClientsParams) map[string]model.ClientInfo {
if apiErr != nil {
log.Printf("Error getting integrated models: %v\n", apiErr)
http.Error(w, "Error getting integrated models", http.StatusInternalServerError)
- return nil
+ return initClientsResult{}
}
if hookResult.GetIntegratedModelsResult != nil && hookResult.GetIntegratedModelsResult.IntegratedModelsMode {
authVars = hookResult.GetIntegratedModelsResult.AuthVars
}
- if len(authVars) == 0 {
+ if len(authVars) == 0 && os.Getenv("IS_CLOUD") != "" {
log.Println("No api keys/credentials provided for models")
http.Error(w, "No api keys/credentials provided for models", http.StatusBadRequest)
- return nil
+ return initClientsResult{}
}
clients := model.InitClients(authVars)
- return clients
+ return initClientsResult{
+ clients: clients,
+ authVars: authVars,
+ }
}
diff --git a/app/server/handlers/context_helper.go b/app/server/handlers/context_helper.go
index cb15dfbc..626440c3 100644
--- a/app/server/handlers/context_helper.go
+++ b/app/server/handlers/context_helper.go
@@ -102,7 +102,7 @@ func loadContexts(
return nil, nil
}
- clients = initClients(
+ res := initClients(
initClientsParams{
w: w,
auth: auth,
@@ -113,7 +113,8 @@ func loadContexts(
},
)
- authVars = context.AuthVars
+ clients = res.clients
+ authVars = res.authVars
break
}
@@ -146,7 +147,16 @@ func loadContexts(
}
}()
- name, err := model.GenPipedDataName(r.Context(), auth, plan, settings, clients, authVars, context.Body, context.SessionId)
+ name, err := model.GenPipedDataName(model.GenPipedDataNameParams{
+ Ctx: r.Context(),
+ Auth: auth,
+ Plan: plan,
+ Settings: settings,
+ AuthVars: authVars,
+ SessionId: context.SessionId,
+ Clients: clients,
+ PipedContent: context.Body,
+ })
if err != nil {
errCh <- fmt.Errorf("error generating name for piped data: %v", err)