2025-05-28 10:39:30 +02:00
|
|
|
import base64, strutils
|
2025-05-22 20:03:22 +02:00
|
|
|
import ./types
|
|
|
|
|
import ./commands/commands
|
|
|
|
|
|
2025-05-28 10:39:30 +02:00
|
|
|
proc handleTask*(task: Task, config: AgentConfig): Task =
|
2025-05-22 20:03:22 +02:00
|
|
|
|
|
|
|
|
# Handle task command
|
|
|
|
|
case task.command:
|
2025-05-28 10:39:30 +02:00
|
|
|
|
2025-05-22 20:03:22 +02:00
|
|
|
of ExecuteShell:
|
|
|
|
|
|
2025-05-23 16:02:16 +02:00
|
|
|
let (output, status) = taskShell(task.args)
|
|
|
|
|
echo output
|
2025-05-22 20:03:22 +02:00
|
|
|
|
|
|
|
|
return Task(
|
|
|
|
|
id: task.id,
|
|
|
|
|
agent: task.agent,
|
|
|
|
|
command: task.command,
|
|
|
|
|
args: task.args,
|
2025-05-23 16:02:16 +02:00
|
|
|
result: encode(output), # Base64 encode result
|
|
|
|
|
status: status
|
2025-05-22 20:03:22 +02:00
|
|
|
)
|
|
|
|
|
|
2025-05-28 10:39:30 +02:00
|
|
|
of Sleep:
|
|
|
|
|
# Parse arguments
|
|
|
|
|
let delay: int = parseInt(task.args[0])
|
|
|
|
|
|
|
|
|
|
# Execute task
|
|
|
|
|
let (output, status) = taskSleep(delay)
|
|
|
|
|
|
|
|
|
|
# Update sleep delay in agent config
|
|
|
|
|
if status == Completed:
|
|
|
|
|
config.sleep = delay
|
|
|
|
|
|
|
|
|
|
# Return result
|
|
|
|
|
return Task(
|
|
|
|
|
id: task.id,
|
|
|
|
|
agent: task.agent,
|
|
|
|
|
command: task.command,
|
|
|
|
|
args: task.args,
|
|
|
|
|
result: encode(output),
|
|
|
|
|
status: status
|
|
|
|
|
)
|
|
|
|
|
|
2025-05-22 20:03:22 +02:00
|
|
|
else:
|
|
|
|
|
echo "Not implemented"
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
return task
|