Skip to content

Commit 659dcbc

Browse files
authored
Merge pull request #35 from hchen2020/main
improve task-flow.
2 parents 0b564fc + 194eec3 commit 659dcbc

File tree

6 files changed

+73
-34
lines changed

6 files changed

+73
-34
lines changed

src/lib/services/api-endpoints.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const endpoints = {
1414
// plugin
1515
pluginListUrl: `${host}/plugins`,
1616
pluginMenuUrl: `${host}/plugin/menu`,
17-
pluginEnableUrl: `${host}/plugin/{id}/enable`,
18-
pluginDisableUrl: `${host}/plugin/{id}/disable`,
17+
pluginInstallUrl: `${host}/plugin/{id}/install`,
18+
pluginRemoveUrl: `${host}/plugin/{id}/remove`,
1919

2020
// agent
2121
agentSettingUrl: `${host}/agent/settings`,

src/lib/services/instruct-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import axios from 'axios';
88
* @param {import('$types').InstructMessageModel} instruction
99
*/
1010
export async function executeAgentInstruction(agentId, instruction) {
11-
let url = replaceUrl(endpoints.conversationInitUrl, {agentId: agentId});
11+
let url = replaceUrl(endpoints.instructCompletionUrl, {agentId: agentId});
1212
await axios.post(url, instruction);
1313
}

src/lib/services/plugin-service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export async function getPluginMenu() {
3232
* @param {string} id
3333
* @returns {Promise<import('$types').PluginDefModel>}
3434
*/
35-
export async function enablePlugin(id) {
36-
let url = replaceUrl(endpoints.pluginEnableUrl, {id: id});
35+
export async function installPlugin(id) {
36+
let url = replaceUrl(endpoints.pluginInstallUrl, {id: id});
3737
const response = await axios.post(url);
3838
return response.data;
3939
}
@@ -43,8 +43,8 @@ export async function enablePlugin(id) {
4343
* @param {string} id
4444
* @returns {Promise<import('$types').PluginDefModel>}
4545
*/
46-
export async function disablePlugin(id) {
47-
let url = replaceUrl(endpoints.pluginDisableUrl, {id: id});
46+
export async function removePlugin(id) {
47+
let url = replaceUrl(endpoints.pluginRemoveUrl, {id: id});
4848
const response = await axios.post(url);
4949
return response.data;
5050
}

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

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import 'drawflow/dist/drawflow.min.css';
44
import '$lib/drawflow/drawflow.css';
55
import { onMount, createEventDispatcher } from 'svelte';
6-
6+
import { replaceNewLine } from '$lib/helpers/http';
7+
import { newConversation } from '$lib/services/conversation-service';
8+
import { conversationStore, getConversationStore } from '$lib/helpers/store.js';
9+
710
/** @type {import('$types').AgentModel} */
811
export let agent;
912
/** @type {import('$types').AgentTemplate[]} */
1013
let taskNodes = [];
14+
/** @type {DrawflowNode} */
15+
let selectedNode;
1116
1217
const dispatch = createEventDispatcher();
1318
@@ -27,6 +32,7 @@
2732
editor.on('nodeSelected', function(id) {
2833
console.log("Node selected " + id);
2934
// emit event
35+
selectedNode = editor.getNodeFromId(id);
3036
});
3137
renderTaskFlow(editor);
3238
}
@@ -37,23 +43,30 @@
3743
let posX = 0;
3844
const nodeSpaceX = 300, nodeSpaceY = 120;
3945
40-
let posY = nodeSpaceY * (agent.templates.length + 1) / 2;
46+
const templates = agent.templates.filter(t => t.name.startsWith("task."));
47+
let posY = nodeSpaceY * (templates.length + 1) / 2;
4148
42-
// add end-user node
49+
// add agent node
50+
let agentNodeHtml = agent.icon_url ? `<img src=${agent.icon_url} height="30" />` : "";
51+
agentNodeHtml += `<span class="h6 ms-2">${agent.name}</span>`;
4352
let agentNodeId = editor.addNode('agent', 0, 1, posX, posY, 'agent',
4453
{
45-
id: ""
46-
}, `<img src=${agent.icon_url} height="30" /><span class="h6">${agent.name}</span>`, false);
54+
is_agent: true,
55+
agent: agent.name
56+
}, agentNodeHtml, false);
4757
4858
posY = 100;
4959
posX += nodeSpaceX;
50-
agent.templates.forEach(template => {
51-
const chatTestLinkHtml = `<a href= "/page/agent/${agent.id}/task/${template.name}" class="btn btn-primary float-end" target="_blank"><i class="bx bx-run"></i></a>`;
52-
let html = `<span class="h6">${template.name}</span>${chatTestLinkHtml}`;
60+
61+
// render tasks
62+
templates.forEach(template => {
63+
const actionLink = `/page/agent/${agent.id}/task/${template.name}`;
64+
let html = `<span class="h6">${template.name}</span>`;
65+
html += `<hr/><div style="max-height: 50px; overflow: hidden;">${replaceNewLine(template.content)}</div>`;
5366
5467
const data = {
55-
id: agent.id,
56-
agent: agent.name
68+
agent: agent.name,
69+
task: template.name,
5770
};
5871
let nid = editor.addNode('agent', 1, 0, posX, posY, 'enabled-node', data, html, false);
5972
editor.addConnection(agentNodeId, nid, "output_1", "input_1");
@@ -62,12 +75,33 @@
6275
});
6376
}
6477
65-
/** @param {import('$types').AgentModel} router */
66-
function getPlannerName(router) {
67-
const planner = router.routing_rules.find(p => p.type == "planner");
78+
/** @param {import('$types').AgentModel} agent */
79+
function getPlannerName(agent) {
80+
const planner = agent.routing_rules.find(p => p.type == "planner");
6881
return planner?.field ?? "NaviePlanner";
6982
}
83+
84+
async function handleTestInChat() {
85+
window.location.href = `/chat/${agent.id}`;
86+
}
87+
88+
async function handleRunTask() {
89+
const conversation = await newConversation(agent.id);
90+
conversationStore.set(conversation);
91+
}
7092
</script>
7193
94+
<div>
95+
{#if selectedNode && selectedNode.data.is_agent}
96+
<button class="btn btn-primary" on:click={handleTestInChat}><i class="bx bx-chat"></i> Test in chat</button>
97+
{/if}
98+
<button class="btn btn-primary" on:click={handleRunTask}><i class="bx bx-run"></i> Run:
99+
{#if selectedNode && selectedNode.data.task}
100+
{selectedNode.data.task}
101+
{:else}
102+
select a task to run
103+
{/if}
104+
</button>
105+
</div>
72106
<div id="drawflow" style="height: 75vh; width: 100%">
73107
</div>

src/routes/page/agent/router/routing-flow.svelte

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@
8787
let nodeId = editor.addNode('router', 1, 1, posX, routerPosY, 'router', data, `${html}`, false);;
8888
// connect user and router
8989
editor.addConnection(userNodeId, nodeId, `output_1`, `input_1`);
90-
routerPosY += nodeSpaceY * (agents.length - 1) / 2;
90+
routerPosY += nodeSpaceY + 50;
9191
});
9292
9393
posY = 100;
9494
posX += nodeSpaceX;
9595
agents.forEach(agent => {
9696
let profiles = [];
9797
const chatTestLinkHtml = `<a href= "/chat/${agent.id}" class="btn btn-primary float-end" target="_blank"><i class="bx bx-chat"></i></a>`;
98-
const taskLinkHtml = `<a href= "/page/agent/${agent.id}/task" class="btn btn-primary float-end" target="_blank"><i class="bx bx-task"></i></a>`;
99-
let html = `<span class="h6">${agent.name}</span>${chatTestLinkHtml}${taskLinkHtml}`;
98+
let html = `<span class="h6">${agent.name}</span>${chatTestLinkHtml}`;
99+
if (agent.type == "static") {
100+
const taskLinkHtml = `<a href= "/page/agent/${agent.id}/task" class="btn btn-primary float-end" target="_blank"><i class="bx bx-task"></i></a>`;
101+
html += taskLinkHtml;
102+
}
100103
if (agent.profiles.length > 0) {
101104
profiles = agent.profiles;
102105
html += `<br/><i class="mdi mdi-folder font-size-16 text-info me-2"></i>` + profiles.join(', ');
@@ -144,15 +147,17 @@
144147
// fallback
145148
const fallback = agent.routing_rules.find(p => p.type == "fallback");
146149
if (fallback) {
147-
let router = agentNodes.find(ag => ag.id == fallback.redirectTo);
148150
editor.addNodeOutput(nid);
149-
editor.addNodeInput(router.nid);
150-
var inputs = editor.getNodeFromId(router.nid).inputs;
151-
let inputId = 0;
152-
for (let prop in inputs) {
153-
inputId++;
151+
let router = agentNodes.find(ag => ag.id == fallback.redirectTo);
152+
if (router) {
153+
editor.addNodeInput(router.nid);
154+
var inputs = editor.getNodeFromId(router.nid).inputs;
155+
let inputId = 0;
156+
for (let prop in inputs) {
157+
inputId++;
158+
}
159+
editor.addConnection(nid, router.nid, `output_1`, `input_${inputId}`);
154160
}
155-
editor.addConnection(nid, router.nid, `output_1`, `input_${inputId}`);
156161
}
157162
});
158163
}
@@ -164,5 +169,5 @@
164169
}
165170
</script>
166171
167-
<div id="drawflow" style="height: 75vh; width: 100%">
172+
<div id="drawflow" style="height: 80vh; width: 100%">
168173
</div>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Col,
77
Row,
88
} from '@sveltestrap/sveltestrap';
9-
import { enablePlugin, disablePlugin } from '$lib/services/plugin-service';
9+
import { installPlugin, removePlugin } from '$lib/services/plugin-service';
1010
import { goto } from '$app/navigation';
1111
1212
/** @type {import('$types').PluginDefModel[]} */
@@ -18,9 +18,9 @@
1818
*/
1919
async function handlePluginStatus(id, enable) {
2020
if (enable) {
21-
await enablePlugin(id);
21+
await installPlugin(id);
2222
} else {
23-
await disablePlugin(id);
23+
await removePlugin(id);
2424
}
2525
2626
const path = window.location.pathname;

0 commit comments

Comments
 (0)