|
| 1 | +<?php |
| 2 | + |
| 3 | +return new class() { |
| 4 | + /** |
| 5 | + * @var \MODX\Revolution\modX |
| 6 | + */ |
| 7 | + private $modx; |
| 8 | + |
| 9 | + /** |
| 10 | + * @var int |
| 11 | + */ |
| 12 | + private $action; |
| 13 | + |
| 14 | + /** |
| 15 | + * @param \MODX\Revolution\modX $modx |
| 16 | + * @param int $action |
| 17 | + * @return bool |
| 18 | + */ |
| 19 | + public function __invoke(&$modx, $action) |
| 20 | + { |
| 21 | + $this->modx =& $modx; |
| 22 | + $this->action = $action; |
| 23 | + |
| 24 | + if ($this->action === \xPDO\Transport\xPDOTransport::ACTION_UNINSTALL) { |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + /** @var class-string<\modAI\Tools\ToolInterface>[] $tools */ |
| 29 | + $tools = [ |
| 30 | + \modAI\Tools\GetWeather::class, |
| 31 | + |
| 32 | + \modAI\Tools\GetCategories::class, |
| 33 | + \modAI\Tools\CreateCategory::class, |
| 34 | + |
| 35 | + \modAI\Tools\GetChunks::class, |
| 36 | + \modAI\Tools\CreateChunk::class, |
| 37 | + |
| 38 | + \modAI\Tools\GetTemplates::class, |
| 39 | + \modAI\Tools\CreateTemplate::class, |
| 40 | + |
| 41 | + \modAI\Tools\CreateResource::class, |
| 42 | + \modAI\Tools\GetResources::class, |
| 43 | + \modAI\Tools\GetResourceDetail::class, |
| 44 | + ]; |
| 45 | + |
| 46 | + foreach ($tools as $tool) { |
| 47 | + $exists = $this->modx->getCount(\modAI\Model\Tool::class, ['name' => $tool::getSuggestedName()]); |
| 48 | + if ($exists > 0) { |
| 49 | + continue; |
| 50 | + } |
| 51 | + |
| 52 | + $toolObjects = $this->modx->newObject(\modAI\Model\Tool::class, [ |
| 53 | + 'class' => $tool, |
| 54 | + 'name' => $tool::getSuggestedName(), |
| 55 | + 'description' => $tool::getDescription(), |
| 56 | + 'prompt' => null, |
| 57 | + 'config' => null, |
| 58 | + 'default' => false, |
| 59 | + 'enabled' => true, |
| 60 | + ]); |
| 61 | + |
| 62 | + $toolObjects->save(); |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + return true; |
| 67 | + } |
| 68 | +}; |
0 commit comments