vpschatbotwidget 1.0.0 → 1.0.1

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.
Files changed (75) hide show
  1. package/README.md +385 -47
  2. package/dist-lib/types/App.d.ts +2 -0
  3. package/dist-lib/types/chatbot/api/chatbot-api.d.ts +25 -0
  4. package/dist-lib/types/chatbot/api/chatbot-types.d.ts +125 -0
  5. package/dist-lib/types/chatbot/chatbot.test.d.ts +1 -0
  6. package/dist-lib/types/chatbot/config/colors.d.ts +165 -0
  7. package/dist-lib/types/chatbot/config/suggestions.d.ts +3 -0
  8. package/dist-lib/types/chatbot/core/ChatContext.d.ts +28 -0
  9. package/dist-lib/types/chatbot/core/ChatEmptyState.d.ts +2 -0
  10. package/dist-lib/types/chatbot/core/ChatError.d.ts +7 -0
  11. package/dist-lib/types/chatbot/core/ChatHeader.d.ts +22 -0
  12. package/dist-lib/types/chatbot/core/ChatInput.d.ts +8 -0
  13. package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +4 -0
  14. package/dist-lib/types/chatbot/core/ChatMessage.d.ts +7 -0
  15. package/dist-lib/types/chatbot/core/ChatMessageList.d.ts +2 -0
  16. package/dist-lib/types/chatbot/core/ChatPanel.d.ts +14 -0
  17. package/dist-lib/types/chatbot/core/ChatProvider.d.ts +19 -0
  18. package/dist-lib/types/chatbot/core/ChatSuggestions.d.ts +11 -0
  19. package/dist-lib/types/chatbot/core/ChatTicketConfirmation.d.ts +2 -0
  20. package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +4 -0
  21. package/dist-lib/types/chatbot/core/ticket-intent.d.ts +2 -0
  22. package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +27 -0
  23. package/dist-lib/types/chatbot/embedded/EmbeddedChatbotPanel.d.ts +12 -0
  24. package/dist-lib/types/chatbot/embedded/EmbeddedChatbotTrigger.d.ts +6 -0
  25. package/dist-lib/types/chatbot/hooks/useChatbot.d.ts +1 -0
  26. package/dist-lib/types/chatbot/index.d.ts +10 -0
  27. package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +26 -0
  28. package/dist-lib/types/chatbot/widget/ChatbotWidgetPanel.d.ts +10 -0
  29. package/dist-lib/types/chatbot/widget/ChatbotWidgetTrigger.d.ts +7 -0
  30. package/dist-lib/types/components/AgentSummaryCard.d.ts +8 -0
  31. package/dist-lib/types/components/ChatHeader.d.ts +20 -0
  32. package/dist-lib/types/components/ChatInput.d.ts +9 -0
  33. package/dist-lib/types/components/ChatWidget.d.ts +14 -0
  34. package/dist-lib/types/components/ConnectingStatus.d.ts +6 -0
  35. package/dist-lib/types/components/EnvBadge.d.ts +31 -0
  36. package/dist-lib/types/components/FeedbackRatingCard.d.ts +7 -0
  37. package/dist-lib/types/components/MessageItem.d.ts +12 -0
  38. package/dist-lib/types/components/MessageList.d.ts +21 -0
  39. package/dist-lib/types/components/OrderTrackingCard.d.ts +13 -0
  40. package/dist-lib/types/components/QuickPrompts.d.ts +11 -0
  41. package/dist-lib/types/components/ResponseIconMapper.d.ts +26 -0
  42. package/dist-lib/types/components/SourceCitations.d.ts +7 -0
  43. package/dist-lib/types/components/ToolCallBadge.d.ts +7 -0
  44. package/dist-lib/types/components/TypingProgressBar.d.ts +21 -0
  45. package/dist-lib/types/components/ui/message-scroller.d.ts +9 -0
  46. package/dist-lib/types/lib/cn.d.ts +1 -0
  47. package/dist-lib/types/lib/gibberishDetector.d.ts +26 -0
  48. package/dist-lib/types/lib/textHighlighter.d.ts +15 -0
  49. package/dist-lib/types/main.d.ts +1 -0
  50. package/dist-lib/types/services/api.d.ts +12 -0
  51. package/dist-lib/types/test/message-scroller-stub.d.ts +36 -0
  52. package/dist-lib/types/test/setup.d.ts +1 -0
  53. package/dist-lib/types/types/chat.d.ts +59 -0
  54. package/dist-lib/vps-chatbot.cjs +101 -0
  55. package/dist-lib/vps-chatbot.js +2179 -0
  56. package/package.json +30 -3
  57. package/src/chatbot/chatbot.test.tsx +87 -0
  58. package/src/chatbot/core/ChatContext.tsx +6 -0
  59. package/src/chatbot/core/ChatProvider.tsx +29 -7
  60. package/src/chatbot/embedded/EmbeddedChatbot.tsx +63 -2
  61. package/src/chatbot/index.ts +25 -5
  62. package/src/chatbot/widget/ChatbotWidget.tsx +64 -2
  63. package/Chatbot.svg +0 -1
  64. package/dist/assets/index-C0fUDi2s.css +0 -1
  65. package/dist/assets/index-foGq5_Av.js +0 -159
  66. package/dist/index.html +0 -17
  67. package/index.html +0 -16
  68. package/src/App.tsx +0 -85
  69. package/src/main.tsx +0 -10
  70. package/src/services/api.ts +0 -74
  71. package/src/test/message-scroller-stub.tsx +0 -60
  72. package/src/test/setup.ts +0 -8
  73. package/src/vite-env.d.ts +0 -14
  74. package/tsconfig.json +0 -21
  75. package/vite.config.ts +0 -28
