Seperated Task and TaskResult types.

This commit is contained in:
Jakob Friedl
2025-05-29 15:26:50 +02:00
parent 118e9eadd2
commit 3849bcd7f1
11 changed files with 59 additions and 75 deletions

View File

@@ -208,19 +208,19 @@ proc getTasks*(listener, agent: string): JsonNode =
# return nil
# Return tasks in JSON format
return %cq.agents[agent.toUpperAscii].tasks.filterIt(it.status != Completed)
return %cq.agents[agent.toUpperAscii].tasks
proc handleResult*(listener, agent, task: string, taskResult: Task) =
proc handleResult*(listener, agent, task: string, taskResult: TaskResult) =
{.cast(gcsafe).}:
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Task execution finished.")
if taskResult.result != "":
if taskResult.data != "":
cq.writeLine(fgBlack, styleBright, fmt"[*] [{task}] ", resetStyle, "Output:")
# Split result string on newline to keep formatting
for line in decode(taskResult.result).split("\n"):
for line in decode(taskResult.data).split("\n"):
cq.writeLine(line)
# Update task queue to include all tasks, except the one that was just completed

View File

@@ -11,8 +11,6 @@ proc taskExecuteShell*(cq: Conquest, arguments: seq[string]) =
agent: cq.interactAgent.name,
command: ExecuteShell,
args: arguments,
result: "",
status: Created
)
# Add new task to the agent's task queue

View File

@@ -20,8 +20,6 @@ proc taskExecuteSleep*(cq: Conquest, delay: int) =
agent: cq.interactAgent.name,
command: Sleep,
args: @[$delay],
result: "",
status: Created
)
# Add new task to the agent's task queue

View File

@@ -101,7 +101,7 @@ proc postResults*(ctx: Context) {.async.} =
try:
let
taskResultJson: JsonNode = parseJson(ctx.request.body)
taskResult: Task = taskResultJson.to(Task)
taskResult: TaskResult = taskResultJson.to(TaskResult)
# Handle and display task result
handleResult(listener, agent, task, taskResult)

View File

@@ -17,34 +17,23 @@ type
Sleep = "sleep"
TaskStatus* = enum
Created = "created"
Completed = "completed"
Created = "created"
Pending = "pending"
Failed = "failed"
Cancelled = "cancelled"
TaskResult* = string
#[
TaskResult*[T] = ref object
data*: T
Task*[T] = ref object
id*: string
agent*: string
command*: TaskCommand
args*: seq[string]
result*: TaskResult[T]
status*: TaskStatus
]#
TaskResult* = ref object
task*: string
agent*: string
data*: string
status*: TaskStatus
Task* = ref object
id*: string
agent*: string
command*: TaskCommand
args*: seq[string]
result*: TaskResult
status*: TaskStatus
args*: seq[string]
AgentRegistrationData* = object
username*: string