@informedai/react 0.4.23 → 0.4.25
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 +224 -47
- package/dist/index.mjs +224 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2468,6 +2468,221 @@ 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
|
+
const cardMarkerStr = match.cardMarker;
|
|
2476
|
+
const parsedCard = cardMarkerStr ? parseCardMarker(cardMarkerStr) : null;
|
|
2477
|
+
const cardData = parsedCard ? extractCardDisplayData(parsedCard) : null;
|
|
2478
|
+
if (cardData) {
|
|
2479
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2480
|
+
"div",
|
|
2481
|
+
{
|
|
2482
|
+
style: {
|
|
2483
|
+
border: "1px solid #e5e7eb",
|
|
2484
|
+
borderRadius: "8px",
|
|
2485
|
+
overflow: "hidden",
|
|
2486
|
+
backgroundColor: "#fff"
|
|
2487
|
+
},
|
|
2488
|
+
children: [
|
|
2489
|
+
cardData.imageUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2490
|
+
"div",
|
|
2491
|
+
{
|
|
2492
|
+
style: {
|
|
2493
|
+
width: "100%",
|
|
2494
|
+
height: "140px",
|
|
2495
|
+
backgroundColor: "#f3f4f6",
|
|
2496
|
+
overflow: "hidden"
|
|
2497
|
+
},
|
|
2498
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2499
|
+
"img",
|
|
2500
|
+
{
|
|
2501
|
+
src: cardData.imageUrl,
|
|
2502
|
+
alt: cardData.title,
|
|
2503
|
+
style: {
|
|
2504
|
+
width: "100%",
|
|
2505
|
+
height: "100%",
|
|
2506
|
+
objectFit: "cover"
|
|
2507
|
+
},
|
|
2508
|
+
onError: (e) => {
|
|
2509
|
+
e.target.style.display = "none";
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
)
|
|
2513
|
+
}
|
|
2514
|
+
),
|
|
2515
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { padding: "12px" }, children: [
|
|
2516
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "6px" }, children: [
|
|
2517
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2518
|
+
"div",
|
|
2519
|
+
{
|
|
2520
|
+
style: {
|
|
2521
|
+
display: "inline-block",
|
|
2522
|
+
fontSize: "10px",
|
|
2523
|
+
fontWeight: 600,
|
|
2524
|
+
textTransform: "uppercase",
|
|
2525
|
+
letterSpacing: "0.5px",
|
|
2526
|
+
color: theme.primaryColor,
|
|
2527
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
2528
|
+
padding: "2px 6px",
|
|
2529
|
+
borderRadius: "4px"
|
|
2530
|
+
},
|
|
2531
|
+
children: parsedCard.type
|
|
2532
|
+
}
|
|
2533
|
+
),
|
|
2534
|
+
score != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2535
|
+
"div",
|
|
2536
|
+
{
|
|
2537
|
+
style: {
|
|
2538
|
+
fontSize: "11px",
|
|
2539
|
+
fontWeight: 600,
|
|
2540
|
+
color: theme.primaryColor,
|
|
2541
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
2542
|
+
padding: "2px 8px",
|
|
2543
|
+
borderRadius: "10px"
|
|
2544
|
+
},
|
|
2545
|
+
children: [
|
|
2546
|
+
score,
|
|
2547
|
+
"%"
|
|
2548
|
+
]
|
|
2549
|
+
}
|
|
2550
|
+
)
|
|
2551
|
+
] }),
|
|
2552
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2553
|
+
"div",
|
|
2554
|
+
{
|
|
2555
|
+
style: {
|
|
2556
|
+
fontSize: "15px",
|
|
2557
|
+
fontWeight: 600,
|
|
2558
|
+
color: "#1f2937",
|
|
2559
|
+
marginBottom: "4px",
|
|
2560
|
+
lineHeight: "1.3"
|
|
2561
|
+
},
|
|
2562
|
+
children: cardData.title
|
|
2563
|
+
}
|
|
2564
|
+
),
|
|
2565
|
+
cardData.subtitle && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2566
|
+
"div",
|
|
2567
|
+
{
|
|
2568
|
+
style: {
|
|
2569
|
+
fontSize: "13px",
|
|
2570
|
+
color: "#6b7280",
|
|
2571
|
+
marginBottom: "6px"
|
|
2572
|
+
},
|
|
2573
|
+
children: cardData.subtitle
|
|
2574
|
+
}
|
|
2575
|
+
),
|
|
2576
|
+
cardData.description && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2577
|
+
"div",
|
|
2578
|
+
{
|
|
2579
|
+
style: {
|
|
2580
|
+
fontSize: "13px",
|
|
2581
|
+
color: "#4b5563",
|
|
2582
|
+
lineHeight: "1.4",
|
|
2583
|
+
marginBottom: "8px"
|
|
2584
|
+
},
|
|
2585
|
+
children: cardData.description
|
|
2586
|
+
}
|
|
2587
|
+
),
|
|
2588
|
+
cardData.actionUrl && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2589
|
+
"a",
|
|
2590
|
+
{
|
|
2591
|
+
href: cardData.actionUrl,
|
|
2592
|
+
target: "_blank",
|
|
2593
|
+
rel: "noopener noreferrer",
|
|
2594
|
+
style: {
|
|
2595
|
+
display: "inline-flex",
|
|
2596
|
+
alignItems: "center",
|
|
2597
|
+
gap: "4px",
|
|
2598
|
+
fontSize: "13px",
|
|
2599
|
+
fontWeight: 500,
|
|
2600
|
+
color: theme.primaryColor,
|
|
2601
|
+
textDecoration: "none",
|
|
2602
|
+
padding: "6px 12px",
|
|
2603
|
+
borderRadius: "6px",
|
|
2604
|
+
backgroundColor: `${theme.primaryColor}10`,
|
|
2605
|
+
marginBottom: "8px"
|
|
2606
|
+
},
|
|
2607
|
+
children: [
|
|
2608
|
+
cardData.actionLabel || "View",
|
|
2609
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
2610
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
|
|
2611
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("polyline", { points: "15 3 21 3 21 9" }),
|
|
2612
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "10", y1: "14", x2: "21", y2: "3" })
|
|
2613
|
+
] })
|
|
2614
|
+
]
|
|
2615
|
+
}
|
|
2616
|
+
),
|
|
2617
|
+
reasons.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", marginTop: cardData.actionUrl ? "0" : "4px" }, children: reasons.map((reason, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2618
|
+
"span",
|
|
2619
|
+
{
|
|
2620
|
+
style: {
|
|
2621
|
+
fontSize: "11px",
|
|
2622
|
+
color: "#4b5563",
|
|
2623
|
+
backgroundColor: "#f3f4f6",
|
|
2624
|
+
padding: "3px 8px",
|
|
2625
|
+
borderRadius: "10px",
|
|
2626
|
+
lineHeight: "1.3"
|
|
2627
|
+
},
|
|
2628
|
+
children: reason
|
|
2629
|
+
},
|
|
2630
|
+
i
|
|
2631
|
+
)) })
|
|
2632
|
+
] })
|
|
2633
|
+
]
|
|
2634
|
+
}
|
|
2635
|
+
);
|
|
2636
|
+
}
|
|
2637
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2638
|
+
"div",
|
|
2639
|
+
{
|
|
2640
|
+
style: {
|
|
2641
|
+
border: "1px solid #e5e7eb",
|
|
2642
|
+
borderRadius: "8px",
|
|
2643
|
+
overflow: "hidden",
|
|
2644
|
+
backgroundColor: "#fff"
|
|
2645
|
+
},
|
|
2646
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { padding: "12px" }, children: [
|
|
2647
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "4px" }, children: [
|
|
2648
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "15px", fontWeight: 600, color: "#1f2937", lineHeight: "1.3" }, children: name }),
|
|
2649
|
+
score != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2650
|
+
"div",
|
|
2651
|
+
{
|
|
2652
|
+
style: {
|
|
2653
|
+
fontSize: "11px",
|
|
2654
|
+
fontWeight: 600,
|
|
2655
|
+
color: theme.primaryColor,
|
|
2656
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
2657
|
+
padding: "2px 8px",
|
|
2658
|
+
borderRadius: "10px"
|
|
2659
|
+
},
|
|
2660
|
+
children: [
|
|
2661
|
+
score,
|
|
2662
|
+
"%"
|
|
2663
|
+
]
|
|
2664
|
+
}
|
|
2665
|
+
)
|
|
2666
|
+
] }),
|
|
2667
|
+
reasons.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", marginTop: "4px" }, children: reasons.map((reason, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2668
|
+
"span",
|
|
2669
|
+
{
|
|
2670
|
+
style: {
|
|
2671
|
+
fontSize: "11px",
|
|
2672
|
+
color: "#4b5563",
|
|
2673
|
+
backgroundColor: "#f3f4f6",
|
|
2674
|
+
padding: "3px 8px",
|
|
2675
|
+
borderRadius: "10px",
|
|
2676
|
+
lineHeight: "1.3"
|
|
2677
|
+
},
|
|
2678
|
+
children: reason
|
|
2679
|
+
},
|
|
2680
|
+
i
|
|
2681
|
+
)) })
|
|
2682
|
+
] })
|
|
2683
|
+
}
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2471
2686
|
function SmartQuestionnaire({ className, ...config }) {
|
|
2472
2687
|
const theme = { ...defaultTheme4, ...config.theme };
|
|
2473
2688
|
const apiUrl = config.apiUrl || "https://api.informedai.app/api/v1";
|
|
@@ -2631,63 +2846,24 @@ function SmartQuestionnaire({ className, ...config }) {
|
|
|
2631
2846
|
};
|
|
2632
2847
|
const startResults = async (finalAnswers, finalMessages, matchList) => {
|
|
2633
2848
|
setPhase("results");
|
|
2634
|
-
|
|
2635
|
-
setStreamingContent("");
|
|
2849
|
+
setError(null);
|
|
2636
2850
|
try {
|
|
2637
2851
|
const res = await fetch(`${apiUrl}/smart-questionnaire/${config.questionnaireId}/results`, {
|
|
2638
2852
|
method: "POST",
|
|
2639
2853
|
headers: jsonHeaders,
|
|
2640
|
-
body: JSON.stringify({ matches: matchList
|
|
2854
|
+
body: JSON.stringify({ matches: matchList })
|
|
2641
2855
|
});
|
|
2642
2856
|
if (!res.ok) {
|
|
2643
2857
|
const err = await res.json().catch(() => ({ error: "Results failed" }));
|
|
2644
2858
|
throw new Error(err.error || `HTTP ${res.status}`);
|
|
2645
2859
|
}
|
|
2646
|
-
const
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
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
|
-
}
|
|
2860
|
+
const data = await res.json();
|
|
2861
|
+
const introMsg = { role: "assistant", content: data.message || "Here is what I found:" };
|
|
2862
|
+
setMessages([...finalMessages, introMsg]);
|
|
2863
|
+
setResultsHistory([introMsg]);
|
|
2864
|
+
setMatches(data.matches || matchList);
|
|
2687
2865
|
} catch (err) {
|
|
2688
|
-
setError(err instanceof Error ? err.message : "Failed to
|
|
2689
|
-
} finally {
|
|
2690
|
-
setIsStreaming(false);
|
|
2866
|
+
setError(err instanceof Error ? err.message : "Failed to load results");
|
|
2691
2867
|
}
|
|
2692
2868
|
};
|
|
2693
2869
|
const sendResultsFollowUp = async (message) => {
|
|
@@ -3019,6 +3195,7 @@ function SmartQuestionnaire({ className, ...config }) {
|
|
|
3019
3195
|
]
|
|
3020
3196
|
}
|
|
3021
3197
|
) }),
|
|
3198
|
+
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
3199
|
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
3200
|
currentStep.options.map((opt) => {
|
|
3024
3201
|
const isSelected = multiSelectChoices.has(opt);
|
package/dist/index.mjs
CHANGED
|
@@ -2435,6 +2435,221 @@ 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
|
+
const cardMarkerStr = match.cardMarker;
|
|
2443
|
+
const parsedCard = cardMarkerStr ? parseCardMarker(cardMarkerStr) : null;
|
|
2444
|
+
const cardData = parsedCard ? extractCardDisplayData(parsedCard) : null;
|
|
2445
|
+
if (cardData) {
|
|
2446
|
+
return /* @__PURE__ */ jsxs4(
|
|
2447
|
+
"div",
|
|
2448
|
+
{
|
|
2449
|
+
style: {
|
|
2450
|
+
border: "1px solid #e5e7eb",
|
|
2451
|
+
borderRadius: "8px",
|
|
2452
|
+
overflow: "hidden",
|
|
2453
|
+
backgroundColor: "#fff"
|
|
2454
|
+
},
|
|
2455
|
+
children: [
|
|
2456
|
+
cardData.imageUrl && /* @__PURE__ */ jsx5(
|
|
2457
|
+
"div",
|
|
2458
|
+
{
|
|
2459
|
+
style: {
|
|
2460
|
+
width: "100%",
|
|
2461
|
+
height: "140px",
|
|
2462
|
+
backgroundColor: "#f3f4f6",
|
|
2463
|
+
overflow: "hidden"
|
|
2464
|
+
},
|
|
2465
|
+
children: /* @__PURE__ */ jsx5(
|
|
2466
|
+
"img",
|
|
2467
|
+
{
|
|
2468
|
+
src: cardData.imageUrl,
|
|
2469
|
+
alt: cardData.title,
|
|
2470
|
+
style: {
|
|
2471
|
+
width: "100%",
|
|
2472
|
+
height: "100%",
|
|
2473
|
+
objectFit: "cover"
|
|
2474
|
+
},
|
|
2475
|
+
onError: (e) => {
|
|
2476
|
+
e.target.style.display = "none";
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
)
|
|
2480
|
+
}
|
|
2481
|
+
),
|
|
2482
|
+
/* @__PURE__ */ jsxs4("div", { style: { padding: "12px" }, children: [
|
|
2483
|
+
/* @__PURE__ */ jsxs4("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "6px" }, children: [
|
|
2484
|
+
/* @__PURE__ */ jsx5(
|
|
2485
|
+
"div",
|
|
2486
|
+
{
|
|
2487
|
+
style: {
|
|
2488
|
+
display: "inline-block",
|
|
2489
|
+
fontSize: "10px",
|
|
2490
|
+
fontWeight: 600,
|
|
2491
|
+
textTransform: "uppercase",
|
|
2492
|
+
letterSpacing: "0.5px",
|
|
2493
|
+
color: theme.primaryColor,
|
|
2494
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
2495
|
+
padding: "2px 6px",
|
|
2496
|
+
borderRadius: "4px"
|
|
2497
|
+
},
|
|
2498
|
+
children: parsedCard.type
|
|
2499
|
+
}
|
|
2500
|
+
),
|
|
2501
|
+
score != null && /* @__PURE__ */ jsxs4(
|
|
2502
|
+
"div",
|
|
2503
|
+
{
|
|
2504
|
+
style: {
|
|
2505
|
+
fontSize: "11px",
|
|
2506
|
+
fontWeight: 600,
|
|
2507
|
+
color: theme.primaryColor,
|
|
2508
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
2509
|
+
padding: "2px 8px",
|
|
2510
|
+
borderRadius: "10px"
|
|
2511
|
+
},
|
|
2512
|
+
children: [
|
|
2513
|
+
score,
|
|
2514
|
+
"%"
|
|
2515
|
+
]
|
|
2516
|
+
}
|
|
2517
|
+
)
|
|
2518
|
+
] }),
|
|
2519
|
+
/* @__PURE__ */ jsx5(
|
|
2520
|
+
"div",
|
|
2521
|
+
{
|
|
2522
|
+
style: {
|
|
2523
|
+
fontSize: "15px",
|
|
2524
|
+
fontWeight: 600,
|
|
2525
|
+
color: "#1f2937",
|
|
2526
|
+
marginBottom: "4px",
|
|
2527
|
+
lineHeight: "1.3"
|
|
2528
|
+
},
|
|
2529
|
+
children: cardData.title
|
|
2530
|
+
}
|
|
2531
|
+
),
|
|
2532
|
+
cardData.subtitle && /* @__PURE__ */ jsx5(
|
|
2533
|
+
"div",
|
|
2534
|
+
{
|
|
2535
|
+
style: {
|
|
2536
|
+
fontSize: "13px",
|
|
2537
|
+
color: "#6b7280",
|
|
2538
|
+
marginBottom: "6px"
|
|
2539
|
+
},
|
|
2540
|
+
children: cardData.subtitle
|
|
2541
|
+
}
|
|
2542
|
+
),
|
|
2543
|
+
cardData.description && /* @__PURE__ */ jsx5(
|
|
2544
|
+
"div",
|
|
2545
|
+
{
|
|
2546
|
+
style: {
|
|
2547
|
+
fontSize: "13px",
|
|
2548
|
+
color: "#4b5563",
|
|
2549
|
+
lineHeight: "1.4",
|
|
2550
|
+
marginBottom: "8px"
|
|
2551
|
+
},
|
|
2552
|
+
children: cardData.description
|
|
2553
|
+
}
|
|
2554
|
+
),
|
|
2555
|
+
cardData.actionUrl && /* @__PURE__ */ jsxs4(
|
|
2556
|
+
"a",
|
|
2557
|
+
{
|
|
2558
|
+
href: cardData.actionUrl,
|
|
2559
|
+
target: "_blank",
|
|
2560
|
+
rel: "noopener noreferrer",
|
|
2561
|
+
style: {
|
|
2562
|
+
display: "inline-flex",
|
|
2563
|
+
alignItems: "center",
|
|
2564
|
+
gap: "4px",
|
|
2565
|
+
fontSize: "13px",
|
|
2566
|
+
fontWeight: 500,
|
|
2567
|
+
color: theme.primaryColor,
|
|
2568
|
+
textDecoration: "none",
|
|
2569
|
+
padding: "6px 12px",
|
|
2570
|
+
borderRadius: "6px",
|
|
2571
|
+
backgroundColor: `${theme.primaryColor}10`,
|
|
2572
|
+
marginBottom: "8px"
|
|
2573
|
+
},
|
|
2574
|
+
children: [
|
|
2575
|
+
cardData.actionLabel || "View",
|
|
2576
|
+
/* @__PURE__ */ jsxs4("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
2577
|
+
/* @__PURE__ */ jsx5("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
|
|
2578
|
+
/* @__PURE__ */ jsx5("polyline", { points: "15 3 21 3 21 9" }),
|
|
2579
|
+
/* @__PURE__ */ jsx5("line", { x1: "10", y1: "14", x2: "21", y2: "3" })
|
|
2580
|
+
] })
|
|
2581
|
+
]
|
|
2582
|
+
}
|
|
2583
|
+
),
|
|
2584
|
+
reasons.length > 0 && /* @__PURE__ */ jsx5("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", marginTop: cardData.actionUrl ? "0" : "4px" }, children: reasons.map((reason, i) => /* @__PURE__ */ jsx5(
|
|
2585
|
+
"span",
|
|
2586
|
+
{
|
|
2587
|
+
style: {
|
|
2588
|
+
fontSize: "11px",
|
|
2589
|
+
color: "#4b5563",
|
|
2590
|
+
backgroundColor: "#f3f4f6",
|
|
2591
|
+
padding: "3px 8px",
|
|
2592
|
+
borderRadius: "10px",
|
|
2593
|
+
lineHeight: "1.3"
|
|
2594
|
+
},
|
|
2595
|
+
children: reason
|
|
2596
|
+
},
|
|
2597
|
+
i
|
|
2598
|
+
)) })
|
|
2599
|
+
] })
|
|
2600
|
+
]
|
|
2601
|
+
}
|
|
2602
|
+
);
|
|
2603
|
+
}
|
|
2604
|
+
return /* @__PURE__ */ jsx5(
|
|
2605
|
+
"div",
|
|
2606
|
+
{
|
|
2607
|
+
style: {
|
|
2608
|
+
border: "1px solid #e5e7eb",
|
|
2609
|
+
borderRadius: "8px",
|
|
2610
|
+
overflow: "hidden",
|
|
2611
|
+
backgroundColor: "#fff"
|
|
2612
|
+
},
|
|
2613
|
+
children: /* @__PURE__ */ jsxs4("div", { style: { padding: "12px" }, children: [
|
|
2614
|
+
/* @__PURE__ */ jsxs4("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "4px" }, children: [
|
|
2615
|
+
/* @__PURE__ */ jsx5("div", { style: { fontSize: "15px", fontWeight: 600, color: "#1f2937", lineHeight: "1.3" }, children: name }),
|
|
2616
|
+
score != null && /* @__PURE__ */ jsxs4(
|
|
2617
|
+
"div",
|
|
2618
|
+
{
|
|
2619
|
+
style: {
|
|
2620
|
+
fontSize: "11px",
|
|
2621
|
+
fontWeight: 600,
|
|
2622
|
+
color: theme.primaryColor,
|
|
2623
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
2624
|
+
padding: "2px 8px",
|
|
2625
|
+
borderRadius: "10px"
|
|
2626
|
+
},
|
|
2627
|
+
children: [
|
|
2628
|
+
score,
|
|
2629
|
+
"%"
|
|
2630
|
+
]
|
|
2631
|
+
}
|
|
2632
|
+
)
|
|
2633
|
+
] }),
|
|
2634
|
+
reasons.length > 0 && /* @__PURE__ */ jsx5("div", { style: { display: "flex", flexWrap: "wrap", gap: "4px", marginTop: "4px" }, children: reasons.map((reason, i) => /* @__PURE__ */ jsx5(
|
|
2635
|
+
"span",
|
|
2636
|
+
{
|
|
2637
|
+
style: {
|
|
2638
|
+
fontSize: "11px",
|
|
2639
|
+
color: "#4b5563",
|
|
2640
|
+
backgroundColor: "#f3f4f6",
|
|
2641
|
+
padding: "3px 8px",
|
|
2642
|
+
borderRadius: "10px",
|
|
2643
|
+
lineHeight: "1.3"
|
|
2644
|
+
},
|
|
2645
|
+
children: reason
|
|
2646
|
+
},
|
|
2647
|
+
i
|
|
2648
|
+
)) })
|
|
2649
|
+
] })
|
|
2650
|
+
}
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2438
2653
|
function SmartQuestionnaire({ className, ...config }) {
|
|
2439
2654
|
const theme = { ...defaultTheme4, ...config.theme };
|
|
2440
2655
|
const apiUrl = config.apiUrl || "https://api.informedai.app/api/v1";
|
|
@@ -2598,63 +2813,24 @@ function SmartQuestionnaire({ className, ...config }) {
|
|
|
2598
2813
|
};
|
|
2599
2814
|
const startResults = async (finalAnswers, finalMessages, matchList) => {
|
|
2600
2815
|
setPhase("results");
|
|
2601
|
-
|
|
2602
|
-
setStreamingContent("");
|
|
2816
|
+
setError(null);
|
|
2603
2817
|
try {
|
|
2604
2818
|
const res = await fetch(`${apiUrl}/smart-questionnaire/${config.questionnaireId}/results`, {
|
|
2605
2819
|
method: "POST",
|
|
2606
2820
|
headers: jsonHeaders,
|
|
2607
|
-
body: JSON.stringify({ matches: matchList
|
|
2821
|
+
body: JSON.stringify({ matches: matchList })
|
|
2608
2822
|
});
|
|
2609
2823
|
if (!res.ok) {
|
|
2610
2824
|
const err = await res.json().catch(() => ({ error: "Results failed" }));
|
|
2611
2825
|
throw new Error(err.error || `HTTP ${res.status}`);
|
|
2612
2826
|
}
|
|
2613
|
-
const
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
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
|
-
}
|
|
2827
|
+
const data = await res.json();
|
|
2828
|
+
const introMsg = { role: "assistant", content: data.message || "Here is what I found:" };
|
|
2829
|
+
setMessages([...finalMessages, introMsg]);
|
|
2830
|
+
setResultsHistory([introMsg]);
|
|
2831
|
+
setMatches(data.matches || matchList);
|
|
2654
2832
|
} catch (err) {
|
|
2655
|
-
setError(err instanceof Error ? err.message : "Failed to
|
|
2656
|
-
} finally {
|
|
2657
|
-
setIsStreaming(false);
|
|
2833
|
+
setError(err instanceof Error ? err.message : "Failed to load results");
|
|
2658
2834
|
}
|
|
2659
2835
|
};
|
|
2660
2836
|
const sendResultsFollowUp = async (message) => {
|
|
@@ -2986,6 +3162,7 @@ function SmartQuestionnaire({ className, ...config }) {
|
|
|
2986
3162
|
]
|
|
2987
3163
|
}
|
|
2988
3164
|
) }),
|
|
3165
|
+
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
3166
|
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
3167
|
currentStep.options.map((opt) => {
|
|
2991
3168
|
const isSelected = multiSelectChoices.has(opt);
|