Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
788 changes: 469 additions & 319 deletions ai.go

Large diffs are not rendered by default.

97 changes: 81 additions & 16 deletions blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ func GetDefaultWorkflowByType(workflow Workflow, orgId string, categoryAction Ca
prepareAgentRun := uuid.NewV4().String()
aiAgentRun := uuid.NewV4().String()
addAgentResponse := uuid.NewV4().String()
assignedAppsId := uuid.NewV4().String()

// Test-workflow used to figure it out
// /workflows/25cd78f7-06a0-4f5e-8026-f1c25c74bf74
Expand Down Expand Up @@ -1259,6 +1260,29 @@ func GetDefaultWorkflowByType(workflow Workflow, orgId string, categoryAction Ca
},
},
},
Action{
Name: "get_datastore_value",
AppID: "Shuffle Tools",
AppName: "Shuffle Tools",
ID: assignedAppsId,
AppVersion: "1.2.0",
Environment: actionEnv,
Label: "Get_assigned_apps",
Parameters: []WorkflowAppActionParameter{
WorkflowAppActionParameter{
Name: "key",
Value: "config",
Multiline: false,
Required: true,
},
WorkflowAppActionParameter{
Name: "category",
Value: "shuffle-security_agent_tools",
Multiline: false,
Required: false,
},
},
},
Action{
Name: "execute_python",
AppID: "Shuffle Tools",
Expand Down Expand Up @@ -1307,7 +1331,7 @@ func GetDefaultWorkflowByType(workflow Workflow, orgId string, categoryAction Ca
Name: "app_name",
Multiline: false,
Required: true,
Value: "Shuffle AI",
Value: "$handle_ai_agent_run.message.assigned_apps",
},
WorkflowAppActionParameter{
Name: "input",
Expand All @@ -1320,11 +1344,13 @@ func GetDefaultWorkflowByType(workflow Workflow, orgId string, categoryAction Ca
**Full context:**
$exec`,
},

/*
WorkflowAppActionParameter{
Name: "action",
Multiline: false,
Required: false,
Value: "Nothing",
Value: "",
},
WorkflowAppActionParameter{
Name: "memory",
Expand All @@ -1338,6 +1364,7 @@ $exec`,
Required: false,
Value: "",
},
*/
},
},
Action{
Expand Down Expand Up @@ -1380,12 +1407,24 @@ $exec`,
},
},
},
Branch{
SourceID: startActionId,
DestinationID: assignedAppsId,
ID: uuid.NewV4().String(),
Conditions: []Condition{},
},
Branch{
SourceID: startActionId,
DestinationID: prepareAgentRun,
ID: uuid.NewV4().String(),
Conditions: []Condition{},
},
Branch{
SourceID: assignedAppsId,
DestinationID: prepareAgentRun,
ID: uuid.NewV4().String(),
Conditions: []Condition{},
},
Branch{
SourceID: relevantPeopleId,
DestinationID: prepareAgentRun,
Expand Down Expand Up @@ -1426,6 +1465,21 @@ $exec`,
Value: "",
},
},
//Condition{
// Source: WorkflowAppActionParameter{
// Name: "source",
// Value: "$handle_ai_agent_run.success",
// },
// Condition: WorkflowAppActionParameter{
// Name: "condition",
// Value: "does not equal",
// Configuration: true, // Opposite
// },
// Destination: WorkflowAppActionParameter{
// Name: "destination",
// Value: "false",
// },
//},
},
},
Branch{
Expand Down Expand Up @@ -4149,16 +4203,6 @@ func handleRelevantPeopleAgentPrepareCode() string {
cur_exec = self.get_key("$exec.shuffle_datastore.key", category="$exec.shuffle_datastore.category")
if cur_exec["success"] and cur_exec["value"]:
cur_exec = cur_exec["value"]

if "finding_uid" in cur_exec and len(cur_exec["finding_uid"]) > 0:
pass
else:
print(json.dumps({
"success": False,
"reason": "No finding_uid in the incident. Not updating."
}))
exit()

else:
print(json.dumps({
"success": False,
Expand All @@ -4170,6 +4214,7 @@ activities = []
if "activity" in cur_exec:
activities = cur_exec["activity"]

agent_name = ""
ai_agent_activities = []
activities_changed = False
for activityIndex in range(len(activities)):
Expand All @@ -4186,6 +4231,7 @@ for activityIndex in range(len(activities)):
if "content" not in activity or ("@aiagent" not in activity["content"].lower()):
continue

agent_name = "default"
ai_agent_activities.append(activity)

db_updated = False
Expand All @@ -4211,6 +4257,24 @@ if activities_changed or len(assignee) > 0:
ret = self.set_key("$exec.shuffle_datastore.key", json.dumps(parsed_activity), category="$exec.shuffle_datastore.category")
if ret["success"]:
db_updated = True

available_apps = ""
assigned_apps = json.loads(r"""$get_assigned_apps""")
if "success" in assigned_apps and assigned_apps["success"] == True and "value" in assigned_apps and len(str(assigned_apps["value"])) > 0:
try:
assigned_apps["value"] = json.loads(assigned_apps["value"])
except:
pass

for agent_config in assigned_apps["value"]:
if agent_config["agent"] != agent_name:
continue

for tool in agent_config["tools"]:
available_apps += tool["name"]+","

if len(available_apps) > 0:
available_apps = available_apps[:-1]

# Print the details of the key after it's been updated
# To get the value, use self.get_key(key)["value"]
Expand All @@ -4219,12 +4283,13 @@ if len(ai_agent_activities) > 0:
"assignee": assignee,
"updated": db_updated,
"agent": ai_agent_activities[0],
"assigned_apps": available_apps,
}))
else:
print(json.dumps({
"updated": db_updated,
"agent": "",
}))`
print(json.dumps({
"updated": db_updated,
"agent": "",
}))`
}

func handleRelevantPeopleAgentResponseCode() string {
Expand Down
9 changes: 9 additions & 0 deletions cloudSync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3656,6 +3656,8 @@ ExecStart=$INSTALL_PATH \
--screenlock_check=$SCREENLOCK_CHECK \
--log_forwarding=$LOG_FORWARDING \
--response_actions=$RESPONSE_ACTIONS
StandardOutput=append:/var/log/orborus.log
StandardError=append:/var/log/orborus.log

Restart=always
RestartSec=5
Expand Down Expand Up @@ -3702,6 +3704,13 @@ install_macos() {

<key>RunAtLoad</key>
<true/>

<key>StandardOutPath</key>
<string>/tmp/orborus.log</string>

<key>StandardErrorPath</key>
<string>/tmp/orborus.log</string>

</dict>
</plist>
EOF
Expand Down
61 changes: 35 additions & 26 deletions codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3936,7 +3936,7 @@ func HandlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
}

func GetAppRequirements() string {
return "requests==2.32.3\nurllib3==2.3.0\nliquidpy==0.8.2\nMarkupSafe==3.0.2\nflask[async]==3.1.0\npython-dateutil==2.9.0.post0\nPyJWT==2.10.1\ncryptography==44.0.2\nshufflepy==0.2.2\nshuffle-sdk==0.0.39"
return "requests==2.32.3\nurllib3==2.3.0\nliquidpy==0.8.2\nMarkupSafe==3.0.2\nflask[async]==3.1.0\npython-dateutil==2.9.0.post0\nPyJWT==2.10.1\ncryptography==44.0.2\nshufflepy==0.2.2\nshuffle-sdk==0.0.40"
}

// Removes JSON values from the input
Expand Down Expand Up @@ -4645,26 +4645,29 @@ func GetAppNameSplit(version DockerRequestCheck) (string, string, string, error)
return appname, baseAppname, appVersion, nil
}

func handleDatastoreAutomationWebhook(ctx context.Context, marshalledBody []byte, cacheData CacheKeyData, automation DatastoreAutomation, url, runType string) error {
func handleDatastoreAutomationRequest(ctx context.Context, marshalledBody []byte, cacheData CacheKeyData, automation DatastoreAutomation, url, runType string) error {
var err error

// Dedup here with cache
cacheName := fmt.Sprintf("automation_%s_%s_%s", runType, cacheData.Category, cacheData.Key)
_, err = GetCache(ctx, cacheName)
if err == nil {
if debug {
log.Printf("[DEBUG] Found existing cache for %s - skipping execution to prevent duplicates", cacheName)
}
// Makes sure we wait 2500ms. This is to avoid infinite loops primarily.
// Problem: There's a difference between user updates and automation updates.
// Trying without cache.

return nil
}
//cacheName := fmt.Sprintf("automation_%s_%s_%s", runType, cacheData.Category, cacheData.Key)
//_, err = GetCache(ctx, cacheName)
//if err == nil {
// if debug {
// log.Printf("[DEBUG] Found existing '%s' cache for '%s' - skipping execution to prevent duplicates", runType, cacheName)
// }

// Makes sure we wait 2500ms
SetCache(ctx, cacheName, []byte("1"), 2500, true)
// return nil
//}
//SetCache(ctx, cacheName, []byte("1"), 2500, true)

if runType == "run_workflow" {

} else if runType == "webhook" {

// For now HTTP app hmm
webhookUrl := ""
for _, option := range automation.Options {
if option.Key == "webhook_url" {
Expand Down Expand Up @@ -4766,6 +4769,10 @@ func handleDatastoreAutomationWebhook(ctx context.Context, marshalledBody []byte
Timeout: time.Second * 5,
}

//if debug {
// log.Printf("[DEBUG] OUTPUT BODY: %s", string(marshalledBody))
//}

req, err := http.NewRequest(
"POST",
parsedUrl,
Expand Down Expand Up @@ -5190,6 +5197,19 @@ func handleRunDatastoreAutomation(ctx context.Context, cacheData CacheKeyData, a
cacheData.WorkflowId = option.Value
workflowIds := strings.Split(option.Value, ",")


formattedBodyStruct := ExecutionRequest{
ExecutionSource: fmt.Sprintf("datastore_%s_%s", cacheData.Category, cacheData.Key),
ExecutionArgument: string(marshalledBody),
}

marshalledFormattedBody, err := json.Marshal(formattedBodyStruct)
if err != nil {
log.Printf("[ERROR] Failed in marshalling data in 'run_workflow' datastore automation for workflow %s")
} else {
marshalledBody = marshalledFormattedBody
}

handled := []string{}
for _, workflowId := range workflowIds {
workflowId = strings.TrimSpace(workflowId)
Expand All @@ -5198,19 +5218,8 @@ func handleRunDatastoreAutomation(ctx context.Context, cacheData CacheKeyData, a
}

handled = append(handled, workflowId)
formattedBodyStruct := ExecutionRequest{
ExecutionSource: fmt.Sprintf("datastore_%s_%s", cacheData.Category, cacheData.Key),
ExecutionArgument: string(marshalledBody),
}

marshalledFormattedBody, err := json.Marshal(formattedBodyStruct)
if err != nil {
log.Printf("[ERROR] Failed in marshalling data in 'run_workflow' datastore automation for workflow %s", workflowId)
} else {
marshalledBody = marshalledFormattedBody
}

go handleDatastoreAutomationWebhook(ctx, marshalledBody, cacheData, automation, fmt.Sprintf("/api/v1/workflows/%s/execute", workflowId), "run_workflow")
go handleDatastoreAutomationRequest(ctx, marshalledBody, cacheData, automation, fmt.Sprintf("/api/v1/workflows/%s/execute", workflowId), "run_workflow")
}

break
Expand All @@ -5222,7 +5231,7 @@ func handleRunDatastoreAutomation(ctx context.Context, cacheData CacheKeyData, a
return errors.New("No options provided for 'run_workflow' automation")
}

return handleDatastoreAutomationWebhook(ctx, marshalledBody, cacheData, automation, "/api/v1/apps/HTTP/run", "webhook")
return handleDatastoreAutomationRequest(ctx, marshalledBody, cacheData, automation, "/api/v1/apps/HTTP/run", "webhook")

// Send the webhook using the HTTP app with a POST request

Expand Down
4 changes: 0 additions & 4 deletions correlations.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ func crossCorrelateNGrams(ctx context.Context, orgId, category, datastoreKey, va
tmpValue := parsedValue
tmpValue = strings.TrimPrefix(tmpValue, "file_")
if isValidUUID(tmpValue) {
if debug {
log.Printf("[DEBUG] Skipping value that is a valid UUID: %s", parsedValue)
}

continue
}

Expand Down
Loading
Loading