BxDolAIToolContentAdd.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\ToolProperty;
  11. use NeuronAI\Tools\ArrayProperty;
  12. use NeuronAI\Tools\ObjectProperty;
  13. class BxDolAIToolContentAdd extends BxDolAITool
  14. {
  15. public function __construct()
  16. {
  17. parent::__construct(
  18. 'content_add',
  19. '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() . '.',
  20. );
  21. }
  22. protected function properties(): array
  23. {
  24. return [
  25. new ToolProperty(
  26. name: 'module',
  27. type: PropertyType::STRING,
  28. description: 'The module name to perform content changes on. Use "system" for site accounts. ',
  29. required: true
  30. ),
  31. new ArrayProperty(
  32. name: 'data',
  33. 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."}.',
  34. required: true,
  35. items: new ObjectProperty(
  36. name: 'parameter',
  37. properties: [
  38. new ToolProperty('name', PropertyType::STRING, 'Parameter name', true),
  39. new ToolProperty('value', PropertyType::STRING, 'Parameter value', true),
  40. ]
  41. )
  42. ),
  43. new ToolProperty(
  44. name: 'profile_id',
  45. type: PropertyType::INTEGER,
  46. description: 'Author profile ID.',
  47. required: true
  48. )
  49. ];
  50. }
  51. public function __invoke(string $module, array $data, int $profile_id): array
  52. {
  53. if ($profile_id) {
  54. $GLOBALS['glForceCurrentProfileId'] = $profile_id;
  55. }
  56. $a = bx_srv('system', 'add', [$module, $this->convertArrayToKeyValue($data)], 'TemplServiceContent');
  57. $GLOBALS['glForceCurrentProfileId'] = 0;
  58. return $a;
  59. }
  60. }