28if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL', 1);
31if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU', 1);
34if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML', 1);
37if (!defined(
'NOREQUIREAJAX')) {
38 define(
'NOREQUIREAJAX', 1);
41if (!defined(
'NOCSRFCHECK')) {
42 define(
'NOCSRFCHECK', 1);
45require
'../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.
'/ai/class/mcp.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/ai/tools/api_bridge.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/ai/lib/ai.lib.php';
61if (!$user->hasRight(
'ai',
'assistant',
'use')) {
70if (
GETPOST(
'action',
'aZ09') ==
'purge') {
73 $nbpurged = $bridge->purgeDefsCache();
74 dol_syslog(
'AI assistant /reload: '.$nbpurged.
' tool definitions cache file(s) purged', LOG_INFO, 0,
'_ai');
75 print json_encode(array(
'status' =>
'ok',
'purged' => $nbpurged));
76 }
catch (Throwable $e) {
77 dol_syslog(
'AI assistant /reload error: '.$e->getMessage().
' in '.$e->getFile().
' on line '.$e->getLine(), LOG_ERR, 0,
'_ai');
78 print json_encode(array(
'error' => $e->getMessage()));
88foreach ($mcp->getToolsSchemaForLLM() as $def) {
89 $name = (string) ($def[
'name'] ??
'');
93 $schema = (isset($def[
'inputSchema']) && is_array($def[
'inputSchema'])) ? $def[
'inputSchema'] : array();
95 foreach (($schema[
'properties'] ?? array()) as $pname => $pdef) {
98 $props[$pname] = array(
99 'type' => (
string) ($pdef[
'type'] ??
'string'),
100 'description' =>
dol_trunc((
string) ($pdef[
'description'] ??
''), 200),
101 'enum' => array_values((array) ($pdef[
'enum'] ?? array())),
102 'items' => (isset($pdef[
'items'][
'properties']) && is_array($pdef[
'items'][
'properties'])) ? array_keys($pdef[
'items'][
'properties']) : array()
106 $tool = $mcp->toolsByName[$name] ??
null;
107 $route = ($tool instanceof
ToolApiBridge) ? $tool->toolRoute($name) :
null;
112 'properties' => $props,
113 'required' => array_values((array) ($schema[
'required'] ?? array()))
124 return strcmp($a[
'title'], $b[
'title']) ?: strcmp($a[
'name'], $b[
'name']);
128print json_encode(array(
'tools' => $out));
aiPaletteToolTitle($langs, $name, $route)
Plain name of a tool for the palette of the chat: "Get invoice" rather than api_invoices_get.
aiPaletteToolDescription($description)
Description of a tool for the palette: without the sentence every generated bridge tool repeats,...
aiCheckCsrfToken($context='')
Check the anti-CSRF token of a request sent to one of the AI Assistant endpoints.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to handle MCP (Model Context Protocol).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.