@levo-so/studio 0.3.9 → 0.3.11

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/index.d.ts CHANGED
@@ -2664,7 +2664,7 @@ export declare const PopoverTrigger: WithBlockPropsComponent<BasePopoverTriggerP
2664
2664
  * Plug-and-play popup integration for React apps.
2665
2665
  * Waits for identity context (session hydrated + identity resolved), then
2666
2666
  * fetches active popups and lazy-loads the renderer only when popups exist.
2667
- * Works without insights network — gates on local readiness, not /welcome.
2667
+ * Works without insights network: gates on local readiness only, nothing waits on a request.
2668
2668
  * Must be placed inside a `<LevoProvider>`.
2669
2669
  */
2670
2670
  export declare const PopupLoader: React.FC<IPopupLoaderProps>;
package/index.js CHANGED
@@ -3800,7 +3800,7 @@ var Di = (e, t) => {
3800
3800
  getAllBlocks() {
3801
3801
  return this.blocks;
3802
3802
  }
3803
- }, yo = vo.getInstance(), bo = nt(() => import("./kbChat-QDHdRejh.js"), { ssr: !1 }), xo = () => {
3803
+ }, yo = vo.getInstance(), bo = nt(() => import("./kbChat-DfcTNf0n.js"), { ssr: !1 }), xo = () => {
3804
3804
  let e = rt(), [t, n] = R(void 0), r = e?.events;
3805
3805
  return F(() => {
3806
3806
  if (typeof window > "u" || !r) return;
@@ -0,0 +1,173 @@
1
+ "use client";
2
+ import { C as e, a as t, c as n, f as r, g as i, h as a, l as o, m as s, n as c, o as l, p as u, r as d, t as f, u as p } from "./pillChrome-QDjBETmP.js";
3
+ import { useEffect as m, useRef as h, useState as g } from "react";
4
+ import { jsx as _, jsxs as v } from "react/jsx-runtime";
5
+ import { ArrowUp as y, Sparkles as b } from "lucide-react";
6
+ //#region ../../libraries/ai-chat/src/useActiveAgent.ts
7
+ var x = (t) => e("active_agent", t), S = (e) => {
8
+ let t = x(e);
9
+ if (!t || typeof window > "u") return null;
10
+ try {
11
+ let e = window.sessionStorage.getItem(t);
12
+ if (!e) return null;
13
+ let n = JSON.parse(e);
14
+ return typeof n?.id != "string" || n.id.length === 0 ? null : n;
15
+ } catch {
16
+ return null;
17
+ }
18
+ }, C = (e, t) => {
19
+ let n = x(e);
20
+ if (!(!n || typeof window > "u")) try {
21
+ t === null ? window.sessionStorage.removeItem(n) : window.sessionStorage.setItem(n, JSON.stringify(t));
22
+ } catch {}
23
+ }, w = ({ url: e, workspaceId: t, headers: n, path: r }) => {
24
+ let [i, a] = g({ status: "loading" });
25
+ m(() => {
26
+ let e = S(t);
27
+ a(e ? {
28
+ status: "ready",
29
+ agent: e
30
+ } : (e) => e.status === "ready" ? { status: "loading" } : e);
31
+ }, [t]);
32
+ let o = h(n);
33
+ return o.current = n, m(() => {
34
+ if (!t || !e) return;
35
+ let n = r ? `${e}${e.includes("?") ? "&" : "?"}path=${encodeURIComponent(r)}` : e, i = new AbortController();
36
+ return (async () => {
37
+ try {
38
+ let e = await fetch(n, {
39
+ method: "GET",
40
+ credentials: "include",
41
+ headers: o.current,
42
+ signal: i.signal
43
+ });
44
+ if (!e.ok) {
45
+ C(t, null), a({ status: "missing" });
46
+ return;
47
+ }
48
+ let r = (await e.json())?.content?.data;
49
+ if (!r || typeof r.id != "string" || r.id.length === 0) {
50
+ C(t, null), a({ status: "missing" });
51
+ return;
52
+ }
53
+ C(t, r), a({
54
+ status: "ready",
55
+ agent: r
56
+ });
57
+ } catch (e) {
58
+ if (e?.name === "AbortError") return;
59
+ console.warn("[levo-kb-chat] active-agent boot failed:", e), a({ status: "error" });
60
+ }
61
+ })(), () => i.abort();
62
+ }, [
63
+ t,
64
+ e,
65
+ r
66
+ ]), i;
67
+ }, T = (...e) => e.filter(Boolean).join(" "), E = () => import("./KBChatWidget-aK7vt64V.js"), D = (e) => {
68
+ let [t, n] = g(null), [r, i] = g(!1), [a, o] = g("");
69
+ return t ? /* @__PURE__ */ _(t, {
70
+ initialOpen: !0,
71
+ initialDraft: a,
72
+ ...e
73
+ }) : /* @__PURE__ */ _(k, {
74
+ siteName: e.siteName,
75
+ draft: a,
76
+ loading: r,
77
+ onDraftChange: o,
78
+ onActivate: () => {
79
+ r || t || (i(!0), E().then((e) => n(() => e.KBChatWidget)).catch((e) => {
80
+ i(!1), console.warn("[levo-kb-chat] widget load failed:", e);
81
+ }));
82
+ },
83
+ onPrefetch: () => {
84
+ E().catch(() => {});
85
+ }
86
+ });
87
+ }, O = () => /* @__PURE__ */ _("span", {
88
+ "aria-hidden": !0,
89
+ className: "h-5 w-5 animate-spin rounded-full border-2 border-current border-t-transparent"
90
+ }), k = ({ siteName: e, draft: i, loading: m, onDraftChange: x, onActivate: S, onPrefetch: C }) => {
91
+ let w = h(null), E = h(null), D = a(e), [k, A] = g(!1);
92
+ return /* @__PURE__ */ _("div", {
93
+ onPointerEnter: C,
94
+ className: T("ai-chat-launcher fixed bottom-8 left-1/2 z-[60] -translate-x-1/2", u),
95
+ children: /* @__PURE__ */ _("div", {
96
+ className: T(c, n, "ai-chat-intro-morph"),
97
+ children: /* @__PURE__ */ v("div", {
98
+ ref: E,
99
+ className: T(p, k && "ai-chat-pill-surface--stacked"),
100
+ children: [
101
+ /* @__PURE__ */ _("button", {
102
+ type: "button",
103
+ onClick: S,
104
+ onFocus: C,
105
+ "aria-label": "Open AI chat",
106
+ className: o,
107
+ children: m ? /* @__PURE__ */ _(O, {}) : /* @__PURE__ */ _(b, { className: "h-5 w-5" })
108
+ }),
109
+ /* @__PURE__ */ v("div", {
110
+ className: d,
111
+ children: [/* @__PURE__ */ _("textarea", {
112
+ ref: w,
113
+ rows: 1,
114
+ autoComplete: "off",
115
+ autoCorrect: "off",
116
+ autoCapitalize: "none",
117
+ inputMode: "text",
118
+ value: i,
119
+ "aria-label": D,
120
+ onFocus: S,
121
+ onChange: (e) => {
122
+ let t = e.currentTarget;
123
+ x(t.value), E.current && A(s(E.current, t));
124
+ },
125
+ className: r
126
+ }), !i && /* @__PURE__ */ _("span", {
127
+ className: T("ai-chat-pill-label pointer-events-none absolute inset-y-0 left-0 flex max-w-full items-center truncate bg-clip-text font-semibold text-[15px] text-transparent", "ai-chat-intro-label"),
128
+ "aria-hidden": !0,
129
+ children: D
130
+ })]
131
+ }),
132
+ /* @__PURE__ */ _("div", {
133
+ className: f,
134
+ children: /* @__PURE__ */ _("button", {
135
+ type: "button",
136
+ onClick: S,
137
+ "aria-label": "Open AI chat",
138
+ className: t,
139
+ style: l,
140
+ children: m ? /* @__PURE__ */ _(O, {}) : /* @__PURE__ */ _(y, { className: "h-5 w-5 stroke-[2.5px]" })
141
+ })
142
+ })
143
+ ]
144
+ })
145
+ })
146
+ });
147
+ }, A = "/.levo/public/api/v1/agents/kb-chat/public", j = (e) => e.replace(/\/v1\/agents\/kb-chat\/public\/?$/, ""), M = ({ workspaceId: e, siteName: t, siteLogo: n, siteIcon: r, apiBaseUrl: a = A, authHeaders: o, showBranding: s, siteSlug: c, path: l }) => {
148
+ let u = w({
149
+ url: `${j(a)}/v1/intelligence/site-agent/get-active`,
150
+ workspaceId: e,
151
+ headers: e ? {
152
+ ...i(o),
153
+ "Levo-Workspace": e
154
+ } : i(o),
155
+ path: l
156
+ });
157
+ return u.status === "ready" ? /* @__PURE__ */ _("div", {
158
+ "data-ai-chat-root": !0,
159
+ children: /* @__PURE__ */ _(D, {
160
+ workspaceId: e,
161
+ siteName: t,
162
+ siteLogo: n,
163
+ siteIcon: r,
164
+ agentId: u.agent.id,
165
+ apiBaseUrl: a,
166
+ authHeaders: o,
167
+ showBranding: s,
168
+ siteSlug: c
169
+ })
170
+ }) : null;
171
+ };
172
+ //#endregion
173
+ export { M as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/studio",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "author": "Levo Engineering <devs@theinternetfolks.com>",
5
5
  "description": "Levo Studio components and utilities for building block-based pages",
6
6
  "type": "module",
@@ -123,8 +123,8 @@
123
123
  "react": ">=19",
124
124
  "next": ">=14",
125
125
  "react-dom": ">=19",
126
- "@levo-so/core": "0.3.9",
127
- "@levo-so/insights": "0.3.9",
128
- "@levo-so/react": "0.3.9"
126
+ "@levo-so/core": "0.3.11",
127
+ "@levo-so/insights": "0.3.11",
128
+ "@levo-so/react": "0.3.11"
129
129
  }
130
130
  }
@@ -0,0 +1,50 @@
1
+ //#region ../../libraries/ai-chat/src/helpers.ts
2
+ var e = "disabled:cursor-not-allowed disabled:opacity-40", t = (e) => {
3
+ if (!e) return null;
4
+ let t = e instanceof Date ? e : new Date(e);
5
+ return Number.isNaN(t.getTime()) ? null : t;
6
+ }, n = (e, n = {
7
+ hour: "numeric",
8
+ minute: "2-digit"
9
+ }) => t(e)?.toLocaleTimeString([], n) ?? "", r = (e, r) => {
10
+ let i = t(e);
11
+ if (!i) return "";
12
+ let a = /* @__PURE__ */ new Date();
13
+ if (i.toDateString() === a.toDateString()) return n(i, r);
14
+ let o = i.toLocaleTimeString([], {
15
+ hour: "numeric",
16
+ minute: "2-digit"
17
+ });
18
+ return `${i.toLocaleDateString([], {
19
+ month: "short",
20
+ day: "numeric",
21
+ ...i.getFullYear() !== a.getFullYear() && { year: "numeric" }
22
+ })} · ${o}`;
23
+ }, i = (e) => {
24
+ let n = t(e);
25
+ return n ? `${n.toLocaleDateString([], { dateStyle: "medium" })} · ${n.toLocaleTimeString([], { timeStyle: "short" })}` : "";
26
+ }, a = (e) => {
27
+ let t = e.metadata?.custom?.createdAt;
28
+ return typeof t == "string" || t instanceof Date ? t : e.createdAt;
29
+ }, o = (e, t) => t ? `levo.site_chat.${e}.${t}` : null, s = (e, t) => {
30
+ e.style.height = "auto", e.style.height = t === void 0 ? `${e.scrollHeight}px` : `${Math.min(e.scrollHeight, t)}px`;
31
+ }, c = (e, t) => {
32
+ e.setText(t);
33
+ let n = document.activeElement?.closest("[data-ai-chat-root]") ?? document;
34
+ requestAnimationFrame(() => {
35
+ let e = n.querySelector("textarea[data-ai-chat-composer]");
36
+ if (!e) return;
37
+ e.focus();
38
+ let t = e.value.length;
39
+ e.setSelectionRange(t, t);
40
+ });
41
+ }, l = (e) => typeof e == "function" ? e() : e ?? {}, u = "w-72", d = "ai-chat-pill-gradient relative rounded-[30px] p-[2px] transition-shadow duration-300", f = "shadow-lg shadow-zinc-950/10", p = "shadow-md", m = "ai-chat-pill-surface min-h-14 w-full rounded-[28px] bg-white p-1.5", h = "ai-chat-pill-surface--stacked", g = "ai-chat-pill-input relative min-w-0", _ = "ai-chat-pill-actions flex items-center gap-1.5", v = "ai-chat-pill-spark flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-full text-blue-500 transition-[background-color,transform] duration-150 hover:bg-zinc-50 active:scale-95", y = "flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-full shadow-sm transition-[transform,box-shadow] duration-150 hover:scale-105 hover:shadow-md active:scale-95", b = "block h-6 max-h-[120px] w-full resize-none overflow-y-auto bg-transparent text-base text-zinc-900 leading-6 placeholder:text-zinc-400 focus:outline-none", x = 24, S = (e, t) => {
42
+ e.classList.remove(h), t.style.height = "auto";
43
+ let n = t.scrollHeight > x + 4;
44
+ return e.classList.toggle(h, n), s(t, 120), n;
45
+ }, C = "ai-chat-pill-label pointer-events-none absolute inset-y-0 left-0 flex max-w-full items-center truncate bg-clip-text font-semibold text-[15px] text-transparent", w = {
46
+ backgroundColor: "var(--color-brand, #0a0a0a)",
47
+ color: "var(--color-brand-foreground, #fff)"
48
+ }, T = (e) => e ? `Ask ${e}` : "Ask AI";
49
+ //#endregion
50
+ export { o as C, a as S, e as _, y as a, i as b, f as c, h as d, b as f, l as g, T as h, C as i, v as l, S as m, d as n, w as o, u as p, g as r, p as s, _ as t, m as u, s as v, r as x, c as y };