Skip to content

Commit 5674561

Browse files
author
Visagan Guruparan
committed
Update rule trigger api routing by agentId #2
1 parent a61a509 commit 5674561

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
import { onMount } from 'svelte';
32
import { getAgentRuleOptionsById, getAgentRuleConfigOptions } from '$lib/services/agent-service';
43
import LoadingToComplete from '$lib/common/spinners/LoadingToComplete.svelte';
54
import { scrollToBottom } from '$lib/helpers/utils/common';
@@ -79,16 +78,28 @@
7978
/** @type {HTMLElement} */
8079
let scrollContainer;
8180
82-
onMount(async () =>{
81+
// React to agent.id changes to reload agent-specific trigger options
82+
$effect(() => {
83+
if (agent?.id) {
84+
// Reset state when agent changes
85+
ruleOptions = [];
86+
innerRules = [];
87+
88+
// Load agent-specific data
89+
Promise.all([
90+
loadAgentRuleOptions(),
91+
loadAgentRuleConfigOptions()
92+
]);
93+
}
94+
});
95+
96+
// Initialize window size on mount
97+
$effect(() => {
8398
resizeWindow();
84-
Promise.all([
85-
loadAgentRuleOptions(),
86-
loadAgentRuleConfigOptions()
87-
]);
8899
});
89100
90101
function loadAgentRuleOptions() {
91-
return new Promise((resolve) => {
102+
return new Promise((resolve, reject) => {
92103
getAgentRuleOptionsById(agent.id).then(data => {
93104
const list = data?.map(x => {
94105
return {
@@ -105,6 +116,10 @@
105116
}, ...list];
106117
init();
107118
resolve('done');
119+
}).catch(error => {
120+
console.error('Failed to load agent rule options:', error);
121+
ruleOptions = [{ name: "", displayName: "" }];
122+
reject(error);
108123
});
109124
});
110125
}
@@ -120,7 +135,7 @@
120135
}
121136
122137
function loadAgentRuleConfigOptions() {
123-
return new Promise((resolve) => {
138+
return new Promise((resolve, reject) => {
124139
getAgentRuleConfigOptions().then(data => {
125140
ruleConfigs = data || {};
126141
const keys = Object.keys(data || {});
@@ -130,6 +145,11 @@
130145
...list
131146
];
132147
resolve('done');
148+
}).catch(error => {
149+
console.error('Failed to load agent rule config options:', error);
150+
ruleConfigs = {};
151+
configOptions = [{ name: '' }];
152+
reject(error);
133153
});
134154
});
135155
}

0 commit comments

Comments
 (0)