@engenty/wizards-runtime 0.19.1 → 0.20.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 (162) hide show
  1. package/apps/runtime/dist/agents/architect.js +4 -4
  2. package/apps/runtime/dist/agents/studio-assistant.js +2 -31
  3. package/apps/runtime/dist/app.js +4 -4
  4. package/apps/runtime/dist/assistant/knows.js +2 -2
  5. package/apps/runtime/dist/auth/index.js +1 -1
  6. package/apps/runtime/dist/authoring/example.js +1 -1
  7. package/apps/runtime/dist/authoring/guide.js +35 -6
  8. package/apps/runtime/dist/broker/account.js +85 -16
  9. package/apps/runtime/dist/broker/call.js +137 -37
  10. package/apps/runtime/dist/broker/log.js +19 -5
  11. package/apps/runtime/dist/broker/rwx.js +12 -9
  12. package/apps/runtime/dist/connectors/index.js +52 -11
  13. package/apps/runtime/dist/connectors/person-connections.js +279 -0
  14. package/apps/runtime/dist/connectors/person-sign-ins.js +74 -3
  15. package/apps/runtime/dist/connectors/same-service.js +14 -0
  16. package/apps/runtime/dist/connectors/space-choice.js +116 -0
  17. package/apps/runtime/dist/connectors/space-connections.js +40 -2
  18. package/apps/runtime/dist/db/client.js +8 -0
  19. package/apps/runtime/dist/db/kept-accounts.js +88 -0
  20. package/apps/runtime/dist/db/migrations/tenant/0075_person_connection.sql +25 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0076_clients_in_spaces.sql +28 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0077_client_spaces_at_root.sql +21 -0
  23. package/apps/runtime/dist/db/migrations/tenant/meta/0075_snapshot.json +7859 -0
  24. package/apps/runtime/dist/db/migrations/tenant/meta/0076_snapshot.json +7859 -0
  25. package/apps/runtime/dist/db/migrations/tenant/meta/0077_snapshot.json +7859 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +21 -0
  27. package/apps/runtime/dist/db/schema.js +67 -16
  28. package/apps/runtime/dist/docs/dev/api.md +8 -8
  29. package/apps/runtime/dist/docs/dev/wizard-format/index.md +3 -1
  30. package/apps/runtime/dist/elements/caller.js +1 -1
  31. package/apps/runtime/dist/elements/knowledge.js +5 -5
  32. package/apps/runtime/dist/elements/wizards.js +7 -11
  33. package/apps/runtime/dist/engine/notices.js +13 -1
  34. package/apps/runtime/dist/engine/requirements.js +116 -3
  35. package/apps/runtime/dist/engine/run-needs.js +58 -0
  36. package/apps/runtime/dist/engine/runner.js +209 -16
  37. package/apps/runtime/dist/engine/starts.js +9 -0
  38. package/apps/runtime/dist/engine/types.js +5 -1
  39. package/apps/runtime/dist/harness/claude.js +3 -1
  40. package/apps/runtime/dist/manage.js +1 -1
  41. package/apps/runtime/dist/mcp/tools.js +3 -3
  42. package/apps/runtime/dist/plugins/runs.js +2 -1
  43. package/apps/runtime/dist/prompts/authoring.md +13 -3
  44. package/apps/runtime/dist/prompts/goose.md +0 -5
  45. package/apps/runtime/dist/routes/api.js +9 -4
  46. package/apps/runtime/dist/routes/client-contract.js +2 -2
  47. package/apps/runtime/dist/routes/client-spaces.js +1 -16
  48. package/apps/runtime/dist/routes/connections.js +6 -1
  49. package/apps/runtime/dist/routes/marketplace.js +27 -7
  50. package/apps/runtime/dist/routes/plugins.js +1 -1
  51. package/apps/runtime/dist/routes/runs.js +157 -11
  52. package/apps/runtime/dist/routes/studio.js +42 -5
  53. package/apps/runtime/dist/services/client-portal.js +58 -49
  54. package/apps/runtime/dist/services/client-spaces.js +57 -125
  55. package/apps/runtime/dist/services/links.js +3 -3
  56. package/apps/runtime/dist/services/marketplace.js +6 -2
  57. package/apps/runtime/dist/services/members-studio.js +1 -1
  58. package/apps/runtime/dist/services/query-vectors.js +1 -1
  59. package/apps/runtime/dist/services/runs.js +19 -20
  60. package/apps/runtime/dist/services/space-parent.js +4 -11
  61. package/apps/runtime/dist/services/spaces.js +56 -47
  62. package/apps/runtime/dist/services/work-ai.js +3 -3
  63. package/apps/runtime/dist/store/index.js +28 -8
  64. package/apps/runtime/dist/store/shared-lists.js +2 -2
  65. package/apps/runtime/dist/sync/hub.js +9 -5
  66. package/apps/runtime/dist/tools/connector.js +4 -2
  67. package/apps/web/dist/assets/{AboutDialog-BUWu36Mb.js → AboutDialog-QWzpEK8M.js} +1 -1
  68. package/apps/web/dist/assets/{BlockEditor-1-EvUIta.js → BlockEditor-C44bI_ih.js} +1 -1
  69. package/apps/web/dist/assets/{Bundle-RNkjBwAL.js → Bundle-DZyQ1FP7.js} +1 -1
  70. package/apps/web/dist/assets/CapabilitiesPage-DAr0-gN1.js +2 -0
  71. package/apps/web/dist/assets/{ChangelogDialog-C_ZZLRZT.js → ChangelogDialog-CdHqJV2P.js} +1 -1
  72. package/apps/web/dist/assets/{CodeEditor-BEJKIMd0.js → CodeEditor-BRufUwu0.js} +1 -1
  73. package/apps/web/dist/assets/ConnectorsSection-BO6jHrYU.js +1 -0
  74. package/apps/web/dist/assets/EditorPage-Bx-fKnsY.js +3 -0
  75. package/apps/web/dist/assets/{FlowPreview-ptI86Ogs.js → FlowPreview-aj58c-gH.js} +1 -1
  76. package/apps/web/dist/assets/{LangSwitch-BNa_H8AR.js → LangSwitch-BNkytlus.js} +1 -1
  77. package/apps/web/dist/assets/Marketplace-D3hdvrkz.js +2 -0
  78. package/apps/web/dist/assets/NewWizardChannels-fveQcQlY.js +1 -0
  79. package/apps/web/dist/assets/NewWizardPage-BTX1g2t1.js +7 -0
  80. package/apps/web/dist/assets/OnboardingPage-DwF6KdQy.js +1 -0
  81. package/apps/web/dist/assets/ProtocolSection-YnJcMN9E.js +1 -0
  82. package/apps/web/dist/assets/PublicRunner-Bp4DxTrD.js +1 -0
  83. package/apps/web/dist/assets/{ReadOnly-YF0RkR7P.js → ReadOnly-C6qmTD35.js} +1 -1
  84. package/apps/web/dist/assets/{Results-DJRLiVo0.js → Results-BNuuBiwU.js} +1 -1
  85. package/apps/web/dist/assets/{RunDrawer-CSpTNJp-.js → RunDrawer-CMgN-XTB.js} +1 -1
  86. package/apps/web/dist/assets/SettingsPage-CuUB26YJ.js +2 -0
  87. package/apps/web/dist/assets/SetupPage-llGzMVeH.js +1 -0
  88. package/apps/web/dist/assets/{SharePage-OiKEnmL1.js → SharePage-CgQp_PT6.js} +1 -1
  89. package/apps/web/dist/assets/SkillEditor-ARx8QPGp.js +1 -0
  90. package/apps/web/dist/assets/Skills-frfXXEcF.js +9 -0
  91. package/apps/web/dist/assets/SpacePage-Dv6ocsc_.js +2 -0
  92. package/apps/web/dist/assets/StudioHome-B0bZRm1L.js +1 -0
  93. package/apps/web/dist/assets/TableEditor-CfzTLmJF.js +7 -0
  94. package/apps/web/dist/assets/{UpdateCheck-BpdsLIOc.js → UpdateCheck-D3QhfI5c.js} +2 -2
  95. package/apps/web/dist/assets/{brand-ByQY-UcL.js → brand-DKuVyYhH.js} +1 -1
  96. package/apps/web/dist/assets/changelog-Db3nvWao.js +1 -0
  97. package/apps/web/dist/assets/{code-editor-B8zG80PA.js → code-editor-BLwDuQLI.js} +2 -2
  98. package/apps/web/dist/assets/host-C-AAp8Bz.js +69 -0
  99. package/apps/web/dist/assets/i18n-Dyi0kvaA.js +55 -0
  100. package/apps/web/dist/assets/{index-D18zQ05f.css → index-CduFlFCp.css} +1 -1
  101. package/apps/web/dist/assets/index-CtE0rJEL.js +102 -0
  102. package/apps/web/dist/assets/{read-aloud-spC7eEBp.js → read-aloud-DGS8mWgC.js} +1 -1
  103. package/apps/web/dist/assets/session-EIDP3Wzc.js +1 -0
  104. package/apps/web/dist/assets/theme-B46aPLtX.js +14 -0
  105. package/apps/web/dist/assets/ui-DSgksc1H.js +16 -0
  106. package/apps/web/dist/assets/{useMutation-CoEdB_9_.js → useMutation-fT44ij_b.js} +1 -1
  107. package/apps/web/dist/assets/{viewers-BmcrgvXX.js → viewers-DvA5VsXw.js} +2 -2
  108. package/apps/web/dist/index.html +18 -13
  109. package/apps/web/dist/mcp/flow.html +62 -62
  110. package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -2
  111. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +67 -0
  112. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10324 -7
  113. package/node_modules/@engenty/wizards-shared/dist/definition.js +32 -6
  114. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +17 -23
  115. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +17 -23
  116. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
  117. package/node_modules/@engenty/wizards-shared/dist/marketplace-search.js +7 -1
  118. package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +9 -2
  119. package/node_modules/@engenty/wizards-shared/dist/page-data.d.ts +72 -0
  120. package/node_modules/@engenty/wizards-shared/dist/page-data.js +5 -0
  121. package/node_modules/@engenty/wizards-shared/dist/page-look.d.ts +17 -0
  122. package/node_modules/@engenty/wizards-shared/dist/page-look.js +118 -0
  123. package/node_modules/@engenty/wizards-shared/dist/page-styles.d.ts +6 -0
  124. package/node_modules/@engenty/wizards-shared/dist/page-styles.js +98 -0
  125. package/node_modules/@engenty/wizards-shared/dist/page-texts.d.ts +36 -0
  126. package/node_modules/@engenty/wizards-shared/dist/page-texts.js +119 -0
  127. package/node_modules/@engenty/wizards-shared/dist/requires.js +2 -0
  128. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -1
  129. package/node_modules/@engenty/wizards-shared/dist/run.js +23 -0
  130. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +27 -1
  131. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +26 -0
  132. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +24 -1
  133. package/node_modules/@engenty/wizards-shared/dist/transition.d.ts +2 -1
  134. package/node_modules/@engenty/wizards-shared/dist/transition.js +5 -1
  135. package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +1 -1
  136. package/package.json +1 -1
  137. package/plugin/.claude-plugin/plugin.json +1 -1
  138. package/plugin/plugin.json +1 -1
  139. package/apps/web/dist/assets/CapabilitiesPage-fgTP28Mn.js +0 -2
  140. package/apps/web/dist/assets/ConnectorsSection-iLrduYak.js +0 -1
  141. package/apps/web/dist/assets/EditorPage-CRZte0O1.js +0 -3
  142. package/apps/web/dist/assets/Marketplace-9aGWG2pJ.js +0 -2
  143. package/apps/web/dist/assets/NewWizardChannels-BFDm9vCT.js +0 -1
  144. package/apps/web/dist/assets/NewWizardPage-ueGFlLDo.js +0 -7
  145. package/apps/web/dist/assets/OnboardingPage-DtDd7k_O.js +0 -1
  146. package/apps/web/dist/assets/PreviewPane-CEltrf_-.js +0 -7
  147. package/apps/web/dist/assets/ProtocolSection-Bb3c44Te.js +0 -1
  148. package/apps/web/dist/assets/PublicRunner-BaTg24s3.js +0 -1
  149. package/apps/web/dist/assets/SettingsPage--_ap3omw.js +0 -2
  150. package/apps/web/dist/assets/SetupPage-ELKHbmnE.js +0 -1
  151. package/apps/web/dist/assets/SkillEditor-C1_zwNOQ.js +0 -1
  152. package/apps/web/dist/assets/Skills-_pLGtOjH.js +0 -9
  153. package/apps/web/dist/assets/SpacePage-r4EbxEJe.js +0 -2
  154. package/apps/web/dist/assets/StudioHome-CwvxI29m.js +0 -1
  155. package/apps/web/dist/assets/changelog-Dt-V-BKp.js +0 -1
  156. package/apps/web/dist/assets/host-Ckjz94Ea.js +0 -69
  157. package/apps/web/dist/assets/i18n-ClCOlfx2.js +0 -55
  158. package/apps/web/dist/assets/index-BHKh0A9F.js +0 -10
  159. package/apps/web/dist/assets/runners-DNqzwMQ0.js +0 -1
  160. package/apps/web/dist/assets/session-Dd9duhPc.js +0 -1
  161. package/apps/web/dist/assets/theme-DumM6FI_.js +0 -14
  162. package/apps/web/dist/assets/ui-BjhZhw8x.js +0 -16
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AboutDialog-BUWu36Mb.js","assets/rolldown-runtime-XKyaHtl9.js","assets/ui-BjhZhw8x.js","assets/jsx-runtime-C3cWAN_r.js","assets/i18n-ClCOlfx2.js","assets/marked.esm-BfGIZK7F.js","assets/preload-helper-Cj7BV335.js","assets/logo-xL-sneZz.js","assets/engenty-Cy7MbUxR.js","assets/UpdateCheck-BpdsLIOc.js","assets/useMutation-CoEdB_9_.js","assets/react-dom-BwXff0Px.js","assets/media-gjOIWMWK.js","assets/ChangelogDialog-C_ZZLRZT.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{n as t,t as n}from"./jsx-runtime-C3cWAN_r.js";import{$ as r,$n as i,Bn as a,C as o,En as s,On as c,Pn as l,Qn as u,Tn as d,Wr as f,Yt as p,_n as m,_r as h,a as g,an as _,ar as v,cn as y,dn as b,dr as x,er as S,fn as C,fr as w,gr as ee,hn as T,in as E,ln as te,lr as D,nn as O,on as ne,pn as k,q as re,rn as A,sn as j,un as ie,v as ae,vn as M,vr as oe,xn as se,yn as ce,yr as N}from"./ui-BjhZhw8x.js";import{$ as le,$t as ue,B as de,Cn as fe,En as pe,Gn as me,Gt as he,H as ge,Hn as _e,Ht as ve,J as ye,Jn as be,K as xe,Kt as Se,Nn as Ce,On as we,Q as Te,Qn as Ee,Qt as De,Rn as Oe,Tn as ke,Ut as Ae,V as je,Wt as Me,X as Ne,Xn as Pe,Xt as Fe,Y as Ie,Yt as Le,Z as Re,Zn as ze,Zt as Be,a as Ve,an as He,ar as Ue,at as We,cn as Ge,cr as Ke,dr as qe,en as Je,et as Ye,f as Xe,fr as Ze,in as Qe,ir as $e,it as et,k as tt,ln as nt,lt as rt,m as it,nn as at,on as P,or as ot,ot as st,qn as ct,r as lt,rn as ut,sn as dt,st as ft,t as pt,tn as mt,tr as ht,tt as gt,vn as _t,wn as vt}from"./host-Ckjz94Ea.js";import{F as yt,M as bt,P as xt,T as St,n as F,s as I,z as Ct}from"./i18n-ClCOlfx2.js";import{_ as wt,b as Tt,f as Et,h as Dt,n as Ot,u as kt,v as At}from"./session-Dd9duhPc.js";import{a as jt,c as Mt,d as Nt,f as Pt,i as Ft,l as It,m as Lt,o as Rt,p as zt,r as Bt,s as L,u as Vt}from"./UpdateCheck-BpdsLIOc.js";import{t as R}from"./useMutation-CoEdB_9_.js";import{c as Ht,d as Ut,i as Wt,l as Gt,n as Kt,r as qt,s as Jt,u as z}from"./marked.esm-BfGIZK7F.js";import{t as Yt}from"./upload-BZThm-R6.js";import{c as Xt,d as Zt,f as Qt,l as $t,u as en}from"./ConnectorsSection-iLrduYak.js";import{t as tn}from"./ProtocolSection-Bb3c44Te.js";import{A as nn,E as rn,O as an,j as on,k as sn}from"./Marketplace-9aGWG2pJ.js";import{n as cn,t as ln}from"./volume-2-Br71vpS5.js";import{n as un,r as dn,t as fn}from"./ReadOnly-YF0RkR7P.js";import{n as pn,t as mn}from"./list-checks-D1zkXlZa.js";import{t as hn}from"./plug-CHvl1GhO.js";import{s as gn}from"./index-BHKh0A9F.js";import{t as _n}from"./LangSwitch-BNa_H8AR.js";import{t as vn}from"./preload-helper-Cj7BV335.js";var yn={name:`contact`,size:24,node:[[`path`,{d:`M16 2v2`,key:`scm5qe`}],[`path`,{d:`M7 21v-2a2 2 0 012-2h6a2 2 0 012 2v2`,key:`k82dct`}],[`path`,{d:`M8 2v2`,key:`pbkmx`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]};yn.node;var bn=Ut(yn),xn={name:`ear`,size:24,node:[[`path`,{d:`M6 8.5a6.5 6.5 0 1 1 13 0c0 6-6 6-6 10a3.5 3.5 0 1 1-7 0`,key:`1dfaln`}],[`path`,{d:`M15 8.5a2.5 2.5 0 0 0-5 0v1a2 2 0 1 1 0 4`,key:`1qnva7`}]]};xn.node;var Sn=Ut(xn),Cn={name:`mail-plus`,size:24,node:[[`path`,{d:`M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8`,key:`12jkf8`}],[`path`,{d:`m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7`,key:`1ocrg3`}],[`path`,{d:`M19 16v6`,key:`tddt3s`}],[`path`,{d:`M16 19h6`,key:`xwg31i`}]]};Cn.node;var wn=Ut(Cn),Tn={name:`split`,size:24,node:[[`path`,{d:`M16 3h5v5`,key:`1806ms`}],[`path`,{d:`M8 3H3v5`,key:`15dfkv`}],[`path`,{d:`M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3`,key:`1qrqzj`}],[`path`,{d:`m15 9 6-6`,key:`ko1vev`}]]};Tn.node;var En=Ut(Tn),B=e(t(),1),V=e(n(),1),Dn=[`pro-modules`],On=`/api/studio/plugins/-/pro`,kn={managed:`pro.held.plan`,not_installed:`pro.held.release`,release:`pro.held.release`,unconfirmed:`pro.held.unconfirmed`,plan:`pro.held.plan`},An=e=>new Date(e).toLocaleDateString(bt[F],{day:`numeric`,month:`long`});function jn(e){let t=f(),n=N({queryKey:Dn,queryFn:()=>r.get(On),enabled:e}),i=e=>(t.setQueryData(Dn,e),t.invalidateQueries({queryKey:[`plugins-all`]}));return{state:n,refresh:R({mutationFn:()=>r.post(`${On}/refresh`),onSuccess:i}),install:R({mutationFn:e=>r.post(`${On}/${e}`),onSuccess:i}),remove:R({mutationFn:e=>r.del(`${On}/${e}`),onSuccess:i})}}function Mn(){let e=h(),t=Dt(),n=f(),r=fe(`account`),i=!!t.data?.account?.signedIn,a=ge(i);return(0,B.useEffect)(()=>{i&&n.invalidateQueries({queryKey:Dn})},[i,n]),(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`pro.notLinked`)}),r?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,V.jsx)(O,{busy:a.link.isPending,onClick:()=>a.link.mutate({}),children:I(`account.signIn`)}),(0,V.jsx)(O,{variant:`ghost`,onClick:()=>e(`/settings/account`),children:I(`pro.newAccount`)})]}),(0,V.jsx)(je,{...a})]}):null]})}function Nn({pro:e}){let{state:t,refresh:n}=e,r=t.data;return(0,V.jsx)(o,{title:I(`pro.title`),hint:I(`pro.hint`),action:r?.linked?(0,V.jsx)(O,{variant:`secondary`,busy:n.isPending,onClick:()=>n.mutate(),children:I(`pro.check`)}):null,children:t.isError?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:I(`pro.failed`,{error:t.error.message})}),(0,V.jsx)(O,{variant:`secondary`,onClick:()=>void t.refetch(),children:I(`pro.retry`)})]}):r?r.linked?(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 text-[0.8125rem] text-ink-3`,children:[(0,V.jsxs)(`span`,{children:[r.plan?I(`pro.plan`,{plan:r.plan.name}):null,r.plan&&r.expiresAt?` · `:null,r.expiresAt?I(`pro.confirmedUntil`,{date:An(r.expiresAt)}):null]}),(0,V.jsxs)(O,{variant:`ghost`,onClick:()=>Le(`${r.accountUrl}/billing`),children:[I(`pro.plans`),` `,(0,V.jsx)(Ht,{className:`size-4`})]})]}),r.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error}):null,r.modules.length?null:(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`pro.none`,{runtime:r.runtime})}),n.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:n.error.message}):null]}):(0,V.jsx)(Mn,{}):(0,V.jsx)(k,{})})}var Pn=[`plugins-all`],Fn={builtin:`plugins.originBuiltin`,pro:`plugins.originPro`,installed:`plugins.originInstalled`,folder:`plugins.originFolder`};function In(){let e=f(),t=Ve(),n=jn(!0),i=N({queryKey:Pn,queryFn:()=>r.get(`/api/studio/plugins/-/all`)}),a=t=>e.setQueryData(Pn,e=>({...e,...t})),s=R({mutationFn:({id:e,on:t})=>r.put(`/api/studio/plugins/-/all/${e}`,{on:t}),onSuccess:a}),c=R({mutationFn:e=>r.del(`/api/studio/plugins/-/all/${e}`),onSuccess:a}),[l,u]=(0,B.useState)(null),[d,p]=(0,B.useState)(!1),m=async e=>{u(e??`*`);try{await lt(e),await i.refetch()}finally{u(null)}},h=i.data?.plugins??[],g=e=>n.state.data?.modules.find(t=>t.id===e),_=(n.state.data?.modules??[]).filter(e=>!h.some(t=>t.id===e.id)),v=s.error??c.error??n.install.error??n.remove.error,y=s.isPending||c.isPending||n.install.isPending;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsxs)(o,{title:I(`plugins.title`),hint:I(`plugins.hint`),action:(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(O,{variant:`secondary`,size:`sm`,busy:l===`*`,onClick:()=>void m(),children:I(`plugins.rescan`)}),(0,V.jsxs)(O,{size:`sm`,onClick:()=>p(!0),children:[(0,V.jsx)(Wt,{className:`size-4`}),` `,I(`plugins.add`)]})]}),children:[i.data?h.length||_.length||t.problems.length?(0,V.jsxs)(`ul`,{className:`divide-y divide-border-soft`,children:[h.map(e=>{let r=g(e.id);return(0,V.jsx)(Ln,{name:e.name,id:e.id,version:e.version,description:e.description,chips:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{tone:e.origin===`installed`?`warn`:`neutral`,children:I(Fn[e.origin])}),e.on?null:(0,V.jsx)(E,{children:I(`plugins.off`)})]}),tools:e.tools,error:e.error?I(`plugins.serverFailed`,{error:e.error}):t.failed[e.id]?I(`plugins.studioFailed`,{error:t.failed[e.id]??``}):null,actions:(0,V.jsxs)(V.Fragment,{children:[r?.update?(0,V.jsx)(O,{size:`sm`,busy:n.install.isPending&&n.install.variables===r.id,disabled:y,onClick:()=>n.install.mutate(r.id),children:I(`pro.update`)}):null,e.origin===`installed`||e.origin===`pro`?(0,V.jsx)(O,{size:`sm`,variant:`ghost`,disabled:y,onClick:()=>e.origin===`pro`?n.remove.mutate(e.id):c.mutate(e.id),children:I(`plugins.remove`)}):null,(0,V.jsx)(j,{label:I(`plugins.reload`),disabled:l!==null||!e.on,onClick:()=>void m(e.id),children:(0,V.jsx)(Oe,{className:l===e.id?`size-4 animate-spin`:`size-4`})}),(0,V.jsx)(T,{checked:e.on,label:e.name,disabled:y,onChange:t=>s.mutate({id:e.id,on:t})})]})},e.id)}),_.map(e=>(0,V.jsx)(Rn,{m:e,busy:n.install.isPending&&n.install.variables===e.id,disabled:y,onInstall:()=>n.install.mutate(e.id)},e.id)),t.problems.map(e=>(0,V.jsxs)(`li`,{className:`py-4 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,V.jsx)(E,{tone:`warn`,children:I(`plugins.problems`)}),(0,V.jsx)(`span`,{className:`break-all font-mono text-[0.75rem] text-ink-3`,children:e.path})]}),(0,V.jsx)(`p`,{className:`mt-1.5 text-[0.8125rem] text-ink-3`,children:e.message})]},e.path))]}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`plugins.none`)}):(0,V.jsx)(k,{}),v?(0,V.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-rose`,children:v.message}):null]}),(0,V.jsx)(Nn,{pro:n}),(0,V.jsx)(zn,{open:d,onClose:()=>p(!1),onDone:a})]})}function Ln({name:e,id:t,version:n,description:r,chips:i,tools:a=[],error:o,actions:s}){return(0,V.jsxs)(`li`,{className:`flex items-start gap-4 py-4 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:e}),e===t?null:(0,V.jsxs)(`span`,{className:`font-mono text-[0.75rem] text-ink-4`,children:[t,` · `,n]}),i]}),r?(0,V.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:r}):null,a.length?(0,V.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[I(`plugins.tools`),a.map(e=>(0,V.jsx)(E,{children:e},e))]}):null,o?(0,V.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:o}):null]}),(0,V.jsx)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:s})]})}function Rn({m:e,busy:t,disabled:n,onInstall:r}){return(0,V.jsx)(Ln,{name:e.name,id:e.id,version:e.installed?.version??e.version,description:e.description,chips:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{children:I(`plugins.originPro`)}),e.included?null:(0,V.jsx)(E,{children:I(`pro.notInPlan`)}),e.installed&&e.heldBack&&e.included?(0,V.jsx)(E,{tone:`warn`,children:I(kn[e.heldBack])}):null]}),actions:e.included&&(!e.installed||e.update)?(0,V.jsx)(O,{size:`sm`,busy:t,disabled:n,onClick:r,children:e.installed?I(`pro.update`):I(`pro.install`)}):null})}function zn({open:e,onClose:t,onDone:n}){let[i,a]=(0,B.useState)(``),o=R({mutationFn:e=>typeof e==`string`?r.post(`/api/studio/plugins/-/install`,{path:e}):r.upload(`/api/studio/plugins/-/install`,e),onSuccess:e=>{n(e),a(``),t()}});return(0,V.jsx)(_,{open:e,onClose:t,title:I(`plugins.addTitle`),children:(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsxs)(`div`,{className:`flex gap-3 rounded-xl bg-amber-tint p-3.5 text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(se,{className:`mt-0.5 size-4 shrink-0 text-ink-2`}),(0,V.jsx)(`p`,{children:I(`plugins.addWarning`)})]}),(0,V.jsxs)(ae,{accept:`.zip,application/zip`,multiple:!1,onFiles:([e])=>e&&o.mutate(e),className:`h-28`,children:[(0,V.jsx)(Yt,{className:`size-4`}),` `,I(`plugins.addZip`)]}),(0,V.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),i.trim()&&o.mutate(i.trim())},className:`flex flex-col gap-2`,children:[(0,V.jsx)(`label`,{htmlFor:`plugin-folder`,className:`font-medium text-[0.875rem]`,children:I(`plugins.addFolder`)}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(y,{id:`plugin-folder`,value:i,placeholder:I(`plugins.addFolderPlaceholder`),onChange:e=>a(e.target.value),className:`font-mono text-[0.8125rem]`}),(0,V.jsx)(O,{type:`submit`,variant:`secondary`,disabled:!i.trim(),children:I(`pro.install`)})]})]}),o.isPending?(0,V.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.875rem] text-ink-3`,children:[(0,V.jsx)(k,{className:`size-4`}),` `,I(`plugins.installing`)]}):null,o.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:o.error.message}):null]})})}function Bn(){let e=Ve();return(0,V.jsxs)(o,{title:I(`plugins.title`),hint:I(`plugins.hintManaged`),children:[e.plugins.length?null:(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`plugins.none`)}),(0,V.jsx)(`ul`,{className:`divide-y divide-border-soft`,children:e.plugins.map(t=>{let n=e.failed[t.id];return(0,V.jsxs)(`li`,{className:`py-4 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-1`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:t.name}),t.name===t.id?null:(0,V.jsxs)(`span`,{className:`font-mono text-[0.75rem] text-ink-4`,children:[t.id,` · `,t.version]})]}),t.description?(0,V.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:t.description}):null,t.tools.length?(0,V.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[I(`plugins.tools`),t.tools.map(e=>(0,V.jsx)(E,{children:e.id},e.id))]}):null,t.error?(0,V.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:I(`plugins.serverFailed`,{error:t.error})}):null,n?(0,V.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:I(`plugins.studioFailed`,{error:n})}):null]},t.id)})})]})}function Vn(){let e=Ve(),[t,n]=x(),{narrow:r}=zt(),i=t.get(`show`),a=e.sections.find(e=>e.id===i)??null,o=!(!i&&r);Nt(o?a?.label()??I(`plugins.overview`):null);let s=e=>n({show:e},{replace:!r});return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(It,{children:(0,V.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[(0,V.jsx)(L,{icon:Ze,label:I(`plugins.overview`),selected:o&&!a,onPick:()=>s(`overview`)}),e.sections.map(e=>(0,V.jsx)(L,{icon:e.icon,label:e.label(),selected:e.id===a?.id,onPick:()=>s(e.id)},e.id))]})}),a?(0,V.jsx)(pt,{of:a,children:(0,V.jsx)(a.component,{})},a.id):e.canReload?(0,V.jsx)(In,{}):(0,V.jsx)(Bn,{})]})}var Hn=e=>new URL(e).host.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``),Un=`engenty-wizards`,Wn=`wizards`,Gn=`engenty wizards`,Kn=`ENGENTY_WIZARDS_KEY`,qn=[{id:`claude-desktop`,name:`Claude Desktop`,widgets:!0,connector:!0},{id:`claude-code`,name:`Claude Code`,widgets:!1},{id:`codex`,name:`Codex · ChatGPT app`,widgets:!1},{id:`cursor`,name:`Cursor`,widgets:!0},{id:`vscode`,name:`VS Code (Copilot)`,widgets:!0},{id:`windsurf`,name:`Windsurf`,widgets:!1},{id:`antigravity`,name:`Antigravity`,widgets:!1},{id:`goose`,name:`Goose`,widgets:!0},{id:`openclaw`,name:`OpenClaw`,widgets:!1},{id:`lm-studio`,name:`LM Studio`,widgets:!1},{id:`claude-ai`,name:`claude.ai`,widgets:!0,oauth:!0},{id:`chatgpt`,name:`ChatGPT`,widgets:!0,oauth:!0}],Jn={"claude-ai":{open:`https://claude.ai/settings/connectors`,where:`integrate.claudeAiWhere`,host:`claude.ai`},"claude-desktop":{where:`integrate.desktopWhere`,host:`claude.ai`},chatgpt:{where:`integrate.chatgptWhere`,host:`chatgpt.com`}};function H({text:e,muted:t}){let[n,r]=(0,B.useState)(!1);return(0,V.jsxs)(`div`,{className:M(`flex items-start gap-2 rounded-lg bg-paper-2 p-3`,t&&`text-ink-3 opacity-80`),children:[(0,V.jsx)(`code`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-all font-mono text-[0.75rem] leading-relaxed`,children:e}),(0,V.jsx)(j,{label:I(n?`settings.copied`:`settings.copy`),onClick:async()=>{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)},children:n?(0,V.jsx)(z,{className:`size-4`}):(0,V.jsx)(Gt,{className:`size-4`})})]})}function Yn(e){try{let t=new URL(e);return t.protocol===`https:`&&!/(^|\.)localhost$/.test(t.hostname)&&!/^(127\.|10\.|192\.168\.|\[::1\])/.test(t.hostname)}catch{return!1}}function U({children:e}){return(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3 leading-relaxed`,children:e})}function Xn({title:e,children:t}){return(0,V.jsxs)(`section`,{className:`flex flex-col gap-2.5 border-border-soft border-t pt-5 first:border-t-0 first:pt-0`,children:[(0,V.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:e}),t]})}var Zn=`https://github.com/engenty/engenty-wizards-wp-plugin/releases/latest/download/engenty-wizards.zip`;function Qn({managed:e}){return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight`,children:`WordPress`}),(0,V.jsx)(`p`,{className:`mt-1 text-[0.9375rem] text-ink-2`,children:I(`integrate.wpIntro`)})]}),(0,V.jsxs)(A,{className:`flex flex-col gap-5 p-5`,children:[(0,V.jsxs)(Xn,{title:I(`integrate.wpInstall`),children:[(0,V.jsx)(U,{children:I(`integrate.wpInstallHint`)}),(0,V.jsx)(`div`,{children:(0,V.jsx)(O,{variant:`secondary`,size:`sm`,onClick:()=>window.open(Zn,`_blank`),children:I(`integrate.wpDownload`)})})]}),(0,V.jsx)(Xn,{title:I(`integrate.wpConnect`),children:(0,V.jsx)(U,{children:I(e?`integrate.wpConnectHint`:`integrate.wpConnectLocal`)})}),(0,V.jsxs)(Xn,{title:I(`integrate.wpPlace`),children:[(0,V.jsx)(U,{children:I(`integrate.wpPlaceHint`)}),(0,V.jsx)(H,{text:`[engenty_wizard id="ID" mode="modal" label="${I(`integrate.wpSampleLabel`)}"]`})]}),(0,V.jsx)(Xn,{title:I(`integrate.wpPro`),children:(0,V.jsx)(U,{children:I(`integrate.wpProHint`)})}),(0,V.jsx)(Xn,{title:I(`integrate.wpLocal`),children:(0,V.jsx)(U,{children:I(`integrate.wpLocalHint`)})})]})]})}function $n(e,t){return JSON.stringify({[e]:{[Un]:t}},null,2)}function er({id:e,url:t,apiKey:n}){let r=n?`Authorization: Bearer ${n}`:null,i=n?{headers:{Authorization:`Bearer ${n}`}}:{};switch(e){case`claude-code`:{let e=t.replace(/\/api\/mcp$/,`/api/claude-plugin`);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`mcp.terminal`)}),(0,V.jsx)(H,{text:`claude mcp add --transport http --scope user ${Un} ${t}${r?` --header "${r}"`:``}`}),!n&&Yn(t)?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`mcp.ccPlugin`)}),(0,V.jsx)(H,{text:`claude plugin marketplace add ${e}/marketplace.json`}),(0,V.jsx)(H,{text:`claude plugin install ${Wn}@${Hn(t)}`})]}):null]})}case`codex`:return n?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`mcp.codexKey`)}),(0,V.jsx)(H,{text:`echo 'export ${Kn}=${n}' >> ~/.zshrc && source ~/.zshrc`}),(0,V.jsx)(H,{text:`codex mcp add ${Un} --url ${t} --bearer-token-env-var ${Kn}`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`mcp.terminal`)}),(0,V.jsx)(H,{text:`codex mcp add ${Un} --url ${t}`}),(0,V.jsx)(H,{text:`codex mcp login ${Un}`})]});case`antigravity`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`mcp.terminal`)}),(0,V.jsx)(H,{text:`agy mcp add${r?` -H "${r}"`:``} ${Un} ${t}`})]});case`cursor`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.file`,{file:`~/.cursor/mcp.json`})}),(0,V.jsx)(H,{text:$n(`mcpServers`,{url:t,...i})})]});case`vscode`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.vscode`)}),(0,V.jsx)(H,{text:$n(`servers`,{type:`http`,url:t,...i})})]});case`windsurf`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.file`,{file:`~/.codeium/windsurf/mcp_config.json`})}),(0,V.jsx)(H,{text:$n(`mcpServers`,{serverUrl:t,...i})})]});case`lm-studio`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.file`,{file:`~/.lmstudio/mcp.json`})}),(0,V.jsx)(H,{text:$n(`mcpServers`,{url:t,...i})})]});case`claude-desktop`:case`claude-ai`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`mcp.claudeAi`)}),(0,V.jsx)(H,{text:t})]});case`chatgpt`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.chatgpt`)}),(0,V.jsx)(H,{text:t})]});default:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.generic`)}),(0,V.jsx)(H,{text:t}),r?(0,V.jsx)(H,{text:r}):null]})}}function tr(){let e=f(),t=N({queryKey:[`api-keys`],queryFn:()=>r.get(`/api/studio/api-keys`)}),n=R({mutationFn:e=>r.del(`/api/studio/api-keys/${e}`),onSuccess:()=>e.invalidateQueries({queryKey:[`api-keys`]})});return t.data?.length?(0,V.jsxs)(`section`,{children:[(0,V.jsx)(`h2`,{className:`font-display font-semibold text-lg`,children:I(`mcp.keys`)}),(0,V.jsx)(`p`,{className:`mt-1 mb-4 text-[0.875rem] text-ink-3`,children:I(`mcp.keysHint`)}),(0,V.jsx)(A,{className:`flex flex-col gap-2 p-3`,children:t.data.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg px-3 py-2`,children:[(0,V.jsx)(ze,{className:`size-4 shrink-0 text-ink-4`}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.875rem]`,children:e.name}),(0,V.jsxs)(`div`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:[e.start,`… ·`,` `,e.lastRequest?I(`settings.lastUsed`,{when:new Date(e.lastRequest).toLocaleString(F)}):I(`settings.neverUsed`)]})]}),(0,V.jsx)(j,{label:I(`settings.revoke`),onClick:()=>n.mutate(e.id),className:`hover:text-rose`,children:(0,V.jsx)(qt,{className:`size-4`})})]},e.id))})]}):null}function nr(e,t){return t?.toolAt?`works`:e?.connected||t?`added`:`none`}var rr={works:`done`,added:`on`,none:void 0},ir={works:`integrate.stateWorks`,added:`integrate.stateAdded`,none:`integrate.stateNone`};function ar({standing:e}){return e===`none`?(0,V.jsx)(`span`,{className:`w-2 text-center text-ink-4 leading-none`,children:`–`}):(0,V.jsx)(`span`,{className:M(`size-2 shrink-0 rounded-full`,e===`works`?`bg-moss`:`bg-ember`)})}function or(){return(0,V.jsx)(`div`,{className:`mt-5 flex flex-col gap-1.5 rounded-lg bg-paper-2 px-3 py-2.5 text-[0.75rem] text-ink-3`,children:[`works`,`added`,`none`].map(e=>(0,V.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,V.jsx)(ar,{standing:e}),I(ir[e])]},e))})}function sr({client:e,signIn:t}){let n=(e,t)=>(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-card px-2.5 py-1 text-[0.8125rem] text-ink-2 ring-1 ring-border-soft`,children:[e,t]}),r=(0,V.jsx)(z,{className:`size-3.5 text-moss`,strokeWidth:3});return(0,V.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[n(r,I(`integrate.outRun`)),e.widgets?n(r,I(`integrate.outWidget`)):n((0,V.jsx)(dn,{className:`size-3.5 text-ink-3`}),I(`integrate.outText`)),t?n((0,V.jsx)(ct,{className:`size-3.5 text-ink-3`}),I(`integrate.outSignIn`)):null]})}function cr({client:e,works:t,children:n}){return(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight`,children:e.name}),t?(0,V.jsx)(E,{tone:`live`,icon:(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}),children:I(`integrate.works`)}):null]}),n]})}function W({n:e,state:t,title:n,children:r}){return(0,V.jsxs)(`li`,{"aria-current":t===`now`?`step`:void 0,className:M(`grid grid-cols-[28px_minmax(0,1fr)] gap-x-3.5 rounded-xl px-3 py-3`,t===`now`&&`bg-ember-tint/40 ring-1 ring-ember-strong/25`),children:[(0,V.jsx)(`span`,{className:M(`grid size-7 place-items-center rounded-full font-semibold text-[0.8125rem]`,t===`done`&&`bg-moss text-white`,(t===`now`||t===`todo`)&&`bg-primary text-primary-foreground`,t===`later`&&`bg-paper text-ink-3 ring-1 ring-border`),children:t===`done`?(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}):e}),(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 pt-1`,children:[(0,V.jsx)(`span`,{className:M(`font-medium text-[0.9375rem]`,t===`later`&&`text-ink-2`),children:n}),r?(0,V.jsx)(`div`,{className:M(`flex flex-col gap-2`,t===`later`&&`opacity-70`),children:r}):null]})]})}function lr({children:e}){return(0,V.jsxs)(A,{className:`p-3 sm:p-4`,children:[(0,V.jsx)(`h3`,{className:`px-3 pt-2 pb-2 font-medium text-[0.9375rem]`,children:I(`integrate.steps`)}),(0,V.jsx)(`ol`,{className:`flex flex-col gap-1`,children:e})]})}function ur({app:e}){return(0,V.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.8125rem] text-ember-strong`,children:[(0,V.jsx)(`span`,{className:`size-2 rounded-full bg-ember`}),I(`integrate.waiting`,{app:e})]})}function dr({client:e,seen:t}){let n=(e,t)=>(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[e?(0,V.jsx)(z,{className:`size-3.5 text-moss`,strokeWidth:3}):(0,V.jsx)(`span`,{className:`size-2.5 rounded-full ring-2 ring-ink-4 ring-inset`}),t]});return(0,V.jsxs)(`p`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-[0.8125rem] text-ink-2`,children:[n(!!t,I(`integrate.checkSeen`)),n(!!t?.toolAt,I(`integrate.checkTool`)),e.widgets?n(!!t?.widgetAt,I(`integrate.checkWidget`)):null]})}function fr(){let e=Dt().data,{space:t}=kt(),n=N({queryKey:[`wizards`,t?.id,!!e?.account],queryFn:()=>r.get(`/api/studio/spaces/${t.id}/wizards`),enabled:!!t}).data??[];return n.find(e=>e.published)??n[0]??null}function pr({client:e,footer:t}){let n=fr(),r=n?[{label:I(`integrate.labelRun`),text:I(`integrate.askRun`,{title:n.title})},{label:I(`integrate.labelBuild`),text:I(`integrate.askBuild`)},{label:I(`integrate.labelExplain`),text:I(`integrate.askExplain`,{title:n.title})}]:[{label:I(`integrate.labelAsk`),text:I(`integrate.askTool`)},{label:I(`integrate.labelBuild`),text:I(`integrate.askBuild`)}];return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(A,{className:`flex flex-col gap-4 p-5 sm:p-6`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:I(`integrate.next`)}),(0,V.jsx)(U,{children:I(`integrate.nextHint`,{app:e.name})})]}),(0,V.jsx)(`ul`,{className:`flex flex-col gap-2`,children:r.map(e=>(0,V.jsxs)(`li`,{className:`grid items-start gap-1 sm:grid-cols-[5.5rem_minmax(0,1fr)] sm:gap-3`,children:[(0,V.jsx)(`span`,{className:`pt-3 text-[0.75rem] text-ink-3`,children:e.label}),(0,V.jsx)(H,{text:e.text})]},e.label))})]}),e.widgets?null:(0,V.jsxs)(`p`,{className:`flex items-start gap-3 rounded-xl bg-paper-2 px-4 py-3 text-[0.875rem] text-ink-2 leading-relaxed`,children:[(0,V.jsx)(dn,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),I(`integrate.textOnly`,{app:e.name})]}),t]})}function mr({children:e}){return(0,V.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-[0.8125rem] text-ink-3`,children:e})}var hr=`inline-flex items-center gap-1 text-ember-strong underline-offset-2 transition hover:underline`;function gr({client:e,local:t,seen:n,url:i}){let a=f(),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(null),[d,p]=(0,B.useState)(!1),m=R({mutationFn:t=>r.post(`/api/studio/local/apps/${e.id}`,{connect:t}),onSuccess:e=>l(e),onError:e=>l({ok:!1,message:e.message}),onSettled:()=>a.invalidateQueries({queryKey:[`local-apps`]})}),h=!!t?.connected,g=!!n?.toolAt;if(o)return(0,V.jsx)(_r,{client:e,seen:n,url:i,onBack:()=>s(!1)});let _=t=>(0,V.jsxs)(V.Fragment,{children:[t?(0,V.jsx)(`span`,{children:I(`integrate.addedIn`,{app:e.name})}):null,(0,V.jsxs)(`button`,{type:`button`,className:hr,onClick:()=>p(!d),children:[I(`integrate.details`),(0,V.jsx)(u,{className:M(`size-3.5 transition`,d&&`rotate-90`)})]}),(0,V.jsx)(`button`,{type:`button`,className:hr,disabled:m.isPending,onClick:()=>m.mutate(!1),children:I(`mcp.appsDisconnect`)})]}),v=d&&t?.where?(0,V.jsx)(`p`,{className:`w-full font-mono text-[0.6875rem] text-ink-4`,children:t.where}):null;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:e,works:g,children:(0,V.jsx)(sr,{client:e})}),g?(0,V.jsx)(pr,{client:e,footer:(0,V.jsxs)(mr,{children:[_(!0),v]})}):(0,V.jsxs)(lr,{children:[(0,V.jsxs)(W,{n:1,state:h?`done`:`now`,title:I(h?`integrate.connected`:`integrate.connect`,{app:e.name}),children:[h?(0,V.jsxs)(mr,{children:[_(!1),v]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:t?.installed===!1?I(`integrate.notInstalled`,{app:e.name}):I(`integrate.connectHint`,{app:e.name})}),(0,V.jsx)(`div`,{children:(0,V.jsxs)(O,{busy:m.isPending,onClick:()=>m.mutate(!0),children:[(0,V.jsx)(Wt,{className:`size-4`}),` `,I(`integrate.connect`,{app:e.name})]})})]}),c&&!c.ok?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:c.message}):null,c?.snippet?(0,V.jsx)(H,{text:c.snippet}):null]}),(0,V.jsx)(W,{n:2,state:n?`done`:h?`now`:`later`,title:I(`integrate.restart`,{app:e.name}),children:n?null:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.restartHint`)}),h?(0,V.jsx)(ur,{app:e.name}):null]})}),(0,V.jsxs)(W,{n:3,state:n?`now`:`later`,title:I(`integrate.try`),children:[(0,V.jsx)(U,{children:I(`integrate.tryHint`)}),(0,V.jsx)(H,{text:I(`integrate.askTool`),muted:!n})]})]}),(0,V.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(cn,{className:`size-4 text-ink-3`}),I(`integrate.elsewhere`,{app:e.name}),(0,V.jsx)(`button`,{type:`button`,className:hr,onClick:()=>s(!0),children:I(`integrate.byAddress`)})]})]})}function _r({client:e,seen:t,url:n,onBack:i}){let a=f(),[o,s]=(0,B.useState)(),c=R({mutationFn:()=>r.post(`/api/studio/api-keys`,{name:e.name.slice(0,32)}),onSuccess:async e=>{s(e.key),await a.invalidateQueries({queryKey:[`api-keys`]})}}),l=(0,V.jsx)(`p`,{className:`text-[0.875rem]`,children:(0,V.jsxs)(`button`,{type:`button`,className:hr,onClick:i,children:[(0,V.jsx)(_e,{className:`size-4`}),I(`integrate.backHere`)]})});return t?.toolAt?(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:e,works:!0,children:(0,V.jsx)(sr,{client:e})}),(0,V.jsx)(pr,{client:e,footer:l})]}):(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:e,works:!1,children:(0,V.jsx)(sr,{client:e})}),(0,V.jsxs)(lr,{children:[(0,V.jsx)(W,{n:1,state:o?`done`:`now`,title:o?I(`integrate.keyReady`):I(`integrate.keyCreate`,{app:e.name}),children:o?null:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(U,{children:I(`integrate.keyHint`,{app:e.name})}),(0,V.jsx)(`div`,{children:(0,V.jsxs)(O,{variant:`secondary`,busy:c.isPending,onClick:()=>c.mutate(),children:[(0,V.jsx)(ze,{className:`size-4`}),` `,I(`integrate.keyCreate`,{app:e.name})]})})]})}),(0,V.jsx)(W,{n:2,state:o?t?`done`:`now`:`later`,title:I(`integrate.add`),children:o&&!t?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(er,{id:e.id,url:n,apiKey:o}),(0,V.jsx)(`p`,{className:`text-[0.75rem] text-ink-4`,children:I(`integrate.addressLocal`)}),(0,V.jsx)(ur,{app:e.name})]}):null}),(0,V.jsxs)(W,{n:3,state:t?`now`:`later`,title:I(`integrate.try`),children:[(0,V.jsx)(U,{children:I(`integrate.tryHint`)}),(0,V.jsx)(H,{text:I(`integrate.askTool`),muted:!t})]})]}),l]})}function vr({app:e,host:t}){return(0,V.jsxs)(`div`,{"aria-hidden":`true`,className:`flex w-56 shrink-0 flex-col items-center gap-2 rounded-xl bg-paper px-4 py-3.5 text-center ring-1 ring-border-soft`,children:[(0,V.jsx)(`span`,{className:`font-display font-semibold text-[0.8125rem] leading-snug`,children:I(`integrate.consentPreview`,{app:e})}),(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.6875rem] text-moss`,children:[(0,V.jsx)(ct,{className:`size-3`}),t]}),(0,V.jsxs)(`span`,{className:`flex w-full gap-1.5`,children:[(0,V.jsx)(`span`,{className:`h-5 flex-1 rounded-full bg-card ring-1 ring-border`}),(0,V.jsx)(`span`,{className:`h-5 flex-1 rounded-full bg-primary`})]})]})}function yr({client:e,url:t,seen:n,tracked:r,accountUrl:i}){let a=Jn[e.id]??Jn[`claude-desktop`],o=e.id===`chatgpt`?`ChatGPT`:`Claude`;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(lr,{children:[(0,V.jsx)(W,{n:1,state:`todo`,title:I(`integrate.open`,{app:e.name}),children:a.open?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsxs)(O,{onClick:()=>Le(a.open),children:[I(`integrate.openConnectors`),(0,V.jsx)(Ht,{className:`size-4`})]}),(0,V.jsx)(U,{children:I(a.where)})]}):(0,V.jsx)(U,{children:I(a.where)})}),(0,V.jsx)(W,{n:2,state:`todo`,title:I(`integrate.nameAddress`),children:(0,V.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:I(`integrate.name`)}),(0,V.jsx)(H,{text:Gn})]}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:I(`integrate.address`)}),(0,V.jsx)(H,{text:t})]})]})}),(0,V.jsx)(W,{n:3,state:n?`done`:`todo`,title:I(`integrate.allow`),children:n?null:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,V.jsx)(`p`,{className:`min-w-0 flex-[1_1_16rem] text-[0.875rem] text-ink-3 leading-relaxed`,children:I(`integrate.allowHint`)}),(0,V.jsx)(vr,{app:o,host:a.host})]})}),(0,V.jsxs)(W,{n:4,state:n?.toolAt?`done`:n?`now`:`later`,title:I(`integrate.try`),children:[n?.toolAt?null:(0,V.jsx)(H,{text:I(`integrate.askTool`),muted:!n}),r?(0,V.jsx)(dr,{client:e,seen:n}):null]})]}),i?(0,V.jsx)(br,{accountUrl:i}):null]})}function br({accountUrl:e}){return(0,V.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 text-[0.8125rem] text-ink-3`,children:[I(`integrate.revoke`),(0,V.jsxs)(`button`,{type:`button`,className:hr,onClick:()=>Le(e),children:[I(`integrate.revokeLink`),(0,V.jsx)(v,{className:`size-3.5`})]})]})}function xr({client:e,me:t,onDesktop:n}){let r=t.account?.signedIn?t.account:null,i=ge(!!r),a=Tt(t.features,`account`);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:e,works:!1,children:(0,V.jsx)(`p`,{className:`mt-2 max-w-2xl text-[0.9375rem] text-ink-2 leading-relaxed`,children:I(`integrate.remoteWhy`,{app:e.name})})}),r?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`p`,{className:`flex items-start gap-2 text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(ot,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),I(`integrate.linked`,{email:r.email,app:e.name})]}),(0,V.jsx)(yr,{client:e,url:`${r.cloudUrl}/api/mcp`,tracked:!1,accountUrl:r.url})]}):a?(0,V.jsxs)(A,{className:`flex flex-col gap-5 p-5 sm:p-6`,children:[(0,V.jsx)(`h3`,{className:`font-medium text-[0.9375rem]`,children:I(`integrate.viaAccount`)}),(0,V.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[{icon:_e,title:I(`integrate.tileHere`),text:I(`integrate.tileHereText`)},{icon:ot,title:`engenty.ai`,text:I(`integrate.tileCloudText`)},{icon:me,title:e.name,text:I(`integrate.tileAppText`)}].map(e=>(0,V.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl bg-paper px-4 py-3.5`,children:[(0,V.jsxs)(`span`,{className:`flex items-center gap-2 font-medium`,children:[(0,V.jsx)(e.icon,{className:`size-4 text-ink-2`}),e.title]}),(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:e.text})]},e.title))}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsxs)(O,{busy:i.link.isPending,onClick:()=>i.link.mutate({}),children:[(0,V.jsx)(ot,{className:`size-4`}),` `,I(`integrate.linkAccount`)]}),(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:I(`integrate.linkHint`,{app:e.name})})]}),(0,V.jsx)(je,{...i})]}):null,r?null:(0,V.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 rounded-xl bg-paper-2 px-4 py-3 text-[0.875rem] text-ink-2`,children:[I(`integrate.noAccount`),(0,V.jsxs)(`button`,{type:`button`,className:hr,onClick:n,children:[I(`integrate.useDesktop`),(0,V.jsx)(v,{className:`size-3.5`})]})]})]})}function Sr({client:e,seen:t,url:n,me:r}){let i=!!t?.toolAt,a=r.manageUrl?`${r.manageUrl}/account`:null;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:e,works:i,children:(0,V.jsx)(sr,{client:e,signIn:!0})}),i?(0,V.jsx)(pr,{client:e}):(0,V.jsxs)(lr,{children:[(0,V.jsx)(W,{n:1,state:t?`done`:`now`,title:I(`integrate.add`),children:t?null:(0,V.jsx)(er,{id:e.id,url:n})}),(0,V.jsx)(W,{n:2,state:t?`done`:`later`,title:I(`integrate.allowFirst`),children:t?null:(0,V.jsx)(U,{children:I(`integrate.allowFirstHint`,{app:e.name})})}),(0,V.jsx)(W,{n:3,state:t?`now`:`later`,title:I(`integrate.try`),children:(0,V.jsx)(H,{text:I(`integrate.askTool`),muted:!t})})]}),a?(0,V.jsx)(br,{accountUrl:a}):null]})}function Cr({client:e,standing:t,onOpen:n,onConnect:r,busy:i}){return(0,V.jsxs)(A,{className:`flex flex-col gap-3 p-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-[10px] bg-paper-2 text-ink-2`,children:e.widgets?(0,V.jsx)(nn,{className:`size-5`}):(0,V.jsx)(ke,{className:`size-5`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate font-medium`,children:e.name}),(0,V.jsxs)(`div`,{className:M(`flex items-center gap-1.5 text-[0.8125rem]`,t===`works`&&`font-medium text-moss`,t===`added`&&`text-ember-strong`,t===`none`&&`text-ink-3`),children:[t===`works`?(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}):null,I(ir[t])]})]})]}),(0,V.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[e.widgets?(0,V.jsx)(nn,{className:`size-3.5`}):(0,V.jsx)(dn,{className:`size-3.5`}),I(e.widgets?`integrate.outWidget`:`integrate.outText`)]}),(0,V.jsx)(`div`,{children:t===`none`&&r?(0,V.jsx)(O,{size:`sm`,variant:`secondary`,busy:i,onClick:r,children:I(`integrate.connectShort`)}):(0,V.jsx)(O,{size:`sm`,variant:t===`added`?`primary`:`secondary`,onClick:n,children:I(t===`works`?`integrate.view`:t===`added`?`integrate.testIt`:`integrate.connectShort`)})})]})}function wr({managed:e,here:t,web:n,standing:i,open:a}){let o=f(),s=R({mutationFn:e=>r.post(`/api/studio/local/apps/${e}`,{connect:!0}),onSettled:()=>o.invalidateQueries({queryKey:[`local-apps`]}),onSuccess:(e,t)=>a(t)}),c=(e,t)=>(0,V.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-[repeat(auto-fill,minmax(15rem,1fr))]`,children:e.map(e=>(0,V.jsx)(Cr,{client:e,standing:i(e.id),onOpen:()=>a(e.id),onConnect:t?()=>s.mutate(e.id):void 0,busy:s.isPending&&s.variables===e.id},e.id))});return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`font-display font-semibold text-[1.625rem] leading-tight tracking-tight`,children:I(`integrate.title`)}),(0,V.jsx)(`p`,{className:`mt-2 max-w-2xl text-[0.9375rem] text-ink-2 leading-relaxed`,children:I(e?`integrate.introManaged`:`integrate.intro`)})]}),e?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:I(`integrate.groupBrowser`)}),c(n,!1)]}),(0,V.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:I(`integrate.groupDesktop`)}),c(t,!1)]})]}):(0,V.jsxs)(V.Fragment,{children:[t.length?(0,V.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:I(`integrate.found`)}),c(t,!0)]}):null,(0,V.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`h3`,{className:`font-display font-semibold text-lg`,children:I(`integrate.groupCloud`)}),(0,V.jsxs)(A,{className:`flex flex-wrap items-center gap-4 p-5`,children:[(0,V.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-[10px] bg-paper-2 text-ink-2`,children:(0,V.jsx)(ot,{className:`size-5`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-[1_1_18rem]`,children:[(0,V.jsx)(`div`,{className:`font-medium`,children:I(`integrate.cloudTitle`)}),(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-relaxed`,children:I(`integrate.cloudText`)})]}),(0,V.jsx)(O,{variant:`secondary`,onClick:()=>a(`claude-ai`),children:I(`integrate.cloudButton`)})]})]})]})]})}function Tr(){let e=Dt(),t=e.data?.mode===`managed`,n=N({queryKey:[`local-apps`],queryFn:()=>r.get(`/api/studio/local/apps`),enabled:e.data?.mode===`local`}),i=N({queryKey:[`integrations-seen`],queryFn:()=>r.get(`/api/studio/integrations/seen`),refetchInterval:2500}),[o,s]=x(),{narrow:c}=zt(),l=Tt(e.data?.features,`wordpress`),u=l||o.get(`show`)!==`wordpress`?o.get(`show`):null,d=qn.find(e=>e.id===u)??null;if(Nt(u===`wordpress`?`WordPress`:d?.name??null),!e.data||!t&&!n.data)return null;let f=e=>n.data?.find(t=>t.id===e),p=e=>i.data?.[e],m=e=>nr(f(e),p(e)),h=e=>s({show:e},{replace:!c}),g=e=>!!(f(e.id)?.installed||f(e.id)?.connected),_=qn.filter(e=>e.oauth),v=qn.filter(e=>!e.oauth&&(t||g(e))),y=t?[]:qn.filter(e=>!e.oauth&&!g(e)),b=e.data.mcpUrl??``,S=e=>(0,V.jsx)(L,{icon:e.oauth?ot:e.widgets?nn:ke,label:e.name,tone:rr[m(e.id)],toneLabel:I(ir[m(e.id)]),selected:e.id===d?.id,onPick:()=>h(e.id)},e.id),C=e.data.manageUrl?`${e.data.manageUrl}/account`:null,w;return w=u===`wordpress`?(0,V.jsx)(Qn,{managed:t}):d?t&&(d.oauth||d.connector)?Yn(b)?(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:d,works:!!p(d.id)?.toolAt,children:(0,V.jsx)(sr,{client:d,signIn:!0})}),p(d.id)?.toolAt?(0,V.jsx)(pr,{client:d,footer:C?(0,V.jsx)(br,{accountUrl:C}):null}):(0,V.jsx)(yr,{client:d,url:b,seen:p(d.id),tracked:!0,accountUrl:C})]}):(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(cr,{client:d,works:!1}),(0,V.jsx)(U,{children:I(`integrate.needsPublic`,{app:d.name})})]}):t?(0,V.jsx)(Sr,{client:d,seen:p(d.id),url:b,me:e.data}):d.oauth?(0,V.jsx)(xr,{client:d,me:e.data,onDesktop:()=>h(`claude-desktop`)}):(0,V.jsx)(gr,{client:d,local:f(d.id),seen:p(d.id),url:b}):(0,V.jsx)(wr,{managed:t,here:v,web:_,standing:m,open:h}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-10`,children:[(0,V.jsxs)(It,{children:[(0,V.jsx)(Rt,{label:I(t?`integrate.groupBrowser`:`integrate.groupHere`),children:(t?_:v).map(S)}),(0,V.jsx)(Rt,{label:I(t?`integrate.groupDesktop`:`integrate.groupCloud`),children:(t?v:_).map(S)}),y.length?(0,V.jsx)(Rt,{label:I(`integrate.groupMore`),collapsible:!0,open:y.some(e=>e.id===d?.id),count:y.length,children:y.map(S)}):null,(0,V.jsxs)(Rt,{label:I(`integrate.groupShare`),children:[(0,V.jsx)(L,{icon:a,label:I(`integrate.shareLink`),badge:(0,V.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4`,children:I(`integrate.soon`)}),selected:!1,disabled:!0}),l?(0,V.jsx)(L,{icon:cn,label:`WordPress`,selected:u===`wordpress`,onPick:()=>h(`wordpress`)}):null,(0,V.jsx)(L,{icon:cn,label:I(`integrate.shareSite`),badge:(0,V.jsx)(`span`,{className:`text-[0.6875rem] text-ink-4`,children:I(`integrate.soon`)}),selected:!1,disabled:!0})]}),(0,V.jsx)(or,{})]}),(0,V.jsx)(`div`,{children:w},d?.id??`start`),t||u===`wordpress`?null:(0,V.jsx)(tr,{})]})}var Er=[`text`,`search`,`decision`],Dr={text:`models.cap.text`,search:`models.cap.search`,decision:`models.cap.decision`},Or=`curl -fsSL https://ollama.com/install.sh | sh`,kr=[`vision`,`audio`,`tools`],Ar=e=>Math.round(e/1e6).toLocaleString(F),jr=e=>e.toLocaleString(F,{maximumFractionDigits:1}),Mr=(e,t)=>e===t||e===`${t}:latest`||`${e}:latest`===t;function G({children:e,tone:t}){return(0,V.jsx)(`span`,{className:M(`inline-flex h-5 items-center rounded-full px-2 text-[0.6875rem]`,t===`done`?`bg-moss-tint text-moss`:`bg-paper-2 text-ink-3`),children:e})}function Nr({title:e,children:t}){return(0,V.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:e}),(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft rounded-xl border border-border-soft`,children:t})]})}function Pr({children:e,actions:t}){return(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-x-3 gap-y-2 px-3 py-2.5`,children:[(0,V.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:e}),(0,V.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:t})]})}function Fr({download:e}){return e.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:e.error===`ollama`?I(`models.local.downloadNoOllama`):I(`models.local.downloadFailed`,{error:e.error})}):(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2 tabular-nums`,children:e.total?I(`models.local.progress`,{done:Ar(e.done),total:Ar(e.total)}):I(`models.local.starting`)})}function Ir(e=!0){return N({queryKey:[`models`,`local`],queryFn:()=>r.get(`/api/studio/models/local`),enabled:e,refetchInterval:e=>e.state.data?.downloads.some(e=>!e.finished)||e.state.data?.ollama.start?.running?1500:!1})}function Lr({job:e,inUse:t,disabled:n,onChoose:i}){let a=f(),[o,s]=(0,B.useState)(``),[c,l]=(0,B.useState)(null),{data:u}=Ir(),d=e=>a.setQueryData([`models`,`local`],e),p=R({mutationFn:e=>r.post(`/api/studio/models/local/pull`,{model:e}),onSuccess:d}),m=R({mutationFn:e=>r.del(`/api/studio/models/local?model=${encodeURIComponent(e)}`),onSuccess:e=>{l(null),d(e)},onError:e=>l(e.message)}),h=R({mutationFn:()=>r.post(`/api/studio/models/local/ollama`,{}),onSuccess:d}),_=u?.installed.map(e=>e.name).join(` `);if((0,B.useEffect)(()=>{_!==void 0&&a.invalidateQueries({queryKey:[`models`],exact:!0})},[_,a]),!u)return null;let{ollama:v}=u;if(!v.version){let e=!!v.start?.running||h.isPending;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:v.installed?I(`models.local.ollamaStopped`):I(`models.local.noOllama`)}),v.installed||v.canInstall?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(O,{busy:e,disabled:n||e,onClick:()=>h.mutate(),children:v.installed?I(`models.local.startOllama`):I(`models.local.installOllama`)}),e?(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:I(`models.local.ollamaStarting`)}):null]}):(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[I(`models.local.ollamaLinux`),` `,(0,V.jsx)(`code`,{className:`font-mono text-[0.75rem]`,children:Or})]}),v.start?.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:I(`models.local.ollamaFailed`,{error:v.start.error})}):null]})}let b=e=>u.downloads.find(t=>Mr(t.model,e)),x=e=>{u.installed.some(t=>Mr(t.name,e))||p.mutate(e),i?.(e)},S=e?u.installed.filter(t=>t.jobs.includes(e)):u.installed,C=u.offered?.filter(t=>(!e||t.job===e)&&!t.installed)??null,w=new Set(Er.map(e=>C?.find(t=>t.job===e&&t.fits)?.name)),ee=u.downloads.filter(e=>!(S.some(t=>Mr(t.name,e.model))||C?.some(t=>t.name===e.model)));return(0,V.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,V.jsx)(Nr,{title:I(`models.local.here`,{version:v.version}),children:S.length?S.map(r=>{let a=t.some(e=>Mr(r.name,e));return(0,V.jsxs)(Pr,{actions:(0,V.jsxs)(V.Fragment,{children:[a?(0,V.jsx)(G,{tone:`done`,children:I(`models.local.inUse`)}):i?(0,V.jsx)(O,{variant:`secondary`,size:`sm`,disabled:n,onClick:()=>i(r.name),children:I(`models.local.use`)}):null,(0,V.jsx)(`button`,{type:`button`,className:`grid size-8 place-items-center rounded-lg text-ink-3 hover:bg-paper-2 hover:text-rose disabled:opacity-50`,title:I(`models.local.remove`),"aria-label":I(`models.local.remove`),disabled:n||a||m.isPending,onClick:async()=>await g(I(`models.local.removeConfirm`,{name:r.name,size:jr(r.size)}))&&m.mutate(r.name),children:(0,V.jsx)(qt,{className:`size-4`})})]}),children:[(0,V.jsx)(`span`,{className:`truncate font-mono text-[0.8125rem]`,children:r.name}),(0,V.jsxs)(`span`,{className:`flex flex-wrap gap-1`,children:[e?null:r.jobs.map(e=>(0,V.jsx)(G,{children:I(Dr[e])},e)),(0,V.jsx)(G,{children:I(`models.local.size`,{size:jr(r.size)})}),r.runner===`mlx`?(0,V.jsx)(G,{children:`MLX`}):null,kr.filter(e=>r.capabilities.includes(e)).map(e=>(0,V.jsx)(G,{children:I(`models.local.cap.${e}`)},e)),r.loaded?(0,V.jsx)(G,{tone:`done`,children:I(`models.local.loaded`)}):null]})]},r.name)}):(0,V.jsx)(`p`,{className:`px-3 py-2.5 text-[0.8125rem] text-ink-3`,children:I(`models.local.hereNone`)})}),c?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:c}):null,C===null?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`models.local.offeredNone`)}):C.length?(0,V.jsx)(Nr,{title:I(`models.local.offered`),children:C.map(t=>{let r=b(t.name),a=!(!r||r.finished);return(0,V.jsxs)(Pr,{actions:a&&r?(0,V.jsx)(Fr,{download:r}):(0,V.jsx)(O,{variant:w.has(t.name)?`primary`:`secondary`,size:`sm`,disabled:n,onClick:()=>x(t.name),children:I(i?`models.local.download`:`models.local.downloadOnly`)}),children:[(0,V.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`truncate font-mono text-[0.8125rem]`,children:t.name}),w.has(t.name)?(0,V.jsx)(G,{tone:`done`,children:I(`models.local.suggested`)}):null]}),(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:t.note[F===`de`?`de`:`en`]}),(0,V.jsxs)(`span`,{className:`flex flex-wrap gap-1`,children:[e?null:(0,V.jsx)(G,{children:I(Dr[t.job])}),(0,V.jsx)(G,{children:I(`models.local.size`,{size:jr(t.size)})}),t.fits?null:(0,V.jsx)(G,{children:I(`models.local.tooBig`,{memory:jr(t.memory)})})]}),r?.error?(0,V.jsx)(Fr,{download:r}):null]},t.name)})}):null,(0,V.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:I(`models.local.other`)}),(0,V.jsxs)(`form`,{className:`grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]`,onSubmit:e=>{e.preventDefault(),x(o.trim()),s(``)},children:[(0,V.jsx)(y,{className:`font-mono text-[0.8125rem]`,value:o,placeholder:I(`models.local.otherPlaceholder`),disabled:n,onChange:e=>s(e.target.value)}),(0,V.jsx)(O,{type:`submit`,variant:`secondary`,disabled:n||!o.trim(),children:I(i?`models.local.use`:`models.local.downloadOnly`)})]}),ee.map(e=>(0,V.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-mono text-[0.8125rem]`,children:e.model}),(0,V.jsx)(Fr,{download:e})]},e.model))]})]})}function K({title:e,aside:t,children:n}){return(0,V.jsxs)(`section`,{className:`flex flex-col gap-3 border-border-soft border-t pt-5 first:border-t-0 first:pt-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,V.jsx)(`h3`,{className:`font-medium text-[0.875rem]`,children:e}),t]}),n]})}function q({children:e}){return(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:e})}function Rr({text:e,tone:t}){return(0,V.jsxs)(`span`,{className:M(`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-full px-3 font-medium text-[0.75rem]`,t===`done`&&`bg-moss-tint text-moss`,t===`ok`&&`bg-amber-tint text-ink-2`,t===`warn`&&`bg-paper-2 text-ink-3`),children:[t===`done`?(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}):null,t===`ok`?(0,V.jsx)(rn,{className:`size-3.5`}):null,t===`warn`?(0,V.jsx)(Ke,{className:`size-3.5`}):null,e]})}function J({icon:e,title:t,lead:n,status:r}){return(0,V.jsxs)(`div`,{className:`flex items-start gap-3 sm:gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-xl bg-ember-tint text-ember-strong`,children:(0,V.jsx)(e,{className:`size-5`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,V.jsx)(`h2`,{className:`font-display font-semibold text-[1.375rem] leading-tight tracking-tight`,children:t}),r]}),(0,V.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:n})]})]})}var zr=[`model-accounts`],Br=[];function Vr(e){return N({queryKey:zr,enabled:e,queryFn:async()=>{let e=await r.get(`/api/studio/models/keys`);return e.kept.length&&(Br=e.kept),e}})}var Hr={bedrock:{mono:`AWS`,name:()=>`AWS Bedrock`,models:()=>`Claude, Mistral, Llama`},azure:{mono:`Az`,name:()=>`Microsoft Azure`,models:()=>`GPT`},mistral:{mono:`Mi`,name:()=>`Mistral`,models:()=>`Mistral`},anthropic:{mono:`An`,name:()=>`Anthropic`,models:()=>`Claude`},openai:{mono:`OA`,name:()=>`OpenAI`,models:()=>`GPT`},google:{mono:`G`,name:()=>`Google`,models:()=>`Gemini`},compat:{mono:`{ }`,name:()=>I(`keys.compat`),models:()=>I(`keys.compatModels`)},"ai-gateway":{mono:`AI`,name:()=>`Vercel AI Gateway`},fal:{mono:`fal`,name:()=>`fal.ai`},elevenlabs:{mono:`11`,name:()=>`ElevenLabs`}},Ur=[`bedrock`,`azure`,`mistral`,`anthropic`,`openai`,`google`,`compat`],Wr=e=>Hr[e]??{mono:e.slice(0,2).toUpperCase(),name:()=>e},Gr=e=>e.source===`compat`?e.label:Wr(e.source).name(),Kr=[{value:`eu-central-1`,label:`eu-central-1 · Frankfurt`},{value:`eu-west-3`,label:`eu-west-3 · Paris`},{value:`eu-north-1`,label:`eu-north-1 · Stockholm`},{value:`us-east-1`,label:`us-east-1 · N. Virginia`},{value:`us-west-2`,label:`us-west-2 · Oregon`}];function qr({source:e,large:t}){return(0,V.jsx)(`span`,{"aria-hidden":!0,className:M(`grid shrink-0 place-items-center bg-paper-2 font-semibold text-ink`,t?`size-[3.25rem] rounded-2xl text-[0.875rem]`:`size-10 rounded-xl text-[0.75rem]`),children:Wr(e).mono})}var Jr={ready:`keys.state.ready`,refused:`keys.state.refused`,resting:`keys.state.resting`};function Yr({status:e,pill:t}){return(0,V.jsxs)(`span`,{className:M(`inline-flex shrink-0 items-center gap-2 whitespace-nowrap text-[0.8125rem]`,t&&`h-7 rounded-full bg-paper-2 px-3 font-medium`,e===`ready`&&`text-moss`,e===`refused`&&`font-medium text-amber`,e===`resting`&&`text-ink-3`),children:[(0,V.jsx)(`i`,{"aria-hidden":!0,className:M(`size-2 rounded-full`,e===`ready`&&`bg-moss`,e===`refused`&&`bg-amber`,e===`resting`&&`bg-ink-4`)}),I(Jr[e])]})}function Xr(e,t){for(let n of e?.accounts??[]){let r=n.uses.find(e=>e.class===t);if(r)return{access:n.status===`refused`&&e?.fallback?I(`keys.fallback`):n.label,model:r.model}}return null}function Zr(e){let t=e.accounts.filter(e=>e.status===`refused`).length,n=e.accounts.filter(e=>e.status===`ready`).length;return{desc:e.accounts.length?`${e.accounts.map(e=>e.label).join(`, `)}.`:I(`overview.keys.admin`),status:t?I(`keys.nRefused`,{n:t}):e.accounts.length?I(`keys.nReady`,{n}):null}}function Qr({organization:e,canEdit:t,onOpen:n,tier:i,policy:a}){let o=Vr(!0),s=f(),[c,l]=(0,B.useState)(!1),[d,p]=(0,B.useState)(Br),m=R({mutationFn:e=>r.patch(`/api/studio/models/keys`,{fallback:e}),onSuccess:({fallback:e})=>s.setQueryData(zr,t=>t&&{...t,fallback:e})}),h=o.data,g=h?.accounts??[];return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-[1_1_20rem]`,children:[(0,V.jsx)(`h1`,{className:`font-display font-semibold text-[1.625rem] leading-tight tracking-tight`,children:I(`policy.ownKeys`)}),(0,V.jsx)(`p`,{className:`mt-1.5 text-[0.9375rem] text-ink-2`,children:I(`keys.lead`)})]}),t?(0,V.jsx)(O,{onClick:()=>l(!0),children:I(`keys.add`)}):null]}),d.length?(0,V.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl bg-amber-tint px-4 py-3 text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(`span`,{className:`flex-1`,children:I(`keys.kept`,{keys:d.map(e=>e.reason===`unsupported`?`${e.name} (${I(`keys.keptUnsupported`)})`:e.message?`${e.name} (${e.message})`:e.name).join(`, `)})}),(0,V.jsx)(j,{label:I(`common.close`),onClick:()=>{Br=[],p([])},className:`-my-1.5 -mr-2`,children:(0,V.jsx)(Kt,{className:`size-4`})})]}):null,o.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:o.error.message}):h?(0,V.jsx)(A,{className:`overflow-hidden p-0`,children:g.length?g.map(e=>(0,V.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),className:`flex w-full items-center gap-3.5 border-border-soft border-t px-4 py-3.5 text-left transition first:border-t-0 hover:bg-accent/60 sm:px-5`,children:[(0,V.jsx)(qr,{source:e.source}),(0,V.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`b`,{className:`block truncate font-medium text-[0.875rem]`,children:e.label}),(0,V.jsx)(`span`,{className:`block truncate text-[0.8125rem] text-ink-3`,children:[Wr(e.source).name(),e.place].filter(Boolean).join(` · `)})]}),(0,V.jsx)(Yr,{status:e.status}),(0,V.jsx)(u,{className:`size-4 shrink-0 text-ink-4`})]},e.id)):(0,V.jsx)(`div`,{className:`px-4 py-5 sm:px-5`,children:(0,V.jsx)(q,{children:I(`keys.empty`)})})}):null,t&&a?a:null,t&&h?(0,V.jsxs)(A,{className:`flex items-center gap-3.5 px-4 py-3.5 sm:px-5`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`b`,{className:`block font-medium text-[0.875rem]`,children:I(`keys.fallback`)}),(0,V.jsx)(`span`,{className:`block text-[0.8125rem] text-ink-3`,children:I(`keys.fallbackHint`)}),m.isError?(0,V.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-rose`,children:m.error.message}):null]}),(0,V.jsx)(T,{checked:m.isPending?!!m.variables:h.fallback,disabled:m.isPending,onChange:e=>m.mutate(e),label:I(`keys.fallback`)})]}):null,t?null:(0,V.jsx)(q,{children:I(`keys.membersNote`,{organization:e})}),(0,V.jsx)(ni,{open:c,onClose:()=>l(!1),tier:i})]})}function $r({id:e,canEdit:t,onGone:n}){let i=Vr(!0),a=f(),[o,s]=(0,B.useState)(!1),c=R({mutationFn:()=>r.del(`/api/studio/models/keys/${encodeURIComponent(e)}`),onSuccess:()=>{a.invalidateQueries({queryKey:zr}),a.invalidateQueries({queryKey:[`models`]}),n()}}),l=i.data?.accounts.find(t=>t.id===e);if(!l)return i.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:i.error.message}):i.data?(0,V.jsx)(q,{children:I(`keys.gone`)}):null;let u=Gr(l),d=l.status===`refused`,p=new Date().toLocaleString(F,{month:`long`}),m=new Intl.NumberFormat(F,{style:`currency`,currency:`USD`,maximumFractionDigits:l.month.usd<10?2:0}).format(l.month.usd);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,V.jsx)(qr,{source:l.source,large:!0}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-[1_1_16rem]`,children:[(0,V.jsx)(`h1`,{className:`truncate font-display font-semibold text-[1.625rem] leading-tight tracking-tight`,children:l.label}),(0,V.jsx)(`p`,{className:`mt-0.5 text-[0.875rem] text-ink-3`,children:[Wr(l.source).name(),l.place,I(`keys.keyEnd`,{hint:l.keyHint})].filter(Boolean).join(` · `)})]}),(0,V.jsx)(Yr,{status:l.status,pill:!0})]}),d?(0,V.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-3.5 rounded-xl bg-amber-tint px-4 py-3.5 ring-1 ring-amber/35 sm:px-5`,children:[(0,V.jsxs)(`p`,{className:`min-w-0 flex-[1_1_18rem] text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(`b`,{className:`font-semibold text-ink`,children:I(`keys.refusedBy`,{provider:u})}),` `,I(i.data?.fallback?`keys.refusedFallback`:`keys.refusedNoFallback`),l.error?(0,V.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:l.error}):null]}),t?(0,V.jsx)(O,{size:`sm`,onClick:()=>s(!0),children:I(`keys.replace`)}):null]}):null,(0,V.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`font-semibold text-[1rem]`,children:I(`keys.runsHere`)}),(0,V.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:l.month.calls?I(`keys.month`,{month:p,calls:l.month.calls.toLocaleString(F),usd:m,provider:u}):I(`keys.monthNone`,{month:p})})]}),l.uses.length?(0,V.jsx)(A,{className:`overflow-hidden p-0`,children:l.uses.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3.5 border-border-soft border-t px-4 py-3 text-[0.875rem] first:border-t-0 sm:px-5`,children:[(0,V.jsx)(`b`,{className:`min-w-0 flex-1 font-medium`,children:et(e.class)}),(0,V.jsx)(`span`,{className:M(`text-right`,d?`text-amber`:`text-ink-2`),children:d?I(`keys.withCredits`,{model:e.model}):e.model})]},e.class))}):(0,V.jsx)(q,{children:I(`keys.nothingRuns`)})]}),t?(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[d?null:(0,V.jsx)(O,{variant:`quiet`,size:`sm`,onClick:()=>s(!0),children:I(`keys.replace`)}),(0,V.jsx)(O,{variant:`danger`,size:`sm`,busy:c.isPending,onClick:async()=>{await g(I(`keys.removeAsk`,{name:l.label}),{detail:I(`keys.removeDetail`),action:I(`common.remove`)})&&c.mutate()},children:I(`common.remove`)}),c.isError?(0,V.jsx)(`p`,{className:`w-full text-[0.8125rem] text-rose`,children:c.error.message}):null]}):null,(0,V.jsx)(ni,{open:o,onClose:()=>s(!1),account:l})]})}var ei={region:`eu-central-1`,baseUrl:``,key:``,deployments:``,confirmed:!1};function ti(e,t){switch(e){case`bedrock`:return{region:t.region};case`azure`:return{baseUrl:t.baseUrl.trim(),deployments:t.deployments.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>({deployment:e})),noAbuseLog:t.confirmed};case`compat`:return{baseUrl:t.baseUrl.trim(),euServers:t.confirmed,noRetention:t.confirmed};default:return}}function ni({open:e,onClose:t,account:n,tier:a}){let o=f(),[s,c]=(0,B.useState)(n?`form`:`pick`),[l,u]=(0,B.useState)(n?.source??Ur[0]),[d,m]=(0,B.useState)(ei),h=R({mutationFn:()=>n?r.patch(`/api/studio/models/keys/${encodeURIComponent(n.id)}`,{key:d.key.trim()}):r.post(`/api/studio/models/keys`,{source:l,label:Wr(l).name(),key:d.key.trim(),settings:ti(l,d)}),onSuccess:()=>{o.invalidateQueries({queryKey:zr}),o.invalidateQueries({queryKey:[`models`]}),c(`done`)}}),g=()=>{t(),c(n?`form`:`pick`),m(ei),h.reset()},v=e=>m(t=>({...t,...e})),b=(0,B.useRef)(null);(0,B.useEffect)(()=>{e&&s===`form`&&b.current?.querySelector(`input, select`)?.focus()},[e,s]);let x=n?n.label:Wr(l).name(),S=!n&&(l===`azure`||l===`compat`),w=d.key.trim().length>0&&(!S||/^https:\/\/\S+$/.test(d.baseUrl.trim()))&&(n||l!==`azure`||d.deployments.trim().length>0),ee=h.data;return(0,V.jsx)(_,{open:e,onClose:g,wide:!0,bare:!0,children:(0,V.jsxs)(`div`,{role:`document`,className:`mx-auto flex h-[min(37.5rem,calc(100dvh-32px))] w-full max-w-[35rem] flex-col overflow-hidden rounded-2xl bg-card shadow-overlay max-sm:h-dvh max-sm:max-w-none max-sm:rounded-none`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 border-border-soft border-b py-3 pr-3 pl-5`,children:[s===`form`&&!n?(0,V.jsx)(j,{label:I(`common.back`),onClick:()=>c(`pick`),className:`-ml-2`,children:(0,V.jsx)(i,{className:`size-[1.125rem]`})}):null,(0,V.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1.125rem]`,children:s===`pick`?I(`keys.add`):x}),(0,V.jsx)(j,{label:I(`common.close`),onClick:g,children:(0,V.jsx)(Kt,{className:`size-[1.125rem]`})})]}),(0,V.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-5`,children:s===`pick`?(0,V.jsx)(`div`,{className:`flex flex-col gap-1`,children:Ur.map(e=>(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":e===l,onClick:()=>u(e),className:M(`flex items-center gap-3 rounded-xl px-3 py-2.5 text-left transition`,e===l?`bg-paper-2 ring-1 ring-ember ring-inset`:`hover:bg-accent`),children:[(0,V.jsx)(qr,{source:e}),(0,V.jsx)(`b`,{className:`min-w-0 flex-1 font-medium text-[0.875rem]`,children:Wr(e).name()}),(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:Wr(e).models?.()})]},e))}):s===`form`?(0,V.jsxs)(`form`,{ref:b,id:`add-key`,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),w&&!h.isPending&&h.mutate()},children:[!n&&l===`bedrock`?(0,V.jsx)(ii,{label:I(`keys.region`),children:(0,V.jsx)(C,{value:d.region,onChange:e=>v({region:e}),options:Kr})}):null,S?(0,V.jsx)(ii,{label:I(l===`azure`?`keys.endpoint`:`keys.address`),children:(0,V.jsx)(y,{type:`url`,value:d.baseUrl,onChange:e=>v({baseUrl:e.target.value}),placeholder:l===`azure`?`https://…openai.azure.com`:`https://…/v1`})}):null,(0,V.jsx)(ii,{label:I(`keys.apiKey`),hint:ri(n?.source??l,x),children:(0,V.jsx)(y,{type:`password`,autoComplete:`off`,value:d.key,onChange:e=>v({key:e.target.value})})}),!n&&l===`azure`?(0,V.jsx)(ii,{label:I(`keys.deployments`),hint:I(`keys.deploymentsHint`),children:(0,V.jsx)(y,{value:d.deployments,onChange:e=>v({deployments:e.target.value}),placeholder:`gpt-5.5, gpt-5.4-mini`})}):null,S?(0,V.jsxs)(`label`,{className:`flex items-start gap-2.5 text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:d.confirmed,onChange:e=>v({confirmed:e.target.checked}),className:`mt-0.5 size-4 shrink-0 accent-ember`}),I(l===`azure`?`keys.azureCheck`:`keys.compatCheck`)]}):null,h.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:h.error instanceof p&&h.error.body?.code===`key_refused`?I(`keys.refusedError`,{provider:x,error:h.error.message}):h.error.message}):null]}):ee?(0,V.jsx)(ai,{account:ee,tier:a??null}):null}),(0,V.jsx)(`div`,{className:`flex justify-end gap-2.5 border-border-soft border-t px-5 py-3.5`,children:s===`pick`?(0,V.jsx)(O,{onClick:()=>c(`form`),children:I(`keys.next`)}):s===`form`?(0,V.jsx)(O,{type:`submit`,form:`add-key`,disabled:!w,busy:h.isPending,children:I(`keys.save`)}):(0,V.jsx)(O,{onClick:g,children:I(`keys.done`)})})]})})}function ri(e,t){return e===`bedrock`||e===`azure`||e===`compat`?I(`keys.keyHint.${e}`):I(`keys.keyHint`,{provider:t})}function ii({label:e,hint:t,children:n}){return(0,V.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.8125rem] text-ink`,children:e}),n,t?(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:t}):null]})}function ai({account:e,tier:t}){let n=e.status===`resting`||e.passing===0?t?I(`keys.restsTier`,{provider:Gr(e),tier:t.name}):I(`keys.rests`):e.uses.length?I(`keys.usesNow`):I(`keys.usesNone`);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`flex flex-col items-center gap-2.5 px-2 pt-6 pb-2 text-center`,children:[(0,V.jsx)(`span`,{className:`grid size-14 place-items-center rounded-full bg-moss-tint text-moss`,children:(0,V.jsx)(z,{className:`size-6`,strokeWidth:2.6})}),(0,V.jsx)(`h3`,{className:`mt-1.5 font-display font-semibold text-[1.125rem]`,children:I(`keys.saved`)}),(0,V.jsx)(`p`,{className:`max-w-[25rem] text-[0.875rem] text-ink-2`,children:n})]}),e.status!==`resting`&&e.uses.length?(0,V.jsx)(A,{className:`overflow-hidden p-0`,children:e.uses.map(e=>(0,V.jsxs)(`div`,{className:`flex justify-between gap-3 border-border-soft border-t px-4 py-3 text-[0.875rem] first:border-t-0`,children:[(0,V.jsx)(`b`,{className:`font-medium`,children:et(e.class)}),(0,V.jsx)(`span`,{className:`text-ink-3`,children:e.model})]},e.class))}):null]})}function oi({where:e,className:t}){return e?(0,V.jsx)(e===`pc`?Pe:ot,{role:`img`,"aria-label":I(e===`pc`?`overview.onComputer`:`overview.inCloud`),className:M(`size-4 shrink-0 text-ink-3`,t)}):null}function si({missing:e,small:t}){return(0,V.jsxs)(`span`,{className:M(`inline-flex shrink-0 items-center gap-2 rounded-full font-medium`,t?`h-6 px-2.5 text-[0.75rem]`:`h-7 px-3 text-[0.8125rem]`,e?`bg-amber-tint text-ink-2`:`bg-moss-tint text-moss`),children:[(0,V.jsx)(`i`,{className:M(`size-2 rounded-full`,e?`bg-amber`:`bg-moss`),"aria-hidden":!0}),e?I(e===1?`overview.missingOne`:`overview.missing`,{n:e}):I(`overview.allReady`)]})}function ci({state:e}){let t=I(e===`ok`?`overview.state.ok`:e===`miss`?`overview.missingWord`:`overview.state.na`);return(0,V.jsx)(`span`,{role:`img`,title:t,"aria-label":t,className:M(`size-2 shrink-0 rounded-full`,e===`ok`&&`bg-moss`,e===`miss`&&`bg-amber`,e===`na`&&`ring-1 ring-ink-4 ring-inset`)})}function li({hero:e}){let t=e.where===`pc`?Pe:ot;return(0,V.jsxs)(A,{className:`overflow-hidden p-0`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 p-4 sm:p-5`,children:[(0,V.jsx)(`span`,{className:`grid size-12 shrink-0 place-items-center rounded-xl bg-paper-2 text-ink`,children:(0,V.jsx)(t,{className:`size-6`})}),(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_16rem] flex-col gap-0.5`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.6875rem] text-ink-3 uppercase tracking-[0.12em]`,children:I(`overview.runsWith`)}),(0,V.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`b`,{className:`font-display font-semibold text-[1.25rem] leading-tight`,children:e.name}),e.plan?(0,V.jsx)(`span`,{className:`rounded-full bg-paper-2 px-2 py-0.5 font-medium text-[0.6875rem] text-ink-2`,children:I(`overview.plan`,{plan:e.plan})}):null]}),(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:e.sub})]}),(0,V.jsx)(si,{missing:e.missing})]}),e.helpers.length?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-border-soft border-t bg-paper-2/50 px-4 py-3 sm:px-5`,children:[(0,V.jsx)(`span`,{className:`mr-1 font-medium text-[0.6875rem] text-ink-3 uppercase tracking-[0.12em]`,children:I(`overview.helpedBy`)}),e.helpers.map(e=>(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-paper-2 px-2.5 py-1 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(oi,{where:e.where,className:`size-3.5`}),(0,V.jsx)(`b`,{className:`font-medium text-ink`,children:e.name}),e.jobs]},e.name))]}):null]})}function ui({options:e,locked:t,disabled:n,onPick:r}){return(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:e.map(e=>{let i=e.disabled||(t||n)&&!e.on;return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":e.on,disabled:i||n,onClick:()=>r(e.id),className:M(`flex flex-col gap-2 rounded-xl border p-4 text-left transition`,e.on?`border-ember bg-card ring-1 ring-ember`:`border-border-soft bg-card hover:border-ink-4`,i&&`cursor-default bg-paper-2/60 hover:border-border-soft`),children:[(0,V.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,V.jsx)(`span`,{className:M(`size-4 shrink-0 rounded-full border`,e.on?`border-[5px] border-ember`:`border-ink-4`)}),(0,V.jsx)(`b`,{className:M(`font-medium text-[0.9375rem]`,i&&`text-ink-3`),children:e.name}),e.tag?(0,V.jsx)(`span`,{className:`ml-auto rounded-full bg-paper-2 px-2 py-0.5 font-medium text-[0.6875rem] text-ink-2`,children:e.tag}):null]}),(0,V.jsx)(`span`,{className:M(`text-[0.8125rem]`,i?`text-ink-4`:`text-ink-2`),children:e.desc})]},e.id)})}),t?(0,V.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(ct,{className:`size-3.5`}),I(`overview.scopeLocked`)]}):null]})}function di({job:e}){return(0,V.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:e.onOpen,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e.onOpen())},className:`grid cursor-pointer grid-cols-[minmax(0,1fr)_1rem] items-center gap-x-3.5 gap-y-1.5 border-border-soft border-t px-4 py-3.5 transition first:border-t-0 hover:bg-accent/60 sm:grid-cols-[minmax(0,1.3fr)_minmax(0,1fr)_minmax(0,1fr)_1rem] sm:px-5`,children:[(0,V.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,V.jsx)(`span`,{className:`mt-[0.4rem] flex`,children:(0,V.jsx)(ci,{state:e.state})}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`b`,{className:`block font-medium text-[0.875rem]`,children:e.name}),(0,V.jsx)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:e.purpose})]})]}),(0,V.jsx)(u,{className:`col-start-2 row-start-1 size-4 text-ink-4 sm:col-start-4`}),e.state===`ok`?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-[0.8125rem] text-ink-2 sm:col-start-2 sm:row-start-1`,children:[(0,V.jsx)(oi,{where:e.where}),(0,V.jsx)(`span`,{className:`truncate`,children:e.access})]}),(0,V.jsx)(`span`,{className:`truncate text-[0.875rem] sm:col-start-3 sm:row-start-1`,children:e.model})]}):e.state===`miss`?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`sm:col-start-2 sm:row-start-1`,children:(0,V.jsx)(`span`,{className:`rounded-full bg-amber-tint px-2.5 py-0.5 font-medium text-[0.75rem] text-amber`,children:I(`overview.missingWord`)})}),(0,V.jsx)(`span`,{className:`sm:col-start-3 sm:row-start-1`,children:(0,V.jsx)(O,{size:`sm`,onClick:t=>{t.stopPropagation(),e.onOpen()},children:I(`overview.setUp`)})})]}):(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 sm:col-span-2 sm:col-start-2 sm:row-start-1`,children:e.naText})]})}function fi({title:e,desc:t,jobs:n}){return(0,V.jsxs)(A,{className:`overflow-hidden p-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3 border-border-soft border-b bg-paper-2/50 px-4 pt-3 pb-2 sm:px-5`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`b`,{className:`block font-semibold text-[0.75rem] text-ink-2 uppercase tracking-[0.08em]`,children:e}),(0,V.jsx)(`span`,{className:`block text-[0.8125rem] text-ink-3`,children:t})]}),(0,V.jsx)(si,{small:!0,missing:n.filter(e=>e.state===`miss`).length})]}),n.map(e=>(0,V.jsx)(di,{job:e},e.id))]})}function pi({rows:e}){return(0,V.jsx)(A,{className:`overflow-hidden p-0`,children:e.map(e=>e.kind===`label`?(0,V.jsx)(`div`,{className:`border-border-soft border-t px-4 pt-3.5 pb-0.5 font-medium text-[0.6875rem] text-ink-3 uppercase tracking-[0.12em] first:border-t-0 sm:px-5`,children:e.label},`label-${e.label}`):(0,V.jsxs)(`div`,{className:`flex items-center gap-3.5 border-border-soft border-t px-4 py-3.5 first:border-t-0 sm:px-5`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[e.onOpen?(0,V.jsx)(`button`,{type:`button`,onClick:e.onOpen,className:`block text-left font-medium text-[0.875rem] hover:text-ember-strong`,children:e.name}):(0,V.jsx)(`b`,{className:`block font-medium text-[0.875rem]`,children:e.name}),(0,V.jsx)(`span`,{className:`block text-[0.8125rem] text-ink-3`,children:e.desc}),e.note?(0,V.jsxs)(`span`,{className:`mt-1.5 flex items-start gap-1.5 text-[0.75rem] text-ink-2`,children:[(0,V.jsx)(Ee,{className:`mt-px size-3.5 shrink-0 text-ink-3`}),e.note]}):null]}),e.status?(0,V.jsx)(`span`,{className:M(`shrink-0 text-right text-[0.8125rem]`,e.muted?`text-ink-3`:`text-ink-2`),children:e.status}):null,e.value?(0,V.jsx)(`span`,{className:`shrink-0 rounded-full bg-paper-2 px-2.5 py-1 font-medium text-[0.8125rem]`,children:e.value}):null,e.button?(0,V.jsx)(O,{size:`sm`,variant:e.button.primary?`primary`:`quiet`,onClick:e.button.onClick,children:e.button.label}):null,e.toggle?(0,V.jsx)(T,{checked:e.toggle.on,disabled:e.toggle.disabled,onChange:e.toggle.onChange,label:e.name}):null]},e.id))})}function mi({title:e,lead:t,children:n}){return(0,V.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`font-semibold text-[1rem]`,children:e}),t?(0,V.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:t}):null]}),n]})}var hi={models:null,default:null,effortCap:null,efforts:null},gi={way:`A`,purposes:{wizard:hi,assistant:hi,work:hi},credits:!0,ownKeys:!0,subscriptions:!0,localModels:!0,apps:{local:!0,subscriptions:!0},masking:!1,maskInstructions:``,maskLabels:[]};function _i(){return vt().workMode===!0?[`wizard`,`assistant`,`work`]:[`wizard`,`assistant`]}var vi={wizard:ce,assistant:d,work:me};function yi(){let e=f();return R({mutationFn:e=>r.put(`/api/studio/model-policy`,e),onSuccess:t=>e.setQueryData([`models`],t)})}function bi(e){return I(`policy.wayShort.${e}`)}function xi({children:e}){return(0,V.jsxs)(`span`,{className:`inline-flex h-6 items-center gap-1 rounded-full bg-paper-2 px-2.5 text-[0.75rem] text-ink-3`,children:[(0,V.jsx)(ct,{className:`size-3`}),e]})}function Si({icon:e,title:t,hint:n,checked:r,locked:i,note:a,warn:o,disabled:s,onChange:c}){return(0,V.jsxs)(`div`,{className:M(`flex items-start gap-3 border-border-soft border-t py-3 first:border-t-0`,i&&`-mx-3 rounded-lg bg-paper-2/60 px-3`),children:[(0,V.jsx)(`span`,{className:`grid size-8 shrink-0 place-items-center rounded-lg bg-paper-2 text-ink-3`,children:(0,V.jsx)(e,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:t}),i?(0,V.jsx)(xi,{children:i}):null,a?(0,V.jsx)(`span`,{className:`inline-flex h-6 items-center rounded-full bg-cobalt-tint px-2.5 text-[0.75rem] text-cobalt`,children:a}):null]}),(0,V.jsxs)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:[n,o?(0,V.jsxs)(`span`,{className:`font-medium text-amber`,children:[` `,o]}):null]})]}),(0,V.jsx)(T,{checked:r&&!i,disabled:s||!!i,onChange:c,label:t})]})}function Ci({tier:e,policy:t,organization:n,canEdit:r}){let i=yi(),a=i.isPending&&i.variables?i.variables:t;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsx)(J,{icon:pe,title:I(`policy.way`),lead:I(`policy.wayLead`,{organization:n??I(`policy.yourOrganization`),tier:e.name}),status:(0,V.jsx)(Oi,{way:a.way})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-5 sm:p-6`,children:[(0,V.jsx)(K,{title:I(`policy.whoPicks`),children:(0,V.jsx)(`div`,{className:`grid gap-2.5 sm:grid-cols-3`,children:[`A`,`B`,`C`].map(e=>(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":a.way===e,disabled:!r,onClick:()=>i.mutate({...a,way:e}),className:M(`flex flex-col gap-1.5 rounded-xl border p-4 text-left transition`,a.way===e?`border-ember ring-1 ring-ember`:`border-border-soft hover:border-ink-4`,!r&&`cursor-default hover:border-border-soft`),children:[(0,V.jsxs)(`span`,{className:`flex items-center justify-between`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.75rem] text-ink-3`,children:e}),(0,V.jsx)(`span`,{className:M(`size-4 rounded-full border`,a.way===e?`border-[5px] border-ember`:`border-ink-4`)})]}),(0,V.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:I(`policy.way.${e}`)}),(0,V.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:I(`policy.way.${e}.hint`)})]},e))})}),i.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:i.error.message}):null]})]})}var wi={ownKeys:ze,subscriptions:Ce,localModels:Pe};function Ti({tier:e,policy:t,field:n,canEdit:r}){let i=yi(),a=i.isPending&&i.variables?i.variables:t,o=Re(e),s=o&&n===`ownKeys`?I(`policy.ownKeys.warn`,{tier:e.name}):o&&n===`subscriptions`?I(`policy.subscriptions.warn`):null;return(0,V.jsxs)(A,{className:`flex flex-col gap-3 p-5 sm:p-6`,children:[(0,V.jsx)(Si,{icon:wi[n],title:I(`policy.${n}`),hint:I(`policy.${n}.hint`),checked:a[n],warn:s,disabled:!r,onChange:e=>i.mutate({...a,[n]:e})}),i.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:i.error.message}):null]})}function Ei({tier:e,policy:t,canEdit:n}){let r=yi(),i=r.isPending&&r.variables?r.variables:t,a=e=>r.mutate({...i,...e});return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsx)(J,{icon:$e,title:I(`overview.menu.masking`),lead:I(`overview.maskingLead`)}),(0,V.jsxs)(A,{className:`flex flex-col gap-3 p-5 sm:p-6`,children:[(0,V.jsx)(Si,{icon:$e,title:I(`policy.masking`),hint:I(`policy.masking.hint`),checked:i.masking,note:e.rules.regions?I(`policy.recommendedOn`,{tier:e.name}):null,disabled:!n,onChange:e=>a({masking:e})}),i.masking?(0,V.jsx)(Di,{policy:t,shown:i,canEdit:n,set:a}):null,r.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null]})]})}function Di({policy:e,shown:t,canEdit:n,set:i}){let[a,o]=(0,B.useState)(e.maskInstructions),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(``);(0,B.useEffect)(()=>o(e.maskInstructions),[e.maskInstructions]);let d=R({mutationFn:e=>r.post(`/api/studio/model-policy/try`,{text:e,maskLabels:t.maskLabels})}),f=t.maskLabels,p=()=>{let e=s.trim().toLowerCase().replace(/\s+/g,` `);e&&!f.includes(e)&&f.length<20&&i({maskLabels:[...f,e]}),c(``)};return(0,V.jsxs)(`div`,{className:`flex flex-col gap-4 border-border-soft border-t py-4`,children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:I(`policy.maskWhat`)}),(0,V.jsx)(q,{children:I(`policy.maskWhat.hint`)}),(0,V.jsx)(m,{minRows:2,maxLength:ft,value:a,disabled:!n,placeholder:I(`policy.maskWhat.placeholder`),onChange:e=>o(e.target.value)}),n&&a.trim()!==t.maskInstructions.trim()?(0,V.jsx)(`div`,{children:(0,V.jsx)(O,{size:`sm`,onClick:()=>i({maskInstructions:a.trim()}),children:I(`policy.maskWhat.save`)})}):null]}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:I(`policy.maskLabels`)}),(0,V.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:f.length?f.map(e=>(0,V.jsxs)(`span`,{className:`inline-flex h-7 items-center gap-1 rounded-full border border-border-soft bg-paper-2 pr-1.5 pl-3 text-[0.8125rem] text-ink-2`,children:[e,n?(0,V.jsx)(`button`,{type:`button`,"aria-label":I(`policy.maskLabels.remove`,{label:e}),className:`grid size-5 place-items-center rounded-full text-ink-3 hover:bg-paper-3 hover:text-ink`,onClick:()=>i({maskLabels:f.filter(t=>t!==e)}),children:(0,V.jsx)(Kt,{className:`size-3`})}):null]},e)):(0,V.jsx)(q,{children:I(`policy.maskLabels.none`)})}),n&&f.length<20?(0,V.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,V.jsx)(y,{value:s,maxLength:60,placeholder:I(`policy.maskLabels.addPlaceholder`),onChange:e=>c(e.target.value),className:`max-w-xs`}),(0,V.jsxs)(O,{type:`submit`,size:`sm`,variant:`secondary`,disabled:!s.trim(),children:[(0,V.jsx)(Wt,{className:`size-3.5`}),I(`policy.maskLabels.add`)]})]}):null,(0,V.jsx)(q,{children:I(`policy.maskLabels.hint`)})]}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl bg-paper-2/60 p-3`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:I(`policy.maskTry`)}),(0,V.jsxs)(`form`,{className:`flex gap-2`,onSubmit:e=>{e.preventDefault(),l.trim()&&d.mutate(l.trim())},children:[(0,V.jsx)(y,{value:l,maxLength:2e3,placeholder:I(`policy.maskTry.placeholder`),onChange:e=>u(e.target.value)}),(0,V.jsx)(O,{type:`submit`,size:`sm`,variant:`secondary`,busy:d.isPending,disabled:!l.trim(),children:I(`policy.maskTry.button`)})]}),d.data?(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[(0,V.jsxs)(`span`,{className:`text-ink-3`,children:[I(`policy.maskTry.sees`),` `]}),d.data.text.split(/(‹[^‹›]+›)/).map((e,t)=>e.startsWith(`‹`)?(0,V.jsx)(`span`,{className:`text-cobalt`,children:e},t):e)]}):null,d.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:d.error.message}):null]})]})}function Oi({way:e}){return(0,V.jsx)(`span`,{className:`inline-flex h-7 items-center rounded-full bg-cobalt-tint px-3 font-medium text-[0.75rem] text-cobalt`,children:I(`policy.way.${e}`)})}function ki({purposes:e,count:t}){let[n,r]=x(),i=Ai(n.get(`for`),e);return(0,V.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`tablist`,children:e.map(e=>{let n=vi[e];return(0,V.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":i===e,onClick:()=>r(t=>({...Object.fromEntries(t),for:e}),{replace:!0}),className:M(`inline-flex h-9 items-center gap-1.5 rounded-full border px-3.5 text-[0.8125rem] transition`,i===e?`border-ember bg-ember-tint font-medium text-ink`:`border-border-soft text-ink-2 hover:border-ink-4`),children:[(0,V.jsx)(n,{className:`size-3.5`}),I(`policy.purpose.${e}`),(0,V.jsx)(`span`,{className:`text-ink-3`,children:t(e)})]},e)})})}function Ai(e,t){return t.find(t=>t===e)??`wizard`}function ji({tier:e,policy:t,canEdit:n}){let r=yi(),i=r.isPending&&r.variables?r.variables:t,a=_i(),[o]=x(),s=Ai(o.get(`for`),a),c=i.purposes[s],l=Ie(e,c),u=e=>r.mutate({...i,purposes:{...i.purposes,[s]:{...c,...e}}}),d=e=>c.efforts?.[e]??[...St],f=new Set(Ye(e).map(e=>e.model)),p=(e,t)=>{let n=t?[...l,e]:l.filter(t=>t!==e);u({models:n,default:c.default===e&&!t?null:c.default})};return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsx)(J,{icon:mn,title:I(`policy.approved`),lead:I(`policy.approvedLead`),status:(0,V.jsx)(Oi,{way:`C`})}),(0,V.jsx)(ki,{purposes:a,count:t=>Ie(e,i.purposes[t]).length}),(0,V.jsx)(A,{className:`overflow-x-auto p-0`,children:(0,V.jsxs)(`table`,{className:`w-full min-w-[40rem] text-[0.8125rem]`,children:[(0,V.jsx)(`thead`,{className:`text-left text-[0.75rem] text-ink-3`,children:(0,V.jsxs)(`tr`,{className:`border-border-soft border-b`,children:[(0,V.jsx)(`th`,{className:`px-4 py-2.5 font-normal`,children:I(`policy.col.use`)}),(0,V.jsx)(`th`,{className:`px-2 py-2.5 font-normal`,children:I(`policy.col.model`)}),(0,V.jsx)(`th`,{className:`px-2 py-2.5 font-normal`,children:I(`policy.col.runsOn`)}),(0,V.jsx)(`th`,{className:`px-2 py-2.5 font-normal`,children:I(`policy.col.effort`)}),(0,V.jsx)(`th`,{className:`px-4 py-2.5 font-normal`,children:I(`policy.col.default`)})]})}),(0,V.jsx)(`tbody`,{children:ye(e).map(t=>{let r=l.find(n=>n===t.id||Ne(e,n)?.model===t.model),i=r??t.id,a=e.classes[t.id],o=St.filter(e=>t.efforts.includes(e));return(0,V.jsxs)(`tr`,{className:`border-border-soft border-b last:border-b-0`,children:[(0,V.jsx)(`td`,{className:`px-4 py-3`,children:(0,V.jsx)(T,{checked:!!r,disabled:!n,onChange:e=>p(i,e),label:t.name})}),(0,V.jsxs)(`td`,{className:`px-2 py-3`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,V.jsx)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:f.has(t.model)?t.hint:[t.hint,I(`chooser.notInPreselection`)].filter(Boolean).join(` · `)})]}),(0,V.jsx)(`td`,{className:`px-2 py-3 text-ink-2`,children:Te(a)?[a.route,a.region].filter(Boolean).join(`, `):null}),(0,V.jsx)(`td`,{className:`px-2 py-3`,children:r&&o.length?(0,V.jsx)(b,{multi:!0,value:d(i).filter(e=>o.includes(e)),options:o,label:e=>I(`class.effort.${e}`),onChange:e=>n&&e.length?u({efforts:{...c.efforts??{},[i]:e}}):void 0}):null}),(0,V.jsx)(`td`,{className:`px-4 py-3`,children:r?(0,V.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-ink-3`,children:[(0,V.jsx)(`input`,{type:`radio`,name:`default-${s}`,checked:c.default===i,disabled:!n,onChange:()=>u({default:i}),className:`accent-ember`}),c.default===i?I(`policy.isDefault`):null]}):null})]},t.model)})})]})}),(0,V.jsx)(q,{children:I(`policy.approvedFoot`)}),r.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null]})}function Mi({tier:e,policy:t,canEdit:n}){let r=yi(),i=r.isPending&&r.variables?r.variables:t,a=_i(),o=le(e).filter(t=>Te(e.classes[t])),s=(e,t)=>r.mutate({...i,purposes:{...i.purposes,[e]:{...i.purposes[e],...t}}});return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsx)(J,{icon:mn,title:I(`policy.defaults`),lead:I(`policy.defaultsLead`),status:(0,V.jsx)(Oi,{way:`B`})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-5 sm:p-6`,children:[(0,V.jsxs)(K,{title:I(`policy.defaultPerTask`),children:[(0,V.jsxs)(`div`,{className:`grid items-center gap-x-4 gap-y-3 sm:grid-cols-[8rem_minmax(0,16rem)_auto]`,children:[(0,V.jsx)(`span`,{className:`hidden text-[0.75rem] text-ink-3 sm:block`,children:I(`policy.col.task`)}),(0,V.jsx)(`span`,{className:`hidden text-[0.75rem] text-ink-3 sm:block`,children:I(`policy.col.model`)}),(0,V.jsx)(`span`,{className:`hidden text-[0.75rem] text-ink-3 sm:block`,children:I(`policy.col.cap`)}),a.map(e=>{let t=vi[e],r=i.purposes[e];return(0,V.jsxs)(`div`,{className:`contents`,children:[(0,V.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.875rem]`,children:[(0,V.jsx)(t,{className:`size-3.5 text-ink-3`}),I(`policy.purpose.${e}`)]}),(0,V.jsx)(C,{value:r.default??``,onChange:t=>s(e,{default:t||null}),options:[{value:``,label:I(`policy.engentyPicks`)},...o.map(e=>({value:e,label:rt(e).maker?et(e):`${et(e)} · ${I(`policy.anyMaker`)}`,disabled:!n}))]}),(0,V.jsx)(b,{value:r.effortCap??`high`,options:[...St],label:e=>I(`class.effort.${e}`),disabled:n?[]:[...St],onChange:t=>s(e,{effortCap:t})})]},e)})]}),(0,V.jsx)(q,{children:I(`policy.capHint`)})]}),(0,V.jsx)(K,{title:I(`policy.tierModels`),aside:(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:I(`policy.tierModelsCount`,{n:o.length,tier:e.name})}),children:(0,V.jsx)(q,{children:I(`policy.tierModelsHint`)})}),r.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null]})]})}function Ni(e){return I(e.local&&e.subscriptions?`policy.apps.all`:e.local?`policy.apps.localOnly`:e.subscriptions?`policy.apps.subscriptionsOnly`:`policy.apps.none`)}function Pi({tier:e,policy:t,canEdit:n}){let i=yi(),a=i.isPending&&i.variables?i.variables:t,o=e=>i.mutate({...a,apps:{...a.apps,...e}}),s=N({queryKey:[`model-policy-apps`],queryFn:()=>r.get(`/api/studio/model-policy/apps`),enabled:n,refetchInterval:3e4}).data?.apps??[];return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsx)(J,{icon:hn,title:I(`policy.apps`),lead:I(`policy.appsLead`),status:(0,V.jsx)(`span`,{className:`inline-flex h-7 items-center rounded-full bg-paper-2 px-3 font-medium text-[0.75rem] text-ink-2`,children:Ni(a.apps)})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-5 sm:p-6`,children:[(0,V.jsx)(K,{title:I(`policy.appsWhich`),children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(Si,{icon:Pe,title:I(`policy.apps.local`),hint:I(`policy.apps.local.hint`),checked:a.apps.local,locked:e.rules.zdr?I(`policy.notIn`,{tier:e.name}):null,disabled:!n,onChange:e=>o({local:e})}),(0,V.jsx)(Si,{icon:Ce,title:I(`policy.apps.subscriptions`),hint:I(`policy.apps.subscriptions.hint`),checked:a.apps.subscriptions,locked:e.rules.zdr?I(`policy.notIn`,{tier:e.name}):null,disabled:!n,onChange:e=>o({subscriptions:e})})]})}),(0,V.jsxs)(K,{title:I(`policy.appsSeen`),children:[s.length?(0,V.jsx)(`ul`,{className:`flex flex-col`,children:s.map(e=>(0,V.jsxs)(`li`,{className:`flex items-center gap-3 border-border-soft border-t py-2.5 first:border-t-0`,children:[(0,V.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:e.app}),e.person?(0,V.jsx)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:e.person}):null]}),e.refused?(0,V.jsxs)(`span`,{className:`inline-flex h-6 items-center gap-1 rounded-full bg-amber-tint px-2.5 text-[0.75rem] text-ink-2`,children:[(0,V.jsx)(Kt,{className:`size-3`}),I(`policy.appsRefused`,{n:e.refused})]}):null,e.allowed?(0,V.jsxs)(`span`,{className:`inline-flex h-6 items-center gap-1 rounded-full bg-moss-tint px-2.5 text-[0.75rem] text-moss`,children:[(0,V.jsx)(z,{className:`size-3`,strokeWidth:3}),I(`policy.appsAllowed`)]}):null]},`${e.app}-${e.person??``}`))}):(0,V.jsx)(q,{children:I(`policy.appsNone`)}),(0,V.jsx)(q,{children:I(`policy.appsNote`)})]}),i.error?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:i.error.message}):null]})]})}function Fi({kept:e,children:t}){let n=e?z:$e;return(0,V.jsxs)(`span`,{className:M(`inline-flex h-7 items-center gap-1.5 rounded-full px-3 font-medium text-[0.75rem]`,e?`bg-moss-tint text-moss`:`bg-paper-2 text-ink-3`),children:[(0,V.jsx)(n,{className:`size-3.5`,strokeWidth:e?3:2}),t]})}function Ii(e){return e.length===1&&e[0]===`eu`?I(`tier.promise.eu`):I(`tier.promise.regions`,{regions:e.map(e=>e.toUpperCase()).join(`, `)})}function Li(e){let t=e?.name??I(`tier.theModel`);return e&&!Te(e)?I(`tier.short.${e.reason}`,{model:t}):I(`tier.short.unbound`,{model:t})}function Ri(e){let t=xt.flatMap(t=>yt[t].map(e=>`${t}/${e}`).filter(t=>t in e.classes).map(e=>({id:e,icon:null,label:et(e)}))),n=[[`classifier`,En,`models.cap.decision`],[`embedding`,c,`models.cap.search`],[`image`,pn,`models.cap.image`],[`video`,an,`models.cap.video`],[`speech`,ln,`models.cap.speech`],[`audio`,Sn,`models.cap.listening`]];return[...Ct.filter(e=>e!==`classifier`).map((e,t)=>({id:e,icon:t===0?l:null,label:I(`class.${e}`)})),...t,...n.map(([e,t,n])=>({id:e,icon:t,label:I(n)}))]}function zi({tier:e}){return(0,V.jsx)(`dl`,{className:`grid grid-cols-[1.25rem_minmax(0,9rem)_minmax(0,1fr)] items-start gap-x-3 gap-y-2 text-[0.8125rem]`,children:Ri(e).map(({id:t,icon:n,label:r})=>{let i=e.classes[t],a=Te(i)?[i.route,i.region].filter(Boolean).join(`, `):``;return(0,V.jsxs)(B.Fragment,{children:[(0,V.jsx)(`span`,{className:`pt-0.5 text-ink-3`,children:n?(0,V.jsx)(n,{className:`size-4`}):null}),(0,V.jsx)(`dt`,{className:`text-ink-2`,children:r}),(0,V.jsxs)(`dd`,{className:M(`min-w-0`,!Te(i)&&`text-ink-3`),children:[Te(i)?(0,V.jsx)(`span`,{className:`font-medium text-ink`,children:i.name}):I(`tier.notOffered`),(0,V.jsx)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:Te(i)?t===`classifier`&&!e.rules.decisions?[a,I(`tier.noEvaluationModel`)].filter(Boolean).join(` · `):a:Li(i)})]})]},t)})})}function Bi({tier:e,modelPolicy:t}){let n=gt(e,t,`wizard`),r=[...n.auto?[{id:`auto`,name:I(`chooser.auto`),hint:I(`chooser.auto.hint`),efforts:null}]:[],...n.items.map(e=>({...e,efforts:n.efforts(e.id).filter(t=>e.efforts.includes(t))}))];return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(q,{children:n.auto?I(`chooser.lead`,{tier:e.name}):I(`chooser.leadOwn`)}),(0,V.jsx)(`dl`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)] items-start gap-x-3 gap-y-2 text-[0.8125rem]`,children:r.map(e=>(0,V.jsxs)(B.Fragment,{children:[(0,V.jsxs)(`dt`,{children:[(0,V.jsx)(`span`,{className:`font-medium text-ink`,children:e.name}),(0,V.jsx)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:e.hint})]}),(0,V.jsx)(`dd`,{className:`text-[0.75rem] text-ink-3`,children:e.efforts?.length?`${I(`class.effort`)}: ${e.efforts.map(e=>I(`class.effort.${e}`)).join(`, `)}`:null})]},e.id))})]})}function Vi({tier:e,modelPolicy:t,organization:n,children:r}){let{rules:i}=e;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,V.jsx)(J,{icon:s,title:I(`overview.scope`),lead:n?I(`tier.lead`,{organization:n}):I(`tier.leadNoName`),status:e.locked?(0,V.jsxs)(`span`,{className:`inline-flex h-7 items-center gap-1.5 rounded-full bg-paper-2 px-3 font-medium text-[0.75rem] text-ink-2`,children:[(0,V.jsx)(ct,{className:`size-3.5`}),I(`tier.locked`)]}):null}),r,(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-5 sm:p-6`,children:[(0,V.jsxs)(K,{title:I(`tier.promises`),aside:(0,V.jsx)(`b`,{className:`text-[0.875rem]`,children:e.name}),children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[i.regions?(0,V.jsx)(Fi,{kept:!0,children:Ii(i.regions)}):null,i.zdr?(0,V.jsx)(Fi,{kept:!0,children:I(`tier.promise.zdr`)}):null,i.noTraining?(0,V.jsx)(Fi,{kept:!0,children:I(`tier.promise.noTraining`)}):null,t?(0,V.jsx)(Fi,{kept:t.masking,children:I(t.masking?`tier.promise.maskingOn`:`tier.promise.maskingOff`)}):null]}),Re(e)?null:(0,V.jsx)(q,{children:I(`tier.promise.none`)})]}),(0,V.jsx)(K,{title:I(`tier.classes`),aside:(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:I(`tier.classesFollow`)}),children:(0,V.jsx)(zi,{tier:e})}),(0,V.jsx)(K,{title:I(`tier.search`),children:(0,V.jsx)(q,{children:I(i.search?`tier.searchOn`:`tier.searchOff`,{tier:e.name})})})]})]})}function Hi(e,t){return e?.env?I(`overview.keys.fromEnv`,{env:e.env}):I(t.cloud?`overview.keys.keptCloud`:`overview.keys.kept`)}var Ui=[`gateway`,`openai`,`local`,`credits`],Wi=[`gateway`,`typesafe`,`local`,`credits`];function Gi(e,t){let n=t===`auto`?e.mode===`managed`:t===`cloud`,r=t===`auto`||t===`linked`?e.account??(t===`linked`?{name:e.user.name,email:e.user.email,organization:null,organizationId:``,plan:null,organizations:[],credits:1250,expiring:[],url:``,cloudUrl:``,signedIn:!0}:null):null;return{cloud:n,account:n?null:r,credits:n||!!r?.signedIn,balance:n?e.credits??(t===`cloud`?1250:null):r?.credits??null,topUp:Xe(e),harnesses:n?[]:e.harnesses,canEdit:!n||e.tenant.role!==`member`,ownKeys:!n||Tt(e.features,`ownKeys`),accounts:n&&Tt(e.features,`ownKeysGateway`)}}var Ki={text:l,image:pn,video:an,speech:ln,listening:Sn},Y={text:`low`,image:`image`,video:`video`,speech:`speech`,listening:`audio`},X=e=>e===`text`;function qi(e,t){return JSON.stringify(e)===JSON.stringify(t)}function Ji(e,t,n){let r=Y[t];if(X(t)&&!n.cloud){if(e.bindings.low?.startsWith(`apple:`))return{kind:`local`,by:`apple`};if(e.source===`account`)return{kind:`credits`};if(e.source!==`own`)return{kind:`client`,id:e.source}}let i=e.bindings[r];if(Qe(i))return{kind:`credits`};if(i?.startsWith(`ollama:`))return{kind:`local`,by:`ollama`};if(i?.startsWith(`apple:`))return{kind:`local`,by:`apple`};let a=i?dt(i):null;if(a)return{kind:`key`,provider:a};if(i&&/^(claude|codex|antigravity|cursor)\//.test(i))return{kind:`client`,id:i.split(`/`)[0]};let o=e.ways[r];switch(o.kind){case`client`:return{kind:`client`,id:o.by};case`key`:return P(o.by??``)?{kind:`key`,provider:o.by}:null;case`local`:return{kind:`local`,by:o.by===`apple`?`apple`:`ollama`};case`credits`:return{kind:`credits`};default:return null}}function Yi(e,t,n){if(X(t)&&e.text)return e.text;let r=Y[t],i=n.bindings[r],a=i&&dt(i)===e.id?i:e.models[t]?.[0]?.ref;return a?{[r]:a}:{}}function Xi(e){return e.version===null?{note:I(`models.noteMissing`),noteTone:`warn`}:e.auth===`none`?{note:I(`models.noteSignedOut`),noteTone:`warn`}:e.auth===`api_key`?{note:I(`models.noteShellKey`)}:{note:I(`models.noteIncluded`),noteTone:`done`}}function Zi(e,t){switch(e.kind){case`client`:return{text:t.harnesses.find(t=>t.id===e.by)?.name??e.by??``,tone:`done`};case`key`:return{text:P(e.by??``)?.name??e.by??``,tone:`done`};case`local`:return{text:e.by===`apple`?I(`models.optApple`):I(`models.way.local`),tone:`done`};case`credits`:return{text:t.cloud?I(`models.way.creditsOrganization`):I(`models.way.credits`),tone:`ok`};default:return{text:I(`models.way.none`),tone:`warn`}}}function Qi(){return N({queryKey:[`models`],queryFn:()=>r.get(`/api/studio/models`),select:st})}function Z(){let e=f();return R({mutationFn:e=>r.put(`/api/studio/models`,e),onSuccess:async t=>{e.setQueryData([`models`],t),await e.invalidateQueries({queryKey:[`me`]})}})}function Q({label:e,children:t}){return(0,V.jsxs)(`div`,{className:`grid items-start gap-x-4 gap-y-1.5 sm:grid-cols-[7.5rem_minmax(0,1fr)]`,children:[(0,V.jsx)(`span`,{className:`pt-2 text-[0.75rem] text-ink-3`,children:e}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t})]})}function $({selected:e,title:t,note:n,noteTone:r,disabled:i,onPick:a}){return(0,V.jsxs)(`button`,{type:`button`,onClick:a,disabled:i,"aria-pressed":e,title:n,className:M(`inline-flex h-9 items-center gap-1.5 rounded-full border px-3.5 text-[0.8125rem] transition coarse:h-11`,e?`border-ember bg-ember-tint font-medium text-ink`:r===`done`?`border-input bg-card text-ink hover:border-ink-4`:`border-border-soft border-dashed text-ink-3 hover:border-ink-4 hover:text-ink`,i&&`cursor-not-allowed opacity-50`),children:[r===`done`?(0,V.jsx)(z,{className:`size-3.5 text-moss`,strokeWidth:3}):null,t,(0,V.jsxs)(`span`,{className:`sr-only`,children:[`: `,n]})]})}function $i({provider:e,stored:t,hint:n,place:i}){let a=Z(),[o,s]=(0,B.useState)(``),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(null),f=R({mutationFn:t=>r.post(`/api/studio/models/keys/${e.id}/check`,t?{key:t}:{})}),p=async()=>{d(null);let t=await f.mutateAsync(o.trim());t.ok?(await a.mutateAsync({keys:{[e.id]:o.trim()}}),s(``),l(!1),d({ok:!0,message:I(`models.keyOk`)})):d({ok:!1,message:t.message??I(`models.keyBad`)})},m=!t||c;return i.ownKeys?(0,V.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[m?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(y,{type:`password`,autoComplete:`off`,className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,placeholder:e.keyPlaceholder,value:o,disabled:!i.canEdit,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&o.trim()&&p()}}),(0,V.jsx)(O,{busy:f.isPending||a.isPending,disabled:!o.trim()||!i.canEdit,onClick:()=>void p(),children:I(`models.keySave`)}),c?(0,V.jsx)(O,{variant:`ghost`,onClick:()=>l(!1),children:I(`common.cancel`)}):null]}):(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,V.jsxs)(`span`,{className:`flex items-center gap-2 text-[0.875rem] text-ink-2`,children:[(0,V.jsx)(ze,{className:`size-4 text-moss`}),n?(0,V.jsx)(`code`,{className:`font-mono text-[0.8125rem]`,children:n.masked}):null,(0,V.jsx)(`span`,{className:`text-ink-3`,children:Hi(n,i)})]}),(0,V.jsx)(O,{size:`sm`,variant:`ghost`,busy:f.isPending,onClick:async()=>{let e=await f.mutateAsync(void 0);d(e.ok?{ok:!0,message:I(`models.keyOk`)}:{ok:!1,message:e.message??I(`models.keyBad`)})},children:I(`models.keyCheck`)}),i.canEdit?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(O,{size:`sm`,variant:`ghost`,onClick:()=>l(!0),children:I(`models.keyReplace`)}),(0,V.jsx)(O,{size:`sm`,variant:`danger`,busy:a.isPending,onClick:()=>{d(null),a.mutate({keys:{[e.id]:``}})},children:I(`models.keyRemove`)})]}):null]}),u?(0,V.jsxs)(`p`,{className:M(`flex items-center gap-1.5 text-[0.8125rem]`,u.ok?`text-moss`:`text-rose`),children:[u.ok?(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}):null,u.message]}):null,(0,V.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[0.75rem] text-ink-4`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Le(e.keyUrl),className:`inline-flex items-center gap-1 font-medium text-ember-strong hover:underline`,children:[I(`models.keyGet`,{name:e.name}),` `,(0,V.jsx)(Ht,{className:`size-3`})]}),(0,V.jsx)(`span`,{children:i.cloud?I(`models.keyWhereCloud`):I(`models.keyWhereLocal`)})]})]}):(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`models.ownKeysPlan`)})}var ea=`__custom__`;function ta({provider:e,cap:t,value:n,onPick:r,disabled:i}){let a=F,o=e.models[t]??[],s=o.some(e=>e.ref===n),[c,l]=(0,B.useState)(!s&&!!n),[u,d]=(0,B.useState)(s?``:n.replace(/^[a-z]+:/,``)),f=e.id===`gateway`?``:`${e.id}:`;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsx)(C,{value:c?ea:n,onChange:e=>{e===ea?l(!0):(l(!1),r(e))},options:[...o.map(e=>({value:e.ref,label:e.note?`${e.label} – ${Ge(e.note,a)}`:e.label})),{value:ea,label:I(`models.modelCustom`)}]}),c?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(y,{className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,value:u,disabled:i,placeholder:o[0]?.ref.replace(/^[a-z]+:/,``)??``,onChange:e=>d(e.target.value)}),(0,V.jsx)(O,{variant:`secondary`,disabled:!u.trim()||i,onClick:()=>r(`${f}${u.trim()}`),children:I(`settings.save`)})]}):null]})}function na({provider:e,state:t}){let n=n=>He(t.bindings[n]??e.text?.[n]??``);return(0,V.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1 text-[0.875rem]`,children:[(0,V.jsx)(`dt`,{className:`text-ink-3`,children:I(`models.textSimple`)}),(0,V.jsx)(`dd`,{className:`truncate font-medium`,children:n(`low`)}),(0,V.jsx)(`dt`,{className:`text-ink-3`,children:I(`models.textDemanding`)}),(0,V.jsx)(`dd`,{className:`truncate font-medium`,children:n(`standard`)})]})}function ra(e,t){return t===`context`?I(`need.context`,{tokens:`${Math.round(Be[e].context/1e3)}k`}):I(`need.${t}`)}function ia({cls:e,lacks:t}){let n=[...Be[e].needs,`context`];return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`text-[0.6875rem] text-ink-4 leading-snug`,children:I(`class.needs`,{needs:n.map(t=>ra(e,t)).join(`, `)})}),t?.length?(0,V.jsxs)(`div`,{className:`flex items-start gap-1 text-[0.6875rem] text-amber leading-snug`,children:[(0,V.jsx)(Ke,{className:`mt-px size-3 shrink-0`}),I(`class.lacks`,{needs:t.map(t=>ra(e,t)).join(`, `)})]}):null]})}function aa({provider:e,state:t,onPick:n,disabled:r}){return(0,V.jsxs)(`details`,{className:`group rounded-lg ring-1 ring-border-soft`,children:[(0,V.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2.5 text-[0.8125rem] text-ink-2 hover:text-ink`,children:(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(v,{className:`size-3.5 transition group-open:rotate-90`}),I(`models.perClass`)]})}),(0,V.jsx)(`div`,{className:`flex flex-col gap-3 px-3 pt-1 pb-3`,children:Ct.map(i=>(0,V.jsxs)(`div`,{className:`grid items-center gap-2 sm:grid-cols-[9rem_minmax(0,1fr)]`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-2`,children:I(`class.${i}`)}),(0,V.jsx)(`div`,{className:`text-[0.6875rem] text-ink-4 leading-snug`,children:I(`class.${i}.hint`)})]}),(0,V.jsx)(ta,{provider:e,cap:`text`,value:t.bindings[i]??e.text?.[i]??``,disabled:r,onPick:e=>n(i,e)}),(0,V.jsx)(`div`,{className:`flex flex-col gap-0.5 sm:col-start-2`,children:(0,V.jsx)(ia,{cls:i,lacks:t.fit[i]})})]},i))})]})}function oa({cap:e,disabled:t}){let n=Y[e],i=R({mutationFn:()=>r.post(`/api/studio/models/test`,{cls:n,lang:F})}),a=i.data;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(O,{variant:`secondary`,busy:i.isPending,disabled:t,onClick:()=>i.mutate(),children:I(`models.try.${e}`)}),(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:e===`video`?I(`models.tryCostVideo`):X(e)?null:I(`models.tryCost`)})]}),i.isPending&&e!==`text`?(0,V.jsxs)(`p`,{className:`flex items-center gap-2 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(k,{className:`size-3.5`}),` `,I(e===`video`?`models.tryWaitVideo`:`models.tryWait`)]}):null,a?.ok?(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[a.media&&e===`image`?(0,V.jsx)(`img`,{src:a.media,alt:``,className:`size-48 rounded-lg object-cover ring-1 ring-border-soft`}):null,a.media&&e===`speech`?(0,V.jsx)(`audio`,{src:a.media,controls:!0,autoPlay:!0,className:`w-full max-w-sm`}):null,a.media&&e===`video`?(0,V.jsx)(`video`,{src:a.media,controls:!0,autoPlay:!0,muted:!0,className:`w-full max-w-md rounded-lg`}):null,(0,V.jsxs)(`p`,{className:`flex items-start gap-2 text-[0.8125rem] text-ink-2`,children:[(0,V.jsx)(z,{className:`mt-0.5 size-3.5 shrink-0 text-moss`,strokeWidth:3}),(0,V.jsx)(`span`,{children:e===`listening`?a.reply?I(`models.tryHeard`,{text:a.reply}):I(`models.tryHeardNothing`):X(e)?I(`local.testOk`,{s:(a.ms/1e3).toFixed(1),ref:He(a.ref??``),reply:a.reply??``}):I(`models.tryOk`,{s:(a.ms/1e3).toFixed(1),model:He(a.ref??``)})})]})]}):null,a&&!a.ok?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:I(`models.tryFailed`,{error:a.error??``})}):null,i.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:I(`models.tryFailed`,{error:i.error.message})}):null]})}function sa(e){let t=e=>(e<10?Math.round(e*10)/10:Math.ceil(e)).toLocaleString(F);return e?.creditsPerImage?I(`models.notePerImage`,{n:t(e.creditsPerImage)}):e?.creditsPerSecond?I(`models.notePerSecond`,{n:t(e.creditsPerSecond)}):e?.creditsPer1kCharacters?I(`models.notePer1k`,{n:t(e.creditsPer1kCharacters)}):e?.creditsPerMinute?I(`models.notePerMinute`,{n:t(e.creditsPerMinute)}):I(`models.noteUsage`)}function ca(e,t){let n=at(t.bindings[Y[e]]);return sa((n?t.creditModels.find(e=>e.id===n):null)??t.prices?.[Y[e]])}function la(e,t,n){return e.creditModels.filter(e=>mt(e.kind)===t&&(!n||e.source===n||e.provider===n))}function ua({cap:e,state:t,disabled:n}){let r=Z(),i=Y[e],a=at(t.bindings[i]),o=la(t,e),s=t.prices?.[i]?.model,c=e=>e.source===`ai-gateway`?P(e.provider)?.name??e.provider:P(e.source)?.name??e.source;return(0,V.jsx)(C,{value:a??``,onChange:e=>r.mutate({bindings:{[i]:ut(e||null)}}),options:[{value:``,label:s?I(`models.creditsAuto`,{model:He(s)}):I(`models.creditsAutoNone`)},...o.map(e=>({value:e.id,label:`${e.name} · ${c(e)} – ${sa(e)}`,disabled:n}))]})}function da({models:e,state:t,place:n}){let r=Z();return(0,V.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:e.map(e=>{let i=mt(e.kind),a=Y[i],o=t.bindings[a]===ut(e.id);return(0,V.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2.5`,children:[(0,V.jsx)(rn,{className:`size-4 shrink-0 text-ink-3`}),(0,V.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:e.name}),(0,V.jsxs)(`span`,{className:`block text-[0.75rem] text-ink-3`,children:[I(`models.cap.${i}`),` · `,sa(e)]})]}),o?(0,V.jsxs)(`span`,{className:`flex items-center gap-1 font-medium text-[0.75rem] text-moss`,children:[(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}),` `,I(`models.inUse`)]}):(0,V.jsx)(O,{size:`sm`,variant:`secondary`,disabled:!n.canEdit||!n.credits,busy:r.isPending&&r.variables?.bindings?.[a]===ut(e.id),onClick:()=>r.mutate({bindings:{[a]:ut(e.id)}}),children:I(`models.useFor`)})]},e.id)})})}function fa({cap:e,state:t,place:n,me:r,onOpen:i}){let a=Z(),o=Y[e],s=t.ways[o],c=Ji(t,e,n),[l,u]=(0,B.useState)(!1),d=Zi(s,n),f=n.harnesses.filter(t=>(X(e)||e===`image`&&t.images)&&(t.version!==null||c?.kind===`client`&&c.id===t.id)),p=Je.filter(t=>t.models[e]?.length),m=r=>{if(u(!1),r.kind===`credits`&&!n.credits){u(!0);return}if(qi(r,c))return;let i=Fe[e],s=e=>Object.fromEntries(i.map(t=>[t,e]));switch(r.kind){case`client`:a.mutate(X(e)?{source:r.id,bindings:At(t.bindings)}:{bindings:{[o]:`${r.id}/image`}});return;case`key`:{let i=P(r.provider);a.mutate({...X(e)&&!n.cloud?{source:`own`}:{},bindings:Yi(i,e,t)});return}case`local`:a.mutate(r.by===`apple`?{bindings:X(e)?pa(t):{audio:`apple:transcribe`}}:{source:`own`,bindings:s(`ollama:qwen3`)});return;case`credits`:a.mutate(X(e)&&!n.cloud?{source:`account`,bindings:At(t.bindings)}:{bindings:s(De)});return}},h=c?.kind===`key`?P(c.provider):null,g=h?!t.keys[h.id]:!1,_=c?.kind===`client`?n.harnesses.find(e=>e.id===c.id):null,v=s.kind!==`none`;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:Ki[e],title:I(`models.cap.${e}`),lead:I(`models.cap.${e}.hint`),status:(0,V.jsx)(Rr,{...d})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,V.jsxs)(K,{title:I(`models.who`),children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f.length?(0,V.jsx)(Q,{label:I(`models.optSubscription`),children:f.map(e=>(0,V.jsx)($,{title:e.name,...Xi(e),selected:c?.kind===`client`&&c.id===e.id,disabled:!n.canEdit,onPick:()=>m({kind:`client`,id:e.id})},e.id))}):null,n.accounts?null:(0,V.jsx)(Q,{label:I(`models.optKey`),children:p.map(e=>(0,V.jsx)($,{title:e.name,note:t.keys[e.id]?I(`models.noteKey`):I(`models.noteNoKey`),noteTone:t.keys[e.id]?`done`:void 0,selected:c?.kind===`key`&&c.provider===e.id,disabled:!n.canEdit,onPick:()=>m({kind:`key`,provider:e.id})},e.id))}),(0,V.jsxs)(Q,{label:X(e)&&!n.cloud?I(`models.optOther`):I(`models.optCreditsGroup`),children:[(X(e)||e===`listening`)&&!n.cloud&&t.apple?.supported?(0,V.jsx)($,{title:I(`models.optApple`),note:X(e)?ma(t.apple):I(`models.optAppleNote`),noteTone:X(e)&&!t.apple.available?void 0:`done`,selected:c?.kind===`local`&&c.by===`apple`,disabled:!n.canEdit||X(e)&&!t.apple.available,onPick:()=>m({kind:`local`,by:`apple`})}):null,X(e)&&!n.cloud?(0,V.jsx)($,{title:I(`models.optLocal`),note:I(`models.optLocalNote`),selected:c?.kind===`local`&&c.by===`ollama`,disabled:!n.canEdit,onPick:()=>m({kind:`local`,by:`ollama`})}):null,(0,V.jsx)($,{title:n.cloud?I(`models.creditsOrganization`):I(`models.creditsName`),note:n.credits?ca(e,t):I(`models.noteNeedsAccount`),noteTone:n.credits?`done`:void 0,selected:c?.kind===`credits`,disabled:!n.canEdit,onPick:()=>m({kind:`credits`})})]})]}),l?(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[I(`local.sourceNeedsAccount`),` `,(0,V.jsx)(Da,{})]}):null,a.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:a.error.message}):null]}),h?(0,V.jsxs)(V.Fragment,{children:[g?(0,V.jsxs)(K,{title:I(`models.keyFor`,{name:h.name}),children:[(0,V.jsx)($i,{provider:h,stored:!1,place:n}),n.credits?(0,V.jsxs)(q,{children:[(0,V.jsx)(rn,{className:`mr-1 inline size-3.5 align-[-2px]`}),I(`models.keyFallback`)]}):null]}):null,g&&n.credits&&la(t,e,h.id).length?(0,V.jsx)(K,{title:I(`models.viaCredits`,{name:h.name}),children:(0,V.jsx)(da,{models:la(t,e,h.id),state:t,place:n})}):null,(0,V.jsx)(K,{title:I(`models.model`),aside:g?null:(0,V.jsx)(`button`,{type:`button`,onClick:()=>i({type:`provider`,id:h.id}),className:`text-[0.75rem] text-ink-3 hover:text-ink`,children:I(`models.manageKey`,{name:h.name})}),children:X(e)&&h.text?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(na,{provider:h,state:t}),(0,V.jsx)(aa,{provider:h,state:t,disabled:!n.canEdit,onPick:(e,t)=>a.mutate({bindings:{[e]:t}})})]}):(0,V.jsx)(ta,{provider:h,cap:e,value:t.bindings[o]??h.models[e]?.[0]?.ref??``,disabled:!n.canEdit,onPick:e=>a.mutate({bindings:{[o]:e}})},`${h.id}:${t.bindings[o]??``}`)})]}):null,c?.kind===`client`&&_?X(e)?(0,V.jsx)(K,{title:_.name,children:(0,V.jsx)(Se,{me:r,id:_.id})}):(0,V.jsx)(K,{title:_.name,children:(0,V.jsx)(q,{children:I(`models.clientImages`,{name:_.name,sub:I(`harness.sub.${_.id}`)})})}):null,c?.kind===`local`?c.by===`apple`?(0,V.jsx)(ha,{cap:e,state:t,place:n}):(0,V.jsx)(ga,{state:t,disabled:!n.canEdit,onOpen:i}):null,c?.kind===`credits`&&n.credits?X(e)?(0,V.jsx)(K,{title:I(`models.creditsName`),children:(0,V.jsxs)(q,{children:[I(`models.creditsPicks`),s.kind===`credits`&&s.ref?` ${I(`models.creditsModel`,{model:He(s.ref)})}`:``]})}):(0,V.jsxs)(K,{title:I(`models.model`),children:[(0,V.jsx)(ua,{cap:e,state:t,disabled:!n.canEdit}),(0,V.jsx)(q,{children:I(`models.creditsPickHint`)})]}):null,s.problem?(0,V.jsxs)(`p`,{className:`flex items-start gap-2 rounded-lg bg-paper-2 px-3 py-2.5 text-[0.8125rem] text-ink-2`,children:[(0,V.jsx)(Ke,{className:`mt-0.5 size-3.5 shrink-0 text-ink-3`}),(0,V.jsx)(`span`,{children:(0,V.jsx)(ie,{text:s.problem})})]}):null,c?.kind===`client`&&X(e)?null:(0,V.jsx)(K,{title:I(`models.try`),children:(0,V.jsx)(oa,{cap:e,disabled:!v||!n.canEdit},`${e}:${s.ref}`)})]})]})}function pa(e){let t=t=>{let n=e.bindings[t]??``;return/^(ollama|apple):/.test(n)?``:n};return{classifier:`apple:default`,low:`apple:default`,standard:t(`standard`),high:t(`high`)}}function ma(e){if(e.available)return I(`models.optAppleNote`);switch(e.reason){case`off`:return I(`models.appleOff`);case`loading`:return I(`models.appleLoading`);default:return I(`models.appleDevice`)}}function ha({cap:e,state:t,place:n}){return(0,V.jsx)(K,{title:I(`models.optApple`),children:(0,V.jsx)(q,{children:X(e)?I(`models.appleHint`,{way:Zi(t.ways.standard,n).text}):I(`models.appleListenHint`)})})}function ga({state:e,disabled:t,onOpen:n}){let r=Z();return(0,V.jsxs)(K,{title:I(`models.optLocal`),aside:(0,V.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:()=>n({type:`local`}),children:[I(`models.ollamaOpen`),(0,V.jsx)(v,{className:`size-4`})]}),children:[(0,V.jsx)(q,{children:I(`models.ollamaHint`)}),(0,V.jsx)(Lr,{job:`text`,inUse:[(e.bindings.low??``).replace(/^ollama:/,``)],disabled:t,onChoose:e=>r.mutate({bindings:Object.fromEntries(Ct.map(t=>[t,`ollama:${e}`]))})}),r.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null]})}function _a(e){return[...Object.values(e.bindings).filter(e=>!!e?.startsWith(`ollama:`)).map(e=>e.slice(7)),e.embedding.local,...e.decision.local?[e.decision.local]:[]]}function va({state:e,place:t}){let n=Z(),r=f(),{data:i}=Ir(),[a,o]=(0,B.useState)(e.ollamaUrl),s=i?.ollama.version;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:ht,title:`Ollama`,lead:I(`models.ollamaLead`),status:i?(0,V.jsx)(Rr,{text:s?I(`models.ollamaRuns`,{version:s}):i.ollama.installed?I(`models.ollamaStoppedShort`):I(`models.ollamaMissingShort`),tone:s?`done`:`warn`}):null}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,V.jsxs)(K,{title:I(`models.ollamaModels`),children:[(0,V.jsx)(q,{children:I(`models.ollamaModelsHint`)}),(0,V.jsx)(Lr,{inUse:_a(e),disabled:!t.canEdit})]}),(0,V.jsxs)(K,{title:I(`models.ollamaAddress`),children:[(0,V.jsx)(q,{children:I(`models.ollamaAddressHint`)}),(0,V.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]`,children:[(0,V.jsx)(y,{className:`font-mono text-[0.8125rem]`,value:a,disabled:!t.canEdit,onChange:e=>o(e.target.value)}),(0,V.jsx)(O,{variant:`secondary`,busy:n.isPending,disabled:!t.canEdit||!a.trim()||a.trim()===e.ollamaUrl,onClick:()=>n.mutate({ollamaUrl:a},{onSuccess:()=>r.invalidateQueries({queryKey:[`models`,`local`]})}),children:I(`settings.save`)})]}),n.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:n.error.message}):null]})]})]})}var ya=[`claude`,`codex`,`cursor`],ba=[`openai`,`anthropic`,`google`,`gateway`];function xa(e,t,n){return e===`models`?I(`models.chatModels`):e===`account`?n.cloud?I(`models.creditsOrganization`):I(`models.creditsName`):t.harnesses.find(t=>t.id===e)?.name??P(e)?.name??e}function Sa({me:e,state:t,place:n,onOpen:i}){let a=f(),o=R({mutationFn:e=>r.put(`/api/studio/local/chat`,{engine:e}),onSuccess:()=>a.invalidateQueries({queryKey:[`me`]})}),[s,c]=(0,B.useState)(!1),l=t=>e.chatWays.includes(t),u=e=>{c(!1),e===`account`&&!l(e)?c(!0):ba.includes(e)&&!l(e)?i({type:`provider`,id:e}):o.mutate(e)},d=n.harnesses.filter(e=>ya.includes(e.id)&&e.version!==null),p=(t,r,i,a,o=!1)=>(0,V.jsx)($,{title:r,note:i,noteTone:a?`done`:void 0,selected:e.chatEngine===t,disabled:!n.canEdit||o,onPick:()=>u(t)},t);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:me,title:I(`models.cap.chat`),lead:I(`models.cap.chat.hint`),status:(0,V.jsx)(Rr,{text:xa(e.chatEngine,e,n),tone:l(e.chatEngine)?`done`:`warn`})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[n.cloud?(0,V.jsxs)(K,{title:I(`models.who`),children:[(0,V.jsx)(Q,{label:I(`models.optOther`),children:(0,V.jsx)($,{title:I(`models.creditsOrganization`),note:I(`models.chatCloudHint`),noteTone:`done`,selected:!0,disabled:!0,onPick:()=>void 0})}),(0,V.jsx)(q,{children:I(`models.chatCloudHint`)})]}):(0,V.jsxs)(K,{title:I(`models.who`),children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[d.length?(0,V.jsx)(Q,{label:I(`models.optSubscription`),children:d.map(e=>p(e.id,e.name,Xi(e).note,l(e.id),!l(e.id)))}):null,(0,V.jsx)(Q,{label:I(`models.optKey`),children:ba.map(e=>p(e,P(e)?.name??e,t.keys[e]?I(`models.noteKey`):I(`models.noteNoKey`),!!t.keys[e]))}),(0,V.jsx)(Q,{label:I(`models.optOther`),children:p(`account`,xa(`account`,e,n),l(`account`)?I(`models.noteUsage`):I(`models.noteNeedsAccount`),l(`account`))})]}),s?(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[I(`local.sourceNeedsAccount`),` `,(0,V.jsx)(Da,{})]}):null,o.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:o.error.message}):null,(0,V.jsx)(q,{children:I(`models.chatHint`)})]}),n.cloud?null:(0,V.jsx)(Ca,{me:e,way:e.chatEngine,disabled:!n.canEdit})]})]})}function Ca({me:e,way:t,disabled:n}){let i=f(),a=e.chatModels.ways[t],o=e.chatModels.chosen[t]??{},s=R({mutationFn:e=>r.put(`/api/studio/local/chat-models`,{way:t,...e}),onSuccess:()=>i.invalidateQueries({queryKey:[`me`]})});if(!a)return null;let c=(e,r,i)=>(0,V.jsx)(wa,{title:r,hint:i,listed:a.models,latest:a[e],value:o[e]??``,disabled:n||s.isPending,onPick:t=>s.mutate({[e]:t||null})},`${t}-${e}-${o[e]??``}`);return(0,V.jsxs)(K,{title:I(`models.chatModelsTitle`),children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[c(`normal`,I(`models.chatModelNormal`),I(`models.chatModelNormalHint`)),c(`extra`,I(`composer.extra`),I(`composer.extraHint`))]}),s.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:s.error.message}):null]})}function wa({title:e,hint:t,listed:n,latest:r,value:i,disabled:a,onPick:o}){let s=e=>n.find(t=>t.id===e)?.label??e.replace(/^[a-z]+:/,``),c=i===``||n.some(e=>e.id===i),[l,u]=(0,B.useState)(!c),[d,f]=(0,B.useState)(c?``:i);return(0,V.jsxs)(`div`,{className:`grid items-start gap-x-4 gap-y-1.5 sm:grid-cols-[10rem_minmax(0,1fr)]`,children:[(0,V.jsxs)(`div`,{className:`pt-2`,children:[(0,V.jsx)(`div`,{className:`text-[0.875rem]`,children:e}),t?(0,V.jsx)(`div`,{className:`text-[0.75rem] text-ink-3`,children:t}):null]}),(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsx)(C,{value:l?ea:i,onChange:e=>{e===ea?u(!0):(u(!1),o(e))},options:[{value:``,label:I(`models.latest`,{model:s(r)})},...n.map(e=>({value:e.id,label:e.label})),{value:ea,label:I(`models.modelCustom`)}]}),l?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(y,{className:`min-w-0 flex-1 font-mono text-[0.8125rem]`,value:d,disabled:a,placeholder:r,onChange:e=>f(e.target.value)}),(0,V.jsx)(O,{variant:`secondary`,disabled:!d.trim()||a,onClick:()=>o(d.trim()),children:I(`settings.save`)})]}):null]})]})}function Ta({provider:e,state:t,place:n,onOpen:r}){let i=Z(),a=ue.filter(t=>e.models[t]?.length),o=t.keys[e.id],s=e.id===`gateway`?[]:t.creditModels.filter(t=>t.source===e.id||t.provider===e.id);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:ze,title:e.name,lead:Ge(e.about,F),status:(0,V.jsx)(Rr,{text:I(o?`models.keyStored`:`models.keyNone`),tone:o?`done`:`warn`})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,V.jsx)(K,{title:I(`models.key`),children:(0,V.jsx)($i,{provider:e,stored:o,hint:t.keyHints?.[e.id],place:n})}),(0,V.jsx)(K,{title:I(`models.uses`),children:(0,V.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:a.map(a=>{let o=Ki[a],s=Ji(t,a,n),c=s?.kind===`key`&&s.provider===e.id;return(0,V.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 py-2.5`,children:[(0,V.jsx)(o,{className:`size-4 shrink-0 text-ink-3`}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>r({type:`cap`,id:a}),className:`min-w-0 flex-1 text-left`,children:[(0,V.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:I(`models.cap.${a}`)}),(0,V.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:(e.models[a]??[]).map(e=>e.label).join(` · `)})]}),c?(0,V.jsxs)(`span`,{className:`flex items-center gap-1 font-medium text-[0.75rem] text-moss`,children:[(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}),` `,I(`models.inUse`)]}):(0,V.jsx)(O,{size:`sm`,variant:`secondary`,disabled:!n.canEdit,busy:i.isPending&&i.variables?.bindings!==void 0,onClick:()=>i.mutate({...X(a)&&!n.cloud?{source:`own`}:{},bindings:Yi(e,a,t)}),children:I(`models.useFor`)})]},a)})})}),s.length?(0,V.jsxs)(K,{title:I(`models.viaCredits`,{name:e.name}),children:[(0,V.jsx)(q,{children:n.credits?I(`models.viaCreditsHint`):I(`models.viaCreditsNeedsAccount`)}),(0,V.jsx)(da,{models:s,state:t,place:n})]}):null]})]})}function Ea({me:e,id:t,state:n,place:r}){let i=Z(),a=r.harnesses.find(e=>e.id===t);if(!a)return null;let o=n.source===t,s=a.version!==null&&a.auth!==`none`;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:Pe,title:a.name,lead:I(`harness.desc.${t}`),status:(0,V.jsx)(Rr,{text:Xi(a).note,tone:s?`done`:`warn`})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,V.jsx)(K,{title:I(`models.clientSignIn`),children:(0,V.jsx)(Se,{me:e,id:t})}),(0,V.jsxs)(K,{title:I(`models.uses`),children:[(0,V.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:[`text`,...a.images?[`image`]:[]].map(e=>{let a=Ki[e],o=Ji(n,e,r),s=o?.kind===`client`&&o.id===t;return(0,V.jsxs)(`li`,{className:`flex items-center gap-3 py-2.5`,children:[(0,V.jsx)(a,{className:`size-4 shrink-0 text-ink-3`}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 font-medium text-[0.875rem]`,children:I(`models.cap.${e}`)}),s?(0,V.jsxs)(`span`,{className:`flex items-center gap-1 font-medium text-[0.75rem] text-moss`,children:[(0,V.jsx)(z,{className:`size-3.5`,strokeWidth:3}),` `,I(`models.inUse`)]}):(0,V.jsx)(O,{size:`sm`,variant:`secondary`,busy:i.isPending,onClick:()=>i.mutate(e===`text`?{source:t,bindings:At(n.bindings)}:{bindings:{image:`${t}/image`}}),children:I(`models.useFor`)})]},e)})}),o?null:(0,V.jsx)(q,{children:I(`models.clientNotChosen`,{name:a.name})})]})]})]})}function Da(){return(0,V.jsx)(D,{to:`/settings/account`,className:`font-medium text-ember-strong underline-offset-2 hover:underline`,children:I(`local.toAccount`)})}function Oa({state:e,place:t,onOpen:n}){let r=Z(),i=ue.filter(t=>e.ways[Y[t]].kind===`credits`),a=t.cloud?I(`models.creditsOrganization`):I(`models.creditsName`);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:rn,title:a,lead:t.cloud?I(`models.creditsCloudHint`):I(`models.creditsLocalLead`),status:t.balance===null?void 0:(0,V.jsx)(`span`,{className:`font-display font-semibold text-[1.25rem] tabular-nums`,children:I(`nav.credits`,{n:Math.floor(t.balance).toLocaleString(F)})})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[!t.cloud&&!t.account?(0,V.jsxs)(K,{title:I(`models.creditsConnectTitle`),children:[(0,V.jsx)(q,{children:I(`models.creditsLocalHint`)}),(0,V.jsx)(`div`,{children:(0,V.jsx)(D,{to:`/settings/account`,children:(0,V.jsx)(O,{children:I(`models.creditsConnect`)})})})]}):null,t.account&&!t.account.signedIn?(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-rose`,children:[I(`local.accountExpired`),` `,(0,V.jsx)(Da,{})]}):null,t.account?(0,V.jsx)(K,{title:I(`models.creditsFallback`),children:(0,V.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,V.jsx)(T,{checked:e.creditFallback,disabled:!t.canEdit,onChange:e=>r.mutate({creditFallback:e}),label:I(`models.creditsFallback`)}),(0,V.jsx)(q,{children:e.creditFallback?I(`models.creditsFallbackOn`):I(`models.creditsFallbackOff`)})]})}):null,t.credits?(0,V.jsx)(K,{title:I(`models.creditsOn`),aside:t.topUp?(0,V.jsxs)(`a`,{href:t.topUp,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 font-medium text-[0.8125rem] text-ember-strong hover:underline`,children:[I(`models.creditsTopUp`),` `,(0,V.jsx)(Ht,{className:`size-3`})]}):null,children:i.length?(0,V.jsx)(`ul`,{className:`flex flex-col divide-y divide-border-soft`,children:i.map(t=>{let r=Ki[t],i=e.ways[Y[t]];return(0,V.jsx)(`li`,{children:(0,V.jsxs)(`button`,{type:`button`,onClick:()=>n({type:`cap`,id:t}),className:`flex w-full items-center gap-3 py-2.5 text-left`,children:[(0,V.jsx)(r,{className:`size-4 shrink-0 text-ink-3`}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 font-medium text-[0.875rem]`,children:I(`models.cap.${t}`)}),(0,V.jsxs)(`span`,{className:`truncate text-[0.75rem] text-ink-3`,children:[i.ref?He(i.ref):``,` · `,ca(t,e)]})]})},t)})}):(0,V.jsx)(q,{children:I(`models.creditsNone`)})}):null]})]})}function ka(e,t){switch(e){case`gateway`:return`Jev · ${P(`gateway`)?.name??`Vercel AI Gateway`}`;case`typesafe`:return`Jev · TypeSafe`;case`local`:return`Clef-flash · ${I(`models.way.local`)}`;default:return`Jev · ${t.cloud?I(`models.creditsOrganization`):I(`models.creditsName`)}`}}function Aa(e,t){let{way:n}=e.decision;return n?{text:ka(n,t).split(` · `)[0],tone:n===`credits`?`ok`:`done`}:e.ways.classifier.kind===`none`?{text:I(`models.way.none`),tone:`warn`}:{text:I(`models.decisionByLlm`),tone:`done`}}function ja({state:e,place:t,onOpen:n}){let r=Z(),[i,a]=(0,B.useState)(!1),{choice:o,ready:s}=e.decision,c=Aa(e,t),l=e=>{a(!1),e===`gateway`&&!s.gateway?n({type:`provider`,id:`gateway`}):e===`credits`&&!s.credits?a(!0):r.mutate({decision:e})},u={gateway:s.gateway?I(`models.noteKey`):I(`models.noteNoKey`),typesafe:s.typesafe?I(`models.noteShellKey`):I(`models.decisionNoTypesafeKey`),local:s.local?I(`models.decisionLocalReady`):I(`models.decisionLocalMissing`),credits:s.credits?I(`models.noteUsage`):I(`models.noteNeedsAccount`)},d=e.ways.classifier;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:En,title:I(`models.cap.decision`),lead:I(`models.cap.decision.hint`),status:(0,V.jsx)(Rr,{text:c.text,tone:c.tone})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,V.jsx)(K,{title:I(`models.who`),children:t.cloud?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:I(`models.decisionModelGroup`),children:(0,V.jsx)($,{title:ka(`credits`,t),note:I(`models.decisionCloudHint`),noteTone:`done`,selected:!0,disabled:!0,onPick:()=>void 0})}),(0,V.jsx)(q,{children:I(`models.decisionCloudHint`)})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,V.jsxs)(Q,{label:I(`models.decisionModelGroup`),children:[(0,V.jsx)($,{title:I(`models.decisionAuto`),note:I(`models.decisionAutoNote`),noteTone:Wi.some(e=>s[e])?`done`:void 0,selected:o===`auto`,disabled:!t.canEdit,onPick:()=>l(`auto`)}),Wi.map(e=>(0,V.jsx)($,{title:ka(e,t),note:u[e],noteTone:s[e]?`done`:void 0,selected:o===e,disabled:!t.canEdit,onPick:()=>l(e)},e))]}),(0,V.jsx)(Q,{label:I(`models.optOther`),children:(0,V.jsx)($,{title:I(`models.decisionLlm`),note:I(`models.decisionLlmNote`),noteTone:d.kind===`none`?void 0:`done`,selected:o===`llm`,disabled:!t.canEdit,onPick:()=>l(`llm`)})})]}),i?(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[I(`local.sourceNeedsAccount`),` `,(0,V.jsx)(Da,{})]}):null,r.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null,(0,V.jsx)(q,{children:I(`models.decisionHint`)})]})}),t.cloud?null:(0,V.jsxs)(K,{title:I(`models.optLocal`),children:[(0,V.jsx)(q,{children:I(`models.decisionLocalHint`)}),(0,V.jsx)(Lr,{job:`decision`,inUse:e.decision.local?[e.decision.local]:[],disabled:!t.canEdit,onChoose:e=>r.mutate({decisionLocal:e})})]}),(0,V.jsxs)(K,{title:I(`models.decisionFallback`),aside:(0,V.jsx)(Rr,{...Zi(d,t)}),children:[(0,V.jsx)(q,{children:I(`models.decisionFallbackHint`)}),d.kind===`none`?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:I(`models.decisionFallbackNone`)}):null,(0,V.jsx)(`div`,{children:(0,V.jsxs)(O,{variant:`secondary`,onClick:()=>n({type:`cap`,id:`text`}),children:[I(`models.decisionOpenText`),(0,V.jsx)(v,{className:`size-4`})]})})]})]})]})}function Ma(e,t,n){switch(e){case`gateway`:case`openai`:return P(e)?.name??e;case`local`:return`${t.embedding.local} · ${I(`models.way.local`)}`;default:return n.cloud?I(`models.creditsOrganization`):I(`models.creditsName`)}}function Na(e,t){let{way:n}=e.embedding;return n?n===`local`?{text:e.embedding.local,tone:`done`}:{text:Ma(n,e,t),tone:n===`credits`?`ok`:`done`}:{text:I(`models.searchWordsOnly`),tone:`warn`}}function Pa({state:e,place:t,onOpen:n}){let r=Z(),[i,a]=(0,B.useState)(!1),{choice:o,ready:s}=e.embedding,l=Na(e,t),u=e=>{a(!1),(e===`gateway`||e===`openai`)&&!s[e]?n({type:`provider`,id:e}):e===`credits`&&!s.credits?a(!0):r.mutate({embedding:e})},d={gateway:s.gateway?I(`models.noteKey`):I(`models.noteNoKey`),openai:s.openai?I(`models.noteKey`):I(`models.noteNoKey`),local:s.local?I(`models.decisionLocalReady`):I(`models.decisionLocalMissing`),credits:s.credits?I(`models.noteUsage`):I(`models.noteNeedsAccount`)};return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:c,title:I(`models.cap.search`),lead:I(`models.cap.search.hint`),status:(0,V.jsx)(Rr,{text:l.text,tone:l.tone})}),(0,V.jsxs)(A,{className:`flex flex-col gap-6 p-3.5 sm:p-5 sm:p-6`,children:[(0,V.jsx)(K,{title:I(`models.who`),children:t.cloud?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:I(`models.searchModelGroup`),children:(0,V.jsx)($,{title:Ma(`credits`,e,t),note:I(`models.searchCloudHint`),noteTone:`done`,selected:!0,disabled:!0,onPick:()=>void 0})}),(0,V.jsx)(q,{children:I(`models.searchCloudHint`)})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,V.jsxs)(Q,{label:I(`models.searchModelGroup`),children:[(0,V.jsx)($,{title:I(`models.decisionAuto`),note:I(`models.decisionAutoNote`),noteTone:Ui.some(e=>s[e])?`done`:void 0,selected:o===`auto`,disabled:!t.canEdit,onPick:()=>u(`auto`)}),Ui.map(n=>(0,V.jsx)($,{title:Ma(n,e,t),note:d[n],noteTone:s[n]?`done`:void 0,selected:o===n,disabled:!t.canEdit,onPick:()=>u(n)},n))]}),(0,V.jsx)(Q,{label:I(`models.optOther`),children:(0,V.jsx)($,{title:I(`models.searchOff`),note:I(`models.searchOffNote`),noteTone:`done`,selected:o===`off`,disabled:!t.canEdit,onPick:()=>u(`off`)})})]}),i?(0,V.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:[I(`local.sourceNeedsAccount`),` `,(0,V.jsx)(Da,{})]}):null,r.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null,(0,V.jsx)(q,{children:I(`models.searchHint`)})]})}),t.cloud?null:(0,V.jsxs)(K,{title:I(`models.optLocal`),children:[(0,V.jsx)(q,{children:s.local?I(`models.searchLocalReady`,{model:e.embedding.local}):I(`models.searchLocalHint`,{model:e.embedding.local})}),(0,V.jsx)(Lr,{job:`search`,inUse:[e.embedding.local],disabled:!t.canEdit,onChoose:e=>r.mutate({embeddingLocal:e})})]}),(0,V.jsxs)(K,{title:I(`models.searchFallback`),aside:e.embedding.way?null:(0,V.jsx)(Rr,{text:I(`models.searchWordsOnly`),tone:`warn`}),children:[(0,V.jsx)(q,{children:I(`models.searchFallbackHint`)}),(0,V.jsx)(q,{children:I(`models.searchReindexHint`)})]})]})]})}var Fa=[`chat`,`credits`,`subs`,`local`,`keys`,`masking`,`scope`,`choice`,`apps`],Ia=[`claude`,`codex`,`antigravity`,`cursor`];function La(e){return e?Fa.includes(e)?{type:e}:e.startsWith(`key:`)?{type:`account`,id:e.slice(4)}:e===`decision`||e===`search`?{type:`cap`,id:`text`}:e===`ollama`?{type:`local`}:ue.includes(e)?{type:`cap`,id:e}:P(e)?{type:`provider`,id:e}:Ia.includes(e)?{type:`client`,id:e}:{type:`overview`}:{type:`overview`}}var Ra=e=>e.type===`overview`?null:e.type===`account`?`key:${e.id}`:e.type===`cap`||e.type===`provider`||e.type===`client`?e.id:e.type,za={text:[`text`],media:[`image`,`video`],voice:[`speech`,`listening`]},Ba={text:[`standard`],media:[`image`,`video`],voice:[`speech`,`audio`]},Va=e=>e===`text`?`text`:e===`image`||e===`video`?`media`:`voice`;function Ha({view:e,onView:t}){return null}function Ua(e,t,n){switch(e.type){case`account`:return n?.accounts.find(t=>t.id===e.id)?.label??I(`overview.menu.keys`);case`overview`:return I(`overview.nav`);case`chat`:return I(`models.cap.chat`);case`cap`:return I(`overview.job.${Va(e.id)}`);case`subs`:return I(`overview.menu.subs`);case`local`:return I(`overview.menu.local`);case`keys`:return I(`overview.menu.keys`);case`masking`:return I(`overview.menu.masking`);case`scope`:return I(`overview.scope`);case`choice`:return I(`policy.way`);case`apps`:return I(`policy.apps`);case`provider`:return P(e.id)?.name??e.id;case`client`:return t?.harnesses.find(t=>t.id===e.id)?.name??e.id;default:return t?.mode===`managed`?I(`models.creditsOrganization`):I(`models.creditsName`)}}function Wa(e,t){return t.cloud?`cloud`:e===`client`||e===`local`||e===`pc`?`pc`:`cloud`}function Ga(e,t){if(t&&Te(t))return t.name;if(e.kind===`credits`||!e.ref)return e.ref&&!Qe(e.ref)?He(e.ref):I(`chooser.auto`);if(e.kind===`client`){let t=e.ref.split(`/`)[1]??e.ref;return t.charAt(0).toUpperCase()+t.slice(1)}return He(e.ref)}function Ka(e,t){let{way:n}=e.decision;return n?n===`local`?{name:`Ollama`,where:Wa(`pc`,t)}:n===`credits`?{name:I(`models.creditsName`),where:`cloud`}:{name:ka(n,t).split(` · `).pop()??n,where:`cloud`}:null}function qa(e,t){let{way:n}=e.embedding;return n?n===`local`?{name:`Ollama`,where:Wa(`pc`,t)}:n===`credits`?{name:I(`models.creditsName`),where:`cloud`}:{name:P(n)?.name??n,where:`cloud`}:null}var Ja=e=>I(`nav.credits`,{n:Math.floor(e).toLocaleString(F)});function Ya(e){let t=e.tenant.plan?.id??``;return t.startsWith(`team`)?`team`:t.startsWith(`pro`)?`pro`:null}function Xa(e){return e===`general`||e===`eu-private`||e===`eu-sovereign`?I(`overview.scope.${e}`):``}function Za(e,t){let{state:n,place:r,tier:i}=t,a=Ba[e],o={id:e,name:I(`overview.job.${e}`),purpose:I(`overview.purpose.${e}`),onOpen:()=>t.open({type:`cap`,id:za[e][0]})};if(i&&a.every(e=>!Te(i.classes[e])))return{...o,state:`na`,where:null,access:``,model:``,naText:I(`policy.notIn`,{tier:i.name})};if(a.some(e=>n.ways[e].kind===`none`))return{...o,state:`miss`,where:null,access:``,model:``};let s=n.ways[a[0]],c=Xr(t.accounts,a[0]);return{...o,state:`ok`,where:Wa(s.kind,r),access:c?.access??(s.kind===`credits`?I(`overview.credits`):Zi(s,r).text),model:c?.model??Ga(s,i?.classes[a[0]])}}function Qa(e){let{me:t,place:n,tier:r}=e,i=t.chatEngine,a=t.chatModels.ways[i],o=t.chatModels.chosen[i]?.normal??a?.normal,s=Za(`text`,e);return{id:`chat`,name:I(`models.cap.chat`),purpose:I(`overview.purpose.chat`),onOpen:()=>e.open({type:`chat`}),state:t.chatWays.includes(i)?`ok`:`miss`,where:i===`models`?s.where:Wa(Ia.includes(i)?`pc`:`cloud`,n),access:i===`models`&&e.accounts?s.access:n.cloud||i===`account`?I(`overview.credits`):i===`models`?s.access:xa(i,t,n),model:i===`models`?s.model:a?a.models.find(e=>e.id===o)?.label??o??``:r&&Te(r.classes.standard)?r.classes.standard.name:I(`chooser.auto`)}}function $a(e,t){let{me:n,state:r,place:i,tier:a,policy:o}=e,s=t.filter(e=>e.state===`miss`).length;if(i.cloud){let e=Re(a);return{name:Ya(n)===`team`&&n.tenant.name?I(`overview.hero.orgCredits`,{organization:n.tenant.name}):I(`models.creditsName`),sub:a&&e?I(`overview.hero.cloudStrict`,{tier:a.name}):I(`overview.hero.cloudAll`),plan:n.tenant.plan?.name??null,where:`cloud`,missing:s,helpers:a&&o.masking?[{name:I(`overview.menu.masking`),jobs:I(`overview.maskingJobs`),where:null}]:[]}}let c=r.ways.standard,l=c.kind===`none`?null:Zi(c,i).text,u=c.kind===`client`?i.harnesses.find(e=>e.id===c.by):null,d=new Map,f=(e,t,n)=>{if(e===l)return;let r=d.get(e);d.set(e,{name:e,where:n,jobs:r?`${r.jobs}, ${t}`:t})},p=Ka(r,i);p&&f(p.name,I(`models.cap.decision`),p.where);let m=qa(r,i);m&&f(m.name,I(`overview.knowledge`),m.where);for(let e of t.filter(e=>e.id===`media`||e.id===`voice`))e.state===`ok`&&f(e.access,e.name,e.where);return{name:l??I(`overview.hero.none`),sub:u?I(`overview.hero.client`,{sub:I(`harness.sub.${u.id}`)}):c.kind===`key`?I(`overview.hero.key`):c.kind===`local`?I(`overview.hero.local`):c.kind===`credits`?I(`overview.hero.credits`):I(`overview.hero.noneSub`),where:c.kind===`client`||c.kind===`local`||c.kind===`none`?`pc`:`cloud`,missing:s,helpers:[...d.values()]}}function eo(e,t){let{me:n,state:r,place:i,tier:a,policy:o,admin:s,ollama:c,open:l}=e,u=Je.filter(e=>r.keys[e.id]),d=[],f=n.tenant.name??I(`policy.yourOrganization`);if(i.cloud){if(d.push({kind:`row`,id:`credits`,name:I(`overview.credits`),desc:Ya(n)===`team`?I(`overview.credits.team`,{organization:f,n:Ja(i.balance??0)}):I(`overview.credits.plan`,{plan:n.tenant.plan?.name??``,n:Ja(i.balance??0)}),button:i.topUp?{label:I(`overview.topUp`),onClick:()=>Le(i.topUp)}:null,onOpen:()=>l({type:`credits`})}),!i.ownKeys)d.push({kind:`row`,id:`keys`,name:I(`policy.ownKeys`),desc:I(`overview.keys.plan`),status:I(`overview.fromPro`),muted:!0});else if(i.accounts&&e.accounts){let t=Zr(e.accounts);d.push({kind:`row`,id:`keys`,name:I(`policy.ownKeys`),desc:t.desc,status:t.status,onOpen:()=>l({type:`keys`})})}if(!a)return d;if(!s)return[...d,{kind:`row`,id:`scope`,name:I(`overview.scope`),desc:Xa(a.id),value:a.name,onOpen:()=>l({type:`scope`})}];let t=Re(a),r=t=>e.savePolicy({...o,...t});return d.push(...i.ownKeys&&!i.accounts?[{kind:`row`,id:`keys`,name:I(`policy.ownKeys`),desc:I(`overview.keys.admin`),note:t&&o.ownKeys?I(`policy.ownKeys.warn`,{tier:a.name}):null,toggle:{on:o.ownKeys,onChange:e=>r({ownKeys:e})},onOpen:()=>l({type:`keys`})}]:[],{kind:`row`,id:`subs`,name:I(`overview.subs`),desc:I(`overview.subs.desc`),note:t&&o.subscriptions?I(`policy.subscriptions.warn`):null,toggle:{on:o.subscriptions,onChange:e=>r({subscriptions:e})},onOpen:()=>l({type:`subs`})},{kind:`row`,id:`local`,name:I(`overview.localModels`),desc:I(`overview.localModels.desc`),toggle:{on:o.localModels,onChange:e=>r({localModels:e})},onOpen:()=>l({type:`local`})},{kind:`row`,id:`masking`,name:I(`policy.masking`),desc:o.maskLabels.length?I(`overview.masking.descLabels`,{labels:o.maskLabels.join(`, `)}):I(`overview.masking.desc`),toggle:{on:o.masking,onChange:e=>r({masking:e})},onOpen:()=>l({type:`masking`})},{kind:`row`,id:`choice`,name:I(`policy.way`),desc:I(`overview.choice`),value:bi(o.way),onOpen:()=>l({type:`choice`})}),d}d.push(i.account?{kind:`row`,id:`credits`,name:I(`overview.credits`),desc:I(`overview.credits.linked`),status:i.balance===null?null:Ja(i.balance),onOpen:()=>l({type:`credits`})}:{kind:`row`,id:`credits`,name:I(`overview.credits`),desc:I(`overview.credits.local`),button:{label:I(`models.creditsConnect`),primary:!0,onClick:()=>l({type:`credits`})},onOpen:()=>l({type:`credits`})}),i.account&&d.push({kind:`row`,id:`fallback`,name:I(`models.creditsFallback`),desc:I(`overview.credits.fallback`),toggle:{on:r.creditFallback,disabled:!i.canEdit,onChange:e=>t.mutate({creditFallback:e})}}),d.push({kind:`label`,label:I(`overview.onComputer`)});for(let e of i.harnesses.filter(e=>e.version!==null)){let t=e.auth!==`none`;d.push({kind:`row`,id:e.id,name:e.name,desc:I(`overview.client.desc`,{sub:I(`harness.sub.${e.id}`)}),status:t?I(e.auth===`api_key`?`overview.client.key`:`overview.client.in`):null,button:t?null:{label:I(`overview.client.signIn`),onClick:()=>l({type:`client`,id:e.id})},onOpen:()=>l({type:`client`,id:e.id})})}return r.apple?.supported&&d.push({kind:`row`,id:`apple`,name:I(`models.optApple`),desc:I(`overview.apple.desc`),status:I(r.apple.available?`overview.ready`:`overview.off`),muted:!r.apple.available,onOpen:()=>l({type:`cap`,id:`text`})}),d.push({kind:`row`,id:`ollama`,name:`Ollama`,desc:c?.models.length?c.models.join(`, `):I(`overview.ollama.desc`),status:c?.running&&c.models.length?I(c.models.length===1?`overview.ollama.one`:`overview.ollama.n`,{n:c.models.length}):null,button:c?.running&&c.models.length?null:{label:I(`overview.setUp`),onClick:()=>l({type:`local`})},onOpen:()=>l({type:`local`})}),d.push({kind:`row`,id:`keys`,name:I(`policy.ownKeys`),desc:u.length?u.map(e=>e.name).join(`, `):Je.slice(0,5).map(e=>e.name).join(`, `),status:u.length?I(`overview.keys.stored`,{n:u.length}):null,button:{label:I(`overview.keys.add`),onClick:()=>l({type:`keys`})},onOpen:()=>l({type:`keys`})}),d}function to(e){let t=f(),n=R({mutationFn:e=>r.put(`/api/studio/model-tier`,{tier:e}),onSuccess:e=>t.setQueryData([`models`],e)}),i=e?.choices??[],a=i.every(e=>e.inPlan);return{options:i.map(t=>({id:t.id,name:t.name,desc:Xa(t.id),tag:t.inPlan?a&&t.id===`eu-private`?I(`overview.recommended`):null:I(t.id===`eu-sovereign`?`overview.fromTeam`:`overview.fromPro`),on:t.id===(n.isPending?n.variables:e?.id),disabled:!t.inPlan})),save:n}}function no({tier:e,canEdit:t}){let{options:n,save:r}=to(e);return n.length?(0,V.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,V.jsx)(ui,{options:n,locked:e.locked,disabled:!t||r.isPending,onPick:e=>r.mutate(e)}),r.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:r.error.message}):null]}):null}function ro({s:e}){let t=Z(),{me:n,place:r,tier:i}=e,a=[Qa(e)],o=[`text`,`media`,`voice`].map(t=>Za(t,e)),s=n.tenant.name??I(`policy.yourOrganization`);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-3.5`,children:[(0,V.jsx)(`h1`,{className:`font-display font-semibold text-[1.625rem] leading-tight tracking-tight`,children:I(`overview.title`)}),(0,V.jsx)(li,{hero:$a(e,[...a,...o])})]}),e.admin&&i?.choices?.length?(0,V.jsx)(mi,{title:I(`overview.scope`),lead:I(`overview.scopeLead`,{organization:s}),children:(0,V.jsx)(no,{tier:i,canEdit:r.canEdit})}):null,(0,V.jsxs)(mi,{title:I(`overview.jobs`),lead:r.cloud&&i&&!r.canEdit?I(`overview.jobsLead.member`,{organization:s}):e.admin&&Ya(n)===`team`?I(`overview.jobsLead.team`,{organization:s}):I(`overview.jobsLead`),children:[(0,V.jsx)(fi,{title:I(`models.groupStudio`),desc:I(r.cloud?`overview.studioDesc.cloud`:`overview.studioDesc`),jobs:a}),(0,V.jsx)(fi,{title:I(`models.groupRuns`),desc:I(r.cloud?`overview.runsDesc.cloud`:r.account?`overview.runsDesc.linked`:`overview.runsDesc`),jobs:o})]}),(0,V.jsxs)(mi,{title:I(`models.groupAccess`),lead:e.admin?I(`overview.accessLead.admin`,{organization:s}):I(r.cloud?`overview.accessLead.member`:`overview.accessLead`),children:[(0,V.jsx)(pi,{rows:eo(e,t)}),t.isError?(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:t.error.message}):null]})]})}function io({s:e}){let{state:t,place:n,tier:r,policy:i,admin:a}=e,o=[...Je].sort((e,n)=>Number(!!t.keys[n.id])-Number(!!t.keys[e.id]));return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:ze,title:I(`overview.menu.keys`),lead:I(`overview.keysLead`)}),a&&r?(0,V.jsx)(Ti,{tier:r,policy:i,field:`ownKeys`,canEdit:n.canEdit}):null,t.ownKeysUnused&&Object.values(t.keys).some(Boolean)?(0,V.jsx)(q,{children:I(`overview.keysUnused`)}):null,n.ownKeys?(0,V.jsx)(pi,{rows:o.map(r=>({kind:`row`,id:r.id,name:r.name,desc:Ge(r.about,F),note:t.keys[r.id]?Hi(t.keyHints?.[r.id],n):null,status:t.keys[r.id]?t.keyHints?.[r.id]?.masked??I(`models.noteKey`):null,button:t.keys[r.id]?null:{label:I(`overview.keys.add`),onClick:()=>e.open({type:`provider`,id:r.id})},onOpen:()=>e.open({type:`provider`,id:r.id})}))}):(0,V.jsx)(A,{className:`p-5 sm:p-6`,children:(0,V.jsx)(q,{children:I(`overview.keys.plan`)})})]})}function ao({s:e}){let{me:t,state:n,place:r,tier:i,policy:a,admin:o}=e;if(r.cloud)return(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:Pe,title:I(`overview.menu.subs`),lead:I(`overview.subsLead.cloud`)}),o&&i?(0,V.jsx)(Ti,{tier:i,policy:a,field:`subscriptions`,canEdit:r.canEdit}):(0,V.jsx)(A,{className:`p-5 sm:p-6`,children:(0,V.jsx)(q,{children:I(a.subscriptions?`overview.subs.allowed`:`overview.subs.refused`)})})]});let s=r.harnesses.filter(e=>e.version!==null),c=s.length?s:r.harnesses.filter(e=>e.id===`claude`||e.id===`codex`);return(0,V.jsx)(`div`,{className:`flex flex-col gap-8`,children:c.map(e=>(0,V.jsx)(Ea,{me:t,id:e.id,state:n,place:r},e.id))})}function oo({s:e}){let{state:t,place:n,tier:r,policy:i,admin:a}=e;return n.cloud?(0,V.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,V.jsx)(J,{icon:ht,title:I(`overview.menu.local`),lead:I(`overview.localLead.cloud`)}),a&&r?(0,V.jsx)(Ti,{tier:r,policy:i,field:`localModels`,canEdit:n.canEdit}):(0,V.jsx)(A,{className:`p-5 sm:p-6`,children:(0,V.jsx)(q,{children:I(i.localModels?`overview.local.allowed`:`overview.local.refused`)})})]}):(0,V.jsx)(va,{state:t,place:n})}function so(){let e=Dt(),t=Qi(),n=Ir(!!e.data&&e.data?.mode!==`managed`),[r,i]=x(),a=h(),[o,c]=(0,B.useState)(`auto`),{narrow:l}=zt(),u=yi(),d=r.get(`show`),f=La(d),p=fe(`modelTiers`)?t.data?.tier??null:null,m=t.data?.modelPolicy??gi,g=Vr(fe(`ownKeysGateway`)&&e.data?.mode===`managed`);if(Nt(d||!l?Ua(f,e.data,g.data):null),!e.data||!t.data)return t.isError?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:t.error.message}):null;let _=t.data,v=e.data,y=Gi(v,o),b=e=>i(Ra(e)?{show:Ra(e)}:{},{replace:!l}),S=e=>e.type===`cap`?Va(e.id):e.type===`provider`||e.type===`account`?`keys`:e.type===`client`?`subs`:e.type,C=e=>!(!d&&l)&&S(e)===S(f),w={me:e.data,state:_,place:y,tier:p,policy:m,admin:y.cloud&&y.canEdit&&!!p,ollama:y.cloud?null:{running:!!n.data?.ollama.version,models:n.data?.installed.map(e=>e.name.replace(/:latest$/,``))??[]},accounts:y.accounts?g.data??null:null,open:b,savePolicy:e=>u.mutate(e)},ee=Qa(w),T=[`text`,`media`,`voice`].map(e=>Za(e,w)),E=e=>e.state===`ok`?`done`:e.state===`miss`?`miss`:`off`,te=e=>e.state===`ok`?e.access:e.state===`miss`?I(`overview.missingWord`):e.naText??``,D=e=>e?(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:e}):null,O=e=>I(e?`overview.on`:`overview.off`),ne=Je.filter(e=>_.keys[e.id]).length,k=w.accounts?.accounts.filter(e=>e.status===`refused`).length??0,re=y.harnesses.filter(e=>e.version!==null&&e.auth!==`none`).length,j=(w.ollama?.running?w.ollama.models.length:0)+ +!!_.apple?.available,ie=e.data.mode===`managed`&&Tt(e.data.features,`organizationSettings`);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(It,{children:[(0,V.jsx)(`ul`,{className:`mb-1 flex flex-col gap-0.5`,children:(0,V.jsx)(L,{icon:be,label:I(`overview.nav`),selected:C({type:`overview`}),onPick:()=>b({type:`overview`})})}),(0,V.jsx)(Rt,{label:I(`models.groupStudio`),children:(0,V.jsx)(L,{icon:me,label:I(`models.cap.chat`),tone:E(ee),toneLabel:te(ee),selected:C({type:`chat`}),onPick:()=>b({type:`chat`})})}),(0,V.jsx)(Rt,{label:I(`models.groupRuns`),children:T.map(e=>(0,V.jsx)(L,{icon:co[e.id],label:e.name,tone:E(e),toneLabel:te(e),selected:C({type:`cap`,id:za[e.id][0]}),onPick:e.onOpen},e.id))}),(0,V.jsxs)(Rt,{label:I(`models.groupAccess`),children:[(0,V.jsx)(L,{icon:rn,label:I(`overview.credits`),badge:D(y.balance===null?y.credits?null:I(`overview.missingWord`):Math.floor(y.balance).toLocaleString(F)),selected:C({type:`credits`}),onPick:()=>b({type:`credits`})}),y.cloud&&!w.admin?null:(0,V.jsx)(L,{icon:Ce,label:I(`overview.menu.subs`),badge:D(y.cloud?O(m.subscriptions):String(re)),selected:C({type:`subs`}),onPick:()=>b({type:`subs`})}),y.cloud&&!w.admin?null:(0,V.jsx)(L,{icon:ht,label:I(`overview.menu.local`),badge:D(y.cloud?O(m.localModels):String(j)),selected:C({type:`local`}),onPick:()=>b({type:`local`})}),(0,V.jsx)(L,{icon:ze,label:I(`overview.menu.keys`),tone:k?`miss`:void 0,toneLabel:k?I(`keys.state.refused`):void 0,badge:D(y.ownKeys?w.admin&&!m.ownKeys?O(!1):w.accounts?String(w.accounts.accounts.length):String(ne):I(`overview.fromPro`)),selected:C({type:`keys`}),onPick:()=>b({type:`keys`})}),w.admin?(0,V.jsx)(L,{icon:$e,label:I(`overview.menu.masking`),badge:D(O(m.masking)),selected:C({type:`masking`}),onPick:()=>b({type:`masking`})}):null]}),w.admin&&p?(0,V.jsxs)(Rt,{label:I(`tier.group`),children:[(0,V.jsx)(L,{icon:s,label:I(`overview.scope`),selected:C({type:`scope`}),onPick:()=>b({type:`scope`})}),(0,V.jsx)(L,{icon:pe,label:I(`policy.way`),badge:D(bi(m.way)),selected:C({type:`choice`}),onPick:()=>b({type:`choice`})}),(0,V.jsx)(L,{icon:hn,label:I(`policy.apps`),badge:D(Ni(m.apps)),selected:C({type:`apps`}),onPick:()=>b({type:`apps`})}),ie?(0,V.jsx)(L,{icon:sn,label:I(`credits.usage`),selected:!1,onPick:()=>a(`/settings/usage`)}):null]}):null,(0,V.jsx)(Ha,{view:o,onView:c})]}),y.canEdit||y.accounts&&S(f)===`keys`?null:(0,V.jsx)(`p`,{className:`mb-4 rounded-lg bg-paper-2 px-3 py-2 text-[0.8125rem] text-ink-2`,children:I(`models.readOnly`)}),f.type===`overview`?(0,V.jsx)(ro,{s:w}):f.type===`choice`&&p?(0,V.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[(0,V.jsx)(Ci,{tier:p,policy:m,organization:e.data.tenant.name,canEdit:y.canEdit}),m.way===`C`?(0,V.jsx)(ji,{tier:p,policy:m,canEdit:y.canEdit}):m.way===`B`?(0,V.jsx)(Mi,{tier:p,policy:m,canEdit:y.canEdit}):null]}):f.type===`apps`&&p?(0,V.jsx)(Pi,{tier:p,policy:m,canEdit:y.canEdit}):f.type===`masking`&&p?(0,V.jsx)(Ei,{tier:p,policy:m,canEdit:y.canEdit}):f.type===`scope`&&p?(0,V.jsx)(Vi,{tier:p,modelPolicy:_.modelPolicy??null,organization:e.data.tenant.name,children:w.admin?(0,V.jsx)(no,{tier:p,canEdit:y.canEdit}):null}):f.type===`chat`?(0,V.jsx)(Sa,{me:e.data,state:_,place:y,onOpen:b}):f.type===`cap`?(0,V.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[za[Va(f.id)].map(e=>(0,V.jsx)(fa,{cap:e,state:_,place:y,me:v,onOpen:b},e)),Va(f.id)===`text`?(0,V.jsxs)(V.Fragment,{children:[p?(0,V.jsx)(A,{className:`flex flex-col gap-3 p-5 sm:p-6`,children:(0,V.jsx)(K,{title:I(`chooser.title`),children:(0,V.jsx)(Bi,{tier:p,modelPolicy:_.modelPolicy??null})})}):null,(0,V.jsx)(ja,{state:_,place:y,onOpen:b}),(0,V.jsx)(Pa,{state:_,place:y,onOpen:b})]}):null]}):y.accounts&&(f.type===`keys`||f.type===`provider`)?(0,V.jsx)(Qr,{organization:e.data.tenant.name??I(`policy.yourOrganization`),canEdit:y.canEdit,tier:p,onOpen:e=>b({type:`account`,id:e}),policy:w.admin&&p?(0,V.jsx)(Ti,{tier:p,policy:m,field:`ownKeys`,canEdit:y.canEdit}):null}):f.type===`account`&&y.accounts?(0,V.jsx)($r,{id:f.id,canEdit:y.canEdit,onGone:()=>b({type:`keys`})},f.id):f.type===`keys`?(0,V.jsx)(io,{s:w}):f.type===`subs`?(0,V.jsx)(ao,{s:w}):f.type===`local`?(0,V.jsx)(oo,{s:w}):f.type===`provider`&&P(f.id)?(0,V.jsx)(Ta,{provider:P(f.id),state:_,place:y,onOpen:b},f.id):f.type===`client`?(0,V.jsx)(Ea,{me:e.data,id:f.id,state:_,place:y},f.id):(0,V.jsx)(Oa,{state:_,place:y,onOpen:b})]})}var co={text:l,media:pn,voice:ln};function lo({name:e,image:t}){return t?(0,V.jsx)(`img`,{src:t,alt:``,className:`size-9 shrink-0 rounded-full object-cover`}):(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 font-medium text-[0.75rem] text-ink-2`,children:Ot(e)})}function uo({me:e}){let t=N({queryKey:[`organization`,e.tenant.id],queryFn:()=>r.get(`/api/studio/organization`)}),n=t.data,i=n?.plan??e.tenant.plan,a=n?.seats;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsxs)(o,{title:I(`organization.title`),hint:I(`organization.hint`),children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[e.tenant.name?(0,V.jsxs)(`div`,{className:`mb-3`,children:[(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:I(`organization.name`)}),(0,V.jsx)(`div`,{className:`mt-0.5 truncate font-medium text-[0.9375rem]`,children:e.tenant.name})]}):null,(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:I(`organization.plan`)}),(0,V.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:i?.name??I(`organization.planFree`)}),a?(0,V.jsx)(E,{children:a.limit===null?I(`organization.seatsUnlimited`):I(`organization.seats`,{taken:a.taken,limit:a.limit})}):null]})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsxs)(O,{variant:`secondary`,onClick:()=>Le(`${e.manageUrl}/billing`),children:[I(`organization.changePlan`),` `,(0,V.jsx)(Ht,{className:`size-4`})]}),n?.canManage?(0,V.jsxs)(O,{onClick:()=>Le(`${e.manageUrl}/`),children:[I(`organization.manage`),` `,(0,V.jsx)(Ht,{className:`size-4`})]}):null]})]}),(0,V.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-ink-3 leading-relaxed`,children:e.tenant.role===`member`?I(`organization.memberNote`):I(`organization.roles`)})]}),(0,V.jsx)(o,{title:I(`organization.members`),children:t.isPending?(0,V.jsx)(k,{}):t.isError||!n?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`organization.failed`)}):(0,V.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[n.members.map(t=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(lo,{name:t.name,image:t.image}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`truncate text-[0.9375rem]`,children:[t.name,t.userId===e.user.id?(0,V.jsxs)(`span`,{className:`text-ink-4`,children:[` · `,I(`organization.you`)]}):null]}),(0,V.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:t.email})]}),(0,V.jsx)(E,{tone:t.role===`member`?void 0:`live`,children:I(`organization.role.${t.role}`)})]},t.userId)),n.invitations.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-3`,children:(0,V.jsx)(wn,{className:`size-4`})}),(0,V.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-[0.9375rem]`,children:e.email}),(0,V.jsxs)(E,{tone:`warn`,children:[I(`organization.invited`),` · `,I(`organization.role.${e.role}`)]})]},e.id)),n.members.length===0&&n.invitations.length===0?(0,V.jsxs)(`div`,{className:`flex items-center gap-3 text-[0.875rem] text-ink-3`,children:[(0,V.jsx)(we,{className:`size-4`}),` –`]}):null]})})]})}function fo(e){return N({queryKey:[`organization-billing`,e.tenant.id],queryFn:()=>r.get(`/api/studio/organization/billing`)})}var po=e=>new Intl.NumberFormat(F).format(Math.round(e)),mo=(e,t)=>new Intl.NumberFormat(F,{style:`currency`,currency:t.toUpperCase()}).format(e/100),ho=e=>new Intl.DateTimeFormat(F,{dateStyle:`medium`}).format(new Date(e)),go=e=>()=>window.location.assign(`${e.manageUrl}/billing`),_o={run:`credits.kind.run`,model:`credits.kind.model`,image:`credits.kind.image`,video:`credits.kind.video`,search:`credits.kind.search`,usage:`credits.kind.usage`,topup:`credits.kind.topup`,start:`credits.kind.start`,grant:`credits.kind.grant`,expire:`credits.kind.expire`,fee:`credits.kind.fee`,adjust:`credits.kind.adjust`,sms:`credits.kind.sms`,call:`credits.kind.call`},vo=e=>_o[e]?I(_o[e]):e.charAt(0).toUpperCase()+e.slice(1);function yo({daily:e,tall:t}){let n=Math.max(1,...e.map(e=>e.credits));return(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:t?`flex h-20 items-end gap-[3px]`:`flex h-14 items-end gap-[3px]`,children:e.map(e=>(0,V.jsx)(`span`,{title:I(`credits.dayLine`,{day:ho(e.day),n:po(e.credits)}),className:`flex-1 rounded-t-[2px] bg-accent`,style:{height:`${Math.max(3,e.credits/n*100)}%`}},e.day))}),t&&e.length?(0,V.jsxs)(`div`,{className:`mt-1.5 flex justify-between text-[0.75rem] text-ink-4`,children:[(0,V.jsx)(`span`,{children:ho(e[0].day)}),(0,V.jsx)(`span`,{children:ho(e[e.length-1].day)})]}):null]})}function bo({me:e}){let t=fo(e),n=t.data;if(!n)return t.isError?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`credits.failed`)}):(0,V.jsx)(k,{});let r=n.expiring.find(e=>e.kind===`monthly`),i=n.usage.last30Credits>0?Math.floor(n.balanceCredits/(n.usage.last30Credits/30)):null;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsxs)(o,{title:I(`credits.title`),hint:I(`credits.hint`,{name:e.tenant.name??``}),children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`font-display font-semibold text-[2rem] tabular-nums leading-none`,children:po(n.balanceCredits)}),(0,V.jsx)(`div`,{className:`mt-2 text-[0.875rem] text-ink-3`,children:r?I(`credits.balanceMonthly`,{n:po(r.credits),date:ho(r.expiresAt)}):I(`credits.balance`)})]}),n.canBuy&&n.topUp?(0,V.jsxs)(O,{onClick:go(e),children:[(0,V.jsx)(Wt,{className:`size-4`}),` `,I(`credits.topUp`)]}):null]}),i===null?null:(0,V.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-ink-3`,children:i>60?I(`credits.lastsLong`):I(`credits.lasts`,{n:i})}),n.canBuy?null:(0,V.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-ink-3`,children:I(`credits.onlyAdmins`)})]}),n.plan?(0,V.jsx)(o,{title:I(`credits.plan`),children:(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 text-ink-2`,children:(0,V.jsx)(Ue,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-display font-semibold text-[1rem]`,children:n.plan.name}),n.plan.cancels?(0,V.jsx)(E,{tone:`warn`,children:I(`credits.planEnds`)}):null]}),(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:[n.plan.price.amount?I(`credits.planPrice`,{price:mo(n.plan.price.amount,n.plan.price.currency)}):I(`credits.planFree`),n.plan.monthlyCredits?I(`credits.planMonthly`,{n:po(n.plan.monthlyCredits)}):null,n.plan.seats.limit===null?I(`credits.planSeatsUnlimited`):I(`credits.planSeats`,{n:n.plan.seats.limit})].filter(Boolean).join(` · `)})]}),n.canChangePlan?(0,V.jsx)(O,{variant:`secondary`,onClick:go(e),children:I(`credits.planChange`)}):null]})}):null,(0,V.jsxs)(o,{title:I(`credits.last30`),children:[(0,V.jsxs)(`div`,{className:`mb-3 flex items-baseline justify-between gap-3`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.9375rem]`,children:I(`credits.used`,{n:po(n.usage.last30Credits)})}),(0,V.jsxs)(D,{to:`/settings/usage`,className:`text-[0.8125rem] text-ink-3 transition hover:text-ink`,children:[I(`credits.seeUsage`),` ›`]})]}),(0,V.jsx)(yo,{daily:n.usage.daily})]})]})}function xo({me:e}){let t=fo(e),n=on({queryKey:[`organization-billing-activity`,e.tenant.id],initialPageParam:0,queryFn:({pageParam:e})=>r.get(`/api/studio/organization/billing/activity?limit=20${e?`&before=${e}`:``}`),getNextPageParam:e=>e.entries.length===20?e.entries[e.entries.length-1].id:void 0}),i=t.data;if(!i)return t.isError?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`credits.failed`)}):(0,V.jsx)(k,{});let a=i.usage.byClass.reduce((e,t)=>e+t.credits,0)||1,s=n.data?.pages.flatMap(e=>e.entries)??[];return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsxs)(o,{title:I(`credits.usage`),hint:I(`credits.usageHint`,{name:e.tenant.name??``}),children:[(0,V.jsx)(`div`,{className:`mb-3 font-display font-semibold text-[1.5rem] tabular-nums`,children:I(`credits.used`,{n:po(i.usage.last30Credits)})}),(0,V.jsx)(yo,{daily:i.usage.daily,tall:!0})]}),(0,V.jsx)(o,{title:I(`credits.whatFor`),children:i.usage.byClass.length?(0,V.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:i.usage.byClass.map(e=>(0,V.jsxs)(`div`,{className:`grid grid-cols-[8rem_1fr_4.5rem] items-center gap-3 text-[0.875rem]`,children:[(0,V.jsx)(`span`,{className:`truncate`,children:vo(e.label)}),(0,V.jsx)(`span`,{className:`h-1.5 overflow-hidden rounded-full bg-paper-2`,children:(0,V.jsx)(`span`,{className:`block h-full rounded-full bg-ember`,style:{width:`${e.credits/a*100}%`}})}),(0,V.jsx)(`span`,{className:`text-right text-ink-2 tabular-nums`,children:po(e.credits)})]},e.label))}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`credits.nothingUsed`)})}),(0,V.jsxs)(o,{title:I(`credits.entries`),children:[s.length?(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:s.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-2.5 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`truncate text-[0.9375rem]`,children:[e.kind===`run`?I(`credits.kind.run`):vo(e.kind),e.kind===`run`&&e.classes.length?(0,V.jsxs)(`span`,{className:`text-ink-4`,children:[` · `,e.classes.map(vo).join(`, `)]}):null]}),(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:new Intl.DateTimeFormat(F,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e.at))})]}),(0,V.jsxs)(`span`,{className:e.credits>0?`text-moss tabular-nums`:`text-ink-2 tabular-nums`,children:[e.credits>0?`+`:`−`,po(Math.abs(e.credits))]})]},e.id))}):n.isPending?(0,V.jsx)(k,{}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`credits.noEntries`)}),n.hasNextPage?(0,V.jsx)(O,{variant:`ghost`,size:`sm`,className:`mt-3`,busy:n.isFetchingNextPage,onClick:()=>void n.fetchNextPage(),children:I(`credits.more`)}):null]})]})}function So({me:e}){let t=fo(e),n=t.data;return n?(0,V.jsx)(`div`,{className:`flex flex-col gap-9`,children:(0,V.jsx)(o,{title:I(`credits.invoices`),hint:I(`credits.invoicesHint`),children:n.canBuy?n.invoices.length?(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:n.invoices.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-2.5 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`w-24 shrink-0 text-[0.875rem] text-ink-2 tabular-nums`,children:ho(e.issuedAt)}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:e.credits?I(`credits.invoiceCredits`,{n:po(e.credits)}):I(`credits.invoicePlan`)}),(0,V.jsx)(`div`,{className:`truncate font-mono text-[0.75rem] text-ink-3`,children:e.number??e.id})]}),(0,V.jsx)(E,{tone:e.status===`paid`?`live`:`warn`,children:e.status===`paid`?I(`credits.paid`):I(`credits.open`)}),(0,V.jsx)(`span`,{className:`w-20 shrink-0 text-right text-[0.875rem] tabular-nums`,children:mo(e.totalCents,e.currency)}),(0,V.jsx)(j,{label:I(`credits.pdf`),onClick:()=>Le(`/api/studio/organization/invoices/${encodeURIComponent(e.id)}/pdf`),children:(0,V.jsx)(Jt,{className:`size-4`})})]},e.id))}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`credits.noInvoices`)}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`credits.invoicesOnlyAdmins`)})})}):t.isError?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`credits.failed`)}):(0,V.jsx)(k,{})}var Co=[`owner`,`admin`,`member`],wo={forbidden:`orgSettings.refused.forbidden`,PLAN_SEATS:`orgSettings.refused.seats`,PLAN_ROLES:`orgSettings.refused.roles`,already_member:`orgSettings.refused.alreadyMember`,last_owner:`orgSettings.refused.lastOwner`};function To(e){if(!e)return null;let t=e instanceof p?e.body?.code:void 0;return t&&wo[t]?I(wo[t]):e.message}function Eo(e){return N({queryKey:[`organization`,e.tenant.id],queryFn:()=>r.get(`/api/studio/organization`)})}function Do({name:e,image:t}){return t?(0,V.jsx)(`img`,{src:t,alt:``,className:`size-9 shrink-0 rounded-full object-cover`}):(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 font-medium text-[0.75rem] text-ink-2`,children:Ot(e)})}function Oo({label:e,text:t}){let[n,r]=(0,B.useState)(!1);return(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-2.5 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:e}),(0,V.jsx)(`div`,{className:`truncate font-mono text-[0.875rem]`,children:t})]}),(0,V.jsx)(j,{label:I(n?`settings.copied`:`settings.copy`),onClick:async()=>{try{await navigator.clipboard.writeText(t),r(!0),setTimeout(()=>r(!1),1500)}catch{}},children:n?(0,V.jsx)(z,{className:`size-4`}):(0,V.jsx)(Gt,{className:`size-4`})})]})}function ko({label:e,value:t,sub:n}){return(0,V.jsxs)(`div`,{className:`min-w-0 rounded-lg bg-paper-2/60 px-3 py-2.5`,children:[(0,V.jsx)(`span`,{className:`block font-medium text-[0.6875rem] text-ink-3 uppercase tracking-[0.1em]`,children:e}),(0,V.jsx)(`b`,{className:`block truncate font-medium text-[0.9375rem]`,children:t}),n?(0,V.jsx)(`span`,{className:`block truncate text-[0.75rem] text-ink-3`,children:n}):null]})}var Ao=(e,t)=>t===null?I(`orgSettings.planNoLimit`,{n:e}):I(`orgSettings.planOf`,{n:e,limit:t});function jo({me:e,billing:t,admin:n}){let r=Eo(e),i=wt(),{tier:a}=We(),s=(a?.choices??[]).filter(e=>e.inPlan).map(e=>e.name);return(0,V.jsx)(o,{title:I(`orgSettings.plan`),hint:I(`orgSettings.planHint`),children:(0,V.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(`b`,{className:`min-w-0 flex-1 font-display font-semibold text-[1.125rem]`,children:e.tenant.plan?.name}),n&&t?(0,V.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 font-medium text-[0.8125rem] text-ember-strong hover:underline`,children:[I(`orgSettings.planChange`),` `,(0,V.jsx)(Ht,{className:`size-3`})]}):null]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:[(0,V.jsx)(ko,{label:I(`orgSettings.planSpaces`),value:i.data?Ao(i.data.length,e.limits.spaces):`–`}),(0,V.jsx)(ko,{label:I(`orgSettings.planMembers`),value:r.data?Ao(r.data.seats.taken,r.data.seats.limit):`–`}),(0,V.jsx)(ko,{label:I(`orgSettings.planCredits`),value:e.credits===null?`–`:I(`orgSettings.planCreditsLeft`,{n:Math.floor(e.credits).toLocaleString(F)})}),(0,V.jsx)(ko,{label:I(`orgSettings.planModels`),value:a?.name??`–`,sub:s.length>1?I(`orgSettings.planTiers`,{tiers:s.join(`, `)}):null})]})]})})}function Mo({me:e}){let t=f(),n=e.tenant.role!==`member`,[i,a]=(0,B.useState)(e.tenant.name??``),s=re(i.trim(),async e=>{e&&(await r.put(`/api/studio/organization`,{name:e}),await t.invalidateQueries({queryKey:[`me`]}))}),c=fe(`customDomains`),l=e.tenant.slug?`${window.location.origin}/studio/${e.tenant.slug}/`:null,u=Xe(e);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsx)(o,{title:I(`orgSettings.name`),hint:I(`orgSettings.nameHint`),save:n?s:void 0,locked:!n,children:(0,V.jsx)(y,{value:i,maxLength:80,"aria-label":I(`orgSettings.name`),onChange:e=>a(e.target.value)})}),e.tenant.plan?(0,V.jsx)(jo,{me:e,billing:u,admin:n}):null,(0,V.jsx)(zo,{me:e,studioUrl:l}),n&&c?(0,V.jsx)(Bo,{me:e}):null]})}function No({me:e}){let[t,n]=(0,B.useState)(!1),i=R({mutationFn:()=>r.del(`/api/studio/organization/members/${encodeURIComponent(e.user.id)}`),onSuccess:()=>window.location.assign(`/api/auth/login`)});return(0,V.jsxs)(o,{title:I(`orgSettings.leave`),hint:I(`orgSettings.leaveHint`),children:[t?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,V.jsx)(`p`,{className:`min-w-48 flex-1 text-[0.875rem]`,children:I(`orgSettings.leaveConfirm`,{name:e.tenant.name??``})}),(0,V.jsx)(O,{variant:`ghost`,onClick:()=>n(!1),children:I(`orgSettings.cancel`)}),(0,V.jsx)(O,{busy:i.isPending,onClick:()=>i.mutate(),children:I(`orgSettings.leaveYes`)})]}):(0,V.jsx)(O,{variant:`secondary`,onClick:()=>n(!0),children:I(`orgSettings.leaveButton`)}),i.error?(0,V.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:To(i.error)}):null]})}function Po({me:e,onDone:t}){let n=f(),[i,a]=(0,B.useState)(``),[o,s]=(0,B.useState)(`member`),c=e.tenant.role===`owner`?Co:Co.filter(e=>e!==`owner`),l=R({mutationFn:()=>r.post(`/api/studio/organization/invitations`,{email:i.trim(),role:o}),onSuccess:async()=>{await n.invalidateQueries({queryKey:[`organization`,e.tenant.id]}),t()}});return(0,V.jsxs)(`form`,{className:`mb-4 flex flex-col gap-3 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,onSubmit:e=>{e.preventDefault(),l.mutate()},children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,V.jsxs)(`label`,{className:`flex min-w-48 flex-1 flex-col gap-1.5`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:I(`orgSettings.inviteEmail`)}),(0,V.jsx)(y,{type:`email`,required:!0,autoFocus:!0,value:i,placeholder:I(`orgSettings.inviteEmailPlaceholder`),onChange:e=>a(e.target.value)})]}),(0,V.jsxs)(`label`,{className:`flex w-40 flex-col gap-1.5`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:I(`orgSettings.role`)}),(0,V.jsx)(C,{value:o,onChange:e=>s(e),options:c.map(e=>({value:e,label:I(`organization.role.${e}`)}))})]})]}),(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`orgSettings.inviteHint`)}),l.error?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:To(l.error)}):null,(0,V.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,V.jsx)(O,{type:`button`,variant:`ghost`,onClick:t,children:I(`orgSettings.cancel`)}),(0,V.jsx)(O,{type:`submit`,busy:l.isPending,children:I(`orgSettings.inviteSend`)})]})]})}function Fo({me:e}){let t=f(),n=Eo(e),i=Ve(),[a,s]=(0,B.useState)(!1),c=()=>t.invalidateQueries({queryKey:[`organization`,e.tenant.id]}),l=R({mutationFn:e=>r.patch(`/api/studio/organization/members/${encodeURIComponent(e.userId)}`,{role:e.role}),onSuccess:c}),u=R({mutationFn:e=>r.del(`/api/studio/organization/members/${encodeURIComponent(e)}`),onSuccess:c}),d=R({mutationFn:e=>r.del(`/api/studio/organization/invitations/${encodeURIComponent(e)}`),onSuccess:c}),p=n.data,m=p?.canManage??!1,h=e.tenant.role===`owner`,g=i.plugins.some(e=>e.id===`contacts`),_=p?.seats,v=_?_.limit===null?I(`orgSettings.membersHintUnlimited`,{name:e.tenant.name??``}):I(`orgSettings.membersHint`,{name:e.tenant.name??``,taken:_.taken,limit:_.limit}):I(`orgSettings.membersHintUnlimited`,{name:e.tenant.name??``}),y=To(l.error??u.error??d.error);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsxs)(o,{title:I(`orgSettings.members`),hint:v,action:m&&!a?(0,V.jsxs)(O,{size:`sm`,onClick:()=>s(!0),children:[(0,V.jsx)(wn,{className:`size-4`}),` `,I(`orgSettings.invite`)]}):null,children:[a?(0,V.jsx)(Po,{me:e,onDone:()=>s(!1)}):null,n.isPending?(0,V.jsx)(k,{}):n.isError||!p?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`organization.failed`)}):(0,V.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[p.members.map(t=>{let n=t.userId===e.user.id,r=m&&!n&&(h||t.role!==`owner`);return(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(Do,{name:t.name,image:t.image}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`truncate text-[0.9375rem]`,children:[t.name,n?(0,V.jsxs)(`span`,{className:`text-ink-4`,children:[` · `,I(`organization.you`)]}):null]}),(0,V.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:t.email})]}),r?(0,V.jsx)(C,{className:`w-36`,value:t.role,onChange:e=>l.mutate({userId:t.userId,role:e}),options:(h?Co:Co.filter(e=>e!==`owner`)).map(e=>({value:e,label:I(`organization.role.${e}`)}))}):(0,V.jsx)(E,{tone:t.role===`member`?void 0:`live`,children:I(`organization.role.${t.role}`)}),r?(0,V.jsx)(j,{label:I(`orgSettings.remove`,{name:t.name}),onClick:()=>u.mutate(t.userId),children:(0,V.jsx)(qt,{className:`size-4`})}):m?(0,V.jsx)(`span`,{className:`size-9 shrink-0`}):null]},t.userId)}),p.invitations.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-3`,children:(0,V.jsx)(wn,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:e.email}),(0,V.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:I(`orgSettings.invitedUntil`,{date:new Date(e.expiresAt).toLocaleDateString()})})]}),(0,V.jsxs)(E,{tone:`warn`,children:[I(`organization.invited`),` · `,I(`organization.role.${e.role}`)]}),m&&(h||e.role!==`owner`)?(0,V.jsx)(O,{variant:`ghost`,size:`sm`,busy:d.isPending&&d.variables===e.id,onClick:()=>d.mutate(e.id),children:I(`orgSettings.withdraw`)}):null]},e.id)),p.members.length===0&&p.invitations.length===0?(0,V.jsxs)(`div`,{className:`flex items-center gap-3 text-[0.875rem] text-ink-3`,children:[(0,V.jsx)(we,{className:`size-4`}),` –`]}):null]}),y?(0,V.jsx)(`p`,{className:`mt-4 text-[0.875rem] text-rose`,children:y}):null]}),g?(0,V.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl bg-card p-4 ring-1 ring-border-soft`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-2`,children:(0,V.jsx)(bn,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:I(`orgSettings.contactsTitle`)}),(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 leading-snug`,children:I(`orgSettings.contactsText`,{name:e.tenant.name??``})})]}),(0,V.jsx)(D,{to:`/contacts`,className:`inline-flex h-8 shrink-0 items-center rounded-full border border-border bg-card px-3 font-medium text-[0.8125rem] text-ink transition hover:bg-paper-2`,children:I(`orgSettings.contactsOpen`)})]}):null,(0,V.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3 leading-relaxed`,children:e.tenant.role===`member`?I(`organization.memberNote`):I(`orgSettings.rolesNote`)}),p?.members.some(t=>t.userId!==e.user.id)?(0,V.jsx)(No,{me:e}):null]})}function Io(e){return N({queryKey:[`organization-address`,e.tenant.id],queryFn:()=>r.get(`/api/studio/organization/address`)})}var Lo=e=>e.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).slice(0,30),Ro={length:`orgSettings.addressProblem.length`,chars:`orgSettings.addressProblem.chars`,hyphen:`orgSettings.addressProblem.hyphen`,reserved:`orgSettings.addressProblem.reserved`,profanity:`orgSettings.addressProblem.profanity`,brand:`orgSettings.addressProblem.brand`,taken:`orgSettings.addressProblem.taken`};function zo({me:e,studioUrl:t}){let n=Io(e),[i,a]=(0,B.useState)(null),[s,c]=(0,B.useState)(!1),l=n.data,u=i??l?.slug??``,d=l?u!==l.slug:!1,f=N({queryKey:[`organization-address-check`,u],queryFn:()=>r.get(`/api/studio/organization/address/check?slug=${encodeURIComponent(u)}`),enabled:d&&u.length>0}),p=R({mutationFn:()=>r.put(`/api/studio/organization/address`,{slug:u}),onSuccess:e=>window.location.assign(`/studio/${e.slug}/settings/general`)}),m=d&&f.data&&!f.data.ok?f.data.code:null,h=l?l.host.slice(l.slug.length):``;return(0,V.jsxs)(o,{title:I(`orgSettings.address`),hint:l?.canChange&&l.changeUntil?I(`orgSettings.addressHintOpen`,{date:new Date(l.changeUntil).toLocaleDateString()}):I(`orgSettings.addressHint`),children:[l?.canChange?(0,V.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center rounded-lg border border-input bg-card focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,children:[(0,V.jsx)(`input`,{"aria-label":I(`orgSettings.address`),className:`h-11 min-w-0 flex-1 bg-transparent pl-3 font-mono text-[0.9375rem] outline-none`,value:u,maxLength:30,autoComplete:`off`,spellCheck:!1,onChange:e=>{a(Lo(e.target.value)),c(!1)}}),(0,V.jsx)(`span`,{className:`shrink-0 pr-3 font-mono text-[0.9375rem] text-ink-4`,children:h})]}),d&&!s?(0,V.jsx)(O,{variant:`secondary`,disabled:f.data?.ok!==!0,onClick:()=>c(!0),children:I(`orgSettings.addressChange`)}):null]}),m?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:Ro[m]?I(Ro[m]):m}):null,s?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,V.jsx)(`p`,{className:`min-w-48 flex-1 text-[0.875rem]`,children:I(`orgSettings.addressConfirm`,{host:`${u}${h}`})}),(0,V.jsx)(O,{variant:`ghost`,onClick:()=>c(!1),children:I(`orgSettings.cancel`)}),(0,V.jsx)(O,{busy:p.isPending,onClick:()=>p.mutate(),children:I(`orgSettings.addressConfirmYes`)})]}):null,p.error?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:To(p.error)}):null]}):null,(0,V.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[t?(0,V.jsx)(Oo,{label:I(`orgSettings.studioAddress`),text:t}):null,l?.host??e.tenant.pagesHost?(0,V.jsx)(Oo,{label:I(`orgSettings.pagesAddress`),text:l?.host??e.tenant.pagesHost??``}):null]})]})}function Bo({me:e}){let t=f(),n=Io(e),[i,a]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),l=()=>t.invalidateQueries({queryKey:[`organization-address`,e.tenant.id]}),u=R({mutationFn:()=>r.post(`/api/studio/organization/domains`,{domain:s}),onSuccess:async()=>{c(``),a(!1),await l()}}),d=R({mutationFn:e=>r.post(`/api/studio/organization/domains/${encodeURIComponent(e)}/verify`),onSuccess:l}),p=R({mutationFn:e=>r.del(`/api/studio/organization/domains/${encodeURIComponent(e)}`),onSuccess:l}),m=n.data?.domains??[];return(0,V.jsxs)(o,{title:I(`orgSettings.domains`),hint:I(`orgSettings.domainsHint`),action:i?null:(0,V.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),children:[(0,V.jsx)(Wt,{className:`size-4`}),` `,I(`orgSettings.domainAdd`)]}),children:[i?(0,V.jsxs)(`form`,{className:`mb-4 flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),u.mutate()},children:[(0,V.jsx)(y,{className:`min-w-48 flex-1`,autoFocus:!0,required:!0,value:s,placeholder:I(`orgSettings.domainPlaceholder`),"aria-label":I(`orgSettings.domains`),onChange:e=>c(e.target.value)}),(0,V.jsx)(O,{type:`button`,variant:`ghost`,onClick:()=>a(!1),children:I(`orgSettings.cancel`)}),(0,V.jsx)(O,{type:`submit`,busy:u.isPending,children:I(`orgSettings.domainAdd`)})]}):null,m.length?(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:m.map(e=>(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-2`,children:(0,V.jsx)(cn,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:e.domain}),e.verified?null:(0,V.jsxs)(`div`,{className:`break-all font-mono text-[0.75rem] text-ink-3`,children:[`TXT `,e.record.name,` = `,e.record.value]})]}),e.verified?(0,V.jsx)(E,{tone:`live`,children:I(`orgSettings.domainVerified`)}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(E,{tone:`warn`,children:I(`orgSettings.domainWaiting`)}),(0,V.jsx)(O,{variant:`secondary`,size:`sm`,busy:d.isPending&&d.variables===e.id,onClick:()=>d.mutate(e.id),children:I(`orgSettings.domainCheck`)})]}),(0,V.jsx)(j,{label:I(`orgSettings.domainRemove`,{domain:e.domain}),onClick:()=>p.mutate(e.id),children:(0,V.jsx)(qt,{className:`size-4`})})]},e.id))}):i?null:(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`orgSettings.domainsNone`)}),d.data&&!d.data.verified?(0,V.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-ink-3`,children:I(`orgSettings.domainNotYet`)}):null,To(u.error??d.error??p.error)?(0,V.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:To(u.error??d.error??p.error)}):null]})}function Vo({me:e}){let t=f(),n=N({queryKey:[`organization-keys`,e.tenant.id],queryFn:()=>r.get(`/api/studio/organization/keys`)}),[i,a]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(null),d=()=>t.invalidateQueries({queryKey:[`organization-keys`,e.tenant.id]}),p=R({mutationFn:()=>r.post(`/api/studio/organization/keys`,{name:s.trim()}),onSuccess:async e=>{u({id:e.id,name:e.name,key:e.key}),c(``),a(!1),await d()}}),m=R({mutationFn:e=>r.del(`/api/studio/organization/keys/${encodeURIComponent(e)}`),onSuccess:async(e,t)=>{u(e=>e?.id===t?null:e),await d()}}),h=n.data?.keys??[];return(0,V.jsx)(`div`,{className:`flex flex-col gap-9`,children:(0,V.jsxs)(o,{title:I(`orgSettings.keys`),hint:I(`orgSettings.keysHint`,{name:e.tenant.name??``}),action:i?null:(0,V.jsxs)(O,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),children:[(0,V.jsx)(Wt,{className:`size-4`}),` `,I(`orgSettings.keyCreate`)]}),children:[l?(0,V.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2 rounded-lg bg-paper p-3 ring-1 ring-ember`,children:[(0,V.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:I(`orgSettings.keyNew`,{name:l.name})}),(0,V.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`orgSettings.keyOnce`)}),(0,V.jsx)(Oo,{label:I(`orgSettings.keys`),text:l.key})]}):null,i?(0,V.jsxs)(`form`,{className:`mb-4 flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),p.mutate()},children:[(0,V.jsx)(y,{className:`min-w-48 flex-1`,autoFocus:!0,required:!0,maxLength:32,value:s,placeholder:I(`orgSettings.keyNamePlaceholder`),"aria-label":I(`orgSettings.keyName`),onChange:e=>c(e.target.value)}),(0,V.jsx)(O,{type:`button`,variant:`ghost`,onClick:()=>a(!1),children:I(`orgSettings.cancel`)}),(0,V.jsx)(O,{type:`submit`,busy:p.isPending,children:I(`orgSettings.keyCreate`)})]}):null,n.isPending?(0,V.jsx)(k,{}):h.length?(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:h.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-full bg-paper-2 text-ink-2`,children:(0,V.jsx)(ze,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:e.name??e.start}),(0,V.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:e.lastRequest?I(`orgSettings.keyUsed`,{date:new Date(e.lastRequest).toLocaleString()}):I(`orgSettings.keyNeverUsed`)})]}),(0,V.jsx)(j,{label:I(`orgSettings.keyDelete`,{name:e.name??``}),onClick:()=>m.mutate(e.id),children:(0,V.jsx)(qt,{className:`size-4`})})]},e.id))}):i?null:(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`orgSettings.keysNone`)}),To(p.error??m.error)?(0,V.jsx)(`p`,{className:`mt-3 text-[0.875rem] text-rose`,children:To(p.error??m.error)}):null]})})}var Ho=`mt-1.5 text-[0.8125rem] text-ink-3`,Uo=e=>new Intl.DateTimeFormat(F,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e));function Wo({me:e}){let t=f(),[n,i]=(0,B.useState)(e.user.name),[a,s]=(0,B.useState)(e.profile),c=e=>s(t=>({...t,...e})),l=re(n.trim(),async e=>{e&&(await r.put(`/api/studio/person/name`,{name:e}),await t.invalidateQueries({queryKey:[`me`]}))}),u=re(a,async e=>{await r.put(`/api/studio/profile`,e),await t.invalidateQueries({queryKey:[`me`]})}),d=l.state===`error`||l.state===`saving`?l:u;return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsx)(o,{title:I(`konto.profile`),hint:I(`konto.profileHint`),save:d,children:(0,V.jsxs)(`div`,{className:`flex flex-col gap-6 sm:flex-row sm:gap-8`,children:[(0,V.jsx)(`div`,{className:`flex shrink-0 flex-col items-center gap-2 sm:w-32`,children:(0,V.jsx)(`div`,{className:`flex size-20 items-center justify-center overflow-hidden rounded-full bg-ember-tint font-semibold text-[1.75rem] text-ember-strong ring-1 ring-border-soft`,children:e.user.image?(0,V.jsx)(`img`,{src:e.user.image,alt:``,className:`size-full object-cover`}):Ot(n)||`?`})}),(0,V.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-5`,children:[(0,V.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(te,{children:I(`account.name`)}),(0,V.jsx)(y,{value:n,maxLength:80,onChange:e=>i(e.target.value)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(te,{children:I(`account.email`)}),(0,V.jsx)(y,{type:`email`,value:e.user.email,disabled:!0,readOnly:!0}),(0,V.jsx)(`p`,{className:Ho,children:I(`konto.emailHint`)})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(te,{children:I(`account.about`)}),(0,V.jsx)(m,{minRows:3,maxLength:2e3,value:a.about,onChange:e=>c({about:e.target.value})}),(0,V.jsx)(`p`,{className:Ho,children:I(`account.aboutHint`)})]}),(0,V.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:(0,V.jsxs)(`div`,{children:[(0,V.jsx)(te,{children:I(`account.phone`)}),(0,V.jsx)(y,{type:`tel`,value:a.phone,maxLength:40,onChange:e=>c({phone:e.target.value})})]})})]})]})}),(0,V.jsx)(o,{title:I(`account.look`),hint:I(`account.lookHint`),children:(0,V.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4 pb-4`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:I(`nav.language`)}),(0,V.jsx)(_n,{})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4 pt-4`,children:[(0,V.jsx)(`span`,{className:`font-medium text-[0.875rem]`,children:I(`nav.theme`)}),(0,V.jsx)(xe,{})]})]})})]})}var Go={owner:`organization.role.owner`,admin:`organization.role.admin`,member:`organization.role.member`},Ko=7;function qo({me:e}){let[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(!1),a=e.organizations.length>=Ko,s=t.trim().toLowerCase(),l=s?e.organizations.filter(e=>e.name.toLowerCase().includes(s)):e.organizations,u=a&&!s&&!r?l.slice(0,6):l;return(0,V.jsxs)(o,{title:I(`konto.organizations`),hint:I(`konto.organizationsHint`,{n:e.organizations.length}),children:[a?(0,V.jsxs)(`div`,{className:`relative mb-4`,children:[(0,V.jsx)(c,{className:`-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 size-4 text-ink-4`}),(0,V.jsx)(y,{className:`pl-9`,value:t,placeholder:I(`konto.organizationsSearch`),"aria-label":I(`konto.organizationsSearch`),onChange:e=>n(e.target.value)})]}):null,(0,V.jsxs)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:[u.map(t=>{let n=t.id===e.tenant.id;return(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 font-medium text-[0.75rem] text-ink-2`,children:Ot(t.name)}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:t.name}),(0,V.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:[I(Go[t.role]),t.plan?.name].filter(Boolean).join(` · `)})]}),n?(0,V.jsx)(E,{children:I(`konto.here`)}):(0,V.jsx)(O,{variant:`ghost`,size:`sm`,onClick:()=>_t(t),children:I(`konto.switch`)})]},t.id)}),s&&!l.length?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`konto.organizationsNone`)}):null]}),a&&!s&&!r&&l.length>u.length?(0,V.jsx)(O,{variant:`ghost`,size:`sm`,className:`mt-3`,onClick:()=>i(!0),children:I(`konto.organizationsAll`,{n:l.length-u.length})}):null,(0,V.jsx)(`p`,{className:`mt-4 text-[0.8125rem] text-ink-3`,children:I(`konto.organizationsLeave`)})]})}var Jo={"wizards:read":`konto.scope.read`,"wizards:write":`konto.scope.write`,"wizards:publish":`konto.scope.publish`,"runs:test":`konto.scope.test`,"runs:read":`konto.scope.results`,profile:`konto.scope.profile`};function Yo(){let e=f(),t=N({queryKey:[`person-connections`],queryFn:()=>r.get(`/api/studio/person/connections`)}),[n,i]=(0,B.useState)(null),[a,s]=(0,B.useState)(null),c=()=>e.invalidateQueries({queryKey:[`person-connections`]}),l=R({mutationFn:e=>r.del(`/api/studio/person/connections/${encodeURIComponent(e)}`),onSuccess:async()=>{s(null),await c()}}),d=R({mutationFn:e=>r.del(`/api/studio/person/computers/${encodeURIComponent(e)}`),onSuccess:c}),p=t.data;return p?(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsx)(o,{title:I(`konto.appsTitle`),hint:I(`konto.appsHint`),children:p.apps.length?(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:p.apps.map(e=>{let t=e.name??e.clientId,r=n===e.id,o=e.scopes.filter(e=>Jo[e]);return(0,V.jsxs)(`div`,{className:`py-3 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`button`,{type:`button`,"aria-expanded":r,onClick:()=>i(r?null:e.id),className:`flex w-full items-center gap-3 text-left`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 text-ink-2`,children:(0,V.jsx)(hn,{className:`size-4`})}),(0,V.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`truncate text-[0.9375rem]`,children:t}),e.tenantName?(0,V.jsx)(E,{children:e.tenantName}):null]}),(0,V.jsx)(`span`,{className:`block truncate text-[0.8125rem] text-ink-3`,children:I(`konto.lastUsed`,{when:Uo(e.lastUsed)})})]}),r?(0,V.jsx)(S,{className:`size-4 text-ink-3`}):(0,V.jsx)(u,{className:`size-4 text-ink-3`})]}),r?(0,V.jsxs)(`div`,{className:`mt-3 ml-12 flex flex-col gap-3 text-[0.875rem]`,children:[o.length?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:I(`konto.may`)}),(0,V.jsx)(`ul`,{className:`mt-1 flex flex-col gap-1 text-ink-2`,children:o.map(e=>(0,V.jsx)(`li`,{children:I(Jo[e])},e))})]}):null,(0,V.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:I(`konto.connectedAt`,{when:Uo(e.connectedAt)})}),a===e.id?(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,V.jsx)(`p`,{className:`min-w-48 flex-1`,children:I(`konto.disconnectConfirm`,{name:t,organization:e.tenantName??``})}),(0,V.jsx)(O,{variant:`ghost`,onClick:()=>s(null),children:I(`orgSettings.cancel`)}),(0,V.jsx)(O,{busy:l.isPending&&l.variables===e.id,onClick:()=>l.mutate(e.id),children:I(`konto.disconnect`)})]}):(0,V.jsx)(`div`,{children:(0,V.jsx)(O,{variant:`secondary`,size:`sm`,onClick:()=>s(e.id),children:I(`konto.disconnect`)})})]}):null]},e.id)})}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`konto.appsNone`)})}),(0,V.jsx)(o,{title:I(`konto.computers`),hint:I(`konto.computersHint`),children:p.computers.length?(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:p.computers.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 text-ink-2`,children:(0,V.jsx)(Pe,{className:`size-4`})}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`truncate text-[0.9375rem]`,children:I(`konto.computer`)}),e.tenantName?(0,V.jsx)(E,{children:e.tenantName}):null]}),(0,V.jsx)(`div`,{className:`truncate text-[0.8125rem] text-ink-3`,children:I(`konto.lastUsed`,{when:Uo(e.lastUsed)})})]}),(0,V.jsx)(O,{variant:`ghost`,size:`sm`,busy:d.isPending&&d.variables===e.id,onClick:()=>d.mutate(e.id),children:I(`konto.signOut`)})]},e.id))}):(0,V.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`konto.computersNone`)})})]}):t.isError?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`konto.appsFailed`)}):(0,V.jsx)(k,{})}var Xo=[`person-sign-ins`],Zo=e=>new Intl.DateTimeFormat(F,{dateStyle:`medium`}).format(new Date(e));function Qo(){let e=f(),t=N({queryKey:Xo,queryFn:()=>r.get(`/api/studio/person/sign-ins`)});en((0,B.useCallback)(()=>void e.invalidateQueries({queryKey:Xo}),[e]));let n=t.data;if(!n)return t.isError?(0,V.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:I(`konto.connectionsFailed`)}):(0,V.jsx)(k,{});let i=n.spaces.filter(e=>e.connections.length);return(0,V.jsxs)(`div`,{className:`flex flex-col gap-9`,children:[(0,V.jsx)(o,{title:I(`konto.connections`),hint:I(`konto.connectionsHint`),plain:!0,children:i.length?null:(0,V.jsx)(`p`,{className:`px-1 text-[0.875rem] text-ink-3`,children:I(`konto.connectionsNone`)})}),i.map(e=>(0,V.jsx)(o,{title:e.name,hint:I(`konto.connectionsCount`,{n:e.connections.length}),children:(0,V.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:e.connections.map(e=>(0,V.jsx)(es,{connection:e},e.id))})},e.id)),i.length?(0,V.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:I(`konto.connectionsFoot`)}):null]})}function $o(e){let t=e.connector?.name??e.connectorId;return e.name===t?e.name:`${t} · ${e.name}`}function es({connection:e}){let t=f(),n=Zt(`/api/studio/connections/${encodeURIComponent(e.id)}/my-sign-in`,()=>t.invalidateQueries({queryKey:Xo})),r=e.signIn===`person`,i=r?[I(`konto.connectionEach`),e.mySignIn?.label].filter(Boolean).join(` · `):[e.account?I(`konto.connectionAsSpace`):I(`konto.connectionSpaceNotYet`),e.setUpBy?I(`konto.connectionSetUpBy`,{name:e.setUpBy,when:Zo(e.setUpAt)}):I(`konto.connectionSetUpAt`,{when:Zo(e.setUpAt)})].join(` · `);return(0,V.jsxs)(`div`,{className:`py-3 first:pt-0 last:pb-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 font-semibold text-[0.75rem] text-ink-2`,children:Ot(e.connector?.name??e.connectorId)||`?`}),(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:$o(e)}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[r?(0,V.jsx)(we,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}):(0,V.jsx)(qe,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,V.jsx)(`span`,{className:`truncate`,children:i})]})]}),e.pausedAt?(0,V.jsx)(E,{tone:`ember`,children:I(`connection.paused`)}):null,r?(0,V.jsx)(Xt,{s:n,auth:e.connector?.auth,signedIn:!!e.mySignIn}):null]}),(0,V.jsx)($t,{s:n,fields:e.connector?.fields??[],signedIn:!!e.mySignIn,confirmText:I(`konto.connectionSignOutConfirm`,{name:$o(e)}),className:`ml-12`})]})}var ts=(0,B.lazy)(()=>vn(()=>import(`./AboutDialog-BUWu36Mb.js`).then(e=>({default:e.AboutPanel})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13]))),ns=e=>e===`earlier`||e===`credits`?e:`new`,rs=new Set([`models`,`integrate`,`plugins`,`setup`]);function is({scope:e=`settings`}){let{section:t}=oe(),[n]=x(),r=h(),i=Dt(),{space:a,loading:s}=kt(),c=Et(),l=gn(),u=fe(`capabilities`),d=ee(),[f,p]=(0,B.useState)(a?.id);(0,B.useEffect)(()=>p(a?.id),[a?.id]);let m=Ve(),g=Pt(),[_,v]=(0,B.useState)(null),[y,b]=(0,B.useState)(null),[S,C]=(0,B.useState)(null),T=e===`account`?Ae(i.data?.features):Me(i.data,m),E=e===`account`?`/account`:`/settings`,te=I(e===`account`?`konto.title`:`settings.title`),D=e===`account`?`profile`:T.some(e=>e.id===`general`)?`general`:(T.find(e=>e.id===`account`)??T[0])?.id,O=T.find(e=>e.id===t),k=T.map(e=>({...e,to:`${E}/${e.id}`})),re=k.find(e=>e.id===t),A=O?rs.has(O.id):!1,j=O?A&&!n.get(`show`)?1:2:0,ie=g?Math.min(j,1):A&&S!==t?1:0,ae=Lt(ie),se=Lt(j),ce=(0,B.useMemo)(()=>({slot:_,narrow:g,setDetail:b}),[_,g]);if(ve(O?.id===`models`?{suggestions:[{label:I(`assistant.suggest.modelsNow`)},{label:I(`assistant.suggest.modelsMissing`)},{label:I(`assistant.suggest.modelsCost`)}]}:O?.id===`account`?{suggestions:[{label:I(`assistant.suggest.credits`)},{label:I(`assistant.suggest.accountWhy`)},{label:I(`assistant.suggest.plans`)}]}:O?.id===`integrate`?{suggestions:[{label:I(`assistant.suggest.integrateWhat`)},{label:I(`assistant.suggest.integrateClaude`)},{label:I(`assistant.suggest.what`)}]}:O?.id===`connectors`?{suggestions:[{label:I(`assistant.suggest.connectorsWhat`)},{label:I(`assistant.suggest.connectorsAdd`),fill:!0},{label:I(`assistant.suggest.what`)}]}:{}),it([{label:te,to:E},...O?[{label:O.label,to:`${E}/${O.id}`}]:[],...O&&y?[{label:y}]:[]]),!O){if(e===`account`&&!i.data)return null;if(e===`settings`&&t===`connectors`&&u)return(0,V.jsx)(w,{to:{pathname:`/capabilities/connectors`,search:d.search},replace:!0});if(t===`build`)return(0,V.jsx)(w,{to:`/settings/integrate`,replace:!0});if(m.sections.some(e=>e.id===t))return(0,V.jsx)(w,{to:`${E}/plugins?show=${t}`,replace:!0});if(t!==void 0||!g)return m.status===`ready`||t===void 0?(0,V.jsx)(w,{to:`${E}/${D}`,replace:!0}):null}let N=O?.id===`connectors`&&c,le=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Ft,{title:te,open:ie===1?re??null:null,onBack:()=>g?r(E):C(t??null)}),(0,V.jsx)(`div`,{className:M(Vt(ae)),children:ie===0?(0,V.jsx)(jt,{entries:k,current:g?void 0:re,onPick:()=>C(null)}):(0,V.jsx)(`div`,{ref:v})},ie)]});return(0,V.jsx)(Mt.Provider,{value:ce,children:(0,V.jsx)(`div`,{className:`animate-rise`,children:(0,V.jsxs)(`div`,{className:M(`grid gap-6`,`md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`),children:[(0,V.jsx)(`aside`,{className:M(`min-w-0 md:sticky md:top-6 md:self-start`,g&&j===2&&`hidden`,g&&se===`back`&&Vt(`back`)),children:le}),O?(0,V.jsxs)(`div`,{className:M(`min-w-0`,![`integrate`,`models`].includes(O.id)&&`max-w-2xl`,g&&j<2&&`hidden`,g&&se===`deeper`&&Vt(`deeper`)),children:[g?(0,V.jsx)(`div`,{className:`mb-3`,children:(0,V.jsx)(Bt,{label:A?O.label:te,onBack:()=>r(A?`${E}/${O.id}`:E)})}):null,N?(0,V.jsx)(`div`,{className:`mb-6`,children:(0,V.jsx)(tt,{})}):null,O.id===`connectors`&&a?(0,V.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[a.readOnly?(0,V.jsx)(fn,{children:un(a)}):null,(0,V.jsx)(Qt,{spaceId:a.id,readOnly:a.readOnly||l},f)]}):null,O.id===`connectors`&&!a&&!s?(0,V.jsx)(ne,{children:I(`settings.noSpace`)}):null,O.id===`models`?(0,V.jsx)(so,{}):null,O.id===`integrate`?(0,V.jsx)(Tr,{}):null,O.id===`account`&&i.data?(0,V.jsx)(de,{me:i.data}):null,O.id===`cloud`?(0,V.jsx)(nt,{}):null,O.id===`setup`&&i.data?(0,V.jsx)(he,{me:i.data}):null,O.id===`about`?(0,V.jsx)(B.Suspense,{fallback:null,children:(0,V.jsx)(ts,{me:i.data,active:!0,initialTab:ns(n.get(`tab`))})}):null,O.id===`organization`&&i.data?(0,V.jsx)(uo,{me:i.data}):null,O.id===`general`&&i.data?(0,V.jsx)(Mo,{me:i.data}):null,O.id===`members`&&i.data?(0,V.jsx)(Fo,{me:i.data}):null,O.id===`keys`&&i.data?(0,V.jsx)(Vo,{me:i.data}):null,O.id===`profile`&&i.data?(0,V.jsx)(Wo,{me:i.data}):null,O.id===`orgs`&&i.data?(0,V.jsx)(qo,{me:i.data}):null,O.id===`apps`&&i.data?(0,V.jsx)(Yo,{}):null,O.id===`connections`?(0,V.jsx)(Qo,{}):null,O.id===`notifications`&&a?(0,V.jsx)(o,{title:I(`protocol.notify.title`),hint:I(`protocol.notify.hint`),children:(0,V.jsx)(tn,{space:a})}):null,O.id===`credits`&&i.data?(0,V.jsx)(bo,{me:i.data}):null,O.id===`usage`&&i.data?(0,V.jsx)(xo,{me:i.data}):null,O.id===`invoices`&&i.data?(0,V.jsx)(So,{me:i.data}):null,O.id===`plugins`?(0,V.jsx)(Vn,{}):null]}):null]})})})}export{is as SettingsPage};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{t}from"./useMutation-CoEdB_9_.js";import{$ as n,An as r,Wr as i,_r as a,ar as o,nn as s,or as ee,vn as c}from"./ui-BjhZhw8x.js";import{u as l}from"./marked.esm-BfGIZK7F.js";import{Cn as u,H as d,Jt as te,K as ne,Kt as re,Sn as ie,V as f,Yt as p,or as m,qt as h}from"./host-Ckjz94Ea.js";import{n as g,t as _}from"./jsx-runtime-C3cWAN_r.js";import{a as ae,c as oe,n as v}from"./brand-ByQY-UcL.js";import{t as y}from"./logo-xL-sneZz.js";import{n as b,s as x}from"./i18n-ClCOlfx2.js";import{h as se,u as ce,v as le}from"./session-Dd9duhPc.js";import{r as ue}from"./LangSwitch-BNa_H8AR.js";var S=e(g(),1),C=e(_(),1),w=`oklch(50% 0.2 262)`,T=`oklch(32% 0.15 262)`,E=`oklch(90% 0.1 80)`,D=`var(--step-done)`,O=`var(--step-now)`,k=`color-mix(in oklab, var(--on) 38%, transparent)`,de={"--on":`white`,"--tile":`rgb(255 255 255 / 0.1)`,"--tile-hover":`rgb(255 255 255 / 0.15)`,"--tile-ring":`rgb(255 255 255 / 0.15)`,"--panel":`rgb(255 255 255 / 0.07)`,"--panel-ring":`rgb(255 255 255 / 0.12)`,"--pick":`white`,"--pick-ink":T,"--pick-mark":T,"--dot":E,"--step-done":`oklch(88% 0.17 150)`,"--step-now":`oklch(88% 0.14 80)`,"--ready-ink":`oklch(27% 0.09 150)`,"--ink-2":`oklch(96% 0.02 262)`,"--ink-3":`oklch(90% 0.035 262)`,"--ink-4":`oklch(82% 0.05 262)`,"--moss":`oklch(90% 0.14 150)`,"--rose":`oklch(89% 0.09 45)`},fe={"--on":`var(--ink)`,"--tile":`var(--card)`,"--tile-hover":`var(--paper-2)`,"--tile-ring":`var(--border-soft)`,"--panel":`var(--card)`,"--panel-ring":`var(--border-soft)`,"--pick":w,"--pick-ink":`white`,"--pick-mark":`white`,"--dot":w,"--step-done":`oklch(52% 0.15 150)`,"--step-now":`oklch(60% 0.15 65)`,"--ready-ink":`white`},A=`ease-[cubic-bezier(0.3,0.7,0.2,1)]`,pe=220,me={codex:`dome`,claude:`oval`,antigravity:`wedge`,cursor:`sprout`,own:`bean`,account:`drop`,apple:`pebble`};function he(e){if(e.available)return x(`models.optAppleNote`);switch(e.reason){case`off`:return x(`models.appleOff`);case`loading`:return x(`models.appleLoading`);default:return x(`models.appleDevice`)}}var j=`relative w-fit max-w-full transition-[left,translate] duration-700 ease-[cubic-bezier(0.3,0.7,0.2,1)] motion-reduce:transition-none`,M=`left-1/2 -translate-x-1/2 text-center`,N=`max-lg:left-1/2 max-lg:-translate-x-1/2 max-lg:text-center lg:left-0 lg:translate-x-0 lg:text-left`;function P(){window.matchMedia(`(max-width: 1023px)`).matches&&window.scrollTo({top:0})}var F=`wizards.setup.own`;function ge(){try{return sessionStorage.getItem(F)===`1`}catch{return!1}}function _e(e){try{e?sessionStorage.setItem(F,`1`):sessionStorage.removeItem(F)}catch{}}function ve(){return(0,C.jsxs)(`span`,{className:`inline-flex items-center gap-2.5`,children:[(0,C.jsx)(y,{size:28}),(0,C.jsxs)(`span`,{className:`font-display font-semibold text-[1.0625rem] tracking-tight`,children:[`engenty`,(0,C.jsx)(`span`,{className:`mr-[0.09em] ml-[0.06em] text-(color:--dot)`,children:`.`}),(0,C.jsx)(`span`,{className:`font-normal text-(color:--on)/70`,children:`wizards`})]})]})}function I({selected:e,title:t,description:n,badge:r,note:i,onPick:a}){return(0,C.jsxs)(`button`,{type:`button`,onClick:a,"aria-pressed":e,className:c(`group relative flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left transition-[background-color,color,box-shadow] duration-300`,e?`bg-(color:--pick) text-(color:--pick-ink) shadow-elevated`:`bg-(color:--tile) ring-(color:--tile-ring) ring-1 hover:bg-(color:--tile-hover)`),children:[r?(0,C.jsx)(`span`,{className:`absolute -top-2.5 right-4 rounded-full px-2.5 py-[3px] font-semibold text-[0.6875rem] leading-none tracking-wide shadow-[0_2px_8px_oklch(0%_0_0/0.22)]`,style:{background:E,color:T},children:r}):null,(0,C.jsx)(`span`,{className:c(`flex size-5 shrink-0 items-center justify-center rounded-full border transition-colors duration-300`,e?`border-transparent bg-(color:--pick-mark)`:`border-(color:--on)/40`),children:e?(0,C.jsx)(l,{className:`size-3.5 text-(color:--pick)`}):null}),(0,C.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,C.jsx)(`span`,{className:`block font-medium text-[0.9375rem]`,children:t}),(0,C.jsx)(`span`,{className:c(`mt-0.5 block truncate text-[0.8125rem]`,e?`opacity-70`:`text-(color:--on)/65`),children:n})]}),i?(0,C.jsx)(`span`,{className:c(`shrink-0 text-[0.75rem]`,e?`opacity-70`:`text-(color:--on)/65`),children:i}):null,(0,C.jsx)(o,{className:c(`size-4 shrink-0 transition`,e?`opacity-70`:`text-(color:--on)/40 group-hover:translate-x-0.5 group-hover:text-(color:--on)/80`)})]})}function ye({name:e,at:t,done:n}){let r=[x(`setup.stage.connect`),x(`setup.stage.test`),x(`setup.stage.done`)],i=n?r.length:t+1;return(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 font-medium text-[0.75rem] uppercase tracking-[0.14em]`,children:[(0,C.jsx)(`span`,{className:`text-(color:--on)/70`,children:e}),(0,C.jsx)(`ol`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:r.map((e,r)=>{let i=n||r<t;return(0,C.jsxs)(`li`,{"aria-current":!i&&r===t?`step`:void 0,className:`flex items-center gap-1 transition-colors duration-500`,style:{color:i?D:r===t?O:k},children:[i?(0,C.jsx)(l,{className:`size-3.5`,strokeWidth:3}):null,e]},e)})}),(0,C.jsx)(`span`,{"aria-hidden":`true`,className:`flex gap-1.5`,children:r.map((e,t)=>(0,C.jsx)(`span`,{className:`h-[3px] w-5 rounded-full transition-colors duration-500`,style:{background:t<i?n?D:O:`color-mix(in oklab, var(--on) 22%, transparent)`}},e))})]})}function be({href:e,children:t}){return(0,C.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`transition hover:text-(color:--on)`,onClick:t=>{t.preventDefault(),p(e)},children:t})}function xe({source:e,signedIn:t,onLocal:n}){let r=d(t),{link:i}=r;return(0,S.useEffect)(()=>{t&&n()},[t,n]),(0,C.jsxs)(`section`,{className:`mx-auto flex w-full max-w-[32rem] animate-rise flex-col items-center text-center`,children:[(0,C.jsx)(v,{kind:`drop`,size:132,fluffy:!0,coat:`fur`}),(0,C.jsxs)(`span`,{className:`mt-4 inline-flex items-center gap-1.5 rounded-full px-3 py-1 font-medium text-[0.75rem]`,style:{color:D,background:`color-mix(in oklab, var(--step-done) 20%, transparent)`},children:[(0,C.jsx)(l,{className:`size-3.5`,strokeWidth:3}),x(`setup.connected`,{name:e})]}),(0,C.jsx)(`h1`,{className:`mt-3 font-display font-semibold text-[1.75rem] leading-[1.08] tracking-[-0.02em]`,children:x(`setup.accountAsk`)}),(0,C.jsx)(`p`,{className:`mt-2.5 text-balance text-(color:--on)/75 text-[0.9375rem] leading-relaxed`,children:x(`setup.accountAskText`)}),(0,C.jsxs)(`div`,{className:`mt-7 flex w-full flex-col gap-4 rounded-2xl bg-(color:--panel) p-5 text-left ring-(color:--panel-ring) ring-1`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3.5`,children:[(0,C.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded-full bg-(color:--pick) text-(color:--pick-ink)`,children:(0,C.jsx)(m,{className:`size-4.5`})}),(0,C.jsxs)(`div`,{className:`min-w-0`,children:[(0,C.jsx)(`p`,{className:`font-medium text-[0.9375rem]`,children:x(`setup.account`)}),(0,C.jsx)(`p`,{className:`text-(color:--on)/75 text-[0.8125rem] leading-snug`,children:x(`setup.accountText`)})]})]}),(0,C.jsxs)(`div`,{className:`flex flex-wrap gap-2.5`,children:[(0,C.jsx)(s,{style:{background:`var(--pick)`,color:`var(--pick-ink)`},busy:i.isPending&&!i.variables?.signup,onClick:()=>i.mutate({}),children:x(`account.signIn`)}),(0,C.jsx)(s,{variant:`secondary`,busy:i.isPending&&!!i.variables?.signup,onClick:()=>i.mutate({signup:!0}),children:x(`account.create`)})]}),(0,C.jsx)(f,{...r})]}),(0,C.jsxs)(`button`,{type:`button`,onClick:n,className:`group mt-7 inline-flex items-center gap-1.5 font-medium text-[0.9375rem] underline decoration-(color:--on)/40 underline-offset-4 transition hover:decoration-(color:--on)`,children:[x(`setup.localContinue`),(0,C.jsx)(o,{className:`size-4 transition-transform group-hover:translate-x-0.5`})]}),(0,C.jsx)(`p`,{className:`mt-2 max-w-[44ch] text-balance text-(color:--on)/65 text-[0.8125rem] leading-snug`,children:x(`setup.localContinueNote`)})]})}function L(){let e=u(`site`),o=oe()!==`light`;ae(o?w:null);let p=se(),g=i(),_=a(),y=ie(),E=u(`account`),{space:O}=ce(),k=d(!!p.data?.account?.signedIn),[F,L]=(0,S.useState)(ge),[R,z]=(0,S.useState)(!1),[B,Se]=(0,S.useState)(!1),V=t({mutationFn:e=>n.put(`/api/studio/local/models`,e===`apple`?{bindings:{classifier:`apple:default`,low:`apple:default`}}:e===`own`?{source:`own`,bindings:{classifier:``,low:``}}:{source:e,bindings:le(p.data?.models?.bindings??{})}),onSuccess:async(e,t)=>{await g.invalidateQueries({queryKey:[`me`]}),L(!0),z(!1),P(),_e(t===`own`)}}),H=t({mutationFn:()=>Promise.all((p.data?.harnesses??[]).map(e=>n.post(`/api/studio/local/harness/${e.id}/detect`))),onSuccess:()=>g.invalidateQueries({queryKey:[`me`]})});if(!p.data?.models)return null;let U=p.data.models,W=e=>(e.version===null?2:0)+ +!e.app,G=[...p.data.harnesses].sort((e,t)=>W(e)-W(t)),Ce=G.filter(e=>e.version!==null),K=p.data.apple,q=U.bindings.low?.startsWith(`apple:`)?`apple`:F||p.data.setupDone||U.source!==`own`?U.source:null,J=p.data.harnesses.find(e=>e.id===q),we=U.source===`account`?x(`models.creditsName`):p.data.harnesses.find(e=>e.id===U.source)?.name??null,Y=p.data.setupDone,Te=Object.values(U.keys).some(Boolean),Ee=Y?2:J?J.auth===`none`?0:1:q===`apple`||q===`account`||Te?1:0,De=Y?x(`setup.h.done`):J?J.version===null?x(`setup.h.install`,{name:J.name}):J.auth===`none`?x(`setup.h.signIn`,{name:J.name}):x(`setup.h.test`):x(q===`apple`||q===`account`||Te?`setup.h.test`:`setup.h.keys`),X=e?y.data?.site:null,Z=q!==null&&!R,Q=V.isPending?V.variables??q:q,Oe=!!p.data.account?.signedIn,ke=J?.name??x(q===`apple`?`models.optApple`:q===`account`?`setup.creditsChoice`:`local.sourceOwn`),$=()=>_(`/`,{replace:!0});return(0,C.jsxs)(`div`,{className:`flex min-h-dvh flex-col px-6 text-(color:--on) sm:px-10`,style:o?de:fe,children:[(0,C.jsxs)(`header`,{className:`flex items-center justify-between pt-6 sm:pt-8`,children:[(0,C.jsx)(ve,{}),(0,C.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(ne,{tone:o?`ground`:`surface`}),(0,C.jsx)(ue,{tone:o?`ground`:`surface`,ink:T})]})]}),(0,C.jsxs)(`main`,{className:`relative mx-auto flex w-full max-w-6xl flex-1 flex-col pt-6 pb-10 lg:pt-[6vh]`,children:[B?(0,C.jsx)(xe,{source:ke,signedIn:Oe,onLocal:$}):null,(0,C.jsx)(`div`,{"aria-hidden":`true`,className:c(`absolute top-6 left-1/2 z-10 origin-top -translate-x-1/2 transition-[opacity,scale,left] duration-500 motion-reduce:transition-none lg:top-[calc(6vh+5.25rem)] lg:origin-center lg:translate-x-0`,A,q?`lg:pointer-events-none lg:left-[calc(50%-560px)] lg:scale-75 lg:opacity-0`:`lg:left-[calc(50%-508px)] lg:scale-100 lg:opacity-100`,Z?`max-lg:pointer-events-none max-lg:scale-[0.4] max-lg:opacity-0`:`max-lg:scale-[0.6] max-lg:opacity-100`),children:(0,C.jsx)(`div`,{className:`animate-rise`,children:(0,C.jsx)(v,{kind:`drop`,size:pe,fluffy:!0,coat:`fur`})})}),(0,C.jsx)(`div`,{"aria-hidden":`true`,className:c(`shrink-0 transition-[height] duration-500 motion-reduce:transition-none lg:h-0`,A,Z?`max-lg:h-0`:`max-lg:h-[148px]`)}),(0,C.jsxs)(`div`,{className:c(`flex flex-col gap-10 lg:flex-row lg:items-start lg:gap-14`,B?`hidden`:``),children:[(0,C.jsxs)(`section`,{className:c(`flex w-full shrink-0 animate-rise flex-col lg:w-[32rem] lg:transition-[margin] lg:duration-700 motion-reduce:transition-none`,A,q?`lg:ml-0`:`lg:ml-[calc(50%-16rem)]`,Z?`max-lg:hidden`:``),children:[(0,C.jsxs)(`div`,{className:`flex flex-col lg:min-h-[6.5rem]`,children:[(0,C.jsx)(`p`,{className:c(j,`font-medium text-(color:--on)/70 text-[0.75rem] uppercase tracking-[0.16em]`,q?N:M),children:x(`setup.title`)}),(0,C.jsx)(`h1`,{className:c(j,`mt-2 font-display font-semibold text-[1.625rem] leading-[1.08] tracking-[-0.02em] sm:text-[1.75rem]`,q?N:M),children:x(`setup.source`)}),(0,C.jsx)(`p`,{className:c(j,`mt-2.5 text-(color:--on)/75 text-[0.9375rem] leading-relaxed`,q?N:M),children:x(`setup.sub`)})]}),E?(0,C.jsxs)(`div`,{className:`mt-5 flex items-center gap-3.5 rounded-2xl bg-(color:--panel) px-4 py-3.5 ring-(color:--panel-ring) ring-1`,children:[(0,C.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded-full bg-(color:--pick) font-semibold text-(color:--pick-ink) text-[0.9375rem]`,children:p.data.account?.signedIn?(p.data.account.name||p.data.account.email).slice(0,1).toUpperCase():(0,C.jsx)(m,{className:`size-4.5`})}),(0,C.jsx)(`div`,{className:`min-w-0 flex-1`,children:p.data.account?.signedIn?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{className:`font-medium text-[0.9375rem]`,children:x(`setup.accountLinked`,{name:p.data.account.name||p.data.account.email})}),(0,C.jsx)(`p`,{className:`text-(color:--on)/75 text-[0.8125rem]`,children:[p.data.account.organization,p.data.account.credits===null?null:x(`setup.accountCredits`,{credits:p.data.account.credits.toLocaleString(b)})].filter(Boolean).join(` · `)})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`p`,{className:`font-medium text-[0.9375rem]`,children:x(`setup.account`)}),(0,C.jsx)(`p`,{className:`text-(color:--on)/75 text-[0.8125rem] leading-snug`,children:x(`setup.accountText`)}),(0,C.jsx)(f,{...k})]})}),p.data.account?.signedIn?null:(0,C.jsx)(s,{variant:`secondary`,size:`sm`,busy:k.link.isPending,onClick:()=>k.link.mutate({}),children:x(`account.signIn`)})]}):null,p.data.account?.signedIn?(0,C.jsx)(`div`,{className:`mt-2.5`,children:(0,C.jsx)(I,{selected:Q===`account`,title:x(`setup.creditsChoice`),description:x(`setup.creditsDesc`),note:p.data.account.credits===null?void 0:x(`setup.accountCredits`,{credits:p.data.account.credits.toLocaleString(b)}),onPick:()=>V.mutate(`account`)})}):null,E?(0,C.jsxs)(`div`,{className:`mt-7`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,C.jsx)(`span`,{className:`h-px flex-1 bg-(color:--on)/25`}),(0,C.jsx)(`span`,{className:`font-medium text-(color:--on)/80 text-[0.75rem] uppercase tracking-[0.14em]`,children:x(`setup.localDivider`)}),(0,C.jsx)(`span`,{className:`h-px flex-1 bg-(color:--on)/25`})]}),(0,C.jsx)(`p`,{className:`mt-2 text-center text-(color:--on)/65 text-[0.8125rem] leading-snug`,children:x(`setup.localNote`)})]}):null,(0,C.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2.5`,children:[G.map((e,t)=>(0,C.jsx)(I,{selected:Q===e.id,title:e.name,description:x(`harness.desc.${e.id}`),badge:t===0?x(`setup.recommended`):void 0,note:e.version===null?x(`harness.notInstalled`):e.auth===`subscription`?x(`harness.ready`):void 0,onPick:()=>V.mutate(e.id)},e.id)),K?.supported?(0,C.jsx)(I,{selected:Q===`apple`,title:x(`models.optApple`),description:x(`setup.appleDesc`),note:he(K),onPick:()=>V.mutate(`apple`)}):null,(0,C.jsx)(I,{selected:Q===`own`,title:x(`local.sourceOwn`),description:x(`setup.ownDesc`),onPick:()=>V.mutate(`own`)})]}),(0,C.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-center gap-x-2 gap-y-1 text-(color:--on)/60 text-[0.8125rem]`,children:[(0,C.jsx)(`span`,{children:Ce.length?null:x(`setup.noHarness`)}),(0,C.jsxs)(s,{variant:`ghost`,size:`sm`,busy:H.isPending,onClick:()=>H.mutate(),children:[(0,C.jsx)(r,{className:`size-3.5`}),` `,x(`local.recheck`)]})]})]}),q?(0,C.jsxs)(`section`,{className:c(`min-w-0 flex-1 animate-settle`,R?`max-lg:hidden`:``),children:[(0,C.jsxs)(`button`,{type:`button`,onClick:()=>{z(!0),P()},className:`-ml-1.5 mb-5 inline-flex items-center gap-1.5 rounded-full px-1.5 py-1 text-(color:--on)/80 text-[0.875rem] transition hover:text-(color:--on) lg:hidden`,children:[(0,C.jsx)(ee,{className:`size-4`}),` `,x(`run.back`)]}),(0,C.jsxs)(`div`,{className:`relative`,children:[(0,C.jsx)(`div`,{"aria-hidden":`true`,className:`absolute top-6 right-2 z-10`,children:(0,C.jsx)(v,{kind:me[q],size:120,fluffy:!0,coat:`fur`})}),(0,C.jsxs)(`div`,{className:`min-h-[6.5rem]`,children:[(0,C.jsx)(ye,{name:ke,at:Ee,done:Y}),(0,C.jsx)(`h2`,{className:`mt-2 animate-rise pr-32 font-display font-semibold text-[clamp(28px,3vw,40px)] leading-[1.06] tracking-[-0.03em]`,children:De},De)]}),(0,C.jsx)(`div`,{className:`mt-5 rounded-2xl bg-(color:--panel) p-5 ring-(color:--panel-ring) ring-1 sm:p-6`,children:J?(0,C.jsx)(re,{me:p.data,id:J.id,autoTest:!Y}):q===`apple`?(0,C.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,C.jsx)(`p`,{className:`text-[0.875rem] text-ink-2 leading-relaxed`,children:we?x(`setup.appleHintKeeps`,{way:we}):x(`setup.appleHint`)}),(0,C.jsx)(h,{auto:!Y&&K?.available===!0})]}):q===`account`?(0,C.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,C.jsx)(`p`,{className:`text-[0.875rem] text-ink-2 leading-relaxed`,children:x(`setup.creditsDesc`)}),(0,C.jsx)(h,{auto:!Y})]}):(0,C.jsx)(te,{models:U})}),(0,C.jsxs)(`div`,{className:`mt-9`,children:[Y?(0,C.jsxs)(`p`,{className:`mb-3 flex animate-rise items-center gap-2 font-medium text-[0.9375rem]`,style:{color:D},children:[(0,C.jsx)(l,{className:`size-4`,strokeWidth:3}),x(`setup.ready`)]}):null,(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,C.jsxs)(`button`,{type:`button`,disabled:!Y,onClick:()=>{E&&!Oe?(Se(!0),window.scrollTo({top:0})):$()},className:c(`group inline-flex h-12 items-center gap-2.5 rounded-full px-6 font-semibold text-[1rem] transition-[background-color,color,box-shadow,filter] duration-300`,Y?`shadow-[0_6px_24px_oklch(88%_0.17_150/0.35)] hover:brightness-105`:`cursor-not-allowed bg-(color:--on)/20 text-(color:--on)/65`),style:Y?{background:D,color:`var(--ready-ink)`}:void 0,children:[x(`setup.done`),(0,C.jsx)(`span`,{"aria-hidden":`true`,className:`transition-transform group-enabled:group-hover:translate-x-0.5`,children:`→`})]}),Y?null:(0,C.jsx)(`span`,{className:`text-(color:--on)/65 text-[0.8125rem]`,children:x(`setup.untilWorks`)})]})]})]})]},q):null]})]}),(0,C.jsxs)(`footer`,{className:`mx-auto flex w-full max-w-6xl items-center justify-between gap-4 pb-6 text-(color:--on)/55 text-[0.75rem] sm:pb-8`,children:[(0,C.jsxs)(`span`,{children:[`engenty ·`,` `,p.data.account?.signedIn?x(`setup.thisComputer`,{space:O?.name??``,organization:p.data.account.organization??p.data.account.name}):x(`setup.local`)]}),(0,C.jsxs)(`span`,{className:`flex items-center gap-5`,children:[X?(0,C.jsx)(be,{href:X,children:new URL(X).host}):null,(0,C.jsx)(`span`,{"aria-hidden":`true`,className:`size-[3px] bg-(color:--dot)`})]})]})]})}export{L as SetupPage};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{$ as t,An as n,Jn as r,Wr as i,Z as a,a as o,an as s,cn as c,hn as l,kt as u,ln as d,lr as f,mt as ee,nn as p,pn as m,q as te,rn as h,sn as g,vn as _,y as ne,yr as v}from"./ui-BjhZhw8x.js";import{a as y,d as re,f as b,l as x,n as S,s as ie,t as C,u as ae}from"./Skills-_pLGtOjH.js";import{t as w}from"./useMutation-CoEdB_9_.js";import{t as T}from"./code-xml-CdJeig44.js";import{d as E,i as oe,l as se,r as D,s as O}from"./marked.esm-BfGIZK7F.js";import{t as k}from"./eye-CG1LzvNI.js";import{n as A,t as ce}from"./scroll-text-DmK2IucJ.js";import{n as j,t as M}from"./jsx-runtime-C3cWAN_r.js";import{n as N,s as P}from"./i18n-ClCOlfx2.js";import{d as le}from"./session-Dd9duhPc.js";import{t as F}from"./code-editor-B8zG80PA.js";import{N as I,a as L,r as R,t as z}from"./dist-Bux-wzFO.js";import{c as ue,n as de,t as fe}from"./Bundle-RNkjBwAL.js";var B={name:`file-archive`,size:24,node:[[`path`,{d:`M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5`,key:`4pqfef`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 12v-1`,key:`1ej8lb`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`path`,{d:`M8 7V6`,key:`1nbb54`}],[`circle`,{cx:`8`,cy:`20`,r:`2`,key:`ckkr5m`}]]};B.node;var pe=E(B),V=e(j(),1),H=z.line({class:`cm-frontmatter`});function U(e){let t=new I,n=e.state.doc;if(n.lines>1&&n.line(1).text.trim()===`---`){for(let e=2;e<=Math.min(n.lines,80);e++)if(n.line(e).text.trim()===`---`){for(let r=1;r<=e;r++)t.add(n.line(r).from,n.line(r).from,H);break}}return t.finish()}function W(){return[L.fromClass(class{decorations;constructor(e){this.decorations=U(e)}update(e){e.docChanged&&(this.decorations=U(e.view))}},{decorations:e=>e.decorations}),R.theme({".cm-frontmatter, .cm-frontmatter *":{fontFamily:`var(--f-mono)`,fontSize:`0.8125rem !important`,fontWeight:`400 !important`,color:`var(--ink-3) !important`,textDecoration:`none !important`}})]}var G=e(M(),1),K=[`always`,`demand`,`off`],me=W();function q(e){return v({queryKey:a.skill(e),queryFn:()=>t.get(`/api/studio/skills/${e}`)})}function he({value:e,onChange:t,disabled:n}){return(0,G.jsx)(`fieldset`,{"aria-label":P(`skills.modeLabel`),className:`m-0 min-w-0 border-0 p-0 flex flex-col gap-2`,children:K.map(r=>{let i=r===e,a=S[r];return(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":i,disabled:n,onClick:()=>!i&&t(r),className:_(`flex items-start gap-3 rounded-xl bg-card p-3 text-left ring-1 transition disabled:pointer-events-none`,i?`ring-ember shadow-[0_0_0_3px] shadow-ember-tint`:`ring-border-soft hover:ring-ink-4`,n&&!i&&`opacity-60`),children:[(0,G.jsx)(`span`,{className:_(`flex size-8 shrink-0 items-center justify-center rounded-lg`,i?`bg-ember-tint text-ember-strong`:`bg-paper-2 text-ink-3`),children:(0,G.jsx)(a,{className:`size-4`})}),(0,G.jsxs)(`span`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`block font-medium text-[0.8125rem]`,children:P(`skills.mode.${r}`)}),(0,G.jsx)(`span`,{className:`block text-[0.75rem] text-ink-3 leading-snug`,children:P(`skills.modeHint.${r}`)})]})]},r)})})}function ge({skill:e}){let n=i(),r=w({mutationFn:n=>t.patch(`/api/studio/skills/${e.id}`,{runScripts:n}),onSuccess:async()=>{await n.invalidateQueries({queryKey:a.skill(e.id)}),await n.invalidateQueries({queryKey:a.skills(e.spaceId)})}}),o=e.source!==`own`&&!e.official;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(y,{title:P(`skills.scriptsTitle`)}),(0,G.jsxs)(h,{className:`flex flex-col gap-2 p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`span`,{className:`flex-1 font-medium text-[0.8125rem]`,children:P(`skills.runScripts`)}),(0,G.jsx)(l,{checked:e.runScripts,label:P(`skills.runScripts`),disabled:e.readOnly||r.isPending,onChange:e=>r.mutate(e)})]}),(0,G.jsx)(`p`,{className:`text-[0.75rem] text-ink-3 leading-snug`,children:P(`skills.runScriptsHint`)}),o?(0,G.jsx)(`p`,{className:`rounded-lg bg-amber-tint px-3 py-2 text-[0.75rem] text-ink-2 leading-snug`,children:P(`skills.runScriptsWarn`)}):null,r.error?(0,G.jsx)(`p`,{className:`text-[0.75rem] text-rose`,children:r.error.message}):null]})]})}function J({code:e,onChange:t}){return(0,G.jsxs)(p,{variant:`secondary`,size:`sm`,"aria-pressed":e,onClick:()=>t(!e),children:[e?(0,G.jsx)(k,{className:`size-4`}):(0,G.jsx)(T,{className:`size-4`}),P(e?`skills.rendered`:`skills.code`)]})}var Y=e=>`${(e/1e3).toLocaleString(N,{maximumFractionDigits:1})} KB`,X=e=>Y(new TextEncoder().encode(e).length),Z=e=>/\.(md|markdown|mdx)$/i.test(e);function _e({file:e,readOnly:t,onChange:n,onDelete:r,onClose:i}){let[a,o]=(0,V.useState)(!1),c=e?Z(e.path):!1,l=a||!c;return(0,G.jsx)(s,{open:e!==null,onClose:i,wide:!0,height:`tall`,title:e?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(O,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`truncate font-mono text-[0.9375rem]`,children:e.path})]}):null,children:e?(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`span`,{className:`flex-1 text-[0.75rem] text-ink-3`,children:X(e.text)}),c?(0,G.jsx)(J,{code:a,onChange:o}):null]}),(0,G.jsx)(h,{className:`overflow-hidden`,children:l?(0,G.jsx)(F,{value:e.text,onChange:n,readOnly:t,language:`markdown`,ariaLabel:e.path,className:`min-h-[50vh] [&_.cm-editor]:min-h-[50vh]`}):(0,G.jsx)(`div`,{className:`p-5`,children:(0,G.jsx)(u,{text:e.text})})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t?null:(0,G.jsxs)(p,{variant:`danger`,size:`sm`,onClick:r,children:[(0,G.jsx)(D,{className:`size-4`}),` `,P(`skills.deleteFile`)]}),(0,G.jsx)(`span`,{className:`flex-1`}),(0,G.jsx)(p,{size:`sm`,onClick:i,children:P(`skills.done`)})]})]}):null})}function ve({open:e,taken:t,onClose:n,onMade:r}){let[i,a]=(0,V.useState)(``),o=i.trim().replace(/^\.?\//,``),l=b(o)&&o!==`SKILL.md`&&!t.includes(o);return(0,G.jsx)(s,{open:e,onClose:n,title:P(`skills.newFile`),children:(0,G.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),l&&(r(o),a(``))},children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(d,{children:P(`skills.filePath`)}),(0,G.jsx)(c,{"data-autofocus":!0,value:i,placeholder:P(`skills.filePathHint`),onChange:e=>a(e.target.value),className:`font-mono`})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(p,{variant:`ghost`,onClick:n,children:P(`common.cancel`)}),(0,G.jsx)(p,{type:`submit`,disabled:!l,children:P(`skills.create`)})]})]})})}function ye({items:e}){let[t,n]=(0,V.useState)(!1),r=(0,V.useRef)(null);return(0,V.useEffect)(()=>{if(!t)return;let e=e=>{r.current?.contains(e.target)||n(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[t]),(0,G.jsxs)(`div`,{className:`relative`,ref:r,children:[(0,G.jsx)(g,{label:P(`skills.more`),"aria-haspopup":`menu`,"aria-expanded":t,onClick:()=>n(e=>!e),className:`ring-1 ring-border`,children:(0,G.jsx)(A,{className:`size-4`})}),t?(0,G.jsx)(`div`,{role:`menu`,className:`absolute top-11 right-0 z-50 w-56 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:e.map(e=>(0,G.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{n(!1),e.onPick()},className:_(`w-full rounded-lg px-2.5 py-2 text-left text-[0.8125rem] transition hover:bg-accent`,e.danger&&`text-rose`),children:e.label},e.label))}):null]})}function be({skill:e}){let r=i(),[o,c]=(0,V.useState)(!1),l=v({queryKey:[`skill-update`,e.id,e.originHash],queryFn:()=>t.get(`/api/studio/skills/${e.id}/update`),staleTime:6e5,retry:!1}),d=w({mutationFn:n=>t.post(`/api/studio/skills/${e.id}/update`,{hash:n}),onSuccess:async()=>{c(!1),await r.invalidateQueries({queryKey:a.skill(e.id)}),await r.invalidateQueries({queryKey:a.skills(e.spaceId)})}}),f=l.data?.update;return!f||e.readOnly?null:(0,G.jsxs)(h,{className:`flex flex-wrap items-center gap-3 px-4 py-3`,children:[(0,G.jsx)(n,{className:`size-4 shrink-0 text-ember`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 text-[0.8125rem]`,children:P(`skills.updateAvailable`)}),(0,G.jsx)(p,{variant:`secondary`,size:`sm`,onClick:()=>c(!0),children:P(`skills.showChanges`)}),(0,G.jsx)(s,{open:o,onClose:()=>c(!1),wide:!0,height:`tall`,title:P(`skills.updateTitle`,{name:e.name}),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:f.description}),(0,G.jsx)(`div`,{className:`rounded-lg bg-paper-2 p-4`,children:(0,G.jsx)(u,{text:f.body})}),(0,G.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-[0.8125rem]`,children:f.fileList.map(e=>(0,G.jsx)(`li`,{className:`font-mono`,children:e.path},e.path))}),(0,G.jsx)(C,{files:f.fileList,skipped:f.skipped}),d.error?(0,G.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:d.error.message}):null,(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(p,{busy:d.isPending,onClick:()=>d.mutate(f.hash),children:P(`skills.takeUpdate`)})})]})})]})}function Q({skillId:e,onGone:t,onOpen:n,filesFirst:r}){let i=q(e);return i.error?(0,G.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:i.error.message}):i.data?(0,G.jsx)($,{skill:i.data,onGone:t,onOpen:n,filesFirst:r},i.data.id):(0,G.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,G.jsx)(m,{className:`size-5`})})}function $({skill:e,onGone:n,onOpen:s,filesFirst:c}){let l=i(),d=e.source===`skills.sh`,g=!!e.bundle,_=e.readOnly||d||g,v=le(),b=ue(e.spaceId,v&&g).data?.find(t=>t.id===e.bundle?.id),[S,C]=(0,V.useState)({name:e.name,description:e.description,body:e.body,meta:e.meta,files:e.fileList}),[T,E]=(0,V.useState)(!1),[D,k]=(0,V.useState)(null),[A,j]=(0,V.useState)(!1),[M,I]=(0,V.useState)(null),[L,R]=(0,V.useState)(!1),z=te(S,async n=>{_||(await t.patch(`/api/studio/skills/${e.id}`,n),await l.invalidateQueries({queryKey:a.skills(e.spaceId)}))}),B=w({mutationFn:n=>t.patch(`/api/studio/skills/${e.id}`,{mode:n}),onSuccess:async()=>{await l.invalidateQueries({queryKey:a.skill(e.id)}),await l.invalidateQueries({queryKey:a.skills(e.spaceId)})}}),H=w({mutationFn:()=>t.del(`/api/studio/skills/${e.id}`),onSuccess:async()=>{await l.invalidateQueries({queryKey:a.skills(e.spaceId)}),n()}}),U=w({mutationFn:()=>t.post(`/api/studio/skills/${e.id}/copy`),onSuccess:async({id:t})=>{await l.invalidateQueries({queryKey:a.skills(e.spaceId)}),s(`k:${t}`)}}),W=S.files.find(e=>e.path===M)??null,K=D??re(S),q=e=>C(t=>({...t,...e})),Z=async()=>{await o(P(d?`skills.removeConfirm`:`skills.deleteConfirm`,{name:e.name}))&&H.mutate()},Q=z.error??B.error?.message??null,$=typeof e.meta.license==`string`?e.meta.license:null,xe=(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(y,{title:P(`skills.filesTitle`),children:_?null:(0,G.jsxs)(p,{variant:`secondary`,size:`sm`,onClick:()=>R(!0),children:[(0,G.jsx)(oe,{className:`size-4`}),` `,P(`skills.addFile`)]})}),S.files.length||e.blobList.length?(0,G.jsxs)(h,{className:`flex flex-col divide-y divide-border-soft overflow-hidden`,children:[S.files.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>I(e.path),className:`flex items-center gap-2.5 px-3 py-2.5 text-left transition hover:bg-accent`,children:[(0,G.jsx)(O,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[0.8125rem]`,children:e.path}),(0,G.jsx)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3`,children:X(e.text)})]},e.path)),e.blobList.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2.5`,children:[(0,G.jsx)(pe,{className:`size-4 shrink-0 text-ink-3`}),(0,G.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[0.8125rem]`,children:e.path}),(0,G.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-3`,children:[P(`skills.forScripts`),` · `,Y(e.bytes)]})]},e.path))]}):(0,G.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:P(`skills.noFiles`)}),(0,G.jsx)(`p`,{className:`px-1 text-[0.75rem] text-ink-3`,children:P(`skills.filesHint`)}),e.blobList.length?(0,G.jsx)(`p`,{className:`px-1 text-[0.75rem] text-ink-3`,children:P(`skills.blobHint`)}):null]});return(0,G.jsxs)(`div`,{className:`flex flex-col gap-5 pb-20`,children:[(0,G.jsxs)(`header`,{className:`flex flex-wrap items-start gap-4`,children:[(0,G.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-xl bg-ember-tint text-ember-strong`,children:(0,G.jsx)(ce,{className:`size-6`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2.5`,children:[_?(0,G.jsx)(`h1`,{className:`font-medium font-mono text-2xl`,children:S.name}):(0,G.jsx)(ne,{fit:!0,value:S.name,label:P(`skills.name`),placeholder:P(`skills.namePlaceholder`),maxLength:x.name,onChange:e=>{k(null),q({name:e.toLowerCase().replace(/[^a-z0-9-]/g,`-`)})},className:`font-medium font-mono text-2xl`}),(0,G.jsx)(ie,{skill:e}),z.state===`saving`?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[(0,G.jsx)(m,{className:`size-3`}),` `,P(`space.saving`)]}):z.state===`saved`?(0,G.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:P(`settings.saved`)}):null]}),_?(0,G.jsx)(`p`,{className:`mt-1 max-w-3xl text-[0.9375rem] text-ink-2 leading-relaxed`,children:S.description}):(0,G.jsx)(`textarea`,{value:S.description,"aria-label":P(`skills.description`),placeholder:P(`skills.descPlaceholder`),maxLength:x.description,rows:2,onChange:e=>{k(null),q({description:e.target.value})},className:`-mx-1 mt-1 block w-full max-w-3xl resize-none rounded-md bg-transparent px-1 py-0.5 text-[0.9375rem] text-ink-2 leading-relaxed outline-none transition placeholder:text-ink-4 hover:bg-paper-2 focus:bg-card focus:text-ink focus:ring-1 focus:ring-border`}),(0,G.jsx)(`p`,{className:`mt-0.5 text-[0.75rem] text-ink-3`,children:P(`skills.descHint`)})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pt-1`,children:[(0,G.jsxs)(`a`,{href:ee(`/api/studio/skills/${e.id}/zip`),download:!0,className:`inline-flex h-8 items-center gap-2 rounded-full bg-card px-3 font-medium text-[0.8125rem] ring-1 ring-border transition hover:bg-accent`,children:[(0,G.jsx)(r,{className:`size-4`}),` `,P(`skills.download`)]}),e.readOnly||g?null:(0,G.jsx)(ye,{items:[...d?[]:[{label:P(`skills.copy`),onPick:()=>U.mutate()}],{label:P(d?`skills.remove`:`skills.delete`),danger:!0,onPick:Z}]})]})]}),d?(0,G.jsx)(be,{skill:e}):null,b?(0,G.jsx)(fe,{bundle:b,writable:!e.readOnly}):null,Q?(0,G.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:Q}):null,(0,G.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(0,1fr)_18rem]`,children:[(0,G.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,G.jsxs)(y,{title:P(`skills.instructions`),children:[(0,G.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:P(`skills.chars`,{n:S.body.length.toLocaleString(N)})}),(0,G.jsx)(J,{code:T,onChange:E})]}),(0,G.jsx)(h,{className:`overflow-hidden`,children:T?(0,G.jsx)(F,{value:K,readOnly:_,onChange:e=>{k(e);try{let t=ae(e);j(!1),q({...t,files:S.files})}catch{j(!0)}},language:`markdown`,ariaLabel:`SKILL.md`,extensions:me,className:`min-h-[55vh] [&_.cm-editor]:min-h-[55vh] sm:[&_.cm-content]:py-5 sm:[&_.cm-line]:px-5`}):(0,G.jsx)(`div`,{className:`min-h-40 p-5 sm:px-8 sm:py-6`,children:S.body.trim()?(0,G.jsx)(u,{text:S.body}):(0,G.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:P(`skills.emptyBody`)})})}),T&&A?(0,G.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-rose`,children:P(`skills.mdError`)}):null,d?(0,G.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:P(`skills.readOnlyNote`)}):null,e.bundle?(0,G.jsx)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:e.bundle.connectors.length?P(`skills.bundle.readOnlyNote`,{name:e.bundle.connectors.map(e=>e.name).join(`, `)}):P(`skills.bundle.readOnlyNotePlugin`,{name:e.bundle.name})}):null]}),(0,G.jsxs)(`aside`,{className:`flex flex-col gap-6`,children:[c?xe:null,(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(y,{title:P(`skills.when`)}),(0,G.jsx)(he,{value:e.mode,onChange:e=>B.mutate(e),disabled:e.readOnly||B.isPending})]}),(0,G.jsx)(ge,{skill:e}),d?(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(y,{title:P(`skills.origin`)}),(0,G.jsx)(h,{className:`p-4`,children:(0,G.jsxs)(`dl`,{className:`grid grid-cols-[6rem_minmax(0,1fr)] gap-y-2 text-[0.8125rem]`,children:[(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.source`)}),(0,G.jsx)(`dd`,{children:(0,G.jsx)(`a`,{href:`https://skills.sh/${e.origin}`,target:`_blank`,rel:`noreferrer`,className:`break-all underline hover:text-ink`,children:e.origin})}),$?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.license`)}),(0,G.jsx)(`dd`,{className:`break-words`,children:$})]}):null,e.originHash?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.version`)}),(0,G.jsx)(`dd`,{className:`font-mono text-[0.75rem]`,children:e.originHash.slice(0,12)})]}):null]})}),e.readOnly?null:(0,G.jsxs)(p,{variant:`secondary`,size:`sm`,className:`self-start`,busy:U.isPending,onClick:()=>U.mutate(),children:[(0,G.jsx)(se,{className:`size-4`}),` `,P(`skills.copy`)]})]}):null,e.bundle?(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(y,{title:P(`skills.origin`)}),(0,G.jsx)(h,{className:`p-4`,children:(0,G.jsxs)(`dl`,{className:`grid grid-cols-[6rem_minmax(0,1fr)] gap-y-2 text-[0.8125rem]`,children:[e.bundle.connectors.length?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.bundle.connector`)}),(0,G.jsx)(`dd`,{children:(0,G.jsx)(f,{to:`/capabilities/connectors`,className:`underline hover:text-ink`,children:e.bundle.connectors.map(e=>e.name).join(`, `)})})]}):null,(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.bundle.plugin`)}),(0,G.jsx)(`dd`,{className:`break-words`,children:e.bundle.name}),e.origin?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.bundle.folder`)}),(0,G.jsx)(`dd`,{className:`break-all font-mono text-[0.75rem]`,children:e.origin})]}):null,$?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`dt`,{className:`text-ink-3`,children:P(`skills.license`)}),(0,G.jsx)(`dd`,{className:`break-words`,children:$})]}):null]})}),e.readOnly?null:(0,G.jsxs)(p,{variant:`secondary`,size:`sm`,className:`self-start`,busy:U.isPending,onClick:()=>U.mutate(),children:[(0,G.jsx)(se,{className:`size-4`}),` `,P(`skills.copy`)]})]}):null,c?null:xe]})]}),b&&!b.connectors.length&&!e.readOnly?(0,G.jsx)(de,{bundle:b,onGone:n}):null,(0,G.jsx)(_e,{file:W,readOnly:_,onClose:()=>I(null),onChange:e=>q({files:S.files.map(t=>t.path===M?{...t,text:e}:t)}),onDelete:()=>{q({files:S.files.filter(e=>e.path!==M)}),I(null)}}),(0,G.jsx)(ve,{open:L,taken:S.files.map(e=>e.path),onClose:()=>R(!1),onMade:e=>{q({files:[...S.files,{path:e,text:``}].sort((e,t)=>e.path.localeCompare(t.path))}),R(!1),I(e)}})]})}export{Q as SkillEditor};