| 60 | } |
| 61 | |
| 62 | QFuture<LLMQore::ToolResult> ReadFileTool::executeAsync(const QJsonObject &input) |
| 63 | { |
| 64 | return QtConcurrent::run([input]() -> LLMQore::ToolResult { |
| 65 | QString rawPath = input["file_path"].toString().trimmed(); |
| 66 | if (rawPath.isEmpty()) { |
| 67 | throw LLMQore::ToolInvalidArgument( |
| 68 | "'file_path' parameter is required and cannot be empty"); |
| 69 | } |
| 70 | |
| 71 | QFileInfo pathInfo(rawPath); |
| 72 | QString absolutePath; |
| 73 | if (pathInfo.isAbsolute()) { |
| 74 | absolutePath = rawPath; |
| 75 | } else { |
| 76 | QString projectRoot = Context::ProjectUtils::getProjectRoot(); |
| 77 | if (projectRoot.isEmpty()) { |
| 78 | throw LLMQore::ToolRuntimeError( |
| 79 | QString("Cannot resolve relative path '%1': no project is open. " |
| 80 | "Provide an absolute path or open a project.") |
| 81 | .arg(rawPath)); |
| 82 | } |
| 83 | absolutePath = QDir(projectRoot).absoluteFilePath(rawPath); |
| 84 | LOG_MESSAGE(QString("ReadFileTool: Resolved relative path '%1' to '%2'") |
| 85 | .arg(rawPath, absolutePath)); |
| 86 | } |
| 87 | |
| 88 | QFileInfo finalInfo(absolutePath); |
| 89 | if (!finalInfo.exists() || !finalInfo.isFile()) { |
| 90 | throw LLMQore::ToolRuntimeError(QString("File does not exist: %1").arg(absolutePath)); |
| 91 | } |
| 92 | |
| 93 | QString content = FileSearchUtils::readFileContent(absolutePath); |
| 94 | if (content.isNull()) { |
| 95 | throw LLMQore::ToolRuntimeError( |
| 96 | QString("Cannot read file '%1'. It may be outside the project scope " |
| 97 | "(enable 'Allow file access outside project' in settings), unreadable, " |
| 98 | "or use an unsupported encoding.") |
| 99 | .arg(absolutePath)); |
| 100 | } |
| 101 | |
| 102 | QString result = QString("File: %1\n\n%2").arg(absolutePath, content); |
| 103 | return LLMQore::ToolResult::text(result); |
| 104 | }); |
| 105 | } |
| 106 | |
| 107 | } // namespace QodeAssist::Tools |
nothing calls this directly
no test coverage detected