- Finish editing of Specialists with overview, agent - task - tool editor
- Split differrent caching mechanisms (types, version tree, config) into different cachers - Improve resource usage on starting components, and correct gevent usage - Refine repopack usage for eveai_app (too large) - Change nginx dockerfile to allow for specialist overviews being served statically
This commit is contained in:
@@ -161,10 +161,31 @@ def register_blueprints(app):
|
||||
|
||||
def register_cache_handlers(app):
|
||||
from common.utils.cache.config_cache import (
|
||||
AgentConfigCacheHandler, TaskConfigCacheHandler, ToolConfigCacheHandler, SpecialistConfigCacheHandler)
|
||||
AgentConfigCacheHandler, AgentConfigTypesCacheHandler, AgentConfigVersionTreeCacheHandler,
|
||||
TaskConfigCacheHandler, TaskConfigTypesCacheHandler, TaskConfigVersionTreeCacheHandler,
|
||||
ToolConfigCacheHandler, ToolConfigTypesCacheHandler, ToolConfigVersionTreeCacheHandler,
|
||||
SpecialistConfigCacheHandler, SpecialistConfigTypesCacheHandler, SpecialistConfigVersionTreeCacheHandler,)
|
||||
|
||||
cache_manager.register_handler(AgentConfigCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(AgentConfigTypesCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(AgentConfigVersionTreeCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(TaskConfigCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(TaskConfigTypesCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(TaskConfigVersionTreeCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(ToolConfigCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(ToolConfigTypesCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(ToolConfigVersionTreeCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(SpecialistConfigCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(SpecialistConfigTypesCacheHandler, 'eveai_config')
|
||||
cache_manager.register_handler(SpecialistConfigVersionTreeCacheHandler, 'eveai_config')
|
||||
|
||||
cache_manager.agents_config_cache.set_version_tree_cache(cache_manager.agents_version_tree_cache)
|
||||
cache_manager.tasks_config_cache.set_version_tree_cache(cache_manager.tasks_version_tree_cache)
|
||||
cache_manager.tools_config_cache.set_version_tree_cache(cache_manager.tools_version_tree_cache)
|
||||
cache_manager.specialists_config_cache.set_version_tree_cache(cache_manager.specialists_version_tree_cache)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
{% extends 'base.html' %}
|
||||
{% from "macros.html" import render_field %}
|
||||
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
|
||||
{% block content_title %}{{ title }}{% endblock %}
|
||||
{% block content_description %}{{ description }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
{% set disabled_fields = [] %}
|
||||
{% set exclude_fields = [] %}
|
||||
{% for field in form.get_static_fields() %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
{% if form.get_dynamic_fields is defined %}
|
||||
{% for collection_name, fields in form.get_dynamic_fields().items() %}
|
||||
{% if fields|length > 0 %}
|
||||
<h4 class="mt-4">{{ collection_name }}</h4>
|
||||
{% endif %}
|
||||
{% for field in fields %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
{% set disabled_fields = [] %}
|
||||
{% set exclude_fields = [] %}
|
||||
{% for field in form.get_static_fields() %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
{% if form.get_dynamic_fields is defined %}
|
||||
{% for collection_name, fields in form.get_dynamic_fields().items() %}
|
||||
{% if fields|length > 0 %}
|
||||
<h4 class="mt-4">{{ collection_name }}</h4>
|
||||
{% endif %}
|
||||
{% for field in fields %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<button type="submit" class="btn btn-primary">{{ submit_text }}</button>
|
||||
</form>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<div class="btn-group mt-3">
|
||||
<button type="submit" class="btn btn-primary component-submit">{{ submit_text }}</button>
|
||||
<button type="button" class="btn btn-secondary ms-2" id="cancelEdit">Cancel</button>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content_footer %}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{% extends "interaction/component.html" %}
|
||||
@@ -1,33 +1,479 @@
|
||||
{% extends 'base.html' %}
|
||||
{% from "macros.html" import render_field %}
|
||||
{% from "macros.html" import render_field, render_selectable_table %}
|
||||
|
||||
{% block title %}Edit Specialist{% endblock %}
|
||||
|
||||
{% block content_title %}Edit Specialist{% endblock %}
|
||||
{% block content_description %}Edit a Specialist{% endblock %}
|
||||
{% block content_description %}Edit a Specialist and its components{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
{% set disabled_fields = ['type'] %}
|
||||
{% set exclude_fields = [] %}
|
||||
<!-- Render Static Fields -->
|
||||
{% for field in form.get_static_fields() %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
<!-- Render Dynamic Fields -->
|
||||
{% for collection_name, fields in form.get_dynamic_fields().items() %}
|
||||
{% if fields|length > 0 %}
|
||||
<h4 class="mt-4">{{ collection_name }}</h4>
|
||||
{% endif %}
|
||||
{% for field in fields %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
<button type="submit" class="btn btn-primary">Save Specialist</button>
|
||||
</form>
|
||||
<div class="container-fluid px-0">
|
||||
<div class="row">
|
||||
<!-- Main Specialist Editor -->
|
||||
<div class="col-12" id="mainEditorSection">
|
||||
<form method="post" id="specialistForm" action="{{ url_for('interaction_bp.edit_specialist', specialist_id=specialist_id) }}">
|
||||
{{ form.hidden_tag() }}
|
||||
{% set disabled_fields = ['type', 'type_version'] %}
|
||||
{% set exclude_fields = [] %}
|
||||
<!-- Render Static Fields -->
|
||||
{% for field in form.get_static_fields() %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
|
||||
<!-- Overview Section -->
|
||||
<div class="row mb-4">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="specialist-overview" id="specialist-svg">
|
||||
<img src="{{ svg_path }}" alt="Specialist Overview" class="w-100">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Nav Tabs -->
|
||||
<div class="row mt-5">
|
||||
<div class="col-lg-12">
|
||||
<div class="nav-wrapper position-relative end-0">
|
||||
<ul class="nav nav-pills nav-fill p-1" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link mb-0 px-0 py-1 active" data-bs-toggle="tab" href="#configuration-tab" role="tab">
|
||||
Configuration
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link mb-0 px-0 py-1" data-bs-toggle="tab" href="#agents-tab" role="tab">
|
||||
Agents
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link mb-0 px-0 py-1" data-bs-toggle="tab" href="#tasks-tab" role="tab">
|
||||
Tasks
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link mb-0 px-0 py-1" data-bs-toggle="tab" href="#tools-tab" role="tab">
|
||||
Tools
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link mb-0 px-0 py-1 d-none" id="editor-tab-link" data-bs-toggle="tab" href="#editor-tab" role="tab">
|
||||
Editor
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="tab-content tab-space">
|
||||
<!-- Configuration Tab -->
|
||||
<div class="tab-pane fade show active" id="configuration-tab" role="tabpanel">
|
||||
{% for collection_name, fields in form.get_dynamic_fields().items() %}
|
||||
{% if fields|length > 0 %}
|
||||
<h4 class="mt-4">{{ collection_name }}</h4>
|
||||
{% endif %}
|
||||
{% for field in fields %}
|
||||
{{ render_field(field, disabled_fields, exclude_fields) }}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- Agents Tab -->
|
||||
<div class="tab-pane fade" id="agents-tab" role="tabpanel">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{ render_selectable_table(
|
||||
headers=["Agent ID", "Name", "Type", "Status"],
|
||||
rows=agent_rows if agent_rows else [],
|
||||
selectable=True,
|
||||
id="agentsTable",
|
||||
is_component_selector=True
|
||||
) }}
|
||||
<div class="form-group mt-3">
|
||||
<button type="button" class="btn btn-primary edit-component"
|
||||
data-component-type="agent"
|
||||
data-edit-url="{{ prefixed_url_for('interaction_bp.edit_agent', agent_id=0) }}">Edit Agent
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tasks Tab -->
|
||||
<div class="tab-pane fade" id="tasks-tab" role="tabpanel">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{ render_selectable_table(
|
||||
headers=["Task ID", "Name", "Type", "Status"],
|
||||
rows=task_rows if task_rows else [],
|
||||
selectable=True,
|
||||
id="tasksTable",
|
||||
is_component_selector=True
|
||||
) }}
|
||||
<div class="form-group mt-3">
|
||||
<button type="button" class="btn btn-primary edit-component"
|
||||
data-component-type="task"
|
||||
data-edit-url="{{ prefixed_url_for('interaction_bp.edit_task', task_id=0) }}">Edit Task
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tools Tab -->
|
||||
<div class="tab-pane fade" id="tools-tab" role="tabpanel">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{ render_selectable_table(
|
||||
headers=["Tool ID", "Name", "Type", "Status"],
|
||||
rows=tool_rows if tool_rows else [],
|
||||
selectable=True,
|
||||
id="toolsTable",
|
||||
is_component_selector=True
|
||||
) }}
|
||||
<div class="form-group mt-3">
|
||||
<button type="button" class="btn btn-primary edit-component"
|
||||
data-component-type="tool"
|
||||
data-edit-url="{{ prefixed_url_for('interaction_bp.edit_tool', tool_id=0) }}">Edit Tool
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Editor Tab -->
|
||||
<div class="tab-pane fade" id="editor-tab" role="tabpanel">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0" id="editorTitle"></h5>
|
||||
</div>
|
||||
<div class="card-body" id="editorContent">
|
||||
<!-- Component editor will be loaded here -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary mt-4">Save Specialist</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content_footer %}
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const editorTab = document.getElementById('editor-tab');
|
||||
const editorTabLink = document.getElementById('editor-tab-link');
|
||||
const editorTitle = document.getElementById('editorTitle');
|
||||
const editorContent = document.getElementById('editorContent');
|
||||
let previousTab = null;
|
||||
|
||||
// Add color classes to the tabs
|
||||
const agentsTabLink = document.querySelector('[href="#agents-tab"]');
|
||||
const tasksTabLink = document.querySelector('[href="#tasks-tab"]');
|
||||
const toolsTabLink = document.querySelector('[href="#tools-tab"]');
|
||||
|
||||
agentsTabLink.classList.add('component-agent');
|
||||
tasksTabLink.classList.add('component-task');
|
||||
toolsTabLink.classList.add('component-tool');
|
||||
|
||||
// Add background colors to the tab panes
|
||||
const agentsTab = document.getElementById('agents-tab');
|
||||
const tasksTab = document.getElementById('tasks-tab');
|
||||
const toolsTab = document.getElementById('tools-tab');
|
||||
|
||||
agentsTab.classList.add('component-agent-bg');
|
||||
tasksTab.classList.add('component-task-bg');
|
||||
toolsTab.classList.add('component-tool-bg');
|
||||
|
||||
// Ensure component selectors don't interfere with form submission
|
||||
const form = document.getElementById('specialistForm');
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
// Remove component selectors from form validation
|
||||
const componentSelectors = form.querySelectorAll('input[data-component-selector]');
|
||||
componentSelectors.forEach(selector => {
|
||||
selector.removeAttribute('required');
|
||||
});
|
||||
});
|
||||
|
||||
// Get all tab links except the editor tab
|
||||
const tabLinks = Array.from(document.querySelectorAll('.nav-link')).filter(link => link.id !== 'editor-tab-link');
|
||||
|
||||
// Function to toggle other tabs' disabled state
|
||||
function toggleOtherTabs(disable) {
|
||||
tabLinks.forEach(link => {
|
||||
if (disable) {
|
||||
link.classList.add('disabled');
|
||||
} else {
|
||||
link.classList.remove('disabled');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Function to toggle main form elements
|
||||
const mainSubmitButton = document.querySelector('#specialistForm > .btn-primary');
|
||||
|
||||
function toggleMainFormElements(disable) {
|
||||
// Toggle tabs
|
||||
document.querySelectorAll('.nav-link').forEach(link => {
|
||||
if (link.id !== 'editor-tab-link') {
|
||||
if (disable) {
|
||||
link.classList.add('disabled');
|
||||
} else {
|
||||
link.classList.remove('disabled');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle main submit button
|
||||
if (mainSubmitButton) {
|
||||
mainSubmitButton.disabled = disable;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle edit buttons
|
||||
document.querySelectorAll('.edit-component').forEach(button => {
|
||||
button.addEventListener('click', function() {
|
||||
const componentType = this.dataset.componentType;
|
||||
const form = this.closest('form');
|
||||
const selectedRow = form.querySelector('input[type="radio"]:checked');
|
||||
|
||||
console.log("I'm in the custom click event listener!")
|
||||
|
||||
if (!selectedRow) {
|
||||
alert('Please select a component to edit');
|
||||
return;
|
||||
}
|
||||
|
||||
const valueMatch = selectedRow.value.match(/'value':\s*(\d+)/);
|
||||
const selectedId = valueMatch ? valueMatch[1] : null;
|
||||
|
||||
if (!selectedId) {
|
||||
console.error('Could not extract ID from value:', selectedRow.value);
|
||||
alert('Error: Could not determine component ID');
|
||||
return;
|
||||
}
|
||||
|
||||
// Make AJAX call to get component editor
|
||||
const urlTemplate = this.dataset.editUrl.replace('/0', `/${selectedId}`);
|
||||
fetch(urlTemplate, {
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(html => {
|
||||
// Store the current active tab
|
||||
previousTab = document.querySelector('.nav-link.active');
|
||||
|
||||
// Update editor content
|
||||
editorTitle.textContent = `Edit ${componentType.charAt(0).toUpperCase() + componentType.slice(1)}`;
|
||||
editorContent.innerHTML = html;
|
||||
|
||||
// Apply the appropriate color class to the editor tab
|
||||
editorTabLink.classList.remove('component-agent', 'component-task', 'component-tool');
|
||||
editorTab.classList.remove('component-agent-bg', 'component-task-bg', 'component-tool-bg');
|
||||
|
||||
editorTabLink.classList.add(`component-${componentType}`);
|
||||
editorTab.classList.add(`component-${componentType}-bg`);
|
||||
|
||||
// Disable other tabs & main form elements
|
||||
toggleOtherTabs(true);
|
||||
toggleMainFormElements(true)
|
||||
|
||||
// Show editor tab and switch to it
|
||||
editorTabLink.classList.remove('d-none');
|
||||
editorTabLink.click();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching editor:', error);
|
||||
alert('Error loading editor. Please try again.');
|
||||
});
|
||||
});
|
||||
|
||||
// Clean up color classes when returning from editor
|
||||
editorTabLink.addEventListener('hide.bs.tab', function() {
|
||||
editorTabLink.classList.remove('component-agent', 'component-task', 'component-tool');
|
||||
editorTab.classList.remove('component-agent-bg', 'component-task-bg', 'component-tool-bg');
|
||||
});
|
||||
});
|
||||
|
||||
// Handle component editor form submissions
|
||||
editorContent.addEventListener('click', function(e) {
|
||||
if (e.target && e.target.classList.contains('component-submit')) {
|
||||
e.preventDefault();
|
||||
console.log('Submit button clicked');
|
||||
|
||||
// Get all form fields from the editor content
|
||||
const formData = new FormData();
|
||||
editorContent.querySelectorAll('input, textarea, select').forEach(field => {
|
||||
if (field.type === 'checkbox') {
|
||||
formData.append(field.name, field.checked ? 'y' : 'n');
|
||||
} else {
|
||||
formData.append(field.name, field.value);
|
||||
}
|
||||
});
|
||||
|
||||
// Add CSRF token
|
||||
const csrfToken = document.querySelector('input[name="csrf_token"]').value;
|
||||
formData.append('csrf_token', csrfToken);
|
||||
|
||||
// Get the component ID from the current state
|
||||
const selectedRow = document.querySelector('input[name="selected_row"]:checked');
|
||||
const componentData = JSON.parse(selectedRow.value.replace(/'/g, '"'));
|
||||
const componentId = componentData.value;
|
||||
|
||||
// Determine the component type (agent, task, or tool)
|
||||
const componentType = editorTabLink.classList.contains('component-agent') ? 'agent' :
|
||||
editorTabLink.classList.contains('component-task') ? 'task' : 'tool';
|
||||
|
||||
// Submit the data
|
||||
fetch(`/admin/interaction/${componentType}/${componentId}/save`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// Handle success - reload the page
|
||||
location.reload();
|
||||
} else {
|
||||
// Handle error
|
||||
alert(data.message || 'Error saving component');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error saving component');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Handle case when editor tab is hidden
|
||||
editorTabLink.addEventListener('hide.bs.tab', function() {
|
||||
// Re-enable all tabs & main form elements
|
||||
toggleOtherTabs(false);
|
||||
toggleMainFormElements(false)
|
||||
|
||||
// Remove color classes
|
||||
editorTabLink.classList.remove('component-agent', 'component-task', 'component-tool');
|
||||
editorTab.classList.remove('component-agent-bg', 'component-task-bg', 'component-tool-bg');
|
||||
});
|
||||
|
||||
// Function to handle canceling edit
|
||||
function cancelEdit() {
|
||||
// Re-enable all tabs & main form elements
|
||||
toggleOtherTabs(false);
|
||||
toggleMainFormElements()
|
||||
|
||||
// Return to previous tab
|
||||
if (previousTab) {
|
||||
previousTab.click();
|
||||
}
|
||||
|
||||
// Hide the editor tab
|
||||
editorTabLink.classList.add('d-none');
|
||||
}
|
||||
|
||||
// Handle cancel button in editor
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target && e.target.id === 'cancelEdit') {
|
||||
// Get the previously active tab (stored before switching to editor)
|
||||
const previousTab = document.querySelector('[href="#configuration-tab"]'); // default to configuration tab
|
||||
|
||||
cancelEdit()
|
||||
|
||||
// Hide the editor tab
|
||||
document.getElementById('editor-tab-link').classList.add('d-none');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.tab-pane .card {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.nav-link.component-agent,
|
||||
.nav-link.component-task,
|
||||
.nav-link.component-tool {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
/* Add new CSS for normal tabs */
|
||||
.nav-link {
|
||||
color: #344767 !important; /* Default dark color */
|
||||
}
|
||||
|
||||
/* Style for disabled tabs */
|
||||
.nav-link.disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.component-agent {
|
||||
background-color: #9c27b0 !important; /* Purple */
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.component-task {
|
||||
background-color: #ff9800 !important; /* Orange */
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.component-tool {
|
||||
background-color: #009688 !important; /* Teal */
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
/* Lighter background versions for the tab content */
|
||||
.tab-pane.component-agent-bg {
|
||||
background-color: rgba(156, 39, 176, 0.2); /* Light purple */
|
||||
}
|
||||
|
||||
.tab-pane.component-task-bg {
|
||||
background-color: rgba(255, 152, 0, 0.2); /* Light orange */
|
||||
}
|
||||
|
||||
.tab-pane.component-tool-bg {
|
||||
background-color: rgba(0, 150, 136, 0.2); /* Light teal */
|
||||
}
|
||||
|
||||
/* Add some padding to the tab content */
|
||||
.tab-pane {
|
||||
padding: 15px;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
.specialist-overview {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
min-height: 200px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.specialist-overview svg {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
max-height: 400px; /* Adjust as needed */
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
@@ -19,5 +19,5 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content_footer %}
|
||||
{{ render_pagination(pagination, 'document_bp.retrievers') }}
|
||||
{{ render_pagination(pagination, 'interaction_bp.specialists') }}
|
||||
{% endblock %}
|
||||
@@ -135,7 +135,7 @@
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_selectable_table(headers, rows, selectable, id) %}
|
||||
{% macro render_selectable_table(headers, rows, selectable, id, is_component_selector=False) %}
|
||||
<div class="card">
|
||||
<div class="table-responsive">
|
||||
<table class="table align-items-center mb-0" id="{{ id }}">
|
||||
@@ -153,7 +153,16 @@
|
||||
{% for row in rows %}
|
||||
<tr>
|
||||
{% if selectable %}
|
||||
<td><input type="radio" name="selected_row" value="{{ row[0] }}" required></td>
|
||||
<td>
|
||||
<input type="radio"
|
||||
name="selected_row"
|
||||
value="{{ row[0] }}"
|
||||
{% if is_component_selector %}
|
||||
data-component-selector="true"
|
||||
{% else %}
|
||||
required
|
||||
{% endif %}>
|
||||
</td>
|
||||
{% endif %}
|
||||
{% for cell in row %}
|
||||
<td class="{{ cell.class }}">
|
||||
|
||||
@@ -21,7 +21,6 @@ def get_tools():
|
||||
|
||||
class SpecialistForm(FlaskForm):
|
||||
name = StringField('Name', validators=[DataRequired(), Length(max=50)])
|
||||
description = TextAreaField('Description', validators=[DataRequired()])
|
||||
|
||||
retrievers = QuerySelectMultipleField(
|
||||
'Retrievers',
|
||||
@@ -37,14 +36,14 @@ class SpecialistForm(FlaskForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
types_dict = cache_manager.specialist_config_cache.get_types()
|
||||
types_dict = cache_manager.specialists_types_cache.get_types()
|
||||
# Dynamically populate the 'type' field using the constructor
|
||||
self.type.choices = [(key, value['name']) for key, value in types_dict.items()]
|
||||
|
||||
|
||||
class EditSpecialistForm(DynamicFormBase):
|
||||
name = StringField('Name', validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[Optional()])
|
||||
|
||||
retrievers = QuerySelectMultipleField(
|
||||
'Retrievers',
|
||||
@@ -55,6 +54,7 @@ class EditSpecialistForm(DynamicFormBase):
|
||||
)
|
||||
|
||||
type = StringField('Specialist Type', validators=[DataRequired()], render_kw={'readonly': True})
|
||||
type_version = StringField('Type Version', validators=[DataRequired()], render_kw={'readonly': True})
|
||||
tuning = BooleanField('Enable Retrieval Tuning', default=False)
|
||||
|
||||
|
||||
@@ -76,41 +76,21 @@ class BaseEditComponentForm(DynamicFormBase):
|
||||
name = StringField('Name', validators=[DataRequired()])
|
||||
description = TextAreaField('Description', validators=[Optional()])
|
||||
type = StringField('Type', validators=[DataRequired()], render_kw={'readonly': True})
|
||||
type_version = StringField('Type Version', validators=[DataRequired()], render_kw={'readonly': True})
|
||||
tuning = BooleanField('Enable Tuning', default=False)
|
||||
|
||||
|
||||
class EveAIAgentForm(BaseComponentForm):
|
||||
role = TextAreaField('Role', validators=[DataRequired()])
|
||||
goal = TextAreaField('Goal', validators=[DataRequired()])
|
||||
backstory = TextAreaField('Backstory', validators=[DataRequired()])
|
||||
|
||||
tools = QuerySelectMultipleField(
|
||||
'Tools',
|
||||
query_factory=get_tools,
|
||||
get_label='name',
|
||||
allow_blank=True,
|
||||
description='Select one or more tools that can be used this agent'
|
||||
)
|
||||
|
||||
def __init__(self, *args, type_config=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if type_config:
|
||||
self.type.choices = [(key, value['name']) for key, value in type_config.items()]
|
||||
|
||||
|
||||
class EditEveAIAgentForm(BaseEditComponentForm):
|
||||
role = StringField('Role', validators=[DataRequired()])
|
||||
goal = StringField('Goal', validators=[DataRequired()])
|
||||
backstory = StringField('Backstory', validators=[DataRequired()])
|
||||
|
||||
tools = QuerySelectMultipleField(
|
||||
'Tools',
|
||||
query_factory=get_tools,
|
||||
get_label='name',
|
||||
allow_blank=True,
|
||||
description='Select one or more tools that can be used this agent'
|
||||
)
|
||||
role = TextAreaField('Role', validators=[Optional()])
|
||||
goal = TextAreaField('Goal', validators=[Optional()])
|
||||
backstory = TextAreaField('Backstory', validators=[Optional()])
|
||||
|
||||
|
||||
class EveAITaskForm(BaseComponentForm):
|
||||
expected_output = TextAreaField('Expected Output', validators=[DataRequired()])
|
||||
class EditEveAITaskForm(BaseEditComponentForm):
|
||||
task_description = StringField('Task Description', validators=[Optional()])
|
||||
expected_outcome = StringField('Expected Outcome', validators=[Optional()])
|
||||
|
||||
|
||||
class EditEveAIToolForm(BaseEditComponentForm):
|
||||
pass
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import ast
|
||||
from datetime import datetime as dt, timezone as tz
|
||||
|
||||
from flask import request, redirect, flash, render_template, Blueprint, session, current_app
|
||||
from flask import request, redirect, flash, render_template, Blueprint, session, current_app, jsonify, url_for
|
||||
from flask_security import roles_accepted
|
||||
from langchain.agents import Agent
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from common.models.document import Embedding, DocumentVersion, Retriever
|
||||
from common.models.interaction import (ChatSession, Interaction, InteractionEmbedding, Specialist, SpecialistRetriever)
|
||||
from common.models.interaction import (ChatSession, Interaction, InteractionEmbedding, Specialist, SpecialistRetriever,
|
||||
EveAIAgent, EveAITask, EveAITool)
|
||||
|
||||
from common.extensions import db, cache_manager
|
||||
from common.utils.model_logging_utils import set_logging_information, update_logging_information
|
||||
@@ -19,7 +21,8 @@ from common.utils.specialist_utils import initialize_specialist
|
||||
|
||||
from config.type_defs.specialist_types import SPECIALIST_TYPES
|
||||
|
||||
from .interaction_forms import (SpecialistForm, EditSpecialistForm)
|
||||
from .interaction_forms import (SpecialistForm, EditSpecialistForm, EditEveAIAgentForm, EditEveAITaskForm,
|
||||
EditEveAIToolForm)
|
||||
|
||||
interaction_bp = Blueprint('interaction_bp', __name__, url_prefix='/interaction')
|
||||
|
||||
@@ -140,7 +143,7 @@ def specialist():
|
||||
new_specialist.name = form.name.data
|
||||
new_specialist.description = form.description.data
|
||||
new_specialist.type = form.type.data
|
||||
new_specialist.type_version = cache_manager.specialist_config_cache.get_latest_version(new_specialist.type)
|
||||
new_specialist.type_version = cache_manager.specialists_version_tree_cache.get_latest_version(new_specialist.type)
|
||||
new_specialist.tuning = form.tuning.data
|
||||
|
||||
set_logging_information(new_specialist, dt.now(tz.utc))
|
||||
@@ -182,16 +185,29 @@ def edit_specialist(specialist_id):
|
||||
specialist = Specialist.query.get_or_404(specialist_id)
|
||||
form = EditSpecialistForm(request.form, obj=specialist)
|
||||
|
||||
specialist_config = cache_manager.specialist_config_cache.get_config(specialist.type, specialist.type_version)
|
||||
specialist_config = cache_manager.specialists_config_cache.get_config(specialist.type, specialist.type_version)
|
||||
configuration_config = specialist_config.get('configuration')
|
||||
form.add_dynamic_fields("configuration", configuration_config, specialist.configuration)
|
||||
|
||||
agent_rows = prepare_table_for_macro(specialist.agents,
|
||||
[('id', ''), ('name', ''), ('type', ''), ('type_version', '')])
|
||||
task_rows = prepare_table_for_macro(specialist.tasks,
|
||||
[('id', ''), ('name', ''), ('type', ''), ('type_version', '')])
|
||||
tool_rows = prepare_table_for_macro(specialist.tools,
|
||||
[('id', ''), ('name', ''), ('type', ''), ('type_version', '')])
|
||||
|
||||
# Construct the SVG overview path
|
||||
svg_filename = f"{specialist.type}_{specialist.type_version}_overview.svg"
|
||||
svg_path = url_for('static', filename=f'assets/specialists/{svg_filename}')
|
||||
|
||||
if request.method == 'GET':
|
||||
# Get the actual Retriever objects for the associated retriever_ids
|
||||
retriever_objects = Retriever.query.filter(
|
||||
Retriever.id.in_([sr.retriever_id for sr in specialist.retrievers])
|
||||
).all()
|
||||
form.retrievers.data = retriever_objects
|
||||
if specialist.description is None:
|
||||
specialist.description = specialist_config.get('metadata').get('description', '')
|
||||
|
||||
if form.validate_on_submit():
|
||||
# Update the basic fields
|
||||
@@ -230,11 +246,25 @@ 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)}')
|
||||
return render_template('interaction/edit_specialist.html', form=form, specialist_id=specialist_id)
|
||||
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,
|
||||
prefixed_url_for=prefixed_url_for,
|
||||
svg_path=svg_path,)
|
||||
else:
|
||||
form_validation_failed(request, form)
|
||||
|
||||
return render_template('interaction/edit_specialist.html', form=form, specialist_id=specialist_id)
|
||||
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,
|
||||
prefixed_url_for=prefixed_url_for,
|
||||
svg_path=svg_path,)
|
||||
|
||||
|
||||
@interaction_bp.route('/specialists', methods=['GET', 'POST'])
|
||||
@@ -268,3 +298,154 @@ def handle_specialist_selection():
|
||||
|
||||
return redirect(prefixed_url_for('interaction_bp.specialists'))
|
||||
|
||||
|
||||
# Routes for Agent management
|
||||
@interaction_bp.route('/agent/<int:agent_id>/edit', methods=['GET'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def edit_agent(agent_id):
|
||||
agent = EveAIAgent.query.get_or_404(agent_id)
|
||||
form = EditEveAIAgentForm(obj=agent)
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
# 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")
|
||||
|
||||
|
||||
@interaction_bp.route('/agent/<int:agent_id>/save', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def 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)
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
form.populate_obj(agent)
|
||||
update_logging_information(agent, dt.now(tz.utc))
|
||||
if not agent_id: # New agent
|
||||
db.session.add(agent)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True, 'message': 'Agent saved successfully'})
|
||||
except Exception as e:
|
||||
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'})
|
||||
|
||||
|
||||
# Routes for Task management
|
||||
@interaction_bp.route('/task/<int:task_id>/edit', methods=['GET'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def edit_task(task_id):
|
||||
task = EveAITask.query.get_or_404(task_id)
|
||||
form = EditEveAITaskForm(obj=task)
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
return render_template('interaction/components/edit_task.html',
|
||||
form=form,
|
||||
task=task)
|
||||
|
||||
|
||||
@interaction_bp.route('/task/<int:task_id>/save', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
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
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
form.populate_obj(task)
|
||||
update_logging_information(task, dt.now(tz.utc))
|
||||
if not task_id: # New task
|
||||
db.session.add(task)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True, 'message': 'Task saved successfully'})
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
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'})
|
||||
|
||||
|
||||
# Routes for Tool management
|
||||
@interaction_bp.route('/tool/<int:tool_id>/edit', methods=['GET'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def edit_tool(tool_id):
|
||||
tool = EveAITool.query.get_or_404(tool_id)
|
||||
form = EditEveAIToolForm(obj=tool)
|
||||
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
|
||||
return render_template('interaction/components/edit_tool.html',
|
||||
form=form,
|
||||
tool=tool)
|
||||
|
||||
|
||||
@interaction_bp.route('/tool/<int:tool_id>/save', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
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
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
form.populate_obj(tool)
|
||||
update_logging_information(tool, dt.now(tz.utc))
|
||||
if not tool_id: # New tool
|
||||
db.session.add(tool)
|
||||
db.session.commit()
|
||||
return jsonify({'success': True, 'message': 'Tool saved successfully'})
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
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'})
|
||||
|
||||
|
||||
# Component selection handlers
|
||||
@interaction_bp.route('/handle_agent_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def handle_agent_selection():
|
||||
agent_identification = request.form['selected_row']
|
||||
agent_id = ast.literal_eval(agent_identification).get('value')
|
||||
action = request.form.get('action')
|
||||
|
||||
if action == "edit_agent":
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_agent', agent_id=agent_id))
|
||||
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_specialist'))
|
||||
|
||||
|
||||
@interaction_bp.route('/handle_task_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def handle_task_selection():
|
||||
task_identification = request.form['selected_row']
|
||||
task_id = ast.literal_eval(task_identification).get('value')
|
||||
action = request.form.get('action')
|
||||
|
||||
if action == "edit_task":
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_task', task_id=task_id))
|
||||
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_specialist'))
|
||||
|
||||
|
||||
@interaction_bp.route('/handle_tool_selection', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def handle_tool_selection():
|
||||
tool_identification = request.form['selected_row']
|
||||
tool_id = ast.literal_eval(tool_identification).get('value')
|
||||
action = request.form.get('action')
|
||||
|
||||
if action == "edit_tool":
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_tool', tool_id=tool_id))
|
||||
|
||||
return redirect(prefixed_url_for('interaction_bp.edit_specialist'))
|
||||
Reference in New Issue
Block a user