-
Notifications
You must be signed in to change notification settings - Fork 70
add rule criteria #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add rule criteria #472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| <script> | ||
| import { slide } from 'svelte/transition'; | ||
| import Markdown from '$lib/common/markdown/Markdown.svelte'; | ||
| import BotsharpTooltip from '$lib/common/tooltip/BotsharpTooltip.svelte'; | ||
| import Select from '$lib/common/dropdowns/Select.svelte'; | ||
|
|
||
| const textLimit = 1024; | ||
|
|
||
| /** | ||
| * @type {{ | ||
| * rule: import('$agentTypes').AgentRule, | ||
|
|
@@ -13,7 +16,8 @@ | |
| * ontoggle?: (data: { ruleIdx: number, field: string, checked: boolean }) => void, | ||
| * onchange?: (data: { ruleIdx: number, field: string, value: string }) => void, | ||
| * ondelete?: (data: { ruleIdx: number, field: string }) => void, | ||
| * oncollapse?: (data: { ruleIdx: number, collapsed: boolean }) => void | ||
| * oncollapse?: (data: { ruleIdx: number, collapsed: boolean }) => void, | ||
| * oncompile?: (data: { ruleIdx: number, rule: import('$agentTypes').AgentRule }) => void | ||
| * }} | ||
| */ | ||
| let { | ||
|
|
@@ -25,9 +29,15 @@ | |
| ontoggle, | ||
| onchange, | ||
| ondelete, | ||
| oncollapse | ||
| oncollapse, | ||
| oncompile | ||
| } = $props(); | ||
|
|
||
| // Code script can only be generated by admins, once a trigger is picked and criteria text exists. | ||
| let canCompile = $derived( | ||
| !!rule.trigger_name && !!rule.config?.criteria?.trim() | ||
| ); | ||
|
|
||
| /** | ||
| * @param {any} e | ||
| * @param {string} field | ||
|
|
@@ -69,6 +79,24 @@ | |
| collapsed: !collapsed | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @param {any} e | ||
| */ | ||
| function changeCriteria(e) { | ||
| onchange?.({ | ||
| ruleIdx: ruleIndex, | ||
| field: 'criteria', | ||
| value: e?.target?.value || '' | ||
| }); | ||
| } | ||
|
|
||
| function compile() { | ||
| oncompile?.({ | ||
| ruleIdx: ruleIndex, | ||
| rule: rule | ||
| }); | ||
| } | ||
| </script> | ||
|
|
||
| <div class="ari-wrapper"> | ||
|
|
@@ -148,6 +176,45 @@ | |
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {#if !collapsed} | ||
| <div class="ari-row ari-row-secondary" transition:slide={{ duration: 200 }}> | ||
| <div class="ari-label ari-label-strong"> | ||
| <div class="ari-cell"> | ||
| {'Criteria'} | ||
| </div> | ||
| {#if canCompile} | ||
| <div class="ari-cell"> | ||
| <i | ||
| class="bx bx-code-alt ari-compile-icon" | ||
| id={`rule-compile-${ruleIndex}`} | ||
| role="link" | ||
| tabindex="0" | ||
| data-bs-toggle="tooltip" | ||
| data-bs-placement="top" | ||
| title="Generate code script" | ||
| onkeydown={() => {}} | ||
| onclick={() => compile()} | ||
| ></i> | ||
|
Comment on lines
+195
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Compile icon not keyboardable In agent-rule-item.svelte the new compile icon is focusable (tabindex=0) but its onkeydown handler is a no-op, so keyboard users cannot trigger compilation via Enter/Space even though the UI presents it as a link. Agent Prompt
|
||
| </div> | ||
| {/if} | ||
| </div> | ||
| <div class="ari-value"> | ||
| <div class="ari-input-wrap ari-cell"> | ||
| <textarea | ||
| class="ari-textarea" | ||
| rows="5" | ||
| maxlength={textLimit} | ||
| placeholder="Describe when this rule should trigger..." | ||
| disabled={rule.disabled} | ||
| value={rule.config?.criteria || ''} | ||
| oninput={e => changeCriteria(e)} | ||
| ></textarea> | ||
| </div> | ||
| <div class="ari-delete ari-cell"></div> | ||
| </div> | ||
| </div> | ||
| {/if} | ||
| </div> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| <script> | ||
| import { getAgentRuleOptionsById } from '$lib/services/agent-service'; | ||
| import { getAgentRuleOptionsById, generateAgentCodeScript } from '$lib/services/agent-service'; | ||
| import LoadingToComplete from '$lib/common/spinners/LoadingToComplete.svelte'; | ||
| import ConfirmModal from '$lib/common/modals/ConfirmModal.svelte'; | ||
| import { scrollToBottom } from '$lib/helpers/utils/common'; | ||
| import { AgentCodeScriptType } from '$lib/helpers/enums'; | ||
| import AgentRuleItem from './agent-rule-item.svelte'; | ||
|
|
||
| const limit = 100; | ||
| const duration = 2000; | ||
|
|
||
| /** | ||
| * @type {{ | ||
|
|
@@ -30,6 +33,11 @@ | |
| /** @type {string} */ | ||
| let errorText = $state(''); | ||
|
|
||
| /** @type {boolean} */ | ||
| let confirmOpen = $state(false); | ||
| /** @type {import('$agentTypes').AgentRule | null} */ | ||
| let pendingRule = $state(null); | ||
|
|
||
| export const fetchRules = () => { | ||
| const candidates = innerRules?.filter(x => !!x.trigger_name)?.map(x => { | ||
| return { | ||
|
|
@@ -157,6 +165,8 @@ | |
| if (field === 'rule') { | ||
| found.trigger_name = value; | ||
| innerRefresh(innerRules); | ||
| } else if (field === 'criteria') { | ||
| found.config = { ...(found.config || {}), criteria: value }; | ||
| } | ||
|
|
||
| handleAgentChange(); | ||
|
|
@@ -220,6 +230,65 @@ | |
|
|
||
|
|
||
|
|
||
| /** | ||
| * @param {any} data | ||
| */ | ||
| function compileCodeScript(data) { | ||
| pendingRule = data.rule; | ||
| confirmOpen = true; | ||
| } | ||
|
|
||
| function closeConfirm() { | ||
| confirmOpen = false; | ||
| pendingRule = null; | ||
| } | ||
|
|
||
| function onConfirmCompile() { | ||
| const rule = pendingRule; | ||
| closeConfirm(); | ||
| if (rule) { | ||
| generateCodeScript(rule); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param {import('$agentTypes').AgentRule} rule | ||
| */ | ||
| function generateCodeScript(rule) { | ||
| isLoading = true; | ||
| generateAgentCodeScript(agent.id, { | ||
| options: { | ||
|
Comment on lines
+257
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. No in-flight compile guard generateCodeScript() sets isLoading but never checks it, so users can trigger multiple confirmed generateAgentCodeScript requests concurrently, causing duplicate work and racing success/error banners/timeouts. Agent Prompt
|
||
| save_to_db: true, | ||
| script_name: `${rule.trigger_name}_criteria.py`, | ||
| script_type: AgentCodeScriptType.Src, | ||
| data: { | ||
| "user_request": rule.config?.criteria | ||
| } | ||
| } | ||
| }).then(res => { | ||
| isLoading = false; | ||
| if (res?.success) { | ||
| isComplete = true; | ||
| successText = 'Code script has been generated!'; | ||
| setTimeout(() => { | ||
| isComplete = false; | ||
| successText = ''; | ||
| }, duration); | ||
| } else { | ||
| throw new Error('error when generating code script.'); | ||
| } | ||
| }).catch(() => { | ||
| isLoading = false; | ||
| isComplete = false; | ||
| isError = true; | ||
| errorText = 'Failed to generate code script.'; | ||
| setTimeout(() => { | ||
| isError = false; | ||
| errorText = ''; | ||
| }, duration); | ||
| }); | ||
| } | ||
|
|
||
| /** @param {import('$agentTypes').AgentRule[]} list */ | ||
| function innerRefresh(list) { | ||
| innerRules = list?.map(x => { | ||
|
|
@@ -248,6 +317,20 @@ | |
| {errorText} | ||
| /> | ||
|
|
||
| <ConfirmModal | ||
| isOpen={confirmOpen} | ||
| icon="warning" | ||
| title="Are you sure?" | ||
| text={pendingRule | ||
| ? `Are you sure you want to generate code script "${pendingRule.trigger_name}_criteria.py"? This will overwrite the existing code script if any.` | ||
| : ''} | ||
| confirmBtnText="Yes" | ||
| cancelBtnText="No" | ||
| confirm={onConfirmCompile} | ||
| cancel={closeConfirm} | ||
| toggleModal={closeConfirm} | ||
| /> | ||
|
|
||
| <div class="ar-card"> | ||
| <div class="ar-card-body"> | ||
| <div class="ar-header"> | ||
|
|
@@ -267,6 +350,7 @@ | |
| ondelete={data => deleteRule(data, uid)} | ||
| onchange={data => changeRule(data, uid)} | ||
| oncollapse={data => toggleCollapse(data, uid)} | ||
| oncompile={data => compileCodeScript(data)} | ||
| /> | ||
| {/each} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Compile allowed when disabled
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools