@gitlab/ui 66.21.0 → 66.23.0
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 +14 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.js +103 -0
- package/dist/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.js +64 -0
- package/dist/components/experimental/duo/chat/constants.js +21 -0
- package/dist/components/experimental/duo/chat/mock_data.js +31 -0
- package/dist/tokens/css/tokens.css +1 -1
- package/dist/tokens/css/tokens.dark.css +1 -1
- package/dist/tokens/js/tokens.dark.js +1 -1
- package/dist/tokens/js/tokens.js +1 -1
- package/dist/tokens/scss/_tokens.dark.scss +1 -1
- package/dist/tokens/scss/_tokens.scss +1 -1
- package/package.json +1 -1
- package/src/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.md +1 -0
- package/src/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.spec.js +92 -0
- package/src/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.stories.js +32 -0
- package/src/components/experimental/duo/chat/components/duo_chat_message_sources/duo_chat_message_sources.vue +80 -0
- package/src/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.md +1 -0
- package/src/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.spec.js +35 -0
- package/src/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.stories.js +36 -0
- package/src/components/experimental/duo/chat/components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.vue +36 -0
- package/src/components/experimental/duo/chat/constants.js +20 -0
- package/src/components/experimental/duo/chat/mock_data.js +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [66.23.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v66.22.0...v66.23.0) (2023-10-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **GlDuoChatPredefinedPrompts:** new component ([c3e2347](https://gitlab.com/gitlab-org/gitlab-ui/commit/c3e234717b9c33ab8bb3d3f66e13387efe235fd7))
|
|
7
|
+
|
|
8
|
+
# [66.22.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v66.21.0...v66.22.0) (2023-10-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **GlDuoChatMessageSources:** Implemented component ([8066320](https://gitlab.com/gitlab-org/gitlab-ui/commit/8066320214e88a8b75279eec1d82029bf8c3e9db))
|
|
14
|
+
|
|
1
15
|
# [66.21.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v66.20.0...v66.21.0) (2023-10-02)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { GlIcon, GlLink } from '../../../../../../index';
|
|
2
|
+
import { DOCUMENTATION_SOURCE_TYPES } from '../../constants';
|
|
3
|
+
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
4
|
+
|
|
5
|
+
const i18n = {
|
|
6
|
+
MESSAGE_SOURCE: 'Source',
|
|
7
|
+
MESSAGE_SOURCES: 'Sources'
|
|
8
|
+
};
|
|
9
|
+
var script = {
|
|
10
|
+
name: 'GlDuoChatMessageSources',
|
|
11
|
+
components: {
|
|
12
|
+
GlIcon,
|
|
13
|
+
GlLink
|
|
14
|
+
},
|
|
15
|
+
props: {
|
|
16
|
+
/**
|
|
17
|
+
* The Array of the message sources.
|
|
18
|
+
*/
|
|
19
|
+
sources: {
|
|
20
|
+
type: Array,
|
|
21
|
+
required: true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
computed: {
|
|
25
|
+
sourceLabel() {
|
|
26
|
+
return this.sources.length > 1 ? i18n.MESSAGE_SOURCES : i18n.MESSAGE_SOURCES;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
methods: {
|
|
30
|
+
getSourceIcon(sourceType) {
|
|
31
|
+
const currentSourceType = Object.values(DOCUMENTATION_SOURCE_TYPES).find(_ref => {
|
|
32
|
+
let {
|
|
33
|
+
value
|
|
34
|
+
} = _ref;
|
|
35
|
+
return value === sourceType;
|
|
36
|
+
});
|
|
37
|
+
return (currentSourceType === null || currentSourceType === void 0 ? void 0 : currentSourceType.icon) || 'document';
|
|
38
|
+
},
|
|
39
|
+
getSourceTitle(_ref2) {
|
|
40
|
+
let {
|
|
41
|
+
title,
|
|
42
|
+
source_type: sourceType,
|
|
43
|
+
stage,
|
|
44
|
+
group,
|
|
45
|
+
date,
|
|
46
|
+
author
|
|
47
|
+
} = _ref2;
|
|
48
|
+
if (title) {
|
|
49
|
+
return title;
|
|
50
|
+
}
|
|
51
|
+
if (sourceType === DOCUMENTATION_SOURCE_TYPES.DOC.value) {
|
|
52
|
+
if (stage && group) {
|
|
53
|
+
return `${stage} / ${group}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (sourceType === DOCUMENTATION_SOURCE_TYPES.BLOG.value) {
|
|
57
|
+
if (date && author) {
|
|
58
|
+
return `${date} / ${author}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return i18n.MESSAGE_SOURCE;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/* script */
|
|
67
|
+
const __vue_script__ = script;
|
|
68
|
+
|
|
69
|
+
/* template */
|
|
70
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-mt-4 gl-mr-3 gl-text-gray-600",attrs:{"data-testid":"duo-chat-message-sources"}},[(_vm.sources.length)?_c('span',[_vm._v(_vm._s(_vm.sourceLabel)+":")]):_vm._e(),_vm._v(" "),_c('ul',{staticClass:"gl-list-style-none gl-p-0 gl-m-0"},_vm._l((_vm.sources),function(source,index){return _c('li',{key:index,staticClass:"gl-display-flex gl-pt-3 gl-align-items-center",attrs:{"data-testid":"source-list-item"}},[(source.source_type)?_c('gl-icon',{staticClass:"gl-flex-shrink-0 gl-mr-2",attrs:{"name":_vm.getSourceIcon(source.source_type)}}):_vm._e(),_vm._v(" "),_c('gl-link',{attrs:{"href":source.source_url}},[_vm._v(_vm._s(_vm.getSourceTitle(source)))])],1)}),0)])};
|
|
71
|
+
var __vue_staticRenderFns__ = [];
|
|
72
|
+
|
|
73
|
+
/* style */
|
|
74
|
+
const __vue_inject_styles__ = undefined;
|
|
75
|
+
/* scoped */
|
|
76
|
+
const __vue_scope_id__ = undefined;
|
|
77
|
+
/* module identifier */
|
|
78
|
+
const __vue_module_identifier__ = undefined;
|
|
79
|
+
/* functional template */
|
|
80
|
+
const __vue_is_functional_template__ = false;
|
|
81
|
+
/* style inject */
|
|
82
|
+
|
|
83
|
+
/* style inject SSR */
|
|
84
|
+
|
|
85
|
+
/* style inject shadow dom */
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
const __vue_component__ = __vue_normalize__(
|
|
90
|
+
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
|
91
|
+
__vue_inject_styles__,
|
|
92
|
+
__vue_script__,
|
|
93
|
+
__vue_scope_id__,
|
|
94
|
+
__vue_is_functional_template__,
|
|
95
|
+
__vue_module_identifier__,
|
|
96
|
+
false,
|
|
97
|
+
undefined,
|
|
98
|
+
undefined,
|
|
99
|
+
undefined
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
export default __vue_component__;
|
|
103
|
+
export { i18n };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { GlButton } from '../../../../../../index';
|
|
2
|
+
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
3
|
+
|
|
4
|
+
var script = {
|
|
5
|
+
name: 'GlDuoChatPredefinedPrompts',
|
|
6
|
+
components: {
|
|
7
|
+
GlButton
|
|
8
|
+
},
|
|
9
|
+
props: {
|
|
10
|
+
/**
|
|
11
|
+
* Array of predefined prompts to display. Every prompt should be a string which will be converted into a prompt when clicked.
|
|
12
|
+
*/
|
|
13
|
+
prompts: {
|
|
14
|
+
type: Array,
|
|
15
|
+
required: true
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
methods: {
|
|
19
|
+
handleClick(prompt) {
|
|
20
|
+
/**
|
|
21
|
+
* Emits the prompt string that was clicked.
|
|
22
|
+
*/
|
|
23
|
+
this.$emit('click', prompt);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/* script */
|
|
29
|
+
const __vue_script__ = script;
|
|
30
|
+
|
|
31
|
+
/* template */
|
|
32
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-text-right"},_vm._l((_vm.prompts),function(prompt,index){return _c('div',{key:("question-" + index),staticClass:"gl-mt-3"},[_c('gl-button',{attrs:{"category":"secondary","variant":"confirm"},on:{"click":function($event){return _vm.handleClick(prompt)}}},[_c('span',{staticClass:"gl-white-space-normal"},[_vm._v(_vm._s(prompt))])])],1)}),0)};
|
|
33
|
+
var __vue_staticRenderFns__ = [];
|
|
34
|
+
|
|
35
|
+
/* style */
|
|
36
|
+
const __vue_inject_styles__ = undefined;
|
|
37
|
+
/* scoped */
|
|
38
|
+
const __vue_scope_id__ = undefined;
|
|
39
|
+
/* module identifier */
|
|
40
|
+
const __vue_module_identifier__ = undefined;
|
|
41
|
+
/* functional template */
|
|
42
|
+
const __vue_is_functional_template__ = false;
|
|
43
|
+
/* style inject */
|
|
44
|
+
|
|
45
|
+
/* style inject SSR */
|
|
46
|
+
|
|
47
|
+
/* style inject shadow dom */
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const __vue_component__ = __vue_normalize__(
|
|
52
|
+
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
|
53
|
+
__vue_inject_styles__,
|
|
54
|
+
__vue_script__,
|
|
55
|
+
__vue_scope_id__,
|
|
56
|
+
__vue_is_functional_template__,
|
|
57
|
+
__vue_module_identifier__,
|
|
58
|
+
false,
|
|
59
|
+
undefined,
|
|
60
|
+
undefined,
|
|
61
|
+
undefined
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export default __vue_component__;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const DOCUMENTATION_SOURCE_TYPES = {
|
|
2
|
+
HANDBOOK: {
|
|
3
|
+
value: 'handbook',
|
|
4
|
+
icon: 'book'
|
|
5
|
+
},
|
|
6
|
+
DOC: {
|
|
7
|
+
value: 'doc',
|
|
8
|
+
icon: 'documents'
|
|
9
|
+
},
|
|
10
|
+
BLOG: {
|
|
11
|
+
value: 'blog',
|
|
12
|
+
icon: 'list-bulleted'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const MESSAGE_MODEL_ROLES = {
|
|
16
|
+
user: 'user',
|
|
17
|
+
system: 'system',
|
|
18
|
+
assistant: 'assistant'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES } from './constants';
|
|
2
|
+
|
|
3
|
+
const MOCK_SOURCES = [{
|
|
4
|
+
title: 'GitLab Handbook',
|
|
5
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value,
|
|
6
|
+
source_url: '/handbook/'
|
|
7
|
+
}, {
|
|
8
|
+
stage: 'Mock Stage',
|
|
9
|
+
group: 'Mock Group',
|
|
10
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.DOC.value,
|
|
11
|
+
source_url: '/company/team/'
|
|
12
|
+
}, {
|
|
13
|
+
date: '2023-04-21',
|
|
14
|
+
author: 'Test User',
|
|
15
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.BLOG.value,
|
|
16
|
+
source_url: '/blog/'
|
|
17
|
+
}];
|
|
18
|
+
const MOCK_RESPONSE_MESSAGE = {
|
|
19
|
+
id: '123',
|
|
20
|
+
content: '_Duo Chat message_ comming from AI',
|
|
21
|
+
contentHtml: '<p><em>Duo Chat message</em> comming from AI</p>',
|
|
22
|
+
role: MESSAGE_MODEL_ROLES.assistant,
|
|
23
|
+
extras: {
|
|
24
|
+
sources: MOCK_SOURCES
|
|
25
|
+
},
|
|
26
|
+
requestId: '987',
|
|
27
|
+
errors: [],
|
|
28
|
+
timestamp: '2021-04-21T12:00:00.000Z'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { MOCK_RESPONSE_MESSAGE };
|
package/dist/tokens/js/tokens.js
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
A simple component to list documentation sources for a documentation-related AI response messages.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { GlIcon, GlLink } from '../../../../../../index';
|
|
3
|
+
import { DOCUMENTATION_SOURCE_TYPES } from '../../constants';
|
|
4
|
+
import GlDuoChatMessageSources from './duo_chat_message_sources.vue';
|
|
5
|
+
|
|
6
|
+
const dummySourceBase = {
|
|
7
|
+
title: 'Foo',
|
|
8
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value,
|
|
9
|
+
stage: 'foo-stage',
|
|
10
|
+
group: 'bar-group',
|
|
11
|
+
date: new Date('December 31, 2020 23:59:59'),
|
|
12
|
+
author: 'Gregor Samsa',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('Duo Chat Message Sources', () => {
|
|
16
|
+
let wrapper;
|
|
17
|
+
|
|
18
|
+
const findListItems = () => wrapper.findAll('[data-testid="source-list-item"]');
|
|
19
|
+
const findSourceIcons = () => wrapper.findAllComponents(GlIcon);
|
|
20
|
+
const findSourceTitles = () => wrapper.findAllComponents(GlLink);
|
|
21
|
+
|
|
22
|
+
const createComponent = ({ propsData = {} } = {}) => {
|
|
23
|
+
wrapper = shallowMount(GlDuoChatMessageSources, {
|
|
24
|
+
propsData,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
it('does not render anything if sources is an empty Array', () => {
|
|
29
|
+
createComponent({
|
|
30
|
+
propsData: {
|
|
31
|
+
sources: [],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
expect(wrapper.text()).toBe('');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders sources passed down as a prop', () => {
|
|
38
|
+
createComponent({
|
|
39
|
+
propsData: {
|
|
40
|
+
sources: [
|
|
41
|
+
dummySourceBase,
|
|
42
|
+
{
|
|
43
|
+
...dummySourceBase,
|
|
44
|
+
title: 'Bar',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
expect(findListItems().length).toBe(2);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it.each`
|
|
53
|
+
type | expectedIcon
|
|
54
|
+
${DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value} | ${DOCUMENTATION_SOURCE_TYPES.HANDBOOK.icon}
|
|
55
|
+
${DOCUMENTATION_SOURCE_TYPES.DOC.value} | ${DOCUMENTATION_SOURCE_TYPES.DOC.icon}
|
|
56
|
+
${DOCUMENTATION_SOURCE_TYPES.BLOG.value} | ${DOCUMENTATION_SOURCE_TYPES.BLOG.icon}
|
|
57
|
+
${'foo'} | ${'document'}
|
|
58
|
+
`('renders the correct icon for $type type', ({ type, expectedIcon } = {}) => {
|
|
59
|
+
createComponent({
|
|
60
|
+
propsData: {
|
|
61
|
+
sources: [
|
|
62
|
+
{
|
|
63
|
+
...dummySourceBase,
|
|
64
|
+
source_type: type,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
expect(findSourceIcons().at(0).props('name')).toBe(expectedIcon);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it.each`
|
|
73
|
+
sourceExtension | expectedTitle
|
|
74
|
+
${{ title: 'Foo' }} | ${'Foo'}
|
|
75
|
+
${{ source_type: DOCUMENTATION_SOURCE_TYPES.DOC.value }} | ${`${dummySourceBase.stage} / ${dummySourceBase.group}`}
|
|
76
|
+
${{ source_type: DOCUMENTATION_SOURCE_TYPES.BLOG.value }} | ${`${dummySourceBase.date} / ${dummySourceBase.author}`}
|
|
77
|
+
${{}} | ${'Source'}
|
|
78
|
+
`('renders the correct title for $sourceExtension', ({ sourceExtension, expectedTitle } = {}) => {
|
|
79
|
+
createComponent({
|
|
80
|
+
propsData: {
|
|
81
|
+
sources: [
|
|
82
|
+
{
|
|
83
|
+
...dummySourceBase,
|
|
84
|
+
title: '',
|
|
85
|
+
...sourceExtension,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
expect(findSourceTitles().at(0).text()).toBe(expectedTitle);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MOCK_RESPONSE_MESSAGE } from '../../mock_data';
|
|
2
|
+
import GlDuoChatMessageSources from './duo_chat_message_sources.vue';
|
|
3
|
+
import readme from './duo_chat_message_sources.md';
|
|
4
|
+
|
|
5
|
+
const generateProps = ({ sources = [] } = {}) => ({
|
|
6
|
+
sources,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const Template = (args, { argTypes }) => ({
|
|
10
|
+
components: { GlDuoChatMessageSources },
|
|
11
|
+
props: Object.keys(argTypes),
|
|
12
|
+
template: `
|
|
13
|
+
<gl-duo-chat-message-sources :sources="sources" />
|
|
14
|
+
`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const Default = Template.bind({});
|
|
18
|
+
Default.args = generateProps({
|
|
19
|
+
sources: MOCK_RESPONSE_MESSAGE.extras.sources,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
title: 'experimental/duo/chat/duo_chat_message_sources',
|
|
24
|
+
component: GlDuoChatMessageSources,
|
|
25
|
+
parameters: {
|
|
26
|
+
docs: {
|
|
27
|
+
description: {
|
|
28
|
+
component: readme,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { GlIcon, GlLink } from '../../../../../../index';
|
|
3
|
+
import { DOCUMENTATION_SOURCE_TYPES } from '../../constants';
|
|
4
|
+
|
|
5
|
+
export const i18n = {
|
|
6
|
+
MESSAGE_SOURCE: 'Source',
|
|
7
|
+
MESSAGE_SOURCES: 'Sources',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: 'GlDuoChatMessageSources',
|
|
12
|
+
components: {
|
|
13
|
+
GlIcon,
|
|
14
|
+
GlLink,
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
/**
|
|
18
|
+
* The Array of the message sources.
|
|
19
|
+
*/
|
|
20
|
+
sources: {
|
|
21
|
+
type: Array,
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
computed: {
|
|
26
|
+
sourceLabel() {
|
|
27
|
+
return this.sources.length > 1 ? i18n.MESSAGE_SOURCES : i18n.MESSAGE_SOURCES;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
methods: {
|
|
31
|
+
getSourceIcon(sourceType) {
|
|
32
|
+
const currentSourceType = Object.values(DOCUMENTATION_SOURCE_TYPES).find(
|
|
33
|
+
({ value }) => value === sourceType
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return currentSourceType?.icon || 'document';
|
|
37
|
+
},
|
|
38
|
+
getSourceTitle({ title, source_type: sourceType, stage, group, date, author }) {
|
|
39
|
+
if (title) {
|
|
40
|
+
return title;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (sourceType === DOCUMENTATION_SOURCE_TYPES.DOC.value) {
|
|
44
|
+
if (stage && group) {
|
|
45
|
+
return `${stage} / ${group}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (sourceType === DOCUMENTATION_SOURCE_TYPES.BLOG.value) {
|
|
50
|
+
if (date && author) {
|
|
51
|
+
return `${date} / ${author}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return i18n.MESSAGE_SOURCE;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
</script>
|
|
60
|
+
<template>
|
|
61
|
+
<div class="gl-mt-4 gl-mr-3 gl-text-gray-600" data-testid="duo-chat-message-sources">
|
|
62
|
+
<span v-if="sources.length">{{ sourceLabel }}:</span>
|
|
63
|
+
|
|
64
|
+
<ul class="gl-list-style-none gl-p-0 gl-m-0">
|
|
65
|
+
<li
|
|
66
|
+
v-for="(source, index) in sources"
|
|
67
|
+
:key="index"
|
|
68
|
+
class="gl-display-flex gl-pt-3 gl-align-items-center"
|
|
69
|
+
data-testid="source-list-item"
|
|
70
|
+
>
|
|
71
|
+
<gl-icon
|
|
72
|
+
v-if="source.source_type"
|
|
73
|
+
:name="getSourceIcon(source.source_type)"
|
|
74
|
+
class="gl-flex-shrink-0 gl-mr-2"
|
|
75
|
+
/>
|
|
76
|
+
<gl-link :href="source.source_url">{{ getSourceTitle(source) }}</gl-link>
|
|
77
|
+
</li>
|
|
78
|
+
</ul>
|
|
79
|
+
</div>
|
|
80
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
The component is a simple list of strings representing possible prompts to AI.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { GlButton } from '../../../../../../index';
|
|
3
|
+
import GlDuoChatPredefinedPrompts from './duo_chat_predefined_prompts.vue';
|
|
4
|
+
|
|
5
|
+
describe('GlDuoChatPredefinedPrompts', () => {
|
|
6
|
+
let wrapper;
|
|
7
|
+
const predefinedPrompt1 = 'foo';
|
|
8
|
+
const predefinedPrompt2 = 'bar';
|
|
9
|
+
|
|
10
|
+
const createComponent = () => {
|
|
11
|
+
wrapper = shallowMount(GlDuoChatPredefinedPrompts, {
|
|
12
|
+
propsData: {
|
|
13
|
+
prompts: [predefinedPrompt1, predefinedPrompt2],
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const findButtons = () => wrapper.findAllComponents(GlButton);
|
|
19
|
+
|
|
20
|
+
it('renders a button for each predefined prompt', () => {
|
|
21
|
+
createComponent();
|
|
22
|
+
|
|
23
|
+
expect(findButtons()).toHaveLength(2);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('emits the click event when a button is clicked', () => {
|
|
27
|
+
createComponent();
|
|
28
|
+
|
|
29
|
+
findButtons().at(0).vm.$emit('click');
|
|
30
|
+
expect(wrapper.emitted('click')).toEqual([[predefinedPrompt1]]);
|
|
31
|
+
|
|
32
|
+
findButtons().at(1).vm.$emit('click');
|
|
33
|
+
expect(wrapper.emitted('click')).toEqual([[predefinedPrompt1], [predefinedPrompt2]]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import GlDuoChatPredefinedPrompts from './duo_chat_predefined_prompts.vue';
|
|
2
|
+
import readme from './duo_chat_predefined_prompts.md';
|
|
3
|
+
|
|
4
|
+
const generateProps = ({ prompts = [] } = {}) => ({
|
|
5
|
+
prompts,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const Template = (args, { argTypes }) => ({
|
|
9
|
+
components: { GlDuoChatPredefinedPrompts },
|
|
10
|
+
props: Object.keys(argTypes),
|
|
11
|
+
template: `
|
|
12
|
+
<gl-duo-chat-predefined-prompts :prompts="prompts" />
|
|
13
|
+
`,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const Default = Template.bind({});
|
|
17
|
+
Default.args = generateProps({
|
|
18
|
+
prompts: [
|
|
19
|
+
'How do I change my password in GitLab?',
|
|
20
|
+
'How do I fork a project?',
|
|
21
|
+
'How do I clone a repository?',
|
|
22
|
+
'How do I create a template?',
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
title: 'experimental/duo/chat/duo_chat_predefined_prompts',
|
|
28
|
+
component: GlDuoChatPredefinedPrompts,
|
|
29
|
+
parameters: {
|
|
30
|
+
docs: {
|
|
31
|
+
description: {
|
|
32
|
+
component: readme,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { GlButton } from '../../../../../../index';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: 'GlDuoChatPredefinedPrompts',
|
|
6
|
+
components: {
|
|
7
|
+
GlButton,
|
|
8
|
+
},
|
|
9
|
+
props: {
|
|
10
|
+
/**
|
|
11
|
+
* Array of predefined prompts to display. Every prompt should be a string which will be converted into a prompt when clicked.
|
|
12
|
+
*/
|
|
13
|
+
prompts: {
|
|
14
|
+
type: Array,
|
|
15
|
+
required: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
methods: {
|
|
19
|
+
handleClick(prompt) {
|
|
20
|
+
/**
|
|
21
|
+
* Emits the prompt string that was clicked.
|
|
22
|
+
*/
|
|
23
|
+
this.$emit('click', prompt);
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
</script>
|
|
28
|
+
<template>
|
|
29
|
+
<div class="gl-text-right">
|
|
30
|
+
<div v-for="(prompt, index) in prompts" :key="`question-${index}`" class="gl-mt-3">
|
|
31
|
+
<gl-button category="secondary" variant="confirm" @click="handleClick(prompt)"
|
|
32
|
+
><span class="gl-white-space-normal">{{ prompt }}</span></gl-button
|
|
33
|
+
>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const DOCUMENTATION_SOURCE_TYPES = {
|
|
2
|
+
HANDBOOK: {
|
|
3
|
+
value: 'handbook',
|
|
4
|
+
icon: 'book',
|
|
5
|
+
},
|
|
6
|
+
DOC: {
|
|
7
|
+
value: 'doc',
|
|
8
|
+
icon: 'documents',
|
|
9
|
+
},
|
|
10
|
+
BLOG: {
|
|
11
|
+
value: 'blog',
|
|
12
|
+
icon: 'list-bulleted',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const MESSAGE_MODEL_ROLES = {
|
|
17
|
+
user: 'user',
|
|
18
|
+
system: 'system',
|
|
19
|
+
assistant: 'assistant',
|
|
20
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES } from './constants';
|
|
2
|
+
|
|
3
|
+
const MOCK_SOURCES = [
|
|
4
|
+
{
|
|
5
|
+
title: 'GitLab Handbook',
|
|
6
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value,
|
|
7
|
+
source_url: '/handbook/',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
stage: 'Mock Stage',
|
|
11
|
+
group: 'Mock Group',
|
|
12
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.DOC.value,
|
|
13
|
+
source_url: '/company/team/',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
date: '2023-04-21',
|
|
17
|
+
author: 'Test User',
|
|
18
|
+
source_type: DOCUMENTATION_SOURCE_TYPES.BLOG.value,
|
|
19
|
+
source_url: '/blog/',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export const MOCK_RESPONSE_MESSAGE = {
|
|
24
|
+
id: '123',
|
|
25
|
+
content: '_Duo Chat message_ comming from AI',
|
|
26
|
+
contentHtml: '<p><em>Duo Chat message</em> comming from AI</p>',
|
|
27
|
+
role: MESSAGE_MODEL_ROLES.assistant,
|
|
28
|
+
extras: {
|
|
29
|
+
sources: MOCK_SOURCES,
|
|
30
|
+
},
|
|
31
|
+
requestId: '987',
|
|
32
|
+
errors: [],
|
|
33
|
+
timestamp: '2021-04-21T12:00:00.000Z',
|
|
34
|
+
};
|