vpschatbotwidget 1.0.3 → 1.2.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/dist-lib/types/App.d.ts +1 -0
- package/dist-lib/types/chatbot/api/chatbot-api.d.ts +14 -3
- package/dist-lib/types/chatbot/api/chatbot-api.test.d.ts +1 -0
- package/dist-lib/types/chatbot/api/chatbot-types.d.ts +35 -0
- package/dist-lib/types/chatbot/core/AgentReasoning.d.ts +8 -0
- package/dist-lib/types/chatbot/core/ChatContext.d.ts +6 -1
- package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +3 -2
- package/dist-lib/types/chatbot/core/ChatProvider.d.ts +15 -1
- package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +1 -0
- package/dist-lib/types/chatbot/core/GroundedSources.d.ts +14 -0
- package/dist-lib/types/chatbot/core/grounding.test.d.ts +1 -0
- package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +14 -1
- package/dist-lib/types/chatbot/index.d.ts +1 -1
- package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +14 -1
- package/dist-lib/vps-chatbot.cjs +53 -20
- package/dist-lib/vps-chatbot.js +1552 -980
- package/package.json +1 -1
- package/src/chatbot/api/chatbot-api.test.ts +48 -0
- package/src/chatbot/api/chatbot-api.ts +199 -5
- package/src/chatbot/api/chatbot-types.ts +39 -0
- package/src/chatbot/chatbot.test.tsx +24 -1
- package/src/chatbot/core/AgentReasoning.tsx +65 -0
- package/src/chatbot/core/ChatContext.tsx +6 -0
- package/src/chatbot/core/ChatInput.tsx +14 -1
- package/src/chatbot/core/ChatMarkdown.tsx +288 -54
- package/src/chatbot/core/ChatMessage.tsx +53 -45
- package/src/chatbot/core/ChatMessageList.tsx +1 -1
- package/src/chatbot/core/ChatProvider.tsx +184 -28
- package/src/chatbot/core/ChatTypingIndicator.tsx +11 -5
- package/src/chatbot/core/GroundedSources.tsx +179 -0
- package/src/chatbot/core/grounding.test.tsx +21 -0
- package/src/chatbot/embedded/EmbeddedChatbot.tsx +36 -4
- package/src/chatbot/index.ts +3 -0
- package/src/chatbot/widget/ChatbotWidget.tsx +36 -4
- package/src/index.css +927 -68
package/dist-lib/types/App.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatMessage, ChatMessageDto, SessionCreated, Source, SourceDto, Ticket, ToolCall, ToolCallDto, TokenUsage, TokenUsageDto } from "./chatbot-types";
|
|
1
|
+
import type { ChatAccessContext, ChatMessage, ChatMessageDto, SessionCreated, Source, SourceDto, Ticket, ToolCall, ToolCallDto, TokenUsage, TokenUsageDto, ModelCatalog } from "./chatbot-types";
|
|
2
2
|
export declare function resolveApiBaseUrl(customUrl?: string): string;
|
|
3
3
|
export declare function buildApiUrl(baseUrl: string | undefined, path: string): string;
|
|
4
4
|
export declare function normalizeSource(dto: SourceDto): Source;
|
|
@@ -7,14 +7,25 @@ export declare function normalizeUsage(dto: TokenUsageDto): TokenUsage;
|
|
|
7
7
|
export declare function normalizeChatMessage(dto: ChatMessageDto): ChatMessage;
|
|
8
8
|
export interface ChatApiClient {
|
|
9
9
|
apiBaseUrl: string;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
listModels?(): Promise<ModelCatalog | null>;
|
|
11
|
+
createSession(signal?: AbortSignal): Promise<SessionCreated>;
|
|
12
|
+
sendMessage(sessionId: string, message: string, access?: ChatAccessContext, signal?: AbortSignal): Promise<{
|
|
12
13
|
requestId: string;
|
|
13
14
|
sessionId: string;
|
|
14
15
|
answer: string;
|
|
15
16
|
sources: Source[];
|
|
16
17
|
toolCalls: ToolCall[];
|
|
17
18
|
usage: TokenUsage;
|
|
19
|
+
durationMs?: number;
|
|
20
|
+
}>;
|
|
21
|
+
sendMessageStream?(sessionId: string, message: string, access?: ChatAccessContext, onProgress?: (stage: string) => void, onToken?: (token: string) => void, signal?: AbortSignal): Promise<{
|
|
22
|
+
requestId: string;
|
|
23
|
+
sessionId: string;
|
|
24
|
+
answer: string;
|
|
25
|
+
sources: Source[];
|
|
26
|
+
toolCalls: ToolCall[];
|
|
27
|
+
usage: TokenUsage;
|
|
28
|
+
durationMs?: number;
|
|
18
29
|
}>;
|
|
19
30
|
getHistory(sessionId: string): Promise<ChatMessage[]>;
|
|
20
31
|
closeSession(sessionId: string): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,6 +4,8 @@ export interface Source {
|
|
|
4
4
|
chunkId: string;
|
|
5
5
|
source: string;
|
|
6
6
|
score: number;
|
|
7
|
+
title?: string;
|
|
8
|
+
snippet?: string;
|
|
7
9
|
}
|
|
8
10
|
export interface ToolCall {
|
|
9
11
|
toolName: string;
|
|
@@ -22,6 +24,8 @@ export interface ChatMessage {
|
|
|
22
24
|
content: string;
|
|
23
25
|
createdAt: string;
|
|
24
26
|
status?: MessageStatus;
|
|
27
|
+
progressText?: string;
|
|
28
|
+
durationMs?: number;
|
|
25
29
|
sources?: Source[];
|
|
26
30
|
toolCalls?: ToolCall[];
|
|
27
31
|
usage?: TokenUsage;
|
|
@@ -30,9 +34,30 @@ export interface ChatUserContext {
|
|
|
30
34
|
customerId?: string;
|
|
31
35
|
email?: string;
|
|
32
36
|
name?: string;
|
|
37
|
+
/** Display name of the role, if the host application has one. */
|
|
33
38
|
role?: string;
|
|
39
|
+
/** Authenticated Customer Portal role ID used for server-side RAG routing. */
|
|
40
|
+
roleId?: number;
|
|
41
|
+
/** Client experience that owns this authenticated session. */
|
|
42
|
+
client?: "mobile" | "web" | "admin";
|
|
34
43
|
page?: string;
|
|
35
44
|
}
|
|
45
|
+
export interface ChatAccessContext {
|
|
46
|
+
roleId?: number;
|
|
47
|
+
client?: "mobile" | "web" | "admin";
|
|
48
|
+
modelId?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ModelOption {
|
|
51
|
+
id: string;
|
|
52
|
+
label: string;
|
|
53
|
+
model: string;
|
|
54
|
+
configured: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface ModelCatalog {
|
|
57
|
+
defaultModelId: string;
|
|
58
|
+
complexModelId?: string | null;
|
|
59
|
+
models: ModelOption[];
|
|
60
|
+
}
|
|
36
61
|
export interface Ticket {
|
|
37
62
|
ticketId: string;
|
|
38
63
|
customerId: string;
|
|
@@ -67,6 +92,8 @@ export interface SourceDto {
|
|
|
67
92
|
chunk_id: string;
|
|
68
93
|
source: string;
|
|
69
94
|
score: number;
|
|
95
|
+
title?: string;
|
|
96
|
+
snippet?: string;
|
|
70
97
|
}
|
|
71
98
|
export interface ToolCallDto {
|
|
72
99
|
tool_name: string;
|
|
@@ -103,6 +130,14 @@ export interface ChatResponseDto {
|
|
|
103
130
|
sources: SourceDto[];
|
|
104
131
|
tool_calls?: ToolCallDto[];
|
|
105
132
|
usage: TokenUsageDto;
|
|
133
|
+
duration_ms?: number;
|
|
134
|
+
role?: RoleDto | null;
|
|
135
|
+
}
|
|
136
|
+
export interface RoleDto {
|
|
137
|
+
id: number;
|
|
138
|
+
usertype: string;
|
|
139
|
+
channel: "mobile" | "web" | "admin";
|
|
140
|
+
knowledge_scopes: string[];
|
|
106
141
|
}
|
|
107
142
|
export interface TicketDto {
|
|
108
143
|
ticket_id: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChatMessage, ChatUserContext, Suggestion, Ticket } from "../api/chatbot-types";
|
|
1
|
+
import type { ChatMessage, ChatUserContext, Suggestion, Ticket, ModelOption } from "../api/chatbot-types";
|
|
2
2
|
export type ChatUiStatus = "idle" | "connecting" | "awaiting" | "error";
|
|
3
3
|
export interface PendingTicket {
|
|
4
4
|
subject: string;
|
|
@@ -17,11 +17,16 @@ export interface ChatContextValue {
|
|
|
17
17
|
suggestionBadgesEnabled: boolean;
|
|
18
18
|
userContext: ChatUserContext;
|
|
19
19
|
apiBaseUrl?: string;
|
|
20
|
+
hideInspectSources?: boolean;
|
|
21
|
+
showGroundedSources?: boolean;
|
|
20
22
|
sendMessage: (text: string) => Promise<void>;
|
|
21
23
|
retryLast: () => Promise<void>;
|
|
22
24
|
confirmTicket: (customerIdOrEmail?: string) => Promise<void>;
|
|
23
25
|
cancelTicket: () => void;
|
|
24
26
|
resetConversation: () => Promise<void>;
|
|
27
|
+
models: ModelOption[];
|
|
28
|
+
selectedModelId: string;
|
|
29
|
+
selectModel: (modelId: string) => void;
|
|
25
30
|
}
|
|
26
31
|
export declare const ChatContext: import("react").Context<ChatContextValue | null>;
|
|
27
32
|
export declare function useChatContext(): ChatContextValue;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function safeHref(value: string): string | undefined;
|
|
3
|
+
export declare const ChatMarkdown: React.NamedExoticComponent<{
|
|
3
4
|
text: string;
|
|
4
|
-
}
|
|
5
|
+
}>;
|
|
@@ -4,10 +4,18 @@ import type { ChatUserContext, Suggestion } from "../api/chatbot-types";
|
|
|
4
4
|
export interface ChatProviderProps {
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
userContext?: ChatUserContext;
|
|
7
|
+
/** Direct role name prop (e.g. "VPS Admin", "Client User", "Captain") */
|
|
8
|
+
role?: string;
|
|
9
|
+
/** Direct role ID prop for server-side RAG access control */
|
|
10
|
+
roleId?: number;
|
|
11
|
+
/** Direct client experience prop ("web" | "mobile" | "admin") */
|
|
12
|
+
client?: "mobile" | "web" | "admin";
|
|
13
|
+
/** Optional custom welcome message to display as initial assistant response */
|
|
14
|
+
welcomeMessage?: string;
|
|
7
15
|
suggestions?: Suggestion[];
|
|
8
16
|
disableSuggestions?: boolean;
|
|
9
17
|
initialMessage?: string;
|
|
10
|
-
/** Backend or proxy API base URL
|
|
18
|
+
/** Backend or proxy API base URL. Defaults to VITE_API_BASE or origin */
|
|
11
19
|
apiBaseUrl?: string;
|
|
12
20
|
/** Alias for apiBaseUrl */
|
|
13
21
|
apiUrl?: string;
|
|
@@ -15,5 +23,11 @@ export interface ChatProviderProps {
|
|
|
15
23
|
proxyUrl?: string;
|
|
16
24
|
/** Optional custom chat API client */
|
|
17
25
|
api?: ChatApiClient;
|
|
26
|
+
/** If true, hides the "Inspect Sources" toggle and details drawer */
|
|
27
|
+
hideInspectSources?: boolean;
|
|
28
|
+
/** Whether to render grounded sources (default: true) */
|
|
29
|
+
showGroundedSources?: boolean;
|
|
30
|
+
/** Configured model alias, or auto for server-side routing. */
|
|
31
|
+
modelId?: string;
|
|
18
32
|
}
|
|
19
33
|
export declare const ChatProvider: React.FC<ChatProviderProps>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Source } from "../api/chatbot-types";
|
|
3
|
+
export interface GroundedSourcesProps {
|
|
4
|
+
sources: Source[];
|
|
5
|
+
/** If true, hides the "Inspect Sources" toggle button and details list */
|
|
6
|
+
hideInspectSources?: boolean;
|
|
7
|
+
/** Direct alias or inverted flag (default: true) */
|
|
8
|
+
showInspectSources?: boolean;
|
|
9
|
+
/** Whether the details view is open by default (default: false) */
|
|
10
|
+
defaultExpanded?: boolean;
|
|
11
|
+
/** Maximum number of grounded sources to display (default: 5) */
|
|
12
|
+
maxSources?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const GroundedSources: React.FC<GroundedSourcesProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,7 +9,15 @@ export interface EmbeddedChatbotProps {
|
|
|
9
9
|
/** Environment badge stage. Omit for production. */
|
|
10
10
|
envStage?: EnvStage;
|
|
11
11
|
envPulse?: boolean;
|
|
12
|
-
/**
|
|
12
|
+
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
13
|
+
role?: string;
|
|
14
|
+
/** Direct role ID for server-side RAG access control */
|
|
15
|
+
roleId?: number;
|
|
16
|
+
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
17
|
+
client?: "mobile" | "web" | "admin";
|
|
18
|
+
/** Optional custom initial welcome message */
|
|
19
|
+
welcomeMessage?: string;
|
|
20
|
+
/** Backend or proxy API base URL */
|
|
13
21
|
apiBaseUrl?: string;
|
|
14
22
|
/** Alias for apiBaseUrl */
|
|
15
23
|
apiUrl?: string;
|
|
@@ -23,5 +31,10 @@ export interface EmbeddedChatbotProps {
|
|
|
23
31
|
disableSuggestions?: boolean;
|
|
24
32
|
/** Initial welcome message to trigger on mount */
|
|
25
33
|
initialMessage?: string;
|
|
34
|
+
/** If true, hides the "Inspect Sources" toggle button and drawer in grounded sources */
|
|
35
|
+
hideInspectSources?: boolean;
|
|
36
|
+
/** Whether to show grounded sources (default: true) */
|
|
37
|
+
showGroundedSources?: boolean;
|
|
38
|
+
modelId?: string;
|
|
26
39
|
}
|
|
27
40
|
export declare const EmbeddedChatbot: React.FC<EmbeddedChatbotProps>;
|
|
@@ -6,5 +6,5 @@ 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 type { ChatUserContext, ChatMessage, Suggestion, Ticket, Source, ToolCall, TokenUsage, ChatRole, MessageStatus, } from "./api/chatbot-types";
|
|
9
|
+
export type { ChatUserContext, ChatAccessContext, ChatMessage, Suggestion, Ticket, Source, ToolCall, TokenUsage, ChatRole, MessageStatus, ModelOption, ModelCatalog, } from "./api/chatbot-types";
|
|
10
10
|
export type { EnvStage } from "../components/EnvBadge";
|
|
@@ -8,7 +8,15 @@ export interface ChatbotWidgetProps {
|
|
|
8
8
|
/** Environment badge stage. Omit for production. */
|
|
9
9
|
envStage?: EnvStage;
|
|
10
10
|
envPulse?: boolean;
|
|
11
|
-
/**
|
|
11
|
+
/** Direct role name (e.g. "VPS Admin", "Client User", "Captain") */
|
|
12
|
+
role?: string;
|
|
13
|
+
/** Direct role ID for server-side RAG access control */
|
|
14
|
+
roleId?: number;
|
|
15
|
+
/** Direct client experience ("web" | "mobile" | "admin") */
|
|
16
|
+
client?: "mobile" | "web" | "admin";
|
|
17
|
+
/** Optional custom initial welcome message */
|
|
18
|
+
welcomeMessage?: string;
|
|
19
|
+
/** Backend or proxy API base URL */
|
|
12
20
|
apiBaseUrl?: string;
|
|
13
21
|
/** Alias for apiBaseUrl */
|
|
14
22
|
apiUrl?: string;
|
|
@@ -22,5 +30,10 @@ export interface ChatbotWidgetProps {
|
|
|
22
30
|
disableSuggestions?: boolean;
|
|
23
31
|
/** Initial welcome message to trigger on mount */
|
|
24
32
|
initialMessage?: string;
|
|
33
|
+
/** If true, hides the "Inspect Sources" toggle button and drawer in grounded sources */
|
|
34
|
+
hideInspectSources?: boolean;
|
|
35
|
+
/** Whether to show grounded sources (default: true) */
|
|
36
|
+
showGroundedSources?: boolean;
|
|
37
|
+
modelId?: string;
|
|
25
38
|
}
|
|
26
39
|
export declare const ChatbotWidget: React.FC<ChatbotWidgetProps>;
|