| 
29 | 29 |     let mid;      | 
30 | 30 |     let lastPosX = 120;  | 
31 | 31 |     let lastPosY = 0;  | 
32 |  | -    const nodeSpaceX = 30, nodeSpaceY = 50;  | 
 | 32 | +    const nodeSpaceX = 50, nodeSpaceY = 50;  | 
 | 33 | +    let messageCount = 0;  | 
33 | 34 | 
  | 
34 | 35 |     const options = {  | 
35 | 36 | 		scrollbars: {  | 
 | 
86 | 87 | 		scrollElements.forEach((item) => {  | 
87 | 88 | 			const scrollbar = OverlayScrollbars(item, options);  | 
88 | 89 | 		});  | 
 | 90 | +
  | 
 | 91 | +        messageCount = 0;  | 
 | 92 | +        editor.zoom_reset();  | 
89 | 93 |     }  | 
90 | 94 | 
  | 
91 | 95 |     /** @param {import('$types').ConversationModel} conversation */  | 
92 | 96 |     function renderConversationNode(conversation) {  | 
93 |  | -        let posX = lastPosX + 250, posY = lastPosX + 20;  | 
94 |  | -        let html = "Initialize session";  | 
 | 97 | +        let posX = lastPosX + 250 + nodeSpaceX, posY = lastPosY;  | 
 | 98 | +        let html = "New conversation";  | 
 | 99 | +        html += `<a href= "chat/${conversation.agent_id}" class="btn btn-primary float-end" target="_blank"><i class="bx bx-chat"></i></a>`;  | 
95 | 100 |         editor.addNodeOutput(tid);  | 
96 | 101 |         cid = editor.addNode('conversation', 1, 0, posX, posY, 'conversation', {}, html, false);  | 
97 | 102 |         editor.addConnection(tid, cid, "output_1", "input_1");  | 
 | 
100 | 105 |         mid = cid;  | 
101 | 106 |     }  | 
102 | 107 | 
  | 
103 |  | -    /** @param {string} message */  | 
104 |  | -    function renderMessageNode(message) {  | 
 | 108 | +    /** @param {string} message   | 
 | 109 | +     * @param {import('$types').ChatResponseModel} response  | 
 | 110 | +    */  | 
 | 111 | +    function renderMessageNode(message, response) {  | 
105 | 112 |         let posX = lastPosX + nodeSpaceX, posY = lastPosY + nodeSpaceY;  | 
106 | 113 |         let html = `${message}`;  | 
 | 114 | +        if (response.data) {  | 
 | 115 | +            html += `<img src=${response.data} alt="" width="165px"/>`  | 
 | 116 | +        }  | 
 | 117 | +        html += `<div class="bg-info mt-1 mb-1 p-1 rounded">${response.text}</div>`;  | 
 | 118 | +
  | 
107 | 119 |         editor.addNodeOutput(mid);  | 
108 | 120 |         let new_mid = editor.addNode('message', 1, 0, posX, posY, 'message', {}, html, false);  | 
109 | 121 |         editor.addConnection(mid, new_mid, "output_1", "input_1");  | 
110 | 122 | 
  | 
111 | 123 |         lastPosX = posX;  | 
112 | 124 |         lastPosY = posY;  | 
113 | 125 |         mid = new_mid;  | 
 | 126 | +
  | 
 | 127 | +        messageCount++;  | 
 | 128 | +        if (messageCount % 10 == 0) {  | 
 | 129 | +            // editor.zoom_out();  | 
 | 130 | +            lastPosX = lastPosX + nodeSpaceX;  | 
 | 131 | +            lastPosY = 0;  | 
 | 132 | +        }  | 
114 | 133 |     }  | 
115 | 134 | 
  | 
116 | 135 |     async function handleRunTaskSequentiallyInServer() {  | 
 | 
123 | 142 |         conversationStore.set(conversation);  | 
124 | 143 |         renderConversationNode(conversation);  | 
125 | 144 |           | 
126 |  | -        await sendMessageToHub(task.agent_id, conversation.id, task.content);  | 
127 |  | -        renderMessageNode(task.content);  | 
 | 145 | +        var response = await sendMessageToHub(task.agent_id, conversation.id, task.content);  | 
 | 146 | +        renderMessageNode(task.content, response);  | 
128 | 147 |     }  | 
129 | 148 | 
  | 
130 | 149 |     async function handleRunTaskInteractively() {  | 
 | 
141 | 160 |         let steps = task.content.split('\n');  | 
142 | 161 |         for (let i = 0; i < steps.length; i++) {  | 
143 | 162 |             let step = steps[i];  | 
144 |  | -            const result = await sendMessageToHub(task.direct_agent_id, conversation.id, step, '', ['hide_context=true']);  | 
145 |  | -            if (result.text == "Failed") {  | 
 | 163 | +            const response = await sendMessageToHub(task.direct_agent_id, conversation.id, step, '', ['hide_context=true']);  | 
 | 164 | +            if (response.text.includes("failed")) {  | 
146 | 165 |                 break;  | 
147 | 166 |             }  | 
148 |  | -            renderMessageNode(step);  | 
 | 167 | +            renderMessageNode(step, response);  | 
149 | 168 |         }          | 
150 | 169 |     }  | 
151 | 170 | </script>  | 
152 | 171 | 
 
  | 
153 | 172 | <div>  | 
154 |  | -    <button class="btn btn-primary me-2" on:click={handleRunTaskSequentiallyInServer}><i class="bx bx-run"></i> Execute in {task?.agent_name}</button>  | 
 | 173 | +    <button class="btn btn-primary me-2" on:click={handleRunTaskSequentiallyInServer}><i class="bx bx-run"></i> Execute Sequentially through Router</button>  | 
155 | 174 |     {#if task?.direct_agent_id}  | 
156 | 175 |     <button class="btn btn-primary" on:click={handleRunTaskInteractively}><i class="bx bx-rocket"></i> Execute Interactively</button>  | 
157 | 176 |     {/if}  | 
 | 
0 commit comments