-
Notifications
You must be signed in to change notification settings - Fork 12
Add scrolling behavior to chat #2975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alexia-Claudia-Micu
wants to merge
24
commits into
main
Choose a base branch
from
users/cmicu/3897966
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
b9e1d08
Change files
Alexia-Claudia-Micu 9348c28
Add scrolling behavior to chat.
Alexia-Claudia-Micu 60671fc
Code clean-up
Alexia-Claudia-Micu 71e56e8
Lint fix
Alexia-Claudia-Micu 934955b
Some behaviour changes
Alexia-Claudia-Micu 99ea9e7
Change files
Alexia-Claudia-Micu b1868c8
Update example app
Alexia-Claudia-Micu 1fd0c2a
Merge branch 'main' into users/cmicu/3897966
Alexia-Claudia-Micu c48348b
Storybook minor text edits
jattasNI b7259ad
Document auto-scroll in spec
jattasNI 00032b2
Document reload scroll behavior
jattasNI 2ca3e45
Change auto-scroll default value
jattasNI bd7d7e3
Directive boolean attribute and tests
jattasNI b78bf4f
Vibe code Blazor app
jattasNI a591a7b
Vibe code React app
jattasNI f5d31a9
ref for messages slot instead of query
jattasNI 28be7dd
Change scroll manager lifecycle
jattasNI dd3990a
Blazor build
jattasNI 53b88c7
Use tag name
jattasNI c23922b
React autoscroll
jattasNI 38851f7
Blazor styling
jattasNI 2ffa392
Blazor wrapper and test and example app
jattasNI 12c0e27
Fix Blazor example
jattasNI d1d2a50
Change files
jattasNI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-angular-2188570c-9255-47e7-8f52-a34d062b7b81.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add auto-scroll attribute to conversation.", | ||
| "packageName": "@ni/spright-angular", | ||
| "email": "163188334+Alexia-Claudia-Micu@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-blazor-08d16ce6-2034-41f4-9374-2a2fed2ee178.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "Add autoscroll to chat conversation", | ||
| "packageName": "@ni/spright-blazor", | ||
| "email": "jattasNI@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@ni-spright-components-98a40075-e551-4376-aa9a-f3a3fb1d4c4a.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
|
Alexia-Claudia-Micu marked this conversation as resolved.
|
||
| "type": "minor", | ||
| "comment": "Add scrolling behavior to chat.", | ||
| "packageName": "@ni/spright-components", | ||
| "email": "163188334+Alexia-Claudia-Micu@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
220 changes: 176 additions & 44 deletions
220
...lar-workspace/example-client-app/src/app/customapp/chat-conversation-section.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,61 +1,193 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { Component, type OnDestroy } from '@angular/core'; | ||
| import type { ChatInputSendEventDetail } from '@ni/spright-angular/chat/input'; | ||
|
|
||
| interface ChatEntry { | ||
|
Alexia-Claudia-Micu marked this conversation as resolved.
|
||
| type: 'user' | 'advisor' | 'system'; | ||
| text: string; | ||
| streaming: boolean; | ||
| } | ||
|
|
||
| const singleResponse = `To configure your Python version, select Adapters from the Configure menu. | ||
| Configure the Python adapter. Choose the desired version from the Version dropdown. | ||
| You can also specify a Python version for a specific module call in the Advanced Settings of the Python adapter. | ||
| Additionally, you can set environment variables in the adapter configuration to control runtime behavior. | ||
| This gives you fine-grained control over which interpreter is used per step in your test sequence. | ||
| If you have multiple virtual environments, make sure to point the adapter to the correct executable path. | ||
| The path must be absolute and should not contain spaces unless properly quoted. | ||
| For further reference, consult the NI TestStand help documentation under the Python Adapter section.`; | ||
|
|
||
| const cannedResponseWords = Array(5).fill(singleResponse).join('\n').split(/\s+/); | ||
|
|
||
| @Component({ | ||
| selector: 'example-chat-conversation-section', | ||
| template: ` | ||
| <example-sub-container label="Chat Conversation and Messages (Spright)"> | ||
| <spright-chat-conversation> | ||
| <nimble-toolbar slot="toolbar"> | ||
| <nimble-icon-messages-sparkle slot="start"></nimble-icon-messages-sparkle> | ||
| <span class="toolbar-title">AI Assistant</span> | ||
| <nimble-button appearance="ghost" content-hidden title="Create new chat" slot="end"> | ||
| Create new chat | ||
| <nimble-icon-pencil-to-rectangle slot="start"></nimble-icon-pencil-to-rectangle> | ||
| </nimble-button> | ||
| </nimble-toolbar> | ||
| <nimble-banner slot="start" open severity="information"> | ||
| <span slot="title">Title of the banner</span> | ||
| <div class="conversations"> | ||
| <spright-chat-conversation> | ||
| <nimble-toolbar slot="toolbar"> | ||
| <nimble-icon-messages-sparkle slot="start"></nimble-icon-messages-sparkle> | ||
| <span class="toolbar-title">AI Assistant</span> | ||
| <nimble-button appearance="ghost" content-hidden title="Create new chat" slot="end"> | ||
| Create new chat | ||
| <nimble-icon-pencil-to-rectangle slot="start"></nimble-icon-pencil-to-rectangle> | ||
| </nimble-button> | ||
| </nimble-toolbar> | ||
| <nimble-banner slot="start" open severity="information"> | ||
| <span slot="title">Title of the banner</span> | ||
| This is the message text of this banner. It tells you something interesting. | ||
| </nimble-banner> | ||
| <spright-chat-message-system>To start, press any key.</spright-chat-message-system> | ||
| <spright-chat-message-outbound>Where is the Any key?</spright-chat-message-outbound> | ||
| <spright-chat-message-system> | ||
| <nimble-spinner appearance="accent"></nimble-spinner> | ||
| </spright-chat-message-system> | ||
| <spright-chat-message-inbound> | ||
| <nimble-button slot="footer-actions" appearance='ghost' content-hidden> | ||
| <nimble-icon-copy-text slot="start"></nimble-icon-copy-text> | ||
| Copy | ||
| </nimble-button> | ||
| <nimble-icon-webvi-custom style="height: 100px; width: 100px;"></nimble-icon-webvi-custom> | ||
| <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
| Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div> | ||
| <nimble-button slot="end" appearance="block">Order a tab</nimble-button> | ||
| <nimble-button slot="end" appearance="block">Check core temperature</nimble-button> | ||
| </spright-chat-message-inbound> | ||
| @for (message of chatUserMessages; track message) { | ||
| <spright-chat-message-outbound><span>{{message}}</span></spright-chat-message-outbound> | ||
| } | ||
| <spright-chat-input slot="input" placeholder="Type here" (send)="onChatInputSend($event)"></spright-chat-input> | ||
| <span slot="end"> | ||
| AI-generated content may be incorrect. | ||
| <nimble-anchor href="https://www.ni.com" target="_blank">View Terms and Conditions</nimble-anchor> | ||
| </span> | ||
| </spright-chat-conversation> | ||
| </nimble-banner> | ||
| <spright-chat-message-system>To start, press any key.</spright-chat-message-system> | ||
| <spright-chat-message-outbound>Where is the Any key?</spright-chat-message-outbound> | ||
| <spright-chat-message-system> | ||
| <nimble-spinner appearance="accent"></nimble-spinner> | ||
| </spright-chat-message-system> | ||
| <spright-chat-message-inbound> | ||
| <nimble-button slot="footer-actions" appearance='ghost' content-hidden> | ||
| <nimble-icon-copy-text slot="start"></nimble-icon-copy-text> | ||
| Copy | ||
| </nimble-button> | ||
| <nimble-icon-webvi-custom style="height: 100px; width: 100px;"></nimble-icon-webvi-custom> | ||
| <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
| Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div> | ||
| <nimble-button slot="end" appearance="block">Order a tab</nimble-button> | ||
| <nimble-button slot="end" appearance="block">Check core temperature</nimble-button> | ||
| </spright-chat-message-inbound> | ||
| @for (message of staticUserMessages; track message) { | ||
| <spright-chat-message-outbound><span>{{message}}</span></spright-chat-message-outbound> | ||
| } | ||
| <spright-chat-input slot="input" placeholder="Type here" (send)="onStaticChatInputSend($event)"></spright-chat-input> | ||
| <span slot="end"> | ||
| AI-generated content may be incorrect. | ||
| <nimble-anchor href="https://www.ni.com" target="_blank">View Terms and Conditions</nimble-anchor> | ||
| </span> | ||
| </spright-chat-conversation> | ||
|
|
||
| <div class="streaming-section"> | ||
| <label class="response-label">Custom advisor response (leave empty for canned):</label> | ||
| <textarea class="response-input" rows="3" (input)="onCustomAdvisorTextInput($event)"></textarea> | ||
| <spright-chat-conversation auto-scroll> | ||
| <nimble-toolbar slot="toolbar"> | ||
| <nimble-icon-messages-sparkle slot="start"></nimble-icon-messages-sparkle> | ||
| <span class="toolbar-title">AI Assistant (Streaming)</span> | ||
| </nimble-toolbar> | ||
| @for (entry of messages; track entry) { | ||
| @if (entry.type === 'user') { | ||
| <spright-chat-message-outbound> | ||
| <span>{{entry.text}}</span> | ||
| </spright-chat-message-outbound> | ||
| } | ||
| @if (entry.type === 'system') { | ||
| <spright-chat-message-system> | ||
| <nimble-spinner appearance="accent"></nimble-spinner> | ||
| </spright-chat-message-system> | ||
| } | ||
| @if (entry.type === 'advisor') { | ||
| <spright-chat-message-inbound> | ||
| <span>{{entry.text}}</span> | ||
| @if (!entry.streaming) { | ||
| <nimble-button slot="footer-actions" appearance="ghost" content-hidden title="Copy"> | ||
| <nimble-icon-copy-text slot="start"></nimble-icon-copy-text> | ||
| Copy | ||
| </nimble-button> | ||
| } | ||
| </spright-chat-message-inbound> | ||
| } | ||
| } | ||
| <spright-chat-input slot="input" placeholder="Send a messageβ¦" (send)="onChatInputSend($event)" [send-disabled]="isStreaming"></spright-chat-input> | ||
| <span slot="end">AI-generated content may be incorrect.</span> | ||
| </spright-chat-conversation> | ||
| </div> | ||
| </div> | ||
| </example-sub-container> | ||
| `, | ||
| styles: [` | ||
| spright-chat-conversation { max-width: 700px; } | ||
| spright-chat-message span { white-space: pre-wrap; } | ||
| .conversations { | ||
| display: flex; | ||
| gap: 16px; | ||
| } | ||
| spright-chat-conversation { | ||
| width: 700px; | ||
| height: 650px; | ||
| } | ||
| .streaming-section { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 8px; | ||
| } | ||
| .response-label { | ||
| font: var(--ni-nimble-body-font); | ||
| color: var(--ni-nimble-body-font-color); | ||
| } | ||
| .response-input { | ||
| font: var(--ni-nimble-body-font); | ||
| color: var(--ni-nimble-body-font-color); | ||
| background: var(--ni-nimble-fill-secondary-color); | ||
| border: 1px solid var(--ni-nimble-border-color); | ||
| padding: 4px; | ||
| width: 700px; | ||
| resize: vertical; | ||
| } | ||
| spright-chat-message-outbound span, | ||
| spright-chat-message-inbound span { white-space: pre-wrap; } | ||
| `], | ||
| standalone: false | ||
| }) | ||
| export class ChatConversationSectionComponent { | ||
| public chatUserMessages: string[] = []; | ||
| export class ChatConversationSectionComponent implements OnDestroy { | ||
| public staticUserMessages: string[] = []; | ||
| public messages: ChatEntry[] = []; | ||
| public isStreaming = false; | ||
|
|
||
| private customAdvisorText = ''; | ||
| private streamInterval: ReturnType<typeof setInterval> | null = null; | ||
|
|
||
| public onCustomAdvisorTextInput(e: Event): void { | ||
| this.customAdvisorText = (e.target as HTMLTextAreaElement).value; | ||
| } | ||
|
|
||
| public onStaticChatInputSend(e: Event): void { | ||
| this.staticUserMessages.push((e as CustomEvent<ChatInputSendEventDetail>).detail.text); | ||
| } | ||
|
|
||
| public onChatInputSend(e: Event): void { | ||
| const chatInputSendEvent = (e as CustomEvent<ChatInputSendEventDetail>); | ||
| this.chatUserMessages.push(chatInputSendEvent.detail.text); | ||
| const text = (e as CustomEvent<ChatInputSendEventDetail>).detail.text; | ||
| this.messages.push({ type: 'user', text, streaming: false }); | ||
| this.startStreaming(); | ||
| } | ||
|
|
||
| public ngOnDestroy(): void { | ||
| if (this.streamInterval !== null) { | ||
| clearInterval(this.streamInterval); | ||
| } | ||
| } | ||
|
|
||
| private startStreaming(): void { | ||
| this.isStreaming = true; | ||
| const spinnerEntry: ChatEntry = { type: 'system', text: '', streaming: true }; | ||
| this.messages.push(spinnerEntry); | ||
|
|
||
| const responseWords = this.customAdvisorText.trim().length > 0 | ||
| ? this.customAdvisorText.trim().split(/\s+/) | ||
| : cannedResponseWords; | ||
| let wordIndex = 0; | ||
| setTimeout(() => { | ||
| const idx = this.messages.indexOf(spinnerEntry); | ||
| if (idx !== -1) { | ||
| this.messages.splice(idx, 1); | ||
| } | ||
| const advisorEntry: ChatEntry = { type: 'advisor', text: '', streaming: true }; | ||
| this.messages.push(advisorEntry); | ||
|
|
||
| this.streamInterval = setInterval(() => { | ||
| if (wordIndex < responseWords.length) { | ||
| advisorEntry.text += (wordIndex === 0 ? '' : ' ') + responseWords[wordIndex]; | ||
| wordIndex += 1; | ||
| } else { | ||
| clearInterval(this.streamInterval!); | ||
| this.streamInterval = null; | ||
| advisorEntry.streaming = false; | ||
| this.isStreaming = false; | ||
| } | ||
| }, 30); | ||
| }, 300); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.