@chaibuilder/sdk 4.0.0-beta.1 → 4.0.0-beta.3

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.
Files changed (184) hide show
  1. package/README.md +27 -20
  2. package/dist/2SSKDMRQ-BnsZi3K3.cjs +1 -0
  3. package/dist/2SSKDMRQ-CnSDkQcy.js +42 -0
  4. package/dist/AP7HFJJL-B31839PG.cjs +1228 -0
  5. package/dist/AP7HFJJL-CymCmW14.js +9214 -0
  6. package/dist/IconPicker-B1rWC-Ex.js +59 -0
  7. package/dist/IconPicker-DREyo007.cjs +1 -0
  8. package/dist/WDYDFRGG-BUVnbAci.js +33 -0
  9. package/dist/WDYDFRGG-BxhOCHc3.cjs +1 -0
  10. package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
  11. package/dist/_commonjsHelpers-DwGv2jUC.cjs +1 -0
  12. package/dist/actions-registery-CZ1w0NKa.js +15545 -0
  13. package/dist/actions-registery-YnFmU21O.cjs +418 -0
  14. package/dist/actions.cjs +1 -0
  15. package/dist/actions.d.ts +3202 -0
  16. package/dist/actions.js +216 -0
  17. package/dist/active-in-another-tab-B47YjQGN.cjs +1 -0
  18. package/dist/active-in-another-tab-CyjngVA6.js +34 -0
  19. package/dist/add-new-language-page-88xzrUy8.cjs +1 -0
  20. package/dist/add-new-language-page-WmlCnytQ.js +401 -0
  21. package/dist/add-new-page-VW2wAYZp.js +31 -0
  22. package/dist/add-new-page-soZ8GAkN.cjs +1 -0
  23. package/dist/ai-panel-content-7zCil042.cjs +1 -0
  24. package/dist/ai-panel-content-D_o7Q_A-.js +61 -0
  25. package/dist/ai-panel-default-lang-COYaxNwn.cjs +3 -0
  26. package/dist/ai-panel-default-lang-DnElspF0.js +341 -0
  27. package/dist/ai-panel-other-lang-CkynNlAU.cjs +1 -0
  28. package/dist/ai-panel-other-lang-Dp0E9_Hx.js +162 -0
  29. package/dist/ai-prompt-input-Bhc0ds7X.js +655 -0
  30. package/dist/ai-prompt-input-CThbVp0_.cjs +1 -0
  31. package/dist/ai-translation-prompt-C2kJQFDX.cjs +1 -0
  32. package/dist/ai-translation-prompt-CZ55HQmo.js +28 -0
  33. package/dist/apply-binding-6iwlED02.js +833 -0
  34. package/dist/apply-binding-KKp5PnpZ.cjs +1 -0
  35. package/dist/code-display-BnqzqzoP.cjs +1 -0
  36. package/dist/{code-display-337R7Dev.js → code-display-DhD_RBcg.js} +1 -1
  37. package/dist/code-editor-DRIAnNbb.js +50 -0
  38. package/dist/code-editor-o3___nu2.cjs +1 -0
  39. package/dist/common-functions-B3a4xKt_.cjs +1 -0
  40. package/dist/common-functions-D2lMFR6K.js +13 -0
  41. package/dist/continue-editing-in-this-client-CS2aQ7yY.js +24 -0
  42. package/dist/continue-editing-in-this-client-CtMYsk-A.cjs +1 -0
  43. package/dist/core-BoRDjj4h.cjs +1 -0
  44. package/dist/core-yvI6kCyw.js +56 -0
  45. package/dist/core.cjs +1 -1
  46. package/dist/core.d.ts +51 -383
  47. package/dist/core.js +39 -106
  48. package/dist/{css-import-modal-DA2L6kwP.js → css-import-modal-Byg6wV0O.js} +36 -36
  49. package/dist/css-import-modal-CyqkXWCO.cjs +13 -0
  50. package/dist/delete-design-token-BRZZiWtQ.js +40 -0
  51. package/dist/delete-design-token-DkVs1oBf.cjs +1 -0
  52. package/dist/delete-page-BzyX9TN-.js +70 -0
  53. package/dist/delete-page-DxX7PFIE.cjs +1 -0
  54. package/dist/design-token-usage-CAHzEGgJ.cjs +1 -0
  55. package/dist/design-token-usage-xQs6SlaJ.js +113 -0
  56. package/dist/digital-asset-manager--uO8Agia.cjs +1 -0
  57. package/dist/digital-asset-manager-DbtwzxRz.js +876 -0
  58. package/dist/duplicate-page-BR7Dlo9d.js +133 -0
  59. package/dist/duplicate-page-CaNAbXwV.cjs +1 -0
  60. package/dist/dynamic-page-selector-Cb5r_W8s.js +85 -0
  61. package/dist/dynamic-page-selector-Cxk_gjni.cjs +1 -0
  62. package/dist/fonts-B-Xt29pe.cjs +1 -0
  63. package/dist/fonts-DRly3Wzd.js +78 -0
  64. package/dist/{get-chai-builder-tailwind-config-C6MHaUM0.cjs → get-chai-builder-tailwind-config-B9rCyiQo.cjs} +1 -1
  65. package/dist/{get-chai-builder-tailwind-config-BqaIvg8p.js → get-chai-builder-tailwind-config-DjoVOuAf.js} +13 -10
  66. package/dist/{get-chai-builder-theme-D0IsUvK4.js → get-chai-builder-theme-BYtp20KD.js} +4 -4
  67. package/dist/get-chai-builder-theme-Dl72X7cz.cjs +1 -0
  68. package/dist/get-seo-defaults-9zHebckY.js +65 -0
  69. package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
  70. package/dist/image-compression-DZ9WMmyn.cjs +1 -0
  71. package/dist/image-compression-DsZ1oqpb.js +37 -0
  72. package/dist/image-editor-DV8kUKhl.js +108 -0
  73. package/dist/image-editor-G-K28aTS.cjs +1 -0
  74. package/dist/index-B-rSiAp_.cjs +1 -0
  75. package/dist/index-Ct7ElCGK.js +19069 -0
  76. package/dist/index-DF5DEvqb.cjs +160 -0
  77. package/dist/index-Dxfyt4d4.js +39 -0
  78. package/dist/index-WQwzsC7A.cjs +5 -0
  79. package/dist/index-ZuacEL1j.js +4732 -0
  80. package/dist/json-diff-viewer-D7z4zNvv.cjs +8 -0
  81. package/dist/json-diff-viewer-krslPepD.js +258 -0
  82. package/dist/lang-panel-BwIewMyw.js +215 -0
  83. package/dist/lang-panel-DT96k1xg.cjs +1 -0
  84. package/dist/manage-design-tokens-Caz_20VK.js +240 -0
  85. package/dist/manage-design-tokens-CrmLe7UT.cjs +1 -0
  86. package/dist/mark-as-template-D295ZQtU.js +156 -0
  87. package/dist/mark-as-template-W3LmpiqN.cjs +1 -0
  88. package/dist/models-5gOsRC56.cjs +1 -0
  89. package/dist/models-D95ZYr_x.js +70 -0
  90. package/dist/nested-path-selector-content-CKYYK-C5.js +87 -0
  91. package/dist/nested-path-selector-content-CoS_d3dc.cjs +1 -0
  92. package/dist/no-language-page-content-BvqRBP6y.js +42 -0
  93. package/dist/no-language-page-content-DkfeMl90.cjs +1 -0
  94. package/dist/no-language-page-dialog-BcEoqyQB.cjs +1 -0
  95. package/dist/no-language-page-dialog-PjNqTUpl.js +10 -0
  96. package/dist/page-creator-C4gc5NSC.cjs +1 -0
  97. package/dist/page-creator-DiOITEMw.js +795 -0
  98. package/dist/page-lock-BdYmCks0.cjs +1 -0
  99. package/dist/page-lock-Bfbs6RgL.js +30 -0
  100. package/dist/page-locked-dialog-B1FAtK92.cjs +1 -0
  101. package/dist/page-locked-dialog-B6MKTRfY.js +133 -0
  102. package/dist/page-manager-new-CHDueBDk.cjs +1 -0
  103. package/dist/page-manager-new-CzX22g2n.js +394 -0
  104. package/dist/page-manager-search-and-filter-CM0UMb6U.js +201 -0
  105. package/dist/page-manager-search-and-filter-DkkRIH86.cjs +1 -0
  106. package/dist/page-revisions-content-ChY-4f2V.cjs +1 -0
  107. package/dist/page-revisions-content-NH9JK4Ey.js +445 -0
  108. package/dist/pages.cjs +1 -0
  109. package/dist/pages.d.ts +491 -0
  110. package/dist/pages.js +27 -0
  111. package/dist/plugin-3ZKK6RXm.js +245 -0
  112. package/dist/plugin-C6rgJDNQ.cjs +22 -0
  113. package/dist/publish-pages-content-D9aixMN5.js +178 -0
  114. package/dist/publish-pages-content-x-JuSFJ9.cjs +1 -0
  115. package/dist/register-partial-type-BjtdfKHE.js +36 -0
  116. package/dist/register-partial-type-ig9fUWIJ.cjs +1 -0
  117. package/dist/render.cjs +2 -2
  118. package/dist/render.d.ts +26 -13
  119. package/dist/render.js +130 -124
  120. package/dist/rte-widget-modal-BaHIuEjF.cjs +1 -0
  121. package/dist/rte-widget-modal-DOJEXLIf.js +38 -0
  122. package/dist/runtime.cjs +1 -1
  123. package/dist/runtime.d.ts +306 -7
  124. package/dist/runtime.js +44 -1
  125. package/dist/save-to-lib-Cgpxw8-g.cjs +1 -0
  126. package/dist/save-to-lib-eiOc_SSN.js +422 -0
  127. package/dist/sdk.css +1 -1
  128. package/dist/selected-block-display-BgRY82CT.cjs +16 -0
  129. package/dist/selected-block-display-CBFePS19.js +319 -0
  130. package/dist/seo-panel-C1-iMOR1.js +798 -0
  131. package/dist/seo-panel-DfAb8U7W.cjs +2 -0
  132. package/dist/shared-json-ld-B4PxAM_0.js +565 -0
  133. package/dist/shared-json-ld-DzG398hr.cjs +1 -0
  134. package/dist/slug-input-AwNJs9im.js +86 -0
  135. package/dist/slug-input-C_ijLQ_X.cjs +1 -0
  136. package/dist/supabase-actions.cjs +1 -0
  137. package/dist/supabase-actions.d.ts +284 -0
  138. package/dist/supabase-actions.js +524 -0
  139. package/dist/take-over-request-BNxcjY2j.cjs +1 -0
  140. package/dist/take-over-request-C4FeDtN_.js +63 -0
  141. package/dist/theme-panel-footer-Cq9pljro.cjs +1 -0
  142. package/dist/theme-panel-footer-uBQqSJXm.js +25 -0
  143. package/dist/translation-warning-modal-B64YqlbI.js +26 -0
  144. package/dist/translation-warning-modal-BZAcwM2_.cjs +1 -0
  145. package/dist/unmark-as-template-CZ9sQp_P.js +39 -0
  146. package/dist/unmark-as-template-EVvk0vmp.cjs +1 -0
  147. package/dist/unpublish-page-D4VwOlxc.js +27 -0
  148. package/dist/unpublish-page-bdSmwAVQ.cjs +1 -0
  149. package/dist/use-page-expand-manager-B6XTvk0E.cjs +1 -0
  150. package/dist/use-page-expand-manager-Cf4MUEJw.js +85 -0
  151. package/dist/{tailwind.cjs → utils.cjs} +1 -1
  152. package/dist/{tailwind.d.ts → utils.d.ts} +12 -11
  153. package/dist/utils.js +7 -0
  154. package/dist/web-blocks.cjs +1 -1
  155. package/dist/web-blocks.d.ts +0 -6
  156. package/dist/web-blocks.js +248 -241
  157. package/dist/web-preview-Cio70gk5.cjs +1 -0
  158. package/dist/web-preview-Djy6WIyj.js +73 -0
  159. package/package.json +175 -105
  160. package/dist/IconPicker-CGWn9C4u.cjs +0 -1
  161. package/dist/IconPicker-QvxJ-4Ez.js +0 -64
  162. package/dist/apply-binding-DCno1xQL.js +0 -711
  163. package/dist/apply-binding-DvHNFLQD.cjs +0 -1
  164. package/dist/code-display-BZ1x7SqI.cjs +0 -1
  165. package/dist/code-editor-B28LoECM.cjs +0 -1
  166. package/dist/code-editor-CfG2FhJ-.js +0 -58
  167. package/dist/common-functions-BGzDsf1z.js +0 -14
  168. package/dist/common-functions-BZmyleS1.cjs +0 -1
  169. package/dist/css-import-modal-CENUYvcl.cjs +0 -13
  170. package/dist/get-chai-builder-theme-Ck_Z4Q-M.cjs +0 -1
  171. package/dist/index-CaGNHF7f.js +0 -12209
  172. package/dist/index-Gn6pJt2v.cjs +0 -166
  173. package/dist/mockServiceWorker.js +0 -307
  174. package/dist/plugin-B5627hMN.js +0 -195
  175. package/dist/plugin-UxTRfDum.cjs +0 -22
  176. package/dist/rte-widget-modal-DL739qeQ.cjs +0 -1
  177. package/dist/rte-widget-modal-Dte0od04.js +0 -41
  178. package/dist/tailwind.js +0 -7
  179. package/dist/tooltip-A4qGk781.cjs +0 -1
  180. package/dist/tooltip-tLiIOgjq.js +0 -1067
  181. package/dist/ui.cjs +0 -1
  182. package/dist/ui.d.ts +0 -415
  183. package/dist/ui.js +0 -129
  184. package/dist/vite.svg +0 -1
