vdb-ai-chat 1.0.0 → 1.0.2

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 (132) hide show
  1. package/dist/10.chat-widget.js +2 -0
  2. package/dist/10.chat-widget.js.LICENSE.txt +1 -0
  3. package/dist/104.chat-widget.js +1 -0
  4. package/dist/248.chat-widget.js +1 -0
  5. package/dist/50.chat-widget.js +1 -0
  6. package/dist/521.chat-widget.js +1 -0
  7. package/dist/538.chat-widget.js +1 -0
  8. package/dist/572.chat-widget.js +1 -0
  9. package/dist/694.chat-widget.js +1 -0
  10. package/dist/chat-widget.js +1 -1
  11. package/dist/chat-widget.js.LICENSE.txt +2 -0
  12. package/lib/commonjs/api.js +6 -8
  13. package/lib/commonjs/api.js.map +1 -1
  14. package/lib/commonjs/components/BetaNotice.js +38 -0
  15. package/lib/commonjs/components/BetaNotice.js.map +1 -0
  16. package/lib/commonjs/components/ChatHeader.js +41 -21
  17. package/lib/commonjs/components/ChatHeader.js.map +1 -1
  18. package/lib/commonjs/components/ChatInput.js +21 -21
  19. package/lib/commonjs/components/ChatInput.js.map +1 -1
  20. package/lib/commonjs/components/ChatWidget.js +162 -90
  21. package/lib/commonjs/components/ChatWidget.js.map +1 -1
  22. package/lib/commonjs/components/MessageBubble.js +28 -68
  23. package/lib/commonjs/components/MessageBubble.js.map +1 -1
  24. package/lib/commonjs/components/MessageMetaRow.js +135 -0
  25. package/lib/commonjs/components/MessageMetaRow.js.map +1 -0
  26. package/lib/commonjs/components/ProductsGrid.js +139 -0
  27. package/lib/commonjs/components/ProductsGrid.js.map +1 -0
  28. package/lib/commonjs/components/ProductsList.js +22 -126
  29. package/lib/commonjs/components/ProductsList.js.map +1 -1
  30. package/lib/commonjs/components/ProductsListView.js +139 -0
  31. package/lib/commonjs/components/ProductsListView.js.map +1 -0
  32. package/lib/commonjs/components/SuggestionsRow.js +41 -23
  33. package/lib/commonjs/components/SuggestionsRow.js.map +1 -1
  34. package/lib/commonjs/components/utils.js +50 -4
  35. package/lib/commonjs/components/utils.js.map +1 -1
  36. package/lib/commonjs/contexts/AnalyticsClientContext.js +19 -0
  37. package/lib/commonjs/contexts/AnalyticsClientContext.js.map +1 -0
  38. package/lib/commonjs/hooks/useAnalytics.js +158 -0
  39. package/lib/commonjs/hooks/useAnalytics.js.map +1 -0
  40. package/lib/commonjs/index.web.js +91 -8
  41. package/lib/commonjs/index.web.js.map +1 -1
  42. package/lib/commonjs/storage.js +5 -5
  43. package/lib/commonjs/storage.js.map +1 -1
  44. package/lib/commonjs/theme.js +4 -4
  45. package/lib/commonjs/theme.js.map +1 -1
  46. package/lib/module/api.js +6 -8
  47. package/lib/module/api.js.map +1 -1
  48. package/lib/module/components/BetaNotice.js +30 -0
  49. package/lib/module/components/BetaNotice.js.map +1 -0
  50. package/lib/module/components/ChatHeader.js +41 -21
  51. package/lib/module/components/ChatHeader.js.map +1 -1
  52. package/lib/module/components/ChatInput.js +21 -21
  53. package/lib/module/components/ChatInput.js.map +1 -1
  54. package/lib/module/components/ChatWidget.js +164 -92
  55. package/lib/module/components/ChatWidget.js.map +1 -1
  56. package/lib/module/components/MessageBubble.js +28 -70
  57. package/lib/module/components/MessageBubble.js.map +1 -1
  58. package/lib/module/components/MessageMetaRow.js +127 -0
  59. package/lib/module/components/MessageMetaRow.js.map +1 -0
  60. package/lib/module/components/ProductsGrid.js +133 -0
  61. package/lib/module/components/ProductsGrid.js.map +1 -0
  62. package/lib/module/components/ProductsList.js +21 -126
  63. package/lib/module/components/ProductsList.js.map +1 -1
  64. package/lib/module/components/ProductsListView.js +132 -0
  65. package/lib/module/components/ProductsListView.js.map +1 -0
  66. package/lib/module/components/SuggestionsRow.js +41 -23
  67. package/lib/module/components/SuggestionsRow.js.map +1 -1
  68. package/lib/module/components/utils.js +46 -3
  69. package/lib/module/components/utils.js.map +1 -1
  70. package/lib/module/contexts/AnalyticsClientContext.js +10 -0
  71. package/lib/module/contexts/AnalyticsClientContext.js.map +1 -0
  72. package/lib/module/hooks/useAnalytics.js +146 -0
  73. package/lib/module/hooks/useAnalytics.js.map +1 -0
  74. package/lib/module/index.native.js +5 -5
  75. package/lib/module/index.web.js +89 -6
  76. package/lib/module/index.web.js.map +1 -1
  77. package/lib/module/storage.js +6 -6
  78. package/lib/module/storage.js.map +1 -1
  79. package/lib/module/theme.js +4 -4
  80. package/lib/module/theme.js.map +1 -1
  81. package/lib/typescript/api.d.ts +1 -1
  82. package/lib/typescript/api.d.ts.map +1 -1
  83. package/lib/typescript/components/BetaNotice.d.ts +5 -0
  84. package/lib/typescript/components/BetaNotice.d.ts.map +1 -0
  85. package/lib/typescript/components/ChatHeader.d.ts +5 -2
  86. package/lib/typescript/components/ChatHeader.d.ts.map +1 -1
  87. package/lib/typescript/components/ChatInput.d.ts.map +1 -1
  88. package/lib/typescript/components/ChatWidget.d.ts.map +1 -1
  89. package/lib/typescript/components/MessageBubble.d.ts +9 -3
  90. package/lib/typescript/components/MessageBubble.d.ts.map +1 -1
  91. package/lib/typescript/components/MessageMetaRow.d.ts +14 -0
  92. package/lib/typescript/components/MessageMetaRow.d.ts.map +1 -0
  93. package/lib/typescript/components/ProductsGrid.d.ts +10 -0
  94. package/lib/typescript/components/ProductsGrid.d.ts.map +1 -0
  95. package/lib/typescript/components/ProductsList.d.ts +4 -2
  96. package/lib/typescript/components/ProductsList.d.ts.map +1 -1
  97. package/lib/typescript/components/ProductsListView.d.ts +10 -0
  98. package/lib/typescript/components/ProductsListView.d.ts.map +1 -0
  99. package/lib/typescript/components/SuggestionsRow.d.ts +2 -0
  100. package/lib/typescript/components/SuggestionsRow.d.ts.map +1 -1
  101. package/lib/typescript/components/utils.d.ts +24 -0
  102. package/lib/typescript/components/utils.d.ts.map +1 -1
  103. package/lib/typescript/contexts/AnalyticsClientContext.d.ts +9 -0
  104. package/lib/typescript/contexts/AnalyticsClientContext.d.ts.map +1 -0
  105. package/lib/typescript/hooks/useAnalytics.d.ts +36 -0
  106. package/lib/typescript/hooks/useAnalytics.d.ts.map +1 -0
  107. package/lib/typescript/index.native.d.ts +5 -5
  108. package/lib/typescript/index.web.d.ts +1 -1
  109. package/lib/typescript/index.web.d.ts.map +1 -1
  110. package/lib/typescript/storage.d.ts.map +1 -1
  111. package/lib/typescript/types.d.ts +4 -2
  112. package/lib/typescript/types.d.ts.map +1 -1
  113. package/package.json +13 -3
  114. package/src/api.ts +26 -14
  115. package/src/components/BetaNotice.tsx +32 -0
  116. package/src/components/ChatHeader.tsx +43 -18
  117. package/src/components/ChatInput.tsx +20 -21
  118. package/src/components/ChatWidget.tsx +282 -219
  119. package/src/components/MessageBubble.tsx +48 -111
  120. package/src/components/MessageMetaRow.tsx +199 -0
  121. package/src/components/ProductsGrid.tsx +163 -0
  122. package/src/components/ProductsList.tsx +20 -144
  123. package/src/components/ProductsListView.tsx +149 -0
  124. package/src/components/SuggestionsRow.tsx +45 -21
  125. package/src/components/utils.ts +66 -5
  126. package/src/contexts/AnalyticsClientContext.tsx +20 -0
  127. package/src/hooks/useAnalytics.tsx +176 -0
  128. package/src/index.native.tsx +5 -5
  129. package/src/index.web.tsx +92 -4
  130. package/src/storage.ts +16 -13
  131. package/src/theme.ts +4 -4
  132. package/src/types.ts +4 -3
