@blinkk/root-cms 3.0.2 → 3.0.4

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 (161) hide show
  1. package/dist/app.js +5 -5
  2. package/dist/{chunk-2BSW7SIH.js → chunk-N4K6ICFR.js} +4 -4
  3. package/dist/{chunk-BGTUWIV6.js → chunk-PNLLZXVY.js} +4 -4
  4. package/dist/{chunk-3HARN4U6.js → chunk-RLZFZT42.js} +176 -83
  5. package/dist/{chunk-C245C557.js → chunk-RXWDB3K4.js} +3 -3
  6. package/dist/{chunk-XLX37FRL.js → chunk-TEKMLYXS.js} +3 -4
  7. package/dist/cli/cli.d.ts +12 -0
  8. package/dist/cli/docs.d.ts +49 -0
  9. package/dist/cli/export.d.ts +11 -0
  10. package/dist/cli/generate-types.d.ts +6 -0
  11. package/dist/cli/import.d.ts +13 -0
  12. package/dist/cli/init-firebase.d.ts +7 -0
  13. package/dist/cli/utils.d.ts +27 -0
  14. package/dist/cli.js +10 -10
  15. package/dist/client.js +1 -1
  16. package/dist/core/ai-tools.d.ts +156 -0
  17. package/dist/core/ai.d.ts +330 -0
  18. package/dist/core/api.d.ts +21 -0
  19. package/dist/core/app.d.ts +16 -0
  20. package/dist/core/checks-translations.d.ts +13 -0
  21. package/dist/core/checks.d.ts +48 -0
  22. package/dist/core/client.d.ts +715 -0
  23. package/dist/core/core.d.ts +5 -0
  24. package/dist/core/cron.d.ts +19 -0
  25. package/dist/core/csv.d.ts +5 -0
  26. package/dist/core/functions.d.ts +9 -0
  27. package/dist/core/plugin.d.ts +357 -0
  28. package/dist/{project.d.ts → core/project.d.ts} +8 -12
  29. package/dist/core/richtext.d.ts +101 -0
  30. package/dist/{core.d.ts → core/route.d.ts} +13 -66
  31. package/dist/core/runtime.d.ts +46 -0
  32. package/dist/{schema-Db_xODoi.d.ts → core/schema.d.ts} +47 -100
  33. package/dist/core/search-extract.d.ts +70 -0
  34. package/dist/core/search-index.d.ts +182 -0
  35. package/dist/core/search-query.d.ts +68 -0
  36. package/dist/core/security.d.ts +6 -0
  37. package/dist/core/server-version.d.ts +5 -0
  38. package/dist/core/services-notifications.d.ts +57 -0
  39. package/dist/core/services.d.ts +44 -0
  40. package/dist/core/sse.d.ts +10 -0
  41. package/dist/core/translations-manager.d.ts +187 -0
  42. package/dist/core/translations.d.ts +83 -0
  43. package/dist/core/url-safety.d.ts +19 -0
  44. package/dist/core/validation.d.ts +30 -0
  45. package/dist/core/values.d.ts +9 -0
  46. package/dist/core/versions.d.ts +48 -0
  47. package/dist/core.js +1 -1
  48. package/dist/edit-M4PN4SGX.js +7 -0
  49. package/dist/functions.js +4 -4
  50. package/dist/{generate-types-SPV7I3A5.js → generate-types-JWIG4QVI.js} +1 -1
  51. package/dist/plugin.js +128 -133
  52. package/dist/shared/marshal.d.ts +68 -0
  53. package/dist/shared/objects.d.ts +9 -0
  54. package/dist/shared/richtext.d.ts +74 -0
  55. package/dist/shared/safe-json.d.ts +11 -0
  56. package/dist/shared/sanitize.d.ts +12 -0
  57. package/dist/shared/slug.d.ts +19 -0
  58. package/dist/shared/sse.d.ts +16 -0
  59. package/dist/shared/strings.d.ts +23 -0
  60. package/dist/ui/AIPage-YI3RFK5F.js +1 -0
  61. package/dist/ui/AssetsPage-4JNAOFYF.js +1 -0
  62. package/dist/ui/CollectionPage-JWHH5G55.js +1 -0
  63. package/dist/ui/ComparePage-YZE3EMU4.js +1 -0
  64. package/dist/ui/DataPage-VRCQSZZG.js +1 -0
  65. package/dist/ui/DataSourcePage-WMSPBZ3W.js +1 -0
  66. package/dist/ui/DocTranslationsPage-RY2LOZBX.js +1 -0
  67. package/dist/ui/DocumentPage-EEGTJMIW.js +1 -0
  68. package/dist/ui/EditDataSourcePage-LLCX6K4J.js +1 -0
  69. package/dist/ui/EditReleasePage-WQYXXMZQ.js +1 -0
  70. package/dist/ui/ImageEditorDialog-4H665KK2.js +81 -0
  71. package/dist/ui/ImageEditorDialog-4H665KK2.js.LEGAL.txt +17 -0
  72. package/dist/ui/LogsPage-IP2DKEYR.js +1 -0
  73. package/dist/ui/NewDataSourcePage-RDYJC4DH.js +1 -0
  74. package/dist/ui/NewReleasePage-DGMFU2JN.js +1 -0
  75. package/dist/ui/NotFoundPage-WDZ2K7EF.js +1 -0
  76. package/dist/ui/ProjectPage-HYJOQUWR.js +1 -0
  77. package/dist/ui/ReleasePage-2KSF23TK.js +1 -0
  78. package/dist/ui/ReleasesPage-NZIBBXU4.js +1 -0
  79. package/dist/ui/SettingsPage-36XFWV62.js +1 -0
  80. package/dist/ui/SidebarToolsPage-5C6YBWJ7.js +1 -0
  81. package/dist/ui/TaskPage-SPIFPGPP.js +1 -0
  82. package/dist/ui/TasksPage-ZOXRPBQV.js +1 -0
  83. package/dist/ui/TranslationsArbPage-UHANA7JD.js +2 -0
  84. package/dist/ui/TranslationsEditPage-PQY6W5YG.js +1 -0
  85. package/dist/ui/TranslationsPage-V2PQFCN5.js +162 -0
  86. package/dist/ui/ai-tools-5E5ELLZX.js +1 -0
  87. package/dist/ui/chunk-3IYZCUPI.js +1 -0
  88. package/dist/ui/chunk-4KE2SZKH.js +1 -0
  89. package/dist/ui/chunk-4W73RW5I.js +1 -0
  90. package/dist/ui/chunk-54DVDYU6.js +1 -0
  91. package/dist/ui/chunk-5MV6XVGA.js +1 -0
  92. package/dist/ui/chunk-62UWGWON.js +1 -0
  93. package/dist/ui/chunk-767BAQ53.js +1 -0
  94. package/dist/ui/chunk-AFWBSIPL.js +1 -0
  95. package/dist/ui/chunk-AL3TN2KI.js +1 -0
  96. package/dist/ui/chunk-BZIRGB4W.js +1 -0
  97. package/dist/ui/chunk-C5NH23G4.js +3 -0
  98. package/dist/ui/chunk-CGCKJFL4.js +1 -0
  99. package/dist/ui/chunk-DEGMKEHP.js +1 -0
  100. package/dist/ui/chunk-DTMZLUNY.js +15 -0
  101. package/dist/ui/chunk-DTMZLUNY.js.LEGAL.txt +237 -0
  102. package/dist/ui/chunk-DUJYIOLE.js +5 -0
  103. package/dist/ui/chunk-E2RCCK2T.js +1 -0
  104. package/dist/ui/chunk-EGEB6N4J.js +22 -0
  105. package/dist/ui/chunk-EGEB6N4J.js.LEGAL.txt +1059 -0
  106. package/dist/ui/chunk-FBJURT7Z.js +1 -0
  107. package/dist/ui/chunk-GXSAEPU3.js +1 -0
  108. package/dist/ui/chunk-HHMG665Z.js +1 -0
  109. package/dist/ui/chunk-HKINZLMW.js +84 -0
  110. package/dist/ui/chunk-HLMBCVRX.js +1 -0
  111. package/dist/ui/chunk-HRGYNHZ3.js +1 -0
  112. package/dist/ui/chunk-I6ICVKEC.js +1 -0
  113. package/dist/ui/chunk-JDW4UORS.js +1 -0
  114. package/dist/ui/chunk-JHBAMPGB.js +1 -0
  115. package/dist/ui/chunk-JT5L6GPZ.js +141 -0
  116. package/dist/ui/chunk-JT5L6GPZ.js.LEGAL.txt +106 -0
  117. package/dist/ui/chunk-JYFLU7DM.js +19 -0
  118. package/dist/ui/chunk-JZFTZ4X4.js +87 -0
  119. package/dist/ui/chunk-JZFTZ4X4.js.LEGAL.txt +9 -0
  120. package/dist/ui/chunk-KFAZBEPV.js +1 -0
  121. package/dist/ui/chunk-KKEWCXVV.js +1 -0
  122. package/dist/ui/chunk-KUCVLANF.js +1 -0
  123. package/dist/ui/chunk-KYDOSLTO.js +1 -0
  124. package/dist/ui/chunk-L4RHGQUG.js +1 -0
  125. package/dist/ui/chunk-MDUBCXU2.js +1 -0
  126. package/dist/ui/chunk-NXQVLOTK.js +1 -0
  127. package/dist/ui/chunk-NZHF733K.js +7 -0
  128. package/dist/ui/chunk-NZHF733K.js.LEGAL.txt +146 -0
  129. package/dist/ui/chunk-ONTGW2VA.js +1 -0
  130. package/dist/ui/chunk-ORXEMIQC.js +1 -0
  131. package/dist/ui/chunk-P3NETZZP.js +1 -0
  132. package/dist/ui/chunk-PHBMVORG.js +1 -0
  133. package/dist/ui/chunk-PJA7YP4A.js +1 -0
  134. package/dist/ui/chunk-PVAE643M.js +1 -0
  135. package/dist/ui/chunk-PWKJDYE2.js +1 -0
  136. package/dist/ui/chunk-RSVO46S3.js +1 -0
  137. package/dist/ui/chunk-SKEP5WYH.js +10 -0
  138. package/dist/ui/chunk-SKEP5WYH.js.LEGAL.txt +176 -0
  139. package/dist/ui/chunk-SQRKKWRG.js +3 -0
  140. package/dist/ui/chunk-TJBVMFNQ.js +1 -0
  141. package/dist/ui/chunk-V7S4IAGB.js +1 -0
  142. package/dist/ui/chunk-VMT7JFAM.js +1 -0
  143. package/dist/ui/chunk-W3BJ2EZX.js +1 -0
  144. package/dist/ui/chunk-W3HIZQ4Z.js +1 -0
  145. package/dist/ui/chunk-X2WHBGTP.js +1 -0
  146. package/dist/ui/chunk-XOQ3KDSR.js +3 -0
  147. package/dist/ui/chunk-YDO2EDVY.js +1 -0
  148. package/dist/ui/chunk-YFA6U2CV.js +1 -0
  149. package/dist/ui/gcs-L33FIRZU.js +1 -0
  150. package/dist/ui/prerender-Q4YSDCPB.js +1 -0
  151. package/dist/ui/signin.js +1 -1
  152. package/dist/ui/ui.css +1 -1
  153. package/dist/ui/ui.js +1 -630
  154. package/dist/ui/ui.js.LEGAL.txt +19 -732
  155. package/package.json +20 -20
  156. package/dist/client-1puwLgNx.d.ts +0 -1552
  157. package/dist/client.d.ts +0 -5
  158. package/dist/edit-MT4B37QK.js +0 -7
  159. package/dist/functions.d.ts +0 -13
  160. package/dist/plugin.d.ts +0 -5
  161. package/dist/richtext.d.ts +0 -104
