@blinkk/root-cms 3.1.5 → 3.1.6

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 (71) hide show
  1. package/dist/app.js +1 -1
  2. package/dist/{chunk-ETHWZSNM.js → chunk-PLSNGCYU.js} +196 -22
  3. package/dist/{chunk-MUXSUGFF.js → chunk-U4TMO2LI.js} +2 -2
  4. package/dist/{chunk-6CTCV2PN.js → chunk-Z2CTQVYR.js} +1 -1
  5. package/dist/cli.js +1 -1
  6. package/dist/client.js +1 -1
  7. package/dist/core/client.d.ts +30 -2
  8. package/dist/core/cron-schedule.d.ts +63 -0
  9. package/dist/core/plugin.d.ts +6 -1
  10. package/dist/core.js +1 -1
  11. package/dist/functions.js +2 -2
  12. package/dist/plugin.js +7 -5
  13. package/dist/richtext.js +1 -1
  14. package/dist/shared/embed-protocol.d.ts +19 -0
  15. package/dist/ui/{AIPage-25WICIOT.js → AIPage-EO5WH25R.js} +1 -1
  16. package/dist/ui/{AssetsPage-WKTM2J2G.js → AssetsPage-ESLB4R3I.js} +1 -1
  17. package/dist/ui/{CollectionPage-5ZOVG7IG.js → CollectionPage-MXN7XKUX.js} +1 -1
  18. package/dist/ui/{ComparePage-DDIFYYTK.js → ComparePage-TY7VJVE3.js} +1 -1
  19. package/dist/ui/{DataPage-RFNGSDDN.js → DataPage-YEIS7HBN.js} +1 -1
  20. package/dist/ui/{DataSourcePage-U46CDIH2.js → DataSourcePage-VD6YBDRW.js} +1 -1
  21. package/dist/ui/{DocTranslationsPage-BFCM2PE3.js → DocTranslationsPage-6XLREBPQ.js} +1 -1
  22. package/dist/ui/DocumentPage-2HNNEGRI.js +1 -0
  23. package/dist/ui/{EditDataSourcePage-NKKIF6AD.js → EditDataSourcePage-E4PSKSG3.js} +1 -1
  24. package/dist/ui/{EditReleasePage-TKNOUT7A.js → EditReleasePage-DOMXJXCU.js} +1 -1
  25. package/dist/ui/{EmbeddedAIPage-4AX7VO3T.js → EmbeddedAIPage-U5LONYH2.js} +1 -1
  26. package/dist/ui/EmbeddedDocumentPage-HYV5GPK6.js +1 -0
  27. package/dist/ui/{LogsPage-SCECIAZH.js → LogsPage-6KV3CQLH.js} +1 -1
  28. package/dist/ui/{NewDataSourcePage-FAOPK2RZ.js → NewDataSourcePage-NJJDHGPX.js} +1 -1
  29. package/dist/ui/{NewReleasePage-HD6T6UV2.js → NewReleasePage-FXHPFUVG.js} +1 -1
  30. package/dist/ui/{NotFoundPage-JRYFUENW.js → NotFoundPage-CA7XVXUO.js} +1 -1
  31. package/dist/ui/{ProjectPage-2WIMWCSX.js → ProjectPage-XUBJSCWB.js} +1 -1
  32. package/dist/ui/{ReleasePage-GUMEMLF6.js → ReleasePage-NLGRYJX7.js} +1 -1
  33. package/dist/ui/{ReleasesPage-AW6PICTQ.js → ReleasesPage-OY7OKC3C.js} +1 -1
  34. package/dist/ui/{SettingsPage-KFLNZ356.js → SettingsPage-5EQUY52A.js} +1 -1
  35. package/dist/ui/SidebarToolsPage-FWG6TIDI.js +1 -0
  36. package/dist/ui/TaskPage-APNRUOYG.js +1 -0
  37. package/dist/ui/{TasksPage-G3GBTV3L.js → TasksPage-FTEELXVZ.js} +1 -1
  38. package/dist/ui/{TranslationsArbPage-K272JEAA.js → TranslationsArbPage-PG5USRYB.js} +1 -1
  39. package/dist/ui/{TranslationsEditPage-XWXPNKRQ.js → TranslationsEditPage-GV3ZJXTY.js} +1 -1
  40. package/dist/ui/{TranslationsPage-7KUHVTLK.js → TranslationsPage-3AKSMCNF.js} +1 -1
  41. package/dist/ui/{chunk-VPZHG7JL.js → chunk-235TRWJF.js} +1 -1
  42. package/dist/ui/{chunk-IGZDFHVM.js → chunk-3LEYSXZP.js} +1 -1
  43. package/dist/ui/chunk-56NMZYX6.js +19 -0
  44. package/dist/ui/{chunk-T5BJNOWE.js → chunk-6WJQBFN5.js} +1 -1
  45. package/dist/ui/{chunk-OWBT6YUM.js → chunk-A7IZAHBZ.js} +1 -1
  46. package/dist/ui/{chunk-WC7KMPEQ.js → chunk-C5FRMXDS.js} +1 -1
  47. package/dist/ui/{chunk-UPN3EMUS.js → chunk-EYJ6GKZR.js} +1 -1
  48. package/dist/ui/{chunk-TNW2GNUR.js → chunk-G5647K25.js} +1 -1
  49. package/dist/ui/chunk-LAXQZPE3.js +31 -0
  50. package/dist/ui/chunk-MYPLMHFW.js +1 -0
  51. package/dist/ui/{chunk-XUBZH4ON.js → chunk-O7ESOZQO.js} +1 -1
  52. package/dist/ui/{chunk-5KSGCGYY.js → chunk-QGAPMQEJ.js} +1 -1
  53. package/dist/ui/{chunk-7UHZS56B.js → chunk-ST6QNIWT.js} +53 -53
  54. package/dist/ui/{chunk-DWV5J2W7.js → chunk-U7LSFUHT.js} +1 -1
  55. package/dist/ui/chunk-UOKVF54Y.js +3 -0
  56. package/dist/ui/{chunk-FVWSVOOY.js → chunk-VJRMR2JM.js} +1 -1
  57. package/dist/ui/chunk-Z2CRNO3I.js +1 -0
  58. package/dist/ui/{chunk-N5RJIILP.js → chunk-ZAJPNVYS.js} +1 -1
  59. package/dist/ui/ui.css +1 -1
  60. package/dist/ui/ui.js +1 -1
  61. package/package.json +3 -3
  62. package/dist/ui/DocumentPage-OTBXM55S.js +0 -1
  63. package/dist/ui/EmbeddedDocumentPage-2CNQJTW5.js +0 -1
  64. package/dist/ui/SidebarToolsPage-3R7BQ2F7.js +0 -1
  65. package/dist/ui/TaskPage-GZGPKIL5.js +0 -1
  66. package/dist/ui/chunk-2FQMT5AB.js +0 -3
  67. package/dist/ui/chunk-GCSN3YEC.js +0 -31
  68. package/dist/ui/chunk-NXWYS4HG.js +0 -19
  69. package/dist/ui/chunk-RN4XVVWD.js +0 -1
  70. /package/dist/ui/{chunk-VPZHG7JL.js.LEGAL.txt → chunk-235TRWJF.js.LEGAL.txt} +0 -0
  71. /package/dist/ui/{chunk-7UHZS56B.js.LEGAL.txt → chunk-ST6QNIWT.js.LEGAL.txt} +0 -0
