Skip to content

Commit 8e22bf3

Browse files
Mark-Htheboxer
authored andcommitted
refactor(tools): improve descriptions and behavior for consistency
- Updated tool descriptions for clarity and to align with MODX terminology and best practices. - Added filters such as `deleted` and `searchable` in GetResources. - Enhanced return properties (e.g., added public URL to GetResources). - Refined templates and chunks search logic by removing redundant category filters. - Improved user confirmation instructions across resource and element creation tools.
1 parent a2121c3 commit 8e22bf3

File tree

9 files changed

+22
-39
lines changed

9 files changed

+22
-39
lines changed

core/components/modai/src/Tools/CreateCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function getSuggestedName(): string
1616

1717
public static function getDescription(): string
1818
{
19-
return "ALWAYS ask for explicit user confirmation in a separate message before calling this function, even if user asks directly for creating categories, you HAVE TO ask for their confirmation in a separate message, provide a list of name, and parent category name that you want to create. If needed, use an appropriate tool to first list available categories. Creates new MODX categories and returns their IDs.";
19+
return "Creates a new Category that any element (chunks or templates) can be grouped by. Use the get categories tool first to check if a category already exists. When successful, this tool returns the category ID to use when creating chunks or templates.";
2020
}
2121

2222
public static function getParameters(): array

core/components/modai/src/Tools/CreateChunk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function getSuggestedName(): string
1616

1717
public static function getDescription(): string
1818
{
19-
return "ALWAYS ask for explicit user confirmation in a separate message before calling this function, even if user asks directly for creating chunk, you HAVE TO ask for their confirmation in a separate message, provide a list of name, description and category name, DON'T output content, that you want to create. If needed, use an appropriate tool to first create categories, wait for it's response and then continue with calling this tool. Creates new MODX chunks. Don't ask for the parameters, unless they were already provided.";
19+
return "Creates a new Chunk, which is a reusable piece of HTML or other code that can be inserted into pages, templates, or other elements. Use when explicitly asked to create a chunk or when creating templates to break up reusable pieces. Once created, chunks can be rendered by using [[\$name_of_chunk]] in a template or elsewhere. ALWAYS ask for explicit user confirmation with the chunk name, description, and category name in a separate message BEFORE calling this function.";
2020
}
2121

2222
public static function getParameters(): array

core/components/modai/src/Tools/CreateResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function getSuggestedName(): string
1616

1717
public static function getDescription(): string
1818
{
19-
return "ALWAYS ask for explicit user confirmation in a separate message before calling this function, even if user asks directly for creating resource (page), you HAVE TO ask for their confirmation in a separate message, provide a list of page titles, DON'T output content, that you want to create. If needed, use an appropriate tool to first create categories or templates, wait for it's response and then continue with calling this tool. Creates new MODX resource (page). Don't ask for the parameters, if they were not provided, make them up.";
19+
return "Creates a new resource, or page, on the website. ALWAYS ask for explicit user confirmation in a separate message before calling this function, even if user asks directly to create a resource, ask the user to confirm the resource before calling the tool with the information you intend to use. ";
2020
}
2121

2222
public static function getParameters(): array

core/components/modai/src/Tools/CreateTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function getSuggestedName(): string
1616

1717
public static function getDescription(): string
1818
{
19-
return "ALWAYS ask for explicit user confirmation in a separate message before calling this function, even if user asks directly for creating template, you HAVE TO ask for their confirmation in a separate message, provide a list of name, description and category name, DON'T output content, that you want to create. If needed, use an appropriate tool to first create categories, wait for it's response and then continue with calling this tool. Creates new MODX templates. Don't ask for the parameters, if they were not provided, make them up.";
19+
return "Creates a new template for the website, which can be assigned to resources to determine how they are rendered in the frontend. Only use when explicitly asked to create a new template, and always check if appropriate templates already exist first. Always ask for explicit user confirmation in a separate message, providing the user with the template name and a summary of what the contents would be, BEFORE calling this function. Do NOT output the full template content. When generating template content you MUST make sure it uses the MODX templating syntax.";
2020
}
2121

