@vellumai/web 0.11.3-staging.2 → 0.11.3-staging.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/assets/{access-DWtJQvRI.js → access-RDaLlBt5.js} +1 -1
  2. package/dist/assets/{account-page-D03pCcnz.js → account-page-JyXn859b.js} +1 -1
  3. package/dist/assets/{account-shell-DmVQwtZ0.js → account-shell-DuR-x14B.js} +1 -1
  4. package/dist/assets/{acp-run-detail-panel-COs66Yrd.js → acp-run-detail-panel-BsGRKgJi.js} +1 -1
  5. package/dist/assets/{activity-steps-panel-CLjBxqNs.js → activity-steps-panel-DGS78a-e.js} +1 -1
  6. package/dist/assets/{ai-page-D4GbPprS.js → ai-page-84Y9c_q2.js} +1 -1
  7. package/dist/assets/{app-card-B7C46-7O.js → app-card-Df-Gy7pD.js} +1 -1
  8. package/dist/assets/{assistant-status-panel-CDUAp33H.js → assistant-status-panel-C92c678g.js} +1 -1
  9. package/dist/assets/{auth-store-DkOiOQNx.js → auth-store-BJdkkmzu.js} +1 -1
  10. package/dist/assets/{background-task-detail-panel-xFGqYCUz.js → background-task-detail-panel-Dq1DgR5i.js} +1 -1
  11. package/dist/assets/billing-page-CAFoZYGH.js +3 -0
  12. package/dist/assets/{bookmarks-page-DqXq2CVJ.js → bookmarks-page-EeUOpkIO.js} +1 -1
  13. package/dist/assets/{build-state-B0f3Jn2o.js → build-state-DJaFMxtL.js} +1 -1
  14. package/dist/assets/{channels-page-route-CbV05RLi.js → channels-page-route-DS9XLjMy.js} +1 -1
  15. package/dist/assets/chat-markdown-message-C6oOqDdl.js +1 -0
  16. package/dist/assets/{checkout-page-BxYwG3J8.js → checkout-page-BqIlZAum.js} +1 -1
  17. package/dist/assets/{command-palette-DSxHNf_m.js → command-palette-D6aRon6x.js} +1 -1
  18. package/dist/assets/{command-palette-window-page-9lbssBKp.js → command-palette-window-page-B1jt_AiM.js} +1 -1
  19. package/dist/assets/{composer-settings-MHDtr31Y.js → composer-settings-Du4kV9LG.js} +1 -1
  20. package/dist/assets/{contacts-page-route-BE3oNfhk.js → contacts-page-route-B4eanbVf.js} +1 -1
  21. package/dist/assets/{conversation-navigation-DbQqV_fs.js → conversation-navigation-gR_RLe1J.js} +1 -1
  22. package/dist/assets/{conversation-queries-CMEwcap1.js → conversation-queries-Bx_JApUN.js} +1 -1
  23. package/dist/assets/{credentials-page-DKfIMfUB.js → credentials-page-BLMs_5u_.js} +1 -1
  24. package/dist/assets/{csv-preview-DB8q0b_y.js → csv-preview-B0xuZwnc.js} +1 -1
  25. package/dist/assets/{debug-page-DpWI-aFX.js → debug-page-7plKE23B.js} +2 -2
  26. package/dist/assets/{deploy-dialogs-BhY-urVH.js → deploy-dialogs-Bjz3OS-8.js} +1 -1
  27. package/dist/assets/{deploy-store-OFWDAEgC.js → deploy-store-BGcHwvB5.js} +1 -1
  28. package/dist/assets/{detail-card-Dsnf52vg.js → detail-card-hWrhardR.js} +1 -1
  29. package/dist/assets/{detail-drawer-AKY7keIJ.js → detail-drawer-s-zfqqMy.js} +1 -1
  30. package/dist/assets/{detail-panel-stop-button-Cvnn4hYA.js → detail-panel-stop-button-CC6QoK-R.js} +1 -1
  31. package/dist/assets/{detail-shell-g6Pw4jiP.js → detail-shell-PCaxY4Tf.js} +1 -1
  32. package/dist/assets/{developer-page-CSFTdMiT.js → developer-page-CV5m0xk-.js} +1 -1
  33. package/dist/assets/{document-viewer-container-Bousf9D9.js → document-viewer-container-wjJ6ACJv.js} +2 -2
  34. package/dist/assets/{document-viewer-page-CJuMnNZk.js → document-viewer-page-C8YfZSmS.js} +1 -1
  35. package/dist/assets/{emails-page-CMoX6WSY.js → emails-page-BqvrSqnK.js} +1 -1
  36. package/dist/assets/{file-editor-BwWJX7zO.js → file-editor-DOnVeKOG.js} +1 -1
  37. package/dist/assets/file-markdown-CGC6ZrPT.js +2 -0
  38. package/dist/assets/{first-run-scope-jh9sT0_v.js → first-run-scope-DKd0ZevK.js} +1 -1
  39. package/dist/assets/{general-page-Biad-auh.js → general-page-C7kX0xLP.js} +1 -1
  40. package/dist/assets/{hatching-screen-DtMbgBm6.js → hatching-screen-Dws0nCOf.js} +1 -1
  41. package/dist/assets/{home-page-route-k81d1Zsb.js → home-page-route-Qs5WbFPD.js} +1 -1
  42. package/dist/assets/home-tool-permission-card-Do3YeiVC.js +1 -0
  43. package/dist/assets/{hosting-screen-C-6MdEhq.js → hosting-screen-BJB_azfa.js} +1 -1
  44. package/dist/assets/{identity-page-route-BEobbSBV.js → identity-page-route-uZNXQbMq.js} +1 -1
  45. package/dist/assets/{index-BI5VpYa-.js → index-DRExgbkb.js} +1 -1
  46. package/dist/assets/index-Q1K0w5kB.css +2 -0
  47. package/dist/assets/{inspect-page-BSPJgPij.js → inspect-page-C1dITgHA.js} +1 -1
  48. package/dist/assets/{integrations-page-DNYDhZHQ.js → integrations-page-D4EH9FG0.js} +1 -1
  49. package/dist/assets/{intelligence-layout-CDcBeu8K.js → intelligence-layout-ByKfD_gm.js} +1 -1
  50. package/dist/assets/{library-detail-page-D5EeSRdZ.js → library-detail-page-BciW_57s.js} +1 -1
  51. package/dist/assets/{library-page-wPVeE7u1.js → library-page-CMO0VZux.js} +1 -1
  52. package/dist/assets/{local-runtime-upgrade-DyHUCz7A.js → local-runtime-upgrade-CXKbgZ4c.js} +1 -1
  53. package/dist/assets/{login-flow-B8CUFAeg.js → login-flow-CN5J4YsY.js} +1 -1
  54. package/dist/assets/{login-page-BgXMUzWB.js → login-page-5jtwkaF1.js} +1 -1
  55. package/dist/assets/{logout-page-COe8dRLu.js → logout-page-Bz0x8UvE.js} +1 -1
  56. package/dist/assets/{logs-layout-BGd_aSZ_.js → logs-layout-B_GC1zBM.js} +1 -1
  57. package/dist/assets/{memory-page-route-BGEmbUCl.js → memory-page-route-BtL6zJZb.js} +1 -1
  58. package/dist/assets/{memory-router-playground-page-B4DX4CON.js → memory-router-playground-page-e4uW8QiT.js} +1 -1
  59. package/dist/assets/{message-files-panel-DTDXhD0C.js → message-files-panel-DxmbSrm8.js} +1 -1
  60. package/dist/assets/{messages-D2OJUCHs.js → messages-DSdy6Lfi.js} +1 -1
  61. package/dist/assets/{metric-card-DgbUgyv7.js → metric-card-BSJPacNm.js} +1 -1
  62. package/dist/assets/{mobile-sidebar-drawer-CRXVtqcP.js → mobile-sidebar-drawer-BGHwfePU.js} +1 -1
  63. package/dist/assets/{multi-activity-group-Chyfm08f.js → multi-activity-group-D_OVaru-.js} +1 -1
  64. package/dist/assets/{open-workspace-file-C4HWMBzn.js → open-workspace-file-DViQQLp4.js} +2 -2
  65. package/dist/assets/{page-shell-CkfnwmIw.js → page-shell-Tpt9AIL2.js} +1 -1
  66. package/dist/assets/{personality-page-CEbJMhDR.js → personality-page-avdvL3Dx.js} +1 -1
  67. package/dist/assets/{plans-page-DXCrcLo8.js → plans-page-CdNdqHks.js} +1 -1
  68. package/dist/assets/{platform-login-notice-CIpebDVw.js → platform-login-notice-BEDBlins.js} +1 -1
  69. package/dist/assets/{platform-loopback-page-BJf6yE-E.js → platform-loopback-page-DcHVugCF.js} +1 -1
  70. package/dist/assets/{preview-error-CihmwI1t.js → preview-error-CVMngD78.js} +1 -1
  71. package/dist/assets/{privacy-page-CxAYEG0r.js → privacy-page-CfJXPReU.js} +1 -1
  72. package/dist/assets/{privacy-screen-DAzWoGQI.js → privacy-screen-4GElE18b.js} +1 -1
  73. package/dist/assets/{provider-callback-page--oWycq5i.js → provider-callback-page-rNJpxKm4.js} +1 -1
  74. package/dist/assets/{provider-signup-page-BaGT8Jl4.js → provider-signup-page-BG-fVW-J.js} +1 -1
  75. package/dist/assets/{remove-from-device-dialog-C0eaWxwl.js → remove-from-device-dialog-BGqwuQw9.js} +1 -1
  76. package/dist/assets/{research-onboarding-route-CXimVFK6.js → research-onboarding-route-s_8BLTOQ.js} +1 -1
  77. package/dist/assets/{retire-confirm-dialog-B1bvTlHS.js → retire-confirm-dialog-Bm7A3sZF.js} +1 -1
  78. package/dist/assets/{review-terms-screen-BxxGJL-B.js → review-terms-screen-CpWYZlRr.js} +1 -1
  79. package/dist/assets/routes-DE2XWIds.js +23 -0
  80. package/dist/assets/{runtime-upgrade-banner--bSmfygH.js → runtime-upgrade-banner-DtzsX2m0.js} +1 -1
  81. package/dist/assets/{sandbox-bridge-BlniBIsp.js → sandbox-bridge-WZhWtkZd.js} +1 -1
  82. package/dist/assets/{schedules-page-DCUj-YbP.js → schedules-page-Cfala7Km.js} +1 -1
  83. package/dist/assets/{select-assistant-screen-C5Cl_pCp.js → select-assistant-screen-BqObBI5Z.js} +1 -1
  84. package/dist/assets/{settings-divider-BuDc875f.js → settings-divider-Dyvf7Uk6.js} +1 -1
  85. package/dist/assets/{settings-layout-Clnlm1aB.js → settings-layout-DfPO11SQ.js} +1 -1
  86. package/dist/assets/{settings-navigation-Cn3KCxOe.js → settings-navigation-C1wEuU56.js} +1 -1
  87. package/dist/assets/{share-feedback-modal-COUhsUqF.js → share-feedback-modal-Ctgazbnj.js} +1 -1
  88. package/dist/assets/{sidebar-tree-BXbcoj07.js → sidebar-tree-VXRWtsy4.js} +1 -1
  89. package/dist/assets/{signup-page-C9ZrCSVo.js → signup-page-CLf-r4oP.js} +1 -1
  90. package/dist/assets/{site-favicon-B3DMFtr3.js → site-favicon-DfuXzZcN.js} +1 -1
  91. package/dist/assets/{skill-detail-page-Ckw6_1PG.js → skill-detail-page-ChpWru-e.js} +2 -2
  92. package/dist/assets/{skill-detail-panel-DdYbYHuj.js → skill-detail-panel-DU0bdJUl.js} +1 -1
  93. package/dist/assets/{skills-Lf85mR9L.js → skills-B4bfakyU.js} +1 -1
  94. package/dist/assets/{src-hNk11eS3.js → src-DyqTPMO2.js} +1 -1
  95. package/dist/assets/{stt-language-picker-modal-B5MO-3gk.js → stt-language-picker-modal-BiWHaqFq.js} +1 -1
  96. package/dist/assets/{subagent-detail-panel-BKhU7VAv.js → subagent-detail-panel-Gi0UOlsn.js} +1 -1
  97. package/dist/assets/superpowers-page-nHT_hb33.js +1 -0
  98. package/dist/assets/{system-events-page-DbcoH4sh.js → system-events-page-Bfpn0HzE.js} +1 -1
  99. package/dist/assets/{telegram-setup-wizard-C4E0wi1B.js → telegram-setup-wizard-GetgaQy5.js} +1 -1
  100. package/dist/assets/{text-preview-KOyX3OrO.js → text-preview-CEL0P-WV.js} +1 -1
  101. package/dist/assets/{theme-stage-page-D4DYc_C8.js → theme-stage-page-CEBFiy-u.js} +1 -1
  102. package/dist/assets/{tiptap-document-editor-CDIJTTa_.js → tiptap-document-editor-DPkcv0pe.js} +1 -1
  103. package/dist/assets/{tool-detail-panel-CmbBw4_n.js → tool-detail-panel-84bl2nI3.js} +1 -1
  104. package/dist/assets/{upgrade-cancel-page-DfjtkvP9.js → upgrade-cancel-page-DNteIqqS.js} +1 -1
  105. package/dist/assets/{upgrade-success-page-BDWg5oK4.js → upgrade-success-page-CAeO4QtE.js} +1 -1
  106. package/dist/assets/{use-assistant-identity-details-BAgi4MHa.js → use-assistant-identity-details-DqiKjphK.js} +1 -1
  107. package/dist/assets/{use-attachment-preview-CB3GsEns.js → use-attachment-preview-B4PALbqs.js} +1 -1
  108. package/dist/assets/{use-attachment-squares-DPuVHGRC.js → use-attachment-squares-C-9Rz-8O.js} +1 -1
  109. package/dist/assets/{use-bookmarks-C6IlHWIK.js → use-bookmarks-BWGVUg59.js} +1 -1
  110. package/dist/assets/{use-checkout-dismiss-refresh-CDwSKr1-.js → use-checkout-dismiss-refresh-BGeYbYii.js} +1 -1
  111. package/dist/assets/{use-command-palette-sections-DXzS2Tio.js → use-command-palette-sections-D3aj-BzX.js} +1 -1
  112. package/dist/assets/{use-edge-swipe-back-ZgANxgKE.js → use-edge-swipe-back-BGq52vVr.js} +2 -2
  113. package/dist/assets/{use-edit-app-BHUYCv4X.js → use-edit-app-u-kyfEFX.js} +1 -1
  114. package/dist/assets/{use-invite-link-dialog-CdY5FNQa.js → use-invite-link-dialog-Ccf_XNV3.js} +1 -1
  115. package/dist/assets/{use-is-org-ready-BmOdacs1.js → use-is-org-ready-CQntk0MX.js} +1 -1
  116. package/dist/assets/{use-onboarding-login-BUaNGE_u.js → use-onboarding-login-Cw_9Ydsv.js} +1 -1
  117. package/dist/assets/{use-platform-assistant-id-CEMyKEvV.js → use-platform-assistant-id-DMP9urFb.js} +1 -1
  118. package/dist/assets/{use-platform-gate-CdwOyQ8A.js → use-platform-gate-2lhRAyKS.js} +1 -1
  119. package/dist/assets/{use-return-to-short-circuit-CTYRB2Ne.js → use-return-to-short-circuit-Dm5PWev2.js} +1 -1
  120. package/dist/assets/{use-skill-actions-GbdM3IIw.js → use-skill-actions-BopRxJ9x.js} +1 -1
  121. package/dist/assets/{use-sticky-profiles-LVe9u5gh.js → use-sticky-profiles-5cPu_MUo.js} +1 -1
  122. package/dist/assets/{use-subagent-card-data-CFKl88ab.js → use-subagent-card-data-VnA5x24X.js} +1 -1
  123. package/dist/assets/use-transcript-message-by-id-DCOlEJjY.js +1 -0
  124. package/dist/assets/{use-transcript-messages-vw2Hogaj.js → use-transcript-messages-BEpY7uG4.js} +1 -1
  125. package/dist/assets/{use-voice-sample-preview-BjIqIVEG.js → use-voice-sample-preview-CzqJYPiZ.js} +1 -1
  126. package/dist/assets/{viewer-store-DhrkeZmJ.js → viewer-store-CayI6XWh.js} +1 -1
  127. package/dist/assets/{voice-list-DnqRx15F.js → voice-list-BS2BNjKN.js} +1 -1
  128. package/dist/assets/{voice-page-CrrYAE9k.js → voice-page-B7t0g-1X.js} +1 -1
  129. package/dist/assets/{voice-providers-note-ValSs0nz.js → voice-providers-note-Cv7vCsDI.js} +1 -1
  130. package/dist/assets/{welcome-screen-CiBqE53u.js → welcome-screen-eqR0DNzE.js} +1 -1
  131. package/dist/assets/{workflow-detail-panel-crM7HRfK.js → workflow-detail-panel-Dlj8i7AM.js} +1 -1
  132. package/dist/assets/{workspace-page-iAsgehav.js → workspace-page-CAbshSeb.js} +1 -1
  133. package/dist/index.html +46 -46
  134. package/package.json +1 -1
  135. package/dist/assets/billing-page-n2hU_EAj.js +0 -3
  136. package/dist/assets/chat-markdown-message-WfT4JUja.js +0 -1
  137. package/dist/assets/file-markdown-CZPyyZhu.js +0 -2
  138. package/dist/assets/home-tool-permission-card-Bytpm6bE.js +0 -1
  139. package/dist/assets/index-_S2T-6in.css +0 -2
  140. package/dist/assets/routes-ZeXUrnzY.js +0 -23
  141. package/dist/assets/superpowers-page-gPiU1fsq.js +0 -1
  142. package/dist/assets/use-transcript-message-by-id-cDbEJMB-.js +0 -1
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-BENY-yx_.js";import{n as r}from"./QueryClientProvider-CMu7CkQU.js";import{t as i}from"./useQuery-Bz-fbQ-m.js";import{t as a}from"./useMutation-CXGTrp4W.js";import{t as o}from"./jsx-runtime-D3ZM-ToX.js";import{t as s}from"./typography-BeUa5Fd-.js";import{c,h as l,i as u,m as d,n as f,r as p,s as m,t as h}from"./use-save-twilio-credentials-D5Zb65WS.js";import{t as g}from"./check-DSgjgwlo.js";import{G as _}from"./src-hNk11eS3.js";import{t as v}from"./link-2-Bm55xvLL.js";import{t as y}from"./loader-circle-DOtGXcds.js";import{t as b}from"./input-DmHXRXaB.js";import{t as x}from"./modal-DI63s9MQ.js";import{n as S}from"./toast-BpuLSxyt.js";import{i as C}from"./utils-CVoSWh7U.js";import{i as w,n as T,t as E}from"./api-errors-BQX1Pzcm.js";import{Qt as D,in as O,nn as k}from"./sdk.gen-CBPZ2IdN.js";import{Q as A,X as j,Y as M,Z as N,c as ee,l as P,w as F}from"./react-query.gen-DxjuNs-5.js";import{n as I}from"./sdk.gen-CAngxL4a.js";import{t as L}from"./copy-to-clipboard-DnJHokIa.js";import{t as R}from"./a2a-invite-DPoues5o.js";var z=e(t(),1),B=o(),V=[`no_one`,`guardian_only`,`trusted_contacts`,`any_contact`,`strangers`],H=`trusted_contacts`,U=new Set([`platform`,`a2a`]),W=new Set([`vellum`,`whatsapp`,`discord`]);function G(e){return W.has(e)}var K={no_one:`No one`,guardian_only:`Only you`,trusted_contacts:`Verified contacts`,any_contact:`Any contact`,strangers:`Strangers`};function q(e){return{no_one:`No one can message ${e} on this channel: every message is blocked, including yours.`,guardian_only:`Only you can message ${e}. Everyone else is turned away.`,trusted_contacts:`You and the people you’ve verified can message ${e}. Anyone else is asked to verify first, and you’re notified.`,any_contact:`You and any known contact can message ${e}, including contacts you haven’t verified yet. Strangers are asked to verify first.`,strangers:`Anyone can message ${e}, including complete strangers.`}}function J(e){return t=>{S.error(t instanceof Error?t.message:e)}}function Y(e){let t=e-Date.now();if(t<=0)return`Expired`;let n=Math.ceil(t/(1e3*60*60*24));return n===1?`Expires in 1 day`:`Expires in ${n} days`}function X({open:e,assistantId:t,onClose:r}){let[i,o]=(0,z.useState)(!1),c=(0,z.useRef)(null),l=(0,z.useRef)(!1),u=a({...M({path:{assistant_id:t}})}),d=(0,z.useRef)(u.mutate);(0,z.useLayoutEffect)(()=>{d.current=u.mutate});let f=(0,z.useRef)(u.reset);(0,z.useLayoutEffect)(()=>{f.current=u.reset}),(0,z.useEffect)(()=>{e&&!l.current&&d.current({path:{assistant_id:t}}),l.current=e},[e,t]),(0,z.useEffect)(()=>()=>{c.current&&clearTimeout(c.current)},[]);let p=(0,z.useCallback)(()=>{f.current(),o(!1),c.current&&=(clearTimeout(c.current),null),r()},[r]),m=(0,z.useCallback)(e=>{L(e,{errorMessage:`Couldn't copy the invite link.`,onCopied:()=>{o(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>o(!1),2e3)}})},[]),h=u.isSuccess&&u.data.token?R({senderAssistantId:t,token:u.data.token}):``;return(0,B.jsx)(x.Root,{open:e,onOpenChange:e=>{e||p()},children:(0,B.jsxs)(x.Content,{size:`sm`,children:[(0,B.jsx)(x.Header,{children:(0,B.jsx)(x.Title,{children:`Share Connection Link`})}),(0,B.jsx)(x.Body,{children:u.isPending?(0,B.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:[(0,B.jsx)(y,{className:`h-4 w-4 animate-spin`}),`Creating invite link…`]}):u.isError?(0,B.jsxs)(`div`,{className:`space-y-3`,children:[(0,B.jsx)(`p`,{role:`alert`,className:`!m-0 text-body-medium-lighter`,style:{color:`var(--system-negative-strong)`},children:`Failed to create invite link. Make sure A2A is enabled for your assistant.`}),(0,B.jsx)(n,{variant:`outlined`,onClick:()=>u.mutate({path:{assistant_id:t}}),children:`Try Again`})]}):u.isSuccess?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(s,{variant:`body-medium-lighter`,style:{color:`var(--content-secondary)`},children:`Share this link with another assistant owner to establish a connection.`}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(b,{type:`text`,readOnly:!0,value:h,fullWidth:!0,wrapperClassName:`flex-1`,className:`font-mono`,onFocus:e=>e.currentTarget.select()}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>m(h),"aria-label":`Copy invite link`,className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-[var(--border-base)] hover:bg-[var(--surface-hover)]`,children:i?(0,B.jsx)(g,{className:`h-4 w-4`}):(0,B.jsx)(_,{className:`h-4 w-4`})})]}),u.data.expiresAt!=null&&(0,B.jsx)(s,{variant:`body-small-default`,style:{color:`var(--content-tertiary)`},children:Y(u.data.expiresAt)})]}):null}),(0,B.jsx)(x.Footer,{children:(0,B.jsx)(n,{variant:`outlined`,onClick:p,children:`Done`})})]})})}function Z({onClick:e}){return(0,B.jsx)(n,{variant:`outlined`,size:`compact`,leftIcon:(0,B.jsx)(v,{className:`h-3.5 w-3.5`}),onClick:e,children:`Share Connection Link`})}function Q(e){return typeof e==`string`&&V.includes(e)}function $(e){return U.has(e)}function te(e){return(e?.policies??[]).filter(e=>!$(e.channelType)&&!G(e.channelType)).map(e=>({...e,policy:Q(e.policy)?e.policy:`trusted_contacts`}))}async function ne(e,t,n,r){if($(t))throw new E(403,`Channel "${t}" is internal and is not user-configurable.`);let{data:i,error:a,response:o}=await I({path:{assistant_id:e,channel_type:t},body:{policy:n,note:r??null},throwOnError:!1});if(T(o,a,`Failed to save channel policy.`),!o.ok)throw new E(o.status,w(a,o,`Failed to save channel policy.`));if(!i?.policy)throw new E(500,`Gateway returned no policy in response.`);return i.policy}var re=`0.10.0`;function ie(){return C(re)}function ae(e){let t=r(),n=ie(),o=(0,z.useMemo)(()=>({path:{assistant_id:e}}),[e]),s=(0,z.useMemo)(()=>l(o),[o]),u=i({...d(o),enabled:n,select:te}),f=(0,z.useMemo)(()=>{let e={};for(let t of u.data??[])c(t.channelType)&&(e[t.channelType]=t.policy);return e},[u.data]),p=a({mutationFn:({channelKey:t,policy:n})=>ne(e,t,n),onSuccess:()=>t.invalidateQueries({queryKey:s}),onError:J(`Failed to save channel policy`)}),m=(0,z.useCallback)((e,t)=>{p.mutate({channelKey:e,policy:t})},[p]);return n?{policies:f,savingKey:p.isPending?p.variables?.channelKey??null:null,isLoading:u.isPending,isError:u.isError,onChange:m}:{policies:void 0,savingKey:null,isLoading:!1,isError:!1,onChange:void 0}}var oe={slack:`I want to reach you on Slack. Let's set it up.`,telegram:`I want to reach you on Telegram. Let's set it up.`,phone:`I want to be able to call you. Let's set you up with a phone number.`},se={slack:`Slack is set up but not working. Can you finish it off?`,telegram:`Telegram is set up but not working. Can you finish it off?`,phone:`My phone number is set up but not working. Can you finish it off?`},ce=15e3;function le({assistantId:e,onStartSetupConversation:t}){let n=r(),o=(0,z.useMemo)(()=>({path:{assistant_id:e}}),[e]),s=(0,z.useMemo)(()=>P(o),[o]),c=i({...ee(o),enabled:!!e,refetchInterval:ce,select:e=>e.snapshots}),l=(0,z.useMemo)(()=>ue(c.data??[]),[c.data]),d=l.some(e=>e.key===`slack`&&e.status===`ready`),m=i({...j(o),enabled:d,select:e=>e.threadMode}),g=ae(e),_=(0,z.useCallback)(()=>n.invalidateQueries({queryKey:s}),[n,s]),v=a({mutationFn:async t=>{let n={path:{assistant_id:e},throwOnError:!0};t===`slack`?await D(n):t===`telegram`?await k(n):t===`phone`&&await O(n)},onSettled:(t,r,i)=>{_(),i===`slack`&&u(n,e)}}),y=f({assistantId:e}),b=p({assistantId:e}),x=h({assistantId:e}),S=a({...A(),onSuccess:()=>{n.invalidateQueries({queryKey:N(o)})}}),C=y.mutate,w=(0,z.useCallback)(e=>{C(e)},[C]),T=b.mutate,E=(0,z.useCallback)((e,t)=>{T({botToken:e,appToken:t})},[T]),M=S.mutate,F=(0,z.useCallback)(t=>{M({path:{assistant_id:e},body:{threadMode:t}})},[M,e]),I=x.mutateAsync,L=(0,z.useCallback)(async(e,t)=>{await I({accountSid:e,authToken:t})},[I]),R=(0,z.useCallback)((e,n=!1)=>{t&&t(n?se[e]:oe[e])},[t]),B=v.mutate,V=(0,z.useCallback)(e=>{B(e)},[B]);return{channels:l,pendingChannelKey:v.isPending?v.variables??null:null,slackThreadMode:m.data,slackThreadModePending:S.isPending,channelPolicies:g.policies,policySavingKey:g.savingKey,policiesLoading:g.isLoading,policiesError:g.isError,onChannelPolicyChange:g.onChange,onSetup:t?R:void 0,onDisconnect:V,onSaveTelegramToken:w,telegramSaveStatus:y.status,telegramSaveError:y.error?.message??null,onSaveSlackConfig:E,slackSaveStatus:b.status,slackSaveError:b.error?.message??null,onSlackThreadModeChange:F,onSaveTwilioCredentials:L}}function ue(e){let t=new Map;for(let n of e)t.set(n.channel,n);return m.map(e=>{let n=t.get(e);return{key:e,status:de(n),address:n?.channelHandle??void 0}})}function de(e){return e?e.ready||e.setupStatus===`ready`?`ready`:e.setupStatus===`incomplete`?`incomplete`:`not_configured`:`not_configured`}function fe(e){let t=r(),[n,i]=(0,z.useState)(!1);return{isOpen:n,open:(0,z.useCallback)(()=>{i(!0)},[]),close:(0,z.useCallback)(()=>{i(!1),t.invalidateQueries({queryKey:F({path:{assistant_id:e}})})},[t,e])}}export{J as a,K as c,X as i,q as l,le as n,H as o,Z as r,V as s,fe as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./button-BENY-yx_.js";import{n as r}from"./QueryClientProvider-CMu7CkQU.js";import{t as i}from"./useQuery-Bz-fbQ-m.js";import{t as a}from"./useMutation-CXGTrp4W.js";import{t as o}from"./jsx-runtime-D3ZM-ToX.js";import{t as s}from"./typography-BeUa5Fd-.js";import{c,h as l,i as u,m as d,n as f,r as p,s as m,t as h}from"./use-save-twilio-credentials-D5Zb65WS.js";import{t as g}from"./check-DSgjgwlo.js";import{K as _}from"./src-DyqTPMO2.js";import{t as v}from"./link-2-Bm55xvLL.js";import{t as y}from"./loader-circle-DOtGXcds.js";import{t as b}from"./input-DmHXRXaB.js";import{t as x}from"./modal-DI63s9MQ.js";import{n as S}from"./toast-BpuLSxyt.js";import{i as C}from"./utils-CVoSWh7U.js";import{i as w,n as T,t as E}from"./api-errors-BQX1Pzcm.js";import{Qt as D,in as O,nn as k}from"./sdk.gen-CBPZ2IdN.js";import{Q as A,X as j,Y as M,Z as N,c as ee,l as P,w as F}from"./react-query.gen-DxjuNs-5.js";import{n as I}from"./sdk.gen-CAngxL4a.js";import{t as L}from"./copy-to-clipboard-DnJHokIa.js";import{t as R}from"./a2a-invite-DPoues5o.js";var z=e(t(),1),B=o(),V=[`no_one`,`guardian_only`,`trusted_contacts`,`any_contact`,`strangers`],H=`trusted_contacts`,U=new Set([`platform`,`a2a`]),W=new Set([`vellum`,`whatsapp`,`discord`]);function G(e){return W.has(e)}var K={no_one:`No one`,guardian_only:`Only you`,trusted_contacts:`Verified contacts`,any_contact:`Any contact`,strangers:`Strangers`};function q(e){return{no_one:`No one can message ${e} on this channel: every message is blocked, including yours.`,guardian_only:`Only you can message ${e}. Everyone else is turned away.`,trusted_contacts:`You and the people you’ve verified can message ${e}. Anyone else is asked to verify first, and you’re notified.`,any_contact:`You and any known contact can message ${e}, including contacts you haven’t verified yet. Strangers are asked to verify first.`,strangers:`Anyone can message ${e}, including complete strangers.`}}function J(e){return t=>{S.error(t instanceof Error?t.message:e)}}function Y(e){let t=e-Date.now();if(t<=0)return`Expired`;let n=Math.ceil(t/(1e3*60*60*24));return n===1?`Expires in 1 day`:`Expires in ${n} days`}function X({open:e,assistantId:t,onClose:r}){let[i,o]=(0,z.useState)(!1),c=(0,z.useRef)(null),l=(0,z.useRef)(!1),u=a({...M({path:{assistant_id:t}})}),d=(0,z.useRef)(u.mutate);(0,z.useLayoutEffect)(()=>{d.current=u.mutate});let f=(0,z.useRef)(u.reset);(0,z.useLayoutEffect)(()=>{f.current=u.reset}),(0,z.useEffect)(()=>{e&&!l.current&&d.current({path:{assistant_id:t}}),l.current=e},[e,t]),(0,z.useEffect)(()=>()=>{c.current&&clearTimeout(c.current)},[]);let p=(0,z.useCallback)(()=>{f.current(),o(!1),c.current&&=(clearTimeout(c.current),null),r()},[r]),m=(0,z.useCallback)(e=>{L(e,{errorMessage:`Couldn't copy the invite link.`,onCopied:()=>{o(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>o(!1),2e3)}})},[]),h=u.isSuccess&&u.data.token?R({senderAssistantId:t,token:u.data.token}):``;return(0,B.jsx)(x.Root,{open:e,onOpenChange:e=>{e||p()},children:(0,B.jsxs)(x.Content,{size:`sm`,children:[(0,B.jsx)(x.Header,{children:(0,B.jsx)(x.Title,{children:`Share Connection Link`})}),(0,B.jsx)(x.Body,{children:u.isPending?(0,B.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:[(0,B.jsx)(y,{className:`h-4 w-4 animate-spin`}),`Creating invite link…`]}):u.isError?(0,B.jsxs)(`div`,{className:`space-y-3`,children:[(0,B.jsx)(`p`,{role:`alert`,className:`!m-0 text-body-medium-lighter`,style:{color:`var(--system-negative-strong)`},children:`Failed to create invite link. Make sure A2A is enabled for your assistant.`}),(0,B.jsx)(n,{variant:`outlined`,onClick:()=>u.mutate({path:{assistant_id:t}}),children:`Try Again`})]}):u.isSuccess?(0,B.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,B.jsx)(s,{variant:`body-medium-lighter`,style:{color:`var(--content-secondary)`},children:`Share this link with another assistant owner to establish a connection.`}),(0,B.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,B.jsx)(b,{type:`text`,readOnly:!0,value:h,fullWidth:!0,wrapperClassName:`flex-1`,className:`font-mono`,onFocus:e=>e.currentTarget.select()}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>m(h),"aria-label":`Copy invite link`,className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-[var(--border-base)] hover:bg-[var(--surface-hover)]`,children:i?(0,B.jsx)(g,{className:`h-4 w-4`}):(0,B.jsx)(_,{className:`h-4 w-4`})})]}),u.data.expiresAt!=null&&(0,B.jsx)(s,{variant:`body-small-default`,style:{color:`var(--content-tertiary)`},children:Y(u.data.expiresAt)})]}):null}),(0,B.jsx)(x.Footer,{children:(0,B.jsx)(n,{variant:`outlined`,onClick:p,children:`Done`})})]})})}function Z({onClick:e}){return(0,B.jsx)(n,{variant:`outlined`,size:`compact`,leftIcon:(0,B.jsx)(v,{className:`h-3.5 w-3.5`}),onClick:e,children:`Share Connection Link`})}function Q(e){return typeof e==`string`&&V.includes(e)}function $(e){return U.has(e)}function te(e){return(e?.policies??[]).filter(e=>!$(e.channelType)&&!G(e.channelType)).map(e=>({...e,policy:Q(e.policy)?e.policy:`trusted_contacts`}))}async function ne(e,t,n,r){if($(t))throw new E(403,`Channel "${t}" is internal and is not user-configurable.`);let{data:i,error:a,response:o}=await I({path:{assistant_id:e,channel_type:t},body:{policy:n,note:r??null},throwOnError:!1});if(T(o,a,`Failed to save channel policy.`),!o.ok)throw new E(o.status,w(a,o,`Failed to save channel policy.`));if(!i?.policy)throw new E(500,`Gateway returned no policy in response.`);return i.policy}var re=`0.10.0`;function ie(){return C(re)}function ae(e){let t=r(),n=ie(),o=(0,z.useMemo)(()=>({path:{assistant_id:e}}),[e]),s=(0,z.useMemo)(()=>l(o),[o]),u=i({...d(o),enabled:n,select:te}),f=(0,z.useMemo)(()=>{let e={};for(let t of u.data??[])c(t.channelType)&&(e[t.channelType]=t.policy);return e},[u.data]),p=a({mutationFn:({channelKey:t,policy:n})=>ne(e,t,n),onSuccess:()=>t.invalidateQueries({queryKey:s}),onError:J(`Failed to save channel policy`)}),m=(0,z.useCallback)((e,t)=>{p.mutate({channelKey:e,policy:t})},[p]);return n?{policies:f,savingKey:p.isPending?p.variables?.channelKey??null:null,isLoading:u.isPending,isError:u.isError,onChange:m}:{policies:void 0,savingKey:null,isLoading:!1,isError:!1,onChange:void 0}}var oe={slack:`I want to reach you on Slack. Let's set it up.`,telegram:`I want to reach you on Telegram. Let's set it up.`,phone:`I want to be able to call you. Let's set you up with a phone number.`},se={slack:`Slack is set up but not working. Can you finish it off?`,telegram:`Telegram is set up but not working. Can you finish it off?`,phone:`My phone number is set up but not working. Can you finish it off?`},ce=15e3;function le({assistantId:e,onStartSetupConversation:t}){let n=r(),o=(0,z.useMemo)(()=>({path:{assistant_id:e}}),[e]),s=(0,z.useMemo)(()=>P(o),[o]),c=i({...ee(o),enabled:!!e,refetchInterval:ce,select:e=>e.snapshots}),l=(0,z.useMemo)(()=>ue(c.data??[]),[c.data]),d=l.some(e=>e.key===`slack`&&e.status===`ready`),m=i({...j(o),enabled:d,select:e=>e.threadMode}),g=ae(e),_=(0,z.useCallback)(()=>n.invalidateQueries({queryKey:s}),[n,s]),v=a({mutationFn:async t=>{let n={path:{assistant_id:e},throwOnError:!0};t===`slack`?await D(n):t===`telegram`?await k(n):t===`phone`&&await O(n)},onSettled:(t,r,i)=>{_(),i===`slack`&&u(n,e)}}),y=f({assistantId:e}),b=p({assistantId:e}),x=h({assistantId:e}),S=a({...A(),onSuccess:()=>{n.invalidateQueries({queryKey:N(o)})}}),C=y.mutate,w=(0,z.useCallback)(e=>{C(e)},[C]),T=b.mutate,E=(0,z.useCallback)((e,t)=>{T({botToken:e,appToken:t})},[T]),M=S.mutate,F=(0,z.useCallback)(t=>{M({path:{assistant_id:e},body:{threadMode:t}})},[M,e]),I=x.mutateAsync,L=(0,z.useCallback)(async(e,t)=>{await I({accountSid:e,authToken:t})},[I]),R=(0,z.useCallback)((e,n=!1)=>{t&&t(n?se[e]:oe[e])},[t]),B=v.mutate,V=(0,z.useCallback)(e=>{B(e)},[B]);return{channels:l,pendingChannelKey:v.isPending?v.variables??null:null,slackThreadMode:m.data,slackThreadModePending:S.isPending,channelPolicies:g.policies,policySavingKey:g.savingKey,policiesLoading:g.isLoading,policiesError:g.isError,onChannelPolicyChange:g.onChange,onSetup:t?R:void 0,onDisconnect:V,onSaveTelegramToken:w,telegramSaveStatus:y.status,telegramSaveError:y.error?.message??null,onSaveSlackConfig:E,slackSaveStatus:b.status,slackSaveError:b.error?.message??null,onSlackThreadModeChange:F,onSaveTwilioCredentials:L}}function ue(e){let t=new Map;for(let n of e)t.set(n.channel,n);return m.map(e=>{let n=t.get(e);return{key:e,status:de(n),address:n?.channelHandle??void 0}})}function de(e){return e?e.ready||e.setupStatus===`ready`?`ready`:e.setupStatus===`incomplete`?`incomplete`:`not_configured`:`not_configured`}function fe(e){let t=r(),[n,i]=(0,z.useState)(!1);return{isOpen:n,open:(0,z.useCallback)(()=>{i(!0)},[]),close:(0,z.useCallback)(()=>{i(!1),t.invalidateQueries({queryKey:F({path:{assistant_id:e}})})},[t,e])}}export{J as a,K as c,X as i,q as l,le as n,H as o,Z as r,V as s,fe as t};
@@ -1 +1 @@
1
- import{$ as e,i as t,it as n,n as r,nt as i,tt as a}from"./auth-store-DkOiOQNx.js";var o=5e3;function s(e,t,n){return!n||e!=null?`ready`:t===`error`?`unavailable`:`resolving`}function c(){return s(i(),a.use.status(),t())}function l(){return s(e(),a.getState().status,n(r.getState().platformSession))}function u(){return c()===`ready`}export{c as i,l as n,u as r,o as t};
1
+ import{$ as e,i as t,it as n,n as r,nt as i,tt as a}from"./auth-store-BJdkkmzu.js";var o=5e3;function s(e,t,n){return!n||e!=null?`ready`:t===`error`?`unavailable`:`resolving`}function c(){return s(i(),a.use.status(),t())}function l(){return s(e(),a.getState().status,n(r.getState().platformSession))}function u(){return c()===`ready`}export{c as i,l as n,u as r,o as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./capture-error-Cw5vs0Ef.js";import{t as n}from"./react-BFJW0bSv.js";import{u as r}from"./chunk-5KNZJZUH-BUqIilZr.js";import{t as i}from"./is-electron-BHXrkjI3.js";import{E as a}from"./platform-detection-C_TK32Dw.js";import{d as o}from"./routes-iipg2wkc.js";import{i as s}from"./navigation-resolver-DrNVOkMu.js";import{t as c}from"./build-state-B0f3Jn2o.js";import{n as l}from"./login-flow-B8CUFAeg.js";import{n as u,r as d}from"./native-auth-error-B9Iha2zU.js";var f=e(n(),1);function p(e){let n=r(),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(null),_=(0,f.useRef)(0);return{loading:p,error:h,login:async()=>{let r=e??s(c({sessionSettled:!0,isAuthenticated:!0}),n.pathname),i=++_.current;g(null),m(!0);try{await a(l,`${o.account.providerCallback}?returnTo=${encodeURIComponent(r)}`,{returnTo:r})}catch(e){if(i!==_.current)return;t(e,{context:`onboarding_login`,tags:{authError:u(e)??`unclassified`}}),g(d(e)),m(!1)}},cancel:()=>{_.current++,m(!1),g(null),i()&&window.vellum?.auth?.cancelOAuth()}}}export{p as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./capture-error-Cw5vs0Ef.js";import{t as n}from"./react-BFJW0bSv.js";import{u as r}from"./chunk-5KNZJZUH-BUqIilZr.js";import{t as i}from"./is-electron-BHXrkjI3.js";import{E as a}from"./platform-detection-C_TK32Dw.js";import{d as o}from"./routes-iipg2wkc.js";import{i as s}from"./navigation-resolver-DrNVOkMu.js";import{t as c}from"./build-state-DJaFMxtL.js";import{n as l}from"./login-flow-CN5J4YsY.js";import{n as u,r as d}from"./native-auth-error-B9Iha2zU.js";var f=e(n(),1);function p(e){let n=r(),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(null),_=(0,f.useRef)(0);return{loading:p,error:h,login:async()=>{let r=e??s(c({sessionSettled:!0,isAuthenticated:!0}),n.pathname),i=++_.current;g(null),m(!0);try{await a(l,`${o.account.providerCallback}?returnTo=${encodeURIComponent(r)}`,{returnTo:r})}catch(e){if(i!==_.current)return;t(e,{context:`onboarding_login`,tags:{authError:u(e)??`unclassified`}}),g(d(e)),m(!1)}},cancel:()=>{_.current++,m(!1),g(null),i()&&window.vellum?.auth?.cancelOAuth()}}}export{p as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{J as n}from"./auth-store-DkOiOQNx.js";var r=e(t(),1);function i(e,t){let[i,a]=(0,r.useState)({platformAssistantId:null,isLoading:!1,error:null});return(0,r.useEffect)(()=>{if(!t||!e){a({platformAssistantId:null,isLoading:!1,error:null});return}let r=!0;return a({platformAssistantId:null,isLoading:!0,error:null}),n(e).then(e=>{r&&a({platformAssistantId:e,isLoading:!1,error:null})}).catch(e=>{r&&a({platformAssistantId:null,isLoading:!1,error:e instanceof Error?e:Error(String(e))})}),()=>{r=!1}},[e,t]),i}export{i as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{J as n}from"./auth-store-BJdkkmzu.js";var r=e(t(),1);function i(e,t){let[i,a]=(0,r.useState)({platformAssistantId:null,isLoading:!1,error:null});return(0,r.useEffect)(()=>{if(!t||!e){a({platformAssistantId:null,isLoading:!1,error:null});return}let r=!0;return a({platformAssistantId:null,isLoading:!0,error:null}),n(e).then(e=>{r&&a({platformAssistantId:e,isLoading:!1,error:null})}).catch(e=>{r&&a({platformAssistantId:null,isLoading:!1,error:e instanceof Error?e:Error(String(e))})}),()=>{r=!1}},[e,t]),i}export{i as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{_ as n,b as r}from"./local-mode-BfEgOekp.js";import{_t as i,i as a,o}from"./auth-store-DkOiOQNx.js";var s=e(t(),1);function c(){let e=i.use.assistantState();return!!(e.kind===`self_hosted`||e.kind===`active`&&e.isLocal)}function l(){let e=i.use.assistantState();return e.kind===`active`&&!e.isLocal}function u(){let e=i.use.assistantState();return e.kind===`loading`||e.kind===`initializing`||e.kind===`cleaning_up`}function d(e={}){let t=p(e);return t===`pending`?`disabled`:t}function f(e={}){let t=p(e),n=m(t===`pending`,e.settleTimeoutMs??5e3);return t===`pending`&&n?`disabled`:t}function p(e){let t=a(),i=o(),s=r(),l=c(),u=i?`disabled`:`pending`;return e.platformHostedOnly?l?`gated`:t?`full`:u:n()&&s?`gated`:t?`full`:u}function m(e,t){let[n,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e){r(!1);return}let n=setTimeout(()=>r(!0),t);return()=>{clearTimeout(n)}},[e,t]),n}export{f as a,d as i,c as n,u as r,l as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{_ as n,b as r}from"./local-mode-BfEgOekp.js";import{_t as i,i as a,o}from"./auth-store-BJdkkmzu.js";var s=e(t(),1);function c(){let e=i.use.assistantState();return!!(e.kind===`self_hosted`||e.kind===`active`&&e.isLocal)}function l(){let e=i.use.assistantState();return e.kind===`active`&&!e.isLocal}function u(){let e=i.use.assistantState();return e.kind===`loading`||e.kind===`initializing`||e.kind===`cleaning_up`}function d(e={}){let t=p(e);return t===`pending`?`disabled`:t}function f(e={}){let t=p(e),n=m(t===`pending`,e.settleTimeoutMs??5e3);return t===`pending`&&n?`disabled`:t}function p(e){let t=a(),i=o(),s=r(),l=c(),u=i?`disabled`:`pending`;return e.platformHostedOnly?l?`gated`:t?`full`:u:n()&&s?`gated`:t?`full`:u}function m(e,t){let[n,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e){r(!1);return}let n=setTimeout(()=>r(!0),t);return()=>{clearTimeout(n)}},[e,t]),n}export{f as a,d as i,c as n,u as r,l as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{h as n,n as r}from"./chunk-5KNZJZUH-BUqIilZr.js";import{t as i}from"./jsx-runtime-D3ZM-ToX.js";import{t as a}from"./loader-circle-DOtGXcds.js";import{a as o,s}from"./auth-store-DkOiOQNx.js";import{R as c}from"./platform-detection-C_TK32Dw.js";import{d as l}from"./routes-iipg2wkc.js";import{a as u}from"./use-platform-gate-CdwOyQ8A.js";import{t as d}from"./hard-navigate-BrsAH6PB.js";import{a as f,o as p}from"./login-flow-B8CUFAeg.js";var m=i();function h(){return(0,m.jsx)(a,{className:`h-6 w-6 animate-spin text-[var(--content-tertiary)]`,"aria-label":`Loading`})}var g=e(t(),1);function _({to:e}){let t=f(e);return(0,g.useEffect)(()=>{t&&d(e)},[t,e]),t?null:(0,m.jsx)(r,{to:e,replace:!0})}function v(){let[e]=n(),t=o(),r=s(),i=u(),a=e.get(`returnTo`),d=c(a,l.assistant);if(!a)return{kind:`proceed`,returnTo:null};if(r)return{kind:`wait`};if(!t)return{kind:`proceed`,returnTo:d};if(p(d)){if(i===`pending`)return{kind:`wait`};if(i===`disabled`)return{kind:`proceed`,returnTo:d}}return{kind:`redirect`,node:(0,m.jsx)(_,{to:d})}}export{h as n,v as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{h as n,n as r}from"./chunk-5KNZJZUH-BUqIilZr.js";import{t as i}from"./jsx-runtime-D3ZM-ToX.js";import{t as a}from"./loader-circle-DOtGXcds.js";import{a as o,s}from"./auth-store-BJdkkmzu.js";import{R as c}from"./platform-detection-C_TK32Dw.js";import{d as l}from"./routes-iipg2wkc.js";import{a as u}from"./use-platform-gate-2lhRAyKS.js";import{t as d}from"./hard-navigate-BrsAH6PB.js";import{a as f,o as p}from"./login-flow-CN5J4YsY.js";var m=i();function h(){return(0,m.jsx)(a,{className:`h-6 w-6 animate-spin text-[var(--content-tertiary)]`,"aria-label":`Loading`})}var g=e(t(),1);function _({to:e}){let t=f(e);return(0,g.useEffect)(()=>{t&&d(e)},[t,e]),t?null:(0,m.jsx)(r,{to:e,replace:!0})}function v(){let[e]=n(),t=o(),r=s(),i=u(),a=e.get(`returnTo`),d=c(a,l.assistant);if(!a)return{kind:`proceed`,returnTo:null};if(r)return{kind:`wait`};if(!t)return{kind:`proceed`,returnTo:d};if(p(d)){if(i===`pending`)return{kind:`wait`};if(i===`disabled`)return{kind:`proceed`,returnTo:d}}return{kind:`redirect`,node:(0,m.jsx)(_,{to:d})}}export{h as n,v as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{n}from"./QueryClientProvider-CMu7CkQU.js";import{t as r}from"./useMutation-CXGTrp4W.js";import{t as i}from"./jsx-runtime-D3ZM-ToX.js";import{t as a}from"./card-q0GJX1HZ.js";import{t as o}from"./createLucideIcon-C1mdGPB9.js";import{t as s}from"./brain-ZiC0HCCF.js";import"./src-hNk11eS3.js";import{t as c}from"./globe-COk-NH9x.js";import{t as l}from"./puzzle-CIWAeBs0.js";import{t as u}from"./terminal-CkQ9DSF2.js";import{t as d}from"./user-Djte2CiZ.js";import{t as f}from"./tag-DeMzQvCo.js";import{i as p,n as m,t as h}from"./api-errors-BQX1Pzcm.js";import{br as g}from"./sdk.gen-CBPZ2IdN.js";import{gn as _}from"./react-query.gen-DxjuNs-5.js";import{t as v}from"./skills-Lf85mR9L.js";var y=o(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),b=e(t(),1),x=i();function S({skill:e,className:t,fallback:n=`🧩`}){let[r,i]=(0,b.useState)(!1);return e.icon&&!r?(0,x.jsx)(`img`,{src:`/assistant/skills/${e.id}/${e.icon}`,alt:``,className:`${t} object-contain`,onError:()=>i(!0)}):(0,x.jsx)(`span`,{className:t,children:e.emoji??n})}var C={vellum:{label:`Vellum`,icon:y},clawhub:{label:`Clawhub`,icon:c},skillssh:{label:`skills.sh`,icon:u},custom:{label:`Custom`,icon:d},"assistant-memory":{label:`Assistant's Memory`,icon:s}};function w({origin:e}){let t=e in C?C[e]:{label:e.replace(/-/g,` `),icon:l};return(0,x.jsx)(f,{tone:`neutral`,leftIcon:(0,b.createElement)(t.icon),className:`capitalize`,children:t.label})}function T(e){return e.kind===`installed`||e.kind===`bundled`}function E(e){return e.kind===`catalog`}function D({icon:e,iconColor:t=`var(--content-tertiary)`,title:n,subtitle:r,children:i}){return(0,x.jsx)(a.Root,{children:(0,x.jsxs)(a.Body,{className:`flex flex-col items-center justify-center py-16 text-center`,children:[(0,x.jsx)(e,{className:`mb-3 h-8 w-8`,style:{color:t},"aria-hidden":!0}),(0,x.jsx)(`h3`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:n}),(0,x.jsx)(`p`,{className:`mt-1 max-w-sm text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:r}),i]})})}async function O(e,t,n){let{data:r,error:i,response:a}=await g({path:{assistant_id:e},body:n?{slug:t,version:n}:{slug:t},throwOnError:!1});if(m(a,i,`Failed to install skill.`),!a.ok)throw new h(a.status,p(i,a,`Failed to install skill.`));return r??{ok:!0}}function k(e,{onRemoved:t}={}){let i=n(),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(null),d=(0,b.useCallback)(()=>{v(i,e)},[e,i]),f=r({mutationFn:t=>O(e,t),onMutate:e=>o(e),onSettled:()=>{o(null),d()}}),p=_({onMutate:e=>c(e.path.id),onSuccess:()=>{t?.()},onSettled:()=>{c(null),d()}}),m=(0,b.useCallback)(e=>{f.mutate(e.slug??e.id)},[f]),h=(0,b.useCallback)(e=>{u(e)},[]),g=(0,b.useCallback)(()=>{l&&(p.mutate({path:{assistant_id:e,id:l.id}}),u(null))},[e,l,p]),y=(0,b.useCallback)(()=>{u(null)},[]);return{handleInstall:m,handleRemove:h,isInstallingSkill:(0,b.useCallback)(e=>a===(e.slug??e.id),[a]),isRemovingSkill:(0,b.useCallback)(e=>s===e.id,[s]),skillPendingRemoval:l,confirmRemove:g,cancelRemove:y}}export{w as a,T as i,D as n,S as o,E as r,y as s,k as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{n}from"./QueryClientProvider-CMu7CkQU.js";import{t as r}from"./useMutation-CXGTrp4W.js";import{t as i}from"./jsx-runtime-D3ZM-ToX.js";import{t as a}from"./card-q0GJX1HZ.js";import{t as o}from"./createLucideIcon-C1mdGPB9.js";import{t as s}from"./brain-ZiC0HCCF.js";import"./src-DyqTPMO2.js";import{t as c}from"./globe-COk-NH9x.js";import{t as l}from"./puzzle-CIWAeBs0.js";import{t as u}from"./terminal-CkQ9DSF2.js";import{t as d}from"./user-Djte2CiZ.js";import{t as f}from"./tag-DeMzQvCo.js";import{i as p,n as m,t as h}from"./api-errors-BQX1Pzcm.js";import{br as g}from"./sdk.gen-CBPZ2IdN.js";import{gn as _}from"./react-query.gen-DxjuNs-5.js";import{t as v}from"./skills-B4bfakyU.js";var y=o(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),b=e(t(),1),x=i();function S({skill:e,className:t,fallback:n=`🧩`}){let[r,i]=(0,b.useState)(!1);return e.icon&&!r?(0,x.jsx)(`img`,{src:`/assistant/skills/${e.id}/${e.icon}`,alt:``,className:`${t} object-contain`,onError:()=>i(!0)}):(0,x.jsx)(`span`,{className:t,children:e.emoji??n})}var C={vellum:{label:`Vellum`,icon:y},clawhub:{label:`Clawhub`,icon:c},skillssh:{label:`skills.sh`,icon:u},custom:{label:`Custom`,icon:d},"assistant-memory":{label:`Assistant's Memory`,icon:s}};function w({origin:e}){let t=e in C?C[e]:{label:e.replace(/-/g,` `),icon:l};return(0,x.jsx)(f,{tone:`neutral`,leftIcon:(0,b.createElement)(t.icon),className:`capitalize`,children:t.label})}function T(e){return e.kind===`installed`||e.kind===`bundled`}function E(e){return e.kind===`catalog`}function D({icon:e,iconColor:t=`var(--content-tertiary)`,title:n,subtitle:r,children:i}){return(0,x.jsx)(a.Root,{children:(0,x.jsxs)(a.Body,{className:`flex flex-col items-center justify-center py-16 text-center`,children:[(0,x.jsx)(e,{className:`mb-3 h-8 w-8`,style:{color:t},"aria-hidden":!0}),(0,x.jsx)(`h3`,{className:`text-title-small`,style:{color:`var(--content-default)`},children:n}),(0,x.jsx)(`p`,{className:`mt-1 max-w-sm text-body-medium-lighter`,style:{color:`var(--content-tertiary)`},children:r}),i]})})}async function O(e,t,n){let{data:r,error:i,response:a}=await g({path:{assistant_id:e},body:n?{slug:t,version:n}:{slug:t},throwOnError:!1});if(m(a,i,`Failed to install skill.`),!a.ok)throw new h(a.status,p(i,a,`Failed to install skill.`));return r??{ok:!0}}function k(e,{onRemoved:t}={}){let i=n(),[a,o]=(0,b.useState)(null),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(null),d=(0,b.useCallback)(()=>{v(i,e)},[e,i]),f=r({mutationFn:t=>O(e,t),onMutate:e=>o(e),onSettled:()=>{o(null),d()}}),p=_({onMutate:e=>c(e.path.id),onSuccess:()=>{t?.()},onSettled:()=>{c(null),d()}}),m=(0,b.useCallback)(e=>{f.mutate(e.slug??e.id)},[f]),h=(0,b.useCallback)(e=>{u(e)},[]),g=(0,b.useCallback)(()=>{l&&(p.mutate({path:{assistant_id:e,id:l.id}}),u(null))},[e,l,p]),y=(0,b.useCallback)(()=>{u(null)},[]);return{handleInstall:m,handleRemove:h,isInstallingSkill:(0,b.useCallback)(e=>a===(e.slug??e.id),[a]),isRemovingSkill:(0,b.useCallback)(e=>s===e.id,[s]),skillPendingRemoval:l,confirmRemove:g,cancelRemove:y}}export{w as a,T as i,D as n,S as o,E as r,y as s,k as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{r as t}from"./capture-error-Cw5vs0Ef.js";import{t as n}from"./react-BFJW0bSv.js";import{t as r}from"./button-BENY-yx_.js";import{n as i}from"./QueryClientProvider-CMu7CkQU.js";import{t as a}from"./useQuery-Bz-fbQ-m.js";import{t as o}from"./jsx-runtime-D3ZM-ToX.js";import{t as s}from"./cn-DFWryB3N.js";import{t as c}from"./typography-BeUa5Fd-.js";import{t as l}from"./chevron-down-CrFV6lfm.js";import{t as u}from"./chevron-right-DBGgpEiZ.js";import{L as d,z as f}from"./src-hNk11eS3.js";import{t as p}from"./loader-circle-DOtGXcds.js";import{n as m,t as h}from"./input-DmHXRXaB.js";import{t as g}from"./toggle-C-v4x7_A.js";import{t as _}from"./modal-DI63s9MQ.js";import{n as v}from"./toast-BpuLSxyt.js";import{t as y}from"./select-B8-i-CZ4.js";import{t as b}from"./is-electron-BHXrkjI3.js";import{A as x,D as S,E as C,F as w,I as T,L as E,M as D,N as O,O as k,T as A,d as j,k as M,s as N,u as ee}from"./profile-pickers-ChG4_Gpc.js";import{t as P}from"./assistant-identity-store-nE-e8KQw.js";import{n as F,o as I}from"./utils-CVoSWh7U.js";import{r as L}from"./api-errors-BQX1Pzcm.js";import{Gt as te,Wt as ne,Xt as re,Yt as R,dr as ie,fr as ae}from"./sdk.gen-CBPZ2IdN.js";import{n as z}from"./use-platform-gate-CdwOyQ8A.js";import{r as B}from"./use-is-org-ready-BmOdacs1.js";import{Ct as oe,J as se,u as ce,wt as le}from"./react-query.gen-DxjuNs-5.js";var V=e(n(),1),ue={maxTokens:!1,contextWindow:!1,effort:!1,speed:!1,verbosity:!1,temperature:!1,topP:!1,thinking:!1,thinkingLevel:!1};function H(e){return e===`gpt-5`||e.startsWith(`gpt-5.`)||e.startsWith(`gpt-5-`)}function U(e){return e.startsWith(`anthropic/`)}function de(e,t){let n=t.toLowerCase();return T(e).find(e=>e.id.toLowerCase()===n)}function fe(e,t){return de(e,t)?.adaptiveThinkingOnly===!0}function pe(e){return U(e)||e.startsWith(`x-ai/grok-4`)||e.startsWith(`deepseek/deepseek-r1`)||e===`qwen/qwen3.5-plus-02-15`||e===`qwen/qwen3.5-397b-a17b`||e===`moonshotai/kimi-k2.6`}var me=[`minimal`,`low`,`medium`,`high`],W=[`low`,`medium`,`high`];function he(e){return/^gemini-3.*pro/.test(e)}var ge=new Set(me);function _e(e){return typeof e==`string`&&ge.has(e)}function ve(e){return he(e.toLowerCase())?W:me}function ye(e,t){let n=de(e,t);return n?.supportsThinking===void 0?e===`anthropic`?!0:e===`openrouter`?pe(t):e===`vercel-ai-gateway`?U(t):!1:n.supportsThinking}function G(e,t,n){return e===`anthropic`?!t.includes(`haiku`)&&n:e===`openai`?H(t):e===`openrouter`||e===`vercel-ai-gateway`?U(t)?!t.includes(`haiku`)&&n:n:e===`fireworks`||e===`together`||e===`baseten`?n:!1}var be=new Set([`openai-compatible`,`fireworks`,`minimax`,`atlascloud`,`baseten`,`ollama`,`openrouter`,`together`,`vercel-ai-gateway`]);function xe(e,t){return t||be.has(e)}function Se(e,t){if(!e||!t)return ue;let n=e.toLowerCase(),r=t.toLowerCase(),i=n===`anthropic`||(n===`openrouter`||n===`vercel-ai-gateway`)&&U(r),a=ye(n,r);return{maxTokens:!0,contextWindow:!0,effort:G(n,r,a),speed:n===`anthropic`&&r.includes(`opus`),verbosity:n===`openai`&&H(r),temperature:i,topP:xe(n,i),thinking:(n===`anthropic`||n===`openrouter`||n===`vercel-ai-gateway`&&U(r))&&a&&!fe(n,r),thinkingLevel:n===`gemini`&&a}}var K=o(),q=[`inherit`,`none`,`low`,`medium`,`high`,`xhigh`,`max`],Ce=[`standard`,`fast`],we=[`low`,`medium`,`high`],Te=`default`,Ee=64e3;function De({label:e,value:t,onChange:n,defaultValue:i,max:a,disabled:o}){let s=t===null,c=t??i,[l,u]=(0,V.useState)(s?``:String(t)),[f,p]=(0,V.useState)(t);t!==f&&(p(t),u(t===null?``:String(t)));function m(e){u(e);let t=e.trim();if(t===``){n(null);return}let r=Number(t);Number.isFinite(r)&&r>=1e3&&r<=a&&n(r)}function g(e){let r=e.trim();if(r===``){n(null);return}let i=Number(r);if(!Number.isFinite(i)){u(t===null?``:String(t));return}let o=ee(i,a);u(String(o)),n(o)}return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:e}),s?(0,K.jsxs)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[`Default · `,j(i)]}):null]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(d,{value:c,onValueChange:e=>n(typeof e==`number`?e:e[0]),min:k,max:a,step:M,disabled:o,"aria-label":e})}),(0,K.jsx)(h,{type:`number`,inputMode:`numeric`,value:l,placeholder:String(i),onChange:e=>m(e.target.value),onBlur:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g(e.currentTarget.value)},min:k,max:a,step:M,disabled:o,"aria-label":`${e} (tokens)`,wrapperClassName:`w-32 shrink-0`,className:`text-right tabular-nums`}),(0,K.jsx)(r,{variant:`ghost`,size:`compact`,onClick:()=>n(null),disabled:o||s,children:`Reset`})]})]})}function J({visibility:e,isReadOnly:t,model:n,selectedModel:r,defaultMaxOutputTokens:i,defaultContextWindowMaxInputTokens:a,maxTokens:o,onMaxTokensChange:s,contextWindowMaxInputTokens:c,onContextWindowChange:l,effort:u,onEffortChange:p,speed:m,onSpeedChange:h,verbosity:_,onVerbosityChange:v,temperatureEnabled:y,onTemperatureEnabledChange:b,temperature:x,onTemperatureChange:S,topPEnabled:C,onTopPEnabledChange:w,topP:T,onTopPChange:E,thinkingEnabled:D,onThinkingEnabledChange:O,thinkingStreamThinking:k,onThinkingStreamThinkingChange:A,thinkingLevel:j,onThinkingLevelChange:M}){let ee=N(),P=r?.maxOutputTokens??Ee,F=r?.contextWindowTokens??2e5,I=Math.min(i??Ee,P),L=Math.min(a??2e5,F);return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!t&&ee&&(0,K.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Fields left at their default are saved with the values shown and won’t change if the assistant defaults change later.`}),e.maxTokens&&(0,K.jsx)(De,{label:`Max Output Tokens`,value:o,onChange:s,defaultValue:I,max:P,disabled:t}),e.contextWindow&&(0,K.jsx)(De,{label:`Context Window`,value:c,onChange:l,defaultValue:L,max:F,disabled:t||!r}),e.effort&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Effort`}),(0,K.jsx)(f,{items:q.map(e=>({value:e,label:e===`inherit`?`default`:e,disabled:t})),value:u,onChange:e=>p(e),ariaLabel:`Effort`})]}),e.speed&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Speed`}),(0,K.jsx)(f,{items:Ce.map(e=>({value:e,label:e,disabled:t})),value:m,onChange:e=>h(e),ariaLabel:`Speed`})]}),e.verbosity&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Verbosity`}),(0,K.jsx)(f,{items:we.map(e=>({value:e,label:e,disabled:t})),value:_,onChange:e=>v(e),ariaLabel:`Verbosity`})]}),e.temperature&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(g,{checked:y,onChange:e=>b(e),label:`Temperature`,disabled:t}),y&&(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(d,{value:x,onValueChange:e=>S(typeof e==`number`?e:e[0]),min:0,max:2,step:.01,disabled:t,showValue:!0,formatValue:e=>typeof e==`number`?e.toFixed(2):String(e)})})})]}),e.topP&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(g,{checked:C,onChange:e=>w(e),label:`Top P`,disabled:t}),C&&(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(d,{value:T,onValueChange:e=>E(typeof e==`number`?e:e[0]),min:0,max:1,step:.01,disabled:t,showValue:!0,formatValue:e=>typeof e==`number`?e.toFixed(2):String(e)})})})]}),e.thinking&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(g,{checked:D,onChange:e=>{O(e),e||A(!1)},label:`Enable extended thinking`,disabled:t}),D&&(0,K.jsx)(`div`,{className:`pl-4`,children:(0,K.jsx)(g,{checked:k,onChange:e=>A(e),label:`Stream thinking tokens`,disabled:t})})]}),e.thinkingLevel&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:[`Thinking level`,` `,(0,K.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(default = inherit)`})]}),(0,K.jsx)(f,{items:[`default`,...ve(n)].map(e=>({value:e,label:`${e}`,disabled:t})),value:j,onChange:M,ariaLabel:`Thinking level`})]})]})}var Y=[`anthropic`,`openai`,`gemini`,`ollama`,`fireworks`,`together`,`openrouter`,`vercel-ai-gateway`,`minimax`,`atlascloud`,`litellm`,`baseten`,`poolside`,`openai-compatible`];function X(e){return e===`ollama`?`none`:`api_key`}function Oe(e){let t=e.split(`/`);return t.length<3||t[0]!==`credential`?null:{service:t[1],field:t.slice(2).join(`/`)}}function ke(e){switch(e){case 409:return`A provider with these settings already exists.`;case 404:return`Provider not found. It may have been removed.`;case 400:return`Invalid configuration. Check the provider settings.`;default:return`Failed to save provider. Please try again.`}}function Ae(e,t){if(e!==400)return;let n=t?.error?.message;return typeof n==`string`&&n.length>0?n:void 0}function je(e){return e.label?e.label:e.auth.type===`oauth_subscription`?O.chatgpt:O[e.provider]??e.provider}var Me=new Set([`ollama`]);function Ne(e,t){return!Me.has(e)||t}function Pe(e){return A.filter(t=>Ne(t,e))}function Fe(e){return Y.filter(t=>Ne(t,e))}function Ie(e){return Object.keys(D).filter(t=>Ne(t,e))}function Le(){return Pe(z())}function Re(){return Fe(z())}function ze(){return Ie(z())}function Be(e,t){let n=[...new Set(e.map(e=>e.provider))].filter(e=>Ne(e,t)),r=[];return n.includes(`vellum`)&&r.push(x),r.push(...Y.filter(e=>n.includes(e)),...n.filter(e=>e!==`vellum`&&!Y.includes(e))),r}function Ve(e,t){let n=new Set(e.map(e=>e.provider));return Fe(t).filter(e=>e!==`openai-compatible`&&!n.has(e))}var He=`${S}::`;function Z(e){return`${He}${e}`}function Q(e){return e.startsWith(He)?e.slice(He.length):null}function Ue(e,t,n){let r=[];for(let i of e){if(i===`vellum`){r.push({value:i,label:n(i),meta:`Managed`});continue}if(i!==`openai-compatible`){r.push({value:i,label:n(i)});continue}for(let e of t)e.provider===`openai-compatible`&&r.push({value:Z(e.name),label:e.label&&e.label.trim()!==``?e.label:e.name,meta:`Custom`})}return r}var We=new Set([`gpt-5.6-sol`,`gpt-5.6-terra`,`gpt-5.6-luna`,`gpt-5.5`,`gpt-5.4`,`gpt-5.4-mini`,`gpt-5.3-codex`]);function Ge(e){return(e??[]).map(e=>({id:e.id,displayName:e.displayName??e.id}))}function Ke(e,t,n){return!e||T(e).length===0?!1:(t?n.find(e=>e.name===t):void 0)?.auth.type===`oauth_subscription`?!0:!t&&n.length>0&&n.every(e=>e.auth.type===`oauth_subscription`)}var qe=`No provider connections. Open Providers to add one.`,Je={"no-provider":{placeholder:`Select a provider first`,hint:null},"configure-connection":{placeholder:`Configure models on connection`,hint:`No models available. Configure models on the provider connection first.`},"unknown-to-catalog":{placeholder:`No models available`,hint:`No models are available for this provider in this app version. Update the app, or enter a custom model ID.`}},Ye=`__custom-model-id__`;function Xe({text:e}){return(0,K.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:e})}function Ze({provider:e,model:t,providerConnection:n,onProviderChange:i,onModelChange:a,onConnectionChange:o,connections:s,isReadOnly:l,availableConnectionsForProvider:u,connectionNotFound:d,hideProviderField:f=!1,providerError:p=null}){let m=e.length>0&&t.length===0,[g,_]=(0,V.useState)(!1),v=Ke(e,n,u),b=e!==``&&!v;(0,V.useEffect)(()=>{b||_(!1)},[e,b]);function x(e){if(e===Ye){_(!0),a(``);return}a(e)}let S=ze(),C=z(),w=(0,V.useMemo)(()=>{let t=Be(s??[],C);return e&&!t.includes(e)?[...t,e]:t},[s,e,C]),E=s===void 0?S:w,D=E.length===0&&!l,k=(0,V.useMemo)(()=>{if(!e)return[];let t=T(e);if(t.length>0)return Ke(e,n,u)?t.filter(e=>We.has(e.id)):t;if(n){let e=u.find(e=>e.name===n);return e?Ge(e.models):[]}let r=new Set,i=[];for(let e of u)for(let t of e.models??[])r.has(t.id)||(r.add(t.id),i.push({id:t.id,displayName:t.displayName??t.id}));return i},[e,n,u]),A=(0,V.useMemo)(()=>{if(!t||k.some(e=>e.id===t))return k;let n=T(e).find(e=>e.id===t),r=u.flatMap(e=>e.models??[]).find(e=>e.id===t),i=n?.displayName??r?.displayName??t;return[...k,{id:t,displayName:i}]},[t,k,e,u]),j=e?k.length===0?e===`openai-compatible`?`configure-connection`:`unknown-to-catalog`:null:`no-provider`,M=j?Je[j]:null;return(0,V.useEffect)(()=>{if(!e||g)return;let n=T(e);n.length>0&&!n.some(e=>e.id===t)||t&&k.length>0&&!k.some(e=>e.id===t)&&a(``)},[t,k,a,e,g]),(0,K.jsxs)(K.Fragment,{children:[!f&&(0,K.jsx)(y,{id:`profile-editor-provider`,label:`Provider`,errorText:p&&D?qe:p,helperText:D&&!p?qe:void 0,value:e===`openai-compatible`&&n?Z(n):e,onChange:e=>{let t=Q(e);if(t){i(`openai-compatible`),o(t);return}i(e)},disabled:l,placeholder:`Select a provider…`,options:[...Ue(E,s??[],e=>O[e]??e).map(({value:e,label:t,meta:n})=>({value:e,label:t,suffix:n?(0,K.jsx)(Xe,{text:n}):void 0})),...d&&e===`openai-compatible`&&n?[{value:Z(n),label:`${n} (not found)`}]:[],...e===`openai-compatible`&&!n?[{value:`openai-compatible`,label:O[`openai-compatible`]??`openai-compatible`}]:[]]}),d&&!l&&(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:`This profile referenced a credential that no longer exists. Saving resets it to use the provider’s available key.`}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Model`}),g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(h,{value:t,onChange:e=>a(e.target.value),disabled:l,placeholder:`provider/model-id`,"aria-label":`Custom model ID`,fullWidth:!0,autoFocus:!0}),(0,K.jsx)(r,{variant:`link`,size:`compact`,disabled:l,onClick:()=>_(!1),children:`Choose from list`})]}):(0,K.jsx)(y,{value:t,onChange:x,disabled:l||!e,"aria-label":`Model`,placeholder:M?.placeholder??`Select a model`,options:[...A.map(e=>({value:e.id,label:e.displayName})),...b?[{value:Ye,label:`Enter a custom model ID…`}]:[]]}),g?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Enter the exact model identifier your provider expects. It's sent to the connection as-is.`}):m&&!l?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:M?.hint??`Select a model.`}):null]})]})}function Qe(e,t,n){return[`credentialPresence`,e,t,n]}function $e({assistantId:e,credentialKind:n,credentialName:r,enabled:i=!0}){let o=B(),s=a({queryKey:Qe(e??``,n,r),queryFn:async()=>{let{data:t}=await ae({path:{assistant_id:e},body:{type:n,name:r},throwOnError:!0});return t.found},enabled:!!e&&i&&o,retry:t,staleTime:3e4});return{hasStoredCredential:s.data??!1,isLoading:s.isLoading}}function et({assistantId:e,onConnected:t}){let[n,i]=(0,V.useState)(`idle`),[a,o]=(0,V.useState)(``),[s,l]=(0,V.useState)(null);async function u(){i(`starting`),l(null);let t=window.open(`about:blank`,`_blank`);try{let{data:{authorize_url:n}}=await te({path:{assistant_id:e},throwOnError:!0});t?(t.opener=null,t.location.href=n):window.open(n,`_blank`,`noopener`),i(`paste_url`)}catch{t?.close(),i(`failed`),l(`Failed to start ChatGPT sign-in. Please try again.`)}}async function d(){l(null);let n=a.trim();if(!n){l(`Please paste the URL from the error page.`);return}let r;try{r=new URL(n)}catch{l(`Invalid URL. Please paste the full URL from the address bar.`);return}let o=r.searchParams.get(`code`),s=r.searchParams.get(`state`);if(!o){l(`The URL is missing the authorization code. Make sure you copied the full URL.`);return}if(!s){l(`The URL is missing the state parameter. Make sure you copied the full URL.`);return}i(`exchanging`);try{await ne({path:{assistant_id:e},body:{code:o,state:s},throwOnError:!0}),i(`completed`);let{data:n}=await R({path:{assistant_id:e},query:{provider:`openai`},throwOnError:!0});t(n.connections.find(e=>e.name===`chatgpt-subscription`||e.name===`openai-chatgpt`)||{name:`chatgpt-subscription`,provider:`openai`,auth:{type:`oauth_subscription`,credential:`credential/openai/chatgpt-subscription`},label:`ChatGPT Subscription`,createdAt:Date.now(),updatedAt:Date.now(),baseUrl:null,models:null,isManaged:!1})}catch{i(`failed`),l(`Failed to complete sign-in. Please try again.`)}}function f(){i(`idle`),o(``),l(null)}return(0,K.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-[var(--border-base)] p-4`,children:[(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Connect your ChatGPT subscription to use OpenAI models without an API key.`}),n===`idle`||n===`paste_url`?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(c,{variant:`body-small-default`,as:`p`,className:n===`paste_url`?`text-[var(--content-tertiary)] line-through`:`text-[var(--content-secondary)]`,children:[`1. Click “Sign in with ChatGPT”`,n===`idle`?` below`:null,` to open a popup`]}),(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-secondary)]`,children:`2. Sign in, then you'll land on an error page — that's expected`}),(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-secondary)]`,children:`3. Copy the full URL from that page's address bar and paste it below`})]}),n===`idle`?(0,K.jsx)(r,{variant:`outlined`,size:`compact`,onClick:()=>void u(),children:`Sign in with ChatGPT`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(h,{value:a,onChange:e=>{o(e.target.value),l(null)},placeholder:`Paste callback URL here...`,fullWidth:!0}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)(r,{variant:`primary`,size:`compact`,disabled:!a.trim(),onClick:()=>void d(),children:`Complete Sign In`})})]})]}):null,n===`starting`?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(p,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}),(0,K.jsx)(c,{variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Starting sign-in...`})]}):null,n===`exchanging`?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(p,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}),(0,K.jsx)(c,{variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Completing sign-in...`})]}):null,n===`completed`?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--system-positive-strong)]`,children:`ChatGPT subscription connected successfully.`}):null,s?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:s}):null,n===`failed`?(0,K.jsx)(r,{variant:`outlined`,size:`compact`,onClick:f,children:`Try Again`}):null]})}var tt=new Set(Object.entries(O).flatMap(([e,t])=>[e.toLowerCase(),t.toLowerCase()])),nt={reserved:`That name belongs to a built-in provider. Pick another.`,duplicate:`A custom provider with this name already exists.`};function rt(e,t,n){let r=e.trim().toLowerCase();return r?tt.has(r)?`reserved`:(t??[]).some(e=>e.provider===`openai-compatible`&&e.name!==n&&(e.label?.trim()||e.name).toLowerCase()===r)?`duplicate`:null:null}function it(e){return e.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).join(`-`)}function at(e){return it(e)}function ot(e,t){let n=new Set(t.map(e=>e.toLowerCase()));if(!n.has(e.toLowerCase()))return e;let r=2,i=`${e}-${r}`;for(;n.has(i.toLowerCase());)r+=1,i=`${e}-${r}`;return i}function st(e,t){return{name:O[e]??e,key:ot(`${at(e)}-personal`,t)}}function ct(e,t){return{name:e,key:ot(at(e),t)}}function lt({apiKeyValue:e,onApiKeyChange:t,credential:n,onCredentialChange:i,isLoadingCredential:a,apiKeyPlaceholder:o,provider:s,providerCredentials:l,showAdvancedSection:d,onError:f}){let[m,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(!1),[b,x]=(0,V.useState)(``);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`API Key`}),a?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,K.jsx)(p,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}),(0,K.jsx)(c,{variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Loading…`})]}):(0,K.jsx)(h,{type:`password`,value:e,onChange:e=>{t(e.target.value),f(null)},placeholder:o,fullWidth:!0})]}),d&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":m,onClick:()=>g(e=>!e),className:`flex items-center gap-1 text-body-small-default text-[var(--content-secondary)] w-full text-left`,children:[(0,K.jsx)(u,{className:`h-4 w-4 transition-transform ${m?`rotate-90`:``}`}),(0,K.jsx)(`span`,{children:`Advanced`}),(0,K.jsx)(`span`,{className:`text-[var(--content-tertiary)] ml-1`,children:`· Credential reference`})]}),m&&(0,K.jsxs)(`div`,{className:`mt-2 space-y-3`,children:[(()=>{let e=l.map(e=>{let t=`credential/${e.service}/${e.field}`;return{label:t,value:t}}),t=e.some(e=>e.value===n),r=n&&!t?[{label:n,value:n},...e]:e;return r.length===0?null:(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Credential Reference`}),(0,K.jsx)(y,{"aria-label":`Credential reference`,value:n,onChange:e=>{i(e)},options:r})]})})(),_&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`New Credential Name`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(h,{value:b,onChange:e=>x(e.target.value),placeholder:`e.g. team-key`,fullWidth:!0}),(0,K.jsx)(r,{variant:`primary`,size:`compact`,disabled:!b.trim(),onClick:()=>{let e=b.trim();e&&(i(`credential/${s}/${e}`),v(!1),x(``))},children:`Use`})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)(r,{variant:`ghost`,size:`compact`,onClick:()=>{_?(v(!1),x(``)):v(!0)},children:_?`Cancel`:`+ New Credential`})})]})]})]})}var ut=`•`.repeat(8);function dt(e,t){return t?ut:e}function ft(e){let t=[];for(let n of e)if(n.type===`api_key`)t.push({service:n.name,field:`api_key`});else if(n.type===`credential`){let e=n.name.lastIndexOf(`:`);if(e>=0){let r=n.name.slice(0,e),i=n.name.slice(e+1);r&&i&&t.push({service:r,field:i})}}return t}function pt({assistantId:e,enabled:n=!0}){let r=B(),i=a({...oe({path:{assistant_id:e}}),enabled:!!e&&n&&r,select:e=>ft(e.secrets),retry:t,staleTime:3e4});return{credentials:i.data??[],isLoading:i.isLoading}}function mt({assistantId:e,existingNames:t,connections:n,defaultProviderType:a,hideProviderSelect:o=!1,onCreated:s,onCancel:l,variant:d=`modal`}){let f=Re(),p=a&&f.includes(a)?a:f[0]??`anthropic`,m=st(p,t),[g,b]=(0,V.useState)(p===`openai-compatible`?``:m.name),[x,S]=(0,V.useState)(m.key),[C,w]=(0,V.useState)(p),T=C===`chatgpt`,E=T?`openai`:C,D=T?`oauth_subscription`:X(E),[k,A]=(0,V.useState)(()=>p===`ollama`?``:p===`openai-compatible`?`credential/${m.key}/api_key`:`credential/${p}/api_key`),[j,M]=(0,V.useState)(``),[N,ee]=(0,V.useState)(``),[P,F]=(0,V.useState)(!1),[I,L]=(0,V.useState)(null),[te,ne]=(0,V.useState)(!1),R=E===`openai-compatible`,ae=(0,V.useMemo)(()=>{let e=!T&&!f.includes(E)?[...f,E]:[...f],t=e.indexOf(`openai`);return t>=0&&e.splice(t+1,0,`chatgpt`),e},[T,E,f]),z=(0,V.useRef)(!1);function B(e){z.current=!0,b(e)}let[oe,se]=(0,V.useState)(``),[ce,ue]=(0,V.useState)(!1),H=i(),U=(0,V.useMemo)(()=>Oe(k),[k]),de=D===`api_key`&&U!==null,{hasStoredCredential:fe,isLoading:pe}=$e({assistantId:e,credentialKind:`credential`,credentialName:U?`${U.service}:${U.field}`:``,enabled:de}),{credentials:me}=pt({assistantId:e,enabled:!0}),W=R?rt(g,n):null,he=x.trim().length>0&&(!R||g.trim().length>0)&&W===null;async function ge(){if(he){F(!0),L(null);try{let t;if(D===`api_key`){let n=k.trim()||`credential/${R?x:E}/api_key`,r=oe.trim();if(r){ue(!0);try{let t=Oe(n);await ie({path:{assistant_id:e},body:t?{type:`credential`,name:`${t.service}:${t.field}`,value:r}:{type:`api_key`,name:E,value:r},throwOnError:!0});let i=Qe(e,`credential`,t?`${t.service}:${t.field}`:``);H.setQueryData(i,!0),H.invalidateQueries({queryKey:le({path:{assistant_id:e}})})}catch{L(`Failed to save API key. Please try again.`);return}finally{ue(!1)}t={type:`api_key`,credential:n}}else if(fe)t={type:`api_key`,credential:n};else if(R)t={type:`none`};else{L(`Enter an API key or select an existing credential.`);return}}else if(D===`oauth_subscription`){L(`Use the "Sign in with ChatGPT" button to connect your subscription.`);return}else t={type:`none`};let n=g.trim()||null,r={name:x.trim(),provider:E,auth:t,...n!==null&&{label:n},...R&&{base_url:j.trim()||null,models:N.trim()?N.split(`,`).map(e=>({id:e.trim()})).filter(e=>e.id):null}},{data:i,error:a,response:o}=await re({path:{assistant_id:e},body:r});if(!o?.ok){L(Ae(o?.status,a)??ke(o?.status));return}if(!i){L(`Server returned an empty response. Please try again.`);return}v.success(`Provider connected`),s(i)}catch{L(`Failed to save provider. Please try again.`)}finally{F(!1)}}}let _e=me.filter(e=>e.service===E),ve=_e.length>0,ye=dt(`Enter your API key`,fe),G=te,be=(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":G,onClick:()=>ne(e=>!e),className:`flex items-center gap-1 text-body-small-default text-[var(--content-secondary)] w-full text-left`,children:[(0,K.jsx)(u,{className:`h-4 w-4 transition-transform ${G?`rotate-90`:``}`}),(0,K.jsx)(`span`,{children:`Advanced`})]}),G&&(0,K.jsx)(`div`,{className:`mt-2 space-y-4`,children:(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:[`Display Name`,` `,(0,K.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(optional)`})]}),(0,K.jsx)(h,{value:g,onChange:e=>B(e.target.value),placeholder:`e.g. My Anthropic Key`,fullWidth:!0})]})})]}),xe=(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!o&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,K.jsx)(y,{"aria-label":`Provider`,value:C,onChange:e=>{if(w(e),L(null),e===`chatgpt`)return;let{name:n,key:r}=st(e,t);z.current||b(e===`openai-compatible`?``:n),S(r),A(e===`ollama`?``:e===`openai-compatible`?`credential/${r}/api_key`:`credential/${e}/api_key`)},options:[...ae.filter(e=>e!==`openai-compatible`).map(e=>({value:e,label:O[e]})),...ae.includes(`openai-compatible`)?[{value:`openai-compatible`,label:`Custom provider`}]:[]]}),R?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Custom providers connect to any endpoint that serves the OpenAI-compatible API — xAI, Groq, LM Studio, vLLM, and similar.`}):null]}),R&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Name`}),(0,K.jsx)(h,{value:g,onChange:e=>B(e.target.value),placeholder:`xAI`,fullWidth:!0}),W?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:nt[W]}):null]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Base URL`}),(0,K.jsx)(h,{value:j,onChange:e=>M(e.target.value),placeholder:`https://api.x.ai/v1`,fullWidth:!0})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Models`}),(0,K.jsx)(h,{value:N,onChange:e=>ee(e.target.value),placeholder:`model-1, model-2`,fullWidth:!0}),(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Comma-separated model identifiers exposed by your endpoint.`})]})]}),D===`api_key`&&(0,K.jsx)(lt,{apiKeyValue:oe,onApiKeyChange:se,credential:k,onCredentialChange:A,isLoadingCredential:pe,apiKeyPlaceholder:ye,provider:E,providerCredentials:_e,showAdvancedSection:ve,onError:L}),R&&D===`api_key`?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Leave the key empty for local endpoints — they connect keyless.`}):null,D===`oauth_subscription`&&(0,K.jsx)(et,{assistantId:e,onConnected:s}),!T&&!R&&be,I&&(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:I})]}),Se=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(r,{variant:`ghost`,size:`compact`,onClick:l,children:`Cancel`}),!T&&(0,K.jsx)(r,{variant:`primary`,size:`compact`,disabled:!he||P||ce,onClick:()=>void ge(),children:P?`Saving…`:R&&g.trim()?`Add ${g.trim()}`:`Add`})]});return d===`inline`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[xe,(0,K.jsx)(`div`,{className:`flex justify-end gap-2`,children:Se})]}):(0,K.jsxs)(_.Content,{size:`md`,children:[(0,K.jsxs)(_.Header,{children:[(0,K.jsx)(_.Title,{children:`Add Provider`}),(0,K.jsx)(_.Description,{children:`Choose a provider and paste its API key.`})]}),(0,K.jsx)(_.Body,{children:xe}),(0,K.jsx)(_.Footer,{children:Se})]})}var ht=`__create_new_provider__`;function gt(e){return X(e)===`api_key`?`Add API key`:`Set up`}function _t({editor:e,assistantId:t,connections:n,variant:r}){let i=z(),a=e.effectiveMode===`create`,o=r===`panel`,[s,l]=(0,V.useState)(!1),d=s||!!e.keyError&&e.getDirty(),f=(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:a?`Name`:`Display Name`}),(0,K.jsx)(h,{type:`text`,value:e.label,onChange:t=>e.handleLabelChange(t.target.value),placeholder:`e.g. Fast & Cheap`,disabled:e.isReadOnly,fullWidth:!0})]}),p=(0,K.jsx)(m,{label:(0,K.jsxs)(K.Fragment,{children:[`Description`,` `,(0,K.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(optional)`})]}),value:e.description,onChange:t=>e.setDescription(t.target.value),placeholder:`Describe when to use this profile`,disabled:e.isReadOnly,rows:2,fullWidth:!0,className:`resize-none`}),_=(0,K.jsx)(h,{label:`Key`,type:`text`,value:e.key,onChange:t=>e.handleKeyChange(t.target.value),placeholder:`e.g. fast-cheap`,disabled:e.isReadOnly||e.effectiveMode===`edit`,errorText:e.isReadOnly?void 0:e.keyError,fullWidth:!0}),v=!o&&(!e.isReadOnly||e.status!==`active`)?(0,K.jsx)(g,{checked:e.status===`active`,onChange:t=>e.setStatus(t?`active`:`disabled`),label:`Active`,className:`touch-mobile:mt-2 touch-mobile:[&_button]:h-7 touch-mobile:[&_button]:w-10 touch-mobile:[&_button>span]:h-6 touch-mobile:[&_button>span]:w-6`}):null,b=(0,K.jsx)(J,{visibility:e.visibility,isReadOnly:e.isReadOnly,model:e.model,selectedModel:e.selectedModel,defaultMaxOutputTokens:e.defaultMaxOutputTokens,defaultContextWindowMaxInputTokens:e.defaultContextWindowMaxInputTokens,maxTokens:e.maxTokens,onMaxTokensChange:e.setMaxTokens,contextWindowMaxInputTokens:e.contextWindowMaxInputTokens,onContextWindowChange:e.setContextWindowMaxInputTokens,effort:e.effort,onEffortChange:e.setEffort,speed:e.speed,onSpeedChange:e.setSpeed,verbosity:e.verbosity,onVerbosityChange:e.setVerbosity,temperatureEnabled:e.temperatureEnabled,onTemperatureEnabledChange:e.setTemperatureEnabled,temperature:e.temperature,onTemperatureChange:e.setTemperature,topPEnabled:e.topPEnabled,onTopPEnabledChange:e.setTopPEnabled,topP:e.topP,onTopPChange:e.setTopP,thinkingEnabled:e.thinkingEnabled,onThinkingEnabledChange:e.setThinkingEnabled,thinkingStreamThinking:e.thinkingStreamThinking,onThinkingStreamThinkingChange:e.setThinkingStreamThinking,thinkingLevel:e.thinkingLevel,onThinkingLevelChange:e.setThinkingLevel}),x=e.saveError?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:e.saveError}):null,C=(0,V.useMemo)(()=>Ve(e.effectiveConnections,i),[e.effectiveConnections,i]),w=(0,V.useMemo)(()=>{let t=Ue(Be(e.effectiveConnections,i),e.effectiveConnections,e=>O[e]??e).map(({value:e,label:t,meta:n})=>({value:e,label:t,suffix:n?(0,K.jsx)(Xe,{text:n}):void 0}));for(let e of C)t.push({value:e,label:O[e]??e,suffix:(0,K.jsx)(Xe,{text:gt(e)})});return t.push({value:ht,label:`+ Create new provider`}),t},[i,e.effectiveConnections,C]),T=(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{id:`profile-editor-provider-label`,className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,K.jsx)(y,{value:e.creatingProvider?e.pendingCreateProvider??ht:e.provider===`openai-compatible`&&e.providerConnection?Z(e.providerConnection):e.provider,onChange:t=>{if(t===ht){e.setCreatingProvider(!0),e.setPendingCreateProvider(null),e.setNewProviderNote(!1);return}if(!t)return;let n=Q(t);if(n){e.setCreatingProvider(!1),e.setPendingCreateProvider(null),e.provider===`openai-compatible`?e.setModel(``):e.handleProviderChange(S),e.setProviderConnection(n);return}let r=t;if(C.includes(r)){e.setCreatingProvider(!0),e.setPendingCreateProvider(r),e.setNewProviderNote(!1);return}e.setCreatingProvider(!1),e.setPendingCreateProvider(null),e.handleProviderChange(r)},placeholder:`Select a provider…`,"aria-labelledby":`profile-editor-provider-label`,options:w}),e.newProviderNote?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`New provider connection will show up in the Providers section.`}):null]}),e.creatingProvider?(0,K.jsx)(mt,{variant:`inline`,assistantId:t,existingNames:e.effectiveConnections.map(e=>e.name),connections:e.effectiveConnections,defaultProviderType:(e.pendingCreateProvider??e.provider)||void 0,hideProviderSelect:e.pendingCreateProvider!==null,onCreated:e.handleProviderCreated,onCancel:()=>{e.setCreatingProvider(!1),e.setPendingCreateProvider(null)}},e.pendingCreateProvider??`any`):(0,K.jsx)(Ze,{provider:e.provider,model:e.model,providerConnection:e.providerConnection,onProviderChange:e.handleProviderChange,onModelChange:e.handleModelChange,onConnectionChange:e.handleConnectionChange,connections:e.effectiveConnections,isReadOnly:e.isReadOnly,availableConnectionsForProvider:e.availableConnectionsForProvider,connectionNotFound:e.connectionNotFound,hideProviderField:!0})]});if(a){let t=e.model!==``;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[f,T,p,v,o?t&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[_,b]}):t&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":d,onClick:()=>l(e=>!e),className:`flex items-center gap-1 text-body-small-default text-[var(--content-secondary)] w-full text-left`,children:[(0,K.jsx)(u,{className:`h-4 w-4 transition-transform ${d?`rotate-90`:``}`}),(0,K.jsx)(`span`,{children:`Advanced`})]}),d?(0,K.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[_,b]}):null]}),x]})}return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[f,p,_,v,(0,K.jsx)(Ze,{provider:e.provider,model:e.model,providerConnection:e.providerConnection,onProviderChange:e.handleProviderChange,onModelChange:e.handleModelChange,onConnectionChange:e.handleConnectionChange,connections:n,isReadOnly:e.isReadOnly,availableConnectionsForProvider:e.availableConnectionsForProvider,connectionNotFound:e.connectionNotFound,providerError:e.providerError}),b,x]})}function vt(e,t,n){if(e){let n=T(e).find(e=>e.id===t);if(n)return n.displayName}for(let e of n??[]){let n=(e.models??[]).find(e=>e.id===t);if(n)return n.displayName??n.id}let r=t.lastIndexOf(`/`);return r>=0?t.slice(r+1):t}function yt(e,t,n){let r=(0,V.useRef)(!1),i=(0,V.useRef)(!1);return{handleLabelChange:(0,V.useCallback)(a=>{i.current=!0,t(a),e===`create`&&!r.current&&n(it(a))},[e,t,n]),handleKeyChange:(0,V.useCallback)(e=>{r.current=!0,i.current=!0,n(e)},[n]),resetDirty:(0,V.useCallback)(()=>{r.current=!1,i.current=!1},[]),getDirty:(0,V.useCallback)(()=>i.current,[])}}var bt=`0.10.12`;async function xt(e,t){await I(t);let n=P.getState().assistantId;return e!=null&&n!==e?!1:F(bt)}function St(e,t){return e===t?!0:e===`vellum`&&C.has(t)}function Ct({mode:e,profileName:t,initialValues:n,existingNames:r,connections:o,assistantId:s,onSave:c}){let[l,u]=(0,V.useState)(e),d=n?.invariant===!0&&l!==`create`,f=l===`view`||d,p=n?.status??`active`,[m,h]=(0,V.useState)(n?.label??``),[g,_]=(0,V.useState)(n?.description??``),[v,y]=(0,V.useState)(e===`create`?``:t??``),[b,S]=(0,V.useState)(n?.provider&&n.provider!==`chatgpt`?n.provider:``),[C,D]=(0,V.useState)(n?.model??``),[O,k]=(0,V.useState)(n?.provider_connection??``),[A,j]=(0,V.useState)(n?.status??`active`),[M,N]=(0,V.useState)([]),[ee,P]=(0,V.useState)(!1),[F,I]=(0,V.useState)(null),[te,ne]=(0,V.useState)(n?.maxTokens??null),[re,R]=(0,V.useState)(n?.contextWindow?.maxInputTokens??null),[ie,ae]=(0,V.useState)(n?.effort??`inherit`),[z,B]=(0,V.useState)(n?.speed??`standard`),[oe,le]=(0,V.useState)(n?.verbosity??`medium`),[ue,H]=(0,V.useState)(typeof n?.temperature==`number`),[U,de]=(0,V.useState)(typeof n?.temperature==`number`?n.temperature:.7),[fe,pe]=(0,V.useState)(typeof n?.topP==`number`),[me,W]=(0,V.useState)(typeof n?.topP==`number`?n.topP:.95),he=f&&A!==p,[ge,ve]=(0,V.useState)(n?.thinking?.enabled??!1),[ye,G]=(0,V.useState)(n?.thinking?.streamThinking??!1),[be,xe]=(0,V.useState)(_e(n?.thinking?.level)?n.thinking.level:Te),K=(0,V.useMemo)(()=>b===`vellum`?E(C):null,[b,C]),q=K?.model??C,Ce=(0,V.useMemo)(()=>b?T(b).find(e=>e.id===q)??null:null,[b,q]),{data:we}=a({...ce({path:{assistant_id:s}}),staleTime:3e4}),Ee=we?.llm?.default?.maxTokens,De=we?.llm?.default?.contextWindow?.maxInputTokens,J=(0,V.useMemo)(()=>Se(b===`vellum`?K?.provider??w(C)??n?.provider??``:b,q),[b,C,q,K,n?.provider]),Y=(0,V.useMemo)(()=>{let e=o??[];if(M.length===0)return e;let t=new Set(e.map(e=>e.name));return[...e,...M.filter(e=>!t.has(e.name))]},[o,M]),X=(0,V.useMemo)(()=>b?Y.filter(e=>St(e.provider,b)):[],[b,Y]),Oe=O!==``&&!X.some(e=>e.name===O),{handleLabelChange:ke,handleKeyChange:Ae,resetDirty:je,getDirty:Me}=yt(l,h,y),Ne=i(),[Pe,Fe]=(0,V.useState)(!1),[Ie,Le]=(0,V.useState)(null),[Re,ze]=(0,V.useState)(!1);(0,V.useEffect)(()=>{n?.provider_connection===`vellum`&&b===(n?.provider??``)&&o?.find(e=>e.name===n.provider_connection)?.provider===`vellum`&&S(x)},[o,b,n]),(0,V.useEffect)(()=>{je(),Fe(!1),Le(null),ze(!1),N([])},[t,e,je]);function Be(e){if(e===b)return;S(e),D(``);let t=Y.filter(t=>St(t.provider,e));k(t.length===1?t[0].name:``),ne(null),R(null),ae(`inherit`),B(`standard`),le(`medium`),H(!1),de(.7),pe(!1),W(.95),ve(!1),G(!1),xe(Te)}function Ve(e){if(k(e),b&&T(b).length===0&&C)if(e===``)new Set(X.flatMap(e=>(e.models??[]).map(e=>e.id))).has(C)||D(``);else{let t=X.find(t=>t.name===e);new Set((t?.models??[]).map(e=>e.id)).has(C)||D(``)}}function He(e){if(e!==C&&(D(e),ne(null),R(null),l===`create`&&e&&!Me())){let{name:t,key:n}=ct(vt(b||void 0,e,X),r);h(t),y(n)}}function Z(e){let t=e.provider;t!==`vellum`&&(N(t=>t.some(t=>t.name===e.name)?t:[...t,e]),S(t),k(e.name),D(``),Fe(!1),Le(null),ze(!0),Ne.invalidateQueries({queryKey:se({path:{assistant_id:s}})}))}let Q=v.trim(),Ue=Q.length===0,We=/\s/.test(v),Ge=l===`create`?r.includes(Q):r.filter(e=>e!==t).includes(Q),Ke=b.length===0,qe=b.length>0&&C.length===0,Je=Ue||We||Ge||Ke||qe,Ye=Ue?`Key is required`:We?`Key cannot contain whitespace`:Ge?`A profile with this key already exists`:null,Xe=!f&&(l===`edit`||Me())&&Ke?`Select a provider`:null;async function Ze(){if(!(Je&&!f)){if(f){if(!he)return;P(!0),I(null);try{await c(Q,{status:`active`},{mode:`merge`})}catch(e){I(L(e)??`Failed to save profile. Please try again.`)}finally{P(!1)}return}P(!0),I(null);try{let e={},t=O===``&&X.length===1?X[0].name:O,r=Oe?``:t,i=b===`vellum`&&await xt(s),a=b===`vellum`?i?x:K?.provider??w(C)??n?.provider??``:b,o=q,u=i?``:r;l===`edit`?(e.label=m.trim()||null,e.description=g.trim()||null,e.provider=a||null,e.model=o||null,e.provider_connection=u||null):(m.trim()&&(e.label=m.trim()),g.trim()&&(e.description=g.trim()),a&&(e.provider=a),o&&(e.model=o),u&&(e.provider_connection=u)),J.maxTokens&&te!==null&&(e.maxTokens=te),J.contextWindow&&re!==null&&(e.contextWindow={maxInputTokens:re}),J.effort&&ie!==`inherit`&&(e.effort=ie),J.speed&&z!==`standard`&&(e.speed=z),J.verbosity&&(e.verbosity=oe),J.temperature&&(ue?e.temperature=U:l===`edit`&&(e.temperature=null)),J.topP&&(fe?e.topP=me:l===`edit`&&(e.topP=null)),J.thinking&&(e.thinking={enabled:ge,...ge?{streamThinking:ye}:{}}),J.thinkingLevel&&be!==`default`&&(e.thinking={enabled:!0,level:be}),(l===`edit`||A!==`active`)&&(e.status=A),await c(Q,e)}catch(e){I(L(e)??`Failed to save profile. Please try again.`)}finally{P(!1)}}}function Qe(){u(`create`),y(``),je()}return{effectiveMode:l,isReadOnly:f,isInvariant:d,hasViewModeChanges:he,label:m,description:g,key:v,provider:b,model:C,providerConnection:O,status:A,saving:ee,saveError:F,keyError:Ye,providerError:Xe,isInvalid:Je,maxTokens:te,contextWindowMaxInputTokens:re,effort:ie,speed:z,verbosity:oe,temperatureEnabled:ue,temperature:U,topPEnabled:fe,topP:me,thinkingEnabled:ge,thinkingStreamThinking:ye,thinkingLevel:be,visibility:J,selectedModel:Ce,defaultMaxOutputTokens:Ee,defaultContextWindowMaxInputTokens:De,effectiveConnections:Y,availableConnectionsForProvider:X,connectionNotFound:Oe,creatingProvider:Pe,pendingCreateProvider:Ie,newProviderNote:Re,setDescription:_,setStatus:j,setMaxTokens:ne,setContextWindowMaxInputTokens:R,setEffort:ae,setSpeed:B,setVerbosity:le,setTemperatureEnabled:H,setTemperature:de,setTopPEnabled:pe,setTopP:W,setThinkingEnabled:ve,setThinkingStreamThinking:G,setThinkingLevel:xe,setCreatingProvider:Fe,setPendingCreateProvider:Le,setNewProviderNote:ze,handleLabelChange:ke,handleKeyChange:Ae,getDirty:Me,handleProviderChange:Be,handleConnectionChange:Ve,handleModelChange:He,handleProviderCreated:Z,setProviderConnection:k,setModel:D,handleSave:Ze,switchToSaveAsNew:Qe}}var wt=`/assistant/assets/pcm-downsample-worklet-CwNZrVLe.js`;function Tt(){if(!(typeof window>`u`))return window.AudioContext??window.webkitAudioContext}function Et(e){let t=Tt();if(!t)throw Error(`Web Audio API is not available in this environment`);return new t(e)}var Dt=`pcm-downsample`,Ot=1600,kt=16e3;function At(){return b()?window.vellum?.helper?.dictation:void 0}function jt(){let e=At();return!!e?.transcribe&&!!e.onTranscribed}var $=null,Mt=null;async function Nt(){return $||($=Et(),Mt=$.audioWorklet.addModule(wt)),$.state!==`running`&&await $.resume(),await Mt,$}async function Pt(e,t){try{let n=await Nt(),r=n.createMediaStreamSource(e),i=new AudioWorkletNode(n,Dt,{numberOfInputs:1,numberOfOutputs:0,channelCount:1}),a=[],o=0,s=0;return i.port.onmessage=e=>{let r=new Int16Array(e.data);if(r.length===0||(a.push(r),o+=r.length,o<Ot))return;let i=new Int16Array(o),c=0;for(let e of a)i.set(e,c),c+=e.length;a=[],o=0,s+=1,(s===1||s%50==0)&&console.info(`dictation: pushed audio chunk #${s} (${i.byteLength} bytes, context=${n.state})`),t(i.buffer)},r.connect(i),console.info(`dictation: audio pump started (context=${n.state})`),()=>{i.port.onmessage=null,i.disconnect(),r.disconnect()}}catch(e){return console.warn(`native-dictation-partials: audio pump failed`,e),null}}var Ft=8e3;async function It(e){let t=At();if(!t?.transcribe||!t.onTranscribed)return null;let n;try{n=await Lt(e)}catch(e){let t=e instanceof DOMException?`${e.name}: ${e.message}`:e;return console.warn(`dictation: blob decode for native transcribe failed`,t),null}if(n.byteLength===0)return null;let r=null,i=t.onTranscribed(e=>{r?.(e.text||null)});try{let e=await t.transcribe(n);if(!e.ok)return console.info(`dictation: native transcribe unavailable:`,e.reason),null;let i=await new Promise(e=>{r=e,setTimeout(()=>e(null),Ft)});return console.info(`dictation: native transcribe ${i?`chars=${i.length}`:`produced no text`}`),i}catch(e){return console.warn(`dictation: native transcribe failed`,e),null}finally{i()}}async function Lt(e){let t=await e.arrayBuffer(),n=await new OfflineAudioContext(1,1,kt).decodeAudioData(t),r=n.numberOfChannels,i=n.length,a=n.getChannelData(0);if(r>1){let e=new Float32Array(i);for(let t=0;t<r;t++){let a=n.getChannelData(t);for(let t=0;t<i;t++)e[t]+=a[t]/r}a=e}let o=new Int16Array(i);for(let e=0;e<i;e++){let t=a[e],n=t<-1?-1:t>1?1:t;o[e]=n<0?n*32768:n*32767}return o.buffer}var Rt=4e3;async function zt(e,t){let n=At();if(!n)return null;let r=n.pushAudioChunk?.bind(n),i=t?.stream,a=!!i&&!!r,o=n.onPartial(t=>{e(t.text)}),s=null,c=null,l=n.onFinalized?.(e=>{s=e.text||null,c?.(s)})??null,u=()=>{l?.(),o()};try{let e=await n.setPartials(!0,void 0,a);if(!e.ok)return console.info(`native-dictation-partials: unavailable:`,e.reason),u(),null}catch(e){return console.warn(`native-dictation-partials: setPartials failed`,e),u(),null}let d=null;if(a&&(d=await Pt(i,e=>r(e)),!d))return u(),n.setPartials(!1).catch(()=>{}),null;let f=null;return()=>f||(d?.(),o(),n.setPartials(!1).catch(()=>{}),f=(async()=>{let e=s;return!e&&l&&(e=await new Promise(e=>{c=e,setTimeout(()=>e(null),Rt)})),l?.(),console.info(e===null?`dictation: native finalized not received`:`dictation: native finalized chars=${e.length}`),e})(),f)}var Bt=[{id:`vellum`,displayName:`Vellum`,subtitle:`Text-to-speech through your Vellum account — billed to Vellum credits, no separate API key needed.`,supportsVoiceSelection:!1,apiKeyPlaceholder:`Connected via your Vellum account`,credentialsGuide:{description:`Connect this assistant to your Vellum account; managed speech uses that connection instead of a provider API key.`,url:`https://platform.vellum.ai/`,linkLabel:`Open Vellum Platform`}},{id:`elevenlabs`,displayName:`ElevenLabs`,subtitle:`High-quality voice synthesis for conversations and read-aloud. Requires an ElevenLabs API key.`,supportsVoiceSelection:!0,apiKeyPlaceholder:`sk_…`,credentialsGuide:{description:`Sign in to ElevenLabs, go to your Profile, and copy your API key.`,url:`https://elevenlabs.io/app/settings/api-keys`,linkLabel:`Open ElevenLabs API Keys`}},{id:`fish-audio`,displayName:`Fish Audio`,subtitle:`Natural-sounding voice synthesis with custom voice cloning. Requires a Fish Audio API key and voice reference ID.`,supportsVoiceSelection:!0,apiKeyPlaceholder:`Enter your Fish Audio API key`,credentialsGuide:{description:`Sign in to Fish Audio, navigate to API Keys in your dashboard, and create a new key.`,url:`https://fish.audio/app/api-keys/`,linkLabel:`Open Fish Audio API Keys`}},{id:`deepgram`,displayName:`Deepgram`,subtitle:`Fast, accurate text-to-speech synthesis. Uses the same API key as Deepgram speech-to-text.`,supportsVoiceSelection:!1,apiKeyPlaceholder:`Enter your Deepgram API key`,credentialsGuide:{description:`Sign in to Deepgram, navigate to your API Keys page, and create or copy an existing key. This is the same key used for speech-to-text.`,url:`https://console.deepgram.com/`,linkLabel:`Open Deepgram Console`}},{id:`xai`,displayName:`xAI`,subtitle:`Text-to-speech from xAI with expressive voices (eve, ara, rex, sal, leo). Requires an xAI API key.`,supportsVoiceSelection:!1,apiKeyPlaceholder:`Enter your xAI API key`,credentialsGuide:{description:`Sign in to the xAI console, navigate to API Keys, and create a new key.`,url:`https://console.x.ai/`,linkLabel:`Open xAI Console`}}],Vt=`macos-native`,Ht=[{id:`vellum`,displayName:`Vellum`,subtitle:`Transcription through your Vellum account — billed to Vellum credits, no separate API key needed.`},{id:`deepgram`,displayName:`Deepgram`,subtitle:`Fast, accurate speech-to-text transcription. Uses the same API key as Deepgram text-to-speech.`,apiKeyPlaceholder:`Enter your Deepgram API key`,credentialsGuide:{description:`Sign in to Deepgram, navigate to your API Keys page, and create or copy an existing key. This is the same key used for text-to-speech.`,url:`https://console.deepgram.com/`,linkLabel:`Open Deepgram Console`}},{id:`openai`,displayName:`OpenAI`,subtitle:`OpenAI Whisper transcription. Requires an OpenAI API key.`,apiKeyPlaceholder:`sk-…`,credentialsGuide:{description:`Sign in to the OpenAI platform, navigate to API Keys, and create a new secret key.`,url:`https://platform.openai.com/api-keys`,linkLabel:`Open OpenAI API Keys`}},{id:Vt,displayName:`macOS Native Dictation`,subtitle:`Apple's on-device speech recognition, running locally through the macOS helper. Works offline and needs no API key.`,requiresNativeDictation:!0,setupWarning:`Requires macOS Dictation to be turned on: open System Settings → Keyboard, then enable Dictation. macOS downloads the on-device speech model the first time Dictation is enabled — without it, voice input produces no transcript.`}],Ut=[{id:`mailgun`,displayName:`Mailgun`,setupSkill:`mailgun-setup`,docsUrl:`https://www.mailgun.com/`},{id:`resend`,displayName:`Resend`,setupSkill:`resend-setup`,docsUrl:`https://resend.com/`}],Wt=[`gemini-3.1-flash-image-preview`,`gemini-3-pro-image-preview`,`gpt-image-2`],Gt={"gemini-3.1-flash-image-preview":`Nano Banana 2`,"gemini-3-pro-image-preview":`Nano Banana Pro`,"gpt-image-2":`GPT Image 2`},Kt=[`vellum`,`gemini`,`openai`],qt={vellum:`Vellum`,gemini:`Gemini`,openai:`OpenAI`};function Jt(e){return e===`vellum`?[...Wt]:Wt.filter(t=>Yt(t)===e)}function Yt(e){return e.startsWith(`gpt-`)||e.startsWith(`dall-e-`)?`openai`:(e.startsWith(`gemini-`),`gemini`)}var Xt=`vellum:ai:imageGenProvider`,Zt=`vellum:ai:imageGenModel`,Qt=`vellum:ai:webSearchProvider`,$t=`vellum:ai:webFetchProvider`,en=`vellum:ai:emailMode`,tn=`vellum:ai:emailByoProvider`,nn=`vellum:voice:ttsProvider`,rn=`vellum:voice:ttsApiKey:`,an=`vellum:voice:ttsVoiceId:`,on=`vellum:voice:sttProvider`,sn=`vellum:voice:sttApiKey:`;function cn({value:e,size:t=`default`,className:n,...r}){let i=t===`compact`;return(0,K.jsxs)(`button`,{type:`button`,className:s(`flex items-center gap-2 rounded-md border border-[var(--field-border)] bg-[var(--field-bg)] text-left text-[var(--content-default)] transition-colors focus:outline-none data-[state=open]:border-[var(--border-active)]`,i?`h-7 min-w-44 px-2.5 text-body-small-default`:`h-9 w-full px-3 text-body-medium-lighter`,n),...r,children:[(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e}),(0,K.jsx)(l,{"aria-hidden":!0,className:s(`shrink-0 text-[var(--content-tertiary)]`,i?`h-3 w-3`:`h-3.5 w-3.5`)})]})}var ln={profiles:{},profileOrder:[]};function un(e,t){let n=e?.profiles,r=e?.profileOrder,i=!!n&&Object.keys(n).length>0,[a,o]=(0,V.useState)(ln),[s,c]=(0,V.useState)(t);return t!==s&&(c(t),o(ln)),(0,V.useEffect)(()=>{i&&o({profiles:n,profileOrder:r??[]})},[i,n,r]),i?{profiles:n,profileOrder:r??[]}:t===s?a:ln}export{vt as A,$e as B,jt as C,Tt as D,Et as E,lt as F,Ae as G,ke as H,nt as I,rt as L,mt as M,pt as N,wt as O,dt as P,et as R,Yt as S,It as T,Oe as U,Le as V,je as W,qt as _,Zt as a,Bt as b,on as c,an as d,$t as f,Kt as g,Gt as h,en as i,_t as j,Ct as k,rn as l,Ut as m,cn as n,Xt as o,Qt as p,tn as r,sn as s,un as t,nn as u,Vt as v,zt as w,Jt as x,Ht as y,Qe as z};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{r as t}from"./capture-error-Cw5vs0Ef.js";import{t as n}from"./react-BFJW0bSv.js";import{t as r}from"./button-BENY-yx_.js";import{n as i}from"./QueryClientProvider-CMu7CkQU.js";import{t as a}from"./useQuery-Bz-fbQ-m.js";import{t as o}from"./jsx-runtime-D3ZM-ToX.js";import{t as s}from"./cn-DFWryB3N.js";import{t as c}from"./typography-BeUa5Fd-.js";import{t as l}from"./chevron-down-CrFV6lfm.js";import{t as u}from"./chevron-right-DBGgpEiZ.js";import{B as d,R as f}from"./src-DyqTPMO2.js";import{t as p}from"./loader-circle-DOtGXcds.js";import{n as m,t as h}from"./input-DmHXRXaB.js";import{t as g}from"./toggle-C-v4x7_A.js";import{t as _}from"./modal-DI63s9MQ.js";import{n as v}from"./toast-BpuLSxyt.js";import{t as y}from"./select-B8-i-CZ4.js";import{t as b}from"./is-electron-BHXrkjI3.js";import{A as x,D as S,E as C,F as w,I as T,L as E,M as D,N as O,O as k,T as A,d as j,k as M,s as N,u as ee}from"./profile-pickers-ChG4_Gpc.js";import{t as P}from"./assistant-identity-store-nE-e8KQw.js";import{n as F,o as I}from"./utils-CVoSWh7U.js";import{r as L}from"./api-errors-BQX1Pzcm.js";import{Gt as te,Wt as ne,Xt as re,Yt as R,dr as ie,fr as ae}from"./sdk.gen-CBPZ2IdN.js";import{n as z}from"./use-platform-gate-2lhRAyKS.js";import{r as B}from"./use-is-org-ready-CQntk0MX.js";import{Ct as oe,J as se,u as ce,wt as le}from"./react-query.gen-DxjuNs-5.js";var V=e(n(),1),ue={maxTokens:!1,contextWindow:!1,effort:!1,speed:!1,verbosity:!1,temperature:!1,topP:!1,thinking:!1,thinkingLevel:!1};function H(e){return e===`gpt-5`||e.startsWith(`gpt-5.`)||e.startsWith(`gpt-5-`)}function U(e){return e.startsWith(`anthropic/`)}function de(e,t){let n=t.toLowerCase();return T(e).find(e=>e.id.toLowerCase()===n)}function fe(e,t){return de(e,t)?.adaptiveThinkingOnly===!0}function pe(e){return U(e)||e.startsWith(`x-ai/grok-4`)||e.startsWith(`deepseek/deepseek-r1`)||e===`qwen/qwen3.5-plus-02-15`||e===`qwen/qwen3.5-397b-a17b`||e===`moonshotai/kimi-k2.6`}var me=[`minimal`,`low`,`medium`,`high`],W=[`low`,`medium`,`high`];function he(e){return/^gemini-3.*pro/.test(e)}var ge=new Set(me);function _e(e){return typeof e==`string`&&ge.has(e)}function ve(e){return he(e.toLowerCase())?W:me}function ye(e,t){let n=de(e,t);return n?.supportsThinking===void 0?e===`anthropic`?!0:e===`openrouter`?pe(t):e===`vercel-ai-gateway`?U(t):!1:n.supportsThinking}function G(e,t,n){return e===`anthropic`?!t.includes(`haiku`)&&n:e===`openai`?H(t):e===`openrouter`||e===`vercel-ai-gateway`?U(t)?!t.includes(`haiku`)&&n:n:e===`fireworks`||e===`together`||e===`baseten`?n:!1}var be=new Set([`openai-compatible`,`fireworks`,`minimax`,`atlascloud`,`baseten`,`ollama`,`openrouter`,`together`,`vercel-ai-gateway`]);function xe(e,t){return t||be.has(e)}function Se(e,t){if(!e||!t)return ue;let n=e.toLowerCase(),r=t.toLowerCase(),i=n===`anthropic`||(n===`openrouter`||n===`vercel-ai-gateway`)&&U(r),a=ye(n,r);return{maxTokens:!0,contextWindow:!0,effort:G(n,r,a),speed:n===`anthropic`&&r.includes(`opus`),verbosity:n===`openai`&&H(r),temperature:i,topP:xe(n,i),thinking:(n===`anthropic`||n===`openrouter`||n===`vercel-ai-gateway`&&U(r))&&a&&!fe(n,r),thinkingLevel:n===`gemini`&&a}}var K=o(),q=[`inherit`,`none`,`low`,`medium`,`high`,`xhigh`,`max`],Ce=[`standard`,`fast`],we=[`low`,`medium`,`high`],Te=`default`,Ee=64e3;function De({label:e,value:t,onChange:n,defaultValue:i,max:a,disabled:o}){let s=t===null,c=t??i,[l,u]=(0,V.useState)(s?``:String(t)),[d,p]=(0,V.useState)(t);t!==d&&(p(t),u(t===null?``:String(t)));function m(e){u(e);let t=e.trim();if(t===``){n(null);return}let r=Number(t);Number.isFinite(r)&&r>=1e3&&r<=a&&n(r)}function g(e){let r=e.trim();if(r===``){n(null);return}let i=Number(r);if(!Number.isFinite(i)){u(t===null?``:String(t));return}let o=ee(i,a);u(String(o)),n(o)}return(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:e}),s?(0,K.jsxs)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:[`Default · `,j(i)]}):null]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(f,{value:c,onValueChange:e=>n(typeof e==`number`?e:e[0]),min:k,max:a,step:M,disabled:o,"aria-label":e})}),(0,K.jsx)(h,{type:`number`,inputMode:`numeric`,value:l,placeholder:String(i),onChange:e=>m(e.target.value),onBlur:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g(e.currentTarget.value)},min:k,max:a,step:M,disabled:o,"aria-label":`${e} (tokens)`,wrapperClassName:`w-32 shrink-0`,className:`text-right tabular-nums`}),(0,K.jsx)(r,{variant:`ghost`,size:`compact`,onClick:()=>n(null),disabled:o||s,children:`Reset`})]})]})}function J({visibility:e,isReadOnly:t,model:n,selectedModel:r,defaultMaxOutputTokens:i,defaultContextWindowMaxInputTokens:a,maxTokens:o,onMaxTokensChange:s,contextWindowMaxInputTokens:c,onContextWindowChange:l,effort:u,onEffortChange:p,speed:m,onSpeedChange:h,verbosity:_,onVerbosityChange:v,temperatureEnabled:y,onTemperatureEnabledChange:b,temperature:x,onTemperatureChange:S,topPEnabled:C,onTopPEnabledChange:w,topP:T,onTopPChange:E,thinkingEnabled:D,onThinkingEnabledChange:O,thinkingStreamThinking:k,onThinkingStreamThinkingChange:A,thinkingLevel:j,onThinkingLevelChange:M}){let ee=N(),P=r?.maxOutputTokens??Ee,F=r?.contextWindowTokens??2e5,I=Math.min(i??Ee,P),L=Math.min(a??2e5,F);return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!t&&ee&&(0,K.jsx)(`p`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:`Fields left at their default are saved with the values shown and won’t change if the assistant defaults change later.`}),e.maxTokens&&(0,K.jsx)(De,{label:`Max Output Tokens`,value:o,onChange:s,defaultValue:I,max:P,disabled:t}),e.contextWindow&&(0,K.jsx)(De,{label:`Context Window`,value:c,onChange:l,defaultValue:L,max:F,disabled:t||!r}),e.effort&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Effort`}),(0,K.jsx)(d,{items:q.map(e=>({value:e,label:e===`inherit`?`default`:e,disabled:t})),value:u,onChange:e=>p(e),ariaLabel:`Effort`})]}),e.speed&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Speed`}),(0,K.jsx)(d,{items:Ce.map(e=>({value:e,label:e,disabled:t})),value:m,onChange:e=>h(e),ariaLabel:`Speed`})]}),e.verbosity&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Verbosity`}),(0,K.jsx)(d,{items:we.map(e=>({value:e,label:e,disabled:t})),value:_,onChange:e=>v(e),ariaLabel:`Verbosity`})]}),e.temperature&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(g,{checked:y,onChange:e=>b(e),label:`Temperature`,disabled:t}),y&&(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(f,{value:x,onValueChange:e=>S(typeof e==`number`?e:e[0]),min:0,max:2,step:.01,disabled:t,showValue:!0,formatValue:e=>typeof e==`number`?e.toFixed(2):String(e)})})})]}),e.topP&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(g,{checked:C,onChange:e=>w(e),label:`Top P`,disabled:t}),C&&(0,K.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,K.jsx)(`div`,{className:`flex-1`,children:(0,K.jsx)(f,{value:T,onValueChange:e=>E(typeof e==`number`?e:e[0]),min:0,max:1,step:.01,disabled:t,showValue:!0,formatValue:e=>typeof e==`number`?e.toFixed(2):String(e)})})})]}),e.thinking&&(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(g,{checked:D,onChange:e=>{O(e),e||A(!1)},label:`Enable extended thinking`,disabled:t}),D&&(0,K.jsx)(`div`,{className:`pl-4`,children:(0,K.jsx)(g,{checked:k,onChange:e=>A(e),label:`Stream thinking tokens`,disabled:t})})]}),e.thinkingLevel&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:[`Thinking level`,` `,(0,K.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(default = inherit)`})]}),(0,K.jsx)(d,{items:[`default`,...ve(n)].map(e=>({value:e,label:`${e}`,disabled:t})),value:j,onChange:M,ariaLabel:`Thinking level`})]})]})}var Y=[`anthropic`,`openai`,`gemini`,`ollama`,`fireworks`,`together`,`openrouter`,`vercel-ai-gateway`,`minimax`,`atlascloud`,`litellm`,`baseten`,`poolside`,`openai-compatible`];function X(e){return e===`ollama`?`none`:`api_key`}function Oe(e){let t=e.split(`/`);return t.length<3||t[0]!==`credential`?null:{service:t[1],field:t.slice(2).join(`/`)}}function ke(e){switch(e){case 409:return`A provider with these settings already exists.`;case 404:return`Provider not found. It may have been removed.`;case 400:return`Invalid configuration. Check the provider settings.`;default:return`Failed to save provider. Please try again.`}}function Ae(e,t){if(e!==400)return;let n=t?.error?.message;return typeof n==`string`&&n.length>0?n:void 0}function je(e){return e.label?e.label:e.auth.type===`oauth_subscription`?O.chatgpt:O[e.provider]??e.provider}var Me=new Set([`ollama`]);function Ne(e,t){return!Me.has(e)||t}function Pe(e){return A.filter(t=>Ne(t,e))}function Fe(e){return Y.filter(t=>Ne(t,e))}function Ie(e){return Object.keys(D).filter(t=>Ne(t,e))}function Le(){return Pe(z())}function Re(){return Fe(z())}function ze(){return Ie(z())}function Be(e,t){let n=[...new Set(e.map(e=>e.provider))].filter(e=>Ne(e,t)),r=[];return n.includes(`vellum`)&&r.push(x),r.push(...Y.filter(e=>n.includes(e)),...n.filter(e=>e!==`vellum`&&!Y.includes(e))),r}function Ve(e,t){let n=new Set(e.map(e=>e.provider));return Fe(t).filter(e=>e!==`openai-compatible`&&!n.has(e))}var He=`${S}::`;function Z(e){return`${He}${e}`}function Q(e){return e.startsWith(He)?e.slice(He.length):null}function Ue(e,t,n){let r=[];for(let i of e){if(i===`vellum`){r.push({value:i,label:n(i),meta:`Managed`});continue}if(i!==`openai-compatible`){r.push({value:i,label:n(i)});continue}for(let e of t)e.provider===`openai-compatible`&&r.push({value:Z(e.name),label:e.label&&e.label.trim()!==``?e.label:e.name,meta:`Custom`})}return r}var We=new Set([`gpt-5.6-sol`,`gpt-5.6-terra`,`gpt-5.6-luna`,`gpt-5.5`,`gpt-5.4`,`gpt-5.4-mini`,`gpt-5.3-codex`]);function Ge(e){return(e??[]).map(e=>({id:e.id,displayName:e.displayName??e.id}))}function Ke(e,t,n){return!e||T(e).length===0?!1:(t?n.find(e=>e.name===t):void 0)?.auth.type===`oauth_subscription`?!0:!t&&n.length>0&&n.every(e=>e.auth.type===`oauth_subscription`)}var qe=`No provider connections. Open Providers to add one.`,Je={"no-provider":{placeholder:`Select a provider first`,hint:null},"configure-connection":{placeholder:`Configure models on connection`,hint:`No models available. Configure models on the provider connection first.`},"unknown-to-catalog":{placeholder:`No models available`,hint:`No models are available for this provider in this app version. Update the app, or enter a custom model ID.`}},Ye=`__custom-model-id__`;function Xe({text:e}){return(0,K.jsx)(`span`,{className:`text-body-small-default text-[var(--content-tertiary)]`,children:e})}function Ze({provider:e,model:t,providerConnection:n,onProviderChange:i,onModelChange:a,onConnectionChange:o,connections:s,isReadOnly:l,availableConnectionsForProvider:u,connectionNotFound:d,hideProviderField:f=!1,providerError:p=null}){let m=e.length>0&&t.length===0,[g,_]=(0,V.useState)(!1),v=Ke(e,n,u),b=e!==``&&!v;(0,V.useEffect)(()=>{b||_(!1)},[e,b]);function x(e){if(e===Ye){_(!0),a(``);return}a(e)}let S=ze(),C=z(),w=(0,V.useMemo)(()=>{let t=Be(s??[],C);return e&&!t.includes(e)?[...t,e]:t},[s,e,C]),E=s===void 0?S:w,D=E.length===0&&!l,k=(0,V.useMemo)(()=>{if(!e)return[];let t=T(e);if(t.length>0)return Ke(e,n,u)?t.filter(e=>We.has(e.id)):t;if(n){let e=u.find(e=>e.name===n);return e?Ge(e.models):[]}let r=new Set,i=[];for(let e of u)for(let t of e.models??[])r.has(t.id)||(r.add(t.id),i.push({id:t.id,displayName:t.displayName??t.id}));return i},[e,n,u]),A=(0,V.useMemo)(()=>{if(!t||k.some(e=>e.id===t))return k;let n=T(e).find(e=>e.id===t),r=u.flatMap(e=>e.models??[]).find(e=>e.id===t),i=n?.displayName??r?.displayName??t;return[...k,{id:t,displayName:i}]},[t,k,e,u]),j=e?k.length===0?e===`openai-compatible`?`configure-connection`:`unknown-to-catalog`:null:`no-provider`,M=j?Je[j]:null;return(0,V.useEffect)(()=>{if(!e||g)return;let n=T(e);n.length>0&&!n.some(e=>e.id===t)||t&&k.length>0&&!k.some(e=>e.id===t)&&a(``)},[t,k,a,e,g]),(0,K.jsxs)(K.Fragment,{children:[!f&&(0,K.jsx)(y,{id:`profile-editor-provider`,label:`Provider`,errorText:p&&D?qe:p,helperText:D&&!p?qe:void 0,value:e===`openai-compatible`&&n?Z(n):e,onChange:e=>{let t=Q(e);if(t){i(`openai-compatible`),o(t);return}i(e)},disabled:l,placeholder:`Select a provider…`,options:[...Ue(E,s??[],e=>O[e]??e).map(({value:e,label:t,meta:n})=>({value:e,label:t,suffix:n?(0,K.jsx)(Xe,{text:n}):void 0})),...d&&e===`openai-compatible`&&n?[{value:Z(n),label:`${n} (not found)`}]:[],...e===`openai-compatible`&&!n?[{value:`openai-compatible`,label:O[`openai-compatible`]??`openai-compatible`}]:[]]}),d&&!l&&(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:`This profile referenced a credential that no longer exists. Saving resets it to use the provider’s available key.`}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Model`}),g?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(h,{value:t,onChange:e=>a(e.target.value),disabled:l,placeholder:`provider/model-id`,"aria-label":`Custom model ID`,fullWidth:!0,autoFocus:!0}),(0,K.jsx)(r,{variant:`link`,size:`compact`,disabled:l,onClick:()=>_(!1),children:`Choose from list`})]}):(0,K.jsx)(y,{value:t,onChange:x,disabled:l||!e,"aria-label":`Model`,placeholder:M?.placeholder??`Select a model`,options:[...A.map(e=>({value:e.id,label:e.displayName})),...b?[{value:Ye,label:`Enter a custom model ID…`}]:[]]}),g?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Enter the exact model identifier your provider expects. It's sent to the connection as-is.`}):m&&!l?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:M?.hint??`Select a model.`}):null]})]})}function Qe(e,t,n){return[`credentialPresence`,e,t,n]}function $e({assistantId:e,credentialKind:n,credentialName:r,enabled:i=!0}){let o=B(),s=a({queryKey:Qe(e??``,n,r),queryFn:async()=>{let{data:t}=await ae({path:{assistant_id:e},body:{type:n,name:r},throwOnError:!0});return t.found},enabled:!!e&&i&&o,retry:t,staleTime:3e4});return{hasStoredCredential:s.data??!1,isLoading:s.isLoading}}function et({assistantId:e,onConnected:t}){let[n,i]=(0,V.useState)(`idle`),[a,o]=(0,V.useState)(``),[s,l]=(0,V.useState)(null);async function u(){i(`starting`),l(null);let t=window.open(`about:blank`,`_blank`);try{let{data:{authorize_url:n}}=await te({path:{assistant_id:e},throwOnError:!0});t?(t.opener=null,t.location.href=n):window.open(n,`_blank`,`noopener`),i(`paste_url`)}catch{t?.close(),i(`failed`),l(`Failed to start ChatGPT sign-in. Please try again.`)}}async function d(){l(null);let n=a.trim();if(!n){l(`Please paste the URL from the error page.`);return}let r;try{r=new URL(n)}catch{l(`Invalid URL. Please paste the full URL from the address bar.`);return}let o=r.searchParams.get(`code`),s=r.searchParams.get(`state`);if(!o){l(`The URL is missing the authorization code. Make sure you copied the full URL.`);return}if(!s){l(`The URL is missing the state parameter. Make sure you copied the full URL.`);return}i(`exchanging`);try{await ne({path:{assistant_id:e},body:{code:o,state:s},throwOnError:!0}),i(`completed`);let{data:n}=await R({path:{assistant_id:e},query:{provider:`openai`},throwOnError:!0});t(n.connections.find(e=>e.name===`chatgpt-subscription`||e.name===`openai-chatgpt`)||{name:`chatgpt-subscription`,provider:`openai`,auth:{type:`oauth_subscription`,credential:`credential/openai/chatgpt-subscription`},label:`ChatGPT Subscription`,createdAt:Date.now(),updatedAt:Date.now(),baseUrl:null,models:null,isManaged:!1})}catch{i(`failed`),l(`Failed to complete sign-in. Please try again.`)}}function f(){i(`idle`),o(``),l(null)}return(0,K.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-[var(--border-base)] p-4`,children:[(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Connect your ChatGPT subscription to use OpenAI models without an API key.`}),n===`idle`||n===`paste_url`?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(c,{variant:`body-small-default`,as:`p`,className:n===`paste_url`?`text-[var(--content-tertiary)] line-through`:`text-[var(--content-secondary)]`,children:[`1. Click “Sign in with ChatGPT”`,n===`idle`?` below`:null,` to open a popup`]}),(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-secondary)]`,children:`2. Sign in, then you'll land on an error page — that's expected`}),(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-secondary)]`,children:`3. Copy the full URL from that page's address bar and paste it below`})]}),n===`idle`?(0,K.jsx)(r,{variant:`outlined`,size:`compact`,onClick:()=>void u(),children:`Sign in with ChatGPT`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(h,{value:a,onChange:e=>{o(e.target.value),l(null)},placeholder:`Paste callback URL here...`,fullWidth:!0}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)(r,{variant:`primary`,size:`compact`,disabled:!a.trim(),onClick:()=>void d(),children:`Complete Sign In`})})]})]}):null,n===`starting`?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(p,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}),(0,K.jsx)(c,{variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Starting sign-in...`})]}):null,n===`exchanging`?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(p,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}),(0,K.jsx)(c,{variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Completing sign-in...`})]}):null,n===`completed`?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--system-positive-strong)]`,children:`ChatGPT subscription connected successfully.`}):null,s?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:s}):null,n===`failed`?(0,K.jsx)(r,{variant:`outlined`,size:`compact`,onClick:f,children:`Try Again`}):null]})}var tt=new Set(Object.entries(O).flatMap(([e,t])=>[e.toLowerCase(),t.toLowerCase()])),nt={reserved:`That name belongs to a built-in provider. Pick another.`,duplicate:`A custom provider with this name already exists.`};function rt(e,t,n){let r=e.trim().toLowerCase();return r?tt.has(r)?`reserved`:(t??[]).some(e=>e.provider===`openai-compatible`&&e.name!==n&&(e.label?.trim()||e.name).toLowerCase()===r)?`duplicate`:null:null}function it(e){return e.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).join(`-`)}function at(e){return it(e)}function ot(e,t){let n=new Set(t.map(e=>e.toLowerCase()));if(!n.has(e.toLowerCase()))return e;let r=2,i=`${e}-${r}`;for(;n.has(i.toLowerCase());)r+=1,i=`${e}-${r}`;return i}function st(e,t){return{name:O[e]??e,key:ot(`${at(e)}-personal`,t)}}function ct(e,t){return{name:e,key:ot(at(e),t)}}function lt({apiKeyValue:e,onApiKeyChange:t,credential:n,onCredentialChange:i,isLoadingCredential:a,apiKeyPlaceholder:o,provider:s,providerCredentials:l,showAdvancedSection:d,onError:f}){let[m,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(!1),[b,x]=(0,V.useState)(``);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`API Key`}),a?(0,K.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,K.jsx)(p,{className:`h-4 w-4 animate-spin text-[var(--content-tertiary)]`}),(0,K.jsx)(c,{variant:`body-small-default`,className:`text-[var(--content-tertiary)]`,children:`Loading…`})]}):(0,K.jsx)(h,{type:`password`,value:e,onChange:e=>{t(e.target.value),f(null)},placeholder:o,fullWidth:!0})]}),d&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":m,onClick:()=>g(e=>!e),className:`flex items-center gap-1 text-body-small-default text-[var(--content-secondary)] w-full text-left`,children:[(0,K.jsx)(u,{className:`h-4 w-4 transition-transform ${m?`rotate-90`:``}`}),(0,K.jsx)(`span`,{children:`Advanced`}),(0,K.jsx)(`span`,{className:`text-[var(--content-tertiary)] ml-1`,children:`· Credential reference`})]}),m&&(0,K.jsxs)(`div`,{className:`mt-2 space-y-3`,children:[(()=>{let e=l.map(e=>{let t=`credential/${e.service}/${e.field}`;return{label:t,value:t}}),t=e.some(e=>e.value===n),r=n&&!t?[{label:n,value:n},...e]:e;return r.length===0?null:(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Credential Reference`}),(0,K.jsx)(y,{"aria-label":`Credential reference`,value:n,onChange:e=>{i(e)},options:r})]})})(),_&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`New Credential Name`}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(h,{value:b,onChange:e=>x(e.target.value),placeholder:`e.g. team-key`,fullWidth:!0}),(0,K.jsx)(r,{variant:`primary`,size:`compact`,disabled:!b.trim(),onClick:()=>{let e=b.trim();e&&(i(`credential/${s}/${e}`),v(!1),x(``))},children:`Use`})]})]}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsx)(r,{variant:`ghost`,size:`compact`,onClick:()=>{_?(v(!1),x(``)):v(!0)},children:_?`Cancel`:`+ New Credential`})})]})]})]})}var ut=`•`.repeat(8);function dt(e,t){return t?ut:e}function ft(e){let t=[];for(let n of e)if(n.type===`api_key`)t.push({service:n.name,field:`api_key`});else if(n.type===`credential`){let e=n.name.lastIndexOf(`:`);if(e>=0){let r=n.name.slice(0,e),i=n.name.slice(e+1);r&&i&&t.push({service:r,field:i})}}return t}function pt({assistantId:e,enabled:n=!0}){let r=B(),i=a({...oe({path:{assistant_id:e}}),enabled:!!e&&n&&r,select:e=>ft(e.secrets),retry:t,staleTime:3e4});return{credentials:i.data??[],isLoading:i.isLoading}}function mt({assistantId:e,existingNames:t,connections:n,defaultProviderType:a,hideProviderSelect:o=!1,onCreated:s,onCancel:l,variant:d=`modal`}){let f=Re(),p=a&&f.includes(a)?a:f[0]??`anthropic`,m=st(p,t),[g,b]=(0,V.useState)(p===`openai-compatible`?``:m.name),[x,S]=(0,V.useState)(m.key),[C,w]=(0,V.useState)(p),T=C===`chatgpt`,E=T?`openai`:C,D=T?`oauth_subscription`:X(E),[k,A]=(0,V.useState)(()=>p===`ollama`?``:p===`openai-compatible`?`credential/${m.key}/api_key`:`credential/${p}/api_key`),[j,M]=(0,V.useState)(``),[N,ee]=(0,V.useState)(``),[P,F]=(0,V.useState)(!1),[I,L]=(0,V.useState)(null),[te,ne]=(0,V.useState)(!1),R=E===`openai-compatible`,ae=(0,V.useMemo)(()=>{let e=!T&&!f.includes(E)?[...f,E]:[...f],t=e.indexOf(`openai`);return t>=0&&e.splice(t+1,0,`chatgpt`),e},[T,E,f]),z=(0,V.useRef)(!1);function B(e){z.current=!0,b(e)}let[oe,se]=(0,V.useState)(``),[ce,ue]=(0,V.useState)(!1),H=i(),U=(0,V.useMemo)(()=>Oe(k),[k]),de=D===`api_key`&&U!==null,{hasStoredCredential:fe,isLoading:pe}=$e({assistantId:e,credentialKind:`credential`,credentialName:U?`${U.service}:${U.field}`:``,enabled:de}),{credentials:me}=pt({assistantId:e,enabled:!0}),W=R?rt(g,n):null,he=x.trim().length>0&&(!R||g.trim().length>0)&&W===null;async function ge(){if(he){F(!0),L(null);try{let t;if(D===`api_key`){let n=k.trim()||`credential/${R?x:E}/api_key`,r=oe.trim();if(r){ue(!0);try{let t=Oe(n);await ie({path:{assistant_id:e},body:t?{type:`credential`,name:`${t.service}:${t.field}`,value:r}:{type:`api_key`,name:E,value:r},throwOnError:!0});let i=Qe(e,`credential`,t?`${t.service}:${t.field}`:``);H.setQueryData(i,!0),H.invalidateQueries({queryKey:le({path:{assistant_id:e}})})}catch{L(`Failed to save API key. Please try again.`);return}finally{ue(!1)}t={type:`api_key`,credential:n}}else if(fe)t={type:`api_key`,credential:n};else if(R)t={type:`none`};else{L(`Enter an API key or select an existing credential.`);return}}else if(D===`oauth_subscription`){L(`Use the "Sign in with ChatGPT" button to connect your subscription.`);return}else t={type:`none`};let n=g.trim()||null,r={name:x.trim(),provider:E,auth:t,...n!==null&&{label:n},...R&&{base_url:j.trim()||null,models:N.trim()?N.split(`,`).map(e=>({id:e.trim()})).filter(e=>e.id):null}},{data:i,error:a,response:o}=await re({path:{assistant_id:e},body:r});if(!o?.ok){L(Ae(o?.status,a)??ke(o?.status));return}if(!i){L(`Server returned an empty response. Please try again.`);return}v.success(`Provider connected`),s(i)}catch{L(`Failed to save provider. Please try again.`)}finally{F(!1)}}}let _e=me.filter(e=>e.service===E),ve=_e.length>0,ye=dt(`Enter your API key`,fe),G=te,be=(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":G,onClick:()=>ne(e=>!e),className:`flex items-center gap-1 text-body-small-default text-[var(--content-secondary)] w-full text-left`,children:[(0,K.jsx)(u,{className:`h-4 w-4 transition-transform ${G?`rotate-90`:``}`}),(0,K.jsx)(`span`,{children:`Advanced`})]}),G&&(0,K.jsx)(`div`,{className:`mt-2 space-y-4`,children:(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:[`Display Name`,` `,(0,K.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(optional)`})]}),(0,K.jsx)(h,{value:g,onChange:e=>B(e.target.value),placeholder:`e.g. My Anthropic Key`,fullWidth:!0})]})})]}),xe=(0,K.jsxs)(`div`,{className:`space-y-4`,children:[!o&&(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,K.jsx)(y,{"aria-label":`Provider`,value:C,onChange:e=>{if(w(e),L(null),e===`chatgpt`)return;let{name:n,key:r}=st(e,t);z.current||b(e===`openai-compatible`?``:n),S(r),A(e===`ollama`?``:e===`openai-compatible`?`credential/${r}/api_key`:`credential/${e}/api_key`)},options:[...ae.filter(e=>e!==`openai-compatible`).map(e=>({value:e,label:O[e]})),...ae.includes(`openai-compatible`)?[{value:`openai-compatible`,label:`Custom provider`}]:[]]}),R?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Custom providers connect to any endpoint that serves the OpenAI-compatible API — xAI, Groq, LM Studio, vLLM, and similar.`}):null]}),R&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Name`}),(0,K.jsx)(h,{value:g,onChange:e=>B(e.target.value),placeholder:`xAI`,fullWidth:!0}),W?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:nt[W]}):null]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Base URL`}),(0,K.jsx)(h,{value:j,onChange:e=>M(e.target.value),placeholder:`https://api.x.ai/v1`,fullWidth:!0})]}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Models`}),(0,K.jsx)(h,{value:N,onChange:e=>ee(e.target.value),placeholder:`model-1, model-2`,fullWidth:!0}),(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Comma-separated model identifiers exposed by your endpoint.`})]})]}),D===`api_key`&&(0,K.jsx)(lt,{apiKeyValue:oe,onApiKeyChange:se,credential:k,onCredentialChange:A,isLoadingCredential:pe,apiKeyPlaceholder:ye,provider:E,providerCredentials:_e,showAdvancedSection:ve,onError:L}),R&&D===`api_key`?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`Leave the key empty for local endpoints — they connect keyless.`}):null,D===`oauth_subscription`&&(0,K.jsx)(et,{assistantId:e,onConnected:s}),!T&&!R&&be,I&&(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:I})]}),Se=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(r,{variant:`ghost`,size:`compact`,onClick:l,children:`Cancel`}),!T&&(0,K.jsx)(r,{variant:`primary`,size:`compact`,disabled:!he||P||ce,onClick:()=>void ge(),children:P?`Saving…`:R&&g.trim()?`Add ${g.trim()}`:`Add`})]});return d===`inline`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[xe,(0,K.jsx)(`div`,{className:`flex justify-end gap-2`,children:Se})]}):(0,K.jsxs)(_.Content,{size:`md`,children:[(0,K.jsxs)(_.Header,{children:[(0,K.jsx)(_.Title,{children:`Add Provider`}),(0,K.jsx)(_.Description,{children:`Choose a provider and paste its API key.`})]}),(0,K.jsx)(_.Body,{children:xe}),(0,K.jsx)(_.Footer,{children:Se})]})}var ht=`__create_new_provider__`;function gt(e){return X(e)===`api_key`?`Add API key`:`Set up`}function _t({editor:e,assistantId:t,connections:n,variant:r}){let i=z(),a=e.effectiveMode===`create`,o=r===`panel`,[s,l]=(0,V.useState)(!1),d=s||!!e.keyError&&e.getDirty(),f=(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{className:`block text-body-small-default text-[var(--content-tertiary)]`,children:a?`Name`:`Display Name`}),(0,K.jsx)(h,{type:`text`,value:e.label,onChange:t=>e.handleLabelChange(t.target.value),placeholder:`e.g. Fast & Cheap`,disabled:e.isReadOnly,fullWidth:!0})]}),p=(0,K.jsx)(m,{label:(0,K.jsxs)(K.Fragment,{children:[`Description`,` `,(0,K.jsx)(`span`,{className:`text-[var(--content-disabled)]`,children:`(optional)`})]}),value:e.description,onChange:t=>e.setDescription(t.target.value),placeholder:`Describe when to use this profile`,disabled:e.isReadOnly,rows:2,fullWidth:!0,className:`resize-none`}),_=(0,K.jsx)(h,{label:`Key`,type:`text`,value:e.key,onChange:t=>e.handleKeyChange(t.target.value),placeholder:`e.g. fast-cheap`,disabled:e.isReadOnly||e.effectiveMode===`edit`,errorText:e.isReadOnly?void 0:e.keyError,fullWidth:!0}),v=!o&&(!e.isReadOnly||e.status!==`active`)?(0,K.jsx)(g,{checked:e.status===`active`,onChange:t=>e.setStatus(t?`active`:`disabled`),label:`Active`,className:`touch-mobile:mt-2 touch-mobile:[&_button]:h-7 touch-mobile:[&_button]:w-10 touch-mobile:[&_button>span]:h-6 touch-mobile:[&_button>span]:w-6`}):null,b=(0,K.jsx)(J,{visibility:e.visibility,isReadOnly:e.isReadOnly,model:e.model,selectedModel:e.selectedModel,defaultMaxOutputTokens:e.defaultMaxOutputTokens,defaultContextWindowMaxInputTokens:e.defaultContextWindowMaxInputTokens,maxTokens:e.maxTokens,onMaxTokensChange:e.setMaxTokens,contextWindowMaxInputTokens:e.contextWindowMaxInputTokens,onContextWindowChange:e.setContextWindowMaxInputTokens,effort:e.effort,onEffortChange:e.setEffort,speed:e.speed,onSpeedChange:e.setSpeed,verbosity:e.verbosity,onVerbosityChange:e.setVerbosity,temperatureEnabled:e.temperatureEnabled,onTemperatureEnabledChange:e.setTemperatureEnabled,temperature:e.temperature,onTemperatureChange:e.setTemperature,topPEnabled:e.topPEnabled,onTopPEnabledChange:e.setTopPEnabled,topP:e.topP,onTopPChange:e.setTopP,thinkingEnabled:e.thinkingEnabled,onThinkingEnabledChange:e.setThinkingEnabled,thinkingStreamThinking:e.thinkingStreamThinking,onThinkingStreamThinkingChange:e.setThinkingStreamThinking,thinkingLevel:e.thinkingLevel,onThinkingLevelChange:e.setThinkingLevel}),x=e.saveError?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-(--system-negative-strong)`,children:e.saveError}):null,C=(0,V.useMemo)(()=>Ve(e.effectiveConnections,i),[e.effectiveConnections,i]),w=(0,V.useMemo)(()=>{let t=Ue(Be(e.effectiveConnections,i),e.effectiveConnections,e=>O[e]??e).map(({value:e,label:t,meta:n})=>({value:e,label:t,suffix:n?(0,K.jsx)(Xe,{text:n}):void 0}));for(let e of C)t.push({value:e,label:O[e]??e,suffix:(0,K.jsx)(Xe,{text:gt(e)})});return t.push({value:ht,label:`+ Create new provider`}),t},[i,e.effectiveConnections,C]),T=(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsx)(`label`,{id:`profile-editor-provider-label`,className:`block text-body-small-default text-[var(--content-tertiary)]`,children:`Provider`}),(0,K.jsx)(y,{value:e.creatingProvider?e.pendingCreateProvider??ht:e.provider===`openai-compatible`&&e.providerConnection?Z(e.providerConnection):e.provider,onChange:t=>{if(t===ht){e.setCreatingProvider(!0),e.setPendingCreateProvider(null),e.setNewProviderNote(!1);return}if(!t)return;let n=Q(t);if(n){e.setCreatingProvider(!1),e.setPendingCreateProvider(null),e.provider===`openai-compatible`?e.setModel(``):e.handleProviderChange(S),e.setProviderConnection(n);return}let r=t;if(C.includes(r)){e.setCreatingProvider(!0),e.setPendingCreateProvider(r),e.setNewProviderNote(!1);return}e.setCreatingProvider(!1),e.setPendingCreateProvider(null),e.handleProviderChange(r)},placeholder:`Select a provider…`,"aria-labelledby":`profile-editor-provider-label`,options:w}),e.newProviderNote?(0,K.jsx)(c,{variant:`body-small-default`,as:`p`,className:`text-[var(--content-tertiary)]`,children:`New provider connection will show up in the Providers section.`}):null]}),e.creatingProvider?(0,K.jsx)(mt,{variant:`inline`,assistantId:t,existingNames:e.effectiveConnections.map(e=>e.name),connections:e.effectiveConnections,defaultProviderType:(e.pendingCreateProvider??e.provider)||void 0,hideProviderSelect:e.pendingCreateProvider!==null,onCreated:e.handleProviderCreated,onCancel:()=>{e.setCreatingProvider(!1),e.setPendingCreateProvider(null)}},e.pendingCreateProvider??`any`):(0,K.jsx)(Ze,{provider:e.provider,model:e.model,providerConnection:e.providerConnection,onProviderChange:e.handleProviderChange,onModelChange:e.handleModelChange,onConnectionChange:e.handleConnectionChange,connections:e.effectiveConnections,isReadOnly:e.isReadOnly,availableConnectionsForProvider:e.availableConnectionsForProvider,connectionNotFound:e.connectionNotFound,hideProviderField:!0})]});if(a){let t=e.model!==``;return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[f,T,p,v,o?t&&(0,K.jsxs)(`div`,{className:`space-y-4`,children:[_,b]}):t&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":d,onClick:()=>l(e=>!e),className:`flex items-center gap-1 text-body-small-default text-[var(--content-secondary)] w-full text-left`,children:[(0,K.jsx)(u,{className:`h-4 w-4 transition-transform ${d?`rotate-90`:``}`}),(0,K.jsx)(`span`,{children:`Advanced`})]}),d?(0,K.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[_,b]}):null]}),x]})}return(0,K.jsxs)(`div`,{className:`space-y-4`,children:[f,p,_,v,(0,K.jsx)(Ze,{provider:e.provider,model:e.model,providerConnection:e.providerConnection,onProviderChange:e.handleProviderChange,onModelChange:e.handleModelChange,onConnectionChange:e.handleConnectionChange,connections:n,isReadOnly:e.isReadOnly,availableConnectionsForProvider:e.availableConnectionsForProvider,connectionNotFound:e.connectionNotFound,providerError:e.providerError}),b,x]})}function vt(e,t,n){if(e){let n=T(e).find(e=>e.id===t);if(n)return n.displayName}for(let e of n??[]){let n=(e.models??[]).find(e=>e.id===t);if(n)return n.displayName??n.id}let r=t.lastIndexOf(`/`);return r>=0?t.slice(r+1):t}function yt(e,t,n){let r=(0,V.useRef)(!1),i=(0,V.useRef)(!1);return{handleLabelChange:(0,V.useCallback)(a=>{i.current=!0,t(a),e===`create`&&!r.current&&n(it(a))},[e,t,n]),handleKeyChange:(0,V.useCallback)(e=>{r.current=!0,i.current=!0,n(e)},[n]),resetDirty:(0,V.useCallback)(()=>{r.current=!1,i.current=!1},[]),getDirty:(0,V.useCallback)(()=>i.current,[])}}var bt=`0.10.12`;async function xt(e,t){await I(t);let n=P.getState().assistantId;return e!=null&&n!==e?!1:F(bt)}function St(e,t){return e===t?!0:e===`vellum`&&C.has(t)}function Ct({mode:e,profileName:t,initialValues:n,existingNames:r,connections:o,assistantId:s,onSave:c}){let[l,u]=(0,V.useState)(e),d=n?.invariant===!0&&l!==`create`,f=l===`view`||d,p=n?.status??`active`,[m,h]=(0,V.useState)(n?.label??``),[g,_]=(0,V.useState)(n?.description??``),[v,y]=(0,V.useState)(e===`create`?``:t??``),[b,S]=(0,V.useState)(n?.provider&&n.provider!==`chatgpt`?n.provider:``),[C,D]=(0,V.useState)(n?.model??``),[O,k]=(0,V.useState)(n?.provider_connection??``),[A,j]=(0,V.useState)(n?.status??`active`),[M,N]=(0,V.useState)([]),[ee,P]=(0,V.useState)(!1),[F,I]=(0,V.useState)(null),[te,ne]=(0,V.useState)(n?.maxTokens??null),[re,R]=(0,V.useState)(n?.contextWindow?.maxInputTokens??null),[ie,ae]=(0,V.useState)(n?.effort??`inherit`),[z,B]=(0,V.useState)(n?.speed??`standard`),[oe,le]=(0,V.useState)(n?.verbosity??`medium`),[ue,H]=(0,V.useState)(typeof n?.temperature==`number`),[U,de]=(0,V.useState)(typeof n?.temperature==`number`?n.temperature:.7),[fe,pe]=(0,V.useState)(typeof n?.topP==`number`),[me,W]=(0,V.useState)(typeof n?.topP==`number`?n.topP:.95),he=f&&A!==p,[ge,ve]=(0,V.useState)(n?.thinking?.enabled??!1),[ye,G]=(0,V.useState)(n?.thinking?.streamThinking??!1),[be,xe]=(0,V.useState)(_e(n?.thinking?.level)?n.thinking.level:Te),K=(0,V.useMemo)(()=>b===`vellum`?E(C):null,[b,C]),q=K?.model??C,Ce=(0,V.useMemo)(()=>b?T(b).find(e=>e.id===q)??null:null,[b,q]),{data:we}=a({...ce({path:{assistant_id:s}}),staleTime:3e4}),Ee=we?.llm?.default?.maxTokens,De=we?.llm?.default?.contextWindow?.maxInputTokens,J=(0,V.useMemo)(()=>Se(b===`vellum`?K?.provider??w(C)??n?.provider??``:b,q),[b,C,q,K,n?.provider]),Y=(0,V.useMemo)(()=>{let e=o??[];if(M.length===0)return e;let t=new Set(e.map(e=>e.name));return[...e,...M.filter(e=>!t.has(e.name))]},[o,M]),X=(0,V.useMemo)(()=>b?Y.filter(e=>St(e.provider,b)):[],[b,Y]),Oe=O!==``&&!X.some(e=>e.name===O),{handleLabelChange:ke,handleKeyChange:Ae,resetDirty:je,getDirty:Me}=yt(l,h,y),Ne=i(),[Pe,Fe]=(0,V.useState)(!1),[Ie,Le]=(0,V.useState)(null),[Re,ze]=(0,V.useState)(!1);(0,V.useEffect)(()=>{n?.provider_connection===`vellum`&&b===(n?.provider??``)&&o?.find(e=>e.name===n.provider_connection)?.provider===`vellum`&&S(x)},[o,b,n]),(0,V.useEffect)(()=>{je(),Fe(!1),Le(null),ze(!1),N([])},[t,e,je]);function Be(e){if(e===b)return;S(e),D(``);let t=Y.filter(t=>St(t.provider,e));k(t.length===1?t[0].name:``),ne(null),R(null),ae(`inherit`),B(`standard`),le(`medium`),H(!1),de(.7),pe(!1),W(.95),ve(!1),G(!1),xe(Te)}function Ve(e){if(k(e),b&&T(b).length===0&&C)if(e===``)new Set(X.flatMap(e=>(e.models??[]).map(e=>e.id))).has(C)||D(``);else{let t=X.find(t=>t.name===e);new Set((t?.models??[]).map(e=>e.id)).has(C)||D(``)}}function He(e){if(e!==C&&(D(e),ne(null),R(null),l===`create`&&e&&!Me())){let{name:t,key:n}=ct(vt(b||void 0,e,X),r);h(t),y(n)}}function Z(e){let t=e.provider;t!==`vellum`&&(N(t=>t.some(t=>t.name===e.name)?t:[...t,e]),S(t),k(e.name),D(``),Fe(!1),Le(null),ze(!0),Ne.invalidateQueries({queryKey:se({path:{assistant_id:s}})}))}let Q=v.trim(),Ue=Q.length===0,We=/\s/.test(v),Ge=l===`create`?r.includes(Q):r.filter(e=>e!==t).includes(Q),Ke=b.length===0,qe=b.length>0&&C.length===0,Je=Ue||We||Ge||Ke||qe,Ye=Ue?`Key is required`:We?`Key cannot contain whitespace`:Ge?`A profile with this key already exists`:null,Xe=!f&&(l===`edit`||Me())&&Ke?`Select a provider`:null;async function Ze(){if(!(Je&&!f)){if(f){if(!he)return;P(!0),I(null);try{await c(Q,{status:`active`},{mode:`merge`})}catch(e){I(L(e)??`Failed to save profile. Please try again.`)}finally{P(!1)}return}P(!0),I(null);try{let e={},t=O===``&&X.length===1?X[0].name:O,r=Oe?``:t,i=b===`vellum`&&await xt(s),a=b===`vellum`?i?x:K?.provider??w(C)??n?.provider??``:b,o=q,u=i?``:r;l===`edit`?(e.label=m.trim()||null,e.description=g.trim()||null,e.provider=a||null,e.model=o||null,e.provider_connection=u||null):(m.trim()&&(e.label=m.trim()),g.trim()&&(e.description=g.trim()),a&&(e.provider=a),o&&(e.model=o),u&&(e.provider_connection=u)),J.maxTokens&&te!==null&&(e.maxTokens=te),J.contextWindow&&re!==null&&(e.contextWindow={maxInputTokens:re}),J.effort&&ie!==`inherit`&&(e.effort=ie),J.speed&&z!==`standard`&&(e.speed=z),J.verbosity&&(e.verbosity=oe),J.temperature&&(ue?e.temperature=U:l===`edit`&&(e.temperature=null)),J.topP&&(fe?e.topP=me:l===`edit`&&(e.topP=null)),J.thinking&&(e.thinking={enabled:ge,...ge?{streamThinking:ye}:{}}),J.thinkingLevel&&be!==`default`&&(e.thinking={enabled:!0,level:be}),(l===`edit`||A!==`active`)&&(e.status=A),await c(Q,e)}catch(e){I(L(e)??`Failed to save profile. Please try again.`)}finally{P(!1)}}}function Qe(){u(`create`),y(``),je()}return{effectiveMode:l,isReadOnly:f,isInvariant:d,hasViewModeChanges:he,label:m,description:g,key:v,provider:b,model:C,providerConnection:O,status:A,saving:ee,saveError:F,keyError:Ye,providerError:Xe,isInvalid:Je,maxTokens:te,contextWindowMaxInputTokens:re,effort:ie,speed:z,verbosity:oe,temperatureEnabled:ue,temperature:U,topPEnabled:fe,topP:me,thinkingEnabled:ge,thinkingStreamThinking:ye,thinkingLevel:be,visibility:J,selectedModel:Ce,defaultMaxOutputTokens:Ee,defaultContextWindowMaxInputTokens:De,effectiveConnections:Y,availableConnectionsForProvider:X,connectionNotFound:Oe,creatingProvider:Pe,pendingCreateProvider:Ie,newProviderNote:Re,setDescription:_,setStatus:j,setMaxTokens:ne,setContextWindowMaxInputTokens:R,setEffort:ae,setSpeed:B,setVerbosity:le,setTemperatureEnabled:H,setTemperature:de,setTopPEnabled:pe,setTopP:W,setThinkingEnabled:ve,setThinkingStreamThinking:G,setThinkingLevel:xe,setCreatingProvider:Fe,setPendingCreateProvider:Le,setNewProviderNote:ze,handleLabelChange:ke,handleKeyChange:Ae,getDirty:Me,handleProviderChange:Be,handleConnectionChange:Ve,handleModelChange:He,handleProviderCreated:Z,setProviderConnection:k,setModel:D,handleSave:Ze,switchToSaveAsNew:Qe}}var wt=`/assistant/assets/pcm-downsample-worklet-CwNZrVLe.js`;function Tt(){if(!(typeof window>`u`))return window.AudioContext??window.webkitAudioContext}function Et(e){let t=Tt();if(!t)throw Error(`Web Audio API is not available in this environment`);return new t(e)}var Dt=`pcm-downsample`,Ot=1600,kt=16e3;function At(){return b()?window.vellum?.helper?.dictation:void 0}function jt(){let e=At();return!!e?.transcribe&&!!e.onTranscribed}var $=null,Mt=null;async function Nt(){return $||($=Et(),Mt=$.audioWorklet.addModule(wt)),$.state!==`running`&&await $.resume(),await Mt,$}async function Pt(e,t){try{let n=await Nt(),r=n.createMediaStreamSource(e),i=new AudioWorkletNode(n,Dt,{numberOfInputs:1,numberOfOutputs:0,channelCount:1}),a=[],o=0,s=0;return i.port.onmessage=e=>{let r=new Int16Array(e.data);if(r.length===0||(a.push(r),o+=r.length,o<Ot))return;let i=new Int16Array(o),c=0;for(let e of a)i.set(e,c),c+=e.length;a=[],o=0,s+=1,(s===1||s%50==0)&&console.info(`dictation: pushed audio chunk #${s} (${i.byteLength} bytes, context=${n.state})`),t(i.buffer)},r.connect(i),console.info(`dictation: audio pump started (context=${n.state})`),()=>{i.port.onmessage=null,i.disconnect(),r.disconnect()}}catch(e){return console.warn(`native-dictation-partials: audio pump failed`,e),null}}var Ft=8e3;async function It(e){let t=At();if(!t?.transcribe||!t.onTranscribed)return null;let n;try{n=await Lt(e)}catch(e){let t=e instanceof DOMException?`${e.name}: ${e.message}`:e;return console.warn(`dictation: blob decode for native transcribe failed`,t),null}if(n.byteLength===0)return null;let r=null,i=t.onTranscribed(e=>{r?.(e.text||null)});try{let e=await t.transcribe(n);if(!e.ok)return console.info(`dictation: native transcribe unavailable:`,e.reason),null;let i=await new Promise(e=>{r=e,setTimeout(()=>e(null),Ft)});return console.info(`dictation: native transcribe ${i?`chars=${i.length}`:`produced no text`}`),i}catch(e){return console.warn(`dictation: native transcribe failed`,e),null}finally{i()}}async function Lt(e){let t=await e.arrayBuffer(),n=await new OfflineAudioContext(1,1,kt).decodeAudioData(t),r=n.numberOfChannels,i=n.length,a=n.getChannelData(0);if(r>1){let e=new Float32Array(i);for(let t=0;t<r;t++){let a=n.getChannelData(t);for(let t=0;t<i;t++)e[t]+=a[t]/r}a=e}let o=new Int16Array(i);for(let e=0;e<i;e++){let t=a[e],n=t<-1?-1:t>1?1:t;o[e]=n<0?n*32768:n*32767}return o.buffer}var Rt=4e3;async function zt(e,t){let n=At();if(!n)return null;let r=n.pushAudioChunk?.bind(n),i=t?.stream,a=!!i&&!!r,o=n.onPartial(t=>{e(t.text)}),s=null,c=null,l=n.onFinalized?.(e=>{s=e.text||null,c?.(s)})??null,u=()=>{l?.(),o()};try{let e=await n.setPartials(!0,void 0,a);if(!e.ok)return console.info(`native-dictation-partials: unavailable:`,e.reason),u(),null}catch(e){return console.warn(`native-dictation-partials: setPartials failed`,e),u(),null}let d=null;if(a&&(d=await Pt(i,e=>r(e)),!d))return u(),n.setPartials(!1).catch(()=>{}),null;let f=null;return()=>f||(d?.(),o(),n.setPartials(!1).catch(()=>{}),f=(async()=>{let e=s;return!e&&l&&(e=await new Promise(e=>{c=e,setTimeout(()=>e(null),Rt)})),l?.(),console.info(e===null?`dictation: native finalized not received`:`dictation: native finalized chars=${e.length}`),e})(),f)}var Bt=[{id:`vellum`,displayName:`Vellum`,subtitle:`Text-to-speech through your Vellum account — billed to Vellum credits, no separate API key needed.`,supportsVoiceSelection:!1,apiKeyPlaceholder:`Connected via your Vellum account`,credentialsGuide:{description:`Connect this assistant to your Vellum account; managed speech uses that connection instead of a provider API key.`,url:`https://platform.vellum.ai/`,linkLabel:`Open Vellum Platform`}},{id:`elevenlabs`,displayName:`ElevenLabs`,subtitle:`High-quality voice synthesis for conversations and read-aloud. Requires an ElevenLabs API key.`,supportsVoiceSelection:!0,apiKeyPlaceholder:`sk_…`,credentialsGuide:{description:`Sign in to ElevenLabs, go to your Profile, and copy your API key.`,url:`https://elevenlabs.io/app/settings/api-keys`,linkLabel:`Open ElevenLabs API Keys`}},{id:`fish-audio`,displayName:`Fish Audio`,subtitle:`Natural-sounding voice synthesis with custom voice cloning. Requires a Fish Audio API key and voice reference ID.`,supportsVoiceSelection:!0,apiKeyPlaceholder:`Enter your Fish Audio API key`,credentialsGuide:{description:`Sign in to Fish Audio, navigate to API Keys in your dashboard, and create a new key.`,url:`https://fish.audio/app/api-keys/`,linkLabel:`Open Fish Audio API Keys`}},{id:`deepgram`,displayName:`Deepgram`,subtitle:`Fast, accurate text-to-speech synthesis. Uses the same API key as Deepgram speech-to-text.`,supportsVoiceSelection:!1,apiKeyPlaceholder:`Enter your Deepgram API key`,credentialsGuide:{description:`Sign in to Deepgram, navigate to your API Keys page, and create or copy an existing key. This is the same key used for speech-to-text.`,url:`https://console.deepgram.com/`,linkLabel:`Open Deepgram Console`}},{id:`xai`,displayName:`xAI`,subtitle:`Text-to-speech from xAI with expressive voices (eve, ara, rex, sal, leo). Requires an xAI API key.`,supportsVoiceSelection:!1,apiKeyPlaceholder:`Enter your xAI API key`,credentialsGuide:{description:`Sign in to the xAI console, navigate to API Keys, and create a new key.`,url:`https://console.x.ai/`,linkLabel:`Open xAI Console`}}],Vt=`macos-native`,Ht=[{id:`vellum`,displayName:`Vellum`,subtitle:`Transcription through your Vellum account — billed to Vellum credits, no separate API key needed.`},{id:`deepgram`,displayName:`Deepgram`,subtitle:`Fast, accurate speech-to-text transcription. Uses the same API key as Deepgram text-to-speech.`,apiKeyPlaceholder:`Enter your Deepgram API key`,credentialsGuide:{description:`Sign in to Deepgram, navigate to your API Keys page, and create or copy an existing key. This is the same key used for text-to-speech.`,url:`https://console.deepgram.com/`,linkLabel:`Open Deepgram Console`}},{id:`openai`,displayName:`OpenAI`,subtitle:`OpenAI Whisper transcription. Requires an OpenAI API key.`,apiKeyPlaceholder:`sk-…`,credentialsGuide:{description:`Sign in to the OpenAI platform, navigate to API Keys, and create a new secret key.`,url:`https://platform.openai.com/api-keys`,linkLabel:`Open OpenAI API Keys`}},{id:Vt,displayName:`macOS Native Dictation`,subtitle:`Apple's on-device speech recognition, running locally through the macOS helper. Works offline and needs no API key.`,requiresNativeDictation:!0,setupWarning:`Requires macOS Dictation to be turned on: open System Settings → Keyboard, then enable Dictation. macOS downloads the on-device speech model the first time Dictation is enabled — without it, voice input produces no transcript.`}],Ut=[{id:`mailgun`,displayName:`Mailgun`,setupSkill:`mailgun-setup`,docsUrl:`https://www.mailgun.com/`},{id:`resend`,displayName:`Resend`,setupSkill:`resend-setup`,docsUrl:`https://resend.com/`}],Wt=[`gemini-3.1-flash-image-preview`,`gemini-3-pro-image-preview`,`gpt-image-2`],Gt={"gemini-3.1-flash-image-preview":`Nano Banana 2`,"gemini-3-pro-image-preview":`Nano Banana Pro`,"gpt-image-2":`GPT Image 2`},Kt=[`vellum`,`gemini`,`openai`],qt={vellum:`Vellum`,gemini:`Gemini`,openai:`OpenAI`};function Jt(e){return e===`vellum`?[...Wt]:Wt.filter(t=>Yt(t)===e)}function Yt(e){return e.startsWith(`gpt-`)||e.startsWith(`dall-e-`)?`openai`:(e.startsWith(`gemini-`),`gemini`)}var Xt=`vellum:ai:imageGenProvider`,Zt=`vellum:ai:imageGenModel`,Qt=`vellum:ai:webSearchProvider`,$t=`vellum:ai:webFetchProvider`,en=`vellum:ai:emailMode`,tn=`vellum:ai:emailByoProvider`,nn=`vellum:voice:ttsProvider`,rn=`vellum:voice:ttsApiKey:`,an=`vellum:voice:ttsVoiceId:`,on=`vellum:voice:sttProvider`,sn=`vellum:voice:sttApiKey:`;function cn({value:e,size:t=`default`,className:n,...r}){let i=t===`compact`;return(0,K.jsxs)(`button`,{type:`button`,className:s(`flex items-center gap-2 rounded-md border border-[var(--field-border)] bg-[var(--field-bg)] text-left text-[var(--content-default)] transition-colors focus:outline-none data-[state=open]:border-[var(--border-active)]`,i?`h-7 min-w-44 px-2.5 text-body-small-default`:`h-9 w-full px-3 text-body-medium-lighter`,n),...r,children:[(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e}),(0,K.jsx)(l,{"aria-hidden":!0,className:s(`shrink-0 text-[var(--content-tertiary)]`,i?`h-3 w-3`:`h-3.5 w-3.5`)})]})}var ln={profiles:{},profileOrder:[]};function un(e,t){let n=e?.profiles,r=e?.profileOrder,i=!!n&&Object.keys(n).length>0,[a,o]=(0,V.useState)(ln),[s,c]=(0,V.useState)(t);return t!==s&&(c(t),o(ln)),(0,V.useEffect)(()=>{i&&o({profiles:n,profileOrder:r??[]})},[i,n,r]),i?{profiles:n,profileOrder:r??[]}:t===s?a:ln}export{vt as A,$e as B,jt as C,Tt as D,Et as E,lt as F,Ae as G,ke as H,nt as I,rt as L,mt as M,pt as N,wt as O,dt as P,et as R,Yt as S,It as T,Oe as U,Le as V,je as W,qt as _,Zt as a,Bt as b,on as c,an as d,$t as f,Kt as g,Gt as h,en as i,_t as j,Ct as k,rn as l,Ut as m,cn as n,Xt as o,Qt as p,tn as r,sn as s,un as t,nn as u,Vt as v,zt as w,Jt as x,Ht as y,Qe as z};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{c as n,m as r,p as i}from"./message-content-Beh5mR15.js";import{n as a}from"./resolved-assistants-store-BFI9c7ip.js";import{i as o,o as s,r as c}from"./subagent-store-9SqF-NFa.js";import{C as l,S as u,_ as d,w as f,y as p}from"./site-favicon-B3DMFtr3.js";function m(e,t){if(t===e)return{kind:`identity`};if(e==null)return{kind:`first`};let n=e.length,r=t.length;return r>n&&(n===0||t[0]===e[0]&&t[n-1]===e[n-1])?{kind:`append`,from:n}:r===n&&r>=1&&t[r-1]!==e[r-1]&&t[r-1].id===e[r-1].id&&e[r-1].type===`text`&&t[r-1].type===`text`&&t[r-1].content.length>=e[r-1].content.length&&t[r-1].content.startsWith(e[r-1].content)&&(r===1||t[r-2]===e[r-2])?{kind:`mutate-last`}:{kind:`fallback`}}var h=e(t(),1);function g(e,t){return JSON.stringify(e)===JSON.stringify(t)}function _(e=A){let t=null,n=[],r=[];function i(e){let i=j(e);return t=e,n=i.steps,r=i.toolMeta,{steps:n,toolMeta:r}}function a(a){let o=m(t,a);switch(o.kind){case`identity`:return{steps:n,toolMeta:r};case`first`:return i(a);case`append`:{let i=a.length,s=n.slice(),c=r.slice();for(let t=o.from;t<i;t++)e(s,c,a[t]);return t=a,n=s,r=c,{steps:n,toolMeta:r}}case`mutate-last`:{let i=a.length,o=n.slice(),s=r.slice(),c=o[o.length-1],l;c&&c.kind===`thinking`&&c.detailKey===a[i-1].id&&(l=c,o.pop(),s.pop()),e(o,s,a[i-1]),t=a;let u=o[o.length-1];return l&&u&&g(l,u)?{steps:n,toolMeta:r}:(n=o,r=s,{steps:n,toolMeta:r})}case`fallback`:return i(a)}}return{project:a}}function v(e){let t=(0,h.useRef)(null),n=(0,h.useRef)(null);t.current??=_();let r=t.current.project(e),i=n.current;return i!=null&&i.steps===r.steps&&i.toolMeta===r.toolMeta?i:(n.current=r,r)}var y=160,b=[];function x(e){return r(e.replace(/\s+/g,` `).trim(),y)}function S(e){let t=((e.input&&typeof e.input.url==`string`?e.input.url:``)||e.content||``).trim(),n=t?u(t):``;return n?`Reading ${n}`:`Reading…`}function C(e,t){let n=typeof e==`number`&&Number.isFinite(e)?t-e:0;return n>0?p(n):``}function w(e,t){return{kind:`web_search_error`,title:`Web search failed`,durationLabel:e,errorMessage:x(t.result??t.content)||`Web search failed`,detailKey:t.toolUseId}}function T(e,t){let n=e.toLowerCase();if(!t)return{};switch(n){case`bash`:case`host_bash`:return{command:t};case`str_replace_editor`:case`text_editor`:return{path:t};case`computer`:return{action:t};case`skill`:case`skill_execute`:case`skill_invoke`:case`skill_load`:return{skill:t};case`subagent_spawn`:return{label:t};default:return{}}}function E(e){let t=e.toolName??``,r=e.content??``,i=n(t,e.input??T(t,r));return{kind:`tool`,durationLabel:``,toolCallId:e.toolUseId??``,iconName:i.iconName,title:i.title,info:i.info||r,activity:i.activity,status:`running`}}function D(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(r.running){if(t.toolUseId){if(r.toolCallId===t.toolUseId)return n;continue}if(!t.toolName||r.toolName===t.toolName)return n}}return-1}function O(e,t,n){return D(e.map((e,n)=>{let r=t[n];return e.kind===`tool`?{toolCallId:e.toolCallId,toolName:r?.toolName??``,running:e.status===`running`}:e.kind===`web_search`?{toolCallId:r?.toolUseId??``,toolName:r?.toolName??``,running:e.title===`Searching the web`}:{toolCallId:``,toolName:r?.toolName??``,running:!1}}),n)}function k(e){switch(e){case`running`:case`pending`:case`awaiting_input`:return`loading`;case`completed`:return`complete`;case`failed`:case`aborted`:case`interrupted`:return`error`;default:return`loading`}}function A(e,t,n){if(n.type===`text`){let r=x(n.content);if(r.length===0)return;e.push({kind:`thinking`,durationLabel:``,text:r,detailKey:n.id}),t.push(void 0);return}if(n.type===`tool_call`){let r=n.toolName??``;if(d.has(r)){if(r===`web_fetch`)e.push({kind:`thinking`,durationLabel:``,text:S(n),detailKey:n.toolUseId}),t.push(void 0);else{let i=n.input&&typeof n.input.query==`string`?n.input.query:n.content||void 0;e.push({kind:`web_search`,query:i,title:`Searching the web`,durationLabel:``,linkCount:0,results:[],detailKey:n.toolUseId}),t.push({startTs:n.timestamp,toolName:r,toolUseId:n.toolUseId})}return}e.push(E(n)),t.push({startTs:n.timestamp,toolName:r});return}if(n.type===`tool_result`){let r=O(e,t,n);if(r===-1)return;let i=e[r],a=t[r]?.startTs,o=C(a,n.timestamp);if(i.kind===`web_search`){if(n.isError){e[r]=w(o,n);return}let t=l(n.result??n.content);e[r]={...i,title:`Searched the web`,query:i.query||n.searchQuery,durationLabel:o,linkCount:t.length,results:t};return}if(i.kind!==`tool`)return;e[r]={...i,status:n.isError?`error`:`completed`,durationLabel:o};return}if(n.type===`error`){let r=O(e,t,n);if(r!==-1){let i=e[r];i.kind===`tool`?e[r]={...i,status:`error`}:i.kind===`web_search`&&(e[r]=w(C(t[r]?.startTs,n.timestamp),n))}let i=x(n.content)||`Subagent error`;e.push({kind:`tool_error`,message:i}),t.push(void 0);return}}function j(e){let t=[],n=[];for(let r of e)A(t,n,r);return{steps:t,toolMeta:n}}function M(e){return!s(e.status)&&o(e)&&e.events.length===0&&!e.detailSettled}function N(e,{steps:t,toolMeta:n}){if(M(e))return{state:`loading`,currentStepTitle:`Loading`,currentStepInfo:e.label,stepCount:``,steps:t,carouselItems:[]};let r=k(e.status),{currentStepTitle:i,currentStepInfo:a}=P(e,t,n);return{state:r,currentStepTitle:i,currentStepInfo:a,stepCount:`${t.length} step${t.length===1?``:`s`}`,steps:t,carouselItems:[]}}function P(e,t,n){let r=e.status===`completed`||e.status===`failed`||e.status===`aborted`||e.status===`interrupted`;if(t.length===0){let t;return t=e.status===`failed`?`Failed`:e.status===`aborted`?`Aborted`:e.status===`interrupted`?`Interrupted`:e.status===`completed`?`Finished`:`Working`,{currentStepTitle:t,currentStepInfo:e.error||e.label}}let a=t[t.length-1];if(a.kind===`thinking`)return{currentStepTitle:r?`Thought`:`Thinking`,currentStepInfo:f(a.text)};if(a.kind===`tool`){if(a.status===`running`)return{currentStepTitle:`Working`,currentStepInfo:a.info};if(!r)return{currentStepTitle:`Finalizing`,currentStepInfo:a.info};let e=n[t.length-1]?.toolName??``;return{currentStepTitle:e?`Used ${i(e)}`:`Done`,currentStepInfo:a.info}}return a.kind===`tool_error`?{currentStepTitle:`Errored`,currentStepInfo:a.message}:a.kind===`web_search`?{currentStepTitle:a.title,currentStepInfo:``}:a.kind===`web_search_error`?{currentStepTitle:a.title,currentStepInfo:a.errorMessage}:{currentStepTitle:``,currentStepInfo:``}}function F(e){let t=c(t=>t.byId[e]),n=a(e=>e.activeAssistantId),r=t!==void 0&&M(t);(0,h.useEffect)(()=>{r&&n&&c.getState().fetchDetailIfNeeded(n,e)},[r,n,e]);let i=v(t?.events??b),o=(0,h.useRef)(null);if(!t)return o.current=null,null;let s=N(t,i),l=o.current;return l!=null&&l.steps===s.steps&&l.state===s.state&&l.currentStepTitle===s.currentStepTitle&&l.currentStepInfo===s.currentStepInfo&&l.stepCount===s.stepCount?l:(o.current=s,s)}function I(e,t,r){if(r.type===`text`){if((r.content??``).trim().length===0)return;e.push({toolCallId:r.id,toolName:``,title:`Thought`,activity:``,input:{},status:`completed`,durationLabel:``,kind:`thinking`,thinkingText:r.content}),t.push({startTs:r.timestamp,running:!1});return}if(r.type===`tool_call`){let i=r.toolUseId??``;if(!i)return;let a=r.toolName??``;if(a===`web_search`){let n=r.input&&typeof r.input.query==`string`?r.input.query:r.content||void 0;e.push({toolCallId:i,toolName:a,title:`Searched the web`,activity:``,input:r.input??{},status:`running`,durationLabel:``,kind:`web_search`,searchQuery:n,searchResults:[]}),t.push({startTs:r.timestamp,running:!0});return}let o=n(a,r.input??T(a,r.content??``));e.push({toolCallId:i,toolName:a,title:o.title,activity:o.activity,input:r.input??{},status:`running`,durationLabel:``,kind:`tool`}),t.push({startTs:r.timestamp,running:!0});return}if(r.type===`tool_result`||r.type===`error`){let n=D(e.map((e,n)=>({toolCallId:e.toolCallId,toolName:e.toolName,running:t[n].running})),r);if(n===-1)return;let i=e[n],a=t[n].startTs,o=C(a,r.timestamp);e[n]=i.kind===`web_search`?{...i,status:r.isError?`error`:`completed`,durationLabel:o,searchQuery:i.searchQuery||r.searchQuery,searchResults:r.isError?[]:l(r.result??r.content),result:r.isError?r.result??r.content:void 0}:{...i,result:r.result??r.content,status:r.isError?`error`:`completed`,durationLabel:o},t[n].running=!1}}export{m as i,F as n,v as r,I as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{c as n,m as r,p as i}from"./message-content-Beh5mR15.js";import{n as a}from"./resolved-assistants-store-BFI9c7ip.js";import{i as o,o as s,r as c}from"./subagent-store-9SqF-NFa.js";import{C as l,S as u,_ as d,w as f,y as p}from"./site-favicon-DfuXzZcN.js";function m(e,t){if(t===e)return{kind:`identity`};if(e==null)return{kind:`first`};let n=e.length,r=t.length;return r>n&&(n===0||t[0]===e[0]&&t[n-1]===e[n-1])?{kind:`append`,from:n}:r===n&&r>=1&&t[r-1]!==e[r-1]&&t[r-1].id===e[r-1].id&&e[r-1].type===`text`&&t[r-1].type===`text`&&t[r-1].content.length>=e[r-1].content.length&&t[r-1].content.startsWith(e[r-1].content)&&(r===1||t[r-2]===e[r-2])?{kind:`mutate-last`}:{kind:`fallback`}}var h=e(t(),1);function g(e,t){return JSON.stringify(e)===JSON.stringify(t)}function _(e=A){let t=null,n=[],r=[];function i(e){let i=j(e);return t=e,n=i.steps,r=i.toolMeta,{steps:n,toolMeta:r}}function a(a){let o=m(t,a);switch(o.kind){case`identity`:return{steps:n,toolMeta:r};case`first`:return i(a);case`append`:{let i=a.length,s=n.slice(),c=r.slice();for(let t=o.from;t<i;t++)e(s,c,a[t]);return t=a,n=s,r=c,{steps:n,toolMeta:r}}case`mutate-last`:{let i=a.length,o=n.slice(),s=r.slice(),c=o[o.length-1],l;c&&c.kind===`thinking`&&c.detailKey===a[i-1].id&&(l=c,o.pop(),s.pop()),e(o,s,a[i-1]),t=a;let u=o[o.length-1];return l&&u&&g(l,u)?{steps:n,toolMeta:r}:(n=o,r=s,{steps:n,toolMeta:r})}case`fallback`:return i(a)}}return{project:a}}function v(e){let t=(0,h.useRef)(null),n=(0,h.useRef)(null);t.current??=_();let r=t.current.project(e),i=n.current;return i!=null&&i.steps===r.steps&&i.toolMeta===r.toolMeta?i:(n.current=r,r)}var y=160,b=[];function x(e){return r(e.replace(/\s+/g,` `).trim(),y)}function S(e){let t=((e.input&&typeof e.input.url==`string`?e.input.url:``)||e.content||``).trim(),n=t?u(t):``;return n?`Reading ${n}`:`Reading…`}function C(e,t){let n=typeof e==`number`&&Number.isFinite(e)?t-e:0;return n>0?p(n):``}function w(e,t){return{kind:`web_search_error`,title:`Web search failed`,durationLabel:e,errorMessage:x(t.result??t.content)||`Web search failed`,detailKey:t.toolUseId}}function T(e,t){let n=e.toLowerCase();if(!t)return{};switch(n){case`bash`:case`host_bash`:return{command:t};case`str_replace_editor`:case`text_editor`:return{path:t};case`computer`:return{action:t};case`skill`:case`skill_execute`:case`skill_invoke`:case`skill_load`:return{skill:t};case`subagent_spawn`:return{label:t};default:return{}}}function E(e){let t=e.toolName??``,r=e.content??``,i=n(t,e.input??T(t,r));return{kind:`tool`,durationLabel:``,toolCallId:e.toolUseId??``,iconName:i.iconName,title:i.title,info:i.info||r,activity:i.activity,status:`running`}}function D(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(r.running){if(t.toolUseId){if(r.toolCallId===t.toolUseId)return n;continue}if(!t.toolName||r.toolName===t.toolName)return n}}return-1}function O(e,t,n){return D(e.map((e,n)=>{let r=t[n];return e.kind===`tool`?{toolCallId:e.toolCallId,toolName:r?.toolName??``,running:e.status===`running`}:e.kind===`web_search`?{toolCallId:r?.toolUseId??``,toolName:r?.toolName??``,running:e.title===`Searching the web`}:{toolCallId:``,toolName:r?.toolName??``,running:!1}}),n)}function k(e){switch(e){case`running`:case`pending`:case`awaiting_input`:return`loading`;case`completed`:return`complete`;case`failed`:case`aborted`:case`interrupted`:return`error`;default:return`loading`}}function A(e,t,n){if(n.type===`text`){let r=x(n.content);if(r.length===0)return;e.push({kind:`thinking`,durationLabel:``,text:r,detailKey:n.id}),t.push(void 0);return}if(n.type===`tool_call`){let r=n.toolName??``;if(d.has(r)){if(r===`web_fetch`)e.push({kind:`thinking`,durationLabel:``,text:S(n),detailKey:n.toolUseId}),t.push(void 0);else{let i=n.input&&typeof n.input.query==`string`?n.input.query:n.content||void 0;e.push({kind:`web_search`,query:i,title:`Searching the web`,durationLabel:``,linkCount:0,results:[],detailKey:n.toolUseId}),t.push({startTs:n.timestamp,toolName:r,toolUseId:n.toolUseId})}return}e.push(E(n)),t.push({startTs:n.timestamp,toolName:r});return}if(n.type===`tool_result`){let r=O(e,t,n);if(r===-1)return;let i=e[r],a=t[r]?.startTs,o=C(a,n.timestamp);if(i.kind===`web_search`){if(n.isError){e[r]=w(o,n);return}let t=l(n.result??n.content);e[r]={...i,title:`Searched the web`,query:i.query||n.searchQuery,durationLabel:o,linkCount:t.length,results:t};return}if(i.kind!==`tool`)return;e[r]={...i,status:n.isError?`error`:`completed`,durationLabel:o};return}if(n.type===`error`){let r=O(e,t,n);if(r!==-1){let i=e[r];i.kind===`tool`?e[r]={...i,status:`error`}:i.kind===`web_search`&&(e[r]=w(C(t[r]?.startTs,n.timestamp),n))}let i=x(n.content)||`Subagent error`;e.push({kind:`tool_error`,message:i}),t.push(void 0);return}}function j(e){let t=[],n=[];for(let r of e)A(t,n,r);return{steps:t,toolMeta:n}}function M(e){return!s(e.status)&&o(e)&&e.events.length===0&&!e.detailSettled}function N(e,{steps:t,toolMeta:n}){if(M(e))return{state:`loading`,currentStepTitle:`Loading`,currentStepInfo:e.label,stepCount:``,steps:t,carouselItems:[]};let r=k(e.status),{currentStepTitle:i,currentStepInfo:a}=P(e,t,n);return{state:r,currentStepTitle:i,currentStepInfo:a,stepCount:`${t.length} step${t.length===1?``:`s`}`,steps:t,carouselItems:[]}}function P(e,t,n){let r=e.status===`completed`||e.status===`failed`||e.status===`aborted`||e.status===`interrupted`;if(t.length===0){let t;return t=e.status===`failed`?`Failed`:e.status===`aborted`?`Aborted`:e.status===`interrupted`?`Interrupted`:e.status===`completed`?`Finished`:`Working`,{currentStepTitle:t,currentStepInfo:e.error||e.label}}let a=t[t.length-1];if(a.kind===`thinking`)return{currentStepTitle:r?`Thought`:`Thinking`,currentStepInfo:f(a.text)};if(a.kind===`tool`){if(a.status===`running`)return{currentStepTitle:`Working`,currentStepInfo:a.info};if(!r)return{currentStepTitle:`Finalizing`,currentStepInfo:a.info};let e=n[t.length-1]?.toolName??``;return{currentStepTitle:e?`Used ${i(e)}`:`Done`,currentStepInfo:a.info}}return a.kind===`tool_error`?{currentStepTitle:`Errored`,currentStepInfo:a.message}:a.kind===`web_search`?{currentStepTitle:a.title,currentStepInfo:``}:a.kind===`web_search_error`?{currentStepTitle:a.title,currentStepInfo:a.errorMessage}:{currentStepTitle:``,currentStepInfo:``}}function F(e){let t=c(t=>t.byId[e]),n=a(e=>e.activeAssistantId),r=t!==void 0&&M(t);(0,h.useEffect)(()=>{r&&n&&c.getState().fetchDetailIfNeeded(n,e)},[r,n,e]);let i=v(t?.events??b),o=(0,h.useRef)(null);if(!t)return o.current=null,null;let s=N(t,i),l=o.current;return l!=null&&l.steps===s.steps&&l.state===s.state&&l.currentStepTitle===s.currentStepTitle&&l.currentStepInfo===s.currentStepInfo&&l.stepCount===s.stepCount?l:(o.current=s,s)}function I(e,t,r){if(r.type===`text`){if((r.content??``).trim().length===0)return;e.push({toolCallId:r.id,toolName:``,title:`Thought`,activity:``,input:{},status:`completed`,durationLabel:``,kind:`thinking`,thinkingText:r.content}),t.push({startTs:r.timestamp,running:!1});return}if(r.type===`tool_call`){let i=r.toolUseId??``;if(!i)return;let a=r.toolName??``;if(a===`web_search`){let n=r.input&&typeof r.input.query==`string`?r.input.query:r.content||void 0;e.push({toolCallId:i,toolName:a,title:`Searched the web`,activity:``,input:r.input??{},status:`running`,durationLabel:``,kind:`web_search`,searchQuery:n,searchResults:[]}),t.push({startTs:r.timestamp,running:!0});return}let o=n(a,r.input??T(a,r.content??``));e.push({toolCallId:i,toolName:a,title:o.title,activity:o.activity,input:r.input??{},status:`running`,durationLabel:``,kind:`tool`}),t.push({startTs:r.timestamp,running:!0});return}if(r.type===`tool_result`||r.type===`error`){let n=D(e.map((e,n)=>({toolCallId:e.toolCallId,toolName:e.toolName,running:t[n].running})),r);if(n===-1)return;let i=e[n],a=t[n].startTs,o=C(a,r.timestamp);e[n]=i.kind===`web_search`?{...i,status:r.isError?`error`:`completed`,durationLabel:o,searchQuery:i.searchQuery||r.searchQuery,searchResults:r.isError?[]:l(r.result??r.content),result:r.isError?r.result??r.content:void 0}:{...i,result:r.result??r.content,status:r.isError?`error`:`completed`,durationLabel:o},t[n].running=!1}}export{m as i,F as n,v as r,I as t};
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{L as n,t as r}from"./use-transcript-messages-BEpY7uG4.js";var i=e(t(),1);function a(e){let t=r();return(0,i.useMemo)(()=>{if(e)return t.find(t=>n(t).includes(e))},[t,e])}export{a as t};
@@ -1,3 +1,3 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{i as t,l as n}from"./local-settings-Bx7FsNo5.js";import{t as r}from"./react-BFJW0bSv.js";import{i}from"./use-attachment-preview-CB3GsEns.js";import{n as a,t as o}from"./create-selectors-DBgi9gD3.js";import{n as s}from"./event-bus-Cy8AzL-G.js";import{r as c}from"./typed-storage-lk6_tW16.js";import{t as l}from"./client-perf-C-xVLAvQ.js";import{a as u}from"./diagnostics-6dSlxnyU.js";import{t as ee}from"./conversation-store-D4pZBwP5.js";import{s as te,u as d}from"./messages-D2OJUCHs.js";import{C as f,D as p,n as ne,t as re,w as ie,x as ae}from"./chat-DYLliWTB.js";var m=e(r(),1),h=1e3,oe=15,se=0,g=new Map,_=[],v=new Map,ce=20;function le(e){let t=`sse-${++se}`,n={id:t,abortSignal:e,initiatedAt:Date.now(),establishedAt:null,lastTrafficAt:null,lastDataAt:null,dataFrames:0,keepalives:0,firstFrameAt:null,interKeepaliveMs:null,endedAt:null,endReason:null};g.set(t,n),xe();let r=()=>{be(t,`aborted`)};return e.aborted?r():e.addEventListener(`abort`,r,{once:!0}),t}function ue(e){let t=g.get(e);t&&t.establishedAt===null&&(t.establishedAt=Date.now())}function de(e,t){let n=g.get(e);if(!n)return;let r=Date.now();n.lastTrafficAt=r,n.firstFrameAt===null&&(n.firstFrameAt=r),t?(n.lastDataAt=r,n.dataFrames++):(n.keepalives++,fe(n,r))}function fe(e,t){let n=v.get(e.id);if(!n){v.set(e.id,{lastKeepaliveAt:t,gaps:[]});return}n.gaps.push(t-n.lastKeepaliveAt),n.lastKeepaliveAt=t,n.gaps.length>ce&&n.gaps.shift(),n.gaps.length>=2&&(e.interKeepaliveMs=Math.round(pe(n.gaps)))}function pe(e){let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==1?t[n]:(t[n-1]+t[n])/2}function me(e,t){_.push({clientId:e,receivedAt:new Date().toISOString(),...t}),_.length>h&&_.shift()}var he=`events-tail`;function ge(e){if(e.length===0)return;let t=new Set;for(let e of _)typeof e.seq==`number`&&t.add(e.seq);for(let n of e)typeof n.seq==`number`&&t.has(n.seq)||_.push({clientId:he,receivedAt:new Date().toISOString(),...n});for(;_.length>h;)_.shift()}function _e(){return Array.from(g.values())}function ve(e=h){let t=Math.max(0,_.length-e);return _.slice(t)}function ye(e,t){if(t===null)return null;let n=1/0;for(let e of _)typeof e.seq==`number`&&(n=Math.min(n,e.seq));return n!==1/0&&n>t+1?null:_.filter(n=>n.conversationId===e&&typeof n.seq==`number`&&n.seq>t).sort((e,t)=>e.seq-t.seq)}function be(e,t){let n=g.get(e);n&&(n.endedAt===null?(n.endedAt=Date.now(),n.endReason=t):n.endReason===`aborted`&&t!==`aborted`&&(n.endReason=t),v.delete(e),xe())}function xe(){let e=0;for(let t of g.values())t.endedAt!==null&&e++;if(!(e<=oe))for(let[t,n]of g){if(e<=oe)break;n.endedAt!==null&&(g.delete(t),v.delete(t),e--)}}var Se=15e3,y=null;function b(){y!==null&&(clearTimeout(y.timer),y=null)}function x(e){if(y===null)return;let t=performance.now()-y.at;b(),l(`client_switch.abandoned`,t,{reason:e})}function Ce(e){x(`superseded`),y={conversationId:e,at:performance.now(),timer:setTimeout(()=>{y=null,l(`client_switch.stalled`,Se,{reason:`timeout`})},Se)}}function we(e,t){if(y===null||y.conversationId!==e)return;let n=performance.now()-y.at;b(),l(`client_switch.transcript_painted`,n,{had_history:t.hadHistory})}function Te({conversationId:e,historyLoadFailed:t,transcriptPainted:n,hadHistory:r}){(0,m.useEffect)(()=>{if(e!==null){if(t){x(`history_error`);return}n&&we(e,{hadHistory:r})}}),(0,m.useEffect)(()=>()=>{x(`unmount`)},[])}function Ee(){let e=s(`app.hidden`,()=>{x(`hidden`)});return()=>{e(),b()}}var S={phase:`idle`,pendingQueuedCount:0,activeToolCallCount:0,activeTurnId:null,lastTerminalReason:null,statusText:null,liveWebActivity:{}};function De(e){return e===`queued`||e===`thinking`||e===`streaming`||e===`awaiting_user_input`}function Oe(e){return e===`thinking`}function C(e){return(e.phase===`idle`||e.phase===`errored`)&&!e.activeTurnId}var ke=o(a()((e,t)=>({...S,requestSend:t=>e(e=>({phase:`thinking`,activeTurnId:t??e.activeTurnId,lastTerminalReason:null,activeToolCallCount:0,statusText:null})),acceptSend:t=>e(e=>({activeTurnId:t,...e.phase===`idle`||e.phase===`errored`?{phase:`thinking`,lastTerminalReason:null}:null})),onTextDelta:()=>{let n=t();if(n.phase===`idle`||n.phase===`errored`){if(!n.activeTurnId)return;e({phase:`streaming`});return}(n.phase===`thinking`||n.phase===`queued`)&&e({phase:`streaming`})},onToolUseStart:()=>{let n=t();C(n)||e({phase:n.phase===`idle`||n.phase===`errored`||n.phase===`queued`?`thinking`:n.phase,activeToolCallCount:n.activeToolCallCount+1})},onToolResult:()=>e(e=>({activeToolCallCount:Math.max(0,e.activeToolCallCount-1)})),onToolActivityMetadata:(n,r)=>{let i=t();C(i)||e({liveWebActivity:{...i.liveWebActivity,[n]:r}})},onActivityThinking:(n,r)=>{let i=t();if(C(i)){if(!r?.canStartFromIdle)return;e({phase:`thinking`,statusText:n??null,lastTerminalReason:null});return}i.phase!==`awaiting_user_input`&&e({phase:`thinking`,statusText:n??null})},recoverFromAwaitingUserInput:()=>{t().phase===`awaiting_user_input`&&e({phase:`thinking`})},showSurface:n=>{C(t())||n&&e({phase:`awaiting_user_input`})},updateSurface:()=>{},dismissSurface:()=>{let n=t();n.phase===`awaiting_user_input`&&n.activeToolCallCount===0&&e({phase:`thinking`})},completeSurface:()=>{let n=t();n.phase===`awaiting_user_input`&&n.activeToolCallCount===0&&e({phase:`thinking`})},onSecretRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},onConfirmationRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},onQuestionRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},onContactRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},completeTurn:()=>{e({phase:t().pendingQueuedCount>0?`queued`:`idle`,activeTurnId:null,activeToolCallCount:0,lastTerminalReason:`complete`,statusText:null,liveWebActivity:{}})},handoffGeneration:()=>{C(t())||e({phase:`thinking`,activeToolCallCount:0,statusText:null})},cancelGeneration:()=>{e({phase:t().pendingQueuedCount>0?`queued`:`idle`,activeTurnId:null,activeToolCallCount:0,lastTerminalReason:`cancelled`,statusText:null,liveWebActivity:{}})},onStreamError:()=>e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,pendingQueuedCount:0,lastTerminalReason:`error`,statusText:null,liveWebActivity:{}}),onSessionError:()=>e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,pendingQueuedCount:0,lastTerminalReason:`session_error`,statusText:null,liveWebActivity:{}}),onTurnTimeout:()=>e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,pendingQueuedCount:0,lastTerminalReason:`timeout`,statusText:null,liveWebActivity:{}}),onPollReconciled:n=>{let r=t();n&&n!==r.activeTurnId||De(r.phase)&&e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,lastTerminalReason:`complete`,statusText:null,liveWebActivity:{}})},resetTurn:()=>e({...S}),clearStaleTurn:()=>{let n=t();n.activeTurnId&&De(n.phase)||e({...S})},enqueueMessage:()=>e(e=>({pendingQueuedCount:e.pendingQueuedCount+1})),dequeueMessage:()=>{let n=t(),r=Math.max(0,n.pendingQueuedCount-1);if(C(n)){e({pendingQueuedCount:r});return}e({phase:`thinking`,pendingQueuedCount:r})},deleteQueuedMessage:()=>{let n=t(),r=Math.max(0,n.pendingQueuedCount-1);if(r===0&&n.phase===`queued`){e({phase:`idle`,pendingQueuedCount:0,activeTurnId:null,lastTerminalReason:`complete`,statusText:null,liveWebActivity:{}});return}e({pendingQueuedCount:r})}})));function Ae(e){if(e.length===0)return``;let t=e[0]??``;for(let n=1;n<e.length;n++){let r=t[t.length-1],i=e[n][0];r&&i&&r!==` `&&r!==`
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{i as t,l as n}from"./local-settings-Bx7FsNo5.js";import{t as r}from"./react-BFJW0bSv.js";import{i}from"./use-attachment-preview-B4PALbqs.js";import{n as a,t as o}from"./create-selectors-DBgi9gD3.js";import{n as s}from"./event-bus-Cy8AzL-G.js";import{r as c}from"./typed-storage-lk6_tW16.js";import{t as l}from"./client-perf-C-xVLAvQ.js";import{a as u}from"./diagnostics-6dSlxnyU.js";import{t as ee}from"./conversation-store-D4pZBwP5.js";import{s as te,u as d}from"./messages-DSdy6Lfi.js";import{C as f,D as p,n as ne,t as re,w as ie,x as ae}from"./chat-DYLliWTB.js";var m=e(r(),1),h=1e3,oe=15,se=0,g=new Map,_=[],v=new Map,ce=20;function le(e){let t=`sse-${++se}`,n={id:t,abortSignal:e,initiatedAt:Date.now(),establishedAt:null,lastTrafficAt:null,lastDataAt:null,dataFrames:0,keepalives:0,firstFrameAt:null,interKeepaliveMs:null,endedAt:null,endReason:null};g.set(t,n),xe();let r=()=>{be(t,`aborted`)};return e.aborted?r():e.addEventListener(`abort`,r,{once:!0}),t}function ue(e){let t=g.get(e);t&&t.establishedAt===null&&(t.establishedAt=Date.now())}function de(e,t){let n=g.get(e);if(!n)return;let r=Date.now();n.lastTrafficAt=r,n.firstFrameAt===null&&(n.firstFrameAt=r),t?(n.lastDataAt=r,n.dataFrames++):(n.keepalives++,fe(n,r))}function fe(e,t){let n=v.get(e.id);if(!n){v.set(e.id,{lastKeepaliveAt:t,gaps:[]});return}n.gaps.push(t-n.lastKeepaliveAt),n.lastKeepaliveAt=t,n.gaps.length>ce&&n.gaps.shift(),n.gaps.length>=2&&(e.interKeepaliveMs=Math.round(pe(n.gaps)))}function pe(e){let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==1?t[n]:(t[n-1]+t[n])/2}function me(e,t){_.push({clientId:e,receivedAt:new Date().toISOString(),...t}),_.length>h&&_.shift()}var he=`events-tail`;function ge(e){if(e.length===0)return;let t=new Set;for(let e of _)typeof e.seq==`number`&&t.add(e.seq);for(let n of e)typeof n.seq==`number`&&t.has(n.seq)||_.push({clientId:he,receivedAt:new Date().toISOString(),...n});for(;_.length>h;)_.shift()}function _e(){return Array.from(g.values())}function ve(e=h){let t=Math.max(0,_.length-e);return _.slice(t)}function ye(e,t){if(t===null)return null;let n=1/0;for(let e of _)typeof e.seq==`number`&&(n=Math.min(n,e.seq));return n!==1/0&&n>t+1?null:_.filter(n=>n.conversationId===e&&typeof n.seq==`number`&&n.seq>t).sort((e,t)=>e.seq-t.seq)}function be(e,t){let n=g.get(e);n&&(n.endedAt===null?(n.endedAt=Date.now(),n.endReason=t):n.endReason===`aborted`&&t!==`aborted`&&(n.endReason=t),v.delete(e),xe())}function xe(){let e=0;for(let t of g.values())t.endedAt!==null&&e++;if(!(e<=oe))for(let[t,n]of g){if(e<=oe)break;n.endedAt!==null&&(g.delete(t),v.delete(t),e--)}}var Se=15e3,y=null;function b(){y!==null&&(clearTimeout(y.timer),y=null)}function x(e){if(y===null)return;let t=performance.now()-y.at;b(),l(`client_switch.abandoned`,t,{reason:e})}function Ce(e){x(`superseded`),y={conversationId:e,at:performance.now(),timer:setTimeout(()=>{y=null,l(`client_switch.stalled`,Se,{reason:`timeout`})},Se)}}function we(e,t){if(y===null||y.conversationId!==e)return;let n=performance.now()-y.at;b(),l(`client_switch.transcript_painted`,n,{had_history:t.hadHistory})}function Te({conversationId:e,historyLoadFailed:t,transcriptPainted:n,hadHistory:r}){(0,m.useEffect)(()=>{if(e!==null){if(t){x(`history_error`);return}n&&we(e,{hadHistory:r})}}),(0,m.useEffect)(()=>()=>{x(`unmount`)},[])}function Ee(){let e=s(`app.hidden`,()=>{x(`hidden`)});return()=>{e(),b()}}var S={phase:`idle`,pendingQueuedCount:0,activeToolCallCount:0,activeTurnId:null,lastTerminalReason:null,statusText:null,liveWebActivity:{}};function De(e){return e===`queued`||e===`thinking`||e===`streaming`||e===`awaiting_user_input`}function Oe(e){return e===`thinking`}function C(e){return(e.phase===`idle`||e.phase===`errored`)&&!e.activeTurnId}var ke=o(a()((e,t)=>({...S,requestSend:t=>e(e=>({phase:`thinking`,activeTurnId:t??e.activeTurnId,lastTerminalReason:null,activeToolCallCount:0,statusText:null})),acceptSend:t=>e(e=>({activeTurnId:t,...e.phase===`idle`||e.phase===`errored`?{phase:`thinking`,lastTerminalReason:null}:null})),onTextDelta:()=>{let n=t();if(n.phase===`idle`||n.phase===`errored`){if(!n.activeTurnId)return;e({phase:`streaming`});return}(n.phase===`thinking`||n.phase===`queued`)&&e({phase:`streaming`})},onToolUseStart:()=>{let n=t();C(n)||e({phase:n.phase===`idle`||n.phase===`errored`||n.phase===`queued`?`thinking`:n.phase,activeToolCallCount:n.activeToolCallCount+1})},onToolResult:()=>e(e=>({activeToolCallCount:Math.max(0,e.activeToolCallCount-1)})),onToolActivityMetadata:(n,r)=>{let i=t();C(i)||e({liveWebActivity:{...i.liveWebActivity,[n]:r}})},onActivityThinking:(n,r)=>{let i=t();if(C(i)){if(!r?.canStartFromIdle)return;e({phase:`thinking`,statusText:n??null,lastTerminalReason:null});return}i.phase!==`awaiting_user_input`&&e({phase:`thinking`,statusText:n??null})},recoverFromAwaitingUserInput:()=>{t().phase===`awaiting_user_input`&&e({phase:`thinking`})},showSurface:n=>{C(t())||n&&e({phase:`awaiting_user_input`})},updateSurface:()=>{},dismissSurface:()=>{let n=t();n.phase===`awaiting_user_input`&&n.activeToolCallCount===0&&e({phase:`thinking`})},completeSurface:()=>{let n=t();n.phase===`awaiting_user_input`&&n.activeToolCallCount===0&&e({phase:`thinking`})},onSecretRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},onConfirmationRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},onQuestionRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},onContactRequest:()=>{C(t())||e({phase:`awaiting_user_input`})},completeTurn:()=>{e({phase:t().pendingQueuedCount>0?`queued`:`idle`,activeTurnId:null,activeToolCallCount:0,lastTerminalReason:`complete`,statusText:null,liveWebActivity:{}})},handoffGeneration:()=>{C(t())||e({phase:`thinking`,activeToolCallCount:0,statusText:null})},cancelGeneration:()=>{e({phase:t().pendingQueuedCount>0?`queued`:`idle`,activeTurnId:null,activeToolCallCount:0,lastTerminalReason:`cancelled`,statusText:null,liveWebActivity:{}})},onStreamError:()=>e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,pendingQueuedCount:0,lastTerminalReason:`error`,statusText:null,liveWebActivity:{}}),onSessionError:()=>e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,pendingQueuedCount:0,lastTerminalReason:`session_error`,statusText:null,liveWebActivity:{}}),onTurnTimeout:()=>e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,pendingQueuedCount:0,lastTerminalReason:`timeout`,statusText:null,liveWebActivity:{}}),onPollReconciled:n=>{let r=t();n&&n!==r.activeTurnId||De(r.phase)&&e({phase:`idle`,activeTurnId:null,activeToolCallCount:0,lastTerminalReason:`complete`,statusText:null,liveWebActivity:{}})},resetTurn:()=>e({...S}),clearStaleTurn:()=>{let n=t();n.activeTurnId&&De(n.phase)||e({...S})},enqueueMessage:()=>e(e=>({pendingQueuedCount:e.pendingQueuedCount+1})),dequeueMessage:()=>{let n=t(),r=Math.max(0,n.pendingQueuedCount-1);if(C(n)){e({pendingQueuedCount:r});return}e({phase:`thinking`,pendingQueuedCount:r})},deleteQueuedMessage:()=>{let n=t(),r=Math.max(0,n.pendingQueuedCount-1);if(r===0&&n.phase===`queued`){e({phase:`idle`,pendingQueuedCount:0,activeTurnId:null,lastTerminalReason:`complete`,statusText:null,liveWebActivity:{}});return}e({pendingQueuedCount:r})}})));function Ae(e){if(e.length===0)return``;let t=e[0]??``;for(let n=1;n<e.length;n++){let r=t[t.length-1],i=e[n][0];r&&i&&r!==` `&&r!==`
2
2
  `&&r!==` `&&i!==` `&&i!==`
3
3
  `&&i!==` `&&(t+=` `),t+=e[n]}return t}function je(e){let t=[];for(let n of e?.contentBlocks??[])n.type===`text`&&t.push(n.text);return Ae(t)}function Me(e){return[...new Set([e.id,...e.mergedMessageIds??[]].filter(e=>typeof e==`string`&&e.length>0))]}function w(e){let t=Me(e);return e.clientMessageId&&!t.includes(e.clientMessageId)?[...t,e.clientMessageId]:t}function T(e,t){return e.id===t||e.clientMessageId===t||(e.mergedMessageIds?.includes(t)??!1)}function Ne(e,t){if(t.length===0)return e;let n=new Map;for(let e of t)for(let t of w(e))n.has(t)||n.set(t,e);let r=[],i=new Set;for(let t of e){let e;for(let r of w(t)){let t=n.get(r);if(t){e=t;break}}if(e){i.has(e)||(r.push(e),i.add(e));continue}r.push(t)}for(let e of t)i.has(e)||r.push(e);return r}function E(e,t){let n=[...e??[]],r=n.findIndex(e=>e.type===`surface`&&e.surface.surfaceId===t.surfaceId);return r===-1?n.push({type:`surface`,surface:t}):n[r]={type:`surface`,surface:t},n}function Pe(e,t){return e?.filter(e=>!(e.type===`surface`&&e.surface.surfaceId===t))}function Fe(e,t){if(!e.surfaces?.length)return e;let n=!1,r=e.contentBlocks,i=e.surfaces.map(e=>{let i=t(e);return i!==e&&(n=!0,r=E(r,i)),i});return n?{...e,surfaces:i,contentBlocks:r}:e}function Ie(e,t){if(!e.surfaces?.length)return e;let n=e.surfaces.filter(t);if(n.length===e.surfaces.length)return e;let r=new Set(e.surfaces.filter(e=>!t(e)).map(e=>e.surfaceId));return{...e,surfaces:n,contentOrder:e.contentOrder?.filter(e=>!(e.type===`surface`&&r.has(e.id))),contentBlocks:e.contentBlocks?.filter(e=>!(e.type===`surface`&&r.has(e.surface.surfaceId)))}}function Le(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function Re(e){let t=JSON.parse(e);return Le(t)?t:null}var ze=500,Be=c({keyFn:e=>`vellum:dismissed-surfaces:${e}`,scope:`user`,parseValue:e=>Le(e)?e:null,fallback:{},maxEntries:200});function Ve(e,t){let n=Be.get(e,t);return n?new Set(n):new Set}function He(e,t,n){let r=Array.from(n);r.length>ze&&(r=r.slice(r.length-ze)),Be.set(e,t,r)}var Ue=[];function We(e,t){if(!e)return Ue;if(t.size===0)return e;let n=!1,r=e.map(e=>{let r=Ie(e,e=>!t.has(e.surfaceId));return r!==e&&(n=!0),r});return n?r:e}function Ge(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.tokens!=`number`||!Number.isFinite(t.tokens)||t.maxTokens!==null&&(typeof t.maxTokens!=`number`||!Number.isFinite(t.maxTokens))||t.fillRatio!==null&&(typeof t.fillRatio!=`number`||!Number.isFinite(t.fillRatio)))}var Ke=c({keyFn:e=>`vellum:ctxwindow:${e}`,scope:`user`,parseValue:e=>Ge(e)?e:null,fallback:{},maxEntries:200});function qe(e){return new Map(Object.entries(Ke.load(e)))}function Je(e,t,n){Ke.set(e,t,n)}var Ye=`PROVIDER_BILLING`,Xe=`PROVIDER_NOT_CONFIGURED`,Ze=`MANAGED_KEY_INVALID`,Qe=`credits_exhausted`,$e=`provider_billing`,et=`daily_limit_reached`;function tt(e){return e?e.category?e.category.endsWith(Qe):e.code===Ye:!1}function nt(e){return e?tt({code:e.code,category:e.errorCategory}):!1}function rt(e){return e?.errorCategory?e.errorCategory.endsWith($e):!1}function it(e){return e?.errorCategory?e.errorCategory.endsWith(et):!1}function at(e){return it(e)?`daily_limit`:nt(e)?`managed_credits`:rt(e)?`provider_billing`:null}function ot(e){return e.billingBannerDecision===`daily_limit`?`daily_limit`:e.billingBannerDecision===`provider_billing`?`provider_billing`:e.billingBannerDecision===`managed_credits`?null:e.dailyLimitReached===!0?`daily_limit`:e.isLowBalance&&!e.dismissed?`low_balance`:null}function D(e){return at(e)!==null||e?.code===Xe||e?.displayAs===`modal`}function st(e){return!!e&&!D(e)}function ct(e){return e?.code===Ze}var lt={pendingSecret:null,isSubmittingSecret:!1,secretSaved:!1,pendingConfirmation:null,isSubmittingConfirmation:!1,pendingContactRequest:null,isSubmittingContactRequest:!1,contactRequestAccepted:!1,pendingQuestion:null,isSubmittingQuestion:!1,isQuestionCardDismissed:!1,inlineConfirmationToolCallId:null,pendingAcpConnect:null,dismissedAcpConnectToolUseIds:new Set,pendingAcpContinue:!1,unknownNudgeToolCallIds:new Set},O=o(a()((e,t)=>({...lt,showSecret:n=>{let{pendingSecret:r}=t();if(r&&r.requestId===n.requestId){let t={};for(let e of Object.keys(n))n[e]!==void 0&&(t[e]=n[e]);e({pendingSecret:{...r,...t}});return}e({pendingSecret:n,isSubmittingSecret:!1,secretSaved:!1})},submitSecretStart:()=>e({isSubmittingSecret:!0}),submitSecretEnd:t=>e({isSubmittingSecret:!1,secretSaved:t??!1}),dismissSecret:()=>e({pendingSecret:null,isSubmittingSecret:!1}),updateSecret:(n,r)=>{let{pendingSecret:i}=t();!i||i.requestId!==n||e({pendingSecret:{...i,...r}})},showConfirmation:t=>e({pendingConfirmation:t,isSubmittingConfirmation:!1}),submitConfirmationStart:()=>e({isSubmittingConfirmation:!0}),submitConfirmationEnd:()=>e({isSubmittingConfirmation:!1}),dismissConfirmation:()=>e({pendingConfirmation:null,isSubmittingConfirmation:!1}),dismissConfirmationIfMatches:n=>{let{pendingConfirmation:r}=t();!r||r.requestId!==n||e({pendingConfirmation:null,isSubmittingConfirmation:!1})},updateConfirmation:(n,r)=>{let{pendingConfirmation:i}=t();!i||i.requestId!==n||e({pendingConfirmation:{...i,...r}})},setInlineConfirmationToolCallId:t=>e({inlineConfirmationToolCallId:t}),showContactRequest:t=>e({pendingContactRequest:t,isSubmittingContactRequest:!1,contactRequestAccepted:!1}),submitContactRequestStart:()=>e({isSubmittingContactRequest:!0}),submitContactRequestEnd:()=>e({isSubmittingContactRequest:!1}),dismissContactRequest:()=>e({pendingContactRequest:null,isSubmittingContactRequest:!1}),acceptContactRequest:()=>e({contactRequestAccepted:!0}),showQuestion:t=>e({pendingQuestion:t,isSubmittingQuestion:!1,isQuestionCardDismissed:!1}),submitQuestionStart:()=>e({isSubmittingQuestion:!0}),submitQuestionEnd:()=>e({isSubmittingQuestion:!1}),dismissQuestion:()=>e({pendingQuestion:null,isSubmittingQuestion:!1,isQuestionCardDismissed:!1}),dismissQuestionIfMatches:n=>{let{pendingQuestion:r}=t();!r||r.requestId!==n||e({pendingQuestion:null,isSubmittingQuestion:!1,isQuestionCardDismissed:!1})},dismissQuestionCard:()=>e({isQuestionCardDismissed:!0}),resetSecretAndConfirmation:()=>e({pendingSecret:null,isSubmittingSecret:!1,secretSaved:!1,pendingConfirmation:null,isSubmittingConfirmation:!1,inlineConfirmationToolCallId:null}),showAcpConnect:t=>e(e=>e.dismissedAcpConnectToolUseIds.has(t.toolUseId)?{}:{pendingAcpConnect:t}),dismissAcpConnect:()=>e(e=>({pendingAcpConnect:null,dismissedAcpConnectToolUseIds:e.pendingAcpConnect?new Set(e.dismissedAcpConnectToolUseIds).add(e.pendingAcpConnect.toolUseId):e.dismissedAcpConnectToolUseIds})),requestAcpContinue:()=>e({pendingAcpContinue:!0}),clearAcpContinue:()=>e({pendingAcpContinue:!1}),addUnknownNudgeToolCallId:n=>{let r=t().unknownNudgeToolCallIds;r.has(n)||e({unknownNudgeToolCallIds:new Set([...r,n])})},removeUnknownNudgeToolCallId:n=>{let r=t().unknownNudgeToolCallIds;if(!r.has(n))return;let i=new Set(r);i.delete(n),e({unknownNudgeToolCallIds:i})},resetAll:()=>e(lt)}))),ut=3670016,dt=[.85,.75,.65,.5],ft=2e7,pt=new Set([`image/jpeg`,`image/jpg`,`image/png`,`image/webp`,`image/heic`,`image/heif`,`image/bmp`,`image/tiff`]),mt=new Set([`jpg`,`jpeg`,`png`,`webp`,`heic`,`heif`,`bmp`,`tif`,`tiff`]);function k(e){let t=e.type.trim().toLowerCase();if(pt.has(t))return!0;let n=e.name.split(`.`).pop()?.trim().toLowerCase();return n?mt.has(n):!1}function ht(e){return k(e)&&e.size>3670016}function gt(e){let t=e.type.trim().toLowerCase();if(t===`image/heic`||t===`image/heif`)return!0;let n=e.name.split(`.`).pop()?.trim().toLowerCase();return n===`heic`||n===`heif`}function _t(e){return ht(e)||gt(e)}function vt(e){if(/^image\/jpe?g$/i.test(e))return`jpg`;let t=e.slice(6).toLowerCase();return/^[a-z0-9]+$/.test(t)?t:`jpg`}function yt(e,t=`image/jpeg`){let n=`attachment`,r=e.trim()||n,i=vt(t),a=r.match(/\.([^./\\]+)$/)?.[1]?.toLowerCase();return a===i||i===`jpg`&&a===`jpeg`?r:`${r.replace(/\.[^./\\]+$/,``)||n}.${i}`}async function bt(e){if(!_t(e)||await St(e))return{status:`unchanged`,file:e};if(e.size>104857600)return{status:`failed`,error:`This image is too large to process safely. Please choose a smaller image.`};let t;try{t=await xt(e)}catch{return{status:`failed`,error:`Couldn't resize this image for upload. Try a smaller image.`}}try{let n;try{n=await wt(t,e.size)}catch{n=null}if(!n||!gt(e)&&n.size>=e.size)return{status:`failed`,error:`Couldn't resize this image for upload. Try a smaller image.`};let r=n.type.startsWith(`image/`)?n.type:`image/jpeg`;return{status:`resized`,file:new File([n],yt(e.name,r),{type:r,lastModified:e.lastModified})}}finally{t.close()}}async function xt(e){if(typeof createImageBitmap==`function`)try{let t=await createImageBitmap(e,{imageOrientation:`from-image`});return{source:t,width:t.width,height:t.height,close:()=>t.close()}}catch{}if(typeof Image>`u`)throw Error(`No browser image decoder is available.`);let t=URL.createObjectURL(e);return await new Promise((e,n)=>{let r=new Image;r.onload=()=>{e({source:r,width:r.naturalWidth||r.width,height:r.naturalHeight||r.height,close:()=>URL.revokeObjectURL(t)})},r.onerror=()=>{URL.revokeObjectURL(t),n(Error(`Image decode failed.`))},r.src=t})}async function St(e){if(!Ct(e))return!1;let t;try{t=new Uint8Array(await e.slice(0,Math.min(e.size,1024*1024)).arrayBuffer())}catch{return!0}if(!j(t,0,`RIFF`)||!j(t,8,`WEBP`))return!1;let n=A(t,`VP8X`);return n>=0&&(t[n+8]??0)&2?!0:A(t,`ANIM`)>=0||A(t,`ANMF`)>=0}function Ct(e){return e.type.trim().toLowerCase()===`image/webp`||/\.webp$/i.test(e.name)}function A(e,t){for(let n=0;n<=e.length-t.length;n+=1)if(j(e,n,t))return n;return-1}function j(e,t,n){if(t+n.length>e.length)return!1;for(let r=0;r<n.length;r+=1)if(e[t+r]!==n.charCodeAt(r))return!1;return!0}async function wt(e,t){let n=e.width*e.height,r=null;if(n<=ft)for(let t of dt){let n=await Tt(e.source,e.width,e.height,t);if(r=M(r,n),n&&n.size<=3670016)return n}let i=r?.size??t,a=Math.min(Math.sqrt(ut/i*.9),.95);for(let t=0;t<4;t+=1){let t=Math.max(Math.floor(e.width*a),1),n=Math.max(Math.floor(e.height*a),1),o=null;for(let i of dt){let a=await Tt(e.source,t,n,i);if(r=M(r,a),o=M(o,a),a&&a.size<=3670016)return a}i=o?.size??i,a*=Math.min(Math.sqrt(ut/i*.9),.9)}return null}function M(e,t){return t&&(!e||t.size<e.size)?t:e}async function Tt(e,t,n,r){if(typeof document>`u`)return null;let i=document.createElement(`canvas`);i.width=t,i.height=n;let a=i.getContext(`2d`);if(!a||typeof i.toBlob!=`function`)return null;a.fillStyle=`#fff`,a.fillRect(0,0,t,n),a.drawImage(e,0,0,t,n);try{return await new Promise(e=>{i.toBlob(t=>e(t),`image/jpeg`,r)})}finally{i.width=0,i.height=0}}var Et=`vellum:chatDrafts:`;function Dt(e){return`${Et}${e}`}function Ot(e){let n=t(Dt(e),``);if(!n)return new Map;try{let e=JSON.parse(n);return typeof e!=`object`||!e||Array.isArray(e)?new Map:new Map(Object.entries(e).filter(e=>typeof e[1]==`string`))}catch{return new Map}}function N(e,t){n(Dt(e),JSON.stringify(Object.fromEntries(t)))}function kt(){return`att-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function At(e){return k(e)?`100 MB`:`50 MB`}function jt(e){return e.size<=52428800?!0:k(e)&&e.size<=104857600}function Mt(e){let t=e.replace(/[/\\]+$/,``),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return n===-1?t:t.slice(n+1)}var P=new Map,F=null,I=new Map,L=new Set,Nt=a()((e,t)=>({input:``,restoredDraftConversationId:null,attachments:[],attachmentLastError:null,setInput:t=>{e(e=>({input:typeof t==`function`?t(e.input):t}))},saveDraft:(e,t)=>{t.trim()?P.set(e,t):P.delete(e),F&&N(F,P)},clearDraft:e=>{P.delete(e),F&&N(F,P)},handleConversationSwitch:({previousKey:n,nextKey:r})=>{if(!(n!==null&&n!==r)||!n)return;let i=t().input;i.trim()?P.set(n,i):P.delete(n);let a=(r&&P.get(r))??``;e({input:a,restoredDraftConversationId:a.length>0&&r?r:null}),F&&N(F,P)},loadAssistantDrafts:(n,r)=>{if(F&&F!==n){let n=t().input;r&&(n.trim()?P.set(r,n):P.delete(r)),N(F,P),e({input:``,restoredDraftConversationId:null})}P=Ot(n),F=n},clearRestoredDraftNotice:()=>{e({restoredDraftConversationId:null})},restoreDraftIfEmpty:n=>{let r=P.get(n);r&&r.trim()&&!t().input.trim()&&e({input:r,restoredDraftConversationId:n})},addFiles:(t,n)=>{let r=Array.from(t);if(r.length===0)return;if(!n){e({attachmentLastError:`No active assistant. Please try again.`});return}let a=[],o=[];for(let e of r)jt(e)?o.push(e):a.push(e);let s=a[0];if(e(s?{attachmentLastError:a.length===1?`${s.name} is larger than ${At(s)} and can't be attached.`:`${a.length} files are too large and can't be attached.`}:{attachmentLastError:null}),o.length===0)return;let c=o.map(e=>({pending:{kind:`uploading`,localId:kt(),filename:e.name||`attachment`,mimeType:e.type||`application/octet-stream`,sizeBytes:e.size},file:e}));e(e=>({attachments:[...e.attachments,...c.map(e=>e.pending)]}));for(let{pending:t,file:r}of c)(async()=>{try{let a=await bt(r);if(L.has(t.localId)){L.delete(t.localId);return}if(a.status===`failed`&&r.size>52428800){R(e,t.localId,a.error);return}let o=a.status===`failed`?r:a.file;if(o.size>52428800){R(e,t.localId,`This attachment is still larger than 50 MB after resizing. Try a smaller image.`);return}a.status===`resized`&&e(e=>({attachments:e.attachments.map(e=>e.localId===t.localId&&e.kind===`uploading`?{...e,filename:o.name||`attachment`,mimeType:o.type||`application/octet-stream`,sizeBytes:o.size}:e)}));let s=await te(n,o);if(L.has(t.localId)){L.delete(t.localId);return}if(!s.ok){R(e,t.localId,s.error.detail??`Upload failed`);return}let c=o.type||`application/octet-stream`,l=s.filename??(o.name||`attachment`),u=s.mimeType??c,ee=s.sizeBytes??o.size,d=o;if(u.startsWith(`image/`)&&u!==c){let e=await i(n,s.id);if(L.has(t.localId)){L.delete(t.localId);return}e&&(d=e)}let f=null;try{f=URL.createObjectURL(d),I.set(t.localId,f)}catch{f=null}e(e=>({attachments:e.attachments.map(e=>e.localId===t.localId?{kind:`uploaded`,localId:t.localId,id:s.id,filename:l,mimeType:u,sizeBytes:ee,previewUrl:f,thumbnailUrl:null}:e)}))}catch{if(L.has(t.localId)){L.delete(t.localId);return}R(e,t.localId,`Upload failed`)}})()},addPathReferences:t=>{let n=[];for(let e of t){let t=e.trim();t&&n.push({kind:`path-reference`,localId:kt(),path:t,filename:Mt(t)||t})}n.length!==0&&e(e=>({attachments:[...e.attachments,...n],attachmentLastError:null}))},removeAttachment:t=>{e(e=>{let n=e.attachments.find(e=>e.localId===t);return n&&n.kind===`uploading`&&L.add(t),{attachments:e.attachments.filter(e=>e.localId!==t)}}),Pt(t)},resetAttachments:()=>{e(e=>{for(let t of e.attachments)t.kind===`uploading`&&L.add(t.localId);return{attachments:[],attachmentLastError:null}})},fullReset:()=>{e(e=>{for(let t of e.attachments)t.kind===`uploading`&&L.add(t.localId);return{attachments:[],attachmentLastError:null}}),I.forEach(e=>URL.revokeObjectURL(e)),I.clear()},dismissAttachmentError:()=>{e({attachmentLastError:null})}}));function R(e,t,n){e(e=>({attachments:e.attachments.map(e=>e.localId!==t||e.kind!==`uploading`?e:{kind:`failed`,localId:t,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,error:n})}))}function Pt(e){let t=I.get(e);t&&(URL.revokeObjectURL(t),I.delete(e))}function Ft(e){return e.reduce((e,t)=>t.kind===`uploading`?e+1:e,0)}function It(e){return e.filter(e=>e.kind===`uploaded`).map(e=>e.id)}function Lt(e){return e.filter(e=>e.kind===`path-reference`).map(e=>e.path)}var z=o(Nt);function Rt(e){if(!(!e||e.length===0))return e.map(e=>{let{previewUrl:t,thumbnailUrl:n}=d(e.mimeType,e.data,e.thumbnailData,e.id!=null);return{id:e.id??e.filename,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes??(e.data?Math.floor(e.data.length*3/4):0),previewUrl:t,thumbnailUrl:n}})}function B(e){let t=e[e.length-1];return!!t&&t.role===`assistant`}function zt(e,t){if(!t)return null;let n=e.length-1;for(;n>=0&&e[n].role===`user`&&e[n].queueStatus===`queued`;)n--;let r=e[n];return!r||r.role!==`assistant`?null:r.id}function V(e,t){return e.findIndex(e=>e.role===`assistant`&&(e.id===t||!!e.mergedMessageIds?.includes(t)))}function H(e,t){if(t){let n=V(e,t);if(n!==-1)return n}let n=e.findLastIndex(e=>e.role===`user`&&e.queueStatus!==`queued`)+1;for(let t=e.length-1;t>=n;t--)if(e[t]?.role===`assistant`)return t;return-1}function U(e,t){if(!t||e.id===t)return e;let n=e.mergedMessageIds??[];return n.includes(t)?e:{...e,mergedMessageIds:[...n,t]}}function W(e,t=Date.now()){if(!e.toolCalls?.some(e=>p(e)))return null;let n=t;return{toolCalls:e.toolCalls.map(e=>p(e)?{...e,completedAt:n}:e),contentBlocks:e.contentBlocks?.map(e=>e.type===`tool_use`&&p(e.toolCall)?{type:`tool_use`,toolCall:{...e.toolCall,completedAt:n}}:e)}}function Bt(e,t,n){return e.map(e=>e.id===t?{...e,queuePosition:n}:e)}function Vt(e,t){return e.map(e=>T(e,t)?{...e,queueStatus:void 0,queuePosition:void 0}:e)}function Ht(e,t){return e.map(e=>T(e,t)?{...e,...e.clientMessageId?{}:{isOptimistic:!0},queueStatus:void 0,queuePosition:void 0}:e)}function Ut(e,t,n){return e.map(e=>T(e,t)?{...e,queueStatus:`queued`,queuePosition:n}:e)}function Wt(e,t){return e.filter(e=>!T(e,t))}function Gt(e,t,n,r=Date.now()){return[...e,{id:n??crypto.randomUUID(),...n?{}:{isOptimistic:!0},role:`assistant`,textSegments:[t],contentOrder:[{type:`text`,id:`0`}],contentBlocks:[{type:`text`,text:t}],timestamp:r}]}function Kt(e,t,n){n&&e[e.length-1]?.type===t.type?e[e.length-1]=t:e.push(t)}function G(e,t,n,r){let i=U(e[t],r),a=[...i.textSegments??[]],o=[...i.contentOrder??[]],s=[...i.contentBlocks??[]],c=o[o.length-1]?.type===`text`&&a.length>0;c?a[a.length-1]=a[a.length-1]+n:(o.push({type:`text`,id:String(a.length)}),a.push(n)),Kt(s,{type:`text`,text:a[a.length-1]},c);let l=[...e];return l[t]={...i,textSegments:a,contentOrder:o,contentBlocks:s},l}function K(e,t,n,r){let i=U(e[t],r),a=[...i.thinkingSegments??[]],o=[...i.contentOrder??[]],s=[...i.contentBlocks??[]],c=o[o.length-1]?.type===`thinking`&&a.length>0;c?a[a.length-1]=a[a.length-1]+n:(o.push({type:`thinking`,id:String(a.length)}),a.push(n)),Kt(s,{type:`thinking`,thinking:a[a.length-1]},c);let l=[...e];return l[t]={...i,thinkingSegments:a,contentOrder:o,contentBlocks:s},l}function qt(e,t,n,r,i=Date.now()){if(n){let a=V(e,n);if(a>=0)return G(e,a,t,n);if(B(e))return G(e,e.length-1,t,n);let o=r?.();return o?G([...e,o],e.length,t,n):Gt(e,t,n,i)}return B(e)?G(e,e.length-1,t,void 0):Gt(e,t,n,i)}function Jt(e,t,n,r=Date.now()){return[...e,{id:n??crypto.randomUUID(),...n?{}:{isOptimistic:!0},role:`assistant`,thinkingSegments:[t],contentOrder:[{type:`thinking`,id:`0`}],contentBlocks:[{type:`thinking`,thinking:t}],timestamp:r}]}function Yt(e,t,n,r,i=Date.now()){if(n){let a=V(e,n);if(a>=0)return K(e,a,t,n);if(B(e))return K(e,e.length-1,t,n);let o=r?.();return o?K([...e,o],e.length,t,n):Jt(e,t,n,i)}return B(e)?K(e,e.length-1,t,void 0):Jt(e,t,n,i)}function Xt(e,t=Date.now()){let n=!1,r=e.map(e=>{if(e.role!==`assistant`)return e;let r=W(e,t);return r?(n=!0,{...e,...r}):e});return n?r:e}function Zt(e,t,n=Date.now()){let r=e[e.length-1],i=Rt(t.attachments);if(r?.role!==`assistant`)return i?[...e,{id:t.messageId??crypto.randomUUID(),...t.messageId?{}:{isOptimistic:!0},role:`assistant`,timestamp:n,attachments:i}]:e;let a=W(r,n),o=r.isOptimistic===!0&&!!t.messageId;return[...e.slice(0,-1),{...r,...o?{id:t.messageId,isOptimistic:!1}:{},...i?{attachments:i}:{},...a??{}}]}function Qt(e,t){if(t!==void 0)return e.findIndex(e=>e.role===`user`&&e.clientMessageId===t);let n=-1;for(let t=e.length-1;t>=0;t--){let r=e[t];if(r&&r.role===`user`&&r.isOptimistic===!0){if(!r.clientMessageId)return t;n===-1&&(n=t)}}return n}function $t(e,t,n=Date.now()){let r=t.messageId;if(r!==void 0&&e.some(e=>e.role===`user`&&(e.id===r||e.mergedMessageIds?.includes(r))))return e;let i=Qt(e,t.clientMessageId);if(i!==-1){if(r===void 0)return e;let t=[...e];return t[i]={...t[i],id:r,isOptimistic:!1,queueStatus:void 0,queuePosition:void 0},t}return[...e,{id:r??crypto.randomUUID(),...r===void 0?{isOptimistic:!0}:{},...t.clientMessageId?{clientMessageId:t.clientMessageId}:{},role:`user`,textSegments:[t.text],contentOrder:[{type:`text`,id:`0`}],contentBlocks:[{type:`text`,text:t.text}],timestamp:n}]}function en(e,t=Date.now()){let n=e.length-1,r=e[n];if(!r||r.role!==`assistant`)return e;let i=W(r,t);if(!(je(r).trim().length>0||r.thinkingSegments!=null&&r.thinkingSegments.length>0||r.toolCalls!=null&&r.toolCalls.length>0||r.surfaces!=null&&r.surfaces.length>0))return e.slice(0,-1);let a=[...e];return a[n]={...r,...i??{}},a}function q(e,t){let n=[...e??[]],r=n.findIndex(e=>e.type===`tool_use`&&e.toolCall.id===t.id);return r===-1?n.push({type:`tool_use`,toolCall:t}):n[r]={type:`tool_use`,toolCall:t},n}function J(e,t,n,r){let i=U(e[t],r),a=i.toolCalls?.findIndex(e=>e.id===n.id)??-1,o=[...e];if(a!==-1){let e=[...i.toolCalls??[]],r={...e[a],...n};return e[a]=r,o[t]={...i,toolCalls:e,contentBlocks:q(i.contentBlocks,r)},o}return o[t]={...i,toolCalls:[...i.toolCalls??[],n],contentOrder:[...i.contentOrder??[],{type:`toolCall`,id:n.id}],contentBlocks:q(i.contentBlocks,n)},o}function tn(e,t,n,r=Date.now()){if(n){let r=V(e,n);if(r>=0)return J(e,r,t,n);if(B(e))return J(e,e.length-1,t,n)}else if(B(e))return J(e,e.length-1,t);return[...e,{id:n??crypto.randomUUID(),...n?{}:{isOptimistic:!0},role:`assistant`,toolCalls:[t],contentOrder:[{type:`toolCall`,id:t.id}],contentBlocks:[{type:`tool_use`,toolCall:t}],timestamp:r}]}function nn(e,t){let n=-1,r=-1;if(t.toolUseId)for(let i=e.length-1;i>=0;i--){let a=e[i];if(a?.role!==`assistant`||!a.toolCalls?.length)continue;let o=a.toolCalls.findIndex(e=>e.id===t.toolUseId);if(o!==-1){n=i,r=o;break}}if(n===-1){if(n=e.findLastIndex(e=>e.role===`assistant`&&e.toolCalls&&e.toolCalls.length>0),n===-1)return e;let t=e[n];if(!t?.toolCalls)return e;r=t.toolCalls.findLastIndex(e=>p(e))}if(r===-1)return e;let i=e[n],a=i.toolCalls[r];if(!a)return e;let o=t.imageDataList===void 0?t.imageData===void 0?void 0:[t.imageData]:t.imageDataList,s=t.imageData===void 0?o?.[0]:t.imageData,c=[...i.toolCalls],l={...a,result:t.result,isError:t.isError,riskLevel:t.riskLevel,riskReason:t.riskReason,matchedTrustRuleId:t.matchedTrustRuleId,approvalMode:t.approvalMode,approvalReason:t.approvalReason,riskThreshold:t.riskThreshold,riskAllowlistOptions:t.riskAllowlistOptions,riskScopeOptions:t.riskScopeOptions,riskDirectoryScopeOptions:t.riskDirectoryScopeOptions,...s===void 0?{}:{imageData:s},...o===void 0?{}:{imageDataList:o},...t.activityMetadata===void 0?{}:{activityMetadata:t.activityMetadata},...t.answeredQuestion===void 0?{}:{answeredQuestion:t.answeredQuestion},...t.errorCode===void 0?{}:{errorCode:t.errorCode},completedAt:t.completedAt??Date.now(),streamedOutput:void 0};c[r]=l;let u=[...e];return u[n]={...i,toolCalls:c,contentBlocks:q(i.contentBlocks,l)},u}var rn=16384;function an(e){return e.length<=16384?e:e.slice(e.length-rn)}function on(e,t){if(!t.chunk)return e;let n=-1,r=-1;if(t.toolUseId){if(t.messageId){let i=V(e,t.messageId);if(i>=0){let a=e[i].toolCalls?.findIndex(e=>e.id===t.toolUseId)??-1;a!==-1&&(n=i,r=a)}}if(n===-1)for(let i=e.length-1;i>=0;i--){let a=e[i];if(a?.role!==`assistant`||!a.toolCalls?.length)continue;let o=a.toolCalls.findIndex(e=>e.id===t.toolUseId);if(o!==-1){n=i,r=o;break}}}else{if(n=e.findLastIndex(e=>e.role===`assistant`&&e.toolCalls&&e.toolCalls.length>0),n===-1)return e;let t=e[n];if(!t?.toolCalls)return e;r=t.toolCalls.findLastIndex(e=>p(e))}if(n===-1||r===-1)return e;let i=e[n],a=i.toolCalls[r];if(!a)return e;let o={...a,streamedOutput:an((a.streamedOutput??``)+t.chunk)},s=[...i.toolCalls];s[r]=o;let c=[...e];return c[n]={...i,toolCalls:s,contentBlocks:q(i.contentBlocks,o)},c}function sn(e,t,n,r=Date.now()){let i=H(e,n),a=[...e];if(i===-1)a.push({id:n??crypto.randomUUID(),...n?{}:{isOptimistic:!0},role:`assistant`,surfaces:[t],contentOrder:[{type:`surface`,id:t.surfaceId}],contentBlocks:[{type:`surface`,surface:t}],timestamp:r});else{let r=U(e[i],n);if(r.contentOrder?.some(e=>e.type===`surface`&&e.id===t.surfaceId)||r.surfaces?.some(e=>e.surfaceId===t.surfaceId))return e;a[i]={...r,surfaces:[...r.surfaces??[],t],contentOrder:[...r.contentOrder??[],{type:`surface`,id:t.surfaceId}],contentBlocks:E(r.contentBlocks,t)}}return a}function cn(e,t,n){let r=H(e,n);if(r===-1)return e;let i=e[r];if(i.pendingVisualToolUseIds?.includes(t))return e;let a=[...e];return a[r]={...U(i,n),pendingVisualToolUseIds:[...i.pendingVisualToolUseIds??[],t]},a}function Y(e,t={}){let n=t.toolUseId===void 0&&t.messageId!==void 0?H(e,t.messageId):void 0,r=!1,i=e.map((e,i)=>{let a=e.pendingVisualToolUseIds;if(!a||a.length===0||n!==void 0&&i!==n)return e;let o=t.toolUseId===void 0?[]:a.filter(e=>e!==t.toolUseId);if(o.length===a.length)return e;r=!0;let s={...e};return o.length===0?delete s.pendingVisualToolUseIds:s.pendingVisualToolUseIds=o,s});return r?i:e}function ln(e,t,n){for(let r=e.length-1;r>=0;r--){let i=e[r],a=i.surfaces?.findIndex(e=>e.surfaceId===t)??-1;if(a===-1)continue;let o=i.surfaces[a],s={...o.data,...n};o.data.templateData&&n.templateData&&typeof o.data.templateData==`object`&&typeof n.templateData==`object`&&(s.templateData={...o.data.templateData,...n.templateData});let c={...o,data:s},l=[...e],u=[...i.surfaces];return u[a]=c,l[r]={...i,surfaces:u,contentBlocks:E(i.contentBlocks,c)},l}return e}function un(e,t){for(let n=e.length-1;n>=0;n--){if(!e[n].surfaces?.some(e=>e.surfaceId===t))continue;let r=[...e];return r[n]={...e[n],surfaces:e[n].surfaces?.filter(e=>e.surfaceId!==t),contentOrder:e[n].contentOrder?.filter(e=>!(e.type===`surface`&&e.id===t)),contentBlocks:Pe(e[n].contentBlocks,t)},r}return e}function dn(e,t,n){for(let r=e.length-1;r>=0;r--){let i=e[r].surfaces?.find(e=>e.surfaceId===t);if(!i)continue;let a={...i,completed:!0,completionSummary:n},o=[...e];return o[r]={...e[r],surfaces:e[r].surfaces?.map(e=>e.surfaceId===t?a:e),contentBlocks:E(e[r].contentBlocks,a)},o}return e}var fn=[`choice`,`oauth_connect`,`form`,`confirmation`,`file_upload`,`card`,`list`,`table`,`browser_view`,`task_preferences`];function pn(e){return e==null||e.hasPendingConfirmation||e.hasUncompletedVisibleSurface}function mn(e,t){let n=!1,r=e.map(e=>{let r=ae(e,e=>e.pendingConfirmation?.requestId===t?{...e,pendingConfirmation:void 0}:e);return r!==e&&(n=!0),r});return n?r:e}function hn(e){let t=!1,n=e.map(e=>{let n=ae(e,e=>e.pendingConfirmation?{...e,pendingConfirmation:void 0}:e);return n!==e&&(t=!0),n});return t?n:e}function gn(e,t){let n=new Set;for(let e of t)if(e.surfaces)for(let t of e.surfaces)ie(t)&&n.add(t.surfaceId);return n.size===0?{updatedMessages:e,dismissedIds:n}:{updatedMessages:e.map(e=>Ie(e,e=>!n.has(e.surfaceId))),dismissedIds:n}}function _n(e,t,n,r,i){for(let a=e.length-1;a>=0;a--){let o=e[a].surfaces?.find(e=>e.surfaceId===t);if(!o)continue;if(!fn.includes(o.surfaceType)||o.completed)return e;let s=o.actions?.find(e=>e.id===n),c=n===`cancel`||n===`dismiss`,l=[...e];return l[a]=Fe(e[a],e=>e.surfaceId===t?{...e,completed:!0,completionSummary:c?`Cancelled`:r??s?.label??void 0,...i?.tone?{completionTone:i.tone}:{}}:e),l}return e}function vn(e,t,n){return e&&re[e]||t||n}function X(e){return typeof e==`string`?e:void 0}function yn(e){return typeof e==`boolean`?e:void 0}function bn(e){return Array.isArray(e)?e:void 0}function xn(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function Z(e){return Array.isArray(e)?e:void 0}function Sn(e){return{requestId:typeof e.requestId==`string`?e.requestId:``,label:X(e.label),service:X(e.service),field:X(e.field),description:X(e.description),placeholder:X(e.placeholder),allowOneTimeSend:yn(e.allowOneTimeSend),allowedTools:bn(e.allowedTools),allowedDomains:bn(e.allowedDomains),purpose:X(e.purpose)}}function Cn(e){let t={requestId:typeof e.requestId==`string`?e.requestId:``,title:X(e.title),description:X(e.description),toolName:X(e.toolName),riskLevel:X(e.riskLevel),riskReason:X(e.riskReason),allowlistOptions:Z(e.allowlistOptions),scopeOptions:Z(e.scopeOptions),directoryScopeOptions:Z(e.directoryScopeOptions),persistentDecisionsAllowed:yn(e.persistentDecisionsAllowed),input:xn(e.input),toolUseId:X(e.toolUseId)};return{confData:t,state:{...t,confirmLabel:X(e.confirmLabel),denyLabel:X(e.denyLabel)}}}function wn(){return`turn-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}function Tn(e,t){let n=Date.parse(e);return Number.isFinite(n)?n:typeof t==`number`?t:0}function En(e,t,n){switch(t.type){case`assistant_text_delta`:return qt(e,t.text,t.messageId,void 0,n);case`assistant_thinking_delta`:return Yt(e,t.thinking,t.messageId,void 0,n);case`message_complete`:return Y(Zt(e,t,n));case`user_message_echo`:return $t(e,{text:t.text,messageId:t.messageId,clientMessageId:t.clientMessageId},n);case`message_dequeued`:return Ht(e,t.requestId);case`message_requeued`:return Ut(e,t.requestId,t.position);case`message_queued_deleted`:return Wt(e,t.requestId);case`assistant_activity_state`:return t.phase===`idle`?Y(Xt(e,n)):e;case`conversation_error`:return Y(en(e,n));case`tool_use_preview_start`:return tn(e,{id:t.toolUseId,name:t.toolName,input:{},previewStartedAt:typeof t.previewStartedAt==`number`?t.previewStartedAt:n},t.messageId,n);case`tool_use_start`:return tn(e,{id:t.toolUseId??`tool-${n}`,name:t.toolName,input:t.input,startedAt:`startedAt`in t&&typeof t.startedAt==`number`?t.startedAt:n,...`previewStartedAt`in t&&typeof t.previewStartedAt==`number`?{previewStartedAt:t.previewStartedAt}:{}},t.messageId,n);case`tool_result`:return nn(Y(e,{toolUseId:t.toolUseId}),{toolUseId:t.toolUseId,result:t.result,isError:t.isError,riskLevel:t.riskLevel,riskReason:t.riskReason,matchedTrustRuleId:t.matchedTrustRuleId,approvalMode:t.approvalMode,approvalReason:t.approvalReason,riskThreshold:t.riskThreshold,riskAllowlistOptions:t.riskAllowlistOptions,riskScopeOptions:t.riskScopeOptions,riskDirectoryScopeOptions:t.riskDirectoryScopeOptions,imageData:t.imageData,imageDataList:t.imageDataList,activityMetadata:t.activityMetadata,answeredQuestion:t.answeredQuestion,errorCode:t.errorCode,completedAt:`completedAt`in t&&typeof t.completedAt==`number`?t.completedAt:n});case`tool_output_chunk`:return t.chunk?on(e,{chunk:t.chunk,toolUseId:t.toolUseId,messageId:t.messageId}):e;case`ui_surface_pending`:return cn(e,t.toolUseId,t.messageId);case`ui_surface_show`:{let r={surfaceId:t.surfaceId,surfaceType:t.surfaceType,title:t.title,data:t.data,actions:t.actions,display:t.display};return r.display=f(r),sn(r.surfaceType===`visual`?Y(e,t.toolCallId?{toolUseId:t.toolCallId}:{messageId:t.messageId}):e,r,t.messageId,n)}case`ui_surface_update`:return ln(e,t.surfaceId,t.data);case`ui_surface_dismiss`:return un(e,t.surfaceId);case`ui_surface_complete`:return dn(e,t.surfaceId,t.summary);case`confirmation_request`:return ne(e,{requestId:t.requestId,toolName:t.toolName,riskLevel:t.riskLevel,riskReason:t.riskReason,allowlistOptions:t.allowlistOptions,scopeOptions:t.scopeOptions,directoryScopeOptions:t.directoryScopeOptions,persistentDecisionsAllowed:t.persistentDecisionsAllowed,input:t.input,toolUseId:t.toolUseId}).updatedMessages;case`interaction_resolved`:return t.kind===`confirmation`||t.kind===`acp_confirmation`?mn(e,t.requestId):e;default:return e}}function Dn(e,t,n){if(e!==void 0){if(typeof n!=`number`)return e;switch(t.type){case`assistant_turn_start`:case`assistant_text_delta`:case`assistant_thinking_delta`:return!0;case`assistant_activity_state`:return t.phase!==`idle`;case`message_complete`:return!1;default:return e}}}function On(e,t){let{seq:n}=t;if(typeof n==`number`&&typeof e.seq==`number`&&n<=e.seq)return e;let r=Tn(t.emittedAt,n),i=En(e.messages,t.message,r),a=typeof n==`number`?Math.max(e.seq??-1,n):e.seq??null,o=Dn(e.processing,t.message,n);return{...e,messages:i,seq:a,processing:o}}function kn(e,t){return t.reduce(On,e)}function An(e,t){return t===null?e:kn(e,t)}var jn={hasMore:!1,oldestTimestamp:null,isLoadingOlder:!1};function Mn(){return{snapshot:null,optimisticSends:[],error:null,notice:null,isLoadingHistory:!0,transcriptPagination:{...jn},contextWindowUsage:null,ephemeralMetaResults:[],compactionCircuitOpenUntil:null,dismissedSurfaceIds:new Set,streamingMessageIds:new Set,pendingQueuedMessageIds:[],requestIdToMessageId:new Map,pendingLocalDeletions:new Set,confirmationToolCallMap:new Map,expandedToolCallIds:new Set,expandedCardIds:new Map,contextWindowUsageByConversation:new Map,previousConversationId:null,previousAssistantId:null,draftConversationIdResolution:!1}}function Q(e,t){return typeof t==`function`?t(e):t}function Nn(e,t){if(e.length===0)return e;let n=new Map;for(let e of t)for(let t of w(e))n.has(t)||n.set(t,e);let r=e.filter(e=>{let t;for(let r of w(e))if(t=n.get(r),t)break;return t?!!e.attachments?.length&&!t.attachments?.length:!0});return r.length===e.length?e:r}var $=o(a()((e,t)=>({...Mn(),seedSnapshot:(n,r)=>{let i=t().snapshot;if(r.seq==null&&i!==null&&typeof i.seq==`number`){u(`history_seed_skipped_anchorless`,{conversationId:n,liveSeq:i.seq});return}let a=ye(n,r.seq??null);if(a===null&&i!==null&&typeof i.seq==`number`&&typeof r.seq==`number`&&r.seq<i.seq){u(`history_seed_skipped_stale_anchor`,{conversationId:n,liveSeq:i.seq,fetchedSeq:r.seq});return}let o=An(r,a);e(e=>({snapshot:o,optimisticSends:Nn(e.optimisticSends,o.messages)}))},applyEnvelopeToSnapshot:t=>e(e=>e.snapshot?{snapshot:On(e.snapshot,t)}:{}),addOptimisticSend:t=>e(e=>({optimisticSends:[...e.optimisticSends,t]})),setOptimisticSends:t=>e(e=>({optimisticSends:Q(e.optimisticSends,t)})),patchSnapshotMessages:t=>e(e=>e.snapshot?{snapshot:{...e.snapshot,messages:t(e.snapshot.messages)}}:{}),setError:t=>e(e=>({error:Q(e.error,t)})),setNotice:t=>e(e=>({notice:Q(e.notice,t)})),setIsLoadingHistory:t=>e({isLoadingHistory:t}),setTranscriptPagination:t=>e(e=>({transcriptPagination:Q(e.transcriptPagination,t)})),setContextWindowUsage:t=>e(e=>({contextWindowUsage:Q(e.contextWindowUsage,t)})),setCompactionCircuitOpenUntil:t=>e(e=>({compactionCircuitOpenUntil:Q(e.compactionCircuitOpenUntil,t)})),switchToConversation:({assistantId:n,activeConversationId:r})=>{let i=t();if(i.draftConversationIdResolution){x(`draft_resolution`),e({draftConversationIdResolution:!1});return}let a=i.previousConversationId,o=!!(a&&a!==r);if(o&&a){let e=O.getState();(e.pendingSecret||e.pendingConfirmation)&&ee.getState().addAttentionConversationId(a)}let s=i.previousAssistantId!==null&&i.previousAssistantId!==n,c=s||i.previousAssistantId===null;u(`conversation_switch_reset`,{assistantId:n,conversationId:r,outgoingConversationId:a??null}),z.getState().handleConversationSwitch({previousKey:a??null,nextKey:r}),ke.getState().resetTurn(),O.getState().resetAll(),s?z.getState().fullReset():z.getState().resetAttachments();let l=c?qe(n):i.contextWindowUsageByConversation;o&&!s?Ce(r):x(`context_change`),e({snapshot:null,optimisticSends:[],ephemeralMetaResults:[],error:D(i.error)?i.error:null,notice:null,isLoadingHistory:!0,transcriptPagination:{...jn},contextWindowUsage:l.get(r)??null,compactionCircuitOpenUntil:null,dismissedSurfaceIds:Ve(n,r),streamingMessageIds:new Set,pendingQueuedMessageIds:[],requestIdToMessageId:new Map,pendingLocalDeletions:new Set,confirmationToolCallMap:new Map,expandedToolCallIds:new Set,expandedCardIds:new Map,contextWindowUsageByConversation:l,previousConversationId:r,previousAssistantId:n,draftConversationIdResolution:!1})},markDraftResolution:()=>e({draftConversationIdResolution:!0}),setConfirmationToolCall:(t,n)=>e(e=>{let r=new Map(e.confirmationToolCallMap);return r.set(t,n),{confirmationToolCallMap:r}}),deleteConfirmationToolCall:t=>e(e=>{let n=new Map(e.confirmationToolCallMap);return n.delete(t),{confirmationToolCallMap:n}}),clearConfirmationToolCallMap:()=>e({confirmationToolCallMap:new Map}),addDismissedSurfaceId:t=>e(e=>{let n=new Set(e.dismissedSurfaceIds);return n.add(t),{dismissedSurfaceIds:n}}),addDismissedSurfaceIds:t=>e(e=>{let n=new Set(e.dismissedSurfaceIds);for(let e of t)n.add(e);return{dismissedSurfaceIds:n}}),batchUpdateStreamingMessageIds:(t,n)=>e(e=>{let r=new Set(e.streamingMessageIds);for(let e of t)r.add(e);for(let e of n)r.delete(e);return{streamingMessageIds:r}}),pushPendingQueuedMessageId:t=>e(e=>({pendingQueuedMessageIds:[...e.pendingQueuedMessageIds,t]})),shiftPendingQueuedMessageId:()=>{let n=t().pendingQueuedMessageIds;if(n.length===0)return;let[r,...i]=n;return e({pendingQueuedMessageIds:i}),r},takePendingQueuedMessageId:n=>{let r=t().pendingQueuedMessageIds;if(r.includes(n))return e({pendingQueuedMessageIds:r.filter(e=>e!==n)}),n},setRequestIdMapping:(t,n)=>e(e=>{let r=new Map(e.requestIdToMessageId);return r.set(t,n),{requestIdToMessageId:r}}),popRequestIdMapping:n=>{let r=t().requestIdToMessageId,i=r.get(n);if(i!==void 0){let t=new Map(r);t.delete(n),e({requestIdToMessageId:t})}return i},addPendingLocalDeletion:t=>e(e=>{let n=new Set(e.pendingLocalDeletions);return n.add(t),{pendingLocalDeletions:n}}),consumePendingLocalDeletion:n=>{let r=t().pendingLocalDeletions;if(!r.has(n))return!1;let i=new Set(r);return i.delete(n),e({pendingLocalDeletions:i}),!0},setExpandedToolCallId:(t,n)=>e(e=>{let r=new Set(e.expandedToolCallIds);return n?r.add(t):r.delete(t),{expandedToolCallIds:r}}),setExpandedCardId:(t,n)=>e(e=>{let r=new Map(e.expandedCardIds);return r.set(t,n),{expandedCardIds:r}}),setContextWindowUsageForConversation:(t,n)=>e(e=>{let r=new Map(e.contextWindowUsageByConversation);return r.set(t,n),{contextWindowUsageByConversation:r}}),addEphemeralMetaResult:t=>e(e=>({ephemeralMetaResults:[...e.ephemeralMetaResults,t]})),clearEphemeralMetaResults:()=>e(e=>e.ephemeralMetaResults.length===0?e:{ephemeralMetaResults:[]})})));function Pn(){let e=$.use.snapshot()?.messages,t=$.use.optimisticSends(),n=$.use.dismissedSurfaceIds();return(0,m.useMemo)(()=>Ne(We(e,n),t),[e,t,n])}export{D as A,De as B,bt as C,ct as D,tt as E,Ne as F,be as G,ke as H,Me as I,ge as J,_e as K,w as L,He as M,Re as N,ot as O,Fe as P,le as Q,T as R,z as S,at as T,Ee as U,Oe as V,Te as W,me as X,ue as Y,de as Z,Bt as _,_n as a,It as b,Cn as c,pn as d,Ht as f,Wt as g,Ut as h,hn as i,Je as j,st as k,Sn as l,zt as m,$ as n,gn as o,Vt as p,ve as q,mn as r,wn as s,Pn as t,vn as u,B as v,O as w,Ft as x,Lt as y,je as z};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./useQuery-Bz-fbQ-m.js";import{n as r}from"./toast-BpuLSxyt.js";import{r as i}from"./use-is-org-ready-BmOdacs1.js";import{Ut as a}from"./react-query.gen-DxjuNs-5.js";import{L as o}from"./react-query.gen-DKb3mEwJ.js";function s(e,t){return{voices:e?.voices??[],defaultModel:e?.defaultModel??null,fetched:!!e,loading:t}}function c(e,t={}){let r=i(),{data:o,isLoading:c}=n({...a({path:{assistant_id:e??``}}),enabled:r&&!!e&&(t.enabled??!0),staleTime:6e4,retry:!1});return s(o,c)}function l(e={}){let t=i(),{data:r,isLoading:a}=n({...o(),enabled:t&&(e.enabled??!0),staleTime:6e4,retry:!1});return s(r,a)}var u=e(t(),1);function d(){let[e,t]=(0,u.useState)(null),n=(0,u.useRef)(null),i=(0,u.useRef)(0),a=()=>{i.current++,n.current?.pause(),n.current=null,t(null)};(0,u.useEffect)(()=>()=>{i.current++,n.current?.pause(),n.current=null},[]);function o(e){if(!e.sampleUrl)return;n.current?.pause();let a=++i.current,o=new Audio(e.sampleUrl);n.current=o,t(e.model);let s=()=>{i.current===a&&t(null)};o.onended=s,o.onerror=s,o.play().catch(()=>{i.current===a&&(r.error(`Could not play the voice sample.`),t(null))})}return{previewingModel:e,play:o,stop:a}}export{c as n,l as r,d as t};
1
+ import{o as e}from"./chunk-jRWAZmH_.js";import{t}from"./react-BFJW0bSv.js";import{t as n}from"./useQuery-Bz-fbQ-m.js";import{n as r}from"./toast-BpuLSxyt.js";import{r as i}from"./use-is-org-ready-CQntk0MX.js";import{Ut as a}from"./react-query.gen-DxjuNs-5.js";import{L as o}from"./react-query.gen-DKb3mEwJ.js";function s(e,t){return{voices:e?.voices??[],defaultModel:e?.defaultModel??null,fetched:!!e,loading:t}}function c(e,t={}){let r=i(),{data:o,isLoading:c}=n({...a({path:{assistant_id:e??``}}),enabled:r&&!!e&&(t.enabled??!0),staleTime:6e4,retry:!1});return s(o,c)}function l(e={}){let t=i(),{data:r,isLoading:a}=n({...o(),enabled:t&&(e.enabled??!0),staleTime:6e4,retry:!1});return s(r,a)}var u=e(t(),1);function d(){let[e,t]=(0,u.useState)(null),n=(0,u.useRef)(null),i=(0,u.useRef)(0),a=()=>{i.current++,n.current?.pause(),n.current=null,t(null)};(0,u.useEffect)(()=>()=>{i.current++,n.current?.pause(),n.current=null},[]);function o(e){if(!e.sampleUrl)return;n.current?.pause();let a=++i.current,o=new Audio(e.sampleUrl);n.current=o,t(e.model);let s=()=>{i.current===a&&t(null)};o.onended=s,o.onerror=s,o.play().catch(()=>{i.current===a&&(r.error(`Could not play the voice sample.`),t(null))})}return{previewingModel:e,play:o,stop:a}}export{c as n,l as r,d as t};