| 87 | } |
| 88 | |
| 89 | QFuture<LLMQore::ToolResult> TodoTool::executeAsync(const QJsonObject &input) |
| 90 | { |
| 91 | return QtConcurrent::run([this, input]() -> LLMQore::ToolResult { |
| 92 | QMutexLocker sessionLocker(&m_mutex); |
| 93 | QString sessionId = m_currentSessionId.isEmpty() ? "current" : m_currentSessionId; |
| 94 | sessionLocker.unlock(); |
| 95 | |
| 96 | const QString operation = input.value("operation").toString(); |
| 97 | |
| 98 | if (operation == "add") { |
| 99 | if (!input.contains("tasks") || !input.value("tasks").isArray()) { |
| 100 | throw LLMQore::ToolRuntimeError( |
| 101 | tr("Error: 'tasks' parameter (array) is required for 'add' operation. " |
| 102 | "Example: {\"operation\": \"add\", \"tasks\": [\"Task 1\", \"Task 2\"]}")); |
| 103 | } |
| 104 | |
| 105 | const QJsonArray tasksArray = input.value("tasks").toArray(); |
| 106 | if (tasksArray.isEmpty()) { |
| 107 | throw LLMQore::ToolRuntimeError( |
| 108 | tr("Error: 'tasks' array cannot be empty. Provide at least one task.")); |
| 109 | } |
| 110 | |
| 111 | QStringList tasks; |
| 112 | for (const QJsonValue &taskValue : tasksArray) { |
| 113 | QString task = taskValue.toString().trimmed(); |
| 114 | if (!task.isEmpty()) { |
| 115 | tasks.append(task); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if (tasks.isEmpty()) { |
| 120 | throw LLMQore::ToolRuntimeError( |
| 121 | tr("Error: All tasks in 'tasks' array are empty strings.")); |
| 122 | } |
| 123 | |
| 124 | return LLMQore::ToolResult::text(addTodos(sessionId, tasks)); |
| 125 | |
| 126 | } else if (operation == "complete") { |
| 127 | if (!input.contains("todo_ids") || !input.value("todo_ids").isArray()) { |
| 128 | throw LLMQore::ToolRuntimeError( |
| 129 | tr("Error: 'todo_ids' parameter (array) is required for 'complete' operation. " |
| 130 | "Example: {\"operation\": \"complete\", \"todo_ids\": [1, 2, 3]}")); |
| 131 | } |
| 132 | |
| 133 | const QJsonArray idsArray = input.value("todo_ids").toArray(); |
| 134 | if (idsArray.isEmpty()) { |
| 135 | throw LLMQore::ToolRuntimeError( |
| 136 | tr("Error: 'todo_ids' array cannot be empty. Provide at least one ID.")); |
| 137 | } |
| 138 | |
| 139 | QList<int> ids; |
| 140 | for (const QJsonValue &idValue : idsArray) { |
| 141 | int id = idValue.toInt(-1); |
| 142 | if (id > 0) { |
| 143 | ids.append(id); |
| 144 | } |
| 145 | } |
| 146 |
nothing calls this directly
no test coverage detected