|
1 | 1 | <script> |
2 | | - import { onMount } from 'svelte'; |
3 | 2 | import { getAgentRuleOptionsById, getAgentRuleConfigOptions } from '$lib/services/agent-service'; |
4 | 3 | import LoadingToComplete from '$lib/common/spinners/LoadingToComplete.svelte'; |
5 | 4 | import { scrollToBottom } from '$lib/helpers/utils/common'; |
|
79 | 78 | /** @type {HTMLElement} */ |
80 | 79 | let scrollContainer; |
81 | 80 |
|
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(() => { |
83 | 98 | resizeWindow(); |
84 | | - Promise.all([ |
85 | | - loadAgentRuleOptions(), |
86 | | - loadAgentRuleConfigOptions() |
87 | | - ]); |
88 | 99 | }); |
89 | 100 |
|
90 | 101 | function loadAgentRuleOptions() { |
91 | | - return new Promise((resolve) => { |
| 102 | + return new Promise((resolve, reject) => { |
92 | 103 | getAgentRuleOptionsById(agent.id).then(data => { |
93 | 104 | const list = data?.map(x => { |
94 | 105 | return { |
|
105 | 116 | }, ...list]; |
106 | 117 | init(); |
107 | 118 | resolve('done'); |
| 119 | + }).catch(error => { |
| 120 | + console.error('Failed to load agent rule options:', error); |
| 121 | + ruleOptions = [{ name: "", displayName: "" }]; |
| 122 | + reject(error); |
108 | 123 | }); |
109 | 124 | }); |
110 | 125 | } |
|
120 | 135 | } |
121 | 136 |
|
122 | 137 | function loadAgentRuleConfigOptions() { |
123 | | - return new Promise((resolve) => { |
| 138 | + return new Promise((resolve, reject) => { |
124 | 139 | getAgentRuleConfigOptions().then(data => { |
125 | 140 | ruleConfigs = data || {}; |
126 | 141 | const keys = Object.keys(data || {}); |
|
130 | 145 | ...list |
131 | 146 | ]; |
132 | 147 | resolve('done'); |
| 148 | + }).catch(error => { |
| 149 | + console.error('Failed to load agent rule config options:', error); |
| 150 | + ruleConfigs = {}; |
| 151 | + configOptions = [{ name: '' }]; |
| 152 | + reject(error); |
133 | 153 | }); |
134 | 154 | }); |
135 | 155 | } |
|
0 commit comments