@informedai/react 0.4.15 → 0.4.16
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +251 -8
- package/dist/index.mjs +252 -9
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -240,6 +240,7 @@ declare function AdminChatbot({ className, ...config }: AdminChatbotProps): reac
|
|
|
240
240
|
* WebsiteChatbot
|
|
241
241
|
* An embeddable chatbot widget for website agents.
|
|
242
242
|
* Uses domain-based authentication - no API key required.
|
|
243
|
+
* Supports rendering rich cards from AI responses.
|
|
243
244
|
*/
|
|
244
245
|
interface WebsiteChatbotTheme {
|
|
245
246
|
primaryColor?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -240,6 +240,7 @@ declare function AdminChatbot({ className, ...config }: AdminChatbotProps): reac
|
|
|
240
240
|
* WebsiteChatbot
|
|
241
241
|
* An embeddable chatbot widget for website agents.
|
|
242
242
|
* Uses domain-based authentication - no API key required.
|
|
243
|
+
* Supports rendering rich cards from AI responses.
|
|
243
244
|
*/
|
|
244
245
|
interface WebsiteChatbotTheme {
|
|
245
246
|
primaryColor?: string;
|
package/dist/index.js
CHANGED
|
@@ -1699,6 +1699,91 @@ function AdminChatbot({ className, ...config }) {
|
|
|
1699
1699
|
|
|
1700
1700
|
// src/components/WebsiteChatbot.tsx
|
|
1701
1701
|
var import_react4 = require("react");
|
|
1702
|
+
|
|
1703
|
+
// src/utils/card-parser.ts
|
|
1704
|
+
var CARD_MARKER_REGEX = /\[([A-Z][A-Z0-9_]*):([^\]]+)\]/g;
|
|
1705
|
+
function parseCardMarker(marker) {
|
|
1706
|
+
const match = marker.match(/^\[([A-Z][A-Z0-9_]*):([^\]]+)\]$/);
|
|
1707
|
+
if (!match) return null;
|
|
1708
|
+
const [, type, valuesStr] = match;
|
|
1709
|
+
const values = valuesStr.split("|").map((v) => v.trim());
|
|
1710
|
+
return {
|
|
1711
|
+
type,
|
|
1712
|
+
values,
|
|
1713
|
+
originalMarker: marker
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
function parseMessageContent(content) {
|
|
1717
|
+
const segments = [];
|
|
1718
|
+
let lastIndex = 0;
|
|
1719
|
+
const matches = [...content.matchAll(CARD_MARKER_REGEX)];
|
|
1720
|
+
for (const match of matches) {
|
|
1721
|
+
const marker = match[0];
|
|
1722
|
+
const startIndex = match.index;
|
|
1723
|
+
if (startIndex > lastIndex) {
|
|
1724
|
+
const text = content.slice(lastIndex, startIndex).trim();
|
|
1725
|
+
if (text) {
|
|
1726
|
+
segments.push({ type: "text", content: text });
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
const card = parseCardMarker(marker);
|
|
1730
|
+
if (card) {
|
|
1731
|
+
segments.push({ type: "card", card });
|
|
1732
|
+
}
|
|
1733
|
+
lastIndex = startIndex + marker.length;
|
|
1734
|
+
}
|
|
1735
|
+
if (lastIndex < content.length) {
|
|
1736
|
+
const text = content.slice(lastIndex).trim();
|
|
1737
|
+
if (text) {
|
|
1738
|
+
segments.push({ type: "text", content: text });
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
if (segments.length === 0 && content.trim()) {
|
|
1742
|
+
segments.push({ type: "text", content: content.trim() });
|
|
1743
|
+
}
|
|
1744
|
+
return segments;
|
|
1745
|
+
}
|
|
1746
|
+
function isUrl(str) {
|
|
1747
|
+
return /^https?:\/\//i.test(str);
|
|
1748
|
+
}
|
|
1749
|
+
function isImageUrl(url) {
|
|
1750
|
+
if (!isUrl(url)) return false;
|
|
1751
|
+
return /\.(jpg|jpeg|png|gif|webp|svg)(\?|$)/i.test(url);
|
|
1752
|
+
}
|
|
1753
|
+
function extractCardDisplayData(card) {
|
|
1754
|
+
const values = [...card.values];
|
|
1755
|
+
const result = {
|
|
1756
|
+
title: values[0] || card.type,
|
|
1757
|
+
extraValues: []
|
|
1758
|
+
};
|
|
1759
|
+
if (values.length <= 1) return result;
|
|
1760
|
+
const imageIndex = values.findIndex((v, i) => i > 0 && isImageUrl(v));
|
|
1761
|
+
if (imageIndex > 0) {
|
|
1762
|
+
result.imageUrl = values[imageIndex];
|
|
1763
|
+
values.splice(imageIndex, 1);
|
|
1764
|
+
}
|
|
1765
|
+
const actionIndex = values.findIndex((v, i) => i > 0 && isUrl(v) && !isImageUrl(v));
|
|
1766
|
+
if (actionIndex > 0) {
|
|
1767
|
+
result.actionUrl = values[actionIndex];
|
|
1768
|
+
result.actionLabel = "View";
|
|
1769
|
+
values.splice(actionIndex, 1);
|
|
1770
|
+
}
|
|
1771
|
+
const remaining = values.slice(1);
|
|
1772
|
+
if (remaining.length > 0) {
|
|
1773
|
+
if (remaining[0].length <= 50) {
|
|
1774
|
+
result.subtitle = remaining[0];
|
|
1775
|
+
remaining.shift();
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
if (remaining.length > 0) {
|
|
1779
|
+
result.description = remaining[0];
|
|
1780
|
+
remaining.shift();
|
|
1781
|
+
}
|
|
1782
|
+
result.extraValues = remaining;
|
|
1783
|
+
return result;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
// src/components/WebsiteChatbot.tsx
|
|
1702
1787
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1703
1788
|
var defaultTheme3 = {
|
|
1704
1789
|
primaryColor: "#f59e0b",
|
|
@@ -1708,6 +1793,167 @@ var defaultTheme3 = {
|
|
|
1708
1793
|
borderRadius: "12px",
|
|
1709
1794
|
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
1710
1795
|
};
|
|
1796
|
+
function ChatCard({ card, theme }) {
|
|
1797
|
+
const data = extractCardDisplayData(card);
|
|
1798
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1799
|
+
"div",
|
|
1800
|
+
{
|
|
1801
|
+
style: {
|
|
1802
|
+
border: "1px solid #e5e7eb",
|
|
1803
|
+
borderRadius: "8px",
|
|
1804
|
+
overflow: "hidden",
|
|
1805
|
+
backgroundColor: "#fff",
|
|
1806
|
+
marginTop: "8px",
|
|
1807
|
+
marginBottom: "8px"
|
|
1808
|
+
},
|
|
1809
|
+
children: [
|
|
1810
|
+
data.imageUrl && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1811
|
+
"div",
|
|
1812
|
+
{
|
|
1813
|
+
style: {
|
|
1814
|
+
width: "100%",
|
|
1815
|
+
height: "140px",
|
|
1816
|
+
backgroundColor: "#f3f4f6",
|
|
1817
|
+
overflow: "hidden"
|
|
1818
|
+
},
|
|
1819
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1820
|
+
"img",
|
|
1821
|
+
{
|
|
1822
|
+
src: data.imageUrl,
|
|
1823
|
+
alt: data.title,
|
|
1824
|
+
style: {
|
|
1825
|
+
width: "100%",
|
|
1826
|
+
height: "100%",
|
|
1827
|
+
objectFit: "cover"
|
|
1828
|
+
},
|
|
1829
|
+
onError: (e) => {
|
|
1830
|
+
e.target.style.display = "none";
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
)
|
|
1834
|
+
}
|
|
1835
|
+
),
|
|
1836
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { padding: "12px" }, children: [
|
|
1837
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1838
|
+
"div",
|
|
1839
|
+
{
|
|
1840
|
+
style: {
|
|
1841
|
+
display: "inline-block",
|
|
1842
|
+
fontSize: "10px",
|
|
1843
|
+
fontWeight: 600,
|
|
1844
|
+
textTransform: "uppercase",
|
|
1845
|
+
letterSpacing: "0.5px",
|
|
1846
|
+
color: theme.primaryColor,
|
|
1847
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
1848
|
+
padding: "2px 6px",
|
|
1849
|
+
borderRadius: "4px",
|
|
1850
|
+
marginBottom: "6px"
|
|
1851
|
+
},
|
|
1852
|
+
children: card.type
|
|
1853
|
+
}
|
|
1854
|
+
),
|
|
1855
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1856
|
+
"div",
|
|
1857
|
+
{
|
|
1858
|
+
style: {
|
|
1859
|
+
fontSize: "15px",
|
|
1860
|
+
fontWeight: 600,
|
|
1861
|
+
color: "#1f2937",
|
|
1862
|
+
marginBottom: "4px",
|
|
1863
|
+
lineHeight: "1.3"
|
|
1864
|
+
},
|
|
1865
|
+
children: data.title
|
|
1866
|
+
}
|
|
1867
|
+
),
|
|
1868
|
+
data.subtitle && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1869
|
+
"div",
|
|
1870
|
+
{
|
|
1871
|
+
style: {
|
|
1872
|
+
fontSize: "13px",
|
|
1873
|
+
color: "#6b7280",
|
|
1874
|
+
marginBottom: "6px"
|
|
1875
|
+
},
|
|
1876
|
+
children: data.subtitle
|
|
1877
|
+
}
|
|
1878
|
+
),
|
|
1879
|
+
data.description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1880
|
+
"div",
|
|
1881
|
+
{
|
|
1882
|
+
style: {
|
|
1883
|
+
fontSize: "13px",
|
|
1884
|
+
color: "#4b5563",
|
|
1885
|
+
lineHeight: "1.4",
|
|
1886
|
+
marginBottom: "8px"
|
|
1887
|
+
},
|
|
1888
|
+
children: data.description
|
|
1889
|
+
}
|
|
1890
|
+
),
|
|
1891
|
+
data.extraValues.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1892
|
+
"div",
|
|
1893
|
+
{
|
|
1894
|
+
style: {
|
|
1895
|
+
fontSize: "12px",
|
|
1896
|
+
color: "#6b7280",
|
|
1897
|
+
marginBottom: "8px"
|
|
1898
|
+
},
|
|
1899
|
+
children: data.extraValues.join(" \u2022 ")
|
|
1900
|
+
}
|
|
1901
|
+
),
|
|
1902
|
+
data.actionUrl && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1903
|
+
"a",
|
|
1904
|
+
{
|
|
1905
|
+
href: data.actionUrl,
|
|
1906
|
+
target: "_blank",
|
|
1907
|
+
rel: "noopener noreferrer",
|
|
1908
|
+
style: {
|
|
1909
|
+
display: "inline-flex",
|
|
1910
|
+
alignItems: "center",
|
|
1911
|
+
gap: "4px",
|
|
1912
|
+
fontSize: "13px",
|
|
1913
|
+
fontWeight: 500,
|
|
1914
|
+
color: theme.primaryColor,
|
|
1915
|
+
textDecoration: "none",
|
|
1916
|
+
padding: "6px 12px",
|
|
1917
|
+
borderRadius: "6px",
|
|
1918
|
+
backgroundColor: `${theme.primaryColor}10`,
|
|
1919
|
+
transition: "background-color 0.2s"
|
|
1920
|
+
},
|
|
1921
|
+
onMouseEnter: (e) => {
|
|
1922
|
+
e.currentTarget.style.backgroundColor = `${theme.primaryColor}20`;
|
|
1923
|
+
},
|
|
1924
|
+
onMouseLeave: (e) => {
|
|
1925
|
+
e.currentTarget.style.backgroundColor = `${theme.primaryColor}10`;
|
|
1926
|
+
},
|
|
1927
|
+
children: [
|
|
1928
|
+
data.actionLabel || "View",
|
|
1929
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
1930
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
|
|
1931
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("polyline", { points: "15 3 21 3 21 9" }),
|
|
1932
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "10", y1: "14", x2: "21", y2: "3" })
|
|
1933
|
+
] })
|
|
1934
|
+
]
|
|
1935
|
+
}
|
|
1936
|
+
)
|
|
1937
|
+
] })
|
|
1938
|
+
]
|
|
1939
|
+
}
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
function MessageContent({ content, theme }) {
|
|
1943
|
+
const segments = parseMessageContent(content);
|
|
1944
|
+
if (segments.length === 1 && segments[0].type === "text") {
|
|
1945
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: segments[0].content });
|
|
1946
|
+
}
|
|
1947
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: segments.map((segment, index) => {
|
|
1948
|
+
if (segment.type === "text") {
|
|
1949
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { whiteSpace: "pre-wrap" }, children: segment.content }, index);
|
|
1950
|
+
}
|
|
1951
|
+
if (segment.type === "card" && segment.card) {
|
|
1952
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChatCard, { card: segment.card, theme }, index);
|
|
1953
|
+
}
|
|
1954
|
+
return null;
|
|
1955
|
+
}) });
|
|
1956
|
+
}
|
|
1711
1957
|
function WebsiteChatbot({ className, ...config }) {
|
|
1712
1958
|
const theme = { ...defaultTheme3, ...config.theme };
|
|
1713
1959
|
const apiUrl = config.apiUrl || "https://api.informedai.app/api/v1";
|
|
@@ -1729,13 +1975,12 @@ function WebsiteChatbot({ className, ...config }) {
|
|
|
1729
1975
|
const newMessages = [...messages, { role: "user", content: message }];
|
|
1730
1976
|
setMessages(newMessages);
|
|
1731
1977
|
try {
|
|
1732
|
-
const response = await fetch(`${apiUrl}/website-agent/message`, {
|
|
1978
|
+
const response = await fetch(`${apiUrl}/website-agent/${config.agentId}/message`, {
|
|
1733
1979
|
method: "POST",
|
|
1734
1980
|
headers: {
|
|
1735
1981
|
"Content-Type": "application/json"
|
|
1736
1982
|
},
|
|
1737
1983
|
body: JSON.stringify({
|
|
1738
|
-
agentId: config.agentId,
|
|
1739
1984
|
message,
|
|
1740
1985
|
history: messages
|
|
1741
1986
|
})
|
|
@@ -1955,10 +2200,9 @@ function WebsiteChatbot({ className, ...config }) {
|
|
|
1955
2200
|
backgroundColor: msg.role === "user" ? "var(--wc-primary)" : "#f3f4f6",
|
|
1956
2201
|
color: msg.role === "user" ? "white" : "var(--wc-text)",
|
|
1957
2202
|
fontSize: "14px",
|
|
1958
|
-
lineHeight: "1.5"
|
|
1959
|
-
whiteSpace: "pre-wrap"
|
|
2203
|
+
lineHeight: "1.5"
|
|
1960
2204
|
},
|
|
1961
|
-
children: msg.content
|
|
2205
|
+
children: msg.role === "user" ? msg.content : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MessageContent, { content: msg.content, theme })
|
|
1962
2206
|
}
|
|
1963
2207
|
)
|
|
1964
2208
|
},
|
|
@@ -1973,11 +2217,10 @@ function WebsiteChatbot({ className, ...config }) {
|
|
|
1973
2217
|
backgroundColor: "#f3f4f6",
|
|
1974
2218
|
color: "var(--wc-text)",
|
|
1975
2219
|
fontSize: "14px",
|
|
1976
|
-
lineHeight: "1.5"
|
|
1977
|
-
whiteSpace: "pre-wrap"
|
|
2220
|
+
lineHeight: "1.5"
|
|
1978
2221
|
},
|
|
1979
2222
|
children: [
|
|
1980
|
-
streamingContent,
|
|
2223
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MessageContent, { content: streamingContent, theme }),
|
|
1981
2224
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: { opacity: 0.5, animation: "blink 1s infinite" }, children: "|" })
|
|
1982
2225
|
]
|
|
1983
2226
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1667,7 +1667,92 @@ function AdminChatbot({ className, ...config }) {
|
|
|
1667
1667
|
|
|
1668
1668
|
// src/components/WebsiteChatbot.tsx
|
|
1669
1669
|
import { useState as useState4, useRef as useRef4, useEffect as useEffect4 } from "react";
|
|
1670
|
-
|
|
1670
|
+
|
|
1671
|
+
// src/utils/card-parser.ts
|
|
1672
|
+
var CARD_MARKER_REGEX = /\[([A-Z][A-Z0-9_]*):([^\]]+)\]/g;
|
|
1673
|
+
function parseCardMarker(marker) {
|
|
1674
|
+
const match = marker.match(/^\[([A-Z][A-Z0-9_]*):([^\]]+)\]$/);
|
|
1675
|
+
if (!match) return null;
|
|
1676
|
+
const [, type, valuesStr] = match;
|
|
1677
|
+
const values = valuesStr.split("|").map((v) => v.trim());
|
|
1678
|
+
return {
|
|
1679
|
+
type,
|
|
1680
|
+
values,
|
|
1681
|
+
originalMarker: marker
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
function parseMessageContent(content) {
|
|
1685
|
+
const segments = [];
|
|
1686
|
+
let lastIndex = 0;
|
|
1687
|
+
const matches = [...content.matchAll(CARD_MARKER_REGEX)];
|
|
1688
|
+
for (const match of matches) {
|
|
1689
|
+
const marker = match[0];
|
|
1690
|
+
const startIndex = match.index;
|
|
1691
|
+
if (startIndex > lastIndex) {
|
|
1692
|
+
const text = content.slice(lastIndex, startIndex).trim();
|
|
1693
|
+
if (text) {
|
|
1694
|
+
segments.push({ type: "text", content: text });
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
const card = parseCardMarker(marker);
|
|
1698
|
+
if (card) {
|
|
1699
|
+
segments.push({ type: "card", card });
|
|
1700
|
+
}
|
|
1701
|
+
lastIndex = startIndex + marker.length;
|
|
1702
|
+
}
|
|
1703
|
+
if (lastIndex < content.length) {
|
|
1704
|
+
const text = content.slice(lastIndex).trim();
|
|
1705
|
+
if (text) {
|
|
1706
|
+
segments.push({ type: "text", content: text });
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
if (segments.length === 0 && content.trim()) {
|
|
1710
|
+
segments.push({ type: "text", content: content.trim() });
|
|
1711
|
+
}
|
|
1712
|
+
return segments;
|
|
1713
|
+
}
|
|
1714
|
+
function isUrl(str) {
|
|
1715
|
+
return /^https?:\/\//i.test(str);
|
|
1716
|
+
}
|
|
1717
|
+
function isImageUrl(url) {
|
|
1718
|
+
if (!isUrl(url)) return false;
|
|
1719
|
+
return /\.(jpg|jpeg|png|gif|webp|svg)(\?|$)/i.test(url);
|
|
1720
|
+
}
|
|
1721
|
+
function extractCardDisplayData(card) {
|
|
1722
|
+
const values = [...card.values];
|
|
1723
|
+
const result = {
|
|
1724
|
+
title: values[0] || card.type,
|
|
1725
|
+
extraValues: []
|
|
1726
|
+
};
|
|
1727
|
+
if (values.length <= 1) return result;
|
|
1728
|
+
const imageIndex = values.findIndex((v, i) => i > 0 && isImageUrl(v));
|
|
1729
|
+
if (imageIndex > 0) {
|
|
1730
|
+
result.imageUrl = values[imageIndex];
|
|
1731
|
+
values.splice(imageIndex, 1);
|
|
1732
|
+
}
|
|
1733
|
+
const actionIndex = values.findIndex((v, i) => i > 0 && isUrl(v) && !isImageUrl(v));
|
|
1734
|
+
if (actionIndex > 0) {
|
|
1735
|
+
result.actionUrl = values[actionIndex];
|
|
1736
|
+
result.actionLabel = "View";
|
|
1737
|
+
values.splice(actionIndex, 1);
|
|
1738
|
+
}
|
|
1739
|
+
const remaining = values.slice(1);
|
|
1740
|
+
if (remaining.length > 0) {
|
|
1741
|
+
if (remaining[0].length <= 50) {
|
|
1742
|
+
result.subtitle = remaining[0];
|
|
1743
|
+
remaining.shift();
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
if (remaining.length > 0) {
|
|
1747
|
+
result.description = remaining[0];
|
|
1748
|
+
remaining.shift();
|
|
1749
|
+
}
|
|
1750
|
+
result.extraValues = remaining;
|
|
1751
|
+
return result;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// src/components/WebsiteChatbot.tsx
|
|
1755
|
+
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1671
1756
|
var defaultTheme3 = {
|
|
1672
1757
|
primaryColor: "#f59e0b",
|
|
1673
1758
|
// Amber
|
|
@@ -1676,6 +1761,167 @@ var defaultTheme3 = {
|
|
|
1676
1761
|
borderRadius: "12px",
|
|
1677
1762
|
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
1678
1763
|
};
|
|
1764
|
+
function ChatCard({ card, theme }) {
|
|
1765
|
+
const data = extractCardDisplayData(card);
|
|
1766
|
+
return /* @__PURE__ */ jsxs3(
|
|
1767
|
+
"div",
|
|
1768
|
+
{
|
|
1769
|
+
style: {
|
|
1770
|
+
border: "1px solid #e5e7eb",
|
|
1771
|
+
borderRadius: "8px",
|
|
1772
|
+
overflow: "hidden",
|
|
1773
|
+
backgroundColor: "#fff",
|
|
1774
|
+
marginTop: "8px",
|
|
1775
|
+
marginBottom: "8px"
|
|
1776
|
+
},
|
|
1777
|
+
children: [
|
|
1778
|
+
data.imageUrl && /* @__PURE__ */ jsx4(
|
|
1779
|
+
"div",
|
|
1780
|
+
{
|
|
1781
|
+
style: {
|
|
1782
|
+
width: "100%",
|
|
1783
|
+
height: "140px",
|
|
1784
|
+
backgroundColor: "#f3f4f6",
|
|
1785
|
+
overflow: "hidden"
|
|
1786
|
+
},
|
|
1787
|
+
children: /* @__PURE__ */ jsx4(
|
|
1788
|
+
"img",
|
|
1789
|
+
{
|
|
1790
|
+
src: data.imageUrl,
|
|
1791
|
+
alt: data.title,
|
|
1792
|
+
style: {
|
|
1793
|
+
width: "100%",
|
|
1794
|
+
height: "100%",
|
|
1795
|
+
objectFit: "cover"
|
|
1796
|
+
},
|
|
1797
|
+
onError: (e) => {
|
|
1798
|
+
e.target.style.display = "none";
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
)
|
|
1802
|
+
}
|
|
1803
|
+
),
|
|
1804
|
+
/* @__PURE__ */ jsxs3("div", { style: { padding: "12px" }, children: [
|
|
1805
|
+
/* @__PURE__ */ jsx4(
|
|
1806
|
+
"div",
|
|
1807
|
+
{
|
|
1808
|
+
style: {
|
|
1809
|
+
display: "inline-block",
|
|
1810
|
+
fontSize: "10px",
|
|
1811
|
+
fontWeight: 600,
|
|
1812
|
+
textTransform: "uppercase",
|
|
1813
|
+
letterSpacing: "0.5px",
|
|
1814
|
+
color: theme.primaryColor,
|
|
1815
|
+
backgroundColor: `${theme.primaryColor}15`,
|
|
1816
|
+
padding: "2px 6px",
|
|
1817
|
+
borderRadius: "4px",
|
|
1818
|
+
marginBottom: "6px"
|
|
1819
|
+
},
|
|
1820
|
+
children: card.type
|
|
1821
|
+
}
|
|
1822
|
+
),
|
|
1823
|
+
/* @__PURE__ */ jsx4(
|
|
1824
|
+
"div",
|
|
1825
|
+
{
|
|
1826
|
+
style: {
|
|
1827
|
+
fontSize: "15px",
|
|
1828
|
+
fontWeight: 600,
|
|
1829
|
+
color: "#1f2937",
|
|
1830
|
+
marginBottom: "4px",
|
|
1831
|
+
lineHeight: "1.3"
|
|
1832
|
+
},
|
|
1833
|
+
children: data.title
|
|
1834
|
+
}
|
|
1835
|
+
),
|
|
1836
|
+
data.subtitle && /* @__PURE__ */ jsx4(
|
|
1837
|
+
"div",
|
|
1838
|
+
{
|
|
1839
|
+
style: {
|
|
1840
|
+
fontSize: "13px",
|
|
1841
|
+
color: "#6b7280",
|
|
1842
|
+
marginBottom: "6px"
|
|
1843
|
+
},
|
|
1844
|
+
children: data.subtitle
|
|
1845
|
+
}
|
|
1846
|
+
),
|
|
1847
|
+
data.description && /* @__PURE__ */ jsx4(
|
|
1848
|
+
"div",
|
|
1849
|
+
{
|
|
1850
|
+
style: {
|
|
1851
|
+
fontSize: "13px",
|
|
1852
|
+
color: "#4b5563",
|
|
1853
|
+
lineHeight: "1.4",
|
|
1854
|
+
marginBottom: "8px"
|
|
1855
|
+
},
|
|
1856
|
+
children: data.description
|
|
1857
|
+
}
|
|
1858
|
+
),
|
|
1859
|
+
data.extraValues.length > 0 && /* @__PURE__ */ jsx4(
|
|
1860
|
+
"div",
|
|
1861
|
+
{
|
|
1862
|
+
style: {
|
|
1863
|
+
fontSize: "12px",
|
|
1864
|
+
color: "#6b7280",
|
|
1865
|
+
marginBottom: "8px"
|
|
1866
|
+
},
|
|
1867
|
+
children: data.extraValues.join(" \u2022 ")
|
|
1868
|
+
}
|
|
1869
|
+
),
|
|
1870
|
+
data.actionUrl && /* @__PURE__ */ jsxs3(
|
|
1871
|
+
"a",
|
|
1872
|
+
{
|
|
1873
|
+
href: data.actionUrl,
|
|
1874
|
+
target: "_blank",
|
|
1875
|
+
rel: "noopener noreferrer",
|
|
1876
|
+
style: {
|
|
1877
|
+
display: "inline-flex",
|
|
1878
|
+
alignItems: "center",
|
|
1879
|
+
gap: "4px",
|
|
1880
|
+
fontSize: "13px",
|
|
1881
|
+
fontWeight: 500,
|
|
1882
|
+
color: theme.primaryColor,
|
|
1883
|
+
textDecoration: "none",
|
|
1884
|
+
padding: "6px 12px",
|
|
1885
|
+
borderRadius: "6px",
|
|
1886
|
+
backgroundColor: `${theme.primaryColor}10`,
|
|
1887
|
+
transition: "background-color 0.2s"
|
|
1888
|
+
},
|
|
1889
|
+
onMouseEnter: (e) => {
|
|
1890
|
+
e.currentTarget.style.backgroundColor = `${theme.primaryColor}20`;
|
|
1891
|
+
},
|
|
1892
|
+
onMouseLeave: (e) => {
|
|
1893
|
+
e.currentTarget.style.backgroundColor = `${theme.primaryColor}10`;
|
|
1894
|
+
},
|
|
1895
|
+
children: [
|
|
1896
|
+
data.actionLabel || "View",
|
|
1897
|
+
/* @__PURE__ */ jsxs3("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
1898
|
+
/* @__PURE__ */ jsx4("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" }),
|
|
1899
|
+
/* @__PURE__ */ jsx4("polyline", { points: "15 3 21 3 21 9" }),
|
|
1900
|
+
/* @__PURE__ */ jsx4("line", { x1: "10", y1: "14", x2: "21", y2: "3" })
|
|
1901
|
+
] })
|
|
1902
|
+
]
|
|
1903
|
+
}
|
|
1904
|
+
)
|
|
1905
|
+
] })
|
|
1906
|
+
]
|
|
1907
|
+
}
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
function MessageContent({ content, theme }) {
|
|
1911
|
+
const segments = parseMessageContent(content);
|
|
1912
|
+
if (segments.length === 1 && segments[0].type === "text") {
|
|
1913
|
+
return /* @__PURE__ */ jsx4(Fragment2, { children: segments[0].content });
|
|
1914
|
+
}
|
|
1915
|
+
return /* @__PURE__ */ jsx4(Fragment2, { children: segments.map((segment, index) => {
|
|
1916
|
+
if (segment.type === "text") {
|
|
1917
|
+
return /* @__PURE__ */ jsx4("span", { style: { whiteSpace: "pre-wrap" }, children: segment.content }, index);
|
|
1918
|
+
}
|
|
1919
|
+
if (segment.type === "card" && segment.card) {
|
|
1920
|
+
return /* @__PURE__ */ jsx4(ChatCard, { card: segment.card, theme }, index);
|
|
1921
|
+
}
|
|
1922
|
+
return null;
|
|
1923
|
+
}) });
|
|
1924
|
+
}
|
|
1679
1925
|
function WebsiteChatbot({ className, ...config }) {
|
|
1680
1926
|
const theme = { ...defaultTheme3, ...config.theme };
|
|
1681
1927
|
const apiUrl = config.apiUrl || "https://api.informedai.app/api/v1";
|
|
@@ -1697,13 +1943,12 @@ function WebsiteChatbot({ className, ...config }) {
|
|
|
1697
1943
|
const newMessages = [...messages, { role: "user", content: message }];
|
|
1698
1944
|
setMessages(newMessages);
|
|
1699
1945
|
try {
|
|
1700
|
-
const response = await fetch(`${apiUrl}/website-agent/message`, {
|
|
1946
|
+
const response = await fetch(`${apiUrl}/website-agent/${config.agentId}/message`, {
|
|
1701
1947
|
method: "POST",
|
|
1702
1948
|
headers: {
|
|
1703
1949
|
"Content-Type": "application/json"
|
|
1704
1950
|
},
|
|
1705
1951
|
body: JSON.stringify({
|
|
1706
|
-
agentId: config.agentId,
|
|
1707
1952
|
message,
|
|
1708
1953
|
history: messages
|
|
1709
1954
|
})
|
|
@@ -1923,10 +2168,9 @@ function WebsiteChatbot({ className, ...config }) {
|
|
|
1923
2168
|
backgroundColor: msg.role === "user" ? "var(--wc-primary)" : "#f3f4f6",
|
|
1924
2169
|
color: msg.role === "user" ? "white" : "var(--wc-text)",
|
|
1925
2170
|
fontSize: "14px",
|
|
1926
|
-
lineHeight: "1.5"
|
|
1927
|
-
whiteSpace: "pre-wrap"
|
|
2171
|
+
lineHeight: "1.5"
|
|
1928
2172
|
},
|
|
1929
|
-
children: msg.content
|
|
2173
|
+
children: msg.role === "user" ? msg.content : /* @__PURE__ */ jsx4(MessageContent, { content: msg.content, theme })
|
|
1930
2174
|
}
|
|
1931
2175
|
)
|
|
1932
2176
|
},
|
|
@@ -1941,11 +2185,10 @@ function WebsiteChatbot({ className, ...config }) {
|
|
|
1941
2185
|
backgroundColor: "#f3f4f6",
|
|
1942
2186
|
color: "var(--wc-text)",
|
|
1943
2187
|
fontSize: "14px",
|
|
1944
|
-
lineHeight: "1.5"
|
|
1945
|
-
whiteSpace: "pre-wrap"
|
|
2188
|
+
lineHeight: "1.5"
|
|
1946
2189
|
},
|
|
1947
2190
|
children: [
|
|
1948
|
-
streamingContent,
|
|
2191
|
+
/* @__PURE__ */ jsx4(MessageContent, { content: streamingContent, theme }),
|
|
1949
2192
|
/* @__PURE__ */ jsx4("span", { style: { opacity: 0.5, animation: "blink 1s infinite" }, children: "|" })
|
|
1950
2193
|
]
|
|
1951
2194
|
}
|