libre-webui 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/backend/dist/middleware/staticAssets.d.ts.map +1 -1
  2. package/backend/dist/middleware/staticAssets.js +21 -5
  3. package/backend/dist/middleware/staticAssets.js.map +1 -1
  4. package/backend/dist/services/appearanceSettingsService.d.ts +1 -1
  5. package/backend/dist/services/appearanceSettingsService.d.ts.map +1 -1
  6. package/backend/dist/services/appearanceSettingsService.js +1 -1
  7. package/backend/dist/services/appearanceSettingsService.js.map +1 -1
  8. package/backend/dist/types/index.d.ts +1 -1
  9. package/backend/dist/types/index.d.ts.map +1 -1
  10. package/backend/package.json +1 -1
  11. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  12. package/frontend/dist/assets/index-DegYzMyw.js +70 -0
  13. package/frontend/dist/assets/{index-DtfJNUat.css → index-gKj8Y1JB.css} +1 -1
  14. package/frontend/dist/index.html +34 -22
  15. package/frontend/dist/js/{ArtifactContainer-DG-qigOa.js → ArtifactContainer-BB6A8cT5.js} +1 -1
  16. package/frontend/dist/js/{ArtifactDemoPage-Cr_bMx_v.js → ArtifactDemoPage-Bf1dW5Z3.js} +1 -1
  17. package/frontend/dist/js/{ArtifactSandboxFrame-2WyuCg4w.js → ArtifactSandboxFrame-DsZW0Axy.js} +1 -1
  18. package/frontend/dist/js/{ArtifactSlideOutPanel-zizbFUzW.js → ArtifactSlideOutPanel-Cartcixp.js} +1 -1
  19. package/frontend/dist/js/{AutomationModal-Dgk1PzNx.js → AutomationModal-BI_3nFeg.js} +1 -1
  20. package/frontend/dist/js/{AutomationsPage-CuDSh_W2.js → AutomationsPage-ChMXj4UG.js} +1 -1
  21. package/frontend/dist/js/{AvatarUpload-D_nSLum9.js → AvatarUpload-gfZ9QWR3.js} +1 -1
  22. package/frontend/dist/js/CalendarPage-Ce1ud5St.js +1 -0
  23. package/frontend/dist/js/ChannelsPage-kl8zJ2HA.js +1 -0
  24. package/frontend/dist/js/ChatPage-Bj98c6rc.js +14 -0
  25. package/frontend/dist/js/ConnectModels-CPftHmE3.js +1 -0
  26. package/frontend/dist/js/{EvaluationsPage-C6NHj9KF.js → EvaluationsPage-Cydglp6R.js} +2 -2
  27. package/frontend/dist/js/{FirstTimeSetup-BVOPC4uh.js → FirstTimeSetup-C5cc-bc9.js} +1 -1
  28. package/frontend/dist/js/GalleryPage-Dvq2GVoH.js +1 -0
  29. package/frontend/dist/js/{HomePage-B9nkyAdS.js → HomePage-zVjADRoX.js} +1 -1
  30. package/frontend/dist/js/LibreClawPage-x0Qmtcnc.js +1 -0
  31. package/frontend/dist/js/{ModelManagerModals-B4NTpNr2.js → ModelManagerModals-K1oiXMTv.js} +1 -1
  32. package/frontend/dist/js/NotesPage-BnqBv-n1.js +3 -0
  33. package/frontend/dist/js/{PasswordStrengthMeter-CNgHwIkW.js → PasswordStrengthMeter-DVFLKG_-.js} +1 -1
  34. package/frontend/dist/js/PersonasPage-DK9-SDZQ.js +13 -0
  35. package/frontend/dist/js/{PluginUsagePage-QGOo5MZj.js → PluginUsagePage-DX9uxdRr.js} +1 -1
  36. package/frontend/dist/js/RichMessageContent-BzfhfzQ4.js +1 -0
  37. package/frontend/dist/js/{RichMessageContent-Cm7kRv3f.js → RichMessageContent-XMkRvBen.js} +1 -1
  38. package/frontend/dist/js/SettingsModal-CMOwEhkG.js +19 -0
  39. package/frontend/dist/js/{ShareDialog-CeHMOTrA.js → ShareDialog-CZpU1itx.js} +1 -1
  40. package/frontend/dist/js/{SystemPage-B1bDpa9g.js → SystemPage-BVaaKTRs.js} +1 -1
  41. package/frontend/dist/js/UserManagementPage-DdpcN4-Q.js +1 -0
  42. package/frontend/dist/js/UserManagementPanel-BxAvybHj.js +1 -0
  43. package/frontend/dist/js/{WhatsNewModal-CKkWbbNI.js → WhatsNewModal-CoFCdUpf.js} +1 -1
  44. package/frontend/dist/js/WorkPage-Du6llCSU.js +7 -0
  45. package/frontend/dist/js/api-CatP45JH.js +1 -0
  46. package/frontend/dist/js/api-DQdJeQjd.js +14 -0
  47. package/frontend/dist/js/{appNavigation-B_QjduzS.js → appNavigation-DRM2Jr4r.js} +1 -1
  48. package/frontend/dist/js/appStore-BXbVcTeo.js +2 -0
  49. package/frontend/dist/js/appVersion-BUroqcki.js +1 -0
  50. package/frontend/dist/js/{ar-DFOuR5-K.js → ar-C8Izi_rT.js} +1 -1
  51. package/frontend/dist/js/{authStore-Bl7S8bPg.js → authStore-DkqtNSYP.js} +3 -3
  52. package/frontend/dist/js/authStore-bqAN5v4N.js +1 -0
  53. package/frontend/dist/js/{bn-BqS1yarc.js → bn-BJJgi-6Q.js} +1 -1
  54. package/frontend/dist/js/{chatStore-DW0LsT5X.js → chatStore-8jYk48hC.js} +3 -3
  55. package/frontend/dist/js/{config-nmgpdBW-.js → config-D4dduT3C.js} +1 -1
  56. package/frontend/dist/js/{cs-C84vh9-u.js → cs-DheVrMUl.js} +1 -1
  57. package/frontend/dist/js/{da-JlIGisjC.js → da-BLszIs3a.js} +1 -1
  58. package/frontend/dist/js/{de-ChxuvrTF.js → de-BvWdcr7T.js} +1 -1
  59. package/frontend/dist/js/{es-Dz-DZUqm.js → es-CQ8Yauda.js} +1 -1
  60. package/frontend/dist/js/{evaluationsApi-B3fvoXgD.js → evaluationsApi-CBKjxZUn.js} +1 -1
  61. package/frontend/dist/js/{fr-xjmr6UIb.js → fr-BD5h-w8z.js} +1 -1
  62. package/frontend/dist/js/{hi-CJoQdoJi.js → hi-IlRhC5IE.js} +1 -1
  63. package/frontend/dist/js/{id-ABrUdDxu.js → id-DalGMQEJ.js} +1 -1
  64. package/frontend/dist/js/{is-DnBvEw5D.js → is-DuQqmHeS.js} +1 -1
  65. package/frontend/dist/js/{it-BG1zJjTU.js → it-DDaqAdB1.js} +1 -1
  66. package/frontend/dist/js/{ja-DtZswh64.js → ja-CYCu9F9Y.js} +1 -1
  67. package/frontend/dist/js/{ko-BKhTnqlM.js → ko-P3JZPOXE.js} +1 -1
  68. package/frontend/dist/js/{messageCodeStyles-CCM1VmjP.js → messageCodeStyles-0_YpQDk4.js} +2 -2
  69. package/frontend/dist/js/{ms-BdRgdch9.js → ms-B3ZIqlUn.js} +1 -1
  70. package/frontend/dist/js/{nl-B3sv2F01.js → nl-1Qpsmmz1.js} +1 -1
  71. package/frontend/dist/js/{pl-CLAO9d2t.js → pl-ErrMri3_.js} +1 -1
  72. package/frontend/dist/js/{pt-BV3z1x11.js → pt-0T0R9AtX.js} +1 -1
  73. package/frontend/dist/js/{ru-CUSOQ4d9.js → ru-B34INyPg.js} +1 -1
  74. package/frontend/dist/js/{sv-nPJsBtOC.js → sv-BSqDwAur.js} +1 -1
  75. package/frontend/dist/js/{teamEventStream-BBNlg5Wd.js → teamEventStream-RoMYo102.js} +1 -1
  76. package/frontend/dist/js/{th-DqM7Arld.js → th-DK9M4-Iy.js} +1 -1
  77. package/frontend/dist/js/{tr-8kvS8u7c.js → tr-DUrkEwr1.js} +1 -1
  78. package/frontend/dist/js/{ui-BZOjqAJH.js → ui-UU79S5lB.js} +2 -2
  79. package/frontend/dist/js/{ui-vendor-DvJV-69N.js → ui-vendor-6y6qiSk5.js} +1 -1
  80. package/frontend/dist/js/{uk-3o761Mgn.js → uk-B5DYTi0e.js} +1 -1
  81. package/frontend/dist/js/{useChat-Bgdsccuz.js → useChat-ImXXcy0q.js} +1 -1
  82. package/frontend/dist/js/useDictation-eMIAncoT.js +1 -0
  83. package/frontend/dist/js/{vi-CT74KJ9a.js → vi-CrtPQUIM.js} +1 -1
  84. package/frontend/dist/js/workApi-BM8qVq_w.js +1 -0
  85. package/frontend/dist/js/{workApi-CqIVWrXF.js → workApi-xhF57amo.js} +2 -2
  86. package/frontend/dist/js/{zh-Bhmpu3gT.js → zh-gbOKajYe.js} +1 -1
  87. package/package.json +1 -1
  88. package/frontend/dist/assets/index-DsrrGy09.js +0 -73
  89. package/frontend/dist/js/CalendarPage-D71tcbA3.js +0 -1
  90. package/frontend/dist/js/ChannelsPage-BFkTp2cp.js +0 -1
  91. package/frontend/dist/js/ChatPage-DRdVuXt2.js +0 -14
  92. package/frontend/dist/js/ConnectModels-CKLUofc6.js +0 -1
  93. package/frontend/dist/js/GalleryPage-CkpikP93.js +0 -1
  94. package/frontend/dist/js/LibreClawPage-CKtbq8am.js +0 -1
  95. package/frontend/dist/js/NotesPage-1TG04re5.js +0 -3
  96. package/frontend/dist/js/PersonasPage-DZ4GBVkJ.js +0 -13
  97. package/frontend/dist/js/RichMessageContent-BxxKwFmA.js +0 -1
  98. package/frontend/dist/js/SettingsModal-Cl5eVfDM.js +0 -19
  99. package/frontend/dist/js/UserManagementPage-CBA-O0bM.js +0 -1
  100. package/frontend/dist/js/WorkPage-BEJ98OxR.js +0 -7
  101. package/frontend/dist/js/api-BMB8tnVI.js +0 -1
  102. package/frontend/dist/js/api-T6SWjL0K.js +0 -14
  103. package/frontend/dist/js/appStore-BonCvc8Q.js +0 -2
  104. package/frontend/dist/js/appVersion-B6Jl_X3L.js +0 -1
  105. package/frontend/dist/js/authStore-C2kI1Q9M.js +0 -1
  106. package/frontend/dist/js/useDictation-AXMLg9HP.js +0 -1
  107. package/frontend/dist/js/workApi-CUSjVilK.js +0 -1
