@informedai/react 0.4.23 → 0.4.24

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.js CHANGED
@@ -2468,6 +2468,45 @@ function MessageContent2({ content, theme }) {
2468
2468
  return null;
2469
2469
  }) });
2470
2470
  }
2471
+ function MatchCard({ match, theme }) {
2472
+ const name = match.name || "Match";
2473
+ const score = match.score;
2474
+ const reasons = match.matchReasons || [];
2475
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2476
+ "div",
2477
+ {
2478
+ style: {
2479
+ border: "1px solid #e5e7eb",
2480
+ borderRadius: "8px",
2481
+ overflow: "hidden",
2482
+ backgroundColor: "#fff"
2483
+ },
2484
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { padding: "12px" }, children: [
2485
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "4px" }, children: [
2486
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "15px", fontWeight: 600, color: "#1f2937", lineHeight: "1.3" }, children: name }),
2487
+ score != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2488
+ "div",
2489
+ {
2490
+ style: {
2491
+ fontSize: "11px",
2492
+ fontWeight: 600,
2493
+ color: theme.primaryColor,
2494
+ backgroundColor: `${theme.primaryColor}15`,
2495
+ padding: "2px 8px",
2496
+ borderRadius: "10px"
2497
+ },
2498
+ children: [
2499
+ score,
2500
+ "%"
2501
+ ]
2502
+ }
2503
+ )
2504
+ ] }),
2505
+ reasons.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "13px", color: "#6b7280", lineHeight: "1.4" }, children: reasons.join(" \u2022 ") })
2506
+ ] })
2507
+ }
2508
+ );
2509
+ }
2471
2510
  function SmartQuestionnaire({ className, ...config }) {
2472
2511
  const theme = { ...defaultTheme4, ...config.theme };
2473
2512
  const apiUrl = config.apiUrl || "https://api.informedai.app/api/v1";
@@ -2631,63 +2670,24 @@ function SmartQuestionnaire({ className, ...config }) {
2631
2670
  };
2632
2671
  const startResults = async (finalAnswers, finalMessages, matchList) => {
2633
2672
  setPhase("results");
2634
- setIsStreaming(true);
2635
- setStreamingContent("");
2673
+ setError(null);
2636
2674
  try {
2637
2675
  const res = await fetch(`${apiUrl}/smart-questionnaire/${config.questionnaireId}/results`, {
2638
2676
  method: "POST",
2639
2677
  headers: jsonHeaders,
2640
- body: JSON.stringify({ matches: matchList, history: [] })
2678
+ body: JSON.stringify({ matches: matchList })
2641
2679
  });
2642
2680
  if (!res.ok) {
2643
2681
  const err = await res.json().catch(() => ({ error: "Results failed" }));
2644
2682
  throw new Error(err.error || `HTTP ${res.status}`);
2645
2683
  }
2646
- const reader = res.body?.getReader();
2647
- if (!reader) throw new Error("No response body");
2648
- const decoder = new TextDecoder();
2649
- let buffer = "";
2650
- let fullContent = "";
2651
- let action = null;
2652
- while (true) {
2653
- const { done, value } = await reader.read();
2654
- if (done) break;
2655
- buffer += decoder.decode(value, { stream: true });
2656
- const lines = buffer.split("\n");
2657
- buffer = lines.pop() || "";
2658
- for (const line of lines) {
2659
- if (line.startsWith("event:")) continue;
2660
- if (line.startsWith("data:")) {
2661
- const d = line.slice(5).trim();
2662
- try {
2663
- const parsed = JSON.parse(d);
2664
- if (parsed.content) {
2665
- fullContent += parsed.content;
2666
- setStreamingContent(fullContent);
2667
- }
2668
- if (parsed.fullContent) {
2669
- fullContent = parsed.fullContent;
2670
- }
2671
- if (parsed.action) {
2672
- action = parsed.action;
2673
- }
2674
- } catch {
2675
- }
2676
- }
2677
- }
2678
- }
2679
- const displayContent = fullContent.replace(/\[RESTART\]/g, "").trim();
2680
- const resultMsg = { role: "assistant", content: displayContent };
2681
- setMessages([...finalMessages, resultMsg]);
2682
- setResultsHistory([resultMsg]);
2683
- setStreamingContent("");
2684
- if (action === "restart") {
2685
- handleRestart();
2686
- }
2684
+ const data = await res.json();
2685
+ const introMsg = { role: "assistant", content: data.message || "Here is what I found:" };
2686
+ setMessages([...finalMessages, introMsg]);
2687
+ setResultsHistory([introMsg]);
2688
+ setMatches(data.matches || matchList);
2687
2689
  } catch (err) {
2688
- setError(err instanceof Error ? err.message : "Failed to stream results");
2689
- } finally {
2690
- setIsStreaming(false);
2690
+ setError(err instanceof Error ? err.message : "Failed to load results");
2691
2691
  }
2692
2692
  };
2693
2693
  const sendResultsFollowUp = async (message) => {
@@ -3019,6 +3019,7 @@ function SmartQuestionnaire({ className, ...config }) {
3019
3019
  ]
3020
3020
  }
3021
3021
  ) }),
