@coveo/quantic 3.40.0 → 3.41.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/force-app/main/default/labels/CustomLabels.labels-meta.xml +77 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/__tests__/quanticGeneratedAnswerBody.test.js +341 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/quanticGeneratedAnswerBody.js +148 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/quanticGeneratedAnswerBody.js-meta.xml +5 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/templates/answer.css +3 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/templates/answer.html +53 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/templates/cannotAnswer.html +7 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/templates/error.html +7 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/__tests__/quanticGeneratedAnswerStreamOfThought.test.js +348 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/quanticGeneratedAnswerStreamOfThought.css +17 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/quanticGeneratedAnswerStreamOfThought.js +163 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/quanticGeneratedAnswerStreamOfThought.js-meta.xml +5 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/templates/collapsedSummary.css +1 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/templates/collapsedSummary.html +32 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/templates/streamOfThought.css +1 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerStreamOfThought/templates/streamOfThought.html +65 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerThread/__tests__/quanticGeneratedAnswerThread.test.js +285 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerThread/quanticGeneratedAnswerThread.css +47 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerThread/quanticGeneratedAnswerThread.html +67 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerThread/quanticGeneratedAnswerThread.js +93 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerThread/quanticGeneratedAnswerThread.js-meta.xml +5 -0
- package/force-app/main/default/lwc/quanticThreadItem/quanticThreadItem.css +0 -4
- package/force-app/main/default/lwc/quanticThreadItem/quanticThreadItem.html +1 -1
- package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +6 -6
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/commerce/common/pagination.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/core/generated-answer/headless-core-generated-answer.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/core/generated-answer/headless-core-interactive-citation.d.ts +3 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/generated-answer/interactive-citation-analytics-client.d.ts +3 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/analytics/analytics-utils.d.ts +3 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-analytics-actions.d.ts +2 -0
- package/force-app/main/default/staticresources/coveoheadless/headless.js +17 -17
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +7 -7
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +14 -14
- package/package.json +2 -2
|
@@ -455,6 +455,13 @@
|
|
|
455
455
|
<protected>false</protected>
|
|
456
456
|
<shortDescription>Collapse [component label]</shortDescription>
|
|
457
457
|
</labels>
|
|
458
|
+
<labels>
|
|
459
|
+
<fullName>quantic_CollapseButton</fullName>
|
|
460
|
+
<value>Collapse</value>
|
|
461
|
+
<language>en_US</language>
|
|
462
|
+
<protected>false</protected>
|
|
463
|
+
<shortDescription>Collapse</shortDescription>
|
|
464
|
+
</labels>
|
|
458
465
|
<labels>
|
|
459
466
|
<fullName>quantic_Expand</fullName>
|
|
460
467
|
<value>Expand {{0}}</value>
|
|
@@ -1288,6 +1295,13 @@
|
|
|
1288
1295
|
<protected>false</protected>
|
|
1289
1296
|
<shortDescription>Something went wrong and we couldn't generate an answer.</shortDescription>
|
|
1290
1297
|
</labels>
|
|
1298
|
+
<labels>
|
|
1299
|
+
<fullName>quantic_GeneratedAnswerErrorTurnLimitReached</fullName>
|
|
1300
|
+
<value>Conversation turn limit reached. Please start a new conversation.</value>
|
|
1301
|
+
<language>en_US</language>
|
|
1302
|
+
<protected>false</protected>
|
|
1303
|
+
<shortDescription>Generated answer conversation turn limit reached error.</shortDescription>
|
|
1304
|
+
</labels>
|
|
1291
1305
|
<labels>
|
|
1292
1306
|
<fullName>quantic_ShowingResultsFor</fullName>
|
|
1293
1307
|
<value>Showing results for {{0}}</value>
|
|
@@ -1638,4 +1652,67 @@
|
|
|
1638
1652
|
<protected>false</protected>
|
|
1639
1653
|
<shortDescription>Submit follow-up</shortDescription>
|
|
1640
1654
|
</labels>
|
|
1655
|
+
<labels>
|
|
1656
|
+
<fullName>quantic_ShowPreviousQuestions_plural</fullName>
|
|
1657
|
+
<value>Show {{0}} previous questions</value>
|
|
1658
|
+
<language>en_US</language>
|
|
1659
|
+
<protected>false</protected>
|
|
1660
|
+
<shortDescription>Show previous questions (plural)</shortDescription>
|
|
1661
|
+
</labels>
|
|
1662
|
+
<labels>
|
|
1663
|
+
<fullName>quantic_AgentGenerationStepAnalyzingQuestion</fullName>
|
|
1664
|
+
<value>Analyzing your question…</value>
|
|
1665
|
+
<language>en_US</language>
|
|
1666
|
+
<protected>false</protected>
|
|
1667
|
+
<shortDescription>Analyzing your question</shortDescription>
|
|
1668
|
+
</labels>
|
|
1669
|
+
<labels>
|
|
1670
|
+
<fullName>quantic_AgentGenerationStepAnalyzingQuestionCompleted</fullName>
|
|
1671
|
+
<value>Question analyzed</value>
|
|
1672
|
+
<language>en_US</language>
|
|
1673
|
+
<protected>false</protected>
|
|
1674
|
+
<shortDescription>Question analyzed</shortDescription>
|
|
1675
|
+
</labels>
|
|
1676
|
+
<labels>
|
|
1677
|
+
<fullName>quantic_AgentGenerationStepSearch</fullName>
|
|
1678
|
+
<value>Searching knowledge base…</value>
|
|
1679
|
+
<language>en_US</language>
|
|
1680
|
+
<protected>false</protected>
|
|
1681
|
+
<shortDescription>Searching knowledge base…</shortDescription>
|
|
1682
|
+
</labels>
|
|
1683
|
+
<labels>
|
|
1684
|
+
<fullName>quantic_AgentGenerationStepSearchCompleted</fullName>
|
|
1685
|
+
<value>Knowledge base searched</value>
|
|
1686
|
+
<language>en_US</language>
|
|
1687
|
+
<protected>false</protected>
|
|
1688
|
+
<shortDescription>Knowledge base searched</shortDescription>
|
|
1689
|
+
</labels>
|
|
1690
|
+
<labels>
|
|
1691
|
+
<fullName>quantic_AgentGenerationStepAnalyzingResults</fullName>
|
|
1692
|
+
<value>Analyzing results…</value>
|
|
1693
|
+
<language>en_US</language>
|
|
1694
|
+
<protected>false</protected>
|
|
1695
|
+
<shortDescription>Analyzing results…</shortDescription>
|
|
1696
|
+
</labels>
|
|
1697
|
+
<labels>
|
|
1698
|
+
<fullName>quantic_AgentGenerationStepAnalyzingResultsCompleted</fullName>
|
|
1699
|
+
<value>Results analyzed</value>
|
|
1700
|
+
<language>en_US</language>
|
|
1701
|
+
<protected>false</protected>
|
|
1702
|
+
<shortDescription>Results analyzed</shortDescription>
|
|
1703
|
+
</labels>
|
|
1704
|
+
<labels>
|
|
1705
|
+
<fullName>quantic_AgentGenerationStepAnswering</fullName>
|
|
1706
|
+
<value>Generating answer…</value>
|
|
1707
|
+
<language>en_US</language>
|
|
1708
|
+
<protected>false</protected>
|
|
1709
|
+
<shortDescription>Generating answer…</shortDescription>
|
|
1710
|
+
</labels>
|
|
1711
|
+
<labels>
|
|
1712
|
+
<fullName>quantic_AgentGenerationStepAnsweringCompleted</fullName>
|
|
1713
|
+
<value>Answer generated</value>
|
|
1714
|
+
<language>en_US</language>
|
|
1715
|
+
<protected>false</protected>
|
|
1716
|
+
<shortDescription>Answer generated</shortDescription>
|
|
1717
|
+
</labels>
|
|
1641
1718
|
</CustomLabels>
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import QuanticGeneratedAnswerBody from 'c/quanticGeneratedAnswerBody';
|
|
3
|
+
import {buildCreateTestComponent, cleanup, flushPromises} from 'c/testUtils';
|
|
4
|
+
|
|
5
|
+
jest.mock('c/quanticHeadlessLoader');
|
|
6
|
+
jest.mock('c/quanticUtils', () => ({
|
|
7
|
+
loadMarkdownDependencies: jest.fn(() => Promise.resolve()),
|
|
8
|
+
transformMarkdownToHtml: jest.fn((answer) => answer),
|
|
9
|
+
LinkUtils: {
|
|
10
|
+
bindAnalyticsToLink: jest.fn(() => jest.fn()),
|
|
11
|
+
},
|
|
12
|
+
generateTextFragmentUrl: jest.fn((uri) => uri),
|
|
13
|
+
}));
|
|
14
|
+
jest.mock(
|
|
15
|
+
'@salesforce/label/c.quantic_CouldNotGenerateAnAnswer',
|
|
16
|
+
() => ({default: 'Could not generate an answer.'}),
|
|
17
|
+
{virtual: true}
|
|
18
|
+
);
|
|
19
|
+
jest.mock(
|
|
20
|
+
'@salesforce/label/c.quantic_GenericErrorTitle',
|
|
21
|
+
() => ({
|
|
22
|
+
default:
|
|
23
|
+
'Something went wrong while generating the answer. Please try again later.',
|
|
24
|
+
}),
|
|
25
|
+
{virtual: true}
|
|
26
|
+
);
|
|
27
|
+
jest.mock(
|
|
28
|
+
'@salesforce/label/c.quantic_GeneratedAnswerErrorTurnLimitReached',
|
|
29
|
+
() => ({
|
|
30
|
+
default:
|
|
31
|
+
'Conversation turn limit reached. Please start a new conversation.',
|
|
32
|
+
}),
|
|
33
|
+
{virtual: true}
|
|
34
|
+
);
|
|
35
|
+
jest.mock(
|
|
36
|
+
'@salesforce/label/c.quantic_ThisAnswerWasHelpful',
|
|
37
|
+
() => ({default: 'This answer was helpful'}),
|
|
38
|
+
{virtual: true}
|
|
39
|
+
);
|
|
40
|
+
jest.mock(
|
|
41
|
+
'@salesforce/label/c.quantic_ThisAnswerWasNotHelpful',
|
|
42
|
+
() => ({default: 'This answer was not helpful'}),
|
|
43
|
+
{virtual: true}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const defaultOptions = {
|
|
47
|
+
engineId: 'example-engine',
|
|
48
|
+
generatedAnswer: {
|
|
49
|
+
answerId: 'answer-1',
|
|
50
|
+
question: 'What is the meaning of life?',
|
|
51
|
+
answer: 'Example generated answer',
|
|
52
|
+
answerContentFormat: 'text/plain',
|
|
53
|
+
citations: [],
|
|
54
|
+
isStreaming: false,
|
|
55
|
+
liked: false,
|
|
56
|
+
disliked: false,
|
|
57
|
+
cannotAnswer: false,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const selectors = {
|
|
62
|
+
body: '[data-testid="generated-answer-body"]',
|
|
63
|
+
actions: '[data-testid="generated-answer-body__actions"]',
|
|
64
|
+
citations: 'c-quantic-source-citations',
|
|
65
|
+
feedback: 'c-quantic-feedback',
|
|
66
|
+
copy: 'c-quantic-generated-answer-copy-to-clipboard',
|
|
67
|
+
error: '[data-testid="generated-answer-body__error"]',
|
|
68
|
+
noAnswer: '[data-testid="generated-answer-body__no-answer-message"]',
|
|
69
|
+
content: 'c-quantic-generated-answer-content',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const createTestComponent = buildCreateTestComponent(
|
|
73
|
+
QuanticGeneratedAnswerBody,
|
|
74
|
+
'c-quantic-generated-answer-body',
|
|
75
|
+
defaultOptions
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
describe('c-quantic-generated-answer-body', () => {
|
|
79
|
+
afterEach(() => {
|
|
80
|
+
cleanup();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should pass answer and answerContentFormat to the QuanticGeneratedAnswerContent component', async () => {
|
|
84
|
+
const element = createTestComponent();
|
|
85
|
+
await flushPromises();
|
|
86
|
+
|
|
87
|
+
const content = element.shadowRoot.querySelector(selectors.content);
|
|
88
|
+
|
|
89
|
+
expect(content.answer).toBe(defaultOptions.generatedAnswer.answer);
|
|
90
|
+
expect(content.answerContentFormat).toBe(
|
|
91
|
+
defaultOptions.generatedAnswer.answerContentFormat
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should send the answerId within event details when dispatching the #quantic__generatedanswerlike event', async () => {
|
|
96
|
+
const element = createTestComponent();
|
|
97
|
+
const handler = jest.fn();
|
|
98
|
+
element.addEventListener('quantic__generatedanswerlike', handler);
|
|
99
|
+
await flushPromises();
|
|
100
|
+
|
|
101
|
+
const feedback = element.shadowRoot.querySelector(selectors.feedback);
|
|
102
|
+
feedback.dispatchEvent(new CustomEvent('quantic__like'));
|
|
103
|
+
|
|
104
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect(handler.mock.calls[0][0].detail).toEqual({answerId: 'answer-1'});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should send the answerId within event details when dispatching the #quantic__generatedanswerdislike event', async () => {
|
|
109
|
+
const element = createTestComponent();
|
|
110
|
+
const handler = jest.fn();
|
|
111
|
+
element.addEventListener('quantic__generatedanswerdislike', handler);
|
|
112
|
+
await flushPromises();
|
|
113
|
+
|
|
114
|
+
const feedback = element.shadowRoot.querySelector(selectors.feedback);
|
|
115
|
+
feedback.dispatchEvent(new CustomEvent('quantic__dislike'));
|
|
116
|
+
|
|
117
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
118
|
+
expect(handler.mock.calls[0][0].detail).toEqual({answerId: 'answer-1'});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should pass the answerId to the copy-to-clipboard component', async () => {
|
|
122
|
+
const element = createTestComponent();
|
|
123
|
+
await flushPromises();
|
|
124
|
+
|
|
125
|
+
const copy = element.shadowRoot.querySelector(selectors.copy);
|
|
126
|
+
|
|
127
|
+
expect(copy.answerId).toBe('answer-1');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should send the answerId within event details when dispatching the #quantic__citationhover event', async () => {
|
|
131
|
+
const element = createTestComponent({
|
|
132
|
+
...defaultOptions,
|
|
133
|
+
generatedAnswer: {
|
|
134
|
+
...defaultOptions.generatedAnswer,
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
citations: [{id: 'citation-1', title: 'Citation'}],
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
const handler = jest.fn();
|
|
140
|
+
element.addEventListener('quantic__citationhover', handler);
|
|
141
|
+
await flushPromises();
|
|
142
|
+
|
|
143
|
+
const citations = element.shadowRoot.querySelector(
|
|
144
|
+
'c-quantic-source-citations'
|
|
145
|
+
);
|
|
146
|
+
citations.citationHoverHandler('citation-1', 1200);
|
|
147
|
+
|
|
148
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
149
|
+
expect(handler.mock.calls[0][0].detail).toEqual({
|
|
150
|
+
answerId: 'answer-1',
|
|
151
|
+
citationId: 'citation-1',
|
|
152
|
+
citationHoverTimeMs: 1200,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe('when an answer has not been generated', () => {
|
|
157
|
+
it('should render the no-answer message when the answer cannot be generated', async () => {
|
|
158
|
+
const element = createTestComponent({
|
|
159
|
+
...defaultOptions,
|
|
160
|
+
generatedAnswer: {
|
|
161
|
+
...defaultOptions.generatedAnswer,
|
|
162
|
+
cannotAnswer: true,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
await flushPromises();
|
|
166
|
+
|
|
167
|
+
const noAnswer = element.shadowRoot.querySelector(selectors.noAnswer);
|
|
168
|
+
|
|
169
|
+
expect(noAnswer).not.toBeNull();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('when an error occurs', () => {
|
|
174
|
+
it('should render the generic error message when a non-retryable error occurs', async () => {
|
|
175
|
+
const element = createTestComponent({
|
|
176
|
+
...defaultOptions,
|
|
177
|
+
generatedAnswer: {
|
|
178
|
+
...defaultOptions.generatedAnswer,
|
|
179
|
+
answer: '',
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
error: {code: 500},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
await flushPromises();
|
|
185
|
+
|
|
186
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
187
|
+
|
|
188
|
+
expect(error).not.toBeNull();
|
|
189
|
+
expect(error.textContent).toContain(
|
|
190
|
+
'Something went wrong while generating the answer. Please try again later.'
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should render the turn limit reached error message when the SSE turn limit is exceeded', async () => {
|
|
195
|
+
const element = createTestComponent({
|
|
196
|
+
...defaultOptions,
|
|
197
|
+
generatedAnswer: {
|
|
198
|
+
...defaultOptions.generatedAnswer,
|
|
199
|
+
answer: '',
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
error: {
|
|
202
|
+
code: 429,
|
|
203
|
+
isSseTurnLimitReachedError: () => true,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
await flushPromises();
|
|
208
|
+
|
|
209
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
210
|
+
|
|
211
|
+
expect(error).not.toBeNull();
|
|
212
|
+
expect(error.textContent).toContain(
|
|
213
|
+
'Conversation turn limit reached. Please start a new conversation.'
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('should render the error message even when the answer is not empty', async () => {
|
|
218
|
+
const element = createTestComponent({
|
|
219
|
+
...defaultOptions,
|
|
220
|
+
generatedAnswer: {
|
|
221
|
+
...defaultOptions.generatedAnswer,
|
|
222
|
+
answer: 'Partial answer content',
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
error: {code: 500},
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
await flushPromises();
|
|
228
|
+
|
|
229
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
230
|
+
const content = element.shadowRoot.querySelector(selectors.content);
|
|
231
|
+
|
|
232
|
+
expect(error).not.toBeNull();
|
|
233
|
+
expect(content).toBeNull();
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe('rendering of actions', () => {
|
|
238
|
+
it('should display actions when the answer is not empty and done streaming', async () => {
|
|
239
|
+
const element = createTestComponent();
|
|
240
|
+
await flushPromises();
|
|
241
|
+
|
|
242
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
243
|
+
|
|
244
|
+
expect(actions).not.toBeNull();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('should not display actions while the answer is streaming', async () => {
|
|
248
|
+
const element = createTestComponent({
|
|
249
|
+
...defaultOptions,
|
|
250
|
+
generatedAnswer: {
|
|
251
|
+
...defaultOptions.generatedAnswer,
|
|
252
|
+
isStreaming: true,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
await flushPromises();
|
|
256
|
+
|
|
257
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
258
|
+
|
|
259
|
+
expect(actions).toBeNull();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should not display actions when there is no answer', async () => {
|
|
263
|
+
const element = createTestComponent({
|
|
264
|
+
...defaultOptions,
|
|
265
|
+
generatedAnswer: {
|
|
266
|
+
...defaultOptions.generatedAnswer,
|
|
267
|
+
answer: '',
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
await flushPromises();
|
|
271
|
+
|
|
272
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
273
|
+
|
|
274
|
+
expect(actions).toBeNull();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('rendering of citations', () => {
|
|
279
|
+
it('should display citations when citations are not empty', async () => {
|
|
280
|
+
const element = createTestComponent({
|
|
281
|
+
...defaultOptions,
|
|
282
|
+
generatedAnswer: {
|
|
283
|
+
...defaultOptions.generatedAnswer,
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
citations: [{id: 'citation-1', title: 'Citation'}],
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
await flushPromises();
|
|
289
|
+
|
|
290
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
291
|
+
|
|
292
|
+
expect(citations).not.toBeNull();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('should not display citations when citations are empty', async () => {
|
|
296
|
+
const element = createTestComponent();
|
|
297
|
+
await flushPromises();
|
|
298
|
+
|
|
299
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
300
|
+
|
|
301
|
+
expect(citations).toBeNull();
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('should not display citations while the answer is streaming', async () => {
|
|
305
|
+
const element = createTestComponent({
|
|
306
|
+
...defaultOptions,
|
|
307
|
+
generatedAnswer: {
|
|
308
|
+
...defaultOptions.generatedAnswer,
|
|
309
|
+
// @ts-ignore
|
|
310
|
+
citations: [{id: 'citation-1', title: 'Citation'}],
|
|
311
|
+
isStreaming: true,
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
await flushPromises();
|
|
315
|
+
|
|
316
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
317
|
+
|
|
318
|
+
expect(citations).toBeNull();
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe('when generatedAnswer is null', () => {
|
|
323
|
+
it('should render without errors', async () => {
|
|
324
|
+
const element = createTestComponent({
|
|
325
|
+
...defaultOptions,
|
|
326
|
+
generatedAnswer: null,
|
|
327
|
+
});
|
|
328
|
+
await flushPromises();
|
|
329
|
+
|
|
330
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
331
|
+
const noAnswer = element.shadowRoot.querySelector(selectors.noAnswer);
|
|
332
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
333
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
334
|
+
|
|
335
|
+
expect(error).toBeNull();
|
|
336
|
+
expect(noAnswer).toBeNull();
|
|
337
|
+
expect(actions).toBeNull();
|
|
338
|
+
expect(citations).toBeNull();
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import couldNotGenerateAnAnswer from '@salesforce/label/c.quantic_CouldNotGenerateAnAnswer';
|
|
2
|
+
import generatedAnswerErrorTurnLimitReached from '@salesforce/label/c.quantic_GeneratedAnswerErrorTurnLimitReached';
|
|
3
|
+
import genericErrorTitle from '@salesforce/label/c.quantic_GenericErrorTitle';
|
|
4
|
+
import thisAnswerWasHelpful from '@salesforce/label/c.quantic_ThisAnswerWasHelpful';
|
|
5
|
+
import thisAnswerWasNotHelpful from '@salesforce/label/c.quantic_ThisAnswerWasNotHelpful';
|
|
6
|
+
import {LightningElement, api} from 'lwc';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import answerTemplate from './templates/answer.html';
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import cannotAnswerTemplate from './templates/cannotAnswer.html';
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
import errorTemplate from './templates/error.html';
|
|
13
|
+
|
|
14
|
+
/** @typedef {import("@coveo/headless").GeneratedAnswerBase} GeneratedAnswerBase */
|
|
15
|
+
|
|
16
|
+
const FEEDBACK_NEUTRAL_STATE = 'neutral';
|
|
17
|
+
const FEEDBACK_LIKED_STATE = 'liked';
|
|
18
|
+
const FEEDBACK_DISLIKED_STATE = 'disliked';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The `QuanticGeneratedAnswerBody` component renders a single generated answer unit.
|
|
22
|
+
* @category Internal
|
|
23
|
+
* @fires CustomEvent#quantic__generatedanswerlike
|
|
24
|
+
* @fires CustomEvent#quantic__generatedanswerdislike
|
|
25
|
+
* @fires CustomEvent#quantic__generatedanswercopy
|
|
26
|
+
* @fires CustomEvent#quantic__citationhover
|
|
27
|
+
*/
|
|
28
|
+
export default class QuanticGeneratedAnswerBody extends LightningElement {
|
|
29
|
+
/**
|
|
30
|
+
* The ID of the engine instance the component registers to.
|
|
31
|
+
* @api
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
34
|
+
@api engineId;
|
|
35
|
+
/**
|
|
36
|
+
* The generated answer object to render.
|
|
37
|
+
* @api
|
|
38
|
+
* @type {GeneratedAnswerBase}
|
|
39
|
+
*/
|
|
40
|
+
@api generatedAnswer;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to disable citation anchoring.
|
|
43
|
+
* @api
|
|
44
|
+
* @type {boolean}
|
|
45
|
+
*/
|
|
46
|
+
@api disableCitationAnchoring = false;
|
|
47
|
+
|
|
48
|
+
labels = {
|
|
49
|
+
couldNotGenerateAnAnswer,
|
|
50
|
+
generatedAnswerErrorTurnLimitReached,
|
|
51
|
+
genericErrorTitle,
|
|
52
|
+
thisAnswerWasHelpful,
|
|
53
|
+
thisAnswerWasNotHelpful,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
get answer() {
|
|
57
|
+
return this.generatedAnswer?.answer;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get citations() {
|
|
61
|
+
return this.generatedAnswer?.citations || [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get answerId() {
|
|
65
|
+
return this.generatedAnswer?.answerId;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get answerContentFormat() {
|
|
69
|
+
return this.generatedAnswer?.answerContentFormat;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get isStreaming() {
|
|
73
|
+
return !!this.generatedAnswer?.isStreaming;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get hasError() {
|
|
77
|
+
return !!this.generatedAnswer?.error?.code;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get cannotAnswer() {
|
|
81
|
+
return !!this.generatedAnswer?.cannotAnswer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get errorMessage() {
|
|
85
|
+
if (this.generatedAnswer?.error?.isSseTurnLimitReachedError?.()) {
|
|
86
|
+
return this.labels.generatedAnswerErrorTurnLimitReached;
|
|
87
|
+
}
|
|
88
|
+
return this.labels.genericErrorTitle;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get computedFeedbackState() {
|
|
92
|
+
if (this.generatedAnswer?.liked) {
|
|
93
|
+
return FEEDBACK_LIKED_STATE;
|
|
94
|
+
}
|
|
95
|
+
if (this.generatedAnswer?.disliked) {
|
|
96
|
+
return FEEDBACK_DISLIKED_STATE;
|
|
97
|
+
}
|
|
98
|
+
return FEEDBACK_NEUTRAL_STATE;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get shouldShowCitations() {
|
|
102
|
+
return this.citations.length > 0 && !this.isStreaming;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get shouldShowActions() {
|
|
106
|
+
return Boolean(this.answer) && !this.isStreaming;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
handleLike(event) {
|
|
110
|
+
event.stopPropagation();
|
|
111
|
+
this.dispatchAnswerInteractionEvent('quantic__generatedanswerlike');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
handleDislike(event) {
|
|
115
|
+
event.stopPropagation();
|
|
116
|
+
this.dispatchAnswerInteractionEvent('quantic__generatedanswerdislike');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
handleCitationHover = (citationId, citationHoverTimeMs) => {
|
|
120
|
+
this.dispatchAnswerInteractionEvent('quantic__citationhover', {
|
|
121
|
+
citationId,
|
|
122
|
+
citationHoverTimeMs,
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
dispatchAnswerInteractionEvent(eventName, payload = {}) {
|
|
127
|
+
this.dispatchEvent(
|
|
128
|
+
new CustomEvent(eventName, {
|
|
129
|
+
detail: {
|
|
130
|
+
answerId: this.answerId,
|
|
131
|
+
...payload,
|
|
132
|
+
},
|
|
133
|
+
bubbles: true,
|
|
134
|
+
composed: true,
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
render() {
|
|
140
|
+
if (this.hasError) {
|
|
141
|
+
return errorTemplate;
|
|
142
|
+
}
|
|
143
|
+
if (this.cannotAnswer) {
|
|
144
|
+
return cannotAnswerTemplate;
|
|
145
|
+
}
|
|
146
|
+
return answerTemplate;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section
|
|
3
|
+
data-testid="generated-answer-body"
|
|
4
|
+
class="generated-answer__body"
|
|
5
|
+
>
|
|
6
|
+
<c-quantic-generated-answer-content
|
|
7
|
+
answer-content-format={answerContentFormat}
|
|
8
|
+
answer={answer}
|
|
9
|
+
is-streaming={isStreaming}
|
|
10
|
+
>
|
|
11
|
+
</c-quantic-generated-answer-content>
|
|
12
|
+
<div class="slds-grid slds-grid_vertical">
|
|
13
|
+
<template lwc:if={shouldShowCitations}>
|
|
14
|
+
<div class="slds-size_1-of-1 slds-var-m-top_x-small">
|
|
15
|
+
<c-quantic-source-citations
|
|
16
|
+
data-testid="generated-answer-body__citations"
|
|
17
|
+
engine-id={engineId}
|
|
18
|
+
citations={citations}
|
|
19
|
+
citation-hover-handler={handleCitationHover}
|
|
20
|
+
disable-citation-anchoring={disableCitationAnchoring}
|
|
21
|
+
></c-quantic-source-citations>
|
|
22
|
+
</div>
|
|
23
|
+
</template>
|
|
24
|
+
<template lwc:if={shouldShowActions}>
|
|
25
|
+
<div
|
|
26
|
+
data-testid="generated-answer-body__actions"
|
|
27
|
+
class="slds-size_1-of-1 slds-grid slds-grid_vertical-align-center slds-var-m-top_x-small slds-grid_align-start"
|
|
28
|
+
>
|
|
29
|
+
<c-quantic-feedback
|
|
30
|
+
state={computedFeedbackState}
|
|
31
|
+
onquantic__like={handleLike}
|
|
32
|
+
onquantic__dislike={handleDislike}
|
|
33
|
+
like-icon-name="utility:like"
|
|
34
|
+
like-label={labels.thisAnswerWasHelpful}
|
|
35
|
+
dislike-icon-name="utility:dislike"
|
|
36
|
+
dislike-label={labels.thisAnswerWasNotHelpful}
|
|
37
|
+
size="x-small"
|
|
38
|
+
question=""
|
|
39
|
+
hide-explain-why-button
|
|
40
|
+
hide-labels
|
|
41
|
+
></c-quantic-feedback>
|
|
42
|
+
<c-quantic-generated-answer-copy-to-clipboard
|
|
43
|
+
data-testid="generated-answer-body__copy-to-clipboard"
|
|
44
|
+
answer={answer}
|
|
45
|
+
answer-id={answerId}
|
|
46
|
+
size="x-small"
|
|
47
|
+
class="slds-var-m-horizontal_xx-small"
|
|
48
|
+
></c-quantic-generated-answer-copy-to-clipboard>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
</div>
|
|
52
|
+
</section>
|
|
53
|
+
</template>
|