@@ -7,7 +7,7 @@
7
7
  let mode = 'dark';
8
8
 
9
9
  try {
10
- const known = ['light', 'dark', 'amoled'];
10
+ const known = ['light', 'dark', 'amoled', 'celestial'];
11
11
  const savedState = JSON.parse(
12
12
  localStorage.getItem('libre-webui-app-state') || 'null'
13
13
  );
@@ -19,11 +19,15 @@
19
19
  );
20
20
  const savedMode = savedState?.state?.theme?.mode;
21
21
  const savedByUser = savedState?.state?.themeSource === 'user';
22
+ // The public demo lands in the celestial sky.
23
+ const demoHost = /^(demo|preview)\./.test(location.hostname);
22
24
 
23
25
  if (savedByUser && known.includes(savedMode)) {
24
26
  mode = savedMode;
25
27
  } else if (known.includes(instanceTheme?.mode)) {
26
28
  mode = instanceTheme.mode;
29
+ } else if (demoHost) {
30
+ mode = 'celestial';
27
31
  } else if (known.includes(savedMode)) {
28
32
  mode = savedMode;
29
33
  }
@@ -31,10 +35,18 @@
31
35
  // Keep the dark default when persisted state is unavailable or invalid.
32
36
  }
33
37
 
34
- document.documentElement.classList.toggle('dark', mode !== 'light');
38
+ // Celestial follows the sun; before the app computes the real
39
+ // palette, a coarse hour check picks the nearest of light or dark.
40
+ const hour = new Date().getHours();
41
+ const dark =
42
+ mode === 'celestial' ? hour < 6 || hour >= 19 : mode !== 'light';
43
+ document.documentElement.classList.toggle('dark', dark);
35
44
  document.documentElement.classList.toggle('amoled', mode === 'amoled');
36
- document.documentElement.style.colorScheme =
37
- mode === 'light' ? 'light' : 'dark';
45
+ document.documentElement.classList.toggle(
46
+ 'celestial',
47
+ mode === 'celestial'
48
+ );
49
+ document.documentElement.style.colorScheme = dark ? 'dark' : 'light';
38
50
  })();
39
51
  </script>
40
52
  <!-- The SVG mark carries its own prefers-color-scheme rule, so the favicon
@@ -77,7 +89,7 @@
77
89
  name="twitter:image:alt"
78
90
  content="Libre WebUI icon over a retro-futuristic cityscape"
79
91
  />
80
- <script type="module" crossorigin src="/assets/index-DsrrGy09.js"></script>
92
+ <script type="module" crossorigin src="/assets/index-DegYzMyw.js"></script>
81
93
  <link rel="modulepreload" crossorigin href="/js/rolldown-runtime-hePW80VL.js">
82
94
  <link rel="modulepreload" crossorigin href="/js/react-vendor-D0Ec-185.js">
83
95
  <link rel="modulepreload" crossorigin href="/js/useQuery-BKulzCS7.js">
@@ -88,32 +100,32 @@
88
100
  <link rel="modulepreload" crossorigin href="/js/useTranslation-D0mJ4NnO.js">
89
101
  <link rel="modulepreload" crossorigin href="/js/i18next-ChipS_AK.js">
90
102
  <link rel="modulepreload" crossorigin href="/js/goober.modern-BaHbaW3_.js">
91
- <link rel="modulepreload" crossorigin href="/js/ui-vendor-DvJV-69N.js">
92
- <link rel="modulepreload" crossorigin href="/js/config-nmgpdBW-.js">
93
- <link rel="modulepreload" crossorigin href="/js/workApi-CqIVWrXF.js">
94
- <link rel="modulepreload" crossorigin href="/js/api-T6SWjL0K.js">
95
- <link rel="modulepreload" crossorigin href="/js/chatStore-DW0LsT5X.js">
96
- <link rel="modulepreload" crossorigin href="/js/appStore-BonCvc8Q.js">
97
- <link rel="modulepreload" crossorigin href="/js/authStore-Bl7S8bPg.js">
103
+ <link rel="modulepreload" crossorigin href="/js/ui-vendor-6y6qiSk5.js">
104
+ <link rel="modulepreload" crossorigin href="/js/config-D4dduT3C.js">
105
+ <link rel="modulepreload" crossorigin href="/js/workApi-xhF57amo.js">
106
+ <link rel="modulepreload" crossorigin href="/js/api-DQdJeQjd.js">
107
+ <link rel="modulepreload" crossorigin href="/js/chatStore-8jYk48hC.js">
108
+ <link rel="modulepreload" crossorigin href="/js/appStore-BXbVcTeo.js">
109
+ <link rel="modulepreload" crossorigin href="/js/authStore-DkqtNSYP.js">
98
110
  <link rel="modulepreload" crossorigin href="/js/welcomePrompts-to5mv_gx.js">
99
- <link rel="modulepreload" crossorigin href="/js/messageCodeStyles-CCM1VmjP.js">
111
+ <link rel="modulepreload" crossorigin href="/js/messageCodeStyles-0_YpQDk4.js">
100
112
  <link rel="modulepreload" crossorigin href="/js/Button-BQ5JnUVj.js">
101
- <link rel="modulepreload" crossorigin href="/js/ui-BZOjqAJH.js">
102
- <link rel="modulepreload" crossorigin href="/js/AvatarUpload-D_nSLum9.js">
113
+ <link rel="modulepreload" crossorigin href="/js/ui-UU79S5lB.js">
114
+ <link rel="modulepreload" crossorigin href="/js/AvatarUpload-gfZ9QWR3.js">
103
115
  <link rel="modulepreload" crossorigin href="/js/Logo-BlcOFpac.js">
104
116
  <link rel="modulepreload" crossorigin href="/js/LogoMark-CNeQ6eO9.js">
105
- <link rel="modulepreload" crossorigin href="/js/ShareDialog-CeHMOTrA.js">
106
- <link rel="modulepreload" crossorigin href="/js/teamEventStream-BBNlg5Wd.js">
117
+ <link rel="modulepreload" crossorigin href="/js/ShareDialog-CZpU1itx.js">
118
+ <link rel="modulepreload" crossorigin href="/js/teamEventStream-RoMYo102.js">
107
119
  <link rel="modulepreload" crossorigin href="/js/workStatus-CcO9Fg41.js">
108
120
  <link rel="modulepreload" crossorigin href="/js/artifactHtml-DDmfpcB0.js">
109
- <link rel="modulepreload" crossorigin href="/js/useChat-Bgdsccuz.js">
110
- <link rel="modulepreload" crossorigin href="/js/appNavigation-B_QjduzS.js">
121
+ <link rel="modulepreload" crossorigin href="/js/useChat-ImXXcy0q.js">
122
+ <link rel="modulepreload" crossorigin href="/js/appNavigation-DRM2Jr4r.js">
111
123
  <link rel="modulepreload" crossorigin href="/js/ttsBatching-kFVEE3Ip.js">
112
124
  <link rel="modulepreload" crossorigin href="/js/webauthnClient-CPSq528Q.js">
113
125
  <link rel="modulepreload" crossorigin href="/js/TurnstileWidget-CEJst9eS.js">
114
- <link rel="modulepreload" crossorigin href="/js/PasswordStrengthMeter-CNgHwIkW.js">
115
- <link rel="modulepreload" crossorigin href="/js/appVersion-B6Jl_X3L.js">
116
- <link rel="stylesheet" crossorigin href="/assets/index-DtfJNUat.css">
126
+ <link rel="modulepreload" crossorigin href="/js/PasswordStrengthMeter-DVFLKG_-.js">
127
+ <link rel="modulepreload" crossorigin href="/js/appVersion-BUroqcki.js">
128
+ <link rel="stylesheet" crossorigin href="/assets/index-gKj8Y1JB.css">
117
129
  </head>
118
130
  <body>
119
131
  <div id="root"></div>
