@akropolys/kiku 1.5.14 → 1.5.17

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
@@ -653,7 +653,7 @@ I couldn't find any matching products in the store.`;
653
653
  }) }) });
654
654
  }
655
655
  const featured = sources.filter((src) => src.id && referencedIds.includes(src.id));
656
- const general = sources.filter((src) => !src.id || !referencedIds.includes(src.id));
656
+ const general = featured.length > 0 ? [] : sources.filter((src) => !src.id || !referencedIds.includes(src.id));
657
657
  return /* @__PURE__ */ jsxs4("div", { className: "hsk-sources-container", children: [
658
658
  featured.length > 0 && /* @__PURE__ */ jsxs4("div", { className: "hsk-sources-group", style: { marginBottom: "10px" }, children: [
659
659
  /* @__PURE__ */ jsx5("div", { className: "hsk-sources-group-title", children: "\u2B50 Featured in response" }),
@@ -1324,8 +1324,10 @@ function SourcesCarousel({ sources, defaultCurrency, onSelectSource, referencedI
1324
1324
  const scrollNext = () => {
1325
1325
  railRef.current?.scrollBy({ left: 170, behavior: "smooth" });
1326
1326
  };
1327
+ const referenced = sources.filter((s) => s.id && referencedIds.includes(s.id));
1328
+ const display = referenced.length > 0 ? referenced : sources;
1327
1329
  return /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-sources-wrap", children: [
1328
- /* @__PURE__ */ jsx7("div", { className: "hsk-cb-sources", ref: railRef, children: sources.map((src, si) => {
1330
+ /* @__PURE__ */ jsx7("div", { className: "hsk-cb-sources", ref: railRef, children: display.map((src, si) => {
1329
1331
  const isReferenced = !!(src.id && referencedIds.includes(src.id));
1330
1332
  return /* @__PURE__ */ jsxs6(
1331
1333
  "div",
@@ -1505,6 +1507,18 @@ var getFriendlyError = (err) => {
1505
1507
  return str;
1506
1508
  }
1507
1509
  };
1510
+ var MK_ADJ = ["flying", "silent", "golden", "lucky", "brave", "swift", "royal", "cosmic"];
1511
+ var MK_NOUN = ["thunder", "falcon", "river", "ember", "tiger", "comet", "willow", "onyx"];
1512
+ function generateMagicWord() {
1513
+ return MK_ADJ[Math.floor(Math.random() * MK_ADJ.length)] + MK_NOUN[Math.floor(Math.random() * MK_NOUN.length)];
1514
+ }
1515
+ function parseMemoryKey(raw) {
1516
+ const cleaned = raw.trim().replace(/\s+/g, "");
1517
+ const m = cleaned.match(/^(\d{6,})([a-zA-Z].*)?$/);
1518
+ const phone = m?.[1] || cleaned.replace(/\D/g, "");
1519
+ const word = (m?.[2] || "").toLowerCase() || generateMagicWord();
1520
+ return { phone, word };
1521
+ }
1508
1522
  function parseThinking(text) {
1509
1523
  const openMatch = text.match(/<\s*thinking\s*>/i);
1510
1524
  if (!openMatch) {
@@ -1646,17 +1660,34 @@ function ChatModal({
1646
1660
  const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
1647
1661
  const recognition = new SR();
1648
1662
  recognition.lang = "en-US";
1649
- recognition.interimResults = false;
1663
+ recognition.interimResults = true;
1650
1664
  recognition.maxAlternatives = 1;
1651
1665
  recognitionRef.current = recognition;
1652
1666
  recognition.onstart = () => setVoiceState("listening");
1653
1667
  recognition.onresult = (event) => {
1654
- const transcript = event.results[0][0].transcript;
1655
- setInput(transcript);
1656
- pendingVoiceRef.current = transcript;
1657
- setVoiceState("processing");
1668
+ let finalText = "";
1669
+ let interimText = "";
1670
+ for (let i = 0; i < event.results.length; i++) {
1671
+ const seg = event.results[i][0].transcript;
1672
+ if (event.results[i].isFinal) finalText += seg;
1673
+ else interimText += seg;
1674
+ }
1675
+ const live = (finalText + " " + interimText).trim();
1676
+ if (live) setInput(live);
1677
+ if (finalText.trim()) {
1678
+ pendingVoiceRef.current = finalText.trim();
1679
+ setVoiceState("processing");
1680
+ }
1681
+ };
1682
+ recognition.onerror = (event) => {
1683
+ const err = event?.error;
1684
+ if (err === "not-allowed" || err === "service-not-allowed") {
1685
+ setInput("Microphone access was blocked \u2014 enable it in your browser to use voice.");
1686
+ } else if (err === "no-speech") {
1687
+ setInput("Didn't catch that \u2014 tap the mic and try again.");
1688
+ }
1689
+ setVoiceState("idle");
1658
1690
  };
1659
- recognition.onerror = () => setVoiceState("idle");
1660
1691
  recognition.onend = () => {
1661
1692
  setVoiceState((prev) => prev === "listening" ? "idle" : prev);
1662
1693
  };
@@ -1684,6 +1715,7 @@ function ChatModal({
1684
1715
  });
1685
1716
  const [merchantRef, setMerchantRef] = useState5(null);
1686
1717
  const [paymentPhase, setPaymentPhase] = useState5("idle");
1718
+ const [memoryKey, setMemoryKey] = useState5(null);
1687
1719
  const [sessions, setSessions] = useState5(() => loadSessions());
1688
1720
  const [sidebarOpen, setSidebarOpen] = useState5(false);
1689
1721
  const [replayMessages, setReplayMessages] = useState5(null);
@@ -1725,6 +1757,10 @@ function ChatModal({
1725
1757
  }
1726
1758
  const isHistoryIntent = lastIntent === "capture" || lastIntent === "delete" || lastIntent === "view_history";
1727
1759
  if (isHistoryIntent) {
1760
+ const { phone, word } = parseMemoryKey(phoneInput);
1761
+ if (!phone) return;
1762
+ client.setShopperIdentity(phone, word);
1763
+ setMemoryKey(phone + word);
1728
1764
  setPaymentPhase("idle");
1729
1765
  const lastUserMsg = [...messages].reverse().find((m) => m.role === "user");
1730
1766
  if (lastUserMsg) {
@@ -2030,7 +2066,25 @@ function ChatModal({
2030
2066
  !replayMessages && paymentPhase === "prompt_phone" && (() => {
2031
2067
  const isHistoryIntent = lastIntent === "capture" || lastIntent === "delete" || lastIntent === "view_history";
2032
2068
  if (isHistoryIntent) {
2033
- return null;
2069
+ return /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-ai-msg", children: [
2070
+ /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx7(SparkleIcon2, {}) }),
2071
+ /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-body", children: /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-text", children: /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-phone-form", children: [
2072
+ /* @__PURE__ */ jsx7("label", { className: "hsk-cb-phone-label", children: "Your phone number \u2014 or paste your memory key" }),
2073
+ /* @__PURE__ */ jsx7(
2074
+ "input",
2075
+ {
2076
+ type: "text",
2077
+ className: "hsk-cb-phone-input",
2078
+ placeholder: "0712345678 or 0712345678flyingthunder",
2079
+ value: phoneInput,
2080
+ onChange: (e) => setPhoneInput(e.target.value.replace(/[^0-9a-zA-Z]/g, "")),
2081
+ onKeyDown: (e) => e.key === "Enter" && handlePhoneSubmit(),
2082
+ autoFocus: true
2083
+ }
2084
+ ),
2085
+ /* @__PURE__ */ jsx7("button", { className: "hsk-cb-phone-submit", onClick: handlePhoneSubmit, children: "Save & sync my items" })
2086
+ ] }) }) })
2087
+ ] });
2034
2088
  }
2035
2089
  return /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-ai-msg", children: [
2036
2090
  /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx7(SparkleIcon2, {}) }),
@@ -2052,6 +2106,22 @@ function ChatModal({
2052
2106
  ] }) }) })
2053
2107
  ] });
2054
2108
  })(),
2109
+ !replayMessages && memoryKey && /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-ai-msg", children: [
2110
+ /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-icon", style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx7(SparkleIcon2, {}) }),
2111
+ /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-body", children: /* @__PURE__ */ jsx7("div", { className: "hsk-cb-ai-text", children: /* @__PURE__ */ jsxs6("div", { style: { padding: "10px 12px", border: "1px solid var(--hsk-border, #e5e5e5)", borderRadius: 8 }, children: [
2112
+ /* @__PURE__ */ jsx7("div", { style: { fontSize: 12, fontWeight: 600, marginBottom: 4 }, children: "\u{1F511} Your memory key" }),
2113
+ /* @__PURE__ */ jsx7("code", { style: { display: "block", fontSize: 14, fontWeight: 700, marginBottom: 6, wordBreak: "break-all" }, children: memoryKey }),
2114
+ /* @__PURE__ */ jsxs6("div", { style: { display: "flex", gap: 8, alignItems: "center" }, children: [
2115
+ /* @__PURE__ */ jsx7("button", { className: "hsk-cb-phone-submit", style: { padding: "4px 10px" }, onClick: () => {
2116
+ try {
2117
+ navigator.clipboard?.writeText(memoryKey);
2118
+ } catch {
2119
+ }
2120
+ }, children: "Copy" }),
2121
+ /* @__PURE__ */ jsx7("span", { style: { fontSize: 11, opacity: 0.7 }, children: "Save it \u2014 enter it on any site to get your items back." })
2122
+ ] })
2123
+ ] }) }) })
2124
+ ] }),
2055
2125
  !replayMessages && paymentPhase === "awaiting" && /* @__PURE__ */ jsxs6("div", { className: "hsk-cb-payment-prompt hsk-cb-payment-prompt--awaiting", children: [
2056
2126
  /* @__PURE__ */ jsx7("div", { className: "hsk-cb-payment-pulse-ring" }),
2057
2127
  /* @__PURE__ */ jsx7("div", { className: "hsk-cb-payment-icon-wrap", children: /* @__PURE__ */ jsx7("span", { style: { fontSize: "2rem" }, children: "\u{1F4F1}" }) }),
@@ -2148,7 +2218,7 @@ function ChatModal({
2148
2218
  value: input,
2149
2219
  onChange: handleInput,
2150
2220
  onKeyDown: handleKeyDown,
2151
- placeholder: activePlaceholder,
2221
+ placeholder: voiceState === "listening" ? "\u{1F399}\uFE0F Listening\u2026 tap the mic to stop" : voiceState === "processing" ? "Got it \u2014 sending\u2026" : activePlaceholder,
2152
2222
  rows: 1,
2153
2223
  disabled: loading,
2154
2224
  autoFocus: true