Просмотр исходного кода

#5406 AI Agents revamp: get single comment info tool

Aleksandr Trofimov 3 месяцев назад
Родитель
Сommit
740cb0ce6c
3 измененных файлов с 51 добавлено и 1 удалено
  1. 47 0
      inc/classes/BxDolAIToolCmtsGetSingle.php
  2. 1 0
      inc/classes/BxDolCmtsQuery.php
  3. 3 1
      install/sql/system.sql

+ 47 - 0
inc/classes/BxDolAIToolCmtsGetSingle.php

@@ -0,0 +1,47 @@
+<?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\PropertyType;
+use NeuronAI\Tools\ToolProperty;
+
+class BxDolAIToolCmtsGetSingle extends BxDolAITool
+{
+    public function __construct()
+    {
+        parent::__construct(
+            'comment_get',
+            'Get single comment info. Prepend base URL to links in comment info: ' . BX_DOL_URL_ROOT,
+        );
+    }
+    
+    protected function properties(): array
+    {
+        return [
+            new ToolProperty(
+                name: 'comment_id',
+                type: PropertyType::INTEGER,
+                description: 'ID of comment to get.',
+                required: true
+            ),
+        ];
+    }
+
+    public function __invoke(int $comment_id): array
+    {
+        $aCmt = BxDolCmtsQuery::getCommentExtendedByUniqId($comment_id);        
+        $oCmtsObject = $aCmt ? BxDolCmts::getObjectInstance($aCmt['system_name'], $aCmt['cmt_object_id']) : null;
+
+        if ($oCmtsObject) {
+            $a = $oCmtsObject->getDataAPI($aCmt);
+            return $a['data_api'];
+        }
+
+        return ['msg' => '_sys_txt_not_found', 'code' => 404];
+    }
+}

+ 1 - 0
inc/classes/BxDolCmtsQuery.php

@@ -174,6 +174,7 @@ class BxDolCmtsQuery extends BxDolDb
         $sQuery = "SELECT 
                 `ti`.`cmt_id` AS `cmt_id`, 
                 `ti`.`system_id` AS `cmt_system_id`, 
+                `to`.`Name` AS `system_name`,
                 `to`.`Table` AS `cmt_table` 
             FROM `" . BxDolCmts::$sTableIds . "` AS `ti` 
             INNER JOIN  `" . BxDolCmts::$sTableSystems . "` AS `to` ON  `ti`.`system_id` = `to`.`ID`

+ 3 - 1
install/sql/system.sql

@@ -7352,7 +7352,9 @@ INSERT INTO `sys_agents_tools` (`type`, `title`, `docs`, `params`, `params_user`
 ('comments_get', 'Comments get', 'This tool allows agents to get comments for specific content by module name and content id.', '{}', NULL, 0, 0, 1, 'BxDolAIToolCmtsGet', ''),
 ('comments_add', 'Comments add', 'This tool allows agents to post comments for specific content.', '{}', NULL, 0, 0, 1, 'BxDolAIToolCmtsAdd', ''),
 ('comments_update', 'Comments update', 'This tool allows agents to edit comments.', '{}', NULL, 0, 0, 1, 'BxDolAIToolCmtsUpdate', ''),
-('comments_delete', 'Comments delete', 'This tool allows agents to delete comments.', '{}', NULL, 0, 0, 1, 'BxDolAIToolCmtsDelete', '');
+('comments_delete', 'Comments delete', 'This tool allows agents to delete comments.', '{}', NULL, 0, 0, 1, 'BxDolAIToolCmtsDelete', ''),
+
+('comment_get', 'Comment get', 'This tool allows agents to get single comment by global comment id.', '{}', NULL, 0, 0, 1, 'BxDolAIToolCmtsGetSingle', '');
 
 CREATE TABLE IF NOT EXISTS `sys_agents_chat_history` (
   `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,