Automation API

Android device automation

Job Task Management

Utils

Manage job tasks, submit results, and request new tasks

Access job management through agent.utils.job. Used for managing job tasks, submitting results, and requesting new tasks.

JobUtils Interface
TypeScript
interface JobUtils {
submitTask(
automationStatus: "running" | "success" | "failed" | "declined",
data: Record<string, any>,
finish: boolean,
files: { name: string; extension: string; base64Data: string }[]
): Promise<{ success: false; error: string } | { success: true }>;
useAnotherTask(): Promise<{ job_task_id: string; job_proof: string } | null>;
getCurrentTask(): Promise<
{ success: false; error: string } |
{ success: true; parent_task_id: string; job_proof: any }
>;
}

submitTask()

TypeScript
submitTask(automationStatus: "running" | "success" | "failed" | "declined", data: Record<string, any>, finish: boolean, files: { name: string; extension: string; base64Data: string }[]): Promise<{ success: false; error: string } | { success: true }>

Submits the current task result to the server. Use this to report progress, success, or failure of job tasks. Note: Once you call submitTask with finish=true, you cannot submit again for the same task. The files parameter is ignored when finish=false.

Parameters

NameTypeDescription
automationStatus"running" | "success" | "failed" | "declined"Current status of the task
dataRecord<string, any>Task result data as key-value pairs
finishbooleanWhether this is the final submission for this task. Once true, no more submissions are allowed for this task.
files{ name, extension, base64Data }[]Array of files to upload with the task. Ignored when finish=false.

Returns

{ success: true } | { success: false; error: string }Success status or error message

Examples

Submit successful task with data
TypeScript
const result = await agent.utils.job.submitTask(
"success",
{
orderId: "12345",
totalAmount: 99.99,
itemsProcessed: 3
},
true, // Final submission
[] // No files
);
if (result.success) {
console.log("Task submitted successfully");
}
Submit task with files
TypeScript
const screenshot = await agent.actions.screenshot(1080, 1920, 80);
const result = await agent.utils.job.submitTask(
"success",
{ status: "completed" },
true, // Final submission
[{
name: "confirmation",
extension: "jpg",
base64Data: screenshot.screenshot || ""
}]
);
Report progress (not finished)
TypeScript
// Note: files parameter is ignored when finish=false
await agent.utils.job.submitTask(
"running",
{ currentStep: 3, totalSteps: 10 },
false, // More submissions coming
[] // Files ignored for progress updates
);
Decline a task
TypeScript
await agent.utils.job.submitTask(
"declined",
{ reason: "Item out of stock" },
true, // Final submission
[]
);

useAnotherTask()

TypeScript
useAnotherTask(): Promise<{ job_task_id: string; job_proof: string } | null>

Requests a new task from the job queue. Returns the next available task or null if no tasks are available.

Returns

{ job_task_id: string; job_proof: string } | nullNext task details or null if queue is empty

Examples

TypeScript
// Process multiple tasks in a loop
while (true) {
const nextTask = await agent.utils.job.useAnotherTask();
if (!nextTask) {
console.log("No more tasks available");
break;
}
console.log("Processing task:", nextTask.job_task_id);
const proof = JSON.parse(nextTask.job_proof);
// Process the task...
await agent.utils.job.submitTask("success", { completed: true }, true, []);
}

getCurrentTask()

TypeScript
getCurrentTask(): Promise<{ success: false; error: string } | { success: true; parent_task_id: string; job_proof: any }>

Gets information about the currently assigned task, including the parent task ID and job proof data.

Returns

{ success: true; parent_task_id: string; job_proof: any } | { success: false; error: string }Current task details or error

Examples

TypeScript
const task = await agent.utils.job.getCurrentTask();
if (task.success) {
console.log("Current task ID:", task.parent_task_id);
console.log("Job proof:", task.job_proof);
// Access job proof data
const targetUrl = task.job_proof.url;
const credentials = task.job_proof.credentials;
} else {
console.log("Error getting task:", task.error);
}