2222
public static function getParameters(): array

core/components/modai/src/Tools/GetCategories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function getSuggestedName(): string
1616

1717
public static function getDescription(): string
1818
{
19-
return "Get all categories in the current MODX Revolution database. Categories are used to separate chunks, snippets, templates, template variables and plugins. Each category can have parent to create a tree like structure. If parent is 0, the category is at root level.";
19+
return "Lists all categories used to group templates and chunks. Each category can have a parent to create a tree like structure. If parent is 0, the category is at root level.";
2020
}
2121

2222
public static function getParameters(): array

core/components/modai/src/Tools/GetChunks.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static function getSuggestedName(): string
1616

1717
public static function getDescription(): string
1818
{
19-
return "Get or search chunks (modChunk) from current MODX Revolution database. You can provide optional parameters to return only specific chunks - query: search chunks by name, broad match; name: return chunk with a given name; id: return chunk with a given ID. You'll receive an array of chunks with a properties of id, name, description, category (ID of a category) and optionally content.";
19+
return "Find existing chunks in the website. Chunks are reusable pieces of HTML or other content. The tool can search for Get or search chunks (modChunk) from current MODX Revolution database. You can provide optional parameters to return only specific chunks - query: search chunks by name, broad match; name: return chunk with a given name; id: return chunk with a given ID. You'll receive an array of chunks with a properties of id, name, description, category (ID of a category) and optionally content.";
2020
}
2121

2222
public static function getParameters(): array
@@ -26,26 +26,22 @@ public static function getParameters(): array
2626
'properties' => [
2727
'query' => [
2828
'type' => 'string',
29-
"description" => 'Search by category name'
29+
"description" => 'Simple wild-card search on the chunk name'
3030
],
3131
'name' => [
3232
'type' => 'string',
33-
"description" => 'Get single chunk by name'
33+
"description" => 'Get a single chunk by name if you already know the name'
3434
],
3535
'id' => [
3636
'type' => 'number',
37-
"description" => 'Get single chunk by ID'
37+
"description" => 'Get a single chunk by its ID'
3838
],
3939
'categories' => [
4040
'type' => 'array',
4141
'items' => [
4242
'type' => 'number',
4343
],
44-
"description" => 'Search chunks by multiple category IDs'
45-
],
46-
'category' => [
47-
'type' => 'number',
48-
"description" => 'Search chunks by category ID'
44+
"description" => 'List chunks that are assigned to the provided category ID(s)'
4945
],
5046
'returnContent' => [
5147
'type' => 'boolean',
@@ -97,12 +93,6 @@ public function runTool($parameters): string
9793
];
9894
}
9995

100-
if (!empty($parameters['category'])) {
101-
$where[] = [
102-
'category' => $parameters['category'],
103-
];
104-
}
105-
10696
if (!empty($parameters['categories'])) {
10797
$where[] = [
10898
'category:IN' => $parameters['categories'],

core/components/modai/src/Tools/GetResourceDetail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function getSuggestedName(): string
1717

1818
public static function getDescription(): string
1919
{
20-
return "Use this tool to get more information about a resource, concept, or service you are unfamiliar with from of an array of integer resource IDs. Use the appropriate tool first to identify relevant resources on a topic. The tool will retrieve metadata, like title, description, published state, and last edit dates, as well as full HTML-formatted content. Provide at least one, or multiple resource IDs.";
20+
return "Get more information about a resource, page, concept, or service you are unfamiliar with from of an array of integer resource IDs. Use the appropriate tool first to identify relevant resources on a topic. The tool will retrieve metadata, like title, description, published state, and last edit dates, as well as full HTML-formatted content. Provide at least one, or multiple resource IDs.";
2121
}
2222

2323
public static function getParameters(): array
@@ -31,7 +31,7 @@ public static function getParameters(): array
3131
'items' => [
3232
'type' => 'number'
3333
],
34-
"description" => 'Array of IDs of resources to get details for.'
34+
"description" => 'Array of IDs of resources to load.'
3535
],
3636
],
3737
"required" => ['ids']

