@snf/qa-bot-core 0.1.0 → 0.2.1

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.
@@ -3,6 +3,8 @@ import type { BotControllerHandle } from '../config';
3
3
  interface BotControllerProps {
4
4
  embedded: boolean;
5
5
  currentOpen?: boolean;
6
+ enabled: boolean;
7
+ onSetEnabled?: (enabled: boolean) => void;
6
8
  }
7
9
  /**
8
10
  * BotController Component
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ /**
3
+ * LoginButton Component
4
+ *
5
+ * A standalone component for the login button that can be styled independently
6
+ *
7
+ * @param props - Component props
8
+ * @param props.loginUrl - URL to navigate to for login
9
+ * @param props.className - Optional CSS class for styling
10
+ * @param props.style - Optional inline styles
11
+ * @param props.isHeaderButton - Whether this is rendered in the header (different styling)
12
+ * @returns Rendered login button
13
+ */
14
+ interface LoginButtonProps {
15
+ loginUrl: string;
16
+ className?: string;
17
+ style?: React.CSSProperties;
18
+ isHeaderButton?: boolean;
19
+ }
20
+ declare const LoginButton: React.FC<LoginButtonProps>;
21
+ export default LoginButton;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ /**
3
+ * UserIcon Component
4
+ *
5
+ * A standalone component for the user icon that can be styled independently.
6
+ * Visibility controlled by CSS classes on the container.
7
+ *
8
+ * @returns Rendered user icon
9
+ */
10
+ declare const UserIcon: React.FC;
11
+ export default UserIcon;
@@ -14,6 +14,10 @@ export interface QABotProps {
14
14
  footerText?: string;
15
15
  footerLink?: string;
16
16
  tooltipText?: string;
17
+ enabled?: boolean;
18
+ loginUrl?: string;
19
+ open?: boolean;
20
+ onOpenChange?: (open: boolean) => void;
17
21
  }
18
22
  /**
19
23
  * Default values for overridable props
@@ -28,6 +32,8 @@ export declare const defaultValues: {
28
32
  errorMessage: string;
29
33
  embedded: boolean;
30
34
  tooltipText: string;
35
+ enabled: boolean;
36
+ loginUrl: string;
31
37
  };
32
38
  /**
33
39
  * Fixed react-chatbotify settings
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface SessionContextType {
3
+ resetSession: () => void;
4
+ clearResettingFlag: () => void;
5
+ }
6
+ export declare const SessionProvider: React.FC<{
7
+ children: React.ReactNode;
8
+ resetSession: () => void;
9
+ clearResettingFlag: () => void;
10
+ }>;
11
+ export declare const useSession: () => SessionContextType;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Custom hook to update the chatbot header based on login state
3
+ * Adds/removes the 'bot-logged-in' CSS class to control visibility of login button vs user icon
4
+ *
5
+ * @param isLoggedIn - Whether the user is logged in
6
+ * @param containerRef - Reference to the chatbot container element
7
+ */
8
+ declare const useUpdateHeader: (isLoggedIn: boolean, containerRef: React.RefObject<HTMLDivElement>) => void;
9
+ export default useUpdateHeader;
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  /**
2
3
  * Creates the basic Q&A conversation flow
3
4
  * Handles questions, responses, and optional ratings
@@ -6,20 +7,36 @@
6
7
  * @param {string} params.endpoint Q&A API endpoint (required)
7
8
  * @param {string} params.ratingEndpoint Rating API endpoint (optional)
8
9
  * @param {string} params.apiKey API key for authentication (optional)
9
- * @param {string} params.sessionId Session ID for tracking
10
+ * @param {Function} params.sessionId Function that returns current session ID
11
+ * @param {Function} params.isResetting Function that returns whether we're currently resetting
12
+ * @param {boolean} params.enabled Whether the user is logged in/enabled (optional)
13
+ * @param {string} params.loginUrl Login URL to redirect to (optional)
10
14
  * @returns {Object} Q&A flow configuration
11
15
  */
