2025-07-09 14:38:30 +02:00
|
|
|
import strutils, tables, json
|
2025-05-22 20:03:22 +02:00
|
|
|
import ./types
|
|
|
|
|
import ./commands/commands
|
|
|
|
|
|
2025-05-29 15:26:50 +02:00
|
|
|
proc handleTask*(task: Task, config: AgentConfig): TaskResult =
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-07-08 23:10:19 +02:00
|
|
|
var taskResult: TaskResult
|
|
|
|
|
|
|
|
|
|
let handlers = {
|
|
|
|
|
ExecuteShell: taskShell,
|
|
|
|
|
Sleep: taskSleep,
|
|
|
|
|
GetWorkingDirectory: taskPwd,
|
|
|
|
|
SetWorkingDirectory: taskCd,
|
|
|
|
|
ListDirectory: taskDir,
|
|
|
|
|
RemoveFile: taskRm,
|
|
|
|
|
RemoveDirectory: taskRmdir
|
|
|
|
|
}.toTable
|
2025-05-28 10:39:30 +02:00
|
|
|
|
2025-07-08 23:10:19 +02:00
|
|
|
# Handle task command
|
|
|
|
|
taskResult = handlers[task.command](task)
|
|
|
|
|
echo taskResult.data
|
2025-05-22 20:03:22 +02:00
|
|
|
|
2025-07-08 23:10:19 +02:00
|
|
|
# Handle actions on specific commands
|
|
|
|
|
case task.command:
|
2025-05-29 15:26:50 +02:00
|
|
|
of Sleep:
|
|
|
|
|
if taskResult.status == Completed:
|
2025-07-09 14:38:30 +02:00
|
|
|
config.sleep = parseJson(task.args)["delay"].getInt()
|
2025-05-22 20:03:22 +02:00
|
|
|
else:
|
2025-07-08 23:10:19 +02:00
|
|
|
discard
|
|
|
|
|
|
|
|
|
|
# Return the result
|
|
|
|
|
return taskResult
|