addTask
codebolt.taskplaner.addTask(task: string): Promise<AddTaskResponse>
Adds a new task to the task management system via WebSocket communication. This method creates a new task with the provided description and stores it in the system for tracking and management.
Parameters
task(string): The task description to be added. This should be a clear, descriptive string that explains what needs to be accomplished.
Returns
Promise<AddTaskResponse>: A promise that resolves with the response containing the newly created task information.
Response Structure
The method returns a Promise that resolves to an AddTaskResponse object with the following properties:
type(string): Always "addTaskResponse".task(Task, optional): The newly created Task object containing:id(string, optional): Unique identifier for the task.title(string, optional): The title or name of the task.description(string, optional): Detailed description of the task.completed(boolean, optional): Indicates whether the task is completed (typically false for new tasks).
success(boolean, optional): Indicates if the operation was successful.message(string, optional): Additional information about the response.error(string, optional): Error details if the operation failed.messageId(string, optional): Unique identifier for the message.threadId(string, optional): Thread identifier for the request.
Examples
// Example 1: Basic task addition
const addResult = await codebolt.taskplaner.addTask('Complete project documentation');
console.log('✅ Task added successfully');
console.log('New task:', addResult.task);
console.log('Task ID:', addResult.task?.id);
// Example 2: Add task with error handling
const addTaskSafely = async (taskDescription) => {
try {
const result = await codebolt.taskplaner.addTask(taskDescription);
if (result.success) {
console.log('✅ Task added successfully');
console.log('Task details:', result.task);
return result.task;
} else {
console.error('❌ Failed to add task:', result.error);
return null;
}
} catch (error) {
console.error('❌ Exception while adding task:', error.message);
return null;
}
};
// Usage
const newTask = await addTaskSafely('Review code changes');
// Example 3: Add multiple tasks in sequence
const addMultipleTasks = async (taskDescriptions) => {
const results = [];
for (const description of taskDescriptions) {
try {
const result = await codebolt.taskplaner.addTask(description);
results.push({
description,
success: result.success,
task: result.task,
error: result.error
});
console.log(`${result.success ? '✅' : '❌'} ${description}`);
} catch (error) {
console.error(`❌ Failed to add "${description}":`, error);
results.push({
description,
success: false,
error: error.message
});
}
}
return results;
};
// Usage
const tasks = [
'Review code changes',
'Update unit tests',
'Fix bug in authentication module',
'Prepare release notes'
];
const addResults = await addMultipleTasks(tasks);
console.log('✅ Multiple tasks added');
console.log('Results:', addResults);
// Example 4: Add task with validation
const addValidatedTask = async (taskDescription) => {
// Validate input
if (!taskDescription || typeof taskDescription !== 'string') {
throw new Error('Task description must be a non-empty string');
}
if (taskDescription.trim().length === 0) {
throw new Error('Task description cannot be empty');
}
if (taskDescription.length > 500) {
throw new Error('Task description is too long (max 500 characters)');
}
const trimmedDescription = taskDescription.trim();
console.log(`🔄 Adding task: "${trimmedDescription}"`);
const result = await codebolt.taskplaner.addTask(trimmedDescription);
if (result.success) {
console.log('✅ Validated task added successfully');
console.log('Task details:', result.task);
} else {
console.error('❌ Validated task addition failed:', result.error);
}
return result;
};
// Usage
await addValidatedTask(' Complete API documentation ');
// Example 5: Add task with priority and category
const addCategorizedTask = async (taskData) => {
const { description, priority, category, assignee } = taskData;
// Format task description with metadata
let formattedDescription = description;
if (priority) {
formattedDescription += ` [PRIORITY: ${priority.toUpperCase()}]`;
}
if (category) {
formattedDescription += ` [CATEGORY: ${category}]`;
}
if (assignee) {
formattedDescription += ` [ASSIGNED: ${assignee}]`;
}
const result = await codebolt.taskplaner.addTask(formattedDescription);
if (result.success) {
console.log('✅ Categorized task added');
console.log('Task:', result.task);
} else {
console.error('❌ Failed to add categorized task:', result.error);
}
return result;
};
// Usage
await addCategorizedTask({
description: 'Implement user authentication',
priority: 'high',
category: 'Security',
assignee: 'John Doe'
});
// Example 6: Add task with deadline and dependencies
const addDetailedTask = async (taskInfo) => {
const {
title,
description,
deadline,
dependencies,
estimatedHours,
tags
} = taskInfo;
let taskDescription = title || description;
if (deadline) {
taskDescription += ` [DEADLINE: ${deadline}]`;
}
if (estimatedHours) {
taskDescription += ` [ESTIMATE: ${estimatedHours}h]`;
}
if (dependencies && dependencies.length > 0) {
taskDescription += ` [DEPENDS: ${dependencies.join(', ')}]`;
}
if (tags && tags.length > 0) {
taskDescription += ` [TAGS: ${tags.join(', ')}]`;
}
const result = await codebolt.taskplaner.addTask(taskDescription);
if (result.success) {
console.log('✅ Detailed task added');
console.log('Task:', result.task);
} else {
console.error('