@v-tilt/browser 1.3.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.
- package/dist/all-external-dependencies.js.map +1 -1
- package/dist/array.full.js +1 -1
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/chat.js +2 -0
- package/dist/chat.js.map +1 -0
- package/dist/entrypoints/chat.d.ts +22 -0
- package/dist/extensions/chat/chat-wrapper.d.ts +172 -0
- package/dist/extensions/chat/chat.d.ts +87 -0
- package/dist/extensions/chat/index.d.ts +10 -0
- package/dist/extensions/chat/types.d.ts +156 -0
- package/dist/external-scripts-loader.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +279 -2
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +279 -2
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/recorder.js.map +1 -1
- package/dist/types.d.ts +27 -0
- package/dist/utils/globals.d.ts +111 -1
- package/dist/vtilt.d.ts +11 -1
- package/dist/web-vitals.js.map +1 -1
- package/lib/entrypoints/chat.d.ts +22 -0
- package/lib/entrypoints/chat.js +32 -0
- package/lib/extensions/chat/chat-wrapper.d.ts +172 -0
- package/lib/extensions/chat/chat-wrapper.js +497 -0
- package/lib/extensions/chat/chat.d.ts +87 -0
- package/lib/extensions/chat/chat.js +998 -0
- package/lib/extensions/chat/index.d.ts +10 -0
- package/lib/extensions/chat/index.js +27 -0
- package/lib/extensions/chat/types.d.ts +156 -0
- package/lib/extensions/chat/types.js +22 -0
- package/lib/types.d.ts +27 -0
- package/lib/utils/globals.d.ts +111 -1
- package/lib/vtilt.d.ts +11 -1
- package/lib/vtilt.js +42 -1
- 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
|
@@ -78,6 +78,10 @@ export interface VTiltConfig {
|
|
|
78
78
|
session_recording?: SessionRecordingOptions;
|
|
79
79
|
/** Disable session recording (convenience flag) */
|
|
80
80
|
disable_session_recording?: boolean;
|
|
81
|
+
/** Chat widget configuration */
|
|
82
|
+
chat?: ChatWidgetConfig;
|
|
83
|
+
/** Disable chat (convenience flag) */
|
|
84
|
+
disable_chat?: boolean;
|
|
81
85
|
/** Global attributes added to all events */
|
|
82
86
|
globalAttributes?: Record<string, string>;
|
|
83
87
|
/** Bootstrap data for initialization */
|
|
@@ -289,6 +293,29 @@ export interface SessionRecordingOptions {
|
|
|
289
293
|
/** Internal: Mutation throttler bucket size */
|
|
290
294
|
__mutationThrottlerBucketSize?: number;
|
|
291
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
|
+
}
|
|
292
319
|
export interface RemoteConfig {
|
|
293
320
|
/** Default to identified_only mode */
|
|
294
321
|
defaultIdentifiedOnly?: boolean;
|
package/lib/utils/globals.d.ts
CHANGED
|
@@ -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
|
|
@@ -42,6 +42,114 @@ export interface WebVitalsCallbacks {
|
|
|
42
42
|
onINP: WebVitalsCallbackFn;
|
|
43
43
|
onTTFB?: WebVitalsCallbackFn;
|
|
44
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
|
+
}
|
|
45
153
|
/**
|
|
46
154
|
* VTilt Extensions interface for dynamically loaded modules
|
|
47
155
|
* This is the contract between lazily loaded extensions and the SDK
|
|
@@ -64,6 +172,8 @@ export interface VTiltExtensions {
|
|
|
64
172
|
initSessionRecording?: (instance: any, config?: any) => LazyLoadedSessionRecordingInterface;
|
|
65
173
|
/** Web Vitals callbacks (set by web-vitals.ts entrypoint) */
|
|
66
174
|
webVitalsCallbacks?: WebVitalsCallbacks;
|
|
175
|
+
/** Factory to create LazyLoadedChat (set by chat.ts entrypoint) */
|
|
176
|
+
initChat?: (instance: any, config?: ChatConfig) => LazyLoadedChatInterface;
|
|
67
177
|
}
|
|
68
178
|
export type AssignableWindow = Window & typeof globalThis & {
|
|
69
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
|
-
|
|
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
|
-
|
|
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
|
package/package.json
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@v-tilt/browser",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "vTilt browser tracking library",
|
|
5
|
-
"main": "dist/main.js",
|
|
6
|
-
"module": "dist/module.js",
|
|
7
|
-
"types": "dist/module.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"lib/*",
|
|
10
|
-
"dist/*"
|
|
11
|
-
],
|
|
12
|
-
"publishConfig": {
|
|
13
|
-
"access": "public"
|
|
14
|
-
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsc -b && rollup -c",
|
|
17
|
-
"dev": "rollup -c -w",
|
|
18
|
-
"type-check": "tsc --noEmit",
|
|
19
|
-
"lint": "eslint src --ext .ts",
|
|
20
|
-
"lint:fix": "eslint src --ext .ts --fix",
|
|
21
|
-
"clean": "rimraf lib dist",
|
|
22
|
-
"prepublishOnly": "pnpm run build"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"analytics",
|
|
26
|
-
"tracking",
|
|
27
|
-
"web-vitals",
|
|
28
|
-
"performance"
|
|
29
|
-
],
|
|
30
|
-
"author": "vTilt",
|
|
31
|
-
"license": "MIT",
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@babel/preset-env": "^7.28.3",
|
|
34
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
35
|
-
"@rollup/plugin-commonjs": "^25.0.8",
|
|
36
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
37
|
-
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
38
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
39
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
40
|
-
"@types/node": "^20.10.5",
|
|
41
|
-
"@v-tilt/eslint-config": "workspace:*",
|
|
42
|
-
"eslint": "^9.0.0",
|
|
43
|
-
"rimraf": "^5.0.5",
|
|
44
|
-
"rollup": "^4.9.1",
|
|
45
|
-
"rollup-plugin-dts": "^6.2.3",
|
|
46
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
47
|
-
"rollup-plugin-visualizer": "^6.0.3",
|
|
48
|
-
"typescript": "^5.3.3"
|
|
49
|
-
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@rrweb/record": "2.0.0-alpha.17",
|
|
52
|
-
"@rrweb/rrweb-plugin-console-record": "2.0.0-alpha.17",
|
|
53
|
-
"@rrweb/types": "2.0.0-alpha.17",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-tilt/browser",
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "vTilt browser tracking library",
|
|
5
|
+
"main": "dist/main.js",
|
|
6
|
+
"module": "dist/module.js",
|
|
7
|
+
"types": "dist/module.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib/*",
|
|
10
|
+
"dist/*"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -b && rollup -c",
|
|
17
|
+
"dev": "rollup -c -w",
|
|
18
|
+
"type-check": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint src --ext .ts",
|
|
20
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
21
|
+
"clean": "rimraf lib dist",
|
|
22
|
+
"prepublishOnly": "pnpm run build"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"analytics",
|
|
26
|
+
"tracking",
|
|
27
|
+
"web-vitals",
|
|
28
|
+
"performance"
|
|
29
|
+
],
|
|
30
|
+
"author": "vTilt",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@babel/preset-env": "^7.28.3",
|
|
34
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
35
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
36
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^15.3.1",
|
|
38
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
39
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
40
|
+
"@types/node": "^20.10.5",
|
|
41
|
+
"@v-tilt/eslint-config": "workspace:*",
|
|
42
|
+
"eslint": "^9.0.0",
|
|
43
|
+
"rimraf": "^5.0.5",
|
|
44
|
+
"rollup": "^4.9.1",
|
|
45
|
+
"rollup-plugin-dts": "^6.2.3",
|
|
46
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
47
|
+
"rollup-plugin-visualizer": "^6.0.3",
|
|
48
|
+
"typescript": "^5.3.3"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@rrweb/record": "2.0.0-alpha.17",
|
|
52
|
+
"@rrweb/rrweb-plugin-console-record": "2.0.0-alpha.17",
|
|
53
|
+
"@rrweb/types": "2.0.0-alpha.17",
|
|
54
|
+
"ably": "^2.4.0",
|
|
55
|
+
"fflate": "^0.8.2",
|
|
56
|
+
"web-vitals": "^3.5.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"web-vitals": "^3.0.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"web-vitals": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|