@@ -0,0 +1,31 @@
1
+ import { jsx as o, jsxs as r } from "react/jsx-runtime";
2
+ import { D as t, d as c, e as p, f as m, p as h } from "./index-Ct7ElCGK.js";
3
+ import { Suspense as f, lazy as D } from "react";
4
+ import { useTranslation as u } from "react-i18next";
5
+ const x = D(() => import("./page-creator-DiOITEMw.js")), C = ({
6
+ addEditPage: e,
7
+ setAddEditPage: s,
8
+ closePanel: l
9
+ }) => {
10
+ const { t: n } = u(), a = !!(e != null && e.id), i = !!e;
11
+ return /* @__PURE__ */ o(t, { open: i, onOpenChange: () => s(void 0), children: i && /* @__PURE__ */ r(c, { className: "sm:max-w-[425px]", children: [
12
+ /* @__PURE__ */ r(p, { children: [
13
+ /* @__PURE__ */ r(m, { children: [
14
+ n(a ? "Edit" : "Add New"),
15
+ " "
16
+ ] }),
17
+ /* @__PURE__ */ o(h, { children: n(a ? "Update your page name" : "Enter details to create a new page") })
18
+ ] }),
19
+ /* @__PURE__ */ o(f, { fallback: /* @__PURE__ */ o("div", { className: "min-h-40" }), children: /* @__PURE__ */ o(
20
+ x,
21
+ {
22
+ closePanel: l,
23
+ addEditPage: e,
24
+ close: () => s(void 0)
25
+ }
26
+ ) })
27
+ ] }) });
28
+ };
29
+ export {
30
+ C as default
31
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DF5DEvqb.cjs"),c=require("react"),a=require("react-i18next"),u=c.lazy(()=>Promise.resolve().then(()=>require("./page-creator-C4gc5NSC.cjs"))),x=({addEditPage:n,setAddEditPage:r,closePanel:l})=>{const{t:o}=a.useTranslation(),t=!!(n!=null&&n.id),i=!!n;return e.jsx(s.Dialog,{open:i,onOpenChange:()=>r(void 0),children:i&&e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{children:[o(t?"Edit":"Add New")," "]}),e.jsx(s.DialogDescription,{children:o(t?"Update your page name":"Enter details to create a new page")})]}),e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"min-h-40"}),children:e.jsx(u,{closePanel:l,addEditPage:n,close:()=>r(void 0)})})]})})};exports.default=x;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-DF5DEvqb.cjs"),m=require("./index-WQwzsC7A.cjs"),N=require("lucide-react"),s=require("react"),M=require("react-i18next"),k=require("sonner"),A=require("./models-5gOsRC56.cjs"),R=s.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-default-lang-COYaxNwn.cjs"))),z=s.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-other-lang-CkynNlAU.cjs"))),B=()=>{const{t:r}=M.useTranslation(),[S,a]=s.useState(""),[t,l]=s.useState([]),[c,i]=s.useState(!1),[u,d]=s.useState(null),[p,f]=s.useState(null),[b,P]=s.useState(A.getDefaultModel().id),{selectedLang:h,fallbackLang:q}=j.useLanguages(),v=m.useBuilderFetch(),[w]=m.useSearchParams(),y=w.get("page"),C=(t==null?void 0:t.filter(n=>n.role==="user").length)>=4,L=(t==null?void 0:t.filter(n=>n.role==="user").length)>=10;s.useEffect(()=>{l([])},[h,y]);const g=()=>{l([]),a(""),f(null),d(null),i(!1)},x={t:r,fetch:v,input:S,messages:t,setInput:a,isLoading:c,handleStop:()=>{u&&(u.abort(),d(null)),i(!1),a(""),f(null),l(n=>{const o=n[n.length-1];return o&&o.role==="assistant"&&o.isReasoning&&o.isStreaming?n.slice(0,-1):n}),k.toast.info(r("Generation stopped"))},handleReset:g,setMessages:l,setIsLoading:i,currentBlock:p,fallbackLang:q,abortController:u,setCurrentBlock:f,setAbortController:d,forceNewConversation:L,suggestNewConversation:C,selectedModel:b,onModelChange:P};return e.jsxs(e.Fragment,{children:[c&&e.jsx("div",{className:"fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent"}),e.jsxs("div",{className:"flex h-full w-full flex-col",children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500",children:r("Your conversation will not be saved")}),(t==null?void 0:t.length)>0&&e.jsx(j.Button,{variant:"outline",size:"icon",onClick:g,className:"h-6 w-6",disabled:c,children:e.jsx(N.Plus,{})})]}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"flex h-full w-full items-center justify-center text-xs",children:"Loading AI Panel"}),children:h?e.jsx(z,{...x,selectedLang:h}):e.jsx(R,{...x})})]})]})};exports.default=B;
@@ -0,0 +1,61 @@
1
+ import { jsxs as h, Fragment as k, jsx as n } from "react/jsx-runtime";
2
+ import { n as y, B as A } from "./index-Ct7ElCGK.js";
3
+ import { v as B, c as F } from "./index-ZuacEL1j.js";
4
+ import { Plus as z } from "lucide-react";
5
+ import { useState as l, useEffect as I, Suspense as D, lazy as x } from "react";
6
+ import { useTranslation as R } from "react-i18next";
7
+ import { toast as E } from "sonner";
8
+ import { g as G } from "./models-D95ZYr_x.js";
9
+ const O = x(() => import("./ai-panel-default-lang-DnElspF0.js")), T = x(() => import("./ai-panel-other-lang-Dp0E9_Hx.js")), X = () => {
10
+ const { t: r } = R(), [b, a] = l(""), [e, s] = l([]), [c, i] = l(!1), [f, u] = l(null), [w, d] = l(null), [C, L] = l(G().id), { selectedLang: m, fallbackLang: N } = y(), P = B(), [v] = F(), S = v.get("page"), M = (e == null ? void 0 : e.filter((t) => t.role === "user").length) >= 4, j = (e == null ? void 0 : e.filter((t) => t.role === "user").length) >= 10;
11
+ I(() => {
12
+ s([]);
13
+ }, [m, S]);
14
+ const g = () => {
15
+ s([]), a(""), d(null), u(null), i(!1);
16
+ }, p = {
17
+ t: r,
18
+ fetch: P,
19
+ input: b,
20
+ messages: e,
21
+ setInput: a,
22
+ isLoading: c,
23
+ handleStop: () => {
24
+ f && (f.abort(), u(null)), i(!1), a(""), d(null), s((t) => {
25
+ const o = t[t.length - 1];
26
+ return o && o.role === "assistant" && o.isReasoning && o.isStreaming ? t.slice(0, -1) : t;
27
+ }), E.info(r("Generation stopped"));
28
+ },
29
+ handleReset: g,
30
+ setMessages: s,
31
+ setIsLoading: i,
32
+ currentBlock: w,
33
+ fallbackLang: N,
34
+ abortController: f,
35
+ setCurrentBlock: d,
36
+ setAbortController: u,
37
+ forceNewConversation: j,
38
+ suggestNewConversation: M,
39
+ selectedModel: C,
40
+ onModelChange: L
41
+ };
42
+ return /* @__PURE__ */ h(k, { children: [
43
+ c && /* @__PURE__ */ n("div", { className: "fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent" }),
44
+ /* @__PURE__ */ h("div", { className: "flex h-full w-full flex-col", children: [
45
+ /* @__PURE__ */ h("div", { className: "flex w-full items-center justify-between", children: [
46
+ /* @__PURE__ */ n("p", { className: "text-xs text-gray-500", children: r("Your conversation will not be saved") }),
47
+ (e == null ? void 0 : e.length) > 0 && /* @__PURE__ */ n(A, { variant: "outline", size: "icon", onClick: g, className: "h-6 w-6", disabled: c, children: /* @__PURE__ */ n(z, {}) })
48
+ ] }),
49
+ /* @__PURE__ */ n(
50
+ D,
51
+ {
52
+ fallback: /* @__PURE__ */ n("div", { className: "flex h-full w-full items-center justify-center text-xs", children: "Loading AI Panel" }),
53
+ children: m ? /* @__PURE__ */ n(T, { ...p, selectedLang: m }) : /* @__PURE__ */ n(O, { ...p })
54
+ }
55
+ )
56
+ ] })
57
+ ] });
58
+ };
59
+ export {
60
+ X as default
61
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),v=require("./index-DF5DEvqb.cjs"),S=require("./selected-block-display-BgRY82CT.cjs"),P=require("lucide-react"),j=require("react"),O=require("sonner"),W=require("./models-5gOsRC56.cjs"),F=require("lodash-es"),q=require("./apply-binding-KKp5PnpZ.cjs"),$=require("@tanstack/react-query"),_=(a,k)=>{const h=a.filter(p=>p._parent===k),I=h.map(p=>p._id),A=h.flatMap(p=>_(a,p._id));return[...I,...A]},V=(a,k,h)=>{const I=F.find(a,{_id:k});if(!I)return a;const A=a.findIndex(g=>g._id===k),p=_(a,k),C=new Set([k,...p]),u=a.filter(g=>!C.has(g._id)),w=new Set(h.map(g=>g._id)),R=h.map(g=>!g._parent||!w.has(g._parent)?{...g,_parent:I._parent}:g);return[...u.slice(0,A),...R,...u.slice(A)]},K=()=>{const[,a]=v.useSelectedBlockIds(),{setNewBlocks:k}=v.useBlocksStoreUndoableActions(),{hasPermission:h}=v.usePermissions();return j.useCallback((I,A)=>{if(!h(v.PERMISSIONS.EDIT_BLOCK))return;const p=v.builderStore.get(v.presentBlocksAtom),C=I?V(p,I,A):A;k(C),A.length>0&&setTimeout(()=>a([A[0]._id]),200)},[a,k,h])},U=()=>{const{addPredefinedBlock:a}=v.useAddBlock(),k=K(),h=v.useRemoveBlocks(),I=$.useQueryClient(),A=async(s,e)=>{if(!e)return;const r=q.getBlocksFromHTML(e);await a(r,s.parentId,s.position)},p=async(s,e)=>{if(!s.blockId||!e)return;const r=q.getBlocksFromHTML(e);await k(s.blockId,r)},C=async s=>{!s.ids||s.ids.length===0||await h(s.ids)};let u=null;const w=(s,e)=>{const r=document.getElementById("canvas-iframe");if(!r)return null;const d=r==null?void 0:r.contentDocument;if(!d)return null;d.querySelectorAll("[data-stream-canvas]").forEach(m=>m.remove());let n=null;if(s&&s!=="undefined"&&(n=d.querySelector(`[data-block-id="${s}"]`)),n||(n=d.body),!n)return null;if(u=d.createElement("div"),u.setAttribute("data-stream-canvas","true"),e!==void 0&&e>=0&&n.children){const m=Math.min(e,n.children.length);m<n.children.length?n.insertBefore(u,n.children[m]):n.appendChild(u)}else n.appendChild(u);return u},R=s=>{var n;const e=document.getElementById("canvas-iframe");if(!e)return null;const r=e==null?void 0:e.contentDocument;if(!r)return null;r.querySelectorAll("[data-stream-canvas]").forEach(m=>m.remove());const f=r.querySelector(`[data-block-id="${s}"]`);return f?(u=r.createElement("div"),u.setAttribute("data-stream-canvas","true"),(n=f.parentNode)==null||n.insertBefore(u,f.nextSibling),f.style.display="none",u):null},M=(s,e,r)=>{const d=w(e,r);if(d){d.innerHTML=s;const f=d.getBoundingClientRect(),n=document.getElementById("canvas-iframe"),m=n==null?void 0:n.contentWindow;m&&(f.top>=0&&f.bottom<=m.innerHeight||d.scrollIntoView({behavior:"smooth",block:"nearest"}))}},g=(s,e)=>{const r=R(e);r&&(r.innerHTML=s)},D=s=>{const e=s.match(/^--ACTION=(.+)--$/);if(!e)return null;let d=e[1].replace(/--/g,"").split("|");const n={type:d[0]};return d.forEach(m=>{const t=m.trim();if(t.startsWith("PARENT=")){const T=t.substring(7);n.parentId=T==="undefined"?void 0:T}else t.startsWith("POS=")?n.position=parseInt(t.substring(4)):t.startsWith("ID=")?n.blockId=t.substring(3):t.startsWith("IDS=")&&(n.ids=t.substring(4).split(",").map(T=>T.trim()))}),n};return j.useCallback(async(s,e)=>{const r=new TextDecoder;let d="",f="",n=!1,m=null;const t={isInAction:!1,currentAction:null,htmlBuffer:"",isCapturingHtml:!1},T=async y=>{const o=y.trim();if(o==="--START--"){n=!0;return}if(n){if(o==="--END--"){t.currentAction&&(t.htmlBuffer||t.currentAction.type==="REMOVE")&&await E(t.currentAction,t.htmlBuffer),u&&(u.remove(),u=null);return}if(o.startsWith("--THINKING=")){const i=o.substring(11);e(l=>{const B=[...l],x=B[B.length-1];if(x&&x.role==="assistant"&&x.isReasoning)x.content=i,x.isStreaming=!1;else{const b={id:Date.now().toString(),role:"assistant",content:i,isReasoning:!0,isStreaming:!1};B.push(b)}return B});return}if(o.startsWith("--TASK=")){const i=o.substring(7),l=`task-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,B={id:l,role:"assistant",content:i.replace(/--$/,""),isTask:!0,isTaskLoading:!0,isTaskCompleted:!1};m=l,e(x=>[...x,B]);return}if(o.startsWith("--MSG=")){const i=o.substring(6),l={id:Date.now().toString(),role:"assistant",content:i.replace(/--$/g,""),isReasoning:!1,isStreaming:!1};e(B=>[...B,l]);return}if(o.startsWith("--ACTION=")){t.currentAction&&(t.htmlBuffer||t.currentAction.type==="REMOVE")&&await E(t.currentAction,t.htmlBuffer),t.currentAction=D(o),t.htmlBuffer="",t.isInAction=!0;return}if(o==="--ENDACTION--"){t.currentAction&&(t.htmlBuffer||t.currentAction.type==="REMOVE")&&await E(t.currentAction,t.htmlBuffer),m&&(e(i=>i.map(l=>l.isTask?{...l,isTaskCompleted:!0}:l)),m=null),t.currentAction=null,t.htmlBuffer="",t.isInAction=!1;return}if(o==="--HTML--"){t.isCapturingHtml=!0;return}if(o==="--ENDHTML--"){t.isCapturingHtml=!1;return}if(o.startsWith("--HTML--")&&o.includes("--ENDHTML--")){const i=o.match(/^--HTML--(.+?)--ENDHTML--$/);if(i&&t.currentAction){const l=i[1];t.htmlBuffer+=l,t.currentAction.type==="ADD"?M(t.htmlBuffer,t.currentAction.parentId,t.currentAction.position):t.currentAction.type==="EDIT"&&t.currentAction.blockId&&g(t.htmlBuffer,t.currentAction.blockId)}return}t.isCapturingHtml&&t.currentAction&&(t.htmlBuffer+=y+`
2
+ `,t.currentAction.type==="ADD"?M(t.htmlBuffer,t.currentAction.parentId,t.currentAction.position):t.currentAction.type==="EDIT"&&t.currentAction.blockId&&g(t.htmlBuffer,t.currentAction.blockId))}},E=async(y,o)=>{try{switch(y.type){case"ADD":await A(y,o);break;case"EDIT":await p(y,o);break;case"REMOVE":await C(y);break}e(i=>i.filter(l=>!l.isTask))}catch(i){console.log(i)}};try{for(;;){const{done:y,value:o}=await s.read();if(y)break;const i=r.decode(o,{stream:!0});d+=i,f+=i;const l=f.split(`
3
+ `);f=l.pop()||"";for(const B of l)await T(B)}f&&await T(f),I.invalidateQueries({queryKey:["AI_USAGE"]})}catch(y){console.log(y)}},[h])},G=j.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-CThbVp0_.cjs"))),Q=({t:a,fetch:k,input:h,messages:I,setInput:A,isLoading:p,setMessages:C,handleStop:u,setIsLoading:w,currentBlock:R,fallbackLang:M,setCurrentBlock:g,setAbortController:D,selectedModel:s=W.getDefaultModel().id,onModelChange:e})=>{const r=v.useSelectedBlock(),[,d]=v.useSelectedBlockIds(),f=v.useBlocksHtmlForAi(),n=U(),m=async(t,T,E,y)=>{var x;if(!t||p)return;g(r);const o=f(r?{blockId:r._id,additionalCoreBlocks:["Icon"]}:{additionalCoreBlocks:["Icon"]});if(r&&!o){O.toast.error(a("Something went wrong. Please try again."));return}const i={id:Date.now().toString(),role:"user",content:S.getUserPrompt({language:M,userInput:T||t,currentHtml:o}),userMessage:t},l={id:(Date.now()+1).toString(),role:"assistant",content:"",isReasoning:!0,isStreaming:!0};C(b=>[...b,i,l]),w(!0);const B=new AbortController;D(B);try{const b={messages:[i].map(L=>({role:L.role,content:L.content})),model:y||s};E&&(b.image=E);const N=await k({body:{action:"ASK_AI",data:b},streamResponse:!0});if(!N.ok)throw new Error(a("Failed to get AI response"));const H=(x=N.body)==null?void 0:x.getReader();if(!H)throw new Error(a("Response body is not readable"));await n(H,C)}catch(b){if(b.name!=="AbortError"){const N={id:(Date.now()+1).toString(),role:"assistant",content:a("Sorry, I encountered an error. Please try again.")};C(H=>[...H,N])}}finally{A(""),w(!1),g(null),D(null)}};return c.jsxs(c.Fragment,{children:[c.jsxs(S.Conversation,{className:"no-scrollbar",children:[c.jsxs(S.ConversationContent,{className:"gap-2 px-0",children:[I.length===0&&c.jsx(S.ConversationEmptyState,{icon:c.jsx(P.Bot,{size:48,className:"text-gray-300"}),title:"Start a conversation",description:a("Start a conversation with the AI assistant to add/edit current page")}),I.map(t=>t.role!=="system"&&c.jsx(j.Fragment,{children:t.isReasoning?c.jsxs(S.Reasoning,{isStreaming:t.isStreaming,defaultOpen:!0,children:[c.jsx(S.ReasoningTrigger,{className:"text-xs [&_p]:text-muted-foreground"}),c.jsx(S.ReasoningContent,{className:"p-0 text-xs",children:t.content})]}):t.isTask&&!t.isTaskCompleted?c.jsx(S.TaskMessage,{content:t.content,isLoading:t.isTaskLoading}):c.jsx(S.Message,{from:t.role,children:c.jsx(S.MessageContent,{className:"p-0",children:t.role==="assistant"?c.jsx(S.MessageResponse,{className:"p-0 text-xs",children:t.content}):c.jsx("div",{className:"p-0 text-xs",children:t.userMessage||t.content})})})},t.id))]}),c.jsx(S.ConversationScrollButton,{})]}),c.jsxs("div",{className:"border-gray-200 pb-2",children:[c.jsx(S.SelectedBlockDisplay,{onRemove:()=>d([]),isLoading:p}),c.jsx(j.Suspense,{fallback:c.jsx("div",{children:"Loading..."}),children:c.jsx(G,{input:h,setInput:A,onSend:m,onStop:u,isLoading:p,selectedLang:"",currentBlock:r||R,disabled:(h==null?void 0:h.length)===0,selectedModel:s,onModelChange:e})})]})]})};exports.default=Q;
@@ -0,0 +1,341 @@
1
+ import { jsxs as D, Fragment as W, jsx as g } from "react/jsx-runtime";
2
+ import { a as _, al as F, am as $, an as q, ao as V, ap as K, aq as U, ar as j, as as G, at as z } from "./index-Ct7ElCGK.js";
3
+ import { C as Q, a as J, b as X, R as Y, c as Z, d as tt, T as et, M as nt, e as rt, f as st, g as ot, S as at, h as it } from "./selected-block-display-CBFePS19.js";
4
+ import { Bot as ct } from "lucide-react";
5
+ import { useCallback as P, Fragment as lt, Suspense as ut, lazy as dt } from "react";
6
+ import { toast as ft } from "sonner";
7
+ import { g as mt } from "./models-D95ZYr_x.js";
8
+ import { find as pt } from "lodash-es";
9
+ import { g as L } from "./apply-binding-6iwlED02.js";
10
+ import { useQueryClient as ht } from "@tanstack/react-query";
11
+ const O = (i, I) => {
12
+ const m = i.filter((h) => h._parent === I), k = m.map((h) => h._id), A = m.flatMap((h) => O(i, h._id));
13
+ return [...k, ...A];
14
+ }, gt = (i, I, m) => {
15
+ const k = pt(i, { _id: I });
16
+ if (!k) return i;
17
+ const A = i.findIndex((p) => p._id === I), h = O(i, I), v = /* @__PURE__ */ new Set([I, ...h]), l = i.filter((p) => !v.has(p._id)), T = new Set(m.map((p) => p._id)), E = m.map((p) => !p._parent || !T.has(p._parent) ? { ...p, _parent: k._parent } : p);
18
+ return [
19
+ ...l.slice(0, A),
20
+ ...E,
21
+ ...l.slice(A)
22
+ ];
23
+ }, At = () => {
24
+ const [, i] = _(), { setNewBlocks: I } = F(), { hasPermission: m } = $();
25
+ return P(
26
+ (k, A) => {
27
+ if (!m(q.EDIT_BLOCK)) return;
28
+ const h = V.get(K), v = k ? gt(h, k, A) : A;
29
+ I(v), A.length > 0 && setTimeout(() => i([A[0]._id]), 200);
30
+ },
31
+ [i, I, m]
32
+ );
33
+ }, It = () => {
34
+ const { addPredefinedBlock: i } = U(), I = At(), m = j(), k = ht(), A = async (s, e) => {
35
+ if (!e) return;
36
+ const r = L(e);
37
+ await i(r, s.parentId, s.position);
38
+ }, h = async (s, e) => {
39
+ if (!s.blockId || !e) return;
40
+ const r = L(e);
41
+ await I(s.blockId, r);
42
+ }, v = async (s) => {
43
+ !s.ids || s.ids.length === 0 || await m(s.ids);
44
+ };
45
+ let l = null;
46
+ const T = (s, e) => {
47
+ const r = document.getElementById("canvas-iframe");
48
+ if (!r)
49
+ return null;
50
+ const u = r == null ? void 0 : r.contentDocument;
51
+ if (!u)
52
+ return null;
53
+ u.querySelectorAll("[data-stream-canvas]").forEach((f) => f.remove());
54
+ let n = null;
55
+ if (s && s !== "undefined" && (n = u.querySelector(`[data-block-id="${s}"]`)), n || (n = u.body), !n)
56
+ return null;
57
+ if (l = u.createElement("div"), l.setAttribute("data-stream-canvas", "true"), e !== void 0 && e >= 0 && n.children) {
58
+ const f = Math.min(e, n.children.length);
59
+ f < n.children.length ? n.insertBefore(l, n.children[f]) : n.appendChild(l);
60
+ } else
61
+ n.appendChild(l);
62
+ return l;
63
+ }, E = (s) => {
64
+ var n;
65
+ const e = document.getElementById("canvas-iframe");
66
+ if (!e)
67
+ return null;
68
+ const r = e == null ? void 0 : e.contentDocument;
69
+ if (!r)
70
+ return null;
71
+ r.querySelectorAll("[data-stream-canvas]").forEach((f) => f.remove());
72
+ const d = r.querySelector(`[data-block-id="${s}"]`);
73
+ return d ? (l = r.createElement("div"), l.setAttribute("data-stream-canvas", "true"), (n = d.parentNode) == null || n.insertBefore(l, d.nextSibling), d.style.display = "none", l) : null;
74
+ }, R = (s, e, r) => {
75
+ const u = T(e, r);
76
+ if (u) {
77
+ u.innerHTML = s;
78
+ const d = u.getBoundingClientRect(), n = document.getElementById("canvas-iframe"), f = n == null ? void 0 : n.contentWindow;
79
+ f && (d.top >= 0 && d.bottom <= f.innerHeight || u.scrollIntoView({ behavior: "smooth", block: "nearest" }));
80
+ }
81
+ }, p = (s, e) => {
82
+ const r = E(e);
83
+ r && (r.innerHTML = s);
84
+ }, M = (s) => {
85
+ const e = s.match(/^--ACTION=(.+)--$/);
86
+ if (!e) return null;
87
+ let u = e[1].replace(/--/g, "").split("|");
88
+ const n = { type: u[0] };
89
+ return u.forEach((f) => {
90
+ const t = f.trim();
91
+ if (t.startsWith("PARENT=")) {
92
+ const C = t.substring(7);
93
+ n.parentId = C === "undefined" ? void 0 : C;
94
+ } else t.startsWith("POS=") ? n.position = parseInt(t.substring(4)) : t.startsWith("ID=") ? n.blockId = t.substring(3) : t.startsWith("IDS=") && (n.ids = t.substring(4).split(",").map((C) => C.trim()));
95
+ }), n;
96
+ };
97
+ return P(
98
+ async (s, e) => {
99
+ const r = new TextDecoder();
100
+ let u = "", d = "", n = !1, f = null;
101
+ const t = {
102
+ isInAction: !1,
103
+ currentAction: null,
104
+ htmlBuffer: "",
105
+ isCapturingHtml: !1
106
+ }, C = async (S) => {
107
+ const o = S.trim();
108
+ if (o === "--START--") {
109
+ n = !0;
110
+ return;
111
+ }
112
+ if (n) {
113
+ if (o === "--END--") {
114
+ t.currentAction && (t.htmlBuffer || t.currentAction.type === "REMOVE") && await b(t.currentAction, t.htmlBuffer), l && (l.remove(), l = null);
115
+ return;
116
+ }
117
+ if (o.startsWith("--THINKING=")) {
118
+ const a = o.substring(11);
119
+ e((c) => {
120
+ const y = [...c], B = y[y.length - 1];
121
+ if (B && B.role === "assistant" && B.isReasoning)
122
+ B.content = a, B.isStreaming = !1;
123
+ else {
124
+ const w = {
125
+ id: Date.now().toString(),
126
+ role: "assistant",
127
+ content: a,
128
+ isReasoning: !0,
129
+ isStreaming: !1
130
+ };
131
+ y.push(w);
132
+ }
133
+ return y;
134
+ });
135
+ return;
136
+ }
137
+ if (o.startsWith("--TASK=")) {
138
+ const a = o.substring(7), c = `task-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, y = {
139
+ id: c,
140
+ role: "assistant",
141
+ content: a.replace(/--$/, ""),
142
+ isTask: !0,
143
+ isTaskLoading: !0,
144
+ isTaskCompleted: !1
145
+ };
146
+ f = c, e((B) => [...B, y]);
147
+ return;
148
+ }
149
+ if (o.startsWith("--MSG=")) {
150
+ const a = o.substring(6), c = {
151
+ id: Date.now().toString(),
152
+ role: "assistant",
153
+ content: a.replace(/--$/g, ""),
154
+ isReasoning: !1,
155
+ isStreaming: !1
156
+ };
157
+ e((y) => [...y, c]);
158
+ return;
159
+ }
160
+ if (o.startsWith("--ACTION=")) {
161
+ t.currentAction && (t.htmlBuffer || t.currentAction.type === "REMOVE") && await b(t.currentAction, t.htmlBuffer), t.currentAction = M(o), t.htmlBuffer = "", t.isInAction = !0;
162
+ return;
163
+ }
164
+ if (o === "--ENDACTION--") {
165
+ t.currentAction && (t.htmlBuffer || t.currentAction.type === "REMOVE") && await b(t.currentAction, t.htmlBuffer), f && (e((a) => a.map((c) => c.isTask ? { ...c, isTaskCompleted: !0 } : c)), f = null), t.currentAction = null, t.htmlBuffer = "", t.isInAction = !1;
166
+ return;
167
+ }
168
+ if (o === "--HTML--") {
169
+ t.isCapturingHtml = !0;
170
+ return;
171
+ }
172
+ if (o === "--ENDHTML--") {
173
+ t.isCapturingHtml = !1;
174
+ return;
175
+ }
176
+ if (o.startsWith("--HTML--") && o.includes("--ENDHTML--")) {
177
+ const a = o.match(/^--HTML--(.+?)--ENDHTML--$/);
178
+ if (a && t.currentAction) {
179
+ const c = a[1];
180
+ t.htmlBuffer += c, t.currentAction.type === "ADD" ? R(t.htmlBuffer, t.currentAction.parentId, t.currentAction.position) : t.currentAction.type === "EDIT" && t.currentAction.blockId && p(t.htmlBuffer, t.currentAction.blockId);
181
+ }
182
+ return;
183
+ }
184
+ t.isCapturingHtml && t.currentAction && (t.htmlBuffer += S + `
185
+ `, t.currentAction.type === "ADD" ? R(t.htmlBuffer, t.currentAction.parentId, t.currentAction.position) : t.currentAction.type === "EDIT" && t.currentAction.blockId && p(t.htmlBuffer, t.currentAction.blockId));
186
+ }
187
+ }, b = async (S, o) => {
188
+ try {
189
+ switch (S.type) {
190
+ case "ADD":
191
+ await A(S, o);
192
+ break;
193
+ case "EDIT":
194
+ await h(S, o);
195
+ break;
196
+ case "REMOVE":
197
+ await v(S);
198
+ break;
199
+ }
200
+ e((a) => a.filter((c) => !c.isTask));
201
+ } catch (a) {
202
+ console.log(a);
203
+ }
204
+ };
205
+ try {
206
+ for (; ; ) {
207
+ const { done: S, value: o } = await s.read();
208
+ if (S) break;
209
+ const a = r.decode(o, { stream: !0 });
210
+ u += a, d += a;
211
+ const c = d.split(`
212
+ `);
213
+ d = c.pop() || "";
214
+ for (const y of c)
215
+ await C(y);
216
+ }
217
+ d && await C(d), k.invalidateQueries({
218
+ queryKey: ["AI_USAGE"]
219
+ });
220
+ } catch (S) {
221
+ console.log(S);
222
+ }
223
+ },
224
+ [m]
225
+ );
226
+ }, St = dt(() => import("./ai-prompt-input-Bhc0ds7X.js")), Mt = ({
227
+ t: i,
228
+ fetch: I,
229
+ input: m,
230
+ messages: k,
231
+ setInput: A,
232
+ isLoading: h,
233
+ setMessages: v,
234
+ handleStop: l,
235
+ setIsLoading: T,
236
+ currentBlock: E,
237
+ fallbackLang: R,
238
+ setCurrentBlock: p,
239
+ setAbortController: M,
240
+ selectedModel: s = mt().id,
241
+ onModelChange: e
242
+ }) => {
243
+ const r = G(), [, u] = _(), d = z(), n = It(), f = async (t, C, b, S) => {
244
+ var B;
245
+ if (!t || h) return;
246
+ p(r);
247
+ const o = d(r ? { blockId: r._id, additionalCoreBlocks: ["Icon"] } : { additionalCoreBlocks: ["Icon"] });
248
+ if (r && !o) {
249
+ ft.error(i("Something went wrong. Please try again."));
250
+ return;
251
+ }
252
+ const a = {
253
+ id: Date.now().toString(),
254
+ role: "user",
255
+ content: it({
256
+ language: R,
257
+ userInput: C || t,
258
+ currentHtml: o
259
+ }),
260
+ userMessage: t
261
+ }, c = {
262
+ id: (Date.now() + 1).toString(),
263
+ role: "assistant",
264
+ content: "",
265
+ isReasoning: !0,
266
+ isStreaming: !0
267
+ };
268
+ v((w) => [...w, a, c]), T(!0);
269
+ const y = new AbortController();
270
+ M(y);
271
+ try {
272
+ const w = {
273
+ messages: [a].map((H) => ({
274
+ role: H.role,
275
+ content: H.content
276
+ })),
277
+ model: S || s
278
+ };
279
+ b && (w.image = b);
280
+ const x = await I({ body: { action: "ASK_AI", data: w }, streamResponse: !0 });
281
+ if (!x.ok)
282
+ throw new Error(i("Failed to get AI response"));
283
+ const N = (B = x.body) == null ? void 0 : B.getReader();
284
+ if (!N) throw new Error(i("Response body is not readable"));
285
+ await n(N, v);
286
+ } catch (w) {
287
+ if (w.name !== "AbortError") {
288
+ const x = {
289
+ id: (Date.now() + 1).toString(),
290
+ role: "assistant",
291
+ content: i("Sorry, I encountered an error. Please try again.")
292
+ };
293
+ v((N) => [...N, x]);
294
+ }
295
+ } finally {
296
+ A(""), T(!1), p(null), M(null);
297
+ }
298
+ };
299
+ return /* @__PURE__ */ D(W, { children: [
300
+ /* @__PURE__ */ D(Q, { className: "no-scrollbar", children: [
301
+ /* @__PURE__ */ D(J, { className: "gap-2 px-0", children: [
302
+ k.length === 0 && /* @__PURE__ */ g(
303
+ X,
304
+ {
305
+ icon: /* @__PURE__ */ g(ct, { size: 48, className: "text-gray-300" }),
306
+ title: "Start a conversation",
307
+ description: i("Start a conversation with the AI assistant to add/edit current page")
308
+ }
309
+ ),
310
+ k.map(
311
+ (t) => t.role !== "system" && /* @__PURE__ */ g(lt, { children: t.isReasoning ? /* @__PURE__ */ D(Y, { isStreaming: t.isStreaming, defaultOpen: !0, children: [
312
+ /* @__PURE__ */ g(Z, { className: "text-xs [&_p]:text-muted-foreground" }),
313
+ /* @__PURE__ */ g(tt, { className: "p-0 text-xs", children: t.content })
314
+ ] }) : t.isTask && !t.isTaskCompleted ? /* @__PURE__ */ g(et, { content: t.content, isLoading: t.isTaskLoading }) : /* @__PURE__ */ g(nt, { from: t.role, children: /* @__PURE__ */ g(rt, { className: "p-0", children: t.role === "assistant" ? /* @__PURE__ */ g(st, { className: "p-0 text-xs", children: t.content }) : /* @__PURE__ */ g("div", { className: "p-0 text-xs", children: t.userMessage || t.content }) }) }) }, t.id)
315
+ )
316
+ ] }),
317
+ /* @__PURE__ */ g(ot, {})
318
+ ] }),
319
+ /* @__PURE__ */ D("div", { className: "border-gray-200 pb-2", children: [
320
+ /* @__PURE__ */ g(at, { onRemove: () => u([]), isLoading: h }),
321
+ /* @__PURE__ */ g(ut, { fallback: /* @__PURE__ */ g("div", { children: "Loading..." }), children: /* @__PURE__ */ g(
322
+ St,
323
+ {
324
+ input: m,
325
+ setInput: A,
326
+ onSend: f,
327
+ onStop: l,
328
+ isLoading: h,
329
+ selectedLang: "",
330
+ currentBlock: r || E,
331
+ disabled: (m == null ? void 0 : m.length) === 0,
332
+ selectedModel: s,
333
+ onModelChange: e
334
+ }
335
+ ) })
336
+ ] })
337
+ ] });
338
+ };
339
+ export {
340
+ Mt as default
341
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-DF5DEvqb.cjs"),f=require("lodash-es"),l=require("react"),G=require("./core-BoRDjj4h.cjs"),c=require("./selected-block-display-BgRY82CT.cjs"),H=require("lucide-react"),Q=require("react-i18next"),X=require("./models-5gOsRC56.cjs"),C=(s,o)=>{const r=s.filter(n=>n._parent===o),i=r.flatMap(n=>C(s,n._id));return[...r,...i]},Y=(s,o)=>{const r=o.find(n=>n._id===s);if(!r)return[];const i=C(o,s);return[r,...i]},Z=()=>{const s=p.useSelectedBlock(),[o]=p.useBlocksStore();return l.useCallback((r="")=>{const i=s!=null&&s._id?Y(s._id,o):o;return i?f.compact(i.map(n=>{const h=G.getRegisteredChaiBlock(n._type);if(!h)return null;const x=(h==null?void 0:h.i18nProps)??[];if(x.length===0)return null;const g=r==="ALL"?Object.keys(n).filter(a=>x.find(S=>a.startsWith(S))):x.map(a=>r?`${a}-${r}`:a),d=f.pick(n,["_id"]);return f.each(g,a=>{d[a]=f.get(n,a,f.get(n,a.replace(`-${r}`,"")))}),d})):[]},[s==null?void 0:s._id,o])},ee=l.lazy(()=>Promise.resolve().then(()=>require("./ai-translation-prompt-C2kJQFDX.cjs"))),te=l.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-CThbVp0_.cjs"))),ne=({fetch:s,input:o,messages:r,setInput:i,isLoading:n,handleStop:h,setMessages:x,setIsLoading:g,selectedLang:d,currentBlock:a,fallbackLang:S,abortController:k,setAbortController:E,setCurrentBlock:T,selectedModel:B=X.getDefaultModel().id,onModelChange:M})=>{const{t:u}=Q.useTranslation(),O=l.useRef(null),y=p.useSelectedBlock(),[,D]=p.useSelectedBlockIds(),R=Z(),I=p.useStreamMultipleBlocksProps(),F=()=>{var t;(t=O.current)==null||t.scrollIntoView({behavior:"smooth"})};l.useEffect(()=>{F()},[r,n]);const N=async(t,w,$)=>{var P;y&&T(y);const q=(t==null?void 0:t.toLowerCase())==="translate",v={id:Date.now().toString(),role:"user",content:c.getTranslationUserPrompt({fallbackLang:S,userInput:w||t,language:d,blocks:q?R():R(d)}),userMessage:w||t||u("Translate the content")},z={id:(Date.now()+1).toString(),role:"assistant",content:"Thinking...",isReasoning:!0,isStreaming:!0};g(!0);const W=new AbortController;E(W),x(b=>[...b,v,z]),g(!0);try{const A=await s({body:{action:"ASK_AI",data:{messages:[v],initiator:q?"TRANSLATE_CONTENT":"UPDATE_CONTENT",model:$||B}},streamResponse:!0});if(!A.ok)throw new Error(u("Failed to get AI response"));const _=(P=A.body)==null?void 0:P.getReader(),U=new TextDecoder;let j="";if(!_)throw new Error(u("Response body is not readable"));for(;;){const{done:K,value:L}=await _.read();if(K)break;const V=U.decode(L,{stream:!0});j+=V,x(m=>(m[m.length-1].content=j,[...m]))}const J=JSON.parse(j==null?void 0:j.replace("```json","").replace("```",""));I(J)}catch{k==null||k.abort()}finally{g(!1),i(""),T(null)}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(l.Suspense,{fallback:e.jsx("div",{children:u("Loading...")}),children:e.jsx(ee,{isLoading:n,selectedBlock:y,selectedLang:d,onClick:N})})}),e.jsx(c.Conversation,{children:e.jsxs(c.ConversationContent,{className:"gap-4 px-0",children:[r.length===0&&e.jsx(c.ConversationEmptyState,{icon:e.jsx(H.Bot,{size:48,className:"text-gray-300"}),title:u("Start a conversation with the AI assistant to translate/edit your content"),description:u("Only content can be edited in secondary languages. To edit layout, styles and more, switch to the default language.")}),r.map(t=>t.role!=="system"&&e.jsx(l.Fragment,{children:t.isReasoning?e.jsxs(c.Reasoning,{isStreaming:t.isStreaming,defaultOpen:!0,children:[e.jsx(c.ReasoningTrigger,{className:"text-xs [&_p]:text-muted-foreground"}),e.jsx(c.ReasoningContent,{className:"p-0 text-xs",children:t.content})]}):t.isTask?e.jsx(c.TaskMessage,{content:t.content,isLoading:t.isTaskLoading}):e.jsx(c.Message,{from:t.role,children:e.jsx(c.MessageContent,{className:"p-0",children:t.role==="assistant"?e.jsx(c.MessageResponse,{className:"p-0 text-xs",children:t.content}):e.jsx("div",{className:"p-0 text-xs",children:t.userMessage||t.content})})})},t.id))]})}),e.jsxs("div",{className:"border-gray-200 pb-2",children:[e.jsx(c.SelectedBlockDisplay,{onRemove:()=>D([]),isLoading:n}),e.jsx(l.Suspense,{fallback:e.jsx("div",{children:u("Loading...")}),children:e.jsx(te,{input:o,setInput:i,onSend:N,onStop:h,isLoading:n,selectedLang:d,currentBlock:y||a,disabled:(o==null?void 0:o.length)===0,selectedModel:B,onModelChange:M})})]})]})};exports.default=ne;
@@ -0,0 +1,162 @@
1
+ import { jsxs as p, Fragment as H, jsx as t } from "react/jsx-runtime";
2
+ import { as as P, ah as Q, a as X, au as Y } from "./index-Ct7ElCGK.js";
3
+ import { compact as Z, pick as ee, each as te, get as v } from "lodash-es";
4
+ import { useCallback as ne, useRef as se, useEffect as oe, Suspense as M, lazy as E, Fragment as re } from "react";
5
+ import { e as ae } from "./core-yvI6kCyw.js";
6
+ import { C as ie, a as ce, b as le, R as de, c as ue, d as he, T as me, M as fe, e as pe, f as ge, S as ye, i as Se } from "./selected-block-display-CBFePS19.js";
7
+ import { Bot as Te } from "lucide-react";
8
+ import { useTranslation as ke } from "react-i18next";
9
+ import { g as Ne } from "./models-D95ZYr_x.js";
10
+ const O = (s, r) => {
11
+ const o = s.filter((n) => n._parent === r), i = o.flatMap((n) => O(s, n._id));
12
+ return [...o, ...i];
13
+ }, we = (s, r) => {
14
+ const o = r.find((n) => n._id === s);
15
+ if (!o) return [];
16
+ const i = O(r, s);
17
+ return [o, ...i];
18
+ }, Be = () => {
19
+ const s = P(), [r] = Q();
20
+ return ne(
21
+ (o = "") => {
22
+ const i = s != null && s._id ? we(s._id, r) : r;
23
+ return i ? Z(
24
+ i.map((n) => {
25
+ const d = ae(n._type);
26
+ if (!d) return null;
27
+ const u = (d == null ? void 0 : d.i18nProps) ?? [];
28
+ if (u.length === 0) return null;
29
+ const h = o === "ALL" ? Object.keys(n).filter((a) => u.find((g) => a.startsWith(g))) : u.map((a) => o ? `${a}-${o}` : a), c = ee(n, ["_id"]);
30
+ return te(h, (a) => {
31
+ c[a] = v(n, a, v(n, a.replace(`-${o}`, "")));
32
+ }), c;
33
+ })
34
+ ) : [];
35
+ },
36
+ [s == null ? void 0 : s._id, r]
37
+ );
38
+ }, Re = E(() => import("./ai-translation-prompt-CZ55HQmo.js")), xe = E(() => import("./ai-prompt-input-Bhc0ds7X.js")), De = ({
39
+ fetch: s,
40
+ input: r,
41
+ messages: o,
42
+ setInput: i,
43
+ isLoading: n,
44
+ handleStop: d,
45
+ setMessages: u,
46
+ setIsLoading: h,
47
+ selectedLang: c,
48
+ currentBlock: a,
49
+ fallbackLang: g,
50
+ abortController: y,
51
+ setAbortController: D,
52
+ setCurrentBlock: T,
53
+ selectedModel: k = Ne().id,
54
+ onModelChange: j
55
+ }) => {
56
+ const { t: l } = ke(), F = se(null), f = P(), [, I] = X(), N = Be(), $ = Y(), W = () => {
57
+ var e;
58
+ (e = F.current) == null || e.scrollIntoView({ behavior: "smooth" });
59
+ };
60
+ oe(() => {
61
+ W();
62
+ }, [o, n]);
63
+ const w = async (e, B, q) => {
64
+ var A;
65
+ f && T(f);
66
+ const R = (e == null ? void 0 : e.toLowerCase()) === "translate", x = {
67
+ id: Date.now().toString(),
68
+ role: "user",
69
+ content: Se({
70
+ fallbackLang: g,
71
+ userInput: B || e,
72
+ language: c,
73
+ blocks: R ? N() : N(c)
74
+ }),
75
+ userMessage: B || e || l("Translate the content")
76
+ }, z = {
77
+ id: (Date.now() + 1).toString(),
78
+ role: "assistant",
79
+ content: "Thinking...",
80
+ isReasoning: !0,
81
+ isStreaming: !0
82
+ };
83
+ h(!0);
84
+ const U = new AbortController();
85
+ D(U), u((_) => [..._, x, z]), h(!0);
86
+ try {
87
+ const b = await s({ body: { action: "ASK_AI", data: {
88
+ messages: [x],
89
+ initiator: R ? "TRANSLATE_CONTENT" : "UPDATE_CONTENT",
90
+ model: q || k
91
+ } }, streamResponse: !0 });
92
+ if (!b.ok)
93
+ throw new Error(l("Failed to get AI response"));
94
+ const C = (A = b.body) == null ? void 0 : A.getReader(), J = new TextDecoder();
95
+ let m = "";
96
+ if (!C) throw new Error(l("Response body is not readable"));
97
+ for (; ; ) {
98
+ const { done: L, value: V } = await C.read();
99
+ if (L)
100
+ break;
101
+ const G = J.decode(V, { stream: !0 });
102
+ m += G, u((S) => (S[S.length - 1].content = m, [...S]));
103
+ }
104
+ const K = JSON.parse(m == null ? void 0 : m.replace("```json", "").replace("```", ""));
105
+ $(K);
106
+ } catch {
107
+ y == null || y.abort();
108
+ } finally {
109
+ h(!1), i(""), T(null);
110
+ }
111
+ };
112
+ return /* @__PURE__ */ p(H, { children: [
113
+ /* @__PURE__ */ t("div", { className: "py-2", children: /* @__PURE__ */ t(M, { fallback: /* @__PURE__ */ t("div", { children: l("Loading...") }), children: /* @__PURE__ */ t(
114
+ Re,
115
+ {
116
+ isLoading: n,
117
+ selectedBlock: f,
118
+ selectedLang: c,
119
+ onClick: w
120
+ }
121
+ ) }) }),
122
+ /* @__PURE__ */ t(ie, { children: /* @__PURE__ */ p(ce, { className: "gap-4 px-0", children: [
123
+ o.length === 0 && /* @__PURE__ */ t(
124
+ le,
125
+ {
126
+ icon: /* @__PURE__ */ t(Te, { size: 48, className: "text-gray-300" }),
127
+ title: l("Start a conversation with the AI assistant to translate/edit your content"),
128
+ description: l(
129
+ "Only content can be edited in secondary languages. To edit layout, styles and more, switch to the default language."
130
+ )
131
+ }
132
+ ),
133
+ o.map(
134
+ (e) => e.role !== "system" && /* @__PURE__ */ t(re, { children: e.isReasoning ? /* @__PURE__ */ p(de, { isStreaming: e.isStreaming, defaultOpen: !0, children: [
135
+ /* @__PURE__ */ t(ue, { className: "text-xs [&_p]:text-muted-foreground" }),
136
+ /* @__PURE__ */ t(he, { className: "p-0 text-xs", children: e.content })
137
+ ] }) : e.isTask ? /* @__PURE__ */ t(me, { content: e.content, isLoading: e.isTaskLoading }) : /* @__PURE__ */ t(fe, { from: e.role, children: /* @__PURE__ */ t(pe, { className: "p-0", children: e.role === "assistant" ? /* @__PURE__ */ t(ge, { className: "p-0 text-xs", children: e.content }) : /* @__PURE__ */ t("div", { className: "p-0 text-xs", children: e.userMessage || e.content }) }) }) }, e.id)
138
+ )
139
+ ] }) }),
140
+ /* @__PURE__ */ p("div", { className: "border-gray-200 pb-2", children: [
141
+ /* @__PURE__ */ t(ye, { onRemove: () => I([]), isLoading: n }),
142
+ /* @__PURE__ */ t(M, { fallback: /* @__PURE__ */ t("div", { children: l("Loading...") }), children: /* @__PURE__ */ t(
143
+ xe,
144
+ {
145
+ input: r,
146
+ setInput: i,
147
+ onSend: w,
148
+ onStop: d,
149
+ isLoading: n,
150
+ selectedLang: c,
151
+ currentBlock: f || a,
152
+ disabled: (r == null ? void 0 : r.length) === 0,
153
+ selectedModel: k,
154
+ onModelChange: j
155
+ }
156
+ ) })
157
+ ] })
158
+ ] });
159
+ };
160
+ export {
161
+ De as default
162
+ };