@informedai/react 0.4.28 → 0.4.30

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
@@ -31,6 +31,7 @@ interface WidgetMessage {
31
31
  runId: string;
32
32
  query: string;
33
33
  status: string;
34
+ queryType?: string;
34
35
  };
35
36
  triages?: string[];
36
37
  };
package/dist/index.d.ts CHANGED
@@ -31,6 +31,7 @@ interface WidgetMessage {
31
31
  runId: string;
32
32
  query: string;
33
33
  status: string;
34
+ queryType?: string;
34
35
  };
35
36
  triages?: string[];
36
37
  };
package/dist/index.js CHANGED
@@ -316,6 +316,7 @@ function InformedAIProvider({ config, children }) {
316
316
  const initRef = (0, import_react.useRef)(false);
317
317
  const heartbeatIntervalRef = (0, import_react.useRef)(null);
318
318
  const sessionIdRef = (0, import_react.useRef)(null);
319
+ const operationInFlightRef = (0, import_react.useRef)(false);
319
320
  const shouldPersist = config.persistSession ?? true;
320
321
  const storageKey = getStorageKey(config.documentTypeId, config.externalId);
321
322
  (0, import_react.useEffect)(() => {
@@ -532,6 +533,10 @@ function InformedAIProvider({ config, children }) {
532
533
  if (window.document.hidden) {
533
534
  stopHeartbeat();
534
535
  } else if (session?.id && clientRef.current) {
536
+ if (operationInFlightRef.current) {
537
+ startHeartbeat(session.id);
538
+ return;
539
+ }
535
540
  try {
536
541
  const refreshedSession = await clientRef.current.getSession(session.id);
537
542
  if (refreshedSession.status === "abandoned") {
@@ -588,6 +593,7 @@ function InformedAIProvider({ config, children }) {
588
593
  const sendMessage = (0, import_react.useCallback)(async (message) => {
589
594
  if (!clientRef.current || !session) return;
590
595
  try {
596
+ operationInFlightRef.current = true;
591
597
  const optimisticMessage = {
592
598
  id: `temp-${Date.now()}`,
593
599
  role: "user",
@@ -613,12 +619,14 @@ function InformedAIProvider({ config, children }) {
613
619
  setError(error2);
614
620
  config.onError?.(error2);
615
621
  } finally {
622
+ operationInFlightRef.current = false;
616
623
  setIsStreaming(false);
617
624
  }
618
625
  }, [session, handleSSEEvent, handleSessionDeleted, config]);
619
626
  const sendQuickAction = (0, import_react.useCallback)(async (action) => {
620
627
  if (!clientRef.current || !session) return;
621
628
  try {
629
+ operationInFlightRef.current = true;
622
630
  setIsStreaming(true);
623
631
  setStreamingContent("");
624
632
  setError(null);
@@ -641,12 +649,14 @@ function InformedAIProvider({ config, children }) {
641
649
  setError(error2);
642
650
  config.onError?.(error2);
643
651
  } finally {
652
+ operationInFlightRef.current = false;
644
653
  setIsStreaming(false);
645
654
  }
646
655
  }, [session, handleSSEEvent, handleSessionDeleted, config]);
647
656
  const applyPendingValue = (0, import_react.useCallback)(async () => {
648
657
  if (!clientRef.current || !session) return;
649
658
  try {
659
+ operationInFlightRef.current = true;
650
660
  setError(null);
651
661
  const result = await clientRef.current.applyPendingValue(session.id);
652
662
  setSession(result.session);
@@ -660,11 +670,14 @@ function InformedAIProvider({ config, children }) {
660
670
  const error2 = err instanceof Error ? err : new Error("Failed to apply value");
661
671
  setError(error2);
662
672
  config.onError?.(error2);
673
+ } finally {
674
+ operationInFlightRef.current = false;
663
675
  }
664
676
  }, [session, handleSessionDeleted, config]);
665
677
  const skipTask = (0, import_react.useCallback)(async () => {
666
678
  if (!clientRef.current || !session) return;
667
679
  try {
680
+ operationInFlightRef.current = true;
668
681
  setError(null);
669
682
  const newSession = await clientRef.current.skipTask(session.id);
670
683
  setSession(newSession);
@@ -677,6 +690,8 @@ function InformedAIProvider({ config, children }) {
677
690
  const error2 = err instanceof Error ? err : new Error("Failed to skip task");
678
691
  setError(error2);
679
692
  config.onError?.(error2);
693
+ } finally {
694
+ operationInFlightRef.current = false;
680
695
  }
681
696
  }, [session, handleSessionDeleted, config]);
682
697
  const startNewSession = (0, import_react.useCallback)(async () => {
@@ -1209,7 +1224,8 @@ function MessageBubble({ message, theme, onQuickAction, isLatest = false, quickA
1209
1224
  {
1210
1225
  runId: message.agentContext.analyticsRun.runId,
1211
1226
  query: message.agentContext.analyticsRun.query,
1212
- status: message.agentContext.analyticsRun.status
1227
+ status: message.agentContext.analyticsRun.status,
1228
+ queryType: message.agentContext.analyticsRun.queryType
1213
1229
  }
1214
1230
  ),
1215
1231
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -1347,7 +1363,7 @@ function GroupedQuickActions({ actions, groups, theme, onQuickAction }) {
1347
1363
  ] }, groupKey);
1348
1364
  }) });
1349
1365
  }
1350
- function AnalyticsBadge({ runId, query, status }) {
1366
+ function AnalyticsBadge({ runId, query, status, queryType }) {
1351
1367
  const { session, onAnalyticsRunClick, getAnalyticsRun } = useInformedAI();
1352
1368
  const [expanded, setExpanded] = (0, import_react2.useState)(false);
1353
1369
  const [runDetail, setRunDetail] = (0, import_react2.useState)(null);
@@ -1392,7 +1408,10 @@ function AnalyticsBadge({ runId, query, status }) {
1392
1408
  title: `Analytics query: ${query}`,
1393
1409
  children: [
1394
1410
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChartIcon, { size: 12 }),
1395
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Analytics query" }),
1411
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
1412
+ "Analytics query",
1413
+ queryType ? ` \xB7 ${queryType.charAt(0).toUpperCase() + queryType.slice(1)}` : ""
1414
+ ] }),
1396
1415
  !onAnalyticsRunClick && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "9px", marginLeft: "2px" }, children: expanded ? "\u25B2" : "\u25BC" })
1397
1416
  ]
1398
1417
  }
package/dist/index.mjs CHANGED
@@ -283,6 +283,7 @@ function InformedAIProvider({ config, children }) {
283
283
  const initRef = useRef(false);
284
284
  const heartbeatIntervalRef = useRef(null);
285
285
  const sessionIdRef = useRef(null);
286
+ const operationInFlightRef = useRef(false);
286
287
  const shouldPersist = config.persistSession ?? true;
287
288
  const storageKey = getStorageKey(config.documentTypeId, config.externalId);
288
289
  useEffect(() => {
@@ -499,6 +500,10 @@ function InformedAIProvider({ config, children }) {
499
500
  if (window.document.hidden) {
500
501
  stopHeartbeat();
501
502
  } else if (session?.id && clientRef.current) {
503
+ if (operationInFlightRef.current) {
504
+ startHeartbeat(session.id);
505
+ return;
506
+ }
502
507
  try {
503
508
  const refreshedSession = await clientRef.current.getSession(session.id);
504
509
  if (refreshedSession.status === "abandoned") {
@@ -555,6 +560,7 @@ function InformedAIProvider({ config, children }) {
555
560
  const sendMessage = useCallback(async (message) => {
556
561
  if (!clientRef.current || !session) return;
557
562
  try {
563
+ operationInFlightRef.current = true;
558
564
  const optimisticMessage = {
559
565
  id: `temp-${Date.now()}`,
560
566
  role: "user",
@@ -580,12 +586,14 @@ function InformedAIProvider({ config, children }) {
580
586
  setError(error2);
581
587
  config.onError?.(error2);
582
588
  } finally {
589
+ operationInFlightRef.current = false;
583
590
  setIsStreaming(false);
584
591
  }
585
592
  }, [session, handleSSEEvent, handleSessionDeleted, config]);
586
593
  const sendQuickAction = useCallback(async (action) => {
587
594
  if (!clientRef.current || !session) return;
588
595
  try {
596
+ operationInFlightRef.current = true;
589
597
  setIsStreaming(true);
590
598
  setStreamingContent("");
591
599
  setError(null);
@@ -608,12 +616,14 @@ function InformedAIProvider({ config, children }) {
608
616
  setError(error2);
609
617
  config.onError?.(error2);
610
618
  } finally {
619
+ operationInFlightRef.current = false;
611
620
  setIsStreaming(false);
612
621
  }
613
622
  }, [session, handleSSEEvent, handleSessionDeleted, config]);
614
623
  const applyPendingValue = useCallback(async () => {
615
624
  if (!clientRef.current || !session) return;
616
625
  try {
626
+ operationInFlightRef.current = true;
617
627
  setError(null);
618
628
  const result = await clientRef.current.applyPendingValue(session.id);
619
629
  setSession(result.session);
@@ -627,11 +637,14 @@ function InformedAIProvider({ config, children }) {
627
637
  const error2 = err instanceof Error ? err : new Error("Failed to apply value");
628
638
  setError(error2);
629
639
  config.onError?.(error2);
640
+ } finally {
641
+ operationInFlightRef.current = false;
630
642
  }
631
643
  }, [session, handleSessionDeleted, config]);
632
644
  const skipTask = useCallback(async () => {
633
645
  if (!clientRef.current || !session) return;
634
646
  try {
647
+ operationInFlightRef.current = true;
635
648
  setError(null);
636
649
  const newSession = await clientRef.current.skipTask(session.id);
637
650
  setSession(newSession);
@@ -644,6 +657,8 @@ function InformedAIProvider({ config, children }) {
644
657
  const error2 = err instanceof Error ? err : new Error("Failed to skip task");
645
658
  setError(error2);
646
659
  config.onError?.(error2);
660
+ } finally {
661
+ operationInFlightRef.current = false;
647
662
  }
648
663
  }, [session, handleSessionDeleted, config]);
649
664
  const startNewSession = useCallback(async () => {
@@ -1176,7 +1191,8 @@ function MessageBubble({ message, theme, onQuickAction, isLatest = false, quickA
1176
1191
  {
1177
1192
  runId: message.agentContext.analyticsRun.runId,
1178
1193
  query: message.agentContext.analyticsRun.query,
1179
- status: message.agentContext.analyticsRun.status
1194
+ status: message.agentContext.analyticsRun.status,
1195
+ queryType: message.agentContext.analyticsRun.queryType
1180
1196
  }
1181
1197
  ),
1182
1198
  /* @__PURE__ */ jsx2(
@@ -1314,7 +1330,7 @@ function GroupedQuickActions({ actions, groups, theme, onQuickAction }) {
1314
1330
  ] }, groupKey);
1315
1331
  }) });
1316
1332
  }
1317
- function AnalyticsBadge({ runId, query, status }) {
1333
+ function AnalyticsBadge({ runId, query, status, queryType }) {
1318
1334
  const { session, onAnalyticsRunClick, getAnalyticsRun } = useInformedAI();
1319
1335
  const [expanded, setExpanded] = useState2(false);
1320
1336
  const [runDetail, setRunDetail] = useState2(null);
@@ -1359,7 +1375,10 @@ function AnalyticsBadge({ runId, query, status }) {
1359
1375
  title: `Analytics query: ${query}`,
1360
1376
  children: [
1361
1377
  /* @__PURE__ */ jsx2(ChartIcon, { size: 12 }),
1362
- /* @__PURE__ */ jsx2("span", { children: "Analytics query" }),
1378
+ /* @__PURE__ */ jsxs("span", { children: [
1379
+ "Analytics query",
1380
+ queryType ? ` \xB7 ${queryType.charAt(0).toUpperCase() + queryType.slice(1)}` : ""
1381
+ ] }),
1363
1382
  !onAnalyticsRunClick && /* @__PURE__ */ jsx2("span", { style: { fontSize: "9px", marginLeft: "2px" }, children: expanded ? "\u25B2" : "\u25BC" })
1364
1383
  ]
1365
1384
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@informedai/react",
3
- "version": "0.4.28",
3
+ "version": "0.4.30",
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",