libre-webui 0.37.0 → 0.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/backend/dist/cordis/dsh/engine-plugin.d.ts.map +1 -1
- package/backend/dist/cordis/dsh/engine-plugin.js +4 -1
- package/backend/dist/cordis/dsh/engine-plugin.js.map +1 -1
- package/backend/dist/cordis/host/config.d.ts.map +1 -1
- package/backend/dist/cordis/host/config.js +14 -4
- package/backend/dist/cordis/host/config.js.map +1 -1
- package/backend/dist/cordis/host/host.d.ts.map +1 -1
- package/backend/dist/cordis/host/host.js +7 -2
- package/backend/dist/cordis/host/host.js.map +1 -1
- package/backend/dist/cordis/host/privacy.d.ts +8 -0
- package/backend/dist/cordis/host/privacy.d.ts.map +1 -0
- package/backend/dist/cordis/host/privacy.js +73 -0
- package/backend/dist/cordis/host/privacy.js.map +1 -0
- package/backend/dist/cordis/runtime.d.ts.map +1 -1
- package/backend/dist/cordis/runtime.js +12 -1
- package/backend/dist/cordis/runtime.js.map +1 -1
- package/backend/dist/services/agentCliService.d.ts.map +1 -1
- package/backend/dist/services/agentCliService.js +3 -0
- package/backend/dist/services/agentCliService.js.map +1 -1
- package/backend/dist/utils/pluginDefinitionTrust.js +1 -1
- package/backend/package.json +2 -2
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/artifact-runtime/framer-motion.js +3 -3
- package/frontend/dist/artifact-runtime/lucide-react.js +1 -1
- package/frontend/dist/artifact-runtime/react.js +5 -5
- package/frontend/dist/artifact-runtime/recharts.js +45 -45
- package/frontend/dist/assets/index-DWLnkKwj.js +16 -0
- package/frontend/dist/index.html +30 -30
- package/frontend/dist/js/{ArtifactContainer-Bd0IrnmH.js → ArtifactContainer-D4v4l15L.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-CL_ROEDy.js → ArtifactDemoPage-B2uaVpsi.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-Dv32Q7Q9.js → ArtifactSandboxFrame-DlWJHI-r.js} +1 -1
- package/frontend/dist/js/{ArtifactSlideOutPanel-BIeQrdzE.js → ArtifactSlideOutPanel-laZ98QKB.js} +1 -1
- package/frontend/dist/js/{AutomationModal-Dy42OlIk.js → AutomationModal-CjjiEZFA.js} +1 -1
- package/frontend/dist/js/{AutomationsPage-DWtmeftv.js → AutomationsPage-jnWmD58y.js} +1 -1
- package/frontend/dist/js/{AvatarUpload-ClO6yGZX.js → AvatarUpload-KaBaTKoG.js} +1 -1
- package/frontend/dist/js/{Button-ZQ6BePid.js → Button-CGMYia4g.js} +1 -1
- package/frontend/dist/js/{CalendarPage-ChZgPFIy.js → CalendarPage-Dc7r-86c.js} +1 -1
- package/frontend/dist/js/ChannelsPage-DHPabX1e.js +1 -0
- package/frontend/dist/js/ChatPage-ZvGp-iqV.js +14 -0
- package/frontend/dist/js/{ConnectModels-S4NOCxtb.js → ConnectModels-aUTD6s9B.js} +1 -1
- package/frontend/dist/js/{CordisPage-BN6AcgVv.js → CordisPage-DZKcpPVj.js} +1 -1
- package/frontend/dist/js/{EvaluationsPage-DsGvkOBY.js → EvaluationsPage-BB7sPhIR.js} +1 -1
- package/frontend/dist/js/{FirstTimeSetup-DOHfNdJo.js → FirstTimeSetup-elqSi9JH.js} +1 -1
- package/frontend/dist/js/{GalleryPage-Fndn6_oZ.js → GalleryPage-CrlNRnkn.js} +1 -1
- package/frontend/dist/js/{HomePage-DPoIA-VC.js → HomePage-lR9h7_a1.js} +1 -1
- package/frontend/dist/js/{LanguageSwitcher-DAkaWEHB.js → LanguageSwitcher-CWkbzpxT.js} +1 -1
- package/frontend/dist/js/{LibreClawPage-CdFXe8Mg.js → LibreClawPage-P19FnNlu.js} +1 -1
- package/frontend/dist/js/{Logo-C9fsEUaY.js → Logo-HZvdAk2c.js} +1 -1
- package/frontend/dist/js/{LogoMark-Cvu5CQOW.js → LogoMark-GJnfMXsk.js} +1 -1
- package/frontend/dist/js/{ModelManagerModals-oO3ygVfy.js → ModelManagerModals-Bk6OQzJI.js} +1 -1
- package/frontend/dist/js/{NotesPage-44VKCZNH.js → NotesPage-DopG0M4B.js} +2 -2
- package/frontend/dist/js/{OptimizedSyntaxHighlighter-aKWyHj_c.js → OptimizedSyntaxHighlighter-CzzV6ONG.js} +1 -1
- package/frontend/dist/js/OptimizedSyntaxHighlighter-ajqwyBQm.js +1 -0
- package/frontend/dist/js/{PasswordStrengthMeter-BZF8U24d.js → PasswordStrengthMeter-DasfJa4P.js} +1 -1
- package/frontend/dist/js/{PersonasPage-DoHAgNb3.js → PersonasPage-CIJINcQK.js} +1 -1
- package/frontend/dist/js/{PluginUsagePage-BfkgiWdb.js → PluginUsagePage-Cj0mUxD8.js} +1 -1
- package/frontend/dist/js/RichMessageContent-BZndQSJU.js +1 -0
- package/frontend/dist/js/{RichMessageContent-B3V8vNPB.js → RichMessageContent-DxCHlUlY.js} +2 -2
- package/frontend/dist/js/SettingsModal-wAuFQOE4.js +19 -0
- package/frontend/dist/js/{SettingsToggle-CKLHOUt-.js → SettingsToggle-oxvw7ulA.js} +1 -1
- package/frontend/dist/js/{ShareDialog-DFCFk_5o.js → ShareDialog-Bhpt_Y1N.js} +1 -1
- package/frontend/dist/js/{SystemPage-CqZLDXog.js → SystemPage-BfhVXqar.js} +1 -1
- package/frontend/dist/js/{TurnstileWidget-BO2ceTt8.js → TurnstileWidget-CVepEMEQ.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-Ch-PvYQ9.js → UserManagementPage-2yHv89ZA.js} +1 -1
- package/frontend/dist/js/{UserManagementPanel-D7TNSA3i.js → UserManagementPanel-BU95ZPOv.js} +1 -1
- package/frontend/dist/js/{WhatsNewModal-5hfNdmEV.js → WhatsNewModal-Dl69bG2T.js} +1 -1
- package/frontend/dist/js/WorkPage-CSderbeT.js +8 -0
- package/frontend/dist/js/api-CU-JXx2u.js +1 -0
- package/frontend/dist/js/{api-jEschMu2.js → api-DPXCtanG.js} +1 -1
- package/frontend/dist/js/{appNavigation-Dr7gFa_n.js → appNavigation-R8iKverf.js} +1 -1
- package/frontend/dist/js/{appStore-DglPGdPW.js → appStore-BD70bvas.js} +2 -2
- package/frontend/dist/js/appVersion-C7sxqgMd.js +1 -0
- package/frontend/dist/js/{authStore-BSn9e-LG.js → authStore-D8fc-Hl0.js} +3 -3
- package/frontend/dist/js/authStore-FNKLFUQp.js +1 -0
- package/frontend/dist/js/{chatStore-BtjmZY_D.js → chatStore-CK5ojwft.js} +3 -3
- package/frontend/dist/js/{client-CUuh7qtw.js → client-BeJbHHWx.js} +2 -2
- package/frontend/dist/js/{config-CBGiqPGG.js → config-D6Kcp5n3.js} +1 -1
- package/frontend/dist/js/{cordisApi-c6Um_474.js → cordisApi-BS8QMSV4.js} +1 -1
- package/frontend/dist/js/{estree-DCT3Jm65.js → estree-DGmLqopC.js} +17 -17
- package/frontend/dist/js/{evaluationsApi-_U24Slqu.js → evaluationsApi-2YwZBPk5.js} +1 -1
- package/frontend/dist/js/{html-CBXMuS97.js → html-BryNQ_yx.js} +6 -6
- package/frontend/dist/js/{markdown-Bo71X2X2.js → markdown-CZ1tYEW8.js} +17 -17
- package/frontend/dist/js/{markdown-core-BFkBYv2v.js → markdown-core-KjS96SYW.js} +1 -1
- package/frontend/dist/js/{markdown-html-CwjnwJbl.js → markdown-html-DQEwrWcf.js} +1 -1
- package/frontend/dist/js/{markdown-math-CJvHdD1l.js → markdown-math-CKi32S5d.js} +1 -1
- package/frontend/dist/js/{markdownHtml-egpK3_YY.js → markdownHtml-lrXhxBhK.js} +1 -1
- package/frontend/dist/js/markdownMath-B0BpyFBS.js +1 -0
- package/frontend/dist/js/{messageCodeStyles-BuSENDg_.js → messageCodeStyles-D4haBw80.js} +1 -1
- package/frontend/dist/js/react-vendor-wiHys0m2.js +9 -0
- package/frontend/dist/js/router-vendor-HZm4FR0A.js +1 -0
- package/frontend/dist/js/{standalone-6z5x8CWe.js → standalone-DbyFjvTU.js} +1 -1
- package/frontend/dist/js/{syntax-highlight-7t8DGG2n.js → syntax-highlight-DNc3FFCa.js} +1 -1
- package/frontend/dist/js/{teamEventStream-B37335ai.js → teamEventStream-omPy51va.js} +1 -1
- package/frontend/dist/js/{typescript-CslHIgIJ.js → typescript-DUM5niRM.js} +1 -1
- package/frontend/dist/js/{ui-CwzgKeUQ.js → ui-D5-4niRk.js} +2 -2
- package/frontend/dist/js/ui-vendor-BhHHyHk3.js +1 -0
- package/frontend/dist/js/{useChat-yWCeS8Rw.js → useChat-DnGClJeX.js} +1 -1
- package/frontend/dist/js/{useDialogFocus-BQLdAGYH.js → useDialogFocus-BPTG_Zmy.js} +1 -1
- package/frontend/dist/js/{useDictation-a98XeJii.js → useDictation-D7zVBjDJ.js} +1 -1
- package/frontend/dist/js/useQuery-hWmQjdLu.js +1 -0
- package/frontend/dist/js/{useTranslation-Kn7_iLGj.js → useTranslation-B9kflK9S.js} +1 -1
- package/frontend/dist/js/{utils-Dq1w7K0c.js → utils-p8Gt72YP.js} +1 -1
- package/frontend/dist/js/{utils-vendor-dx9vGAt3.js → utils-vendor-DISWt2y9.js} +1 -1
- package/frontend/dist/js/{workApi-Xmj4wmPi.js → workApi-C5InfT8x.js} +1 -1
- package/frontend/dist/js/workApi-FV75LKJn.js +1 -0
- package/package.json +5 -5
- package/plugins/codex-oauth.json +2 -0
- package/frontend/dist/assets/index-C1SuPfNL.js +0 -71
- package/frontend/dist/js/ChannelsPage-zN03cSNe.js +0 -1
- package/frontend/dist/js/ChatPage-8miRtYkQ.js +0 -14
- package/frontend/dist/js/OptimizedSyntaxHighlighter-BFjOBavF.js +0 -1
- package/frontend/dist/js/RichMessageContent-Cm-Sw-ux.js +0 -1
- package/frontend/dist/js/SettingsModal-DhBjTuR7.js +0 -19
- package/frontend/dist/js/WorkPage-CTd_UrET.js +0 -8
- package/frontend/dist/js/api-D7VJAMui.js +0 -1
- package/frontend/dist/js/appVersion-BQ7RP6kt.js +0 -1
- package/frontend/dist/js/authStore-DSIpfiYd.js +0 -1
- package/frontend/dist/js/markdownMath-mesq3ZcY.js +0 -1
- package/frontend/dist/js/react-vendor-D0Ec-185.js +0 -9
- package/frontend/dist/js/router-vendor-CM0PhOMl.js +0 -1
- package/frontend/dist/js/ui-vendor-wayYH9Nf.js +0 -177
- package/frontend/dist/js/useQuery-C3O4CZ54.js +0 -1
- package/frontend/dist/js/workApi-DXie0wBj.js +0 -1
package/frontend/dist/js/{ArtifactSandboxFrame-Dv32Q7Q9.js → ArtifactSandboxFrame-DlWJHI-r.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{t as r}from"./logger-BR4forr_.js";import{t as i}from"./config-D6Kcp5n3.js";import{a,l as o,n as s,o as c,r as l,t as u}from"./artifactHtml-DDmfpcB0.js";var d=e(t(),1),f=`${i.replace(/\/+$/,``)}/artifacts/sandbox`,p=window.location.protocol===`file:`?new URL(f).origin:window.location.origin,m=`/artifact-runtime`,h=`runtime`,g=`react`,_=`babel`,v=`tailwind`,y=`fonts`,b={react:g,"react-dom":g,"react-dom/client":g,"react/jsx-runtime":g,"react/jsx-dev-runtime":g,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},x=[h,g,_,v],S=[h,`mermaid`],C=[{pattern:/cdn\.tailwindcss\.com/i,bundle:v},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:v},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:y},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:g},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:g},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:_}],w=`__libreArtifactRuntime`;function T(e){if(b[e])return e;let t=C.find(({pattern:t})=>t.test(e))?.bundle??Object.values(b).find(t=>e.startsWith(`${t}/`));return t?Object.entries(b).find(([,e])=>e===t)?.[0]??null:null}function E(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=T(e);n&&t.add(b[n])}return[...t]}var D=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function O(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(D)??[]).size>=3}function k(e){let t=new Set;for(let[n,r]of Object.entries(b)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function A(e){return C.find(({pattern:t})=>t.test(e))?.bundle??null}function j(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function M(e){let t=new Set;for(let n of j(e)){let e=A(n);e&&t.add(e)}return[...t]}var N=`8174697699fafa9a`,P=new Map;function F(e){let t=P.get(e);if(t)return t;let n=fetch(`${p}${m}/${e}.js?v=${N}`,{credentials:`same-origin`,cache:`no-cache`}).then(t=>{if(!t.ok)throw Error(`The artifact runtime bundle "${e}" is unavailable (HTTP ${t.status}).`);return t.text()});return n.catch(()=>P.delete(e)),P.set(e,n),n}async function I(e){let t=await Promise.all(e.map(F));return Object.fromEntries(e.map((e,n)=>[e,t[n]]))}var L=`
|
|
2
2
|
html, body { margin: 0; min-height: 100%; }
|
|
3
3
|
body {
|
|
4
4
|
background: #ffffff;
|
package/frontend/dist/js/{ArtifactSlideOutPanel-BIeQrdzE.js → ArtifactSlideOutPanel-laZ98QKB.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-D0Ec-185.js";import{t as i}from"./logger-BR4forr_.js";import{t as ee}from"./useTranslation-Kn7_iLGj.js";import{t as a}from"./utils-Dq1w7K0c.js";import{T as te,t as ne}from"./chatStore-BtjmZY_D.js";import{$t as o,Cn as re,Fn as s,In as c,On as ie,Qn as ae,Xn as l,Yn as oe,_n as u,g as d,jn as se,n as ce,tn as le}from"./ui-vendor-wayYH9Nf.js";import{t as ue}from"./appStore-DglPGdPW.js";import{t as f}from"./Button-ZQ6BePid.js";import{i as de,r as p}from"./artifactHtml-DDmfpcB0.js";import{t as m}from"./OptimizedSyntaxHighlighter-aKWyHj_c.js";import{t as fe}from"./ArtifactSandboxFrame-Dv32Q7Q9.js";var h=e(t(),1),pe=n(),g=r(),me=i(`components:artifact-slide-out-panel`),_=320,he=.9,ge=400,_e=`(min-width: 768px)`,ve=`(min-width: 1024px)`,v=e=>{let[t,n]=(0,h.useState)(()=>typeof window<`u`&&window.matchMedia(e).matches);return(0,h.useEffect)(()=>{let t=window.matchMedia(e),r=()=>n(t.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t},y=()=>{let{t:e,i18n:t}=ee(),n=te(t.language),{artifactPanelOpen:r,artifactPanelArtifact:i,openArtifactPanel:y,closeArtifactPanel:b,theme:x,artifactPanelWidth:S,setArtifactPanelWidth:C,artifactPanelResizing:w,setArtifactPanelResizing:T,sidebarOpen:E,sidebarCompact:D}=ue(),O=v(_e),k=v(ve)?E?D?64:288:0:E&&D?64:0,A=(0,h.useCallback)(()=>O?Math.max(_,window.innerWidth-k-ge):window.innerWidth*he,[O,k]),j=ne(e=>e.currentSession),M=h.useMemo(()=>{if(!i)return[];let e=i.title.trim().toLowerCase(),t=(j?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===i.id||e.content===i.content)?t:[...t,i]},[j,i]),N=M.findIndex(e=>e.id===i?.id);N===-1&&i&&(N=M.findIndex(e=>e.content===i.content));let[P,F]=(0,h.useState)(!1),[I,L]=(0,h.useState)(`preview`),R=(0,h.useRef)(null),z=(0,h.useRef)(null),B=(0,h.useRef)(0),V=(0,h.useRef)(0),H=(0,h.useRef)(null),U=(0,h.useRef)(null),W=(0,h.useRef)(S),G=i?.id??null;G!==z.current&&(z.current=G,I!==`preview`&&L(`preview`));let K=(0,h.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,C(W.current)}))},[C]),q=(0,h.useCallback)(()=>{H.current=null,T(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,C(W.current))},[T,C]),ye=(0,h.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=S,B.current=e.clientX,W.current=S,e.currentTarget.setPointerCapture(e.pointerId),T(!0)},[S,T]),J=(0,h.useCallback)(e=>{if(!w||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=Math.min(A(),Math.max(_,V.current+t));K(r)},[w,n,K,A]);if((0,h.useEffect)(()=>{if(!w){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[w,J,q]),(0,h.useEffect)(()=>{let e=()=>{let e=A();S>e&&C(e)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[S,C,A]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{e.key===`Escape`&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,b,O]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{w||R.current&&!R.current.contains(e.target)&&r&&b()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,b,w,O]),!i)return null;let Y=i,be=async e=>{try{await navigator.clipboard.writeText(e),F(!0),setTimeout(()=>F(!1),2e3)}catch(e){me.error(`Failed to copy:`,e)}},xe=()=>{let e=Y.type===`html`?p(Y.content,Y.title):Y.content,t=new Blob([e],{type:Se(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${Ce(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},Se=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},Ce=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},we=()=>{switch(Y.type){case`html`:return(0,g.jsx)(le,{className:`h-5 w-5`});case`react`:return(0,g.jsx)(s,{className:`h-5 w-5`});case`svg`:return(0,g.jsx)(u,{className:`h-5 w-5`});case`code`:return(0,g.jsx)(s,{className:`h-5 w-5`});default:return(0,g.jsx)(u,{className:`h-5 w-5`})}},X=()=>(0,g.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,g.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,g.jsx)(d,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,g.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,g.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,g.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>L(`code`),className:`mt-4`,children:[(0,g.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Z=e=>Y.content.trim()?(0,g.jsx)(fe,{content:Y.content,title:Y.title,kind:e,colorScheme:x.mode===`light`?`light`:`dark`,className:a(`w-full h-full border-0 rounded-lg bg-white`,w&&`pointer-events-none`),fallback:X()}):X(),Te=()=>(0,g.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:de(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(m,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:x.mode!==`light`,className:`!m-0 !rounded-lg !h-full`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:Y.content})}),Ee=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(m,{language:`json`,isDark:x.mode!==`light`,className:`!m-0 !rounded-lg !h-full`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:t})})}catch{return(0,g.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,g.jsxs)(`div`,{className:`text-center`,children:[(0,g.jsx)(d,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,g.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},De=()=>{if(I===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Te();case`json`:return Ee();default:return Q()}},Oe=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,ke=$?`100%`:`${S}px`,Ae=(0,g.jsxs)(g.Fragment,{children:[!O&&(0,g.jsx)(`div`,{className:a(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),w&&(0,g.jsx)(`div`,{className:a(`fixed inset-0 cursor-col-resize select-none`,O?`z-40`:`z-[55]`),"aria-hidden":`true`}),(0,g.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:ke},className:a(`fixed top-0 end-0 h-full`,O?`z-30`:`z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,g.jsxs)(`div`,{onPointerDown:ye,"data-testid":`artifact-resize-handle`,title:e(`artifacts.dragEdgeToResize`),className:a(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,g.jsx)(`div`,{className:a(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,w&&`bg-primary-500 h-24`)}),(0,g.jsx)(`div`,{className:a(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,w&&`opacity-100`),children:(0,g.jsx)(o,{className:`h-4 w-4`})})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-gray-200 dark:border-dark-200 ps-3 pe-2 py-1.5`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,g.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:we()}),(0,g.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100 truncate`,title:Y.description||`${e(`artifacts.created`)}: ${new Date(Y.createdAt).toLocaleString()}`,children:Y.title}),(0,g.jsx)(`span`,{className:`hidden sm:inline text-[10px] bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-1.5 py-0.5 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),M.length>1&&N!==-1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,g.jsx)(f,{variant:`ghost`,size:`sm`,disabled:N===0,onClick:()=>y(M[N-1]),className:`h-7 w-7 p-0`,title:e(`artifacts.previousVersion`),children:(0,g.jsx)(l,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,g.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:N+1,total:M.length})}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,disabled:N===M.length-1,onClick:()=>y(M[N+1]),className:`h-7 w-7 p-0`,title:e(`artifacts.nextVersion`),children:(0,g.jsx)(oe,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Oe()&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,g.jsxs)(f,{variant:I===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`preview`),className:`h-7 px-2 text-xs`,title:e(`artifacts.previewMode`),children:[(0,g.jsx)(re,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.preview`)]}),(0,g.jsxs)(f,{variant:I===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`code`),className:`h-7 px-2 text-xs`,title:e(`artifacts.codeMode`),children:[(0,g.jsx)(c,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.code`)]})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>be(Y.content),className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:P?(0,g.jsx)(ae,{className:`h-3.5 w-3.5 text-green-500`}):(0,g.jsx)(se,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:xe,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:(0,g.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:b,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(O?`common.close`:`artifacts.closePanelEsc`),children:(0,g.jsx)(ce,{className:`h-4 w-4`})})]})]}),(0,g.jsx)(`div`,{className:`flex-1 p-2 overflow-hidden`,children:De()})]})]});return(0,pe.createPortal)(Ae,document.body)};export{y as ArtifactSlideOutPanel};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-wiHys0m2.js";import{t as i}from"./logger-BR4forr_.js";import{t as ee}from"./useTranslation-B9kflK9S.js";import{t as a}from"./utils-p8Gt72YP.js";import{T as te,t as ne}from"./chatStore-CK5ojwft.js";import{$t as o,Cn as re,Fn as s,In as c,On as ie,Qn as ae,Xn as l,Yn as oe,_n as u,g as d,jn as se,n as ce,tn as le}from"./ui-vendor-BhHHyHk3.js";import{t as ue}from"./appStore-BD70bvas.js";import{t as f}from"./Button-CGMYia4g.js";import{i as de,r as p}from"./artifactHtml-DDmfpcB0.js";import{t as m}from"./OptimizedSyntaxHighlighter-CzzV6ONG.js";import{t as fe}from"./ArtifactSandboxFrame-DlWJHI-r.js";var h=e(t(),1),pe=n(),g=r(),me=i(`components:artifact-slide-out-panel`),_=320,he=.9,ge=400,_e=`(min-width: 768px)`,ve=`(min-width: 1024px)`,v=e=>{let[t,n]=(0,h.useState)(()=>typeof window<`u`&&window.matchMedia(e).matches);return(0,h.useEffect)(()=>{let t=window.matchMedia(e),r=()=>n(t.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t},y=()=>{let{t:e,i18n:t}=ee(),n=te(t.language),{artifactPanelOpen:r,artifactPanelArtifact:i,openArtifactPanel:y,closeArtifactPanel:b,theme:x,artifactPanelWidth:S,setArtifactPanelWidth:C,artifactPanelResizing:w,setArtifactPanelResizing:T,sidebarOpen:E,sidebarCompact:D}=ue(),O=v(_e),k=v(ve)?E?D?64:288:0:E&&D?64:0,A=(0,h.useCallback)(()=>O?Math.max(_,window.innerWidth-k-ge):window.innerWidth*he,[O,k]),j=ne(e=>e.currentSession),M=h.useMemo(()=>{if(!i)return[];let e=i.title.trim().toLowerCase(),t=(j?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===i.id||e.content===i.content)?t:[...t,i]},[j,i]),N=M.findIndex(e=>e.id===i?.id);N===-1&&i&&(N=M.findIndex(e=>e.content===i.content));let[P,F]=(0,h.useState)(!1),[I,L]=(0,h.useState)(`preview`),R=(0,h.useRef)(null),z=(0,h.useRef)(null),B=(0,h.useRef)(0),V=(0,h.useRef)(0),H=(0,h.useRef)(null),U=(0,h.useRef)(null),W=(0,h.useRef)(S),G=i?.id??null;G!==z.current&&(z.current=G,I!==`preview`&&L(`preview`));let K=(0,h.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,C(W.current)}))},[C]),q=(0,h.useCallback)(()=>{H.current=null,T(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,C(W.current))},[T,C]),ye=(0,h.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=S,B.current=e.clientX,W.current=S,e.currentTarget.setPointerCapture(e.pointerId),T(!0)},[S,T]),J=(0,h.useCallback)(e=>{if(!w||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=Math.min(A(),Math.max(_,V.current+t));K(r)},[w,n,K,A]);if((0,h.useEffect)(()=>{if(!w){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[w,J,q]),(0,h.useEffect)(()=>{let e=()=>{let e=A();S>e&&C(e)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[S,C,A]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{e.key===`Escape`&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,b,O]),(0,h.useEffect)(()=>{if(O)return;let e=e=>{w||R.current&&!R.current.contains(e.target)&&r&&b()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,b,w,O]),!i)return null;let Y=i,be=async e=>{try{await navigator.clipboard.writeText(e),F(!0),setTimeout(()=>F(!1),2e3)}catch(e){me.error(`Failed to copy:`,e)}},xe=()=>{let e=Y.type===`html`?p(Y.content,Y.title):Y.content,t=new Blob([e],{type:Se(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${Ce(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},Se=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},Ce=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},we=()=>{switch(Y.type){case`html`:return(0,g.jsx)(le,{className:`h-5 w-5`});case`react`:return(0,g.jsx)(s,{className:`h-5 w-5`});case`svg`:return(0,g.jsx)(u,{className:`h-5 w-5`});case`code`:return(0,g.jsx)(s,{className:`h-5 w-5`});default:return(0,g.jsx)(u,{className:`h-5 w-5`})}},X=()=>(0,g.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,g.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,g.jsx)(d,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,g.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,g.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,g.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>L(`code`),className:`mt-4`,children:[(0,g.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Z=e=>Y.content.trim()?(0,g.jsx)(fe,{content:Y.content,title:Y.title,kind:e,colorScheme:x.mode===`light`?`light`:`dark`,className:a(`w-full h-full border-0 rounded-lg bg-white`,w&&`pointer-events-none`),fallback:X()}):X(),Te=()=>(0,g.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:de(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(m,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:x.mode!==`light`,className:`!m-0 !rounded-lg !h-full`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:Y.content})}),Ee=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,g.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,g.jsx)(m,{language:`json`,isDark:x.mode!==`light`,className:`!m-0 !rounded-lg !h-full`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:x.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:t})})}catch{return(0,g.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,g.jsxs)(`div`,{className:`text-center`,children:[(0,g.jsx)(d,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,g.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},De=()=>{if(I===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Te();case`json`:return Ee();default:return Q()}},Oe=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,ke=$?`100%`:`${S}px`,Ae=(0,g.jsxs)(g.Fragment,{children:[!O&&(0,g.jsx)(`div`,{className:a(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),w&&(0,g.jsx)(`div`,{className:a(`fixed inset-0 cursor-col-resize select-none`,O?`z-40`:`z-[55]`),"aria-hidden":`true`}),(0,g.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:ke},className:a(`fixed top-0 end-0 h-full`,O?`z-30`:`z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,g.jsxs)(`div`,{onPointerDown:ye,"data-testid":`artifact-resize-handle`,title:e(`artifacts.dragEdgeToResize`),className:a(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,g.jsx)(`div`,{className:a(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,w&&`bg-primary-500 h-24`)}),(0,g.jsx)(`div`,{className:a(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,w&&`opacity-100`),children:(0,g.jsx)(o,{className:`h-4 w-4`})})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-gray-200 dark:border-dark-200 ps-3 pe-2 py-1.5`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,g.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:we()}),(0,g.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100 truncate`,title:Y.description||`${e(`artifacts.created`)}: ${new Date(Y.createdAt).toLocaleString()}`,children:Y.title}),(0,g.jsx)(`span`,{className:`hidden sm:inline text-[10px] bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-1.5 py-0.5 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),M.length>1&&N!==-1&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,g.jsx)(f,{variant:`ghost`,size:`sm`,disabled:N===0,onClick:()=>y(M[N-1]),className:`h-7 w-7 p-0`,title:e(`artifacts.previousVersion`),children:(0,g.jsx)(l,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,g.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:N+1,total:M.length})}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,disabled:N===M.length-1,onClick:()=>y(M[N+1]),className:`h-7 w-7 p-0`,title:e(`artifacts.nextVersion`),children:(0,g.jsx)(oe,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Oe()&&(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,g.jsxs)(f,{variant:I===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`preview`),className:`h-7 px-2 text-xs`,title:e(`artifacts.previewMode`),children:[(0,g.jsx)(re,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.preview`)]}),(0,g.jsxs)(f,{variant:I===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>L(`code`),className:`h-7 px-2 text-xs`,title:e(`artifacts.codeMode`),children:[(0,g.jsx)(c,{className:`h-3.5 w-3.5 me-1`}),e(`artifacts.code`)]})]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-0.5 flex-shrink-0`,children:[(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:()=>be(Y.content),className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:P?(0,g.jsx)(ae,{className:`h-3.5 w-3.5 text-green-500`}):(0,g.jsx)(se,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:xe,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:(0,g.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,g.jsx)(f,{variant:`ghost`,size:`sm`,onClick:b,className:`h-7 w-7 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(O?`common.close`:`artifacts.closePanelEsc`),children:(0,g.jsx)(ce,{className:`h-4 w-4`})})]})]}),(0,g.jsx)(`div`,{className:`flex-1 p-2 overflow-hidden`,children:De()})]})]});return(0,pe.createPortal)(Ae,document.body)};export{y as ArtifactSlideOutPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-D0Ec-185.js";import{t as i}from"./useTranslation-Kn7_iLGj.js";import{t as a}from"./utils-Dq1w7K0c.js";import{Rn as o,et as s,n as c,v as l,wr as u}from"./ui-vendor-wayYH9Nf.js";import{E as d}from"./api-jEschMu2.js";import{t as f}from"./workApi-Xmj4wmPi.js";import{c as p,d as m,l as h,n as g}from"./calendarDates-Co3o_05Y.js";var _=e(t(),1),v=n(),y=[`channel-mention`,`channel-dm`,`channel-invite`,`share`,`calendar-reminder`,`media-ready`,`media-failed`,`budget-alert`,`work-run-finished`,`work-run-attention`,`work-takeover`,`work-approval`,`system`],b=e=>e.length>0&&e.every(e=>e.kind===`event`),x=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),S=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),C=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function w(e,t,n){switch(e.kind){case`event`:return n(e.match?`automations.trigger.eventMatching`:`automations.trigger.event`,{event:n(`automations.triggers.events.${e.event}`),match:e.match??``});case`once`:return n(`automations.trigger.once`,{when:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.at))});case`hourly`:{let t=e.startHour!==void 0||e.endHour!==void 0?` (${e.startHour??0}–${e.endHour??23})`:``;return n(`automations.trigger.hourly`,{minute:String(e.minute).padStart(2,`0`)})+t}case`daily`:return n(`automations.trigger.daily`,{time:x(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:S(e.dayOfWeek,t),time:x(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:x(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:C(e.month,e.dayOfMonth,t),time:x(e.hour,e.minute,t)})}}function T(e,t,n){return e.map(e=>w(e,t,n)).join(` · `)}function E(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){case`event`:return y.includes(e.event)&&(e.match===void 0||typeof e.match==`string`&&e.match.length<=200);case`once`:return t(e.at,0,864e13);case`hourly`:return t(e.minute,0,59)&&(e.startHour===void 0||t(e.startHour,0,23))&&(e.endHour===void 0||t(e.endHour,0,23))&&(e.startHour===void 0||e.endHour===void 0||e.endHour>=e.startHour);case`daily`:return t(e.hour,0,23)&&t(e.minute,0,59);case`weekly`:return t(e.dayOfWeek,0,6)&&t(e.hour,0,23)&&t(e.minute,0,59);case`monthly`:return t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);case`yearly`:return t(e.month,1,12)&&t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);default:return!1}}var D=r(),O=[`event`,`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],k=`rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,A=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,j=e=>{switch(e){case`event`:return{kind:`event`,event:`channel-mention`};case`once`:{let e=new Date;return e.setHours(e.getHours()+1,0,0,0),{kind:`once`,at:e.getTime()}}case`hourly`:return{kind:`hourly`,minute:0};case`daily`:return{kind:`daily`,hour:8,minute:0};case`weekly`:return{kind:`weekly`,dayOfWeek:1,hour:9,minute:0};case`monthly`:return{kind:`monthly`,dayOfMonth:1,hour:9,minute:0};case`yearly`:return{kind:`yearly`,month:1,dayOfMonth:1,hour:9,minute:0}}};function M({trigger:e,onChange:t,onRemove:n}){let{t:r,i18n:a}=i(),s=m(a.language,`short`),c=new Intl.DateTimeFormat(a.language,{month:`long`}),u=n=>{let[r,i]=(n||`00:00`).split(`:`).map(Number);e.kind!==`hourly`&&e.kind!==`once`&&e.kind!==`event`&&t({...e,hour:r,minute:i})},d=e.kind!==`once`&&e.kind!==`hourly`&&e.kind!==`event`?(0,D.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:A(e.hour,e.minute),onChange:e=>u(e.target.value),className:k}):null;return(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-black/[0.06] bg-black/[0.02] px-2.5 py-2 dark:border-white/[0.06] dark:bg-white/[0.03]`,"data-testid":`automation-trigger`,children:[(0,D.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,D.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(j(e.target.value)),className:k,"data-testid":`automation-trigger-kind`,children:O.map(e=>(0,D.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`event`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`select`,{"aria-label":r(`automations.form.event`),value:e.event,onChange:n=>t({...e,event:n.target.value}),className:k,"data-testid":`automation-trigger-event`,children:y.map(e=>(0,D.jsx)(`option`,{value:e,children:r(`automations.triggers.events.${e}`)},e))}),(0,D.jsx)(`input`,{type:`text`,"aria-label":r(`automations.form.eventMatch`),placeholder:r(`automations.form.eventMatchPlaceholder`),value:e.match??``,onChange:n=>t({...e,match:n.target.value.slice(0,200)}),className:`${k} min-w-0 flex-1`,"data-testid":`automation-trigger-match`})]}),e.kind===`once`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`input`,{type:`date`,"aria-label":r(`calendar.date`),value:p(e.at),onChange:n=>t({...e,at:g(n.target.value,h(e.at))}),className:k}),(0,D.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:h(e.at),onChange:n=>t({...e,at:g(p(e.at),n.target.value)}),className:k})]}),e.kind===`hourly`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,D.jsx)(`input`,{type:`number`,min:0,max:59,value:e.minute,onChange:n=>t({...e,minute:Math.min(59,Math.max(0,Number(n.target.value)))}),className:`${k} w-16`})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,D.jsx)(`input`,{type:`number`,min:0,max:23,value:e.startHour??0,onChange:n=>t({...e,startHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${k} w-16`})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,D.jsx)(`input`,{type:`number`,min:0,max:23,value:e.endHour??23,onChange:n=>t({...e,endHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${k} w-16`})]})]}),e.kind===`weekly`&&(0,D.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:k,children:s.map((e,t)=>(0,D.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,D.jsx)(`input`,{type:`number`,min:1,max:31,value:e.dayOfMonth,onChange:n=>t({...e,dayOfMonth:Math.min(31,Math.max(1,Number(n.target.value)))}),className:`${k} w-16`})]}),e.kind===`yearly`&&(0,D.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:k,children:Array.from({length:12},(e,t)=>(0,D.jsx)(`option`,{value:t+1,children:c.format(new Date(2024,t,1))},t+1))}),d,n&&(0,D.jsx)(`button`,{type:`button`,onClick:n,"aria-label":r(`common.delete`),className:`ms-auto rounded-md p-1 text-red-500 transition-colors hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,D.jsx)(l,{className:`h-3.5 w-3.5`})})]})}var N=`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,P=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,F=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function I({open:e,automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s}){return e?(0,D.jsx)(L,{automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s},t?.id??n?.name??`new`):null}function L({automation:e,initial:t,fixedWorkTaskId:n,models:r,saving:o,onClose:l,onSave:p}){let{t:m}=i(),h=!!(n??e?.workTaskId),[g,y]=(0,_.useState)(e?.name??t?.name??``),[x,S]=(0,_.useState)(e?.instructions??t?.instructions??``),[C,w]=(0,_.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[T,O]=(0,_.useState)(e?.model??``),[k,A]=(0,_.useState)(e?.notify??`app`),[j,I]=(0,_.useState)(e?.target??`chat`),[L,R]=(0,_.useState)(e?.workPolicyId??``),[z,B]=(0,_.useState)([]);(0,_.useEffect)(()=>{if(j!==`work`||h)return;let e=!1;return f.listPolicies().then(t=>{!e&&t.success&&Array.isArray(t.data)&&B(t.data)}).catch(()=>void 0),()=>{e=!0}},[j,h]);let[V,H]=(0,_.useState)(e?.webhookEnabled===!0),[U,W]=(0,_.useState)(null),[G,K]=(0,_.useState)(!1),q=async()=>{if(e){K(!0);try{let t=await d.rotateWebhookSecret(e.id);if(!t.success||!t.data)throw Error(t.error);H(!0),W(t.data)}catch{u.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{K(!1)}}},J=async()=>{if(e){K(!0);try{let t=await d.disableWebhook(e.id);if(!t.success)throw Error(t.error);H(!1),W(null)}catch{u.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{K(!1)}}},Y=g.trim().length>0&&x.trim().length>0&&C.length>0&&C.every(E);return(0,v.createPortal)((0,D.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:l,children:(0,D.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,"data-testid":`automation-modal`,className:`flex max-h-[90vh] w-full max-w-lg flex-col overflow-hidden rounded-3xl border border-black/[0.07] bg-white shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:(0,D.jsxs)(`div`,{"data-testid":`automation-scroll-region`,className:`min-h-0 overflow-y-auto p-6 scrollbar-thin`,children:[(0,D.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,D.jsx)(`h3`,{id:`automation-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:m(e?`automations.editAutomation`:`automations.newAutomation`)}),(0,D.jsx)(`button`,{onClick:l,"aria-label":m(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,D.jsx)(c,{size:20,className:`text-gray-500`})})]}),(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-name`,className:P,children:m(`automations.form.name`)}),(0,D.jsx)(`input`,{id:`automation-name`,"data-testid":`automation-name`,type:`text`,value:g,onChange:e=>y(e.target.value),placeholder:m(`automations.form.namePlaceholder`),className:N,maxLength:200,autoFocus:!0})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:P,children:m(`automations.form.triggers`)}),(0,D.jsxs)(`div`,{className:`space-y-2`,children:[C.map((e,t)=>(0,D.jsx)(M,{trigger:e,onChange:e=>w(n=>n.map((n,r)=>r===t?e:n)),onRemove:C.length>1?()=>w(e=>e.filter((e,n)=>n!==t)):void 0},t)),b(C)&&(0,D.jsx)(`p`,{"data-testid":`automation-event-only-hint`,className:`text-[12px] text-gray-500 dark:text-dark-500`,children:m(`automations.form.eventOnlyHint`)}),C.length<5&&(0,D.jsxs)(`button`,{type:`button`,onClick:()=>w(e=>[...e,{kind:`daily`,hour:8,minute:0}]),"data-testid":`automation-add-trigger`,className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:[(0,D.jsx)(s,{className:`h-3.5 w-3.5`}),m(`automations.form.addTrigger`)]})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-instructions`,className:P,children:m(`automations.form.instructions`)}),(0,D.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:x,onChange:e=>S(e.target.value),placeholder:m(`automations.form.instructionsPlaceholder`),rows:5,className:N,maxLength:2e4})]}),h&&(0,D.jsx)(`p`,{"data-testid":`automation-task-bound-note`,className:`rounded-lg bg-primary-500/10 px-3 py-2 text-[12px] leading-relaxed text-primary-700 dark:text-primary-300`,children:m(`automations.form.taskBoundNote`,{defaultValue:`This routine runs inside the agent's own workspace and conversation, with the agent's model and runtime.`})}),(0,D.jsxs)(`div`,{className:a(`grid grid-cols-2 gap-3`,h&&`hidden`),children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-target`,className:P,children:m(`automations.form.target`)}),(0,D.jsxs)(`select`,{id:`automation-target`,"data-testid":`automation-target`,value:j,onChange:e=>I(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:`chat`,children:m(`automations.form.targetChat`)}),(0,D.jsx)(`option`,{value:`work`,children:m(`automations.form.targetWork`)})]})]}),j===`work`&&z.length>0&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-work-policy`,className:P,children:m(`automations.form.workPolicy`)}),(0,D.jsxs)(`select`,{id:`automation-work-policy`,"data-testid":`automation-work-policy`,value:L,onChange:e=>R(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:``,children:m(`automations.form.workPolicyDefault`)}),z.map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,D.jsxs)(`div`,{className:a(h&&`hidden`),children:[(0,D.jsx)(`label`,{htmlFor:`automation-model`,className:P,children:m(`automations.form.model`)}),(0,D.jsxs)(`select`,{id:`automation-model`,value:T,onChange:e=>O(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:``,children:m(`automations.form.modelAuto`)}),r.map(e=>(0,D.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-notify`,className:P,children:m(`automations.form.notification`)}),(0,D.jsxs)(`select`,{id:`automation-notify`,value:k,onChange:e=>A(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:`app`,children:m(`automations.form.notifyApp`)}),(0,D.jsx)(`option`,{value:`off`,children:m(`automations.form.notifyOff`)})]})]})]}),e&&(0,D.jsxs)(`div`,{"data-testid":`automation-webhook`,className:`rounded-xl border border-gray-200 p-3 dark:border-dark-300`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`automations.webhook.title`,{defaultValue:`Webhook trigger`})}),(0,D.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-600`,children:V?m(`automations.webhook.enabledHint`,{defaultValue:`External systems can fire this automation with the secret. Rotating invalidates the previous secret.`}):m(`automations.webhook.disabledHint`,{defaultValue:`Let an external system (CI, cron, home automation) fire this automation with a POST and a secret.`})})]}),(0,D.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-rotate`,onClick:()=>void q(),disabled:G,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:V?m(`automations.webhook.rotate`,{defaultValue:`Rotate secret`}):m(`automations.webhook.enable`,{defaultValue:`Enable`})}),V&&(0,D.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-disable`,onClick:()=>void J(),disabled:G,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:m(`automations.webhook.disable`,{defaultValue:`Disable`})})]})]}),U&&(0,D.jsxs)(`div`,{"data-testid":`automation-webhook-secret`,className:`mt-2 space-y-1 rounded-lg bg-gray-50 p-2 dark:bg-dark-100`,children:[(0,D.jsx)(`p`,{className:`text-[11px] text-gray-500 dark:text-dark-600`,children:m(`automations.webhook.revealHint`,{defaultValue:`Shown once. Send it as a Bearer token or an X-Libre-Webhook-Secret header.`})}),(0,D.jsxs)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:[`POST `,U.path]}),(0,D.jsx)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:U.secret})]})]}),(0,D.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,D.jsx)(`button`,{onClick:l,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:m(`common.cancel`)}),(0,D.jsx)(`button`,{onClick:()=>{if(!Y)return;if(h){p({name:g.trim(),instructions:x.trim(),triggers:C,notify:k,target:`work`,workTaskId:n??e?.workTaskId});return}let t=r.find(e=>e.name===T);p({name:g.trim(),instructions:x.trim(),triggers:C,...t?{provider:F(t),model:t.name}:{},notify:k,target:j,...j===`work`&&L?{workPolicyId:L}:{}})},disabled:o||!Y,"data-testid":`automation-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:m(o?`common.saving`:`common.save`)})]})]})]})})}),document.body)}export{T as n,b as r,I as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-wiHys0m2.js";import{t as i}from"./useTranslation-B9kflK9S.js";import{t as a}from"./utils-p8Gt72YP.js";import{Rn as o,et as s,n as c,v as l,wr as u}from"./ui-vendor-BhHHyHk3.js";import{E as d}from"./api-DPXCtanG.js";import{t as f}from"./workApi-C5InfT8x.js";import{c as p,d as m,l as h,n as g}from"./calendarDates-Co3o_05Y.js";var _=e(t(),1),v=n(),y=[`channel-mention`,`channel-dm`,`channel-invite`,`share`,`calendar-reminder`,`media-ready`,`media-failed`,`budget-alert`,`work-run-finished`,`work-run-attention`,`work-takeover`,`work-approval`,`system`],b=e=>e.length>0&&e.every(e=>e.kind===`event`),x=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),S=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),C=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function w(e,t,n){switch(e.kind){case`event`:return n(e.match?`automations.trigger.eventMatching`:`automations.trigger.event`,{event:n(`automations.triggers.events.${e.event}`),match:e.match??``});case`once`:return n(`automations.trigger.once`,{when:new Intl.DateTimeFormat(t,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.at))});case`hourly`:{let t=e.startHour!==void 0||e.endHour!==void 0?` (${e.startHour??0}–${e.endHour??23})`:``;return n(`automations.trigger.hourly`,{minute:String(e.minute).padStart(2,`0`)})+t}case`daily`:return n(`automations.trigger.daily`,{time:x(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:S(e.dayOfWeek,t),time:x(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:x(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:C(e.month,e.dayOfMonth,t),time:x(e.hour,e.minute,t)})}}function T(e,t,n){return e.map(e=>w(e,t,n)).join(` · `)}function E(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){case`event`:return y.includes(e.event)&&(e.match===void 0||typeof e.match==`string`&&e.match.length<=200);case`once`:return t(e.at,0,864e13);case`hourly`:return t(e.minute,0,59)&&(e.startHour===void 0||t(e.startHour,0,23))&&(e.endHour===void 0||t(e.endHour,0,23))&&(e.startHour===void 0||e.endHour===void 0||e.endHour>=e.startHour);case`daily`:return t(e.hour,0,23)&&t(e.minute,0,59);case`weekly`:return t(e.dayOfWeek,0,6)&&t(e.hour,0,23)&&t(e.minute,0,59);case`monthly`:return t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);case`yearly`:return t(e.month,1,12)&&t(e.dayOfMonth,1,31)&&t(e.hour,0,23)&&t(e.minute,0,59);default:return!1}}var D=r(),O=[`event`,`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],k=`rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,A=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,j=e=>{switch(e){case`event`:return{kind:`event`,event:`channel-mention`};case`once`:{let e=new Date;return e.setHours(e.getHours()+1,0,0,0),{kind:`once`,at:e.getTime()}}case`hourly`:return{kind:`hourly`,minute:0};case`daily`:return{kind:`daily`,hour:8,minute:0};case`weekly`:return{kind:`weekly`,dayOfWeek:1,hour:9,minute:0};case`monthly`:return{kind:`monthly`,dayOfMonth:1,hour:9,minute:0};case`yearly`:return{kind:`yearly`,month:1,dayOfMonth:1,hour:9,minute:0}}};function M({trigger:e,onChange:t,onRemove:n}){let{t:r,i18n:a}=i(),s=m(a.language,`short`),c=new Intl.DateTimeFormat(a.language,{month:`long`}),u=n=>{let[r,i]=(n||`00:00`).split(`:`).map(Number);e.kind!==`hourly`&&e.kind!==`once`&&e.kind!==`event`&&t({...e,hour:r,minute:i})},d=e.kind!==`once`&&e.kind!==`hourly`&&e.kind!==`event`?(0,D.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:A(e.hour,e.minute),onChange:e=>u(e.target.value),className:k}):null;return(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-xl border border-black/[0.06] bg-black/[0.02] px-2.5 py-2 dark:border-white/[0.06] dark:bg-white/[0.03]`,"data-testid":`automation-trigger`,children:[(0,D.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,D.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(j(e.target.value)),className:k,"data-testid":`automation-trigger-kind`,children:O.map(e=>(0,D.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`event`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`select`,{"aria-label":r(`automations.form.event`),value:e.event,onChange:n=>t({...e,event:n.target.value}),className:k,"data-testid":`automation-trigger-event`,children:y.map(e=>(0,D.jsx)(`option`,{value:e,children:r(`automations.triggers.events.${e}`)},e))}),(0,D.jsx)(`input`,{type:`text`,"aria-label":r(`automations.form.eventMatch`),placeholder:r(`automations.form.eventMatchPlaceholder`),value:e.match??``,onChange:n=>t({...e,match:n.target.value.slice(0,200)}),className:`${k} min-w-0 flex-1`,"data-testid":`automation-trigger-match`})]}),e.kind===`once`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`input`,{type:`date`,"aria-label":r(`calendar.date`),value:p(e.at),onChange:n=>t({...e,at:g(n.target.value,h(e.at))}),className:k}),(0,D.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:h(e.at),onChange:n=>t({...e,at:g(p(e.at),n.target.value)}),className:k})]}),e.kind===`hourly`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,D.jsx)(`input`,{type:`number`,min:0,max:59,value:e.minute,onChange:n=>t({...e,minute:Math.min(59,Math.max(0,Number(n.target.value)))}),className:`${k} w-16`})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,D.jsx)(`input`,{type:`number`,min:0,max:23,value:e.startHour??0,onChange:n=>t({...e,startHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${k} w-16`})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,D.jsx)(`input`,{type:`number`,min:0,max:23,value:e.endHour??23,onChange:n=>t({...e,endHour:Math.min(23,Math.max(0,Number(n.target.value)))}),className:`${k} w-16`})]})]}),e.kind===`weekly`&&(0,D.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:k,children:s.map((e,t)=>(0,D.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,D.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,D.jsx)(`input`,{type:`number`,min:1,max:31,value:e.dayOfMonth,onChange:n=>t({...e,dayOfMonth:Math.min(31,Math.max(1,Number(n.target.value)))}),className:`${k} w-16`})]}),e.kind===`yearly`&&(0,D.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:k,children:Array.from({length:12},(e,t)=>(0,D.jsx)(`option`,{value:t+1,children:c.format(new Date(2024,t,1))},t+1))}),d,n&&(0,D.jsx)(`button`,{type:`button`,onClick:n,"aria-label":r(`common.delete`),className:`ms-auto rounded-md p-1 text-red-500 transition-colors hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,D.jsx)(l,{className:`h-3.5 w-3.5`})})]})}var N=`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,P=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,F=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function I({open:e,automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s}){return e?(0,D.jsx)(L,{automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s},t?.id??n?.name??`new`):null}function L({automation:e,initial:t,fixedWorkTaskId:n,models:r,saving:o,onClose:l,onSave:p}){let{t:m}=i(),h=!!(n??e?.workTaskId),[g,y]=(0,_.useState)(e?.name??t?.name??``),[x,S]=(0,_.useState)(e?.instructions??t?.instructions??``),[C,w]=(0,_.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[T,O]=(0,_.useState)(e?.model??``),[k,A]=(0,_.useState)(e?.notify??`app`),[j,I]=(0,_.useState)(e?.target??`chat`),[L,R]=(0,_.useState)(e?.workPolicyId??``),[z,B]=(0,_.useState)([]);(0,_.useEffect)(()=>{if(j!==`work`||h)return;let e=!1;return f.listPolicies().then(t=>{!e&&t.success&&Array.isArray(t.data)&&B(t.data)}).catch(()=>void 0),()=>{e=!0}},[j,h]);let[V,H]=(0,_.useState)(e?.webhookEnabled===!0),[U,W]=(0,_.useState)(null),[G,K]=(0,_.useState)(!1),q=async()=>{if(e){K(!0);try{let t=await d.rotateWebhookSecret(e.id);if(!t.success||!t.data)throw Error(t.error);H(!0),W(t.data)}catch{u.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{K(!1)}}},J=async()=>{if(e){K(!0);try{let t=await d.disableWebhook(e.id);if(!t.success)throw Error(t.error);H(!1),W(null)}catch{u.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{K(!1)}}},Y=g.trim().length>0&&x.trim().length>0&&C.length>0&&C.every(E);return(0,v.createPortal)((0,D.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:l,children:(0,D.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,"data-testid":`automation-modal`,className:`flex max-h-[90vh] w-full max-w-lg flex-col overflow-hidden rounded-3xl border border-black/[0.07] bg-white shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:(0,D.jsxs)(`div`,{"data-testid":`automation-scroll-region`,className:`min-h-0 overflow-y-auto p-6 scrollbar-thin`,children:[(0,D.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,D.jsx)(`h3`,{id:`automation-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:m(e?`automations.editAutomation`:`automations.newAutomation`)}),(0,D.jsx)(`button`,{onClick:l,"aria-label":m(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,D.jsx)(c,{size:20,className:`text-gray-500`})})]}),(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-name`,className:P,children:m(`automations.form.name`)}),(0,D.jsx)(`input`,{id:`automation-name`,"data-testid":`automation-name`,type:`text`,value:g,onChange:e=>y(e.target.value),placeholder:m(`automations.form.namePlaceholder`),className:N,maxLength:200,autoFocus:!0})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:P,children:m(`automations.form.triggers`)}),(0,D.jsxs)(`div`,{className:`space-y-2`,children:[C.map((e,t)=>(0,D.jsx)(M,{trigger:e,onChange:e=>w(n=>n.map((n,r)=>r===t?e:n)),onRemove:C.length>1?()=>w(e=>e.filter((e,n)=>n!==t)):void 0},t)),b(C)&&(0,D.jsx)(`p`,{"data-testid":`automation-event-only-hint`,className:`text-[12px] text-gray-500 dark:text-dark-500`,children:m(`automations.form.eventOnlyHint`)}),C.length<5&&(0,D.jsxs)(`button`,{type:`button`,onClick:()=>w(e=>[...e,{kind:`daily`,hour:8,minute:0}]),"data-testid":`automation-add-trigger`,className:`flex items-center gap-1.5 rounded-lg px-2 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:[(0,D.jsx)(s,{className:`h-3.5 w-3.5`}),m(`automations.form.addTrigger`)]})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-instructions`,className:P,children:m(`automations.form.instructions`)}),(0,D.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:x,onChange:e=>S(e.target.value),placeholder:m(`automations.form.instructionsPlaceholder`),rows:5,className:N,maxLength:2e4})]}),h&&(0,D.jsx)(`p`,{"data-testid":`automation-task-bound-note`,className:`rounded-lg bg-primary-500/10 px-3 py-2 text-[12px] leading-relaxed text-primary-700 dark:text-primary-300`,children:m(`automations.form.taskBoundNote`,{defaultValue:`This routine runs inside the agent's own workspace and conversation, with the agent's model and runtime.`})}),(0,D.jsxs)(`div`,{className:a(`grid grid-cols-2 gap-3`,h&&`hidden`),children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-target`,className:P,children:m(`automations.form.target`)}),(0,D.jsxs)(`select`,{id:`automation-target`,"data-testid":`automation-target`,value:j,onChange:e=>I(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:`chat`,children:m(`automations.form.targetChat`)}),(0,D.jsx)(`option`,{value:`work`,children:m(`automations.form.targetWork`)})]})]}),j===`work`&&z.length>0&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-work-policy`,className:P,children:m(`automations.form.workPolicy`)}),(0,D.jsxs)(`select`,{id:`automation-work-policy`,"data-testid":`automation-work-policy`,value:L,onChange:e=>R(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:``,children:m(`automations.form.workPolicyDefault`)}),z.map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,D.jsxs)(`div`,{className:a(h&&`hidden`),children:[(0,D.jsx)(`label`,{htmlFor:`automation-model`,className:P,children:m(`automations.form.model`)}),(0,D.jsxs)(`select`,{id:`automation-model`,value:T,onChange:e=>O(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:``,children:m(`automations.form.modelAuto`)}),r.map(e=>(0,D.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{htmlFor:`automation-notify`,className:P,children:m(`automations.form.notification`)}),(0,D.jsxs)(`select`,{id:`automation-notify`,value:k,onChange:e=>A(e.target.value),className:N,children:[(0,D.jsx)(`option`,{value:`app`,children:m(`automations.form.notifyApp`)}),(0,D.jsx)(`option`,{value:`off`,children:m(`automations.form.notifyOff`)})]})]})]}),e&&(0,D.jsxs)(`div`,{"data-testid":`automation-webhook`,className:`rounded-xl border border-gray-200 p-3 dark:border-dark-300`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`automations.webhook.title`,{defaultValue:`Webhook trigger`})}),(0,D.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-600`,children:V?m(`automations.webhook.enabledHint`,{defaultValue:`External systems can fire this automation with the secret. Rotating invalidates the previous secret.`}):m(`automations.webhook.disabledHint`,{defaultValue:`Let an external system (CI, cron, home automation) fire this automation with a POST and a secret.`})})]}),(0,D.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-rotate`,onClick:()=>void q(),disabled:G,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:V?m(`automations.webhook.rotate`,{defaultValue:`Rotate secret`}):m(`automations.webhook.enable`,{defaultValue:`Enable`})}),V&&(0,D.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-disable`,onClick:()=>void J(),disabled:G,className:`rounded-lg border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:border-dark-300 dark:text-dark-700 dark:hover:bg-dark-200`,children:m(`automations.webhook.disable`,{defaultValue:`Disable`})})]})]}),U&&(0,D.jsxs)(`div`,{"data-testid":`automation-webhook-secret`,className:`mt-2 space-y-1 rounded-lg bg-gray-50 p-2 dark:bg-dark-100`,children:[(0,D.jsx)(`p`,{className:`text-[11px] text-gray-500 dark:text-dark-600`,children:m(`automations.webhook.revealHint`,{defaultValue:`Shown once. Send it as a Bearer token or an X-Libre-Webhook-Secret header.`})}),(0,D.jsxs)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:[`POST `,U.path]}),(0,D.jsx)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:U.secret})]})]}),(0,D.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,D.jsx)(`button`,{onClick:l,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:m(`common.cancel`)}),(0,D.jsx)(`button`,{onClick:()=>{if(!Y)return;if(h){p({name:g.trim(),instructions:x.trim(),triggers:C,notify:k,target:`work`,workTaskId:n??e?.workTaskId});return}let t=r.find(e=>e.name===T);p({name:g.trim(),instructions:x.trim(),triggers:C,...t?{provider:F(t),model:t.name}:{},notify:k,target:j,...j===`work`&&L?{workPolicyId:L}:{}})},disabled:o||!Y,"data-testid":`automation-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:m(o?`common.saving`:`common.save`)})]})]})]})})}),document.body)}export{T as n,b as r,I as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{d as r}from"./router-vendor-CM0PhOMl.js";import{t as i}from"./logger-BR4forr_.js";import{t as a}from"./useTranslation-Kn7_iLGj.js";import{i as o,t as s}from"./utils-Dq1w7K0c.js";import{t as c}from"./chatStore-BtjmZY_D.js";import{Dn as l,Hn as u,Lt as d,Un as ee,Vn as f,X as p,ct as te,et as ne,ot as m,rt as h,t as g,v as _,wr as v}from"./ui-vendor-wayYH9Nf.js";import{E as y}from"./api-jEschMu2.js";import{t as b}from"./Button-ZQ6BePid.js";import"./ui-CwzgKeUQ.js";import{n as x,r as S,t as C}from"./AutomationModal-Dy42OlIk.js";var w=e(t(),1),T=n();function E({days:e,locale:t}){let{t:n}=a(),r=e.reduce((e,t)=>e+t.succeeded,0),i=e.reduce((e,t)=>e+t.failed,0),o=Math.max(1,...e.map(e=>e.succeeded+e.failed)),s=new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}),c=new Date,l=e=>s.format(new Date(c.getFullYear(),c.getMonth(),c.getDate()-29+e));return(0,T.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.06] bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,"data-testid":`automation-run-strip`,children:[(0,T.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,T.jsx)(`p`,{className:`text-[12px] font-medium text-gray-700 dark:text-dark-700`,children:n(`automations.runHistory`)}),(0,T.jsxs)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:[(0,T.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[r,` `,n(`automations.succeeded`)]}),` · `,(0,T.jsxs)(`span`,{className:`text-red-500 dark:text-red-400`,children:[i,` `,n(`automations.failed`)]})]})]}),(0,T.jsx)(`div`,{className:`flex h-12 items-end gap-[3px]`,children:e.map((e,t)=>{let n=e.succeeded+e.failed;if(n===0)return(0,T.jsx)(`div`,{title:l(t),className:`h-[3px] flex-1 rounded-sm bg-black/[0.06] dark:bg-white/[0.08]`},t);let r=Math.max(6,Math.round(n/o*48)),i=Math.round(e.failed/n*r);return(0,T.jsxs)(`div`,{title:`${l(t)}: ${e.succeeded}✓ ${e.failed}✗`,className:`flex flex-1 flex-col justify-end overflow-hidden rounded-sm`,style:{height:r},children:[(0,T.jsx)(`div`,{className:`w-full bg-emerald-500/80`,style:{height:r-i}}),i>0&&(0,T.jsx)(`div`,{className:`w-full bg-red-500/80`,style:{height:i}})]},t)})})]})}var D=[{id:`morningBrief`,instructions:`Put together my morning brief: the top world, business, and tech headlines from the last 24 hours with one-line summaries, and one story worth reading in depth and why. Keep the whole thing scannable.`,triggers:[{kind:`daily`,hour:7,minute:30}]},{id:`newsDigest`,instructions:`Summarize the most important AI news from the last 24 hours: model releases, notable research papers, funding rounds, and policy changes. For each item add one sentence on why it matters. Skip minor product updates and rumors.`,triggers:[{kind:`daily`,hour:8,minute:0}]},{id:`weeklyReview`,instructions:`Help me wrap the week: prompt me to reflect on what I accomplished, what is still open, and what the top priorities for next week should be. Structure it as a short template I can fill in.`,triggers:[{kind:`weekly`,dayOfWeek:5,hour:16,minute:0}]},{id:`monthlyReport`,instructions:`Draft a monthly status report outline: key accomplishments, metrics to review, risks, and goals for the next month. Leave placeholders where my specifics belong.`,triggers:[{kind:`monthly`,dayOfMonth:1,hour:9,minute:0}]}],O=i(`pages:automations`),k=()=>{let{t:e,i18n:t}=a(),n=r(),i=c(e=>e.models),k=c(e=>e.loadModels),[j,M]=(0,w.useState)(`automations`),[N,P]=(0,w.useState)([]),[F,I]=(0,w.useState)([]),[L,R]=(0,w.useState)(null),[z,B]=(0,w.useState)(!0),[V,H]=(0,w.useState)(!1),[U,W]=(0,w.useState)(null),[G,K]=(0,w.useState)(null),[q,J]=(0,w.useState)(!1),[Y,X]=(0,w.useState)(null),[re,ie]=(0,w.useState)(0),Z=(0,w.useCallback)(()=>ie(e=>e+1),[]);(0,w.useEffect)(()=>{let t=!1;return Promise.all([y.getAutomations(),y.getRuns(),y.getRunsSummary()]).then(([e,n,r])=>{t||(e.success&&e.data&&P(e.data),n.success&&n.data&&I(n.data),r.success&&r.data&&R(r.data))}).catch(n=>{t||(O.error(`Failed to load automations:`,n),v.error(e(`automations.loadFailed`)))}).finally(()=>{t||B(!1)}),()=>{t=!0}},[re,e]),(0,w.useEffect)(()=>{i.length===0&&k({quiet:!0})},[i.length,k]),(0,w.useEffect)(()=>{j===`runs`&&y.markRunsSeen().then(()=>y.getRunsSummary()).then(e=>{e.success&&e.data&&R(e.data)}).catch(()=>void 0)},[j,F.length]);let ae=()=>{W(null),K(null),H(!0)},Q=t=>{W(null),K({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),H(!0)},oe=e=>{W(e),K(null),X(null),H(!0)},se=async t=>{J(!0);try{let n=U?await y.updateAutomation(U.id,t):await y.createAutomation(t);n.success?(H(!1),Z()):v.error(n.error||e(`automations.saveFailed`))}catch(t){O.error(`Failed to save automation:`,t),v.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{X(null);try{n===`pause`?await y.pauseAutomation(t.id):n===`resume`?await y.resumeAutomation(t.id):n===`run`?(await y.runAutomationNow(t.id),v.success(e(`automations.runQueued`))):await y.deleteAutomation(t.id),Z()}catch(t){O.error(`Automation ${n} failed:`,t),v.error(e(`automations.actionFailed`))}},ce=e=>e.status===`succeeded`?(0,T.jsx)(ee,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,T.jsx)(f,{className:`h-4 w-4 text-red-500`}):(0,T.jsx)(d,{className:`h-4 w-4 animate-spin text-gray-400`}),le=t=>N.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`);return(0,T.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`automations-page`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,T.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`automations.title`)}),(0,T.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`automations`,`runs`].map(t=>(0,T.jsx)(`button`,{onClick:()=>M(t),"data-testid":`automations-tab-${t}`,className:s(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,j===t?`bg-white text-gray-900 shadow-sm dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`automations.tab.${t}`)},t))})]}),(0,T.jsxs)(b,{size:`sm`,onClick:ae,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,T.jsx)(ne,{className:`h-3.5 w-3.5`}),e(`automations.newAutomation`)]})]}),(0,T.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-4 scrollbar-thin`,children:[j===`automations`?z?null:N.length===0?(0,T.jsxs)(`div`,{className:`px-3 py-16 text-center`,children:[(0,T.jsx)(g,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,T.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.empty`)})]}):(0,T.jsx)(`div`,{className:`mx-auto w-full max-w-3xl space-y-2`,children:N.map(n=>(0,T.jsx)(`div`,{"data-testid":`automation-row`,className:`rounded-2xl border border-black/[0.06] bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`p`,{className:`truncate text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,T.jsx)(`span`,{className:s(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,n.status===`active`?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:`bg-gray-500/10 text-gray-500 dark:text-dark-500`),children:e(`automations.status.${n.status}`)})]}),(0,T.jsxs)(`p`,{className:`mt-0.5 truncate text-[12px] text-gray-500 dark:text-dark-500`,children:[x(n.triggers,t.language,e),!S(n.triggers)&&n.nextRunAt&&(0,T.jsxs)(T.Fragment,{children:[` · `,e(`automations.nextRun`,{when:new Intl.DateTimeFormat(t.language,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(n.nextRunAt)})]})]})]}),(0,T.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,T.jsx)(`button`,{onClick:()=>X(e=>e===n.id?null:n.id),"aria-label":e(`automations.actions`),"data-testid":`automation-menu`,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-black/[0.04] hover:text-gray-700 dark:hover:bg-white/[0.06] dark:hover:text-dark-800`,children:(0,T.jsx)(l,{className:`h-4 w-4`})}),Y===n.id&&(0,T.jsxs)(`div`,{className:`absolute end-0 top-8 z-20 w-44 rounded-xl border border-black/[0.07] bg-white p-1 shadow-lg dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,T.jsx)(A,{icon:m,label:e(`common.edit`),onClick:()=>oe(n)}),n.status===`active`?(0,T.jsx)(A,{icon:te,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,T.jsx)(A,{icon:h,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,T.jsx)(A,{icon:p,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,T.jsx)(A,{icon:_,label:e(`common.delete`),destructive:!0,onClick:()=>$(n,`delete`)})]})]})]})},n.id))}):null,j===`automations`&&!z&&(0,T.jsxs)(`div`,{className:`mx-auto mt-8 w-full max-w-3xl`,children:[(0,T.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e(`automations.templatesTitle`)}),(0,T.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:D.map(n=>(0,T.jsxs)(`button`,{type:`button`,onClick:()=>Q(n),"data-testid":`automation-template`,className:`rounded-2xl border border-black/[0.06] bg-white/40 px-4 py-3 text-start transition-colors hover:bg-white/80 dark:border-white/[0.07] dark:bg-dark-100/40 dark:hover:bg-dark-100/80`,children:[(0,T.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e(`automations.templates.${n.id}.name`)}),(0,T.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e(`automations.templates.${n.id}.description`)}),(0,T.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:x(n.triggers,t.language,e)})]},n.id))})]}),j===`runs`&&(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[L&&(0,T.jsx)(E,{days:L.days,locale:t.language}),F.length===0?(0,T.jsxs)(`div`,{className:`px-3 py-12 text-center`,children:[(0,T.jsx)(u,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,T.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.noRuns`)})]}):(0,T.jsx)(`div`,{className:`space-y-1`,"data-testid":`automation-run-list`,children:F.map(r=>(0,T.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-black/[0.05] bg-white/50 px-3 py-2 dark:border-white/[0.06] dark:bg-dark-100/50`,children:[ce(r),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`p`,{className:`truncate text-[13px] text-gray-900 dark:text-dark-900`,children:le(r.automationId)}),(0,T.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[o(r.scheduledFor,t.language),r.error&&(0,T.jsxs)(T.Fragment,{children:[` · `,(0,T.jsx)(`span`,{className:`text-red-500`,children:r.error})]})]})]}),r.sessionId&&(0,T.jsx)(`button`,{onClick:()=>n(`/c/${r.sessionId}`),"data-testid":`automation-run-open`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openChat`)}),r.workTaskId&&(0,T.jsx)(`button`,{onClick:()=>n(`/work/${r.workTaskId}`),"data-testid":`automation-run-open-task`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openTask`)})]},r.id))})]})]}),(0,T.jsx)(C,{open:V,automation:U,initial:G,models:i,saving:q,onClose:()=>H(!1),onSave:e=>void se(e)})]})};function A({icon:e,label:t,destructive:n,onClick:r}){return(0,T.jsxs)(`button`,{onClick:r,className:s(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-start text-[13px] transition-colors`,n?`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`:`text-gray-700 hover:bg-black/[0.04] dark:text-dark-700 dark:hover:bg-white/[0.06]`),children:[(0,T.jsx)(e,{className:`h-3.5 w-3.5`}),t]})}export{k as default};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{d as r}from"./router-vendor-HZm4FR0A.js";import{t as i}from"./logger-BR4forr_.js";import{t as a}from"./useTranslation-B9kflK9S.js";import{i as o,t as s}from"./utils-p8Gt72YP.js";import{t as c}from"./chatStore-CK5ojwft.js";import{Dn as l,Hn as u,Lt as d,Un as ee,Vn as f,X as p,ct as te,et as ne,ot as m,rt as h,t as g,v as _,wr as v}from"./ui-vendor-BhHHyHk3.js";import{E as y}from"./api-DPXCtanG.js";import{t as b}from"./Button-CGMYia4g.js";import"./ui-D5-4niRk.js";import{n as x,r as S,t as C}from"./AutomationModal-CjjiEZFA.js";var w=e(t(),1),T=n();function E({days:e,locale:t}){let{t:n}=a(),r=e.reduce((e,t)=>e+t.succeeded,0),i=e.reduce((e,t)=>e+t.failed,0),o=Math.max(1,...e.map(e=>e.succeeded+e.failed)),s=new Intl.DateTimeFormat(t,{month:`short`,day:`numeric`}),c=new Date,l=e=>s.format(new Date(c.getFullYear(),c.getMonth(),c.getDate()-29+e));return(0,T.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.06] bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,"data-testid":`automation-run-strip`,children:[(0,T.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,T.jsx)(`p`,{className:`text-[12px] font-medium text-gray-700 dark:text-dark-700`,children:n(`automations.runHistory`)}),(0,T.jsxs)(`p`,{className:`text-[11px] text-gray-400 dark:text-dark-500`,children:[(0,T.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[r,` `,n(`automations.succeeded`)]}),` · `,(0,T.jsxs)(`span`,{className:`text-red-500 dark:text-red-400`,children:[i,` `,n(`automations.failed`)]})]})]}),(0,T.jsx)(`div`,{className:`flex h-12 items-end gap-[3px]`,children:e.map((e,t)=>{let n=e.succeeded+e.failed;if(n===0)return(0,T.jsx)(`div`,{title:l(t),className:`h-[3px] flex-1 rounded-sm bg-black/[0.06] dark:bg-white/[0.08]`},t);let r=Math.max(6,Math.round(n/o*48)),i=Math.round(e.failed/n*r);return(0,T.jsxs)(`div`,{title:`${l(t)}: ${e.succeeded}✓ ${e.failed}✗`,className:`flex flex-1 flex-col justify-end overflow-hidden rounded-sm`,style:{height:r},children:[(0,T.jsx)(`div`,{className:`w-full bg-emerald-500/80`,style:{height:r-i}}),i>0&&(0,T.jsx)(`div`,{className:`w-full bg-red-500/80`,style:{height:i}})]},t)})})]})}var D=[{id:`morningBrief`,instructions:`Put together my morning brief: the top world, business, and tech headlines from the last 24 hours with one-line summaries, and one story worth reading in depth and why. Keep the whole thing scannable.`,triggers:[{kind:`daily`,hour:7,minute:30}]},{id:`newsDigest`,instructions:`Summarize the most important AI news from the last 24 hours: model releases, notable research papers, funding rounds, and policy changes. For each item add one sentence on why it matters. Skip minor product updates and rumors.`,triggers:[{kind:`daily`,hour:8,minute:0}]},{id:`weeklyReview`,instructions:`Help me wrap the week: prompt me to reflect on what I accomplished, what is still open, and what the top priorities for next week should be. Structure it as a short template I can fill in.`,triggers:[{kind:`weekly`,dayOfWeek:5,hour:16,minute:0}]},{id:`monthlyReport`,instructions:`Draft a monthly status report outline: key accomplishments, metrics to review, risks, and goals for the next month. Leave placeholders where my specifics belong.`,triggers:[{kind:`monthly`,dayOfMonth:1,hour:9,minute:0}]}],O=i(`pages:automations`),k=()=>{let{t:e,i18n:t}=a(),n=r(),i=c(e=>e.models),k=c(e=>e.loadModels),[j,M]=(0,w.useState)(`automations`),[N,P]=(0,w.useState)([]),[F,I]=(0,w.useState)([]),[L,R]=(0,w.useState)(null),[z,B]=(0,w.useState)(!0),[V,H]=(0,w.useState)(!1),[U,W]=(0,w.useState)(null),[G,K]=(0,w.useState)(null),[q,J]=(0,w.useState)(!1),[Y,X]=(0,w.useState)(null),[re,ie]=(0,w.useState)(0),Z=(0,w.useCallback)(()=>ie(e=>e+1),[]);(0,w.useEffect)(()=>{let t=!1;return Promise.all([y.getAutomations(),y.getRuns(),y.getRunsSummary()]).then(([e,n,r])=>{t||(e.success&&e.data&&P(e.data),n.success&&n.data&&I(n.data),r.success&&r.data&&R(r.data))}).catch(n=>{t||(O.error(`Failed to load automations:`,n),v.error(e(`automations.loadFailed`)))}).finally(()=>{t||B(!1)}),()=>{t=!0}},[re,e]),(0,w.useEffect)(()=>{i.length===0&&k({quiet:!0})},[i.length,k]),(0,w.useEffect)(()=>{j===`runs`&&y.markRunsSeen().then(()=>y.getRunsSummary()).then(e=>{e.success&&e.data&&R(e.data)}).catch(()=>void 0)},[j,F.length]);let ae=()=>{W(null),K(null),H(!0)},Q=t=>{W(null),K({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),H(!0)},oe=e=>{W(e),K(null),X(null),H(!0)},se=async t=>{J(!0);try{let n=U?await y.updateAutomation(U.id,t):await y.createAutomation(t);n.success?(H(!1),Z()):v.error(n.error||e(`automations.saveFailed`))}catch(t){O.error(`Failed to save automation:`,t),v.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{X(null);try{n===`pause`?await y.pauseAutomation(t.id):n===`resume`?await y.resumeAutomation(t.id):n===`run`?(await y.runAutomationNow(t.id),v.success(e(`automations.runQueued`))):await y.deleteAutomation(t.id),Z()}catch(t){O.error(`Automation ${n} failed:`,t),v.error(e(`automations.actionFailed`))}},ce=e=>e.status===`succeeded`?(0,T.jsx)(ee,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,T.jsx)(f,{className:`h-4 w-4 text-red-500`}):(0,T.jsx)(d,{className:`h-4 w-4 animate-spin text-gray-400`}),le=t=>N.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`);return(0,T.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`automations-page`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,T.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`automations.title`)}),(0,T.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`automations`,`runs`].map(t=>(0,T.jsx)(`button`,{onClick:()=>M(t),"data-testid":`automations-tab-${t}`,className:s(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,j===t?`bg-white text-gray-900 shadow-sm dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`automations.tab.${t}`)},t))})]}),(0,T.jsxs)(b,{size:`sm`,onClick:ae,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,T.jsx)(ne,{className:`h-3.5 w-3.5`}),e(`automations.newAutomation`)]})]}),(0,T.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto px-4 py-4 scrollbar-thin`,children:[j===`automations`?z?null:N.length===0?(0,T.jsxs)(`div`,{className:`px-3 py-16 text-center`,children:[(0,T.jsx)(g,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,T.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.empty`)})]}):(0,T.jsx)(`div`,{className:`mx-auto w-full max-w-3xl space-y-2`,children:N.map(n=>(0,T.jsx)(`div`,{"data-testid":`automation-row`,className:`rounded-2xl border border-black/[0.06] bg-white/60 px-4 py-3 dark:border-white/[0.07] dark:bg-dark-100/60`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`p`,{className:`truncate text-[14px] font-medium text-gray-900 dark:text-dark-900`,children:n.name}),(0,T.jsx)(`span`,{className:s(`rounded-full px-2 py-0.5 text-[10px] font-medium uppercase tracking-wide`,n.status===`active`?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:`bg-gray-500/10 text-gray-500 dark:text-dark-500`),children:e(`automations.status.${n.status}`)})]}),(0,T.jsxs)(`p`,{className:`mt-0.5 truncate text-[12px] text-gray-500 dark:text-dark-500`,children:[x(n.triggers,t.language,e),!S(n.triggers)&&n.nextRunAt&&(0,T.jsxs)(T.Fragment,{children:[` · `,e(`automations.nextRun`,{when:new Intl.DateTimeFormat(t.language,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(n.nextRunAt)})]})]})]}),(0,T.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,T.jsx)(`button`,{onClick:()=>X(e=>e===n.id?null:n.id),"aria-label":e(`automations.actions`),"data-testid":`automation-menu`,className:`rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-black/[0.04] hover:text-gray-700 dark:hover:bg-white/[0.06] dark:hover:text-dark-800`,children:(0,T.jsx)(l,{className:`h-4 w-4`})}),Y===n.id&&(0,T.jsxs)(`div`,{className:`absolute end-0 top-8 z-20 w-44 rounded-xl border border-black/[0.07] bg-white p-1 shadow-lg dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,T.jsx)(A,{icon:m,label:e(`common.edit`),onClick:()=>oe(n)}),n.status===`active`?(0,T.jsx)(A,{icon:te,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,T.jsx)(A,{icon:h,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,T.jsx)(A,{icon:p,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,T.jsx)(A,{icon:_,label:e(`common.delete`),destructive:!0,onClick:()=>$(n,`delete`)})]})]})]})},n.id))}):null,j===`automations`&&!z&&(0,T.jsxs)(`div`,{className:`mx-auto mt-8 w-full max-w-3xl`,children:[(0,T.jsx)(`p`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e(`automations.templatesTitle`)}),(0,T.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:D.map(n=>(0,T.jsxs)(`button`,{type:`button`,onClick:()=>Q(n),"data-testid":`automation-template`,className:`rounded-2xl border border-black/[0.06] bg-white/40 px-4 py-3 text-start transition-colors hover:bg-white/80 dark:border-white/[0.07] dark:bg-dark-100/40 dark:hover:bg-dark-100/80`,children:[(0,T.jsx)(`p`,{className:`text-[13px] font-medium text-gray-900 dark:text-dark-900`,children:e(`automations.templates.${n.id}.name`)}),(0,T.jsx)(`p`,{className:`mt-0.5 text-[12px] text-gray-500 dark:text-dark-500`,children:e(`automations.templates.${n.id}.description`)}),(0,T.jsx)(`p`,{className:`mt-1.5 text-[11px] text-gray-400 dark:text-dark-500`,children:x(n.triggers,t.language,e)})]},n.id))})]}),j===`runs`&&(0,T.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl space-y-4`,children:[L&&(0,T.jsx)(E,{days:L.days,locale:t.language}),F.length===0?(0,T.jsxs)(`div`,{className:`px-3 py-12 text-center`,children:[(0,T.jsx)(u,{className:`mx-auto mb-2 h-6 w-6 text-gray-300 dark:text-dark-400`}),(0,T.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-dark-500`,children:e(`automations.noRuns`)})]}):(0,T.jsx)(`div`,{className:`space-y-1`,"data-testid":`automation-run-list`,children:F.map(r=>(0,T.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-black/[0.05] bg-white/50 px-3 py-2 dark:border-white/[0.06] dark:bg-dark-100/50`,children:[ce(r),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`p`,{className:`truncate text-[13px] text-gray-900 dark:text-dark-900`,children:le(r.automationId)}),(0,T.jsxs)(`p`,{className:`truncate text-[11px] text-gray-400 dark:text-dark-500`,children:[o(r.scheduledFor,t.language),r.error&&(0,T.jsxs)(T.Fragment,{children:[` · `,(0,T.jsx)(`span`,{className:`text-red-500`,children:r.error})]})]})]}),r.sessionId&&(0,T.jsx)(`button`,{onClick:()=>n(`/c/${r.sessionId}`),"data-testid":`automation-run-open`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openChat`)}),r.workTaskId&&(0,T.jsx)(`button`,{onClick:()=>n(`/work/${r.workTaskId}`),"data-testid":`automation-run-open-task`,className:`shrink-0 rounded-lg px-2.5 py-1 text-[12px] font-medium text-primary-600 transition-colors hover:bg-primary-500/10 dark:text-primary-400`,children:e(`automations.openTask`)})]},r.id))})]})]}),(0,T.jsx)(C,{open:V,automation:U,initial:G,models:i,saving:q,onClose:()=>H(!1),onSave:e=>void se(e)})]})};function A({icon:e,label:t,destructive:n,onClick:r}){return(0,T.jsxs)(`button`,{onClick:r,className:s(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-start text-[13px] transition-colors`,n?`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`:`text-gray-700 hover:bg-black/[0.04] dark:text-dark-700 dark:hover:bg-white/[0.06]`),children:[(0,T.jsx)(e,{className:`h-3.5 w-3.5`}),t]})}export{k as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{t as r}from"./logger-BR4forr_.js";import{t as i}from"./useTranslation-B9kflK9S.js";import{c as a,n as o,p as s,wr as c}from"./ui-vendor-BhHHyHk3.js";import{t as l}from"./Button-CGMYia4g.js";import"./ui-D5-4niRk.js";var u=e(t(),1),d=n(),f=r(`components:avatar-upload`),p=({value:e,onChange:t,className:n=``})=>{let{t:r}=i(),p=(0,u.useRef)(null),[m,h]=(0,u.useState)(!1),[g,_]=(0,u.useState)(!1),v=async e=>{if(!e.type.startsWith(`image/`)){c.error(r(`user.avatar.invalidFile`));return}if(e.size>2097152){c.error(r(`user.avatar.fileTooLarge`));return}h(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),c.success(r(`user.avatar.uploaded`))},n.onerror=()=>{c.error(r(`user.avatar.readFailed`))},n.readAsDataURL(e)}catch(e){f.error(`Failed to upload avatar:`,e),c.error(r(`user.avatar.uploadFailed`))}finally{h(!1)}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),_(!0)},x=e=>{e.preventDefault(),_(!1)},S=e=>{e.preventDefault(),_(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},C=()=>{t(``),c.success(r(`user.avatar.removed`))},w=()=>e||null;return(0,d.jsx)(`div`,{className:`space-y-4 ${n}`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-600 mb-2`,children:r(`user.avatar.label`)}),(0,d.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,d.jsx)(`div`,{className:`flex-shrink-0`,children:(0,d.jsx)(`div`,{className:`w-20 h-20 rounded-full overflow-hidden bg-gray-100 dark:bg-dark-200 border-2 border-gray-300 dark:border-dark-300 flex items-center justify-center`,children:w()?(0,d.jsx)(`img`,{src:w(),alt:`Avatar preview`,className:`w-full h-full object-cover`}):(0,d.jsx)(a,{className:`h-8 w-8 text-gray-400 dark:text-gray-500`})})}),(0,d.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[e?(0,d.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-gray-50 dark:bg-dark-200 rounded-lg`,children:[(0,d.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:r(`user.avatar.customAvatar`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:r(`user.avatar.clickToChange`)})]}),(0,d.jsx)(l,{variant:`ghost`,size:`sm`,onClick:C,className:`text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400 dark:hover:text-red-300 dark:hover:bg-red-900/20`,children:(0,d.jsx)(o,{className:`h-4 w-4`})})]}):(0,d.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-4 text-center cursor-pointer transition-colors ${g?`border-primary-500 bg-primary-50 dark:bg-primary-900/20`:`border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500`}`,onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>p.current?.click(),children:[(0,d.jsx)(s,{className:`h-8 w-8 mx-auto text-gray-400 dark:text-gray-500 mb-2`}),(0,d.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 mb-2`,children:r(`user.avatar.uploadAvatarImage`)}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mb-2`,children:r(`user.avatar.dragAndDrop`)}),(0,d.jsxs)(l,{variant:`outline`,size:`sm`,disabled:m,className:`mx-auto`,children:[(0,d.jsx)(s,{className:`h-4 w-4 mr-2`}),r(m?`user.avatar.uploading`:`user.avatar.chooseImage`)]})]}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`label`,{className:`block text-xs font-medium text-gray-600 dark:text-gray-400 mb-1`,children:r(`user.avatar.enterImageUrl`)}),(0,d.jsx)(`input`,{type:`url`,value:e,onChange:e=>t(e.target.value),className:`w-full px-3 py-2 text-sm border border-gray-300 dark:border-dark-300 rounded-md bg-white dark:bg-dark-50 text-gray-900 dark:text-dark-800`,placeholder:`https://example.com/avatar.jpg`})]})]})]}),(0,d.jsx)(`input`,{ref:p,type:`file`,accept:`image/*`,onChange:y,className:`hidden`}),(0,d.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-2`,children:r(`user.avatar.supportedFormats`)})]})})};export{p as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./rolldown-runtime-hePW80VL.js";import{i as e,t}from"./react-vendor-
|
|
1
|
+
import"./rolldown-runtime-hePW80VL.js";import{i as e,t}from"./react-vendor-wiHys0m2.js";import{t as n}from"./utils-p8Gt72YP.js";e();var r=t(),i=({variant:e=`primary`,size:t=`md`,loading:i=!1,disabled:a,children:o,className:s,...c})=>(0,r.jsxs)(`button`,{className:n(`group relative inline-flex select-none items-center justify-center rounded-xl border font-medium tracking-[-0.01em] transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:focus-visible:ring-primary-400 disabled:cursor-not-allowed disabled:opacity-40 motion-reduce:transition-none`,{primary:`border-transparent bg-ink text-ink-inverse shadow-subtle hover:opacity-90`,secondary:`border-line bg-surface-raised text-ink shadow-subtle hover:border-line-strong hover:bg-surface-subtle`,outline:`border-line bg-transparent text-ink hover:border-line-strong hover:bg-surface-subtle`,ghost:`border-transparent bg-transparent text-ink-muted shadow-none hover:bg-surface-subtle hover:text-ink`,danger:`border-transparent bg-error-600 text-white shadow-subtle hover:bg-error-700 dark:bg-error-500 dark:text-ink-inverse dark:hover:bg-error-400`}[e],{sm:`h-8 px-3 text-sm gap-1.5`,md:`h-10 px-4 text-sm gap-2`,lg:`h-11 px-5 text-base gap-2.5`}[t],s),disabled:a||i,"aria-busy":i||void 0,...c,children:[i&&(0,r.jsxs)(`svg`,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,children:[(0,r.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,r.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]}),o]});export{i as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-D0Ec-185.js";import{d as i}from"./router-vendor-CM0PhOMl.js";import{t as a}from"./logger-BR4forr_.js";import{t as o}from"./useTranslation-Kn7_iLGj.js";import{t as s}from"./utils-Dq1w7K0c.js";import{B as c,On as l,Xn as u,Yn as d,et as f,n as p,p as m,v as h,wr as g}from"./ui-vendor-wayYH9Nf.js";import{E as _,k as v}from"./api-jEschMu2.js";import{t as y}from"./Button-ZQ6BePid.js";import"./ui-CwzgKeUQ.js";import{t as b}from"./ShareDialog-DFCFk_5o.js";import{a as x,c as S,d as C,i as w,l as T,n as E,o as D,r as O,s as k,t as A,u as j}from"./calendarDates-Co3o_05Y.js";var M=e(t(),1),N=r(),P={event:`bg-primary-500/15 text-primary-700 hover:bg-primary-500/25 dark:text-primary-300`,automation:`bg-amber-500/15 text-amber-700 hover:bg-amber-500/25 dark:text-amber-300`,runSucceeded:`bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300`,runFailed:`bg-red-500/15 text-red-700 hover:bg-red-500/25 dark:text-red-300`};function F({event:e,label:t,onClick:n}){return(0,N.jsx)(`button`,{type:`button`,"data-testid":`calendar-event-chip`,"data-variant":e.variant??`event`,title:e.title,onClick:e=>{e.stopPropagation(),n()},className:s(`w-full truncate rounded-md px-1.5 py-0.5 text-start text-[11px] leading-4 transition-colors`,P[e.variant??`event`],e.baseEventId&&`opacity-75`),children:t})}var I=3;function L({year:e,monthIndex:t,events:n,onDayClick:r,onEventClick:i}){let{t:a,i18n:c}=o(),l=(0,M.useMemo)(()=>O(e,t),[e,t]),u=new Date,d=(0,M.useMemo)(()=>{let e=new Map;for(let t of n){let n=new Date(t.startAt),r=`${n.getFullYear()}-${n.getMonth()}-${n.getDate()}`,i=e.get(r);i?i.push(t):e.set(r,[t])}return e},[n]),f=(0,M.useMemo)(()=>C(c.language),[c.language]);return(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`calendar-month-grid`,children:[(0,N.jsx)(`div`,{className:`grid grid-cols-7 border-b border-black/[0.06] dark:border-white/[0.07]`,children:f.map(e=>(0,N.jsx)(`div`,{className:`px-2 py-1.5 text-center text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e},e))}),(0,N.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-7 grid-rows-6`,children:l.map(e=>{let n=e.getMonth()===t,o=w(e,u),l=`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`,f=d.get(l)??[],p=f.length-I;return(0,N.jsxs)(`div`,{role:`gridcell`,"data-testid":`calendar-day-cell`,onClick:()=>r(e),className:s(`flex min-h-0 cursor-pointer flex-col gap-0.5 border-b border-e border-black/[0.04] p-1 transition-colors hover:bg-black/[0.02] dark:border-white/[0.04] dark:hover:bg-white/[0.03]`,!n&&`opacity-40`),children:[(0,N.jsx)(`span`,{className:s(`flex h-6 w-6 items-center justify-center rounded-full text-[12px]`,o?`bg-primary-500 font-semibold text-white`:`text-gray-600 dark:text-dark-600`),children:e.getDate()}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0.5 overflow-hidden`,children:[f.slice(0,I).map(e=>(0,N.jsx)(F,{event:e,label:e.allDay?e.title:`${k(e.startAt,c.language)} ${e.title}`,onClick:()=>i(e)},e.id)),p>0&&(0,N.jsx)(`span`,{className:`px-1 text-[10px] text-gray-400 dark:text-dark-500`,children:a(`calendar.more`,{n:p})})]})]},l)})})]})}var R=48;function ee({anchor:e,events:t,dayCount:n=7,onDayClick:r,onEventClick:i}){let{i18n:a}=o(),c=(0,M.useMemo)(()=>n===1?[new Date(e.getFullYear(),e.getMonth(),e.getDate())]:j(e),[e,n]),l=new Date,u=(0,M.useMemo)(()=>new Intl.DateTimeFormat(a.language,{hour:`numeric`}),[a.language]),d=(0,M.useMemo)(()=>new Intl.DateTimeFormat(a.language,{weekday:`short`,day:`numeric`}),[a.language]),f=e=>t.filter(t=>t.allDay&&w(new Date(t.startAt),e)),p=e=>t.filter(t=>!t.allDay&&w(new Date(t.startAt),e));return(0,N.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto scrollbar-thin`,"data-testid":`calendar-week-grid`,children:(0,N.jsxs)(`div`,{className:`grid grid-cols-[3.5rem_repeat(7,1fr)]`,children:[(0,N.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-black/[0.06] bg-surface dark:border-white/[0.07]`}),c.map(e=>(0,N.jsxs)(`div`,{className:`sticky top-0 z-10 border-b border-e border-black/[0.06] bg-surface px-1 py-1.5 dark:border-white/[0.07]`,children:[(0,N.jsx)(`span`,{className:s(`block truncate text-center text-[11px] font-medium`,w(e,l)?`text-primary-600 dark:text-primary-400`:`text-gray-500 dark:text-dark-500`),children:d.format(e)}),(0,N.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:f(e).map(e=>(0,N.jsx)(F,{event:e,label:e.title,onClick:()=>i(e)},e.id))})]},e.toISOString())),Array.from({length:24},(e,t)=>(0,N.jsxs)(M.Fragment,{children:[(0,N.jsx)(`div`,{className:`relative border-b border-black/[0.04] pe-1.5 text-end text-[10px] text-gray-400 dark:border-white/[0.04] dark:text-dark-500`,children:(0,N.jsx)(`span`,{className:`relative -top-1.5`,children:t>0?u.format(new Date(2024,0,1,t)):``})}),c.map(e=>{let n=p(e).filter(e=>new Date(e.startAt).getHours()===t);return(0,N.jsx)(`div`,{onClick:()=>r(e,t),style:{height:R},className:`cursor-pointer space-y-0.5 overflow-hidden border-b border-e border-black/[0.04] p-0.5 transition-colors hover:bg-black/[0.02] dark:border-white/[0.04] dark:hover:bg-white/[0.03]`,children:n.map(e=>(0,N.jsx)(F,{event:e,label:`${k(e.startAt,a.language)} ${e.title}`,onClick:()=>i(e)},e.id))},`${e.toISOString()}-${t}`)})]},t))]})})}var z=n(),B=e=>!e||e.kind===`once`||e.kind===`hourly`||e.kind===`event`?`none`:e.kind,V=(e,t)=>{let n=new Date(t),r=n.getHours(),i=n.getMinutes();switch(e){case`daily`:return{kind:`daily`,hour:r,minute:i};case`weekly`:return{kind:`weekly`,dayOfWeek:n.getDay(),hour:r,minute:i};case`monthly`:return{kind:`monthly`,dayOfMonth:n.getDate(),hour:r,minute:i};case`yearly`:return{kind:`yearly`,month:n.getMonth()+1,dayOfMonth:n.getDate(),hour:r,minute:i};default:return null}},H=`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,U=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`;function te({open:e,event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s}){return e?(0,N.jsx)(W,{event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s},`${t?.id??`new`}:${n}`):null}function W({event:e,initialStartAt:t,calendars:n,saving:r,onClose:i,onSave:a,onDelete:s}){let{t:c}=o(),l=e?.startAt??t,[u,d]=(0,M.useState)(e?.title??``),[f,m]=(0,M.useState)(e?.notes??``),[g,_]=(0,M.useState)(S(l)),[v,y]=(0,M.useState)(e?T(l):`09:00`),[b,x]=(0,M.useState)(e?.endAt===void 0?``:T(e.endAt)),[C,w]=(0,M.useState)(e?.allDay??!1),[D,O]=(0,M.useState)(B(e?.recurrence)),[k,A]=(0,M.useState)(e?.calendarId??``),[j,P]=(0,M.useState)(e?.reminderMinutes===void 0?``:String(e.reminderMinutes)),F=()=>{if(!u.trim()||!g)return;let e=E(g,C?``:v),t=!C&&b?E(g,b):null;a({title:u.trim(),notes:f.trim()?f.trim():void 0,startAt:e,endAt:t!==null&&t>e?t:null,allDay:C,recurrence:V(D,e),calendarId:k||null,reminderMinutes:j?Number(j):null})},I=[{value:``,label:c(`calendar.reminderNone`)},{value:`5`,label:c(`calendar.reminderMinutes`,{minutes:5})},{value:`15`,label:c(`calendar.reminderMinutes`,{minutes:15})},{value:`30`,label:c(`calendar.reminderMinutes`,{minutes:30})},{value:`60`,label:c(`calendar.reminderHour`)},{value:`1440`,label:c(`calendar.reminderDay`)}],L=[{value:`none`,label:c(`calendar.repeatNone`)},{value:`daily`,label:c(`calendar.repeatDaily`)},{value:`weekly`,label:c(`calendar.repeatWeekly`)},{value:`monthly`,label:c(`calendar.repeatMonthly`)},{value:`yearly`,label:c(`calendar.repeatYearly`)}];return(0,z.createPortal)((0,N.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:i,children:(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`calendar-event-modal-title`,"data-testid":`calendar-event-modal`,className:`w-full max-w-md rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,N.jsx)(`h3`,{id:`calendar-event-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:c(e?`calendar.editEvent`:`calendar.newEvent`)}),(0,N.jsx)(`button`,{onClick:i,"aria-label":c(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,N.jsx)(p,{size:20,className:`text-gray-500`})})]}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-title`,className:U,children:c(`calendar.eventTitle`)}),(0,N.jsx)(`input`,{id:`calendar-event-title`,"data-testid":`calendar-event-title`,type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:c(`calendar.titlePlaceholder`),className:H,maxLength:200,autoFocus:!0})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-date`,className:U,children:c(`calendar.date`)}),(0,N.jsx)(`input`,{id:`calendar-event-date`,type:`date`,value:g,onChange:e=>_(e.target.value),className:H})]}),(0,N.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,N.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px] text-gray-700 dark:text-dark-700`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:C,onChange:e=>w(e.target.checked),className:`h-4 w-4 rounded accent-primary-500`}),c(`calendar.allDay`)]})})]}),!C&&(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-start`,className:U,children:c(`calendar.start`)}),(0,N.jsx)(`input`,{id:`calendar-event-start`,type:`time`,value:v,onChange:e=>y(e.target.value),className:H})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-end`,className:U,children:c(`calendar.end`)}),(0,N.jsx)(`input`,{id:`calendar-event-end`,type:`time`,value:b,onChange:e=>x(e.target.value),className:H})]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-repeat`,className:U,children:c(`calendar.repeat`)}),(0,N.jsx)(`select`,{id:`calendar-event-repeat`,value:D,onChange:e=>O(e.target.value),className:H,children:L.map(e=>(0,N.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-notes`,className:U,children:c(`calendar.notes`)}),(0,N.jsx)(`textarea`,{id:`calendar-event-notes`,value:f,onChange:e=>m(e.target.value),rows:3,className:H,maxLength:1e4})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{className:U,children:c(`calendar.calendarLabel`)}),(0,N.jsxs)(`select`,{value:k,onChange:e=>A(e.target.value),className:H,"data-testid":`calendar-event-calendar`,children:[(0,N.jsx)(`option`,{value:``,children:c(`calendar.personalCalendar`)}),n.map(e=>(0,N.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{className:U,children:c(`calendar.reminderLabel`)}),(0,N.jsx)(`select`,{value:j,onChange:e=>P(e.target.value),className:H,"data-testid":`calendar-event-reminder`,children:I.map(e=>(0,N.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[e&&s?(0,N.jsxs)(`button`,{onClick:s,"data-testid":`calendar-event-delete`,className:`flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:[(0,N.jsx)(h,{className:`h-4 w-4`}),c(`common.delete`)]}):(0,N.jsx)(`span`,{}),(0,N.jsxs)(`div`,{className:`flex gap-3`,children:[(0,N.jsx)(`button`,{onClick:i,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:c(`common.cancel`)}),(0,N.jsx)(`button`,{onClick:F,disabled:r||!u.trim(),"data-testid":`calendar-event-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:c(r?`common.saving`:`common.save`)})]})]})]})]})}),document.body)}var G=a(`pages:calendar`),K=()=>{let{t:e,i18n:t}=o(),n=i(),[r,a]=(0,M.useState)(`month`),[h,S]=(0,M.useState)(()=>new Date),[C,w]=(0,M.useState)([]),[T,E]=(0,M.useState)([]),[O,k]=(0,M.useState)(!1),[j,P]=(0,M.useState)(null),[F,I]=(0,M.useState)(()=>Date.now()),[R,z]=(0,M.useState)(!1),[B,V]=(0,M.useState)([]),[H,U]=(0,M.useState)(``),[W,K]=(0,M.useState)(!1),[q,J]=(0,M.useState)(null),Y=M.useRef(null),X=(0,M.useMemo)(()=>{if(r===`month`){let e=new Date(h.getFullYear(),h.getMonth(),1),t=D(e);return{from:t.getTime(),to:A(t,42).getTime()}}if(r===`day`){let e=new Date(h.getFullYear(),h.getMonth(),h.getDate());return{from:e.getTime(),to:A(e,1).getTime()}}let e=D(h);return{from:e.getTime(),to:A(e,7).getTime()}},[h,r]),[Z,ne]=(0,M.useState)(0),Q=(0,M.useCallback)(()=>ne(e=>e+1),[]);(0,M.useEffect)(()=>{v.getCalendars().then(e=>{e.success&&e.data&&V(e.data)}).catch(e=>G.error(`Failed to load calendars:`,e))},[Z]),(0,M.useEffect)(()=>{let t=!1;return v.getEvents(X.from,X.to).then(e=>{t||e.success&&e.data&&w(e.data)}).catch(n=>{t||(G.error(`Failed to load calendar events:`,n),g.error(e(`calendar.loadFailed`)))}),Promise.all([_.getOccurrences(X.from,X.to),_.getRuns({from:X.from,to:X.to}),_.getAutomations()]).then(([n,r,i])=>{if(t)return;let a=Date.now(),o=t=>i.data?.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`),s=[];for(let e of n.data??[])e.at<=a||s.push({id:`automation:${e.automationId}:${e.at}`,title:e.name,startAt:e.at,allDay:!1,createdAt:e.at,updatedAt:e.at,variant:`automation`});for(let e of r.data??[])(e.status===`succeeded`||e.status===`failed`)&&s.push({id:`run:${e.id}`,title:o(e.automationId),startAt:e.scheduledFor,allDay:!1,createdAt:e.createdAt,updatedAt:e.createdAt,variant:e.status===`succeeded`?`runSucceeded`:`runFailed`,...e.sessionId?{sessionId:e.sessionId}:{}});E(s)}).catch(e=>{t||G.error(`Failed to project automations onto the calendar:`,e)}),()=>{t=!0}},[X.from,X.to,Z,e]);let re=(0,M.useMemo)(()=>[...C,...T].sort((e,t)=>e.startAt-t.startAt),[C,T]),ie=e=>{S(t=>r===`month`?new Date(t.getFullYear(),t.getMonth()+e,1):A(t,e*(r===`day`?1:7)))},$=(e,t=9)=>{P(null),I(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t,0).getTime()),k(!0)},ae=t=>{if(t.variant===`runSucceeded`||t.variant===`runFailed`){t.sessionId?n(`/c/${t.sessionId}`):n(`/automations`);return}if(t.variant===`automation`){n(`/automations`);return}if(t.shared&&t.shared.permission!==`write`){g(e(`calendar.sharedReadOnly`));return}if(t.baseEventId){let e=C.find(e=>e.id===t.baseEventId);P(e??t)}else P(t);k(!0)},oe=async t=>{z(!0);try{let n=j?await v.updateEvent(j.id,t):await v.createEvent(t);n.success?(k(!1),Q()):g.error(n.error||e(`calendar.saveFailed`))}catch(t){G.error(`Failed to save calendar event:`,t),g.error(e(`calendar.saveFailed`))}finally{z(!1)}},se=async()=>{if(j){z(!0);try{let t=await v.deleteEvent(j.id);t.success?(k(!1),Q()):g.error(t.error||e(`calendar.deleteFailed`))}catch(t){G.error(`Failed to delete calendar event:`,t),g.error(e(`calendar.deleteFailed`))}finally{z(!1)}}},ce=r===`month`?x(h.getFullYear(),h.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(r===`day`?h:D(h)),le=async()=>{let t=H.trim();if(!t||W)return;K(!0);let n=await v.createCalendar({name:t}).catch(()=>void 0);K(!1),n?.success?(U(``),Q()):g.error(e(`calendar.calendarSaveFailed`))},ue=async t=>{try{let e=await v.exportIcs(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`calendar.ics`,r.click(),URL.revokeObjectURL(n)}catch(t){G.error(`Failed to export the calendar:`,t),g.error(e(`calendar.exportFailed`))}},de=async t=>{try{let n=await t.text(),r=await v.importIcs(n);r.success&&r.data?(g.success(e(`calendar.importResult`,{total:r.data.imported})),Q()):g.error(r.error||e(`calendar.importFailed`))}catch(t){G.error(`Failed to import the calendar:`,t),g.error(e(`calendar.importFailed`))}};return(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`calendar-page`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,N.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`calendar.title`)}),(0,N.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-dark-500`,"data-testid":`calendar-range-label`,children:ce})]}),(0,N.jsxs)(`div`,{className:`flex w-full min-w-0 flex-wrap items-center gap-2 sm:w-auto`,children:[(0,N.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`month`,`week`,`day`].map(t=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(t),"aria-pressed":r===t,"data-testid":`calendar-view-${t}`,className:s(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,r===t?`bg-white text-gray-900 shadow-sm dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`calendar.${t}`)},t))}),(0,N.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>ie(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),"aria-label":e(`calendar.previous`),children:(0,N.jsx)(u,{className:`h-4 w-4 rtl:rotate-180`})}),(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>S(new Date),className:`h-7 px-2 text-[12px]`,children:e(`calendar.today`)}),(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>ie(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),"aria-label":e(`calendar.next`),children:(0,N.jsx)(d,{className:`h-4 w-4 rtl:rotate-180`})})]}),(0,N.jsxs)(y,{size:`sm`,onClick:()=>$(h),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,N.jsx)(f,{className:`h-3.5 w-3.5`}),e(`calendar.newEvent`)]})]})]}),(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-black/[0.06] px-4 py-2 dark:border-white/[0.07]`,children:[B.map(t=>(0,N.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-black/[0.08] px-2.5 py-1 text-xs text-gray-700 dark:border-white/[0.1] dark:text-dark-800`,"data-testid":`calendar-chip`,children:[(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:t.color??`#8b8b8b`}}),(0,N.jsx)(`span`,{className:`truncate`,title:t.name,children:t.name}),t.shared?(0,N.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:e(`calendar.sharedBadge`)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{onClick:()=>J(t),className:`shrink-0 text-gray-400 hover:text-primary-500 dark:text-dark-500`,title:e(`calendar.shareCalendar`),"data-testid":`calendar-share`,children:(0,N.jsx)(c,{className:`h-3 w-3`})}),(0,N.jsx)(`button`,{onClick:()=>void v.deleteCalendar(t.id).then(Q),className:`shrink-0 text-gray-400 hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),children:(0,N.jsx)(p,{className:`h-3 w-3`})})]})]},t.id)),(0,N.jsxs)(`form`,{className:`flex min-w-0 max-w-full items-center gap-1`,onSubmit:e=>{e.preventDefault(),le()},children:[(0,N.jsx)(`input`,{type:`text`,value:H,disabled:W,onChange:e=>U(e.target.value),placeholder:e(`calendar.newCalendarPlaceholder`),"aria-label":e(`calendar.newCalendarPlaceholder`),className:`min-w-0 w-36 rounded-full border border-dashed border-black/[0.12] bg-transparent px-2.5 py-1 text-base text-gray-700 placeholder:text-gray-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:border-white/[0.16] dark:text-dark-800 sm:text-xs`,"data-testid":`calendar-new-calendar`}),(0,N.jsx)(y,{type:`submit`,size:`sm`,variant:`ghost`,disabled:!H.trim(),loading:W,className:`h-7 shrink-0 px-2 text-xs`,"data-testid":`calendar-create-calendar`,children:e(`common.save`)})]}),(0,N.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,N.jsx)(`input`,{ref:Y,type:`file`,accept:`.ics,text/calendar`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&de(t),e.target.value=``}}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>Y.current?.click(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-import`,children:[(0,N.jsx)(m,{className:`h-3.5 w-3.5`}),e(`calendar.importIcs`)]}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>void ue(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-export`,children:[(0,N.jsx)(l,{className:`h-3.5 w-3.5`}),e(`calendar.exportIcs`)]})]})]}),r===`month`?(0,N.jsx)(L,{year:h.getFullYear(),monthIndex:h.getMonth(),events:re,onDayClick:e=>$(e),onEventClick:ae}):(0,N.jsx)(ee,{anchor:h,events:re,dayCount:r===`day`?1:7,onDayClick:(e,t)=>$(e,t),onEventClick:ae}),q&&(0,N.jsx)(b,{resourceType:`calendar`,resourceId:q.id,resourceLabel:q.name,onClose:()=>J(null)}),(0,N.jsx)(te,{open:O,event:j,initialStartAt:F,calendars:B.filter(e=>!e.shared||e.shared.permission===`write`),saving:R,onClose:()=>k(!1),onSave:e=>void oe(e),onDelete:()=>void se()})]})};export{K as default};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-wiHys0m2.js";import{d as i}from"./router-vendor-HZm4FR0A.js";import{t as a}from"./logger-BR4forr_.js";import{t as o}from"./useTranslation-B9kflK9S.js";import{t as s}from"./utils-p8Gt72YP.js";import{B as c,On as l,Xn as u,Yn as d,et as f,n as p,p as m,v as h,wr as g}from"./ui-vendor-BhHHyHk3.js";import{E as _,k as v}from"./api-DPXCtanG.js";import{t as y}from"./Button-CGMYia4g.js";import"./ui-D5-4niRk.js";import{t as b}from"./ShareDialog-Bhpt_Y1N.js";import{a as x,c as S,d as C,i as w,l as T,n as E,o as D,r as O,s as k,t as A,u as j}from"./calendarDates-Co3o_05Y.js";var M=e(t(),1),N=r(),P={event:`bg-primary-500/15 text-primary-700 hover:bg-primary-500/25 dark:text-primary-300`,automation:`bg-amber-500/15 text-amber-700 hover:bg-amber-500/25 dark:text-amber-300`,runSucceeded:`bg-emerald-500/15 text-emerald-700 hover:bg-emerald-500/25 dark:text-emerald-300`,runFailed:`bg-red-500/15 text-red-700 hover:bg-red-500/25 dark:text-red-300`};function F({event:e,label:t,onClick:n}){return(0,N.jsx)(`button`,{type:`button`,"data-testid":`calendar-event-chip`,"data-variant":e.variant??`event`,title:e.title,onClick:e=>{e.stopPropagation(),n()},className:s(`w-full truncate rounded-md px-1.5 py-0.5 text-start text-[11px] leading-4 transition-colors`,P[e.variant??`event`],e.baseEventId&&`opacity-75`),children:t})}var I=3;function L({year:e,monthIndex:t,events:n,onDayClick:r,onEventClick:i}){let{t:a,i18n:c}=o(),l=(0,M.useMemo)(()=>O(e,t),[e,t]),u=new Date,d=(0,M.useMemo)(()=>{let e=new Map;for(let t of n){let n=new Date(t.startAt),r=`${n.getFullYear()}-${n.getMonth()}-${n.getDate()}`,i=e.get(r);i?i.push(t):e.set(r,[t])}return e},[n]),f=(0,M.useMemo)(()=>C(c.language),[c.language]);return(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,"data-testid":`calendar-month-grid`,children:[(0,N.jsx)(`div`,{className:`grid grid-cols-7 border-b border-black/[0.06] dark:border-white/[0.07]`,children:f.map(e=>(0,N.jsx)(`div`,{className:`px-2 py-1.5 text-center text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:e},e))}),(0,N.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-7 grid-rows-6`,children:l.map(e=>{let n=e.getMonth()===t,o=w(e,u),l=`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`,f=d.get(l)??[],p=f.length-I;return(0,N.jsxs)(`div`,{role:`gridcell`,"data-testid":`calendar-day-cell`,onClick:()=>r(e),className:s(`flex min-h-0 cursor-pointer flex-col gap-0.5 border-b border-e border-black/[0.04] p-1 transition-colors hover:bg-black/[0.02] dark:border-white/[0.04] dark:hover:bg-white/[0.03]`,!n&&`opacity-40`),children:[(0,N.jsx)(`span`,{className:s(`flex h-6 w-6 items-center justify-center rounded-full text-[12px]`,o?`bg-primary-500 font-semibold text-white`:`text-gray-600 dark:text-dark-600`),children:e.getDate()}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-0.5 overflow-hidden`,children:[f.slice(0,I).map(e=>(0,N.jsx)(F,{event:e,label:e.allDay?e.title:`${k(e.startAt,c.language)} ${e.title}`,onClick:()=>i(e)},e.id)),p>0&&(0,N.jsx)(`span`,{className:`px-1 text-[10px] text-gray-400 dark:text-dark-500`,children:a(`calendar.more`,{n:p})})]})]},l)})})]})}var R=48;function ee({anchor:e,events:t,dayCount:n=7,onDayClick:r,onEventClick:i}){let{i18n:a}=o(),c=(0,M.useMemo)(()=>n===1?[new Date(e.getFullYear(),e.getMonth(),e.getDate())]:j(e),[e,n]),l=new Date,u=(0,M.useMemo)(()=>new Intl.DateTimeFormat(a.language,{hour:`numeric`}),[a.language]),d=(0,M.useMemo)(()=>new Intl.DateTimeFormat(a.language,{weekday:`short`,day:`numeric`}),[a.language]),f=e=>t.filter(t=>t.allDay&&w(new Date(t.startAt),e)),p=e=>t.filter(t=>!t.allDay&&w(new Date(t.startAt),e));return(0,N.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 overflow-y-auto scrollbar-thin`,"data-testid":`calendar-week-grid`,children:(0,N.jsxs)(`div`,{className:`grid grid-cols-[3.5rem_repeat(7,1fr)]`,children:[(0,N.jsx)(`div`,{className:`sticky top-0 z-10 border-b border-black/[0.06] bg-surface dark:border-white/[0.07]`}),c.map(e=>(0,N.jsxs)(`div`,{className:`sticky top-0 z-10 border-b border-e border-black/[0.06] bg-surface px-1 py-1.5 dark:border-white/[0.07]`,children:[(0,N.jsx)(`span`,{className:s(`block truncate text-center text-[11px] font-medium`,w(e,l)?`text-primary-600 dark:text-primary-400`:`text-gray-500 dark:text-dark-500`),children:d.format(e)}),(0,N.jsx)(`div`,{className:`mt-0.5 space-y-0.5`,children:f(e).map(e=>(0,N.jsx)(F,{event:e,label:e.title,onClick:()=>i(e)},e.id))})]},e.toISOString())),Array.from({length:24},(e,t)=>(0,N.jsxs)(M.Fragment,{children:[(0,N.jsx)(`div`,{className:`relative border-b border-black/[0.04] pe-1.5 text-end text-[10px] text-gray-400 dark:border-white/[0.04] dark:text-dark-500`,children:(0,N.jsx)(`span`,{className:`relative -top-1.5`,children:t>0?u.format(new Date(2024,0,1,t)):``})}),c.map(e=>{let n=p(e).filter(e=>new Date(e.startAt).getHours()===t);return(0,N.jsx)(`div`,{onClick:()=>r(e,t),style:{height:R},className:`cursor-pointer space-y-0.5 overflow-hidden border-b border-e border-black/[0.04] p-0.5 transition-colors hover:bg-black/[0.02] dark:border-white/[0.04] dark:hover:bg-white/[0.03]`,children:n.map(e=>(0,N.jsx)(F,{event:e,label:`${k(e.startAt,a.language)} ${e.title}`,onClick:()=>i(e)},e.id))},`${e.toISOString()}-${t}`)})]},t))]})})}var z=n(),B=e=>!e||e.kind===`once`||e.kind===`hourly`||e.kind===`event`?`none`:e.kind,V=(e,t)=>{let n=new Date(t),r=n.getHours(),i=n.getMinutes();switch(e){case`daily`:return{kind:`daily`,hour:r,minute:i};case`weekly`:return{kind:`weekly`,dayOfWeek:n.getDay(),hour:r,minute:i};case`monthly`:return{kind:`monthly`,dayOfMonth:n.getDate(),hour:r,minute:i};case`yearly`:return{kind:`yearly`,month:n.getMonth()+1,dayOfMonth:n.getDate(),hour:r,minute:i};default:return null}},H=`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900`,U=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`;function te({open:e,event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s}){return e?(0,N.jsx)(W,{event:t,initialStartAt:n,calendars:r,saving:i,onClose:a,onSave:o,onDelete:s},`${t?.id??`new`}:${n}`):null}function W({event:e,initialStartAt:t,calendars:n,saving:r,onClose:i,onSave:a,onDelete:s}){let{t:c}=o(),l=e?.startAt??t,[u,d]=(0,M.useState)(e?.title??``),[f,m]=(0,M.useState)(e?.notes??``),[g,_]=(0,M.useState)(S(l)),[v,y]=(0,M.useState)(e?T(l):`09:00`),[b,x]=(0,M.useState)(e?.endAt===void 0?``:T(e.endAt)),[C,w]=(0,M.useState)(e?.allDay??!1),[D,O]=(0,M.useState)(B(e?.recurrence)),[k,A]=(0,M.useState)(e?.calendarId??``),[j,P]=(0,M.useState)(e?.reminderMinutes===void 0?``:String(e.reminderMinutes)),F=()=>{if(!u.trim()||!g)return;let e=E(g,C?``:v),t=!C&&b?E(g,b):null;a({title:u.trim(),notes:f.trim()?f.trim():void 0,startAt:e,endAt:t!==null&&t>e?t:null,allDay:C,recurrence:V(D,e),calendarId:k||null,reminderMinutes:j?Number(j):null})},I=[{value:``,label:c(`calendar.reminderNone`)},{value:`5`,label:c(`calendar.reminderMinutes`,{minutes:5})},{value:`15`,label:c(`calendar.reminderMinutes`,{minutes:15})},{value:`30`,label:c(`calendar.reminderMinutes`,{minutes:30})},{value:`60`,label:c(`calendar.reminderHour`)},{value:`1440`,label:c(`calendar.reminderDay`)}],L=[{value:`none`,label:c(`calendar.repeatNone`)},{value:`daily`,label:c(`calendar.repeatDaily`)},{value:`weekly`,label:c(`calendar.repeatWeekly`)},{value:`monthly`,label:c(`calendar.repeatMonthly`)},{value:`yearly`,label:c(`calendar.repeatYearly`)}];return(0,z.createPortal)((0,N.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:i,children:(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`calendar-event-modal-title`,"data-testid":`calendar-event-modal`,className:`w-full max-w-md rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,N.jsx)(`h3`,{id:`calendar-event-modal-title`,className:`text-lg font-medium tracking-[-0.02em] text-gray-950 dark:text-dark-950`,children:c(e?`calendar.editEvent`:`calendar.newEvent`)}),(0,N.jsx)(`button`,{onClick:i,"aria-label":c(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,N.jsx)(p,{size:20,className:`text-gray-500`})})]}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-title`,className:U,children:c(`calendar.eventTitle`)}),(0,N.jsx)(`input`,{id:`calendar-event-title`,"data-testid":`calendar-event-title`,type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:c(`calendar.titlePlaceholder`),className:H,maxLength:200,autoFocus:!0})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-date`,className:U,children:c(`calendar.date`)}),(0,N.jsx)(`input`,{id:`calendar-event-date`,type:`date`,value:g,onChange:e=>_(e.target.value),className:H})]}),(0,N.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,N.jsxs)(`label`,{className:`flex items-center gap-2 text-[13px] text-gray-700 dark:text-dark-700`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:C,onChange:e=>w(e.target.checked),className:`h-4 w-4 rounded accent-primary-500`}),c(`calendar.allDay`)]})})]}),!C&&(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-start`,className:U,children:c(`calendar.start`)}),(0,N.jsx)(`input`,{id:`calendar-event-start`,type:`time`,value:v,onChange:e=>y(e.target.value),className:H})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-end`,className:U,children:c(`calendar.end`)}),(0,N.jsx)(`input`,{id:`calendar-event-end`,type:`time`,value:b,onChange:e=>x(e.target.value),className:H})]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-repeat`,className:U,children:c(`calendar.repeat`)}),(0,N.jsx)(`select`,{id:`calendar-event-repeat`,value:D,onChange:e=>O(e.target.value),className:H,children:L.map(e=>(0,N.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{htmlFor:`calendar-event-notes`,className:U,children:c(`calendar.notes`)}),(0,N.jsx)(`textarea`,{id:`calendar-event-notes`,value:f,onChange:e=>m(e.target.value),rows:3,className:H,maxLength:1e4})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{className:U,children:c(`calendar.calendarLabel`)}),(0,N.jsxs)(`select`,{value:k,onChange:e=>A(e.target.value),className:H,"data-testid":`calendar-event-calendar`,children:[(0,N.jsx)(`option`,{value:``,children:c(`calendar.personalCalendar`)}),n.map(e=>(0,N.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`label`,{className:U,children:c(`calendar.reminderLabel`)}),(0,N.jsx)(`select`,{value:j,onChange:e=>P(e.target.value),className:H,"data-testid":`calendar-event-reminder`,children:I.map(e=>(0,N.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[e&&s?(0,N.jsxs)(`button`,{onClick:s,"data-testid":`calendar-event-delete`,className:`flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-900/20`,children:[(0,N.jsx)(h,{className:`h-4 w-4`}),c(`common.delete`)]}):(0,N.jsx)(`span`,{}),(0,N.jsxs)(`div`,{className:`flex gap-3`,children:[(0,N.jsx)(`button`,{onClick:i,className:`rounded-xl px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-100 dark:text-dark-700 dark:hover:bg-dark-200`,children:c(`common.cancel`)}),(0,N.jsx)(`button`,{onClick:F,disabled:r||!u.trim(),"data-testid":`calendar-event-save`,className:`rounded-xl bg-gray-950 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,children:c(r?`common.saving`:`common.save`)})]})]})]})]})}),document.body)}var G=a(`pages:calendar`),K=()=>{let{t:e,i18n:t}=o(),n=i(),[r,a]=(0,M.useState)(`month`),[h,S]=(0,M.useState)(()=>new Date),[C,w]=(0,M.useState)([]),[T,E]=(0,M.useState)([]),[O,k]=(0,M.useState)(!1),[j,P]=(0,M.useState)(null),[F,I]=(0,M.useState)(()=>Date.now()),[R,z]=(0,M.useState)(!1),[B,V]=(0,M.useState)([]),[H,U]=(0,M.useState)(``),[W,K]=(0,M.useState)(!1),[q,J]=(0,M.useState)(null),Y=M.useRef(null),X=(0,M.useMemo)(()=>{if(r===`month`){let e=new Date(h.getFullYear(),h.getMonth(),1),t=D(e);return{from:t.getTime(),to:A(t,42).getTime()}}if(r===`day`){let e=new Date(h.getFullYear(),h.getMonth(),h.getDate());return{from:e.getTime(),to:A(e,1).getTime()}}let e=D(h);return{from:e.getTime(),to:A(e,7).getTime()}},[h,r]),[Z,ne]=(0,M.useState)(0),Q=(0,M.useCallback)(()=>ne(e=>e+1),[]);(0,M.useEffect)(()=>{v.getCalendars().then(e=>{e.success&&e.data&&V(e.data)}).catch(e=>G.error(`Failed to load calendars:`,e))},[Z]),(0,M.useEffect)(()=>{let t=!1;return v.getEvents(X.from,X.to).then(e=>{t||e.success&&e.data&&w(e.data)}).catch(n=>{t||(G.error(`Failed to load calendar events:`,n),g.error(e(`calendar.loadFailed`)))}),Promise.all([_.getOccurrences(X.from,X.to),_.getRuns({from:X.from,to:X.to}),_.getAutomations()]).then(([n,r,i])=>{if(t)return;let a=Date.now(),o=t=>i.data?.find(e=>e.id===t)?.name??e(`automations.deletedAutomation`),s=[];for(let e of n.data??[])e.at<=a||s.push({id:`automation:${e.automationId}:${e.at}`,title:e.name,startAt:e.at,allDay:!1,createdAt:e.at,updatedAt:e.at,variant:`automation`});for(let e of r.data??[])(e.status===`succeeded`||e.status===`failed`)&&s.push({id:`run:${e.id}`,title:o(e.automationId),startAt:e.scheduledFor,allDay:!1,createdAt:e.createdAt,updatedAt:e.createdAt,variant:e.status===`succeeded`?`runSucceeded`:`runFailed`,...e.sessionId?{sessionId:e.sessionId}:{}});E(s)}).catch(e=>{t||G.error(`Failed to project automations onto the calendar:`,e)}),()=>{t=!0}},[X.from,X.to,Z,e]);let re=(0,M.useMemo)(()=>[...C,...T].sort((e,t)=>e.startAt-t.startAt),[C,T]),ie=e=>{S(t=>r===`month`?new Date(t.getFullYear(),t.getMonth()+e,1):A(t,e*(r===`day`?1:7)))},$=(e,t=9)=>{P(null),I(new Date(e.getFullYear(),e.getMonth(),e.getDate(),t,0).getTime()),k(!0)},ae=t=>{if(t.variant===`runSucceeded`||t.variant===`runFailed`){t.sessionId?n(`/c/${t.sessionId}`):n(`/automations`);return}if(t.variant===`automation`){n(`/automations`);return}if(t.shared&&t.shared.permission!==`write`){g(e(`calendar.sharedReadOnly`));return}if(t.baseEventId){let e=C.find(e=>e.id===t.baseEventId);P(e??t)}else P(t);k(!0)},oe=async t=>{z(!0);try{let n=j?await v.updateEvent(j.id,t):await v.createEvent(t);n.success?(k(!1),Q()):g.error(n.error||e(`calendar.saveFailed`))}catch(t){G.error(`Failed to save calendar event:`,t),g.error(e(`calendar.saveFailed`))}finally{z(!1)}},se=async()=>{if(j){z(!0);try{let t=await v.deleteEvent(j.id);t.success?(k(!1),Q()):g.error(t.error||e(`calendar.deleteFailed`))}catch(t){G.error(`Failed to delete calendar event:`,t),g.error(e(`calendar.deleteFailed`))}finally{z(!1)}}},ce=r===`month`?x(h.getFullYear(),h.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(r===`day`?h:D(h)),le=async()=>{let t=H.trim();if(!t||W)return;K(!0);let n=await v.createCalendar({name:t}).catch(()=>void 0);K(!1),n?.success?(U(``),Q()):g.error(e(`calendar.calendarSaveFailed`))},ue=async t=>{try{let e=await v.exportIcs(t),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`calendar.ics`,r.click(),URL.revokeObjectURL(n)}catch(t){G.error(`Failed to export the calendar:`,t),g.error(e(`calendar.exportFailed`))}},de=async t=>{try{let n=await t.text(),r=await v.importIcs(n);r.success&&r.data?(g.success(e(`calendar.importResult`,{total:r.data.imported})),Q()):g.error(r.error||e(`calendar.importFailed`))}catch(t){G.error(`Failed to import the calendar:`,t),g.error(e(`calendar.importFailed`))}};return(0,N.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden`,"data-testid":`calendar-page`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-black/[0.06] px-4 py-3 dark:border-white/[0.07]`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,N.jsx)(`h1`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`calendar.title`)}),(0,N.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-dark-500`,"data-testid":`calendar-range-label`,children:ce})]}),(0,N.jsxs)(`div`,{className:`flex w-full min-w-0 flex-wrap items-center gap-2 sm:w-auto`,children:[(0,N.jsx)(`div`,{className:`flex items-center rounded-xl bg-black/[0.04] p-0.5 dark:bg-white/[0.06]`,children:[`month`,`week`,`day`].map(t=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(t),"aria-pressed":r===t,"data-testid":`calendar-view-${t}`,className:s(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,r===t?`bg-white text-gray-900 shadow-sm dark:bg-dark-200 dark:text-dark-900`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),children:e(`calendar.${t}`)},t))}),(0,N.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>ie(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),"aria-label":e(`calendar.previous`),children:(0,N.jsx)(u,{className:`h-4 w-4 rtl:rotate-180`})}),(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>S(new Date),className:`h-7 px-2 text-[12px]`,children:e(`calendar.today`)}),(0,N.jsx)(y,{size:`sm`,variant:`ghost`,onClick:()=>ie(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),"aria-label":e(`calendar.next`),children:(0,N.jsx)(d,{className:`h-4 w-4 rtl:rotate-180`})})]}),(0,N.jsxs)(y,{size:`sm`,onClick:()=>$(h),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,N.jsx)(f,{className:`h-3.5 w-3.5`}),e(`calendar.newEvent`)]})]})]}),(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-black/[0.06] px-4 py-2 dark:border-white/[0.07]`,children:[B.map(t=>(0,N.jsxs)(`span`,{className:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-black/[0.08] px-2.5 py-1 text-xs text-gray-700 dark:border-white/[0.1] dark:text-dark-800`,"data-testid":`calendar-chip`,children:[(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:t.color??`#8b8b8b`}}),(0,N.jsx)(`span`,{className:`truncate`,title:t.name,children:t.name}),t.shared?(0,N.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:e(`calendar.sharedBadge`)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{onClick:()=>J(t),className:`shrink-0 text-gray-400 hover:text-primary-500 dark:text-dark-500`,title:e(`calendar.shareCalendar`),"data-testid":`calendar-share`,children:(0,N.jsx)(c,{className:`h-3 w-3`})}),(0,N.jsx)(`button`,{onClick:()=>void v.deleteCalendar(t.id).then(Q),className:`shrink-0 text-gray-400 hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),children:(0,N.jsx)(p,{className:`h-3 w-3`})})]})]},t.id)),(0,N.jsxs)(`form`,{className:`flex min-w-0 max-w-full items-center gap-1`,onSubmit:e=>{e.preventDefault(),le()},children:[(0,N.jsx)(`input`,{type:`text`,value:H,disabled:W,onChange:e=>U(e.target.value),placeholder:e(`calendar.newCalendarPlaceholder`),"aria-label":e(`calendar.newCalendarPlaceholder`),className:`min-w-0 w-36 rounded-full border border-dashed border-black/[0.12] bg-transparent px-2.5 py-1 text-base text-gray-700 placeholder:text-gray-400 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:border-white/[0.16] dark:text-dark-800 sm:text-xs`,"data-testid":`calendar-new-calendar`}),(0,N.jsx)(y,{type:`submit`,size:`sm`,variant:`ghost`,disabled:!H.trim(),loading:W,className:`h-7 shrink-0 px-2 text-xs`,"data-testid":`calendar-create-calendar`,children:e(`common.save`)})]}),(0,N.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,N.jsx)(`input`,{ref:Y,type:`file`,accept:`.ics,text/calendar`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&de(t),e.target.value=``}}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>Y.current?.click(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-import`,children:[(0,N.jsx)(m,{className:`h-3.5 w-3.5`}),e(`calendar.importIcs`)]}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>void ue(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-export`,children:[(0,N.jsx)(l,{className:`h-3.5 w-3.5`}),e(`calendar.exportIcs`)]})]})]}),r===`month`?(0,N.jsx)(L,{year:h.getFullYear(),monthIndex:h.getMonth(),events:re,onDayClick:e=>$(e),onEventClick:ae}):(0,N.jsx)(ee,{anchor:h,events:re,dayCount:r===`day`?1:7,onDayClick:(e,t)=>$(e,t),onEventClick:ae}),q&&(0,N.jsx)(b,{resourceType:`calendar`,resourceId:q.id,resourceLabel:q.name,onClose:()=>J(null)}),(0,N.jsx)(te,{open:O,event:j,initialStartAt:F,calendars:B.filter(e=>!e.shared||e.shared.permission===`write`),saving:R,onClose:()=>k(!1),onSave:e=>void oe(e),onDelete:()=>void se()})]})};export{K as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-wiHys0m2.js";import{i as r}from"./router-vendor-HZm4FR0A.js";import{t as i}from"./logger-BR4forr_.js";import{t as a}from"./useTranslation-B9kflK9S.js";import{i as o,t as s}from"./utils-p8Gt72YP.js";import{t as c}from"./chatStore-CK5ojwft.js";import{Dt as l,Ft as u,Lt as d,Nn as f,Qn as ee,Sn as te,V as p,W as m,Xt as h,Yn as g,Zn as _,_r as v,et as y,it as ne,kt as re,lr as ie,lt as ae,n as b,ot as x,r as S,s as oe,v as C,wr as w}from"./ui-vendor-BhHHyHk3.js";import{O as T}from"./api-DPXCtanG.js";import{t as se}from"./authStore-D8fc-Hl0.js";import{t as E}from"./Button-CGMYia4g.js";import{i as D,n as O,r as k}from"./ui-D5-4niRk.js";import{t as ce}from"./teamEventStream-omPy51va.js";var A=e(t(),1),j=n(),M=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],le=180,N=({calls:e})=>{let{t}=a(),[n,r]=(0,A.useState)(!1),i=e.some(e=>e.status===`denied`);return(0,j.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,j.jsx)(_,{className:`h-3 w-3`}):(0,j.jsx)(g,{className:`h-3 w-3`}),(0,j.jsx)(S,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,j.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,j.jsxs)(`div`,{className:`rounded-lg border border-black/[0.06] px-2 py-1 dark:border-white/[0.08]`,"data-testid":`channel-tool-call`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,j.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,j.jsx)(`span`,{className:s(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,j.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap break-words font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,le)})]},e.id)),i&&(0,j.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},P=({message:e,currentUserId:t,canModerate:n,actions:r,compact:i=!1})=>{let{t:c,i18n:u}=a(),[f,p]=(0,A.useState)(!1),[m,h]=(0,A.useState)(e.content),[g,_]=(0,A.useState)(!1),v=e.authorKind===`model`,y=!v&&e.author?.userId===t&&!e.deleted,re=v?e.model??c(`channels.modelAuthor`):e.author?.username??c(`channels.unknownAuthor`);return(0,j.jsxs)(`div`,{className:s(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/[0.025] dark:hover:bg-white/[0.03]`,i&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[v&&(0,j.jsx)(ie,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,j.jsx)(`span`,{className:s(`shrink-0 text-[13px] font-semibold`,v?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:re}),(0,j.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:o(e.createdAt,u.language)}),e.editedAt&&!e.deleted&&(0,j.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:c(`channels.edited`)}),e.pinnedAt&&(0,j.jsx)(ne,{className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,j.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:c(`channels.deletedMessage`)}):f?(0,j.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,j.jsx)(`textarea`,{value:m,onChange:e=>h(e.target.value),rows:2,className:`min-w-0 flex-1 resize-none rounded-lg border border-black/[0.08] bg-transparent px-2 py-1 text-[13px] focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,m),p(!1)},className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,j.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,j.jsx)(b,{className:`h-3.5 w-3.5`})})]}):(0,j.jsxs)(j.Fragment,{children:[e.pending?(0,j.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,j.jsx)(d,{className:`h-3.5 w-3.5 animate-spin`}),c(`channels.modelThinking`)]}):e.error?(0,j.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,j.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),v&&(e.toolCalls?.length??0)>0&&(0,j.jsx)(N,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/[0.06] px-2 py-1 text-[12px] text-gray-600 hover:bg-black/[0.03] dark:border-white/[0.08] dark:text-dark-700 dark:hover:bg-white/[0.04]`,"data-testid":`channel-attachment`,children:[(0,j.jsx)(ae,{className:`h-3 w-3`}),(0,j.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:s(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/[0.08] text-gray-600 hover:bg-black/[0.03] dark:border-white/[0.1] dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!i&&(e.replyCount??0)>0&&r.onReply&&(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,j.jsx)(l,{className:`h-3 w-3`}),c(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!f&&(0,j.jsxs)(`div`,{className:`absolute -top-2.5 right-2 hidden items-center gap-0.5 rounded-lg border border-black/[0.08] bg-white px-1 py-0.5 shadow-sm group-hover:flex dark:border-white/[0.1] dark:bg-dark-50`,children:[(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`rounded p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:c(`channels.react`),"data-testid":`channel-react`,children:(0,j.jsx)(te,{className:`h-3.5 w-3.5`})}),g&&(0,j.jsx)(`div`,{className:`absolute right-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/[0.08] bg-white p-1 shadow-md dark:border-white/[0.1] dark:bg-dark-50`,children:M.map(t=>(0,j.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),_(!1)},className:`rounded p-0.5 text-sm hover:bg-black/[0.05] dark:hover:bg-white/[0.08]`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:c(`channels.reply`),"data-testid":`channel-reply`,children:(0,j.jsx)(l,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?c(`channels.unpin`):c(`channels.pin`),"data-testid":`channel-pin`,children:(0,j.jsx)(ne,{className:`h-3.5 w-3.5`})}),y&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>{h(e.content),p(!0)},className:`rounded p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:c(`channels.edit`),"data-testid":`channel-edit`,children:(0,j.jsx)(x,{className:`h-3.5 w-3.5`})}),(y||n)&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>void r.onDelete(e),className:`rounded p-1 text-gray-400 hover:text-red-500`,title:c(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,j.jsx)(C,{className:`h-3.5 w-3.5`})})]})]})},F=i(`pages:channels`),ue=e=>e.type===`dm`?(0,j.jsx)(re,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,j.jsx)(u,{className:`h-3.5 w-3.5 shrink-0`}):(0,j.jsx)(h,{className:`h-3.5 w-3.5 shrink-0`}),de=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,I=()=>{let{t:e}=a(),t=se(e=>e.user),n=c(e=>e.models),[i,o]=(0,A.useState)([]),[u,ee]=(0,A.useState)(null),[te,h]=(0,A.useState)(!1),[g,_]=(0,A.useState)(!0),[x,S]=(0,A.useState)(null),[C,D]=(0,A.useState)(null),[O,k]=(0,A.useState)([]),[M,le]=(0,A.useState)([]),[N,I]=(0,A.useState)(null),[L,R]=(0,A.useState)(null),[ge,z]=(0,A.useState)([]),[B,_e]=(0,A.useState)(``),[V,ve]=(0,A.useState)(``),[H,ye]=(0,A.useState)(!1),[U,be]=(0,A.useState)(null),[xe,Se]=(0,A.useState)(!1),[Ce,we]=(0,A.useState)(!1),[W,Te]=(0,A.useState)(``),[Ee,G]=(0,A.useState)(!1),De=(0,A.useRef)(null),Oe=(0,A.useRef)(null),[ke,Ae]=r(),K=(0,A.useMemo)(()=>i.find(e=>e.id===x)??null,[i,x]),[je,Me]=(0,A.useState)(null);x!==je&&(Me(x),D(null),R(null),I(null));let q=K?.role===`owner`,J=(0,A.useCallback)(()=>{T.listMine().then(e=>{e.success&&e.data&&o(e.data)}).catch(e=>F.error(`Failed to load channels:`,e)).finally(()=>_(!1))},[]);(0,A.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=ke.get(`channel`);Y&&x!==Y&&S(Y),(0,A.useEffect)(()=>{Y&&Ae({},{replace:!0})},[Y,Ae]);let X=(0,A.useRef)(null);(0,A.useLayoutEffect)(()=>(X.current=x?{channelId:x,requestId:0}:null,()=>{X.current=null}),[x]);let Z=(0,A.useCallback)(e=>{let t=X.current;if(!t||t.channelId!==e)return;let n=++t.requestId;T.listMessages(e,{limit:100}).then(e=>{X.current===t&&t.requestId===n&&e.success&&e.data&&D(e.data)}).catch(e=>F.error(`Failed to load messages:`,e))},[]),Ne=(0,A.useRef)(null);(0,A.useEffect)(()=>{Ne.current=L},[L]);let Pe=(0,A.useCallback)(e=>{Z(e),T.markRead(e);let t=Ne.current;t&&T.thread(t).then(e=>{e.success&&e.data&&z(e.data)})},[Z]);(0,A.useEffect)(()=>{if(!x)return;Z(x),T.markRead(x).then(J);let e=new AbortController;return ce({path:`/channels/${x}/events`,signal:e.signal,onEvent:()=>Pe(x)}),()=>e.abort()},[x,Z,J,Pe]);let Fe=C?.length??0;(0,A.useEffect)(()=>{let e=Oe.current;e&&(e.scrollTop=e.scrollHeight)},[Fe,x]),(0,A.useEffect)(()=>{x&&N&&(N===`members`?T.listMembers(x).then(e=>{e.success&&e.data&&k(e.data)}):T.listPins(x).then(e=>{e.success&&e.data&&le(e.data)}))},[x,N]),(0,A.useEffect)(()=>{L&&T.thread(L).then(e=>{e.success&&e.data&&z(e.data)})},[L]);let Ie=()=>{h(!0),T.listPublic().then(e=>{e.success&&e.data&&ee(e.data)})},Q=async t=>{if(!x||H)return;let n=B.trim();if(n||U){ye(!0);try{let r=await T.postMessage(x,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(_e(``),be(null),ve(``),Z(x),t){let e=await T.thread(t);e.success&&e.data&&z(e.data)}}else w.error(r.error||e(`channels.sendFailed`))}catch(t){F.error(`Failed to send message:`,t),w.error(e(`channels.sendFailed`))}finally{ye(!1)}}},Le=async t=>{if(x)try{let n=await T.uploadAttachment(x,t);n.success&&n.data?be({id:n.data.id,filename:n.data.filename}):w.error(n.error||e(`channels.uploadFailed`))}catch(t){F.error(`Failed to upload attachment:`,t),w.error(e(`channels.uploadFailed`))}},Re=async()=>{if(x&&W.trim()){if((await T.addMember(x,W.trim()).catch(()=>void 0))?.success){Te(``);let t=await T.listMembers(x);t.success&&t.data&&k(t.data),w.success(e(`channels.memberAdded`))}else w.error(e(`channels.memberAddFailed`))}},ze={onReply:e=>R(e.id),onEdit:async(e,t)=>{(await T.editMessage(e.id,t).catch(()=>void 0))?.success&&x&&Z(x)},onDelete:async e=>{(await T.deleteMessage(e.id).catch(()=>void 0))?.success&&x&&Z(x)},onPin:async e=>{await T.setPinned(e.id,!e.pinnedAt).catch(()=>void 0),x&&Z(x)},onReact:async(e,t,n)=>{n?await T.removeReaction(e.id,t).catch(()=>void 0):await T.addReaction(e.id,t).catch(()=>void 0),x&&Z(x)},onDownload:async(e,t)=>{try{let n=await T.downloadAttachment(e),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}catch(e){F.error(`Failed to download attachment:`,e)}}},$=ge[0];return(0,j.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,j.jsxs)(`aside`,{className:s(`flex w-64 shrink-0 flex-col border-r border-black/[0.06] dark:border-white/[0.06]`,x?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1 px-3 py-2.5`,children:[(0,j.jsx)(`h1`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`channels.title`)}),(0,j.jsx)(`button`,{type:`button`,onClick:Ie,title:e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channels-browse`,children:(0,j.jsx)(f,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>we(!0),title:e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channels-new-dm`,children:(0,j.jsx)(re,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>Se(!0),title:e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channels-new`,children:(0,j.jsx)(y,{className:`h-4 w-4`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:g?(0,j.jsx)(d,{className:`mx-auto mt-6 h-4 w-4 animate-spin text-gray-400`}):i.length===0?(0,j.jsx)(`p`,{className:`px-2 pt-6 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.empty`)}):i.map(e=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>S(e.id),className:s(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px]`,x===e.id?`bg-black/[0.05] text-gray-900 dark:bg-white/[0.08] dark:text-dark-900`:`text-gray-600 hover:bg-black/[0.03] dark:text-dark-700 dark:hover:bg-white/[0.04]`),"data-testid":`channel-item`,children:[ue(e),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:de(e)}),(e.unreadCount??0)>0&&(0,j.jsx)(`span`,{className:`rounded-full bg-primary-500 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,children:e.unreadCount})]},e.id))})]}),(0,j.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-4 py-2.5 dark:border-white/[0.06]`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>S(null),className:`rounded-md p-1 text-gray-500 hover:bg-black/[0.04] md:hidden dark:text-dark-600`,children:(0,j.jsx)(v,{className:`h-4 w-4`})}),ue(K),(0,j.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:de(K)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(N===`pins`?null:`pins`),title:e(`channels.pins`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-pins-toggle`,children:(0,j.jsx)(ne,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(N===`members`?null:`members`),title:e(`channels.members`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-members-toggle`,children:(0,j.jsx)(oe,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-settings`,children:(0,j.jsx)(p,{className:`h-4 w-4`})})]}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,j.jsx)(`div`,{ref:Oe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:C===null?(0,j.jsx)(d,{className:`mx-auto mt-6 h-4 w-4 animate-spin text-gray-400`}):C.length===0?(0,j.jsx)(`p`,{className:`pt-8 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noMessages`)}):C.map(e=>(0,j.jsx)(P,{message:e,currentUserId:t?.id,canModerate:q,actions:ze},e.id))}),(0,j.jsxs)(`div`,{className:`border-t border-black/[0.06] p-3 dark:border-white/[0.06]`,children:[U&&(0,j.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/[0.06] px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/[0.08] dark:text-dark-700`,children:[(0,j.jsx)(ae,{className:`h-3.5 w-3.5`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>be(null),className:`text-gray-400 hover:text-red-500`,children:(0,j.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,j.jsx)(`input`,{ref:De,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Le(t),e.target.value=``}}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>De.current?.click(),title:e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/[0.04] dark:text-dark-600 dark:hover:bg-white/[0.06]`,"data-testid":`channel-attach`,children:(0,j.jsx)(ae,{className:`h-4 w-4`})}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(ie,{className:s(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,j.jsxs)(`select`,{value:V,onChange:e=>ve(e.target.value),className:`max-w-[130px] rounded-md border border-black/[0.08] bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:outline-none dark:border-white/[0.1] dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,j.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,j.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,j.jsx)(`textarea`,{value:B,onChange:e=>_e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/[0.08] bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`channel-composer`}),(0,j.jsx)(E,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"data-testid":`channel-send`,children:H?(0,j.jsx)(d,{className:`h-4 w-4 animate-spin`}):(0,j.jsx)(m,{className:`h-4 w-4`})})]})]})]}),L&&(0,j.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-l border-black/[0.06] dark:border-white/[0.06]`,"data-testid":`channel-thread`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-3 py-2 dark:border-white/[0.06]`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>R(null),className:`rounded-md p-1 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,j.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:ge.map(e=>(0,j.jsx)(P,{message:e,currentUserId:t?.id,canModerate:q,actions:{...ze,onReply:void 0},compact:!0},e.id))}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/[0.06] p-2 dark:border-white/[0.06]`,children:[(0,j.jsx)(`textarea`,{value:B,onChange:e=>_e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/[0.08] bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:outline-none dark:border-white/[0.1] dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,j.jsx)(E,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),children:(0,j.jsx)(m,{className:`h-3.5 w-3.5`})})]})]}),N&&(0,j.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-black/[0.06] dark:border-white/[0.06]`,"data-testid":`channel-${N}-panel`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/[0.06] px-3 py-2 dark:border-white/[0.06]`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(N===`members`?`channels.members`:`channels.pins`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(null),className:`rounded-md p-1 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,j.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:N===`members`?(0,j.jsxs)(j.Fragment,{children:[q&&K.type===`private`&&(0,j.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,j.jsx)(`input`,{type:`text`,value:W,onChange:e=>Te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Re()},placeholder:e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/[0.08] bg-transparent px-2 py-1 text-xs focus:outline-none dark:border-white/[0.1] dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,j.jsx)(E,{size:`sm`,disabled:!W.trim(),onClick:()=>void Re(),"data-testid":`channel-invite-submit`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})})]}),O.map(n=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,j.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>void T.removeMember(K.id,n.userId).then(()=>k(e=>e.filter(e=>e.userId!==n.userId))),className:`rounded p-0.5 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),children:(0,j.jsx)(b,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,j.jsx)(E,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:()=>void T.removeMember(K.id,t?.id??``).then(()=>{S(null),J()}),"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):M.length===0?(0,j.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):M.map(e=>(0,j.jsx)(P,{message:e,currentUserId:t?.id,canModerate:q,actions:ze,compact:!0},e.id))})]})]})]}):(0,j.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 text-gray-400 dark:text-dark-500`,children:[(0,j.jsx)(l,{className:`h-8 w-8`}),(0,j.jsx)(`p`,{className:`text-sm`,children:e(`channels.selectPrompt`)})]})}),xe&&(0,j.jsx)(fe,{onClose:()=>Se(!1),onCreated:e=>{Se(!1),J(),S(e.id)}}),Ce&&(0,j.jsx)(pe,{onClose:()=>we(!1),onOpened:e=>{we(!1),J(),S(e.id)}}),te&&(0,j.jsx)(me,{channels:u,onClose:()=>h(!1),onJoined:e=>{h(!1),J(),S(e)}}),Ee&&K&&(0,j.jsx)(he,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),S(null),J()}})]})},fe=({onClose:e,onCreated:t})=>{let{t:n}=a(),[r,i]=(0,A.useState)(``),[o,s]=(0,A.useState)(`public`),[c,l]=(0,A.useState)(``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(O,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,j.jsx)(E,{size:`sm`,disabled:u||!r.trim(),onClick:()=>{d(!0),T.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):w.error(e.error||n(`channels.createFailed`))}).catch(()=>w.error(n(`channels.createFailed`))).finally(()=>d(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:D,children:n(`channels.nameLabel`)}),(0,j.jsx)(`input`,{className:k,value:r,onChange:e=>i(e.target.value),"data-testid":`create-channel-name`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:D,children:n(`channels.typeLabel`)}),(0,j.jsxs)(`select`,{className:k,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,j.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,j.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:D,children:n(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{className:k,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},pe=({onClose:e,onOpened:t})=>{let{t:n}=a(),[r,i]=(0,A.useState)(``),[o,s]=(0,A.useState)(!1),c=()=>{r.trim()&&(s(!0),T.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):w.error(e.error||n(`channels.dmFailed`))}).catch(()=>w.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,j.jsx)(O,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,j.jsx)(E,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,j.jsx)(`input`,{className:k,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},me=({channels:e,onClose:t,onJoined:n})=>{let{t:r}=a();return(0,j.jsx)(O,{titleId:`browse-channels-title`,title:r(`channels.browsePublic`),onClose:t,testId:`browse-channels-modal`,children:e===null?(0,j.jsx)(d,{className:`mx-auto h-4 w-4 animate-spin text-gray-400`}):e.length===0?(0,j.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:r(`channels.noPublic`)}):e.map(e=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/[0.06] px-3 py-2 dark:border-white/[0.08]`,"data-testid":`browse-channel-item`,children:[(0,j.jsx)(h,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,j.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:r(`channels.joined`)}):(0,j.jsx)(E,{size:`sm`,onClick:()=>void T.join(e.id).then(()=>n(e.id)),"data-testid":`browse-channel-join`,children:r(`channels.join`)})]},e.id))})},he=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:i}=a(),[o,s]=(0,A.useState)(e.name),[c,l]=(0,A.useState)(e.description??``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(O,{titleId:`channel-settings-title`,title:i(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,j.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,j.jsx)(E,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:()=>void T.delete(e.id).then(e=>{e.success&&r()}),"data-testid":`channel-delete`,children:i(`channels.delete`)}),(0,j.jsx)(E,{size:`sm`,disabled:u||!o.trim(),onClick:()=>{d(!0),T.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success&&n()}).finally(()=>d(!1))},"data-testid":`channel-settings-save`,children:i(`channels.save`)})]}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:D,children:i(`channels.nameLabel`)}),(0,j.jsx)(`input`,{className:k,value:o,onChange:e=>s(e.target.value)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{className:D,children:i(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{className:k,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{I as default};
|