11
2- import { create } from 'zustand' ;
32import { User as AuthUser } from '@supabase/supabase-js' ;
4- import { supabase } from './supabaseClient ' ;
3+ import { create } from 'zustand ' ;
54import {
65 Agent ,
76 AuraAssist ,
8- ProfessorEtiquette ,
7+ BahasaMalaysiaTrainerAgent ,
8+ BengaliTrainerAgent ,
9+ ChallengingCustomerAgent ,
10+ ChineseMalaysianTrainerAgent ,
911 CountessCouture ,
12+ createNewAgent ,
1013 CulinaryCometShane ,
11- Penny ,
12- ChallengingCustomerAgent ,
1314 InquisitiveFoodieAgent ,
1415 MenuKnowledgeAssistantAgent ,
15- BahasaMalaysiaTrainerAgent ,
16- ChineseMalaysianTrainerAgent ,
17- TamilMalaysianTrainerAgent ,
1816 MyanmarTrainerAgent ,
19- BengaliTrainerAgent ,
20- createNewAgent
17+ Penny ,
18+ ProfessorEtiquette ,
19+ TamilMalaysianTrainerAgent
2120} from '../../lib/presets/agents' ;
21+ import { supabase } from './supabaseClient' ;
2222
2323// Database types
2424export type Profile = {
@@ -81,7 +81,8 @@ export const useUser = create<UserState>((set, get) => ({
8181 }
8282
8383 if ( data ) {
84- set ( { profile : data , profileComplete : ! ! ( data . name && data . gender ) } ) ;
84+ const profileData = data as Profile ;
85+ set ( { profile : profileData , profileComplete : ! ! ( profileData . name && profileData . gender ) } ) ;
8586 }
8687 } catch ( error ) {
8788 console . error ( 'Error fetching user profile:' , error ) ;
@@ -107,7 +108,8 @@ export const useUser = create<UserState>((set, get) => ({
107108 if ( error ) throw error ;
108109
109110 if ( data ) {
110- set ( { profile : data , profileComplete : ! ! ( data . name && data . gender ) } ) ;
111+ const profileData = data as Profile ;
112+ set ( { profile : profileData , profileComplete : ! ! ( profileData . name && profileData . gender ) } ) ;
111113 }
112114 } catch ( error ) {
113115 console . error ( 'Error updating profile:' , error ) ;
@@ -228,13 +230,15 @@ export const useAgent = create<AgentState>((set, get) => ({
228230 if ( error ) throw error ;
229231
230232 if ( data ) {
233+ const flarebotData = data as Flarebot ;
231234 const addedAgent : Agent = {
232- id : data . id ,
233- name : data . name ,
234- personality : data . personality || '' ,
235- bodyColor : data . body_color || '#58A6FF' ,
236- voice : data . voice ,
237- menuDescription : data . menu_description || '' ,
235+ id : flarebotData . id ,
236+ name : flarebotData . name ,
237+ personality : flarebotData . personality || '' ,
238+ bodyColor : flarebotData . body_color || '#58A6FF' ,
239+ voice : flarebotData . voice ,
240+ knowledgeBase : '' , // Default empty knowledge base
241+ menuDescription : flarebotData . menu_description || '' ,
238242 } ;
239243 set ( state => ( {
240244 availablePersonal : [ ...state . availablePersonal , addedAgent ] ,
@@ -251,15 +255,15 @@ export const useAgent = create<AgentState>((set, get) => ({
251255 updateAgent : async ( agentId : string , adjustments : Partial < Agent > ) => {
252256 // Presets cannot be updated in the DB
253257 if ( get ( ) . availablePresets . some ( p => p . id === agentId ) ) {
254- const agent = get ( ) . availablePresets . find ( a => a . id === agentId ) ! ;
255- const updatedAgent = { ...agent , ...adjustments } ;
256- set ( state => ( {
257- availablePresets : state . availablePresets . map ( a =>
258- a . id === agentId ? updatedAgent : a
259- ) ,
260- current : state . current . id === agentId ? updatedAgent : state . current ,
261- } ) ) ;
262- return ;
258+ const agent = get ( ) . availablePresets . find ( a => a . id === agentId ) ! ;
259+ const updatedAgent = { ...agent , ...adjustments } ;
260+ set ( state => ( {
261+ availablePresets : state . availablePresets . map ( a =>
262+ a . id === agentId ? updatedAgent : a
263+ ) ,
264+ current : state . current . id === agentId ? updatedAgent : state . current ,
265+ } ) ) ;
266+ return ;
263267 }
264268
265269 set ( { loading : true } ) ;
@@ -282,13 +286,15 @@ export const useAgent = create<AgentState>((set, get) => ({
282286 if ( error ) throw error ;
283287
284288 if ( data ) {
289+ const flarebotData = data as Flarebot ;
285290 const updatedAgent : Agent = {
286- id : data . id ,
287- name : data . name ,
288- personality : data . personality || '' ,
289- bodyColor : data . body_color || '#58A6FF' ,
290- voice : data . voice ,
291- menuDescription : data . menu_description || '' ,
291+ id : flarebotData . id ,
292+ name : flarebotData . name ,
293+ personality : flarebotData . personality || '' ,
294+ bodyColor : flarebotData . body_color || '#58A6FF' ,
295+ voice : flarebotData . voice ,
296+ knowledgeBase : '' , // Default empty knowledge base
297+ menuDescription : flarebotData . menu_description || '' ,
292298 } ;
293299
294300 set ( state => ( {
0 commit comments