core/components/modai/src/Tools/GetResources.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function getSuggestedName(): string
1717

1818
public static function getDescription(): string
1919
{
20-
return "Get or search resources (modResource) from current MODX Revolution database. You can provide optional parameters to return only specific resources. You'll receive an array of resources with a properties of id, pagetitle, parent (ID of another resource), template (ID of a template) and edit url.";
20+
return "Search for resources, also called pages or documents, on the website. You can provide optional parameters to return only specific resources. Returns matching resources with their id, pagetitle, parent resource ID, template ID, edit url, and public URL.";
2121
}
2222

2323
public static function getParameters(): array
@@ -63,6 +63,8 @@ public function runTool($parameters): string
6363
}
6464

6565
$where = [];
66+
$where['deleted'] = false;
67+
$where['searchable'] = true;
6668

6769
if (is_array($parameters)) {
6870
if (!empty($parameters['query'])) {
@@ -97,6 +99,7 @@ public function runTool($parameters): string
9799
'parent' => $resource->get('parent'),
98100
'template' => $resource->get('template'),
99101
'edit_url' => $this->modx->config['manager_url'] . '?a=resource/update&id=' . $resource->get('id'),
102+
'url' => $this->modx->makeUrl($resource->get('id'), '', '', 'full'),
100103
];
101104

102105
$output[] = $arr;

core/components/modai/src/Tools/GetTemplates.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function getSuggestedName(): string
1717

1818
public static function getDescription(): string
1919
{
20-
return "Get or search templates (modTemplate) from current MODX Revolution database. You can provide optional parameters to return only specific templates. You'll receive an array of templates with a properties of id, name, description, category (ID of a category) and optionally content.";
20+
return "Find templates available in the website. Templates are assigned to resources and determine how a page is rendered to visitors. You can provide optional parameters to return only specific templates. You'll receive an array of templates with a properties of id, name, description, category (ID of a category) and optionally content.";
2121
}
2222

2323
public static function getParameters(): array
@@ -27,30 +27,26 @@ public static function getParameters(): array
2727
'properties' => [
2828
'query' => [
2929
'type' => 'string',
30-
"description" => 'Search templates by name'
30+
"description" => 'Search templates by a simple search on the name'
3131
],
3232
'name' => [
3333
'type' => 'string',
34-
"description" => 'Get single template by name'
34+
"description" => 'Get a template by its exact name'
3535
],
3636
'id' => [
3737
'type' => 'number',
38-
"description" => 'Get single template by ID'
38+
"description" => 'Get a template by its ID'
3939
],
4040
'categories' => [
4141
'type' => 'array',
4242
'items' => [
4343
'type' => 'number',
4444
],
45-
"description" => 'Search templates by multiple category IDs'
46-
],
47-
'category' => [
48-
'type' => 'number',
49-
"description" => 'Search templates by category ID'
45+
"description" => 'List templates within the provided categories'
5046
],
5147
'returnContent' => [
5248
'type' => 'boolean',
53-
"description" => 'Return template\'s content, use this only when you are tasked with updating template'
49+
"description" => 'Include the template content in the response, use this only when you are tasked with updating template'
5450
],
5551
],
5652
"required" => []
@@ -97,12 +93,6 @@ public function runTool($parameters): string
9793
];
9894
}
9995

100-
if (!empty($parameters['category'])) {
101-
$where[] = [
102-
'category' => $parameters['category'],
103-
];
104-
}
105-
10696
if (!empty($parameters['categories'])) {
10797
$where[] = [
10898
'category:IN' => $parameters['categories'],

0 commit comments

Comments
 (0)