Skip to content

Commit b9bc7d6

Browse files
authored
Merge pull request #37 from hchen2020/main
remove node in task-flow
2 parents 870443e + 99949a9 commit b9bc7d6

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

src/lib/drawflow/drawflow.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
color: white;
1616
}
1717

18+
.drawflow .parent-node .task-node {
19+
width: 300px;
20+
}
21+
1822
.drawflow-delete {
1923
background-color: var(--bs-danger);
2024
line-height: 25px;

src/routes/page/agent/[agentId]/task/task-flow.svelte

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import { newConversation } from '$lib/services/conversation-service';
88
import { conversationStore } from '$lib/helpers/store.js';
99
import { sendMessageToHub } from '$lib/services/conversation-service.js';
10+
import 'overlayscrollbars/overlayscrollbars.css';
11+
import { OverlayScrollbars } from 'overlayscrollbars';
1012
1113
/** @type {import('$types').AgentModel} */
1214
export let agent;
@@ -42,19 +44,35 @@
4244
});
4345
renderTaskFlow(editor);
4446
}
47+
48+
const options = {
49+
scrollbars: {
50+
visibility: 'auto',
51+
autoHide: 'move',
52+
autoHideDelay: 100,
53+
dragScroll: true,
54+
clickScroll: false,
55+
theme: 'os-theme-dark',
56+
pointers: ['mouse', 'touch', 'pen']
57+
}
58+
};
59+
const scrollElements = document.querySelectorAll('.scrollbar');
60+
scrollElements.forEach((item) => {
61+
OverlayScrollbars(item, options);
62+
});
4563
});
4664
4765
/** @param {Drawflow} editor */
4866
function renderTaskFlow(editor){
4967
let posX = 0;
50-
const nodeSpaceX = 300, nodeSpaceY = 120;
68+
const nodeSpaceX = 250, nodeSpaceY = 150;
5169
5270
const templates = agent.templates.filter(t => t.name.startsWith("task."));
5371
let posY = nodeSpaceY * (templates.length + 1) / 2;
5472
5573
// add agent node
5674
let agentNodeHtml = agent.icon_url ? `<img src=${agent.icon_url} height="30" />` : "";
57-
agentNodeHtml += `<span class="h6 ms-2">${agent.name}</span>`;
75+
agentNodeHtml += `<span class="h5 ms-2">${agent.name}</span>`;
5876
let agentNodeId = editor.addNode('agent', 0, 1, posX, posY, 'agent',
5977
{
6078
is_agent: true,
@@ -67,18 +85,19 @@
6785
// render tasks
6886
templates.forEach(template => {
6987
const actionLink = `page/agent/${agent.id}/task/${template.name}`;
70-
let html = `<span class="h6">${template.name}</span>`;
71-
html += `<hr/><div style="max-height: 50px; overflow: hidden;">${replaceNewLine(template.content)}</div>`;
88+
let html = `<span class="h5">${template.name}</span>`;
89+
html += `<hr/><div class="scrollbar" style="max-height: 150px;"><i class="bx bx-script"></i>${replaceNewLine(template.content)}</div>`;
7290
7391
const data = {
7492
agent: agent.name,
7593
task: template.name,
7694
content: template.content
7795
};
78-
let nid = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false);
96+
let nid = editor.addNode('agent', 1, 0, posX, posY, 'task-node', data, html, false);
7997
editor.addConnection(agentNodeId, nid, "output_1", "input_1");
8098
8199
posY += nodeSpaceY;
100+
posX += 50;
82101
});
83102
84103
lastPosX = posX + nodeSpaceX;
@@ -94,20 +113,38 @@
94113
window.location.href = `chat/${agent.id}`;
95114
}
96115
116+
/** @type {string} */
117+
let cid;
118+
/** @type {string} */
119+
let mid;
97120
async function handleRunTask() {
121+
// clean added nodes
122+
if (mid) {
123+
editor.removeNodeId(`node-${mid}`);
124+
}
125+
126+
if (cid) {
127+
editor.removeNodeId(`node-${cid}`);
128+
editor.removeNodeOutput(selectedNode.id, "output_1");
129+
}
130+
98131
// new conversation
99132
const conversation = await newConversation(agent.id);
100133
conversationStore.set(conversation);
101134
102135
// draw conversation node
103-
let posX = lastPosX, posY = 100;
104-
const html = "New task conversation";
136+
let posX = lastPosX + 100, posY = 100;
137+
let html = "Initialize session";
105138
editor.addNodeOutput(selectedNode.id);
106-
let cid = editor.addNode('conversation', 1, 0, posX, posY, 'conversation', {}, html, false);
139+
cid = editor.addNode('conversation', 1, 1, posX, posY, 'conversation', {}, html, false);
107140
editor.addConnection(selectedNode.id, cid, "output_1", "input_1");
108-
141+
109142
// send message
143+
posY += 100;
144+
html = "Execute task";
110145
await sendMessageToHub(agent.id, conversation.id, selectedNode.data.content);
146+
mid = editor.addNode('message', 1, 0, posX, posY, 'message', {}, html, false);
147+
editor.addConnection(cid, mid, "output_1", "input_1");
111148
}
112149
</script>
113150

src/routes/page/plugin/plugin-list.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
}
2525
2626
// refresh page
27-
// const path = window.location.pathname;
28-
// goto('/').then(() => goto(path));
27+
const path = window.location.pathname;
28+
goto('/').then(() => goto(path));
2929
}
3030
</script>
3131

@@ -62,12 +62,12 @@
6262
<span class="badge rounded-1 badge-soft-info">Public</span>
6363
</div>
6464
<div class="mt-2 hstack pt-2 gap-2 border-top">
65-
<a href="#" class="btn btn-soft-success btn-sm">View</a>
65+
<button class="btn btn-soft-success btn-sm">View</button>
6666
{#if item.settings_name}
6767
<a href="page/setting#{item.settings_name}" class="btn btn-soft-success btn-sm">Settings</a>
6868
{/if}
6969
{#if !item.is_core}
70-
<a href="#" class="btn btn-soft-warning btn-sm" on:click={() => handlePluginStatus(item.id, !item.enabled)}>{item.enabled ? "Remove" : "Install"}</a>
70+
<button class="btn btn-soft-warning btn-sm" on:click={() => handlePluginStatus(item.id, !item.enabled)}>{item.enabled ? "Remove" : "Install"}</button>
7171
{/if}
7272
</div>
7373
</CardBody>

0 commit comments

Comments
 (0)