Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/helpers/types/agentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@
*/

/**
* @typedef {Object} RuleCriteria
* @property {string?} [mode] - Criteria mode: llm, code, etc. Takes precedence over the mode carried on the trigger options.
* @typedef {Object} RuleCriteriaConfig
* @property {string?} [mode] - Criteria mode: llm, python script, etc. Takes precedence over the mode carried on the trigger options.
* @property {string?} [criteria] - Criteria text
*/

Expand All @@ -267,7 +267,7 @@
* @property {string?} [displayName]
* @property {boolean} disabled
* @property {string?} [message] - Message sent to agent
* @property {RuleCriteria?} [criteria]
* @property {RuleCriteriaConfig?} [criteria_config]
* @property {any?} [output_args]
* @property {string?} [json_args]
* @property {string?} [statement]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

// Code script can only be generated by admins, once a trigger is picked and criteria text exists.
let canCompile = $derived(
!!rule.trigger_name && !!rule.criteria?.criteria?.trim()
!!rule.trigger_name && !!rule.criteria_config?.criteria?.trim()
);

// The rule's own mode wins; otherwise the trigger option's mode applies.
Expand Down Expand Up @@ -250,7 +250,7 @@
containerStyles={'width: 100%;'}
placeholder={modePlaceholder}
disabled={rule.disabled}
selectedValues={rule.criteria?.mode ? [rule.criteria.mode] : []}
selectedValues={rule.criteria_config?.mode ? [rule.criteria_config.mode] : []}
options={criteriaModeOptions}
onselect={e => changeRule(e, 'criteria_mode')}
/>
Expand Down Expand Up @@ -302,7 +302,7 @@
maxlength={textLimit}
placeholder="Describe when this rule should trigger..."
disabled={rule.disabled}
value={rule.criteria?.criteria || ''}
value={rule.criteria_config?.criteria || ''}
oninput={e => changeText(e, 'criteria')}
></textarea>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
trigger_name: x.trigger_name,
disabled: x.disabled,
message: x.message || null,
criteria: normalizeCriteria(x.criteria),
criteria_config: normalizeCriteriaConfig(x.criteria_config),
expanded: x.expanded
Comment on lines 46 to 48

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. Legacy criteria ignored 🐞 Bug ≡ Correctness

The rules UI now reads and saves only rule.criteria_config; any existing rule objects that still
have the legacy criteria field will render as having no criteria (including disabling code
generation) and will be saved with criteria_config: null in the rebuilt rules payload.
Agent Prompt
## Issue description
The UI migrated from `criteria` to `criteria_config` but does not map legacy rule objects that still carry `criteria`. Because `fetchRules()` rebuilds the rules payload using only `x.criteria_config`, legacy criteria can be dropped on save.

## Issue Context
This repo appears to be a frontend that consumes persisted agent rule JSON from an external API/storage; renames like this typically require handling pre-migration data.

## Fix Focus Areas
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte[41-50]
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule.svelte[164-172]
- src/routes/page/agent/[agentId]/agent-components/rules/agent-rule-item.svelte[44-47]

## What to change
1. When initializing/refreshing `innerRules` (e.g., in `init()` or `innerRefresh()`), map legacy to new:
   - If `x.criteria_config` is missing but `x.criteria` exists, set `criteria_config = x.criteria` (or normalize it).
2. In `fetchRules()`, be defensive when normalizing:
   - Use `normalizeCriteriaConfig(x.criteria_config ?? x.criteria)`.
3. Optionally (belt-and-suspenders), in the UI read path you can also fall back:
   - `rule.criteria_config?.criteria ?? rule.criteria?.criteria` (only if `rule.criteria` can exist at runtime).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

};
});
Expand All @@ -64,14 +64,14 @@
}

/**
* Collapse a blank criteria into null so the rule is saved without a
* criteria object instead of with an empty one.
* @param {import('$agentTypes').RuleCriteria | null | undefined} criteria
* @returns {import('$agentTypes').RuleCriteria | null}
* Collapse a blank criteria config into null so the rule is saved without a
* criteria config instead of with an empty one.
* @param {import('$agentTypes').RuleCriteriaConfig | null | undefined} config
* @returns {import('$agentTypes').RuleCriteriaConfig | null}
*/
function normalizeCriteria(criteria) {
const mode = criteria?.mode || '';
const text = criteria?.criteria || '';
function normalizeCriteriaConfig(config) {
const mode = config?.mode || '';
const text = config?.criteria || '';
if (!mode.trim() && !text.trim()) return null;

return {
Expand Down Expand Up @@ -187,9 +187,9 @@
} else if (field === 'message') {
found.message = value;
} else if (field === 'criteria') {
found.criteria = { ...(found.criteria || {}), criteria: value };
found.criteria_config = { ...(found.criteria_config || {}), criteria: value };
} else if (field === 'criteria_mode') {
found.criteria = { ...(found.criteria || {}), mode: value };
found.criteria_config = { ...(found.criteria_config || {}), mode: value };
}

handleAgentChange();
Expand All @@ -203,7 +203,7 @@
displayName: '',
disabled: false,
message: '',
criteria: { mode: '', criteria: '' },
criteria_config: { mode: '', criteria: '' },
expanded: true
}
];
Expand Down Expand Up @@ -287,7 +287,7 @@
script_name: `${rule.trigger_name}_criteria.py`,
script_type: AgentCodeScriptType.Src,
data: {
"user_request": rule.criteria?.criteria
"user_request": rule.criteria_config?.criteria
}
}
}).then(res => {
Expand Down
Loading