Skip to content

Commit ddb248d

Browse files
committed
feat: add CMP to manage agents
1 parent 1478da8 commit ddb248d

File tree

37 files changed

+2153
-143
lines changed

37 files changed

+2153
-143
lines changed

_build/scripts/seed.gpm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __invoke(&$modx, $action)
2929
[
3030
'name' => \modAI\Tools\GetWeather::getSuggestedName(),
3131
'class' => \modAI\Tools\GetWeather::class,
32+
'description' => "Gets weather information from an external API.",
3233
'config' => [],
3334
'enabled' => true,
3435
'default' => false,
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
modAIAdmin.grid.AgentContextProviders = function (config) {
2+
config = config || {};
3+
4+
Ext.applyIf(config, {
5+
url: MODx.config.connector_url,
6+
baseParams: {
7+
action: 'modAI\\Processors\\ContextProviders\\GetList',
8+
agent: MODx.request.id,
9+
},
10+
preventSaveRefresh: false,
11+
fields: ['id', 'name', 'description'],
12+
paging: true,
13+
remoteSort: true,
14+
emptyText: _('modai.admin.global.no_records'),
15+
columns: [
16+
{
17+
header: _('id'),
18+
dataIndex: 'id',
19+
width: 0.05,
20+
sortable: true,
21+
hidden: true
22+
},
23+
{
24+
header: _('modai.admin.context_provider.name'),
25+
dataIndex: 'name',
26+
width: 0.2,
27+
sortable: true,
28+
hidden: false,
29+
editor: {
30+
xtype: 'textfield',
31+
}
32+
},
33+
{
34+
header: _('modai.admin.context_provider.description'),
35+
dataIndex: 'description',
36+
width: 0.6,
37+
sortable: true,
38+
hidden: false,
39+
editor: {
40+
xtype: 'textfield',
41+
}
42+
},
43+
],
44+
tbar: this.getTbar(config)
45+
});
46+
modAIAdmin.grid.AgentContextProviders.superclass.constructor.call(this, config);
47+
};
48+
Ext.extend(modAIAdmin.grid.AgentContextProviders, MODx.grid.Grid, {
49+
50+
getMenu: function () {
51+
var m = [];
52+
53+
m.push({
54+
text: _('modai.admin.agent_context_provider.view'),
55+
handler: this.viewContextProvider
56+
});
57+
58+
m.push('-');
59+
60+
m.push({
61+
text: _('modai.admin.agent_context_provider.remove'),
62+
handler: this.removeContextProvider
63+
});
64+
65+
return m;
66+
},
67+
68+
getTbar: function(config) {
69+
return [
70+
{
71+
text: _('modai.admin.agent_context_provider.create'),
72+
handler: this.createContextProvider
73+
},
74+
'->',
75+
{
76+
xtype: 'textfield',
77+
emptyText: _('modai.admin.context_provider.search'),
78+
listeners: {
79+
change: {
80+
fn: this.search,
81+
scope: this
82+
},
83+
render: {
84+
fn: function (cmp) {
85+
new Ext.KeyMap(cmp.getEl(), {
86+
key: Ext.EventObject.ENTER,
87+
fn: function () {
88+
this.blur();
89+
return true;
90+
},
91+
scope: cmp
92+
});
93+
},
94+
scope: this
95+
}
96+
}
97+
},
98+
];
99+
},
100+
101+
createContextProvider: function(btn, e) {
102+
const record = {
103+
agent_id: MODx.request.id,
104+
};
105+
106+
const win = MODx.load({
107+
xtype: 'modai-window-agent_context_providers',
108+
record: record,
109+
listeners: {
110+
success: {
111+
fn: function () {
112+
this.refresh();
113+
},
114+
scope: this
115+
}
116+
}
117+
});
118+
119+
win.fp.getForm().setValues(record);
120+
win.show(e.target);
121+
122+
return true;
123+
},
124+
125+
removeContextProvider: function (btn, e) {
126+
if (!this.menu.record) return false;
127+
128+
MODx.msg.confirm({
129+
title: _('modai.admin.agent_context_provider.remove'),
130+
text: _('modai.admin.agent_context_provider.remove_confirm', { name: this.menu.record.name }),
131+
url: this.config.url,
132+
params: {
133+
action: 'modAI\\Processors\\AgentContextProviders\\Remove',
134+
agent_id: MODx.request.id,
135+
context_provider_id: this.menu.record.id
136+
},
137+
listeners: {
138+
success: {
139+
fn: function (r) {
140+
this.refresh();
141+
},
142+
scope: this
143+
}
144+
}
145+
});
146+
147+
return true;
148+
},
149+
150+
viewContextProvider: function(btn, e) {
151+
modAIAdmin.loadPage('context_provider/update', { id: this.menu.record.id });
152+
},
153+
154+
filterCombo: function (combo, record) {
155+
const s = this.getStore();
156+
s.baseParams[combo.filterName] = record.data[combo.valueField];
157+
this.getBottomToolbar().changePage(1);
158+
},
159+
160+
search: function (field, value) {
161+
const s = this.getStore();
162+
s.baseParams.search = value;
163+
this.getBottomToolbar().changePage(1);
164+
}
165+
});
166+
Ext.reg('modai-grid-agent_context_providers', modAIAdmin.grid.AgentContextProviders);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
modAIAdmin.window.AgentContextProviders = function (config) {
2+
config = config || {};
3+
Ext.applyIf(config, {
4+
title: _('modai.admin.agent_context_provider.create'),
5+
closeAction: 'close',
6+
url: MODx.config.connector_url,
7+
action: 'modAI\\Processors\\AgentContextProviders\\Create',
8+
modal: true,
9+
autoHeight: true,
10+
fields: this.getFields(config)
11+
});
12+
modAIAdmin.window.AgentContextProviders.superclass.constructor.call(this, config);
13+
};
14+
Ext.extend(modAIAdmin.window.AgentContextProviders, MODx.Window, {
15+
getFields: function (config) {
16+
return [
17+
{
18+
xtype: 'hidden',
19+
name: 'agent_id'
20+
},
21+
{
22+
xtype: 'modai-combo-context_providers',
23+
agent: config.record.agent_id,
24+
fieldLabel: _('modai.admin.agent.context_providers'),
25+
name: 'context_providers[]',
26+
hiddenName: 'context_providers[]',
27+
anchor: '100%',
28+
29+
},
30+
];
31+
}
32+
});
33+
Ext.reg('modai-window-agent_context_providers', modAIAdmin.window.AgentContextProviders);
34+
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
modAIAdmin.grid.AgentTools = function (config) {
2+
config = config || {};
3+
4+
Ext.applyIf(config, {
5+
url: MODx.config.connector_url,
6+
baseParams: {
7+
action: 'modAI\\Processors\\Tools\\GetList',
8+
agent: MODx.request.id,
9+
},
10+
preventSaveRefresh: false,
11+
fields: ['id', 'name', 'description'],
12+
paging: true,
13+
remoteSort: true,
14+
emptyText: _('modai.admin.global.no_records'),
15+
columns: [
16+
{
17+
header: _('id'),
18+
dataIndex: 'id',
19+
width: 0.05,
20+
sortable: true,
21+
hidden: true
22+
},
23+
{
24+
header: _('modai.admin.tool.name'),
25+
dataIndex: 'name',
26+
width: 0.2,
27+
sortable: true,
28+
hidden: false,
29+
},
30+
{
31+
header: _('modai.admin.tool.description'),
32+
dataIndex: 'description',
33+
width: 0.6,
34+
sortable: true,
35+
hidden: false,
36+
},
37+
],
38+
tbar: this.getTbar(config)
39+
});
40+
modAIAdmin.grid.AgentTools.superclass.constructor.call(this, config);
41+
};
42+
Ext.extend(modAIAdmin.grid.AgentTools, MODx.grid.Grid, {
43+
44+
getMenu: function () {
45+
var m = [];
46+
47+
m.push({
48+
text: _('modai.admin.agent_tool.view'),
49+
handler: this.viewTool
50+
});
51+
52+
m.push('-');
53+
54+
m.push({
55+
text: _('modai.admin.agent_tool.remove'),
56+
handler: this.removeTool
57+
});
58+
59+
return m;
60+
},
61+
62+
getTbar: function(config) {
63+
return [
64+
{
65+
text: _('modai.admin.agent_tool.create'),
66+
handler: this.createTool
67+
},
68+
'->',
69+
{
70+
xtype: 'textfield',
71+
emptyText: _('modai.admin.tool.search'),
72+
listeners: {
73+
change: {
74+
fn: this.search,
75+
scope: this
76+
},
77+
render: {
78+
fn: function (cmp) {
79+
new Ext.KeyMap(cmp.getEl(), {
80+
key: Ext.EventObject.ENTER,
81+
fn: function () {
82+
this.blur();
83+
return true;
84+
},
85+
scope: cmp
86+
});
87+
},
88+
scope: this
89+
}
90+
}
91+
},
92+
];
93+
},
94+
95+
createTool: function(btn, e) {
96+
const record = {
97+
agent_id: MODx.request.id,
98+
};
99+
100+
const win = MODx.load({
101+
xtype: 'modai-window-agent_tools',
102+
record: record,
103+
listeners: {
104+
success: {
105+
fn: function () {
106+
this.refresh();
107+
},
108+
scope: this
109+
}
110+
}
111+
});
112+
113+
win.fp.getForm().setValues(record);
114+
win.show(e.target);
115+
116+
return true;
117+
},
118+
119+
removeTool: function (btn, e) {
120+
if (!this.menu.record) return false;
121+
122+
MODx.msg.confirm({
123+
title: _('modai.admin.agent_tool.remove'),
124+
text: _('modai.admin.agent_tool.remove_confirm', { name: this.menu.record.name }),
125+
url: this.config.url,
126+
params: {
127+
action: 'modAI\\Processors\\AgentTools\\Remove',
128+
agent_id: MODx.request.id,
129+
tool_id: this.menu.record.id
130+
},
131+
listeners: {
132+
success: {
133+
fn: function (r) {
134+
this.refresh();
135+
},
136+
scope: this
137+
}
138+
}
139+
});
140+
141+
return true;
142+
},
143+
144+
viewTool: function(btn, e) {
145+
modAIAdmin.loadPage('tool/update', { id: this.menu.record.id });
146+
},
147+
148+
filterCombo: function (combo, record) {
149+
const s = this.getStore();
150+
s.baseParams[combo.filterName] = record.data[combo.valueField];
151+
this.getBottomToolbar().changePage(1);
152+
},
153+
154+
search: function (field, value) {
155+
const s = this.getStore();
156+
s.baseParams.search = value;
157+
this.getBottomToolbar().changePage(1);
158+
}
159+
});
160+
Ext.reg('modai-grid-agent_tools', modAIAdmin.grid.AgentTools);

0 commit comments

Comments
 (0)