|
149 | 149 | }) || []; |
150 | 150 |
|
151 | 151 | const savedMessages = conversationUserMessageStore.get(); |
| 152 | + // @ts-ignore |
152 | 153 | const otherConvMessages = savedMessages?.messages?.filter(x => x.conversationId !== params.conversationId) || []; |
153 | 154 | const allMessages = [...otherConvMessages, ...curConvMessages]; |
154 | 155 | const trimmedMessages = trimUserSentMessages(allMessages); |
|
273 | 274 | truncateDialogs(data.message_id); |
274 | 275 | } |
275 | 276 |
|
276 | | - async function newConversationHandler() { |
| 277 | + async function handleNewConversation() { |
277 | 278 | const conversation = await newConversation(params.agentId); |
278 | 279 | conversationStore.set(conversation); |
279 | 280 | const url = `chat/${params.agentId}/${conversation.id}`; |
|
289 | 290 | isSendingMsg = true; |
290 | 291 | renewUserSentMessages(msgText); |
291 | 292 |
|
292 | | - const postback = buildPostbackMessage(dialogs, data?.payload || null); |
| 293 | + const postback = buildPostbackMessage(dialogs, data?.payload || msgText, data?.truncateMsgId); |
293 | 294 | /** @type {import('$types').MessageData?} */ |
294 | 295 | const messageData = { |
295 | 296 | ...data, |
|
381 | 382 | /** |
382 | 383 | * @param {import('$types').ChatResponseModel[]} dialogs |
383 | 384 | * @param {string?} content |
| 385 | + * @param {string?} [truncateMsgId] |
384 | 386 | */ |
385 | | - function buildPostbackMessage(dialogs, content) { |
| 387 | + function buildPostbackMessage(dialogs, content, truncateMsgId) { |
386 | 388 | /** @type {import('$types').Postback?} */ |
387 | 389 | let postback = null; |
388 | | - const lastMsg = dialogs.slice(-1)[0]; |
| 390 | + let lastMsg = dialogs.slice(-1)[0]; |
| 391 | +
|
| 392 | + if (!!truncateMsgId) { |
| 393 | + const foundIdx = dialogs.findIndex(x => x.message_id === truncateMsgId); |
| 394 | + const truncatedDialogs = dialogs.filter((x, idx) => idx < foundIdx); |
| 395 | + lastMsg = truncatedDialogs.slice(-1)[0]; |
| 396 | + } |
| 397 | +
|
389 | 398 | if (!!lastMsg?.rich_content?.fill_postback |
390 | 399 | && !!lastMsg?.function |
391 | 400 | && lastMsg?.sender?.role === UserRole.Assistant) { |
|
748 | 757 | </Dropdown> |
749 | 758 | </li> |
750 | 759 | {/if} |
751 | | - <DropdownItem on:click={newConversationHandler}>New Conversation</DropdownItem> |
| 760 | + <DropdownItem on:click={handleNewConversation}>New Conversation</DropdownItem> |
752 | 761 | </DropdownMenu> |
753 | 762 | </Dropdown> |
754 | 763 | </li> |
|
0 commit comments