浏览代码

#5406 AI Agents revamp: content change tools

Aleksandr Trofimov 6 月之前
父节点
当前提交
d3a825f638

+ 20 - 20
composer.lock

@@ -207,16 +207,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.379.0",
+            "version": "3.379.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "a50c3cc2c59f5ebeb56cbe170e6f144034b252b6"
+                "reference": "45c385619d43e54ede8daca211960c345d3ff3b7"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/a50c3cc2c59f5ebeb56cbe170e6f144034b252b6",
-                "reference": "a50c3cc2c59f5ebeb56cbe170e6f144034b252b6",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/45c385619d43e54ede8daca211960c345d3ff3b7",
+                "reference": "45c385619d43e54ede8daca211960c345d3ff3b7",
                 "shasum": ""
             },
             "require": {
@@ -298,9 +298,9 @@
             "support": {
                 "forum": "https://github.com/aws/aws-sdk-php/discussions",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.379.0"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.379.2"
             },
-            "time": "2026-04-13T18:11:10+00:00"
+            "time": "2026-04-17T18:05:27+00:00"
         },
         {
             "name": "bshaffer/oauth2-server-php",
@@ -1979,16 +1979,16 @@
         },
         {
             "name": "neuron-core/neuron-ai",
-            "version": "3.3.8",
+            "version": "3.3.9",
             "source": {
                 "type": "git",
                 "url": "https://github.com/neuron-core/neuron-ai.git",
-                "reference": "1d4f433f055deb3c89f4378a33ec1b04180f4e7d"
+                "reference": "bf065041bbf86c07e49e168b73a4403c7b2ebfc9"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/neuron-core/neuron-ai/zipball/1d4f433f055deb3c89f4378a33ec1b04180f4e7d",
-                "reference": "1d4f433f055deb3c89f4378a33ec1b04180f4e7d",
+                "url": "https://api.github.com/repos/neuron-core/neuron-ai/zipball/bf065041bbf86c07e49e168b73a4403c7b2ebfc9",
+                "reference": "bf065041bbf86c07e49e168b73a4403c7b2ebfc9",
                 "shasum": ""
             },
             "require": {
@@ -2039,7 +2039,7 @@
             "description": "The PHP Agentic Framework.",
             "support": {
                 "issues": "https://github.com/neuron-core/neuron-ai/issues",
-                "source": "https://github.com/neuron-core/neuron-ai/tree/3.3.8"
+                "source": "https://github.com/neuron-core/neuron-ai/tree/3.3.9"
             },
             "funding": [
                 {
@@ -2047,7 +2047,7 @@
                     "type": "github"
                 }
             ],
-            "time": "2026-04-14T16:24:52+00:00"
+            "time": "2026-04-20T10:16:04+00:00"
         },
         {
             "name": "nyholm/psr7",
@@ -3871,7 +3871,7 @@
         },
         {
             "name": "symfony/polyfill-ctype",
-            "version": "v1.35.0",
+            "version": "v1.36.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/polyfill-ctype.git",
@@ -3930,7 +3930,7 @@
                 "portable"
             ],
             "support": {
-                "source": "https://github.com/symfony/polyfill-ctype/tree/v1.35.0"
+                "source": "https://github.com/symfony/polyfill-ctype/tree/v1.36.0"
             },
             "funding": [
                 {
@@ -3954,7 +3954,7 @@
         },
         {
             "name": "symfony/polyfill-mbstring",
-            "version": "v1.35.0",
+            "version": "v1.36.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/polyfill-mbstring.git",
@@ -4015,7 +4015,7 @@
                 "shim"
             ],
             "support": {
-                "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.35.0"
+                "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.36.0"
             },
             "funding": [
                 {
@@ -4039,7 +4039,7 @@
         },
         {
             "name": "symfony/polyfill-php80",
-            "version": "v1.35.0",
+            "version": "v1.36.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/polyfill-php80.git",
@@ -4099,7 +4099,7 @@
                 "shim"
             ],
             "support": {
-                "source": "https://github.com/symfony/polyfill-php80/tree/v1.35.0"
+                "source": "https://github.com/symfony/polyfill-php80/tree/v1.36.0"
             },
             "funding": [
                 {
@@ -4123,7 +4123,7 @@
         },
         {
             "name": "symfony/polyfill-php82",
-            "version": "v1.35.0",
+            "version": "v1.36.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/polyfill-php82.git",
@@ -4179,7 +4179,7 @@
                 "shim"
             ],
             "support": {
-                "source": "https://github.com/symfony/polyfill-php82/tree/v1.35.0"
+                "source": "https://github.com/symfony/polyfill-php82/tree/v1.36.0"
             },
             "funding": [
                 {

+ 31 - 0
inc/classes/BxDolAITool.php

@@ -0,0 +1,31 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+use NeuronAI\Tools\Tool;
+
+class BxDolAITool extends Tool
+{
+    function getContentModules() 
+    {
+        $a = bx_srv('system', 'modules_list', [true, true], 'TemplServiceContent');
+        return implode(', ', $a);
+    }
+
+    function convertArrayToKeyValue($data) {
+        $result = [];
+        
+        foreach ($data as $item) {
+            if (isset($item['name']) && isset($item['value'])) {
+                $result[$item['name']] = $item['value'];
+            }
+        }
+        
+        return $result;
+    }
+}

+ 15 - 10
inc/classes/BxDolAIToolContentAdd.php

@@ -8,18 +8,17 @@
  */
 
 use NeuronAI\Tools\PropertyType;
-use NeuronAI\Tools\Tool;
 use NeuronAI\Tools\ToolProperty;
 use NeuronAI\Tools\ArrayProperty;
 use NeuronAI\Tools\ObjectProperty;
 
-class BxDolAIToolContentAdd extends Tool
+class BxDolAIToolContentAdd extends BxDolAITool
 {
     public function __construct()
     {
         parent::__construct(
             'content_add',
-            'Use this tool to add content to content modules. Always use "content_structure" tool to get knowledge about content modules fields. Available modules: ' . bx_srv('system', 'modules_list', [true, true], 'TemplServiceContent') . '.',
+            'Use this tool to add content to content modules. Always use "content_structure" tool to get knowledge about content modules fields. Available modules: ' . $this->getContentModules() . '.',
         );
     }
 
@@ -32,11 +31,17 @@ class BxDolAIToolContentAdd extends Tool
                 description: 'The module name to perform content changes on. Use "system" for site accounts. ',
                 required: true
             ),
-            new ToolProperty(
+            new ArrayProperty(
                 name: 'data',
-                type: PropertyType::OBJECT,
-                description: 'The data to add, as key-value pairs.',
-                required: true
+                description: 'Key-value pairs of data fields to add, where keys match the field names. Example: {"title": "Hello song title", "text": "Hello song text goes here."}.',
+                required: true,
+                items: new ObjectProperty(
+                    name: 'parameter',
+                    properties: [
+                        new ToolProperty('name', PropertyType::STRING, 'Parameter name', true),
+                        new ToolProperty('value', PropertyType::STRING, 'Parameter value', true),
+                    ]
+                )
             ),
             new ToolProperty(
                 name: 'profile_id',
@@ -47,16 +52,16 @@ class BxDolAIToolContentAdd extends Tool
         ];
     }
 
-    public function __invoke(string $module, array $data, int $profile_id): string
+    public function __invoke(string $module, array $data, int $profile_id): array
     {
         if ($profile_id) {
             $GLOBALS['glForceCurrentProfileId'] = $profile_id;
         }
 
-        $a = bx_srv('system', 'add', [$module, $data], 'TemplServiceContent');
+        $a = bx_srv('system', 'add', [$module, $this->convertArrayToKeyValue($data)], 'TemplServiceContent');
 
         $GLOBALS['glForceCurrentProfileId'] = 0;
 
-        return json_encode($a);
+        return $a;
     }
 }

+ 4 - 5
inc/classes/BxDolAIToolContentDelete.php

@@ -8,18 +8,17 @@
  */
 
 use NeuronAI\Tools\PropertyType;
-use NeuronAI\Tools\Tool;
 use NeuronAI\Tools\ToolProperty;
 use NeuronAI\Tools\ArrayProperty;
 use NeuronAI\Tools\ObjectProperty;
 
-class BxDolAIToolContentChange extends Tool
+class BxDolAIToolContentDelete extends BxDolAITool
 {
     public function __construct()
     {
         parent::__construct(
             'content_delete',
-            'Use this tool to delete content. Available modules: ' . bx_srv('system', 'modules_list', [true, true], 'TemplServiceContent') . '.',
+            'Use this tool to delete content. Available modules: ' . $this->getContentModules() . '.',
         );
     }
 
@@ -41,9 +40,9 @@ class BxDolAIToolContentChange extends Tool
         ];
     }
 
-    public function __invoke(string $module, int $content_id = 0): string
+    public function __invoke(string $module, int $content_id = 0): array
     {        
         $a = bx_srv('system', 'delete', [$module, $content_id], 'TemplServiceContent');
-        return json_encode($a);
+        return $a;
     }
 }

+ 1 - 3
inc/classes/BxDolAIToolContentGet.php

@@ -8,10 +8,9 @@
  */
 
 use NeuronAI\Tools\PropertyType;
-use NeuronAI\Tools\Tool;
 use NeuronAI\Tools\ToolProperty;
 
-class BxDolAIToolContentGet extends Tool
+class BxDolAIToolContentGet extends BxDolAITool
 {
     public function __construct()
     {
@@ -41,7 +40,6 @@ class BxDolAIToolContentGet extends Tool
 
     public function __invoke(string $module, int $content_id): array
     {
-echoDbgLog("Invoking content get tool with module: {$module}, content_id: {$content_id}");
         $a = bx_srv('system', 'get_info', [$module, $content_id], 'TemplServiceContent');
         if (!$a)
             return ["error" => "Content item was not found"];

+ 1 - 2
inc/classes/BxDolAIToolContentSearch.php

@@ -8,11 +8,10 @@
  */
 
 use NeuronAI\Tools\PropertyType;
-use NeuronAI\Tools\Tool;
 use NeuronAI\Tools\ToolProperty;
 use NeuronAI\Tools\ArrayProperty;
 
-class BxDolAIToolContentSearch extends Tool
+class BxDolAIToolContentSearch extends BxDolAITool
 {
     public function __construct()
     {

+ 1 - 2
inc/classes/BxDolAIToolContentStructure.php

@@ -8,10 +8,9 @@
  */
 
 use NeuronAI\Tools\PropertyType;
-use NeuronAI\Tools\Tool;
 use NeuronAI\Tools\ToolProperty;
 
-class BxDolAIToolContentStructure extends Tool
+class BxDolAIToolContentStructure extends BxDolAITool
 {
     public function __construct()
     {

+ 14 - 9
inc/classes/BxDolAIToolContentUpdate.php

@@ -8,18 +8,17 @@
  */
 
 use NeuronAI\Tools\PropertyType;
-use NeuronAI\Tools\Tool;
 use NeuronAI\Tools\ToolProperty;
 use NeuronAI\Tools\ArrayProperty;
 use NeuronAI\Tools\ObjectProperty;
 
-class BxDolAIToolContentUpdate extends Tool
+class BxDolAIToolContentUpdate extends BxDolAITool
 {
     public function __construct()
     {
         parent::__construct(
             'content_update',
-            'Use this tool to update content. Always use "content_structure" tool to get knowledge about content modules fields. Available modules: ' . bx_srv('system', 'modules_list', [true, true], 'TemplServiceContent') . '.',
+            'Use this tool to update content. Always use "content_structure" tool to get knowledge about content modules fields. Available modules: ' . $this->getContentModules() . '.',
         );
     }
 
@@ -38,11 +37,17 @@ class BxDolAIToolContentUpdate extends Tool
                 description: 'Content ID to update.',
                 required: true
             ),
-            new ToolProperty(
+            new ArrayProperty(
                 name: 'data',
-                type: PropertyType::OBJECT,
-                description: 'The data to update, as key-value pairs.',
-                required: true
+                description: 'Key-value pairs of data fields to add, where keys match the field names. Never use fields what aren\'t defined in content structure.',
+                required: true,
+                items: new ObjectProperty(
+                    name: 'parameter',
+                    properties: [
+                        new ToolProperty('name', PropertyType::STRING, 'Parameter name', true),
+                        new ToolProperty('value', PropertyType::STRING, 'Parameter value', true),
+                    ]
+                )
             ),
             new ToolProperty(
                 name: 'profile_id',
@@ -53,13 +58,13 @@ class BxDolAIToolContentUpdate extends Tool
         ];
     }
 
-    public function __invoke(string $module, int $content_id, array $data, int $profile_id): string
+    public function __invoke(string $module, int $content_id, array $data, int $profile_id): array
     {
         if ($profile_id) {
             $GLOBALS['glForceCurrentProfileId'] = $profile_id;
         }
 
-        $a = bx_srv('system', 'update', [$module, $content_id, $data], 'TemplServiceContent');
+        $a = bx_srv('system', 'update', [$module, $content_id, $this->convertArrayToKeyValue($data)], 'TemplServiceContent');
 
         $GLOBALS['glForceCurrentProfileId'] = 0;
 

+ 3 - 3
inc/classes/BxDolAiAgent.php

@@ -19,10 +19,11 @@ class BxDolAiAgent extends RAG
 
         $sKey = getParam('sys_agents_inspector_key');
         if ($sKey) {
-            $this->observe(InspectorObserver::instance(
+            $logger = InspectorObserver::instance(
                 key: $sKey,
                 autoFlush: true,
-            ));            
+            );
+            $this->observe($logger);
         }
         else {
             $logger = new BxDolLoggerDb('sys_agents_' . $this->aAgent['id']);
@@ -95,7 +96,6 @@ class BxDolAiAgent extends RAG
 
     protected function getСhatHistoryThreadId(): string
     {
-        echoDbgLog($this->aParams);
         $s = $this->aAgent['trigger'] . ':' . $this->aAgent['id'];
         if (isset($this->aParams['chat_history_subindex']))
             $s .=  ':' . $this->aParams['chat_history_subindex'];