@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 CHANGED
@@ -33,14 +33,13 @@ interface BradyChatContextType {
33
33
  resetMode: () => void;
34
34
  calculatorOpen: boolean;
35
35
  setCalculatorOpen: (open: boolean) => void;
36
- inputDisabled: boolean;
37
- setInputDisabled: React.Dispatch<React.SetStateAction<boolean>>;
38
- showModePrompts: boolean;
39
- setShowModePrompts: React.Dispatch<React.SetStateAction<boolean>>;
40
36
  isHidden: boolean;
41
37
  setIsHidden: React.Dispatch<React.SetStateAction<boolean>>;
42
38
  hideBradyForModal: () => void;
43
39
  restoreBradyAfterModal: () => void;
40
+ setUserText: (text: string) => void;
41
+ userTextToSend?: string;
42
+ setUserTextToSend?: (text: string | undefined) => void;
44
43
  }
45
44
  declare function BradyChatProvider({ children }: {
46
45
  children: ReactNode;
@@ -59,8 +58,12 @@ interface EnhancedBradyChatProps {
59
58
  * Typically you pass something like `/bradyIcon.png` from your app's public assets.
60
59
  */
61
60
  avatarSrc: string;
61
+ /**
62
+ * If set, will immediately set the input value and send it as a user message.
63
+ */
64
+ setUserText?: string;
62
65
  }
63
- declare function EnhancedBradyChat({ modeVariant, avatarSrc }: EnhancedBradyChatProps): react_jsx_runtime.JSX.Element;
66
+ declare function EnhancedBradyChat({ modeVariant, avatarSrc, setUserText }: EnhancedBradyChatProps): react_jsx_runtime.JSX.Element;
64
67
 
65
68
  declare const DEFAULT_BRADY_API_KEY: string;
66
69
  declare const API_URL: string;
@@ -83,4 +86,4 @@ interface BradyChatResponse {
83
86
  declare function sendBradyPrompt(messages: BradyMessage[], apiKey?: string): Promise<BradyChatResponse>;
84
87
  declare function checkBradyHealth(): Promise<boolean>;
85
88
 
86
- export { API_URL, BradyChatProvider, type BradyChatRequest, type BradyChatResponse, type BradyMessage, type ChatMessage, type ChatWorkflowType, DEFAULT_BRADY_API_KEY, EnhancedBradyChat, type EnhancedBradyChatProps, type ModeStep, type ModeType, checkBradyHealth, sendBradyPrompt, useBradyChat };
89
+ export { API_URL, type BradyChatContextType, BradyChatProvider, type BradyChatRequest, type BradyChatResponse, type BradyMessage, type ChatMessage, type ChatWorkflowType, DEFAULT_BRADY_API_KEY, EnhancedBradyChat, type EnhancedBradyChatProps, type ModeStep, type ModeType, checkBradyHealth, sendBradyPrompt, useBradyChat };
package/dist/index.d.ts CHANGED
@@ -33,14 +33,13 @@ interface BradyChatContextType {
33
33
  resetMode: () => void;
34
34
  calculatorOpen: boolean;
35
35
  setCalculatorOpen: (open: boolean) => void;
36
- inputDisabled: boolean;
37
- setInputDisabled: React.Dispatch<React.SetStateAction<boolean>>;
38
- showModePrompts: boolean;
39
- setShowModePrompts: React.Dispatch<React.SetStateAction<boolean>>;
40
36
  isHidden: boolean;
41
37
  setIsHidden: React.Dispatch<React.SetStateAction<boolean>>;
42
38
  hideBradyForModal: () => void;
43
39
  restoreBradyAfterModal: () => void;
40
+ setUserText: (text: string) => void;
41
+ userTextToSend?: string;
42
+ setUserTextToSend?: (text: string | undefined) => void;
44
43
  }
45
44
  declare function BradyChatProvider({ children }: {
46
45
  children: ReactNode;
@@ -59,8 +58,12 @@ interface EnhancedBradyChatProps {
59
58
  * Typically you pass something like `/bradyIcon.png` from your app's public assets.
60
59
  */
61
60
  avatarSrc: string;
61
+ /**
62
+ * If set, will immediately set the input value and send it as a user message.
63
+ */
64
+ setUserText?: string;
62
65
  }
63
- declare function EnhancedBradyChat({ modeVariant, avatarSrc }: EnhancedBradyChatProps): react_jsx_runtime.JSX.Element;
66
+ declare function EnhancedBradyChat({ modeVariant, avatarSrc, setUserText }: EnhancedBradyChatProps): react_jsx_runtime.JSX.Element;
64
67
 
65
68
  declare const DEFAULT_BRADY_API_KEY: string;
66
69
  declare const API_URL: string;
@@ -83,4 +86,4 @@ interface BradyChatResponse {
83
86
  declare function sendBradyPrompt(messages: BradyMessage[], apiKey?: string): Promise<BradyChatResponse>;
84
87
  declare function checkBradyHealth(): Promise<boolean>;
85
88
 
86
- export { API_URL, BradyChatProvider, type BradyChatRequest, type BradyChatResponse, type BradyMessage, type ChatMessage, type ChatWorkflowType, DEFAULT_BRADY_API_KEY, EnhancedBradyChat, type EnhancedBradyChatProps, type ModeStep, type ModeType, checkBradyHealth, sendBradyPrompt, useBradyChat };
89
+ export { API_URL, type BradyChatContextType, BradyChatProvider, type BradyChatRequest, type BradyChatResponse, type BradyMessage, type ChatMessage, type ChatWorkflowType, DEFAULT_BRADY_API_KEY, EnhancedBradyChat, type EnhancedBradyChatProps, type ModeStep, type ModeType, checkBradyHealth, sendBradyPrompt, useBradyChat };
package/dist/index.js CHANGED
@@ -40,14 +40,16 @@ var initialMessages = [
40
40
  }
41
41
  ];
42
42
  function BradyChatProvider({ children }) {
43
+ const [userTextToSend, setUserTextToSend] = (0, import_react.useState)(void 0);
44
+ const setUserText = (text) => {
45
+ setUserTextToSend(text);
46
+ };
43
47
  const [workflowType, setWorkflowType] = (0, import_react.useState)("free");
44
48
  const [messages, setMessages] = (0, import_react.useState)(initialMessages);
45
49
  const [activeMode, setActiveMode] = (0, import_react.useState)("none");
46
50
  const [modeStep, setModeStep] = (0, import_react.useState)("initial");
47
51
  const [modeData, setModeData] = (0, import_react.useState)({});
48
52
  const [calculatorOpen, setCalculatorOpen] = (0, import_react.useState)(false);
49
- const [inputDisabled, setInputDisabled] = (0, import_react.useState)(false);
50
- const [showModePrompts, setShowModePrompts] = (0, import_react.useState)(false);
51
53
  const [isHidden, setIsHidden] = (0, import_react.useState)(true);
52
54
  const [wasBradyVisibleBeforeModal, setWasBradyVisibleBeforeModal] = (0, import_react.useState)(false);
53
55
  const hideBradyForModal = () => {
@@ -126,9 +128,6 @@ function BradyChatProvider({ children }) {
126
128
  setModeData({});
127
129
  setCalculatorOpen(false);
128
130
  setWorkflowType("free");
129
- setMessages(initialMessages);
130
- setInputDisabled(false);
131
- setShowModePrompts(false);
132
131
  };
133
132
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
134
133
  BradyChatContext.Provider,
@@ -149,14 +148,14 @@ function BradyChatProvider({ children }) {
149
148
  resetMode,
150
149
  calculatorOpen,
151
150
  setCalculatorOpen,
152
- inputDisabled,
153
- setInputDisabled,
154
- showModePrompts,
155
- setShowModePrompts,
156
151
  isHidden,
157
152
  setIsHidden,
158
153
  hideBradyForModal,
159
- restoreBradyAfterModal
154
+ restoreBradyAfterModal,
155
+ setUserText,
156
+ // Expose userTextToSend and setUserTextToSend for EnhancedBradyChat
157
+ userTextToSend,
158
+ setUserTextToSend
160
159
  },
161
160
  children
162
161
  }
@@ -928,7 +927,7 @@ function ImageWithFallback(props) {
928
927
 
929
928
  // src/lib/EnhancedBradyChat.tsx
930
929
  var import_jsx_runtime8 = require("react/jsx-runtime");
931
- function EnhancedBradyChat({ modeVariant = "loan-officer", avatarSrc }) {
930
+ function EnhancedBradyChat({ modeVariant = "loan-officer", avatarSrc, setUserText }) {
932
931
  const [bradyHealthy, setBradyHealthy] = (0, import_react11.useState)(true);
933
932
  const {
934
933
  workflowType,
@@ -944,15 +943,37 @@ function EnhancedBradyChat({ modeVariant = "loan-officer", avatarSrc }) {
944
943
  setCalculatorOpen,
945
944
  activateMode,
946
945
  resetMode,
947
- inputDisabled,
948
- setInputDisabled,
949
- showModePrompts,
950
- setShowModePrompts,
951
946
  isHidden,
952
- setIsHidden
947
+ setIsHidden,
948
+ // Add userTextToSend and setUserTextToSend from context
949
+ setUserText: contextSetUserText,
950
+ // @ts-ignore: context type not updated yet
951
+ userTextToSend,
952
+ // @ts-ignore: context type not updated yet
953
+ setUserTextToSend
953
954
  } = useBradyChat();
954
955
  const [inputValue, setInputValue] = (0, import_react11.useState)("");
956
+ const [setUserTextSent, setSetUserTextSent] = (0, import_react11.useState)(void 0);
957
+ (0, import_react11.useEffect)(() => {
958
+ if (userTextToSend && userTextToSend !== setUserTextSent) {
959
+ setInputValue(userTextToSend);
960
+ setSetUserTextSent(userTextToSend);
961
+ }
962
+ }, [userTextToSend, setUserTextSent]);
963
+ (0, import_react11.useEffect)(() => {
964
+ if (setUserText && setUserText !== setUserTextSent) {
965
+ setInputValue(setUserText);
966
+ setSetUserTextSent(setUserText);
967
+ }
968
+ }, [setUserText, setUserTextSent]);
969
+ (0, import_react11.useEffect)(() => {
970
+ if ((setUserText && setUserTextSent === setUserText && inputValue === setUserText || userTextToSend && setUserTextSent === userTextToSend && inputValue === userTextToSend) && inputValue.trim()) {
971
+ handleSend();
972
+ }
973
+ }, [inputValue, setUserText, setUserTextSent, userTextToSend]);
955
974
  const [showForm, setShowForm] = (0, import_react11.useState)(false);
975
+ const [inputDisabled, setInputDisabled] = (0, import_react11.useState)(false);
976
+ const [showModePrompts, setShowModePrompts] = (0, import_react11.useState)(false);
956
977
  const messagesEndRef = (0, import_react11.useRef)(null);
957
978
  const [suggestionLinks, setSuggestionLinks] = (0, import_react11.useState)(null);
958
979
  const isBranchManager = modeVariant === "branch-manager";
@@ -1157,6 +1178,9 @@ I'll focus on ways to increase ${isBranchManager ? "profit" : "income"} using ${
1157
1178
  const userText = inputValue;
1158
1179
  addMessage({ type: "user", text: userText });
1159
1180
  setInputValue("");
1181
+ if (userTextToSend && setUserTextSent === userTextToSend && setUserTextToSend) {
1182
+ setUserTextToSend(void 0);
1183
+ }
1160
1184
  try {
1161
1185
  const apiResponse = await sendBradyPrompt([{ role: "user", content: userText }]);
1162
1186
  let mappedType = "brady";