Skip to content

Commit 09a8734

Browse files
Mark-Htheboxer
authored andcommitted
refactor(tools): update parameter 'parameters' to 'arguments' for consistency with ToolInterface
Updates new EditChunk and EditTemplate tools to the changed interface.
1 parent 6e4c49b commit 09a8734

File tree

12 files changed

+86
-76
lines changed

12 files changed

+86
-76
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ public function __construct(modX $modx, array $config)
6565
}
6666

6767
/**
68-
* @param array $parameters
68+
* @param array $arguments
6969
* @return string
7070
*/
71-
public function runTool($parameters): string
71+
public function runTool($arguments): string
7272
{
7373
if (!self::checkPermissions($this->modx)) {
7474
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
7575
}
7676

77-
if (empty($parameters)) {
77+
if (empty($arguments)) {
7878
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
7979
}
8080

8181
$output = [];
8282

83-
foreach ($parameters['categories'] as $data) {
83+
foreach ($arguments['categories'] as $data) {
8484
$category = $this->modx->newObject(modCategory::class);
8585
$category->set('category', $data['name']);
8686
$category->set('parent', $data['parent_id']);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ public function __construct(modX $modx, array $config)
6666
}
6767

6868
/**
69-
* @param array $parameters
69+
* @param array $arguments
7070
* @return string
7171
*/
72-
public function runTool($parameters): string
72+
public function runTool($arguments): string
7373
{
7474
if (!self::checkPermissions($this->modx)) {
7575
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
7676
}
7777

78-
if (empty($parameters)) {
78+
if (empty($arguments)) {
7979
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
8080
}
8181

8282
$output = [];
8383

84-
foreach ($parameters['chunks'] as $data) {
84+
foreach ($arguments['chunks'] as $data) {
8585
if ($exists = $this->modx->getObject('modChunk', ['name' => $data['name']])) {
8686
$output[] = [
8787
'id' => $exists->get('id'),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ public function __construct(modX $modx, array $config)
6666
}
6767

6868
/**
69-
* @param array $parameters
69+
* @param array $arguments
7070
* @return string
7171
*/
72-
public function runTool($parameters): string
72+
public function runTool($arguments): string
7373
{
7474
if (!self::checkPermissions($this->modx)) {
7575
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
7676
}
7777

78-
if (empty($parameters)) {
78+
if (empty($arguments)) {
7979
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
8080
}
8181

8282
$output = [];
8383

84-
foreach ($parameters['resources'] as $data) {
84+
foreach ($arguments['resources'] as $data) {
8585
if (!isset($data['parent'])) {
8686
return json_encode(['success' => false, 'message' => 'parent is required.']);
8787
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ public function __construct(modX $modx, array $config)
6666
}
6767

6868
/**
69-
* @param array $parameters
69+
* @param array $arguments
7070
* @return string
7171
*/
72-
public function runTool($parameters): string
72+
public function runTool($arguments): string
7373
{
7474
if (!self::checkPermissions($this->modx)) {
7575
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
7676
}
7777

78-
if (empty($parameters)) {
78+
if (empty($arguments)) {
7979
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
8080
}
8181

8282
$output = [];
8383

84-
foreach ($parameters['templates'] as $data) {
84+
foreach ($arguments['templates'] as $data) {
8585
if ($exists = $this->modx->getObject(modTemplate::class, ['templatename' => $data['name']])) {
8686
$output[] = [
8787
'id' => $exists->get('id'),

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function getSuggestedName(): string
1414
return 'edit_chunk';
1515
}
1616

17-
public static function getDescription(): string
17+
public static function getPrompt(): string
1818
{
1919
return "Edits an existing 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. Get the current content to edit using the get_chunks tool. Chunks can be used by adding [[\$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
}
@@ -48,7 +48,7 @@ public static function getParameters(): array
4848
];
4949
}
5050

51-
public static function getConfig(): array
51+
public static function getConfig(modX $modx): array
5252
{
5353
return [];
5454
}
@@ -59,25 +59,25 @@ public function __construct(modX $modx, array $config)
5959
}
6060

6161
/**
62-
* @param array $parameters
62+
* @param array $arguments
6363
* @return string
6464
*/
65-
public function runTool($parameters): string
65+
public function runTool($arguments): string
6666
{
6767
if (!self::checkPermissions($this->modx)) {
6868
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
6969
}
7070

71-
if (empty($parameters)) {
71+
if (empty($arguments)) {
7272
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
7373
}
7474

75-
$chunk = $this->modx->getObject(modChunk::class, ['name' => $parameters['chunk']['name']]);
75+
$chunk = $this->modx->getObject(modChunk::class, ['name' => $arguments['chunk']['name']]);
7676
if (!$chunk) {
7777
return json_encode(['success' => false, 'message' => 'Chunk not found with name.']);
7878
}
79-
$chunk->set('description', (string)$parameters['chunk']['description']);
80-
$chunk->set('snippet', (string)$parameters['chunk']['content']);
79+
$chunk->set('description', (string)$arguments['chunk']['description']);
80+
$chunk->set('snippet', (string)$arguments['chunk']['content']);
8181
if ($chunk->save()) {
8282
return json_encode(['success' => true, 'message' => 'Chunk updated. Use with: [[$' . $chunk->get('name') . ']]']);
8383
}
@@ -89,4 +89,9 @@ public static function checkPermissions(modX $modx): bool
8989
{
9090
return $modx->hasPermission('save_chunk');
9191
}
92+
93+
public static function getDescription(): string
94+
{
95+
return 'Allows the assistant to edit chunks.';
96+
}
9297
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static function getSuggestedName(): string
1414
return 'edit_template';
1515
}
1616

17-
public static function getDescription(): string
17+
public static function getPrompt(): string
1818
{
1919
return "Edits an existing template, which is used to render a resource on the front-end of the website. Use when explicitly asked to edit a template. In most cases, you should also check other templates to see the preferred coding style and structure of the website. Get the current content of the template with the get_templates tool. ALWAYS ask for explicit user confirmation with the template name and a summary of the changes you are making BEFORE calling this function.";
2020
}
@@ -48,7 +48,7 @@ public static function getParameters(): array
4848
];
4949
}
5050

51-
public static function getConfig(): array
51+
public static function getConfig(modX $modx): array
5252
{
5353
return [];
5454
}
@@ -59,25 +59,25 @@ public function __construct(modX $modx, array $config)
5959
}
6060

6161
/**
62-
* @param array $parameters
62+
* @param array $arguments
6363
* @return string
6464
*/
65-
public function runTool($parameters): string
65+
public function runTool($arguments): string
6666
{
6767
if (!self::checkPermissions($this->modx)) {
6868
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
6969
}
7070

71-
if (empty($parameters)) {
71+
if (empty($arguments)) {
7272
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
7373
}
7474

75-
$template = $this->modx->getObject(modTemplate::class, ['templatename' => $parameters['template']['name']]);
75+
$template = $this->modx->getObject(modTemplate::class, ['templatename' => $arguments['template']['name']]);
7676
if (!$template) {
7777
return json_encode(['success' => false, 'message' => 'Template not found with name.']);
7878
}
79-
$template->set('description', (string)$parameters['template']['description']);
80-
$template->set('content', (string)$parameters['template']['content']);
79+
$template->set('description', (string)$arguments['template']['description']);
80+
$template->set('content', (string)$arguments['template']['content']);
8181
if ($template->save()) {
8282
return json_encode(['success' => true, 'message' => 'Template updated.']);
8383
}
@@ -89,4 +89,9 @@ public static function checkPermissions(modX $modx): bool
8989
{
9090
return $modx->hasPermission('save_template');
9191
}
92+
93+
public static function getDescription(): string
94+
{
95+
return 'Allows the assistant to edit templates.';
96+
}
9297
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function __construct(modX $modx, array $config)
3535
}
3636

3737
/**
38-
* @param array | null $parameters
38+
* @param array | null $arguments
3939
* @return string
4040
*/
41-
public function runTool($parameters): string
41+
public function runTool($arguments): string
4242
{
4343
if (!self::checkPermissions($this->modx)) {
4444
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,39 +63,39 @@ public function __construct(modX $modx, array $config)
6363
}
6464

6565
/**
66-
* @param array | null $parameters
66+
* @param array | null $arguments
6767
* @return string
6868
*/
69-
public function runTool($parameters): string
69+
public function runTool($arguments): string
7070
{
7171
if (!self::checkPermissions($this->modx)) {
7272
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
7373
}
7474

7575
$where = [];
7676

77-
if (is_array($parameters)) {
78-
if (!empty($parameters['query'])) {
77+
if (is_array($arguments)) {
78+
if (!empty($arguments['query'])) {
7979
$where[] = [
80-
'name:LIKE' => '%' . $parameters['query'] . '%',
80+
'name:LIKE' => '%' . $arguments['query'] . '%',
8181
];
8282
}
8383

84-
if (!empty($parameters['name'])) {
84+
if (!empty($arguments['name'])) {
8585
$where[] = [
86-
'name' => $parameters['query'],
86+
'name' => $arguments['query'],
8787
];
8888
}
8989

90-
if (!empty($parameters['id'])) {
90+
if (!empty($arguments['id'])) {
9191
$where[] = [
92-
'id' => $parameters['id'],
92+
'id' => $arguments['id'],
9393
];
9494
}
9595

96-
if (!empty($parameters['categories'])) {
96+
if (!empty($arguments['categories'])) {
9797
$where[] = [
98-
'category:IN' => $parameters['categories'],
98+
'category:IN' => $arguments['categories'],
9999
];
100100
}
101101
}
@@ -112,7 +112,7 @@ public function runTool($parameters): string
112112
'category' => $chunk->get('category'),
113113
];
114114

115-
if ($parameters['returnContent'] === true) {
115+
if ($arguments['returnContent'] === true) {
116116
$arr['content'] = $chunk->get('content');
117117
}
118118

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ public function __construct(modX $modx, array $config)
4949
}
5050

5151
/**
52-
* @param array | null $parameters
52+
* @param array | null $arguments
5353
* @return string
5454
*/
55-
public function runTool($parameters): string
55+
public function runTool($arguments): string
5656
{
5757
if (!self::checkPermissions($this->modx)) {
5858
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
5959
}
6060

61-
if (empty($parameters)) {
61+
if (empty($arguments)) {
6262
return json_encode(['success' => false, 'message' => 'Parameters are required.']);
6363
}
6464

6565
$where = [
66-
'id:IN' => $parameters['ids'],
66+
'id:IN' => $arguments['ids'],
6767
];
6868

6969
$output = [];

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public function __construct(modX $modx, array $config)
5353
}
5454

5555
/**
56-
* @param array | null $parameters
56+
* @param array | null $arguments
5757
* @return string
5858
*/
59-
public function runTool($parameters): string
59+
public function runTool($arguments): string
6060
{
6161
if (!self::checkPermissions($this->modx)) {
6262
return json_encode(['success' => false, "message" => "You do not have permission to use this tool."]);
@@ -66,24 +66,24 @@ public function runTool($parameters): string
6666
$where['deleted'] = false;
6767
$where['searchable'] = true;
6868

69-
if (is_array($parameters)) {
70-
if (!empty($parameters['query'])) {
69+
if (is_array($arguments)) {
70+
if (!empty($arguments['query'])) {
7171
$where[] = [
72-
'pagetitle:LIKE' => '%' . $parameters['query'] . '%',
73-
'OR:longtitle:LIKE' => '%' . $parameters['query'] . '%',
74-
'OR:introtext:LIKE' => '%' . $parameters['query'] . '%',
72+
'pagetitle:LIKE' => '%' . $arguments['query'] . '%',
73+
'OR:longtitle:LIKE' => '%' . $arguments['query'] . '%',
74+
'OR:introtext:LIKE' => '%' . $arguments['query'] . '%',
7575
];
7676
}
7777

78-
if (!empty($parameters['id'])) {
78+
if (!empty($arguments['id'])) {
7979
$where[] = [
80-
'id' => $parameters['id'],
80+
'id' => $arguments['id'],
8181
];
8282
}
8383

84-
if (!empty($parameters['parent'])) {
84+
if (!empty($arguments['parent'])) {
8585
$where[] = [
86-
'parent' => $parameters['parent'],
86+
'parent' => $arguments['parent'],
8787
];
8888
}
8989
}

0 commit comments

Comments
 (0)