@prodact.ai/sdk 0.0.6 → 0.0.7

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.
@@ -0,0 +1,332 @@
1
+ // Core SDK Types
2
+ export interface ProduckConfig {
3
+ guiderId?: string;
4
+ sdkKey?: string;
5
+ apiUrl?: string;
6
+ onAction?: (actionKey: string, action: ActionPayload) => void;
7
+ onMessage?: (message: ChatMessage) => void;
8
+ onError?: (error: Error) => void;
9
+ onFlowStart?: (flow: FlowPayload) => void;
10
+ onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
11
+ onFlowComplete?: (result: FlowResult) => void;
12
+ recording?: RecordingConfig;
13
+ proactive?: ProactiveConfig;
14
+ userFlows?: UserFlowConfig;
15
+ onProactiveMessage?: (message: string, context: ProactiveContext) => void;
16
+ initialMessage?: string;
17
+ streamInitialMessage?: boolean;
18
+ }
19
+
20
+ export interface ActionPayload {
21
+ actionKey: string;
22
+ name: string;
23
+ actionType: string;
24
+ actionConfig: Record<string, any>;
25
+ responseMessage?: string;
26
+ }
27
+
28
+ export interface FlowStep {
29
+ operationId: string;
30
+ order: number;
31
+ condition?: Record<string, any>;
32
+ inputMapping?: Record<string, any>;
33
+ }
34
+
35
+ export interface FlowPayload {
36
+ flowId: string;
37
+ name: string;
38
+ description: string;
39
+ steps: FlowStep[];
40
+ }
41
+
42
+ export interface FlowStepResult {
43
+ operationId: string;
44
+ order: number;
45
+ success: boolean;
46
+ data?: any;
47
+ error?: string;
48
+ }
49
+
50
+ export interface FlowResult {
51
+ flowId: string;
52
+ name: string;
53
+ steps: FlowStepResult[];
54
+ completed: boolean;
55
+ totalSteps: number;
56
+ successfulSteps: number;
57
+ }
58
+
59
+ export interface ChatMessage {
60
+ role: 'user' | 'assistant';
61
+ content: string;
62
+ action?: ActionPayload;
63
+ flow?: FlowPayload;
64
+ flowResult?: FlowResult;
65
+ visualFlows?: VisualFlowReference[];
66
+ images?: ImageReference[];
67
+ }
68
+
69
+ export interface VisualFlowReference {
70
+ flowId: string;
71
+ name: string;
72
+ description: string;
73
+ score: number;
74
+ stepsCount?: number;
75
+ tags?: string[];
76
+ }
77
+
78
+ export interface ImageReference {
79
+ url: string;
80
+ name: string;
81
+ description: string;
82
+ score: number;
83
+ }
84
+
85
+ export interface VisualFlowStep {
86
+ id: string;
87
+ stepOrder: number;
88
+ title: string;
89
+ description: string;
90
+ screenshotUrl: string | null;
91
+ elementSelector: string | null;
92
+ pageUrl: string;
93
+ }
94
+
95
+ export interface VisualFlowDetails {
96
+ id: string;
97
+ flowId: string;
98
+ name: string;
99
+ description: string;
100
+ tags: string[];
101
+ steps: VisualFlowStep[];
102
+ }
103
+
104
+ export type ActionHandler = (payload: ActionPayload) => void | Promise<void>;
105
+
106
+ export type ProduckEventType = 'action' | 'message' | 'error' | 'ready' | 'flowStart' | 'flowStepComplete' | 'flowComplete' | 'proactive';
107
+
108
+ // Recording Types
109
+ export interface RecordingConfig {
110
+ enabled?: boolean;
111
+ samplingRate?: number;
112
+ privacy?: RecordingPrivacyConfig;
113
+ performance?: RecordingPerformanceConfig;
114
+ capture?: RecordingCaptureConfig;
115
+ maxDuration?: number;
116
+ }
117
+
118
+ export interface RecordingPrivacyConfig {
119
+ maskAllInputs?: boolean;
120
+ maskInputTypes?: string[];
121
+ maskSelectors?: string[];
122
+ blockSelectors?: string[];
123
+ ignoreSelectors?: string[];
124
+ maskTextContent?: boolean;
125
+ maskTextSelectors?: string[];
126
+ }
127
+
128
+ export interface RecordingPerformanceConfig {
129
+ checkoutEveryNms?: number;
130
+ batchSize?: number;
131
+ batchIntervalMs?: number;
132
+ compressionEnabled?: boolean;
133
+ }
134
+
135
+ export interface RecordingCaptureConfig {
136
+ mouse?: boolean;
137
+ scroll?: boolean;
138
+ input?: boolean;
139
+ resize?: boolean;
140
+ mediaInteraction?: boolean;
141
+ console?: boolean;
142
+ errors?: boolean;
143
+ }
144
+
145
+ export interface RecordingSession {
146
+ sessionId: string;
147
+ startTime: Date;
148
+ duration: number;
149
+ eventCount: number;
150
+ isActive: boolean;
151
+ }
152
+
153
+ export interface RecordingStats {
154
+ totalEvents: number;
155
+ batchesSent: number;
156
+ errors: number;
157
+ duration: number;
158
+ }
159
+
160
+ export interface CustomRecordingEvent {
161
+ type: string;
162
+ data: Record<string, any>;
163
+ timestamp?: number;
164
+ }
165
+
166
+ // Proactive Types
167
+ export interface ProactiveConfig {
168
+ enabled?: boolean;
169
+ idleTimeThreshold?: number;
170
+ scrollDepthThreshold?: number;
171
+ ragClickThreshold?: number;
172
+ exitIntentEnabled?: boolean;
173
+ triggers?: ProactiveTrigger[];
174
+ }
175
+
176
+ export interface ProactiveTrigger {
177
+ type: 'idle' | 'scroll' | 'rage_click' | 'exit_intent' | 'time_on_page' | 'custom';
178
+ condition?: Record<string, any>;
179
+ message?: string;
180
+ priority?: number;
181
+ }
182
+
183
+ export interface ProactiveContext {
184
+ triggerType: string;
185
+ pageUrl: string;
186
+ timeOnPage: number;
187
+ scrollDepth: number;
188
+ metadata?: Record<string, any>;
189
+ }
190
+
191
+ export interface ProactiveCallbacks {
192
+ onTrigger?: (trigger: ProactiveTrigger, context: ProactiveContext) => void;
193
+ onMessage?: (message: string, context: ProactiveContext) => void;
194
+ }
195
+
196
+ export declare const defaultProactiveConfig: ProactiveConfig;
197
+
198
+ // User Flow Types
199
+ export interface UserFlowConfig {
200
+ enabled?: boolean;
201
+ events?: UserFlowEventsConfig;
202
+ elements?: UserFlowElementConfig;
203
+ performance?: UserFlowPerformanceConfig;
204
+ }
205
+
206
+ export interface UserFlowEventsConfig {
207
+ clicks?: boolean;
208
+ inputs?: boolean;
209
+ scrolls?: boolean;
210
+ navigation?: boolean;
211
+ errors?: boolean;
212
+ customEvents?: boolean;
213
+ }
214
+
215
+ export interface UserFlowElementConfig {
216
+ captureSelectors?: boolean;
217
+ captureText?: boolean;
218
+ maxTextLength?: number;
219
+ }
220
+
221
+ export interface UserFlowPerformanceConfig {
222
+ batchSize?: number;
223
+ batchIntervalMs?: number;
224
+ maxEventsPerSession?: number;
225
+ }
226
+
227
+ export interface UserIdentification {
228
+ userId?: string;
229
+ email?: string;
230
+ name?: string;
231
+ metadata?: Record<string, any>;
232
+ }
233
+
234
+ export interface DeviceInfo {
235
+ userAgent: string;
236
+ language: string;
237
+ platform: string;
238
+ screenWidth: number;
239
+ screenHeight: number;
240
+ viewportWidth: number;
241
+ viewportHeight: number;
242
+ devicePixelRatio: number;
243
+ timezone: string;
244
+ }
245
+
246
+ export interface ElementInfo {
247
+ tagName: string;
248
+ id?: string;
249
+ className?: string;
250
+ text?: string;
251
+ selector?: string;
252
+ }
253
+
254
+ export interface UserFlowEvent {
255
+ type: string;
256
+ timestamp: number;
257
+ data: Record<string, any>;
258
+ }
259
+
260
+ export interface UserFlowSession {
261
+ sessionId: string;
262
+ startTime: Date;
263
+ events: UserFlowEvent[];
264
+ }
265
+
266
+ export interface TrackingState {
267
+ isTracking: boolean;
268
+ sessionId: string | null;
269
+ eventCount: number;
270
+ }
271
+
272
+ export interface TrackerStats {
273
+ totalEvents: number;
274
+ batchesSent: number;
275
+ errors: number;
276
+ }
277
+
278
+ // Core SDK Class
279
+ export declare class ProduckSDK {
280
+ constructor(config: ProduckConfig);
281
+ init(): Promise<void>;
282
+ getSessionToken(): string | null;
283
+ sendMessage(message: string): Promise<ChatMessage>;
284
+ registerAction(key: string, handler: ActionHandler): void;
285
+ unregisterAction(key: string): void;
286
+ on(event: ProduckEventType, callback: Function): void;
287
+ off(event: ProduckEventType, callback: Function): void;
288
+ getVisualFlow(flowId: string): Promise<VisualFlowDetails | null>;
289
+ destroy(): void;
290
+
291
+ // Recording methods
292
+ startRecording(): Promise<void>;
293
+ stopRecording(): Promise<void>;
294
+ pauseRecording(): void;
295
+ resumeRecording(): void;
296
+ getRecordingStats(): RecordingStats | null;
297
+ addCustomEvent(event: CustomRecordingEvent): void;
298
+
299
+ // User identification
300
+ identify(user: UserIdentification): void;
301
+
302
+ // User flow tracking
303
+ trackEvent(eventType: string, data?: Record<string, any>): void;
304
+ getFlowStats(): TrackerStats | null;
305
+ }
306
+
307
+ // Session Recorder Class
308
+ export declare class SessionRecorder {
309
+ constructor(config?: RecordingConfig);
310
+ start(sdkSessionToken: string, apiUrl: string, sdkKey?: string): Promise<void>;
311
+ stop(): Promise<void>;
312
+ pause(): void;
313
+ resume(): void;
314
+ getStats(): RecordingStats;
315
+ getSession(): RecordingSession | null;
316
+ addCustomEvent(event: CustomRecordingEvent): void;
317
+ }
318
+
319
+ // User Flow Tracker Class
320
+ export declare class UserFlowTracker {
321
+ constructor(config?: UserFlowConfig);
322
+ start(sessionToken: string, apiUrl: string, sdkKey?: string): void;
323
+ stop(): void;
324
+ identify(user: UserIdentification): void;
325
+ trackEvent(eventType: string, data?: Record<string, any>): void;
326
+ getStats(): TrackerStats;
327
+ }
328
+
329
+ // Factory functions
330
+ export declare function createProduck(config: ProduckConfig): ProduckSDK;
331
+ export declare function createSessionRecorder(config?: RecordingConfig): SessionRecorder;
332
+ export declare function createUserFlowTracker(config?: UserFlowConfig): UserFlowTracker;
@@ -0,0 +1,155 @@
1
+ import { ReactNode, CSSProperties } from 'react';
2
+
3
+ // Re-export core types
4
+ export type {
5
+ ProduckConfig,
6
+ ActionPayload,
7
+ ChatMessage,
8
+ ActionHandler,
9
+ FlowPayload,
10
+ FlowStep,
11
+ FlowResult,
12
+ FlowStepResult,
13
+ VisualFlowReference,
14
+ VisualFlowDetails,
15
+ VisualFlowStep,
16
+ ImageReference,
17
+ } from './index';
18
+
19
+ import type {
20
+ ProduckConfig,
21
+ ActionPayload,
22
+ ChatMessage,
23
+ FlowPayload,
24
+ FlowResult,
25
+ FlowStepResult,
26
+ VisualFlowReference,
27
+ } from './index';
28
+
29
+ import { ProduckSDK } from './index';
30
+
31
+ // Context Types
32
+ export interface ProduckContextValue {
33
+ sdk: ProduckSDK | null;
34
+ isReady: boolean;
35
+ sessionToken: string | null;
36
+ messages: ChatMessage[];
37
+ isLoading: boolean;
38
+ sendMessage: (message: string) => Promise<void>;
39
+ register: (actionKey: string, handler: (payload: ActionPayload) => void) => void;
40
+ unregister: (actionKey: string) => void;
41
+ activeFlow: FlowPayload | null;
42
+ flowResult: FlowResult | null;
43
+ isExecutingFlow: boolean;
44
+ }
45
+
46
+ // Provider Props
47
+ export interface ProduckProviderProps {
48
+ config: Omit<ProduckConfig, 'onAction' | 'onMessage' | 'onError' | 'onFlowStart' | 'onFlowStepComplete' | 'onFlowComplete'>;
49
+ children: ReactNode;
50
+ onAction?: (actionKey: string, payload: ActionPayload) => void;
51
+ onError?: (error: Error) => void;
52
+ onFlowStart?: (flow: FlowPayload) => void;
53
+ onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
54
+ onFlowComplete?: (result: FlowResult) => void;
55
+ }
56
+
57
+ // Chat Appearance
58
+ export interface ProduckChatAppearance {
59
+ width?: string | number;
60
+ height?: string | number;
61
+ borderRadius?: string | number;
62
+ backgroundColor?: string;
63
+ headerBackgroundColor?: string;
64
+ headerTextColor?: string;
65
+ inputBackgroundColor?: string;
66
+ inputTextColor?: string;
67
+ inputBorderColor?: string;
68
+ userMessageBackgroundColor?: string;
69
+ userMessageTextColor?: string;
70
+ assistantMessageBackgroundColor?: string;
71
+ assistantMessageTextColor?: string;
72
+ buttonBackgroundColor?: string;
73
+ buttonTextColor?: string;
74
+ buttonBorderRadius?: string | number;
75
+ floatingButtonSize?: string | number;
76
+ fontFamily?: string;
77
+ fontSize?: string | number;
78
+ headerFontSize?: string | number;
79
+ border?: string;
80
+ boxShadow?: string;
81
+ floatingButtonIcon?: ReactNode;
82
+ floatingButtonLoadingIcon?: ReactNode;
83
+ showCloseButton?: boolean;
84
+ headerIcon?: ReactNode;
85
+ sendButtonText?: string;
86
+ sendButtonIcon?: ReactNode;
87
+ emptyStateIcon?: ReactNode;
88
+ emptyStateTitle?: string;
89
+ emptyStateSubtitle?: string;
90
+ }
91
+
92
+ // Chat Props
93
+ export interface ProduckChatProps {
94
+ placeholder?: string;
95
+ title?: string;
96
+ position?: 'bottom-right' | 'bottom-left' | 'inline';
97
+ theme?: 'light' | 'dark';
98
+ primaryColor?: string;
99
+ className?: string;
100
+ style?: CSSProperties;
101
+ defaultOpen?: boolean;
102
+ appearance?: ProduckChatAppearance;
103
+ initialMessage?: string;
104
+ initialMessageDelay?: number;
105
+ autoOpenDelay?: number;
106
+ proactiveEnabled?: boolean;
107
+ showPoweredBy?: boolean;
108
+ poweredByText?: string;
109
+ poweredByUrl?: string;
110
+ }
111
+
112
+ // Target Props
113
+ export interface ProduckTargetProps {
114
+ actionKey: string;
115
+ children: ReactNode;
116
+ onTrigger?: (payload: ActionPayload) => void;
117
+ highlightStyle?: CSSProperties;
118
+ highlightDuration?: number;
119
+ scrollIntoView?: boolean;
120
+ }
121
+
122
+ // Visual Flow Display Props
123
+ export interface VisualFlowDisplayProps {
124
+ flowRef: VisualFlowReference;
125
+ theme?: 'light' | 'dark';
126
+ primaryColor?: string;
127
+ }
128
+
129
+ // Components
130
+ export declare function ProduckProvider(props: ProduckProviderProps): JSX.Element;
131
+ export declare function ProduckChat(props: ProduckChatProps): JSX.Element;
132
+ export declare function ProduckTarget(props: ProduckTargetProps): JSX.Element;
133
+ export declare function VisualFlowDisplay(props: VisualFlowDisplayProps): JSX.Element;
134
+
135
+ // Context
136
+ export declare const ProduckContext: React.Context<ProduckContextValue | null>;
137
+
138
+ // Hooks
139
+ export declare function useProduck(): ProduckContextValue;
140
+ export declare function useProduckAction(
141
+ actionKey: string,
142
+ handler: (payload: ActionPayload) => void,
143
+ deps?: any[]
144
+ ): void;
145
+ export declare function useProduckReady(): boolean;
146
+ export declare function useProduckMessages(): {
147
+ messages: ChatMessage[];
148
+ isLoading: boolean;
149
+ sendMessage: (message: string) => Promise<void>;
150
+ };
151
+ export declare function useProduckFlow(): {
152
+ activeFlow: FlowPayload | null;
153
+ flowResult: FlowResult | null;
154
+ isExecutingFlow: boolean;
155
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prodact.ai/sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Interactive SDK for Prodact.ai - AI-powered UI interactions",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -26,7 +26,8 @@
26
26
  "README.md"
27
27
  ],
28
28
  "scripts": {
29
- "build": "tsup",
29
+ "build": "tsup && npm run postbuild",
30
+ "postbuild": "cp types/index.d.ts dist/index.d.ts && cp types/react.d.ts dist/react.d.ts",
30
31
  "build:cdn": "tsup --config tsup.cdn.config.ts",
31
32
  "build:wordpress": "tsup --config tsup.wordpress.config.ts",
32
33
  "build:all": "npm run build && npm run build:cdn",