@informedai/react 0.4.9 → 0.4.11

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
@@ -13,6 +13,10 @@ interface Session {
13
13
  aiConversations: Record<string, ChatMessage[]>;
14
14
  status: 'active' | 'ended' | 'abandoned';
15
15
  }
16
+ interface KbSearchInfo {
17
+ query: string;
18
+ documentNames: string[];
19
+ }
16
20
  interface WidgetMessage {
17
21
  id: string;
18
22
  role: 'user' | 'assistant' | 'agent' | 'system';
@@ -21,6 +25,7 @@ interface WidgetMessage {
21
25
  quickActions?: QuickAction[];
22
26
  timestamp: string;
23
27
  taskContext?: string;
28
+ kbSearch?: KbSearchInfo;
24
29
  }
25
30
  interface QuickAction {
26
31
  id: string;
package/dist/index.d.ts CHANGED
@@ -13,6 +13,10 @@ interface Session {
13
13
  aiConversations: Record<string, ChatMessage[]>;
14
14
  status: 'active' | 'ended' | 'abandoned';
15
15
  }
16
+ interface KbSearchInfo {
17
+ query: string;
18
+ documentNames: string[];
19
+ }
16
20
  interface WidgetMessage {
17
21
  id: string;
18
22
  role: 'user' | 'assistant' | 'agent' | 'system';
@@ -21,6 +25,7 @@ interface WidgetMessage {
21
25
  quickActions?: QuickAction[];
22
26
  timestamp: string;
23
27
  taskContext?: string;
28
+ kbSearch?: KbSearchInfo;
24
29
  }
25
30
  interface QuickAction {
26
31
  id: string;
package/dist/index.js CHANGED
@@ -748,9 +748,17 @@ function AssistantWidget({ className, theme, position = "inline", defaultCollaps
748
748
  const [isCollapsed, setIsCollapsed] = (0, import_react2.useState)(defaultCollapsed);
749
749
  const [inputValue, setInputValue] = (0, import_react2.useState)("");
750
750
  const messagesEndRef = (0, import_react2.useRef)(null);
751
+ const inputRef = (0, import_react2.useRef)(null);
752
+ const wasStreamingRef = (0, import_react2.useRef)(false);
751
753
  (0, import_react2.useEffect)(() => {
752
754
  messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
753
755
  }, [session?.widgetMessages, streamingContent]);
756
+ (0, import_react2.useEffect)(() => {
757
+ if (wasStreamingRef.current && !isStreaming) {
758
+ inputRef.current?.focus();
759
+ }
760
+ wasStreamingRef.current = isStreaming;
761
+ }, [isStreaming]);
754
762
  const handleSubmit = async (e) => {
755
763
  e.preventDefault();
756
764
  if (!inputValue.trim() || isStreaming) return;
@@ -1027,6 +1035,7 @@ function AssistantWidget({ className, theme, position = "inline", defaultCollaps
1027
1035
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1028
1036
  "input",
1029
1037
  {
1038
+ ref: inputRef,
1030
1039
  type: "text",
1031
1040
  value: inputValue,
1032
1041
  onChange: (e) => setInputValue(e.target.value),
@@ -1112,6 +1121,7 @@ function QuickActionButton({
1112
1121
  function MessageBubble({ message, theme, onQuickAction, isLatest = false }) {
1113
1122
  const isUser = message.role === "user";
1114
1123
  const hasQuickActions = isLatest && message.quickActions && message.quickActions.length > 0;
1124
+ const hasKbSearch = message.kbSearch !== void 0;
1115
1125
  if ((message.type === "quick_actions" || !message.content) && hasQuickActions) {
1116
1126
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: {
1117
1127
  display: "flex",
@@ -1142,6 +1152,32 @@ function MessageBubble({ message, theme, onQuickAction, isLatest = false }) {
1142
1152
  ] });
1143
1153
  }
1144
1154
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
1155
+ hasKbSearch && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1156
+ "div",
1157
+ {
1158
+ style: {
1159
+ display: "flex",
1160
+ alignItems: "center",
1161
+ gap: "6px",
1162
+ padding: "4px 10px",
1163
+ backgroundColor: message.kbSearch.documentNames.length > 0 ? "#dbeafe" : "#f3f4f6",
1164
+ borderRadius: "12px",
1165
+ fontSize: "11px",
1166
+ color: message.kbSearch.documentNames.length > 0 ? "#1e40af" : "#6b7280",
1167
+ marginBottom: "4px",
1168
+ width: "fit-content"
1169
+ },
1170
+ title: message.kbSearch.documentNames.length > 0 ? `Found: ${message.kbSearch.documentNames.join(", ")}` : `Searched for: ${message.kbSearch.query}`,
1171
+ children: [
1172
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BookIcon, { size: 12 }),
1173
+ message.kbSearch.documentNames.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1174
+ "Referenced: ",
1175
+ message.kbSearch.documentNames.slice(0, 2).join(", "),
1176
+ message.kbSearch.documentNames.length > 2 && ` +${message.kbSearch.documentNames.length - 2} more`
1177
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "No matching documents found" })
1178
+ ]
1179
+ }
1180
+ ),
1145
1181
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1146
1182
  "div",
1147
1183
  {
@@ -1214,6 +1250,12 @@ function MinimizeIcon() {
1214
1250
  function ChevronRightIcon({ size = 16, color = "currentColor" }) {
1215
1251
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M9 18l6-6-6-6" }) });
1216
1252
  }
1253
+ function BookIcon({ size = 16, color = "currentColor" }) {
1254
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1255
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M4 19.5A2.5 2.5 0 016.5 17H20" }),
1256
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M6.5 2H20v20H6.5A2.5 2.5 0 014 19.5v-15A2.5 2.5 0 016.5 2z" })
1257
+ ] });
1258
+ }
1217
1259
  function LoadingSpinner({ size = 20 }) {
1218
1260
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1219
1261
  "svg",
package/dist/index.mjs CHANGED
@@ -718,9 +718,17 @@ function AssistantWidget({ className, theme, position = "inline", defaultCollaps
718
718
  const [isCollapsed, setIsCollapsed] = useState2(defaultCollapsed);
719
719
  const [inputValue, setInputValue] = useState2("");
720
720
  const messagesEndRef = useRef2(null);
721
+ const inputRef = useRef2(null);
722
+ const wasStreamingRef = useRef2(false);
721
723
  useEffect2(() => {
722
724
  messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
723
725
  }, [session?.widgetMessages, streamingContent]);
726
+ useEffect2(() => {
727
+ if (wasStreamingRef.current && !isStreaming) {
728
+ inputRef.current?.focus();
729
+ }
730
+ wasStreamingRef.current = isStreaming;
731
+ }, [isStreaming]);
724
732
  const handleSubmit = async (e) => {
725
733
  e.preventDefault();
726
734
  if (!inputValue.trim() || isStreaming) return;
@@ -997,6 +1005,7 @@ function AssistantWidget({ className, theme, position = "inline", defaultCollaps
997
1005
  /* @__PURE__ */ jsx2(
998
1006
  "input",
999
1007
  {
1008
+ ref: inputRef,
1000
1009
  type: "text",
1001
1010
  value: inputValue,
1002
1011
  onChange: (e) => setInputValue(e.target.value),
@@ -1082,6 +1091,7 @@ function QuickActionButton({
1082
1091
  function MessageBubble({ message, theme, onQuickAction, isLatest = false }) {
1083
1092
  const isUser = message.role === "user";
1084
1093
  const hasQuickActions = isLatest && message.quickActions && message.quickActions.length > 0;
1094
+ const hasKbSearch = message.kbSearch !== void 0;
1085
1095
  if ((message.type === "quick_actions" || !message.content) && hasQuickActions) {
1086
1096
  return /* @__PURE__ */ jsxs("div", { style: {
1087
1097
  display: "flex",
@@ -1112,6 +1122,32 @@ function MessageBubble({ message, theme, onQuickAction, isLatest = false }) {
1112
1122
  ] });
1113
1123
  }
1114
1124
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1125
+ hasKbSearch && /* @__PURE__ */ jsxs(
1126
+ "div",
1127
+ {
1128
+ style: {
1129
+ display: "flex",
1130
+ alignItems: "center",
1131
+ gap: "6px",
1132
+ padding: "4px 10px",
1133
+ backgroundColor: message.kbSearch.documentNames.length > 0 ? "#dbeafe" : "#f3f4f6",
1134
+ borderRadius: "12px",
1135
+ fontSize: "11px",
1136
+ color: message.kbSearch.documentNames.length > 0 ? "#1e40af" : "#6b7280",
1137
+ marginBottom: "4px",
1138
+ width: "fit-content"
1139
+ },
1140
+ title: message.kbSearch.documentNames.length > 0 ? `Found: ${message.kbSearch.documentNames.join(", ")}` : `Searched for: ${message.kbSearch.query}`,
1141
+ children: [
1142
+ /* @__PURE__ */ jsx2(BookIcon, { size: 12 }),
1143
+ message.kbSearch.documentNames.length > 0 ? /* @__PURE__ */ jsxs("span", { children: [
1144
+ "Referenced: ",
1145
+ message.kbSearch.documentNames.slice(0, 2).join(", "),
1146
+ message.kbSearch.documentNames.length > 2 && ` +${message.kbSearch.documentNames.length - 2} more`
1147
+ ] }) : /* @__PURE__ */ jsx2("span", { children: "No matching documents found" })
1148
+ ]
1149
+ }
1150
+ ),
1115
1151
  /* @__PURE__ */ jsx2(
1116
1152
  "div",
1117
1153
  {
@@ -1184,6 +1220,12 @@ function MinimizeIcon() {
1184
1220
  function ChevronRightIcon({ size = 16, color = "currentColor" }) {
1185
1221
  return /* @__PURE__ */ jsx2("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx2("path", { d: "M9 18l6-6-6-6" }) });
1186
1222
  }
1223
+ function BookIcon({ size = 16, color = "currentColor" }) {
1224
+ return /* @__PURE__ */ jsxs("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: color, strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
1225
+ /* @__PURE__ */ jsx2("path", { d: "M4 19.5A2.5 2.5 0 016.5 17H20" }),
1226
+ /* @__PURE__ */ jsx2("path", { d: "M6.5 2H20v20H6.5A2.5 2.5 0 014 19.5v-15A2.5 2.5 0 016.5 2z" })
1227
+ ] });
1228
+ }
1187
1229
  function LoadingSpinner({ size = 20 }) {
1188
1230
  return /* @__PURE__ */ jsxs(
1189
1231
  "svg",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@informedai/react",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "React SDK for InformedAI Assistant - AI-powered content creation widget",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",