@akropolys/kiku 1.5.5 → 1.5.8

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.mjs CHANGED
@@ -1453,19 +1453,95 @@ var getFriendlyError = (err) => {
1453
1453
  return str;
1454
1454
  }
1455
1455
  };
1456
- var LOADING_MESSAGES = [
1457
- "Walking down the aisle...",
1458
- "Consulting the blueprints...",
1459
- "Polishing the keys...",
1460
- "Checking the backyard...",
1461
- "Checking the inventory...",
1462
- "Inspecting the plumbing...",
1463
- "Asking the concierge...",
1464
- "Searching the shelves...",
1465
- "Measuring the square footage...",
1466
- "Dusting off the fireplace...",
1467
- "Asking the store clerk..."
1468
- ];
1456
+ function parseThinking(text) {
1457
+ const openMatch = text.match(/<\s*thinking\s*>/i);
1458
+ if (!openMatch) {
1459
+ return { thinking: "", content: text, isComplete: true };
1460
+ }
1461
+ const openIdx = openMatch.index ?? 0;
1462
+ const openTagLength = openMatch[0].length;
1463
+ const start = openIdx + openTagLength;
1464
+ const contentBefore = text.slice(0, openIdx);
1465
+ const textAfterOpen = text.slice(start);
1466
+ const closeMatch = textAfterOpen.match(/<\/\s*thinking\s*>/i);
1467
+ if (!closeMatch) {
1468
+ return {
1469
+ thinking: textAfterOpen,
1470
+ content: contentBefore,
1471
+ isComplete: false
1472
+ };
1473
+ }
1474
+ const closeIdx = closeMatch.index ?? 0;
1475
+ const closeTagLength = closeMatch[0].length;
1476
+ return {
1477
+ thinking: textAfterOpen.slice(0, closeIdx),
1478
+ content: contentBefore + textAfterOpen.slice(closeIdx + closeTagLength),
1479
+ isComplete: true
1480
+ };
1481
+ }
1482
+ function ThinkingBlock({ text, isComplete }) {
1483
+ const [isOpen, setIsOpen] = useState5(true);
1484
+ useEffect3(() => {
1485
+ if (!isComplete) {
1486
+ setIsOpen(true);
1487
+ }
1488
+ }, [isComplete]);
1489
+ return /* @__PURE__ */ jsxs6("div", { style: {
1490
+ marginBottom: "12px",
1491
+ borderLeft: "2px solid #e4e4e7",
1492
+ paddingLeft: "10px",
1493
+ fontSize: "0.825rem",
1494
+ backgroundColor: "rgba(244, 244, 245, 0.4)",
1495
+ padding: "8px 10px",
1496
+ borderRadius: "0 6px 6px 0"
1497
+ }, children: [
1498
+ /* @__PURE__ */ jsxs6(
1499
+ "div",
1500
+ {
1501
+ onClick: () => setIsOpen(!isOpen),
1502
+ style: {
1503
+ display: "flex",
1504
+ alignItems: "center",
1505
+ gap: "6px",
1506
+ color: "#71717a",
1507
+ cursor: "pointer",
1508
+ fontWeight: 500,
1509
+ userSelect: "none"
1510
+ },
1511
+ children: [
1512
+ /* @__PURE__ */ jsxs6("span", { style: { display: "flex", alignItems: "center", gap: "4px" }, children: [
1513
+ /* @__PURE__ */ jsxs6("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", style: { animation: !isComplete ? "spin 3s linear infinite" : "none" }, children: [
1514
+ /* @__PURE__ */ jsx7("circle", { cx: "12", cy: "12", r: "10" }),
1515
+ /* @__PURE__ */ jsx7("path", { d: "M12 6v6l4 2" })
1516
+ ] }),
1517
+ "Thinking Process"
1518
+ ] }),
1519
+ !isComplete && /* @__PURE__ */ jsx7("span", { style: {
1520
+ width: "6px",
1521
+ height: "6px",
1522
+ borderRadius: "50%",
1523
+ backgroundColor: "#3b82f6",
1524
+ display: "inline-block",
1525
+ animation: "hsk-pulse 1.2s infinite ease-in-out"
1526
+ } }),
1527
+ /* @__PURE__ */ jsx7("span", { style: {
1528
+ fontSize: "0.7rem",
1529
+ marginLeft: "auto",
1530
+ transform: isOpen ? "rotate(90deg)" : "none",
1531
+ transition: "transform 0.1s"
1532
+ }, children: "\u25B6" })
1533
+ ]
1534
+ }
1535
+ ),
1536
+ isOpen && /* @__PURE__ */ jsx7("div", { style: {
1537
+ marginTop: "6px",
1538
+ color: "#52525b",
1539
+ whiteSpace: "pre-wrap",
1540
+ lineHeight: "1.4",
1541
+ fontStyle: "italic"
1542
+ }, children: text })
1543
+ ] });
1544
+ }
1469
1545
  var PROPERTY_CHIPS = [
1470
1546
  "3 bedroom apartments",
1471
1547
  "Houses under KSh 5,000,000",
@@ -1490,7 +1566,6 @@ function ChatModal({
1490
1566
  const client = useAkropolysContext3();
1491
1567
  const { messages, sources, loading, streaming, error, lastAction, lastIntent, send, reset, referencedIds } = useKiku2();
1492
1568
  const [input, setInput] = useState5("");
1493
- const [loadingMessageIndex, setLoadingMessageIndex] = useState5(0);
1494
1569
  const [attachments, setAttachments] = useState5([]);
1495
1570
  const imageInputRef = useRef5(null);
1496
1571
  const handleImageFiles = (files) => {
@@ -1546,16 +1621,6 @@ function ChatModal({
1546
1621
  const activeChips = chips === DEFAULT_CHIPS && isProperty ? PROPERTY_CHIPS : chips;
1547
1622
  const activeTitle = title === "Shopping Assistant" && isProperty ? "Property Assistant" : title;
1548
1623
  const activePlaceholder = placeholder === "Ask me anything \u2014 gifts, budget, use case\u2026" && isProperty ? "Ask me anything \u2014 location, budget, bedrooms\u2026" : placeholder;
1549
- useEffect3(() => {
1550
- if (loading && !streaming) {
1551
- const interval = setInterval(() => {
1552
- setLoadingMessageIndex((prev) => (prev + 1) % LOADING_MESSAGES.length);
1553
- }, 1500);
1554
- return () => clearInterval(interval);
1555
- } else {
1556
- setLoadingMessageIndex(0);
1557
- }
1558
- }, [loading, streaming]);
1559
1624
  const [selectedProduct, setSelectedProduct] = useState5(null);
1560
1625
  const bottomRef = useRef5(null);
1561
1626
  const textareaRef = useRef5(null);
@@ -1826,7 +1891,13 @@ function ChatModal({
1826
1891
  ] }) : /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-ai-msg", children: [
1827
1892
  /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx7(SparkleIcon2, {}) }),
1828
1893
  /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-ai-body", children: [
1829
- /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-text", children: renderMarkdown(displayContent) }),
1894
+ (() => {
1895
+ const { thinking, content, isComplete } = parseThinking(displayContent);
1896
+ return /* @__PURE__ */ jsxs6(Fragment3, { children: [
1897
+ thinking && /* @__PURE__ */ jsx7(ThinkingBlock, { text: thinking, isComplete }),
1898
+ content && /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-text", children: renderMarkdown(content) })
1899
+ ] });
1900
+ })(),
1830
1901
  isLast && lastIntent === "compare" && sources.length >= 2 && !replayMessages && /* @__PURE__ */ jsx7(ComparisonMatrix, { sources, defaultCurrency }),
1831
1902
  isLast && sources.length > 0 && lastIntent !== "compare" && lastAction?.type !== "request_phone" && lastAction?.type !== "awaiting_payment" && lastAction?.type !== "checkout" && !msg.cartSnapshot && /* @__PURE__ */ jsx7(
1832
1903
  SourcesCarousel,
@@ -1892,7 +1963,7 @@ function ChatModal({
1892
1963
  50% { opacity: 1; }
1893
1964
  }
1894
1965
  ` }),
1895
- /* @__PURE__ */ jsx7("div", { style: { fontSize: "0.85rem", color: "#6b7280", fontStyle: "italic", animation: "hsk-pulse 1.5s infinite ease-in-out" }, children: LOADING_MESSAGES[loadingMessageIndex] }),
1966
+ /* @__PURE__ */ jsx7("div", { style: { fontSize: "0.85rem", color: "#6b7280", fontStyle: "italic", animation: "hsk-pulse 1.5s infinite ease-in-out" }, children: isProperty ? "Analyzing listings..." : "Searching catalog..." }),
1896
1967
  /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-typing", style: { margin: 0, alignSelf: "flex-start" }, children: [
1897
1968
  /* @__PURE__ */ jsx7("div", { className: "hsk-cb-dot" }),
1898
1969
  /* @__PURE__ */ jsx7("div", { className: "hsk-cb-dot" }),