- Specialist Editor Change (all components in same overview), modal editors to allow for more complex configuration of Agents, Tasks and Tools
- Strengthening dynamic forms
This commit is contained in:
@@ -262,23 +262,42 @@ def edit_specialist(specialist_id):
|
||||
db.session.rollback()
|
||||
flash(f'Failed to update specialist. Error: {str(e)}', 'danger')
|
||||
current_app.logger.error(f'Failed to update specialist {specialist_id}. Error: {str(e)}')
|
||||
# On error, re-render with components list config
|
||||
from eveai_app.views.list_views.interaction_list_views import get_specialist_components_list_view
|
||||
components_config = get_specialist_components_list_view(specialist)
|
||||
return render_template('interaction/edit_specialist.html',
|
||||
form=form,
|
||||
specialist_id=specialist_id,
|
||||
agent_rows=agent_rows,
|
||||
task_rows=task_rows,
|
||||
tool_rows=tool_rows,
|
||||
components_title=components_config.get('title'),
|
||||
components_data=components_config.get('data'),
|
||||
components_columns=components_config.get('columns'),
|
||||
components_actions=components_config.get('actions'),
|
||||
components_initial_sort=components_config.get('initial_sort'),
|
||||
components_table_id=components_config.get('table_id'),
|
||||
components_table_height=components_config.get('table_height'),
|
||||
components_description=components_config.get('description'),
|
||||
components_index=components_config.get('index'),
|
||||
prefixed_url_for=prefixed_url_for,
|
||||
svg_path=svg_path, )
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
# Build combined components list view config for embedding
|
||||
from eveai_app.views.list_views.interaction_list_views import get_specialist_components_list_view
|
||||
components_config = get_specialist_components_list_view(specialist)
|
||||
|
||||
return render_template('interaction/edit_specialist.html',
|
||||
form=form,
|
||||
specialist_id=specialist_id,
|
||||
agent_rows=agent_rows,
|
||||
task_rows=task_rows,
|
||||
tool_rows=tool_rows,
|
||||
components_title=components_config.get('title'),
|
||||
components_data=components_config.get('data'),
|
||||
components_columns=components_config.get('columns'),
|
||||
components_actions=components_config.get('actions'),
|
||||
components_initial_sort=components_config.get('initial_sort'),
|
||||
components_table_id=components_config.get('table_id'),
|
||||
components_table_height=components_config.get('table_height'),
|
||||
components_description=components_config.get('description'),
|
||||
components_index=components_config.get('index'),
|
||||
prefixed_url_for=prefixed_url_for,
|
||||
svg_path=svg_path, )
|
||||
|
||||
@@ -310,6 +329,15 @@ def handle_specialist_selection():
|
||||
return redirect(prefixed_url_for('interaction_bp.specialists', for_redirect=True))
|
||||
|
||||
|
||||
@interaction_bp.route('/specialist/<int:specialist_id>/components_data', methods=['GET'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def specialist_components_data(specialist_id):
|
||||
"""Return JSON data for the specialist's combined components list (agents, tasks, tools)."""
|
||||
specialist = Specialist.query.get_or_404(specialist_id)
|
||||
from eveai_app.views.list_views.interaction_list_views import get_specialist_components_list_view
|
||||
config = get_specialist_components_list_view(specialist)
|
||||
return jsonify({'data': config.get('data', [])})
|
||||
|
||||
# Routes for Agent management ---------------------------------------------------------------------
|
||||
@interaction_bp.route('/agent/<int:agent_id>/edit', methods=['GET'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
@@ -318,22 +346,34 @@ def edit_agent(agent_id):
|
||||
form = EditEveAIAgentForm(obj=agent)
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
# Determine defaults for reset button if available
|
||||
enable_reset_defaults = False
|
||||
model_default = ''
|
||||
temperature_default = ''
|
||||
if getattr(form, '_agent_config', None):
|
||||
model_default = form._agent_config.get('full_model_name', 'mistral.mistral-medium-latest')
|
||||
temperature_default = form._agent_config.get('temperature', 0.7)
|
||||
enable_reset_defaults = True
|
||||
# Return just the form portion for AJAX requests
|
||||
return render_template('interaction/components/edit_agent.html',
|
||||
form=form,
|
||||
agent=agent,
|
||||
title="Edit Agent",
|
||||
description="Configure the agent with company-specific details if required",
|
||||
submit_text="Save Agent")
|
||||
submit_text="Save Agent",
|
||||
enable_reset_defaults=enable_reset_defaults,
|
||||
model_default=model_default,
|
||||
temperature_default=temperature_default)
|
||||
return None
|
||||
|
||||
|
||||
@interaction_bp.route('/agent/<int:agent_id>/save', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def save_agent(agent_id):
|
||||
current_app.logger.info(f'Trying to save agent {agent_id} -------------------------------------------')
|
||||
agent = EveAIAgent.query.get_or_404(agent_id) if agent_id else EveAIAgent()
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
form = EditEveAIAgentForm(obj=agent)
|
||||
form = EditEveAIAgentForm(formdata=request.form, obj=agent)
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
@@ -347,8 +387,25 @@ def save_agent(agent_id):
|
||||
db.session.rollback()
|
||||
current_app.logger.error(f'Failed to save agent {agent_id} for tenant {tenant_id}. Error: {str(e)}')
|
||||
return jsonify({'success': False, 'message': f"Failed to save agent {agent_id}: {str(e)}"})
|
||||
|
||||
return jsonify({'success': False, 'message': 'Validation failed'})
|
||||
else:
|
||||
# On validation errors, return the editor partial HTML so the frontend can display inline errors in the modal
|
||||
form_validation_failed(request, form)
|
||||
enable_reset_defaults = False
|
||||
model_default = ''
|
||||
temperature_default = ''
|
||||
if getattr(form, '_agent_config', None):
|
||||
model_default = form._agent_config.get('full_model_name', 'mistral.mistral-medium-latest')
|
||||
temperature_default = form._agent_config.get('temperature', 0.7)
|
||||
enable_reset_defaults = True
|
||||
return render_template('interaction/components/edit_agent.html',
|
||||
form=form,
|
||||
agent=agent,
|
||||
title="Edit Agent",
|
||||
description="Configure the agent with company-specific details if required",
|
||||
submit_text="Save Agent",
|
||||
enable_reset_defaults=enable_reset_defaults,
|
||||
model_default=model_default,
|
||||
temperature_default=temperature_default), 400
|
||||
|
||||
|
||||
# Routes for Task management ----------------------------------------------------------------------
|
||||
@@ -374,7 +431,7 @@ def edit_task(task_id):
|
||||
def save_task(task_id):
|
||||
task = EveAITask.query.get_or_404(task_id) if task_id else EveAITask()
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
form = EditEveAITaskForm(obj=task) # Replace with actual task form
|
||||
form = EditEveAITaskForm(formdata=request.form, obj=task) # Bind explicit formdata
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
@@ -389,7 +446,14 @@ def save_task(task_id):
|
||||
current_app.logger.error(f'Failed to save task {task_id} for tenant {tenant_id}. Error: {str(e)}')
|
||||
return jsonify({'success': False, 'message': f"Failed to save task {task_id}: {str(e)}"})
|
||||
|
||||
return jsonify({'success': False, 'message': 'Validation failed'})
|
||||
# On validation errors, return the editor partial HTML (400) so frontend can show inline errors
|
||||
form_validation_failed(request, form)
|
||||
return render_template('interaction/components/edit_task.html',
|
||||
form=form,
|
||||
task=task,
|
||||
title="Edit Task",
|
||||
description="Configure the task with company-specific details if required",
|
||||
submit_text="Save Task"), 400
|
||||
|
||||
|
||||
# Routes for Tool management ----------------------------------------------------------------------
|
||||
@@ -415,7 +479,7 @@ def edit_tool(tool_id):
|
||||
def save_tool(tool_id):
|
||||
tool = EveAITool.query.get_or_404(tool_id) if tool_id else EveAITool()
|
||||
tenant_id = session.get('tenant').get('id')
|
||||
form = EditEveAIToolForm(obj=tool) # Replace with actual tool form
|
||||
form = EditEveAIToolForm(formdata=request.form, obj=tool)
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
@@ -430,7 +494,14 @@ def save_tool(tool_id):
|
||||
current_app.logger.error(f'Failed to save tool {tool_id} for tenant {tenant_id}. Error: {str(e)}')
|
||||
return jsonify({'success': False, 'message': f"Failed to save tool {tool_id}: {str(e)}"})
|
||||
|
||||
return jsonify({'success': False, 'message': 'Validation failed'})
|
||||
# On validation errors, return the editor partial HTML (400)
|
||||
form_validation_failed(request, form)
|
||||
return render_template('interaction/components/edit_tool.html',
|
||||
form=form,
|
||||
tool=tool,
|
||||
title="Edit Tool",
|
||||
description="Configure the tool with company-specific details if required",
|
||||
submit_text="Save Tool"), 400
|
||||
|
||||
|
||||
# Component selection handlers --------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user