|
| 1 | +<script> |
| 2 | + import { Card, CardBody, CardTitle, Col, Row } from '@sveltestrap/sveltestrap'; |
| 3 | + import { _ } from 'svelte-i18n'; |
| 4 | + import { onMount } from 'svelte'; |
| 5 | + import ChatTextArea from '../../chat/[agentId]/[conversationId]/chat-util/chat-text-area.svelte'; |
| 6 | + import { getConversation, updateDashboardConversation, unpinConversationFromDashboard } from '$lib/services/conversation-service'; |
| 7 | +
|
| 8 | + /** @type {string}*/ |
| 9 | + export let conversationId; |
| 10 | + /** @type {string}*/ |
| 11 | + export let instruction; |
| 12 | + /** @type {string}*/ |
| 13 | + export let userId; |
| 14 | +
|
| 15 | + /** @type {import('$conversationTypes').ConversationModel}*/ |
| 16 | + let conversationModel; |
| 17 | +
|
| 18 | + let agent = { |
| 19 | + name: "Loading", |
| 20 | + icon_url: "https://botsharp.azurewebsites.net/images/users/bot.png" |
| 21 | + }; |
| 22 | + |
| 23 | + let isLoading = true; |
| 24 | +
|
| 25 | + /** @type {string} */ |
| 26 | + let hide = ''; |
| 27 | + |
| 28 | + /** @type {string} */ |
| 29 | + let text; |
| 30 | + /** @type {boolean} */ |
| 31 | + let loadUtils; |
| 32 | + |
| 33 | + /** @type {number} */ |
| 34 | + let messageInputTimeout; |
| 35 | +
|
| 36 | + /** @type {string[]} */ |
| 37 | + let chatUtilOptions = []; |
| 38 | +
|
| 39 | + onMount(() => { |
| 40 | + if (conversationId) { |
| 41 | + loadDashboardComponents(conversationId); |
| 42 | + } |
| 43 | + if (instruction) { |
| 44 | + text = instruction; |
| 45 | + } |
| 46 | + } |
| 47 | + ); |
| 48 | +
|
| 49 | + /** |
| 50 | + * delete a message in conversation |
| 51 | + * @param {string} id The user input |
| 52 | + */ |
| 53 | + async function loadDashboardComponents(id) { |
| 54 | + getConversation(id) |
| 55 | + .then( |
| 56 | + response => { |
| 57 | + conversationModel = response; |
| 58 | + isLoading = false; |
| 59 | + } |
| 60 | + ) |
| 61 | + .catch(); |
| 62 | + } |
| 63 | + |
| 64 | + /** @param {any} e */ |
| 65 | + function handleMessageInput(e) { |
| 66 | + const value = e.target.value; |
| 67 | +
|
| 68 | + clearTimeout(messageInputTimeout); |
| 69 | + chatUtilOptions = []; |
| 70 | + } |
| 71 | +</script> |
| 72 | + |
| 73 | +<Col xl={4}> |
| 74 | + <Card bind:class={hide}> |
| 75 | + <CardBody> |
| 76 | + {#if isLoading} |
| 77 | + <CardTitle class="mb-0">{"Loading..."} </CardTitle> |
| 78 | + <p> Loading ... </p> |
| 79 | + {:else} |
| 80 | + <div class="row"> |
| 81 | + <div class="col-10"> |
| 82 | + <CardTitle class="mb-0">{conversationModel.title} </CardTitle> |
| 83 | + </div> |
| 84 | + <div class="col-2 "> |
| 85 | + <button |
| 86 | + class={`btn btn-rounded btn-sm btn-light`} |
| 87 | + on:click={() => { |
| 88 | + hide = 'hide'; |
| 89 | + unpinConversationFromDashboard(conversationModel.agent_id, conversationId); |
| 90 | + }} |
| 91 | + > |
| 92 | + <i |
| 93 | + class="mdi mdi-pin-off" |
| 94 | + style="font-size: 12px;" |
| 95 | + data-bs-toggle="tooltip" |
| 96 | + data-bs-placement="top" |
| 97 | + title="Unpin" |
| 98 | + /> |
| 99 | + </button> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + <div class="card mb-2"> |
| 103 | + <div class="chat-head"> |
| 104 | + <div class="row chat-row"> |
| 105 | + <div class="col-md-0 col-7 chat-head-info"> |
| 106 | + <div class="chat-head-agent"> |
| 107 | + {#if agent?.icon_url} |
| 108 | + <div class="line-align-center"> |
| 109 | + <img class="chat-head-agent-icon" src={agent.icon_url} alt=""> |
| 110 | + </div> |
| 111 | + {/if} |
| 112 | + <div class="chat-head-agent-name line-align-center ellipsis">{conversationModel.agent_id}</div> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + |
| 118 | + <div class={`chat-input-section css-animation fade-in-from-none mb-2`}> |
| 119 | + <div class="row"> |
| 120 | + <div class="col-10"> |
| 121 | + <div class="position-relative"> |
| 122 | + <ChatTextArea |
| 123 | + className={`chat-input`} |
| 124 | + maxLength={1024} |
| 125 | + disabled={false} |
| 126 | + bind:text={text} |
| 127 | + bind:loadUtils={loadUtils} |
| 128 | + bind:options={chatUtilOptions} |
| 129 | + onFocus={e => chatUtilOptions = []} |
| 130 | + > |
| 131 | + </ChatTextArea> |
| 132 | + </div> |
| 133 | + </div> |
| 134 | + <div class="col-auto"> |
| 135 | + <button |
| 136 | + type="submit" |
| 137 | + class={`btn btn-rounded chat-send waves-effect waves-light btn-primary`} |
| 138 | + disabled={!!!(text)} |
| 139 | + on:click={() => updateDashboardConversation(userId, { |
| 140 | + conversation_id: conversationId, |
| 141 | + name: '', |
| 142 | + instruction: text |
| 143 | + })} |
| 144 | + > |
| 145 | + <i class="mdi mdi-send" /> |
| 146 | + </button> |
| 147 | + </div> |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + </div> |
| 151 | + {/if} |
| 152 | + |
| 153 | + </CardBody> |
| 154 | + </Card> |
| 155 | +</Col> |
0 commit comments