@gitlab/duo-ui 8.11.0 → 8.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [8.12.1](https://gitlab.com/gitlab-org/duo-ui/compare/v8.12.0...v8.12.1) (2025-04-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * make custom code buttons work when response html lacks code tag ([35ce601](https://gitlab.com/gitlab-org/duo-ui/commit/35ce60111be3494ba58a4da7dfe4f916cc488547))
7
+
8
+ # [8.12.0](https://gitlab.com/gitlab-org/duo-ui/compare/v8.11.0...v8.12.0) (2025-04-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add frontend duo link sanitization ([158bfba](https://gitlab.com/gitlab-org/duo-ui/commit/158bfba6c807f99749e1e55f2cf04694dd7879f4))
14
+ * add frontend duo link sanitization ([5493491](https://gitlab.com/gitlab-org/duo-ui/commit/549349111905feb83d47025bde7c5b7a0eda8368))
15
+ * add frontend duo link sanitization ([0bd7dd4](https://gitlab.com/gitlab-org/duo-ui/commit/0bd7dd47bc7a7a6bb405389e92d9e3f14726ae8e))
16
+
17
+
18
+ ### Features
19
+
20
+ * new agentic duo chat UI ([76a3cff](https://gitlab.com/gitlab-org/duo-ui/commit/76a3cffd821dd61e34d18ad80e348f7b02935317))
21
+
1
22
  # [8.11.0](https://gitlab.com/gitlab-org/duo-ui/compare/v8.10.0...v8.11.0) (2025-04-02)
2
23
 
3
24
 
@@ -0,0 +1,648 @@
1
+ import throttle from 'lodash/throttle';
2
+ import VueResizable from 'vue-resizable';
3
+ import { GlButton, GlAlert, GlFormInputGroup, GlFormTextarea, GlForm, GlExperimentBadge, GlCard, GlDropdownItem, GlSafeHtmlDirective } from '@gitlab/ui';
4
+ import { translate } from '../../utils/i18n';
5
+ import { badgeTypes, badgeTypeValidator, CHAT_RESET_MESSAGE, CHAT_INCLUDE_MESSAGE, MESSAGE_MODEL_ROLES, CHAT_CLEAR_MESSAGE, CHAT_NEW_MESSAGE } from '../chat/constants';
6
+ import { VIEW_TYPES } from '../chat/components/duo_chat_header/constants';
7
+ import DuoChatLoader from '../chat/components/duo_chat_loader/duo_chat_loader';
8
+ import DuoChatPredefinedPrompts from '../chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts';
9
+ import DuoChatConversation from '../chat/components/duo_chat_conversation/duo_chat_conversation';
10
+ import DuoChatHeader from '../chat/components/duo_chat_header/duo_chat_header';
11
+ import DuoChatThreads from '../chat/components/duo_chat_threads/duo_chat_threads';
12
+ import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
13
+
14
+ const i18n = {
15
+ CHAT_DEFAULT_TITLE: translate('AgenticDuoChat.chatDefaultTitle', 'GitLab Duo Chat'),
16
+ CHAT_HISTORY_TITLE: translate('AgenticDuoChat.chatHistoryTitle', 'Chat history'),
17
+ CHAT_DISCLAMER: translate('AgenticDuoChat.chatDisclamer', 'Responses may be inaccurate. Verify before use.'),
18
+ CHAT_EMPTY_STATE_TITLE: translate('AgenticDuoChat.chatEmptyStateTitle', '👋 I am GitLab Duo Chat, your personal AI-powered assistant. How can I help you today?'),
19
+ CHAT_PROMPT_PLACEHOLDER_DEFAULT: translate('AgenticDuoChat.chatPromptPlaceholderDefault', 'GitLab Duo Chat'),
20
+ CHAT_PROMPT_PLACEHOLDER_WITH_COMMANDS: translate('AgenticDuoChat.chatPromptPlaceholderWithCommands', 'Type /help to learn more'),
21
+ CHAT_SUBMIT_LABEL: translate('AgenticDuoChat.chatSubmitLabel', 'Send chat message.'),
22
+ CHAT_CANCEL_LABEL: translate('AgenticDuoChat.chatCancelLabel', 'Cancel'),
23
+ CHAT_DEFAULT_PREDEFINED_PROMPTS: [translate('AgenticDuoChat.chatDefaultPredefinedPromptsChangePassword', 'How do I change my password in GitLab?'), translate('AgenticDuoChat.chatDefaultPredefinedPromptsForkProject', 'How do I fork a project?'), translate('AgenticDuoChat.chatDefaultPredefinedPromptsCloneRepository', 'How do I clone a repository?'), translate('AgenticDuoChat.chatDefaultPredefinedPromptsCreateTemplate', 'How do I create a template?')]
24
+ };
25
+ const isMessage = item => Boolean(item) && (item === null || item === void 0 ? void 0 : item.role);
26
+ const isSlashCommand = command => Boolean(command) && (command === null || command === void 0 ? void 0 : command.name) && command.description;
27
+
28
+ // eslint-disable-next-line unicorn/no-array-callback-reference
29
+ const itemsValidator = items => items.every(isMessage);
30
+ // eslint-disable-next-line unicorn/no-array-callback-reference
31
+ const slashCommandsValidator = commands => commands.every(isSlashCommand);
32
+ const isThread = thread => typeof thread === 'object' && typeof thread.id === 'string' && typeof thread.lastUpdatedAt === 'string' && typeof thread.createdAt === 'string' && typeof thread.conversationType === 'string' && (thread.title === null || typeof thread.title === 'string');
33
+
34
+ // eslint-disable-next-line unicorn/no-array-callback-reference
35
+ const threadListValidator = threads => threads.every(isThread);
36
+ const localeValidator = value => {
37
+ try {
38
+ Intl.getCanonicalLocales(value);
39
+ return true;
40
+ } catch {
41
+ return false;
42
+ }
43
+ };
44
+ var script = {
45
+ name: 'DuoChat',
46
+ components: {
47
+ GlButton,
48
+ GlAlert,
49
+ GlFormInputGroup,
50
+ GlFormTextarea,
51
+ GlForm,
52
+ GlExperimentBadge,
53
+ DuoChatLoader,
54
+ DuoChatPredefinedPrompts,
55
+ DuoChatConversation,
56
+ DuoChatHeader,
57
+ DuoChatThreads,
58
+ GlCard,
59
+ GlDropdownItem,
60
+ VueResizable
61
+ },
62
+ directives: {
63
+ SafeHtml: GlSafeHtmlDirective
64
+ },
65
+ props: {
66
+ /**
67
+ * Determines if the component should be resizable. When true, it renders inside
68
+ * a `vue-resizable` wrapper; otherwise, a standard `div` is used.
69
+ */
70
+ shouldRenderResizable: {
71
+ type: Boolean,
72
+ required: false,
73
+ default: false
74
+ },
75
+ /**
76
+ * Defines the dimensions of the chat container when resizable.
77
+ * By default, the height is set to match the height of the browser window,
78
+ * and the width is fixed at 400px. The `top` position is left undefined,
79
+ * allowing it to be dynamically adjusted if needed.
80
+ */
81
+ dimensions: {
82
+ type: Object,
83
+ required: false,
84
+ default: () => ({
85
+ width: undefined,
86
+ height: undefined,
87
+ top: undefined,
88
+ left: undefined,
89
+ maxWidth: undefined,
90
+ minWidth: 400,
91
+ maxHeight: undefined,
92
+ minHeight: 400
93
+ })
94
+ },
95
+ /**
96
+ * The title of the chat/feature.
97
+ */
98
+ title: {
99
+ type: String,
100
+ required: false,
101
+ default: i18n.CHAT_DEFAULT_TITLE
102
+ },
103
+ /**
104
+ * Array of messages to display in the chat.
105
+ */
106
+ messages: {
107
+ type: Array,
108
+ required: false,
109
+ default: () => [],
110
+ validator: itemsValidator
111
+ },
112
+ /**
113
+ * The ID of the active thread (if any).
114
+ */
115
+ activeThreadId: {
116
+ type: String,
117
+ required: false,
118
+ default: () => ''
119
+ },
120
+ /**
121
+ * The chat page that should be shown.
122
+ */
123
+ multiThreadedView: {
124
+ type: String,
125
+ required: false,
126
+ default: VIEW_TYPES.LIST,
127
+ validator: value => [VIEW_TYPES.LIST, VIEW_TYPES.CHAT].includes(value)
128
+ },
129
+ /**
130
+ * Array of RequestIds that have been canceled.
131
+ */
132
+ canceledRequestIds: {
133
+ type: Array,
134
+ required: false,
135
+ default: () => []
136
+ },
137
+ /**
138
+ * A non-recoverable error message to display in the chat.
139
+ */
140
+ error: {
141
+ type: String,
142
+ required: false,
143
+ default: ''
144
+ },
145
+ /**
146
+ * Array of messages to display in the chat.
147
+ */
148
+ threadList: {
149
+ type: Array,
150
+ required: false,
151
+ default: () => [],
152
+ validator: threadListValidator
153
+ },
154
+ /**
155
+ * Whether the chat is currently fetching a response from AI.
156
+ */
157
+ isLoading: {
158
+ type: Boolean,
159
+ required: false,
160
+ default: false
161
+ },
162
+ /**
163
+ * Whether the conversational interfaces should be enabled.
164
+ */
165
+ isChatAvailable: {
166
+ type: Boolean,
167
+ required: false,
168
+ default: true
169
+ },
170
+ /**
171
+ * Whether the insertCode feature should be available.
172
+ */
173
+ enableCodeInsertion: {
174
+ type: Boolean,
175
+ required: false,
176
+ default: false
177
+ },
178
+ /**
179
+ * Array of predefined prompts to display in the chat to start a conversation.
180
+ */
181
+ predefinedPrompts: {
182
+ type: Array,
183
+ required: false,
184
+ default: () => i18n.CHAT_DEFAULT_PREDEFINED_PROMPTS
185
+ },
186
+ /**
187
+ * The type of the badge. This is passed down to the `GlExperimentBadge` component. Refer that component for more information.
188
+ */
189
+ badgeType: {
190
+ type: String || null,
191
+ required: false,
192
+ default: badgeTypes[0],
193
+ validator: badgeTypeValidator
194
+ },
195
+ /**
196
+ * The current tool's name to display in the loading message while waiting for a response from AI. Refer the `DuoChatLoader` component for more information.
197
+ */
198
+ toolName: {
199
+ type: String,
200
+ required: false,
201
+ default: i18n.CHAT_DEFAULT_TITLE
202
+ },
203
+ /**
204
+ * Array of slash commands to display in the chat.
205
+ */
206
+ slashCommands: {
207
+ type: Array,
208
+ required: false,
209
+ default: () => [],
210
+ validator: slashCommandsValidator
211
+ },
212
+ /**
213
+ * Whether the header should be displayed.
214
+ */
215
+ showHeader: {
216
+ type: Boolean,
217
+ required: false,
218
+ default: true
219
+ },
220
+ /**
221
+ * Override the default empty state title text.
222
+ */
223
+ emptyStateTitle: {
224
+ type: String,
225
+ required: false,
226
+ default: i18n.CHAT_EMPTY_STATE_TITLE
227
+ },
228
+ /**
229
+ * Override the default chat prompt placeholder text.
230
+ */
231
+ chatPromptPlaceholder: {
232
+ type: String,
233
+ required: false,
234
+ default: ''
235
+ },
236
+ /**
237
+ * Whether the chat is running in multi-threaded mode
238
+ */
239
+ isMultithreaded: {
240
+ type: Boolean,
241
+ required: false,
242
+ default: false
243
+ },
244
+ /**
245
+ * The preferred locale for the chat interface.
246
+ * Follows BCP 47 language tag format (e.g., 'en-US', 'fr-FR', 'es-ES').
247
+ */
248
+ preferredLocale: {
249
+ type: Array,
250
+ required: false,
251
+ default: () => ['en-US', 'en'],
252
+ validator: localeValidator
253
+ }
254
+ },
255
+ data() {
256
+ return {
257
+ isHidden: false,
258
+ prompt: '',
259
+ scrolledToBottom: true,
260
+ activeCommandIndex: 0,
261
+ displaySubmitButton: true,
262
+ compositionJustEnded: false,
263
+ contextItemsMenuIsOpen: false,
264
+ contextItemMenuRef: null,
265
+ currentView: this.multiThreadedView
266
+ };
267
+ },
268
+ computed: {
269
+ shouldShowThreadList() {
270
+ return this.isMultithreaded && this.currentView === VIEW_TYPES.LIST;
271
+ },
272
+ withSlashCommands() {
273
+ return this.slashCommands.length > 0;
274
+ },
275
+ hasMessages() {
276
+ var _this$messages;
277
+ return ((_this$messages = this.messages) === null || _this$messages === void 0 ? void 0 : _this$messages.length) > 0;
278
+ },
279
+ conversations() {
280
+ if (!this.hasMessages) return [];
281
+ return this.messages.reduce((acc, message) => {
282
+ if (message.content === CHAT_RESET_MESSAGE) {
283
+ acc.push([]);
284
+ } else {
285
+ acc[acc.length - 1].push(message);
286
+ }
287
+ return acc;
288
+ }, [[]]);
289
+ },
290
+ lastMessage() {
291
+ var _this$messages2;
292
+ return (_this$messages2 = this.messages) === null || _this$messages2 === void 0 ? void 0 : _this$messages2[this.messages.length - 1];
293
+ },
294
+ caseInsensitivePrompt() {
295
+ return this.prompt.toLowerCase().trim();
296
+ },
297
+ isStreaming() {
298
+ var _this$lastMessage, _this$lastMessage2, _this$lastMessage2$ch, _this$lastMessage3, _this$lastMessage4;
299
+ if (this.canceledRequestIds.includes((_this$lastMessage = this.lastMessage) === null || _this$lastMessage === void 0 ? void 0 : _this$lastMessage.requestId)) {
300
+ return false;
301
+ }
302
+ return Boolean(((_this$lastMessage2 = this.lastMessage) === null || _this$lastMessage2 === void 0 ? void 0 : (_this$lastMessage2$ch = _this$lastMessage2.chunks) === null || _this$lastMessage2$ch === void 0 ? void 0 : _this$lastMessage2$ch.length) > 0 && !((_this$lastMessage3 = this.lastMessage) !== null && _this$lastMessage3 !== void 0 && _this$lastMessage3.content) || typeof ((_this$lastMessage4 = this.lastMessage) === null || _this$lastMessage4 === void 0 ? void 0 : _this$lastMessage4.chunkId) === 'number');
303
+ },
304
+ filteredSlashCommands() {
305
+ return this.slashCommands.filter(c => c.name.toLowerCase().startsWith(this.caseInsensitivePrompt)).filter(c => {
306
+ if (c.name === CHAT_INCLUDE_MESSAGE) {
307
+ return this.hasContextItemSelectionMenu;
308
+ }
309
+ return true;
310
+ });
311
+ },
312
+ shouldShowSlashCommands() {
313
+ if (!this.withSlashCommands || this.contextItemsMenuIsOpen) return false;
314
+ const startsWithSlash = this.caseInsensitivePrompt.startsWith('/');
315
+ const startsWithSlashCommand = this.slashCommands.some(c => this.caseInsensitivePrompt.startsWith(c.name));
316
+ return startsWithSlash && this.filteredSlashCommands.length && !startsWithSlashCommand;
317
+ },
318
+ shouldShowContextItemSelectionMenu() {
319
+ if (!this.hasContextItemSelectionMenu) {
320
+ return false;
321
+ }
322
+ const isSlash = this.caseInsensitivePrompt === '/';
323
+ if (!this.caseInsensitivePrompt || isSlash) {
324
+ // if user has removed entire command (or whole command except for '/') we should close context item menu and allow slash command menu to show again
325
+ return false;
326
+ }
327
+ return CHAT_INCLUDE_MESSAGE.startsWith(this.caseInsensitivePrompt);
328
+ },
329
+ inputPlaceholder() {
330
+ if (this.chatPromptPlaceholder) {
331
+ return this.chatPromptPlaceholder;
332
+ }
333
+ return this.withSlashCommands ? i18n.CHAT_PROMPT_PLACEHOLDER_WITH_COMMANDS : i18n.CHAT_PROMPT_PLACEHOLDER_DEFAULT;
334
+ },
335
+ hasContextItemSelectionMenu() {
336
+ return Boolean(this.contextItemMenuRef);
337
+ },
338
+ activeThread() {
339
+ return this.activeThreadId ? this.threadList.find(thread => thread.id === this.activeThreadId) : null;
340
+ },
341
+ activeThreadTitle() {
342
+ var _this$activeThread;
343
+ return (_this$activeThread = this.activeThread) === null || _this$activeThread === void 0 ? void 0 : _this$activeThread.title;
344
+ },
345
+ activeThreadTitleForView() {
346
+ return this.currentView === VIEW_TYPES.CHAT && this.activeThreadTitle || '';
347
+ }
348
+ },
349
+ watch: {
350
+ multiThreadedView(newView) {
351
+ this.currentView = newView;
352
+ },
353
+ isLoading(newVal) {
354
+ if (!newVal && !this.isStreaming) {
355
+ this.displaySubmitButton = true; // Re-enable submit button when loading stops
356
+ }
357
+ this.isHidden = false;
358
+ },
359
+ isStreaming(newVal) {
360
+ if (!newVal && !this.isLoading) {
361
+ this.displaySubmitButton = true; // Re-enable submit button when streaming stops
362
+ }
363
+ },
364
+ lastMessage(newMessage) {
365
+ if (this.scrolledToBottom || (newMessage === null || newMessage === void 0 ? void 0 : newMessage.role.toLowerCase()) === MESSAGE_MODEL_ROLES.user) {
366
+ // only scroll to bottom on new message if the user hasn't explicitly scrolled up to view an earlier message
367
+ // or if the user has just submitted a new message
368
+ this.scrollToBottom();
369
+ }
370
+ },
371
+ shouldShowSlashCommands(shouldShow) {
372
+ if (shouldShow) {
373
+ this.onShowSlashCommands();
374
+ }
375
+ }
376
+ },
377
+ created() {
378
+ this.handleScrollingThrottled = throttle(this.handleScrolling, 200); // Assume a 200ms throttle for example
379
+ },
380
+ mounted() {
381
+ this.scrollToBottom();
382
+ },
383
+ methods: {
384
+ onGoBack() {
385
+ this.$emit('back-to-list');
386
+ },
387
+ onNewChat() {
388
+ this.$emit('new-chat');
389
+ this.$nextTick(() => {
390
+ this.focusChatInput();
391
+ });
392
+ },
393
+ updateSize(e) {
394
+ this.$emit('chat-resize', e);
395
+ },
396
+ compositionEnd() {
397
+ this.compositionJustEnded = true;
398
+ },
399
+ hideChat() {
400
+ this.isHidden = true;
401
+ /**
402
+ * Emitted when clicking the cross in the title and the chat gets closed.
403
+ */
404
+ this.$emit('chat-hidden');
405
+ },
406
+ cancelPrompt() {
407
+ /**
408
+ * Emitted when user clicks the stop button in the textarea
409
+ */
410
+
411
+ this.displaySubmitButton = true;
412
+ this.$emit('chat-cancel');
413
+ this.setPromptAndFocus();
414
+ },
415
+ sendChatPrompt() {
416
+ if (!this.displaySubmitButton || this.contextItemsMenuIsOpen) {
417
+ return;
418
+ }
419
+ if (this.prompt) {
420
+ if (this.caseInsensitivePrompt.startsWith(CHAT_INCLUDE_MESSAGE) && this.hasContextItemSelectionMenu) {
421
+ this.contextItemsMenuIsOpen = true;
422
+ return;
423
+ }
424
+ if (![CHAT_RESET_MESSAGE, CHAT_CLEAR_MESSAGE, CHAT_NEW_MESSAGE].includes(this.caseInsensitivePrompt)) {
425
+ this.displaySubmitButton = false;
426
+ }
427
+
428
+ /**
429
+ * Emitted when a new user prompt should be sent out.
430
+ *
431
+ * @param {String} prompt The user prompt to send.
432
+ */
433
+ this.$emit('send-chat-prompt', this.prompt.trim());
434
+ this.setPromptAndFocus();
435
+ }
436
+ },
437
+ sendPredefinedPrompt(prompt) {
438
+ this.contextItemsMenuIsOpen = false;
439
+ this.prompt = prompt;
440
+ this.sendChatPrompt();
441
+ },
442
+ handleScrolling(event) {
443
+ const {
444
+ scrollTop,
445
+ offsetHeight,
446
+ scrollHeight
447
+ } = event.target;
448
+ this.scrolledToBottom = scrollTop + offsetHeight >= scrollHeight;
449
+ },
450
+ async scrollToBottom() {
451
+ var _this$$refs$anchor, _this$$refs$anchor$sc;
452
+ await this.$nextTick();
453
+ (_this$$refs$anchor = this.$refs.anchor) === null || _this$$refs$anchor === void 0 ? void 0 : (_this$$refs$anchor$sc = _this$$refs$anchor.scrollIntoView) === null || _this$$refs$anchor$sc === void 0 ? void 0 : _this$$refs$anchor$sc.call(_this$$refs$anchor);
454
+ },
455
+ focusChatInput() {
456
+ var _this$$refs$prompt, _this$$refs$prompt$$e;
457
+ // This method is also called directly by consumers of this component
458
+ // https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/blob/dae2d4669ab4da327921492a2962beae8a05c290/webviews/vue2/gitlab_duo_chat/src/App.vue#L109
459
+ (_this$$refs$prompt = this.$refs.prompt) === null || _this$$refs$prompt === void 0 ? void 0 : (_this$$refs$prompt$$e = _this$$refs$prompt.$el) === null || _this$$refs$prompt$$e === void 0 ? void 0 : _this$$refs$prompt$$e.focus();
460
+ },
461
+ onTrackFeedback(event) {
462
+ /**
463
+ * Notify listeners about the feedback form submission on a response message.
464
+ * @param {*} event An event, containing the feedback choices and the extended feedback text.
465
+ */
466
+ this.$emit('track-feedback', event);
467
+ },
468
+ onShowSlashCommands() {
469
+ /**
470
+ * Emitted when user opens the slash commands menu
471
+ */
472
+ this.$emit('chat-slash');
473
+ },
474
+ sendChatPromptOnEnter(e) {
475
+ const {
476
+ metaKey,
477
+ ctrlKey,
478
+ altKey,
479
+ shiftKey,
480
+ isComposing
481
+ } = e;
482
+ const isModifierKey = metaKey || ctrlKey || altKey || shiftKey;
483
+ return !(isModifierKey || isComposing || this.compositionJustEnded);
484
+ },
485
+ onInputKeyup(e) {
486
+ const {
487
+ key
488
+ } = e;
489
+ if (this.contextItemsMenuIsOpen) {
490
+ var _this$contextItemMenu;
491
+ if (!this.shouldShowContextItemSelectionMenu) {
492
+ this.contextItemsMenuIsOpen = false;
493
+ }
494
+ (_this$contextItemMenu = this.contextItemMenuRef) === null || _this$contextItemMenu === void 0 ? void 0 : _this$contextItemMenu.handleKeyUp(e);
495
+ return;
496
+ }
497
+ if (this.caseInsensitivePrompt === CHAT_INCLUDE_MESSAGE) {
498
+ this.contextItemsMenuIsOpen = true;
499
+ return;
500
+ }
501
+ if (this.shouldShowSlashCommands) {
502
+ e.preventDefault();
503
+ if (key === 'Enter') {
504
+ this.selectSlashCommand(this.activeCommandIndex);
505
+ } else if (key === 'ArrowUp') {
506
+ this.prevCommand();
507
+ } else if (key === 'ArrowDown') {
508
+ this.nextCommand();
509
+ } else {
510
+ this.activeCommandIndex = 0;
511
+ }
512
+ } else if (key === 'Enter' && this.sendChatPromptOnEnter(e)) {
513
+ e.preventDefault();
514
+ this.sendChatPrompt();
515
+ }
516
+ this.compositionJustEnded = false;
517
+ },
518
+ prevCommand() {
519
+ this.activeCommandIndex -= 1;
520
+ this.wrapCommandIndex();
521
+ },
522
+ nextCommand() {
523
+ this.activeCommandIndex += 1;
524
+ this.wrapCommandIndex();
525
+ },
526
+ wrapCommandIndex() {
527
+ if (this.activeCommandIndex < 0) {
528
+ this.activeCommandIndex = this.filteredSlashCommands.length - 1;
529
+ } else if (this.activeCommandIndex >= this.filteredSlashCommands.length) {
530
+ this.activeCommandIndex = 0;
531
+ }
532
+ },
533
+ async setPromptAndFocus() {
534
+ let prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
535
+ this.prompt = prompt;
536
+ await this.$nextTick();
537
+ this.focusChatInput();
538
+ },
539
+ selectSlashCommand(index) {
540
+ const command = this.filteredSlashCommands[index];
541
+ if (command.shouldSubmit) {
542
+ this.prompt = command.name;
543
+ this.sendChatPrompt();
544
+ } else {
545
+ this.setPromptAndFocus(`${command.name} `);
546
+ if (command.name === CHAT_INCLUDE_MESSAGE && this.hasContextItemSelectionMenu) {
547
+ this.contextItemsMenuIsOpen = true;
548
+ }
549
+ }
550
+ },
551
+ onInsertCodeSnippet(e) {
552
+ /**
553
+ * Emit insert-code-snippet event that clients can use to interact with a suggested code.
554
+ * @param {*} event An event containing code string in the "detail.code" field.
555
+ */
556
+ this.$emit('insert-code-snippet', e);
557
+ },
558
+ onCopyCodeSnippet(e) {
559
+ /**
560
+ * Emit copy-code-snippet event that clients can use to interact with a suggested code.
561
+ * @param {*} event An event containing code string in the "detail.code" field.
562
+ */
563
+ this.$emit('copy-code-snippet', e);
564
+ },
565
+ onCopyMessage(e) {
566
+ /**
567
+ * Emit copy-message event that clients can use to copy chat message content.
568
+ * @param {*} event An event containing code string in the "detail.message" field.
569
+ */
570
+ this.$emit('copy-message', e);
571
+ },
572
+ onGetContextItemContent(event) {
573
+ /**
574
+ * Emit get-context-item-content event that tells clients to load the full file content for a selected context item.
575
+ * The fully hydrated context item should be updated in the chat message context item.
576
+ * @param {*} event An event containing the message ID and context item to hydrate
577
+ */
578
+ this.$emit('get-context-item-content', event);
579
+ },
580
+ closeContextItemsMenuOpen() {
581
+ this.contextItemsMenuIsOpen = false;
582
+ this.setPromptAndFocus();
583
+ },
584
+ setContextItemsMenuRef(ref) {
585
+ this.contextItemMenuRef = ref;
586
+ },
587
+ onSelectThread(thread) {
588
+ /**
589
+ * Emitted when a thread is selected from the history.
590
+ * @param {Object} thread The selected thread object
591
+ */
592
+ this.$emit('thread-selected', thread);
593
+ },
594
+ onDeleteThread(threadId) {
595
+ /**
596
+ * Emitted when a thread is deleted from the history.
597
+ * @param {String} threadId The ID of the thread to delete
598
+ */
599
+ this.$emit('delete-thread', threadId);
600
+ }
601
+ },
602
+ i18n
603
+ };
604
+
605
+ /* script */
606
+ const __vue_script__ = script;
607
+
608
+ /* template */
609
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c(_vm.shouldRenderResizable ? 'vue-resizable' : 'div',{tag:"component",class:{
610
+ 'duo-chat-resizable': _vm.shouldRenderResizable,
611
+ 'non-resizable-wrapper': !_vm.shouldRenderResizable,
612
+ },attrs:{"width":_vm.shouldRenderResizable ? _vm.dimensions.width : null,"height":_vm.shouldRenderResizable ? _vm.dimensions.height : null,"max-width":_vm.shouldRenderResizable ? _vm.dimensions.maxWidth : null,"max-height":_vm.shouldRenderResizable ? _vm.dimensions.maxHeight : null,"min-width":_vm.shouldRenderResizable ? _vm.dimensions.minWidth : null,"left":_vm.shouldRenderResizable ? _vm.dimensions.left : null,"top":_vm.shouldRenderResizable ? _vm.dimensions.top : null,"fit-parent":true,"min-height":_vm.shouldRenderResizable ? _vm.dimensions.minHeight : null,"active":_vm.shouldRenderResizable ? ['l', 't', 'lt'] : null},on:{"resize:end":_vm.updateSize}},[(!_vm.isHidden)?_c('aside',{staticClass:"markdown-code-block duo-chat gl-bottom-0 gl-max-h-full gl-flex gl-flex-col",class:{
613
+ 'resizable-content': _vm.shouldRenderResizable,
614
+ 'duo-chat-drawer': !_vm.shouldRenderResizable,
615
+ },attrs:{"id":"chat-component","role":"complementary","data-testid":"chat-component"}},[(_vm.showHeader)?_c('duo-chat-header',{ref:"header",attrs:{"active-thread-id":_vm.activeThreadId,"title":_vm.isMultithreaded && _vm.currentView === 'list' ? _vm.$options.i18n.CHAT_HISTORY_TITLE : _vm.title,"subtitle":_vm.activeThreadTitleForView,"error":_vm.error,"is-multithreaded":_vm.isMultithreaded,"current-view":_vm.currentView,"should-render-resizable":_vm.shouldRenderResizable,"badge-type":_vm.isMultithreaded ? null : _vm.badgeType},on:{"go-back":_vm.onGoBack,"new-chat":_vm.onNewChat,"close":_vm.hideChat},scopedSlots:_vm._u([{key:"subheader",fn:function(){return [_vm._t("subheader")]},proxy:true}],null,true)}):_vm._e(),_vm._v(" "),_c('div',{staticClass:"gl-overflow-y-auto gl-flex gl-flex-col gl-flex-1 gl-flex-grow gl-bg-inherit gl-overscroll-contain",attrs:{"data-testid":"chat-history"},on:{"scroll":_vm.handleScrollingThrottled}},[(_vm.shouldShowThreadList)?_c('duo-chat-threads',{attrs:{"threads":_vm.threadList,"preferred-locale":_vm.preferredLocale},on:{"new-chat":_vm.onNewChat,"select-thread":_vm.onSelectThread,"delete-thread":_vm.onDeleteThread,"close":_vm.hideChat}}):_c('transition-group',{staticClass:"duo-chat-history gl-p-5 gl-mt-auto",attrs:{"mode":"out-in","tag":"section","name":"message"}},[_vm._l((_vm.conversations),function(conversation,index){return _c('duo-chat-conversation',{key:("conversation-" + index),attrs:{"enable-code-insertion":_vm.enableCodeInsertion,"messages":conversation,"canceled-request-ids":_vm.canceledRequestIds,"show-delimiter":index > 0},on:{"track-feedback":_vm.onTrackFeedback,"insert-code-snippet":_vm.onInsertCodeSnippet,"copy-code-snippet":_vm.onCopyCodeSnippet,"copy-message":_vm.onCopyMessage,"get-context-item-content":_vm.onGetContextItemContent}})}),_vm._v(" "),(!_vm.hasMessages && !_vm.isLoading)?[_c('div',{key:"empty-state-message",staticClass:"duo-chat-message gl-rounded-bl-none gl-border-1 gl-border-solid gl-border-gray-50 gl-bg-gray-10 gl-p-4 gl-leading-20 gl-text-gray-900 gl-break-anywhere",attrs:{"data-testid":"gl-duo-chat-empty-state"}},[(_vm.emptyStateTitle)?_c('p',{staticClass:"gl-m-0",attrs:{"data-testid":"gl-duo-chat-empty-state-title"}},[_vm._v("\n "+_vm._s(_vm.emptyStateTitle)+"\n ")]):_vm._e(),_vm._v(" "),_c('duo-chat-predefined-prompts',{key:"predefined-prompts",attrs:{"prompts":_vm.predefinedPrompts},on:{"click":_vm.sendPredefinedPrompt}})],1)]:_vm._e(),_vm._v(" "),(_vm.isLoading)?_c('duo-chat-loader',{key:"loader",attrs:{"tool-name":_vm.toolName}}):_vm._e(),_vm._v(" "),_c('div',{key:"anchor",ref:"anchor",staticClass:"scroll-anchor"})],2)],1),_vm._v(" "),(_vm.isChatAvailable && !_vm.shouldShowThreadList)?_c('footer',{staticClass:"duo-chat-drawer-footer gl-border-0 gl-bg-default gl-pb-3 gl-shrink-0 gl-relative gl-z-2",class:{ 'duo-chat-drawer-body-scrim-on-footer': !_vm.scrolledToBottom },attrs:{"data-testid":"chat-footer"}},[_c('gl-form',{attrs:{"data-testid":"chat-prompt-form"},on:{"submit":function($event){$event.stopPropagation();$event.preventDefault();return _vm.sendChatPrompt.apply(null, arguments)}}},[_c('div',{staticClass:"gl-relative gl-max-w-full"},[_vm._t("context-items-menu",null,{"isOpen":_vm.contextItemsMenuIsOpen,"onClose":_vm.closeContextItemsMenuOpen,"setRef":_vm.setContextItemsMenuRef,"focusPrompt":_vm.focusChatInput})],2),_vm._v(" "),_c('gl-form-input-group',{scopedSlots:_vm._u([{key:"append",fn:function(){return [(_vm.displaySubmitButton)?_c('gl-button',{staticClass:"!gl-absolute gl-bottom-2 gl-right-2 !gl-rounded-full",attrs:{"icon":"paper-airplane","category":"primary","variant":"confirm","type":"submit","data-testid":"chat-prompt-submit-button","aria-label":_vm.$options.i18n.CHAT_SUBMIT_LABEL}}):_c('gl-button',{staticClass:"!gl-absolute gl-bottom-2 gl-right-2 !gl-rounded-full",attrs:{"icon":"stop","category":"primary","variant":"default","data-testid":"chat-prompt-cancel-button","aria-label":_vm.$options.i18n.CHAT_CANCEL_LABEL},on:{"click":_vm.cancelPrompt}})]},proxy:true}],null,false,608602988)},[_c('div',{staticClass:"duo-chat-input gl-min-h-8 gl-max-w-full gl-grow gl-align-top",attrs:{"data-value":_vm.prompt}},[(_vm.shouldShowSlashCommands)?_c('gl-card',{ref:"commands",staticClass:"slash-commands !gl-absolute gl-w-full -gl-translate-y-full gl-list-none gl-pl-0 gl-shadow-md",attrs:{"body-class":"!gl-p-2"}},_vm._l((_vm.filteredSlashCommands),function(command,index){return _c('gl-dropdown-item',{key:command.name,class:{ 'active-command': index === _vm.activeCommandIndex },on:{"click":function($event){return _vm.selectSlashCommand(index)}},nativeOn:{"mouseenter":function($event){_vm.activeCommandIndex = index;}}},[_c('span',{staticClass:"gl-flex gl-justify-between"},[_c('span',{staticClass:"gl-block"},[_vm._v(_vm._s(command.name))]),_vm._v(" "),_c('small',{staticClass:"gl-pl-3 gl-text-right gl-italic gl-text-subtle"},[_vm._v(_vm._s(command.description))])])])}),1):_vm._e(),_vm._v(" "),_c('gl-form-textarea',{ref:"prompt",staticClass:"gl-absolute !gl-h-full gl-rounded-br-none gl-rounded-tr-none !gl-bg-transparent !gl-py-4 !gl-shadow-none",class:{ 'gl-truncate': !_vm.prompt },attrs:{"data-testid":"chat-prompt-input","placeholder":_vm.inputPlaceholder,"autofocus":""},on:{"compositionend":_vm.compositionEnd},nativeOn:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey||$event.metaKey){ return null; }$event.preventDefault();},"keyup":function($event){return _vm.onInputKeyup.apply(null, arguments)}},model:{value:(_vm.prompt),callback:function ($$v) {_vm.prompt=$$v;},expression:"prompt"}})],1)])],1),_vm._v(" "),_c('p',{staticClass:"gl-mb-0 gl-mt-3 gl-px-4 gl-text-sm gl-text-secondary"},[_vm._v("\n "+_vm._s(_vm.$options.i18n.CHAT_DISCLAMER)+"\n ")])],1):_vm._e()],1):_vm._e()])};
616
+ var __vue_staticRenderFns__ = [];
617
+
618
+ /* style */
619
+ const __vue_inject_styles__ = undefined;
620
+ /* scoped */
621
+ const __vue_scope_id__ = undefined;
622
+ /* module identifier */
623
+ const __vue_module_identifier__ = undefined;
624
+ /* functional template */
625
+ const __vue_is_functional_template__ = false;
626
+ /* style inject */
627
+
628
+ /* style inject SSR */
629
+
630
+ /* style inject shadow dom */
631
+
632
+
633
+
634
+ const __vue_component__ = __vue_normalize__(
635
+ { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
636
+ __vue_inject_styles__,
637
+ __vue_script__,
638
+ __vue_scope_id__,
639
+ __vue_is_functional_template__,
640
+ __vue_module_identifier__,
641
+ false,
642
+ undefined,
643
+ undefined,
644
+ undefined
645
+ );
646
+
647
+ export default __vue_component__;
648
+ export { i18n };