@@ -0,0 +1,106 @@
1
+ Bundled license information:
2
+
3
+ use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js:
4
+ /**
5
+ * @license React
6
+ * use-sync-external-store-with-selector.production.js
7
+ *
8
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+
14
+ prismjs/prism.js:
15
+ /**
16
+ * Prism: Lightweight, robust, elegant syntax highlighting
17
+ *
18
+ * @license MIT <https://opensource.org/licenses/MIT>
19
+ * @author Lea Verou <https://lea.verou.me>
20
+ * @namespace
21
+ * @public
22
+ */
23
+
24
+ @editorjs/editorjs/dist/editorjs.mjs:
25
+ /*!
26
+ * CodeX.Tooltips
27
+ *
28
+ * @version 1.0.5
29
+ *
30
+ * @licence MIT
31
+ * @author CodeX <https://codex.so>
32
+ *
33
+ *
34
+ */
35
+ /*!
36
+ * Library for handling keyboard shortcuts
37
+ * @copyright CodeX (https://codex.so)
38
+ * @license MIT
39
+ * @author CodeX (https://codex.so)
40
+ * @version 1.2.0
41
+ */
42
+ /**
43
+ * Base Paragraph Block for the Editor.js.
44
+ * Represents a regular text block
45
+ *
46
+ * @author CodeX (team@codex.so)
47
+ * @copyright CodeX 2018
48
+ * @license The MIT License (MIT)
49
+ */
50
+ /**
51
+ * Editor.js
52
+ *
53
+ * @license Apache-2.0
54
+ * @see Editor.js <https://editorjs.io>
55
+ * @author CodeX Team <https://codex.so>
56
+ */
57
+
58
+ @editorjs/header/dist/header.mjs:
59
+ /**
60
+ * Header block for the Editor.js.
61
+ *
62
+ * @author CodeX (team@ifmo.su)
63
+ * @copyright CodeX 2018
64
+ * @license MIT
65
+ * @version 2.0.0
66
+ */
67
+
68
+ @editorjs/image/dist/image.mjs:
69
+ /**
70
+ * Image Tool for the Editor.js
71
+ * @author CodeX <team@codex.so>
72
+ * @license MIT
73
+ * @see {@link https://github.com/editor-js/image}
74
+ *
75
+ * To developers.
76
+ * To simplify Tool structure, we split it to 4 parts:
77
+ * 1) index.ts — main Tool's interface, public API and methods for working with data
78
+ * 2) uploader.ts — module that has methods for sending files via AJAX: from device, by URL or File pasting
79
+ * 3) ui.ts — module for UI manipulations: render, showing preloader, etc
80
+ *
81
+ * For debug purposes there is a testing server
82
+ * that can save uploaded files and return a Response {@link UploadResponseFormat}
83
+ *
84
+ * $ node dev/server.js
85
+ *
86
+ * It will expose 8008 port, so you can pass http://localhost:8008 with the Tools config:
87
+ *
88
+ * image: {
89
+ * class: ImageTool,
90
+ * config: {
91
+ * endpoints: {
92
+ * byFile: 'http://localhost:8008/uploadFile',
93
+ * byUrl: 'http://localhost:8008/fetchUrl',
94
+ * }
95
+ * },
96
+ * },
97
+ */
98
+
99
+ @editorjs/raw/dist/raw.mjs:
100
+ /**
101
+ * Raw HTML Tool for CodeX Editor
102
+ *
103
+ * @author CodeX (team@codex.so)
104
+ * @copyright CodeX 2018
105
+ * @license The MIT License (MIT)
106
+ */
@@ -0,0 +1,19 @@
1
+ import{a as _t,b as ht,c as ut,d as tt}from"./chunk-PHBMVORG.js";import{a as lt,b as mt,d as Z}from"./chunk-JZFTZ4X4.js";import{b as dt,d as ct}from"./chunk-HKINZLMW.js";import{f as pt}from"./chunk-SKEP5WYH.js";import{f as K}from"./chunk-5MV6XVGA.js";import{d as at,f as M}from"./chunk-AL3TN2KI.js";import{$a as X,Bc as rt,Ga as O,Ha as t,Pc as st,Uc as B,V,W as E,_a as q,a as p,ab as Y,c as k,ca as J,e as N,ea as S,ec as G,g as ot,h as T,j as At,jc as Q,kc as it,mb as nt,ra as $,vc as j}from"./chunk-NZHF733K.js";import{d as et}from"./chunk-KUCVLANF.js";At();function ft(o){let{size:e=14}=o,a=e*3.57,i=e*2;return t("div",{className:"BouncingLoader",style:{"--dot-size":`${e}px`,width:`${a}px`,height:`${i}px`}})}var W=[{id:"read",label:"Read only",description:"Inspect CMS content without planning or applying writes."},{id:"approve",label:"Ask before writing",description:"Read freely, then pause for approval before draft edits."},{id:"auto",label:"Auto-apply draft edits",description:"Apply draft-only writes without approval in this chat."}],It="root-cms.ai.executionMode",vt="root-cms.ai.selectedModel";function bt(o){return W.some(e=>e.id===o)}function Rt(){if(typeof window>"u")return"approve";try{let o=window.localStorage.getItem(It);if(bt(o))return o}catch(o){console.error("failed to read AI execution mode preference",o)}return"approve"}function yt(o){if(typeof window>"u")return null;try{let e=window.localStorage.getItem(vt);if(e&&o.some(a=>a.id===e))return e}catch(e){console.error("failed to read AI model preference",e)}return null}function wt(o){if(!(typeof window>"u"))try{window.localStorage.setItem(vt,o)}catch(e){console.error("failed to save AI model preference",e)}}function kt(o){if(!(typeof window>"u"))try{window.localStorage.setItem(It,o)}catch(e){console.error("failed to save AI execution mode preference",e)}}var U="";function Ie(o){let[e,a]=p(null),[i,m]=p("");k(()=>{let r=!0;return fetch("/cms/api/ai.config",{credentials:"include"}).then(async l=>{let g=await l.json();r&&a(g)}).catch(l=>{r&&m(String(l))}),()=>{r=!1}},[]);let h=!!e?.enabled&&(e.models?.length||0)>0;return t("div",{className:M("RootAIChat",`RootAIChat--${o.variant}`),children:!e&&!i?t("div",{className:"RootAIChat__loading",children:t(V,{size:"md",color:"gray"})}):h?t(Mt,{variant:o.variant,config:e,initialChatId:o.variant==="panel"?void 0:o.initialChatId,docContext:o.docContext,onClose:o.onClose}):t(Nt,{error:i,onClose:o.onClose})})}function Nt(o){return t("div",{className:"RootAIChat__notEnabled",children:[o.onClose&&t(E,{className:"RootAIChat__notEnabled__close",onClick:o.onClose,title:"Close",children:t(B,{size:16})}),t("div",{className:"RootAIChat__notEnabled__icon",children:t(j,{size:36})}),t("div",{className:"RootAIChat__notEnabled__title",children:"Root AI is not configured for this project."}),t("div",{className:"RootAIChat__notEnabled__body",children:["Add an ",t("code",{children:"ai.models"})," entry to ",t("code",{children:"cmsPlugin()"})," in"," ",t("code",{children:"root.config.ts"}),"."]}),o.error&&t("pre",{className:"RootAIChat__notEnabled__error",children:o.error})]})}function Mt(o){let e=o.variant==="panel",{route:a}=at(),i=o.config.models||[],m=()=>yt(i)||o.config.defaultModel||i[0]?.id||"",[h,r]=p(m),[l,g]=p(Rt),[u,I]=p(o.initialChatId||U),[P,y]=p(o.initialChatId||U),[D,s]=p([]),[f,x]=p([]),[v,w]=p(0),z=async()=>{if(!e)try{let R=await(await fetch("/cms/api/ai.chats.list",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({})})).json();R.success&&x(R.chats||[])}catch(d){console.error("failed to load chat list",d)}};k(()=>{z(),!e&&o.initialChatId&&n(o.initialChatId)},[]),k(()=>{kt(l)},[l]);let n=async d=>{try{let b=await(await fetch("/cms/api/ai.chats.get",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({id:d})})).json();if(!b.success)return;I(d),y(d),s(b.chat.messages||[]),b.chat.modelId&&i.find(F=>F.id===b.chat.modelId)&&r(b.chat.modelId),w(L=>L+1)}catch(R){console.error("failed to load chat",R)}},_=()=>{r(m()),I(U),y(U),s([]),w(d=>d+1),e||a("/cms/ai")},c=async d=>{if(d!==P)try{let b=await(await fetch("/cms/api/ai.chats.get",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({id:d})})).json();if(!b.success)return;I(d),y(d),s(b.chat.messages||[]),b.chat.modelId&&i.find(F=>F.id===b.chat.modelId)&&r(b.chat.modelId),w(L=>L+1),e||a(`/cms/ai/chat/${d}`)}catch(R){console.error("failed to load chat",R)}},C=async d=>{try{await fetch("/cms/api/ai.chats.delete",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({id:d})}),P===d&&_(),z()}catch(R){console.error("failed to delete chat",R)}},A=i.find(d=>d.id===h)||i[0],H=d=>{r(d),wt(d)};return t("div",{className:"RootAIChat__layout",children:[!e&&t(Tt,{chats:f,activeChatId:P,onSelect:c,onNew:_,onDelete:C}),t("div",{className:"RootAIChat__main",children:[e&&t(Pt,{onNewChat:_,onClose:o.onClose}),t(zt,{initialChatId:u,model:A,initialMessages:D,executionMode:l,models:i,selectedModel:A,docContext:o.docContext,onSelectModel:H,onSelectExecutionMode:g,onChatPersisted:d=>{y(d),z(),e||window.history.replaceState(null,"",`/cms/ai/chat/${d}`)}},v)]})]})}function Pt(o){return t("div",{className:"RootAIChat__panelHeader",children:[t("div",{className:"RootAIChat__panelHeader__title",children:[t(j,{size:14}),t("span",{children:"Root AI"})]}),t("div",{className:"RootAIChat__panelHeader__actions",children:[t(O,{label:"New chat",children:t(E,{size:"xs",onClick:o.onNewChat,children:t(G,{size:14})})}),o.onClose&&t(O,{label:"Close (\u2318 + i)",children:t(E,{size:"xs",onClick:o.onClose,children:t(B,{size:14})})})]})]})}function Tt(o){return t("aside",{className:"RootAIChat__sidebar",children:[t("button",{type:"button",className:"RootAIChat__sidebar__newButton",onClick:o.onNew,children:[t(G,{size:18}),t("span",{children:"New chat"})]}),t("div",{className:"RootAIChat__sidebar__list",children:[o.chats.length===0&&t("div",{className:"RootAIChat__sidebar__empty",children:"No chats yet."}),o.chats.map(e=>t("div",{className:M("RootAIChat__sidebar__item",e.id===o.activeChatId&&"RootAIChat__sidebar__item--active"),onClick:()=>o.onSelect(e.id),children:[t("div",{className:"RootAIChat__sidebar__item__title",title:e.title||"Untitled chat",children:e.title||"Untitled chat"}),t("button",{type:"button",className:"RootAIChat__sidebar__item__delete",title:"Delete chat",onClick:a=>{a.stopPropagation(),window.confirm("Delete this chat?")&&o.onDelete(e.id)},children:t(st,{size:14})})]},e.id))]})]})}function Et(o){let e=W.find(a=>a.id===o.executionMode)||W[0];return t("div",{className:"RootAIChat__options",children:[t($,{control:t(S,{type:"button",className:"RootAIChat__modePicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:t(it,{size:16}),children:e.label}),children:W.map(a=>t($.Item,{onClick:()=>o.onSelectExecutionMode(a.id),children:t("div",{className:"RootAIChat__modePicker__option",children:[t("div",{className:"RootAIChat__modePicker__option__label",children:a.label}),t("div",{className:"RootAIChat__modePicker__option__description",children:a.description})]})},a.id))}),t($,{control:t(S,{type:"button",className:"RootAIChat__modelPicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:t(j,{size:16}),children:o.selectedModel?.label||"Select model"}),children:o.models.map(a=>t($.Item,{onClick:()=>o.onSelectModel(a.id),children:t("div",{className:"RootAIChat__modelPicker__option",children:[t("div",{className:"RootAIChat__modelPicker__option__label",children:a.label}),a.description&&t("div",{className:"RootAIChat__modelPicker__option__description",children:a.description})]})},a.id))})]})}function zt(o){let[e]=p(()=>o.initialChatId||Gt()),a=N(o.model?.id);a.current=o.model?.id;let i=N(o.executionMode);i.current=o.executionMode;let m=N(o.docContext);m.current=o.docContext;let[h,r]=p({}),l=N({});k(()=>()=>{for(let n of Object.values(l.current))n("reject");l.current={}},[]);let g=T((n,_,c,C)=>new Promise(A=>{l.current[n]=A,r(H=>({...H,[n]:{toolCallId:n,toolName:_,input:c,preview:C,status:"pending"}}))}),[]),u=T(n=>{r(_=>{let c=_[n];return c?{..._,[n]:{...c,status:"executing"}}:_}),l.current[n]?.("approve"),delete l.current[n]},[]),I=T(n=>{r(_=>{let c={..._};return delete c[n],c}),l.current[n]?.("reject"),delete l.current[n]},[]),P=T(async n=>{if(!ht(n.toolName))return await tt(n.toolName,n.input);let _=i.current;if(_==="read")return{success:!1,error:"WRITE_BLOCKED_BY_MODE",message:"The current execution mode is read only. Do not call write tools."};let c;try{c=await ut(n.toolName,n.input)}catch(C){return{success:!1,error:"PREVIEW_FAILED",message:C?.message||String(C)}}if(c.error)return{success:!1,error:c.error,message:c.summary,errors:c.errors,hint:c.hint};if(_==="approve"&&await g(n.toolCallId,n.toolName,n.input,c)==="reject")return{success:!1,error:"USER_REJECTED",message:"The user rejected this draft change. Do not retry unless they ask for a revised version."};try{return await tt(n.toolName,n.input)}finally{r(C=>{if(!C[n.toolCallId])return C;let A={...C};return delete A[n.toolCallId],A})}},[g]),y=ot(()=>new dt({api:"/cms/api/ai.chat",credentials:"include",prepareSendMessagesRequest:({messages:n})=>({body:{message:n.at(-1),chatId:e,modelId:a.current,executionMode:i.current,docId:m.current?.docId}})}),[e]),{messages:D,sendMessage:s,status:f,error:x,stop:v,addToolOutput:w}=_t({id:e,messages:o.initialMessages,transport:y,sendAutomaticallyWhen:ct,onToolCall:async({toolCall:n})=>{let _=await P(n);w({tool:n.toolName,toolCallId:n.toolCallId,output:_})},onFinish:()=>{o.onChatPersisted(e)}}),z=f==="streaming"||f==="submitted";return t(et,{children:[t(St,{messages:D,isStreaming:z,emptyMessage:o.model?void 0:"Select a model to start.",toolApprovals:{approvals:h,onApprove:u,onReject:I}}),x&&t("div",{className:"RootAIChat__error",children:[t("strong",{children:"Error:"})," ",x.message]}),t(Vt,{disabled:!o.model,canAttach:o.model?.capabilities.attachments??!1,isStreaming:z,onStop:v,controls:t(Et,{models:o.models,selectedModel:o.selectedModel,onSelectModel:o.onSelectModel,executionMode:o.executionMode,onSelectExecutionMode:o.onSelectExecutionMode}),onSend:(n,_)=>{if(!n&&_.length===0)return;let c=Jt(_),C=[n,c.text].filter(Boolean).join(`
2
+
3
+ `);s({text:C,files:c.files.map(A=>({type:"file",mediaType:A.mediaType,url:A.url,filename:A.filename}))})}})]})}function St(o){let e=N(null);return k(()=>{let a=e.current;a&&(a.scrollTop=a.scrollHeight)},[o.messages]),o.messages.length===0?t("div",{className:"RootAIChat__transcript RootAIChat__transcript--empty",ref:e,children:t("div",{className:"RootAIChat__welcome",children:[t("div",{className:"RootAIChat__welcome__icon",children:t(j,{size:36})}),t("div",{className:"RootAIChat__welcome__title",children:"Root AI"}),t("div",{className:"RootAIChat__welcome__body",children:o.emptyMessage||"What are we going to get done today?"})]})}):t("div",{className:"RootAIChat__transcript",ref:e,children:t("div",{className:"RootAIChat__transcript__inner",children:[o.messages.map(a=>t(jt,{message:a,toolApprovals:o.toolApprovals},a.id)),o.isStreaming&&t("div",{className:"RootAIChat__streamingIndicator",children:t(ft,{size:6})})]})})}function jt(o){let e=o.message,a=e.role==="user",i=a?"You":"Root AI",m=a?window.firebase.user?.photoURL:null,[h,r]=p(!1),l=T(()=>(e.parts||[]).filter(u=>u.type==="text"&&u.text).map(u=>u.text).join(`
4
+
5
+ `),[e.parts]),g=T(async()=>{let u=l();if(!u)return;let I=mt.parse(u);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([I],{type:"text/html"}),"text/plain":new Blob([u],{type:"text/plain"})})]),r(!0),setTimeout(()=>r(!1),2e3)}catch{await navigator.clipboard.writeText(u),r(!0),setTimeout(()=>r(!1),2e3)}},[l]);return t("div",{className:M("RootAIChat__message",`RootAIChat__message--${e.role}`),children:[t("div",{className:"RootAIChat__message__avatar",children:m?t("img",{src:m,alt:i}):t(j,{size:20})}),t("div",{className:"RootAIChat__message__body",children:[t("div",{className:"RootAIChat__message__username",children:i}),t("div",{className:"RootAIChat__message__parts",children:(e.parts||[]).map((u,I)=>t(Dt,{part:u,toolApprovals:o.toolApprovals},I))}),t("button",{type:"button",className:M("RootAIChat__message__copy",h&&"RootAIChat__message__copy--copied"),title:h?"Copied!":"Copy message",onClick:g,children:h?t(q,{size:14}):t(nt,{size:14})})]})]})}function Dt(o){let e=o.part;return e.type==="text"?e.text?t("div",{className:"RootAIChat__textPart",children:t(Z,{code:e.text})}):null:e.type==="reasoning"?t(Lt,{text:e.text}):e.type==="file"?t($t,{part:e}):e.type==="source-url"?t("a",{className:"RootAIChat__sourcePart",href:e.url,target:"_blank",rel:"noopener noreferrer",children:e.title||e.url}):typeof e.type=="string"&&e.type.startsWith("tool-")?t(gt,{part:e,toolApprovals:o.toolApprovals}):e.type==="dynamic-tool"?t(gt,{part:e,toolApprovals:o.toolApprovals}):e.type==="step-start"?null:t("div",{className:"RootAIChat__unknownPart",children:t("pre",{children:JSON.stringify(e,null,2)})})}function Lt(o){let[e,a]=p(!1);return o.text?t("div",{className:M("RootAIChat__reasoning",e&&"RootAIChat__reasoning--open"),children:[t("button",{type:"button",className:"RootAIChat__reasoning__toggle",onClick:()=>a(!e),children:[t(X,{size:14,style:{transform:e?"rotate(0deg)":"rotate(-90deg)"}}),t("span",{children:"Thinking"})]}),e&&t("div",{className:"RootAIChat__reasoning__body",children:t(Z,{code:o.text})})]}):null}function $t(o){let e=o.part;return e.mediaType?.startsWith("image/")?t("div",{className:"RootAIChat__filePart",children:t("img",{src:e.url,alt:e.filename||"attachment"})}):t("a",{className:"RootAIChat__filePart RootAIChat__filePart--link",href:e.url,target:"_blank",rel:"noopener noreferrer",children:[t(Q,{size:14}),t("span",{children:e.filename||e.url})]})}function gt(o){let e=o.part,a=typeof e.type=="string"&&e.type.startsWith("tool-")?e.type.slice(5):e.toolName||"tool",i=e.state||"",m=Bt(e),h=o.toolApprovals,r=m?h?.approvals[m]:void 0,[l,g]=p(!!r);return k(()=>{r&&g(!0)},[r]),t("div",{className:"RootAIChat__tool",children:[t("button",{type:"button",className:"RootAIChat__tool__header",onClick:()=>g(!l),children:[t(X,{className:M("RootAIChat__tool__header__icon",l&&"RootAIChat__tool__header__icon--open"),size:14}),t(J,{color:"dark",variant:"filled",size:"xs",children:a}),t("span",{className:"RootAIChat__tool__title",children:Ot(a,e.input)}),t("span",{className:"RootAIChat__tool__state",children:r?Ht(r.status):Ft(i)})]}),l&&t("div",{className:"RootAIChat__tool__body",children:[r&&h&&t(Ut,{approval:r,onApprove:()=>h.onApprove(r.toolCallId),onReject:()=>h.onReject(r.toolCallId)}),e.output?.receipt&&t(Wt,{output:e.output}),e.input&&t("details",{children:[t("summary",{children:[t(Y,{size:14,className:"RootAIChat__tool__json__icon"}),t("span",{children:"Input"})]}),t("pre",{children:JSON.stringify(e.input,null,2)})]}),e.output&&t("details",{children:[t("summary",{children:[t(Y,{size:14,className:"RootAIChat__tool__json__icon"}),t("span",{children:"Output"})]}),t("pre",{children:JSON.stringify(e.output,null,2)})]}),e.errorText&&t("div",{className:"RootAIChat__tool__error",children:e.errorText})]})]})}function Bt(o){return o.toolCallId||o.id||""}function Ot(o,e){switch(o){case"collections_list":return"List collections";case"docs_list":return`List ${e?.collectionId||"documents"}`;case"docs_search":return`Search docs${e?.query?` for "${e.query}"`:""}`;case"doc_get":return`Read ${e?.docId||"document"}`;case"doc_getVersion":return`Read ${e?.docId||"document"} version`;case"doc_set":return`Replace ${e?.docId||"draft fields"}`;case"doc_create":return`Create ${e?.docId||"draft document"}`;case"doc_updateField":return`Update ${e?.path||"field"}`;case"doc_edit":return`Edit ${e?.docId||"document"}`;case"doc_duplicate":return`Duplicate ${e?.fromDocId||"document"}`;case"doc_listVersions":return`List versions for ${e?.docId||"document"}`;case"doc_translateField":return"Translate field text";case"schema_get":return`Read ${e?.collectionId||"collection"} schema`;default:return o}}function Ut(o){let e=o.approval.preview,a=e.before!==void 0&&e.after!==void 0;return t("div",{className:"RootAIChat__approval",children:[t("div",{className:"RootAIChat__approval__header",children:[t("div",{children:[t("div",{className:"RootAIChat__approval__title",children:e.title}),t("div",{className:"RootAIChat__approval__summary",children:e.summary})]}),t(J,{className:"RootAIChat__approval__status",variant:"light",color:"gray",children:o.approval.status==="executing"?"Applying":"Review"})]}),e.details.length>0&&t("div",{className:"RootAIChat__approval__details",children:e.details.map(i=>t("div",{children:[t("span",{children:i.label}),t("strong",{children:i.value})]},`${i.label}:${i.value}`))}),a&&t(lt,{className:"RootAIChat__approval__diff",oldCode:K(e.before),newCode:K(e.after)}),t("div",{className:"RootAIChat__approval__actions",children:[t(S,{variant:"default",color:"dark",size:"xs",type:"button",className:"RootAIChat__approval__button",disabled:o.approval.status==="executing",onClick:o.onReject,children:"Reject"}),t(S,{variant:"filled",color:"green",size:"xs",type:"button",className:"RootAIChat__approval__button RootAIChat__approval__button--primary",disabled:o.approval.status==="executing",onClick:o.onApprove,children:"Approve draft edit"})]})]})}function Wt(o){let e=o.output.receipt;return t("div",{className:"RootAIChat__receipt",children:[t("div",{className:"RootAIChat__receipt__title",children:[t(q,{size:14}),t("span",{children:e.title})]}),t("div",{className:"RootAIChat__receipt__summary",children:e.summary}),e.details?.length>0&&t("div",{className:"RootAIChat__receipt__details",children:e.details.map(a=>t("div",{children:[t("span",{children:a.label}),t("strong",{children:a.value})]},`${a.label}:${a.value}`))}),e.adminUrl&&t(S,{component:"a",className:"RootAIChat__receipt__link",variant:"default",size:"xs",compact:!0,href:e.adminUrl,children:"Open document"})]})}function Ht(o){return o==="executing"?"applying\u2026":"waiting for approval"}function Ft(o){switch(o){case"input-streaming":return"preparing\u2026";case"input-available":return"running\u2026";case"output-available":return"done";case"output-error":return"error";default:return o}}function Vt(o){let[e,a]=p(""),[i,m]=p([]),[h,r]=p(!1),l=N(null),g=N(null);k(()=>{window.requestAnimationFrame(()=>{let s=g.current;s&&(s.style.height="auto",s.style.height=`${Math.min(s.scrollHeight,240)}px`)})},[e,i]);let I=()=>{o.disabled||o.isStreaming||!e&&i.length===0||(o.onSend(e,i),a(""),m([]),l.current&&(l.current.value=""))},P=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),I())},y=async s=>{r(!0);try{let f=s.type||Yt(s.name),x=await qt(s,f),v=await pt(s,{disableGci:!0});m(w=>[...w,{url:v.src,filename:v.filename||s.name,mediaType:f,textContent:x?.text,textTruncated:x?.truncated,width:v.width,height:v.height}])}catch(f){console.error("upload failed",f)}finally{r(!1),l.current&&(l.current.value="")}},D=s=>{let f=s.target;Array.from(f.files||[]).forEach(y)};return t("div",{className:"RootAIChat__composer",children:[i.length>0&&t("div",{className:"RootAIChat__composer__attachments",children:i.map((s,f)=>t("div",{className:"RootAIChat__composer__attachment",children:[s.mediaType.startsWith("image/")?t("img",{src:s.url,alt:s.filename}):t("span",{className:"RootAIChat__composer__attachment__name",children:s.filename}),t("button",{type:"button",className:"RootAIChat__composer__attachment__remove",onClick:()=>m(x=>x.filter((v,w)=>w!==f)),children:t(B,{size:12})})]},f))}),t("div",{className:"RootAIChat__composer__row",children:[t(O,{label:o.canAttach?"Attach file":"Model doesn't support attachments",className:"RootAIChat__composer__attachTooltip",children:t(E,{component:"label",radius:"xl",className:M("RootAIChat__composer__attach",!o.canAttach&&"RootAIChat__composer__attach--disabled"),disabled:!o.canAttach,children:[h?t(V,{size:"xs"}):t(Q,{size:18}),t("input",{ref:l,type:"file",style:{display:"none"},onChange:D})]})}),t("textarea",{ref:g,className:"RootAIChat__composer__textarea",placeholder:o.disabled?"Select a model\u2026":"Ask anything\u2026",value:e,rows:1,autofocus:!0,disabled:o.disabled,onKeyDown:P,onChange:s=>a(s.target.value),onPaste:s=>{let f=s.clipboardData?.items||[];for(let x of f)if(x.kind==="file"){let v=x.getAsFile();v&&o.canAttach&&y(v)}}}),o.isStreaming?t(E,{className:"RootAIChat__composer__button RootAIChat__composer__stopButton",radius:"xl",color:"dark",variant:"filled",onClick:o.onStop,title:"Stop",children:t(B,{size:18})}):t(E,{className:"RootAIChat__composer__button RootAIChat__composer__submitButton",radius:"xl",color:"dark",variant:"filled",disabled:o.disabled||h||!e&&i.length===0,onClick:I,title:"Send",children:t(rt,{size:18})})]}),o.controls]})}var xt=1e5;function Jt(o){let e=o.filter(Ct),a=o.filter(i=>!Ct(i)).map(Kt);return{files:e,text:a.length?`Attached files:
6
+
7
+ ${a.join(`
8
+
9
+ `)}`:""}}function Ct(o){return o.mediaType.startsWith("image/")}function Kt(o){let e=`File: ${o.filename} (${o.mediaType})`;if(o.textContent!==void 0){let a=o.textTruncated?`
10
+
11
+ [Content truncated before sending to the model.]`:"";return`${e}
12
+ URL: ${o.url}
13
+
14
+ ~~~
15
+ ${o.textContent}${a}
16
+ ~~~`}return`${e}
17
+ URL: ${o.url}
18
+
19
+ [The file was uploaded, but its binary content was not inlined into this chat message.]`}async function qt(o,e){if(!Xt(o.name,e))return null;let a=await o.text();return a.length<=xt?{text:a,truncated:!1}:{text:a.slice(0,xt),truncated:!0}}function Xt(o,e){return e.startsWith("text/")?!0:[".css",".js",".jsx",".json",".md",".mdx",".mjs",".scss",".ts",".tsx",".txt",".yaml",".yml"].some(a=>o.toLowerCase().endsWith(a))}function Yt(o){let e=o.toLowerCase();return e.endsWith(".png")?"image/png":e.endsWith(".webp")?"image/webp":e.endsWith(".jpg")||e.endsWith(".jpeg")?"image/jpeg":e.endsWith(".gif")?"image/gif":e.endsWith(".svg")?"image/svg+xml":e.endsWith(".pdf")?"application/pdf":e.endsWith(".json")?"application/json":e.endsWith(".csv")?"text/csv":e.endsWith(".md")?"text/markdown":e.endsWith(".txt")?"text/plain":"application/octet-stream"}function Gt(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}export{Ie as a};