Skip to content

Commit ba09fb0

Browse files
committed
chore: add conversational-ui demo
1 parent aff3b51 commit ba09fb0

File tree

6 files changed

+238
-0
lines changed

6 files changed

+238
-0
lines changed

examples-standalone/kendoangular-landing-page/package-lock.json

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

examples-standalone/kendoangular-landing-page/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@progress/kendo-angular-buttons": "18.5.2",
2323
"@progress/kendo-angular-charts": "^18.5.2",
2424
"@progress/kendo-angular-common": "18.5.2",
25+
"@progress/kendo-angular-conversational-ui": "^18.5.2",
2526
"@progress/kendo-angular-dateinputs": "18.5.2",
2627
"@progress/kendo-angular-dialog": "18.5.2",
2728
"@progress/kendo-angular-dropdowns": "18.5.2",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Subject } from 'rxjs';
2+
import { Injectable } from '@angular/core';
3+
4+
@Injectable()
5+
export class ChatService {
6+
public readonly responses: Subject<string> = new Subject<string>();
7+
8+
public submit(question: string): void {
9+
const length = question.length;
10+
const answer = `"${question}" contains exactly ${length} symbols.`;
11+
12+
setTimeout(() => this.responses.next(answer), 1000);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.container {
2+
display: flex;
3+
width: 100%;
4+
height: 400px;
5+
flex-direction: row;
6+
margin: 0;
7+
gap: 10%;
8+
padding: 0% 5%;
9+
}
10+
11+
.chat {
12+
height: 400px;
13+
width: 50%;
14+
margin: 0;
15+
}
16+
17+
.prompt {
18+
height: 400px;
19+
width: 50%;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="container">
2+
<kendo-chat class="chat" [messages]="(feed | async)!" [user]="user" (sendMessage)="sendMessage($event)">
3+
</kendo-chat>
4+
5+
<kendo-aiprompt
6+
class="prompt"
7+
(promptRequest)="onPromptRequest($event)"
8+
(commandExecute)="onCommandExecute($event)"
9+
[promptOutputs]="promptOutputs"
10+
[promptCommands]="commands"
11+
[promptSuggestions]="suggestions"
12+
[(activeView)]="activeView"
13+
>
14+
<kendo-aiprompt-prompt-view></kendo-aiprompt-prompt-view>
15+
<kendo-aiprompt-output-view></kendo-aiprompt-output-view>
16+
<kendo-aiprompt-command-view></kendo-aiprompt-command-view>
17+
</kendo-aiprompt>
18+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import { Component } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
import { KENDO_BUTTONS } from '@progress/kendo-angular-buttons';
5+
import { KENDO_INPUTS } from '@progress/kendo-angular-inputs';
6+
import { KENDO_LAYOUT } from '@progress/kendo-angular-layout';
7+
import {
8+
KENDO_CONVERSATIONALUI,
9+
CommandExecuteEvent,
10+
Message,
11+
PromptCommand,
12+
PromptOutput,
13+
PromptRequestEvent,
14+
SendMessageEvent,
15+
User,
16+
} from '@progress/kendo-angular-conversational-ui';
17+
import {
18+
SVGIcon,
19+
bellIcon,
20+
eyeIcon,
21+
infoCircleIcon,
22+
questionCircleIcon,
23+
warningCircleIcon,
24+
xIcon,
25+
} from '@progress/kendo-svg-icons';
26+
27+
import { from, merge, Observable, Subject } from 'rxjs';
28+
import { ChatService } from './chat.service';
29+
import { map, scan } from 'rxjs/operators';
30+
31+
@Component({
32+
selector: 'app-conversational-ui',
33+
standalone: true,
34+
imports: [CommonModule, KENDO_CONVERSATIONALUI, KENDO_BUTTONS, KENDO_INPUTS, KENDO_LAYOUT],
35+
providers: [ChatService],
36+
templateUrl: './conversational-ui.component.html',
37+
styleUrl: './conversational-ui.component.css',
38+
})
39+
export class ConversationalUiComponent {
40+
public closeIcon: SVGIcon = xIcon;
41+
public eye: SVGIcon = eyeIcon;
42+
public feed: Observable<Message[]>;
43+
44+
public readonly user: User = {
45+
id: 1,
46+
};
47+
48+
public readonly bot: User = {
49+
id: 0,
50+
};
51+
52+
public promptOutputs: PromptOutput[] = [];
53+
public activeView: number = 0;
54+
public idCounter = 0;
55+
56+
public commands: PromptCommand[] = [
57+
{
58+
text: 'Command text 1',
59+
id: 0,
60+
icon: 'bell',
61+
svgIcon: bellIcon,
62+
},
63+
{
64+
text: 'Command text 2',
65+
id: 1,
66+
icon: 'info',
67+
svgIcon: infoCircleIcon,
68+
},
69+
{
70+
text: 'Command text 3',
71+
id: 2,
72+
icon: 'question',
73+
svgIcon: questionCircleIcon,
74+
},
75+
{
76+
text: 'Command text 4',
77+
id: 3,
78+
icon: 'warning',
79+
svgIcon: warningCircleIcon,
80+
},
81+
];
82+
83+
public suggestions: string[] = ['Suggеstion 1', 'Suggestion 2'];
84+
85+
private local: Subject<Message> = new Subject<Message>();
86+
87+
constructor(private svc: ChatService) {
88+
const hello: Message = {
89+
author: this.bot,
90+
suggestedActions: [
91+
{
92+
type: 'reply',
93+
value: 'Neat!',
94+
},
95+
{
96+
type: 'reply',
97+
value: 'Thanks, but this is boring.',
98+
},
99+
],
100+
timestamp: new Date(),
101+
text: 'Hello, this is a demo bot. I don`t do much, but I can count symbols!',
102+
};
103+
104+
this.feed = merge(
105+
from([hello]),
106+
this.local,
107+
this.svc.responses.pipe(
108+
map(
109+
(response): Message => ({
110+
author: this.bot,
111+
text: response,
112+
})
113+
)
114+
)
115+
).pipe(scan((acc: Message[], x: Message) => [...acc, x], []));
116+
}
117+
118+
public sendMessage(e: SendMessageEvent): void {
119+
this.local.next(e.message);
120+
121+
this.local.next({
122+
author: this.bot,
123+
typing: true,
124+
});
125+
126+
if (e.message.text) {
127+
this.svc.submit(e.message.text);
128+
}
129+
}
130+
131+
public onPromptRequest(ev: PromptRequestEvent): void {
132+
if (!ev.prompt) {
133+
return;
134+
}
135+
this.createPromptOutput(ev);
136+
this.activeView = 1;
137+
}
138+
139+
public onCommandExecute(ev: CommandExecuteEvent): void {
140+
this.createPromptOutput(ev);
141+
this.activeView = 1;
142+
}
143+
144+
private createPromptOutput(ev: PromptRequestEvent | CommandExecuteEvent): void {
145+
this.idCounter += 1;
146+
const newOutput = {
147+
title: ev.isRetry ? 'Retry test title' : 'Test title',
148+
id: this.idCounter,
149+
prompt: (ev as PromptRequestEvent).prompt
150+
? (ev as PromptRequestEvent).prompt
151+
: (ev as CommandExecuteEvent).command.text,
152+
output: 'Test content',
153+
isRetry: ev.isRetry,
154+
commandId: (ev as PromptRequestEvent).prompt ? null : (ev as CommandExecuteEvent).command.id,
155+
};
156+
this.promptOutputs.unshift(newOutput as PromptOutput);
157+
}
158+
}

0 commit comments

Comments
 (0)