@servicetitan/titan-chatbot-api 6.1.1 → 7.0.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 +12 -0
- package/dist/api-client/__mocks__/chatbot-api-client.mock.d.ts +1 -1
- package/dist/api-client/__mocks__/chatbot-api-client.mock.d.ts.map +1 -1
- package/dist/api-client/__mocks__/chatbot-api-client.mock.js +6 -6
- package/dist/api-client/__mocks__/chatbot-api-client.mock.js.map +1 -1
- package/dist/api-client/base/chatbot-api-client.d.ts +1 -1
- package/dist/api-client/base/chatbot-api-client.d.ts.map +1 -1
- package/dist/api-client/help-center/chatbot-api-client.d.ts +1 -1
- package/dist/api-client/help-center/chatbot-api-client.d.ts.map +1 -1
- package/dist/api-client/help-center/chatbot-api-client.js +7 -4
- package/dist/api-client/help-center/chatbot-api-client.js.map +1 -1
- package/dist/api-client/titan-chat/__tests__/native-client.test.d.ts +2 -0
- package/dist/api-client/titan-chat/__tests__/native-client.test.d.ts.map +1 -0
- package/dist/api-client/titan-chat/__tests__/native-client.test.js +36 -0
- package/dist/api-client/titan-chat/__tests__/native-client.test.js.map +1 -0
- package/dist/api-client/titan-chat/chatbot-api-client.d.ts +2 -2
- package/dist/api-client/titan-chat/chatbot-api-client.d.ts.map +1 -1
- package/dist/api-client/titan-chat/chatbot-api-client.js +5 -5
- package/dist/api-client/titan-chat/chatbot-api-client.js.map +1 -1
- package/dist/api-client/titan-chat/native-client.d.ts +98 -40
- package/dist/api-client/titan-chat/native-client.d.ts.map +1 -1
- package/dist/api-client/titan-chat/native-client.js +436 -384
- package/dist/api-client/titan-chat/native-client.js.map +1 -1
- package/dist/stores/chatbot-ui-backend.store.d.ts.map +1 -1
- package/dist/stores/chatbot-ui-backend.store.js +17 -16
- package/dist/stores/chatbot-ui-backend.store.js.map +1 -1
- package/dist/stores/chatbot-ui.store.d.ts +5 -4
- package/dist/stores/chatbot-ui.store.d.ts.map +1 -1
- package/dist/stores/chatbot-ui.store.js +4 -6
- package/dist/stores/chatbot-ui.store.js.map +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.d.ts.map +1 -1
- package/dist/stores/message-feedback-base.store.d.ts +2 -1
- package/dist/stores/message-feedback-base.store.d.ts.map +1 -1
- package/dist/stores/message-feedback-guardrail.store.d.ts +2 -3
- package/dist/stores/message-feedback-guardrail.store.d.ts.map +1 -1
- package/dist/stores/message-feedback-guardrail.store.js +4 -10
- package/dist/stores/message-feedback-guardrail.store.js.map +1 -1
- package/dist/stores/message-feedback.store.d.ts +2 -3
- package/dist/stores/message-feedback.store.d.ts.map +1 -1
- package/dist/stores/message-feedback.store.js +3 -6
- package/dist/stores/message-feedback.store.js.map +1 -1
- package/dist/stores/session-feedback.store.d.ts +2 -2
- package/dist/stores/session-feedback.store.d.ts.map +1 -1
- package/dist/stores/session-feedback.store.js +3 -3
- package/dist/stores/session-feedback.store.js.map +1 -1
- package/package.json +3 -3
- package/src/api-client/__mocks__/chatbot-api-client.mock.ts +1 -1
- package/src/api-client/base/chatbot-api-client.ts +4 -1
- package/src/api-client/help-center/chatbot-api-client.ts +9 -5
- package/src/api-client/titan-chat/__tests__/native-client.test.ts +37 -0
- package/src/api-client/titan-chat/chatbot-api-client.ts +7 -7
- package/src/api-client/titan-chat/native-client.ts +622 -424
- package/src/stores/chatbot-ui-backend.store.ts +19 -16
- package/src/stores/chatbot-ui.store.ts +7 -10
- package/src/stores/index.ts +1 -1
- package/src/stores/message-feedback-base.store.ts +7 -1
- package/src/stores/message-feedback-guardrail.store.ts +6 -12
- package/src/stores/message-feedback.store.ts +5 -8
- package/src/stores/session-feedback.store.ts +4 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -19,6 +19,9 @@ import { InitializeStore } from './initialize.store';
|
|
|
19
19
|
|
|
20
20
|
const DEFAULT_CHATBOT_ASK_BOT_TIMEOUT_MS = 31000; // 31 seconds
|
|
21
21
|
|
|
22
|
+
const isAbortedError = (error: unknown): boolean =>
|
|
23
|
+
axios.isCancel(error) || (error as { name?: string } | null)?.name === 'AbortError';
|
|
24
|
+
|
|
22
25
|
export const CHATBOT_UI_BACKEND_STORE_TOKEN = symbolToken<IChatbotUiBackendStore>(
|
|
23
26
|
'CHATBOT_UI_BACKEND_STORE_TOKEN'
|
|
24
27
|
);
|
|
@@ -140,24 +143,24 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
|
|
|
140
143
|
handleSessionFeedback: ChatUiEventListener<{
|
|
141
144
|
state: Models.ChatbotFeedbackState;
|
|
142
145
|
feedback?: Models.Feedback;
|
|
143
|
-
}> = async (resolve, _,
|
|
146
|
+
}> = async (resolve, _, draft?: Models.IFeedback) => {
|
|
144
147
|
let feedbackState: Models.ChatbotFeedbackState;
|
|
145
|
-
let feedbackResult =
|
|
148
|
+
let feedbackResult: Models.Feedback | undefined = draft
|
|
149
|
+
? new Models.Feedback(draft)
|
|
150
|
+
: undefined;
|
|
146
151
|
try {
|
|
147
|
-
if (!
|
|
152
|
+
if (!draft) {
|
|
148
153
|
throw new ChatError('Session feedback is missing.', {
|
|
149
154
|
recoverStrategy: false,
|
|
150
155
|
});
|
|
151
156
|
}
|
|
152
|
-
if (typeof
|
|
157
|
+
if (typeof draft.messageId !== 'undefined') {
|
|
153
158
|
throw new ChatError('Session feedback should not contain messageId.', {
|
|
154
159
|
recoverStrategy: false,
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
162
|
await this.startSession();
|
|
158
|
-
|
|
159
|
-
feedback.sessionId = this.session!.id;
|
|
160
|
-
});
|
|
163
|
+
const feedback = new Models.Feedback({ ...draft, sessionId: this.session!.id! });
|
|
161
164
|
feedbackResult = await this.api('postFeedback', feedback, this.abortController.signal);
|
|
162
165
|
feedbackState = Models.ChatbotFeedbackState.Success;
|
|
163
166
|
} catch (error: unknown) {
|
|
@@ -178,24 +181,24 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
|
|
|
178
181
|
handleMessageFeedback: ChatUiEventListener<{
|
|
179
182
|
state: Models.ChatbotFeedbackState;
|
|
180
183
|
feedback?: Models.Feedback;
|
|
181
|
-
}> = async (resolve, _,
|
|
184
|
+
}> = async (resolve, _, draft?: Models.IFeedback) => {
|
|
182
185
|
let feedbackState: Models.ChatbotFeedbackState;
|
|
183
|
-
let feedbackResult =
|
|
186
|
+
let feedbackResult: Models.Feedback | undefined = draft
|
|
187
|
+
? new Models.Feedback(draft)
|
|
188
|
+
: undefined;
|
|
184
189
|
try {
|
|
185
|
-
if (!
|
|
190
|
+
if (!draft) {
|
|
186
191
|
throw new ChatError('Message feedback is missing.', {
|
|
187
192
|
recoverStrategy: false,
|
|
188
193
|
});
|
|
189
194
|
}
|
|
190
|
-
if (!
|
|
195
|
+
if (!draft.messageId) {
|
|
191
196
|
throw new ChatError('Message feedback is missing messageId.', {
|
|
192
197
|
recoverStrategy: false,
|
|
193
198
|
});
|
|
194
199
|
}
|
|
195
200
|
await this.startSession();
|
|
196
|
-
|
|
197
|
-
feedback.sessionId = this.session!.id;
|
|
198
|
-
});
|
|
201
|
+
const feedback = new Models.Feedback({ ...draft, sessionId: this.session!.id! });
|
|
199
202
|
feedbackResult = await this.api('postFeedback', feedback, this.abortController.signal);
|
|
200
203
|
feedbackState = Models.ChatbotFeedbackState.Success;
|
|
201
204
|
} catch (error: unknown) {
|
|
@@ -240,7 +243,7 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
|
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
protected logError(code: string, message: string, error: any) {
|
|
243
|
-
if (
|
|
246
|
+
if (isAbortedError(error)) {
|
|
244
247
|
return;
|
|
245
248
|
}
|
|
246
249
|
this.logService.error({
|
|
@@ -428,7 +431,7 @@ export class ChatbotUiBackendStore extends InitializeStore implements IChatbotUi
|
|
|
428
431
|
}
|
|
429
432
|
|
|
430
433
|
protected setError(code: string, title: string, message: string, error: any) {
|
|
431
|
-
if (
|
|
434
|
+
if (isAbortedError(error)) {
|
|
432
435
|
return;
|
|
433
436
|
}
|
|
434
437
|
this.logError(code, message, error);
|
|
@@ -4,6 +4,7 @@ import { action, makeObservable } from 'mobx';
|
|
|
4
4
|
import { Models } from '../api-client';
|
|
5
5
|
import { ChatbotCustomizations } from '../models';
|
|
6
6
|
import { FilterStore, IFilterStore, IFilterStoreInitOptions } from './filter.store';
|
|
7
|
+
import { FeedbackDraft } from './message-feedback-base.store';
|
|
7
8
|
|
|
8
9
|
export const CHATBOT_UI_STORE_TOKEN = symbolToken<IChatbotUiStore>('CHATBOT_UI_STORE_TOKEN');
|
|
9
10
|
|
|
@@ -22,12 +23,10 @@ export interface IChatbotUiStore extends IChatUiStore<ChatbotCustomizations> {
|
|
|
22
23
|
sessionData?: Models.ISession['data'],
|
|
23
24
|
forceRecreate?: boolean
|
|
24
25
|
): Promise<undefined | Models.Session>;
|
|
25
|
-
sendSessionFeedback(
|
|
26
|
-
feedback: Models.IFeedback
|
|
27
|
-
): Promise<undefined | Models.ChatbotFeedbackState>;
|
|
26
|
+
sendSessionFeedback(feedback: FeedbackDraft): Promise<undefined | Models.ChatbotFeedbackState>;
|
|
28
27
|
sendMessageFeedback(
|
|
29
28
|
message: Models.IBotMessageWithFeedback,
|
|
30
|
-
messageFeedback:
|
|
29
|
+
messageFeedback: FeedbackDraft
|
|
31
30
|
): Promise<undefined | Models.ChatbotFeedbackState>;
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -80,11 +79,10 @@ export class ChatbotUiStore extends ChatUiStore<ChatbotCustomizations> implement
|
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
@action
|
|
83
|
-
async sendSessionFeedback(feedback:
|
|
84
|
-
feedback.messageId = undefined; // Ensure messageId is not set for session feedback
|
|
82
|
+
async sendSessionFeedback(feedback: FeedbackDraft) {
|
|
85
83
|
const result = await this.emitAsync<Models.ChatbotFeedbackState>(
|
|
86
84
|
ChatbotUiEvent.eventChatbotSessionFeedback,
|
|
87
|
-
feedback
|
|
85
|
+
{ ...feedback, messageId: undefined }
|
|
88
86
|
);
|
|
89
87
|
return result;
|
|
90
88
|
}
|
|
@@ -92,12 +90,11 @@ export class ChatbotUiStore extends ChatUiStore<ChatbotCustomizations> implement
|
|
|
92
90
|
@action
|
|
93
91
|
async sendMessageFeedback(
|
|
94
92
|
message: Models.IBotMessageWithFeedback,
|
|
95
|
-
messageFeedback:
|
|
93
|
+
messageFeedback: FeedbackDraft
|
|
96
94
|
) {
|
|
97
|
-
messageFeedback.messageId = message.id;
|
|
98
95
|
const result = await this.emitAsync<Models.ChatbotFeedbackState>(
|
|
99
96
|
ChatbotUiEvent.eventChatbotMessageFeedback,
|
|
100
|
-
messageFeedback
|
|
97
|
+
{ ...messageFeedback, messageId: message.id }
|
|
101
98
|
);
|
|
102
99
|
return result;
|
|
103
100
|
}
|
package/src/stores/index.ts
CHANGED
|
@@ -18,4 +18,4 @@ export { InitializeStore, InitializeStoreStatus } from './initialize.store';
|
|
|
18
18
|
export { MessageFeedbackStore } from './message-feedback.store';
|
|
19
19
|
export { MessageFeedbackGuardrailStore } from './message-feedback-guardrail.store';
|
|
20
20
|
export { SessionFeedbackStore } from './session-feedback.store';
|
|
21
|
-
export { IMessageFeedbackBaseStore } from './message-feedback-base.store';
|
|
21
|
+
export { type FeedbackDraft, IMessageFeedbackBaseStore } from './message-feedback-base.store';
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { FormState } from 'formstate';
|
|
2
2
|
import { Models } from '../api-client';
|
|
3
3
|
|
|
4
|
+
/*
|
|
5
|
+
* A Feedback being assembled by a form or thumbs-up gesture. sessionId is filled in later
|
|
6
|
+
* by ChatbotUiBackendStore once a session exists, so it's intentionally omitted here.
|
|
7
|
+
*/
|
|
8
|
+
export type FeedbackDraft = Omit<Models.IFeedback, 'sessionId'>;
|
|
9
|
+
|
|
4
10
|
export interface IMessageFeedbackBaseStore<T extends FormState<{}> = FormState<{}>> {
|
|
5
11
|
isValid: boolean;
|
|
6
12
|
formState: T;
|
|
7
|
-
export():
|
|
13
|
+
export(): FeedbackDraft;
|
|
8
14
|
}
|
|
@@ -2,7 +2,7 @@ import { injectable } from '@servicetitan/react-ioc';
|
|
|
2
2
|
import { FieldState, FormState } from 'formstate';
|
|
3
3
|
import { action, computed, makeObservable, observable } from 'mobx';
|
|
4
4
|
import { Models } from '../api-client';
|
|
5
|
-
import { IMessageFeedbackBaseStore } from './message-feedback-base.store';
|
|
5
|
+
import { FeedbackDraft, IMessageFeedbackBaseStore } from './message-feedback-base.store';
|
|
6
6
|
|
|
7
7
|
export type FeedbackFormState = FormState<{
|
|
8
8
|
linkUrl: FieldState<string>;
|
|
@@ -22,24 +22,18 @@ export class MessageFeedbackGuardrailStore implements IMessageFeedbackBaseStore<
|
|
|
22
22
|
makeObservable(this);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export():
|
|
25
|
+
export(): FeedbackDraft {
|
|
26
26
|
const fs = this.formState.$;
|
|
27
|
-
|
|
27
|
+
const feedback: FeedbackDraft = {
|
|
28
28
|
rating: Models.FeedbackRatings.GuardrailFeedback,
|
|
29
29
|
};
|
|
30
30
|
if (fs.linkUrl.value) {
|
|
31
|
-
feedback =
|
|
32
|
-
...feedback,
|
|
33
|
-
linkUrl: fs.linkUrl.value,
|
|
34
|
-
};
|
|
31
|
+
feedback.linkUrl = fs.linkUrl.value;
|
|
35
32
|
}
|
|
36
33
|
if (fs.comment.value) {
|
|
37
|
-
feedback =
|
|
38
|
-
...feedback,
|
|
39
|
-
description: fs.comment.value,
|
|
40
|
-
};
|
|
34
|
+
feedback.description = fs.comment.value;
|
|
41
35
|
}
|
|
42
|
-
return
|
|
36
|
+
return feedback;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
getFormErrors(): string[] {
|
|
@@ -3,7 +3,7 @@ import { FieldState, FormState } from 'formstate';
|
|
|
3
3
|
import { action, computed, makeObservable, observable } from 'mobx';
|
|
4
4
|
import { Models } from '../api-client';
|
|
5
5
|
import { CHATBOT_UI_STORE_TOKEN, IChatbotUiStore } from './chatbot-ui.store';
|
|
6
|
-
import { IMessageFeedbackBaseStore } from './message-feedback-base.store';
|
|
6
|
+
import { FeedbackDraft, IMessageFeedbackBaseStore } from './message-feedback-base.store';
|
|
7
7
|
|
|
8
8
|
export type MessageFeedbackFormState = FormState<{
|
|
9
9
|
unrelated: FieldState<boolean>;
|
|
@@ -41,7 +41,7 @@ export class MessageFeedbackStore implements IMessageFeedbackBaseStore<MessageFe
|
|
|
41
41
|
makeObservable(this);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export():
|
|
44
|
+
export(): FeedbackDraft {
|
|
45
45
|
const fs = this.formState.$;
|
|
46
46
|
const options: Models.FeedbackOptions[] = [];
|
|
47
47
|
if (fs.unrelated.value) {
|
|
@@ -59,17 +59,14 @@ export class MessageFeedbackStore implements IMessageFeedbackBaseStore<MessageFe
|
|
|
59
59
|
if (fs.other.value) {
|
|
60
60
|
options.push(Models.FeedbackOptions.Other);
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
const feedback: FeedbackDraft = {
|
|
63
63
|
rating: Models.FeedbackRatings.ThumbsDown,
|
|
64
64
|
options,
|
|
65
65
|
};
|
|
66
66
|
if (fs.otherComment.value) {
|
|
67
|
-
feedback =
|
|
68
|
-
...feedback,
|
|
69
|
-
description: fs.otherComment.value,
|
|
70
|
-
};
|
|
67
|
+
feedback.description = fs.otherComment.value;
|
|
71
68
|
}
|
|
72
|
-
return
|
|
69
|
+
return feedback;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
@action
|
|
@@ -2,6 +2,7 @@ import { injectable } from '@servicetitan/react-ioc';
|
|
|
2
2
|
import { FieldState, FormState } from 'formstate';
|
|
3
3
|
import { computed, makeObservable, observable } from 'mobx';
|
|
4
4
|
import { Models } from '../api-client';
|
|
5
|
+
import { FeedbackDraft } from './message-feedback-base.store';
|
|
5
6
|
|
|
6
7
|
@injectable()
|
|
7
8
|
export class SessionFeedbackStore {
|
|
@@ -17,14 +18,14 @@ export class SessionFeedbackStore {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
@computed
|
|
20
|
-
get feedback():
|
|
21
|
-
return
|
|
21
|
+
get feedback(): FeedbackDraft {
|
|
22
|
+
return {
|
|
22
23
|
rating:
|
|
23
24
|
this.formState.$.thumbs.value > 0
|
|
24
25
|
? Models.FeedbackRatings.ThumbsUp
|
|
25
26
|
: Models.FeedbackRatings.ThumbsDown,
|
|
26
27
|
description: this.formState.$.comment.value || undefined,
|
|
27
|
-
}
|
|
28
|
+
};
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
@computed
|