mirror of
https://github.com/vegu-ai/talemate.git
synced 2025-12-16 19:57:47 +01:00
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:
@@ -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) => {
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user