@afncdelacru/brady-chat 0.5.0 → 0.5.2
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/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +40 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/lib/BradyChatContext.tsx +17 -19
- package/src/lib/EnhancedBradyChat.tsx +49 -9
|
@@ -26,10 +26,14 @@ export interface EnhancedBradyChatProps {
|
|
|
26
26
|
* Typically you pass something like `/bradyIcon.png` from your app's public assets.
|
|
27
27
|
*/
|
|
28
28
|
avatarSrc: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* If set, will immediately set the input value and send it as a user message.
|
|
32
|
+
*/
|
|
33
|
+
setUserText?: string;
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc }: EnhancedBradyChatProps) {
|
|
32
|
-
|
|
36
|
+
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, setUserText }: EnhancedBradyChatProps) {
|
|
33
37
|
const [bradyHealthy, setBradyHealthy] = useState(true);
|
|
34
38
|
const {
|
|
35
39
|
workflowType,
|
|
@@ -45,15 +49,48 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc }: E
|
|
|
45
49
|
setCalculatorOpen,
|
|
46
50
|
activateMode,
|
|
47
51
|
resetMode,
|
|
48
|
-
inputDisabled,
|
|
49
|
-
setInputDisabled,
|
|
50
|
-
showModePrompts,
|
|
51
|
-
setShowModePrompts,
|
|
52
52
|
isHidden,
|
|
53
53
|
setIsHidden,
|
|
54
|
+
// Add userTextToSend and setUserTextToSend from context
|
|
55
|
+
setUserText: contextSetUserText,
|
|
56
|
+
// @ts-ignore: context type not updated yet
|
|
57
|
+
userTextToSend,
|
|
58
|
+
// @ts-ignore: context type not updated yet
|
|
59
|
+
setUserTextToSend,
|
|
54
60
|
} = useBradyChat();
|
|
55
61
|
const [inputValue, setInputValue] = useState('');
|
|
62
|
+
const [setUserTextSent, setSetUserTextSent] = useState<string | undefined>(undefined);
|
|
63
|
+
|
|
64
|
+
// If userTextToSend from context changes, treat as setUserText
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (userTextToSend && userTextToSend !== setUserTextSent) {
|
|
67
|
+
setInputValue(userTextToSend);
|
|
68
|
+
setSetUserTextSent(userTextToSend);
|
|
69
|
+
}
|
|
70
|
+
}, [userTextToSend, setUserTextSent]);
|
|
71
|
+
|
|
72
|
+
// Auto-send user text if setUserText prop changes
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (setUserText && setUserText !== setUserTextSent) {
|
|
75
|
+
setInputValue(setUserText);
|
|
76
|
+
setSetUserTextSent(setUserText);
|
|
77
|
+
}
|
|
78
|
+
}, [setUserText, setUserTextSent]);
|
|
79
|
+
|
|
80
|
+
// When inputValue is set by setUserText or contextUserText, trigger send
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (
|
|
83
|
+
((setUserText && setUserTextSent === setUserText && inputValue === setUserText) ||
|
|
84
|
+
(userTextToSend && setUserTextSent === userTextToSend && inputValue === userTextToSend)) &&
|
|
85
|
+
inputValue.trim()
|
|
86
|
+
) {
|
|
87
|
+
handleSend();
|
|
88
|
+
}
|
|
89
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
|
+
}, [inputValue, setUserText, setUserTextSent, userTextToSend]);
|
|
56
91
|
const [showForm, setShowForm] = useState(false);
|
|
92
|
+
const [inputDisabled, setInputDisabled] = useState(false);
|
|
93
|
+
const [showModePrompts, setShowModePrompts] = useState(false);
|
|
57
94
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
58
95
|
const [suggestionLinks, setSuggestionLinks] = useState<{ text: string; prompt: string }[] | null>(null);
|
|
59
96
|
|
|
@@ -293,9 +330,12 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc }: E
|
|
|
293
330
|
const handleSend = async () => {
|
|
294
331
|
if (inputValue.trim() && !inputDisabled) {
|
|
295
332
|
const userText = inputValue;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
333
|
+
addMessage({ type: 'user', text: userText });
|
|
334
|
+
setInputValue('');
|
|
335
|
+
// If userTextToSend was used, clear it after send to avoid repeated triggers
|
|
336
|
+
if (userTextToSend && setUserTextSent === userTextToSend && setUserTextToSend) {
|
|
337
|
+
setUserTextToSend(undefined);
|
|
338
|
+
}
|
|
299
339
|
try {
|
|
300
340
|
const apiResponse = await sendBradyPrompt([{ role: 'user', content: userText }]);
|
|
301
341
|
let mappedType: 'user' | 'brady' | 'form' = 'brady';
|