From 411d6dc8e33f0b22311f844e02779f9af3e39b09 Mon Sep 17 00:00:00 2001 From: Ryan Thrash Date: Fri, 5 Jun 2026 17:06:52 -0500 Subject: [PATCH] fix: correct three bugs in built-in Tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found while documenting the built-in tools. - GetChunks / GetTemplates: the `name` filter built its WHERE clause from `$arguments['query']` instead of `$arguments['name']`, so filtering by exact name searched by the (often empty) query value and returned nothing. - CreateResource: the JSON-Schema `required` list was ["name", "description", "content"] — properties that don't exist on the item — while omitting `template` and `parent`, which runTool enforces at runtime. Corrected to ["pagetitle", "template", "parent", "content"] so the advertised schema matches what the tool actually requires. - EditChunk: the success branch returned before the clear_cache refresh, so the cache was never refreshed after a successful chunk edit (the refresh was only reachable on the failed-save path). Inverted the save check so the refresh runs before the success return, matching EditTemplate (which was already correct and is unchanged). Co-Authored-By: Claude Opus 4.8 --- core/components/modai/src/Tools/CreateResource.php | 2 +- core/components/modai/src/Tools/EditChunk.php | 6 +++--- core/components/modai/src/Tools/GetChunks.php | 2 +- core/components/modai/src/Tools/GetTemplates.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/components/modai/src/Tools/CreateResource.php b/core/components/modai/src/Tools/CreateResource.php index fda0f24..c0930e2 100644 --- a/core/components/modai/src/Tools/CreateResource.php +++ b/core/components/modai/src/Tools/CreateResource.php @@ -50,7 +50,7 @@ public static function getParameters(modX $modx): array "description" => 'The content of the new resource. Generate this based on the users\' prompt. Allow the user to iterate on the content to create before finally calling the appropriate tool. Generate the content as HTML.' ], ], - "required" => ["name", "description", 'content'] + "required" => ["pagetitle", "template", "parent", 'content'] ], "description" => "List of resources to create" ], diff --git a/core/components/modai/src/Tools/EditChunk.php b/core/components/modai/src/Tools/EditChunk.php index ff23d53..516c7c9 100644 --- a/core/components/modai/src/Tools/EditChunk.php +++ b/core/components/modai/src/Tools/EditChunk.php @@ -93,15 +93,15 @@ public function runTool(array $arguments): string } $chunk->set('description', (string)$arguments['chunk']['description']); $chunk->set('snippet', (string)$arguments['chunk']['content']); - if ($chunk->save()) { - return json_encode(['success' => true, 'message' => 'Chunk updated. Use with: [[$' . $chunk->get('name') . ']]']); + if (!$chunk->save()) { + return json_encode(['success' => false, 'message' => 'Could not save chunk.']); } if ($this->clearCache) { $this->modx->cacheManager->refresh(); } - return json_encode(['success' => false, 'message' => 'Could not save chunk.']); + return json_encode(['success' => true, 'message' => 'Chunk updated. Use with: [[$' . $chunk->get('name') . ']]']); } public static function checkPermissions(modX $modx): bool diff --git a/core/components/modai/src/Tools/GetChunks.php b/core/components/modai/src/Tools/GetChunks.php index 5dfdb65..83dbb2e 100644 --- a/core/components/modai/src/Tools/GetChunks.php +++ b/core/components/modai/src/Tools/GetChunks.php @@ -83,7 +83,7 @@ public function runTool(array $arguments): string if (!empty($arguments['name'])) { $where[] = [ - 'name' => $arguments['query'], + 'name' => $arguments['name'], ]; } diff --git a/core/components/modai/src/Tools/GetTemplates.php b/core/components/modai/src/Tools/GetTemplates.php index deb088d..1228603 100644 --- a/core/components/modai/src/Tools/GetTemplates.php +++ b/core/components/modai/src/Tools/GetTemplates.php @@ -83,7 +83,7 @@ public function runTool(array $arguments): string if (!empty($arguments['name'])) { $where[] = [ - 'templatename' => $arguments['query'], + 'templatename' => $arguments['name'], ]; }