forked from SciSharp/BotSharp-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-service.js
More file actions
195 lines (178 loc) · 5.15 KB
/
agent-service.js
File metadata and controls
195 lines (178 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { endpoints } from '$lib/services/api-endpoints.js';
import axios from 'axios';
import qs from 'qs';
/**
* Get agent settings
* @returns {Promise<import('$agentTypes').AgentSettings>}
*/
export async function getSettings() {
let url = endpoints.agentSettingUrl;
const response = await axios.get(url);
return response.data;
}
/**
* Get agent list
* @param {import('$agentTypes').AgentFilter} filter
* @param {boolean} checkAuth
* @param {AbortSignal | null} signal
* @returns {Promise<import('$commonTypes').PagedItems<import('$agentTypes').AgentModel>>}
*/
export async function getAgents(filter, checkAuth = false, signal = null) {
let url = endpoints.agentListUrl;
const response = await axios.get(url, {
params: {
...filter,
checkAuth : checkAuth
},
paramsSerializer: {
dots: true,
indexes: null,
},
signal: signal || undefined
});
return response.data;
}
/**
* Get agent list
* @returns {Promise<import('$commonTypes').IdName[]>}
*/
export async function getAgentOptions() {
let url = endpoints.agentOptionsUrl;
const response = await axios.get(url);
return response.data;
}
/**
* Get agent detail
* @param {string} id
* @returns {Promise<import('$agentTypes').AgentModel>}
*/
export async function getAgent(id) {
let url = endpoints.agentDetailUrl.replace("{id}", id);
const response = await axios.get(url);
return response.data;
}
/**
* Save agent detail
* @param {import('$agentTypes').AgentModel} agent
*/
export async function saveAgent(agent) {
let url = endpoints.agentDetailUrl.replace("{id}", agent.id);
await axios.put(url, agent);
}
/**
* Delete agent detail
* @param {string} agentId
*/
export async function deleteAgent(agentId) {
let url = endpoints.agentDetailUrl.replace("{id}", agentId);
await axios.delete(url);
}
/**
* Refresh agent data
* @returns {Promise<string>}
*/
export async function refreshAgents() {
const url = endpoints.agentRefreshUrl;
const response = await axios.post(url, {});
return response.data;
}
/**
* Create agent
* @param {import('$agentTypes').AgentModel} agent
* @returns {Promise<import('$agentTypes').AgentModel>}
*/
export async function createAgent(agent) {
const url = endpoints.agentCreateUrl;
const response = await axios.post(url, agent);
return response.data;
}
/**
* Get agent utility options
* @returns {Promise<import('$agentTypes').AgentUtility[]>}
*/
export async function getAgentUtilityOptions() {
const url = endpoints.agentUtilityOptionsUrl;
const response = await axios.get(url);
return response.data;
}
/**
* Get agent rule options
* @returns {Promise<import('$agentTypes').AgentRule[]>}
*/
export async function getAgentRuleOptions() {
const url = endpoints.agentRuleOptionsUrl;
const response = await axios.get(url);
return response.data;
}
/**
* Get agent rule criteria providers
* @returns {Promise<import('$commonTypes').KeyValuePair[]>}
*/
export async function getAgentRuleCriteriaProviders() {
const url = endpoints.agentRuleCriteriaProvidersUrl;
const response = await axios.get(url);
return response.data;
}
/**
* Get agent rule actions
* @returns {Promise<import('$commonTypes').KeyValuePair[]>}
*/
export async function getAgentRuleActions() {
const url = endpoints.agentRuleActionsUrl;
const response = await axios.get(url);
return response.data;
}
/**
* Get agent labels
* @param {number?} [size]
* @returns {Promise<string[]>}
*/
export async function getAgentLabels(size = null) {
const url = endpoints.agentLabelsUrl;
const response = await axios.get(url, {
params: { size: size }
});
return response.data;
}
/**
* Get agent code scripts
* @param {string} agentId
* @param {import('$agentTypes').AgentCodeScriptFilter?} filter
* @returns {Promise<import('$agentTypes').AgentCodeScriptViewModel[]>}
*/
export async function getAgentCodeScripts(agentId, filter = null) {
const url = endpoints.agentCodeScriptListUrl.replace("{agentId}", agentId);
const response = await axios.get(url, {
params: {
...filter
},
paramsSerializer: (params) => qs.stringify(params, { encode: false, allowDots: true, arrayFormat: "indices" })
});
return response.data;
}
/**
* Update agent code scripts
* @param {string} agentId
* @param {import('$agentTypes').AgentCodeScriptUpdateModel} update
* @returns {Promise<boolean>}
*/
export async function updateAgentCodeScripts(agentId, update) {
const url = endpoints.agentCodeScriptUpdateUrl.replace("{agentId}", agentId);
const response = await axios.post(url, {
...update
});
return response.data;
}
/**
* Generate agent code script
* @param {string} agentId
* @param {import('$agentTypes').AgentCodeScriptGenerateModel} request
* @returns {Promise<import('$agentTypes').CodeGenerationResult>}
*/
export async function generateAgentCodeScript(agentId, request) {
const url = endpoints.agentCodeScriptGenerateUrl.replace("{agentId}", agentId);
const response = await axios.post(url, {
...request
});
return response.data;
}