package/dist/index.html DELETED
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300B4D8'><path d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm1 14.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-4.5a1 1 0 0 1-2 0V7a1 1 0 0 1 2 0z'/></svg>" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>VPS Veritas AI Customer Assistant</title>
8
- <link rel="preconnect" href="https://fonts.googleapis.com">
9
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
- <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
11
- <script type="module" crossorigin src="/assets/index-foGq5_Av.js"></script>
12
- <link rel="stylesheet" crossorigin href="/assets/index-C0fUDi2s.css">
13
- </head>
14
- <body>
15
- <div id="root"></div>
16
- </body>
17
- </html>
package/index.html DELETED
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300B4D8'><path d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm1 14.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0zm0-4.5a1 1 0 0 1-2 0V7a1 1 0 0 1 2 0z'/></svg>" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>VPS Veritas AI Customer Assistant</title>
8
- <link rel="preconnect" href="https://fonts.googleapis.com">
9
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
- <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
11
- </head>
12
- <body>
13
- <div id="root"></div>
14
- <script type="module" src="/src/main.tsx"></script>
15
- </body>
16
- </html>
package/src/App.tsx DELETED
@@ -1,85 +0,0 @@
1
- import React, { useState } from "react";
2
- import { LayoutGrid, Layers, MessageSquare } from "lucide-react";
3
- import {
4
- ChatProvider,
5
- ChatbotWidget,
6
- EmbeddedChatbot,
7
- type ChatUserContext,
8
- } from "./chatbot";
9
-
10
- type DemoMode = "widget" | "embedded";
11
-
12
- export const App: React.FC = () => {
13
- const [mode, setMode] = useState<DemoMode>("widget");
14
- const [customerId, setCustomerId] = useState("");
15
- const [email, setEmail] = useState("");
16
- const [widgetOpen, setWidgetOpen] = useState(false);
17
- const [embeddedOpen, setEmbeddedOpen] = useState(false);
18
-
19
- const userContext: ChatUserContext = {
20
- customerId: customerId.trim() || undefined,
21
- email: email.trim() || undefined,
22
- page: "portal-demo",
23
- };
24
-
25
- return (
26
- <ChatProvider userContext={userContext}>
27
- <div className="flex min-h-screen flex-col bg-background">
28
- <header className="sticky top-0 z-50 flex flex-wrap items-center justify-between gap-3 border-b border-border bg-card px-7 py-3.5 shadow-sm">
29
- <div className="flex items-center gap-3">
30
-
31
- <div>
32
- <h1 className="text-base font-bold text-foreground">
33
- Veritas AI Assistant
34
- </h1>
35
- <p className="text-xs text-muted-foreground">
36
- Your AI-powered assistant for Veritas
37
- </p>
38
- </div>
39
- </div>
40
- <div className="flex flex-wrap items-center gap-1.5">
41
- <button
42
- type="button"
43
- className={`inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-[12.5px] font-semibold ${
44
- mode === "widget"
45
- ? "border-action bg-action text-action-foreground"
46
- : "border-border bg-muted text-muted-foreground"
47
- }`}
48
- onClick={() => {
49
- setMode("widget");
50
- setEmbeddedOpen(false);
51
- }}
52
- >
53
- <Layers size={14} />
54
- Widget
55
- </button>
56
- <button
57
- type="button"
58
- className={`inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-[12.5px] font-semibold ${
59
- mode === "embedded"
60
- ? "border-action bg-action text-action-foreground"
61
- : "border-border bg-muted text-muted-foreground"
62
- }`}
63
- onClick={() => {
64
- setMode("embedded");
65
- setWidgetOpen(false);
66
- setEmbeddedOpen(true);
67
- }}
68
- >
69
- <LayoutGrid size={14} />
70
- Slide-out
71
- </button>
72
- </div>
73
- </header>
74
-
75
-
76
- {mode === "widget" && (
77
- <ChatbotWidget open={widgetOpen} onOpenChange={setWidgetOpen} envStage="alpha" envPulse/>
78
- )}
79
- {mode === "embedded" && (
80
- <EmbeddedChatbot open={embeddedOpen} onOpenChange={setEmbeddedOpen} envStage="alpha" />
81
- )}
82
- </div>
83
- </ChatProvider>
84
- );
85
- };
package/src/main.tsx DELETED
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- import ReactDOM from "react-dom/client";
3
- import { App } from "./App";
4
- import "./index.css";
5
-
6
- ReactDOM.createRoot(document.getElementById("root")!).render(
7
- <React.StrictMode>
8
- <App />
9
- </React.StrictMode>
10
- );
@@ -1,74 +0,0 @@
1
- import { ChatApiResponse, Message, SessionResponse } from "../types/chat";
2
-
3
- const API_BASE = "";
4
-
5
- export class ChatService {
6
- static async createSession(): Promise<string> {
7
- const response = await fetch(`${API_BASE}/api/v1/sessions`, {
8
- method: "POST",
9
- headers: { "Content-Type": "application/json" },
10
- });
11
- if (!response.ok) {
12
- throw new Error(`Failed to create session: ${response.statusText}`);
13
- }
14
- const data: SessionResponse = await response.json();
15
- return data.session_id;
16
- }
17
-
18
- static async sendMessage(sessionId: string, message: string): Promise<ChatApiResponse> {
19
- const response = await fetch(`${API_BASE}/api/v1/sessions/${sessionId}/messages`, {
20
- method: "POST",
21
- headers: { "Content-Type": "application/json" },
22
- body: JSON.stringify({ message }),
23
- });
24
- if (!response.ok) {
25
- const err = await response.json().catch(() => ({}));
26
- const message = err?.error?.message || `Server error (${response.status})`;
27
- throw new Error(message);
28
- }
29
- return response.json();
30
- }
31
-
32
- static async getHistory(sessionId: string): Promise<Message[]> {
33
- const response = await fetch(`${API_BASE}/api/v1/sessions/${sessionId}/messages`);
34
- if (!response.ok) {
35
- return [];
36
- }
37
- const data = await response.json();
38
- return (data.messages || []).map((m: any) => ({
39
- id: m.id,
40
- role: m.role,
41
- content: m.content,
42
- timestamp: m.created_at || new Date().toISOString(),
43
- usage: m.model ? {
44
- model: m.model,
45
- prompt_tokens: m.prompt_tokens || 0,
46
- completion_tokens: m.completion_tokens || 0,
47
- total_tokens: (m.prompt_tokens || 0) + (m.completion_tokens || 0),
48
- } : undefined,
49
- }));
50
- }
51
-
52
- static async closeSession(sessionId: string): Promise<void> {
53
- await fetch(`${API_BASE}/api/v1/sessions/${sessionId}`, {
54
- method: "DELETE",
55
- }).catch(() => {});
56
- }
57
-
58
- static async checkHealth(): Promise<boolean> {
59
- try {
60
- const res = await fetch(`${API_BASE}/health`);
61
- return res.ok;
62
- } catch {
63
- return false;
64
- }
65
- }
66
-
67
- static async getCustomers(): Promise<any[]> {
68
- return [];
69
- }
70
-
71
- static async getTickets(): Promise<any[]> {
72
- return [];
73
- }
74
- }
@@ -1,60 +0,0 @@
1
- import React, { type ReactNode } from "react";
2
-
3
- type Props = {
4
- children?: ReactNode;
5
- className?: string;
6
- "aria-label"?: string;
7
- "aria-busy"?: boolean;
8
- messageId?: string;
9
- scrollAnchor?: boolean;
10
- autoScroll?: boolean;
11
- defaultScrollPosition?: string;
12
- scrollPreviousItemPeek?: number;
13
- direction?: string;
14
- };
15
-
16
- function PassThrough({ children, className, ...props }: Props) {
17
- const {
18
- messageId: _messageId,
19
- scrollAnchor: _scrollAnchor,
20
- autoScroll: _autoScroll,
21
- defaultScrollPosition: _defaultScrollPosition,
22
- scrollPreviousItemPeek: _scrollPreviousItemPeek,
23
- direction: _direction,
24
- ...dom
25
- } = props;
26
- return (
27
- <div className={className} {...dom}>
28
- {children}
29
- </div>
30
- );
31
- }
32
-
33
- export const MessageScroller = {
34
- Provider: PassThrough,
35
- Root: PassThrough,
36
- Viewport: PassThrough,
37
- Content: PassThrough,
38
- Item: PassThrough,
39
- Button: ({ children, className, ...props }: Props) => (
40
- <button type="button" className={className} {...props}>
41
- {children}
42
- </button>
43
- ),
44
- };
45
-
46
- export function useMessageScroller() {
47
- return {
48
- scrollToEnd: () => true,
49
- scrollToMessage: () => true,
50
- scrollToStart: () => true,
51
- };
52
- }
53
-
54
- export function useMessageScrollerScrollable() {
55
- return { start: false, end: false };
56
- }
57
-
58
- export function useMessageScrollerVisibility() {
59
- return { currentAnchorId: null, visibleMessageIds: [] as string[] };
60
- }
package/src/test/setup.ts DELETED
@@ -1,8 +0,0 @@
1
- import "@testing-library/jest-dom/vitest";
2
- import { afterEach, vi } from "vitest";
3
- import { cleanup } from "@testing-library/react";
4
-
5
- afterEach(() => {
6
- cleanup();
7
- vi.restoreAllMocks();
8
- });
package/src/vite-env.d.ts DELETED
@@ -1,14 +0,0 @@
1
- /// <reference types="vite/client" />
2
-
3
- interface ImportMetaEnv {
4
- /**
5
- * Base URL for the backend API.
6
- * - In local dev: leave empty — Vite proxies /api and /health to localhost:8000.
7
- * - In production builds: set to the deployed backend URL, e.g. https://vpsai.onrender.com
8
- */
9
- readonly VITE_API_BASE?: string;
10
- }
11
-
12
- interface ImportMeta {
13
- readonly env: ImportMetaEnv;
14
- }
package/tsconfig.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
- "module": "ESNext",
7
- "skipLibCheck": true,
8
- "moduleResolution": "bundler",
9
- "allowImportingTsExtensions": false,
10
- "resolveJsonModule": true,
11
- "isolatedModules": true,
12
- "noEmit": true,
13
- "jsx": "react-jsx",
14
- "strict": true,
15
- "noUnusedLocals": false,
16
- "noUnusedParameters": false,
17
- "noFallthroughCasesInSwitch": true,
18
- "types": ["vite/client", "vitest/globals"]
19
- },
20
- "include": ["src"]
21
- }
package/vite.config.ts DELETED
@@ -1,28 +0,0 @@
1
- import tailwindcss from "@tailwindcss/vite";
2
- import react from "@vitejs/plugin-react";
3
- import { defineConfig } from "vitest/config";
4
-
5
- export default defineConfig({
6
- plugins: [react(), tailwindcss()],
7
- server: {
8
- port: 5173,
9
- proxy: {
10
- "/api": {
11
- target: "https://vpsai.onrender.com",
12
- changeOrigin: true,
13
- },
14
- "/health": {
15
- target: "https://vpsai.onrender.com",
16
- changeOrigin: true,
17
- },
18
- },
19
- },
20
- build: {
21
- outDir: "dist",
22
- emptyOutDir: true,
23
- },
24
- test: {
25
- environment: "jsdom",
26
- setupFiles: "./src/test/setup.ts",
27
- },
28
- });