Skip to content

Commit 46a96f1

Browse files
authored
Merge pull request #38 from hchen2020/main
Show image in chatbox
2 parents 4fd2239 + 7da916d commit 46a96f1

File tree

8 files changed

+44
-16
lines changed

8 files changed

+44
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ You can preview the production build with `npm run preview`.
5050
To manual deploy as [Azure Static Web Apps](https://learn.microsoft.com/en-us/azure/static-web-apps/) at scale.
5151

5252
```bash
53+
npm run build -- --mode production
5354
npm install -g @azure/static-web-apps-cli
5455
swa deploy ./build/ --env production --deployment-token {token}
5556
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "botsharp-ui",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"private": true,
55
"engines": {
66
"node": ">=18.0.0"

src/lib/drawflow/drawflow.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.drawflow .drawflow-node {
22
background: var(--bs-primary);
33
color: white;
4-
width: 200px;
4+
width: 250px;
55
border: 2px solid var(--bs-primary);
66
}
77

src/lib/helpers/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ IRichContent.prototype.text;
247247
* @property {string} message_id - The message id.
248248
* @property {string} text - The message content.
249249
* @property {RichContent} rich_content - Rich content
250+
* @property {string} data
250251
* @property {Date} created_at - The message sent time.
251252
*/
252253

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@
374374
{/if}
375375
</div>
376376
{/if}
377+
377378
{#if message.sender.id === currentUser.id}
378379
<div class="ctext-wrap float-end">
379380
<!--<div class="conversation-name">{message.sender.full_name}</div>-->
@@ -401,6 +402,12 @@
401402
</div>
402403
</div>
403404
{/if}
405+
406+
{#if message.data && message.data.includes('data:image/png;base64,')}
407+
<div style="width: 80%; display: flex; margin-left: 35px; margin-top: 40px;">
408+
<img src="{message.data}" width="200px" alt="" class="rounded"/>
409+
</div>
410+
{/if}
404411
</div>
405412
</li>
406413
{/each}

src/routes/page/task/[taskId]/execution-flow.svelte

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
let mid;
3030
let lastPosX = 120;
3131
let lastPosY = 0;
32-
const nodeSpaceX = 30, nodeSpaceY = 50;
32+
const nodeSpaceX = 50, nodeSpaceY = 50;
33+
let messageCount = 0;
3334
3435
const options = {
3536
scrollbars: {
@@ -86,12 +87,16 @@
8687
scrollElements.forEach((item) => {
8788
const scrollbar = OverlayScrollbars(item, options);
8889
});
90+
91+
messageCount = 0;
92+
editor.zoom_reset();
8993
}
9094
9195
/** @param {import('$types').ConversationModel} conversation */
9296
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>`;
95100
editor.addNodeOutput(tid);
96101
cid = editor.addNode('conversation', 1, 0, posX, posY, 'conversation', {}, html, false);
97102
editor.addConnection(tid, cid, "output_1", "input_1");
@@ -100,17 +105,31 @@
100105
mid = cid;
101106
}
102107
103-
/** @param {string} message */
104-
function renderMessageNode(message) {
108+
/** @param {string} message
109+
* @param {import('$types').ChatResponseModel} response
110+
*/
111+
function renderMessageNode(message, response) {
105112
let posX = lastPosX + nodeSpaceX, posY = lastPosY + nodeSpaceY;
106113
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+
107119
editor.addNodeOutput(mid);
108120
let new_mid = editor.addNode('message', 1, 0, posX, posY, 'message', {}, html, false);
109121
editor.addConnection(mid, new_mid, "output_1", "input_1");
110122
111123
lastPosX = posX;
112124
lastPosY = posY;
113125
mid = new_mid;
126+
127+
messageCount++;
128+
if (messageCount % 10 == 0) {
129+
// editor.zoom_out();
130+
lastPosX = lastPosX + nodeSpaceX;
131+
lastPosY = 0;
132+
}
114133
}
115134
116135
async function handleRunTaskSequentiallyInServer() {
@@ -123,8 +142,8 @@
123142
conversationStore.set(conversation);
124143
renderConversationNode(conversation);
125144
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);
128147
}
129148
130149
async function handleRunTaskInteractively() {
@@ -141,17 +160,17 @@
141160
let steps = task.content.split('\n');
142161
for (let i = 0; i < steps.length; i++) {
143162
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")) {
146165
break;
147166
}
148-
renderMessageNode(step);
167+
renderMessageNode(step, response);
149168
}
150169
}
151170
</script>
152171

153172
<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>
155174
{#if task?.direct_agent_id}
156175
<button class="btn btn-primary" on:click={handleRunTaskInteractively}><i class="bx bx-rocket"></i> Execute Interactively</button>
157176
{/if}

svelte.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const config = {
6060
},
6161

6262
onwarn: (warning, handler) => {
63-
if (warning.code.startsWith('a11y-')) {
63+
if (warning.code.includes('a11y-')) {
6464
return;
6565
}
6666
handler(warning);

0 commit comments

Comments
 (0)