@v-tilt/browser 1.2.0 → 1.4.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.
Files changed (61) hide show
  1. package/dist/all-external-dependencies.js +2 -0
  2. package/dist/all-external-dependencies.js.map +1 -0
  3. package/dist/array.full.js +2 -0
  4. package/dist/array.full.js.map +1 -0
  5. package/dist/array.js +1 -1
  6. package/dist/array.js.map +1 -1
  7. package/dist/array.no-external.js +1 -1
  8. package/dist/array.no-external.js.map +1 -1
  9. package/dist/chat.js +2 -0
  10. package/dist/chat.js.map +1 -0
  11. package/dist/entrypoints/all-external-dependencies.d.ts +8 -0
  12. package/dist/entrypoints/array.full.d.ts +17 -0
  13. package/dist/entrypoints/chat.d.ts +22 -0
  14. package/dist/entrypoints/web-vitals.d.ts +14 -0
  15. package/dist/extensions/chat/chat-wrapper.d.ts +172 -0
  16. package/dist/extensions/chat/chat.d.ts +87 -0
  17. package/dist/extensions/chat/index.d.ts +10 -0
  18. package/dist/extensions/chat/types.d.ts +156 -0
  19. package/dist/external-scripts-loader.js +1 -1
  20. package/dist/external-scripts-loader.js.map +1 -1
  21. package/dist/main.js +1 -1
  22. package/dist/main.js.map +1 -1
  23. package/dist/module.d.ts +312 -5
  24. package/dist/module.js +1 -1
  25. package/dist/module.js.map +1 -1
  26. package/dist/module.no-external.d.ts +312 -5
  27. package/dist/module.no-external.js +1 -1
  28. package/dist/module.no-external.js.map +1 -1
  29. package/dist/recorder.js.map +1 -1
  30. package/dist/types.d.ts +59 -2
  31. package/dist/utils/globals.d.ts +138 -1
  32. package/dist/vtilt.d.ts +11 -1
  33. package/dist/web-vitals.d.ts +89 -5
  34. package/dist/web-vitals.js +2 -0
  35. package/dist/web-vitals.js.map +1 -0
  36. package/lib/config.js +5 -3
  37. package/lib/entrypoints/all-external-dependencies.d.ts +8 -0
  38. package/lib/entrypoints/all-external-dependencies.js +10 -0
  39. package/lib/entrypoints/array.full.d.ts +17 -0
  40. package/lib/entrypoints/array.full.js +19 -0
  41. package/lib/entrypoints/chat.d.ts +22 -0
  42. package/lib/entrypoints/chat.js +32 -0
  43. package/lib/entrypoints/external-scripts-loader.js +1 -1
  44. package/lib/entrypoints/web-vitals.d.ts +14 -0
  45. package/lib/entrypoints/web-vitals.js +29 -0
  46. package/lib/extensions/chat/chat-wrapper.d.ts +172 -0
  47. package/lib/extensions/chat/chat-wrapper.js +497 -0
  48. package/lib/extensions/chat/chat.d.ts +87 -0
  49. package/lib/extensions/chat/chat.js +998 -0
  50. package/lib/extensions/chat/index.d.ts +10 -0
  51. package/lib/extensions/chat/index.js +27 -0
  52. package/lib/extensions/chat/types.d.ts +156 -0
  53. package/lib/extensions/chat/types.js +22 -0
  54. package/lib/types.d.ts +59 -2
  55. package/lib/types.js +16 -0
  56. package/lib/utils/globals.d.ts +138 -1
  57. package/lib/vtilt.d.ts +11 -1
  58. package/lib/vtilt.js +42 -1
  59. package/lib/web-vitals.d.ts +89 -5
  60. package/lib/web-vitals.js +354 -46
  61. package/package.json +66 -65
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Chat Extension
3
+ *
4
+ * Exports for the chat widget extension.
5
+ * The main export is ChatWrapper which is included in the main bundle.
6
+ * The actual implementation (LazyLoadedChat) is loaded on demand.
7
+ */
8
+ export { ChatWrapper } from "./chat-wrapper";
9
+ export * from "./types";
10
+ export type { ChatMessage, ChatChannel, ChatConfig, ChatTheme, LazyLoadedChatInterface, } from "../../utils/globals";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /**
3
+ * Chat Extension
4
+ *
5
+ * Exports for the chat widget extension.
6
+ * The main export is ChatWrapper which is included in the main bundle.
7
+ * The actual implementation (LazyLoadedChat) is loaded on demand.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ChatWrapper = void 0;
25
+ var chat_wrapper_1 = require("./chat-wrapper");
26
+ Object.defineProperty(exports, "ChatWrapper", { enumerable: true, get: function () { return chat_wrapper_1.ChatWrapper; } });
27
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Chat Extension Types
3
+ *
4
+ * Type definitions for the chat widget extension.
5
+ * Core types are re-exported from globals.ts for consistency.
6
+ */
7
+ export type { ChatMessage, ChatChannel, ChatConfig, ChatTheme, LazyLoadedChatInterface, } from "../../utils/globals";
8
+ /**
9
+ * Sender types for chat messages
10
+ */
11
+ export type SenderType = "user" | "agent" | "ai" | "system";
12
+ /**
13
+ * Channel status
14
+ */
15
+ export type ChannelStatus = "open" | "closed" | "snoozed";
16
+ /**
17
+ * Content types for messages
18
+ */
19
+ export type ContentType = "text" | "html" | "attachment";
20
+ /**
21
+ * Widget position options
22
+ */
23
+ export type WidgetPosition = "bottom-right" | "bottom-left";
24
+ /**
25
+ * Connection state for realtime
26
+ */
27
+ export type ConnectionState = "connecting" | "connected" | "disconnected" | "error";
28
+ /**
29
+ * Typing status event
30
+ */
31
+ export interface TypingStatus {
32
+ channel_id: string;
33
+ sender_type: SenderType;
34
+ sender_id: string;
35
+ is_typing: boolean;
36
+ timestamp: number;
37
+ }
38
+ /**
39
+ * Presence status for users
40
+ */
41
+ export interface PresenceStatus {
42
+ distinct_id: string;
43
+ status: "online" | "away" | "offline";
44
+ last_seen_at: string;
45
+ current_page_url?: string;
46
+ }
47
+ /**
48
+ * Chat event names for analytics tracking
49
+ */
50
+ export declare const CHAT_EVENTS: {
51
+ readonly STARTED: "$chat_started";
52
+ readonly MESSAGE_SENT: "$chat_message_sent";
53
+ readonly MESSAGE_RECEIVED: "$chat_message_received";
54
+ readonly AI_HANDOFF: "$chat_ai_handoff";
55
+ readonly CLOSED: "$chat_closed";
56
+ readonly READ: "$chat_read";
57
+ readonly WIDGET_OPENED: "$chat_widget_opened";
58
+ readonly WIDGET_CLOSED: "$chat_widget_closed";
59
+ };
60
+ /**
61
+ * Chat event properties for $chat_message_sent
62
+ */
63
+ export interface ChatMessageSentEventProperties {
64
+ $channel_id: string;
65
+ $message_id: string;
66
+ $content_preview: string;
67
+ $sender_type: SenderType;
68
+ $ai_mode: boolean;
69
+ $word_count: number;
70
+ }
71
+ /**
72
+ * Chat event properties for $chat_message_received
73
+ */
74
+ export interface ChatMessageReceivedEventProperties {
75
+ $channel_id: string;
76
+ $message_id: string;
77
+ $content_preview: string;
78
+ $sender_type: SenderType;
79
+ $response_time_ms?: number;
80
+ }
81
+ /**
82
+ * Chat event properties for $chat_started
83
+ */
84
+ export interface ChatStartedEventProperties {
85
+ $channel_id: string;
86
+ $initiated_by: "user" | "agent";
87
+ $ai_mode: boolean;
88
+ }
89
+ /**
90
+ * Chat event properties for $chat_closed
91
+ */
92
+ export interface ChatClosedEventProperties {
93
+ $channel_id: string;
94
+ $resolved_by: "agent" | "user" | "system" | "auto";
95
+ $resolution: "resolved" | "unresolved" | "abandoned";
96
+ $message_count: number;
97
+ $duration_seconds: number;
98
+ $ai_only: boolean;
99
+ }
100
+ /**
101
+ * Internal widget state
102
+ */
103
+ export interface ChatWidgetState {
104
+ isOpen: boolean;
105
+ isVisible: boolean;
106
+ isConnected: boolean;
107
+ isLoading: boolean;
108
+ unreadCount: number;
109
+ channel: import("../../utils/globals").ChatChannel | null;
110
+ messages: import("../../utils/globals").ChatMessage[];
111
+ isTyping: boolean;
112
+ typingSender: string | null;
113
+ agentLastReadAt: string | null;
114
+ }
115
+ /**
116
+ * Message callback type
117
+ */
118
+ export type MessageCallback = (message: import("../../utils/globals").ChatMessage) => void;
119
+ /**
120
+ * Typing callback type
121
+ */
122
+ export type TypingCallback = (isTyping: boolean, senderType: string) => void;
123
+ /**
124
+ * Connection callback type
125
+ */
126
+ export type ConnectionCallback = (connected: boolean) => void;
127
+ /**
128
+ * Unsubscribe function type
129
+ */
130
+ export type Unsubscribe = () => void;
131
+ /**
132
+ * API response for creating a channel
133
+ */
134
+ export interface CreateChannelResponse {
135
+ channel: import("../../utils/globals").ChatChannel;
136
+ config: {
137
+ ai_enabled: boolean;
138
+ ai_greeting: string | null;
139
+ widget_greeting: string | null;
140
+ };
141
+ }
142
+ /**
143
+ * API response for sending a message
144
+ */
145
+ export interface SendMessageResponse {
146
+ message: import("../../utils/globals").ChatMessage;
147
+ ai_response?: import("../../utils/globals").ChatMessage;
148
+ }
149
+ /**
150
+ * Ably realtime channel for chat
151
+ */
152
+ export interface AblyChannel {
153
+ subscribe: (event: string, callback: (message: unknown) => void) => void;
154
+ unsubscribe: () => void;
155
+ publish: (event: string, data: unknown) => Promise<void>;
156
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Chat Extension Types
4
+ *
5
+ * Type definitions for the chat widget extension.
6
+ * Core types are re-exported from globals.ts for consistency.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CHAT_EVENTS = void 0;
10
+ /**
11
+ * Chat event names for analytics tracking
12
+ */
13
+ exports.CHAT_EVENTS = {
14
+ STARTED: "$chat_started",
15
+ MESSAGE_SENT: "$chat_message_sent",
16
+ MESSAGE_RECEIVED: "$chat_message_received",
17
+ AI_HANDOFF: "$chat_ai_handoff",
18
+ CLOSED: "$chat_closed",
19
+ READ: "$chat_read",
20
+ WIDGET_OPENED: "$chat_widget_opened",
21
+ WIDGET_CLOSED: "$chat_widget_closed",
22
+ };
package/lib/types.d.ts CHANGED
@@ -51,8 +51,11 @@ export interface VTiltConfig {
51
51
  person_profiles?: PersonProfilesMode;
52
52
  /** Enable autocapture */
53
53
  autocapture?: boolean;
54
- /** Enable web vitals tracking */
55
- capture_performance?: boolean;
54
+ /**
55
+ * Enable web vitals tracking.
56
+ * Can be a boolean or an object with detailed configuration.
57
+ */
58
+ capture_performance?: boolean | CapturePerformanceConfig;
56
59
  /** Enable page view tracking */
57
60
  capture_pageview?: boolean | "auto";
58
61
  /** Enable page leave tracking */
@@ -75,6 +78,10 @@ export interface VTiltConfig {
75
78
  session_recording?: SessionRecordingOptions;
76
79
  /** Disable session recording (convenience flag) */
77
80
  disable_session_recording?: boolean;
81
+ /** Chat widget configuration */
82
+ chat?: ChatWidgetConfig;
83
+ /** Disable chat (convenience flag) */
84
+ disable_chat?: boolean;
78
85
  /** Global attributes added to all events */
79
86
  globalAttributes?: Record<string, string>;
80
87
  /** Bootstrap data for initialization */
@@ -160,6 +167,29 @@ export interface AliasEvent {
160
167
  distinct_id: string;
161
168
  original: string;
162
169
  }
170
+ /** Supported Web Vitals metrics */
171
+ export type SupportedWebVitalsMetric = "LCP" | "CLS" | "FCP" | "INP" | "TTFB";
172
+ /** All supported Web Vitals metrics */
173
+ export declare const ALL_WEB_VITALS_METRICS: SupportedWebVitalsMetric[];
174
+ /** Default Web Vitals metrics (matches PostHog defaults) */
175
+ export declare const DEFAULT_WEB_VITALS_METRICS: SupportedWebVitalsMetric[];
176
+ /**
177
+ * Web Vitals capture configuration
178
+ */
179
+ export interface CapturePerformanceConfig {
180
+ /** Enable or disable web vitals capture */
181
+ web_vitals?: boolean;
182
+ /** Which metrics to capture (default: LCP, CLS, FCP, INP) */
183
+ web_vitals_allowed_metrics?: SupportedWebVitalsMetric[];
184
+ /** Delay before flushing metrics in ms (default: 5000) */
185
+ web_vitals_delayed_flush_ms?: number;
186
+ /**
187
+ * Maximum allowed metric value in ms (default: 900000 = 15 minutes)
188
+ * Values above this are considered anomalies and ignored.
189
+ * Set to 0 to disable this check.
190
+ */
191
+ __web_vitals_max_value?: number;
192
+ }
163
193
  export interface WebVitalMetric {
164
194
  name: string;
165
195
  value: number;
@@ -167,6 +197,10 @@ export interface WebVitalMetric {
167
197
  rating: "good" | "needs-improvement" | "poor";
168
198
  id: string;
169
199
  navigationType: string;
200
+ /** Timestamp when the metric was captured (added internally) */
201
+ timestamp?: number;
202
+ /** Attribution data from web-vitals library */
203
+ attribution?: Record<string, unknown>;
170
204
  }
171
205
  export interface GeolocationData {
172
206
  country?: string;
@@ -259,6 +293,29 @@ export interface SessionRecordingOptions {
259
293
  /** Internal: Mutation throttler bucket size */
260
294
  __mutationThrottlerBucketSize?: number;
261
295
  }
296
+ /** Chat widget configuration */
297
+ export interface ChatWidgetConfig {
298
+ /** Enable/disable chat widget (default: auto from dashboard) */
299
+ enabled?: boolean;
300
+ /** Auto-fetch settings from dashboard (default: true) */
301
+ autoConfig?: boolean;
302
+ /** Widget position (default: 'bottom-right') */
303
+ position?: "bottom-right" | "bottom-left";
304
+ /** Widget header/greeting message */
305
+ greeting?: string;
306
+ /** Widget primary color */
307
+ color?: string;
308
+ /** Start in AI mode (default: true) */
309
+ aiMode?: boolean;
310
+ /** AI greeting message (first message from AI) */
311
+ aiGreeting?: string;
312
+ /** Preload widget script on idle vs on-demand */
313
+ preload?: boolean;
314
+ /** Offline message shown when business is unavailable */
315
+ offlineMessage?: string;
316
+ /** Collect email when offline */
317
+ collectEmailOffline?: boolean;
318
+ }
262
319
  export interface RemoteConfig {
263
320
  /** Default to identified_only mode */
264
321
  defaultIdentifiedOnly?: boolean;
package/lib/types.js CHANGED
@@ -6,3 +6,19 @@
6
6
  * Following PostHog's patterns where applicable.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DEFAULT_WEB_VITALS_METRICS = exports.ALL_WEB_VITALS_METRICS = void 0;
10
+ /** All supported Web Vitals metrics */
11
+ exports.ALL_WEB_VITALS_METRICS = [
12
+ "LCP",
13
+ "CLS",
14
+ "FCP",
15
+ "INP",
16
+ "TTFB",
17
+ ];
18
+ /** Default Web Vitals metrics (matches PostHog defaults) */
19
+ exports.DEFAULT_WEB_VITALS_METRICS = [
20
+ "LCP",
21
+ "CLS",
22
+ "FCP",
23
+ "INP",
24
+ ];
@@ -2,7 +2,7 @@ declare const win: (Window & typeof globalThis) | undefined;
2
2
  /**
3
3
  * Extension kinds that can be lazy loaded
4
4
  */
5
- export type VTiltExtensionKind = "recorder" | "web-vitals";
5
+ export type VTiltExtensionKind = "recorder" | "web-vitals" | "chat";
6
6
  /**
7
7
  * Interface for lazy-loaded session recording (set by recorder.ts)
8
8
  * Matches LazyLoadedSessionRecordingInterface in session-recording-wrapper.ts
@@ -17,6 +17,139 @@ export interface LazyLoadedSessionRecordingInterface {
17
17
  log: (message: string, level: "log" | "warn" | "error") => void;
18
18
  updateConfig: (config: any) => void;
19
19
  }
20
+ /**
21
+ * Web Vitals metric callback type
22
+ */
23
+ export type WebVitalsMetricCallback = (metric: any) => void;
24
+ /**
25
+ * Options for web vitals callbacks
26
+ */
27
+ export interface WebVitalsCallbackOptions {
28
+ /** Report all changes (useful for CLS which updates over time) */
29
+ reportAllChanges?: boolean;
30
+ }
31
+ /**
32
+ * Web Vitals callback function type (with optional options)
33
+ */
34
+ export type WebVitalsCallbackFn = (callback: WebVitalsMetricCallback, options?: WebVitalsCallbackOptions) => void;
35
+ /**
36
+ * Web Vitals callbacks interface (set by web-vitals.ts entrypoint)
37
+ */
38
+ export interface WebVitalsCallbacks {
39
+ onLCP: WebVitalsCallbackFn;
40
+ onCLS: WebVitalsCallbackFn;
41
+ onFCP: WebVitalsCallbackFn;
42
+ onINP: WebVitalsCallbackFn;
43
+ onTTFB?: WebVitalsCallbackFn;
44
+ }
45
+ /**
46
+ * Chat message structure (matches PostgreSQL chat_messages table)
47
+ * Note: Read status is determined by cursor comparison, not per-message
48
+ */
49
+ export interface ChatMessage {
50
+ id: string;
51
+ channel_id: string;
52
+ sender_type: "user" | "agent" | "ai" | "system";
53
+ sender_id: string | null;
54
+ sender_name: string | null;
55
+ sender_avatar_url: string | null;
56
+ content: string;
57
+ content_type: "text" | "html" | "attachment";
58
+ metadata: Record<string, unknown>;
59
+ created_at: string;
60
+ }
61
+ /**
62
+ * Chat channel structure (maps 1:1 to Ably channel)
63
+ */
64
+ export interface ChatChannel {
65
+ id: string;
66
+ project_id: string;
67
+ person_id: string;
68
+ distinct_id: string;
69
+ status: "open" | "closed" | "snoozed";
70
+ ai_mode: boolean;
71
+ unread_count: number;
72
+ last_message_at: string | null;
73
+ last_message_preview: string | null;
74
+ last_message_sender: "user" | "agent" | "ai" | "system" | null;
75
+ user_last_read_at: string | null;
76
+ agent_last_read_at: string | null;
77
+ created_at: string;
78
+ }
79
+ /**
80
+ * Chat widget configuration
81
+ *
82
+ * Settings can come from two sources:
83
+ * 1. Dashboard (fetched from /api/chat/settings) - "snippet-only" mode
84
+ * 2. Code config (passed to vt.init) - overrides dashboard settings
85
+ *
86
+ * This enables Intercom-like flexibility: just add snippet OR customize with code.
87
+ */
88
+ export interface ChatConfig {
89
+ /**
90
+ * Enable/disable chat widget.
91
+ * - undefined: Use dashboard setting (auto-fetch)
92
+ * - true: Enable (override dashboard)
93
+ * - false: Disable entirely
94
+ */
95
+ enabled?: boolean;
96
+ /**
97
+ * Auto-fetch settings from dashboard (default: true)
98
+ * When true, SDK fetches /api/chat/settings and uses those as base config.
99
+ * Code config always overrides fetched settings.
100
+ */
101
+ autoConfig?: boolean;
102
+ /** Widget position (default: 'bottom-right') */
103
+ position?: "bottom-right" | "bottom-left";
104
+ /** Widget header/greeting message */
105
+ greeting?: string;
106
+ /** Widget primary color */
107
+ color?: string;
108
+ /** Start in AI mode (default: true) */
109
+ aiMode?: boolean;
110
+ /** AI greeting message (first message from AI) */
111
+ aiGreeting?: string;
112
+ /** Preload widget script on idle vs on-demand */
113
+ preload?: boolean;
114
+ /** Custom theme */
115
+ theme?: ChatTheme;
116
+ /** Offline message shown when business is unavailable */
117
+ offlineMessage?: string;
118
+ /** Collect email when offline */
119
+ collectEmailOffline?: boolean;
120
+ }
121
+ /**
122
+ * Chat theme customization
123
+ */
124
+ export interface ChatTheme {
125
+ primaryColor?: string;
126
+ fontFamily?: string;
127
+ borderRadius?: string;
128
+ headerBgColor?: string;
129
+ userBubbleColor?: string;
130
+ agentBubbleColor?: string;
131
+ }
132
+ /**
133
+ * Interface for lazy-loaded chat widget (set by chat.ts entrypoint)
134
+ */
135
+ export interface LazyLoadedChatInterface {
136
+ readonly isOpen: boolean;
137
+ readonly isConnected: boolean;
138
+ readonly isLoading: boolean;
139
+ readonly unreadCount: number;
140
+ readonly channel: ChatChannel | null;
141
+ open(): void;
142
+ close(): void;
143
+ toggle(): void;
144
+ show(): void;
145
+ hide(): void;
146
+ sendMessage(content: string): Promise<void>;
147
+ markAsRead(): void;
148
+ onMessage(callback: (message: ChatMessage) => void): () => void;
149
+ onTyping(callback: (isTyping: boolean, senderType: string) => void): () => void;
150
+ onConnectionChange(callback: (connected: boolean) => void): () => void;
151
+ destroy(): void;
152
+ }
20
153
  /**
21
154
  * VTilt Extensions interface for dynamically loaded modules
22
155
  * This is the contract between lazily loaded extensions and the SDK
@@ -37,6 +170,10 @@ export interface VTiltExtensions {
37
170
  };
38
171
  /** Factory to create LazyLoadedSessionRecording (set by recorder.ts) */
39
172
  initSessionRecording?: (instance: any, config?: any) => LazyLoadedSessionRecordingInterface;
173
+ /** Web Vitals callbacks (set by web-vitals.ts entrypoint) */
174
+ webVitalsCallbacks?: WebVitalsCallbacks;
175
+ /** Factory to create LazyLoadedChat (set by chat.ts entrypoint) */
176
+ initChat?: (instance: any, config?: ChatConfig) => LazyLoadedChatInterface;
40
177
  }
41
178
  export type AssignableWindow = Window & typeof globalThis & {
42
179
  /** Main VTilt instance */
package/lib/vtilt.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { VTiltConfig, EventPayload } from "./types";
2
2
  import { HistoryAutocapture } from "./extensions/history-autocapture";
3
3
  import { SessionRecordingWrapper } from "./extensions/replay";
4
+ import { ChatWrapper } from "./extensions/chat/chat-wrapper";
4
5
  import { type QueuedRequest } from "./request-queue";
5
6
  export declare class VTilt {
6
7
  readonly version = "1.1.5";
@@ -13,6 +14,7 @@ export declare class VTilt {
13
14
  private rateLimiter;
14
15
  historyAutocapture?: HistoryAutocapture;
15
16
  sessionRecording?: SessionRecordingWrapper;
17
+ chat?: ChatWrapper;
16
18
  __loaded: boolean;
17
19
  private _initial_pageview_captured;
18
20
  private _visibility_state_listener;
@@ -271,11 +273,19 @@ export declare class VTilt {
271
273
  /**
272
274
  * Check if session recording is active
273
275
  */
274
- isSessionRecordingActive(): boolean;
276
+ isRecordingActive(): boolean;
275
277
  /**
276
278
  * Get session recording ID
277
279
  */
278
280
  getSessionRecordingId(): string | null;
281
+ /**
282
+ * Initialize chat widget
283
+ */
284
+ private _initChat;
285
+ /**
286
+ * Build chat config from VTiltConfig
287
+ */
288
+ private _buildChatConfig;
279
289
  /**
280
290
  * _execute_array() deals with processing any vTilt function
281
291
  * calls that were called before the vTilt library was loaded
package/lib/vtilt.js CHANGED
@@ -9,6 +9,7 @@ const user_manager_1 = require("./user-manager");
9
9
  const web_vitals_1 = require("./web-vitals");
10
10
  const history_autocapture_1 = require("./extensions/history-autocapture");
11
11
  const replay_1 = require("./extensions/replay");
12
+ const chat_wrapper_1 = require("./extensions/chat/chat-wrapper");
12
13
  const request_1 = require("./request");
13
14
  const request_queue_1 = require("./request-queue");
14
15
  const retry_queue_1 = require("./retry-queue");
@@ -137,6 +138,8 @@ class VTilt {
137
138
  this.historyAutocapture.startIfEnabled();
138
139
  // Initialize session recording if enabled
139
140
  this._initSessionRecording();
141
+ // Initialize chat widget
142
+ this._initChat();
140
143
  // Set up page unload handler to flush queued events
141
144
  this._setup_unload_handler();
142
145
  // Enable the request queue for batched sending (PostHog pattern)
@@ -825,7 +828,7 @@ class VTilt {
825
828
  /**
826
829
  * Check if session recording is active
827
830
  */
828
- isSessionRecordingActive() {
831
+ isRecordingActive() {
829
832
  var _a;
830
833
  return ((_a = this.sessionRecording) === null || _a === void 0 ? void 0 : _a.status) === "active";
831
834
  }
@@ -836,6 +839,44 @@ class VTilt {
836
839
  var _a;
837
840
  return ((_a = this.sessionRecording) === null || _a === void 0 ? void 0 : _a.sessionId) || null;
838
841
  }
842
+ // ============================================================================
843
+ // Chat
844
+ // ============================================================================
845
+ /**
846
+ * Initialize chat widget
847
+ */
848
+ _initChat() {
849
+ const config = this.configManager.getConfig();
850
+ // Don't initialize if explicitly disabled
851
+ if (config.disable_chat) {
852
+ return;
853
+ }
854
+ // Build chat config from VTiltConfig
855
+ const chatConfig = this._buildChatConfig(config);
856
+ // Create chat wrapper (lightweight - actual chat is lazy-loaded)
857
+ this.chat = new chat_wrapper_1.ChatWrapper(this, chatConfig);
858
+ // Start chat if enabled (this will fetch server settings and show bubble)
859
+ this.chat.startIfEnabled();
860
+ }
861
+ /**
862
+ * Build chat config from VTiltConfig
863
+ */
864
+ _buildChatConfig(config) {
865
+ var _a;
866
+ const chat = config.chat || {};
867
+ return {
868
+ enabled: chat.enabled,
869
+ autoConfig: (_a = chat.autoConfig) !== null && _a !== void 0 ? _a : true, // Default to auto-config from dashboard
870
+ position: chat.position,
871
+ greeting: chat.greeting,
872
+ color: chat.color,
873
+ aiMode: chat.aiMode,
874
+ aiGreeting: chat.aiGreeting,
875
+ preload: chat.preload,
876
+ offlineMessage: chat.offlineMessage,
877
+ collectEmailOffline: chat.collectEmailOffline,
878
+ };
879
+ }
839
880
  /**
840
881
  * _execute_array() deals with processing any vTilt function
841
882
  * calls that were called before the vTilt library was loaded