@@ -1,6 +1,6 @@
1
1
  // React Native entry point - re-export everything from main index
2
- export { ChatWidget } from './components/ChatWidget';
3
- export * from './types';
4
- export * from './theme';
5
- export { normaliseMessages } from './api';
6
- export { initStorage, isStorageInitialized, Storage } from './storage';
2
+ export { ChatWidget } from "./components/ChatWidget";
3
+ export * from "./types";
4
+ export * from "./theme";
5
+ export { normaliseMessages } from "./api";
6
+ export { initStorage, isStorageInitialized, Storage } from "./storage";
package/src/index.web.tsx CHANGED
@@ -1,27 +1,115 @@
1
- import * as React from "react";
1
+ import React from "react";
2
+ import { Platform, StyleSheet, View } from "react-native";
2
3
  import { createRoot } from "react-dom/client";
3
- import { View, StyleSheet } from "react-native";
4
+ import { AnalyticsBrowser } from "@segment/analytics-next";
5
+ import { AnalyticsClientProvider } from "./contexts/AnalyticsClientContext";
4
6
  import { ChatWidget } from "./components/ChatWidget";
5
7
  import type { ChatTheme } from "./types";
8
+ import { getUserDetails } from "./components/utils";
6
9
 
7
10
  export function renderChatApp(
8
11
  domElement: HTMLElement,
9
12
  apiUrl: string,
10
13
  theme?: Partial<ChatTheme>,
11
14
  onClose?: () => void,
12
- onClearChat?: () => void
15
+ onClearChat?: () => void,
16
+ segmentWriteKey?: string,
17
+ onViewAllPress?: (url: string, payload: any) => void,
18
+ onItemPress?: (url: string, item: any) => void,
19
+ isBetaMode?: boolean,
13
20
  ) {
14
21
  const root = createRoot(domElement);
15
- root.render(
22
+
23
+ // Bridge to parent RN WebView / browser
24
+ const sendToParent = (type: string, payload: any) => {
25
+ const msg = { source: "vdb-ai-chat", type, payload };
26
+ const json = JSON.stringify(msg);
27
+
28
+ // RN WebView bridge
29
+ const rnwv = (window as any).ReactNativeWebView;
30
+ if (rnwv?.postMessage) {
31
+ rnwv.postMessage(json);
32
+ } else {
33
+ // Browser/iframe
34
+ try {
35
+ window.parent?.postMessage(msg, "*");
36
+ } catch {}
37
+ try {
38
+ window.dispatchEvent(new CustomEvent("vdb-ai-event", { detail: msg }));
39
+ } catch {}
40
+ }
41
+ };
42
+
43
+ const handleViewAll = (url: string, payload: any) => {
44
+ onViewAllPress?.(url, payload);
45
+ sendToParent("ai_view_all", { url, payload });
46
+ onClose?.();
47
+ };
48
+
49
+ const handleItemPress = (url: string, item: any) => {
50
+ onItemPress?.(url, item);
51
+ sendToParent("ai_item_click", { url, item });
52
+ onClose?.();
53
+ };
54
+
55
+ // Build base content and render immediately
56
+ const content = (
16
57
  <View style={styles.root}>
17
58
  <ChatWidget
18
59
  apiUrl={apiUrl}
19
60
  theme={theme}
20
61
  onClose={onClose}
21
62
  onClearChat={onClearChat}
63
+ onViewAllPress={handleViewAll}
64
+ onItemPress={handleItemPress}
65
+ isBetaMode={isBetaMode}
22
66
  />
23
67
  </View>
24
68
  );
69
+ root.render(content);
70
+
71
+ if (Platform.OS === "web" && segmentWriteKey) {
72
+ try {
73
+ const isEdge =
74
+ typeof navigator !== "undefined" &&
75
+ (navigator.userAgent.includes("Edg") || navigator.userAgent.includes("Edge"));
76
+
77
+ const clientPromise = AnalyticsBrowser.load({
78
+ writeKey: segmentWriteKey,
79
+ trackAppLifecycleEvents: false as any,
80
+ flushAt: (isEdge ? 1 : 10) as any,
81
+ flushInterval: (10000 as any),
82
+ maxBatchSize: (isEdge ? 1 : 10) as any,
83
+ } as any);
84
+
85
+ clientPromise
86
+ .then( async ([client]: any) => {
87
+ (client as any)?.debug?.(true);
88
+ (window as any).analytics = client;
89
+
90
+ client.page?.();
91
+ try {
92
+ const user = await getUserDetails();
93
+ const userId = user?.id;
94
+ if (userId) client.identify(userId);
95
+ } catch {}
96
+
97
+ const contentWithAnalytics = (
98
+ <AnalyticsClientProvider client={client}>
99
+ {content}
100
+ </AnalyticsClientProvider>
101
+ );
102
+ root.render(contentWithAnalytics);
103
+ })
104
+ .catch((e: any) => {
105
+ // eslint-disable-next-line no-console
106
+ console.error("[Segment] init failed", e);
107
+ });
108
+ } catch (e) {
109
+ // eslint-disable-next-line no-console
110
+ console.error("[Segment] init failed", e);
111
+ }
112
+ }
25
113
  }
26
114
 
27
115
  const styles = StyleSheet.create({
package/src/storage.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Platform } from 'react-native';
1
+ import { Platform } from "react-native";
2
2
 
3
3
  // Storage interface that works across platforms
4
4
  interface StorageInterface {
@@ -9,7 +9,7 @@ interface StorageInterface {
9
9
 
10
10
  // Helper to safely get localStorage (only available on web)
11
11
  function getLocalStorage(): Storage | null {
12
- if (typeof window !== 'undefined' && window.localStorage) {
12
+ if (typeof window !== "undefined" && window.localStorage) {
13
13
  return window.localStorage;
14
14
  }
15
15
  return null;
@@ -54,7 +54,7 @@ let hasWarnedAboutStorage = false;
54
54
  /**
55
55
  * Initialize storage with AsyncStorage for React Native.
56
56
  * Call this once at app startup before using ChatWidget.
57
- *
57
+ *
58
58
  * @example
59
59
  * import AsyncStorage from '@react-native-async-storage/async-storage';
60
60
  * import { initStorage } from 'vdb-ai-chat';
@@ -69,7 +69,7 @@ export function initStorage(asyncStorage: StorageInterface): void {
69
69
  * Check if storage is properly initialized for the current platform
70
70
  */
71
71
  export function isStorageInitialized(): boolean {
72
- if (Platform.OS === 'web') {
72
+ if (Platform.OS === "web") {
73
73
  return getLocalStorage() !== null;
74
74
  }
75
75
  return nativeStorage !== null;
@@ -84,21 +84,21 @@ const noopStorage: StorageInterface = {
84
84
 
85
85
  // Get the appropriate storage based on platform
86
86
  function getStorage(): StorageInterface {
87
- if (Platform.OS === 'web') {
87
+ if (Platform.OS === "web") {
88
88
  return webStorage;
89
89
  }
90
-
90
+
91
91
  if (!nativeStorage) {
92
92
  // Only warn once to avoid console spam
93
93
  if (!hasWarnedAboutStorage) {
94
94
  console.warn(
95
- '[vdb-ai-chat] AsyncStorage not initialized. Call initStorage(AsyncStorage) at app startup.'
95
+ "[vdb-ai-chat] AsyncStorage not initialized. Call initStorage(AsyncStorage) at app startup."
96
96
  );
97
97
  hasWarnedAboutStorage = true;
98
98
  }
99
99
  return noopStorage;
100
100
  }
101
-
101
+
102
102
  return nativeStorage;
103
103
  }
104
104
 
@@ -107,17 +107,20 @@ export const Storage = {
107
107
  getItem: async (key: string): Promise<string | null> => {
108
108
  return getStorage().getItem(key);
109
109
  },
110
-
110
+
111
111
  setItem: async (key: string, value: string): Promise<void> => {
112
112
  return getStorage().setItem(key, value);
113
113
  },
114
-
114
+
115
115
  removeItem: async (key: string): Promise<void> => {
116
116
  return getStorage().removeItem(key);
117
117
  },
118
-
118
+
119
119
  // Convenience method to get and parse JSON
120
- getJSON: async <T = any>(key: string, defaultValue: T | null = null): Promise<T | null> => {
120
+ getJSON: async <T = any>(
121
+ key: string,
122
+ defaultValue: T | null = null
123
+ ): Promise<T | null> => {
121
124
  try {
122
125
  const value = await getStorage().getItem(key);
123
126
  if (value) {
@@ -128,7 +131,7 @@ export const Storage = {
128
131
  return defaultValue;
129
132
  }
130
133
  },
131
-
134
+
132
135
  // Convenience method to stringify and set JSON
133
136
  setJSON: async (key: string, value: any): Promise<void> => {
134
137
  try {
package/src/theme.ts CHANGED
@@ -4,14 +4,14 @@ export const defaultTheme: ChatTheme = {
4
4
  primaryColor: "#0b93f6",
5
5
  backgroundColor: "#ffffff",
6
6
  inputColor: "#FFF",
7
- inputBackgroundColor: "#f5f5f5",
7
+ inputBackgroundColor: "#FFFFFF",
8
8
  inputBorderRadius: 8,
9
9
  inputTextColor: "#000000",
10
- userBubbleColor: "#804195",
10
+ userBubbleColor: "#4F4E57",
11
11
  userTextColor: "#ffffff",
12
- botBubbleColor: "#e5e5ea",
12
+ botBubbleColor: "#EDEDF2",
13
13
  botTextColor: "#000000",
14
- borderRadius: 18,
14
+ borderRadius: 8,
15
15
  fontFamily: undefined,
16
16
  fontSize: 16,
17
17
  };
package/src/types.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  export type Role = "user" | "assistant";
2
2
 
3
3
  export interface ChatMessage {
4
- agent_response?: any;
5
4
  id: string;
6
5
  role: Role;
7
6
  text: string;
8
7
  createdAt: number;
9
8
  isLoading?: boolean;
10
9
  suggestions?: string[];
11
- // "0" unset, "1" like, "2" dislike
12
- reaction?: "0" | "1" | "2";
10
+ reaction?: string;
11
+ search_payload?: Record<string, any>;
13
12
  }
14
13
 
15
14
  export interface ChatTheme {
@@ -44,6 +43,8 @@ export interface ChatWidgetProps {
44
43
  onViewAllPress?: (deepLinkUrl: string, payload: any) => void;
45
44
  /** Called when a product item is pressed. Receives the deep link URL and item data. */
46
45
  onItemPress?: (deepLinkUrl: string, item: any) => void;
46
+ /** When true, shows beta labels and disclaimer. */
47
+ isBetaMode?: boolean;
47
48
  }
48
49
 
49
50
  export interface ChatWidgetRef {