* @brief Returns the AI tool surface: 3 meta tools + a small curated set. */
| 2406 | * @brief Returns the AI tool surface: 3 meta tools + a small curated set. |
| 2407 | */ |
| 2408 | QJsonArray AI::Conversation::dispatcherTools() const |
| 2409 | { |
| 2410 | if (!m_dispatcher) |
| 2411 | return {}; |
| 2412 | |
| 2413 | QJsonArray remapped; |
| 2414 | const auto caps = m_provider ? m_provider->capabilities() : ProviderCapabilities{}; |
| 2415 | |
| 2416 | appendCoreMetaTools(remapped); |
| 2417 | appendDocMetaTools(remapped); |
| 2418 | |
| 2419 | QStringList essentials = essentialToolNames(); |
| 2420 | if (caps.needsSmallToolSurface) { |
| 2421 | essentials.removeAll(QStringLiteral("project.workspace.addWidget")); |
| 2422 | essentials.removeAll(QStringLiteral("project.workspace.removeWidget")); |
| 2423 | essentials.removeAll(QStringLiteral("project.workspace.setCustomizeMode")); |
| 2424 | essentials.removeAll(QStringLiteral("project.dataset.setOptions")); |
| 2425 | } |
| 2426 | |
| 2427 | const auto raw = m_dispatcher->availableTools(); |
| 2428 | |
| 2429 | auto append = [&remapped](const QJsonObject& obj) { |
| 2430 | auto schema = obj.value(QStringLiteral("inputSchema")).toObject(); |
| 2431 | if (!schema.contains(QStringLiteral("type"))) |
| 2432 | schema[QStringLiteral("type")] = QStringLiteral("object"); |
| 2433 | |
| 2434 | if (!schema.contains(QStringLiteral("properties"))) |
| 2435 | schema[QStringLiteral("properties")] = QJsonObject(); |
| 2436 | |
| 2437 | QJsonObject tool; |
| 2438 | tool[QStringLiteral("name")] = obj.value(QStringLiteral("name")); |
| 2439 | tool[QStringLiteral("description")] = obj.value(QStringLiteral("description")); |
| 2440 | tool[QStringLiteral("input_schema")] = schema; |
| 2441 | remapped.append(tool); |
| 2442 | }; |
| 2443 | |
| 2444 | for (const auto& essentialName : essentials) { |
| 2445 | for (const auto& v : raw) { |
| 2446 | const auto obj = v.toObject(); |
| 2447 | if (obj.value(QStringLiteral("name")).toString() == essentialName) { |
| 2448 | append(obj); |
| 2449 | break; |
| 2450 | } |
| 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | return remapped; |
| 2455 | } |
| 2456 | |
| 2457 | //-------------------------------------------------------------------------------------------------- |
| 2458 | // Snapshot (round-trips m_history + m_uiMessages through the ChatStore) |
nothing calls this directly
no test coverage detected