Skip to content

Commit e291074

Browse files
committed
clean code
1 parent 64f3093 commit e291074

2 files changed

Lines changed: 6 additions & 269 deletions

File tree

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte

Lines changed: 2 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@
7373
});
7474
}
7575
76-
// function compileCodeScript() {
77-
// svelteDispatch('compile', {
78-
// rule: rule
79-
// });
80-
// }
81-
8276
function toggleConfig() {
8377
svelteDispatch('config', {
8478
ruleIdx: ruleIndex
@@ -138,7 +132,7 @@
138132
</div>
139133
{/if}
140134
141-
{#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name && rule.config?.topology_provider}
135+
{#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name && rule.config?.topology_name}
142136
<!-- svelte-ignore a11y-no-static-element-interactions -->
143137
<div class="line-align-center">
144138
<!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -200,39 +194,7 @@
200194
on:change={e => changeRule(e, 'topology')}
201195
>
202196
{#each [...configOptions] as option}
203-
<option value={`${option.name}`} selected={option.name == rule.config?.topology_provider}>
204-
{option.name}
205-
</option>
206-
{/each}
207-
</Input>
208-
</div>
209-
<div class="utility-delete line-align-center"></div>
210-
</div>
211-
</div>
212-
<!-- <div class="utility-list-item">
213-
<div class="utility-label line-align-center">
214-
<div class="d-flex gap-1">
215-
<div class="line-align-center">
216-
{'Criteria'}
217-
</div>
218-
<div class="line-align-center">
219-
<Input
220-
type="checkbox"
221-
checked={!rule.rule_criteria?.disabled}
222-
on:change={e => toggleRule(e, 'criteria')}
223-
/>
224-
</div>
225-
</div>
226-
</div>
227-
<div class="utility-value">
228-
<div class="utility-input line-align-center">
229-
<Input
230-
type="select"
231-
disabled={!!rule.rule_criteria?.disabled}
232-
on:change={e => changeRule(e, 'criteria')}
233-
>
234-
{#each [...criteriaOptions] as option}
235-
<option value={`${option.name}#${option.defaultConfig}`} selected={option.name == rule.rule_criteria?.name}>
197+
<option value={`${option.name}`} selected={option.name == rule.config?.topology_name}>
236198
{option.name}
237199
</option>
238200
{/each}
@@ -241,97 +203,6 @@
241203
<div class="utility-delete line-align-center"></div>
242204
</div>
243205
</div>
244-
<div class="utility-list-item">
245-
<div class="utility-label line-align-center">
246-
<div class="d-flex gap-1">
247-
<div class="line-align-center">
248-
{'Text'}
249-
</div>
250-
{#if ADMIN_ROLES.includes(user?.role || '') && !!rule.trigger_name && !!rule.rule_criteria?.criteria_text?.trim()}
251-
<div
252-
class="line-align-center clickable text-primary fs-5"
253-
style="padding-top: 3px;"
254-
data-bs-toggle="tooltip"
255-
data-bs-placement="top"
256-
title="Compile code script"
257-
>
258-
<i
259-
class="mdi mdi-play-circle"
260-
role="link"
261-
tabindex="0"
262-
on:keydown={() => {}}
263-
on:click={() => compileCodeScript()}
264-
/>
265-
</div>
266-
{/if}
267-
</div>
268-
</div>
269-
<div class="utility-value">
270-
<div class="utility-input line-align-center">
271-
<Input
272-
type="textarea"
273-
style="resize: none;"
274-
rows={5}
275-
disabled={!!rule.rule_criteria?.disabled}
276-
maxlength={textLimit}
277-
value={rule.rule_criteria?.criteria_text}
278-
on:input={e => changeRule(e, 'criteria-text')}
279-
/>
280-
</div>
281-
<div class="utility-delete line-align-center">
282-
{#if rule.json_args}
283-
<div class="line-align-center">
284-
<i
285-
class="bx bxs-info-circle text-primary fs-5"
286-
id={`rule-args-${ruleIndex}`}
287-
data-bs-toggle="tooltip"
288-
data-bs-placement="top"
289-
title="Rule arguments"
290-
/>
291-
<BotsharpTooltip
292-
containerClasses="agent-utility-desc"
293-
style={`min-width: ${Math.floor(windowWidth*0.3)}px;`}
294-
target={`rule-args-${ruleIndex}`}
295-
placement="right"
296-
persist
297-
>
298-
<Markdown
299-
rawText
300-
scrollable
301-
containerClasses={'markdown-div'}
302-
containerStyles={`max-width: ${Math.floor(windowWidth*0.3)}px;`}
303-
text={rule.json_args}
304-
/>
305-
</BotsharpTooltip>
306-
</div>
307-
{/if}
308-
</div>
309-
</div>
310-
</div>
311-
{#if rule.rule_criteria?.name}
312-
<div class="utility-list-item">
313-
<div class="utility-label line-align-center">
314-
<div class="d-flex gap-1">
315-
<div class="line-align-center">
316-
{'Config'}
317-
</div>
318-
</div>
319-
</div>
320-
<div class="utility-value">
321-
<div class="utility-input line-align-center">
322-
<CodeScript
323-
language="json"
324-
containerClasses="agent-rule-config"
325-
hideLineNumber={true}
326-
editable={!rule.rule_criteria?.disabled}
327-
scriptText={JSON.stringify(rule.rule_criteria?.config || {}, null, 2)}
328-
on:change={(e) => changeRule(e, 'criteria-config')}
329-
/>
330-
</div>
331-
<div class="utility-delete line-align-center"></div>
332-
</div>
333-
</div>
334-
{/if} -->
335206
</div>
336207
</div>
337208
{/if}

src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte

Lines changed: 4 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<script>
22
import { onMount } from 'svelte';
3-
import Swal from 'sweetalert2';
43
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';
75
import LoadingToComplete from '$lib/common/spinners/LoadingToComplete.svelte';
8-
import { AgentCodeScriptType } from '$lib/helpers/enums';
96
import { scrollToBottom } from '$lib/helpers/utils/common';
107
import AgentRuleItem from './agent-rule-item.svelte';
118
import PlainModal from '$lib/common/modals/PlainModal.svelte';
@@ -22,7 +19,6 @@
2219
let isOpenConfigModal = false;
2320
2421
/** @type {number} */
25-
let duration = 2000;
2622
let windowWidth = 0;
2723
let windowHeight = 0;
2824
@@ -151,46 +147,11 @@
151147
} else if (field === 'topology') {
152148
found.config = {
153149
...found.config || {},
154-
topology_provider: value
150+
topology_name: value
155151
};
156152
innerRefresh(innerRules);
157153
}
158154
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-
194155
handleAgentChange();
195156
}
196157
@@ -233,16 +194,6 @@
233194
found.disabled = !e.detail.checked;
234195
}
235196
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-
246197
innerRefresh(innerRules);
247198
handleAgentChange();
248199
}
@@ -272,79 +223,6 @@
272223
handleAgentChange();
273224
}
274225
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-
348226
349227
/** @param {import('$agentTypes').AgentRule[]} list */
350228
function innerRefresh(list) {
@@ -359,29 +237,17 @@
359237
}) || [];
360238
}
361239
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-
374240
/**
375241
* @param {any} e
376242
* @param {number} uid
377243
*/
378244
function openRuleConfigModal(e, uid) {
379245
const found = innerRules.find((_, index) => index === uid);
380-
if (!found || !found.config?.topology_provider) {
246+
if (!found || !found.config?.topology_name) {
381247
return;
382248
}
383249
384-
const config = ruleConfigs[found.config.topology_provider];
250+
const config = ruleConfigs[found.config.topology_name];
385251
const customParam = config.customParameters || {};
386252
387253
if (customParam.htmlTag === 'iframe') {

0 commit comments

Comments
 (0)