/**
* Get Task Status Tool
* Retrieves the status of a previously executed command/task
*/
import type { OpenClawClient } from '../openclaw-client.js';
import type { GetTaskStatusParams } from '../types.js';
/**
* Input schema for get_task_status tool
*/
export const GetTaskStatusInputSchema = {
type: 'object',
properties: {
taskId: {
type: 'string',
description: 'The ID of the task to check status for',
},
},
required: ['taskId'],
};
/**
* Execute the get_task_status tool
*/
export async function executeGetTaskStatus(
client: OpenClawClient,
args: GetTaskStatusParams
) {
try {
// Validate required fields
if (!args.taskId || args.taskId.trim() === '') {
return {
content: [
{
type: 'text',
text: JSON.stringify({ error: 'Task ID is required' }, null, 2),
},
],
isError: true,
};
}
// Call the OpenClaw API
const response = await client.getTaskStatus({
taskId: args.taskId,
});
if (response.success && response.status) {
const result: Record<string, unknown> = {
success: true,
taskId: args.taskId,
status: response.status,
};
if (response.output !== undefined) {
result.output = response.output;
}
if (response.exitCode !== undefined) {
result.exitCode = response.exitCode;
}
// Add status description
const statusDescriptions: Record<string, string> = {
pending: 'Task is waiting to start',
running: 'Task is currently executing',
completed: 'Task completed successfully',
failed: 'Task failed during execution',
};
result.description = statusDescriptions[response.status] || 'Unknown status';
return {
content: [
{
type: 'text',
text: JSON.stringify(result, null, 2),
},
],
};
} else {
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
success: false,
taskId: args.taskId,
error: response.error || 'Failed to get task status',
},
null,
2
),
},
],
isError: true,
};
}
} catch (error) {
return {
content: [
{
type: 'text',
text: JSON.stringify(
{
error: 'Unexpected error occurred',
details: error instanceof Error ? error.message : String(error),
},
null,
2
),
},
],
isError: true,
};
}
}
/**
* Tool definition for get_task_status
*/
export const GetTaskStatusTool = {
name: 'get_task_status',
description: 'Get the current status of a previously executed async command/task',
inputSchema: GetTaskStatusInputSchema,
};