@vezlo/assistant-chat 1.9.1 → 1.10.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/README.md CHANGED
@@ -102,6 +102,7 @@ npm run dev
102
102
  - ✅ **Human agent support** (conversation management, agent handoff)
103
103
  - ✅ **Realtime updates** (live message synchronization)
104
104
  - ✅ **Database tools** (connect external databases for natural language queries - [docs](./docs/DATABASE_TOOLS.md))
105
+ - ✅ **AI Settings** (customize AI behavior, model, temperature, and prompts per company)
105
106
  - ✅ Docker support
106
107
  - ✅ Vercel deployment
107
108
 
@@ -0,0 +1,35 @@
1
+ import type { ReactNode } from 'react';
2
+ interface User {
3
+ name: string;
4
+ email: string;
5
+ avatar?: string;
6
+ id?: string;
7
+ role?: string;
8
+ profile?: {
9
+ company_uuid: string;
10
+ company_name: string;
11
+ role: string;
12
+ };
13
+ }
14
+ interface Workspace {
15
+ name: string;
16
+ plan: string;
17
+ avatar?: string;
18
+ }
19
+ interface AppContextType {
20
+ user: User | null;
21
+ workspace: Workspace | null;
22
+ activeSection: string;
23
+ isAuthenticated: boolean;
24
+ token: string | null;
25
+ setActiveSection: (section: string) => void;
26
+ setUser: (user: User | null) => void;
27
+ setWorkspace: (workspace: Workspace | null) => void;
28
+ login: (token: string, user: User) => void;
29
+ logout: () => Promise<void>;
30
+ }
31
+ export declare function AppProvider({ children }: {
32
+ children: ReactNode;
33
+ }): import("react/jsx-runtime").JSX.Element;
34
+ export declare function useApp(): AppContextType;
35
+ export {};
@@ -0,0 +1,93 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState, useEffect } from 'react';
3
+ import { logoutUser } from '@/api';
4
+ import { initializeRealtime } from '@/services/realtime';
5
+ const AppContext = createContext(undefined);
6
+ const TOKEN_KEY = 'vezlo_auth_token';
7
+ const USER_KEY = 'vezlo_user';
8
+ const WORKSPACE_KEY = 'vezlo_workspace';
9
+ export function AppProvider({ children }) {
10
+ // Initialize from localStorage
11
+ const [token, setToken] = useState(() => {
12
+ return localStorage.getItem(TOKEN_KEY);
13
+ });
14
+ const [user, setUser] = useState(() => {
15
+ const storedUser = localStorage.getItem(USER_KEY);
16
+ return storedUser ? JSON.parse(storedUser) : null;
17
+ });
18
+ const [workspace, setWorkspace] = useState(() => {
19
+ const storedWorkspace = localStorage.getItem(WORKSPACE_KEY);
20
+ return storedWorkspace ? JSON.parse(storedWorkspace) : null;
21
+ });
22
+ const [activeSection, setActiveSection] = useState('widget');
23
+ const isAuthenticated = !!token && !!user;
24
+ // Sync token to localStorage
25
+ useEffect(() => {
26
+ if (token) {
27
+ localStorage.setItem(TOKEN_KEY, token);
28
+ }
29
+ else {
30
+ localStorage.removeItem(TOKEN_KEY);
31
+ }
32
+ }, [token]);
33
+ // Sync user to localStorage
34
+ useEffect(() => {
35
+ if (user) {
36
+ localStorage.setItem(USER_KEY, JSON.stringify(user));
37
+ }
38
+ else {
39
+ localStorage.removeItem(USER_KEY);
40
+ }
41
+ }, [user]);
42
+ useEffect(() => {
43
+ if (workspace) {
44
+ localStorage.setItem(WORKSPACE_KEY, JSON.stringify(workspace));
45
+ }
46
+ else {
47
+ localStorage.removeItem(WORKSPACE_KEY);
48
+ }
49
+ }, [workspace]);
50
+ const login = (newToken, newUser) => {
51
+ setToken(newToken);
52
+ setUser(newUser);
53
+ };
54
+ const logout = async () => {
55
+ if (token) {
56
+ try {
57
+ await logoutUser(token);
58
+ }
59
+ catch (error) {
60
+ console.error('[AppContext] Failed to logout via API:', error);
61
+ }
62
+ }
63
+ setToken(null);
64
+ setUser(null);
65
+ setWorkspace(null);
66
+ localStorage.removeItem(TOKEN_KEY);
67
+ localStorage.removeItem(USER_KEY);
68
+ localStorage.removeItem(WORKSPACE_KEY);
69
+ };
70
+ // Initialize Realtime connection on app load
71
+ useEffect(() => {
72
+ initializeRealtime();
73
+ }, []);
74
+ return (_jsx(AppContext.Provider, { value: {
75
+ user,
76
+ workspace,
77
+ activeSection,
78
+ isAuthenticated,
79
+ token,
80
+ setActiveSection,
81
+ setUser,
82
+ setWorkspace,
83
+ login,
84
+ logout,
85
+ }, children: children }));
86
+ }
87
+ export function useApp() {
88
+ const context = useContext(AppContext);
89
+ if (context === undefined) {
90
+ throw new Error('useApp must be used within an AppProvider');
91
+ }
92
+ return context;
93
+ }
@@ -0,0 +1,13 @@
1
+ type AuthBroadcastPayload = {
2
+ uuid: string;
3
+ name: string;
4
+ email: string;
5
+ role: string;
6
+ };
7
+ /**
8
+ * Initialize Supabase Realtime client connection
9
+ * Call this on app load to establish the WebSocket connection
10
+ */
11
+ export declare function initializeRealtime(): boolean;
12
+ export declare function listenForAuthBroadcast(onPayload: (payload: AuthBroadcastPayload) => void): () => void;
13
+ export {};
@@ -0,0 +1,79 @@
1
+ import { createClient } from '@supabase/supabase-js';
2
+ const SUPABASE_URL = import.meta.env.VITE_SUPABASE_URL;
3
+ const SUPABASE_ANON_KEY = import.meta.env.VITE_SUPABASE_ANON_KEY;
4
+ let client = null;
5
+ function getClient() {
6
+ if (!SUPABASE_URL || !SUPABASE_ANON_KEY) {
7
+ console.error('[Realtime] Missing VITE_SUPABASE_URL or VITE_SUPABASE_ANON_KEY environment variables');
8
+ return null;
9
+ }
10
+ if (!client) {
11
+ try {
12
+ client = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
13
+ realtime: { params: { eventsPerSecond: 2 } },
14
+ });
15
+ }
16
+ catch (error) {
17
+ console.error('[Realtime] Failed to initialize client:', error instanceof Error ? error.message : 'Unknown error');
18
+ return null;
19
+ }
20
+ }
21
+ return client;
22
+ }
23
+ /**
24
+ * Initialize Supabase Realtime client connection
25
+ * Call this on app load to establish the WebSocket connection
26
+ */
27
+ export function initializeRealtime() {
28
+ try {
29
+ const realtimeClient = getClient();
30
+ if (realtimeClient) {
31
+ console.info('[Realtime] Initialized and connected');
32
+ return true;
33
+ }
34
+ return false;
35
+ }
36
+ catch (error) {
37
+ console.error('[Realtime] Initialization failed:', error instanceof Error ? error.message : 'Unknown error');
38
+ return false;
39
+ }
40
+ }
41
+ export function listenForAuthBroadcast(onPayload) {
42
+ try {
43
+ const realtimeClient = getClient();
44
+ if (!realtimeClient) {
45
+ return () => { };
46
+ }
47
+ const channel = realtimeClient.channel('vezlo_authenticated', {
48
+ config: {
49
+ broadcast: { self: true, ack: false }
50
+ }
51
+ });
52
+ channel.on('broadcast', { event: 'me_payload' }, ({ payload }) => {
53
+ onPayload(payload);
54
+ });
55
+ channel.subscribe((status, err) => {
56
+ if (err) {
57
+ console.error('[Realtime] Subscription failed:', err.message || err);
58
+ }
59
+ else if (status === 'SUBSCRIBED') {
60
+ console.info('[Realtime] Subscribed to channel: vezlo_authenticated');
61
+ }
62
+ else if (status === 'CLOSED' || status === 'CHANNEL_ERROR') {
63
+ console.error('[Realtime] Channel connection failed:', status);
64
+ }
65
+ });
66
+ return () => {
67
+ try {
68
+ channel.unsubscribe();
69
+ }
70
+ catch (error) {
71
+ console.error('[Realtime] Unsubscribe error:', error instanceof Error ? error.message : 'Unknown error');
72
+ }
73
+ };
74
+ }
75
+ catch (error) {
76
+ console.error('[Realtime] Failed to setup broadcast listener:', error instanceof Error ? error.message : 'Unknown error');
77
+ return () => { };
78
+ }
79
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Hook to check if the current user is an admin
3
+ * @returns true if user role is 'admin', false otherwise
4
+ */
5
+ export declare function useIsAdmin(): boolean;
@@ -0,0 +1,9 @@
1
+ import { useApp } from '@/contexts/AppContext';
2
+ /**
3
+ * Hook to check if the current user is an admin
4
+ * @returns true if user role is 'admin', false otherwise
5
+ */
6
+ export function useIsAdmin() {
7
+ const { user } = useApp();
8
+ return user?.profile?.role === 'admin';
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vezlo/assistant-chat",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "React component library for AI-powered chat widgets with RAG knowledge base integration, realtime updates, and human agent support",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -38,6 +38,7 @@
38
38
  "lucide-react": "^0.544.0",
39
39
  "marked": "^17.0.1",
40
40
  "react-hot-toast": "^2.6.0",
41
+ "react-markdown": "^10.1.0",
41
42
  "react-router-dom": "^7.9.3",
42
43
  "tailwindcss": "^4.1.14"
43
44
  },