@coveo/quantic 3.40.0 → 3.42.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/docs/out/quantic-docs.json +9 -0
- package/force-app/main/default/labels/CustomLabels.labels-meta.xml +91 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +271 -22
- package/force-app/main/default/lwc/quanticGeneratedAnswer/quanticGeneratedAnswer.js +92 -31
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/conversation.css +7 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/conversation.html +63 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/generatedAnswer.css +0 -11
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/generatedAnswer.html +2 -2
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/__tests__/quanticGeneratedAnswerBody.test.js +379 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswerBody/quanticGeneratedAnswerBody.js +152 -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 +59 -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/quanticGeneratedAnswerCopyToClipboard/__tests__/quanticGeneratedAnswerCopyToClipboard.test.js +5 -1
- package/force-app/main/default/lwc/quanticGeneratedAnswerCopyToClipboard/quanticGeneratedAnswerCopyToClipboard.js +9 -2
- package/force-app/main/default/lwc/quanticGeneratedAnswerFollowUpInput/__tests__/quanticGeneratedAnswerFollowUpInput.test.js +109 -55
- package/force-app/main/default/lwc/quanticGeneratedAnswerFollowUpInput/quanticGeneratedAnswerFollowUpInput.css +59 -11
- package/force-app/main/default/lwc/quanticGeneratedAnswerFollowUpInput/quanticGeneratedAnswerFollowUpInput.html +14 -13
- package/force-app/main/default/lwc/quanticGeneratedAnswerFollowUpInput/quanticGeneratedAnswerFollowUpInput.js +40 -2
- 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/quanticSourceCitations/__tests__/quanticSourceCitations.test.js +22 -2
- package/force-app/main/default/lwc/quanticSourceCitations/quanticSourceCitations.js +7 -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 +15 -15
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/commerce/common/pagination.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/sub-controller/headless-sub-controller.d.ts +3 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recent-queries-list/headless-recent-queries-list.d.ts +13 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/search/did-you-mean/headless-did-you-mean.d.ts +10 -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/headless-generated-answer.d.ts +2 -2
- 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/follow-up-answers/follow-up-answers-actions.d.ts +32 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-actions.d.ts +26 -1
- 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/definitions/features/generated-answer/generated-answer-state.d.ts +19 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/index.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.d.ts +4 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-commerce-next.index.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-commerce.index.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-next/commerce/controllers/did-you-mean/headless-did-you-mean.ssr.d.ts +4 -3
- package/force-app/main/default/staticresources/coveoheadless/headless.js +18 -18
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +16 -16
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +14 -14
- package/package.json +2 -2
|
@@ -0,0 +1,379 @@
|
|
|
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
|
+
streamOfThought: 'c-quantic-generated-answer-stream-of-thought',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const createTestComponent = buildCreateTestComponent(
|
|
74
|
+
QuanticGeneratedAnswerBody,
|
|
75
|
+
'c-quantic-generated-answer-body',
|
|
76
|
+
defaultOptions
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
describe('c-quantic-generated-answer-body', () => {
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
cleanup();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should pass the answer, answerContentFormat, engineId, and answerId properties to the QuanticGeneratedAnswerContent component', async () => {
|
|
85
|
+
const element = createTestComponent();
|
|
86
|
+
await flushPromises();
|
|
87
|
+
|
|
88
|
+
const content = element.shadowRoot.querySelector(selectors.content);
|
|
89
|
+
|
|
90
|
+
expect(content.answer).toBe(defaultOptions.generatedAnswer.answer);
|
|
91
|
+
expect(content.answerContentFormat).toBe(
|
|
92
|
+
defaultOptions.generatedAnswer.answerContentFormat
|
|
93
|
+
);
|
|
94
|
+
expect(content.engineId).toBe(defaultOptions.engineId);
|
|
95
|
+
expect(content.answerId).toBe(defaultOptions.generatedAnswer.answerId);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should pass agentSteps and isStreaming to the QuanticGeneratedAnswerStreamOfThought component', async () => {
|
|
99
|
+
const generationSteps = [{id: 'step-1'}, {id: 'step-2'}];
|
|
100
|
+
const element = createTestComponent({
|
|
101
|
+
...defaultOptions,
|
|
102
|
+
generatedAnswer: {
|
|
103
|
+
...defaultOptions.generatedAnswer,
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
generationSteps,
|
|
106
|
+
isStreaming: true,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
await flushPromises();
|
|
110
|
+
|
|
111
|
+
const streamOfThought = element.shadowRoot.querySelector(
|
|
112
|
+
selectors.streamOfThought
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
expect(streamOfThought).not.toBeNull();
|
|
116
|
+
expect(streamOfThought.agentSteps).toEqual(generationSteps);
|
|
117
|
+
expect(streamOfThought.isStreaming).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should pass an empty agentSteps array to QuanticGeneratedAnswerStreamOfThought when generationSteps is undefined', async () => {
|
|
121
|
+
const element = createTestComponent();
|
|
122
|
+
await flushPromises();
|
|
123
|
+
|
|
124
|
+
const streamOfThought = element.shadowRoot.querySelector(
|
|
125
|
+
selectors.streamOfThought
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(streamOfThought).not.toBeNull();
|
|
129
|
+
expect(streamOfThought.agentSteps).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should send the answerId within event details when dispatching the #quantic__generatedanswerlike event', async () => {
|
|
133
|
+
const element = createTestComponent();
|
|
134
|
+
const handler = jest.fn();
|
|
135
|
+
element.addEventListener('quantic__generatedanswerlike', handler);
|
|
136
|
+
await flushPromises();
|
|
137
|
+
|
|
138
|
+
const feedback = element.shadowRoot.querySelector(selectors.feedback);
|
|
139
|
+
feedback.dispatchEvent(new CustomEvent('quantic__like'));
|
|
140
|
+
|
|
141
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
142
|
+
expect(handler.mock.calls[0][0].detail).toEqual({answerId: 'answer-1'});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should send the answerId within event details when dispatching the #quantic__generatedanswerdislike event', async () => {
|
|
146
|
+
const element = createTestComponent();
|
|
147
|
+
const handler = jest.fn();
|
|
148
|
+
element.addEventListener('quantic__generatedanswerdislike', handler);
|
|
149
|
+
await flushPromises();
|
|
150
|
+
|
|
151
|
+
const feedback = element.shadowRoot.querySelector(selectors.feedback);
|
|
152
|
+
feedback.dispatchEvent(new CustomEvent('quantic__dislike'));
|
|
153
|
+
|
|
154
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
155
|
+
expect(handler.mock.calls[0][0].detail).toEqual({answerId: 'answer-1'});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('should pass the answerId to the copy-to-clipboard component', async () => {
|
|
159
|
+
const element = createTestComponent();
|
|
160
|
+
await flushPromises();
|
|
161
|
+
|
|
162
|
+
const copy = element.shadowRoot.querySelector(selectors.copy);
|
|
163
|
+
|
|
164
|
+
expect(copy.answerId).toBe('answer-1');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should send the answerId within event details when dispatching the #quantic__citationhover event', async () => {
|
|
168
|
+
const element = createTestComponent({
|
|
169
|
+
...defaultOptions,
|
|
170
|
+
generatedAnswer: {
|
|
171
|
+
...defaultOptions.generatedAnswer,
|
|
172
|
+
// @ts-ignore
|
|
173
|
+
citations: [{id: 'citation-1', title: 'Citation'}],
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
const handler = jest.fn();
|
|
177
|
+
element.addEventListener('quantic__citationhover', handler);
|
|
178
|
+
await flushPromises();
|
|
179
|
+
|
|
180
|
+
const citations = element.shadowRoot.querySelector(
|
|
181
|
+
'c-quantic-source-citations'
|
|
182
|
+
);
|
|
183
|
+
citations.citationHoverHandler('citation-1', 1200);
|
|
184
|
+
|
|
185
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(handler.mock.calls[0][0].detail).toEqual({
|
|
187
|
+
answerId: 'answer-1',
|
|
188
|
+
citationId: 'citation-1',
|
|
189
|
+
citationHoverTimeMs: 1200,
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('when an answer has not been generated', () => {
|
|
194
|
+
it('should render the no-answer message when the answer cannot be generated', async () => {
|
|
195
|
+
const element = createTestComponent({
|
|
196
|
+
...defaultOptions,
|
|
197
|
+
generatedAnswer: {
|
|
198
|
+
...defaultOptions.generatedAnswer,
|
|
199
|
+
cannotAnswer: true,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
await flushPromises();
|
|
203
|
+
|
|
204
|
+
const noAnswer = element.shadowRoot.querySelector(selectors.noAnswer);
|
|
205
|
+
|
|
206
|
+
expect(noAnswer).not.toBeNull();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('when an error occurs', () => {
|
|
211
|
+
it('should render the generic error message when a non-retryable error occurs', async () => {
|
|
212
|
+
const element = createTestComponent({
|
|
213
|
+
...defaultOptions,
|
|
214
|
+
generatedAnswer: {
|
|
215
|
+
...defaultOptions.generatedAnswer,
|
|
216
|
+
answer: '',
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
error: {code: 500},
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
await flushPromises();
|
|
222
|
+
|
|
223
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
224
|
+
|
|
225
|
+
expect(error).not.toBeNull();
|
|
226
|
+
expect(error.textContent).toContain(
|
|
227
|
+
'Something went wrong while generating the answer. Please try again later.'
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should render the turn limit reached error message when the SSE turn limit is exceeded', async () => {
|
|
232
|
+
const element = createTestComponent({
|
|
233
|
+
...defaultOptions,
|
|
234
|
+
generatedAnswer: {
|
|
235
|
+
...defaultOptions.generatedAnswer,
|
|
236
|
+
answer: '',
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
error: {
|
|
239
|
+
code: 429,
|
|
240
|
+
isSseTurnLimitReachedError: () => true,
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
await flushPromises();
|
|
245
|
+
|
|
246
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
247
|
+
|
|
248
|
+
expect(error).not.toBeNull();
|
|
249
|
+
expect(error.textContent).toContain(
|
|
250
|
+
'Conversation turn limit reached. Please start a new conversation.'
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should render the error message even when the answer is not empty', async () => {
|
|
255
|
+
const element = createTestComponent({
|
|
256
|
+
...defaultOptions,
|
|
257
|
+
generatedAnswer: {
|
|
258
|
+
...defaultOptions.generatedAnswer,
|
|
259
|
+
answer: 'Partial answer content',
|
|
260
|
+
// @ts-ignore
|
|
261
|
+
error: {code: 500},
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
await flushPromises();
|
|
265
|
+
|
|
266
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
267
|
+
const content = element.shadowRoot.querySelector(selectors.content);
|
|
268
|
+
|
|
269
|
+
expect(error).not.toBeNull();
|
|
270
|
+
expect(content).toBeNull();
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe('rendering of actions', () => {
|
|
275
|
+
it('should display actions when the answer is not empty and done streaming', async () => {
|
|
276
|
+
const element = createTestComponent();
|
|
277
|
+
await flushPromises();
|
|
278
|
+
|
|
279
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
280
|
+
|
|
281
|
+
expect(actions).not.toBeNull();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('should not display actions while the answer is streaming', async () => {
|
|
285
|
+
const element = createTestComponent({
|
|
286
|
+
...defaultOptions,
|
|
287
|
+
generatedAnswer: {
|
|
288
|
+
...defaultOptions.generatedAnswer,
|
|
289
|
+
isStreaming: true,
|
|
290
|
+
},
|
|
291
|
+
});
|
|
292
|
+
await flushPromises();
|
|
293
|
+
|
|
294
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
295
|
+
|
|
296
|
+
expect(actions).toBeNull();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('should not display actions when there is no answer', async () => {
|
|
300
|
+
const element = createTestComponent({
|
|
301
|
+
...defaultOptions,
|
|
302
|
+
generatedAnswer: {
|
|
303
|
+
...defaultOptions.generatedAnswer,
|
|
304
|
+
answer: '',
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
await flushPromises();
|
|
308
|
+
|
|
309
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
310
|
+
|
|
311
|
+
expect(actions).toBeNull();
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe('rendering of citations', () => {
|
|
316
|
+
it('should display citations when citations are not empty', async () => {
|
|
317
|
+
const element = createTestComponent({
|
|
318
|
+
...defaultOptions,
|
|
319
|
+
generatedAnswer: {
|
|
320
|
+
...defaultOptions.generatedAnswer,
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
citations: [{id: 'citation-1', title: 'Citation'}],
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
await flushPromises();
|
|
326
|
+
|
|
327
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
328
|
+
|
|
329
|
+
expect(citations).not.toBeNull();
|
|
330
|
+
expect(citations.answerId).toBe(defaultOptions.generatedAnswer.answerId);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should not display citations when citations are empty', async () => {
|
|
334
|
+
const element = createTestComponent();
|
|
335
|
+
await flushPromises();
|
|
336
|
+
|
|
337
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
338
|
+
|
|
339
|
+
expect(citations).toBeNull();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('should not display citations while the answer is streaming', async () => {
|
|
343
|
+
const element = createTestComponent({
|
|
344
|
+
...defaultOptions,
|
|
345
|
+
generatedAnswer: {
|
|
346
|
+
...defaultOptions.generatedAnswer,
|
|
347
|
+
// @ts-ignore
|
|
348
|
+
citations: [{id: 'citation-1', title: 'Citation'}],
|
|
349
|
+
isStreaming: true,
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
await flushPromises();
|
|
353
|
+
|
|
354
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
355
|
+
|
|
356
|
+
expect(citations).toBeNull();
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
describe('when generatedAnswer is null', () => {
|
|
361
|
+
it('should render without errors', async () => {
|
|
362
|
+
const element = createTestComponent({
|
|
363
|
+
...defaultOptions,
|
|
364
|
+
generatedAnswer: null,
|
|
365
|
+
});
|
|
366
|
+
await flushPromises();
|
|
367
|
+
|
|
368
|
+
const error = element.shadowRoot.querySelector(selectors.error);
|
|
369
|
+
const noAnswer = element.shadowRoot.querySelector(selectors.noAnswer);
|
|
370
|
+
const actions = element.shadowRoot.querySelector(selectors.actions);
|
|
371
|
+
const citations = element.shadowRoot.querySelector(selectors.citations);
|
|
372
|
+
|
|
373
|
+
expect(error).toBeNull();
|
|
374
|
+
expect(noAnswer).toBeNull();
|
|
375
|
+
expect(actions).toBeNull();
|
|
376
|
+
expect(citations).toBeNull();
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
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 like from '@salesforce/label/c.quantic_Like';
|
|
5
|
+
import dislike from '@salesforce/label/c.quantic_Dislike';
|
|
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
|
+
like,
|
|
53
|
+
dislike,
|
|
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 agentSteps() {
|
|
77
|
+
return this.generatedAnswer?.generationSteps || [];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get hasError() {
|
|
81
|
+
return !!this.generatedAnswer?.error?.code;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get cannotAnswer() {
|
|
85
|
+
return !!this.generatedAnswer?.cannotAnswer;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get errorMessage() {
|
|
89
|
+
if (this.generatedAnswer?.error?.isSseTurnLimitReachedError?.()) {
|
|
90
|
+
return this.labels.generatedAnswerErrorTurnLimitReached;
|
|
91
|
+
}
|
|
92
|
+
return this.labels.genericErrorTitle;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get computedFeedbackState() {
|
|
96
|
+
if (this.generatedAnswer?.liked) {
|
|
97
|
+
return FEEDBACK_LIKED_STATE;
|
|
98
|
+
}
|
|
99
|
+
if (this.generatedAnswer?.disliked) {
|
|
100
|
+
return FEEDBACK_DISLIKED_STATE;
|
|
101
|
+
}
|
|
102
|
+
return FEEDBACK_NEUTRAL_STATE;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get shouldShowCitations() {
|
|
106
|
+
return this.citations.length > 0 && !this.isStreaming;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get shouldShowActions() {
|
|
110
|
+
return Boolean(this.answer) && !this.isStreaming;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
handleLike(event) {
|
|
114
|
+
event.stopPropagation();
|
|
115
|
+
this.dispatchAnswerInteractionEvent('quantic__generatedanswerlike');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
handleDislike(event) {
|
|
119
|
+
event.stopPropagation();
|
|
120
|
+
this.dispatchAnswerInteractionEvent('quantic__generatedanswerdislike');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
handleCitationHover = (citationId, citationHoverTimeMs) => {
|
|
124
|
+
this.dispatchAnswerInteractionEvent('quantic__citationhover', {
|
|
125
|
+
citationId,
|
|
126
|
+
citationHoverTimeMs,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
dispatchAnswerInteractionEvent(eventName, payload = {}) {
|
|
131
|
+
this.dispatchEvent(
|
|
132
|
+
new CustomEvent(eventName, {
|
|
133
|
+
detail: {
|
|
134
|
+
answerId: this.answerId,
|
|
135
|
+
...payload,
|
|
136
|
+
},
|
|
137
|
+
bubbles: true,
|
|
138
|
+
composed: true,
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
render() {
|
|
144
|
+
if (this.hasError) {
|
|
145
|
+
return errorTemplate;
|
|
146
|
+
}
|
|
147
|
+
if (this.cannotAnswer) {
|
|
148
|
+
return cannotAnswerTemplate;
|
|
149
|
+
}
|
|
150
|
+
return answerTemplate;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section data-testid="generated-answer-body" class="generated-answer__body">
|
|
3
|
+
<div class="slds-var-m-bottom_small">
|
|
4
|
+
<c-quantic-generated-answer-stream-of-thought
|
|
5
|
+
agent-steps={agentSteps}
|
|
6
|
+
is-streaming={isStreaming}
|
|
7
|
+
></c-quantic-generated-answer-stream-of-thought>
|
|
8
|
+
</div>
|
|
9
|
+
<c-quantic-generated-answer-content
|
|
10
|
+
engine-id={engineId}
|
|
11
|
+
answer-id={answerId}
|
|
12
|
+
answer-content-format={answerContentFormat}
|
|
13
|
+
answer={answer}
|
|
14
|
+
is-streaming={isStreaming}
|
|
15
|
+
>
|
|
16
|
+
</c-quantic-generated-answer-content>
|
|
17
|
+
<div class="slds-grid slds-grid_vertical">
|
|
18
|
+
<template lwc:if={shouldShowCitations}>
|
|
19
|
+
<div class="slds-size_1-of-1 slds-var-m-top_x-small">
|
|
20
|
+
<c-quantic-source-citations
|
|
21
|
+
data-testid="generated-answer-body__citations"
|
|
22
|
+
engine-id={engineId}
|
|
23
|
+
citations={citations}
|
|
24
|
+
citation-hover-handler={handleCitationHover}
|
|
25
|
+
disable-citation-anchoring={disableCitationAnchoring}
|
|
26
|
+
answer-id={answerId}
|
|
27
|
+
></c-quantic-source-citations>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
30
|
+
<template lwc:if={shouldShowActions}>
|
|
31
|
+
<div
|
|
32
|
+
data-testid="generated-answer-body__actions"
|
|
33
|
+
class="slds-size_1-of-1 slds-grid slds-grid_vertical-align-center slds-var-m-top_x-small slds-grid_align-start"
|
|
34
|
+
>
|
|
35
|
+
<c-quantic-feedback
|
|
36
|
+
state={computedFeedbackState}
|
|
37
|
+
onquantic__like={handleLike}
|
|
38
|
+
onquantic__dislike={handleDislike}
|
|
39
|
+
like-icon-name="utility:like"
|
|
40
|
+
like-label={labels.like}
|
|
41
|
+
dislike-icon-name="utility:dislike"
|
|
42
|
+
dislike-label={labels.dislike}
|
|
43
|
+
size="x-small"
|
|
44
|
+
question=""
|
|
45
|
+
hide-explain-why-button
|
|
46
|
+
hide-labels
|
|
47
|
+
></c-quantic-feedback>
|
|
48
|
+
<c-quantic-generated-answer-copy-to-clipboard
|
|
49
|
+
data-testid="generated-answer-body__copy-to-clipboard"
|
|
50
|
+
answer={answer}
|
|
51
|
+
answer-id={answerId}
|
|
52
|
+
size="x-small"
|
|
53
|
+
class="slds-var-m-horizontal_xx-small"
|
|
54
|
+
></c-quantic-generated-answer-copy-to-clipboard>
|
|
55
|
+
</div>
|
|
56
|
+
</template>
|
|
57
|
+
</div>
|
|
58
|
+
</section>
|
|
59
|
+
</template>
|
|
@@ -34,6 +34,7 @@ const selectors = {
|
|
|
34
34
|
|
|
35
35
|
const defaultOptions = {
|
|
36
36
|
answer: 'Example generated answer',
|
|
37
|
+
answerId: 'example-answer-id',
|
|
37
38
|
size: defaultSize,
|
|
38
39
|
};
|
|
39
40
|
|
|
@@ -109,7 +110,7 @@ describe('c-quantic-generated-answer-copy-to-clipboard', () => {
|
|
|
109
110
|
expect(copyButton.iconSize).toBe(defaultSize);
|
|
110
111
|
});
|
|
111
112
|
|
|
112
|
-
it('should copy the answer and dispatch the #quantic__generatedanswercopy event', async () => {
|
|
113
|
+
it('should copy the answer and dispatch the #quantic__generatedanswercopy event with the answerId', async () => {
|
|
113
114
|
const element = createTestComponent();
|
|
114
115
|
const handler = jest.fn();
|
|
115
116
|
element.addEventListener('quantic__generatedanswercopy', handler);
|
|
@@ -121,5 +122,8 @@ describe('c-quantic-generated-answer-copy-to-clipboard', () => {
|
|
|
121
122
|
|
|
122
123
|
expect(copyToClipboard).toHaveBeenCalledWith(defaultOptions.answer);
|
|
123
124
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
125
|
+
expect(handler.mock.calls[0][0].detail).toEqual({
|
|
126
|
+
answerId: defaultOptions.answerId,
|
|
127
|
+
});
|
|
124
128
|
});
|
|
125
129
|
});
|
|
@@ -15,6 +15,12 @@ export default class QuanticGeneratedAnswerCopyToClipboard extends LightningElem
|
|
|
15
15
|
* @type {string}
|
|
16
16
|
*/
|
|
17
17
|
@api answer = '';
|
|
18
|
+
/**
|
|
19
|
+
* The unique identifier of the generated answer.
|
|
20
|
+
* @api
|
|
21
|
+
* @type {string}
|
|
22
|
+
*/
|
|
23
|
+
@api answerId;
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* The size of the copy icon.
|
|
@@ -41,11 +47,12 @@ export default class QuanticGeneratedAnswerCopyToClipboard extends LightningElem
|
|
|
41
47
|
isSelected = false;
|
|
42
48
|
tooltip = this.labels.copy;
|
|
43
49
|
|
|
44
|
-
dispatchCopyToClipboardEvent(
|
|
50
|
+
dispatchCopyToClipboardEvent() {
|
|
45
51
|
this.dispatchEvent(
|
|
46
52
|
new CustomEvent('quantic__generatedanswercopy', {
|
|
47
|
-
detail:
|
|
53
|
+
detail: {answerId: this.answerId},
|
|
48
54
|
bubbles: true,
|
|
55
|
+
composed: true,
|
|
49
56
|
})
|
|
50
57
|
);
|
|
51
58
|
}
|