|
7 | 7 | import { newConversation } from '$lib/services/conversation-service'; |
8 | 8 | import { conversationStore } from '$lib/helpers/store.js'; |
9 | 9 | import { sendMessageToHub } from '$lib/services/conversation-service.js'; |
| 10 | + import 'overlayscrollbars/overlayscrollbars.css'; |
| 11 | + import { OverlayScrollbars } from 'overlayscrollbars'; |
10 | 12 |
|
11 | 13 | /** @type {import('$types').AgentModel} */ |
12 | 14 | export let agent; |
|
42 | 44 | }); |
43 | 45 | renderTaskFlow(editor); |
44 | 46 | } |
| 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 | + }); |
45 | 63 | }); |
46 | 64 |
|
47 | 65 | /** @param {Drawflow} editor */ |
48 | 66 | function renderTaskFlow(editor){ |
49 | 67 | let posX = 0; |
50 | | - const nodeSpaceX = 300, nodeSpaceY = 120; |
| 68 | + const nodeSpaceX = 250, nodeSpaceY = 150; |
51 | 69 |
|
52 | 70 | const templates = agent.templates.filter(t => t.name.startsWith("task.")); |
53 | 71 | let posY = nodeSpaceY * (templates.length + 1) / 2; |
54 | 72 |
|
55 | 73 | // add agent node |
56 | 74 | 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>`; |
58 | 76 | let agentNodeId = editor.addNode('agent', 0, 1, posX, posY, 'agent', |
59 | 77 | { |
60 | 78 | is_agent: true, |
|
67 | 85 | // render tasks |
68 | 86 | templates.forEach(template => { |
69 | 87 | 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>`; |
72 | 90 | |
73 | 91 | const data = { |
74 | 92 | agent: agent.name, |
75 | 93 | task: template.name, |
76 | 94 | content: template.content |
77 | 95 | }; |
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); |
79 | 97 | editor.addConnection(agentNodeId, nid, "output_1", "input_1"); |
80 | 98 |
|
81 | 99 | posY += nodeSpaceY; |
| 100 | + posX += 50; |
82 | 101 | }); |
83 | 102 |
|
84 | 103 | lastPosX = posX + nodeSpaceX; |
|
94 | 113 | window.location.href = `chat/${agent.id}`; |
95 | 114 | } |
96 | 115 |
|
| 116 | + /** @type {string} */ |
| 117 | + let cid; |
| 118 | + /** @type {string} */ |
| 119 | + let mid; |
97 | 120 | 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 | +
|
98 | 131 | // new conversation |
99 | 132 | const conversation = await newConversation(agent.id); |
100 | 133 | conversationStore.set(conversation); |
101 | 134 |
|
102 | 135 | // 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"; |
105 | 138 | 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); |
107 | 140 | editor.addConnection(selectedNode.id, cid, "output_1", "input_1"); |
108 | | - |
| 141 | +
|
109 | 142 | // send message |
| 143 | + posY += 100; |
| 144 | + html = "Execute task"; |
110 | 145 | 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"); |
111 | 148 | } |
112 | 149 | </script> |
113 | 150 |
|
|
0 commit comments