vpschatbotwidget 1.2.4 → 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 +3962 -3857
- 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/ChatHeader.tsx +5 -2
- package/src/chatbot/core/ChatMessage.tsx +3 -1
- package/src/chatbot/core/ChatProvider.tsx +42 -10
- package/src/chatbot/embedded/EmbeddedChatbot.tsx +24 -3
- package/src/chatbot/embedded/EmbeddedChatbotTrigger.tsx +2 -2
- package/src/chatbot/index.ts +2 -0
- package/src/chatbot/widget/ChatbotWidget.tsx +6 -2
- package/src/index.css +17 -2
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ A React 19 and TypeScript chat widget for the VPS Customer Portal. Use the float
|
|
|
14
14
|
- [2. Standalone Slide-out Panel](#2-standalone-slide-out-panel)
|
|
15
15
|
- [3. Shared Conversation Mode](#3-shared-conversation-mode-multiple-views)
|
|
16
16
|
- [Conversation UI](#conversation-ui)
|
|
17
|
+
- [Role-aware chat](#role-aware-chat)
|
|
17
18
|
- [API & Proxy URL Configuration](#api--proxy-url-configuration)
|
|
18
19
|
- [URL Normalization Behavior](#url-normalization-behavior)
|
|
19
20
|
- [Component Props Reference](#component-props-reference)
|
|
@@ -154,6 +155,18 @@ export function App() {
|
|
|
154
155
|
|
|
155
156
|
---
|
|
156
157
|
|
|
158
|
+
## Role-aware chat
|
|
159
|
+
|
|
160
|
+
Pass the active Customer Portal role ID to `ChatbotWidget`, `EmbeddedChatbot`, or a shared `ChatProvider`. You can also set `userContext.roleId`.
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
<ChatbotWidget roleId={currentUser.roleId} service="tot" apiBaseUrl="/api" />
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Use `service="vessel"` or `service="tot"` when the current portal screen already identifies the service. Leave it unset for automatic routing and service clarification. `userContext.service` works as well. The widget uses the role and service for starter questions and displays the chatbot's clarification choices in the composer. The conversation continues when the service changes. Switching accounts, roles, or clients starts a fresh conversation. Use `client="web"` to select browser guidance for a role that also has a mobile or admin experience.
|
|
167
|
+
|
|
168
|
+
Private VPS Admin guidance requires a trusted portal proxy. The proxy verifies the active user and session ownership, derives the role from the authenticated portal session, and attaches the API credential server-side.
|
|
169
|
+
|
|
157
170
|
## API & Proxy URL Configuration
|
|
158
171
|
|
|
159
172
|
Pass the API URL as a prop, use a same-origin proxy, or configure it when building the frontend with Vite.
|
|
@@ -17,6 +17,7 @@ export interface ChatApiClient {
|
|
|
17
17
|
toolCalls: ToolCall[];
|
|
18
18
|
usage: TokenUsage;
|
|
19
19
|
durationMs?: number;
|
|
20
|
+
suggestions?: string[];
|
|
20
21
|
}>;
|
|
21
22
|
sendMessageStream?(sessionId: string, message: string, access?: ChatAccessContext, onProgress?: (stage: string) => void, onToken?: (token: string) => void, signal?: AbortSignal): Promise<{
|
|
22
23
|
requestId: string;
|
|
@@ -26,6 +27,7 @@ export interface ChatApiClient {
|
|
|
26
27
|
toolCalls: ToolCall[];
|
|
27
28
|
usage: TokenUsage;
|
|
28
29
|
durationMs?: number;
|
|
30
|
+
suggestions?: string[];
|
|
29
31
|
}>;
|
|
30
32
|
getHistory(sessionId: string): Promise<ChatMessage[]>;
|
|
31
33
|
closeSession(sessionId: string): Promise<void>;
|
|
@@ -35,22 +35,26 @@ export interface ChatMessage {
|
|
|
35
35
|
toolCalls?: ToolCall[];
|
|
36
36
|
usage?: TokenUsage;
|
|
37
37
|
feedback?: MessageFeedback;
|
|
38
|
+
suggestions?: string[];
|
|
38
39
|
}
|
|
40
|
+
export type ChatServiceArea = "vessel" | "tot";
|
|
39
41
|
export interface ChatUserContext {
|
|
40
42
|
customerId?: string;
|
|
41
43
|
email?: string;
|
|
42
44
|
name?: string;
|
|
43
45
|
/** Display name of the role, if the host application has one. */
|
|
44
46
|
role?: string;
|
|
45
|
-
/**
|
|
47
|
+
/** Customer Portal role ID used to personalize help and route knowledge. */
|
|
46
48
|
roleId?: number;
|
|
47
|
-
/** Client experience
|
|
49
|
+
/** Client experience. The widget infers it from a known role ID when omitted. */
|
|
48
50
|
client?: "mobile" | "web" | "admin";
|
|
51
|
+
service?: ChatServiceArea;
|
|
49
52
|
page?: string;
|
|
50
53
|
}
|
|
51
54
|
export interface ChatAccessContext {
|
|
52
55
|
roleId?: number;
|
|
53
56
|
client?: "mobile" | "web" | "admin";
|
|
57
|
+
service?: ChatServiceArea;
|
|
54
58
|
modelId?: string;
|
|
55
59
|
}
|
|
56
60
|
export interface ModelOption {
|
|
@@ -139,12 +143,15 @@ export interface ChatResponseDto {
|
|
|
139
143
|
usage: TokenUsageDto;
|
|
140
144
|
duration_ms?: number;
|
|
141
145
|
role?: RoleDto | null;
|
|
146
|
+
suggestions?: string[];
|
|
142
147
|
}
|
|
143
148
|
export interface RoleDto {
|
|
144
149
|
id: number;
|
|
145
150
|
usertype: string;
|
|
146
151
|
channel: "mobile" | "web" | "admin";
|
|
147
152
|
knowledge_scopes: string[];
|
|
153
|
+
services?: ChatServiceArea[];
|
|
154
|
+
menu_items?: string[];
|
|
148
155
|
}
|
|
149
156
|
export interface TicketDto {
|
|
150
157
|
ticket_id: string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ChatAccessContext, ChatServiceArea } from "../api/chatbot-types";
|
|
2
|
+
interface PortalRole {
|
|
3
|
+
name: string;
|
|
4
|
+
client: NonNullable<ChatAccessContext["client"]>;
|
|
5
|
+
topics: string;
|
|
6
|
+
questions: readonly string[];
|
|
7
|
+
services: readonly ChatServiceArea[];
|
|
8
|
+
serviceQuestions?: Partial<Record<ChatServiceArea, readonly string[]>>;
|
|
9
|
+
webQuestions?: readonly string[];
|
|
10
|
+
webServiceQuestions?: Partial<Record<ChatServiceArea, readonly string[]>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const CUSTOMER_PORTAL_ROLES: {
|
|
13
|
+
readonly 1: {
|
|
14
|
+
readonly name: "CC Report";
|
|
15
|
+
readonly client: "web";
|
|
16
|
+
readonly services: readonly ["vessel", "tot"];
|
|
17
|
+
readonly topics: "finding, filtering, and downloading reports";
|
|
18
|
+
readonly questions: readonly ["How do I download a fuel report?", "How do I filter lubricant reports?", "How do I find a transformer oil report?"];
|
|
19
|
+
readonly serviceQuestions: {
|
|
20
|
+
readonly vessel: readonly ["How do I download a fuel report?", "How do I filter lubricant reports?"];
|
|
21
|
+
readonly tot: readonly ["How do I find a transformer oil report?", "How do I download a transformer oil report as a PDF?"];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
readonly 2: {
|
|
25
|
+
readonly name: "Client Admin";
|
|
26
|
+
readonly client: "admin";
|
|
27
|
+
readonly services: readonly ["vessel", "tot"];
|
|
28
|
+
readonly topics: "client access, Vessel and TOT workflows, and VPS support";
|
|
29
|
+
readonly questions: readonly ["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?"];
|
|
30
|
+
};
|
|
31
|
+
readonly 6: {
|
|
32
|
+
readonly name: "Fleet Manager";
|
|
33
|
+
readonly client: "web";
|
|
34
|
+
readonly services: readonly ["vessel"];
|
|
35
|
+
readonly topics: "vessels, marine samples, reports, and fleet trends";
|
|
36
|
+
readonly questions: readonly ["How do I find reports for a vessel?", "Where can I find a vessel's sample status?", "How do I review fleet fuel trends?"];
|
|
37
|
+
};
|
|
38
|
+
readonly 7: {
|
|
39
|
+
readonly name: "High Level Management";
|
|
40
|
+
readonly client: "web";
|
|
41
|
+
readonly services: readonly ["vessel", "tot"];
|
|
42
|
+
readonly topics: "management dashboards and trend comparisons";
|
|
43
|
+
readonly questions: readonly ["How do I compare fuel trends across vessels?", "How do I review transformer oil trends?", "Where is the CII Dashboard?"];
|
|
44
|
+
};
|
|
45
|
+
readonly 9: {
|
|
46
|
+
readonly name: "Sampler";
|
|
47
|
+
readonly client: "mobile";
|
|
48
|
+
readonly services: readonly ["vessel", "tot"];
|
|
49
|
+
readonly topics: "sample pre-registration, barcode scanning, and labels in the mobile app";
|
|
50
|
+
readonly questions: readonly ["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?"];
|
|
51
|
+
readonly serviceQuestions: {
|
|
52
|
+
readonly vessel: readonly ["How do I pre-register a vessel sample in the mobile app?", "How do I scan a vessel sample label?"];
|
|
53
|
+
readonly tot: readonly ["How do I pre-register a transformer sample in the mobile app?", "How do I scan a transformer sample label?"];
|
|
54
|
+
};
|
|
55
|
+
readonly webQuestions: readonly ["How do I pre-register a vessel sample in the portal?", "How do I pre-register a transformer sample in the portal?"];
|
|
56
|
+
readonly webServiceQuestions: {
|
|
57
|
+
readonly vessel: readonly ["How do I pre-register a vessel sample in the portal?", "Where can I download my fuel report?"];
|
|
58
|
+
readonly tot: readonly ["How do I pre-register a transformer sample in the portal?", "Where can I download a transformer oil report?"];
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
readonly 10: {
|
|
62
|
+
readonly name: "VPS Admin";
|
|
63
|
+
readonly client: "admin";
|
|
64
|
+
readonly services: readonly ["vessel", "tot"];
|
|
65
|
+
readonly topics: "Vessel and TOT workflows, portal administration, and VPS support";
|
|
66
|
+
readonly questions: readonly ["How do I review a portal registration request?", "Where do I find vessel reports?", "How do I view transformer oil test trends?"];
|
|
67
|
+
};
|
|
68
|
+
readonly 11: {
|
|
69
|
+
readonly name: "Transoil";
|
|
70
|
+
readonly client: "web";
|
|
71
|
+
readonly services: readonly ["tot"];
|
|
72
|
+
readonly topics: "transformer assets, oil reports, and trends";
|
|
73
|
+
readonly questions: readonly ["How do I find my transformer equipment?", "Where can I download a transformer oil report?", "How do I review transformer oil trends?"];
|
|
74
|
+
};
|
|
75
|
+
readonly 12: {
|
|
76
|
+
readonly name: "Bunker Master Only";
|
|
77
|
+
readonly client: "mobile";
|
|
78
|
+
readonly services: readonly ["vessel"];
|
|
79
|
+
readonly topics: "Bunker Master access, calculators, and Fuel Change-Over";
|
|
80
|
+
readonly questions: readonly ["How do I request Bunker Master access?", "Where can I find the Bunker Master calculators?", "How do I download the Fuel Change-Over workbook?"];
|
|
81
|
+
};
|
|
82
|
+
readonly 13: {
|
|
83
|
+
readonly name: "Fleet Manager Transoil";
|
|
84
|
+
readonly client: "web";
|
|
85
|
+
readonly services: readonly ["tot"];
|
|
86
|
+
readonly topics: "transformer equipment, reports, and fleet trends";
|
|
87
|
+
readonly questions: readonly ["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?"];
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export type CustomerPortalRoleId = keyof typeof CUSTOMER_PORTAL_ROLES;
|
|
91
|
+
export declare function findPortalRole(roleId?: number): PortalRole | undefined;
|
|
92
|
+
export {};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type ChatApiClient } from "../api/chatbot-api";
|
|
3
|
-
import type { ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
3
|
+
import type { ChatServiceArea, ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
4
4
|
export interface ChatProviderProps {
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
userContext?: ChatUserContext;
|
|
7
7
|
/** Direct role name prop (e.g. "VPS Admin", "Client User", "Captain") */
|
|
8
8
|
role?: string;
|
|
9
|
-
/**
|
|
9
|
+
/** Customer Portal role ID used to tailor questions and route knowledge */
|
|
10
10
|
roleId?: number;
|
|
11
11
|
/** Direct client experience prop ("web" | "mobile" | "admin") */
|
|
12
12
|
client?: "mobile" | "web" | "admin";
|
|
13
|
+
/** Active VPS service, when the portal already knows it. */
|
|
14
|
+
service?: ChatServiceArea;
|
|
13
15
|
/** Optional custom welcome message to display as initial assistant response */
|
|
14
16
|
welcomeMessage?: string;
|
|
15
17
|
suggestions?: Suggestion[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type EnvStage } from "../../components/EnvBadge";
|
|
3
|
-
import type { ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
3
|
+
import type { ChatServiceArea, ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
4
4
|
export interface EmbeddedChatbotProps {
|
|
5
5
|
defaultOpen?: boolean;
|
|
6
6
|
open?: boolean;
|
|
@@ -11,10 +11,11 @@ export interface EmbeddedChatbotProps {
|
|
|
11
11
|
envPulse?: boolean;
|
|
12
12
|
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
13
13
|
role?: string;
|
|
14
|
-
/**
|
|
14
|
+
/** Customer Portal role ID used to tailor questions and route knowledge */
|
|
15
15
|
roleId?: number;
|
|
16
16
|
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
17
17
|
client?: "mobile" | "web" | "admin";
|
|
18
|
+
service?: ChatServiceArea;
|
|
18
19
|
/** Optional custom initial welcome message */
|
|
19
20
|
welcomeMessage?: string;
|
|
20
21
|
/** Backend or proxy API base URL */
|
|
@@ -6,5 +6,6 @@ export { ChatbotWidget, type ChatbotWidgetProps } from "./widget/ChatbotWidget";
|
|
|
6
6
|
export { EmbeddedChatbot, type EmbeddedChatbotProps } from "./embedded/EmbeddedChatbot";
|
|
7
7
|
export { chatApi, createChatApi, buildApiUrl, resolveApiBaseUrl, type ChatApiClient, } from "./api/chatbot-api";
|
|
8
8
|
export { ColorPalette } from "./config/colors";
|
|
9
|
-
export
|
|
9
|
+
export { CUSTOMER_PORTAL_ROLES, type CustomerPortalRoleId } from "./config/roles";
|
|
10
|
+
export type { ChatUserContext, ChatAccessContext, ChatServiceArea, ChatMessage, Suggestion, Ticket, Source, ToolCall, TokenUsage, ChatRole, MessageStatus, MessageFeedback, ModelOption, ModelCatalog, } from "./api/chatbot-types";
|
|
10
11
|
export type { EnvStage } from "../components/EnvBadge";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type EnvStage } from "../../components/EnvBadge";
|
|
3
|
-
import type { ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
3
|
+
import type { ChatServiceArea, ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
4
4
|
export interface ChatbotWidgetProps {
|
|
5
5
|
defaultOpen?: boolean;
|
|
6
6
|
open?: boolean;
|
|
@@ -10,10 +10,11 @@ export interface ChatbotWidgetProps {
|
|
|
10
10
|
envPulse?: boolean;
|
|
11
11
|
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
12
12
|
role?: string;
|
|
13
|
-
/**
|
|
13
|
+
/** Customer Portal role ID used to tailor questions and route knowledge */
|
|
14
14
|
roleId?: number;
|
|
15
15
|
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
16
16
|
client?: "mobile" | "web" | "admin";
|
|
17
|
+
service?: ChatServiceArea;
|
|
17
18
|
/** Optional custom initial welcome message */
|
|
18
19
|
welcomeMessage?: string;
|
|
19
20
|
/** Backend or proxy API base URL */
|