@gitlab/duo-ui 10.23.1 → 11.0.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.
@@ -0,0 +1,725 @@
1
+ import throttle from 'lodash/throttle';
2
+ import { GlButton, GlFormTextarea, GlForm, GlCard, GlDropdownItem, GlSafeHtmlDirective } from '@gitlab/ui';
3
+ import { translate, sprintf, translatePlural } from '@gitlab/ui/dist/utils/i18n';
4
+ import { badgeTypes, badgeTypeValidator, MAX_PROMPT_LENGTH, PROMPT_LENGTH_WARNING, CHAT_RESET_MESSAGE, CHAT_INCLUDE_MESSAGE, MESSAGE_MODEL_ROLES, CHAT_BASE_COMMANDS } from '../chat/constants';
5
+ import { VIEW_TYPES } from '../chat/components/duo_chat_header/constants';
6
+ import DuoChatLoader from '../chat/components/duo_chat_loader/duo_chat_loader';
7
+ import DuoChatPredefinedPrompts from '../chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts';
8
+ import DuoChatConversation from '../chat/components/duo_chat_conversation/duo_chat_conversation';
9
+ import WebDuoChatHeader from '../chat/components/duo_chat_header/web_duo_chat_header';
10
+ import DuoChatThreads from '../chat/components/duo_chat_threads/duo_chat_threads';
11
+ import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
12
+
13
+ const i18n = {
14
+ CHAT_DEFAULT_TITLE: translate('WebAgenticDuoChat.chatDefaultTitle', 'GitLab Duo Agentic Chat'),
15
+ CHAT_HISTORY_TITLE: translate('WebAgenticDuoChat.chatHistoryTitle', 'Chat history'),
16
+ CHAT_DISCLAMER: translate('WebAgenticDuoChat.chatDisclamer', 'Responses may be inaccurate. Verify before use.'),
17
+ CHAT_EMPTY_STATE_TITLE: translate('WebAgenticDuoChat.chatEmptyStateTitle', '👋 I am GitLab Duo Agentic Chat, your personal AI-powered assistant. How can I help you today?'),
18
+ CHAT_PROMPT_PLACEHOLDER_DEFAULT: translate('WebAgenticDuoChat.chatPromptPlaceholderDefault', "Let's work through this together..."),
19
+ CHAT_MODEL_PLACEHOLDER: translate('WebAgenticDuoChat.chatModelPlaceholder', 'GitLab Duo Agentic Chat'),
20
+ CHAT_PROMPT_PLACEHOLDER_WITH_COMMANDS: translate('WebAgenticDuoChat.chatPromptPlaceholderWithCommands', 'Type /help to learn more'),
21
+ CHAT_SUBMIT_LABEL: translate('WebAgenticDuoChat.chatSubmitLabel', 'Send chat message.'),
22
+ CHAT_CANCEL_LABEL: translate('WebAgenticDuoChat.chatCancelLabel', 'Cancel'),
23
+ CHAT_DEFAULT_PREDEFINED_PROMPTS: [translate('WebAgenticDuoChat.chatDefaultPredefinedPromptsChangePassword', 'How do I change my password in GitLab?'), translate('WebAgenticDuoChat.chatDefaultPredefinedPromptsForkProject', 'How do I fork a project?'), translate('WebAgenticDuoChat.chatDefaultPredefinedPromptsCloneRepository', 'How do I clone a repository?'), translate('WebAgenticDuoChat.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.updatedAt === 'string' && (thread.title === null || typeof thread.title === 'string' || typeof thread.goal === '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
+ GlFormTextarea,
49
+ GlForm,
50
+ DuoChatLoader,
51
+ DuoChatPredefinedPrompts,
52
+ DuoChatConversation,
53
+ WebDuoChatHeader,
54
+ DuoChatThreads,
55
+ GlCard,
56
+ GlDropdownItem
57
+ },
58
+ directives: {
59
+ SafeHtml: GlSafeHtmlDirective
60
+ },
61
+ props: {
62
+ /**
63
+ * Determines if the component should be resizable. When true, it renders inside
64
+ * a `vue-resizable` wrapper; otherwise, a standard `div` is used.
65
+ */
66
+ shouldRenderResizable: {
67
+ type: Boolean,
68
+ required: false,
69
+ default: false
70
+ },
71
+ /**
72
+ * Defines the dimensions of the chat container when resizable.
73
+ * By default, the height is set to match the height of the browser window,
74
+ * and the width is fixed at 400px. The `top` position is left undefined,
75
+ * allowing it to be dynamically adjusted if needed.
76
+ */
77
+ dimensions: {
78
+ type: Object,
79
+ required: false,
80
+ default: () => ({
81
+ width: undefined,
82
+ height: undefined,
83
+ top: undefined,
84
+ left: undefined,
85
+ maxWidth: undefined,
86
+ minWidth: 400,
87
+ maxHeight: undefined,
88
+ minHeight: 400
89
+ })
90
+ },
91
+ agents: {
92
+ type: Array,
93
+ required: false,
94
+ default: () => []
95
+ },
96
+ /**
97
+ * The title of the chat/feature.
98
+ */
99
+ title: {
100
+ type: String,
101
+ required: false,
102
+ default: i18n.CHAT_DEFAULT_TITLE
103
+ },
104
+ /**
105
+ * Array of messages to display in the chat.
106
+ */
107
+ messages: {
108
+ type: Array,
109
+ required: false,
110
+ default: () => [],
111
+ validator: itemsValidator
112
+ },
113
+ /**
114
+ * The ID of the active thread (if any).
115
+ */
116
+ activeThreadId: {
117
+ type: String,
118
+ required: false,
119
+ default: () => ''
120
+ },
121
+ /**
122
+ * The chat page that should be shown.
123
+ */
124
+ multiThreadedView: {
125
+ type: String,
126
+ required: false,
127
+ default: VIEW_TYPES.LIST,
128
+ validator: value => [VIEW_TYPES.LIST, VIEW_TYPES.CHAT].includes(value)
129
+ },
130
+ /**
131
+ * A non-recoverable error message to display in the chat.
132
+ */
133
+ error: {
134
+ type: String,
135
+ required: false,
136
+ default: ''
137
+ },
138
+ /**
139
+ * Array of messages to display in the chat.
140
+ */
141
+ threadList: {
142
+ type: Array,
143
+ required: false,
144
+ default: () => [],
145
+ validator: threadListValidator
146
+ },
147
+ /**
148
+ * Whether the chat is currently fetching a response from AI.
149
+ */
150
+ isLoading: {
151
+ type: Boolean,
152
+ required: false,
153
+ default: false
154
+ },
155
+ /**
156
+ * Whether the conversational interfaces should be enabled.
157
+ */
158
+ isChatAvailable: {
159
+ type: Boolean,
160
+ required: false,
161
+ default: true
162
+ },
163
+ /**
164
+ * Whether the insertCode feature should be available.
165
+ */
166
+ enableCodeInsertion: {
167
+ type: Boolean,
168
+ required: false,
169
+ default: false
170
+ },
171
+ /**
172
+ * Array of predefined prompts to display in the chat to start a conversation.
173
+ */
174
+ predefinedPrompts: {
175
+ type: Array,
176
+ required: false,
177
+ default: () => i18n.CHAT_DEFAULT_PREDEFINED_PROMPTS
178
+ },
179
+ /**
180
+ * The type of the badge. This is passed down to the `GlExperimentBadge` component. Refer that component for more information.
181
+ */
182
+ badgeType: {
183
+ type: String || null,
184
+ required: false,
185
+ default: badgeTypes[0],
186
+ validator: badgeTypeValidator
187
+ },
188
+ /**
189
+ * 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.
190
+ */
191
+ toolName: {
192
+ type: String,
193
+ required: false,
194
+ default: i18n.CHAT_DEFAULT_TITLE
195
+ },
196
+ /**
197
+ * Array of slash commands to display in the chat.
198
+ */
199
+ slashCommands: {
200
+ type: Array,
201
+ required: false,
202
+ default: () => [],
203
+ validator: slashCommandsValidator
204
+ },
205
+ /**
206
+ * Whether the header should be displayed.
207
+ */
208
+ showHeader: {
209
+ type: Boolean,
210
+ required: false,
211
+ default: true
212
+ },
213
+ /**
214
+ * Override the default empty state title text.
215
+ */
216
+ emptyStateTitle: {
217
+ type: String,
218
+ required: false,
219
+ default: i18n.CHAT_EMPTY_STATE_TITLE
220
+ },
221
+ /**
222
+ * Override the default chat prompt placeholder text.
223
+ */
224
+ chatPromptPlaceholder: {
225
+ type: String,
226
+ required: false,
227
+ default: ''
228
+ },
229
+ /**
230
+ * Whether the chat is running in multi-threaded mode
231
+ */
232
+ isMultithreaded: {
233
+ type: Boolean,
234
+ required: false,
235
+ default: false
236
+ },
237
+ /**
238
+ * The preferred locale for the chat interface.
239
+ * Follows BCP 47 language tag format (e.g., 'en-US', 'fr-FR', 'es-ES').
240
+ */
241
+ preferredLocale: {
242
+ type: Array,
243
+ required: false,
244
+ default: () => ['en-US', 'en'],
245
+ validator: localeValidator
246
+ },
247
+ /**
248
+ * Whether the chat should show the feedback link on the assistant messages.
249
+ */
250
+ withFeedback: {
251
+ type: Boolean,
252
+ required: false,
253
+ default: true
254
+ },
255
+ /**
256
+ * Whether the tool call is currently being processed.
257
+ */
258
+ isToolApprovalProcessing: {
259
+ type: Boolean,
260
+ required: false,
261
+ default: false
262
+ },
263
+ /**
264
+ * Optional parameter to pass in the working directory - needed for MessageMap Tool type
265
+ */
266
+ workingDirectory: {
267
+ type: String,
268
+ required: false,
269
+ default: ''
270
+ },
271
+ /**
272
+ * Optional parameter to expose the workflow/session ID in the Agentic Chat UI via a copy Session ID dropdown.
273
+ */
274
+ sessionId: {
275
+ type: String,
276
+ required: false,
277
+ default: () => ''
278
+ }
279
+ },
280
+ data() {
281
+ return {
282
+ prompt: '',
283
+ scrolledToBottom: true,
284
+ activeCommandIndex: 0,
285
+ canSubmit: true,
286
+ hasValidPrompt: true,
287
+ compositionJustEnded: false,
288
+ contextItemsMenuIsOpen: false,
289
+ contextItemMenuRef: null,
290
+ currentView: this.multiThreadedView,
291
+ maxPromptLength: MAX_PROMPT_LENGTH,
292
+ maxPromptLengthWarning: PROMPT_LENGTH_WARNING,
293
+ promptLengthWarningCount: MAX_PROMPT_LENGTH - PROMPT_LENGTH_WARNING
294
+ };
295
+ },
296
+ computed: {
297
+ shouldShowThreadList() {
298
+ return this.isMultithreaded && this.currentView === VIEW_TYPES.LIST;
299
+ },
300
+ withSlashCommands() {
301
+ return this.slashCommands.length > 0;
302
+ },
303
+ hasMessages() {
304
+ var _this$messages;
305
+ return ((_this$messages = this.messages) === null || _this$messages === void 0 ? void 0 : _this$messages.length) > 0;
306
+ },
307
+ conversations() {
308
+ if (!this.hasMessages) return [];
309
+ return this.messages.reduce((acc, message) => {
310
+ if (message.content === CHAT_RESET_MESSAGE) {
311
+ acc.push([]);
312
+ } else {
313
+ acc[acc.length - 1].push(message);
314
+ }
315
+ return acc;
316
+ }, [[]]);
317
+ },
318
+ lastMessage() {
319
+ var _this$messages2;
320
+ return (_this$messages2 = this.messages) === null || _this$messages2 === void 0 ? void 0 : _this$messages2[this.messages.length - 1];
321
+ },
322
+ caseInsensitivePrompt() {
323
+ return this.prompt.toLowerCase().trim();
324
+ },
325
+ isPromptEmpty() {
326
+ return this.caseInsensitivePrompt.length === 0;
327
+ },
328
+ isStreaming() {
329
+ var _this$lastMessage, _this$lastMessage$chu, _this$lastMessage2, _this$lastMessage3;
330
+ return Boolean(((_this$lastMessage = this.lastMessage) === null || _this$lastMessage === void 0 ? void 0 : (_this$lastMessage$chu = _this$lastMessage.chunks) === null || _this$lastMessage$chu === void 0 ? void 0 : _this$lastMessage$chu.length) > 0 && !((_this$lastMessage2 = this.lastMessage) !== null && _this$lastMessage2 !== void 0 && _this$lastMessage2.content) || typeof ((_this$lastMessage3 = this.lastMessage) === null || _this$lastMessage3 === void 0 ? void 0 : _this$lastMessage3.chunkId) === 'number');
331
+ },
332
+ filteredSlashCommands() {
333
+ return this.slashCommands.filter(c => c.name.toLowerCase().startsWith(this.caseInsensitivePrompt)).filter(c => {
334
+ if (c.name === CHAT_INCLUDE_MESSAGE) {
335
+ return this.hasContextItemSelectionMenu;
336
+ }
337
+ return true;
338
+ });
339
+ },
340
+ shouldShowSlashCommands() {
341
+ if (!this.withSlashCommands || this.contextItemsMenuIsOpen) return false;
342
+ const startsWithSlash = this.caseInsensitivePrompt.startsWith('/');
343
+ const startsWithSlashCommand = this.slashCommands.some(c => this.caseInsensitivePrompt.startsWith(c.name));
344
+ return startsWithSlash && this.filteredSlashCommands.length && !startsWithSlashCommand;
345
+ },
346
+ shouldShowContextItemSelectionMenu() {
347
+ if (!this.hasContextItemSelectionMenu) {
348
+ return false;
349
+ }
350
+ const isSlash = this.caseInsensitivePrompt === '/';
351
+ if (!this.caseInsensitivePrompt || isSlash) {
352
+ // 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
353
+ return false;
354
+ }
355
+ return CHAT_INCLUDE_MESSAGE.startsWith(this.caseInsensitivePrompt);
356
+ },
357
+ inputPlaceholder() {
358
+ if (this.chatPromptPlaceholder) {
359
+ return this.chatPromptPlaceholder;
360
+ }
361
+ return this.withSlashCommands ? i18n.CHAT_PROMPT_PLACEHOLDER_WITH_COMMANDS : i18n.CHAT_PROMPT_PLACEHOLDER_DEFAULT;
362
+ },
363
+ hasContextItemSelectionMenu() {
364
+ return Boolean(this.contextItemMenuRef);
365
+ },
366
+ activeThread() {
367
+ return this.activeThreadId ? this.threadList.find(thread => thread.id === this.activeThreadId) : null;
368
+ },
369
+ activeThreadTitle() {
370
+ var _this$activeThread;
371
+ return (_this$activeThread = this.activeThread) === null || _this$activeThread === void 0 ? void 0 : _this$activeThread.title;
372
+ },
373
+ activeThreadTitleForView() {
374
+ return this.currentView === VIEW_TYPES.CHAT && this.activeThreadTitle || '';
375
+ }
376
+ },
377
+ watch: {
378
+ multiThreadedView(newView) {
379
+ this.currentView = newView;
380
+ },
381
+ isLoading(loading) {
382
+ if (!loading && !this.isStreaming) {
383
+ this.canSubmit = true; // Re-enable submit button when loading stops
384
+ }
385
+ },
386
+ isStreaming(streaming) {
387
+ if (!streaming && !this.isLoading) {
388
+ this.canSubmit = true; // Re-enable submit button when streaming stops
389
+ }
390
+ },
391
+ lastMessage(newMessage) {
392
+ if (this.scrolledToBottom || (newMessage === null || newMessage === void 0 ? void 0 : newMessage.role.toLowerCase()) === MESSAGE_MODEL_ROLES.user) {
393
+ // only scroll to bottom on new message if the user hasn't explicitly scrolled up to view an earlier message
394
+ // or if the user has just submitted a new message
395
+ this.scrollToBottom();
396
+ }
397
+ },
398
+ shouldShowSlashCommands(shouldShow) {
399
+ if (shouldShow) {
400
+ this.onShowSlashCommands();
401
+ }
402
+ },
403
+ prompt(newPrompt) {
404
+ this.hasValidPrompt = (newPrompt === null || newPrompt === void 0 ? void 0 : newPrompt.length) < MAX_PROMPT_LENGTH + 1;
405
+ }
406
+ },
407
+ created() {
408
+ this.handleScrollingThrottled = throttle(this.handleScrolling, 200); // Assume a 200ms throttle for example
409
+ },
410
+ mounted() {
411
+ this.scrollToBottom();
412
+ },
413
+ methods: {
414
+ onGoBack() {
415
+ this.$emit('back-to-list');
416
+ },
417
+ onNewChat(agent) {
418
+ this.$emit('new-chat', agent);
419
+ this.$nextTick(() => {
420
+ this.focusChatInput();
421
+ });
422
+ },
423
+ compositionEnd() {
424
+ this.compositionJustEnded = true;
425
+ },
426
+ hideChat() {
427
+ /**
428
+ * Emitted when clicking the cross in the title and the chat gets closed.
429
+ */
430
+ this.$emit('chat-hidden');
431
+ },
432
+ cancelPrompt() {
433
+ /**
434
+ * Emitted when user clicks the stop button in the textarea
435
+ */
436
+ this.canSubmit = true;
437
+ this.$emit('chat-cancel');
438
+ this.setPromptAndFocus();
439
+ },
440
+ async sendChatPrompt() {
441
+ if (!this.canSubmit || this.contextItemsMenuIsOpen) {
442
+ return;
443
+ }
444
+ if (this.prompt) {
445
+ // Store these before any async operations that might clear the prompt
446
+ const trimmedPrompt = this.prompt.trim();
447
+ const lowerCasePrompt = this.prompt.toLowerCase().trim();
448
+ if (lowerCasePrompt.startsWith(CHAT_INCLUDE_MESSAGE) && this.hasContextItemSelectionMenu) {
449
+ this.contextItemsMenuIsOpen = true;
450
+ return;
451
+ }
452
+
453
+ /**
454
+ * Emitted when a new user prompt should be sent out.
455
+ *
456
+ * @param {String} prompt The user prompt to send.
457
+ */
458
+ this.$emit('send-chat-prompt', trimmedPrompt);
459
+
460
+ // Always clear the prompt after sending, regardless of the command type
461
+ await this.setPromptAndFocus();
462
+ // Check if it was a special command using the stored value (before clearing)
463
+ if (!CHAT_BASE_COMMANDS.includes(lowerCasePrompt)) {
464
+ // Wait for all reactive updates to complete before setting canSubmit
465
+ await this.$nextTick();
466
+ this.canSubmit = false;
467
+ }
468
+ }
469
+ },
470
+ sendPredefinedPrompt(prompt) {
471
+ this.contextItemsMenuIsOpen = false;
472
+ this.prompt = prompt;
473
+ this.sendChatPrompt();
474
+ },
475
+ handleScrolling(event) {
476
+ const {
477
+ scrollTop,
478
+ offsetHeight,
479
+ scrollHeight
480
+ } = event.target;
481
+ this.scrolledToBottom = scrollTop + offsetHeight >= scrollHeight;
482
+ },
483
+ async scrollToBottom() {
484
+ var _this$$refs$anchor, _this$$refs$anchor$sc;
485
+ await this.$nextTick();
486
+ (_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);
487
+ },
488
+ focusChatInput() {
489
+ var _this$$refs$prompt, _this$$refs$prompt$$e, _this$$refs$prompt$$e2, _this$$refs$prompt$$e3;
490
+ (_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$$e2 = _this$$refs$prompt$$e.querySelector) === null || _this$$refs$prompt$$e2 === void 0 ? void 0 : (_this$$refs$prompt$$e3 = _this$$refs$prompt$$e2.call(_this$$refs$prompt$$e, 'textarea')) === null || _this$$refs$prompt$$e3 === void 0 ? void 0 : _this$$refs$prompt$$e3.focus();
491
+ },
492
+ onTrackFeedback(event) {
493
+ /**
494
+ * Notify listeners about the feedback form submission on a response message.
495
+ * @param {*} event An event, containing the feedback choices and the extended feedback text.
496
+ */
497
+ this.$emit('track-feedback', event);
498
+ },
499
+ onShowSlashCommands() {
500
+ /**
501
+ * Emitted when user opens the slash commands menu
502
+ */
503
+ this.$emit('chat-slash');
504
+ },
505
+ sendChatPromptOnEnter(e) {
506
+ const {
507
+ metaKey,
508
+ ctrlKey,
509
+ altKey,
510
+ shiftKey,
511
+ isComposing
512
+ } = e;
513
+ const isModifierKey = metaKey || ctrlKey || altKey || shiftKey;
514
+ return !(isModifierKey || isComposing || this.compositionJustEnded);
515
+ },
516
+ onInputKeyup(e) {
517
+ const {
518
+ key
519
+ } = e;
520
+ if (this.contextItemsMenuIsOpen) {
521
+ var _this$contextItemMenu;
522
+ if (!this.shouldShowContextItemSelectionMenu) {
523
+ this.contextItemsMenuIsOpen = false;
524
+ }
525
+ (_this$contextItemMenu = this.contextItemMenuRef) === null || _this$contextItemMenu === void 0 ? void 0 : _this$contextItemMenu.handleKeyUp(e);
526
+ return;
527
+ }
528
+ if (this.caseInsensitivePrompt === CHAT_INCLUDE_MESSAGE) {
529
+ this.contextItemsMenuIsOpen = true;
530
+ return;
531
+ }
532
+ if (this.shouldShowSlashCommands) {
533
+ e.preventDefault();
534
+ if (key === 'Enter') {
535
+ this.selectSlashCommand(this.activeCommandIndex);
536
+ } else if (key === 'ArrowUp') {
537
+ this.prevCommand();
538
+ } else if (key === 'ArrowDown') {
539
+ this.nextCommand();
540
+ } else {
541
+ this.activeCommandIndex = 0;
542
+ }
543
+ } else if (key === 'Enter' && this.sendChatPromptOnEnter(e)) {
544
+ e.preventDefault();
545
+ this.sendChatPrompt();
546
+ }
547
+ this.compositionJustEnded = false;
548
+ },
549
+ prevCommand() {
550
+ this.activeCommandIndex -= 1;
551
+ this.wrapCommandIndex();
552
+ },
553
+ nextCommand() {
554
+ this.activeCommandIndex += 1;
555
+ this.wrapCommandIndex();
556
+ },
557
+ wrapCommandIndex() {
558
+ if (this.activeCommandIndex < 0) {
559
+ this.activeCommandIndex = this.filteredSlashCommands.length - 1;
560
+ } else if (this.activeCommandIndex >= this.filteredSlashCommands.length) {
561
+ this.activeCommandIndex = 0;
562
+ }
563
+ },
564
+ async setPromptAndFocus() {
565
+ let prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
566
+ this.prompt = prompt;
567
+ await this.$nextTick();
568
+ this.focusChatInput();
569
+ },
570
+ selectSlashCommand(index) {
571
+ const command = this.filteredSlashCommands[index];
572
+ if (command.shouldSubmit) {
573
+ this.prompt = command.name;
574
+ this.sendChatPrompt();
575
+ } else {
576
+ this.setPromptAndFocus(`${command.name} `);
577
+ if (command.name === CHAT_INCLUDE_MESSAGE && this.hasContextItemSelectionMenu) {
578
+ this.contextItemsMenuIsOpen = true;
579
+ }
580
+ }
581
+ },
582
+ onInsertCodeSnippet(e) {
583
+ /**
584
+ * Emit insert-code-snippet event that clients can use to interact with a suggested code.
585
+ * @param {*} event An event containing code string in the "detail.code" field.
586
+ */
587
+ this.$emit('insert-code-snippet', e);
588
+ },
589
+ onCopyCodeSnippet(e) {
590
+ /**
591
+ * Emit copy-code-snippet event that clients can use to interact with a suggested code.
592
+ * @param {*} event An event containing code string in the "detail.code" field.
593
+ */
594
+ this.$emit('copy-code-snippet', e);
595
+ },
596
+ onCopyMessage(e) {
597
+ /**
598
+ * Emit copy-message event that clients can use to copy chat message content.
599
+ * @param {*} event An event containing code string in the "detail.message" field.
600
+ */
601
+ this.$emit('copy-message', e);
602
+ },
603
+ onGetContextItemContent(event) {
604
+ /**
605
+ * Emit get-context-item-content event that tells clients to load the full file content for a selected context item.
606
+ * The fully hydrated context item should be updated in the chat message context item.
607
+ * @param {*} event An event containing the message ID and context item to hydrate
608
+ */
609
+ this.$emit('get-context-item-content', event);
610
+ },
611
+ closeContextItemsMenuOpen() {
612
+ this.contextItemsMenuIsOpen = false;
613
+ this.setPromptAndFocus();
614
+ },
615
+ setContextItemsMenuRef(ref) {
616
+ this.contextItemMenuRef = ref;
617
+ },
618
+ onSelectThread(thread) {
619
+ /**
620
+ * Emitted when a thread is selected from the history.
621
+ * @param {Object} thread The selected thread object
622
+ */
623
+ this.$emit('thread-selected', thread);
624
+ },
625
+ onDeleteThread(threadId) {
626
+ /**
627
+ * Emitted when a thread is deleted from the history.
628
+ * @param {String} threadId The ID of the thread to delete
629
+ */
630
+ this.$emit('delete-thread', threadId);
631
+ },
632
+ onApproveToolCall() {
633
+ /**
634
+ * Emitted when a user approves a tool call.
635
+ */
636
+ this.$emit('approve-tool');
637
+ },
638
+ onDenyToolCall(reason) {
639
+ /**
640
+ * Emitted when a user denies a tool call.
641
+ * @param {String} reason The reason for denying the tool call.
642
+ */
643
+ this.$emit('deny-tool', reason);
644
+ },
645
+ onOpenFilePath(filePath) {
646
+ /**
647
+ * Emitted when a file path link is clicked in a chat message.
648
+ * @param {String} filePath The file path to open
649
+ */
650
+ this.$emit('open-file-path', filePath);
651
+ },
652
+ handleUndo(event) {
653
+ var _document$execCommand, _document;
654
+ event.preventDefault();
655
+ (_document$execCommand = (_document = document).execCommand) === null || _document$execCommand === void 0 ? void 0 : _document$execCommand.call(_document, 'undo');
656
+ },
657
+ handleRedo(event) {
658
+ var _document$execCommand2, _document2;
659
+ event.preventDefault();
660
+ (_document$execCommand2 = (_document2 = document).execCommand) === null || _document$execCommand2 === void 0 ? void 0 : _document$execCommand2.call(_document2, 'redo');
661
+ },
662
+ remainingCharacterCountMessage(count) {
663
+ return sprintf(translatePlural('WebAgenticDuoChat.remainingCharacterCountMessage', '%{count} character remaining.', '%{count} characters remaining.')(count), {
664
+ count
665
+ });
666
+ },
667
+ overLimitCharacterCountMessage(count) {
668
+ return sprintf(translatePlural('WebAgenticDuoChat.overLimitCharacterCountMessage', '%{count} character over limit.', '%{count} characters over limit.')(count), {
669
+ count
670
+ });
671
+ }
672
+ },
673
+ i18n
674
+ };
675
+
676
+ /* script */
677
+ const __vue_script__ = script;
678
+
679
+ /* template */
680
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"markdown-code-block duo-chat gl-bottom-0 gl-flex gl-max-h-full gl-flex-grow gl-flex-col",attrs:{"id":"chat-component","role":"complementary","data-testid":"chat-component"}},[(_vm.showHeader)?_c('web-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,"session-id":_vm.sessionId,"agents":_vm.agents},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-flex gl-flex-1 gl-flex-grow gl-flex-col gl-overflow-y-auto gl-overscroll-contain gl-bg-inherit",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-mt-auto gl-p-5",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,"show-delimiter":index > 0,"with-feedback":_vm.withFeedback,"is-tool-approval-processing":_vm.isToolApprovalProcessing,"working-directory":_vm.workingDirectory},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,"approve-tool":_vm.onApproveToolCall,"deny-tool":_vm.onDenyToolCall,"open-file-path":_vm.onOpenFilePath}})}),_vm._v(" "),(!_vm.hasMessages && !_vm.isLoading)?[_c('div',{key:"empty-state-message",staticClass:"duo-chat-message gl-rounded-bl-none 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-relative gl-z-2 gl-shrink-0 gl-border-0 gl-bg-default gl-pb-3",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('div',{staticClass:"duo-chat-input gl-min-h-8 gl-max-w-full gl-grow gl-flex-col gl-rounded-bl-[12px] gl-rounded-br-[18px] gl-rounded-tl-[12px] gl-rounded-tr-[12px] gl-align-top"},[_c('div',{staticClass:"gl-flex gl-justify-between gl-border-0 gl-border-b-1 gl-border-solid gl-border-strong gl-px-4 gl-py-4"},[_c('div',[_vm._v(_vm._s(_vm.$options.i18n.CHAT_MODEL_PLACEHOLDER))]),_vm._v(" "),_c('div',[_vm._t("agentic-switch")],2)]),_vm._v(" "),_c('div',{staticClass:"gl-h-[40px] gl-grow",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",attrs:{"disabled":!_vm.canSubmit,"data-testid":"chat-prompt-input","placeholder":_vm.inputPlaceholder,"character-count-limit":_vm.maxPromptLength,"textarea-classes":[
681
+ '!gl-h-full',
682
+ '!gl-bg-transparent',
683
+ '!gl-py-4',
684
+ '!gl-shadow-none',
685
+ 'form-control',
686
+ 'gl-form-input',
687
+ 'gl-form-textarea',
688
+ { 'gl-truncate': !_vm.prompt } ],"aria-label":"Chat prompt input","autofocus":""},on:{"keydown":[function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"z",undefined,$event.key,undefined)){ return null; }if(!$event.ctrlKey){ return null; }if($event.shiftKey||$event.altKey||$event.metaKey){ return null; }return _vm.handleUndo.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"z",undefined,$event.key,undefined)){ return null; }if(!$event.metaKey){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey){ return null; }return _vm.handleUndo.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"z",undefined,$event.key,undefined)){ return null; }if(!$event.ctrlKey){ return null; }if(!$event.shiftKey){ return null; }if($event.altKey||$event.metaKey){ return null; }return _vm.handleRedo.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"z",undefined,$event.key,undefined)){ return null; }if(!$event.metaKey){ return null; }if(!$event.shiftKey){ return null; }if($event.ctrlKey||$event.altKey){ return null; }return _vm.handleRedo.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"y",undefined,$event.key,undefined)){ return null; }if(!$event.ctrlKey){ return null; }if($event.shiftKey||$event.altKey||$event.metaKey){ return null; }return _vm.handleRedo.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"y",undefined,$event.key,undefined)){ return null; }if(!$event.metaKey){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey){ return null; }return _vm.handleRedo.apply(null, arguments)}],"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)}},scopedSlots:_vm._u([{key:"remaining-character-count-text",fn:function(ref){
689
+ var count = ref.count;
690
+ return [(count <= _vm.promptLengthWarningCount)?_c('span',{staticClass:"gl-absolute gl-bottom-[-25px] gl-right-px gl-pr-3"},[_vm._v("\n "+_vm._s(_vm.remainingCharacterCountMessage(count))+"\n ")]):_vm._e()]}},{key:"character-count-over-limit-text",fn:function(ref){
691
+ var count = ref.count;
692
+ return [_c('span',{staticClass:"gl-absolute gl-bottom-[-25px] gl-right-px gl-pr-3"},[_vm._v(_vm._s(_vm.overLimitCharacterCountMessage(count)))])]}}],null,false,839584904),model:{value:(_vm.prompt),callback:function ($$v) {_vm.prompt=$$v;},expression:"prompt"}})],1),_vm._v(" "),_c('div',{staticClass:"gl-flex gl-justify-end gl-px-3 gl-pb-3"},[(_vm.canSubmit)?_c('gl-button',{staticClass:"gl-bottom-2 gl-right-2 gl-ml-auto !gl-rounded-full",attrs:{"icon":"paper-airplane","category":"primary","variant":"confirm","type":"submit","disabled":_vm.isPromptEmpty || !_vm.hasValidPrompt,"data-testid":"chat-prompt-submit-button","aria-label":_vm.$options.i18n.CHAT_SUBMIT_LABEL}}):_c('gl-button',{staticClass:"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}})],1)])]),_vm._v(" "),_vm._t("footer-controls"),_vm._v(" "),_c('p',{staticClass:"gl-mb-0 gl-mt-3 gl-px-4 gl-text-sm gl-text-secondary",class:{ 'gl-mt-6 sm:gl-mt-3 sm:gl-max-w-1/2': _vm.prompt.length >= _vm.maxPromptLengthWarning }},[_vm._v("\n "+_vm._s(_vm.$options.i18n.CHAT_DISCLAMER)+"\n ")])],2):_vm._e()],1)};
693
+ var __vue_staticRenderFns__ = [];
694
+
695
+ /* style */
696
+ const __vue_inject_styles__ = undefined;
697
+ /* scoped */
698
+ const __vue_scope_id__ = undefined;
699
+ /* module identifier */
700
+ const __vue_module_identifier__ = undefined;
701
+ /* functional template */
702
+ const __vue_is_functional_template__ = false;
703
+ /* style inject */
704
+
705
+ /* style inject SSR */
706
+
707
+ /* style inject shadow dom */
708
+
709
+
710
+
711
+ const __vue_component__ = __vue_normalize__(
712
+ { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
713
+ __vue_inject_styles__,
714
+ __vue_script__,
715
+ __vue_scope_id__,
716
+ __vue_is_functional_template__,
717
+ __vue_module_identifier__,
718
+ false,
719
+ undefined,
720
+ undefined,
721
+ undefined
722
+ );
723
+
724
+ export default __vue_component__;
725
+ export { i18n };