@afncdelacru/brady-chat 0.4.2 → 0.4.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@afncdelacru/brady-chat",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Brady AI chat sidebar component and context for AFN recruiting experiences.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"afn"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@afncdelacru/brady-chat": "^0.4.
|
|
35
|
+
"@afncdelacru/brady-chat": "^0.4.4"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -50,6 +50,9 @@ interface BradyChatContextType {
|
|
|
50
50
|
// Modal-aware Brady AI
|
|
51
51
|
hideBradyForModal: () => void;
|
|
52
52
|
restoreBradyAfterModal: () => void;
|
|
53
|
+
|
|
54
|
+
// Set user text and trigger send in EnhancedBradyChat
|
|
55
|
+
setUserText: (text: string) => void;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
const BradyChatContext = createContext<BradyChatContextType | undefined>(undefined);
|
|
@@ -62,6 +65,12 @@ const initialMessages: ChatMessage[] = [
|
|
|
62
65
|
];
|
|
63
66
|
|
|
64
67
|
export function BradyChatProvider({ children }: { children: ReactNode }) {
|
|
68
|
+
// setUserText state for EnhancedBradyChat
|
|
69
|
+
const [userTextToSend, setUserTextToSend] = useState<string | undefined>(undefined);
|
|
70
|
+
// Expose setUserText to context consumers
|
|
71
|
+
const setUserText = (text: string) => {
|
|
72
|
+
setUserTextToSend(text);
|
|
73
|
+
};
|
|
65
74
|
const [workflowType, setWorkflowType] = useState<ChatWorkflowType>('free');
|
|
66
75
|
const [messages, setMessages] = useState<ChatMessage[]>(initialMessages);
|
|
67
76
|
// Mode system state
|
|
@@ -187,8 +196,10 @@ export function BradyChatProvider({ children }: { children: ReactNode }) {
|
|
|
187
196
|
setIsHidden,
|
|
188
197
|
hideBradyForModal,
|
|
189
198
|
restoreBradyAfterModal,
|
|
199
|
+
setUserText,
|
|
190
200
|
}}
|
|
191
201
|
>
|
|
202
|
+
{/* Pass userTextToSend as a prop to EnhancedBradyChat via context if needed */}
|
|
192
203
|
{children}
|
|
193
204
|
</BradyChatContext.Provider>
|
|
194
205
|
);
|
|
@@ -34,7 +34,6 @@ export interface EnhancedBradyChatProps {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, setUserText }: EnhancedBradyChatProps) {
|
|
37
|
-
|
|
38
37
|
const [bradyHealthy, setBradyHealthy] = useState(true);
|
|
39
38
|
const {
|
|
40
39
|
workflowType,
|
|
@@ -52,11 +51,29 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
|
|
|
52
51
|
resetMode,
|
|
53
52
|
isHidden,
|
|
54
53
|
setIsHidden,
|
|
54
|
+
setUserText: contextSetUserText,
|
|
55
55
|
} = useBradyChat();
|
|
56
56
|
const [inputValue, setInputValue] = useState('');
|
|
57
57
|
const [setUserTextSent, setSetUserTextSent] = useState<string | undefined>(undefined);
|
|
58
58
|
|
|
59
|
-
//
|
|
59
|
+
// Listen for setUserText from context (external trigger)
|
|
60
|
+
const [contextUserText, setContextUserText] = useState<string | undefined>(undefined);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
// Patch contextSetUserText to update local state
|
|
63
|
+
if (contextSetUserText) {
|
|
64
|
+
(contextSetUserText as any)._setLocalUserText = setContextUserText;
|
|
65
|
+
}
|
|
66
|
+
}, [contextSetUserText]);
|
|
67
|
+
|
|
68
|
+
// If contextUserText changes, treat as setUserText
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (contextUserText && contextUserText !== setUserTextSent) {
|
|
71
|
+
setInputValue(contextUserText);
|
|
72
|
+
setSetUserTextSent(contextUserText);
|
|
73
|
+
}
|
|
74
|
+
}, [contextUserText, setUserTextSent]);
|
|
75
|
+
|
|
76
|
+
// Auto-send user text if setUserText prop changes
|
|
60
77
|
useEffect(() => {
|
|
61
78
|
if (setUserText && setUserText !== setUserTextSent) {
|
|
62
79
|
setInputValue(setUserText);
|
|
@@ -64,13 +81,17 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
|
|
|
64
81
|
}
|
|
65
82
|
}, [setUserText, setUserTextSent]);
|
|
66
83
|
|
|
67
|
-
// When inputValue is set by setUserText, trigger send
|
|
84
|
+
// When inputValue is set by setUserText or contextUserText, trigger send
|
|
68
85
|
useEffect(() => {
|
|
69
|
-
if (
|
|
86
|
+
if (
|
|
87
|
+
((setUserText && setUserTextSent === setUserText && inputValue === setUserText) ||
|
|
88
|
+
(contextUserText && setUserTextSent === contextUserText && inputValue === contextUserText)) &&
|
|
89
|
+
inputValue.trim()
|
|
90
|
+
) {
|
|
70
91
|
handleSend();
|
|
71
92
|
}
|
|
72
93
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
-
}, [inputValue, setUserText, setUserTextSent]);
|
|
94
|
+
}, [inputValue, setUserText, setUserTextSent, contextUserText]);
|
|
74
95
|
const [showForm, setShowForm] = useState(false);
|
|
75
96
|
const [inputDisabled, setInputDisabled] = useState(false);
|
|
76
97
|
const [showModePrompts, setShowModePrompts] = useState(false);
|