@afncdelacru/brady-chat 0.2.6 → 0.2.8

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.
@@ -112,44 +112,53 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc }: E
112
112
  }, [workflowType]);
113
113
 
114
114
  useEffect(() => {
115
- if (activeMode !== 'none' && modeStep === 'volume') {
116
- setShowModePrompts(true);
115
+ // Only react to activeMode changes (not modeStep or unstable addMessage) so volume prompts run once per activation.
116
+ if (activeMode === 'none' || modeStep !== 'volume') {
117
+ return;
118
+ }
117
119
 
118
- if (activeMode === 'earnings') {
119
- if (hasPersonalizedData) {
120
- setTimeout(() => {
121
- addMessage({
122
- type: 'brady',
123
- text: 'I have an estimate of your recent production.\nDoes this feel close?',
124
- });
125
- }, 500);
126
- } else {
127
- setTimeout(() => {
128
- addMessage({
129
- type: 'brady',
130
- text: 'To keep this realistic, about how much volume do you fund in an average month?',
131
- });
132
- }, 500);
133
- }
134
- } else if (activeMode === 'profit') {
135
- if (hasPersonalizedData) {
136
- setTimeout(() => {
137
- addMessage({
138
- type: 'brady',
139
- text: 'I have a baseline view of your branch.\nDoes this feel directionally right?',
140
- });
141
- }, 500);
142
- } else {
143
- setTimeout(() => {
144
- addMessage({
145
- type: 'brady',
146
- text: 'To start, about how much volume does your branch fund annually?',
147
- });
148
- }, 500);
149
- }
120
+ setShowModePrompts(true);
121
+
122
+ let timeoutId: ReturnType<typeof setTimeout>;
123
+ if (activeMode === 'earnings') {
124
+ if (hasPersonalizedData) {
125
+ timeoutId = setTimeout(() => {
126
+ addMessage({
127
+ type: 'brady',
128
+ text: 'I have an estimate of your recent production.\nDoes this feel close?',
129
+ });
130
+ }, 500);
131
+ } else {
132
+ timeoutId = setTimeout(() => {
133
+ addMessage({
134
+ type: 'brady',
135
+ text: 'To keep this realistic, about how much volume do you fund in an average month?',
136
+ });
137
+ }, 500);
138
+ }
139
+ } else if (activeMode === 'profit') {
140
+ if (hasPersonalizedData) {
141
+ timeoutId = setTimeout(() => {
142
+ addMessage({
143
+ type: 'brady',
144
+ text: 'I have a baseline view of your branch.\nDoes this feel directionally right?',
145
+ });
146
+ }, 500);
147
+ } else {
148
+ timeoutId = setTimeout(() => {
149
+ addMessage({
150
+ type: 'brady',
151
+ text: 'To start, about how much volume does your branch fund annually?',
152
+ });
153
+ }, 500);
150
154
  }
151
155
  }
152
- }, [activeMode, modeStep, addMessage]);
156
+
157
+ return () => {
158
+ if (timeoutId !== undefined) clearTimeout(timeoutId);
159
+ };
160
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- intentional: run once when activeMode changes; modeStep/addMessage omitted to avoid duplicate prompts
161
+ }, [activeMode]);
153
162
 
154
163
  useEffect(() => {
155
164
  scrollToBottom();
@@ -474,6 +483,8 @@ export function EnhancedBradyChat({ modeVariant = 'loan-officer', avatarSrc }: E
474
483
  {modeBadge}
475
484
  </div>
476
485
  )}
486
+
487
+
477
488
  <div className="flex-1 overflow-y-auto p-4 space-y-4">
478
489
  <AnimatePresence>
479
490
  {messages.map((msg, idx) => (
@@ -16,7 +16,7 @@ export const API_URL =
16
16
  process.env.BRADY_API_URL || process.env.NEXT_PUBLIC_BRADY_API_URL
17
17
  )
18
18
  ? process.env.BRADY_API_URL || process.env.NEXT_PUBLIC_BRADY_API_URL
19
- : 'https://afn-bradyjr-api-dev.azurewebsites.net/';
19
+ : 'https://afn-bradyjr-api-dev.azurewebsites.net';
20
20
 
21
21
  export interface BradyMessage {
22
22
  role: 'user' | 'assistant' | 'system';
@@ -42,7 +42,7 @@ export async function sendBradyPrompt(
42
42
  console.log('[DEFAULT_BRADY_API_KEY]', DEFAULT_BRADY_API_KEY);
43
43
  console.log('[API_URL]', API_URL);
44
44
 
45
- const res = await fetch(`${API_URL}/api/chat/prompt`, {
45
+ const res = await fetch(`${API_URL}api/chat/prompt`, {
46
46
  method: 'POST',
47
47
  headers: {
48
48
  'Content-Type': 'application/json',
@@ -58,7 +58,7 @@ export async function sendBradyPrompt(
58
58
 
59
59
  export async function checkBradyHealth(): Promise<boolean> {
60
60
  try {
61
- const res = await fetch(`${API_URL}/api/Health`);
61
+ const res = await fetch(`${API_URL}api/Health`);
62
62
  if (!res.ok) return false;
63
63
  console.log('[Brady API Response]', res);
64
64
  return true;