|
1 | 1 | <script> |
2 | 2 | import { onMount } from 'svelte'; |
3 | | - import Swal from 'sweetalert2'; |
4 | 3 | import { Card, CardBody, Button } from '@sveltestrap/sveltestrap'; |
5 | | - import { AI_PROGRAMMER_AGENT_ID, RULE_TRIGGER_CODE_GENERATE_TEMPLATE } from '$lib/helpers/constants'; |
6 | | - import { getAgentRuleOptions, generateAgentCodeScript, getAgentRuleConfigOptions } from '$lib/services/agent-service'; |
| 4 | + import { getAgentRuleOptions, getAgentRuleConfigOptions } from '$lib/services/agent-service'; |
7 | 5 | import LoadingToComplete from '$lib/common/spinners/LoadingToComplete.svelte'; |
8 | | - import { AgentCodeScriptType } from '$lib/helpers/enums'; |
9 | 6 | import { scrollToBottom } from '$lib/helpers/utils/common'; |
10 | 7 | import AgentRuleItem from './agent-rule-item.svelte'; |
11 | 8 | import PlainModal from '$lib/common/modals/PlainModal.svelte'; |
|
22 | 19 | let isOpenConfigModal = false; |
23 | 20 |
|
24 | 21 | /** @type {number} */ |
25 | | - let duration = 2000; |
26 | 22 | let windowWidth = 0; |
27 | 23 | let windowHeight = 0; |
28 | 24 |
|
|
151 | 147 | } else if (field === 'topology') { |
152 | 148 | found.config = { |
153 | 149 | ...found.config || {}, |
154 | | - topology_provider: value |
| 150 | + topology_name: value |
155 | 151 | }; |
156 | 152 | innerRefresh(innerRules); |
157 | 153 | } |
158 | 154 | |
159 | | - // else if (field === 'criteria') { |
160 | | - // const name = value.split('#')[0]; |
161 | | - // const defaultConfig = value.split('#')[1]; |
162 | | - // found.rule_criteria = { |
163 | | - // ...found.rule_criteria || {}, |
164 | | - // name: name, |
165 | | - // disabled: found.rule_criteria?.disabled || false, |
166 | | - // config: JSON.parse(defaultConfig || '{}') |
167 | | - // }; |
168 | | - // innerRefresh(innerRules); |
169 | | - // } else if (field === 'criteria-text') { |
170 | | - // if (found.rule_criteria == null) { |
171 | | - // found.rule_criteria = { |
172 | | - // name: '', |
173 | | - // disabled: false, |
174 | | - // config: {} |
175 | | - // }; |
176 | | - // } |
177 | | - // found.rule_criteria.criteria_text = value; |
178 | | - // innerRefresh(innerRules); |
179 | | - // } else if (field === 'criteria-config') { |
180 | | - // if (found.rule_criteria == null) { |
181 | | - // found.rule_criteria = { |
182 | | - // name: '', |
183 | | - // disabled: false, |
184 | | - // config: {} |
185 | | - // }; |
186 | | - // } |
187 | | - // try { |
188 | | - // found.rule_criteria.config = JSON.parse(value || '{}'); |
189 | | - // } catch { |
190 | | - // // ignore invalid JSON while typing |
191 | | - // } |
192 | | - // } |
193 | | -
|
194 | 155 | handleAgentChange(); |
195 | 156 | } |
196 | 157 |
|
|
233 | 194 | found.disabled = !e.detail.checked; |
234 | 195 | } |
235 | 196 | |
236 | | - // else if (field === 'criteria') { |
237 | | - // if (!found.rule_criteria) { |
238 | | - // found.rule_criteria = { |
239 | | - // name: '', |
240 | | - // disabled: false |
241 | | - // }; |
242 | | - // } |
243 | | - // found.rule_criteria.disabled = !e.detail.checked; |
244 | | - // } |
245 | | - |
246 | 197 | innerRefresh(innerRules); |
247 | 198 | handleAgentChange(); |
248 | 199 | } |
|
272 | 223 | handleAgentChange(); |
273 | 224 | } |
274 | 225 |
|
275 | | - // /** |
276 | | - // * @param {import("$agentTypes").AgentRule} rule |
277 | | - // */ |
278 | | - // function compileCodeScript(rule) { |
279 | | - // if (!!rule.rule_criteria?.disabled) { |
280 | | - // return; |
281 | | - // } |
282 | | -
|
283 | | - // Swal.fire({ |
284 | | - // title: 'Are you sure?', |
285 | | - // html: ` |
286 | | - // <div> |
287 | | - // <p>Are you sure you want to generate code script <b>"${buildScriptName(rule.trigger_name)}"</b>?</p> |
288 | | - // <p>This action will overwrite existing code script if any.</p> |
289 | | - // </div> |
290 | | - // `, |
291 | | - // icon: 'warning', |
292 | | - // showCancelButton: true, |
293 | | - // cancelButtonText: 'No', |
294 | | - // confirmButtonText: 'Yes' |
295 | | - // }).then(async (result) => { |
296 | | - // if (result.value) { |
297 | | - // generateCodeScript(rule); |
298 | | - // } |
299 | | - // }); |
300 | | - // } |
301 | | -
|
302 | | - // /** |
303 | | - // * @param {import("$agentTypes").AgentRule} rule |
304 | | - // */ |
305 | | - // function generateCodeScript(rule) { |
306 | | - // return new Promise((resolve, reject) => { |
307 | | - // isLoading = true; |
308 | | - // generateAgentCodeScript(agent.id, { |
309 | | - // text: '', |
310 | | - // options: { |
311 | | - // agent_id: AI_PROGRAMMER_AGENT_ID, |
312 | | - // template_name: RULE_TRIGGER_CODE_GENERATE_TEMPLATE, |
313 | | - // save_to_db: true, |
314 | | - // script_name: buildScriptName(rule.trigger_name), |
315 | | - // script_type: AgentCodeScriptType.Src, |
316 | | - // data: { |
317 | | - // 'args_example': { ...rule.output_args }, |
318 | | - // 'user_request': rule.rule_criteria?.criteria_text |
319 | | - // } |
320 | | - // } |
321 | | - // }).then(res => { |
322 | | - // if (res?.success) { |
323 | | - // isLoading = false; |
324 | | - // isComplete = true; |
325 | | - // successText = "Code script has been generated!"; |
326 | | - // setTimeout(() => { |
327 | | - // isComplete = false; |
328 | | - // successText = ""; |
329 | | - // }, duration); |
330 | | - // resolve(res); |
331 | | - // } else { |
332 | | - // throw "error when generating code script."; |
333 | | - // } |
334 | | - // }).catch(() => { |
335 | | - // isLoading = false; |
336 | | - // isComplete = false; |
337 | | - // isError = true; |
338 | | - // errorText = "Failed to generate code script."; |
339 | | - // setTimeout(() => { |
340 | | - // isError = false; |
341 | | - // errorText = ""; |
342 | | - // }, duration); |
343 | | - // reject(); |
344 | | - // }); |
345 | | - // }); |
346 | | - // } |
347 | | -
|
348 | 226 |
|
349 | 227 | /** @param {import('$agentTypes').AgentRule[]} list */ |
350 | 228 | function innerRefresh(list) { |
|
359 | 237 | }) || []; |
360 | 238 | } |
361 | 239 |
|
362 | | - // /** @param {string} name */ |
363 | | - // function buildScriptName(name) { |
364 | | - // let scriptName = name?.trim(); |
365 | | - // if (!name) { |
366 | | - // scriptName = 'unknown_rule.py'; |
367 | | - // } else { |
368 | | - // scriptName = `${scriptName.replace(/\s+/g, "_")}_rule.py`; |
369 | | - // } |
370 | | - |
371 | | - // return scriptName; |
372 | | - // } |
373 | | -
|
374 | 240 | /** |
375 | 241 | * @param {any} e |
376 | 242 | * @param {number} uid |
377 | 243 | */ |
378 | 244 | function openRuleConfigModal(e, uid) { |
379 | 245 | const found = innerRules.find((_, index) => index === uid); |
380 | | - if (!found || !found.config?.topology_provider) { |
| 246 | + if (!found || !found.config?.topology_name) { |
381 | 247 | return; |
382 | 248 | } |
383 | 249 |
|
384 | | - const config = ruleConfigs[found.config.topology_provider]; |
| 250 | + const config = ruleConfigs[found.config.topology_name]; |
385 | 251 | const customParam = config.customParameters || {}; |
386 | 252 |
|
387 | 253 | if (customParam.htmlTag === 'iframe') { |
|
0 commit comments