3022
+ phase === "results" && matches && matches.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { display: "flex", flexDirection: "column", gap: "8px", maxWidth: "90%" }, children: matches.map((match, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MatchCard, { match, theme }, i)) }),
3022
3023
  showOptions && currentStep.options.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { display: "flex", flexDirection: "column", gap: "6px", maxWidth: "85%" }, children: currentStep.multiSelect ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
3023
3024
  currentStep.options.map((opt) => {
3024
3025
  const isSelected = multiSelectChoices.has(opt);
package/dist/index.mjs CHANGED
@@ -2435,6 +2435,45 @@ function MessageContent2({ content, theme }) {
2435
2435
  return null;
2436
2436
  }) });
2437
2437
  }
2438
+ function MatchCard({ match, theme }) {
2439
+ const name = match.name || "Match";
2440
+ const score = match.score;
2441
+ const reasons = match.matchReasons || [];
2442
+ return /* @__PURE__ */ jsx5(
2443
+ "div",
2444
+ {
2445
+ style: {
2446
+ border: "1px solid #e5e7eb",
2447
+ borderRadius: "8px",
2448
+ overflow: "hidden",
2449
+ backgroundColor: "#fff"
2450
+ },
2451
+ children: /* @__PURE__ */ jsxs4("div", { style: { padding: "12px" }, children: [
2452
+ /* @__PURE__ */ jsxs4("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "4px" }, children: [
2453
+ /* @__PURE__ */ jsx5("div", { style: { fontSize: "15px", fontWeight: 600, color: "#1f2937", lineHeight: "1.3" }, children: name }),
2454
+ score != null && /* @__PURE__ */ jsxs4(
2455
+ "div",
2456
+ {
2457
+ style: {
2458
+ fontSize: "11px",
2459
+ fontWeight: 600,
2460
+ color: theme.primaryColor,
2461
+ backgroundColor: `${theme.primaryColor}15`,
2462
+ padding: "2px 8px",
2463
+ borderRadius: "10px"
2464
+ },
2465
+ children: [
2466
+ score,
2467
+ "%"
2468
+ ]
2469
+ }
2470
+ )
2471
+ ] }),
2472
+ reasons.length > 0 && /* @__PURE__ */ jsx5("div", { style: { fontSize: "13px", color: "#6b7280", lineHeight: "1.4" }, children: reasons.join(" \u2022 ") })
2473
+ ] })
2474
+ }
2475
+ );
2476
+ }
2438
2477
  function SmartQuestionnaire({ className, ...config }) {
2439
2478
  const theme = { ...defaultTheme4, ...config.theme };
2440
2479
  const apiUrl = config.apiUrl || "https://api.informedai.app/api/v1";
@@ -2598,63 +2637,24 @@ function SmartQuestionnaire({ className, ...config }) {
2598
2637
  };
2599
2638
  const startResults = async (finalAnswers, finalMessages, matchList) => {
2600
2639
  setPhase("results");
2601
- setIsStreaming(true);
2602
- setStreamingContent("");
2640
+ setError(null);
2603
2641
  try {
2604
2642
  const res = await fetch(`${apiUrl}/smart-questionnaire/${config.questionnaireId}/results`, {
2605
2643
  method: "POST",
2606
2644
  headers: jsonHeaders,
2607
- body: JSON.stringify({ matches: matchList, history: [] })
2645
+ body: JSON.stringify({ matches: matchList })
2608
2646
  });
2609
2647
  if (!res.ok) {
2610
2648
  const err = await res.json().catch(() => ({ error: "Results failed" }));
2611
2649
  throw new Error(err.error || `HTTP ${res.status}`);
2612
2650
  }
2613
- const reader = res.body?.getReader();
2614
- if (!reader) throw new Error("No response body");
2615
- const decoder = new TextDecoder();
2616
- let buffer = "";
2617
- let fullContent = "";
2618
- let action = null;
2619
- while (true) {
2620
- const { done, value } = await reader.read();
2621
- if (done) break;
2622
- buffer += decoder.decode(value, { stream: true });
2623
- const lines = buffer.split("\n");
2624
- buffer = lines.pop() || "";
2625
- for (const line of lines) {
2626
- if (line.startsWith("event:")) continue;
2627
- if (line.startsWith("data:")) {
2628
- const d = line.slice(5).trim();
2629
- try {
2630
- const parsed = JSON.parse(d);
2631
- if (parsed.content) {
2632
- fullContent += parsed.content;
2633
- setStreamingContent(fullContent);
2634
- }
2635
- if (parsed.fullContent) {
2636
- fullContent = parsed.fullContent;
2637
- }
2638
- if (parsed.action) {
2639
- action = parsed.action;
2640
- }
2641
- } catch {
2642
- }
2643
- }
2644
- }
2645
- }
2646
- const displayContent = fullContent.replace(/\[RESTART\]/g, "").trim();
2647
- const resultMsg = { role: "assistant", content: displayContent };
2648
- setMessages([...finalMessages, resultMsg]);
2649
- setResultsHistory([resultMsg]);
2650
- setStreamingContent("");
2651
- if (action === "restart") {
2652
- handleRestart();
2653
- }
2651
+ const data = await res.json();
2652
+ const introMsg = { role: "assistant", content: data.message || "Here is what I found:" };
2653
+ setMessages([...finalMessages, introMsg]);
2654
+ setResultsHistory([introMsg]);
2655
+ setMatches(data.matches || matchList);
2654
2656
  } catch (err) {
2655
- setError(err instanceof Error ? err.message : "Failed to stream results");
2656
- } finally {
2657
- setIsStreaming(false);
2657
+ setError(err instanceof Error ? err.message : "Failed to load results");
2658
2658
  }
2659
2659
  };
2660
2660
  const sendResultsFollowUp = async (message) => {
@@ -2986,6 +2986,7 @@ function SmartQuestionnaire({ className, ...config }) {
2986
2986
  ]
2987
2987
  }
2988
2988
  ) }),
2989
+ phase === "results" && matches && matches.length > 0 && /* @__PURE__ */ jsx5("div", { style: { display: "flex", flexDirection: "column", gap: "8px", maxWidth: "90%" }, children: matches.map((match, i) => /* @__PURE__ */ jsx5(MatchCard, { match, theme }, i)) }),
2989
2990
  showOptions && currentStep.options.length > 0 && /* @__PURE__ */ jsx5("div", { style: { display: "flex", flexDirection: "column", gap: "6px", maxWidth: "85%" }, children: currentStep.multiSelect ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
2990
2991
  currentStep.options.map((opt) => {
2991
2992
  const isSelected = multiSelectChoices.has(opt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@informedai/react",
3
- "version": "0.4.23",
3
+ "version": "0.4.24",
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",