Skip to content

Commit 97590df

Browse files
committed
feat: rename tool's description to prompt and add internal description to tools & context providers
1 parent 4241ada commit 97590df

File tree

26 files changed

+180
-53
lines changed

26 files changed

+180
-53
lines changed

assets/components/modai/mgr/js/context_provider/panel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,17 @@ Ext.extend(modAIAdmin.panel.ContextProvider, MODx.FormPanel, {
128128
xtype: 'modai-combo-context_provider_class',
129129
value: config.record.class,
130130
listeners: {
131-
select: (self, record) => {
131+
beforeselect: (self, record) => {
132+
const name = this.getForm().findField('name');
133+
if (name && (self.getValue() !== record.data.class || !name.getValue())) {
134+
name.setValue(record.data.suggestedName);
135+
}
136+
137+
const description = this.getForm().findField('description');
138+
if (description && (self.getValue() !== record.data.class || !description.getValue())) {
139+
description.setValue(record.data.description);
140+
}
141+
132142
this.configSection.removeAll();
133143
Object.entries(record.data.config).forEach(([key, config]) => {
134144
this.configSection.add(modAIAdmin.formatConfigItem(key, config));

assets/components/modai/mgr/js/tool/panel.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,17 @@ Ext.extend(modAIAdmin.panel.Tool, MODx.FormPanel, {
125125
xtype: 'modai-combo-tool_class',
126126
value: config.record.class,
127127
listeners: {
128-
select: (self, record) => {
128+
beforeselect: (self, record) => {
129129
const name = this.getForm().findField('name');
130-
if (name && !name.getValue()) {
130+
if (name && (self.getValue() !== record.data.class || !name.getValue())) {
131131
name.setValue(record.data.suggestedName);
132132
}
133133

134+
const description = this.getForm().findField('description');
135+
if (description && (self.getValue() !== record.data.class ||!description.getValue())) {
136+
description.setValue(record.data.description);
137+
}
138+
134139
this.configSection.removeAll();
135140
Object.entries(record.data.config).forEach(([key, config]) => {
136141
this.configSection.add(modAIAdmin.formatConfigItem(key, config));

assets/components/modai/mgr/js/utils/combos.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ modAIAdmin.combo.ContextProviderClass = function (config) {
133133
hiddenName: 'class',
134134
displayField: 'class',
135135
valueField: 'class',
136-
fields: ['class', 'config'],
136+
fields: ['class', 'config', 'suggestedName', 'description'],
137137
typeAhead: false,
138138
editable: true,
139139
forceSelection: true,
@@ -142,7 +142,13 @@ modAIAdmin.combo.ContextProviderClass = function (config) {
142142
url: MODx.config.connector_url,
143143
baseParams: {
144144
action: 'modAI\\Processors\\Combos\\ContextProviderClass',
145-
}
145+
},
146+
tpl: new Ext.XTemplate('<tpl for=".">' +
147+
'<div class="x-combo-list-item x-combo-list-item-grouped">' +
148+
'<div class="x-combo-list-title">{class:htmlEncode}</div>' +
149+
'{description:htmlEncode()}' +
150+
'</div>' +
151+
'</tpl>')
146152
});
147153
modAIAdmin.combo.ContextProviderClass.superclass.constructor.call(this, config);
148154
};
@@ -156,7 +162,7 @@ modAIAdmin.combo.ToolClass = function (config) {
156162
hiddenName: 'class',
157163
displayField: 'class',
158164
valueField: 'class',
159-
fields: ['class', 'config', 'suggestedName'],
165+
fields: ['class', 'config', 'suggestedName', 'description'],
160166
typeAhead: false,
161167
editable: true,
162168
forceSelection: true,
@@ -165,7 +171,13 @@ modAIAdmin.combo.ToolClass = function (config) {
165171
url: MODx.config.connector_url,
166172
baseParams: {
167173
action: 'modAI\\Processors\\Combos\\ToolClass',
168-
}
174+
},
175+
tpl: new Ext.XTemplate('<tpl for=".">' +
176+
'<div class="x-combo-list-item x-combo-list-item-grouped">' +
177+
'<div class="x-combo-list-title">{class:htmlEncode}</div>' +
178+
'{description:htmlEncode()}' +
179+
'</div>' +
180+
'</tpl>')
169181
});
170182
modAIAdmin.combo.ToolClass.superclass.constructor.call(this, config);
171183
};

core/components/modai/controllers/context_provider/update.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function process(array $scriptProperties = [])
2121
}
2222

2323
$this->contextProviderData = $contextProvider->toArray();
24-
$this->contextProviderData['classConfig'] = $this->contextProviderData['class']::getConfig();
24+
$this->contextProviderData['classConfig'] = $this->contextProviderData['class']::getConfig($this->modx);
2525
}
2626

2727
public function getPageTitle()

core/components/modai/controllers/tool/update.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function process(array $scriptProperties = [])
2121
}
2222

2323
$this->toolData = $tool->toArray();
24-
$this->toolData['classConfig'] = $this->toolData['class']::getConfig();
24+
$this->toolData['classConfig'] = $this->toolData['class']::getConfig($this->modx);
2525
}
2626

2727
public function getPageTitle()

core/components/modai/lexicon/en/default.inc.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@
9090
$_lang['modai.admin.related_agent.remove'] = 'Unassign Agent';
9191
$_lang['modai.admin.related_agent.remove_confirm'] = 'Are you sure you want to unassign "[[+name]]" agent?';
9292

93+
$_lang['modai.admin.context_provider.pinecone.api_key'] = 'API Key';
94+
$_lang['modai.admin.context_provider.pinecone.api_key_desc'] = 'API Key to access Pinecone';
95+
$_lang['modai.admin.context_provider.pinecone.endpoint'] = 'API endpoint';
96+
$_lang['modai.admin.context_provider.pinecone.endpoint_desc'] = 'Endpoint of your Pinecone API instance.';
97+
$_lang['modai.admin.context_provider.pinecone.namespace'] = 'Namespace';
98+
$_lang['modai.admin.context_provider.pinecone.namespace_desc'] = 'Namespace that will be used to store/query your data.';
99+
$_lang['modai.admin.context_provider.pinecone.fields'] = 'Fields to index';
100+
$_lang['modai.admin.context_provider.pinecone.fields_desc'] = 'Comma separated list of fields to index.';
101+
$_lang['modai.admin.context_provider.pinecone.fields_map'] = 'Map fields to a different name';
102+
$_lang['modai.admin.context_provider.pinecone.fields_map_desc'] = 'Comma separated list of original_name:new_name pairs';
103+
$_lang['modai.admin.context_provider.pinecone.context_messages'] = 'Context Messages';
104+
$_lang['modai.admin.context_provider.pinecone.context_messages_desc'] = 'Additional context messages that will be put in front of the data from DB. One message per line. Can contain {id} or any {field} (defined in fields config) placeholder, you can also reference a system setting with using ++ as a prefix, for example {++site_url}.';
105+
106+
93107
$_lang['modai.admin.error.required'] = 'Field is required.';
94108

95109
$_lang['modai.admin.error.context_provider_name_already_exists'] = 'Context Provider with this name already exists.';

core/components/modai/src/ContextProviders/ContextProviderInterface.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,19 @@ public function __construct(modX $modx, array $config = []);
1414
*/
1515
public function provideContext(string $prompt): array;
1616

17-
public static function getConfig(): array;
17+
public static function getConfig(modX $modx): array;
18+
19+
/**
20+
* Internal description
21+
*
22+
* @return string
23+
*/
24+
public static function getDescription(): string;
25+
26+
/**
27+
* The suggested name for the context provider, this will be pre-filled for the user when configuring the context provider.
28+
*
29+
* @return string
30+
*/
31+
public static function getSuggestedName(): string;
1832
}

core/components/modai/src/ContextProviders/Pinecone.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,42 +220,42 @@ private function formatMessage($msg, $data): string
220220
return str_replace($search, $replace, $msg);
221221
}
222222

223-
public static function getConfig(): array
223+
public static function getConfig(modX $modx): array
224224
{
225225
return [
226226
'api_key' => [
227-
'name' => 'API Key',
228-
'description' => 'API Key to access Pinecone',
227+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.api_key'),
228+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.api_key_desc'),
229229
'required' => true,
230230
'type' => 'text-password'
231231
],
232232
'endpoint' => [
233-
'name' => 'API endpoint',
234-
'description' => 'Endpoint of your Pinecone API instance.',
233+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.endpoint'),
234+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.endpoint_desc'),
235235
'required' => true,
236236
'type' => 'textfield'
237237
],
238238
'namespace' => [
239-
'name' => 'Namespace',
240-
'description' => 'Namespace that will be used to store/query your data.',
239+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.namespace'),
240+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.namespace_desc'),
241241
'required' => true,
242242
'type' => 'textfield'
243243
],
244244
'fields' => [
245-
'name' => 'Fields to index',
246-
'description' => 'Comma separated list of fields to index.',
245+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.fields'),
246+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.fields_desc'),
247247
'required' => true,
248248
'type' => 'textfield'
249249
],
250250
'fields_map' => [
251-
'name' => 'Map fields to a different name',
252-
'description' => 'Comma separated list of original_name:new_name pairs',
251+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.fields_map'),
252+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.fields_map_desc'),
253253
'required' => false,
254254
'type' => 'textfield'
255255
],
256256
'context_messages' => [
257-
'name' => 'Context Messages',
258-
'description' => 'Additional context messages that will be put in front of the data from DB. One message per line. Can contain {id} or any {field} (defined in fields config) placeholder, you can also reference a system setting with using ++ as a prefix, for example {++site_url}.',
257+
'name' => $modx->lexicon('modai.admin.context_provider.pinecone.context_messages'),
258+
'description' => $modx->lexicon('modai.admin.context_provider.pinecone.context_messages_desc'),
259259
'required' => false,
260260
'type' => 'textarea',
261261
'extraProperties' => [
@@ -264,4 +264,14 @@ public static function getConfig(): array
264264
],
265265
];
266266
}
267+
268+
public static function getDescription(): string
269+
{
270+
return 'Pinecone\'s vector database';
271+
}
272+
273+
public static function getSuggestedName(): string
274+
{
275+
return 'pinecone';
276+
}
267277
}

core/components/modai/src/Processors/Combos/ContextProviderClass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function process()
4343
return $this->outputArray(array_map(function($class) {
4444
return [
4545
'class' => $class,
46-
'config' => $class::getConfig(),
46+
'config' => $class::getConfig($this->modx),
47+
'description' => $class::getDescription(),
48+
'suggestedName' => $class::getSuggestedName(),
4749
];
4850
}, $classes), count($classes));
4951
}

core/components/modai/src/Processors/Combos/ToolClass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public function process()
4343
return $this->outputArray(array_map(function($class) {
4444
return [
4545
'class' => $class,
46-
'config' => $class::getConfig(),
46+
'config' => $class::getConfig($this->modx),
4747
'suggestedName' => $class::getSuggestedName(),
48+
'description' => $class::getDescription(),
4849
];
4950
}, $classes), count($classes));
5051
}

0 commit comments

Comments
 (0)