Commit graph

4 commits

Author SHA1 Message Date
Laurent Destailleur
56009b9bf8 NEW Add count tool for AI 2026-05-21 19:33:50 +02:00
Pichinov-Jose
a9fbc88b84
Qual: enrich UniversalLLMAdapter::curl error diagnostics (#38304)
Rebased on top of upstream commit 95b57550d3 ("Fix curl direct use
is forbidden. Must use getUrlContent()") which replaced the raw
curl_* calls in this method with getURLContent(). The diagnostics
this patch adds are re-implemented on top of the new array shape
returned by getURLContent().

When the LLM API returns a non-JSON body, the previous code surfaced
only the generic message:

    "Error: Invalid JSON response from API."

with no clue about what really happened. Common real-world causes
are: HTTP 4xx/5xx with empty body, HTML error page from a proxy,
gateway timeout, model not found, etc. None of these are
distinguishable from each other in the admin Log Viewer, so admins
had to re-run with curl by hand to diagnose.

This patch:

- Reads $result['http_code'] and $result['url'] (both populated by
  getURLContent() via curl_getinfo()) and stores an enriched payload
  in $this->lastResponse so the admin Log Viewer shows HTTP code +
  effective URL + body length + body contents.
- Returns a descriptive error message when the body is not valid
  JSON: includes the HTTP code, body length, and a 500-char body
  snippet (with the '<empty>' placeholder for zero-length bodies).
- Adds the cURL error number ($result['curl_error_no']) alongside
  the cURL error message in the network-level error message, with
  the effective URL for context.
- Restores the LLM-specific response timeout that was lost in the
  getURLContent() refactor: $this->timeout is now passed as the
  10th argument ($timeoutresponse) so the configured value is
  honored instead of falling back to MAIN_USE_RESPONSE_TIMEOUT
  (default 30s). This also fixes the phpstan warning
  "Property UniversalLLMAdapter::$timeout is never read, only
  written." that the upstream refactor introduced.

No behavioral change for successful calls. Strictly improves the
error-path diagnostics surfaced to administrators, and restores
the per-LLM configurable timeout.

Tested with: a misconfigured Google Gemini URL that returns HTTP
404 with an empty body now produces:

    Error: Invalid JSON response from API (HTTP 404, 0 bytes).
    Body snippet: <empty>

instead of the previous opaque message.
2026-05-18 01:18:27 +02:00
Laurent Destailleur
95b57550d3 Fix curl direct use is forbidden. Must use getUrlContent(). 2026-05-17 23:55:13 +02:00
sonikf
faa8005eb4
NEW: MCP server and AI Assistant (#37888)
* fix list query

* Update other.lang

* remove duplicate

* initial commit

* AI Assistant initial commit

* Rename htdocs/ai/index.php to htdocs/ai/assistant/index.php

* AI Assistant initial commit

* Initial commit

* Rename htdocs/ai/ai_assistant.css to htdocs/ai/css/ai_assistant.css

* Initial commit

* Rename htdocs/ai/ai_assistant.js to htdocs/ai/js/ai_assistant.js

* Initial commit

* Rename htdocs/ai/mcp_server.php to htdocs/ai/server/mcp_server.php

* Initial commit

* category tools

* Rename htdocs/ai/categories.php to htdocs/ai/tools/categories.php

* Global tools to restrict AI

* Tools for crud actions on Dolibarr objects

* Tools for products and services.

* Tools to generate reports

* Missing PHPDoc

* Tools for thirdparties and contacts

* Tool for generating navigation URLs in Dolibarr

* Tools related to invoices and payments

* Update ai_assistant.js

* Initial commit

* Rename htdocs/ai/purge_logs.php to htdocs/ai/scripts/purge_logs.php

* fix pre commit

* re fix pre-commit

* fix pre-commit

* Rename categories.php to categories.class.php

* Rename conversation.php to conversation.class.php

* Rename crud_objects.php to crud_objects.class.php

* Rename invoices.php to invoices.class.php

* Rename navigation.php to navigation.class.php

* Rename products.php to products.class.php

* Rename reports.php to reports.class.php

* Rename thirdparty.php to thirdparty.class.php

* fix pre-commit

* Update parse_intent.php

* fix pre commit

* fix phpdoc

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* fix pre-commit

* add missing phpdoc

* fix pre-commit

* fix phpdoc

* fix phpdoc

* fix pre-commit

* fix pre-commit

* fix phpdoc

* fix pre-commit

* fix pre-commit

* fix phpdoc

* fix phpdoc

* fix phpdoc

* fix phpdoc

* fix php-stan

* fix php-stan

* fix phan

* fix phan

* fix phan

* security check

* security check

* security check

* security check

* enhance security check

* enhance security check

* fix pre-commit

* Update log_viewer.php

* Improve access control logic in log_viewer.php

Refactor access control checks for admin and module activation.

* fix phan

* fix phan

* fix phan

* fix phan

* fix phan

* try fix phan

* fix pre-commit

* fix phan

* try fix phan

* fix phan

* fix php-stan

* fix phan php-stan

* fix pre-commit

* fix phan php-stan

* fix pre-commit

* fix phan php-stan

* fix phan php-stan

* fix phn php-stan

* fix phan php-stan

* fix phan php-stan

* fix phan php-stan

* fix phan php-stan

* fix pre-commit

* fix phan php-stan

* fix php-stan

* Fix MCP tool registration for .class.php file naming

* fix typo

* fix ci

* fix pre-commit

* fix ci

* fix pre-commit

* Update categories.class.php

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* fix ci

* add missing user in constructor

* add missing user in constructor

* improve invoice validation error handling

* add missing user in constructor

* Rename mcp_protocol.php to mcp_protocol.class.php

* Update mcp_server.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2026-05-11 01:59:55 +02:00