@prodact.ai/sdk 0.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.
@@ -0,0 +1,244 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import React__default, { ReactNode, CSSProperties } from 'react';
4
+
5
+ interface ProduckConfig {
6
+ guiderId?: string;
7
+ sdkKey?: string;
8
+ apiUrl?: string;
9
+ onAction?: (actionKey: string, action: ActionPayload) => void;
10
+ onMessage?: (message: ChatMessage) => void;
11
+ onError?: (error: Error) => void;
12
+ onFlowStart?: (flow: FlowPayload) => void;
13
+ onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
14
+ onFlowComplete?: (result: FlowResult) => void;
15
+ }
16
+ interface ActionPayload {
17
+ actionKey: string;
18
+ name: string;
19
+ actionType: string;
20
+ actionConfig: Record<string, any>;
21
+ responseMessage?: string;
22
+ }
23
+ interface FlowStep {
24
+ operationId: string;
25
+ order: number;
26
+ condition?: Record<string, any>;
27
+ inputMapping?: Record<string, any>;
28
+ }
29
+ interface FlowPayload {
30
+ flowId: string;
31
+ name: string;
32
+ description: string;
33
+ steps: FlowStep[];
34
+ }
35
+ interface FlowStepResult {
36
+ operationId: string;
37
+ order: number;
38
+ success: boolean;
39
+ data?: any;
40
+ error?: string;
41
+ }
42
+ interface FlowResult {
43
+ flowId: string;
44
+ name: string;
45
+ steps: FlowStepResult[];
46
+ completed: boolean;
47
+ totalSteps: number;
48
+ successfulSteps: number;
49
+ }
50
+ interface ChatMessage {
51
+ role: 'user' | 'assistant';
52
+ content: string;
53
+ action?: ActionPayload;
54
+ flow?: FlowPayload;
55
+ flowResult?: FlowResult;
56
+ }
57
+ interface ActionHandler {
58
+ (payload: ActionPayload): void | Promise<void>;
59
+ }
60
+ type ProduckEventType = 'action' | 'message' | 'error' | 'ready' | 'flowStart' | 'flowStepComplete' | 'flowComplete';
61
+ declare class ProduckSDK {
62
+ private config;
63
+ private actions;
64
+ private eventListeners;
65
+ private sessionToken;
66
+ private isReady;
67
+ constructor(config: ProduckConfig);
68
+ /**
69
+ * Initialize the SDK and create a chat session
70
+ */
71
+ init(): Promise<void>;
72
+ /**
73
+ * Register an action handler
74
+ */
75
+ register(actionKey: string, handler: ActionHandler): void;
76
+ /**
77
+ * Unregister an action handler
78
+ */
79
+ unregister(actionKey: string): void;
80
+ /**
81
+ * Send a message and handle potential action or flow triggers
82
+ */
83
+ sendMessage(message: string): Promise<ChatMessage>;
84
+ /**
85
+ * Execute a flow by running each step's operation sequentially
86
+ */
87
+ executeFlow(flow: FlowPayload): Promise<FlowResult>;
88
+ /**
89
+ * Send log data to backend for analytics
90
+ */
91
+ private sendLogToBackend;
92
+ /**
93
+ * Send detailed log to backend
94
+ */
95
+ private log;
96
+ /**
97
+ * Execute a registered action
98
+ */
99
+ private executeAction;
100
+ /**
101
+ * Add event listener
102
+ */
103
+ on(event: ProduckEventType, callback: Function): void;
104
+ /**
105
+ * Remove event listener
106
+ */
107
+ off(event: ProduckEventType, callback: Function): void;
108
+ /**
109
+ * Emit event
110
+ */
111
+ private emit;
112
+ /**
113
+ * Get session token
114
+ */
115
+ getSessionToken(): string | null;
116
+ /**
117
+ * Check if SDK is ready
118
+ */
119
+ getIsReady(): boolean;
120
+ /**
121
+ * Get registered action keys
122
+ */
123
+ getRegisteredActions(): string[];
124
+ /**
125
+ * Destroy the SDK instance
126
+ */
127
+ destroy(): void;
128
+ }
129
+
130
+ interface ProduckProviderProps {
131
+ config: Omit<ProduckConfig, 'onAction' | 'onMessage' | 'onError' | 'onFlowStart' | 'onFlowStepComplete' | 'onFlowComplete'>;
132
+ children: ReactNode;
133
+ onAction?: (actionKey: string, payload: ActionPayload) => void;
134
+ onError?: (error: Error) => void;
135
+ onFlowStart?: (flow: FlowPayload) => void;
136
+ onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
137
+ onFlowComplete?: (result: FlowResult) => void;
138
+ }
139
+ declare function ProduckProvider({ config, children, onAction, onError, onFlowStart, onFlowStepComplete, onFlowComplete, }: ProduckProviderProps): react_jsx_runtime.JSX.Element;
140
+
141
+ interface ProduckChatAppearance {
142
+ width?: string | number;
143
+ height?: string | number;
144
+ borderRadius?: string | number;
145
+ backgroundColor?: string;
146
+ headerBackgroundColor?: string;
147
+ headerTextColor?: string;
148
+ inputBackgroundColor?: string;
149
+ inputTextColor?: string;
150
+ inputBorderColor?: string;
151
+ userMessageBackgroundColor?: string;
152
+ userMessageTextColor?: string;
153
+ assistantMessageBackgroundColor?: string;
154
+ assistantMessageTextColor?: string;
155
+ buttonBackgroundColor?: string;
156
+ buttonTextColor?: string;
157
+ buttonBorderRadius?: string | number;
158
+ floatingButtonSize?: string | number;
159
+ fontFamily?: string;
160
+ fontSize?: string | number;
161
+ headerFontSize?: string | number;
162
+ border?: string;
163
+ boxShadow?: string;
164
+ floatingButtonIcon?: React__default.ReactNode;
165
+ floatingButtonLoadingIcon?: React__default.ReactNode;
166
+ showCloseButton?: boolean;
167
+ headerIcon?: React__default.ReactNode;
168
+ sendButtonText?: string;
169
+ sendButtonIcon?: React__default.ReactNode;
170
+ emptyStateIcon?: React__default.ReactNode;
171
+ emptyStateTitle?: string;
172
+ emptyStateSubtitle?: string;
173
+ }
174
+ interface ProduckChatProps {
175
+ placeholder?: string;
176
+ title?: string;
177
+ position?: 'bottom-right' | 'bottom-left' | 'inline';
178
+ theme?: 'light' | 'dark';
179
+ primaryColor?: string;
180
+ className?: string;
181
+ style?: CSSProperties;
182
+ defaultOpen?: boolean;
183
+ appearance?: ProduckChatAppearance;
184
+ }
185
+ declare function ProduckChat({ placeholder, title, position, theme, primaryColor, className, style, defaultOpen, appearance, }: ProduckChatProps): react_jsx_runtime.JSX.Element;
186
+
187
+ interface ProduckTargetProps {
188
+ actionKey: string;
189
+ children: ReactNode;
190
+ onTrigger?: (payload: ActionPayload) => void;
191
+ highlightStyle?: React__default.CSSProperties;
192
+ highlightDuration?: number;
193
+ scrollIntoView?: boolean;
194
+ }
195
+ /**
196
+ * Wrapper component that registers an action and can highlight/scroll to the target
197
+ */
198
+ declare function ProduckTarget({ actionKey, children, onTrigger, highlightStyle, highlightDuration, scrollIntoView, }: ProduckTargetProps): react_jsx_runtime.JSX.Element;
199
+
200
+ interface ProduckContextValue {
201
+ sdk: ProduckSDK | null;
202
+ isReady: boolean;
203
+ sessionToken: string | null;
204
+ messages: ChatMessage[];
205
+ isLoading: boolean;
206
+ sendMessage: (message: string) => Promise<void>;
207
+ register: (actionKey: string, handler: (payload: ActionPayload) => void) => void;
208
+ unregister: (actionKey: string) => void;
209
+ activeFlow: FlowPayload | null;
210
+ flowResult: FlowResult | null;
211
+ isExecutingFlow: boolean;
212
+ }
213
+ declare const ProduckContext: React.Context<ProduckContextValue | null>;
214
+
215
+ /**
216
+ * Hook to access Produck SDK functionality
217
+ */
218
+ declare function useProduck(): ProduckContextValue;
219
+ /**
220
+ * Hook to register an action handler
221
+ */
222
+ declare function useProduckAction(actionKey: string, handler: (payload: ActionPayload) => void, deps?: any[]): void;
223
+ /**
224
+ * Hook to check if SDK is ready
225
+ */
226
+ declare function useProduckReady(): boolean;
227
+ /**
228
+ * Hook to get chat messages
229
+ */
230
+ declare function useProduckMessages(): {
231
+ messages: ChatMessage[];
232
+ isLoading: boolean;
233
+ sendMessage: (message: string) => Promise<void>;
234
+ };
235
+ /**
236
+ * Hook to get flow execution status
237
+ */
238
+ declare function useProduckFlow(): {
239
+ activeFlow: FlowPayload | null;
240
+ flowResult: FlowResult | null;
241
+ isExecutingFlow: boolean;
242
+ };
243
+
244
+ export { type ActionHandler, type ActionPayload, type ChatMessage, type FlowPayload, type FlowResult, type FlowStep, type FlowStepResult, ProduckChat, type ProduckChatAppearance, type ProduckChatProps, type ProduckConfig, ProduckContext, type ProduckContextValue, ProduckProvider, type ProduckProviderProps, ProduckTarget, type ProduckTargetProps, useProduck, useProduckAction, useProduckFlow, useProduckMessages, useProduckReady };
@@ -0,0 +1,244 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import React__default, { ReactNode, CSSProperties } from 'react';
4
+
5
+ interface ProduckConfig {
6
+ guiderId?: string;
7
+ sdkKey?: string;
8
+ apiUrl?: string;
9
+ onAction?: (actionKey: string, action: ActionPayload) => void;
10
+ onMessage?: (message: ChatMessage) => void;
11
+ onError?: (error: Error) => void;
12
+ onFlowStart?: (flow: FlowPayload) => void;
13
+ onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
14
+ onFlowComplete?: (result: FlowResult) => void;
15
+ }
16
+ interface ActionPayload {
17
+ actionKey: string;
18
+ name: string;
19
+ actionType: string;
20
+ actionConfig: Record<string, any>;
21
+ responseMessage?: string;
22
+ }
23
+ interface FlowStep {
24
+ operationId: string;
25
+ order: number;
26
+ condition?: Record<string, any>;
27
+ inputMapping?: Record<string, any>;
28
+ }
29
+ interface FlowPayload {
30
+ flowId: string;
31
+ name: string;
32
+ description: string;
33
+ steps: FlowStep[];
34
+ }
35
+ interface FlowStepResult {
36
+ operationId: string;
37
+ order: number;
38
+ success: boolean;
39
+ data?: any;
40
+ error?: string;
41
+ }
42
+ interface FlowResult {
43
+ flowId: string;
44
+ name: string;
45
+ steps: FlowStepResult[];
46
+ completed: boolean;
47
+ totalSteps: number;
48
+ successfulSteps: number;
49
+ }
50
+ interface ChatMessage {
51
+ role: 'user' | 'assistant';
52
+ content: string;
53
+ action?: ActionPayload;
54
+ flow?: FlowPayload;
55
+ flowResult?: FlowResult;
56
+ }
57
+ interface ActionHandler {
58
+ (payload: ActionPayload): void | Promise<void>;
59
+ }
60
+ type ProduckEventType = 'action' | 'message' | 'error' | 'ready' | 'flowStart' | 'flowStepComplete' | 'flowComplete';
61
+ declare class ProduckSDK {
62
+ private config;
63
+ private actions;
64
+ private eventListeners;
65
+ private sessionToken;
66
+ private isReady;
67
+ constructor(config: ProduckConfig);
68
+ /**
69
+ * Initialize the SDK and create a chat session
70
+ */
71
+ init(): Promise<void>;
72
+ /**
73
+ * Register an action handler
74
+ */
75
+ register(actionKey: string, handler: ActionHandler): void;
76
+ /**
77
+ * Unregister an action handler
78
+ */
79
+ unregister(actionKey: string): void;
80
+ /**
81
+ * Send a message and handle potential action or flow triggers
82
+ */
83
+ sendMessage(message: string): Promise<ChatMessage>;
84
+ /**
85
+ * Execute a flow by running each step's operation sequentially
86
+ */
87
+ executeFlow(flow: FlowPayload): Promise<FlowResult>;
88
+ /**
89
+ * Send log data to backend for analytics
90
+ */
91
+ private sendLogToBackend;
92
+ /**
93
+ * Send detailed log to backend
94
+ */
95
+ private log;
96
+ /**
97
+ * Execute a registered action
98
+ */
99
+ private executeAction;
100
+ /**
101
+ * Add event listener
102
+ */
103
+ on(event: ProduckEventType, callback: Function): void;
104
+ /**
105
+ * Remove event listener
106
+ */
107
+ off(event: ProduckEventType, callback: Function): void;
108
+ /**
109
+ * Emit event
110
+ */
111
+ private emit;
112
+ /**
113
+ * Get session token
114
+ */
115
+ getSessionToken(): string | null;
116
+ /**
117
+ * Check if SDK is ready
118
+ */
119
+ getIsReady(): boolean;
120
+ /**
121
+ * Get registered action keys
122
+ */
123
+ getRegisteredActions(): string[];
124
+ /**
125
+ * Destroy the SDK instance
126
+ */
127
+ destroy(): void;
128
+ }
129
+
130
+ interface ProduckProviderProps {
131
+ config: Omit<ProduckConfig, 'onAction' | 'onMessage' | 'onError' | 'onFlowStart' | 'onFlowStepComplete' | 'onFlowComplete'>;
132
+ children: ReactNode;
133
+ onAction?: (actionKey: string, payload: ActionPayload) => void;
134
+ onError?: (error: Error) => void;
135
+ onFlowStart?: (flow: FlowPayload) => void;
136
+ onFlowStepComplete?: (step: FlowStepResult, flow: FlowPayload) => void;
137
+ onFlowComplete?: (result: FlowResult) => void;
138
+ }
139
+ declare function ProduckProvider({ config, children, onAction, onError, onFlowStart, onFlowStepComplete, onFlowComplete, }: ProduckProviderProps): react_jsx_runtime.JSX.Element;
140
+
141
+ interface ProduckChatAppearance {
142
+ width?: string | number;
143
+ height?: string | number;
144
+ borderRadius?: string | number;
145
+ backgroundColor?: string;
146
+ headerBackgroundColor?: string;
147
+ headerTextColor?: string;
148
+ inputBackgroundColor?: string;
149
+ inputTextColor?: string;
150
+ inputBorderColor?: string;
151
+ userMessageBackgroundColor?: string;
152
+ userMessageTextColor?: string;
153
+ assistantMessageBackgroundColor?: string;
154
+ assistantMessageTextColor?: string;
155
+ buttonBackgroundColor?: string;
156
+ buttonTextColor?: string;
157
+ buttonBorderRadius?: string | number;
158
+ floatingButtonSize?: string | number;
159
+ fontFamily?: string;
160
+ fontSize?: string | number;
161
+ headerFontSize?: string | number;
162
+ border?: string;
163
+ boxShadow?: string;
164
+ floatingButtonIcon?: React__default.ReactNode;
165
+ floatingButtonLoadingIcon?: React__default.ReactNode;
166
+ showCloseButton?: boolean;
167
+ headerIcon?: React__default.ReactNode;
168
+ sendButtonText?: string;
169
+ sendButtonIcon?: React__default.ReactNode;
170
+ emptyStateIcon?: React__default.ReactNode;
171
+ emptyStateTitle?: string;
172
+ emptyStateSubtitle?: string;
173
+ }
174
+ interface ProduckChatProps {
175
+ placeholder?: string;
176
+ title?: string;
177
+ position?: 'bottom-right' | 'bottom-left' | 'inline';
178
+ theme?: 'light' | 'dark';
179
+ primaryColor?: string;
180
+ className?: string;
181
+ style?: CSSProperties;
182
+ defaultOpen?: boolean;
183
+ appearance?: ProduckChatAppearance;
184
+ }
185
+ declare function ProduckChat({ placeholder, title, position, theme, primaryColor, className, style, defaultOpen, appearance, }: ProduckChatProps): react_jsx_runtime.JSX.Element;
186
+
187
+ interface ProduckTargetProps {
188
+ actionKey: string;
189
+ children: ReactNode;
190
+ onTrigger?: (payload: ActionPayload) => void;
191
+ highlightStyle?: React__default.CSSProperties;
192
+ highlightDuration?: number;
193
+ scrollIntoView?: boolean;
194
+ }
195
+ /**
196
+ * Wrapper component that registers an action and can highlight/scroll to the target
197
+ */
198
+ declare function ProduckTarget({ actionKey, children, onTrigger, highlightStyle, highlightDuration, scrollIntoView, }: ProduckTargetProps): react_jsx_runtime.JSX.Element;
199
+
200
+ interface ProduckContextValue {
201
+ sdk: ProduckSDK | null;
202
+ isReady: boolean;
203
+ sessionToken: string | null;
204
+ messages: ChatMessage[];
205
+ isLoading: boolean;
206
+ sendMessage: (message: string) => Promise<void>;
207
+ register: (actionKey: string, handler: (payload: ActionPayload) => void) => void;
208
+ unregister: (actionKey: string) => void;
209
+ activeFlow: FlowPayload | null;
210
+ flowResult: FlowResult | null;
211
+ isExecutingFlow: boolean;
212
+ }
213
+ declare const ProduckContext: React.Context<ProduckContextValue | null>;
214
+
215
+ /**
216
+ * Hook to access Produck SDK functionality
217
+ */
218
+ declare function useProduck(): ProduckContextValue;
219
+ /**
220
+ * Hook to register an action handler
221
+ */
222
+ declare function useProduckAction(actionKey: string, handler: (payload: ActionPayload) => void, deps?: any[]): void;
223
+ /**
224
+ * Hook to check if SDK is ready
225
+ */
226
+ declare function useProduckReady(): boolean;
227
+ /**
228
+ * Hook to get chat messages
229
+ */
230
+ declare function useProduckMessages(): {
231
+ messages: ChatMessage[];
232
+ isLoading: boolean;
233
+ sendMessage: (message: string) => Promise<void>;
234
+ };
235
+ /**
236
+ * Hook to get flow execution status
237
+ */
238
+ declare function useProduckFlow(): {
239
+ activeFlow: FlowPayload | null;
240
+ flowResult: FlowResult | null;
241
+ isExecutingFlow: boolean;
242
+ };
243
+
244
+ export { type ActionHandler, type ActionPayload, type ChatMessage, type FlowPayload, type FlowResult, type FlowStep, type FlowStepResult, ProduckChat, type ProduckChatAppearance, type ProduckChatProps, type ProduckConfig, ProduckContext, type ProduckContextValue, ProduckProvider, type ProduckProviderProps, ProduckTarget, type ProduckTargetProps, useProduck, useProduckAction, useProduckFlow, useProduckMessages, useProduckReady };