@@ -1,19 +0,0 @@
1
- import{a as Nt,b as Pt,c as Et,d as St,e as zt,f as jt,g as Dt,h as Lt,i as $t,j as Bt,k as Ut,l as Ot,m as Wt,n as Ht,o as nt}from"./chunk-GCSN3YEC.js";import{a as wt}from"./chunk-QWB6MAPJ.js";import{a as Tt,c as at}from"./chunk-VPZHG7JL.js";import{P as kt,T as Mt}from"./chunk-AAR7DBEN.js";import{f as Y}from"./chunk-5MV6XVGA.js";import{b as _t,c as mt,g as ut,h as ht,j as ft,n as q,o as gt,p as xt,r as Ct,v as G}from"./chunk-XOWWPE7X.js";import{d as At,e as N}from"./chunk-WASID5UU.js";import{$a as Q,Bc as j,Fa as H,Ga as o,Hc as yt,V as J,Vc as Rt,W as P,a as h,ab as Z,ad as U,ba as X,bb as tt,c as k,da as z,e as v,g as pt,h as M,j as oe,kc as et,pb as vt,pc as ot,qa as B,qc as bt}from"./chunk-WRA24P66.js";import{d as ct}from"./chunk-KUCVLANF.js";import{h as It}from"./chunk-7SK47HHZ.js";oe();var ae=500;function Ft(){return window.firebase.db}function Vt(){return window.__ROOT_CTX.rootConfig.projectId}function it(){return window.firebase.user?.email||""}function ne(){return _t(Ft(),"Projects",Vt(),"AiChats")}function rt(t){return mt(Ft(),"Projects",Vt(),"AiChats",t)}function D(t){return t&&typeof t.toMillis=="function"?t.toMillis():typeof t=="number"?t:0}async function Kt(t){let e=it();if(!e)return[];let a=t?.limit,n=typeof a=="number"&&Number.isFinite(a)&&a>0?Math.min(Math.floor(a),100):50,p=ut(ne(),ht("createdBy","==",e),ft(ae)),s=(await gt(p)).docs.map(l=>l.data());return s.sort((l,g)=>D(g.modifiedAt)-D(l.modifiedAt)),s.slice(0,n).map(l=>({id:l.id,title:l.title,modelId:l.modelId,createdAt:D(l.createdAt),modifiedAt:D(l.modifiedAt)}))}async function st(t){let e=await q(rt(t));if(!e.exists())return null;let a=e.data();return a.createdBy!==it()?null:{id:a.id||t,title:a.title,modelId:a.modelId,createdAt:D(a.createdAt),modifiedAt:D(a.modifiedAt),messages:a.messages||[]}}async function Jt(t,e){let a=it(),n=rt(t),p=await q(n);if(p.exists()&&p.data().createdBy!==a)throw new Error("chat is owned by another user");let _={id:t,createdBy:a,modifiedAt:G(),messages:$t(e.messages)};p.exists()||(_.createdAt=G()),e.modelId&&(_.modelId=e.modelId),e.title&&(_.title=e.title),await xt(n,_,{merge:!0})}async function Xt(t){await st(t)&&await Ct(rt(t))}async function qt(t,e){let a=St(e);if(a==="New chat")return a;let n=zt(e);if(!n)return a;try{let p=Et(Pt(t)),_=await kt({model:p,system:Dt,prompt:Lt(n),maxOutputTokens:64,temperature:.3}),s=jt(_.text);if(s)return s}catch(p){console.error("failed to generate chat title:",p)}return a}function Gt(t){let{size:e=14}=t,a=e*3.57,n=e*2;return o("div",{className:"BouncingLoader",style:{"--dot-size":`${e}px`,width:`${a}px`,height:`${n}px`}})}var lt=[{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."}],te="root-cms.ai.executionMode",ee="root-cms.ai.selectedModel";function ie(t){return lt.some(e=>e.id===t)}function re(){if(typeof window>"u")return"approve";try{let t=window.localStorage.getItem(te);if(ie(t))return t}catch(t){console.error("failed to read AI execution mode preference",t)}return"approve"}function se(t){if(typeof window>"u")return null;try{let e=window.localStorage.getItem(ee);if(e&&t.some(a=>a.id===e))return e}catch(e){console.error("failed to read AI model preference",e)}return null}function le(t){if(!(typeof window>"u"))try{window.localStorage.setItem(ee,t)}catch(e){console.error("failed to save AI model preference",e)}}function de(t){if(!(typeof window>"u"))try{window.localStorage.setItem(te,t)}catch(e){console.error("failed to save AI execution mode preference",e)}}var F="";function mo(t){let[e,a]=h(null),[n,p]=h("");k(()=>{let s=!0;return fetch("/cms/api/ai.config",{credentials:"include"}).then(async l=>{let g=await l.json();s&&a(g)}).catch(l=>{s&&p(String(l))}),()=>{s=!1}},[]);let _=!!e?.enabled&&(e.models?.length||0)>0;return o("div",{className:N("RootAIChat",`RootAIChat--${t.variant}`),children:!e&&!n?o("div",{className:"RootAIChat__loading",children:o(J,{size:"md",color:"gray"})}):_?o(pe,{variant:t.variant,config:e,initialChatId:t.variant==="panel"?void 0:t.initialChatId,docContext:t.docContext,onClose:t.onClose}):o(ce,{error:n,onClose:t.onClose})})}function ce(t){return o("div",{className:"RootAIChat__notEnabled",children:[t.onClose&&o(P,{className:"RootAIChat__notEnabled__close",onClick:t.onClose,title:"Close",children:o(U,{size:16})}),o("div",{className:"RootAIChat__notEnabled__icon",children:o(j,{size:36})}),o("div",{className:"RootAIChat__notEnabled__title",children:"Root AI is not configured for this project."}),o("div",{className:"RootAIChat__notEnabled__body",children:["Add an ",o("code",{children:"ai.models"})," entry to ",o("code",{children:"cmsPlugin()"})," in"," ",o("code",{children:"root.config.ts"}),"."]}),t.error&&o("pre",{className:"RootAIChat__notEnabled__error",children:t.error})]})}function pe(t){let e=t.variant==="panel",{route:a}=At(),n=t.config.models||[],p=()=>se(n)||t.config.defaultModel||n[0]?.id||"",[_,s]=h(p),[l,g]=h(re),[f,b]=h(t.initialChatId||F),[y,C]=h(t.initialChatId||F),[E,d]=h([]),[x,A]=h(""),[I,T]=h([]),[V,O]=h(0),S=async()=>{if(!e)try{let i=await Kt();T(i)}catch(i){console.error("failed to load chat list",i)}};k(()=>{S(),!e&&t.initialChatId&&K(t.initialChatId)},[]),k(()=>{de(l)},[l]);let L=async i=>{try{let u=await st(i);return u?(b(i),C(i),d(u.messages||[]),A(u.title||""),u.modelId&&n.find(R=>R.id===u.modelId)&&s(u.modelId),O(w=>w+1),!0):!1}catch(u){return console.error("failed to load chat",u),!1}},K=i=>L(i),$=()=>{s(p()),b(F),C(F),d([]),A(""),O(i=>i+1),e||a("/cms/ai")},W=async i=>{if(i===y)return;await L(i)&&!e&&a(`/cms/ai/chat/${i}`)},r=async i=>{try{await Xt(i),y===i&&$(),S()}catch(u){console.error("failed to delete chat",u)}},m=n.find(i=>i.id===_)||n[0],c=i=>{s(i),le(i)};return o("div",{className:"RootAIChat__layout",children:[!e&&o(me,{chats:I,activeChatId:y,onSelect:W,onNew:$,onDelete:r}),o("div",{className:"RootAIChat__main",children:[e&&o(_e,{onNewChat:$,onClose:t.onClose}),o(he,{initialChatId:f,initialTitle:x,model:m,initialMessages:E,executionMode:l,canAutoApply:t.config.canAutoApply??!1,models:n,selectedModel:m,docContext:t.docContext,onSelectModel:c,onSelectExecutionMode:g,onChatPersisted:i=>{C(i),S(),e||window.history.replaceState(null,"",`/cms/ai/chat/${i}`)}},V)]})]})}function _e(t){return o("div",{className:"RootAIChat__panelHeader",children:[o("div",{className:"RootAIChat__panelHeader__title",children:[o(j,{size:14}),o("span",{children:"Root AI"})]}),o("div",{className:"RootAIChat__panelHeader__actions",children:[o(H,{label:"New chat",children:o(P,{size:"xs",onClick:t.onNewChat,children:o(et,{size:14})})}),t.onClose&&o(H,{label:"Close (\u2318 + i)",children:o(P,{size:"xs",onClick:t.onClose,children:o(U,{size:14})})})]})]})}function me(t){return o("aside",{className:"RootAIChat__sidebar",children:[o("button",{type:"button",className:"RootAIChat__sidebar__newButton",onClick:t.onNew,children:[o(et,{size:18}),o("span",{children:"New chat"})]}),o("div",{className:"RootAIChat__sidebar__list",children:[t.chats.length===0&&o("div",{className:"RootAIChat__sidebar__empty",children:"No chats yet."}),t.chats.map(e=>o("div",{className:N("RootAIChat__sidebar__item",e.id===t.activeChatId&&"RootAIChat__sidebar__item--active"),onClick:()=>t.onSelect(e.id),children:[o("div",{className:"RootAIChat__sidebar__item__title",title:e.title||"Untitled chat",children:e.title||"Untitled chat"}),o("button",{type:"button",className:"RootAIChat__sidebar__item__delete",title:"Delete chat",onClick:a=>{a.stopPropagation(),window.confirm("Delete this chat?")&&t.onDelete(e.id)},children:o(Rt,{size:14})})]},e.id))]})]})}function ue(t){let e=t.canAutoApply?lt:lt.filter(n=>n.id!=="auto"),a=e.find(n=>n.id===t.executionMode)||e[0];return o("div",{className:"RootAIChat__options",children:[o(B,{control:o(z,{type:"button",className:"RootAIChat__modePicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:o(bt,{size:16}),children:a.label}),children:e.map(n=>o(B.Item,{onClick:()=>t.onSelectExecutionMode(n.id),children:o("div",{className:"RootAIChat__modePicker__option",children:[o("div",{className:"RootAIChat__modePicker__option__label",children:n.label}),o("div",{className:"RootAIChat__modePicker__option__description",children:n.description})]})},n.id))}),o(B,{control:o(z,{type:"button",className:"RootAIChat__modelPicker",variant:"subtle",color:"dark",size:"xs",compact:!0,leftIcon:o(j,{size:16}),children:t.selectedModel?.label||"Select model"}),children:t.models.map(n=>o(B.Item,{onClick:()=>t.onSelectModel(n.id),children:o("div",{className:"RootAIChat__modelPicker__option",children:[o("div",{className:"RootAIChat__modelPicker__option__label",children:n.label}),n.description&&o("div",{className:"RootAIChat__modelPicker__option__description",children:n.description})]})},n.id))})]})}function he(t){let[e]=h(()=>t.initialChatId||Se()),a=v(t.model?.id);a.current=t.model?.id;let n=v(t.executionMode);n.current=t.executionMode;let p=v(t.docContext);p.current=t.docContext;let _=v(t.onChatPersisted);_.current=t.onChatPersisted;let s=v(null),l=v(t.executionMode),g=v(t.initialTitle),f=v(null),[b,y]=h({}),C=v({});k(()=>()=>{for(let r of Object.values(C.current))r("reject");C.current={}},[]);let E=M((r,m,c,i)=>new Promise(u=>{C.current[r]=u,y(w=>({...w,[r]:{toolCallId:r,toolName:m,input:c,preview:i,status:"pending"}}))}),[]),d=M(r=>{y(m=>{let c=m[r];return c?{...m,[r]:{...c,status:"executing"}}:m}),C.current[r]?.("approve"),delete C.current[r]},[]),x=M(r=>{y(m=>{let c={...m};return delete c[r],c}),C.current[r]?.("reject"),delete C.current[r]},[]),A=M(async r=>{if(!Wt(r.toolName))return await nt(r.toolName,r.input);let m=l.current;if(m==="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 Ht(r.toolName,r.input)}catch(i){return{success:!1,error:"PREVIEW_FAILED",message:i?.message||String(i)}}if(c.error)return{success:!1,error:c.error,message:c.summary,errors:c.errors,hint:c.hint};if(m==="approve"&&await E(r.toolCallId,r.toolName,r.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 nt(r.toolName,r.input)}finally{y(i=>{if(!i[r.toolCallId])return i;let u={...i};return delete u[r.toolCallId],u})}},[E]),I=M(async r=>{let m=s.current;try{let c=g.current;if(!c&&m){let i=await qt(m,r);i&&i!=="New chat"&&(c=i,g.current=i)}await Jt(e,{messages:r,modelId:m?.id||a.current,title:c||void 0})}catch(c){console.error("failed to persist chat history",c)}_.current(e)},[e]),T=pt(()=>Bt({loadTurnConfig:async()=>{let r=a.current,m=n.current,c=p.current?.docId,i=`${r}|${m}|${c||""}`,u=f.current;if(u&&u.key===i)return u.config;let w=await fetch("/cms/api/ai.chat.prepare",{method:"POST",credentials:"include",headers:{"content-type":"application/json"},body:JSON.stringify({modelId:r,executionMode:m,docId:c})}),R=await w.json();if(!w.ok||!R.success)throw new Error(R.error||`ai.chat.prepare failed: ${w.status}`);let dt={model:R.model,system:R.system,maxSteps:R.maxSteps};return s.current=R.model,l.current=R.executionMode||m,f.current={key:i,config:dt},dt},buildTools:r=>r.capabilities.tools?l.current==="read"?Ot():Ut():{},onFinish:I}),[I]),{messages:V,sendMessage:O,status:S,error:L,stop:K,addToolOutput:$}=Nt({id:e,messages:t.initialMessages,transport:T,sendAutomaticallyWhen:Mt,onToolCall:async({toolCall:r})=>{let m=await A(r);$({tool:r.toolName,toolCallId:r.toolCallId,output:m})}}),W=S==="streaming"||S==="submitted";return o(ct,{children:[o(fe,{messages:V,isStreaming:W,emptyMessage:t.model?void 0:"Select a model to start.",toolApprovals:{approvals:b,onApprove:d,onReject:x}}),L&&o("div",{className:"RootAIChat__error",children:[o("strong",{children:"Error:"})," ",L.message]}),o(ke,{disabled:!t.model,canAttach:t.model?.capabilities.attachments??!1,isStreaming:W,onStop:K,controls:o(ue,{models:t.models,selectedModel:t.selectedModel,onSelectModel:t.onSelectModel,executionMode:t.executionMode,canAutoApply:t.canAutoApply,onSelectExecutionMode:t.onSelectExecutionMode}),onSend:(r,m)=>{if(!r&&m.length===0)return;let c=Me(m),i=[r,c.text].filter(Boolean).join(`
2
-
3
- `);O({text:i,files:c.files.map(u=>({type:"file",mediaType:u.mediaType,url:u.url,filename:u.filename}))})}})]})}function fe(t){let e=v(null);return k(()=>{let a=e.current;a&&(a.scrollTop=a.scrollHeight)},[t.messages]),t.messages.length===0?o("div",{className:"RootAIChat__transcript RootAIChat__transcript--empty",ref:e,children:o("div",{className:"RootAIChat__welcome",children:[o("div",{className:"RootAIChat__welcome__icon",children:o(j,{size:36})}),o("div",{className:"RootAIChat__welcome__title",children:"Root AI"}),o("div",{className:"RootAIChat__welcome__body",children:t.emptyMessage||"What are we going to get done today?"})]})}):o("div",{className:"RootAIChat__transcript",ref:e,children:o("div",{className:"RootAIChat__transcript__inner",children:[t.messages.map(a=>o(ge,{message:a,toolApprovals:t.toolApprovals},a.id)),t.isStreaming&&o("div",{className:"RootAIChat__streamingIndicator",children:o(Gt,{size:6})})]})})}function ge(t){let e=t.message,a=e.role==="user",n=a?"You":"Root AI",p=a?window.firebase.user?.photoURL:null,[_,s]=h(!1),l=M(()=>(e.parts||[]).filter(f=>f.type==="text"&&f.text).map(f=>f.text).join(`
4
-
5
- `),[e.parts]),g=M(async()=>{let f=l();if(!f)return;let b=Tt.parse(f);try{await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([b],{type:"text/html"}),"text/plain":new Blob([f],{type:"text/plain"})})]),s(!0),setTimeout(()=>s(!1),2e3)}catch{await navigator.clipboard.writeText(f),s(!0),setTimeout(()=>s(!1),2e3)}},[l]);return o("div",{className:N("RootAIChat__message",`RootAIChat__message--${e.role}`),children:[o("div",{className:"RootAIChat__message__avatar",children:p?o("img",{src:p,alt:n}):o(j,{size:20})}),o("div",{className:"RootAIChat__message__body",children:[o("div",{className:"RootAIChat__message__username",children:n}),o("div",{className:"RootAIChat__message__parts",children:(e.parts||[]).map((f,b)=>o(xe,{part:f,toolApprovals:t.toolApprovals},b))}),o("button",{type:"button",className:N("RootAIChat__message__copy",_&&"RootAIChat__message__copy--copied"),title:_?"Copied!":"Copy message",onClick:g,children:_?o(Q,{size:14}):o(vt,{size:14})})]})]})}function xe(t){let e=t.part;return e.type==="text"?e.text?o("div",{className:"RootAIChat__textPart",children:o(at,{code:e.text})}):null:e.type==="reasoning"?o(Ce,{text:e.text}):e.type==="file"?o(Ae,{part:e}):e.type==="source-url"?o("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-")?o(Yt,{part:e,toolApprovals:t.toolApprovals}):e.type==="dynamic-tool"?o(Yt,{part:e,toolApprovals:t.toolApprovals}):e.type==="step-start"?null:o("div",{className:"RootAIChat__unknownPart",children:o("pre",{children:JSON.stringify(e,null,2)})})}function Ce(t){let[e,a]=h(!1);return t.text?o("div",{className:N("RootAIChat__reasoning",e&&"RootAIChat__reasoning--open"),children:[o("button",{type:"button",className:"RootAIChat__reasoning__toggle",onClick:()=>a(!e),children:[o(Z,{size:14,style:{transform:e?"rotate(0deg)":"rotate(-90deg)"}}),o("span",{children:"Thinking"})]}),e&&o("div",{className:"RootAIChat__reasoning__body",children:o(at,{code:t.text})})]}):null}function Ae(t){let e=t.part;return e.mediaType?.startsWith("image/")?o("div",{className:"RootAIChat__filePart",children:o("img",{src:e.url,alt:e.filename||"attachment"})}):o("a",{className:"RootAIChat__filePart RootAIChat__filePart--link",href:e.url,target:"_blank",rel:"noopener noreferrer",children:[o(ot,{size:14}),o("span",{children:e.filename||e.url})]})}function Yt(t){let e=t.part,a=typeof e.type=="string"&&e.type.startsWith("tool-")?e.type.slice(5):e.toolName||"tool",n=e.state||"",p=Ie(e),_=t.toolApprovals,s=p?_?.approvals[p]:void 0,[l,g]=h(!!s);return k(()=>{s&&g(!0)},[s]),o("div",{className:"RootAIChat__tool",children:[o("button",{type:"button",className:"RootAIChat__tool__header",onClick:()=>g(!l),children:[o(Z,{className:N("RootAIChat__tool__header__icon",l&&"RootAIChat__tool__header__icon--open"),size:14}),o(X,{color:"dark",variant:"filled",size:"xs",children:a}),o("span",{className:"RootAIChat__tool__title",children:ve(a,e.input)}),o("span",{className:"RootAIChat__tool__state",children:s?Re(s.status):we(n)})]}),l&&o("div",{className:"RootAIChat__tool__body",children:[s&&_&&o(be,{approval:s,onApprove:()=>_.onApprove(s.toolCallId),onReject:()=>_.onReject(s.toolCallId)}),e.output?.receipt&&o(ye,{output:e.output}),e.input&&o("details",{children:[o("summary",{children:[o(tt,{size:14,className:"RootAIChat__tool__json__icon"}),o("span",{children:"Input"})]}),o("pre",{children:JSON.stringify(e.input,null,2)})]}),e.output&&o("details",{children:[o("summary",{children:[o(tt,{size:14,className:"RootAIChat__tool__json__icon"}),o("span",{children:"Output"})]}),o("pre",{children:JSON.stringify(e.output,null,2)})]}),e.errorText&&o("div",{className:"RootAIChat__tool__error",children:e.errorText})]})]})}function Ie(t){return t.toolCallId||t.id||""}function ve(t,e){switch(t){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 t}}function be(t){let e=t.approval.preview,a=e.before!==void 0&&e.after!==void 0;return o("div",{className:"RootAIChat__approval",children:[o("div",{className:"RootAIChat__approval__header",children:[o("div",{children:[o("div",{className:"RootAIChat__approval__title",children:e.title}),o("div",{className:"RootAIChat__approval__summary",children:e.summary})]}),o(X,{className:"RootAIChat__approval__status",variant:"light",color:"gray",children:t.approval.status==="executing"?"Applying":"Review"})]}),e.details.length>0&&o("div",{className:"RootAIChat__approval__details",children:e.details.map(n=>o("div",{children:[o("span",{children:n.label}),o("strong",{children:n.value})]},`${n.label}:${n.value}`))}),a&&o(wt,{className:"RootAIChat__approval__diff",oldCode:Y(e.before),newCode:Y(e.after)}),o("div",{className:"RootAIChat__approval__actions",children:[o(z,{variant:"default",color:"dark",size:"xs",type:"button",className:"RootAIChat__approval__button",disabled:t.approval.status==="executing",onClick:t.onReject,children:"Reject"}),o(z,{variant:"filled",color:"green",size:"xs",type:"button",className:"RootAIChat__approval__button RootAIChat__approval__button--primary",disabled:t.approval.status==="executing",onClick:t.onApprove,children:"Approve draft edit"})]})]})}function ye(t){let e=t.output.receipt;return o("div",{className:"RootAIChat__receipt",children:[o("div",{className:"RootAIChat__receipt__title",children:[o(Q,{size:14}),o("span",{children:e.title})]}),o("div",{className:"RootAIChat__receipt__summary",children:e.summary}),e.details?.length>0&&o("div",{className:"RootAIChat__receipt__details",children:e.details.map(a=>o("div",{children:[o("span",{children:a.label}),o("strong",{children:a.value})]},`${a.label}:${a.value}`))}),e.adminUrl&&o(z,{component:"a",className:"RootAIChat__receipt__link",variant:"default",size:"xs",compact:!0,href:e.adminUrl,children:"Open document"})]})}function Re(t){return t==="executing"?"applying\u2026":"waiting for approval"}function we(t){switch(t){case"input-streaming":return"preparing\u2026";case"input-available":return"running\u2026";case"output-available":return"done";case"output-error":return"error";default:return t}}function ke(t){let[e,a]=h(""),[n,p]=h([]),[_,s]=h(!1),l=v(null),g=v(null);k(()=>{window.requestAnimationFrame(()=>{let d=g.current;d&&(d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight,240)}px`)})},[e,n]);let b=()=>{t.disabled||t.isStreaming||!e&&n.length===0||(t.onSend(e,n),a(""),p([]),l.current&&(l.current.value=""))},y=d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),b())},C=async d=>{s(!0);try{let x=d.type||Ee(d.name),A=await Te(d,x),I=await It(d,{disableGci:!0});p(T=>[...T,{url:I.src,filename:I.filename||d.name,mediaType:x,textContent:A?.text,textTruncated:A?.truncated,width:I.width,height:I.height}])}catch(x){console.error("upload failed",x)}finally{s(!1),l.current&&(l.current.value="")}},E=d=>{let x=d.target;Array.from(x.files||[]).forEach(C)};return o("div",{className:"RootAIChat__composer",children:[n.length>0&&o("div",{className:"RootAIChat__composer__attachments",children:n.map((d,x)=>o("div",{className:"RootAIChat__composer__attachment",children:[d.mediaType.startsWith("image/")?o("img",{src:d.url,alt:d.filename}):o("span",{className:"RootAIChat__composer__attachment__name",children:d.filename}),o("button",{type:"button",className:"RootAIChat__composer__attachment__remove",onClick:()=>p(A=>A.filter((I,T)=>T!==x)),children:o(U,{size:12})})]},x))}),o("div",{className:"RootAIChat__composer__row",children:[o(H,{label:t.canAttach?"Attach file":"Model doesn't support attachments",className:"RootAIChat__composer__attachTooltip",children:o(P,{component:"label",radius:"xl",className:N("RootAIChat__composer__attach",!t.canAttach&&"RootAIChat__composer__attach--disabled"),disabled:!t.canAttach,children:[_?o(J,{size:"xs"}):o(ot,{size:18}),o("input",{ref:l,type:"file",style:{display:"none"},onChange:E})]})}),o("textarea",{ref:g,className:"RootAIChat__composer__textarea",placeholder:t.disabled?"Select a model\u2026":"Ask anything\u2026",value:e,rows:1,autofocus:!0,disabled:t.disabled,onKeyDown:y,onChange:d=>a(d.target.value),onPaste:d=>{let x=d.clipboardData?.items||[];for(let A of x)if(A.kind==="file"){let I=A.getAsFile();I&&t.canAttach&&C(I)}}}),t.isStreaming?o(P,{className:"RootAIChat__composer__button RootAIChat__composer__stopButton",radius:"xl",color:"dark",variant:"filled",onClick:t.onStop,title:"Stop",children:o(U,{size:18})}):o(P,{className:"RootAIChat__composer__button RootAIChat__composer__submitButton",radius:"xl",color:"dark",variant:"filled",disabled:t.disabled||_||!e&&n.length===0,onClick:b,title:"Send",children:o(yt,{size:18})})]}),t.controls]})}var Qt=1e5;function Me(t){let e=t.filter(Zt),a=t.filter(n=>!Zt(n)).map(Ne);return{files:e,text:a.length?`Attached files:
6
-
7
- ${a.join(`
8
-
9
- `)}`:""}}function Zt(t){return t.mediaType.startsWith("image/")}function Ne(t){let e=`File: ${t.filename} (${t.mediaType})`;if(t.textContent!==void 0){let a=t.textTruncated?`
10
-
11
- [Content truncated before sending to the model.]`:"";return`${e}
12
- URL: ${t.url}
13
-
14
- ~~~
15
- ${t.textContent}${a}
16
- ~~~`}return`${e}
17
- URL: ${t.url}
18
-
19
- [The file was uploaded, but its binary content was not inlined into this chat message.]`}async function Te(t,e){if(!Pe(t.name,e))return null;let a=await t.text();return a.length<=Qt?{text:a,truncated:!1}:{text:a.slice(0,Qt),truncated:!0}}function Pe(t,e){return e.startsWith("text/")?!0:[".css",".js",".jsx",".json",".md",".mdx",".mjs",".scss",".ts",".tsx",".txt",".yaml",".yml"].some(a=>t.toLowerCase().endsWith(a))}function Ee(t){let e=t.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 Se(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`chat-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}export{mo as a};
@@ -1 +0,0 @@
1
- import{a as _,c as P}from"./chunk-ATTW36EM.js";import{D as u,a as w,b as j,c as n,g as T,n as b,o as R,p as I,q as m,u as h,v as l,x as f}from"./chunk-XOWWPE7X.js";async function F(t,a){if(!t)throw new Error("missing data source id");let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t);await I(s,{...a,id:t,createdAt:l(),createdBy:window.firebase.user.email}),u("datasource.create",{metadata:{datasourceId:t}})}async function G(){let t=window.__ROOT_CTX.rootConfig.projectId,a=window.firebase.db,o=j(a,"Projects",t,"DataSources"),e=T(o),s=await R(e),r=[];return s.forEach(c=>{r.push(c.data())}),r}async function S(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t),s=await b(e);return s.exists()?s.data():null}async function O(t,a){let o=a?.mode||"draft",e=window.__ROOT_CTX.rootConfig.projectId,s=window.firebase.db,r=n(s,"Projects",e,"DataSources",t,"Data",o),c=await b(r);return c.exists()?c.data():null}async function U(t,a){let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t);await m(s,a),u("datasource.save",{metadata:{datasourceId:t}})}async function q(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t);await m(e,{archivedAt:l(),archivedBy:window.firebase.user.email}),u("datasource.archive",{metadata:{datasourceId:t}})}async function H(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t);await m(e,{archivedAt:h(),archivedBy:h()}),u("datasource.unarchive",{metadata:{datasourceId:t}})}async function W(t){let a=await S(t);if(!a)throw new Error(`data source not found: ${t}`);if(a.archivedAt)throw new Error(`data source is archived: ${t}`);if(a.type==="http"&&a.url&&!C(a.url)){let o=await fetch("/cms/api/data.sync",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({id:a.id})});if(o.status!==200){let e=await o.text();throw new Error(`sync failed: ${e}`)}}else{let{data:o,headers:e}=await x(a),s=window.__ROOT_CTX.rootConfig.projectId,r=window.firebase.db,c=n(r,"Projects",s,"DataSources",t),d=n(r,"Projects",s,"DataSources",t,"Data","draft"),p={...a,syncedAt:w.now(),syncedBy:window.firebase.user.email},i=f(r);i.set(d,{dataSource:p,data:o,...e?{headers:e}:{}}),i.update(c,{syncedAt:w.now(),syncedBy:window.firebase.user.email}),await i.commit()}console.log(`synced data source: ${t}`),u("datasource.sync",{metadata:{datasourceId:t}})}async function M(t){let a=await S(t);if(!a)throw new Error(`data source not found: ${t}`);if(a.archivedAt)throw new Error(`data source is archived: ${t}`);let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t),r=n(e,"Projects",o,"DataSources",t,"Data","draft"),c=n(e,"Projects",o,"DataSources",t,"Data","published"),d=await O(t,{mode:"draft"}),p={...a,publishedAt:w.now(),publishedBy:window.firebase.user.email},i=f(e);i.set(c,{dataSource:p,data:d?.data||null,...d?.headers?{headers:d.headers}:{}}),i.update(r,{dataSource:p}),i.update(s,{publishedAt:w.now(),publishedBy:window.firebase.user.email}),await i.commit(),console.log(`published data ${t}`),u("datasource.publish",{metadata:{datasourceId:t}})}async function k(t){if(!await S(t))throw new Error(`data source not found: ${t}`);let o=window.__ROOT_CTX.rootConfig.projectId,e=window.firebase.db,s=n(e,"Projects",o,"DataSources",t),r=n(e,"Projects",o,"DataSources",t,"Data","draft"),c=n(e,"Projects",o,"DataSources",t,"Data","published"),d=f(e);d.update(s,{publishedAt:h(),publishedBy:h()}),(await b(r)).exists()&&d.update(r,{"dataSource.publishedAt":h(),"dataSource.publishedBy":h()}),d.delete(c),await d.commit(),console.log(`unpublished data source: ${t}`),u("datasource.unpublish",{metadata:{datasourceId:t}})}async function J(t,a){if(t.length===0)return;let o=window.firebase.db,e=window.__ROOT_CTX.rootConfig.projectId,s=a?.batch||f(o);for(let r of t){let c=await S(r);if(!c)throw new Error(`data source not found: ${r}`);if(c.archivedAt)throw new Error(`data source is archived: ${r}`);let d=await O(r,{mode:"draft"}),p=n(o,"Projects",e,"DataSources",r),i=n(o,"Projects",e,"DataSources",r,"Data","draft"),y=n(o,"Projects",e,"DataSources",r,"Data","published"),D={...c,publishedAt:l(),publishedBy:window.firebase.user.email};s.set(y,{dataSource:D,data:d?.data||null,...d?.headers?{headers:d.headers}:{}}),s.update(i,{dataSource:D}),s.update(p,{publishedAt:l(),publishedBy:window.firebase.user.email}),u("datasource.publish",{metadata:{datasourceId:r}})}(!a?.batch||a?.commitBatch)&&await s.commit()}async function N(t){let a=window.__ROOT_CTX.rootConfig.projectId,o=window.firebase.db,e=n(o,"Projects",a,"DataSources",t),s=n(o,"Projects",a,"DataSources",t,"Data","draft"),r=n(o,"Projects",a,"DataSources",t,"Data","published"),c=f(o);c.delete(s),c.delete(r),c.delete(e),await c.commit(),console.log(`deleted data source ${t}`),u("datasource.delete",{metadata:{datasourceId:t}})}async function x(t){if(t.type==="http")return{data:await B(t)};if(t.type==="gsheet")return await v(t);throw new Error(`unsupported data source: ${t.type}`)}async function v(t){let a=P(t.url);if(!a?.spreadsheetId)throw new Error(`failed to parse google sheet url: ${t.url}`);let e=await new _(a.spreadsheetId).getSheet(a.gid??0);if(!e)throw new Error(`could not find sheet: ${t.url}`);let s=t.dataFormat||"map",[r,c]=await e.getValues();return s==="array"?{data:[r,c],headers:r}:{data:c.map(p=>{let i={};return p.forEach((y,D)=>{let g=r[D];g&&(i[g]=String(y||""))}),i}),headers:r}}async function B(t){if(!C(t.url))throw new Error(`unsupported url: ${t.url}`);let a=await fetch(t.url,{method:t.httpOptions?.method||"GET",headers:t.httpOptions?.headers||[],body:t.httpOptions?.body||void 0});if(a.status!==200){let e=await a.text();throw new Error(`req failed: ${e}`)}return String(a.headers.get("content-type")).includes("application/json")?await a.json():a.text()}function C(t){return t&&t.startsWith("/")}export{F as a,G as b,S as c,O as d,U as e,q as f,H as g,W as h,M as i,k as j,J as k,N as l};