12
- export declare const createQAFlow: ({ endpoint, ratingEndpoint, apiKey, sessionId }: {
16
+ export declare const createQAFlow: ({ endpoint, ratingEndpoint, apiKey, sessionId: getSessionId, isResetting, enabled, loginUrl }: {
13
17
  endpoint: any;
14
18
  ratingEndpoint: any;
15
19
  apiKey: any;
16
20
  sessionId: any;
21
+ isResetting?: () => boolean;
22
+ enabled?: boolean;
23
+ loginUrl?: string;
17
24
  }) => {
25
+ qa_loop: {
26
+ message: string;
27
+ component: React.JSX.Element;
28
+ chatDisabled: boolean;
29
+ path: string;
30
+ options?: undefined;
31
+ renderMarkdown?: undefined;
32
+ };
33
+ } | {
18
34
  qa_loop: {
19
35
  message: (chatState: any) => Promise<"Thanks for the feedback! Feel free to ask another question." | "I apologize, but I'm having trouble processing your question. Please try again later.">;
20
36
  options: (chatState: any) => string[];
21
37
  renderMarkdown: string[];
22
38
  chatDisabled: boolean;
23
39
  path: string;
40
+ component?: undefined;
24
41
  };
25
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snf/qa-bot-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "A configurable chatbot setup for quick integration of RAG-powered Q&A and rating system",
5
5
  "main": "./dist/qa-bot-core.umd.cjs",
6
6
  "module": "./dist/qa-bot-core.js",
@@ -1,66 +0,0 @@
1
- /**
2
- * QA Bot Core - Runtime Constants and Usage Examples
3
- *
4
- * This file contains runtime constants and documentation that was previously
5
- * in the large api-reference.js file. TypeScript interfaces are now in types.ts.
6
- */
7
- import { CONSTANTS } from './types';
8
- export { CONSTANTS };
9
- /**
10
- * ===========================================
11
- * USAGE EXAMPLES & PATTERNS
12
- * ===========================================
13
- */
14
- export declare const USAGE_EXAMPLES: {
15
- readonly SIMPLE: {
16
- readonly name: "Level 1: Simple Usage";
17
- readonly description: "Just business logic props - everything else uses sensible defaults";
18
- readonly code: "\n<QABot\n apiKey=\"your-key\"\n endpoints={{ qa: 'https://your-api.com/chat' }}\n/>";
19
- readonly requiredProps: readonly ["apiKey", "endpoints"];
20
- readonly optionalProps: readonly ["userEmail", "welcomeMessage"];
21
- };
22
- readonly COMPLEX: {
23
- readonly name: "Level 2: Complex Usage";
24
- readonly description: "Business logic props + full react-chatbotify settings control";
25
- readonly code: "\n<QABot\n apiKey=\"your-key\"\n endpoints={{ qa: 'https://your-api.com/chat' }}\n welcomeMessage=\"Custom welcome!\"\n settings={{\n general: { primaryColor: '#brand-color' },\n header: { title: 'Support Bot' }\n }}\n/>";
26
- readonly props: readonly ["...businessProps", "settings", "plugins", "...reactChatbotifyProps"];
27
- };
28
- readonly WRAPPER: {
29
- readonly name: "Level 3: Wrapper Pattern";
30
- readonly description: "Create organizational bots with pre-configured defaults";
31
- readonly code: "\nfunction MyOrgBot({ settings = {}, ...props }: WrapperProps) {\n return (\n <QABot\n endpoints={{ qa: 'https://org.com/api' }}\n settings={{\n general: { primaryColor: '#org-blue' },\n ...settings\n }}\n {...props}\n />\n );\n}";
32
- };
33
- };
34
- /**
35
- * ===========================================
36
- * CUSTOM FLOWS EXAMPLES
37
- * ===========================================
38
- */
39
- export declare const FLOW_EXAMPLES: {
40
- readonly description: "Examples of custom conversation flows";
41
- readonly simple: "\nconst customFlows = {\n start: {\n message: \"How can I help you?\",\n options: [\"Ask Question\", \"Create Ticket\"],\n paths: [\"qa_loop\", \"ticket_flow\"]\n },\n\n ticket_flow: {\n message: \"Please describe your issue:\",\n function: async (params) => {\n const ticket = await createTicket(params.userInput);\n return `Ticket #${ticket.id} created!`;\n }\n }\n};";
42
- readonly advanced: "\nconst advancedFlows = {\n start: {\n message: \"Welcome! What would you like to do?\",\n options: [\"General Q&A\", \"Create Support Ticket\", \"Report Security Issue\"],\n paths: [\"qa_loop\", \"ticket_flow\", \"security_flow\"]\n },\n\n security_flow: {\n message: \"Security reports are taken seriously. Please describe the issue:\",\n function: async (params) => {\n await createSecurityReport({\n description: params.userInput,\n userEmail: params.userEmail,\n timestamp: new Date(),\n sessionId: params.sessionId\n });\n return \"Thank you for the security report. Our team has been notified.\";\n }\n }\n};";
43
- };
44
- /**
45
- * ===========================================
46
- * MIGRATION GUIDE
47
- * ===========================================
48
- */
49
- export declare const MIGRATION_FROM_CONFIG_SYSTEM: {
50
- readonly description: "How to migrate from the old config-based system to the new prop-based system";
51
- readonly mappings: {
52
- readonly 'config.core.auth.apiKey': "apiKey prop";
53
- readonly 'config.core.endpoints.qa': "endpoints.qa prop";
54
- readonly 'config.core.endpoints.rating': "endpoints.rating prop";
55
- readonly 'config.user.email': "userEmail prop";
56
- readonly 'config.user.name': "userName prop";
57
- readonly 'config.user.loginUrl': "loginUrl prop";
58
- readonly 'config.flows.welcomeMessage': "welcomeMessage prop";
59
- readonly 'config.flows.customFlows': "customFlows prop";
60
- readonly 'config.general.*': "settings.general.*";
61
- readonly 'config.header.*': "settings.header.*";
62
- readonly 'config.chatInput.*': "settings.chatInput.*";
63
- };
64
- readonly before: "\n// Old config-based system\n<QABot\n config={{\n core: {\n auth: { apiKey: 'key' },\n endpoints: { qa: '/api' }\n },\n flows: { welcomeMessage: 'Hi!' },\n general: { primaryColor: '#blue' }\n }}\n embedded={true} // Prop override confusion\n/>";
65
- readonly after: "\n// New prop-based system\n<QABot\n apiKey=\"key\"\n endpoints={{ qa: '/api' }}\n welcomeMessage=\"Hi!\"\n settings={{\n general: {\n primaryColor: '#blue',\n embedded: true\n }\n }}\n/>";
66
- };
@@ -1,118 +0,0 @@
1
- /**
2
- * Default react-chatbotify settings for QA Bot Core
3
- *
4
- * These are sensible defaults that provide a good out-of-the-box experience.
5
- * Users can override any of these by passing their own settings object.
6
- */
7
- import React from 'react';
8
- import type { CustomFlows } from './types';
9
- export interface ReactChatbotifySettings {
10
- general?: {
11
- primaryColor?: string;
12
- secondaryColor?: string;
13
- fontFamily?: string;
14
- embedded?: boolean;
15
- showHeader?: boolean;
16
- showFooter?: boolean;
17
- };
18
- device?: {
19
- desktopEnabled?: boolean;
20
- mobileEnabled?: boolean;
21
- applyMobileOptimizations?: boolean;
22
- };
23
- chatHistory?: {
24
- disabled?: boolean;
25
- };
26
- chatButton?: {
27
- icon?: string;
28
- };
29
- audio?: {
30
- disabled?: boolean;
31
- };
32
- emoji?: {
33
- disabled?: boolean;
34
- };
35
- fileAttachment?: {
36
- disabled?: boolean;
37
- };
38
- notification?: {
39
- disabled?: boolean;
40
- };
41
- footer?: {
42
- text?: React.ReactElement;
43
- buttons?: React.ReactElement[];
44
- };
45
- event?: {
46
- rcbToggleChatWindow?: boolean;
47
- };
48
- tooltip?: {
49
- mode?: 'CLOSE' | 'ALWAYS' | 'NEVER';
50
- text?: string;
51
- };
52
- header?: {
53
- title?: string | React.ReactElement;
54
- showAvatar?: boolean;
55
- avatar?: string;
56
- buttons?: any[];
57
- };
58
- chatInput?: {
59
- disabled?: boolean;
60
- enabledPlaceholderText?: string;
61
- disabledPlaceholderText?: string;
62
- characterLimit?: number;
63
- showCharacterCount?: boolean;
64
- allowNewline?: boolean;
65
- sendButtonStyle?: any;
66
- sendButtonAriaLabel?: string;
67
- ariaLabel?: string;
68
- ariaDescribedBy?: string;
69
- };
70
- chatWindow?: {
71
- defaultOpen?: boolean;
72
- showScrollbar?: boolean;
73
- };
74
- botBubble?: {
75
- simulateStream?: boolean;
76
- streamSpeed?: number;
77
- showAvatar?: boolean;
78
- allowNewline?: boolean;
79
- dangerouslySetInnerHTML?: boolean;
80
- renderHtml?: boolean;
81
- ariaLabel?: string;
82
- role?: string;
83
- };
84
- userBubble?: {
85
- showAvatar?: boolean;
86
- };
87
- }
88
- export declare const defaultReactChatbotifySettings: ReactChatbotifySettings;
89
- /**
90
- * Default welcome message for Q&A flows
91
- */
92
- export declare const defaultWelcomeMessage: string;
93
- /**
94
- * Default business configuration structure
95
- * Used internally for flow generation and business logic
96
- */
97
- export interface BusinessConfig {
98
- core: {
99
- endpoints: {
100
- qa?: string;
101
- rating?: string;
102
- };
103
- auth: {
104
- apiKey?: string;
105
- };
106
- };
107
- user: {
108
- email?: string;
109
- name?: string;
110
- loginUrl?: string;
111
- };
112
- flows: {
113
- welcomeMessage: string;
114
- customFlows?: CustomFlows;
115
- };
116
- }
117
- export type { FlowStep, FlowParams } from './types';
118
- export declare const defaultBusinessConfig: BusinessConfig;
@@ -1,11 +0,0 @@
1
- /**
2
- * QA Bot Core - Configuration Exports
3
- *
4
- * Central export point for all configuration, types, and constants.
5
- * This replaces the old complex api-reference.js system.
6
- */
7
- export type { QABotProps, QABotBusinessProps, EndpointsConfig, BrandingConfig, MessagesConfig, ReactChatbotifyFlow, ReactChatbotifyPlugin, ReactChatbotifyStyles, SimpleUsageProps, ThemeColors, BotControllerHandle, TooltipMode, FlowPath } from './types';
8
- export type { ReactChatbotifySettings, BusinessConfig } from './defaults';
9
- export type { CustomFlows, FlowStep, FlowParams } from './types';
10
- export { defaultReactChatbotifySettings, defaultWelcomeMessage, defaultBusinessConfig } from './defaults';
11
- export { CONSTANTS } from './types';
@@ -1,150 +0,0 @@
1
- /**
2
- * QA Bot Core - TypeScript Type Definitions
3
- *
4
- * SINGLE SOURCE OF TRUTH for all TypeScript interfaces and types.
5
- * This replaces the old api-reference.js with proper type definitions.
6
- */
7
- export interface CustomFlows {
8
- [stepName: string]: FlowStep;
9
- }
10
- export interface FlowStep {
11
- message: string;
12
- options?: string[];
13
- path?: string | ((input: string) => string | Promise<string>);
14
- paths?: string[];
15
- function?: (params: FlowParams) => string | Promise<string>;
16
- }
17
- export interface FlowParams {
18
- userInput: string;
19
- sessionId: string;
20
- injectMessage: (message: string) => void;
21
- }
22
- /**
23
- * ===========================================
24
- * SIMPLE CONFIGURATION (For out-of-the-box users)
25
- * ===========================================
26
- */
27
- export interface BrandingConfig {
28
- /** Logo/avatar URL for the chatbot header */
29
- logo?: string;
30
- /** Primary color for buttons, highlights (e.g., "#007bff") */
31
- primaryColor?: string;
32
- /** Secondary color for hover states (e.g., "#0056b3") */
33
- secondaryColor?: string;
34
- /** Primary font family for the chat interface */
35
- primaryFont?: string;
36
- /** Secondary font family for special text (code, etc.) */
37
- secondaryFont?: string;
38
- /** Name displayed in the chat header */
39
- botName?: string;
40
- }
41
- export interface MessagesConfig {
42
- /** Initial greeting message from the bot */
43
- welcome?: string;
44
- /** Placeholder text in the input field */
45
- placeholder?: string;
46
- /** Error message when something goes wrong */
47
- error?: string;
48
- /** Message shown when chat is disabled */
49
- disabled?: string;
50
- }
51
- /**
52
- * ===========================================
53
- * BUSINESS LOGIC PROPS (QA Bot Core Specific)
54
- * ===========================================
55
- */
56
- export interface EndpointsConfig {
57
- /** Q&A endpoint URL (e.g., "https://your-api.com/chat") */
58
- qa: string;
59
- /** Optional rating/feedback endpoint URL */
60
- rating?: string;
61
- }
62
- export interface QABotBusinessProps {
63
- /** API key for authenticating with your Q&A service */
64
- apiKey?: string;
65
- /** API endpoints for Q&A and rating services */
66
- endpoints?: EndpointsConfig;
67
- /** URL to redirect users for login/authentication */
68
- loginUrl?: string;
69
- /** Initial greeting message from the bot */
70
- welcomeMessage?: string;
71
- /** Custom conversation flow definitions */
72
- customFlows?: CustomFlows;
73
- /** Simple branding configuration */
74
- branding?: BrandingConfig;
75
- /** Simple message customization */
76
- messages?: MessagesConfig;
77
- }
78
- /**
79
- * ===========================================
80
- * REACT-CHATBOTIFY INTEGRATION
81
- * ===========================================
82
- */
83
- export interface ReactChatbotifyFlow {
84
- [stepName: string]: any;
85
- }
86
- export type ReactChatbotifyPlugin = (...args: unknown[]) => {
87
- name: string;
88
- settings?: any;
89
- styles?: any;
90
- };
91
- export interface ReactChatbotifyStyles {
92
- [key: string]: any;
93
- }
94
- /**
95
- * ===========================================
96
- * COMPLETE QABOT PROPS
97
- * ===========================================
98
- */
99
- export interface QABotProps extends QABotBusinessProps {
100
- }
101
- /**
102
- * ===========================================
103
- * USAGE TYPES (SIMPLIFIED)
104
- * ===========================================
105
- */
106
- export interface SimpleUsageProps {
107
- apiKey: string;
108
- endpoints: EndpointsConfig;
109
- welcomeMessage?: string;
110
- }
111
- /**
112
- * ===========================================
113
- * INTERNAL TYPES
114
- * ===========================================
115
- */
116
- export interface ThemeColors {
117
- primaryColor?: string;
118
- secondaryColor?: string;
119
- fontFamily?: string;
120
- }
121
- export interface BotControllerHandle {
122
- addMessage: (message: string) => void;
123
- openChat: () => void;
124
- closeChat: () => void;
125
- toggleChat: () => void;
126
- setBotEnabled: (enabled: boolean) => void;
127
- }
128
- /**
129
- * ===========================================
130
- * CONSTANTS & ENUMS
131
- * ===========================================
132
- */
133
- export declare const CONSTANTS: {
134
- readonly DEFAULT_WELCOME_MESSAGE: "Hello! What can I help you with?";
135
- readonly DEFAULT_PRIMARY_COLOR: "#1a5b6e";
136
- readonly DEFAULT_SECONDARY_COLOR: "#107180";
137
- readonly DEFAULT_FONT_FAMILY: "Arial, sans-serif";
138
- readonly DEFAULT_AVATAR: "/default-chat-icon.svg";
139
- readonly DEFAULT_CHARACTER_LIMIT: 1000;
140
- readonly DEFAULT_STREAM_SPEED: 10;
141
- readonly TOOLTIP_MODES: readonly ["CLOSE", "ALWAYS", "NEVER"];
142
- readonly FLOW_PATHS: {
143
- readonly QA_LOOP: "qa_loop";
144
- readonly QA_START: "qa_start";
145
- readonly RATING: "rating";
146
- readonly START: "start";
147
- };
148
- };
149
- export type TooltipMode = typeof CONSTANTS.TOOLTIP_MODES[number];
150
- export type FlowPath = typeof CONSTANTS.FLOW_PATHS[keyof typeof CONSTANTS.FLOW_PATHS];
@@ -1,12 +0,0 @@
1
- import type { BusinessConfig, CustomFlows, ReactChatbotifyFlow } from '../config';
2
- interface CreateBotFlowParams {
3
- config: BusinessConfig;
4
- customFlows?: CustomFlows;
5
- sessionId: string;
6
- }
7
- /**
8
- * Creates the bot conversation flow
9
- * Supports both basic Q&A and custom flows via plugins
10
- */
11
- export declare function createBotFlow({ config, customFlows, sessionId }: CreateBotFlowParams): ReactChatbotifyFlow;
12
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * Deep merge utility for nested configuration objects
3
- * Handles proper merging of nested objects while preserving arrays and other types
4
- */
5
- export declare function deepMerge(target: any, source: any): any;
6
- /**
7
- * Merge multiple objects with deep merging
8
- * Objects are merged left-to-right (later objects have higher priority)
9
- */
10
- export declare function deepMergeAll(...objects: any[]): any;
@@ -1,14 +0,0 @@
1
- import type { Flow } from 'react-chatbotify';
2
- import type { CustomFlows } from '../config';
3
- /**
4
- * Merges custom flows with the base Q&A flow
5
- * Custom flows can:
6
- * - Override existing flow steps
7
- * - Add new flow paths
8
- * - Integrate with Q&A loop via 'qa_loop' path
9
- */
10
- export declare function mergeFlows(baseFlow: Flow, customFlows?: CustomFlows): Flow;
11
- /**
12
- * Creates a flow that integrates custom flows with Q&A
13
- */
14
- export declare function createIntegratedFlow(qaFlow: Flow, customFlows?: CustomFlows, welcomeMessage?: string): Flow;
@@ -1,19 +0,0 @@
1
- /**
2
- * Email validation utility functions
3
- */
4
- /**
5
- * Validates email format using a comprehensive regex pattern
6
- */
7
- export declare const isValidEmail: (email: string) => boolean;
8
- interface ValidationResult {
9
- success: boolean;
10
- promptContent?: string;
11
- promptDuration?: number;
12
- promptType?: string;
13
- highlightTextArea?: boolean;
14
- }
15
- /**
16
- * Creates email validation for chat bot flows
17
- */
18
- export declare const validateEmail: (email: string) => ValidationResult;
19
- export {};