@@ -21110,54 +21110,6 @@ func PrepareSingleAction(ctx context.Context, user User, appId string, body []by
2111021110 }
2111121111 }
2111221112
21113- // Fallback to inject AI creds if the user don't have any
21114- if strings.ToLower(app.Name) == "openai" && len(action.AuthenticationId) == 0 {
21115- apiKey := os.Getenv("AI_API_KEY")
21116- if apiKey == "" {
21117- apiKey = os.Getenv("OPENAI_API_KEY")
21118- }
21119-
21120- apiUrl := os.Getenv("AI_API_URL")
21121- if apiUrl == "" {
21122- apiUrl = os.Getenv("OPENAI_API_URL")
21123- }
21124- if apiUrl == "" {
21125- apiUrl = "https://api.openai.com"
21126- }
21127-
21128- if len(apiKey) > 0 {
21129- // TODO: Track actual token usage from response
21130-
21131- urlFound := false
21132- apikeyFound := false
21133- for i, param := range action.Parameters {
21134- if param.Name == "url" {
21135- action.Parameters[i].Value = apiUrl // Don't trust the user provided url, use the one from the env
21136- urlFound = true
21137- }
21138- if param.Name == "apikey" {
21139- action.Parameters[i].Value = apiKey
21140- action.Parameters[i].Configuration = true
21141- apikeyFound = true
21142- }
21143- }
21144- if !urlFound {
21145- action.Parameters = append(action.Parameters, WorkflowAppActionParameter{
21146- Name: "url",
21147- Value: apiUrl,
21148- })
21149- }
21150- if !apikeyFound {
21151- action.Parameters = append(action.Parameters, WorkflowAppActionParameter{
21152- Name: "apikey",
21153- Value: apiKey,
21154- Configuration: true,
21155- })
21156- }
21157- log.Printf("[AUDIT] Injected system OpenAI credentials (fallback) for org %s", user.ActiveOrg.Id)
21158- }
21159- }
21160-
2116121113 if runValidationAction {
2116221114 log.Printf("\n\n[INFO] SHOULD BE Running validation action for %s for org %s (%s)\n\n", app.Name, user.ActiveOrg.Name, user.ActiveOrg.Id)
2116321115
@@ -21216,9 +21168,6 @@ func PrepareSingleAction(ctx context.Context, user User, appId string, body []by
2121621168
2121721169 action.AppID = appId
2121821170 workflow := Workflow{
21219- Actions: []Action{
21220- action,
21221- },
2122221171 Start: action.ID,
2122321172 ID: uuid.NewV4().String(),
2122421173 Generated: true,
@@ -21234,6 +21183,74 @@ func PrepareSingleAction(ctx context.Context, user User, appId string, body []by
2123421183 workflowExecution.OrgId = user.ActiveOrg.Id
2123521184 }
2123621185
21186+ // Fallback to inject AI creds if the user don't have any
21187+ if strings.ToLower(app.Name) == "openai" && len(action.AuthenticationId) == 0 {
21188+ apiKey := os.Getenv("AI_API_KEY")
21189+ if apiKey == "" {
21190+ apiKey = os.Getenv("OPENAI_API_KEY")
21191+ }
21192+
21193+ apiUrl := os.Getenv("AI_API_URL")
21194+ if apiUrl == "" {
21195+ apiUrl = os.Getenv("OPENAI_API_URL")
21196+ }
21197+
21198+ if apiUrl == "" {
21199+ apiUrl = "https://api.openai.com"
21200+ }
21201+
21202+ if len(apiKey) > 0 {
21203+ IncrementCache(ctx, user.ActiveOrg.Id, "ai_executions", 1)
21204+
21205+ urlFound := false
21206+ apikeyFound := false
21207+ for i, param := range action.Parameters {
21208+ if param.Name == "url" {
21209+ action.Parameters[i].Value = apiUrl
21210+ urlFound = true
21211+ }
21212+
21213+ if param.Name == "apikey" {
21214+ action.Parameters[i].Value = apiKey
21215+ action.Parameters[i].Configuration = true
21216+ apikeyFound = true
21217+ }
21218+ }
21219+
21220+ if !urlFound {
21221+ action.Parameters = append(action.Parameters, WorkflowAppActionParameter{
21222+ Name: "url",
21223+ Value: apiUrl,
21224+ })
21225+ }
21226+
21227+ if !apikeyFound {
21228+ action.Parameters = append(action.Parameters, WorkflowAppActionParameter{
21229+ Name: "apikey",
21230+ Value: apiKey,
21231+ Configuration: true,
21232+ })
21233+ }
21234+
21235+ log.Printf("[AUDIT] Injected system AI credentials (fallback) for org %s", user.ActiveOrg.Id)
21236+
21237+ // Mapping to internal so the execution itself is not referencable
21238+ if project.Environment == "cloud" {
21239+ workflowExecution.ExecutionOrg = "INTERNAL"
21240+ workflowExecution.Workflow.OrgId = "INTERNAL"
21241+ workflow.OrgId = "INTERNAL"
21242+ workflow.ExecutingOrg = OrgMini{
21243+ Name: "INTERNAL",
21244+ Id: "INTERNAL",
21245+ }
21246+ }
21247+ }
21248+ }
21249+
21250+ workflow.Actions = []Action{
21251+ action,
21252+ }
21253+
2123721254 // Add fake queries to it. Doesn't matter what is here.
2123821255 // This is just to ensure that _something_ is sent
2123921256 badRequest := &http.Request{}
0 commit comments