@afncdelacru/brady-chat 0.4.4 → 0.4.5

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.4",
3
+ "version": "0.4.5",
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.4"
35
+ "@afncdelacru/brady-chat": "^0.4.5"
36
36
  }
37
37
  }
@@ -53,6 +53,9 @@ interface BradyChatContextType {
53
53
 
54
54
  // Set user text and trigger send in EnhancedBradyChat
55
55
  setUserText: (text: string) => void;
56
+ // Expose userTextToSend and setUserTextToSend for EnhancedBradyChat
57
+ userTextToSend?: string;
58
+ setUserTextToSend?: (text: string | undefined) => void;
56
59
  }
57
60
 
58
61
  const BradyChatContext = createContext<BradyChatContextType | undefined>(undefined);
@@ -197,9 +200,11 @@ export function BradyChatProvider({ children }: { children: ReactNode }) {
197
200
  hideBradyForModal,
198
201
  restoreBradyAfterModal,
199
202
  setUserText,
203
+ // Expose userTextToSend and setUserTextToSend for EnhancedBradyChat
204
+ userTextToSend,
205
+ setUserTextToSend,
200
206
  }}
201
207
  >
202
- {/* Pass userTextToSend as a prop to EnhancedBradyChat via context if needed */}
203
208
  {children}
204
209
  </BradyChatContext.Provider>
205
210
  );
@@ -51,27 +51,23 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
51
51
  resetMode,
52
52
  isHidden,
53
53
  setIsHidden,
54
+ // Add userTextToSend and setUserTextToSend from context
54
55
  setUserText: contextSetUserText,
56
+ // @ts-ignore: context type not updated yet
57
+ userTextToSend,
58
+ // @ts-ignore: context type not updated yet
59
+ setUserTextToSend,
55
60
  } = useBradyChat();
56
61
  const [inputValue, setInputValue] = useState('');
57
62
  const [setUserTextSent, setSetUserTextSent] = useState<string | undefined>(undefined);
58
63
 
59
- // Listen for setUserText from context (external trigger)
60
- const [contextUserText, setContextUserText] = useState<string | undefined>(undefined);
64
+ // If userTextToSend from context changes, treat as setUserText
61
65
  useEffect(() => {
62
- // Patch contextSetUserText to update local state
63
- if (contextSetUserText) {
64
- (contextSetUserText as any)._setLocalUserText = setContextUserText;
66
+ if (userTextToSend && userTextToSend !== setUserTextSent) {
67
+ setInputValue(userTextToSend);
68
+ setSetUserTextSent(userTextToSend);
65
69
  }
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]);
70
+ }, [userTextToSend, setUserTextSent]);
75
71
 
76
72
  // Auto-send user text if setUserText prop changes
77
73
  useEffect(() => {
@@ -85,13 +81,13 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
85
81
  useEffect(() => {
86
82
  if (
87
83
  ((setUserText && setUserTextSent === setUserText && inputValue === setUserText) ||
88
- (contextUserText && setUserTextSent === contextUserText && inputValue === contextUserText)) &&
84
+ (userTextToSend && setUserTextSent === userTextToSend && inputValue === userTextToSend)) &&
89
85
  inputValue.trim()
90
86
  ) {
91
87
  handleSend();
92
88
  }
93
89
  // eslint-disable-next-line react-hooks/exhaustive-deps
94
- }, [inputValue, setUserText, setUserTextSent, contextUserText]);
90
+ }, [inputValue, setUserText, setUserTextSent, userTextToSend]);
95
91
  const [showForm, setShowForm] = useState(false);
96
92
  const [inputDisabled, setInputDisabled] = useState(false);
97
93
  const [showModePrompts, setShowModePrompts] = useState(false);
@@ -334,9 +330,12 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc, set
334
330
  const handleSend = async () => {
335
331
  if (inputValue.trim() && !inputDisabled) {
336
332
  const userText = inputValue;
337
- addMessage({ type: 'user', text: userText });
338
- setInputValue('');
339
-
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
+ }
340
339
  try {
341
340
  const apiResponse = await sendBradyPrompt([{ role: 'user', content: userText }]);
342
341
  let mappedType: 'user' | 'brady' | 'form' = 'brady';