Implement updateChoicesOnly method in AgentModal to preserve unsaved user values when updating agent choices. Update AIAgent to call this method when the modal is open and the current agent is being updated.

This commit is contained in:
vegu-ai-tools
2025-11-29 21:07:50 +02:00
parent 87089fad46
commit 1d032e3309
2 changed files with 47 additions and 0 deletions

View File

@@ -374,6 +374,12 @@ export default {
}
agent.enabled = data.data.enabled;
// If the modal is open and this is the current agent, update choices only (preserve user's unsaved values)
if (this.state.dialog && this.state.currentAgent && this.state.currentAgent.name === data.name && this.$refs.modal) {
// Update choices directly in the modal's local agent object to avoid triggering the watcher
this.$refs.modal.updateChoicesOnly(agent);
}
// sort agents by label
this.state.agents.sort((a, b) => {

View File

@@ -466,6 +466,47 @@ export default {
this.$emit('save', this.agent);
},
/**
* Updates only the choices arrays in the local agent object from updated agent data,
* preserving all user-entered values to avoid overwriting unsaved changes.
*/
updateChoicesOnly(updatedAgent) {
if (!updatedAgent?.data?.actions || !this.agent?.data?.actions) {
return;
}
// Update choices in data.actions (the schema/definition)
for (const actionKey in updatedAgent.data.actions) {
const updatedAction = updatedAgent.data.actions[actionKey];
if (!updatedAction?.config) continue;
// Ensure local agent has the action structure
if (!this.agent.data.actions[actionKey]) {
this.agent.data.actions[actionKey] = {};
}
if (!this.agent.data.actions[actionKey].config) {
this.agent.data.actions[actionKey].config = {};
}
// Update choices for each config item
for (const configKey in updatedAction.config) {
const updatedConfig = updatedAction.config[configKey];
// Only update if choices exist and are not null/undefined
if (updatedConfig?.choices != null) {
// Ensure the config object exists
if (!this.agent.data.actions[actionKey].config[configKey]) {
this.agent.data.actions[actionKey].config[configKey] = {};
}
// Update only the choices property, preserving all other config properties
// Create new array reference to ensure Vue reactivity
this.agent.data.actions[actionKey].config[configKey].choices = Array.isArray(updatedConfig.choices)
? [...updatedConfig.choices]
: updatedConfig.choices;
}
}
}
},
wstemplateChoices(action_config) {
// Resolve template bucket by desired template type; bail early if not available
const bucket = this.templates?.by_type?.[action_config?.wstemplate_type];