|
84 | 84 | /** @type {boolean} */
|
85 | 85 | let isLoadContentLog = false;
|
86 | 86 | let isLoadStateLog = false;
|
87 |
| - let isContentLogClosed = false; |
88 |
| - let isStateLogClosed = false; |
| 87 | + let isContentLogClosed = false; // initial condition |
| 88 | + let isStateLogClosed = false; // initial condition |
89 | 89 | let isOpenEditMsgModal = false;
|
90 | 90 | let isOpenAddStateModal = false;
|
91 | 91 | let isSendingMsg = false;
|
92 | 92 | let isThinking = false;
|
93 | 93 | let isLite = false;
|
94 | 94 | let isFrame = false;
|
95 |
| -
|
96 |
| - /** @type {any} */ |
97 |
| - let contentLogComponent; |
98 |
| - /** @type {any} */ |
99 |
| - let stateLogComponent; |
100 | 95 |
|
101 | 96 | onMount(async () => {
|
102 | 97 | dialogs = await GetDialogs(params.conversationId);
|
|
119 | 114 | function resizeChatWindow() {
|
120 | 115 | isLite = Viewport.Width <= screenWidthThreshold;
|
121 | 116 | if (!isLite) {
|
122 |
| - if (isContentLogClosed) { |
123 |
| - isLoadContentLog = false; |
124 |
| - } else { |
125 |
| - isLoadContentLog = true; |
126 |
| - } |
127 |
| - if (isStateLogClosed) { |
128 |
| - isLoadStateLog = false; |
129 |
| - } else { |
130 |
| - isLoadStateLog = true; |
131 |
| - } |
| 117 | + isLoadContentLog = !isContentLogClosed; |
| 118 | + isLoadStateLog = !isStateLogClosed; |
132 | 119 | } else {
|
133 | 120 | isLoadContentLog = false;
|
134 | 121 | isLoadStateLog = false;
|
|
137 | 124 | }
|
138 | 125 | }
|
139 | 126 |
|
| 127 | + function initChatView() { |
| 128 | + isFrame = $page.url.searchParams.get('isFrame') === 'true'; |
| 129 | + // initial condition |
| 130 | + isContentLogClosed = false; |
| 131 | + isStateLogClosed = false; |
| 132 | + resizeChatWindow(); |
| 133 | + } |
| 134 | +
|
140 | 135 | /** @param {import('$types').ChatResponseModel[]} dialogs */
|
141 | 136 | function initUserSentMessages(dialogs) {
|
142 | 137 | const curConvMessages = dialogs?.filter(x => x.sender?.role != UserRole.Assistant).map(x => {
|
|
186 | 181 | return messages?.slice(-messageLimit) || [];
|
187 | 182 | }
|
188 | 183 |
|
189 |
| - function initChatView() { |
190 |
| - isFrame = $page.url.searchParams.get('isFrame') === 'true'; |
191 |
| - resizeChatWindow(); |
192 |
| - } |
193 |
| -
|
194 | 184 | /** @param {import('$types').ChatResponseModel[]} dialogs */
|
195 | 185 | function findLastBotMessage(dialogs) {
|
196 | 186 | const lastMsg = dialogs.slice(-1)[0];
|
|
543 | 533 |
|
544 | 534 | /** @param {string} messageId */
|
545 | 535 | function truncateLogs(messageId) {
|
546 |
| - if (contentLogComponent && contentLogComponent.onDeleteMessage) { |
547 |
| - contentLogComponent.onDeleteMessage(messageId); |
| 536 | + if (isLoadContentLog) { |
| 537 | + const targetIdx = contentLogs.findIndex(x => x.message_id === messageId); |
| 538 | + if (targetIdx < 0) { |
| 539 | + contentLogs = []; |
| 540 | + } else { |
| 541 | + contentLogs = contentLogs.filter((x, idx) => idx < targetIdx); |
| 542 | + } |
548 | 543 | }
|
549 | 544 |
|
550 |
| - if (stateLogComponent && stateLogComponent.onDeleteMessage) { |
551 |
| - stateLogComponent.onDeleteMessage(messageId); |
| 545 | + if (isLoadStateLog) { |
| 546 | + const targetIdx = stateLogs.findIndex(x => x.message_id === messageId); |
| 547 | + if (targetIdx < 0) { |
| 548 | + stateLogs = []; |
| 549 | + } else { |
| 550 | + stateLogs = stateLogs.filter((x, idx) => idx < targetIdx); |
| 551 | + } |
552 | 552 | }
|
553 | 553 | }
|
554 | 554 |
|
|
557 | 557 | if (!!!messageId || isLite) return;
|
558 | 558 |
|
559 | 559 | highlightChatMessage(messageId);
|
| 560 | + highlightStateLog(messageId); |
| 561 | + autoScrollToTargetLog(messageId); |
| 562 | + } |
| 563 | +
|
| 564 | + /** @param {string} messageId */ |
| 565 | + function highlightChatMessage(messageId) { |
| 566 | + const targets = document.querySelectorAll('.user-msg'); |
| 567 | + targets.forEach(elm => { |
| 568 | + if (elm.id === `user-msg-${messageId}`) { |
| 569 | + elm.classList.add('bg-primary', 'text-white'); |
| 570 | + } else { |
| 571 | + elm.classList.remove('bg-primary', 'text-white'); |
| 572 | + } |
| 573 | + }); |
| 574 | + } |
| 575 | +
|
| 576 | + /** @param {string} messageId */ |
| 577 | + function highlightStateLog(messageId) { |
| 578 | + if (!isLoadStateLog) return; |
| 579 | +
|
| 580 | + stateLogs = stateLogs.map(item => { |
| 581 | + if (item.message_id === messageId) { |
| 582 | + item.expand_level = 1; |
| 583 | + } else { |
| 584 | + item.expand_level = 0; |
| 585 | + } |
| 586 | + return item; |
| 587 | + }); |
| 588 | + const targets = document.querySelectorAll('.state-log-item'); |
| 589 | + targets.forEach(elm => { |
| 590 | + const contentElm = elm.querySelector('.log-content'); |
| 591 | + if (!contentElm) return; |
| 592 | +
|
| 593 | + if (elm.id === `state-log-${messageId}`) { |
| 594 | + contentElm.classList.add('border', 'border-warning', 'rounded', 'p-1'); |
| 595 | + } else { |
| 596 | + contentElm.classList.remove('border', 'border-warning', 'rounded', 'p-1'); |
| 597 | + } |
| 598 | + }); |
| 599 | + } |
| 600 | +
|
| 601 | + /** @param {string} messageId */ |
| 602 | + function autoScrollToTargetLog(messageId) { |
560 | 603 | const elements = [];
|
561 | 604 | const contentLogElm = document.querySelector(`#content-log-${messageId}`);
|
562 |
| - if (!!contentLogElm) { |
| 605 | + if (isLoadContentLog && !!contentLogElm) { |
563 | 606 | elements.push({
|
564 | 607 | elm: contentLogElm,
|
565 | 608 | wrapperName: '.content-log-scrollbar'
|
566 | 609 | });
|
567 | 610 | }
|
568 | 611 |
|
569 | 612 | const stateLogElm = document.querySelector(`#state-log-${messageId}`);
|
570 |
| - if (!!stateLogElm) { |
| 613 | + if (isLoadStateLog && !!stateLogElm) { |
571 | 614 | elements.push({
|
572 | 615 | elm: stateLogElm,
|
573 | 616 | wrapperName: '.state-log-scrollbar'
|
|
582 | 625 | });
|
583 | 626 | }
|
584 | 627 |
|
585 |
| - /** @param {string} messageId */ |
586 |
| - function highlightChatMessage(messageId) { |
587 |
| - const targets = document.querySelectorAll('.user-msg'); |
588 |
| - targets.forEach(elm => { |
589 |
| - if (elm.id === `user-msg-${messageId}`) { |
590 |
| - elm.classList.add('bg-primary', 'text-white'); |
591 |
| - } else { |
592 |
| - elm.classList.remove('bg-primary', 'text-white'); |
593 |
| - } |
594 |
| - }); |
595 |
| - } |
596 |
| -
|
597 | 628 | function openFullScreen() {
|
598 | 629 | window.open($page.url.pathname);
|
599 | 630 | }
|
|
627 | 658 | {#if isLoadStateLog}
|
628 | 659 | <Pane size={30} minSize={20} maxSize={50} >
|
629 | 660 | <StateLog
|
630 |
| - bind:this={stateLogComponent} |
631 |
| - stateLogs={stateLogs} |
| 661 | + bind:stateLogs={stateLogs} |
632 | 662 | closeWindow={toggleStateLog}
|
633 | 663 | cleanScreen={cleanStateLogScreen}
|
634 | 664 | />
|
|
648 | 678 |
|
649 | 679 | <div class="col-md-8 col-5">
|
650 | 680 | <ul class="list-inline user-chat-nav user-chat-nav-flex mb-0">
|
651 |
| - {#if isFrame} |
652 |
| - <li class="chat-nav-element"> |
| 681 | + {#if 1} |
| 682 | + <li class="list-inline-item"> |
653 | 683 | <button
|
654 |
| - class="btn btn-secondary nav-btn dropdown-toggle" |
| 684 | + class="btn btn-secondary btn-rounded btn-sm" |
655 | 685 | on:click={() => openFullScreen()}
|
656 | 686 | >
|
657 | 687 | <i class="bx bx-fullscreen" />
|
658 | 688 | </button>
|
659 | 689 | </li>
|
660 | 690 | {/if}
|
661 |
| - <li class="chat-nav-element"> |
| 691 | + <li class="list-inline-item"> |
662 | 692 | <Dropdown>
|
663 | 693 | <DropdownToggle class="nav-btn dropdown-toggle">
|
664 | 694 | <i class="bx bx-dots-horizontal-rounded" />
|
|
690 | 720 | </Dropdown>
|
691 | 721 | </li>
|
692 | 722 |
|
693 |
| - <li class="chat-nav-element d-md-inline-block"> |
| 723 | + <li class="list-inline-item d-md-inline-block"> |
694 | 724 | <button
|
695 | 725 | class="btn btn-primary btn-rounded btn-sm chat-send waves-effect waves-light"
|
696 | 726 | on:click={() => endChat()}
|
|
835 | 865 | {#if isLoadContentLog}
|
836 | 866 | <Pane size={30} minSize={20} maxSize={50}>
|
837 | 867 | <ContentLog
|
838 |
| - bind:this={contentLogComponent} |
839 |
| - contentLogs={contentLogs} |
| 868 | + bind:contentLogs={contentLogs} |
840 | 869 | closeWindow={toggleContentLog}
|
841 | 870 | cleanScreen={cleanContentLogScreen}
|
842 | 871 | />
|
|
0 commit comments