BxDolAIToolContentUpdate.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. use NeuronAI\Tools\PropertyType;
  10. use NeuronAI\Tools\Tool;
  11. use NeuronAI\Tools\ToolProperty;
  12. use NeuronAI\Tools\ArrayProperty;
  13. use NeuronAI\Tools\ObjectProperty;
  14. class BxDolAIToolContentUpdate extends Tool
  15. {
  16. public function __construct()
  17. {
  18. parent::__construct(
  19. 'content_update',
  20. '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') . '.',
  21. );
  22. }
  23. protected function properties(): array
  24. {
  25. return [
  26. new ToolProperty(
  27. name: 'module',
  28. type: PropertyType::STRING,
  29. description: 'The module name to perform content changes on. Use "system" for site accounts. ',
  30. required: true
  31. ),
  32. new ToolProperty(
  33. name: 'content_id',
  34. type: PropertyType::INTEGER,
  35. description: 'Content ID to update.',
  36. required: true
  37. ),
  38. new ToolProperty(
  39. name: 'data',
  40. type: PropertyType::OBJECT,
  41. description: 'The data to update, as key-value pairs.',
  42. required: true
  43. ),
  44. new ToolProperty(
  45. name: 'profile_id',
  46. type: PropertyType::INTEGER,
  47. description: 'Author profile ID.',
  48. required: true
  49. )
  50. ];
  51. }
  52. public function __invoke(string $module, int $content_id, array $data, int $profile_id): string
  53. {
  54. if ($profile_id) {
  55. $GLOBALS['glForceCurrentProfileId'] = $profile_id;
  56. }
  57. $a = bx_srv('system', 'update', [$module, $content_id, $data], 'TemplServiceContent');
  58. $GLOBALS['glForceCurrentProfileId'] = 0;
  59. return $a;
  60. }
  61. }