vpschatbotwidget 1.2.5 → 1.2.6
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/README.md +13 -0
- package/dist-lib/types/chatbot/api/chatbot-api.d.ts +2 -0
- package/dist-lib/types/chatbot/api/chatbot-types.d.ts +9 -2
- package/dist-lib/types/chatbot/config/roles.d.ts +92 -0
- package/dist-lib/types/chatbot/core/ChatProvider.d.ts +4 -2
- package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +3 -2
- package/dist-lib/types/chatbot/index.d.ts +2 -1
- package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +3 -2
- package/dist-lib/vps-chatbot.cjs +45 -45
- package/dist-lib/vps-chatbot.js +3767 -3660
- package/package.json +1 -1
- package/src/chatbot/api/chatbot-api.ts +9 -1
- package/src/chatbot/api/chatbot-types.ts +10 -2
- package/src/chatbot/chatbot.test.tsx +52 -0
- package/src/chatbot/config/roles.ts +99 -0
- package/src/chatbot/core/ChatProvider.tsx +42 -10
- package/src/chatbot/embedded/EmbeddedChatbot.tsx +6 -2
- package/src/chatbot/index.ts +2 -0
- package/src/chatbot/widget/ChatbotWidget.tsx +6 -2
- package/src/index.css +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vpschatbotwidget",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This is an Package for the chatbot widget ui for our customer portel . ",
|
|
6
6
|
"homepage": "https://github.com/dhineshkumar-natobotics/VPS-Chatbot-Widget#readme",
|
|
@@ -158,6 +158,7 @@ export interface ChatApiClient {
|
|
|
158
158
|
toolCalls: ToolCall[];
|
|
159
159
|
usage: TokenUsage;
|
|
160
160
|
durationMs?: number;
|
|
161
|
+
suggestions?: string[];
|
|
161
162
|
}>;
|
|
162
163
|
sendMessageStream?(
|
|
163
164
|
sessionId: string,
|
|
@@ -174,6 +175,7 @@ export interface ChatApiClient {
|
|
|
174
175
|
toolCalls: ToolCall[];
|
|
175
176
|
usage: TokenUsage;
|
|
176
177
|
durationMs?: number;
|
|
178
|
+
suggestions?: string[];
|
|
177
179
|
}>;
|
|
178
180
|
getHistory(sessionId: string): Promise<ChatMessage[]>;
|
|
179
181
|
closeSession(sessionId: string): Promise<void>;
|
|
@@ -243,6 +245,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
243
245
|
message,
|
|
244
246
|
...(access?.roleId !== undefined ? { role_id: access.roleId } : {}),
|
|
245
247
|
...(access?.client ? { client: access.client } : {}),
|
|
248
|
+
...(access?.service ? { service: access.service } : {}),
|
|
246
249
|
...(access?.modelId ? { model_id: access.modelId } : {}),
|
|
247
250
|
}),
|
|
248
251
|
}
|
|
@@ -255,6 +258,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
255
258
|
toolCalls: (dto.tool_calls || []).map(normalizeToolCall),
|
|
256
259
|
usage: normalizeUsage(dto.usage),
|
|
257
260
|
durationMs: dto.duration_ms,
|
|
261
|
+
suggestions: dto.suggestions,
|
|
258
262
|
};
|
|
259
263
|
},
|
|
260
264
|
|
|
@@ -278,6 +282,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
278
282
|
message,
|
|
279
283
|
...(access?.roleId !== undefined ? { role_id: access.roleId } : {}),
|
|
280
284
|
...(access?.client ? { client: access.client } : {}),
|
|
285
|
+
...(access?.service ? { service: access.service } : {}),
|
|
281
286
|
...(access?.modelId ? { model_id: access.modelId } : {}),
|
|
282
287
|
}),
|
|
283
288
|
});
|
|
@@ -304,7 +309,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
304
309
|
requestId: dto.request_id, sessionId: dto.session_id, answer: dto.answer,
|
|
305
310
|
sources: (dto.sources || []).map(normalizeSource),
|
|
306
311
|
toolCalls: (dto.tool_calls || []).map(normalizeToolCall),
|
|
307
|
-
usage: normalizeUsage(dto.usage), durationMs: dto.duration_ms,
|
|
312
|
+
usage: normalizeUsage(dto.usage), durationMs: dto.duration_ms, suggestions: dto.suggestions,
|
|
308
313
|
};
|
|
309
314
|
}
|
|
310
315
|
|
|
@@ -319,6 +324,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
319
324
|
toolCalls: ToolCall[];
|
|
320
325
|
usage: TokenUsage;
|
|
321
326
|
durationMs?: number;
|
|
327
|
+
suggestions?: string[];
|
|
322
328
|
};
|
|
323
329
|
const finalResult: { value: StreamResult | null } = { value: null };
|
|
324
330
|
|
|
@@ -340,6 +346,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
340
346
|
tool_calls?: ToolCallDto[];
|
|
341
347
|
usage?: TokenUsageDto;
|
|
342
348
|
duration_ms?: number;
|
|
349
|
+
suggestions?: string[];
|
|
343
350
|
message?: string;
|
|
344
351
|
} = {};
|
|
345
352
|
try {
|
|
@@ -365,6 +372,7 @@ export function createChatApi(initialBaseUrl?: string): ChatApiClient {
|
|
|
365
372
|
? normalizeUsage(data.usage)
|
|
366
373
|
: { model: "", promptTokens: 0, completionTokens: 0, totalTokens: 0 },
|
|
367
374
|
durationMs: data.duration_ms,
|
|
375
|
+
suggestions: data.suggestions,
|
|
368
376
|
};
|
|
369
377
|
} else if (data.type === "error") {
|
|
370
378
|
throw {
|
|
@@ -41,24 +41,29 @@ export interface ChatMessage {
|
|
|
41
41
|
toolCalls?: ToolCall[];
|
|
42
42
|
usage?: TokenUsage;
|
|
43
43
|
feedback?: MessageFeedback;
|
|
44
|
+
suggestions?: string[];
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
export type ChatServiceArea = "vessel" | "tot";
|
|
48
|
+
|
|
46
49
|
export interface ChatUserContext {
|
|
47
50
|
customerId?: string;
|
|
48
51
|
email?: string;
|
|
49
52
|
name?: string;
|
|
50
53
|
/** Display name of the role, if the host application has one. */
|
|
51
54
|
role?: string;
|
|
52
|
-
/**
|
|
55
|
+
/** Customer Portal role ID used to personalize help and route knowledge. */
|
|
53
56
|
roleId?: number;
|
|
54
|
-
/** Client experience
|
|
57
|
+
/** Client experience. The widget infers it from a known role ID when omitted. */
|
|
55
58
|
client?: "mobile" | "web" | "admin";
|
|
59
|
+
service?: ChatServiceArea;
|
|
56
60
|
page?: string;
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
export interface ChatAccessContext {
|
|
60
64
|
roleId?: number;
|
|
61
65
|
client?: "mobile" | "web" | "admin";
|
|
66
|
+
service?: ChatServiceArea;
|
|
62
67
|
modelId?: string;
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -161,6 +166,7 @@ export interface ChatResponseDto {
|
|
|
161
166
|
usage: TokenUsageDto;
|
|
162
167
|
duration_ms?: number;
|
|
163
168
|
role?: RoleDto | null;
|
|
169
|
+
suggestions?: string[];
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
export interface RoleDto {
|
|
@@ -168,6 +174,8 @@ export interface RoleDto {
|
|
|
168
174
|
usertype: string;
|
|
169
175
|
channel: "mobile" | "web" | "admin";
|
|
170
176
|
knowledge_scopes: string[];
|
|
177
|
+
services?: ChatServiceArea[];
|
|
178
|
+
menu_items?: string[];
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
export interface TicketDto {
|
|
@@ -157,6 +157,58 @@ describe("chatbot UI", () => {
|
|
|
157
157
|
);
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
+
it("uses the role ID to send role context and starts a fresh chat when it changes", async () => {
|
|
161
|
+
const user = userEvent.setup();
|
|
162
|
+
const { rerender } = render(<ChatbotWidget open roleId={9} />);
|
|
163
|
+
const question = "How do I pre-register a vessel sample in the mobile app?";
|
|
164
|
+
|
|
165
|
+
await user.click(screen.getByRole("button", { name: question }));
|
|
166
|
+
await user.keyboard("{Enter}");
|
|
167
|
+
expect(await screen.findByText("Transformer oil reports are available in the Reports page.")).toBeVisible();
|
|
168
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
169
|
+
"/api/v1/sessions/session-1/messages/stream",
|
|
170
|
+
expect.objectContaining({
|
|
171
|
+
body: JSON.stringify({ message: question, role_id: 9, client: "mobile", model_id: "auto" }),
|
|
172
|
+
})
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
rerender(<ChatbotWidget open roleId={11} />);
|
|
176
|
+
expect(screen.queryByText("Transformer oil reports are available in the Reports page.")).not.toBeInTheDocument();
|
|
177
|
+
expect(screen.getByRole("button", { name: "Where can I download a transformer oil report?" })).toBeVisible();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("shows a service clarification and reuses the session when the service changes", async () => {
|
|
181
|
+
const user = userEvent.setup();
|
|
182
|
+
const question = "Where do I download my reports?";
|
|
183
|
+
const answer = "Which service are you using?";
|
|
184
|
+
const fetchMock = vi.mocked(fetch);
|
|
185
|
+
fetchMock.mockImplementation(async (input, init) => {
|
|
186
|
+
const url = String(input);
|
|
187
|
+
if (url.endsWith("/api/v1/sessions")) return jsonResponse({ session_id: "session-1" });
|
|
188
|
+
if (url.includes("/messages")) {
|
|
189
|
+
const body = JSON.parse(String(init?.body));
|
|
190
|
+
return jsonResponse({ session_id: "session-1", request_id: body.message, usage,
|
|
191
|
+
answer: body.message === question ? answer : "Open Reports and choose VPS Power.",
|
|
192
|
+
suggestions: body.message === question ? ["Vessel", "Transformer Oil Testing (TOT)"] : [] });
|
|
193
|
+
}
|
|
194
|
+
return jsonResponse({}, 404);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const { rerender } = render(<ChatbotWidget open roleId={10} />);
|
|
198
|
+
const input = screen.getByLabelText("Chat message");
|
|
199
|
+
await user.type(input, question);
|
|
200
|
+
await user.keyboard("{Enter}");
|
|
201
|
+
expect(await screen.findByText(answer)).toBeVisible();
|
|
202
|
+
await user.click(screen.getByRole("button", { name: "Transformer Oil Testing (TOT)" }));
|
|
203
|
+
rerender(<ChatbotWidget open roleId={10} service="tot" />);
|
|
204
|
+
await user.keyboard("{Enter}");
|
|
205
|
+
expect(await screen.findByText("Open Reports and choose VPS Power.")).toBeVisible();
|
|
206
|
+
expect(fetchMock).toHaveBeenLastCalledWith("/api/v1/sessions/session-1/messages/stream", expect.objectContaining({
|
|
207
|
+
body: JSON.stringify({ message: "Transformer Oil Testing (TOT)", role_id: 10, client: "admin", service: "tot", model_id: "auto" }),
|
|
208
|
+
}));
|
|
209
|
+
expect(fetchMock.mock.calls.filter(([url]) => String(url).endsWith("/api/v1/sessions"))).toHaveLength(1);
|
|
210
|
+
});
|
|
211
|
+
|
|
160
212
|
it("copies only the completed assistant reply and reports clipboard failures", async () => {
|
|
161
213
|
const user = userEvent.setup();
|
|
162
214
|
render(<ChatbotWidget defaultOpen />);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ChatAccessContext, ChatServiceArea } from "../api/chatbot-types";
|
|
2
|
+
|
|
3
|
+
interface PortalRole {
|
|
4
|
+
name: string;
|
|
5
|
+
client: NonNullable<ChatAccessContext["client"]>;
|
|
6
|
+
topics: string;
|
|
7
|
+
questions: readonly string[];
|
|
8
|
+
services: readonly ChatServiceArea[];
|
|
9
|
+
serviceQuestions?: Partial<Record<ChatServiceArea, readonly string[]>>;
|
|
10
|
+
webQuestions?: readonly string[];
|
|
11
|
+
webServiceQuestions?: Partial<Record<ChatServiceArea, readonly string[]>>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const BOTH_SERVICES = ["vessel", "tot"] as const;
|
|
15
|
+
|
|
16
|
+
export const CUSTOMER_PORTAL_ROLES = {
|
|
17
|
+
1: {
|
|
18
|
+
name: "CC Report",
|
|
19
|
+
client: "web",
|
|
20
|
+
services: BOTH_SERVICES,
|
|
21
|
+
topics: "finding, filtering, and downloading reports",
|
|
22
|
+
questions: ["How do I download a fuel report?", "How do I filter lubricant reports?", "How do I find a transformer oil report?"],
|
|
23
|
+
serviceQuestions: {
|
|
24
|
+
vessel: ["How do I download a fuel report?", "How do I filter lubricant reports?"],
|
|
25
|
+
tot: ["How do I find a transformer oil report?", "How do I download a transformer oil report as a PDF?"],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
2: {
|
|
29
|
+
name: "Client Admin",
|
|
30
|
+
client: "admin",
|
|
31
|
+
services: BOTH_SERVICES,
|
|
32
|
+
topics: "client access, Vessel and TOT workflows, and VPS support",
|
|
33
|
+
questions: ["How do I add a client user?", "How do I find reports for a vessel or transformer?", "Why is a portal menu missing for a client user?"],
|
|
34
|
+
},
|
|
35
|
+
6: {
|
|
36
|
+
name: "Fleet Manager",
|
|
37
|
+
client: "web",
|
|
38
|
+
services: ["vessel"],
|
|
39
|
+
topics: "vessels, marine samples, reports, and fleet trends",
|
|
40
|
+
questions: ["How do I find reports for a vessel?", "Where can I find a vessel's sample status?", "How do I review fleet fuel trends?"],
|
|
41
|
+
},
|
|
42
|
+
7: {
|
|
43
|
+
name: "High Level Management",
|
|
44
|
+
client: "web",
|
|
45
|
+
services: BOTH_SERVICES,
|
|
46
|
+
topics: "management dashboards and trend comparisons",
|
|
47
|
+
questions: ["How do I compare fuel trends across vessels?", "How do I review transformer oil trends?", "Where is the CII Dashboard?"],
|
|
48
|
+
},
|
|
49
|
+
9: {
|
|
50
|
+
name: "Sampler",
|
|
51
|
+
client: "mobile",
|
|
52
|
+
services: BOTH_SERVICES,
|
|
53
|
+
topics: "sample pre-registration, barcode scanning, and labels in the mobile app",
|
|
54
|
+
questions: ["How do I pre-register a vessel sample in the mobile app?", "How do I scan a sample label?", "How do I pre-register a transformer sample in the mobile app?"],
|
|
55
|
+
serviceQuestions: {
|
|
56
|
+
vessel: ["How do I pre-register a vessel sample in the mobile app?", "How do I scan a vessel sample label?"],
|
|
57
|
+
tot: ["How do I pre-register a transformer sample in the mobile app?", "How do I scan a transformer sample label?"],
|
|
58
|
+
},
|
|
59
|
+
webQuestions: ["How do I pre-register a vessel sample in the portal?", "How do I pre-register a transformer sample in the portal?"],
|
|
60
|
+
webServiceQuestions: {
|
|
61
|
+
vessel: ["How do I pre-register a vessel sample in the portal?", "Where can I download my fuel report?"],
|
|
62
|
+
tot: ["How do I pre-register a transformer sample in the portal?", "Where can I download a transformer oil report?"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
10: {
|
|
66
|
+
name: "VPS Admin",
|
|
67
|
+
client: "admin",
|
|
68
|
+
services: BOTH_SERVICES,
|
|
69
|
+
topics: "Vessel and TOT workflows, portal administration, and VPS support",
|
|
70
|
+
questions: ["How do I review a portal registration request?", "Where do I find vessel reports?", "How do I view transformer oil test trends?"],
|
|
71
|
+
},
|
|
72
|
+
11: {
|
|
73
|
+
name: "Transoil",
|
|
74
|
+
client: "web",
|
|
75
|
+
services: ["tot"],
|
|
76
|
+
topics: "transformer assets, oil reports, and trends",
|
|
77
|
+
questions: ["How do I find my transformer equipment?", "Where can I download a transformer oil report?", "How do I review transformer oil trends?"],
|
|
78
|
+
},
|
|
79
|
+
12: {
|
|
80
|
+
name: "Bunker Master Only",
|
|
81
|
+
client: "mobile",
|
|
82
|
+
services: ["vessel"],
|
|
83
|
+
topics: "Bunker Master access, calculators, and Fuel Change-Over",
|
|
84
|
+
questions: ["How do I request Bunker Master access?", "Where can I find the Bunker Master calculators?", "How do I download the Fuel Change-Over workbook?"],
|
|
85
|
+
},
|
|
86
|
+
13: {
|
|
87
|
+
name: "Fleet Manager Transoil",
|
|
88
|
+
client: "web",
|
|
89
|
+
services: ["tot"],
|
|
90
|
+
topics: "transformer equipment, reports, and fleet trends",
|
|
91
|
+
questions: ["How do I compare transformer oil trends for equipment?", "How do I filter transformer oil reports by site?", "How do I pre-register a transformer sample?"],
|
|
92
|
+
},
|
|
93
|
+
} as const satisfies Record<number, PortalRole>;
|
|
94
|
+
|
|
95
|
+
export type CustomerPortalRoleId = keyof typeof CUSTOMER_PORTAL_ROLES;
|
|
96
|
+
|
|
97
|
+
export function findPortalRole(roleId?: number): PortalRole | undefined {
|
|
98
|
+
return CUSTOMER_PORTAL_ROLES[roleId as CustomerPortalRoleId];
|
|
99
|
+
}
|
|
@@ -2,11 +2,13 @@ import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
|
2
2
|
import { createChatApi, type ChatApiClient } from "../api/chatbot-api";
|
|
3
3
|
import type {
|
|
4
4
|
ChatMessage,
|
|
5
|
+
ChatServiceArea,
|
|
5
6
|
ChatUserContext,
|
|
6
7
|
Suggestion,
|
|
7
8
|
ModelOption,
|
|
8
9
|
} from "../api/chatbot-types";
|
|
9
10
|
import { DEFAULT_SUGGESTIONS } from "../config/suggestions";
|
|
11
|
+
import { findPortalRole } from "../config/roles";
|
|
10
12
|
import { useResponseSound } from "../hooks/useResponseSound";
|
|
11
13
|
import { ChatContext, type ChatContextValue, type ChatUiStatus } from "./ChatContext";
|
|
12
14
|
|
|
@@ -30,10 +32,12 @@ export interface ChatProviderProps {
|
|
|
30
32
|
userContext?: ChatUserContext;
|
|
31
33
|
/** Direct role name prop (e.g. "VPS Admin", "Client User", "Captain") */
|
|
32
34
|
role?: string;
|
|
33
|
-
/**
|
|
35
|
+
/** Customer Portal role ID used to tailor questions and route knowledge */
|
|
34
36
|
roleId?: number;
|
|
35
37
|
/** Direct client experience prop ("web" | "mobile" | "admin") */
|
|
36
38
|
client?: "mobile" | "web" | "admin";
|
|
39
|
+
/** Active VPS service, when the portal already knows it. */
|
|
40
|
+
service?: ChatServiceArea;
|
|
37
41
|
/** Optional custom welcome message to display as initial assistant response */
|
|
38
42
|
welcomeMessage?: string;
|
|
39
43
|
suggestions?: Suggestion[];
|
|
@@ -80,14 +84,22 @@ function friendlyError(err: unknown): string {
|
|
|
80
84
|
return "I couldn't process that request right now.";
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
87
|
+
export const ChatProvider: React.FC<ChatProviderProps> = (props) => {
|
|
88
|
+
const roleId = props.roleId ?? props.userContext?.roleId;
|
|
89
|
+
const clientChannel = props.client ?? props.userContext?.client ?? findPortalRole(roleId)?.client;
|
|
90
|
+
const scopeKey = JSON.stringify([roleId, clientChannel, props.userContext?.customerId, props.userContext?.email]);
|
|
91
|
+
return <ChatSessionProvider key={scopeKey} {...props} roleId={roleId} client={clientChannel} />;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const ChatSessionProvider: React.FC<ChatProviderProps> = ({
|
|
84
95
|
children,
|
|
85
96
|
userContext = {},
|
|
86
97
|
role,
|
|
87
98
|
roleId,
|
|
88
99
|
client: clientChannel,
|
|
100
|
+
service,
|
|
89
101
|
welcomeMessage,
|
|
90
|
-
suggestions
|
|
102
|
+
suggestions,
|
|
91
103
|
disableSuggestions = false,
|
|
92
104
|
initialMessage,
|
|
93
105
|
apiBaseUrl,
|
|
@@ -103,26 +115,39 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
103
115
|
() => api ?? createChatApi(resolvedBaseUrl),
|
|
104
116
|
[api, resolvedBaseUrl]
|
|
105
117
|
);
|
|
118
|
+
const portalRole = findPortalRole(roleId);
|
|
119
|
+
const activeService = service ?? userContext.service;
|
|
120
|
+
const effectiveSuggestions = useMemo(() => {
|
|
121
|
+
if (suggestions) return suggestions;
|
|
122
|
+
if (!portalRole) return DEFAULT_SUGGESTIONS;
|
|
123
|
+
const webExperience = clientChannel === "web" && portalRole.webQuestions;
|
|
124
|
+
const groupedQuestions = webExperience ? portalRole.webServiceQuestions : portalRole.serviceQuestions;
|
|
125
|
+
const questions = (activeService && groupedQuestions?.[activeService]) || webExperience || portalRole.questions;
|
|
126
|
+
return questions.map((query) => ({ label: query, query }));
|
|
127
|
+
}, [activeService, clientChannel, portalRole, suggestions]);
|
|
106
128
|
|
|
107
129
|
const effectiveUserContext = useMemo<ChatUserContext>(() => {
|
|
108
130
|
return {
|
|
109
131
|
...userContext,
|
|
110
|
-
|
|
132
|
+
role: role ?? userContext.role ?? portalRole?.name,
|
|
111
133
|
...(roleId !== undefined ? { roleId } : {}),
|
|
112
134
|
...(clientChannel !== undefined ? { client: clientChannel } : {}),
|
|
135
|
+
...(service !== undefined ? { service } : {}),
|
|
113
136
|
};
|
|
114
|
-
}, [userContext, role, roleId, clientChannel]);
|
|
137
|
+
}, [userContext, role, roleId, clientChannel, portalRole, service]);
|
|
115
138
|
|
|
116
139
|
const defaultWelcomeMsg = useMemo<ChatMessage | null>(() => {
|
|
117
140
|
if (welcomeMessage === "") return null;
|
|
118
141
|
return {
|
|
119
142
|
id: "welcome-default",
|
|
120
143
|
role: "assistant",
|
|
121
|
-
content: welcomeMessage
|
|
144
|
+
content: welcomeMessage ?? (portalRole
|
|
145
|
+
? `Hello! I’m your **VPS Veritas assistant**. I can help with ${portalRole.topics}. What would you like to do?`
|
|
146
|
+
: DEFAULT_WELCOME_TEXT),
|
|
122
147
|
createdAt: new Date().toISOString(),
|
|
123
148
|
status: "complete",
|
|
124
149
|
};
|
|
125
|
-
}, [welcomeMessage]);
|
|
150
|
+
}, [portalRole, welcomeMessage]);
|
|
126
151
|
|
|
127
152
|
const [sessionId, setSessionId] = useState<string | null>(null);
|
|
128
153
|
const [messages, setMessages] = useState<ChatMessage[]>(() => {
|
|
@@ -250,6 +275,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
250
275
|
{
|
|
251
276
|
roleId: effectiveUserContext.roleId,
|
|
252
277
|
client: effectiveUserContext.client,
|
|
278
|
+
service: effectiveUserContext.service,
|
|
253
279
|
modelId: selectedModelId,
|
|
254
280
|
},
|
|
255
281
|
updateProgress,
|
|
@@ -271,6 +297,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
271
297
|
: await client.sendMessage(currentSession, text, {
|
|
272
298
|
roleId: effectiveUserContext.roleId,
|
|
273
299
|
client: effectiveUserContext.client,
|
|
300
|
+
service: effectiveUserContext.service,
|
|
274
301
|
modelId: selectedModelId,
|
|
275
302
|
}, controller.signal);
|
|
276
303
|
|
|
@@ -290,6 +317,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
290
317
|
status: "complete",
|
|
291
318
|
progressText: undefined,
|
|
292
319
|
sources: response.sources,
|
|
320
|
+
suggestions: response.suggestions,
|
|
293
321
|
toolCalls: response.toolCalls,
|
|
294
322
|
usage: response.usage,
|
|
295
323
|
durationMs: Math.max(
|
|
@@ -324,7 +352,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
324
352
|
}
|
|
325
353
|
}
|
|
326
354
|
},
|
|
327
|
-
[ensureSession, client, effectiveUserContext.client, effectiveUserContext.roleId, selectedModelId, prepareSound, playSound]
|
|
355
|
+
[ensureSession, client, effectiveUserContext.client, effectiveUserContext.roleId, effectiveUserContext.service, selectedModelId, prepareSound, playSound]
|
|
328
356
|
);
|
|
329
357
|
|
|
330
358
|
const sendMessage = useCallback(
|
|
@@ -391,6 +419,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
391
419
|
void sendMessage(initialMessage);
|
|
392
420
|
}, [initialMessage, sendMessage]);
|
|
393
421
|
|
|
422
|
+
const followUpChoices = messages[messages.length - 1]?.suggestions;
|
|
394
423
|
const value = useMemo(
|
|
395
424
|
() => ({
|
|
396
425
|
messages,
|
|
@@ -400,7 +429,9 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
400
429
|
pendingTicket: null,
|
|
401
430
|
ticketBusy: false,
|
|
402
431
|
lastTicket: null,
|
|
403
|
-
suggestions
|
|
432
|
+
suggestions: followUpChoices?.length
|
|
433
|
+
? followUpChoices.map((query) => ({ label: query, query }))
|
|
434
|
+
: effectiveSuggestions,
|
|
404
435
|
showSuggestions:
|
|
405
436
|
!disableSuggestions &&
|
|
406
437
|
status === "idle" &&
|
|
@@ -430,7 +461,8 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
430
461
|
status,
|
|
431
462
|
error,
|
|
432
463
|
sessionId,
|
|
433
|
-
|
|
464
|
+
effectiveSuggestions,
|
|
465
|
+
followUpChoices,
|
|
434
466
|
disableSuggestions,
|
|
435
467
|
effectiveUserContext,
|
|
436
468
|
client.apiBaseUrl,
|
|
@@ -4,7 +4,7 @@ import { EmbeddedChatbotTrigger } from "./EmbeddedChatbotTrigger";
|
|
|
4
4
|
import { type EnvStage } from "../../components/EnvBadge";
|
|
5
5
|
import { useOptionalChatContext } from "../core/ChatContext";
|
|
6
6
|
import { ChatProvider } from "../core/ChatProvider";
|
|
7
|
-
import type { ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
7
|
+
import type { ChatServiceArea, ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
8
8
|
import { resolveApiBaseUrl } from "../api/chatbot-api";
|
|
9
9
|
|
|
10
10
|
export interface EmbeddedChatbotProps {
|
|
@@ -17,10 +17,11 @@ export interface EmbeddedChatbotProps {
|
|
|
17
17
|
envPulse?: boolean;
|
|
18
18
|
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
19
19
|
role?: string;
|
|
20
|
-
/**
|
|
20
|
+
/** Customer Portal role ID used to tailor questions and route knowledge */
|
|
21
21
|
roleId?: number;
|
|
22
22
|
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
23
23
|
client?: "mobile" | "web" | "admin";
|
|
24
|
+
service?: ChatServiceArea;
|
|
24
25
|
/** Optional custom initial welcome message */
|
|
25
26
|
welcomeMessage?: string;
|
|
26
27
|
/** Backend or proxy API base URL */
|
|
@@ -105,6 +106,7 @@ export const EmbeddedChatbot: React.FC<EmbeddedChatbotProps> = ({
|
|
|
105
106
|
role,
|
|
106
107
|
roleId,
|
|
107
108
|
client,
|
|
109
|
+
service,
|
|
108
110
|
welcomeMessage,
|
|
109
111
|
suggestions,
|
|
110
112
|
disableSuggestions,
|
|
@@ -124,6 +126,7 @@ export const EmbeddedChatbot: React.FC<EmbeddedChatbotProps> = ({
|
|
|
124
126
|
role === undefined &&
|
|
125
127
|
roleId === undefined &&
|
|
126
128
|
client === undefined &&
|
|
129
|
+
service === undefined &&
|
|
127
130
|
welcomeMessage === undefined &&
|
|
128
131
|
!suggestions &&
|
|
129
132
|
disableSuggestions === undefined &&
|
|
@@ -142,6 +145,7 @@ export const EmbeddedChatbot: React.FC<EmbeddedChatbotProps> = ({
|
|
|
142
145
|
role={role}
|
|
143
146
|
roleId={roleId}
|
|
144
147
|
client={client}
|
|
148
|
+
service={service}
|
|
145
149
|
welcomeMessage={welcomeMessage}
|
|
146
150
|
suggestions={suggestions}
|
|
147
151
|
disableSuggestions={disableSuggestions}
|
package/src/chatbot/index.ts
CHANGED
|
@@ -12,9 +12,11 @@ export {
|
|
|
12
12
|
type ChatApiClient,
|
|
13
13
|
} from "./api/chatbot-api";
|
|
14
14
|
export { ColorPalette } from "./config/colors";
|
|
15
|
+
export { CUSTOMER_PORTAL_ROLES, type CustomerPortalRoleId } from "./config/roles";
|
|
15
16
|
export type {
|
|
16
17
|
ChatUserContext,
|
|
17
18
|
ChatAccessContext,
|
|
19
|
+
ChatServiceArea,
|
|
18
20
|
ChatMessage,
|
|
19
21
|
Suggestion,
|
|
20
22
|
Ticket,
|
|
@@ -4,7 +4,7 @@ import { ChatbotWidgetTrigger } from "./ChatbotWidgetTrigger";
|
|
|
4
4
|
import { type EnvStage } from "../../components/EnvBadge";
|
|
5
5
|
import { useOptionalChatContext } from "../core/ChatContext";
|
|
6
6
|
import { ChatProvider } from "../core/ChatProvider";
|
|
7
|
-
import type { ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
7
|
+
import type { ChatServiceArea, ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
8
8
|
import { resolveApiBaseUrl } from "../api/chatbot-api";
|
|
9
9
|
|
|
10
10
|
|
|
@@ -17,10 +17,11 @@ export interface ChatbotWidgetProps {
|
|
|
17
17
|
envPulse?: boolean;
|
|
18
18
|
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
19
19
|
role?: string;
|
|
20
|
-
/**
|
|
20
|
+
/** Customer Portal role ID used to tailor questions and route knowledge */
|
|
21
21
|
roleId?: number;
|
|
22
22
|
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
23
23
|
client?: "mobile" | "web" | "admin";
|
|
24
|
+
service?: ChatServiceArea;
|
|
24
25
|
/** Optional custom initial welcome message */
|
|
25
26
|
welcomeMessage?: string;
|
|
26
27
|
/** Backend or proxy API base URL */
|
|
@@ -85,6 +86,7 @@ export const ChatbotWidget: React.FC<ChatbotWidgetProps> = ({
|
|
|
85
86
|
role,
|
|
86
87
|
roleId,
|
|
87
88
|
client,
|
|
89
|
+
service,
|
|
88
90
|
welcomeMessage,
|
|
89
91
|
suggestions,
|
|
90
92
|
disableSuggestions,
|
|
@@ -104,6 +106,7 @@ export const ChatbotWidget: React.FC<ChatbotWidgetProps> = ({
|
|
|
104
106
|
role === undefined &&
|
|
105
107
|
roleId === undefined &&
|
|
106
108
|
client === undefined &&
|
|
109
|
+
service === undefined &&
|
|
107
110
|
welcomeMessage === undefined &&
|
|
108
111
|
!suggestions &&
|
|
109
112
|
disableSuggestions === undefined &&
|
|
@@ -122,6 +125,7 @@ export const ChatbotWidget: React.FC<ChatbotWidgetProps> = ({
|
|
|
122
125
|
role={role}
|
|
123
126
|
roleId={roleId}
|
|
124
127
|
client={client}
|
|
128
|
+
service={service}
|
|
125
129
|
welcomeMessage={welcomeMessage}
|
|
126
130
|
suggestions={suggestions}
|
|
127
131
|
disableSuggestions={disableSuggestions}
|
package/src/index.css
CHANGED
|
@@ -690,6 +690,14 @@ button {
|
|
|
690
690
|
gap: 6px;
|
|
691
691
|
}
|
|
692
692
|
|
|
693
|
+
.app-role-select {
|
|
694
|
+
display: flex;
|
|
695
|
+
align-items: center;
|
|
696
|
+
gap: 6px;
|
|
697
|
+
font-size: 0.75rem;
|
|
698
|
+
color: var(--text-muted);
|
|
699
|
+
}
|
|
700
|
+
|
|
693
701
|
/* Mode toggle buttons (Widget / Slide-out) */
|
|
694
702
|
.mode-btn {
|
|
695
703
|
display: inline-flex;
|