Skip to content

Commit 2f091e4

Browse files
committed
Merge branch 'main' of github.com:Shuffle/Shuffle-shared
2 parents b2844ac + d45fcf1 commit 2f091e4

File tree

3 files changed

+73
-21
lines changed

3 files changed

+73
-21
lines changed

app_upload/stitcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var appSearchIndex = "appsearch"
4242

4343
// CONFIGURE APP LOCATIONS TO USE
4444
// ALSO REQUIRES ACCESS TO UPLOAD TO CLOUD
45-
var appbasefile = "/Users/frikky/git/shuffle/backend/app_sdk/app_base.py"
45+
var appbasefile = "/Users/frikky/git/app_sdk/shuffle_sdk/shuffle_sdk.py"
4646
var appfolder = "/Users/frikky/git/python-apps"
4747
var baseUrl = ""
4848
var apikey = ""

kms.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ func AutofixAppLabels(app WorkflowApp, label string) WorkflowApp {
13071307
// fml, there is no consistency to casing + underscores, so we keep the new
13081308
//label = strings.ReplaceAll(strings.Title(strings.ToLower(label)), "_", " ")
13091309

1310-
log.Printf("[INFO] Running app fix for label '%s' for app %s (%s) with %d actions", label, app.Name, app.ID, len(app.Actions))
1310+
log.Printf("[INFO][AI] Running app fix for label '%s' for app %s (%s) with %d actions", label, app.Name, app.ID, len(app.Actions))
13111311

13121312
// Just a reset, as Other doesn't really achieve anything directly
13131313
if len(app.Categories) > 0 && app.Categories[0] == "Other" {

shared.go

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18053,7 +18053,7 @@ func PrepareSingleAction(ctx context.Context, user User, fileId string, body []b
1805318053
newParams = append(newParams, param)
1805418054
}
1805518055

18056-
log.Printf("URL %#v", originalUrl)
18056+
//log.Printf("URL %#v", originalUrl)
1805718057

1805818058
action.Parameters = newParams
1805918059

@@ -18108,6 +18108,13 @@ func PrepareSingleAction(ctx context.Context, user User, fileId string, body []b
1810818108

1810918109
workflowExecution, _, errString, err := PrepareWorkflowExecution(ctx, workflow, badRequest, 10)
1811018110
if err != nil || len(errString) > 0 {
18111+
18112+
// FIXME: Handle other error returns as well?
18113+
if strings.Contains(errString, "App Auth ID") {
18114+
log.Printf("[DEBUG] Bad auth ID provided for single action: %s", errString)
18115+
return workflowExecution, errors.New("The authentication ID provided is invalid. Please try another.")
18116+
}
18117+
1811118118
log.Printf("[ERROR] Failed preparing single execution (%s): %s", workflowExecution.ExecutionId, err)
1811218119
}
1811318120

@@ -25027,8 +25034,8 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2502725034
categories := GetAllAppCategories()
2502825035

2502925036
value.Category = strings.ToLower(value.Category)
25030-
value.Label = strings.ReplaceAll(strings.ToLower(value.Label), " ", "_")
25031-
value.AppName = strings.ReplaceAll(strings.ToLower(value.AppName), " ", "_")
25037+
value.Label = strings.ReplaceAll(strings.ToLower(strings.TrimSpace(value.Label)), " ", "_")
25038+
value.AppName = strings.ReplaceAll(strings.ToLower(strings.TrimSpace(value.AppName)), " ", "_")
2503225039

2503325040
if value.AppName == "email" {
2503425041
value.Category = "email"
@@ -25143,14 +25150,17 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2514325150

2514425151
//RunAiQuery(systemMessage, userMessage)
2514525152

25153+
partialMatch := true
2514625154
availableLabels := []string{}
25155+
25156+
matchName := strings.ReplaceAll(strings.ToLower(strings.TrimSpace(value.AppName)), " ", "_")
2514725157
for _, app := range newapps {
2514825158
if app.Name == "" || len(app.Categories) == 0 {
2514925159
continue
2515025160
}
2515125161

2515225162
// If we HAVE an app as a category already
25153-
if len(value.AppName) == 0 {
25163+
if len(matchName) == 0 {
2515425164
availableLabels = []string{}
2515525165
if len(app.Categories) == 0 {
2515625166
continue
@@ -25195,22 +25205,33 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2519525205
}
2519625206

2519725207
} else {
25208+
appName := strings.TrimSpace(strings.ReplaceAll(strings.ToLower(app.Name), " ", "_"))
25209+
2519825210
// If we DONT have a category app already
25199-
if app.ID == value.AppName || strings.ReplaceAll(strings.ToLower(app.Name), " ", "_") == value.AppName {
25200-
//log.Printf("[DEBUG] Found app - checking label: %s vs %s (%s)", app.Name, value.AppName, app.ID)
25201-
selectedAction, selectedCategory, availableLabels = GetActionFromLabel(ctx, selectedApp, value.Label, true)
25211+
if app.ID == matchName || appName == matchName {
25212+
selectedApp = app
25213+
log.Printf("[DEBUG] Found app - checking label: %s vs %s (%s)", app.Name, value.AppName, app.ID)
25214+
//selectedAction, selectedCategory, availableLabels = GetActionFromLabel(ctx, selectedApp, value.Label, true)
25215+
selectedAction, selectedCategory, availableLabels = GetActionFromLabel(ctx, app, value.Label, true)
25216+
partialMatch = false
2520225217

2520325218
break
2520425219

25205-
} else if selectedApp.ID == "" && len(value.AppName) > 0 && (strings.Contains(strings.ToLower(app.Name), strings.ToLower(value.AppName)) || strings.Contains(strings.ToLower(value.AppName), strings.ToLower(app.Name))) {
25220+
// Finds a random match, but doesn't break in case it finds exact
25221+
} else if selectedApp.ID == "" && len(matchName) > 0 && (strings.Contains(appName, matchName) || strings.Contains(matchName, appName)) {
2520625222
selectedApp = app
2520725223

25208-
log.Printf("[WARNING] Set selected app to partial match %s (%s) for input %s", selectedApp.Name, selectedApp.ID, value.AppName)
25209-
selectedAction, selectedCategory, availableLabels = GetActionFromLabel(ctx, selectedApp, value.Label, true)
25224+
log.Printf("[WARNING] Set selected app to PARTIAL match %s (%s) for input %s", selectedApp.Name, selectedApp.ID, value.AppName)
25225+
selectedAction, selectedCategory, availableLabels = GetActionFromLabel(ctx, app, value.Label, true)
25226+
25227+
partialMatch = true
2521025228
}
2521125229
}
2521225230
}
2521325231

25232+
// In case we wanna use this to get good matches
25233+
_ = partialMatch
25234+
2521425235
if len(selectedApp.ID) == 0 {
2521525236
log.Printf("[WARNING] Couldn't find app with ID or name '%s' active in org %s (%s)", value.AppName, user.ActiveOrg.Name, user.ActiveOrg.Id)
2521625237
failed := true
@@ -25293,6 +25314,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2529325314
}
2529425315

2529525316
if strings.Contains(strings.ToLower(strings.Join(selectedApp.ReferenceInfo.Triggers, ",")), "webhook") {
25317+
log.Printf("[INFO] App %s (%s) has a webhook trigger as default. Setting available labels to Webhook", selectedApp.Name, selectedApp.ID)
2529625318
availableLabels = append(availableLabels, "Webhook")
2529725319

2529825320
if len(selectedAction.Name) == 0 {
@@ -25840,6 +25862,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2584025862

2584125863
client := GetExternalClient(baseUrl)
2584225864

25865+
2584325866
selectedAction.AppName = selectedApp.Name
2584425867
selectedAction.AppID = selectedApp.ID
2584525868
selectedAction.AppVersion = selectedApp.AppVersion
@@ -26013,6 +26036,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2601326036

2601426037
//streamUrl = "http://localhost:5002"
2601526038
conversationUrl := fmt.Sprintf("%s/api/v1/conversation", baseUrl)
26039+
log.Printf("[DEBUG][AI] Sending single conversation execution to %s", conversationUrl)
2601626040

2601726041
// Check if "execution_id" & "authorization" queries exist
2601826042
if len(request.Header.Get("Authorization")) == 0 && len(request.URL.Query().Get("execution_id")) > 0 && len(request.URL.Query().Get("authorization")) > 0 {
@@ -26152,6 +26176,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2615226176
// The app run url to use. Default delete is false
2615326177
shouldDelete := "false"
2615426178
apprunUrl := fmt.Sprintf("%s/api/v1/apps/%s/run?delete=%s", baseUrl, secondAction.AppID, shouldDelete)
26179+
2615526180
if len(request.Header.Get("Authorization")) == 0 && len(request.URL.Query().Get("execution_id")) > 0 && len(request.URL.Query().Get("authorization")) > 0 {
2615626181
apprunUrl = fmt.Sprintf("%s&execution_id=%s&authorization=%s", apprunUrl, request.URL.Query().Get("execution_id"), request.URL.Query().Get("authorization"))
2615726182

@@ -26173,6 +26198,8 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2617326198

2617426199
// Runs attempts up to X times
2617526200
maxAttempts := 7
26201+
26202+
log.Printf("[DEBUG][AI] Sending single API run execution to %s", apprunUrl)
2617626203
for i := 0; i < maxAttempts; i++ {
2617726204

2617826205
// Sends back how many translations happened
@@ -26214,6 +26241,7 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2621426241
return
2621526242
}
2621626243

26244+
2621726245
// Ensures frontend has something to debug if things go wrong
2621826246
for key, value := range newresp.Header {
2621926247
if strings.HasSuffix(strings.ToLower(key), "-url") {
@@ -26236,14 +26264,27 @@ func RunCategoryAction(resp http.ResponseWriter, request *http.Request) {
2623626264
return
2623726265
}
2623826266

26267+
// Parse success struct
26268+
successStruct := ResultChecker{}
26269+
json.Unmarshal(apprunBody, &successStruct)
26270+
26271+
httpOutput, marshalledBody, httpParseErr := FindHttpBody(apprunBody)
26272+
//log.Printf("\n\nGOT RESPONSE (%d): %s. STATUS: %d\n\n", newresp.StatusCode, string(apprunBody), httpOutput.Status)
26273+
if successStruct.Success == false && len(successStruct.Reason) > 0 && httpOutput.Status == 0 && strings.Contains(strings.ReplaceAll(string(apprunBody), " ", ""), `"success":false`){
26274+
log.Printf("[WARNING][AI] Failed running app %s (%s). Contact support. Reason: %s", selectedAction.Name, selectedAction.AppID, successStruct.Reason)
26275+
26276+
resp.WriteHeader(400)
26277+
resp.Write(apprunBody)
26278+
return
26279+
}
26280+
2623926281
// Input value to get raw output instead of translated
2624026282
if value.SkipOutputTranslation {
2624126283
resp.WriteHeader(202)
2624226284
resp.Write(apprunBody)
2624326285
return
2624426286
}
2624526287

26246-
httpOutput, marshalledBody, httpParseErr := FindHttpBody(apprunBody)
2624726288
parsedTranslation := SchemalessOutput{
2624826289
Success: false,
2624926290
Action: value.Label,
@@ -26821,6 +26862,7 @@ func GetActionFromLabel(ctx context.Context, app WorkflowApp, label string, fixL
2682126862

2682226863
categories := GetAllAppCategories()
2682326864
lowercaseLabel := strings.ReplaceAll(strings.ToLower(label), " ", "_")
26865+
exactMatch := false
2682426866
for _, action := range app.Actions {
2682526867
if len(action.CategoryLabel) == 0 {
2682626868
//log.Printf("%s: %#v\n", action.Name, action.CategoryLabel)
@@ -26829,15 +26871,18 @@ func GetActionFromLabel(ctx context.Context, app WorkflowApp, label string, fixL
2682926871

2683026872
//log.Printf("FOUND LABELS: %s -> %#v\n", action.Name, action.CategoryLabel)
2683126873

26832-
for labelIndex, _ := range action.CategoryLabel {
26833-
if strings.ReplaceAll(strings.ToLower(action.CategoryLabel[labelIndex]), " ", "_") == "no_label" {
26874+
for _, label := range action.CategoryLabel {
26875+
newLabel := strings.ReplaceAll(strings.ToLower(label), " ", "_")
26876+
if newLabel == "no_label" {
2683426877
continue
2683526878
}
2683626879

26837-
availableLabels = append(availableLabels, action.CategoryLabel[labelIndex])
26838-
actionCategory := strings.ReplaceAll(strings.ToLower(action.CategoryLabel[labelIndex]), " ", "_")
26880+
// To ensure we have both normal + parsed label
26881+
availableLabels = append(availableLabels, newLabel)
26882+
availableLabels = append(availableLabels, label)
2683926883

26840-
if actionCategory == lowercaseLabel || strings.HasPrefix(actionCategory, lowercaseLabel) {
26884+
if newLabel == lowercaseLabel || strings.HasPrefix(newLabel, lowercaseLabel) {
26885+
//log.Printf("[DEBUG] Found action for label '%s' in app %s (%s): %s", label, app.Name, app.ID, action.Name)
2684126886
selectedAction = action
2684226887

2684326888
for _, category := range categories {
@@ -26846,13 +26891,20 @@ func GetActionFromLabel(ctx context.Context, app WorkflowApp, label string, fixL
2684626891
break
2684726892
}
2684826893
}
26894+
26895+
if newLabel == lowercaseLabel {
26896+
exactMatch = true
26897+
break
26898+
}
2684926899
}
2685026900
}
26851-
}
2685226901

26853-
//log.Printf("\n\n[DEBUG] SELECTED: %#v\n\n", selectedAction)
26902+
if len(selectedAction.ID) > 0 && exactMatch {
26903+
break
26904+
}
26905+
}
2685426906

26855-
// FIXME: If selectedAction isn't chosen, then we need to try to discover it in the app
26907+
// Decides if we are to autocomplete the app if labels are not found
2685626908
if len(selectedAction.ID) == 0 {
2685726909
if fixLabels == true {
2685826910
//log.Printf("\n\n[DEBUG] Action not found in app %s (%s) for label '%s'. Autodiscovering and updating the app!!!\n\n", app.Name, app.ID, label)

0 commit comments

Comments
 (0)