@@ -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{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./useTranslation-D0mJ4NnO.js";import{t as a}from"./utils-Bn0RE9_8.js";import{An as o,Cn as s,En as c,Ot as l,Xt as u,fn as d,g as f,jn as p,qn as m,vn as h}from"./ui-vendor-DvJV-69N.js";import{t as g}from"./appStore-BonCvc8Q.js";import{t as _}from"./Button-BQ5JnUVj.js";import{i as v,r as y}from"./artifactHtml-DDmfpcB0.js";import{t as b}from"./OptimizedSyntaxHighlighter-CtQ_FGCX.js";import{t as x}from"./ArtifactSandboxFrame-2WyuCg4w.js";var S=e(t(),1),C=n(),w=r(`components:artifact-renderer`),T=({artifact:e,className:t})=>{let{t:n}=i(),[r,T]=(0,S.useState)(!1),[E,D]=(0,S.useState)(`preview`),{theme:O,openArtifactPanel:k,artifactPanelOpen:A,artifactPanelArtifact:j}=g(),M=async e=>{try{await navigator.clipboard.writeText(e),T(!0),setTimeout(()=>T(!1),2e3)}catch(e){w.error(`Failed to copy:`,e)}},N=()=>{let t=e.type===`html`?y(e.content,e.title):e.content,n=new Blob([t],{type:P(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${F(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},P=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`}},F=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`}},I=()=>{switch(e.type){case`html`:return(0,C.jsx)(u,{className:`h-4 w-4`});case`react`:return(0,C.jsx)(o,{className:`h-4 w-4`});case`svg`:return(0,C.jsx)(d,{className:`h-4 w-4`});case`code`:return(0,C.jsx)(o,{className:`h-4 w-4`});default:return(0,C.jsx)(d,{className:`h-4 w-4`})}},L=()=>(0,C.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 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,C.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,C.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,C.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,C.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,C.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>D(`code`),className:`mt-4`,children:[(0,C.jsx)(p,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),R=t=>e.content.trim()?(0,C.jsx)(x,{content:e.content,title:e.title,kind:t,colorScheme:O.mode===`light`?`light`:`dark`,className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,fallback:L()}):L(),z=()=>(0,C.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:v(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg bg-white`,sandbox:``,title:e.title}),B=()=>(0,C.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,C.jsx)(b,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:O.mode!==`light`,className:`!m-0 !rounded-lg`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:O.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:e.content})}),V=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,C.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,C.jsx)(b,{language:`json`,isDark:O.mode!==`light`,className:`!m-0 !rounded-lg`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:O.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:n})})}catch{return(0,C.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,C.jsxs)(`div`,{className:`text-center`,children:[(0,C.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},H=()=>{if(E===`code`)return B();switch(e.type){case`html`:return R(`html`);case`react`:return R(`react`);case`mermaid`:return R(`mermaid`);case`svg`:return z();case`json`:return V();default:return B()}},U=()=>e.type===`html`||e.type===`svg`||e.type===`react`||e.type===`mermaid`;return A&&j!==null&&j.title.trim().toLowerCase()===e.title.trim().toLowerCase()?(0,C.jsxs)(`button`,{type:`button`,"data-testid":`artifact-collapsed-card`,onClick:()=>k(e),title:n(`artifacts.openInPanel`),className:a(`flex w-full max-w-full items-center gap-3 rounded-xl border border-gray-200 bg-white px-4 py-3 text-start shadow-sm transition-colors animate-fade-in`,`hover:bg-gray-50 dark:border-dark-200 dark:bg-dark-25 dark:hover:bg-dark-100`,t),children:[(0,C.jsx)(`div`,{className:`flex-shrink-0 text-gray-600 dark:text-gray-400`,children:I()}),(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-gray-900 dark:text-gray-100`,children:e.title}),(0,C.jsx)(`span`,{className:`flex-shrink-0 rounded-full bg-primary-50 px-2 py-1 text-xs font-medium text-primary-700 dark:bg-primary-900/20 dark:text-primary-300`,children:e.type.toUpperCase()}),(0,C.jsx)(l,{className:`h-4 w-4 flex-shrink-0 text-gray-400 dark:text-dark-500`})]}):(0,C.jsxs)(`div`,{className:a(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,C.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:I()}),(0,C.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[U()&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(_,{variant:E===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,C.jsx)(h,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(_,{variant:E===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,C.jsx)(p,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:r?(0,C.jsx)(m,{className:`h-2.5 w-2.5 text-green-500`}):(0,C.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,C.jsx)(s,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>k(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,C.jsx)(l,{className:`h-2.5 w-2.5`})})]})]}),(0,C.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,C.jsx)(`div`,{className:`flex-shrink-0`,children:I()}),(0,C.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,C.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[U()&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(_,{variant:E===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,C.jsx)(h,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,C.jsxs)(_,{variant:E===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,C.jsx)(p,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:r?(0,C.jsx)(m,{className:`h-4 w-4 text-green-500`}):(0,C.jsx)(c,{className:`h-4 w-4`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,C.jsx)(s,{className:`h-4 w-4`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>k(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,C.jsx)(l,{className:`h-4 w-4`})})]})]})]}),(0,C.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,C.jsx)(`div`,{className:`h-full overflow-auto`,children:H()})]}),(0,C.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:(0,C.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]})})]})},E=({artifacts:e,className:t})=>!e||e.length===0?null:(0,C.jsx)(`div`,{className:a(`space-y-3`,t),children:e.map(e=>(0,C.jsx)(T,{artifact:e},e.id))});export{E as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./useTranslation-D0mJ4NnO.js";import{t as a}from"./utils-Bn0RE9_8.js";import{Dn as o,Jn as s,Mn as c,Zt as l,g as u,jn as d,kt as f,pn as p,wn as m,yn as h}from"./ui-vendor-6y6qiSk5.js";import{t as g}from"./appStore-BXbVcTeo.js";import{t as _}from"./Button-BQ5JnUVj.js";import{i as v,r as y}from"./artifactHtml-DDmfpcB0.js";import{t as b}from"./OptimizedSyntaxHighlighter-CtQ_FGCX.js";import{t as x}from"./ArtifactSandboxFrame-DsZW0Axy.js";var S=e(t(),1),C=n(),w=r(`components:artifact-renderer`),T=({artifact:e,className:t})=>{let{t:n}=i(),[r,T]=(0,S.useState)(!1),[E,D]=(0,S.useState)(`preview`),{theme:O,openArtifactPanel:k,artifactPanelOpen:A,artifactPanelArtifact:j}=g(),M=async e=>{try{await navigator.clipboard.writeText(e),T(!0),setTimeout(()=>T(!1),2e3)}catch(e){w.error(`Failed to copy:`,e)}},N=()=>{let t=e.type===`html`?y(e.content,e.title):e.content,n=new Blob([t],{type:P(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${F(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},P=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`}},F=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`}},I=()=>{switch(e.type){case`html`:return(0,C.jsx)(l,{className:`h-4 w-4`});case`react`:return(0,C.jsx)(d,{className:`h-4 w-4`});case`svg`:return(0,C.jsx)(p,{className:`h-4 w-4`});case`code`:return(0,C.jsx)(d,{className:`h-4 w-4`});default:return(0,C.jsx)(p,{className:`h-4 w-4`})}},L=()=>(0,C.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 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,C.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,C.jsx)(u,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,C.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,C.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,C.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>D(`code`),className:`mt-4`,children:[(0,C.jsx)(c,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),R=t=>e.content.trim()?(0,C.jsx)(x,{content:e.content,title:e.title,kind:t,colorScheme:O.mode===`light`?`light`:`dark`,className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,fallback:L()}):L(),z=()=>(0,C.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:v(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg bg-white`,sandbox:``,title:e.title}),B=()=>(0,C.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,C.jsx)(b,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:O.mode!==`light`,className:`!m-0 !rounded-lg`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:O.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:e.content})}),V=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,C.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,C.jsx)(b,{language:`json`,isDark:O.mode!==`light`,className:`!m-0 !rounded-lg`,codeTheme:`night`,showLineNumbers:!0,backgroundColor:O.mode===`light`?void 0:`rgb(var(--color-dark-50))`,children:n})})}catch{return(0,C.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,C.jsxs)(`div`,{className:`text-center`,children:[(0,C.jsx)(u,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},H=()=>{if(E===`code`)return B();switch(e.type){case`html`:return R(`html`);case`react`:return R(`react`);case`mermaid`:return R(`mermaid`);case`svg`:return z();case`json`:return V();default:return B()}},U=()=>e.type===`html`||e.type===`svg`||e.type===`react`||e.type===`mermaid`;return A&&j!==null&&j.title.trim().toLowerCase()===e.title.trim().toLowerCase()?(0,C.jsxs)(`button`,{type:`button`,"data-testid":`artifact-collapsed-card`,onClick:()=>k(e),title:n(`artifacts.openInPanel`),className:a(`flex w-full max-w-full items-center gap-3 rounded-xl border border-gray-200 bg-white px-4 py-3 text-start shadow-sm transition-colors animate-fade-in`,`hover:bg-gray-50 dark:border-dark-200 dark:bg-dark-25 dark:hover:bg-dark-100`,t),children:[(0,C.jsx)(`div`,{className:`flex-shrink-0 text-gray-600 dark:text-gray-400`,children:I()}),(0,C.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium text-gray-900 dark:text-gray-100`,children:e.title}),(0,C.jsx)(`span`,{className:`flex-shrink-0 rounded-full bg-primary-50 px-2 py-1 text-xs font-medium text-primary-700 dark:bg-primary-900/20 dark:text-primary-300`,children:e.type.toUpperCase()}),(0,C.jsx)(f,{className:`h-4 w-4 flex-shrink-0 text-gray-400 dark:text-dark-500`})]}):(0,C.jsxs)(`div`,{className:a(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,C.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,C.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:I()}),(0,C.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,C.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[U()&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(_,{variant:E===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,C.jsx)(h,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(_,{variant:E===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,C.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:r?(0,C.jsx)(s,{className:`h-2.5 w-2.5 text-green-500`}):(0,C.jsx)(o,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,C.jsx)(m,{className:`h-2.5 w-2.5`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>k(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,C.jsx)(f,{className:`h-2.5 w-2.5`})})]})]}),(0,C.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,C.jsx)(`div`,{className:`flex-shrink-0`,children:I()}),(0,C.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,C.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[U()&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(_,{variant:E===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,C.jsx)(h,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,C.jsxs)(_,{variant:E===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>D(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,C.jsx)(c,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,C.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:r?(0,C.jsx)(s,{className:`h-4 w-4 text-green-500`}):(0,C.jsx)(o,{className:`h-4 w-4`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,C.jsx)(m,{className:`h-4 w-4`})}),(0,C.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>k(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,C.jsx)(f,{className:`h-4 w-4`})})]})]})]}),(0,C.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,C.jsx)(`div`,{className:`h-full overflow-auto`,children:H()})]}),(0,C.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:(0,C.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]})})]})},E=({artifacts:e,className:t})=>!e||e.length===0?null:(0,C.jsx)(`div`,{className:a(`space-y-3`,t),children:e.map(e=>(0,C.jsx)(T,{artifact:e},e.id))});export{E as t};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./Button-BQ5JnUVj.js";import{o as i}from"./ui-BZOjqAJH.js";import{t as a}from"./ArtifactContainer-DG-qigOa.js";var o=e(t(),1),s=n(),c=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./Button-BQ5JnUVj.js";import{o as i}from"./ui-UU79S5lB.js";import{t as a}from"./ArtifactContainer-BB6A8cT5.js";var o=e(t(),1),s=n(),c=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
2
2
  <h1 style="color: #333; font-family: Arial, sans-serif;">Welcome to Libre WebUI!</h1>
3
3
  <p style="color: #666; font-size: 16px;">This is an interactive HTML artifact.</p>
