Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add step mode for each examples in workstation #284

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/agentscope/studio/static/css/workstation.css
Original file line number Diff line number Diff line change
Expand Up @@ -839,4 +839,35 @@ pre[class*="language-"] {
font-size: 16px;
line-height: 1.2;
resize: vertical;
}

.new-action {
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
cursor: pointer;
padding: 8px;
margin-left: auto;
border: none;
border-radius: 20px;
background-color: #007bff;
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
color: white;
transition: all 0.3s ease;
font-size: 14px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
max-width: 30px;
overflow: hidden;
white-space: nowrap;
display: flex;
justify-content: center;
align-items: center;
}

.new-action:hover, .new-action:focus {
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
width: auto;
padding: 8px 16px;
background-color: #0056b3;
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.new-action:active {
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
background-color: #00488a;
DavdGao marked this conversation as resolved.
Show resolved Hide resolved
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
32 changes: 18 additions & 14 deletions src/agentscope/studio/static/js/workstation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@ function importExample(index) {
editor.import(dataToImport);
Object.keys(dataToImport.drawflow.Home.data).forEach((nodeId) => {
setupNodeListeners(nodeId);
setupTextInputListeners(nodeId);
const nodeElement = document.getElementById(`node-${nodeId}`);
if (nodeElement) {
const copyButton = nodeElement.querySelector('.button.copy-button');
Expand All @@ -1879,11 +1880,13 @@ function importExample(index) {
function importExample_step(index) {
fetchExample(index, data => {
const dataToImportStep = data.json;
clearModuleSelected();
descriptionStep = ["Readme", "Model", "UserAgent",
"DialogAgent"];
initializeImport(dataToImportStep);
})
addHtmlAndReplacePlaceHolderBeforeImport(dataToImportStep).then(() => {
clearModuleSelected();
descriptionStep = ["Readme", "Model", "UserAgent",
"DialogAgent"];
initializeImport(dataToImportStep);
})
});
}


Expand All @@ -1907,13 +1910,13 @@ function createElement(tag, id, html = '', parent = document.body) {


function initializeImport(data) {
['buttons-container', 'buttons-container-html'].forEach(cls => {
['menu-btn', 'menu-btn-svg'].forEach(cls => {
let containers = document.getElementsByClassName(cls);
Array.from(containers).forEach(container => container.style.display = 'none');
});

createElement('div', 'left-sidebar-blur', '', document.body).style.cssText = `
position: fixed; top: 67px; left: 0; bottom: 0; width: 250px;
position: fixed; top: 60px; left: 0; bottom: 0; width: 250px;
background: rgba(128, 128, 128, 0.7);
filter: blur(2px); z-index: 1000; cursor: not-allowed;
`;
Expand All @@ -1926,19 +1929,19 @@ function initializeImport(data) {
const importButtonsDiv = document.getElementById('import-buttons');
createElement('div', 'step-info', '', importButtonsDiv);
createElement('button', 'import-prev',
'<i class="fas fa-arrow-left"></i> <span>{{_("Previous")}}</span>',
'<i class="fas fa-arrow-left"></i> <span>Previous</span>',
importButtonsDiv).onclick = importPreviousComponent;
createElement('button', 'import-next',
'<i class="fas fa-arrow-right"></i> <span>{{_("Next")}}</span>',
'<i class="fas fa-arrow-right"></i> <span>Next</span>',
importButtonsDiv).onclick = importNextComponent;
createElement('button', 'import-skip',
'<i class="fas fa-forward"></i> <span>{{_("Skip")}}</span>',
'<i class="fas fa-forward"></i> <span>Skip</span>',
importButtonsDiv).onclick = importSkipComponent;
createElement('button', 'import-quit',
'<i class="fas fa-sign-out-alt"></i> <span>{{_("Quit")}}</span>',
'<i class="fas fa-sign-out-alt"></i> <span>Quit</span>',
importButtonsDiv).onclick = importQuitComponent;
createElement('div', 'step-warning',
'{{_("Caution: You are currently in the tutorial mode where modifications are restricted.<br>Please click <strong>Quit</strong> to exit and start creating your custom multi-agent applications.")}}', document.body);
'Caution: You are currently in the tutorial mode where modifications are restricted.<br>Please click <strong>Quit</strong> to exit and start creating your custom multi-agent applications.', document.body);

accumulatedImportData = {};
currentImportIndex = 0;
Expand All @@ -1962,6 +1965,7 @@ function importPreviousComponent() {
function importNextComponent() {
const nodeId = importQueue[currentImportIndex];
accumulatedImportData[nodeId] = dataToImportStep.drawflow.Home.data[nodeId];

editor.import({drawflow: {Home: {data: accumulatedImportData}}});
currentImportIndex++;
updateStepInfo();
Expand All @@ -1980,7 +1984,7 @@ function importSkipComponent() {

function importQuitComponent() {
clearModuleSelected();
['buttons-container', 'buttons-container-html'].forEach(cls => {
['menu-btn', 'menu-btn-svg'].forEach(cls => {
let containers = document.getElementsByClassName(cls);
Array.from(containers).forEach(container => container.style.display = '');
});
Expand All @@ -1991,7 +1995,7 @@ function updateStepInfo() {
let stepInfoDiv = document.getElementById('step-info');
if (stepInfoDiv && currentImportIndex > 0) {
stepInfoDiv.innerHTML =
`{{_("Current Step")}} (${currentImportIndex}/${importQueue.length}) <br> ${descriptionStep[currentImportIndex - 1]}`;
`Current Step (${currentImportIndex}/${importQueue.length}) <br> ${descriptionStep[currentImportIndex - 1]}`;
} else if (stepInfoDiv) {
stepInfoDiv.innerHTML = 'No steps to display.';
}
Expand Down
20 changes: 20 additions & 0 deletions src/agentscope/studio/templates/workstation.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,35 @@
<ul>
<li class="workstation-sidebar-subitem unselectable-text"
onclick="importExample(1);">Two Agents
<div class="new-action"
onclick="event.stopPropagation();
importExample_step(1)">
<i class="fas fa-book-open"></i>
</div>
</li>
<li class="workstation-sidebar-subitem unselectable-text"
onclick="importExample(2);">Pipeline
<div class="new-action"
onclick="event.stopPropagation();
importExample_step(2)">
<i class="fas fa-book-open"></i>
</div>
</li>
<li class="workstation-sidebar-subitem unselectable-text"
onclick="importExample(3);">Conversation
<div class="new-action"
onclick="event.stopPropagation();
importExample_step(3)">
<i class="fas fa-book-open"></i>
</div>
</li>
<li class="workstation-sidebar-subitem unselectable-text"
onclick="importExample(4);">Group Chat
<div class="new-action"
onclick="event.stopPropagation();
importExample_step(4)">
<i class="fas fa-book-open"></i>
</div>
</li>
</ul>
</li>
Expand Down