@afncdelacru/brady-chat 0.4.7 → 0.5.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/dist/index.d.mts +6 -9
- package/dist/index.d.ts +6 -9
- package/dist/index.js +16 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
- package/src/lib/BradyChatContext.tsx +19 -17
- package/src/lib/EnhancedBradyChat.tsx +9 -49
|
@@ -26,14 +26,10 @@ 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;
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc
|
|
31
|
+
export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc }: EnhancedBradyChatProps) {
|
|
32
|
+
|
|
37
33
|
const [bradyHealthy, setBradyHealthy] = useState(true);
|
|
38
34
|
const {
|
|
39
35
|
workflowType,
|
|
@@ -49,48 +45,15 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
|
|
|
49
45
|
setCalculatorOpen,
|
|
50
46
|
activateMode,
|
|
51
47
|
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,
|
|
60
54
|
} = useBradyChat();
|
|
61
55
|
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]);
|
|
91
56
|
const [showForm, setShowForm] = useState(false);
|
|
92
|
-
const [inputDisabled, setInputDisabled] = useState(false);
|
|
93
|
-
const [showModePrompts, setShowModePrompts] = useState(false);
|
|
94
57
|
const messagesEndRef = useRef<HTMLDivElement>(null);
|
|
95
58
|
const [suggestionLinks, setSuggestionLinks] = useState<{ text: string; prompt: string }[] | null>(null);
|
|
96
59
|
|
|
@@ -330,12 +293,9 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
|
|
|
330
293
|
const handleSend = async () => {
|
|
331
294
|
if (inputValue.trim() && !inputDisabled) {
|
|
332
295
|
const userText = inputValue;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (userTextToSend && setUserTextSent === userTextToSend && setUserTextToSend) {
|
|
337
|
-
setUserTextToSend(undefined);
|
|
338
|
-
}
|
|
296
|
+
addMessage({ type: 'user', text: userText });
|
|
297
|
+
setInputValue('');
|
|
298
|
+
|
|
339
299
|
try {
|
|
340
300
|
const apiResponse = await sendBradyPrompt([{ role: 'user', content: userText }]);
|
|
341
301
|
let mappedType: 'user' | 'brady' | 'form' = 'brady';
|