@afncdelacru/brady-chat 0.4.1 → 0.4.3
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.3",
|
|
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.3"
|
|
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
|
);
|
|
@@ -28,13 +28,12 @@ export interface EnhancedBradyChatProps {
|
|
|
28
28
|
avatarSrc: string;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* If set, will set the input value and send it
|
|
31
|
+
* If set, will immediately set the input value and send it as a user message.
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
setUserText?: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc,
|
|
37
|
-
|
|
36
|
+
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, setUserText }: EnhancedBradyChatProps) {
|
|
38
37
|
const [bradyHealthy, setBradyHealthy] = useState(true);
|
|
39
38
|
const {
|
|
40
39
|
workflowType,
|
|
@@ -52,24 +51,47 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, aut
|
|
|
52
51
|
resetMode,
|
|
53
52
|
isHidden,
|
|
54
53
|
setIsHidden,
|
|
54
|
+
setUserText: contextSetUserText,
|
|
55
55
|
} = useBradyChat();
|
|
56
56
|
const [inputValue, setInputValue] = useState('');
|
|
57
|
-
const [
|
|
58
|
-
// Auto-send user text if provided
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (autoUserText && !autoUserTextSent) {
|
|
61
|
-
setInputValue(autoUserText);
|
|
62
|
-
setAutoUserTextSent(true);
|
|
63
|
-
}
|
|
64
|
-
}, [autoUserText, autoUserTextSent]);
|
|
57
|
+
const [setUserTextSent, setSetUserTextSent] = useState<string | undefined>(undefined);
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
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
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (setUserText && setUserText !== setUserTextSent) {
|
|
79
|
+
setInputValue(setUserText);
|
|
80
|
+
setSetUserTextSent(setUserText);
|
|
81
|
+
}
|
|
82
|
+
}, [setUserText, setUserTextSent]);
|
|
83
|
+
|
|
84
|
+
// When inputValue is set by setUserText or contextUserText, trigger send
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (
|
|
87
|
+
((setUserText && setUserTextSent === setUserText && inputValue === setUserText) ||
|
|
88
|
+
(contextUserText && setUserTextSent === contextUserText && inputValue === contextUserText)) &&
|
|
89
|
+
inputValue.trim()
|
|
90
|
+
) {
|
|
91
|
+
handleSend();
|
|
92
|
+
}
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, [inputValue, setUserText, setUserTextSent, contextUserText]);
|
|
73
95
|
const [showForm, setShowForm] = useState(false);
|
|
74
96
|
const [inputDisabled, setInputDisabled] = useState(false);
|
|
75
97
|
const [showModePrompts, setShowModePrompts] = useState(false);
|