4
4
  <button
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./config-nmgpdBW-.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=`8c3aca57a001c902`,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=`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./config-D4dduT3C.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=`2ce875e136acced2`,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;
@@ -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-DnuT4jgB.js";import{t as ee}from"./useTranslation-D0mJ4NnO.js";import{t as a}from"./utils-Bn0RE9_8.js";import{T as te,t as ne}from"./chatStore-DW0LsT5X.js";import{An as o,Cn as re,En as ie,Gn as ae,Jt as oe,Wn as se,Xt as s,fn as c,g as l,jn as u,n as ce,qn as le,vn as ue}from"./ui-vendor-DvJV-69N.js";import{t as d}from"./appStore-BonCvc8Q.js";import{t as f}from"./Button-BQ5JnUVj.js";import{i as de,r as p}from"./artifactHtml-DDmfpcB0.js";import{t as m}from"./OptimizedSyntaxHighlighter-CtQ_FGCX.js";import{t as fe}from"./ArtifactSandboxFrame-2WyuCg4w.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}=d(),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)(s,{className:`h-5 w-5`});case`react`:return(0,g.jsx)(o,{className:`h-5 w-5`});case`svg`:return(0,g.jsx)(c,{className:`h-5 w-5`});case`code`:return(0,g.jsx)(o,{className:`h-5 w-5`});default:return(0,g.jsx)(c,{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)(l,{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)(u,{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)(l,{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)(oe,{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)(ae,{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)(se,{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)(ue,{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)(u,{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)(le,{className:`h-3.5 w-3.5 text-green-500`}):(0,g.jsx)(ie,{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)(re,{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-D0Ec-185.js";import{t as i}from"./logger-DnuT4jgB.js";import{t as ee}from"./useTranslation-D0mJ4NnO.js";import{t as a}from"./utils-Bn0RE9_8.js";import{T as te,t as ne}from"./chatStore-8jYk48hC.js";import{Dn as re,Gn as ie,Jn as ae,Kn as oe,Mn as o,Yt as se,Zt as s,g as c,jn as l,n as ce,pn as u,wn as le,yn as ue}from"./ui-vendor-6y6qiSk5.js";import{t as d}from"./appStore-BXbVcTeo.js";import{t as f}from"./Button-BQ5JnUVj.js";import{i as de,r as p}from"./artifactHtml-DDmfpcB0.js";import{t as m}from"./OptimizedSyntaxHighlighter-CtQ_FGCX.js";import{t as fe}from"./ArtifactSandboxFrame-DsZW0Axy.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}=d(),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)(s,{className:`h-5 w-5`});case`react`:return(0,g.jsx)(l,{className:`h-5 w-5`});case`svg`:return(0,g.jsx)(u,{className:`h-5 w-5`});case`code`:return(0,g.jsx)(l,{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)(c,{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)(o,{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)(c,{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)(se,{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)(oe,{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)(ie,{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)(ue,{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)(o,{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)(re,{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)(le,{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-D0mJ4NnO.js";import{t as a}from"./utils-Bn0RE9_8.js";import{Nn as o,Q as s,n as c,v as l,yr as u}from"./ui-vendor-DvJV-69N.js";import{t as d}from"./workApi-CqIVWrXF.js";import{T as f}from"./api-T6SWjL0K.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=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),b=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),x=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function S(e,t,n){switch(e.kind){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:y(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:b(e.dayOfWeek,t),time:y(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:y(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:x(e.month,e.dayOfMonth,t),time:y(e.hour,e.minute,t)})}}function C(e,t,n){return e.map(e=>S(e,t,n)).join(` · `)}function w(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){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 T=r(),E=[`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],D=`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`,O=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,k=e=>{switch(e){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 A({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`&&t({...e,hour:r,minute:i})},d=e.kind!==`once`&&e.kind!==`hourly`?(0,T.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:O(e.hour,e.minute),onChange:e=>u(e.target.value),className:D}):null;return(0,T.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,T.jsx)(o,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,T.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(k(e.target.value)),className:D,"data-testid":`automation-trigger-kind`,children:E.map(e=>(0,T.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`once`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.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:D}),(0,T.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:D})]}),e.kind===`hourly`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,T.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:`${D} w-16`})]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,T.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:`${D} w-16`})]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,T.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:`${D} w-16`})]})]}),e.kind===`weekly`&&(0,T.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:D,children:s.map((e,t)=>(0,T.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,T.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:`${D} w-16`})]}),e.kind===`yearly`&&(0,T.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:D,children:Array.from({length:12},(e,t)=>(0,T.jsx)(`option`,{value:t+1,children:c.format(new Date(2024,t,1))},t+1))}),d,n&&(0,T.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,T.jsx)(l,{className:`h-3.5 w-3.5`})})]})}var j=`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`,M=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,N=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function P({open:e,automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s}){return e?(0,T.jsx)(F,{automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s},t?.id??n?.name??`new`):null}function F({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??``),[b,x]=(0,_.useState)(e?.instructions??t?.instructions??``),[S,C]=(0,_.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[E,D]=(0,_.useState)(e?.model??``),[O,k]=(0,_.useState)(e?.notify??`app`),[P,F]=(0,_.useState)(e?.target??`chat`),[I,L]=(0,_.useState)(e?.workPolicyId??``),[R,z]=(0,_.useState)([]);(0,_.useEffect)(()=>{if(P!==`work`||h)return;let e=!1;return d.listPolicies().then(t=>{!e&&t.success&&Array.isArray(t.data)&&z(t.data)}).catch(()=>void 0),()=>{e=!0}},[P,h]);let[B,V]=(0,_.useState)(e?.webhookEnabled===!0),[H,U]=(0,_.useState)(null),[W,G]=(0,_.useState)(!1),K=async()=>{if(e){G(!0);try{let t=await f.rotateWebhookSecret(e.id);if(!t.success||!t.data)throw Error(t.error);V(!0),U(t.data)}catch{u.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{G(!1)}}},q=async()=>{if(e){G(!0);try{let t=await f.disableWebhook(e.id);if(!t.success)throw Error(t.error);V(!1),U(null)}catch{u.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{G(!1)}}},J=g.trim().length>0&&b.trim().length>0&&S.length>0&&S.every(w);return(0,v.createPortal)((0,T.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,T.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,"data-testid":`automation-modal`,className:`max-h-[90vh] w-full max-w-lg overflow-y-auto rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in scrollbar-thin dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,T.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,T.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,T.jsx)(c,{size:20,className:`text-gray-500`})})]}),(0,T.jsxs)(`div`,{className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-name`,className:M,children:m(`automations.form.name`)}),(0,T.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:j,maxLength:200,autoFocus:!0})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{className:M,children:m(`automations.form.triggers`)}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[S.map((e,t)=>(0,T.jsx)(A,{trigger:e,onChange:e=>C(n=>n.map((n,r)=>r===t?e:n)),onRemove:S.length>1?()=>C(e=>e.filter((e,n)=>n!==t)):void 0},t)),S.length<5&&(0,T.jsxs)(`button`,{type:`button`,onClick:()=>C(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,T.jsx)(s,{className:`h-3.5 w-3.5`}),m(`automations.form.addTrigger`)]})]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-instructions`,className:M,children:m(`automations.form.instructions`)}),(0,T.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:b,onChange:e=>x(e.target.value),placeholder:m(`automations.form.instructionsPlaceholder`),rows:5,className:j,maxLength:2e4})]}),h&&(0,T.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,T.jsxs)(`div`,{className:a(`grid grid-cols-2 gap-3`,h&&`hidden`),children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-target`,className:M,children:m(`automations.form.target`)}),(0,T.jsxs)(`select`,{id:`automation-target`,"data-testid":`automation-target`,value:P,onChange:e=>F(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:`chat`,children:m(`automations.form.targetChat`)}),(0,T.jsx)(`option`,{value:`work`,children:m(`automations.form.targetWork`)})]})]}),P===`work`&&R.length>0&&(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-work-policy`,className:M,children:m(`automations.form.workPolicy`)}),(0,T.jsxs)(`select`,{id:`automation-work-policy`,"data-testid":`automation-work-policy`,value:I,onChange:e=>L(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:``,children:m(`automations.form.workPolicyDefault`)}),R.map(e=>(0,T.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,T.jsxs)(`div`,{className:a(h&&`hidden`),children:[(0,T.jsx)(`label`,{htmlFor:`automation-model`,className:M,children:m(`automations.form.model`)}),(0,T.jsxs)(`select`,{id:`automation-model`,value:E,onChange:e=>D(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:``,children:m(`automations.form.modelAuto`)}),r.map(e=>(0,T.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-notify`,className:M,children:m(`automations.form.notification`)}),(0,T.jsxs)(`select`,{id:`automation-notify`,value:O,onChange:e=>k(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:`app`,children:m(`automations.form.notifyApp`)}),(0,T.jsx)(`option`,{value:`off`,children:m(`automations.form.notifyOff`)})]})]})]}),e&&(0,T.jsxs)(`div`,{"data-testid":`automation-webhook`,className:`rounded-xl border border-gray-200 p-3 dark:border-dark-300`,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.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`automations.webhook.title`,{defaultValue:`Webhook trigger`})}),(0,T.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-600`,children:B?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,T.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,T.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-rotate`,onClick:()=>void K(),disabled:W,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:B?m(`automations.webhook.rotate`,{defaultValue:`Rotate secret`}):m(`automations.webhook.enable`,{defaultValue:`Enable`})}),B&&(0,T.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-disable`,onClick:()=>void q(),disabled:W,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`})})]})]}),H&&(0,T.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,T.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,T.jsxs)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:[`POST `,H.path]}),(0,T.jsx)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:H.secret})]})]}),(0,T.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,T.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,T.jsx)(`button`,{onClick:()=>{if(!J)return;if(h){p({name:g.trim(),instructions:b.trim(),triggers:S,notify:O,target:`work`,workTaskId:n??e?.workTaskId});return}let t=r.find(e=>e.name===E);p({name:g.trim(),instructions:b.trim(),triggers:S,...t?{provider:N(t),model:t.name}:{},notify:O,target:P,...P===`work`&&I?{workPolicyId:I}:{}})},disabled:o||!J,"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{C as n,P 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-D0Ec-185.js";import{t as i}from"./useTranslation-D0mJ4NnO.js";import{t as a}from"./utils-Bn0RE9_8.js";import{$ as o,Pn as s,br as c,n as l,v as u}from"./ui-vendor-6y6qiSk5.js";import{t as d}from"./workApi-xhF57amo.js";import{T as f}from"./api-DQdJeQjd.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=(e,t,n)=>new Intl.DateTimeFormat(n,{hour:`numeric`,minute:`2-digit`}).format(new Date(2024,0,1,e,t)),b=(e,t)=>new Intl.DateTimeFormat(t,{weekday:`long`}).format(new Date(2024,0,7+e)),x=(e,t,n)=>new Intl.DateTimeFormat(n,{month:`long`,day:`numeric`}).format(new Date(2024,e-1,t));function S(e,t,n){switch(e.kind){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:y(e.hour,e.minute,t)});case`weekly`:return n(`automations.trigger.weekly`,{day:b(e.dayOfWeek,t),time:y(e.hour,e.minute,t)});case`monthly`:return n(`automations.trigger.monthly`,{day:e.dayOfMonth,time:y(e.hour,e.minute,t)});case`yearly`:return n(`automations.trigger.yearly`,{date:x(e.month,e.dayOfMonth,t),time:y(e.hour,e.minute,t)})}}function C(e,t,n){return e.map(e=>S(e,t,n)).join(` · `)}function w(e){let t=(e,t,n)=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=t&&e<=n;switch(e.kind){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 T=r(),E=[`once`,`hourly`,`daily`,`weekly`,`monthly`,`yearly`],D=`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`,O=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`,k=e=>{switch(e){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 A({trigger:e,onChange:t,onRemove:n}){let{t:r,i18n:a}=i(),o=m(a.language,`short`),c=new Intl.DateTimeFormat(a.language,{month:`long`}),l=n=>{let[r,i]=(n||`00:00`).split(`:`).map(Number);e.kind!==`hourly`&&e.kind!==`once`&&t({...e,hour:r,minute:i})},d=e.kind!==`once`&&e.kind!==`hourly`?(0,T.jsx)(`input`,{type:`time`,"aria-label":r(`automations.form.time`),value:O(e.hour,e.minute),onChange:e=>l(e.target.value),className:D}):null;return(0,T.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,T.jsx)(s,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,T.jsx)(`select`,{"aria-label":r(`automations.form.frequency`),value:e.kind,onChange:e=>t(k(e.target.value)),className:D,"data-testid":`automation-trigger-kind`,children:E.map(e=>(0,T.jsx)(`option`,{value:e,children:r(`automations.kind.${e}`)},e))}),e.kind===`once`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.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:D}),(0,T.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:D})]}),e.kind===`hourly`&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.minute`),(0,T.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:`${D} w-16`})]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.fromHour`),(0,T.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:`${D} w-16`})]}),(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.toHour`),(0,T.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:`${D} w-16`})]})]}),e.kind===`weekly`&&(0,T.jsx)(`select`,{"aria-label":r(`automations.form.weekday`),value:e.dayOfWeek,onChange:n=>t({...e,dayOfWeek:Number(n.target.value)}),className:D,children:o.map((e,t)=>(0,T.jsx)(`option`,{value:t,children:e},e))}),(e.kind===`monthly`||e.kind===`yearly`)&&(0,T.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[r(`automations.form.dayOfMonth`),(0,T.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:`${D} w-16`})]}),e.kind===`yearly`&&(0,T.jsx)(`select`,{"aria-label":r(`automations.form.month`),value:e.month,onChange:n=>t({...e,month:Number(n.target.value)}),className:D,children:Array.from({length:12},(e,t)=>(0,T.jsx)(`option`,{value:t+1,children:c.format(new Date(2024,t,1))},t+1))}),d,n&&(0,T.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,T.jsx)(u,{className:`h-3.5 w-3.5`})})]})}var j=`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`,M=`mb-1 block text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500`,N=e=>e.isPlugin&&e.pluginId?`plugin:${e.pluginId}`:e.isAgent&&e.agentId?`agent:${e.agentId}`:`ollama`;function P({open:e,automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s}){return e?(0,T.jsx)(F,{automation:t,initial:n,fixedWorkTaskId:r,models:i,saving:a,onClose:o,onSave:s},t?.id??n?.name??`new`):null}function F({automation:e,initial:t,fixedWorkTaskId:n,models:r,saving:s,onClose:u,onSave:p}){let{t:m}=i(),h=!!(n??e?.workTaskId),[g,y]=(0,_.useState)(e?.name??t?.name??``),[b,x]=(0,_.useState)(e?.instructions??t?.instructions??``),[S,C]=(0,_.useState)(e?.triggers??t?.triggers??[{kind:`daily`,hour:8,minute:0}]),[E,D]=(0,_.useState)(e?.model??``),[O,k]=(0,_.useState)(e?.notify??`app`),[P,F]=(0,_.useState)(e?.target??`chat`),[I,L]=(0,_.useState)(e?.workPolicyId??``),[R,z]=(0,_.useState)([]);(0,_.useEffect)(()=>{if(P!==`work`||h)return;let e=!1;return d.listPolicies().then(t=>{!e&&t.success&&Array.isArray(t.data)&&z(t.data)}).catch(()=>void 0),()=>{e=!0}},[P,h]);let[B,V]=(0,_.useState)(e?.webhookEnabled===!0),[H,U]=(0,_.useState)(null),[W,G]=(0,_.useState)(!1),K=async()=>{if(e){G(!0);try{let t=await f.rotateWebhookSecret(e.id);if(!t.success||!t.data)throw Error(t.error);V(!0),U(t.data)}catch{c.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{G(!1)}}},q=async()=>{if(e){G(!0);try{let t=await f.disableWebhook(e.id);if(!t.success)throw Error(t.error);V(!1),U(null)}catch{c.error(m(`automations.webhook.failed`,{defaultValue:`Could not update the webhook.`}))}finally{G(!1)}}},J=g.trim().length>0&&b.trim().length>0&&S.length>0&&S.every(w);return(0,v.createPortal)((0,T.jsx)(`div`,{className:`fixed inset-0 z-[2147483647] flex items-center justify-center bg-gray-950/55 p-4 backdrop-blur-md`,onClick:u,children:(0,T.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`automation-modal-title`,"data-testid":`automation-modal`,className:`max-h-[90vh] w-full max-w-lg overflow-y-auto rounded-3xl border border-black/[0.07] bg-white p-6 shadow-[0_24px_80px_rgba(0,0,0,0.24)] animate-scale-in scrollbar-thin dark:border-white/[0.08] dark:bg-dark-25`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`mb-4 flex items-center justify-between`,children:[(0,T.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,T.jsx)(`button`,{onClick:u,"aria-label":m(`common.close`),className:`rounded-xl p-2 transition-colors hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,T.jsx)(l,{size:20,className:`text-gray-500`})})]}),(0,T.jsxs)(`div`,{className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-name`,className:M,children:m(`automations.form.name`)}),(0,T.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:j,maxLength:200,autoFocus:!0})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{className:M,children:m(`automations.form.triggers`)}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[S.map((e,t)=>(0,T.jsx)(A,{trigger:e,onChange:e=>C(n=>n.map((n,r)=>r===t?e:n)),onRemove:S.length>1?()=>C(e=>e.filter((e,n)=>n!==t)):void 0},t)),S.length<5&&(0,T.jsxs)(`button`,{type:`button`,onClick:()=>C(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,T.jsx)(o,{className:`h-3.5 w-3.5`}),m(`automations.form.addTrigger`)]})]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-instructions`,className:M,children:m(`automations.form.instructions`)}),(0,T.jsx)(`textarea`,{id:`automation-instructions`,"data-testid":`automation-instructions`,value:b,onChange:e=>x(e.target.value),placeholder:m(`automations.form.instructionsPlaceholder`),rows:5,className:j,maxLength:2e4})]}),h&&(0,T.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,T.jsxs)(`div`,{className:a(`grid grid-cols-2 gap-3`,h&&`hidden`),children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-target`,className:M,children:m(`automations.form.target`)}),(0,T.jsxs)(`select`,{id:`automation-target`,"data-testid":`automation-target`,value:P,onChange:e=>F(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:`chat`,children:m(`automations.form.targetChat`)}),(0,T.jsx)(`option`,{value:`work`,children:m(`automations.form.targetWork`)})]})]}),P===`work`&&R.length>0&&(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-work-policy`,className:M,children:m(`automations.form.workPolicy`)}),(0,T.jsxs)(`select`,{id:`automation-work-policy`,"data-testid":`automation-work-policy`,value:I,onChange:e=>L(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:``,children:m(`automations.form.workPolicyDefault`)}),R.map(e=>(0,T.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,T.jsxs)(`div`,{className:a(h&&`hidden`),children:[(0,T.jsx)(`label`,{htmlFor:`automation-model`,className:M,children:m(`automations.form.model`)}),(0,T.jsxs)(`select`,{id:`automation-model`,value:E,onChange:e=>D(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:``,children:m(`automations.form.modelAuto`)}),r.map(e=>(0,T.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`label`,{htmlFor:`automation-notify`,className:M,children:m(`automations.form.notification`)}),(0,T.jsxs)(`select`,{id:`automation-notify`,value:O,onChange:e=>k(e.target.value),className:j,children:[(0,T.jsx)(`option`,{value:`app`,children:m(`automations.form.notifyApp`)}),(0,T.jsx)(`option`,{value:`off`,children:m(`automations.form.notifyOff`)})]})]})]}),e&&(0,T.jsxs)(`div`,{"data-testid":`automation-webhook`,className:`rounded-xl border border-gray-200 p-3 dark:border-dark-300`,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.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:m(`automations.webhook.title`,{defaultValue:`Webhook trigger`})}),(0,T.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-600`,children:B?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,T.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,T.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-rotate`,onClick:()=>void K(),disabled:W,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:B?m(`automations.webhook.rotate`,{defaultValue:`Rotate secret`}):m(`automations.webhook.enable`,{defaultValue:`Enable`})}),B&&(0,T.jsx)(`button`,{type:`button`,"data-testid":`automation-webhook-disable`,onClick:()=>void q(),disabled:W,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`})})]})]}),H&&(0,T.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,T.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,T.jsxs)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:[`POST `,H.path]}),(0,T.jsx)(`code`,{dir:`ltr`,className:`block break-all font-mono text-xs text-gray-800 dark:text-gray-200`,children:H.secret})]})]}),(0,T.jsxs)(`div`,{className:`flex justify-end gap-3 border-t border-gray-200 pt-4 dark:border-dark-300`,children:[(0,T.jsx)(`button`,{onClick:u,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,T.jsx)(`button`,{onClick:()=>{if(!J)return;if(h){p({name:g.trim(),instructions:b.trim(),triggers:S,notify:O,target:`work`,workTaskId:n??e?.workTaskId});return}let t=r.find(e=>e.name===E);p({name:g.trim(),instructions:b.trim(),triggers:S,...t?{provider:N(t),model:t.name}:{},notify:O,target:P,...P===`work`&&I?{workPolicyId:I}:{}})},disabled:s||!J,"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(s?`common.saving`:`common.save`)})]})]})]})}),document.body)}export{C as n,P 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-CMbYTGdh.js";import{t as i}from"./logger-DnuT4jgB.js";import{t as a}from"./useTranslation-D0mJ4NnO.js";import{r as o,t as s}from"./utils-Bn0RE9_8.js";import{t as c}from"./chatStore-DW0LsT5X.js";import{In as l,J as u,Ln as d,Nt as f,Q as p,Rn as m,Sn as h,it as ee,ot as te,t as g,tt as _,v,yr as y}from"./ui-vendor-DvJV-69N.js";import{T as b}from"./api-T6SWjL0K.js";import{t as x}from"./Button-BQ5JnUVj.js";import"./ui-BZOjqAJH.js";import{n as S,t as C}from"./AutomationModal-Dgk1PzNx.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),[Z,ne]=(0,w.useState)(0),Q=(0,w.useCallback)(()=>ne(e=>e+1),[]);(0,w.useEffect)(()=>{let t=!1;return Promise.all([b.getAutomations(),b.getRuns(),b.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),y.error(e(`automations.loadFailed`)))}).finally(()=>{t||B(!1)}),()=>{t=!0}},[Z,e]),(0,w.useEffect)(()=>{i.length===0&&k({quiet:!0})},[i.length,k]),(0,w.useEffect)(()=>{j===`runs`&&b.markRunsSeen().then(()=>b.getRunsSummary()).then(e=>{e.success&&e.data&&R(e.data)}).catch(()=>void 0)},[j,F.length]);let re=()=>{W(null),K(null),H(!0)},ie=t=>{W(null),K({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),H(!0)},ae=e=>{W(e),K(null),X(null),H(!0)},oe=async t=>{J(!0);try{let n=U?await b.updateAutomation(U.id,t):await b.createAutomation(t);n.success?(H(!1),Q()):y.error(n.error||e(`automations.saveFailed`))}catch(t){O.error(`Failed to save automation:`,t),y.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{X(null);try{n===`pause`?await b.pauseAutomation(t.id):n===`resume`?await b.resumeAutomation(t.id):n===`run`?(await b.runAutomationNow(t.id),y.success(e(`automations.runQueued`))):await b.deleteAutomation(t.id),Q()}catch(t){O.error(`Automation ${n} failed:`,t),y.error(e(`automations.actionFailed`))}},se=e=>e.status===`succeeded`?(0,T.jsx)(m,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,T.jsx)(l,{className:`h-4 w-4 text-red-500`}):(0,T.jsx)(f,{className:`h-4 w-4 animate-spin text-gray-400`}),ce=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)(x,{size:`sm`,onClick:re,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,T.jsx)(p,{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:[S(n.triggers,t.language,e),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)(h,{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:ee,label:e(`common.edit`),onClick:()=>ae(n)}),n.status===`active`?(0,T.jsx)(A,{icon:te,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,T.jsx)(A,{icon:_,label:e(`automations.resume`),onClick:()=>$(n,`resume`)}),(0,T.jsx)(A,{icon:u,label:e(`automations.runNow`),onClick:()=>$(n,`run`)}),(0,T.jsx)(A,{icon:v,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:()=>ie(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:S(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)(d,{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:[se(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:ce(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 oe(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-D0Ec-185.js";import{d as r}from"./router-vendor-CMbYTGdh.js";import{t as i}from"./logger-DnuT4jgB.js";import{t as a}from"./useTranslation-D0mJ4NnO.js";import{r as o,t as s}from"./utils-Bn0RE9_8.js";import{t as c}from"./chatStore-8jYk48hC.js";import{$ as l,Cn as ee,Ln as u,Pt as d,Rn as f,Y as p,at as m,br as h,nt as te,st as g,t as _,v,zn as y}from"./ui-vendor-6y6qiSk5.js";import{T as b}from"./api-DQdJeQjd.js";import{t as x}from"./Button-BQ5JnUVj.js";import"./ui-UU79S5lB.js";import{n as S,t as C}from"./AutomationModal-BI_3nFeg.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),[Z,ne]=(0,w.useState)(0),Q=(0,w.useCallback)(()=>ne(e=>e+1),[]);(0,w.useEffect)(()=>{let t=!1;return Promise.all([b.getAutomations(),b.getRuns(),b.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),h.error(e(`automations.loadFailed`)))}).finally(()=>{t||B(!1)}),()=>{t=!0}},[Z,e]),(0,w.useEffect)(()=>{i.length===0&&k({quiet:!0})},[i.length,k]),(0,w.useEffect)(()=>{j===`runs`&&b.markRunsSeen().then(()=>b.getRunsSummary()).then(e=>{e.success&&e.data&&R(e.data)}).catch(()=>void 0)},[j,F.length]);let re=()=>{W(null),K(null),H(!0)},ie=t=>{W(null),K({name:e(`automations.templates.${t.id}.name`),instructions:t.instructions,triggers:t.triggers}),H(!0)},ae=e=>{W(e),K(null),X(null),H(!0)},oe=async t=>{J(!0);try{let n=U?await b.updateAutomation(U.id,t):await b.createAutomation(t);n.success?(H(!1),Q()):h.error(n.error||e(`automations.saveFailed`))}catch(t){O.error(`Failed to save automation:`,t),h.error(e(`automations.saveFailed`))}finally{J(!1)}},$=async(t,n)=>{X(null);try{n===`pause`?await b.pauseAutomation(t.id):n===`resume`?await b.resumeAutomation(t.id):n===`run`?(await b.runAutomationNow(t.id),h.success(e(`automations.runQueued`))):await b.deleteAutomation(t.id),Q()}catch(t){O.error(`Automation ${n} failed:`,t),h.error(e(`automations.actionFailed`))}},se=e=>e.status===`succeeded`?(0,T.jsx)(y,{className:`h-4 w-4 text-emerald-500`}):e.status===`failed`?(0,T.jsx)(u,{className:`h-4 w-4 text-red-500`}):(0,T.jsx)(d,{className:`h-4 w-4 animate-spin text-gray-400`}),ce=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)(x,{size:`sm`,onClick:re,"data-testid":`automation-new`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,T.jsx)(l,{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)(_,{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:[S(n.triggers,t.language,e),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)(ee,{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:()=>ae(n)}),n.status===`active`?(0,T.jsx)(A,{icon:g,label:e(`automations.pause`),onClick:()=>$(n,`pause`)}):(0,T.jsx)(A,{icon:te,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:v,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:()=>ie(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:S(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)(f,{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:[se(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:ce(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 oe(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-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./useTranslation-D0mJ4NnO.js";import{c as a,n as o,p as s,yr as c}from"./ui-vendor-DvJV-69N.js";import{t as l}from"./Button-BQ5JnUVj.js";import"./ui-BZOjqAJH.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
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./logger-DnuT4jgB.js";import{t as i}from"./useTranslation-D0mJ4NnO.js";import{br as a,c as o,n as s,p as c}from"./ui-vendor-6y6qiSk5.js";import{t as l}from"./Button-BQ5JnUVj.js";import"./ui-UU79S5lB.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/`)){a.error(r(`user.avatar.invalidFile`));return}if(e.size>2097152){a.error(r(`user.avatar.fileTooLarge`));return}h(!0);try{let n=new FileReader;n.onload=e=>{let n=e.target?.result;t(n),a.success(r(`user.avatar.uploaded`))},n.onerror=()=>{a.error(r(`user.avatar.readFailed`))},n.readAsDataURL(e)}catch(e){f.error(`Failed to upload avatar:`,e),a.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(``),a.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)(o,{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)(s,{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)(c,{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)(c,{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};
@@ -0,0 +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-CMbYTGdh.js";import{t as a}from"./logger-DnuT4jgB.js";import{t as o}from"./useTranslation-D0mJ4NnO.js";import{t as s}from"./utils-Bn0RE9_8.js";import{$ as c,Gn as l,Kn as u,br as d,n as f,p,v as m,wn as h,z as g}from"./ui-vendor-6y6qiSk5.js";import{O as _,T as v}from"./api-DQdJeQjd.js";import{t as y}from"./Button-BQ5JnUVj.js";import"./ui-UU79S5lB.js";import{t as b}from"./ShareDialog-CZpU1itx.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`?`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??``),[p,h]=(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:p.trim()?p.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)(f,{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:p,onChange:e=>h(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)(m,{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`),[m,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)(null),q=M.useRef(null),J=(0,M.useMemo)(()=>{if(r===`month`){let e=new Date(m.getFullYear(),m.getMonth(),1),t=D(e);return{from:t.getTime(),to:A(t,42).getTime()}}if(r===`day`){let e=new Date(m.getFullYear(),m.getMonth(),m.getDate());return{from:e.getTime(),to:A(e,1).getTime()}}let e=D(m);return{from:e.getTime(),to:A(e,7).getTime()}},[m,r]),[Y,ne]=(0,M.useState)(0),X=(0,M.useCallback)(()=>ne(e=>e+1),[]);(0,M.useEffect)(()=>{_.getCalendars().then(e=>{e.success&&e.data&&V(e.data)}).catch(e=>G.error(`Failed to load calendars:`,e))},[Y]),(0,M.useEffect)(()=>{let t=!1;return _.getEvents(J.from,J.to).then(e=>{t||e.success&&e.data&&w(e.data)}).catch(n=>{t||(G.error(`Failed to load calendar events:`,n),d.error(e(`calendar.loadFailed`)))}),Promise.all([v.getOccurrences(J.from,J.to),v.getRuns({from:J.from,to:J.to}),v.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}},[J.from,J.to,Y,e]);let Z=(0,M.useMemo)(()=>[...C,...T].sort((e,t)=>e.startAt-t.startAt),[C,T]),Q=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)},re=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`){d(e(`calendar.sharedReadOnly`));return}if(t.baseEventId){let e=C.find(e=>e.id===t.baseEventId);P(e??t)}else P(t);k(!0)},ie=async t=>{z(!0);try{let n=j?await _.updateEvent(j.id,t):await _.createEvent(t);n.success?(k(!1),X()):d.error(n.error||e(`calendar.saveFailed`))}catch(t){G.error(`Failed to save calendar event:`,t),d.error(e(`calendar.saveFailed`))}finally{z(!1)}},ae=async()=>{if(j){z(!0);try{let t=await _.deleteEvent(j.id);t.success?(k(!1),X()):d.error(t.error||e(`calendar.deleteFailed`))}catch(t){G.error(`Failed to delete calendar event:`,t),d.error(e(`calendar.deleteFailed`))}finally{z(!1)}}},oe=r===`month`?x(m.getFullYear(),m.getMonth(),t.language):new Intl.DateTimeFormat(t.language,{month:`long`,day:`numeric`,year:`numeric`}).format(r===`day`?m:D(m)),se=async()=>{let t=H.trim();t&&((await _.createCalendar({name:t}).catch(()=>void 0))?.success?(U(``),X()):d.error(e(`calendar.calendarSaveFailed`)))},ce=async t=>{try{let e=await _.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),d.error(e(`calendar.exportFailed`))}},le=async t=>{try{let n=await t.text(),r=await _.importIcs(n);r.success&&r.data?(d.success(e(`calendar.importResult`,{total:r.data.imported})),X()):d.error(r.error||e(`calendar.importFailed`))}catch(t){G.error(`Failed to import the calendar:`,t),d.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 items-center gap-2`,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:oe})]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,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`,{onClick:()=>a(t),"data-testid":`calendar-view-${t}`,className:s(`rounded-[10px] px-2.5 py-1 text-[12px] font-medium transition-colors`,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:()=>Q(-1),className:`h-7 w-7 p-0`,title:e(`calendar.previous`),children:(0,N.jsx)(u,{className:`h-4 w-4`})}),(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:()=>Q(1),className:`h-7 w-7 p-0`,title:e(`calendar.next`),children:(0,N.jsx)(l,{className:`h-4 w-4`})})]}),(0,N.jsxs)(y,{size:`sm`,onClick:()=>$(m),"data-testid":`calendar-new-event`,className:`h-7 gap-1 px-2.5 text-[12px]`,children:[(0,N.jsx)(c,{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 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 rounded-full`,style:{backgroundColor:t.color??`#8b8b8b`}}),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:()=>K(t),className:`text-gray-400 hover:text-primary-500 dark:text-dark-500`,title:e(`calendar.shareCalendar`),"data-testid":`calendar-share`,children:(0,N.jsx)(g,{className:`h-3 w-3`})}),(0,N.jsx)(`button`,{onClick:()=>void _.deleteCalendar(t.id).then(X),className:`text-gray-400 hover:text-red-500 dark:text-dark-500`,title:e(`common.delete`),children:(0,N.jsx)(f,{className:`h-3 w-3`})})]})]},t.id)),(0,N.jsx)(`input`,{type:`text`,value:H,onChange:e=>U(e.target.value),onKeyDown:e=>{e.key===`Enter`&&se()},placeholder:e(`calendar.newCalendarPlaceholder`),className:`w-36 rounded-full border border-dashed border-black/[0.12] bg-transparent px-2.5 py-1 text-xs text-gray-700 placeholder:text-gray-400 focus:outline-none dark:border-white/[0.16] dark:text-dark-800`,"data-testid":`calendar-new-calendar`}),(0,N.jsxs)(`div`,{className:`ms-auto flex items-center gap-1`,children:[(0,N.jsx)(`input`,{ref:q,type:`file`,accept:`.ics,text/calendar`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&le(t),e.target.value=``}}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>q.current?.click(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-import`,children:[(0,N.jsx)(p,{className:`h-3.5 w-3.5`}),e(`calendar.importIcs`)]}),(0,N.jsxs)(y,{size:`sm`,variant:`ghost`,onClick:()=>void ce(),className:`h-7 gap-1 px-2 text-[12px]`,"data-testid":`calendar-export`,children:[(0,N.jsx)(h,{className:`h-3.5 w-3.5`}),e(`calendar.exportIcs`)]})]})]}),r===`month`?(0,N.jsx)(L,{year:m.getFullYear(),monthIndex:m.getMonth(),events:Z,onDayClick:e=>$(e),onEventClick:re}):(0,N.jsx)(ee,{anchor:m,events:Z,dayCount:r===`day`?1:7,onDayClick:(e,t)=>$(e,t),onEventClick:re}),W&&(0,N.jsx)(b,{resourceType:`calendar`,resourceId:W.id,resourceLabel:W.name,onClose:()=>K(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 ie(e),onDelete:()=>void ae()})]})};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-D0Ec-185.js";import{i as r}from"./router-vendor-CMbYTGdh.js";import{t as i}from"./logger-DnuT4jgB.js";import{t as a}from"./useTranslation-D0mJ4NnO.js";import{r as o,t as s}from"./utils-Bn0RE9_8.js";import{t as c}from"./chatStore-8jYk48hC.js";import{$ as l,Dt as u,Et as d,Jn as ee,Kt as f,Mt as p,Pt as m,U as h,V as te,ar as ne,at as g,br as _,ct as v,kn as y,n as b,pr as x,rt as S,s as re,v as ie,vn as ae}from"./ui-vendor-6y6qiSk5.js";import{D as C}from"./api-DQdJeQjd.js";import{t as oe}from"./authStore-DkqtNSYP.js";import{t as w}from"./Button-BQ5JnUVj.js";import{i as T,n as E,r as D}from"./ui-UU79S5lB.js";import{t as se}from"./teamEventStream-RoMYo102.js";var O=e(t(),1),k=n(),ce=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],le=({message:e,currentUserId:t,canModerate:n,actions:r,compact:i=!1})=>{let{t:c,i18n:l}=a(),[u,f]=(0,O.useState)(!1),[p,h]=(0,O.useState)(e.content),[te,_]=(0,O.useState)(!1),y=e.authorKind===`model`,x=!y&&e.author?.userId===t&&!e.deleted,re=y?e.model??c(`channels.modelAuthor`):e.author?.username??c(`channels.unknownAuthor`);return(0,k.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,k.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[y&&(0,k.jsx)(ne,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,k.jsx)(`span`,{className:s(`shrink-0 text-[13px] font-semibold`,y?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:re}),(0,k.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:o(e.createdAt,l.language)}),e.editedAt&&!e.deleted&&(0,k.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:c(`channels.edited`)}),e.pinnedAt&&(0,k.jsx)(S,{className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,k.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:c(`channels.deletedMessage`)}):u?(0,k.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,k.jsx)(`textarea`,{value:p,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,k.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,p),f(!1)},className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,k.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,k.jsx)(b,{className:`h-3.5 w-3.5`})})]}):(0,k.jsxs)(k.Fragment,{children:[e.pending?(0,k.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,k.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}),c(`channels.modelThinking`)]}):e.error?(0,k.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,k.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),(e.attachments?.length??0)>0&&(0,k.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,k.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,k.jsx)(v,{className:`h-3 w-3`}),(0,k.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,k.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,k.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,k.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,k.jsx)(d,{className:`h-3 w-3`}),c(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!u&&(0,k.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,k.jsxs)(`div`,{className:`relative`,children:[(0,k.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,k.jsx)(ae,{className:`h-3.5 w-3.5`})}),te&&(0,k.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:ce.map(t=>(0,k.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,k.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,k.jsx)(d,{className:`h-3.5 w-3.5`})}),(0,k.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,k.jsx)(S,{className:`h-3.5 w-3.5`})}),x&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>{h(e.content),f(!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,k.jsx)(g,{className:`h-3.5 w-3.5`})}),(x||n)&&(0,k.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,k.jsx)(ie,{className:`h-3.5 w-3.5`})})]})]})},A=i(`pages:channels`),ue=e=>e.type===`dm`?(0,k.jsx)(u,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,k.jsx)(p,{className:`h-3.5 w-3.5 shrink-0`}):(0,k.jsx)(f,{className:`h-3.5 w-3.5 shrink-0`}),de=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,fe=()=>{let{t:e}=a(),t=oe(e=>e.user),n=c(e=>e.models),[i,o]=(0,O.useState)([]),[ee,f]=(0,O.useState)(null),[p,g]=(0,O.useState)(!1),[ie,ae]=(0,O.useState)(!0),[T,E]=(0,O.useState)(null),[D,ce]=(0,O.useState)(null),[fe,j]=(0,O.useState)([]),[_e,ve]=(0,O.useState)([]),[M,N]=(0,O.useState)(null),[P,F]=(0,O.useState)(null),[ye,I]=(0,O.useState)([]),[L,R]=(0,O.useState)(``),[z,be]=(0,O.useState)(``),[B,xe]=(0,O.useState)(!1),[V,H]=(0,O.useState)(null),[Se,U]=(0,O.useState)(!1),[Ce,we]=(0,O.useState)(!1),[W,Te]=(0,O.useState)(``),[Ee,G]=(0,O.useState)(!1),De=(0,O.useRef)(null),Oe=(0,O.useRef)(null),[ke,Ae]=r(),K=(0,O.useMemo)(()=>i.find(e=>e.id===T)??null,[i,T]),[je,Me]=(0,O.useState)(null);T!==je&&(Me(T),ce(null),F(null),N(null));let q=K?.role===`owner`,J=(0,O.useCallback)(()=>{C.listMine().then(e=>{e.success&&e.data&&o(e.data)}).catch(e=>A.error(`Failed to load channels:`,e)).finally(()=>ae(!1))},[]);(0,O.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=ke.get(`channel`);Y&&T!==Y&&E(Y),(0,O.useEffect)(()=>{Y&&Ae({},{replace:!0})},[Y,Ae]);let X=(0,O.useCallback)(e=>{C.listMessages(e,{limit:100}).then(e=>{e.success&&e.data&&ce(e.data)}).catch(e=>A.error(`Failed to load messages:`,e))},[]),Ne=(0,O.useRef)(null);(0,O.useEffect)(()=>{Ne.current=P},[P]);let Pe=(0,O.useCallback)(e=>{X(e),C.markRead(e);let t=Ne.current;t&&C.thread(t).then(e=>{e.success&&e.data&&I(e.data)})},[X]);(0,O.useEffect)(()=>{if(!T)return;X(T),C.markRead(T).then(J);let e=new AbortController;return se({path:`/channels/${T}/events`,signal:e.signal,onEvent:()=>Pe(T)}),()=>e.abort()},[T,X,J,Pe]);let Fe=D?.length??0;(0,O.useEffect)(()=>{let e=Oe.current;e&&(e.scrollTop=e.scrollHeight)},[Fe,T]),(0,O.useEffect)(()=>{!T||!M||(M===`members`?C.listMembers(T).then(e=>{e.success&&e.data&&j(e.data)}):C.listPins(T).then(e=>{e.success&&e.data&&ve(e.data)}))},[T,M]),(0,O.useEffect)(()=>{P&&C.thread(P).then(e=>{e.success&&e.data&&I(e.data)})},[P]);let Ie=()=>{g(!0),C.listPublic().then(e=>{e.success&&e.data&&f(e.data)})},Z=async t=>{if(!T||B)return;let n=L.trim();if(!(!n&&!V)){xe(!0);try{let r=await C.postMessage(T,{content:n,...t?{parentId:t}:{},...V?{attachmentIds:[V.id]}:{},...z?{mentionModel:z}:{}});if(r.success){if(R(``),H(null),be(``),X(T),t){let e=await C.thread(t);e.success&&e.data&&I(e.data)}}else _.error(r.error||e(`channels.sendFailed`))}catch(t){A.error(`Failed to send message:`,t),_.error(e(`channels.sendFailed`))}finally{xe(!1)}}},Le=async t=>{if(T)try{let n=await C.uploadAttachment(T,t);n.success&&n.data?H({id:n.data.id,filename:n.data.filename}):_.error(n.error||e(`channels.uploadFailed`))}catch(t){A.error(`Failed to upload attachment:`,t),_.error(e(`channels.uploadFailed`))}},Re=async()=>{if(!(!T||!W.trim())){if((await C.addMember(T,W.trim()).catch(()=>void 0))?.success){Te(``);let t=await C.listMembers(T);t.success&&t.data&&j(t.data),_.success(e(`channels.memberAdded`))}else _.error(e(`channels.memberAddFailed`))}},Q={onReply:e=>F(e.id),onEdit:async(e,t)=>{(await C.editMessage(e.id,t).catch(()=>void 0))?.success&&T&&X(T)},onDelete:async e=>{(await C.deleteMessage(e.id).catch(()=>void 0))?.success&&T&&X(T)},onPin:async e=>{await C.setPinned(e.id,!e.pinnedAt).catch(()=>void 0),T&&X(T)},onReact:async(e,t,n)=>{n?await C.removeReaction(e.id,t).catch(()=>void 0):await C.addReaction(e.id,t).catch(()=>void 0),T&&X(T)},onDownload:async(e,t)=>{try{let n=await C.downloadAttachment(e),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}catch(e){A.error(`Failed to download attachment:`,e)}}},$=ye[0];return(0,k.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,k.jsxs)(`aside`,{className:s(`flex w-64 shrink-0 flex-col border-r border-black/[0.06] dark:border-white/[0.06]`,T?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1 px-3 py-2.5`,children:[(0,k.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,k.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,k.jsx)(y,{className:`h-4 w-4`})}),(0,k.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,k.jsx)(u,{className:`h-4 w-4`})}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>U(!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,k.jsx)(l,{className:`h-4 w-4`})})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:ie?(0,k.jsx)(m,{className:`mx-auto mt-6 h-4 w-4 animate-spin text-gray-400`}):i.length===0?(0,k.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,k.jsxs)(`button`,{type:`button`,onClick:()=>E(e.id),className:s(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px]`,T===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,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:de(e)}),(e.unreadCount??0)>0&&(0,k.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,k.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,k.jsxs)(k.Fragment,{children:[(0,k.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,k.jsx)(`button`,{type:`button`,onClick:()=>E(null),className:`rounded-md p-1 text-gray-500 hover:bg-black/[0.04] md:hidden dark:text-dark-600`,children:(0,k.jsx)(x,{className:`h-4 w-4`})}),ue(K),(0,k.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,k.jsx)(`button`,{type:`button`,onClick:()=>N(M===`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,k.jsx)(S,{className:`h-4 w-4`})}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>N(M===`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,k.jsx)(re,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,k.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,k.jsx)(te,{className:`h-4 w-4`})})]}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,k.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:D===null?(0,k.jsx)(m,{className:`mx-auto mt-6 h-4 w-4 animate-spin text-gray-400`}):D.length===0?(0,k.jsx)(`p`,{className:`pt-8 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noMessages`)}):D.map(e=>(0,k.jsx)(le,{message:e,currentUserId:t?.id,canModerate:q,actions:Q},e.id))}),(0,k.jsxs)(`div`,{className:`border-t border-black/[0.06] p-3 dark:border-white/[0.06]`,children:[V&&(0,k.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,k.jsx)(v,{className:`h-3.5 w-3.5`}),(0,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:V.filename}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>H(null),className:`text-gray-400 hover:text-red-500`,children:(0,k.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,k.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,k.jsx)(`input`,{ref:De,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Le(t),e.target.value=``}}),(0,k.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,k.jsx)(v,{className:`h-4 w-4`})}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(ne,{className:s(`h-4 w-4`,z?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,k.jsxs)(`select`,{value:z,onChange:e=>be(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,k.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,k.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,k.jsx)(`textarea`,{value:L,onChange:e=>R(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Z())},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,k.jsx)(w,{size:`sm`,disabled:B||!L.trim()&&!V,onClick:()=>void Z(),"data-testid":`channel-send`,children:B?(0,k.jsx)(m,{className:`h-4 w-4 animate-spin`}):(0,k.jsx)(h,{className:`h-4 w-4`})})]})]})]}),P&&(0,k.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,k.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,k.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>F(null),className:`rounded-md p-1 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,k.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:ye.map(e=>(0,k.jsx)(le,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Q,onReply:void 0},compact:!0},e.id))}),(0,k.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/[0.06] p-2 dark:border-white/[0.06]`,children:[(0,k.jsx)(`textarea`,{value:L,onChange:e=>R(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),$&&Z($.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,k.jsx)(w,{size:`sm`,disabled:B||!L.trim(),onClick:()=>$&&void Z($.id),children:(0,k.jsx)(h,{className:`h-3.5 w-3.5`})})]})]}),M&&(0,k.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-l border-black/[0.06] dark:border-white/[0.06]`,"data-testid":`channel-${M}-panel`,children:[(0,k.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,k.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(M===`members`?`channels.members`:`channels.pins`)}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>N(null),className:`rounded-md p-1 text-gray-400 hover:bg-black/[0.04] dark:hover:bg-white/[0.06]`,children:(0,k.jsx)(b,{className:`h-3.5 w-3.5`})})]}),(0,k.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:M===`members`?(0,k.jsxs)(k.Fragment,{children:[q&&K.type===`private`&&(0,k.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,k.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,k.jsx)(w,{size:`sm`,disabled:!W.trim(),onClick:()=>void Re(),"data-testid":`channel-invite-submit`,children:(0,k.jsx)(l,{className:`h-3.5 w-3.5`})})]}),fe.map(n=>(0,k.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,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,k.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,k.jsx)(`button`,{type:`button`,onClick:()=>void C.removeMember(K.id,n.userId).then(()=>j(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,k.jsx)(b,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,k.jsx)(w,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:()=>void C.removeMember(K.id,t?.id??``).then(()=>{E(null),J()}),"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):_e.length===0?(0,k.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):_e.map(e=>(0,k.jsx)(le,{message:e,currentUserId:t?.id,canModerate:q,actions:Q,compact:!0},e.id))})]})]})]}):(0,k.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 text-gray-400 dark:text-dark-500`,children:[(0,k.jsx)(d,{className:`h-8 w-8`}),(0,k.jsx)(`p`,{className:`text-sm`,children:e(`channels.selectPrompt`)})]})}),Se&&(0,k.jsx)(pe,{onClose:()=>U(!1),onCreated:e=>{U(!1),J(),E(e.id)}}),Ce&&(0,k.jsx)(me,{onClose:()=>we(!1),onOpened:e=>{we(!1),J(),E(e.id)}}),p&&(0,k.jsx)(he,{channels:ee,onClose:()=>g(!1),onJoined:e=>{g(!1),J(),E(e)}}),Ee&&K&&(0,k.jsx)(ge,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),E(null),J()}})]})},pe=({onClose:e,onCreated:t})=>{let{t:n}=a(),[r,i]=(0,O.useState)(``),[o,s]=(0,O.useState)(`public`),[c,l]=(0,O.useState)(``),[u,d]=(0,O.useState)(!1);return(0,k.jsxs)(E,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,k.jsx)(w,{size:`sm`,disabled:u||!r.trim(),onClick:()=>{d(!0),C.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):_.error(e.error||n(`channels.createFailed`))}).catch(()=>_.error(n(`channels.createFailed`))).finally(()=>d(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:T,children:n(`channels.nameLabel`)}),(0,k.jsx)(`input`,{className:D,value:r,onChange:e=>i(e.target.value),"data-testid":`create-channel-name`})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:T,children:n(`channels.typeLabel`)}),(0,k.jsxs)(`select`,{className:D,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,k.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,k.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:T,children:n(`channels.descriptionLabel`)}),(0,k.jsx)(`textarea`,{className:D,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},me=({onClose:e,onOpened:t})=>{let{t:n}=a(),[r,i]=(0,O.useState)(``),[o,s]=(0,O.useState)(!1),c=()=>{r.trim()&&(s(!0),C.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):_.error(e.error||n(`channels.dmFailed`))}).catch(()=>_.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,k.jsx)(E,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,k.jsx)(w,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,k.jsx)(`input`,{className:D,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},he=({channels:e,onClose:t,onJoined:n})=>{let{t:r}=a();return(0,k.jsx)(E,{titleId:`browse-channels-title`,title:r(`channels.browsePublic`),onClose:t,testId:`browse-channels-modal`,children:e===null?(0,k.jsx)(m,{className:`mx-auto h-4 w-4 animate-spin text-gray-400`}):e.length===0?(0,k.jsx)(`p`,{className:`text-center text-xs text-gray-400 dark:text-dark-500`,children:r(`channels.noPublic`)}):e.map(e=>(0,k.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,k.jsx)(f,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,k.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:r(`channels.joined`)}):(0,k.jsx)(w,{size:`sm`,onClick:()=>void C.join(e.id).then(()=>n(e.id)),"data-testid":`browse-channel-join`,children:r(`channels.join`)})]},e.id))})},ge=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:i}=a(),[o,s]=(0,O.useState)(e.name),[c,l]=(0,O.useState)(e.description??``),[u,d]=(0,O.useState)(!1);return(0,k.jsxs)(E,{titleId:`channel-settings-title`,title:i(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,k.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,k.jsx)(w,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:()=>void C.delete(e.id).then(e=>{e.success&&r()}),"data-testid":`channel-delete`,children:i(`channels.delete`)}),(0,k.jsx)(w,{size:`sm`,disabled:u||!o.trim(),onClick:()=>{d(!0),C.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,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:T,children:i(`channels.nameLabel`)}),(0,k.jsx)(`input`,{className:D,value:o,onChange:e=>s(e.target.value)})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:T,children:i(`channels.descriptionLabel`)}),(0,k.jsx)(`textarea`,{className:D,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{fe as default};