orc-ai 0.1.63 → 0.1.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/index.js +897 -803
- package/dist/skills/orc-platform/SKILL.md +1 -1
- package/dist/skills/orc-platform/references/html-kit.md +154 -0
- package/dist/skills/orc-platform/references/scratchpads.md +6 -2
- package/dist/web/assets/{Agents-DmrIiUAL.js → Agents-G5dt5_s6.js} +2 -2
- package/dist/web/assets/Audit-De9E5Tfd.js +1 -0
- package/dist/web/assets/ChatUiRenderer-B1D3eTfy.js +4 -0
- package/dist/web/assets/ConfirmDialog-Cp1PcD4R.js +1 -0
- package/dist/web/assets/{Dashboard-Dh9P-zTd.js → Dashboard-DWorNfLX.js} +1 -1
- package/dist/web/assets/DocumentWorkspace-DZI0NvGD.js +1 -0
- package/dist/web/assets/FileEditor-CarhD1G9.js +1 -0
- package/dist/web/assets/{IntegrationCallback-CUZ5N-88.js → IntegrationCallback-CuUd_OOy.js} +1 -1
- package/dist/web/assets/JobWebhooks-8emXf4c1.js +1 -0
- package/dist/web/assets/Jobs-ComQ_dFU.js +3 -0
- package/dist/web/assets/Knowledge-Cm2ZVDRs.js +1 -0
- package/dist/web/assets/{MarkdownRenderer-fsBqw-wB.js → MarkdownRenderer-CHALCapQ.js} +5 -5
- package/dist/web/assets/{NativeFolderField-BuHwey26.js → NativeFolderField-CdaIEZa-.js} +1 -1
- package/dist/web/assets/PackageCatalog-CcPUM8f8.js +8 -0
- package/dist/web/assets/{PackageRunDialog-C8m43ZhJ.js → PackageRunDialog-DV1E6WX3.js} +19 -19
- package/dist/web/assets/{Pager-Dbs7fj3d.js → Pager-DZtibAkl.js} +1 -1
- package/dist/web/assets/Projects-BxrWujMD.js +3 -0
- package/dist/web/assets/{ResponsiveFilters-HzhzzjyL.js → ResponsiveFilters-C3siPRT-.js} +1 -1
- package/dist/web/assets/{ResumeActions-e6YpUhEq.js → ResumeActions-0eJvpGmW.js} +1 -1
- package/dist/web/assets/Rules-CHdgAIUd.js +18 -0
- package/dist/web/assets/{ScratchpadDiagramEditor-DkW_SmM8.js → ScratchpadDiagramEditor-6R8JsXS3.js} +1 -1
- package/dist/web/assets/Scratchpads-uD9R68sw.js +10 -0
- package/dist/web/assets/{SessionHomeLink-BAWO86fJ.js → SessionHomeLink-CMCZb7Vy.js} +1 -1
- package/dist/web/assets/Sessions-BD9AlzAN.js +4 -0
- package/dist/web/assets/Settings-Bt1even4.js +14 -0
- package/dist/web/assets/Skills-BSsN8kq-.js +3 -0
- package/dist/web/assets/{SourceEditor-B6pT-Rc0.js → SourceEditor-V5vL7Aof.js} +4 -4
- package/dist/web/assets/{TagInput-ChFu05vJ.js → TagInput-DU4zMpED.js} +1 -1
- package/dist/web/assets/TaskDetailSheet-C8dGHMsb.js +1 -0
- package/dist/web/assets/{Tasks-CC92r1kL.js → Tasks-wxRlyx-L.js} +6 -6
- package/dist/web/assets/Terminals-BFRG72xa.js +2 -0
- package/dist/web/assets/{ViewHeader-D-lhe59Y.js → ViewHeader-CKIR1ZTZ.js} +1 -1
- package/dist/web/assets/{Webhooks-BxpA1QBK.js → Webhooks-Bg3pm4rJ.js} +1 -1
- package/dist/web/assets/{badge-BqTVr27Z.js → badge-DfvoXiLp.js} +1 -1
- package/dist/web/assets/check-DrnDUgkq.js +1 -0
- package/dist/web/assets/chevron-down-C1WyGsAA.js +1 -0
- package/dist/web/assets/chevron-up-ZnWliPW7.js +1 -0
- package/dist/web/assets/{chunk-OB3PAWPO-1IihCzFx.js → chunk-OB3PAWPO-BD6ylT0A.js} +1 -1
- package/dist/web/assets/{circle-check-DWP3C_MJ.js → circle-check-CnioupGj.js} +1 -1
- package/dist/web/assets/{client-954dj6K2.js → client-DigivyCS.js} +1 -1
- package/dist/web/assets/{download-BD7lYc4O.js → download-CNwtbYo1.js} +1 -1
- package/dist/web/assets/{highlighted-body-JLMTFACH-CAMR1LA5.js → highlighted-body-JLMTFACH-dpkthrjz.js} +1 -1
- package/dist/web/assets/{index-XIDqokJX.js → index-Bc-Nka6Y.js} +50 -49
- package/dist/web/assets/index-BrDTqMtQ.css +1 -0
- package/dist/web/assets/{live-sessions-C6D_vHcN.js → live-sessions-BG3mNXnQ.js} +1 -1
- package/dist/web/assets/{maximize-2-BUxUwGbf.js → maximize-2-CcupqYE8.js} +1 -1
- package/dist/web/assets/mermaid-WFAXDIZX-BX9NWlJb.js +1 -0
- package/dist/web/assets/orc-kit-BZEVA3Qv.js +317 -0
- package/dist/web/assets/{scratchpad-kinds-B0Y6McXL.js → scratchpad-kinds-RGciqVT1.js} +1 -1
- package/dist/web/assets/{scratchpad-routes-BtsIfhUW.js → scratchpad-routes-Q2TRGUnx.js} +1 -1
- package/dist/web/assets/send-0IpktRLv.js +1 -0
- package/dist/web/assets/{upload-CPf6QZHl.js → upload-CaDKCpy5.js} +1 -1
- package/dist/web/assets/{useDetailRoute-DOhAbdV7.js → useDetailRoute-B-xjWsyW.js} +1 -1
- package/dist/web/assets/{useIntegrations-C0MAVKB4.js → useIntegrations-C6zijOMH.js} +1 -1
- package/dist/web/assets/{useJobs-BlWldKP0.js → useJobs-Dly6n-pv.js} +1 -1
- package/dist/web/assets/{useMemories-CAf8HcOI.js → useMemories-jakANU6m.js} +1 -1
- package/dist/web/assets/useProjectScope-DpgzthH7.js +1 -0
- package/dist/web/assets/{useSessions-DiUU2FN8.js → useSessions-tFa1FZ9M.js} +1 -1
- package/dist/web/assets/{view-params-DD7i9s5g.js → view-params-YEmeZppw.js} +1 -1
- package/dist/web/assets/{x-tY-z3woy.js → x-BayoBYp_.js} +1 -1
- package/dist/web/index.html +11 -18
- package/dist/web/sw.js +26 -17
- package/package.json +1 -1
- package/dist/web/assets/Audit-DGSNmToV.js +0 -1
- package/dist/web/assets/ChatUiRenderer-Dddr55cW.js +0 -4
- package/dist/web/assets/ConfirmDialog-B5es4nUp.js +0 -1
- package/dist/web/assets/DocumentWorkspace-I81K42yx.js +0 -1
- package/dist/web/assets/FileEditor-wRs221QU.js +0 -1
- package/dist/web/assets/JobWebhooks-oaF694Af.js +0 -1
- package/dist/web/assets/Jobs-Lmyw5700.js +0 -3
- package/dist/web/assets/Knowledge-V4JuZnUZ.js +0 -1
- package/dist/web/assets/Markdown-D-AaJ4bU.js +0 -2
- package/dist/web/assets/MarkdownEditor-5U4_BhYm.js +0 -2
- package/dist/web/assets/PackageCatalog-BC-yAjPQ.js +0 -8
- package/dist/web/assets/Projects-C280nbHV.js +0 -3
- package/dist/web/assets/Rules-BwsnRQBe.js +0 -18
- package/dist/web/assets/Scratchpads-BtUKOhup.js +0 -10
- package/dist/web/assets/Sessions-Cn2dIJBt.js +0 -4
- package/dist/web/assets/Settings-Bb01CfFw.js +0 -14
- package/dist/web/assets/Skills-Vw41zPVg.js +0 -3
- package/dist/web/assets/TaskDetailSheet-DuTfo6rZ.js +0 -1
- package/dist/web/assets/Terminals-dCbgpRsm.js +0 -2
- package/dist/web/assets/check-Cg2_C_4I.js +0 -1
- package/dist/web/assets/chevron-down-KBvm_HoX.js +0 -1
- package/dist/web/assets/dialog-DNIYhwi4.js +0 -1
- package/dist/web/assets/file-kind-BYU1kv95.js +0 -1
- package/dist/web/assets/index-hvCYuRJb.css +0 -1
- package/dist/web/assets/label-Bm_d0NKL.js +0 -1
- package/dist/web/assets/mermaid-WFAXDIZX-Bzg8wVqT.js +0 -1
- package/dist/web/assets/select-cyLFVkkB.js +0 -1
- package/dist/web/assets/tabs-bEwJLtA0.js +0 -1
- package/dist/web/assets/textarea-CovStda2.js +0 -1
- package/dist/web/assets/useProjectScope-DtEj9j-P.js +0 -1
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i}from"./useMutation-CRAWY7v2.js";import{f as a,m as o,t as s,u as c}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as l}from"./button-By-NN7c7.js";import{n as u}from"./client-954dj6K2.js";import{t as d}from"./chevron-down-KBvm_HoX.js";import{t as f}from"./scratchpad-kinds-B0Y6McXL.js";import{t as p}from"./ResponsiveFilters-HzhzzjyL.js";import{t as m}from"./label-Bm_d0NKL.js";import{t as h}from"./Markdown-D-AaJ4bU.js";import{a as g,n as _,o as v,r as y,s as b,t as x}from"./dialog-DNIYhwi4.js";import{$r as S,Bt as ee,Dr as te,Fr as C,Gt as w,It as T,Jt as E,Kt as D,Lt as O,O as k,Qr as A,Rt as j,Ut as ne,Wt as M,Xt as re,Yt as N,_r as P,ai as F,bn as ie,dr as ae,dt as I,fr as L,ft as R,gr as z,gt as B,ht as V,kr as H,lr as U,mr as W,ot as oe,pn as se,pr as ce,qt as le,ut as G,wn as K,wr as q,zt as J}from"./index-XIDqokJX.js";import{t as Y}from"./StatusBadge-CKL0hTFN.js";import{c as ue,n as de}from"./scratchpad-routes-BtsIfhUW.js";import{i as fe,r as pe,s as me,t as he}from"./live-sessions-C6D_vHcN.js";import{t as ge}from"./ErrorState-DB0nWfcc.js";import{t as _e}from"./ViewHeader-D-lhe59Y.js";import{t as ve}from"./EmptyState-YM4VSLR9.js";import{t as ye}from"./Pager-Dbs7fj3d.js";import{a as be,c as xe,n as Se,o as Ce,t as we}from"./useSessions-DiUU2FN8.js";import{t as Te}from"./useProjectScope-DtEj9j-P.js";import{t as Ee}from"./ResumeActions-e6YpUhEq.js";import{t as De}from"./SessionHomeLink-BAWO86fJ.js";var X=e(t(),1),Z=n();function Oe({projectId:e}){let[t]=o(),n=a(),s=ie(),c=r(),f=oe(),[p,h]=(0,X.useState)({key:``,offset:0}),[b,S]=(0,X.useState)(null),[ee,te]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(``),[D,O]=(0,X.useState)(``),[k,A]=(0,X.useState)(e),[j,ne]=(0,X.useState)(``),[M,re]=(0,X.useState)(``),[N,F]=(0,X.useState)(``),[I,R]=(0,X.useState)(``),[B,V]=(0,X.useState)(0),H=t.get(`q`)??``,W=t.get(`agent`)??``,ce=t.get(`ended`)!==`0`,le=JSON.stringify([e,H,W]),G=p.key===le?p.offset:0,K=e=>h({key:le,offset:e}),q=i({queryKey:[`sessions`,`archive`,e,H,W,G],queryFn:()=>u.sessions.archive({q:H,...e===`all`?{}:{project_id:e},...[`claude`,`codex`].includes(W)?{agent:W}:{},offset:G,limit:20}),enabled:ce,refetchInterval:1e4}),J=i({queryKey:[`sessions`,`archive-transcript`,b?.id,b?.revision,B],queryFn:()=>u.sessions.archiveTranscript(b?.id,{revision:b?.revision,offset:B,limit:50}),enabled:!!b});async function Y(e){w(!0),E(``),O(``);try{await e(),await c.invalidateQueries({queryKey:[`sessions`]})}catch(e){E(e instanceof Error?e.message:`Request failed`)}finally{w(!1)}}async function ue(e){if(!e?.length)return;let t=f.data?.find(e=>e.id===k)?.name;t?await Y(async()=>{let n=localStorage.getItem(`orc_session_upload_source`);n||(n=crypto.randomUUID(),localStorage.setItem(`orc_session_upload_source`,n));let r=0,i=[];for(let a of Array.from(e))try{if(a.size>62914560)throw Error(`File exceeds 60 MiB`);let e=await a.text(),i=e.split(/\r?\n/).filter(e=>e.trim()).map(e=>JSON.parse(e)),o=i[0]?.type===`session_meta`,s=o?i[0].payload:i.find(e=>e.sessionId),c=await u.sessions.archiveUpload({project:t,source_id:n,agent:o?`codex`:`claude`,session_id:o?s?.id:s?.sessionId,title:a.name.slice(0,200),metadata:{cwd:s?.cwd??``,subdirectory:``,...o&&s?.git?.repository_url?{repository:s.git.repository_url}:{},...o&&s?.git?.branch?{branch:s.git.branch}:{},...o&&s?.git?.commit_hash?{commit:s.git.commit_hash}:{}},bundle:{version:1,files:[{path:`session.jsonl`,content:e}]}});[`created`,`updated`,`unchanged`,`stale`].includes(c.outcome)&&r++}catch(e){i.push(`${a.name}: ${e instanceof Error?e.message:`Upload failed`}`)}O(`${r} of ${e.length} sessions synchronized${i.length?`; ${i.length} need attention`:``}.`),i.length&&E(i.join(`
|
|
2
|
-
`))}):E(`Select a project before uploading`)}async function de(e){await Y(async()=>{if(!b)return;let r=await u.sessions.archiveResume(b.id,{revision:b.revision,repository:j,branch:M,commit:N,subdirectory:I});if(r.status!==`ready`||!r.live_session_id)throw Error(r.error||`Session preparation failed`);if(e===`terminal`){let e=await u.terminals.create({kind:b.agent,live_session_id:r.live_session_id});n(`/terminals/${e.id}`)}else{s.openThread(await u.chat.resume(r.live_session_id),{projectId:b.project_id}),S(null);let e=new URLSearchParams(t);e.set(`chat`,`open`),e.delete(`session`),n({search:e.toString()})}})}return ce?(0,Z.jsxs)(`section`,{className:`mt-4 space-y-3 border-t border-border pt-2`,"data-testid":`session-archive`,children:[D&&(0,Z.jsx)(`p`,{role:`status`,"data-testid":`archive-feedback`,className:`text-sm`,children:D}),(T||q.error)&&(0,Z.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-error`,children:T||q.error?.message}),q.data?.degraded&&(0,Z.jsx)(`p`,{role:`status`,"data-testid":`archive-degraded`,className:`text-xs text-outline`,children:q.data.degraded}),!!q.data?.pending_chunks&&(0,Z.jsxs)(`p`,{className:`text-xs text-outline`,children:[q.data.pending_chunks,` passages waiting for embeddings`]}),q.data?.sessions.some(e=>e.embedding_error)&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:`Some archived sessions could not be indexed. Open archived sessions for details.`}),(0,Z.jsxs)(`details`,{"data-testid":`archive-disclosure`,children:[(0,Z.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-2 text-sm text-outline lg:min-h-8`,children:[`Archived sessions`,q.data?` · ${G+q.data.sessions.length}${q.data.has_more?`+`:``}`:``]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Z.jsx)(P,{label:`Archived sessions`,children:`Uploaded history stays available after the source computer is offline.`}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(l,{variant:`outline`,size:`sm`,"data-testid":`archive-index`,disabled:C,onClick:()=>void Y(async()=>{let t=await u.sessions.archiveIndex(e===`all`||e===`unassigned`?void 0:e);O(`${t.indexed} sessions indexed; ${t.failed} failed; ${t.skipped} skipped.`)}),children:`Index discovered sessions`}),(0,Z.jsx)(l,{size:`sm`,"data-testid":`archive-upload-open`,onClick:()=>{A(e),te(!0)},children:`Upload sessions`})]})]}),(0,Z.jsxs)(`div`,{className:`divide-y divide-border`,"data-testid":`archive-records`,children:[q.isLoading&&(0,Z.jsx)(`p`,{className:`p-4 text-sm`,children:`Loading archived sessions…`}),!q.isLoading&&!q.data?.sessions.length&&(0,Z.jsx)(`p`,{className:`p-4 text-sm text-outline`,children:`No archived sessions match this view.`}),q.data?.sessions.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`archive-session-row`,"data-archive-id":e.id,className:`block w-full p-3 text-left hover:bg-surface-container`,onClick:()=>{S(e),V(0),ne(e.metadata.repository??``),re(e.metadata.branch??``),F(e.metadata.commit??``),R(e.metadata.subdirectory)},children:[(0,Z.jsx)(`span`,{className:`block text-sm font-medium`,children:e.title}),(0,Z.jsxs)(`span`,{className:`text-xs text-outline`,children:[e.agent,` · ended · `,new Date(e.updated_at).toLocaleString(),` · revision`,` `,e.revision,` · `,e.metadata.cwd]}),e.passages.map(e=>(0,Z.jsx)(`span`,{className:`mt-1 block text-sm text-outline`,children:e.snippet},e.citation)),e.embedding_error&&(0,Z.jsx)(`span`,{className:`block text-xs text-error`,children:e.embedding_error})]},e.id))]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,Z.jsx)(l,{variant:`ghost`,disabled:G===0,onClick:()=>K(Math.max(0,G-20)),children:`Previous`}),(0,Z.jsx)(l,{variant:`ghost`,disabled:!q.data?.has_more,onClick:()=>K(G+20),children:`Next`})]})]}),(0,Z.jsx)(x,{open:ee,onOpenChange:te,children:(0,Z.jsxs)(_,{children:[(0,Z.jsxs)(g,{children:[(0,Z.jsx)(v,{children:`Upload session histories`}),(0,Z.jsx)(y,{children:`Select an existing project and native Claude/Codex JSONL files. This stores history without starting a terminal. For large collections, use the orc-platform sync script.`})]}),(0,Z.jsx)(m,{htmlFor:`archive-project`,children:`Project`}),(0,Z.jsxs)(`select`,{id:`archive-project`,"data-testid":`archive-project`,value:k,onChange:e=>A(e.target.value),className:`rounded border border-outline-variant bg-surface p-2`,children:[(0,Z.jsx)(`option`,{value:`all`,children:`Select a project`}),f.data?.map(e=>(0,Z.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Z.jsx)(z,{"data-testid":`archive-files`,type:`file`,multiple:!0,accept:`.jsonl`,disabled:C||!f.data?.some(e=>e.id===k),onChange:e=>void ue(e.target.files)}),C&&(0,Z.jsx)(`p`,{role:`status`,children:`Uploading…`}),D&&(0,Z.jsx)(`p`,{role:`status`,"data-testid":`archive-upload-feedback`,children:D}),T&&(0,Z.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-error`,children:T})]})}),(0,Z.jsx)(x,{open:!!b,onOpenChange:e=>{e||S(null)},children:(0,Z.jsxs)(_,{className:`max-h-[90vh] max-w-3xl overflow-y-auto`,"data-testid":`archive-detail`,children:[(0,Z.jsxs)(g,{children:[(0,Z.jsx)(v,{children:b?.title}),(0,Z.jsxs)(y,{children:[`Archived history · revision `,b?.revision,`. Prepare a destination checkout to continue in a terminal.`]})]}),J.error&&(0,Z.jsx)(`p`,{role:`alert`,children:J.error.message}),J.data?.turns.map(e=>(0,Z.jsxs)(`div`,{className:`border-b border-outline-variant py-2`,"data-testid":`archive-turn`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-outline`,children:e.role}),(0,Z.jsx)(se,{plain:!0,children:e.blocks.map(e=>e.type===`tool_use`?`${e.name}\n${e.input}\n${e.result??``}`:e.text).join(`
|
|
3
|
-
`)})]},e.index)),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(l,{variant:`ghost`,disabled:!B,onClick:()=>V(Math.max(0,B-50)),children:`Previous messages`}),(0,Z.jsx)(l,{variant:`ghost`,disabled:B+50>=(J.data?.total??0),onClick:()=>V(B+50),children:`Next messages`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 border-t border-outline-variant pt-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-medium`,children:`Continue on ORC`}),(0,Z.jsx)(`p`,{className:`text-xs text-outline`,children:`Use the pushed repository, branch and exact commit for the work you want to continue. The destination project must have its repository configured.`}),(0,Z.jsx)(m,{htmlFor:`archive-repository`,children:`Repository`}),(0,Z.jsx)(z,{id:`archive-repository`,"data-testid":`archive-repository`,value:j,onChange:e=>ne(e.target.value)}),(0,Z.jsx)(m,{htmlFor:`archive-branch`,children:`Branch`}),(0,Z.jsx)(z,{id:`archive-branch`,"data-testid":`archive-branch`,value:M,onChange:e=>re(e.target.value)}),(0,Z.jsx)(m,{htmlFor:`archive-commit`,children:`Pushed commit`}),(0,Z.jsx)(z,{id:`archive-commit`,"data-testid":`archive-commit`,value:N,onChange:e=>F(e.target.value)}),(0,Z.jsx)(m,{htmlFor:`archive-subdirectory`,children:`Repository subdirectory`}),(0,Z.jsx)(z,{id:`archive-subdirectory`,"data-testid":`archive-subdirectory`,value:I,onChange:e=>R(e.target.value),placeholder:`Repository root`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(l,{"data-testid":`archive-resume`,disabled:C||!j||!M||!/^[a-f0-9]{40}$/i.test(N),onClick:()=>void de(`chat`),children:C?`Preparing…`:`Resume`}),(0,Z.jsxs)(U,{children:[(0,Z.jsx)(L,{asChild:!0,children:(0,Z.jsx)(l,{variant:`outline`,size:`icon`,"aria-label":`More resume options`,"data-testid":`archive-resume-menu`,children:(0,Z.jsx)(d,{size:14})})}),(0,Z.jsx)(ae,{className:`w-40 p-1`,align:`start`,children:(0,Z.jsx)(l,{variant:`ghost`,className:`w-full justify-start`,"data-testid":`archive-resume-terminal`,disabled:C||!j||!M||!/^[a-f0-9]{40}$/i.test(N),onClick:()=>void de(`terminal`),children:`Terminal`})})]})]}),T&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:T})]})]})})]}):null}function ke({text:e,query:t}){let n=t.trim();if(n.length<2)return(0,Z.jsx)(Z.Fragment,{children:e});let r=e.split(RegExp(`(${he(n)})`,`gi`));return(0,Z.jsx)(Z.Fragment,{children:r.map((e,t)=>e.toLowerCase()===n.toLowerCase()?(0,Z.jsx)(`mark`,{className:`bg-primary/30 text-on-surface rounded-xs`,children:e},t):e)})}function Ae(e,t){if(!e||e.input_tokens===0)return null;let n=new Intl.NumberFormat(void 0,{maximumFractionDigits:1}).format(e.cached_input_tokens/e.input_tokens*100),r=e.may_be_cold_after!==null&&t>=Date.parse(e.may_be_cold_after);return{label:r?`Cache may need rebuilding · ${n}% last reported`:`${n}% cached input`,cold:r}}var Q=new Intl.NumberFormat;function je({sessionId:e,live:t}){let{data:n,isError:r,refetch:a}=i({queryKey:[`session-cache`,e,t],queryFn:()=>u.sessions.cacheUsage(e),staleTime:15e3,refetchInterval:t?15e3:!1,retry:1}),[o,s]=(0,X.useState)(Date.now);if((0,X.useEffect)(()=>{if(!n?.latest?.may_be_cold_after)return;s(Date.now());let e=Date.parse(n.latest.may_be_cold_after)-Date.now();if(e<=0)return;let t=setTimeout(()=>s(Date.now()),Math.min(e,2147483647));return()=>clearTimeout(t)},[n?.latest?.may_be_cold_after]),r)return(0,Z.jsx)(`button`,{type:`button`,className:`min-h-11 text-xs text-muted-foreground underline`,onClick:()=>void a(),children:`Retry cache usage`});let c=Ae(n?.latest??null,o),l=n?.latest;return!c||!l?null:(0,Z.jsxs)(`details`,{"data-testid":`session-cache`,className:`group mt-2 text-xs`,children:[(0,Z.jsxs)(`summary`,{"data-testid":`session-cache-indicator`,title:`Cache reuse reported for the last request with usage data.`,className:`flex min-h-8 max-md:min-h-11 cursor-pointer items-center gap-2 rounded-sm focus-visible:outline-2 focus-visible:outline-ring ${c.cold?`text-warning`:`text-muted-foreground`}`,children:[(0,Z.jsx)(d,{size:12,"aria-hidden":`true`,className:`group-open:rotate-180`}),c.label]}),(0,Z.jsxs)(`dl`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 pb-2 tabular-nums`,children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Last reported input`}),(0,Z.jsxs)(`dd`,{children:[Q.format(l.input_tokens),` tokens`]}),(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Read from cache`}),(0,Z.jsxs)(`dd`,{children:[Q.format(l.cached_input_tokens),` tokens`]}),l.cache_write_tokens!==null&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Uncached input`}),(0,Z.jsxs)(`dd`,{children:[Q.format(l.input_tokens-l.cached_input_tokens-l.cache_write_tokens),` `,`tokens`]}),(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Written to cache`}),(0,Z.jsxs)(`dd`,{children:[Q.format(l.cache_write_tokens),` tokens`]})]}),l.recorded_at&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Recorded`}),(0,Z.jsx)(`dd`,{children:new Date(l.recorded_at).toLocaleString()})]}),n?.totals&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`dt`,{className:`text-muted-foreground`,children:`Reported session cached input`}),(0,Z.jsxs)(`dd`,{children:[Q.format(n.totals.cached_input_tokens),` /`,` `,Q.format(n.totals.input_tokens)]})]})]}),c.cold&&(0,Z.jsx)(`p`,{className:`mb-2 max-w-prose text-muted-foreground`,children:`The recorded cache lifetime has elapsed since this activity. The next request may rebuild some cached input; reuse also depends on the prompt and other requests.`})]})}function Me({projectId:e,pending:t,onSelect:n}){let[r,a]=(0,X.useState)(``),[o,s]=(0,X.useState)(!1),[c,d]=(0,X.useState)(null),f=i({queryKey:[`tasks`,`session-picker`,e],queryFn:()=>u.tasks.list({...e?{project_id:e}:{},limit:100})});async function p(e){d(null);try{await n(e)}catch(e){d(e instanceof Error?e.message:`Could not link task`)}}async function m(){s(!0),d(null);try{await p((await u.tasks.get(r.trim())).id)}catch(e){d(e instanceof Error?e.message:`Task lookup failed`)}finally{s(!1)}}let h=(f.data?.tasks??[]).filter(e=>`${e.title} ${e.id}`.toLowerCase().includes(r.trim().toLowerCase()));return(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(z,{"data-testid":`session-task-search`,"aria-label":`Search tasks or enter a task ID`,value:r,onChange:e=>{a(e.target.value),d(null)},placeholder:`Search recent tasks or paste a task ID`}),(0,Z.jsxs)(`p`,{className:`text-xs text-outline`,children:[`Up to 100 recent tasks`,e?` in this project`:` across projects`,`. Older or other-project tasks can be linked by exact ID.`]}),c&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:c}),f.error?(0,Z.jsx)(ge,{message:f.error.message,onRetry:()=>f.refetch()}):f.isLoading?(0,Z.jsx)(`p`,{role:`status`,children:`Loading tasks…`}):(0,Z.jsxs)(`div`,{className:`max-h-72 overflow-y-auto divide-y divide-border`,children:[h.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`session-task-option`,"data-task-id":e.id,disabled:t||o,onClick:()=>void p(e.id),className:`w-full min-h-11 py-2 text-left hover:bg-surface-highest disabled:opacity-50`,children:[(0,Z.jsx)(`span`,{className:`block text-sm wrap-break-word`,children:e.title}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-xs text-outline`,children:[(0,Z.jsx)(Y,{status:e.status,className:`px-0`}),e.id]})]},e.id)),h.length===0&&(0,Z.jsx)(`p`,{className:`py-4 text-sm text-outline`,children:`No recent task matches. Paste its exact ID to look it up.`})]}),r.trim()&&(0,Z.jsx)(l,{variant:`outline`,disabled:t||o,onClick:()=>void m(),children:o?`Looking up…`:`Link by exact ID`})]})}function Ne({session:e,linkTestId:t=`open-task`}){let[n]=o(),[r,i]=(0,X.useState)(!1),a=we(),c=n.get(`project`)??e.project_id;async function u(t){try{await a.mutateAsync({id:e.id,taskId:t}),i(!1)}catch{}}return(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[e.task&&(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(s,{"data-testid":t,to:me(`/tasks/${e.task.id}`,c),className:`block max-w-64 truncate text-sm text-primary hover:underline`,title:e.task.title,children:e.task.title}),(0,Z.jsx)(Y,{status:e.task.status,className:`px-0`})]}),(0,Z.jsxs)(x,{open:r,onOpenChange:e=>{i(e),e&&a.reset()},children:[(0,Z.jsx)(b,{asChild:!0,children:(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`link-task`,className:`inline-flex min-h-9 items-center gap-1.5 text-xs text-outline hover:text-on-surface`,children:[e.task?(0,Z.jsx)(H,{size:12}):(0,Z.jsx)(C,{size:13}),e.task?`Change task`:`Link task`]})}),(0,Z.jsxs)(_,{"data-testid":`session-task-dialog`,className:`max-h-[85dvh] w-[calc(100%-2rem)] overflow-y-auto`,children:[(0,Z.jsxs)(g,{children:[(0,Z.jsx)(v,{children:`Link a task`}),(0,Z.jsxs)(y,{children:[`Choose a recent task for `,e.name??`this session`,`, or paste an exact task ID.`]})]}),a.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:a.error.message}),(0,Z.jsx)(Me,{projectId:e.project_id,pending:a.isPending,onSelect:u}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.task&&(0,Z.jsx)(l,{variant:`outline`,"data-testid":`session-task-unlink`,disabled:a.isPending,onClick:()=>void u(null),children:`Unlink task`})})]})]})]})}function Pe({session:e}){let[t]=o(),{data:n}=ue({session_id:e.session_id??void 0,limit:20},{enabled:!!e.session_id}),r=n?.scratchpads??[];if(r.length===0)return null;let i=t.get(`project`)??e.project_id;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,"data-testid":`session-scratchpads`,children:[(0,Z.jsx)(`span`,{className:`text-on-surface-variant`,children:`scratchpads`}),r.map(e=>{let t=f[e.kind].icon;return(0,Z.jsxs)(s,{to:me(de(e.id),i),"data-testid":`session-scratchpad-link`,className:`inline-flex max-w-56 items-center gap-1 text-primary hover:underline`,title:e.title,children:[(0,Z.jsx)(t,{size:12,"aria-hidden":!0,className:`shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.title})]},e.id)})]})}var Fe=`session-search`,Ie={user:`border-border/65`,assistant:`border-border/65`,tool:`border-border/65 bg-transparent`,system:`border-border/65 bg-transparent`},Le=[`command`,`cmd`,`file_path`,`path`,`pattern`,`query`,`url`,`description`];function Re(e){try{let t=JSON.parse(e);for(let e of Le)if(typeof t[e]==`string`)return t[e]}catch{}return e}function ze(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Be(e,t,n){(0,X.useEffect)(()=>{let n=e.current,r=CSS.highlights,i=window.Highlight;if(!n||!r||!i)return;let a=t.trim().toLowerCase(),o=()=>{if(r.delete(Fe),a.length<2)return;let e=[],t=document.createTreeWalker(n,NodeFilter.SHOW_TEXT);for(let n=t.nextNode();n;n=t.nextNode()){let t=n.textContent?.toLowerCase()??``;for(let r=t.indexOf(a);r>=0;r=t.indexOf(a,r+a.length)){let t=new Range;t.setStart(n,r),t.setEnd(n,r+a.length),e.push(t)}}e.length>0&&r.set(Fe,new i(...e))};o();let s,c=new MutationObserver(()=>{clearTimeout(s),s=setTimeout(o,150)});return c.observe(n,{childList:!0,subtree:!0,characterData:!0}),()=>{clearTimeout(s),c.disconnect(),r.delete(Fe)}},[e,t,n])}function Ve({block:e,open:t}){let n=e.result!==void 0;return(0,Z.jsxs)(`details`,{open:t||void 0,"data-testid":`tool-box`,className:`border-l border-border bg-background`,children:[(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer items-center gap-2 px-2 py-1.5 font-label text-xs font-medium text-outline hover:text-on-surface`,children:[(0,Z.jsx)(`span`,{className:`text-secondary shrink-0`,children:e.name}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono normal-case tracking-normal text-on-surface-variant`,children:Re(e.input)}),(0,Z.jsx)(`span`,{className:`shrink-0 ${n?`text-outline`:`text-tertiary`}`,children:n?`done`:`no result`})]}),(0,Z.jsxs)(`div`,{className:`space-y-2 border-t border-border px-2 py-2`,children:[(0,Z.jsx)(`div`,{className:`font-label text-[10px] font-medium text-outline`,children:`input`}),(0,Z.jsx)(`pre`,{className:`max-h-72 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap wrap-break-word`,children:ze(e.input)}),n&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`font-label text-[10px] font-medium text-outline`,children:`result`}),(0,Z.jsx)(`pre`,{className:`max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap wrap-break-word`,children:e.result})]})]})]})}function He({block:e,matched:t}){if(e.type===`text`)return(0,Z.jsx)(se,{revealContext:t,children:e.text});if(e.type===`tool_use`)return(0,Z.jsx)(Ve,{block:e,open:t});let n=e.type===`thinking`?`thinking`:`result`;return(0,Z.jsxs)(`details`,{open:t||void 0,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface`,children:n}),e.type===`thinking`?(0,Z.jsx)(`div`,{className:`mt-1`,children:(0,Z.jsx)(h,{children:e.text})}):(0,Z.jsx)(`pre`,{className:`mt-1 max-h-96 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap wrap-break-word`,children:e.text})]})}function Ue({sessionId:e,initialQuery:t,onClose:n}){let[r,i]=(0,X.useState)(t),[a,o]=(0,X.useState)(0),{data:s}=Se(!1),c=s?.find(t=>t.id===e),l=c!==void 0&&c.status!==`stopped`,u=r.trim().length>=2?r.trim():``,{data:d,isLoading:f,isFetching:p,error:m,refetch:h,dataUpdatedAt:g}=xe(e,u),_=(0,X.useRef)(null),v=(0,X.useRef)(null),y=(0,X.useRef)(!0),b=(0,X.useRef)(0),[x,ee]=(0,X.useState)(!0),C=(0,X.useCallback)(()=>{let e=_.current;e&&(e.scrollTo({top:e.scrollHeight}),requestAnimationFrame(()=>e.scrollTo({top:e.scrollHeight})))},[]);Be(v,u,d?.turns);let w=d?.matches??[],T=w[a];(0,X.useEffect)(()=>{d&&(T===void 0?y.current&&C():(y.current=!1,document.getElementById(`turn-${T}`)?.scrollIntoView({block:`center`})))},[T,d,C]),(0,X.useEffect)(()=>{d&&x&&(b.current=d.total)},[d,x]);let E=e=>{w.length>0&&o(t=>(t+e+w.length)%w.length)};return(0,Z.jsx)(G,{open:!!e,onOpenChange:e=>!e&&n(),children:(0,Z.jsxs)(R,{side:`right`,defaultWidth:1100,resizeKey:`live-session`,"data-testid":`live-session-detail`,children:[(0,Z.jsxs)(V,{children:[(0,Z.jsx)(B,{className:`normal-case tracking-normal text-sm pr-8`,children:c?.name??`Session`}),c&&(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-5 gap-y-1 font-body text-xs text-on-surface tabular-nums`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-primary`,children:c.agent}),(0,Z.jsx)(ce,{state:W(c)}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`text-on-surface-variant`,children:`tokens `}),pe(c)]}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`text-on-surface-variant`,children:`active `}),fe(c.last_activity_at)]}),(0,Z.jsx)(Ne,{session:c,linkTestId:`detail-open-task`}),(0,Z.jsx)(Ee,{session:c}),(0,Z.jsx)(Pe,{session:c}),(0,Z.jsx)(`span`,{className:`truncate max-w-full text-on-surface-variant`,children:c.cwd})]}),e&&(0,Z.jsx)(je,{sessionId:e,live:l},e),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative min-w-[150px] flex-1`,children:[(0,Z.jsx)(q,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-outline`}),(0,Z.jsx)(`input`,{"data-testid":`transcript-search`,"aria-label":`Search this session`,value:r,onChange:e=>{i(e.target.value),o(0)},placeholder:`Search this session`,className:`w-full bg-background border border-control-border rounded-lg min-h-11 pl-7 pr-2 py-2 font-body text-xs text-on-surface`})]}),u&&(0,Z.jsx)(`span`,{"data-testid":`transcript-match-count`,className:`font-label text-xs font-medium text-outline`,children:w.length===0?`no matches`:`${a+1} / ${w.length}`}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Previous match`,onClick:()=>E(-1),className:`min-h-11 min-w-11 p-2 text-outline hover:text-on-surface`,children:(0,Z.jsx)(S,{className:`h-4 w-4`})}),(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Next match`,onClick:()=>E(1),className:`min-h-11 min-w-11 p-2 text-outline hover:text-on-surface`,children:(0,Z.jsx)(A,{className:`h-4 w-4`})}),(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`transcript-refresh`,onClick:()=>{y.current=!0,h()},className:`min-h-11 px-2 inline-flex items-center gap-1 font-label text-xs font-medium text-primary hover:text-on-surface`,children:[(0,Z.jsx)(te,{className:`h-3 w-3 ${p?`animate-spin`:``}`}),`Refresh`]})]}),d&&(0,Z.jsxs)(`div`,{"data-testid":`transcript-status`,className:`mt-2 font-body text-xs text-on-surface-variant tabular-nums`,children:[d.total,` turns`,l?` · live, updated ${new Date(g).toLocaleTimeString()}`:``]})]}),(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,Z.jsx)(I,{ref:_,onScroll:e=>{let t=e.currentTarget,n=t.scrollHeight-t.scrollTop-t.clientHeight<160;y.current=n,ee(n)},children:f?(0,Z.jsx)(`div`,{className:`space-y-4`,children:[...[,,,,,]].map((e,t)=>(0,Z.jsx)(k,{className:`h-16 w-full bg-surface-highest`},t))}):m||!d?(0,Z.jsxs)(`div`,{"data-testid":`transcript-unavailable`,className:`font-body text-xs text-outline py-12 text-center`,children:[m?`Could not load the conversation: ${m.message}`:`No conversation was recorded for this session.`,(0,Z.jsx)(`p`,{className:`mt-2`,children:`Resume actions remain available when the native agent session exists.`}),(0,Z.jsx)(`button`,{type:`button`,className:`mt-3 min-h-11 text-primary hover:underline`,onClick:()=>h(),children:`Retry conversation`})]}):(0,Z.jsx)(`div`,{ref:v,className:`space-y-3`,children:d.turns.map(e=>{let t=w.includes(e.index),n=e.blocks.map((e,n)=>(0,Z.jsx)(He,{block:e,matched:t},n));return(0,Z.jsxs)(`div`,{id:`turn-${e.index}`,"data-testid":`transcript-turn`,"data-role":e.role,style:{contentVisibility:`auto`,containIntrinsicSize:`auto 120px`},className:`border-b px-4 py-3 text-on-surface space-y-2 ${Ie[e.role]} ${e.index===T?`ring-1 ring-primary`:``}`,children:[(0,Z.jsxs)(`div`,{className:`font-label text-xs font-medium text-outline`,children:[e.role,e.time?` · ${fe(e.time)}`:``]}),e.role===`system`?(0,Z.jsxs)(`details`,{open:t||void 0,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface`,children:`injected context`}),(0,Z.jsx)(`div`,{className:`mt-2 space-y-2`,children:n})]}):n]},e.index)})})}),d&&!x&&(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`jump-to-latest`,onClick:()=>{y.current=!0,C()},className:`absolute bottom-4 right-6 inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 font-body text-xs text-primary shadow-lg hover:bg-surface-bright`,children:[(0,Z.jsx)(F,{className:`h-3.5 w-3.5`}),`Jump to latest`,d.total>b.current&&` · ${d.total-b.current} new`]})]})]})})}var We=[...K.flatMap(e=>e.sessionBackends),`cursor`],$=25;function Ge({projectId:e}){let t=c(),[n,r]=o(),i=n.get(`agent`)??``,a=n.get(`ended`)!==`0`,s=n.get(`q`)??``,u=n.get(`order`)===`asc`?`asc`:`desc`,d=n.get(`session`),f=re(n.get(`state`)),[m,h]=(0,X.useState)(s),[g,_]=(0,X.useState)({order:u,page:0}),v=g.order===u?g.page:0,y=(0,X.useCallback)(e=>_({order:u,page:e}),[u]),b=(0,X.useCallback)((e,t)=>{y(0),r(n=>{let r=new URLSearchParams(n);return t?r.set(e,t):r.delete(e),r},{replace:e===`q`})},[r,y]);(0,X.useEffect)(()=>h(s),[s]),(0,X.useEffect)(()=>{if(m===s)return;let e=`${t.pathname}${t.search}${t.hash}`,n=setTimeout(()=>{`${window.location.pathname}${window.location.search}${window.location.hash}`===e&&b(`q`,m.trim()||null)},350);return()=>clearTimeout(n)},[m,s,b,t.pathname,t.search,t.hash]);let x=s.trim().length>=2,S=e===`all`?void 0:e,C=Se(!a,S),k=be(x?s.trim():``,i,S),{data:A}=oe(),P=Ce(),F=new Map((A??[]).map(e=>[e.id,e.name])),ie=x?k.data?.hits??[]:C.data??[],ae=[...new Set([...We,...ie.map(e=>e.agent)])],I=x?k.isLoading:C.isLoading,L=x?k:C,R=ie.filter(e=>(!i||e.agent===i)&&(a||e.status!==`stopped`||e.handoff?.status===`ready`)),z=O();(0,X.useEffect)(()=>{if(!d)return;let e=[`native:${d}`];return J(e),()=>J(e)},[d]);let B=e=>new Date(e.last_activity_at??e.created_at).getTime(),V=new Map(R.map(e=>[e.id,e.id===d?W(e):ee(W(e),B(e),j(z,[`native:${e.id}`]))])),H=e=>V.get(e.id)??W(e),U=R.filter(t=>e===`all`?!0:e===`unassigned`?t.project_id===null:t.project_id===e),se=E(U.map(H)),ce=new Map(U.map(e=>[e.id,e])),G=T({items:U.filter(e=>N(H(e),f)).sort((e,t)=>{let n=new Date(e.last_activity_at??e.created_at).getTime()-new Date(t.last_activity_at??t.created_at).getTime()||e.id.localeCompare(t.id);return u===`asc`?n:-n}),id:e=>e.id,version:e=>String(B(e)),lookup:e=>ce.get(e),resetKey:[e,f,i,a,s,u].join(`
|
|
4
|
-
`),loading:I}),K=G.items,Y=Math.min(v,Math.max(0,Math.ceil(K.length/$)-1))*$,ue=e===`unassigned`?`unassigned`:F.get(e)??e;return(0,Z.jsxs)(`section`,{className:`mb-8`,"data-testid":`live-sessions`,children:[(0,Z.jsx)(_e,{compact:!0,level:2,title:x?`Search results`:`Agent sessions`,help:`Discovered from your coding agents. Working sessions update automatically; waiting sessions remain available to resume.`,meta:(0,Z.jsxs)(Z.Fragment,{children:[K.length,U.length!==R.length&&(0,Z.jsxs)(`span`,{"data-testid":`scope-hint`,className:`normal-case tracking-normal`,children:[` `,`of `,R.length,` · scope: `,ue]}),x&&k.data&&(0,Z.jsxs)(`span`,{"data-testid":`search-meta`,className:`normal-case tracking-normal`,children:[` `,`· `,(k.data.ms/1e3).toFixed(1),`s`,k.data.rg?``:` · titles and summaries only (install ripgrep for content)`]})]}),action:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(De,{label:`Open sessions view`,testId:`live-sessions-open-home`}),(0,Z.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":P.isPending?`Syncing sessions`:`Refresh sessions`,title:`Refresh sessions`,"data-testid":`sync-sessions`,disabled:P.isPending,className:`lg:size-8`,onClick:()=>P.mutate(),children:(0,Z.jsx)(te,{className:P.isPending?`animate-spin`:``})})]})}),(0,Z.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,Z.jsxs)(`div`,{className:`relative min-w-0 flex-1 lg:max-w-md`,children:[(0,Z.jsx)(q,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-outline`}),(0,Z.jsx)(`input`,{type:`search`,"data-testid":`session-search`,"aria-label":`Search agent sessions`,value:m,onChange:e=>h(e.target.value),placeholder:`Search agent sessions…`,className:`h-11 w-full rounded-md border border-control-border bg-background pl-9 pr-3 font-body text-base text-on-surface placeholder:text-outline lg:h-8 lg:text-[13px]`})]}),(0,Z.jsxs)(p,{activeCount:Number(!!i)+Number(!a)+Number(u===`asc`),children:[(0,Z.jsxs)(`select`,{"aria-label":`Sort sessions by date`,"data-testid":`session-date-sort`,value:u,onChange:e=>b(`order`,e.target.value===`asc`?`asc`:null),className:`h-11 max-w-full rounded-md border border-control-border bg-background px-3 text-base text-on-surface lg:h-8 lg:text-[13px]`,children:[(0,Z.jsx)(`option`,{value:`desc`,children:`Last active: newest`}),(0,Z.jsx)(`option`,{value:`asc`,children:`Last active: oldest`})]}),(0,Z.jsxs)(`select`,{"data-testid":`agent-filter`,"aria-label":`Agent`,className:`h-11 max-w-full rounded-md border border-control-border bg-background px-3 text-base text-on-surface lg:h-8 lg:text-[13px]`,value:i,onChange:e=>b(`agent`,e.target.value||null),children:[(0,Z.jsx)(`option`,{value:``,children:`All agents`}),ae.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))]}),(0,Z.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center gap-2 text-[13px] text-outline lg:min-h-8`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,"data-testid":`show-ended`,checked:a,onChange:e=>b(`ended`,e.target.checked?`1`:`0`)}),`Show ended`]})]})]}),(0,Z.jsxs)(`div`,{...G.listProps,children:[x?(0,Z.jsx)(le,{pending:G.pending,onApply:G.apply}):(0,Z.jsx)(D,{className:`mb-3`,value:f,counts:se,onChange:e=>b(`state`,e===`all`?null:e),children:(0,Z.jsx)(le,{pending:G.pending,onApply:G.apply})}),P.error&&(0,Z.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-error`,children:P.error.message}),L.error?(0,Z.jsx)(ge,{message:L.error.message,onRetry:()=>L.refetch()}):I?(0,Z.jsx)(`p`,{role:`status`,className:`py-8 text-sm text-outline`,children:`Loading sessions…`}):K.length===0?(0,Z.jsx)(ve,{message:x||f!==`all`?`No sessions match`:`No active agent sessions. Enable Show ended to browse previous conversations.`}):(0,Z.jsxs)(`div`,{className:`min-w-0 overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`divide-y divide-border`,"data-testid":`live-session-list`,children:K.slice(Y,Y+$).map(e=>(0,Z.jsxs)(`article`,{"data-testid":`live-session-row`,"data-session-id":e.session_id,"data-agent":e.agent,"data-state":H(e),className:`min-w-0 py-1`,children:[(0,Z.jsx)(`div`,{className:`${w} hover:bg-surface`,children:(0,Z.jsx)(`button`,{type:`button`,className:M,onClick:()=>b(`session`,e.id),children:(0,Z.jsx)(ne,{agent:e.agent,title:(0,Z.jsx)(ke,{text:e.name??`Untitled session`,query:x?s:``}),state:H(e),stateTestId:`live-status`,compact:!1})})}),(0,Z.jsxs)(`div`,{className:`grid min-w-0 grid-cols-1 items-center gap-x-3 gap-y-1 pb-1 pl-9 pr-2 text-xs text-on-surface-variant sm:grid-cols-[minmax(0,1fr)_auto]`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 sm:col-start-1`,children:[(0,Z.jsx)(`span`,{children:e.agent}),(0,Z.jsxs)(`span`,{"data-testid":`live-tokens`,children:[pe(e),` tokens`]}),(0,Z.jsx)(`span`,{children:fe(e.last_activity_at)}),(0,Z.jsx)(`span`,{children:e.project_id?F.get(e.project_id)??`Unknown project`:`Unassigned`}),e.handoff?.status===`ready`&&(0,Z.jsx)(`span`,{"data-testid":`handoff-ready`,children:`Ready to resume`})]}),e.summary&&e.summary!==e.name&&(0,Z.jsx)(`p`,{className:`truncate sm:col-start-1`,title:e.summary,children:(0,Z.jsx)(ke,{text:e.summary,query:x?s:``})}),e.snippets?.map(e=>(0,Z.jsx)(`p`,{"data-testid":`search-snippet`,className:`wrap-break-word sm:col-start-1`,children:(0,Z.jsx)(ke,{text:e,query:s})},e)),e.cwd&&(0,Z.jsx)(`p`,{className:`truncate sm:col-start-1`,title:e.cwd,children:e.cwd}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 sm:col-start-2 sm:row-start-1 sm:row-span-3 sm:justify-end`,children:[(0,Z.jsx)(Ne,{session:e}),(0,Z.jsx)(Ee,{session:e}),(0,Z.jsx)(De,{liveId:e.id,label:`Open in sessions view`,testId:`live-session-open-home`})]})]})]},e.id))}),(0,Z.jsx)(ye,{page:Y/$,pageSize:$,total:K.length,onPage:y})]})]}),(0,Z.jsx)(Ue,{sessionId:d,initialQuery:x?s.trim():``,onClose:()=>b(`session`,null)},d??`closed`)]})}function Ke({projectId:e}){let t=Te(e);return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(_e,{title:`Sessions`}),(0,Z.jsx)(Ge,{projectId:t},t),(0,Z.jsx)(Oe,{projectId:t},`archive-${t}`)]})}export{Ke as default};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./rolldown-runtime-DSDNlrLa.js";import{n as t,t as n}from"./jsx-runtime-CVMpzJz9.js";import{n as r}from"./QueryClientProvider-DlPztvhd.js";import{n as i,t as a}from"./useMutation-CRAWY7v2.js";import{t as o}from"./chunk-OB3PAWPO-1IihCzFx.js";import{E as s,c,t as l}from"./button-By-NN7c7.js";import{t as u}from"./x-tY-z3woy.js";import{c as d,d as f,h as p,i as m,l as h,m as g,n as _,o as v,p as y,t as b}from"./client-954dj6K2.js";import{t as x}from"./chevron-down-KBvm_HoX.js";import{a as S,i as C,n as w,r as T,t as E}from"./select-cyLFVkkB.js";import{n as D,t as O}from"./circle-check-DWP3C_MJ.js";import{t as k}from"./download-BD7lYc4O.js";import{t as A}from"./textarea-CovStda2.js";import{i as ee,n as j,r as M,t as N}from"./tabs-bEwJLtA0.js";import{t as P}from"./label-Bm_d0NKL.js";import{_ as F,a as I,c as L,d as R,f as z,g as B,i as V,m as H,o as te,t as U,u as W}from"./schemas-BQZhekae.js";import{a as ne,i as re,n as ie,o as ae,r as oe,t as se}from"./dialog-DNIYhwi4.js";import{$ as ce,$t as le,Cn as ue,Dn as de,Dr as fe,En as pe,Er as me,Fn as he,Gr as ge,On as _e,Or as ve,Pn as ye,Qr as be,Tr as xe,U as Se,Wr as Ce,Z as we,Zt as Te,_n as Ee,_r as G,a as De,ai as Oe,an as ke,c as Ae,d as je,gn as Me,gr as K,hn as Ne,i as Pe,in as Fe,kn as Ie,kr as Le,l as Re,n as ze,ni as Be,nn as Ve,o as He,on as Ue,or as We,ot as Ge,qr as Ke,r as qe,ri as Je,rn as Ye,s as Xe,sn as Ze,sr as Qe,t as $e,tn as et,tt,u as nt,un as rt,vn as it,wn as at,xn as ot,yn as st,yr as ct}from"./index-XIDqokJX.js";import{t as lt}from"./ConfirmDialog-B5es4nUp.js";import{t as ut}from"./ErrorState-DB0nWfcc.js";import{t as dt}from"./ViewHeader-D-lhe59Y.js";import{t as ft}from"./view-params-DD7i9s5g.js";import{_ as pt,a as mt,d as ht,f as gt,g as _t,h as vt,i as yt,l as bt,m as xt,n as St,o as Ct,p as wt,r as Tt,s as Et,t as Dt,u as Ot,v as kt}from"./useIntegrations-C0MAVKB4.js";import{_ as At,f as jt,h as Mt,r as Nt,t as Pt}from"./badge-BqTVr27Z.js";var Ft={name:`bell-off`,size:24,node:[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]};Ft.node;var It=p(Ft),Lt={name:`circle-check-big`,size:24,node:[[`path`,{d:`M21.801 10A10 10 0 1 1 17 3.335`,key:`yps3ct`}],[`path`,{d:`m9 11 3 3L22 4`,key:`1pflzl`}]],aliases:[`check-circle`]};Lt.node;var Rt=p(Lt),zt={name:`eye-off`,size:24,node:[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};zt.node;var Bt=p(zt),Vt={name:`log-in`,size:24,node:[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]};Vt.node;var Ht=p(Vt),Ut={name:`plug`,size:24,node:[[`path`,{d:`M12 22v-5`,key:`1ega77`}],[`path`,{d:`M15 8V2`,key:`18g5xt`}],[`path`,{d:`M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z`,key:`1xoxul`}],[`path`,{d:`M9 8V2`,key:`14iosj`}]]};Ut.node;var Wt=p(Ut),Gt={name:`send`,size:24,node:[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]};Gt.node;var Kt=p(Gt),qt={name:`volume-2`,size:24,node:[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]};qt.node;var Jt=p(qt),q=e(t(),1),J=n(),Yt=Object.defineProperty,Xt=(e,t)=>Yt(e,`name`,{value:t,configurable:!0}),Zt={Horizontal:`horizontal`,Vertical:`vertical`},Qt=Zt.Horizontal,$t=Object.values(Zt),en=q.forwardRef(Xt(function(e,t){let{decorative:n,orientation:r=Qt,...i}=e,a=tn(r)?r:Qt,o=a===Zt.Vertical?a:void 0,c=n?{role:`none`}:{"aria-orientation":o,role:`separator`};return(0,J.jsx)(s.div,{"data-orientation":a,...c,...i,ref:t})},`Separator`));function tn(e){return $t.includes(e)}Xt(tn,`isValidOrientation`);function nn(e){let t=/\bElectron\/([\w.-]+)/.exec(e)?.[1];return t?{app:/\borc\/([\w.-]+)/.exec(e)?.[1]??`unknown`,electron:t}:null}function rn(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t?`${t}d ${n}h`:n?`${n}h ${r}m`:`${r}m`}function an(e){switch(e.phase){case`unavailable`:return`Updates run in an installed app.`;case`checking`:return`Checking for updates…`;case`downloading`:return e.progress==null?`Downloading update…`:`Downloading update… ${Math.round(e.progress)}%`;case`downloaded`:return e.availableVersion?`Version ${e.availableVersion} is ready to install.`:`An update is ready to install.`;case`current`:return`This app is up to date.`;case`error`:return e.error??`Update check failed.`;default:return e.checksEnabled?`Automatic checks are on.`:`Automatic checks are off.`}}function on(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}var sn=`https://github.com/niradler/orc`,cn=[{id:`repo`,label:`Source code`,href:sn},{id:`releases`,label:`Releases and changelog`,href:`${sn}/releases`},{id:`issues`,label:`Report an issue`,href:`${sn}/issues`},{id:`docs`,label:`Documentation`,href:`${sn}/tree/master/docs`},{id:`npm`,label:`npm package (orc-ai)`,href:`https://www.npmjs.com/package/orc-ai`}],ln={win32:`Windows`,darwin:`macOS`,linux:`Linux`};function Y({id:e,label:t,value:n}){return(0,J.jsxs)(`div`,{className:`grid gap-1 border-b border-border py-2.5 text-sm sm:grid-cols-[180px_minmax(0,1fr)] sm:gap-4`,children:[(0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:t}),(0,J.jsx)(`dd`,{"data-testid":`about-${e}`,className:`min-w-0 break-words font-mono text-[13px]`,children:n??`—`})]})}function un({state:e}){let t=st()?.updates,[n,r]=(0,q.useState)(null),i=async e=>{r(null);try{await e()}catch{r(`The update action failed. Please try again.`)}},a=on(e.lastCheckedAt),o=e.phase===`checking`||e.phase===`downloading`,s=(e,n)=>{t&&i(()=>t.setPreferences({channel:e,checksEnabled:n}))};return(0,J.jsxs)(`div`,{className:`mt-8 max-w-3xl`,"data-testid":`about-updates`,children:[(0,J.jsx)(`h3`,{className:`mb-2 text-sm font-medium`,children:`Updates`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`about-update-status`,children:an(e)}),n&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-error`,"data-testid":`about-update-error`,children:n}),a&&(0,J.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,"data-testid":`about-update-checked`,children:[`Last check `,a]}),(0,J.jsxs)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-[180px_minmax(0,1fr)] sm:items-center`,children:[(0,J.jsx)(P,{htmlFor:`about-update-channel`,children:`Channel`}),(0,J.jsxs)(E,{value:e.channel,onValueChange:t=>{(t===`stable`||t===`preview`)&&s(t,e.checksEnabled)},children:[(0,J.jsx)(C,{id:`about-update-channel`,"data-testid":`about-update-channel`,children:(0,J.jsx)(S,{})}),(0,J.jsxs)(w,{children:[(0,J.jsx)(T,{value:`stable`,children:`Stable`}),(0,J.jsx)(T,{value:`preview`,children:`Preview`})]})]})]}),(0,J.jsxs)(`label`,{className:`mt-4 flex min-h-11 items-center gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-foreground`,checked:e.checksEnabled,"data-testid":`about-update-checks`,onChange:t=>s(e.channel,t.target.checked)}),`Check for updates`]}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Stable follows GitHub releases. Preview also includes prereleases. The bundled daemon restarts with the app. Tasks and sessions stay in the data folder.`}),e.phase===`downloaded`&&e.releaseNotes&&(0,J.jsx)(`pre`,{className:`mt-4 max-h-48 overflow-auto whitespace-pre-wrap font-sans text-sm text-foreground`,"data-testid":`about-update-notes`,children:e.releaseNotes}),(0,J.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,J.jsx)(l,{type:`button`,variant:`outline`,disabled:!e.packaged||o,"data-testid":`about-update-check`,onClick:()=>t&&void i(()=>t.check()),children:`Check now`}),e.phase===`downloaded`&&(0,J.jsx)(l,{type:`button`,"data-testid":`about-update-install`,onClick:()=>t&&void i(()=>t.install()),children:`Restart to update`})]})]})}function dn(){let{data:e}=Re(),t=i({queryKey:[`system-about`],queryFn:()=>_.system.about()}),n=nn(navigator.userAgent),r=st()?.updates,[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(!1);(0,q.useEffect)(()=>{if(!r)return;let e=!0;r.state().then(t=>{e&&o(t)}).catch(()=>{e&&c(!0)});let t=r.onChange(o);return()=>{e=!1,t()}},[r]);let l=t.data;return(0,J.jsxs)(`section`,{"aria-labelledby":`about-title`,"data-testid":`settings-about`,children:[(0,J.jsx)(`h2`,{id:`about-title`,className:`mb-6 text-base font-medium`,children:`About`}),(0,J.jsxs)(`dl`,{className:`max-w-3xl`,children:[(0,J.jsx)(Y,{id:`server-version`,label:`Server version`,value:l?.version??e?.version}),n&&(0,J.jsx)(Y,{id:`desktop-version`,label:`Desktop app`,value:n.app}),n&&(0,J.jsx)(Y,{id:`electron-version`,label:`Electron`,value:n.electron}),(0,J.jsx)(Y,{id:`platform`,label:`Server platform`,value:l&&`${ln[l.platform]??l.platform} ${l.os_release} (${l.arch})`}),(0,J.jsx)(Y,{id:`runtime`,label:`Runtime`,value:l?.runtime}),(0,J.jsx)(Y,{id:`data-dir`,label:`Data folder`,value:l?.data_dir}),(0,J.jsx)(Y,{id:`uptime`,label:`Uptime`,value:e?rn(e.uptime):void 0}),(0,J.jsx)(Y,{id:`instance`,label:`Instance`,value:l?.instance_id??e?.instance_id})]}),t.isError&&(0,J.jsxs)(`p`,{role:`alert`,className:`mt-3 text-sm text-error`,children:[`Server details are unavailable: `,t.error.message]}),a&&(0,J.jsx)(un,{state:a}),s&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-error`,children:`Desktop update settings are unavailable. Reload to try again.`}),(0,J.jsx)(`h3`,{className:`mt-8 mb-2 text-sm font-medium`,children:`Links`}),(0,J.jsx)(`ul`,{className:`max-w-3xl space-y-0.5`,children:cn.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,"data-testid":`about-link-${e.id}`,className:`inline-flex min-h-8 items-center gap-1.5 rounded-sm text-sm text-foreground underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-ring max-md:min-h-11`,children:[e.label,(0,J.jsx)(ge,{"aria-hidden":`true`,className:`size-3.5 text-muted-foreground`})]})},e.id))})]})}var fn=`0123456789abcdefghijklmnopqrstuvwxyz`;function pn(){let e=crypto.getRandomValues(new Uint8Array(6)),t=``;for(let n=0;n<6;n++)t+=fn[(e[n]??0)%36];return t}var mn=H().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/);function hn(e){return/(?:^|_)(?:KEY|TOKEN|SECRET|PASSWORD|CREDENTIALS?|AUTHORIZATION)(?:_|$)/i.test(e)}var gn=V(R({name:H().regex(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/).refine(e=>!/^ORC_|^CLAUDECODE$|^CLAUDE_PID$|^CLAUDE_AGENT_SDK_|^CLAUDE_CODE_(?:ENTRYPOINT|CHILD_SESSION|SESSION_|HOST_SESSION_ID|MESSAGING_|SSE_PORT)|^(?:__proto__|constructor|prototype)$/i.test(e),`ORC connection and agent transport variables are managed by ORC`),value:H().max(8192).refine(e=>!e.includes(`\0`),`Environment values cannot contain NUL`).nullable(),secret:I().default(!1)}).strict()).max(64).superRefine((e,t)=>{let n=new Set;for(let[r,i]of e.entries())n.has(i.name.toLowerCase())&&t.addIssue({code:`custom`,path:[r,`name`],message:`Environment names must be unique`}),n.add(i.name.toLowerCase()),hn(i.name)&&!i.secret&&t.addIssue({code:`custom`,path:[r,`secret`],message:`Credential variables must be stored as secrets`})}),_n=R({id:mn,name:H().trim().min(1).max(80),agent:H().regex(ue),enabled:I(),executable:H().trim().max(2048).refine(e=>Array.from(e).every(e=>e.charCodeAt(0)>=32&&e.charCodeAt(0)!==127),`Use an executable path without control characters`).default(``),model:ye.default(``),options:We.optional(),environment:gn.default([])}).strict().superRefine((e,t)=>{e.options&&e.options.runtime!==Qe(e.agent)&&t.addIssue({code:`custom`,path:[`options`],message:`Launch options must match the selected adapter`}),e.executable&&![`claude`,`codex`,`opencode`].includes(e.agent)&&t.addIssue({code:`custom`,path:[`executable`],message:`Configure other agent commands through acpx on the execution host`})}),vn=R({providers:V(_n).min(1).max(64),default_provider_id:mn,revision:H().regex(/^[a-f0-9]{64}$/)}).strict().superRefine((e,t)=>{new Set(e.providers.map(e=>e.id)).size!==e.providers.length&&t.addIssue({code:`custom`,path:[`providers`],message:`Provider IDs must be unique`}),new Set(e.providers.map(e=>e.name.toLowerCase())).size!==e.providers.length&&t.addIssue({code:`custom`,path:[`providers`],message:`Provider names must be unique`}),(!e.providers.some(t=>t.id===e.default_provider_id)||e.providers.some(e=>e.enabled)&&!e.providers.some(t=>t.id===e.default_provider_id&&t.enabled))&&t.addIssue({code:`custom`,path:[`default_provider_id`],message:`Choose an enabled default provider`})}),yn=_n.safeExtend({environment:V(R({name:H(),value:H().max(5e4),secret:I()}).strict()).max(64).default([])}).superRefine((e,t)=>{let n=gn.safeParse(e.environment.map(e=>({...e,value:e.secret?null:e.value})));if(!n.success)for(let e of n.error.issues)t.addIssue({code:`custom`,path:[`environment`,...e.path],message:e.message});e.environment.some(e=>e.secret&&!/^enc:v1:[A-Za-z0-9_-]+:[A-Za-z0-9_-]+:[A-Za-z0-9_-]*$/.test(e.value))&&t.addIssue({code:`custom`,path:[`environment`],message:`Provider secrets must be encrypted through provider settings`})});R({instances:V(yn).min(1).max(64),default_id:mn}).strict().superRefine((e,t)=>{let n=vn.safeParse({providers:e.instances.map(e=>({...e,environment:e.environment.map(e=>({...e,value:e.secret?null:e.value}))})),default_provider_id:e.default_id,revision:`0`.repeat(64)});if(!n.success)for(let e of n.error.issues)t.addIssue({code:`custom`,path:e.path,message:e.message})});function bn(e){return JSON.stringify(e.options?.runtime===`claude-sdk`?e.options.options:e.options?.args??(Qe(e.agent)===`claude-sdk`?{}:[]),null,2)}function xn(){let e=r(),t=Ze(),[n,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(``),[d,f]=(0,q.useState)({}),[p,m]=(0,q.useState)({}),[h,g]=(0,q.useState)({}),[v,y]=(0,q.useState)(!1),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(`claude`),[w,T]=(0,q.useState)(``),[E,D]=(0,q.useState)(``),O=n??t.data,k=O?.providers.find(e=>e.id===(s||O.default_provider_id))??O?.providers[0],ee=(0,q.useRef)(null);(0,q.useEffect)(()=>{k?.id&&ee.current?.scrollIntoView({block:`nearest`,inline:`nearest`})},[k?.id]);let j=O?vn.safeParse(O):null,M=!!O&&(JSON.stringify(O)!==JSON.stringify(t.data)||Object.values(p).some(Boolean)),N=a({mutationFn:e=>_.settings.providers.save(e),onSuccess:async t=>{e.setQueryData(Fe,t),o(null),f({}),m({}),localStorage.removeItem(ot),await e.invalidateQueries({queryKey:ke}),await e.invalidateQueries({queryKey:[`terminal-launchers`]}),await e.invalidateQueries({queryKey:[`terminals`]}),await e.invalidateQueries({queryKey:[`chat-models`]}),window.dispatchEvent(new Event(`orc-chat-settings-changed`))}}),F=t.isFetching||t.isError||N.isPending,I=i({queryKey:[`usage-quotas`],queryFn:_.settings.usageQuotas,enabled:!1}),L=I.data?.accounts.find(e=>e.provider===k?.agent),R=i({queryKey:[`provider-models`,k?.id,t.data?.revision],queryFn:()=>_.chat.models(k?.agent??`codex`,void 0,void 0,void 0,k?.id),enabled:!1,retry:!1});function z(e,t){if(!O||!k)return;let n=e.environment;n&&g(e=>({...e,[k.id]:t??n.map((t,n)=>e[k.id]?.[n]??k.environment[n]?.name??crypto.randomUUID())})),N.reset(),o({...O,providers:O.providers.map(t=>t.id===k.id?{...t,...e}:t)})}function B(){o(null),f({}),m({}),N.reset()}function V(){if(!O)return;let e=S===`other`?w.trim().toLowerCase():S;if(!b.trim()||!/^[a-z][a-z0-9-]{0,31}$/.test(e)){D(`Enter a name and a valid adapter.`);return}if(O.providers.some(e=>e.name.toLowerCase()===b.trim().toLowerCase())){D(`Choose a unique provider name.`);return}let t={id:pn().toLowerCase(),name:b.trim(),agent:e,enabled:!0,executable:``,model:``,environment:[]};o({...O,providers:[...O.providers,t]}),c(t.id),y(!1),x(``),T(``),N.reset()}function H(e){if(k){f(t=>({...t,[k.id]:e}));try{let t=JSON.parse(e),n=Qe(k.agent);z({options:We.parse(n===`claude-sdk`?{runtime:n,options:t}:{runtime:n,args:t})}),m(e=>({...e,[k.id]:``}))}catch{m(e=>({...e,[k.id]:`Enter valid JSON with supported options for this adapter.`}))}}}return(0,J.jsxs)(`section`,{"aria-labelledby":`agent-settings-title`,className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsxs)(`h2`,{id:`agent-settings-title`,className:`text-base font-medium`,children:[`Coding providers`,` `,(0,J.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-muted-foreground`,children:[O?.providers.filter(e=>e.enabled).length??0,` enabled`]})]}),(0,J.jsx)(G,{label:`Coding providers`,testId:`provider-help`,children:`Named configurations for coding agents. Existing conversations keep their selected provider.`})]}),(0,J.jsxs)(l,{variant:`outline`,"data-testid":`provider-new`,disabled:F||(O?.providers.length??0)>=64,onClick:()=>{D(``),y(!0)},children:[(0,J.jsx)(ve,{size:14}),`New provider`]})]}),t.isPending&&(0,J.jsx)(`p`,{role:`status`,children:`Loading providers...`}),t.error&&(0,J.jsxs)(`div`,{role:`alert`,children:[(0,J.jsx)(`p`,{children:`Providers could not be loaded.`}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>void t.refetch(),children:`Retry`})]}),O&&!O.providers.some(e=>e.enabled)&&(0,J.jsx)(`p`,{role:`status`,"data-testid":`provider-none-enabled`,className:`text-sm text-muted-foreground`,children:`No coding providers enabled. Install an agent, then enable it here.`}),O&&(0,J.jsxs)(`div`,{className:`grid items-center gap-2 sm:grid-cols-[140px_minmax(0,1fr)]`,children:[(0,J.jsx)(P,{htmlFor:`provider-default`,children:`Default provider`}),(0,J.jsx)(`select`,{id:`provider-default`,"data-testid":`provider-default`,className:`form-control form-control-single`,disabled:F,value:O.default_provider_id,onChange:e=>{N.reset(),o({...O,default_provider_id:e.target.value})},children:O.providers.map(e=>(0,J.jsxs)(`option`,{value:e.id,disabled:!e.enabled,children:[e.name,e.enabled?``:` (disabled)`]},e.id))})]}),O&&k&&(0,J.jsxs)(`div`,{className:`grid min-w-0 overflow-hidden rounded-md border border-border lg:grid-cols-[220px_minmax(0,1fr)]`,children:[(0,J.jsx)(`nav`,{"aria-label":`Coding providers`,className:`flex overflow-x-auto border-b border-border lg:block lg:max-h-[36rem] lg:overflow-y-auto lg:divide-y lg:divide-border lg:border-r lg:border-b-0`,children:O.providers.map(e=>(0,J.jsxs)(`div`,{className:`flex min-h-11 shrink-0 items-center gap-2 px-3 lg:min-w-0 `+(k.id===e.id?`bg-surface-highest`:``),children:[(0,J.jsxs)(`button`,{type:`button`,"data-testid":`provider-select-${e.id}`,ref:k.id===e.id?ee:void 0,title:e.name,"aria-pressed":k.id===e.id,onClick:()=>c(e.id),className:`flex min-h-11 min-w-0 flex-1 items-center gap-2 text-left`,children:[(0,J.jsx)(rt,{agent:e.agent,decorative:!0,size:16}),(0,J.jsx)(`span`,{className:`min-w-0 truncate text-sm`,children:e.name})]}),(0,J.jsx)(`label`,{className:`flex min-h-11 min-w-11 cursor-pointer items-center justify-center`,children:(0,J.jsx)(`input`,{type:`checkbox`,className:`accent-primary`,"aria-label":`Enable ${e.name}`,"data-testid":`agent-enabled-${e.id}`,checked:e.enabled,disabled:F,onChange:t=>{N.reset(),o({...O,providers:O.providers.map(n=>n.id===e.id?{...n,enabled:t.target.checked}:n)})}})})]},e.id))}),(0,J.jsxs)(`div`,{"data-testid":`provider-editor`,className:`min-w-0 space-y-4 p-4`,children:[(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`provider-name`,children:`Name`}),(0,J.jsx)(K,{id:`provider-name`,"data-testid":`provider-name`,maxLength:80,value:k.name,disabled:F,onChange:e=>z({name:e.target.value})})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{children:`Adapter`}),(0,J.jsxs)(`p`,{className:`flex min-h-8 items-center gap-2 text-sm`,children:[(0,J.jsx)(rt,{agent:k.agent,decorative:!0,size:16}),pe(k.agent),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:_e(k.agent)?`native`:de(k.agent)===`opencode`?`acp`:`acpx`})]})]})]}),[`claude`,`codex`,`opencode`].includes(k.agent)&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{htmlFor:`provider-binary`,children:`Executable path`}),(0,J.jsx)(G,{label:`Executable path`,testId:`provider-binary-help`,children:`Optional local binary path, without arguments. Blank uses the default installation. SSH uses its remote installation.`})]}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`provider-use-default`,disabled:F||!k.executable,onClick:()=>z({executable:``}),children:`Use default`})]}),(0,J.jsx)(K,{id:`provider-binary`,"data-testid":`provider-binary`,value:k.executable,maxLength:2048,placeholder:k.agent,disabled:F,onChange:e=>z({executable:e.target.value})})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{htmlFor:`provider-model`,children:`Default model`}),(0,J.jsx)(G,{label:`Default model`,testId:`provider-model-help`,children:`Leave blank for the adapter default. Explicit session models take precedence. Save connection changes before loading model choices.`})]}),(0,J.jsx)(K,{id:`provider-model`,"data-testid":`provider-model`,value:k.model,placeholder:`Adapter default`,list:`provider-model-choices`,disabled:F,onFocus:()=>{!M&&Ie(k.agent)&&R.refetch()},onChange:e=>z({model:e.target.value})}),(0,J.jsx)(`datalist`,{id:`provider-model-choices`,children:R.data?.models.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.label},e.id))}),(R.data?.warning||R.isError)&&(0,J.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:R.data?.warning??`Models could not be loaded. Enter a custom model ID.`})]}),(0,J.jsxs)(`details`,{"data-testid":`provider-advanced`,className:`space-y-3 border-t border-border pt-3`,children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer text-sm`,children:[`Advanced configuration`,` `,(0,J.jsx)(`span`,{className:`ml-1 text-xs text-muted-foreground`,children:k.environment.length?`${k.environment.length} variables`:``})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{children:`Environment overrides`}),(0,J.jsx)(G,{label:`Environment overrides`,testId:`provider-env-help`,children:`Applies to launches and model discovery. Empty values clear inherited values. Credential variables are encrypted and write-only. Leave a saved secret untouched to preserve it; enter a value to replace it.`})]}),(0,J.jsxs)(l,{variant:`outline`,size:`sm`,"data-testid":`provider-env-add`,disabled:F||k.environment.length>=64,onClick:()=>z({environment:[...k.environment,{name:``,value:``,secret:!1}]}),children:[(0,J.jsx)(ve,{size:14}),`Add variable`]})]}),k.environment.map((e,t)=>(0,J.jsxs)(`div`,{"data-testid":`provider-env-row`,className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-2 border-b border-border py-2`,children:[(0,J.jsx)(K,{"aria-label":`Variable name`,"data-testid":`provider-env-name`,value:e.name,placeholder:`VARIABLE_NAME`,maxLength:128,disabled:F||e.value===null,className:`font-mono text-xs`,onChange:e=>z({environment:k.environment.map((n,r)=>r===t?{...n,name:e.target.value,secret:n.secret||hn(e.target.value)}:n)})}),(0,J.jsxs)(`label`,{className:`flex min-h-11 items-center gap-1 text-xs`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:e.secret,disabled:F||hn(e.name)||e.value===null,onChange:e=>z({environment:k.environment.map((n,r)=>r===t?{...n,secret:e.target.checked}:n)})}),`Secret`]}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove variable ${e.name}`,disabled:F,onClick:()=>z({environment:k.environment.filter((e,n)=>n!==t)},k.environment.map((e,t)=>h[k.id]?.[t]??e.name).filter((e,n)=>n!==t)),children:(0,J.jsx)(u,{size:14})}),(0,J.jsx)(K,{"aria-label":`Value for ${e.name||`variable`}`,"data-testid":`provider-env-value`,type:e.secret?`password`:`text`,autoComplete:`off`,value:e.value??``,placeholder:e.value===null?`Saved secret - enter to replace`:`Value (can be empty)`,maxLength:8192,disabled:F,className:`col-span-3`,onChange:e=>z({environment:k.environment.map((n,r)=>r===t?{...n,value:e.target.value}:n)})})]},h[k.id]?.[t]??e.name))]}),(0,J.jsxs)(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{htmlFor:k.agent===`opencode`?void 0:`provider-options`,children:k.agent===`opencode`?`OpenCode configuration`:`Chat launch options (JSON)`}),(0,J.jsxs)(G,{label:k.agent===`opencode`?`OpenCode configuration`:`Chat launch options`,testId:`provider-options-help`,children:[k.agent===`opencode`?`Configure custom providers and model options in OpenCode on the execution host. Use Default model above for a provider/model override, or leave it blank for OpenCode's default. Environment overrides apply to ACP and model discovery. ACPX launch flags do not apply to OpenCode.`:Qe(k.agent)===`claude-sdk`?`Claude SDK options, for example {"effort":"high","maxTurns":20}.`:Qe(k.agent)===`codex`?`Codex arguments, for example ["-c","model_reasoning_effort=\\"high\\""].`:`ACPX arguments, for example ["--timeout","120"].`,` `,`Session options override these defaults. These options apply to chat, not native terminal launches.`]})]}),k.agent!==`opencode`&&(0,J.jsx)(A,{id:`provider-options`,"data-testid":`provider-options`,rows:4,maxLength:2e4,className:`font-mono text-xs`,disabled:F,value:d[k.id]??bn(k),onChange:e=>H(e.target.value)}),p[k.id]&&(0,J.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,children:p[k.id]})]})]},k.id),(0,J.jsxs)(`div`,{className:`flex items-center gap-1 border-t border-border pt-3`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium`,children:`Context compaction`}),(0,J.jsx)(G,{label:`Context compaction`,testId:`provider-compact-help`,children:_e(k.agent)?`Compact an idle conversation from its actions or send /compact. Automatic compaction stays under the agent's control.`:`Manual compaction is not available through this adapter.`})]}),_e(k.agent)&&(0,J.jsxs)(`details`,{className:`space-y-2 border-t border-border pt-3`,children:[(0,J.jsx)(`summary`,{className:`min-h-11 cursor-pointer text-sm`,children:`Local account limits`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(l,{variant:`outline`,size:`sm`,disabled:I.isFetching,onClick:()=>void I.refetch(),children:I.isFetching?`Checking...`:`Check limits`}),(0,J.jsx)(G,{label:`Local account limits`,testId:`provider-limits-help`,children:`Local CLI account only. Gateway, Bedrock billing and SSH quotas are not included.`})]}),I.isError&&(0,J.jsx)(`p`,{role:`alert`,children:`Limits could not be loaded. Try again.`}),L&&(0,J.jsxs)(`div`,{"data-testid":`provider-limits`,className:`space-y-2 text-xs`,children:[(0,J.jsxs)(`p`,{children:[`Checked `,new Date(L.checked_at).toLocaleTimeString()]}),L.status!==`available`&&(0,J.jsx)(`p`,{children:L.message??`Account limits are unavailable.`}),L.windows.map(e=>(0,J.jsxs)(`p`,{children:[e.label,`: `,e.used_percent,`% used`,e.resets_at?` - Resets ${new Date(e.resets_at).toLocaleString()}`:` - Reset time unavailable`]},e.label))]})]})]})]}),j&&!j.success&&M&&(0,J.jsx)(`p`,{role:`alert`,"data-testid":`provider-validation`,className:`text-sm text-error`,children:[...new Set(j.error.issues.map(e=>e.message))].join(` `)}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(l,{"data-testid":`agent-settings-save`,disabled:F||!M||!j?.success||Object.values(p).some(Boolean),onClick:()=>{O&&N.mutate(O)},children:N.isPending?`Saving...`:`Save changes`}),M&&(0,J.jsx)(l,{variant:`ghost`,"data-testid":`provider-discard`,disabled:N.isPending,onClick:B,children:`Discard changes`}),N.isSuccess&&(0,J.jsx)(`p`,{role:`status`,"data-testid":`agent-settings-saved`,children:`Provider settings saved.`}),N.error&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:N.error.message}),(0,J.jsx)(l,{variant:`outline`,onClick:()=>{B(),t.refetch()},children:`Discard draft and reload`})]})]}),(0,J.jsx)(se,{open:v,onOpenChange:y,children:(0,J.jsxs)(ie,{children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(ae,{children:`New provider`}),(0,J.jsx)(G,{label:`New provider`,testId:`provider-new-help`,children:`Choose a coding-agent adapter, then configure its models and environment.`})]}),(0,J.jsx)(oe,{className:`sr-only`,children:`Choose a coding-agent adapter, then configure its models and environment.`}),(0,J.jsxs)(`div`,{className:`space-y-4`,children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`provider-new-name`,children:`Provider name`}),(0,J.jsx)(K,{id:`provider-new-name`,"data-testid":`provider-new-name`,value:b,placeholder:`e.g. Claude LiteLLM`,maxLength:80,onChange:e=>x(e.target.value)})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`provider-new-adapter`,children:`Adapter`}),(0,J.jsxs)(`select`,{id:`provider-new-adapter`,"data-testid":`provider-new-adapter`,className:`form-control form-control-single`,value:S,onChange:e=>C(e.target.value),children:[at.map(e=>(0,J.jsxs)(`option`,{value:e.id,children:[e.label,_e(e.id)?``:de(e.id)===`opencode`?` (acp)`:` (acpx)`]},e.id)),(0,J.jsx)(`option`,{value:`other`,children:`Other acpx agent`})]})]}),S===`other`&&(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`provider-custom-agent`,children:`acpx agent ID`}),(0,J.jsx)(K,{id:`provider-custom-agent`,"data-testid":`agent-custom`,value:w,placeholder:`e.g. qoder`,onChange:e=>T(e.target.value)})]}),E&&(0,J.jsx)(`p`,{role:`alert`,children:E}),(0,J.jsx)(l,{"data-testid":`provider-create`,disabled:!b.trim(),onClick:V,children:`Configure provider`})]})]})})]})}function Sn(){let e=r(),t=i({queryKey:[`workspace-preferences`],queryFn:_.settings.get}),[n,o]=(0,q.useState)(null),s=a({mutationFn:e=>_.settings.save({attention_retention_hours:e}),onSuccess:async()=>{await e.invalidateQueries({queryKey:[`workspace-preferences`]}),await e.invalidateQueries({queryKey:[`human-requests`]})}}),c=n??String(t.data?.attention_retention_hours??72);return(0,J.jsxs)(`section`,{className:`mt-6 space-y-3`,"aria-labelledby":`attention-settings-title`,children:[(0,J.jsx)(`h2`,{id:`attention-settings-title`,className:`text-base font-medium`,children:`Questions and approvals`}),(0,J.jsx)(`p`,{className:`text-sm text-outline`,children:`Requests stop accepting replies after this many hours from creation. Session continuation clears obsolete requests when reported by a supported hook. Notification and audit history have separate cleanup periods.`}),t.error&&(0,J.jsx)(`p`,{role:`alert`,children:t.error.message}),(0,J.jsxs)(`form`,{className:`flex flex-wrap items-end gap-3`,onSubmit:e=>{e.preventDefault(),s.mutate(Number(c))},children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`attention-retention`,children:`Automatically dismiss after (hours)`}),(0,J.jsx)(K,{id:`attention-retention`,"data-testid":`attention-retention-hours`,type:`number`,min:1,max:8760,step:1,required:!0,value:c,disabled:t.isPending||!!t.error||s.isPending,onChange:e=>{o(e.target.value),s.reset()},className:`w-32`})]}),(0,J.jsx)(l,{"data-testid":`attention-retention-save`,type:`submit`,disabled:t.isPending||!!t.error||s.isPending,children:s.isPending?`Saving…`:`Save retention`})]}),s.error&&(0,J.jsx)(`p`,{role:`alert`,children:s.error.message}),s.isSuccess&&(0,J.jsx)(`p`,{role:`status`,"data-testid":`attention-retention-saved`,children:`Retention saved.`})]})}function Cn(){let e=st()?.preview,[t,n]=(0,q.useState)([]),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)(``),[u,d]=(0,q.useState)(`9222`),[f,p]=(0,q.useState)([]),[m,h]=(0,q.useState)(``),[g,_]=(0,q.useState)(null),[v,y]=(0,q.useState)([]),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(!1),[w,T]=(0,q.useState)(null),[E,D]=(0,q.useState)(null);(0,q.useEffect)(()=>(e?.profiles().then(n).catch(()=>T(`Browser profiles could not be loaded`)),()=>{e?.cancelImport()}),[e]);async function O(e,t=!1){if(!b){x(!0),C(t),T(null),D(null);try{await e()}catch(e){T(e instanceof Error?e.message:`Browser profile operation failed`)}finally{x(!1),C(!1)}}}return(0,J.jsxs)(`div`,{className:`border-b border-border py-4`,"data-testid":`browser-profiles-settings`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium`,children:`Saved browser profiles`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Log in inside ORC to keep a login here. Each chat starts in temporary mode. Choosing the same saved profile explicitly shares its cookies and site storage between those chats.`}),(0,J.jsxs)(`form`,{className:`mt-3 flex flex-wrap gap-2`,onSubmit:t=>{t.preventDefault(),O(async()=>{if(!e)return;let t=await e.createProfile(r.trim());n(await e.profiles()),c(t.id),i(``),D(`Profile created. Select it from the browser panel in a chat.`)})},children:[(0,J.jsx)(`input`,{"aria-label":`New browser profile name`,"data-testid":`browser-profile-name`,className:`form-control form-control-single min-w-0 flex-1`,maxLength:80,value:r,onChange:e=>i(e.target.value),placeholder:`Work account`}),(0,J.jsx)(l,{type:`submit`,disabled:b||!r.trim(),"data-testid":`browser-profile-create`,children:`Create profile`})]}),t.length>0&&(0,J.jsxs)(`select`,{"aria-label":`Saved browser profile`,"data-testid":`browser-profile-select`,className:`form-control form-control-single mt-3`,value:s,onChange:e=>c(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:`Choose a profile`}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),s&&(0,J.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[(0,J.jsx)(`input`,{"aria-label":`Rename browser profile`,"data-testid":`browser-profile-rename-name`,className:`form-control form-control-single min-w-0 flex-1`,maxLength:80,value:a,onChange:e=>o(e.target.value),placeholder:`New profile name`}),(0,J.jsx)(l,{disabled:b||!a.trim(),"data-testid":`browser-profile-rename`,onClick:()=>void O(async()=>{e&&(await e.renameProfile(s,a.trim()),n(await e.profiles()),o(``),D(`Profile renamed.`))}),children:`Rename`}),(0,J.jsx)(l,{variant:`ghost`,disabled:b,"data-testid":`browser-profile-remove`,onClick:()=>void O(async()=>{e&&await e.removeProfile(s)&&(n(await e.profiles()),c(``),D(`Profile removed and site data cleared.`))}),children:`Remove profile`})]}),(0,J.jsxs)(`details`,{className:`mt-4`,"data-testid":`browser-import-settings`,children:[(0,J.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:`Import selected browser logins`}),(0,J.jsx)(`p`,{className:`my-2 text-xs text-muted-foreground`,children:`Select a destination profile above. Scan installed Firefox profiles, or Chrome/Edge/Brave/Chromium on macOS and Linux, and Safari on macOS. Only the sites you choose are copied. Close the source browser first. OS keychain approval may be required; Linux encrypted stores require Secret Service’s secret-tool.`}),(0,J.jsxs)(`div`,{className:`my-2 flex flex-wrap gap-2`,children:[(0,J.jsx)(l,{disabled:b||!s,"data-testid":`browser-import-stores`,onClick:()=>void O(async()=>{if(!e)return;_(null),y([]),h(``),p([]);let t=await e.importStores();p(t),t.length||D(`No supported cookie stores found. Use the live-browser connection below; Windows Chrome/Edge app-bound cookies require it.`)},!0),children:`Scan browser profiles`}),f.length>0&&(0,J.jsxs)(`select`,{"aria-label":`Source browser profile`,disabled:b,className:`form-control form-control-single min-w-0`,value:m,onChange:e=>h(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:`Choose source profile`}),f.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),m&&(0,J.jsx)(l,{disabled:b||!s,"data-testid":`browser-import-store-discover`,onClick:()=>void O(async()=>{e&&(_(null),y([]),_(await e.discoverStore(m)))},!0),children:`Choose source sites`})]}),(0,J.jsx)(`p`,{className:`my-2 text-xs text-muted-foreground`,children:`Connect a Chrome/Edge profile whose local debugging endpoint you enabled, then select sites and a destination profile. Approve any prompt in that browser. Only selected sites’ cookies are copied; the agent never receives this connection. Passwords, local storage and device-bound sessions are not transferred. Some sites require logging in again. Windows Chrome/Edge app-bound cookie files require this connection.`}),(0,J.jsx)(`a`,{className:`text-xs underline`,href:`https://developer.chrome.com/blog/chrome-devtools-mcp-debug-your-browser-session`,target:`_blank`,rel:`noreferrer`,children:`Chrome connection instructions`}),(0,J.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,J.jsx)(`input`,{type:`number`,min:1024,max:65535,"aria-label":`Source browser debugging port`,"data-testid":`browser-import-port`,className:`form-control form-control-single w-28`,value:u,onChange:e=>d(e.target.value)}),(0,J.jsx)(l,{disabled:b||!s,"data-testid":`browser-import-discover`,onClick:()=>void O(async()=>{e&&(_(null),y([]),_(await e.discoverImport(Number(u))))},!0),children:`Find source sites`})]}),g&&(0,J.jsxs)(`div`,{className:`mt-3`,children:[(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[g.name,` · Select sites to copy into`,` `,t.find(e=>e.id===s)?.name]}),(0,J.jsx)(`div`,{className:`mt-2 max-h-48 overflow-y-auto`,children:g.sites.map(e=>(0,J.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2 text-xs`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:v.includes(e),onChange:t=>y(n=>t.target.checked?[...n,e]:n.filter(t=>t!==e))}),e]},e))}),(0,J.jsx)(l,{className:`mt-2`,disabled:b||!s||!v.length,"data-testid":`browser-import-transfer`,onClick:()=>void O(async()=>{if(!e)return;let t=await e.transferImport(g.id,s,v);_(null),y([]),D(`Imported ${t.imported} cookies; skipped ${t.skipped}. Check the selected sites in ORC; import does not guarantee a login.`)},!0),children:`Import selected sites`})]})]}),S&&(0,J.jsx)(l,{variant:`ghost`,onClick:()=>void e?.cancelImport(),children:`Cancel import`}),b&&(0,J.jsx)(`p`,{role:`status`,className:`mt-2 text-xs`,children:`Working…`}),E&&(0,J.jsx)(`p`,{role:`status`,className:`mt-2 text-xs`,children:E}),w&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-2 text-xs text-error`,children:w})]})}function wn(){let{settings:e,error:t,busy:n,save:r}=ce();return(0,J.jsxs)(`section`,{"aria-label":`Browser settings`,"data-testid":`browser-settings`,children:[(0,J.jsx)(`h2`,{className:`mb-2 text-base font-medium`,children:`Browser`}),(0,J.jsx)(`p`,{className:`mb-6 text-xs text-muted-foreground`,children:`Saved on this desktop. Changes apply immediately.`}),t&&(0,J.jsx)(`p`,{role:`alert`,className:`mb-4 text-sm text-error`,children:t}),!e&&!t&&(0,J.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading browser settings…`}),e&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`grid gap-4 border-b border-border py-4 sm:grid-cols-[minmax(160px,1fr)_minmax(0,2fr)]`,children:[(0,J.jsx)(`label`,{htmlFor:`browser-open-links`,className:`text-sm font-medium`,children:`Open web links in`}),(0,J.jsxs)(`select`,{id:`browser-open-links`,"data-testid":`browser-open-links`,className:`form-control form-control-single`,disabled:n,value:e.openLinksIn,onChange:t=>void r({...e,openLinksIn:t.target.value===`system`?`system`:`preview`}),children:[(0,J.jsx)(`option`,{value:`preview`,children:`ORC preview panel`}),(0,J.jsx)(`option`,{value:`system`,children:`System browser`})]})]}),(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-6 border-b border-border py-4`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`label`,{htmlFor:`browser-agent-access`,className:`text-sm font-medium`,children:`Agent browser control`}),(0,J.jsx)(`p`,{className:`mt-1 max-w-xl text-xs text-muted-foreground`,children:`On by default. Agents in the selected conversation can read, screenshot and interact with its browser, including pages you sign into. Turn it off here for every conversation, or use Session settings for one chat.`})]}),(0,J.jsx)(`input`,{id:`browser-agent-access`,"data-testid":`browser-agent-access`,type:`checkbox`,className:`mt-1 h-4 w-4 shrink-0`,checked:e.agentBrowserControl,disabled:n,onChange:t=>void r({...e,agentBrowserControl:t.target.checked})})]}),(0,J.jsx)(`p`,{className:`mt-4 text-xs text-muted-foreground`,children:`Temporary browser logins end with the app; saved profiles retain them separately from ORC. Camera, microphone and location stay blocked. Browser downloads are staged safely and can be saved to the chat workspace. File previews stay inside ORC; the external-link icon opens a source in VS Code.`}),(0,J.jsx)(Cn,{})]}),(0,J.jsx)(l,{variant:`ghost`,className:`mt-5`,disabled:n,onClick:()=>void r(tt.parse({})),children:`Reset browser settings`}),n&&(0,J.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-muted-foreground`,children:`Saving…`})]})}var Tn=H().min(1).max(100).regex(/^[a-z][a-z0-9.-]*$/),En=H().max(2048).refine(e=>e.startsWith(`/`)&&!e.startsWith(`//`)&&[...e].every(e=>e.charCodeAt(0)>32&&e!==`\\`),`Notification links must stay inside ORC`);R({type:Tn,source_key:H().min(1).max(500),source_id:H().min(1).max(256),title:H().trim().min(1).max(200),body:H().max(500).default(``),level:U([`needs-you`,`done`]),project_id:H().min(1).max(256).nullable().default(null),path:En,requires_action:I().default(!1),created_at:W().int().nonnegative(),expires_at:W().int().positive()}).strict().refine(e=>e.expires_at>e.created_at,`Expiry must follow creation`);var Dn=R({id:H(),type:Tn,source_id:H(),title:H(),body:H(),level:U([`needs-you`,`done`]),project_id:H().nullable(),path:En,requires_action:I(),created_at:W(),expires_at:W(),read_at:W().nullable(),dismissed_at:W().nullable()});R({notifications:V(Dn),unread:W().int(),has_more:I()}),R({read:I().optional(),dismissed:I().optional()}).strict().refine(e=>e.read!==void 0||e.dismissed!==void 0,`Supply read or dismissed`);var On=[`human.request`,`agent.question`,`agent.approval`,`agent.finished`,`agent.failed`,`job.finished`,`job.failed`],kn=R({enabled:I().default(!1),types:V(Tn).max(100).default([]),categories:V(U([`human`,`agent`,`job`])).max(3).default([]),levels:V(U([`needs-you`,`done`])).max(2).default([]),outcomes:V(U([`waiting`,`success`,`failure`])).max(3).default([]),include_unknown:I().default(!1)}).strict();R({enabled:I().default(!1),base_url:H().max(2048).default(``).refine(e=>{if(!e)return!0;try{let t=new URL(e);return[`https:`,`http:`].includes(t.protocol)&&!t.username&&!t.password&&!t.search&&!t.hash&&t.pathname===`/`}catch{return!1}},`Use an HTTP(S) ORC origin without credentials, a path, query or fragment`)}).strict().refine(e=>!e.enabled||!!e.base_url,`Set the ORC URL before enabling forwarding`),R({notification_id:H(),connection_id:H(),target_id:H(),status:U([`pending`,`sending`,`delivered`,`failed`,`unknown`,`skipped`]),attempts:W().int(),next_at:W(),error:H().nullable(),receipt_id:H().nullable(),created_at:W(),expires_at:W()});var An=U([`telegram`,`slack`]),jn=[{command:`help`,description:`Chat controls and custom shortcuts`},{command:`status`,description:`Current project, agent, model and session`},{command:`projects`,description:`Select a project and its working folder`},{command:`project`,description:`Select a project (alias for /projects)`},{command:`agent`,description:`Select an agent or restore the default`},{command:`model`,description:`Select a model or restore the default`},{command:`session`,description:`New, list, switch or stop a conversation`},{command:`session_new`,description:`Start a new conversation`},{command:`session_list`,description:`Choose a conversation`},{command:`stop`,description:`Stop the current turn and queued messages`}],Mn=V(R({command:H().regex(/^[a-z][a-z0-9_]{0,31}$/),description:H().trim().min(1).max(100),prompt:H().trim().min(1).max(1e4)}).strict()).max(50).superRefine((e,t)=>{let n=e.map(e=>e.command);(new Set(n).size!==n.length||n.some(e=>[`start`,`orc`,`projects`,`sessions`].includes(e)||jn.some(t=>t.command===e)))&&t.addIssue({code:`custom`,message:`Command names must be unique and cannot replace ORC controls`})});function Nn(e){return Mn.parse(e.commands??[])}var Pn=H().trim().min(1).max(100).regex(/^[a-zA-Z0-9_-]+$/);function Fn(e,t=0,n={nodes:0}){return t>20||++n.nodes>1e4?!1:e===null||typeof e==`boolean`?!0:typeof e==`number`?Number.isFinite(e):typeof e==`string`?e.length<=1e5:Array.isArray(e)?e.every(e=>Fn(e,t+1,n)):typeof e==`object`&&Object.entries(e).every(([e,r])=>![`__proto__`,`prototype`,`constructor`].includes(e)&&Fn(r,t+1,n))}var In=z(H(),B()).refine(e=>Fn(e)&&JSON.stringify(e).length<=262144,`Native payload must be bounded JSON (256 KB, depth 20)`),Ln=[`sender`,`chat`,`thread`,`text`,`command`,`is_direct`,`is_mention`,`kind`],Rn=[`is`,`in`,`contains`,`starts_with`];function X(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length===1&&`always`in e&&e.always===!0}function zn(e,t=0,n={nodes:0}){if(t>5||++n.nodes>100||!e||typeof e!=`object`||Array.isArray(e))return!1;let r=e,i=Object.keys(r);if(i.length===1){if(`always`in r)return t===0&&r.always===!0;if(`not`in r)return zn(r.not,t+1,n);let e=r.all??r.any;return(`all`in r||`any`in r)&&Array.isArray(e)&&e.length>0&&e.every(e=>zn(e,t+1,n))}return i.length!==3||!i.every(e=>[`field`,`op`,`value`].includes(e))||!Ln.includes(r.field)||!Rn.includes(r.op)?!1:r.op===`in`?Array.isArray(r.value)&&r.value.length>0&&r.value.length<=100&&r.value.every(e=>typeof e==`string`&&e.length<=1e3):r.op===`is`?typeof r.value==`boolean`||typeof r.value==`string`&&r.value.length<=1e3:typeof r.value==`string`&&r.value.length>0&&r.value.length<=1e3}var Bn=R({id:Pn,name:H().trim().min(1).max(100),enabled:I().default(!0),condition:B().refine(e=>zn(e),`Use field/op/value, nonempty all/any/not groups (maximum depth 5 and 100 conditions), or a top-level always:true fallback`),action:te(`type`,[R({type:L(`ignore`)}).strict(),R({type:L(`agent`),agent:H().trim().min(1).max(100).regex(/^[a-z][a-z0-9_-]*$/),profile:H().min(1).max(100).optional(),model:H().trim().min(1).max(200).regex(/^[a-z0-9][a-z0-9._:/@+-]*$/i).optional(),project_id:H().min(1).max(100)}).strict()])}).strict(),Vn=R({id:Pn,name:H().trim().min(1).max(100),chat_id:H().trim().min(1).max(200),thread_id:H().trim().min(1).max(200).optional(),user_ids:V(H().trim().min(1).max(100)).max(100).default([]),project_ids:V(H().min(1).max(100)).max(100).default([]),inbound:I().default(!1),outbound:I().default(!0),attention:I().default(!1),notifications:kn.optional()}).strict(),Hn=R({id:Pn,name:H().trim().min(1).max(100),provider:An,enabled:I().default(!1),revision:W().int().min(0).default(0),config:In.default({}),credentials:z(H(),H().max(1e4)).default({}),targets:V(Vn).max(100).default([]),routes:V(Bn).max(100).default([])}).strict().superRefine((e,t)=>{let n=Mn.safeParse(e.config.commands??[]);n.success||t.addIssue({code:`custom`,message:n.error.message,path:[`config`,`commands`]});for(let n of[`targets`,`routes`])new Set(e[n].map(e=>e.id)).size!==e[n].length&&t.addIssue({code:`custom`,message:`Duplicate ${n} IDs`,path:[n]});e.routes.some((t,n)=>X(t.condition)&&n!==e.routes.length-1)&&t.addIssue({code:`custom`,message:`The Otherwise rule must be last; only one is allowed`,path:[`routes`]})}),Un=R({text:H().min(1).max(1e5),format:U([`markdown`,`plain`]).default(`markdown`),links:V(R({label:H().min(1).max(100),url:F().regex(/^https?:\/\//)}).strict()).max(20).default([])}).strict();R({connection:Pn,target:Pn,message:Un,overrides:In.optional().describe(`Native provider message payload. All message fields pass through; explicit fields replace generated fields. Credentials and destination are controlled by ORC.`),project_id:H().min(1).max(100).nullable().optional(),idempotency_key:H().min(1).max(200).optional(),thread_id:H().min(1).max(200).optional()}).strict().omit({connection:!0,target:!0,idempotency_key:!0}),R({id:Pn,name:H(),provider:An,enabled:I(),revision:W().int(),config:In,targets:V(Vn),routes:V(Bn),credentials:z(H(),R({configured:I(),source:U([`environment`,`stored`,`missing`])})),identity:R({id:H(),name:H()}).nullable(),status:U([`disabled`,`setup`,`ready`,`error`]),error:H().nullable()}),R({id:H(),connection:H(),target:H(),project_id:H().nullable(),status:U([`sending`,`accepted`,`failed`,`unknown`,`partial`]),provider_ids:V(H()),destination:R({chat_id:H(),thread_id:H().optional()}).optional(),error:H().nullable(),created_at:W()});var Wn={sender:`Sender ID`,chat:`Chat / channel ID`,thread:`Thread ID`,text:`Message text`,command:`Command`,is_direct:`Direct message`,is_mention:`Mentions bot`,kind:`Event type`},Gn={is:`is`,in:`is one of`,contains:`contains`,starts_with:`starts with`},Kn={is:`is not`,in:`is not one of`,contains:`does not contain`,starts_with:`does not start with`},qn=`form-control form-control-single w-full`;function Jn(e){let t=crypto.randomUUID();if(`all`in e)return{id:t,type:`all`,children:e.all.map(Jn)};if(`any`in e)return{id:t,type:`any`,children:e.any.map(Jn)};if(`not`in e)return{id:t,type:`not`,child:Jn(e.not)};if(`always`in e)throw Error(`Otherwise rules have no conditions`);return{id:t,type:`condition`,clause:e}}function Yn(e){return e.type===`condition`?e.clause:e.type===`not`?{not:Yn(e.child)}:e.type===`all`?{all:e.children.map(Yn)}:{any:e.children.map(Yn)}}function Xn(){return Jn({field:`text`,op:`contains`,value:``})}function Zn(e){return zn(e)?`always`in e?`Every remaining authorized message`:`all`in e||`any`in e?`(${(`all`in e?e.all:e.any).map(Zn).join(`all`in e?` AND `:` OR `)})`:`not`in e?`field`in e.not?Qn(e.not,!0):`NOT ${Zn(e.not)}`:Qn(e):`Invalid conditions`}function Qn(e,t=!1){let n=Array.isArray(e.value)?e.value.join(`, `):typeof e.value==`boolean`?e.value?`Yes`:`No`:e.value;return`${Wn[e.field]} ${t?Kn[e.op]:Gn[e.op]} ${n||`“”`}`}function $n({node:e,onChange:t,onRemove:n,depth:r=0}){let i=e.type===`not`,a=i?e.child:e,o=n=>t(i?{...e,child:n}:n),s=()=>t(i?{...a,id:e.id}:{id:e.id,type:`not`,child:e}),c=n&&(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a.type===`condition`?`Remove condition`:`Remove group`,title:a.type===`condition`?`Remove condition`:`Remove group`,onClick:n,children:(0,J.jsx)(u,{className:`size-4`})});if(a.type===`not`)return(0,J.jsxs)(`fieldset`,{className:`min-w-0 space-y-2 border-l-2 border-border pl-3`,"data-testid":`channel-condition-group`,children:[(0,J.jsx)(`legend`,{className:`text-sm`,children:`Exclude matches`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,onClick:s,children:`Remove exclusion`}),c,(0,J.jsx)($n,{node:a,onChange:o,depth:r+1})]});if(a.type!==`condition`)return(0,J.jsxs)(`fieldset`,{className:`min-w-0 space-y-2 border-l-2 border-border pl-3`,"data-testid":`channel-condition-group`,children:[(0,J.jsx)(`legend`,{className:`sr-only`,children:`Condition group`}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,J.jsxs)(`select`,{"aria-label":`Group match`,className:`${qn} max-w-52`,value:a.type,onChange:e=>o({...a,type:e.target.value}),children:[(0,J.jsx)(`option`,{value:`all`,children:`Match all (AND)`}),(0,J.jsx)(`option`,{value:`any`,children:`Match any (OR)`})]}),(0,J.jsxs)(`label`,{className:`inline-flex min-h-11 items-center gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary`,checked:i,onChange:s,disabled:!i&&r>=5}),`Exclude matches (NOT)`]}),c]}),(0,J.jsx)(`div`,{className:`space-y-3`,children:a.children.map(e=>(0,J.jsx)($n,{node:e,depth:r+(i?2:1),onChange:t=>o({...a,children:a.children.map(n=>n.id===e.id?t:n)}),onRemove:a.children.length>1?()=>o({...a,children:a.children.filter(t=>t.id!==e.id)}):void 0},e.id))}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,J.jsx)(l,{type:`button`,variant:`ghost`,disabled:r+ +!!i>=5,onClick:()=>o({...a,children:[...a.children,Xn()]}),children:`Add condition`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,disabled:r+ +!!i>=4,onClick:()=>o({...a,children:[...a.children,{id:crypto.randomUUID(),type:`any`,children:[Xn()]}]}),children:`Add group`})]})]});let d=a.clause,f=d.field===`is_direct`||d.field===`is_mention`,p=e=>o({...a,clause:e}),m=f?[`true`,`false`]:[`message`,`action`],h=Array.isArray(d.value)?d.value.join(`, `):String(d.value);return(0,J.jsx)(`div`,{className:`space-y-1`,"data-testid":`channel-condition-row`,children:(0,J.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_minmax(0,1.25fr)] items-start gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1.3fr)_auto]`,children:[(0,J.jsx)(`select`,{"aria-label":`Condition field`,className:qn,title:Wn[d.field],value:d.field,onChange:e=>{let t=e.target.value;p({field:t,op:`is`,value:t===`is_direct`||t===`is_mention`?!0:t===`kind`?`message`:``})},children:Ln.map(e=>(0,J.jsx)(`option`,{value:e,children:e===`is_direct`?`Private chat`:e===`chat`?`Chat ID`:Wn[e]},e))}),(0,J.jsx)(`select`,{"aria-label":`Condition comparison`,className:qn,value:`${i?`not:`:``}${d.op}`,onChange:n=>{let r=n.target.value.replace(`not:`,``),i=n.target.value.startsWith(`not:`),o=r===`in`?Array.isArray(d.value)?d.value:[String(d.value)]:Array.isArray(d.value)?d.value.join(`, `):d.value,s={...a,clause:{...d,op:r,value:o}};t(i?{id:e.id,type:`not`,child:s}:{...s,id:e.id})},children:Rn.filter(e=>!f||e===`is`||e===d.op).flatMap(e=>[(0,J.jsx)(`option`,{value:e,children:Gn[e]},e),(0,J.jsx)(`option`,{value:`not:${e}`,children:Kn[e]},`not:${e}`)])}),(0,J.jsxs)(`div`,{className:`col-span-2 flex min-w-0 items-start gap-1 sm:contents`,children:[(0,J.jsx)(`div`,{className:`min-w-0 flex-1`,children:(f||d.field===`kind`)&&d.op===`is`?(0,J.jsxs)(`select`,{"aria-label":`Condition value`,className:qn,value:h,onChange:e=>p({...d,value:f?e.target.value===`true`:e.target.value}),children:[!m.includes(h)&&(0,J.jsx)(`option`,{value:h,children:h||`Empty`}),m.map(e=>(0,J.jsx)(`option`,{value:e,children:f?e===`true`?`Yes`:`No`:e===`message`?`Message`:`Button action`},e))]}):(0,J.jsx)(K,{"aria-label":`Condition value`,value:h,placeholder:d.op===`in`?`Separate values with commas`:d.field===`command`?`Command name without /`:`Value`,onChange:e=>p({...d,value:d.op===`in`?e.target.value.split(`,`).map(e=>e.trim()):e.target.value})})}),(0,J.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[c,!n&&r===0&&(0,J.jsx)(l,{type:`button`,variant:`ghost`,disabled:r>=4,onClick:()=>o({id:crypto.randomUUID(),type:`all`,children:[a,Xn()]}),children:`Add condition`})]})]})]})})}function er({value:e,onChange:t,onValidity:n}){let[r,i]=(0,q.useState)(()=>Jn(e)),a=zn(Yn(r));return(0,J.jsxs)(`div`,{className:`min-w-0 space-y-2`,"data-testid":`channel-condition-builder`,children:[(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`When`}),(0,J.jsx)($n,{node:r,onChange:e=>{let r=Yn(e);i(e),t(r),n(zn(r))}}),!a&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:`Complete the condition values. Groups support up to 5 levels and 100 conditions.`})]})}function tr({label:e,checked:t,disabled:n,onChange:r}){return(0,J.jsxs)(`label`,{className:`inline-flex min-h-11 items-center gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary`,checked:t,disabled:n,onChange:e=>r(e.target.checked)}),e]})}function nr({target:e,projects:t,onChange:n}){let r=e.notifications??kn.parse({}),[i,a]=(0,q.useState)(`job.failed`),[o,s]=(0,q.useState)(``),[c,u]=(0,q.useState)(null),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(!1);function h(e){u(null),n(e)}function g(e,t){return(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-4`,children:t.map(t=>(0,J.jsx)(tr,{label:t,checked:r[e].includes(t),onChange:n=>h({...r,[e]:n?[...r[e],t]:r[e].filter(e=>e!==t)})},t))})}return(0,J.jsxs)(`div`,{"data-testid":`channel-notification-filters`,className:`space-y-2`,children:[(0,J.jsx)(tr,{label:`Forward notifications`,checked:r.enabled,onChange:e=>h({...r,enabled:e})}),(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:`Safe summaries and links only. Uses this recipient’s project restrictions. Does not allow replies or approvals. Replaces interactive question delivery for this recipient while selected.`}),r.enabled&&(0,J.jsxs)(`details`,{className:`border-t border-border`,children:[(0,J.jsx)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:`Notification filters and preview`}),(0,J.jsxs)(`div`,{className:`space-y-3 pb-2`,children:[(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:`Empty groups match all known values. Selected groups must all match. New types are excluded by default.`}),(0,J.jsxs)(`fieldset`,{children:[(0,J.jsx)(`legend`,{className:`text-sm font-medium`,children:`Types`}),g(`types`,On)]}),(0,J.jsxs)(`fieldset`,{children:[(0,J.jsx)(`legend`,{className:`text-sm font-medium`,children:`Categories`}),g(`categories`,[`human`,`agent`,`job`])]}),(0,J.jsxs)(`fieldset`,{children:[(0,J.jsx)(`legend`,{className:`text-sm font-medium`,children:`Severity`}),g(`levels`,[`needs-you`,`done`])]}),(0,J.jsxs)(`fieldset`,{children:[(0,J.jsx)(`legend`,{className:`text-sm font-medium`,children:`Outcome`}),g(`outcomes`,[`waiting`,`success`,`failure`])]}),(0,J.jsx)(tr,{label:`Include new or unknown types`,checked:r.include_unknown,onChange:e=>h({...r,include_unknown:e})}),(0,J.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{className:`grid gap-1 text-sm`,children:[`Preview event`,(0,J.jsx)(`select`,{"data-testid":`notification-preview-type`,className:`form-control form-control-single w-full`,value:i,onChange:e=>{a(e.target.value),u(null)},children:[...On,`future.custom`].map(e=>(0,J.jsx)(`option`,{children:e},e))})]}),(0,J.jsxs)(`label`,{className:`grid gap-1 text-sm`,children:[`Preview project`,(0,J.jsxs)(`select`,{"data-testid":`notification-preview-project`,className:`form-control form-control-single w-full`,value:o,onChange:e=>{s(e.target.value),u(null)},children:[(0,J.jsx)(`option`,{value:``,children:`Unassigned`}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,J.jsx)(l,{type:`button`,variant:`outline`,"data-testid":`notification-filter-preview`,disabled:p,onClick:async()=>{m(!0),f(``);try{u(await _.channels.notificationPreview({filter:r,project_ids:e.project_ids,event:{type:i,level:i.endsWith(`finished`)?`done`:`needs-you`,project_id:o||null}}))}catch(e){f(e instanceof Error?e.message:`Preview failed`)}finally{m(!1)}},children:`Preview filters`}),c&&(0,J.jsxs)(`div`,{role:`status`,"data-testid":`notification-preview-result`,className:`text-sm`,children:[(0,J.jsx)(`p`,{children:c.matches?`Matches draft filters`:`Does not match draft filters`}),(0,J.jsxs)(`p`,{className:`text-xs text-outline`,children:[c.summary,` No message sent. Delivery also requires global forwarding, an enabled outbound connection and producer permission.`]})]}),d&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:d})]})]})]})}function rr({active:e}){let t=(0,q.useId)(),n=r(),a=i({queryKey:[`channel-notification-policy`],queryFn:_.channels.notificationPolicy,enabled:e}),[o,s]=(0,q.useState)(!1),c=i({queryKey:[`channel-notification-deliveries`],queryFn:_.channels.notificationDeliveries,enabled:e&&o,refetchInterval:e&&o?15e3:!1}),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(!1),[m,h]=(0,q.useState)(``),[g,v]=(0,q.useState)(``),y=u??a.data??{enabled:!1,base_url:``},b=f||a.isPending||!!a.error;return(0,J.jsxs)(`details`,{"data-testid":`channel-notification-settings`,className:`border-y border-border`,onToggle:e=>s(e.currentTarget.open),children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:[`Notification forwarding · `,a.data?.enabled?`enabled`:`paused`]}),(0,J.jsxs)(`div`,{className:`space-y-3 pb-3`,children:[(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:`Enable forwarding here and opt in each recipient below. Only new events after activation are forwarded; history and events during a pause are not replayed. In-app notifications stay enabled. An in-flight send may finish after pausing.`}),(0,J.jsx)(tr,{label:`Enable channel notification forwarding`,checked:y.enabled,disabled:b,onChange:e=>d({...y,enabled:e})}),(0,J.jsxs)(`label`,{htmlFor:t,className:`grid gap-1 text-sm`,children:[`ORC URL for source links`,(0,J.jsx)(K,{"data-testid":`notification-base-url`,id:t,type:`url`,placeholder:`https://orc.example.com`,value:y.base_url,disabled:b,onChange:e=>d({...y,base_url:e.target.value})})]}),(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:`Use the ORC origin reachable from your phone or channel client. No credentials, path or query parameters.`}),(0,J.jsx)(l,{type:`button`,size:`sm`,"data-testid":`notification-policy-save`,disabled:b,onClick:async()=>{p(!0),v(``),h(``);try{let e=await _.channels.saveNotificationPolicy(y);n.setQueryData([`channel-notification-policy`],e),d(null),h(e.enabled?`Notification forwarding enabled.`:`Notification forwarding paused.`)}catch(e){v(e instanceof Error?e.message:`Could not save policy`)}finally{p(!1)}},children:`Save forwarding settings`}),m&&(0,J.jsx)(`p`,{role:`status`,className:`text-sm`,children:m}),(g||a.error)&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:g||a.error?.message}),(0,J.jsxs)(`details`,{children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:[`Recent deliveries (`,c.data?.length??0,`)`]}),c.error&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:c.error.message}),c.data?.length===0&&(0,J.jsx)(`p`,{className:`py-2 text-sm text-outline`,children:`No notification deliveries yet.`}),(0,J.jsx)(`div`,{"data-testid":`notification-delivery-status`,className:`max-h-64 overflow-y-auto`,children:c.data?.map(e=>(0,J.jsxs)(`div`,{className:`border-t border-border py-2 text-xs`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2`,children:[(0,J.jsxs)(`span`,{children:[e.connection_id,` / `,e.target_id]}),(0,J.jsxs)(`span`,{children:[e.status,` · `,e.attempts,` attempt(s)`]})]}),e.error&&(0,J.jsx)(`p`,{className:`mt-1 text-error`,children:e.error}),(0,J.jsx)(`p`,{className:`mt-1 truncate text-outline`,title:e.notification_id,children:e.notification_id})]},`${e.notification_id}:${e.connection_id}:${e.target_id}`))})]})]})]})}var ir={all:[{field:`kind`,op:`is`,value:`message`},{field:`is_direct`,op:`is`,value:!0}]},ar=`form-control form-control-single w-full`;function or(e,t){let n=e.action;if(n.type===`ignore`)return`Ignore silently · no agent starts`;let r=t.find(e=>e.id===n.project_id);return`Agent: ${n.agent} · Project: ${r?.name??n.project_id}${n.model?` · Model: ${n.model}`:``}`}function sr(e){let{status:t,identity:n,error:r,credentials:i,...a}=e;return Hn.parse({...a,credentials:{}})}function cr({label:e,checked:t,onChange:n}){return(0,J.jsxs)(`label`,{className:`inline-flex min-h-11 cursor-pointer items-center gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`size-4 accent-primary`}),e]})}function Z({label:e,children:t}){let n=(0,q.useId)();return(0,J.jsxs)(`label`,{htmlFor:n,className:`grid min-w-0 gap-1 text-sm`,children:[(0,J.jsx)(`span`,{children:e}),(0,q.cloneElement)(t,{id:n})]})}function lr({value:e,projects:t,onSave:n,onCancel:r}){let[i,a]=(0,q.useState)(e),[o,s]=(0,q.useState)(``);return(0,J.jsxs)(`div`,{className:`space-y-3 border-t border-border py-3`,"data-testid":`channel-target-editor`,children:[(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsx)(Z,{label:`Recipient alias`,children:(0,J.jsx)(K,{"data-testid":`channel-target-id`,value:i.id,onChange:e=>a({...i,id:e.target.value})})}),(0,J.jsx)(Z,{label:`Display name`,children:(0,J.jsx)(K,{"data-testid":`channel-target-name`,value:i.name,onChange:e=>a({...i,name:e.target.value})})}),(0,J.jsx)(Z,{label:`Provider chat / channel ID`,children:(0,J.jsx)(K,{"data-testid":`channel-target-chat`,value:i.chat_id,onChange:e=>a({...i,chat_id:e.target.value})})}),(0,J.jsx)(Z,{label:`Thread ID (optional)`,children:(0,J.jsx)(K,{value:i.thread_id??``,onChange:e=>{let{thread_id:t,...n}=i;a(e.target.value?{...n,thread_id:e.target.value}:n)}})})]}),(0,J.jsx)(Z,{label:`Approved sender IDs (comma separated)`,children:(0,J.jsx)(K,{"data-testid":`channel-target-users`,value:i.user_ids.join(`, `),onChange:e=>a({...i,user_ids:e.target.value.split(`,`).map(e=>e.trim())})})}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-x-5`,children:[(0,J.jsx)(cr,{label:`Allow outbound`,checked:i.outbound,onChange:e=>a({...i,outbound:e})}),(0,J.jsx)(cr,{label:`Allow inbound`,checked:i.inbound,onChange:e=>a({...i,inbound:e})}),(0,J.jsx)(cr,{label:`Interactive questions and approvals`,checked:i.attention,onChange:e=>a({...i,attention:e})})]}),(0,J.jsx)(nr,{target:i,projects:t,onChange:e=>a({...i,notifications:e})}),(0,J.jsxs)(`details`,{children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:[`Project restrictions (`,i.project_ids.length||`all projects`,`)`]}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-4`,children:t.map(e=>(0,J.jsx)(cr,{label:e.name,checked:i.project_ids.includes(e.id),onChange:t=>a({...i,project_ids:t?[...i.project_ids,e.id]:i.project_ids.filter(t=>t!==e.id)})},e.id))}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No selection allows all projects. Inbound always requires approved sender IDs.`})]}),o&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:o}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(l,{type:`button`,"data-testid":`channel-target-apply`,onClick:()=>{try{let e=Vn.parse({...i,user_ids:i.user_ids.filter(Boolean)});if(e.inbound&&!e.user_ids.length)throw Error(`Inbound requires at least one approved sender ID.`);n(e)}catch(e){s(e instanceof Error?e.message:`Invalid recipient`)}},children:`Apply recipient`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,onClick:r,children:`Cancel`})]})]})}function ur({value:e,projects:t,onSave:n,onCancel:r}){let[i,a]=(0,q.useState)(e),[o,s]=(0,q.useState)(``),[c,u]=(0,q.useState)(zn(e.condition));return(0,J.jsxs)(`div`,{className:`space-y-3 border-t border-border py-3`,"data-testid":`channel-route-editor`,children:[(0,J.jsx)(Z,{label:`Rule name`,children:(0,J.jsx)(K,{"data-testid":`channel-route-name`,value:i.name,onChange:e=>a({...i,name:e.target.value})})}),(0,J.jsx)(cr,{label:`Rule enabled`,checked:i.enabled,onChange:e=>a({...i,enabled:e})}),X(i.condition)?(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Runs only when no enabled rule above matches. Recipient and project permissions still apply.`}):zn(e.condition)&&(0,J.jsx)(er,{value:e.condition,onChange:e=>a({...i,condition:e}),onValidity:u}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsx)(Z,{label:`Action`,children:(0,J.jsxs)(`select`,{"aria-label":`Route action`,className:ar,value:i.action.type,onChange:e=>a({...i,action:e.target.value===`ignore`?{type:`ignore`}:{type:`agent`,agent:`default`,project_id:t[0]?.id??``}}),children:[(0,J.jsx)(`option`,{value:`agent`,children:`Invoke agent`}),(0,J.jsx)(`option`,{value:`ignore`,children:`Ignore silently`})]})}),i.action.type===`agent`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Z,{label:`Agent backend`,children:(0,J.jsx)(K,{"data-testid":`channel-route-agent`,placeholder:`default, codex-cli, claude, …`,value:i.action.agent,onChange:e=>{i.action.type===`agent`&&a({...i,action:{...i.action,agent:e.target.value}})}})}),(0,J.jsx)(Z,{label:`Project`,children:(0,J.jsxs)(`select`,{"data-testid":`channel-route-project`,className:ar,value:i.action.project_id,onChange:e=>{i.action.type===`agent`&&a({...i,action:{...i.action,project_id:e.target.value}})},children:[(0,J.jsx)(`option`,{value:``,children:`Choose a project`}),t.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,J.jsx)(Z,{label:`Default model (optional)`,children:(0,J.jsx)(K,{"data-testid":`channel-route-model`,placeholder:`Use the agent default`,value:i.action.model??``,onChange:e=>{if(i.action.type===`agent`){let{model:t,...n}=i.action;a({...i,action:e.target.value?{...n,model:e.target.value}:n})}}})}),(0,J.jsx)(Z,{label:`Agent profile (optional)`,children:(0,J.jsx)(K,{value:i.action.profile??``,onChange:e=>{if(i.action.type===`agent`){let{profile:t,...n}=i.action;a({...i,action:e.target.value?{...n,profile:e.target.value}:n})}}})})]})]}),o&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:o}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(l,{type:`button`,"data-testid":`channel-route-apply`,disabled:!c,onClick:()=>{try{let e=Bn.safeParse(i);if(!e.success){let t=e.error.issues[0]?.path[0];s(t===`name`?`Give this rule a name.`:t===`action`?`Choose a project and a valid agent, model and profile.`:`Complete the rule conditions.`);return}n(e.data)}catch(e){s(e instanceof Error?e.message:`Invalid rule`)}},children:`Apply rule`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,onClick:r,children:`Cancel`})]})]})}function dr({draft:e,provider:t,projects:n,update:a,run:o,onClose:s}){let c=r(),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(null),[g,v]=(0,q.useState)(n[0]?.id??``),[y,b]=(0,q.useState)(`default`),{data:x}=Se(),S=Ue(),C=Array.from(new Set([`default`,...S,...x?.backends.map(e=>e.name)??[],y])),[w,T]=(0,q.useState)(``),[E,D]=(0,q.useState)(null),O=Nn(e.config),k=t=>{let n={...e.config,commands:t};a({...e,config:n}),M(JSON.stringify(n,null,2))},[A,ee]=(0,q.useState)(null),[j,M]=(0,q.useState)(JSON.stringify(e.config,null,2)),[N,P]=(0,q.useState)(``),F=i({queryKey:[`channel-pairing`,A?.id],queryFn:()=>_.channels.pairing(A?.id??``),enabled:!!A,refetchInterval:I});function I(e){return!e.state.data?.confirmed&&2e3}let[L,R]=(0,q.useState)({sender:``,chat:``,text:``,is_direct:!0,is_mention:!1}),z=f&&(0,J.jsx)(ur,{value:f,projects:n,onCancel:()=>p(null),onSave:t=>{let n=e.routes.some(e=>e.id===t.id)?e.routes.map(e=>e.id===t.id?t:e):X(t.condition)?[...e.routes,t]:[...e.routes.filter(e=>!X(e.condition)),t,...e.routes.filter(e=>X(e.condition))];a({...e,routes:n}),p(null)}},f.id),B=e.routes.find(e=>X(e.condition));return(0,J.jsxs)(`div`,{className:`space-y-4 border-t border-border pt-4`,"data-testid":`channel-editor`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,J.jsx)(`h3`,{className:`text-base font-medium`,children:e.revision?`Edit connection`:`Set up connection`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,onClick:s,children:`Close`})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsx)(Z,{label:`Connection ID`,children:(0,J.jsx)(K,{"data-testid":`channel-id`,disabled:e.revision>0,value:e.id,onChange:t=>a({...e,id:t.target.value})})}),(0,J.jsx)(Z,{label:`Name`,children:(0,J.jsx)(K,{"data-testid":`channel-name`,value:e.name,onChange:t=>a({...e,name:t.target.value})})})]}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.setup.join(` `)}),t.credentials.map(t=>(0,J.jsxs)(`div`,{className:`flex flex-wrap items-end gap-2`,children:[(0,J.jsx)(`div`,{className:`w-full min-w-0 sm:w-auto sm:flex-1`,children:(0,J.jsx)(Z,{label:t.label,children:(0,J.jsx)(K,{autoComplete:`off`,type:`password`,"data-testid":`channel-credential-${t.key}`,value:e.credentials[t.key]??``,placeholder:`Leave blank to keep the configured credential`,onChange:n=>a({...e,credentials:{...e.credentials,[t.key]:n.target.value}})})})}),(0,J.jsxs)(l,{type:`button`,variant:`outline`,onClick:()=>a({...e,credentials:{...e.credentials,[t.key]:`env:${t.env}`}}),children:[`Use `,t.env]})]},t.key)),e.provider===`slack`&&(0,J.jsx)(l,{type:`button`,variant:`outline`,onClick:()=>void o(async()=>{let e=await _.channels.manifest();return await navigator.clipboard.writeText(JSON.stringify(e,null,2)),`Slack app manifest copied. Create an app at api.slack.com/apps using this manifest.`}),children:`Copy Slack app manifest`}),(0,J.jsxs)(`details`,{children:[(0,J.jsx)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:`Provider configuration (advanced)`}),(0,J.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`Set connection-wide native message options under message_defaults. Per-message overrides take precedence. Keep credentials in the credential fields above.`}),(0,J.jsx)(`textarea`,{"aria-label":`Provider configuration JSON`,className:`form-control min-h-28 w-full font-mono text-xs`,value:j,onChange:t=>{M(t.target.value);try{a(Hn.parse({...e,config:JSON.parse(t.target.value)})),P(``)}catch{P(`Enter a valid JSON object for provider configuration.`)}}}),N&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:N})]}),(0,J.jsx)(cr,{label:`Connection enabled`,checked:e.enabled,onChange:t=>a({...e,enabled:t})}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(l,{"data-testid":`channel-save`,disabled:!!u||!!f||!!E||!!m||!!N,onClick:()=>void o(async()=>{let t=await _.channels.save(e);return a(sr(t)),await c.invalidateQueries({queryKey:[`channels`]}),t.error?`Saved. ${t.error}`:`Connection saved.`}),children:`Save connection`}),(0,J.jsx)(l,{variant:`outline`,onClick:()=>void o(async()=>{let t=await _.channels.verify(e.id);return`Verified ${t.name} (${t.id}).`}),children:`Verify identity`}),(0,J.jsxs)(l,{variant:`outline`,onClick:()=>void o(async()=>{let t=await _.channels.pair(e.id);return ee(t),e.provider===`telegram`?`Open the pairing link, start the bot, then confirm the recipient here.`:`Open your workspace, message the ORC app with the pairing text below, then confirm the recipient here.`}),children:[`Pair my `,e.provider===`telegram`?`Telegram`:`Slack`]})]}),A&&(0,J.jsxs)(`div`,{className:`space-y-2 border-l-2 border-border pl-3`,children:[(0,J.jsx)(`a`,{href:A.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex min-h-11 items-center underline`,children:e.provider===`telegram`?`Open Telegram pairing link`:`Open Slack workspace`}),e.provider===`slack`&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`p`,{className:`text-sm`,children:`Send this text in a direct message to the ORC app:`}),(0,J.jsx)(`code`,{className:`break-all text-xs`,children:A.message}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>void o(async()=>(await navigator.clipboard.writeText(A.message),`Pairing text copied.`)),children:`Copy pairing text`})]}),F.error&&(0,J.jsx)(`p`,{role:`alert`,children:F.error.message}),F.data?.candidate&&!F.data.confirmed&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`p`,{className:`text-sm`,children:[`Confirm user `,F.data.candidate.user_id,` in chat`,` `,F.data.candidate.chat_id,`. This sets the recipient alias “me”.`]}),(0,J.jsx)(l,{onClick:()=>void o(async()=>{await _.channels.confirmPairing(A.id);let t=(await _.channels.list()).find(t=>t.id===e.id);return t&&a(sr(t)),ee(null),await c.invalidateQueries({queryKey:[`channels`]}),`Recipient me paired. Enable inbound and add a route to invoke an agent.`}),children:`Confirm recipient`})]})]}),(0,J.jsxs)(`details`,{children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:[`Recipients (`,e.targets.length,`)`]}),(0,J.jsx)(`div`,{className:`divide-y divide-border`,children:e.targets.map(t=>(0,J.jsxs)(`div`,{className:`flex min-h-11 flex-wrap items-center justify-between gap-2 py-1`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,J.jsxs)(`span`,{className:`ml-2 text-muted-foreground`,children:[t.id,` ·`,` `,t.inbound&&t.outbound?`send + receive`:t.inbound?`receive only`:`send only`]})]}),(0,J.jsxs)(`div`,{className:`flex gap-1`,children:[(0,J.jsx)(l,{variant:`ghost`,"data-testid":`channel-enable-replies-${t.id}`,onClick:()=>{h(t.id),v(t.project_ids[0]??n[0]?.id??``)},children:`Set up agent replies`}),(0,J.jsxs)(l,{variant:`ghost`,onClick:()=>d({original:t.id,value:t}),children:[`Edit `,t.id]}),(0,J.jsxs)(l,{variant:`ghost`,onClick:()=>void o(async()=>{let n=await _.channels.send({connection:e.id,target:t.id,message:{text:`**ORC connected**
|
|
2
|
-
Your channel is ready for messages.`,format:`markdown`,links:[]},idempotency_key:crypto.randomUUID()});if(n.status!==`accepted`)throw Error(n.error??n.status);return`Test accepted by provider. Receipt ${n.id}.`}),children:[`Test `,t.id]})]})]},t.id))}),(0,J.jsx)(l,{variant:`outline`,onClick:()=>d({original:null,value:{id:e.targets.length?`recipient-${e.targets.length+1}`:`me`,name:``,chat_id:``,user_ids:[],project_ids:[],inbound:!1,outbound:!0,attention:!1}}),children:`Add recipient`}),m&&(0,J.jsxs)(`div`,{className:`space-y-2 border-t border-border py-3`,"data-testid":`channel-replies-setup`,children:[(0,J.jsxs)(`p`,{className:`text-sm`,children:[`Allow approved senders for `,m,` to talk to an agent and answer its questions.`]}),(0,J.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,J.jsx)(Z,{label:`Reply project`,children:(0,J.jsxs)(`select`,{className:ar,value:g,onChange:e=>v(e.target.value),"data-testid":`channel-replies-project`,children:[(0,J.jsx)(`option`,{value:``,children:`Choose project`}),n.map(e=>(0,J.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,J.jsx)(Z,{label:`Reply agent`,children:(0,J.jsx)(`select`,{className:ar,value:y,onChange:e=>b(e.target.value),"data-testid":`channel-replies-agent`,children:C.map(e=>(0,J.jsx)(`option`,{value:e,children:e==="default"?`Default (Chat Settings)`:e},e))})})]}),(0,J.jsx)(Z,{label:`Reply model (optional)`,children:(0,J.jsx)(K,{"data-testid":`channel-replies-model`,value:w,onChange:e=>T(e.target.value),placeholder:`Use the agent default`})}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The reply project is the default. Use “default” for the agent to follow Chat Settings. /projects, /agent and /model can change this conversation's choices within recipient permissions. The project needs a working directory. Existing earlier routing rules retain priority. Apply, then save the connection.`}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(l,{"data-testid":`channel-replies-apply`,disabled:!g||!y.trim(),onClick:()=>void o(async()=>{let t=e.targets.find(e=>e.id===m);if(!t?.user_ids.length)throw Error(`Pair this recipient or add approved sender IDs first.`);let n=Bn.parse({id:`replies-${t.id}`,name:`Replies to ${t.name}`,enabled:!0,condition:{all:[{field:`kind`,op:`is`,value:`message`},{field:`chat`,op:`is`,value:t.chat_id},...t.thread_id?[{field:`thread`,op:`is`,value:t.thread_id}]:[]]},action:{type:`agent`,agent:y.trim(),project_id:g,...w.trim()?{model:w.trim()}:{}}});return a({...e,targets:e.targets.map(e=>e.id===t.id?{...e,inbound:!0,outbound:!0,attention:!0,project_ids:e.project_ids.length?[...new Set([...e.project_ids,g])]:[]}:e),routes:[...e.routes.filter(e=>e.id!==n.id&&!X(e.condition)),n,...e.routes.filter(e=>X(e.condition))]}),h(null),`Agent replies configured. Save the connection to activate them.`}),children:`Apply agent replies`}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>h(null),children:`Cancel`})]})]}),u&&(0,J.jsx)(lr,{value:u.value,projects:n,onCancel:()=>d(null),onSave:t=>{if(e.targets.some(e=>e.id===t.id&&e.id!==u.original))throw Error(`Recipient alias already exists`);a({...e,targets:[...e.targets.filter(e=>e.id!==u.original),t]}),d(null)}},u.original??`new`)]}),(0,J.jsxs)(`details`,{children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:[`Custom commands (`,O.length,`)`]}),(0,J.jsx)(`p`,{className:`mb-2 text-xs text-muted-foreground`,children:`Shortcuts send a configured prompt to the routed agent. Use $ARGUMENTS for command arguments. Telegram: /summary. Slack: /orc summary. ORC controls cannot be replaced.`}),O.map(e=>(0,J.jsxs)(`div`,{className:`flex min-h-11 flex-wrap items-center justify-between gap-2 border-b border-border py-1`,children:[(0,J.jsxs)(`span`,{className:`min-w-0 text-sm`,children:[`/`,e.command,` · `,e.description]}),(0,J.jsxs)(l,{variant:`ghost`,onClick:()=>D({...e,original:e.command}),children:[`Edit /`,e.command]})]},e.command)),!E&&(0,J.jsx)(l,{variant:`outline`,onClick:()=>D({original:null,command:``,description:``,prompt:``}),children:`Add custom command`}),E&&(0,J.jsxs)(`div`,{className:`space-y-2 py-3`,"data-testid":`channel-command-editor`,children:[(0,J.jsx)(Z,{label:`Command name`,children:(0,J.jsx)(K,{"data-testid":`channel-command-name`,value:E.command,onChange:e=>D({...E,command:e.target.value}),placeholder:`summary`})}),(0,J.jsx)(Z,{label:`Command description`,children:(0,J.jsx)(K,{"data-testid":`channel-command-description`,value:E.description,onChange:e=>D({...E,description:e.target.value})})}),(0,J.jsx)(Z,{label:`Agent prompt`,children:(0,J.jsx)(`textarea`,{className:`form-control min-h-24 w-full`,"data-testid":`channel-command-prompt`,value:E.prompt,onChange:e=>D({...E,prompt:e.target.value})})}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(l,{"data-testid":`channel-command-apply`,onClick:()=>void o(async()=>{let{original:e,...t}=E,n=Mn.parse([...O.filter(t=>t.command!==e),t]);return k(n),D(null),`Command applied. Save the connection to activate it.`}),children:`Apply command`}),E.original&&(0,J.jsx)(l,{variant:`ghost`,onClick:()=>{k(O.filter(e=>e.command!==E.original)),D(null)},children:`Remove command`}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>D(null),children:`Cancel`})]})]})]}),(0,J.jsxs)(`details`,{children:[(0,J.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:[`Inbound routing (`,e.routes.length,`)`]}),(0,J.jsx)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:`Checked from top to bottom. The first enabled match handles the message; later rules do not run. Only approved senders and permitted projects can invoke an agent.`}),(0,J.jsx)(`ol`,{className:`divide-y divide-border`,"data-testid":`channel-route-order`,children:e.routes.filter(e=>!X(e.condition)).map((t,r,i)=>(0,J.jsxs)(`li`,{className:`min-w-0 py-3`,"data-testid":`channel-route-row`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,J.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center text-sm text-muted-foreground`,title:`Priority ${r+1}`,children:r+1}),(0,J.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,J.jsxs)(`p`,{className:`break-words text-sm font-medium`,children:[t.name,!t.enabled&&(0,J.jsx)(`span`,{className:`ml-2 font-normal text-muted-foreground`,children:`Disabled · skipped`})]}),(0,J.jsx)(`p`,{className:`line-clamp-2 break-words text-xs text-muted-foreground`,title:Zn(t.condition),children:Zn(t.condition)}),(0,J.jsx)(`p`,{className:`break-words text-xs`,children:or(t,n)})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 gap-0.5`,children:[(0,J.jsx)(l,{variant:`ghost`,size:`icon`,disabled:r===0,"aria-label":`Move ${t.name} up`,onClick:()=>{let t=[...e.routes];[t[r-1],t[r]]=[t[r],t[r-1]],a({...e,routes:t})},children:(0,J.jsx)(Je,{className:`size-4`})}),(0,J.jsx)(l,{variant:`ghost`,size:`icon`,disabled:r===i.length-1,"aria-label":`Move ${t.name} down`,onClick:()=>{let t=[...e.routes];[t[r],t[r+1]]=[t[r+1],t[r]],a({...e,routes:t})},children:(0,J.jsx)(Oe,{className:`size-4`})}),(0,J.jsx)(l,{variant:`ghost`,size:`icon`,"aria-label":`Edit rule ${t.name}`,onClick:()=>p(t),children:(0,J.jsx)(Le,{className:`size-4`})})]})]}),f?.id===t.id&&z]},t.id))}),!e.routes.some(e=>!X(e.condition))&&(0,J.jsx)(`p`,{className:`py-3 text-sm text-muted-foreground`,children:`No conditions yet. Add a rule for messages that need a specific agent or project.`}),(0,J.jsx)(l,{variant:`outline`,className:`mt-2`,onClick:()=>p({id:crypto.randomUUID(),name:`New rule`,enabled:!0,condition:ir,action:{type:`agent`,agent:`default`,project_id:n[0]?.id??``}}),children:`Add routing rule`}),f&&!X(f.condition)&&!e.routes.some(e=>e.id===f.id)&&z,(0,J.jsxs)(`div`,{className:`my-3 border-y border-border py-3`,"data-testid":`channel-route-default`,children:[(0,J.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,J.jsx)(`p`,{className:`text-sm font-medium`,children:`Otherwise`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`After all rules above, for any remaining authorized message.`}),(0,J.jsx)(`p`,{className:`break-words text-sm`,children:B?.enabled?or(B,n):`${B?`Default disabled. `:``}Show setup guidance; no agent starts.`})]}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>p(e.routes.find(e=>X(e.condition))??{id:crypto.randomUUID(),name:`Otherwise`,enabled:!0,condition:{always:!0},action:{type:`ignore`}}),children:B?`Edit default`:`Set default`})]}),f&&X(f.condition)&&z]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Apply each rule, then save the connection to activate changes. Preview below uses the last saved rules.`}),(0,J.jsxs)(`details`,{className:`mt-3`,children:[(0,J.jsx)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:`Test saved routing without invoking an agent`}),(0,J.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,J.jsx)(Z,{label:`Sender ID`,children:(0,J.jsx)(K,{value:L.sender,onChange:e=>R({...L,sender:e.target.value})})}),(0,J.jsx)(Z,{label:`Chat ID`,children:(0,J.jsx)(K,{value:L.chat,onChange:e=>R({...L,chat:e.target.value})})}),(0,J.jsx)(Z,{label:`Incoming text`,children:(0,J.jsx)(K,{value:L.text,onChange:e=>R({...L,text:e.target.value})})}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(cr,{label:`Direct message`,checked:L.is_direct,onChange:e=>R({...L,is_direct:e})}),(0,J.jsx)(cr,{label:`Mentions bot`,checked:L.is_mention,onChange:e=>R({...L,is_mention:e})})]})]}),(0,J.jsx)(l,{variant:`outline`,onClick:()=>void o(async()=>{let t=(await _.channels.list()).find(t=>t.id===e.id),r=await _.channels.routeTest(e.id,L),i=Bn.shape.action.safeParse(r.action);return r.authorized?r.route_id?(()=>{let e=t?.routes.find(e=>e.id===r.route_id);return`${e&&X(e.condition)?`Otherwise`:`Matched ${e?.name??r.route_id}`}: ${i.success?or({action:i.data},n):`No action`}`})():`No rule matched. Show setup guidance; no agent starts.`:`Sender/destination not authorized.`}),children:`Preview route`})]})]})]})}function fr({active:e}){let t=i({queryKey:[`channels`],queryFn:_.channels.list,enabled:e,refetchInterval:e?15e3:!1}),n=i({queryKey:[`channel-providers`],queryFn:_.channels.providers,enabled:e}),r=i({queryKey:[`channel-projects`],queryFn:()=>_.projects.listAll(),enabled:e}),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)({}),[u,d]=(0,q.useState)(`telegram`),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(``),[g,v]=(0,q.useState)(!1),y=async e=>{if(!g){v(!0),p(``),h(``);try{h(await e())}catch(e){p(e instanceof Error?e.message:`Channel action failed`)}finally{v(!1)}}},b=e=>{let{credentials:t,status:n,identity:r,error:i,...a}=e;c(t=>({...t,[e.id]:t[e.id]??Hn.parse({...a,credentials:{}})})),o(e.id)};return(0,J.jsxs)(`section`,{"aria-label":`Channel settings`,className:`max-w-3xl space-y-4`,"data-testid":`channel-settings`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsx)(`h2`,{className:`text-base font-medium`,children:`Channels`}),(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsxs)(`select`,{className:`form-control form-control-single w-32 min-w-0`,"aria-label":`New channel provider`,value:u,onChange:e=>d(e.target.value),children:[(0,J.jsx)(`option`,{value:`telegram`,children:`Telegram`}),(0,J.jsx)(`option`,{value:`slack`,children:`Slack`})]}),(0,J.jsx)(l,{"data-testid":`channel-add`,className:`shrink-0`,onClick:()=>{let e=`new-${crypto.randomUUID()}`;c(t=>({...t,[e]:Hn.parse({id:`${u}-${Date.now()}`,name:u===`telegram`?`Personal Telegram`:`Work Slack`,provider:u})})),o(e)},children:`Add channel`})]})]}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Send messages to approved recipients and route incoming messages to agents.`}),(0,J.jsx)(rr,{active:e}),(f||t.error||n.error)&&(0,J.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-error`,children:f||t.error?.message||n.error?.message}),m&&(0,J.jsx)(`p`,{role:`status`,className:`break-words text-sm`,children:m}),t.isPending&&(0,J.jsx)(`p`,{className:`text-sm`,children:`Loading channels…`}),(0,J.jsx)(`div`,{className:`divide-y divide-border`,children:t.data?.map(e=>(0,J.jsxs)(`div`,{className:`py-2`,"data-testid":`channel-row-${e.id}`,children:[(0,J.jsxs)(`div`,{className:`flex min-h-11 items-center justify-between gap-2`,children:[(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`div`,{className:`truncate text-sm font-medium`,title:e.name,children:e.name}),(0,J.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[e.provider,` · `,e.identity?.name??e.status,` · `,e.targets.length,` `,e.targets.length===1?`recipient`:`recipients`]})]}),(0,J.jsx)(l,{variant:`ghost`,className:`h-11 min-w-11 shrink-0 px-3 sm:h-8`,"aria-label":`Edit ${e.name}`,"aria-expanded":a===e.id,onClick:()=>b(e),children:`Edit`})]}),e.error&&(0,J.jsx)(`p`,{role:`alert`,className:`break-words text-sm text-error`,children:e.error})]},e.id))}),!t.isPending&&!t.data?.length&&(0,J.jsx)(`p`,{className:`py-3 text-sm text-muted-foreground`,children:`No channels configured. Add Telegram or Slack to get started.`}),(0,J.jsx)(`fieldset`,{disabled:g,className:`min-w-0`,children:Object.entries(s).map(([e,t])=>n.data?.find(e=>e.id===t.provider)&&(0,J.jsx)(`div`,{hidden:a!==e,children:(0,J.jsx)(dr,{draft:t,provider:n.data.find(e=>e.id===t.provider),projects:r.data?.projects??[],update:t=>{t.revision>0&&t.id!==e?(c(n=>{let{[e]:r,...i}=n;return{...i,[t.id]:t}}),o(t.id)):c(n=>({...n,[e]:t}))},run:y,onClose:()=>o(null)})},e))})]})}function pr({onManageProviders:e}){let[t,n]=(0,q.useState)(null),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let e=!1;return _.settings.get().then(t=>{if(e)return;let r=he.parse(t.chat??{});n(r),i(r.models.map(e=>`${e.agent}: ${e.id}`).join(`
|
|
3
|
-
`))}).catch(t=>{e||o(t.message)}),()=>{e=!0}},[]);async function u(){if(t){c(!0),o(``);try{let e=r.split(`
|
|
4
|
-
`).filter(e=>e.trim()).map(e=>{let t=e.match(/^([a-z][a-z0-9-]*):\s*(.+)$/i);if(!t)throw Error(`Use agent: model-id on each model line.`);return{agent:t[1]??``,id:t[2]??``}}),i=he.parse((await _.settings.get()).chat??{}),a=he.parse({...t,agent:i.agent,providerId:i.providerId,model:i.model,models:e});await _.settings.save({chat:a}),n(a),window.dispatchEvent(new Event(`orc-chat-settings-changed`)),o(`Chat defaults saved. They apply to new sessions on every device.`)}catch(e){o(e instanceof Error?e.message:`Chat settings could not be saved.`)}finally{c(!1)}}}return(0,J.jsxs)(`section`,{"aria-labelledby":`chat-settings-title`,className:`space-y-4`,"data-testid":`chat-settings`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`h2`,{id:`chat-settings-title`,className:`text-base font-medium`,children:`Chat`}),(0,J.jsx)(G,{label:`Chat defaults`,testId:`chat-defaults-help`,children:`Defaults for new sessions. Existing chats keep their configuration. Credentials stay on the execution host or in encrypted provider settings.`})]}),t&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-md border border-border p-3`,children:[(0,J.jsx)(`span`,{className:`text-sm`,children:`Provider and model defaults`}),(0,J.jsx)(l,{variant:`outline`,onClick:e,children:`Manage providers`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{htmlFor:`chat-model-catalog`,children:`Model picker choices`}),(0,J.jsx)(G,{label:`Model picker choices`,testId:`chat-model-catalog-help`,children:`One agent: model-id per line. Use model IDs supported by your installed agent and account.`})]}),(0,J.jsx)(A,{id:`chat-model-catalog`,"data-testid":`chat-model-catalog`,value:r,onChange:e=>i(e.target.value),placeholder:`codex: your-model-id
|
|
5
|
-
claude: your-model-id`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{htmlFor:`chat-system-prompt`,children:`Instructions`}),(0,J.jsx)(G,{label:`Chat instructions`,testId:`chat-system-help`,children:`Claude appends these to its coding system prompt. Codex and other agents receive them as turn instructions. Workspace rules remain enforced.`})]}),(0,J.jsx)(A,{id:`chat-system-prompt`,"data-testid":`chat-system-prompt`,rows:6,value:t.system,onChange:e=>n({...t,system:e.target.value})})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(P,{htmlFor:`chat-mcp`,children:`Tools connection`}),(0,J.jsx)(G,{label:`Tools connection`,testId:`chat-mcp-help`,children:`The ORC connection uses server credentials internally and serves meta tools that search, describe and invoke every ORC tool on demand. Host configuration may include other MCP servers; this setting does not disable them. Protected workspaces may also require ORC tools.`})]}),(0,J.jsxs)(`select`,{id:`chat-mcp`,"data-testid":`chat-mcp`,className:`min-h-11 w-full rounded-md border border-control-border bg-background px-3 text-base sm:text-sm`,value:t.mcp,onChange:e=>n({...t,mcp:e.target.value}),children:[(0,J.jsx)(`option`,{value:`orc`,children:`Connect ORC MCP`}),(0,J.jsx)(`option`,{value:`native`,children:`Use the agent’s host configuration`})]})]}),(0,J.jsx)(Te,{config:t,onChange:n,disabled:s}),(0,J.jsx)(l,{"data-testid":`chat-settings-save`,disabled:s,onClick:()=>void u(),children:s?`Saving…`:`Save chat defaults`})]}),a&&(0,J.jsx)(`p`,{role:`status`,"data-testid":`chat-settings-feedback`,className:`wrap-break-word text-sm text-muted-foreground`,children:a})]})}var mr=[{value:`http`,label:`MCP HTTP`},{value:`sse`,label:`MCP SSE`},{value:`stdio`,label:`MCP stdio`},{value:`openapi`,label:`OpenAPI`},{value:`graphql`,label:`GraphQL`}],hr=e=>mr.find(t=>t.value===e)?.label??e??`Unknown`,gr=[`browser`,`device`,`client_credentials`],_r={browser:`Browser sign-in`,device:`Device code`,client_credentials:`Client credentials`},vr=[{value:`none`,label:`None`},{value:`token`,label:`Bearer token`},{value:`oauth`,label:`OAuth`}],yr={type:`http`,authMode:`none`,description:``,url:``,source:``,baseUrl:``,command:``,args:``,cwd:``,auth:``,headers:[],env:[],oauthFlow:``,oauthClientId:``,oauthClientSecret:``,oauthCallbackPort:``,allowedTools:``,disabledTools:``},br=e=>Object.entries(e??{}).map(([e,t])=>({key:e,value:t})),xr=e=>{let t=e.filter(e=>e.key.trim()).map(e=>[e.key.trim(),e.value]);return t.length?Object.fromEntries(t):void 0},Sr=(e,t=/[\n,]/)=>{let n=e.split(t).map(e=>e.trim()).filter(Boolean);return n.length?n:void 0},Cr=e=>e.trim()||void 0;function wr(e){let t={...yr,type:e.type,description:e.description??``,allowedTools:e.allowedTools?.join(`
|
|
6
|
-
`)??``,disabledTools:e.disabledTools?.join(`
|
|
7
|
-
`)??``};switch(e.type){case`stdio`:return{...t,command:e.command,args:e.args?.join(`
|
|
8
|
-
`)??``,cwd:e.cwd??``,env:br(e.env)};case`http`:case`sse`:{let n=!!(e.oauthFlow||e.oauthClientId||e.oauthCallbackPort);return{...t,authMode:n?`oauth`:e.auth?`token`:`none`,url:e.url,auth:e.auth??``,headers:br(e.headers),oauthFlow:e.oauthFlow??``,oauthClientId:e.oauthClientId??``,oauthCallbackPort:e.oauthCallbackPort?.toString()??``}}default:return{...t,authMode:e.auth?`token`:`none`,source:e.source,baseUrl:e.type===`openapi`?e.baseUrl??``:``,auth:e.auth??``,headers:br(e.headers)}}}var Tr=e=>e===`stdio`?[]:vr.filter(t=>t.value!==`oauth`||e===`http`||e===`sse`),Er=e=>!!(e.headers.length||e.baseUrl.trim()||e.cwd.trim()||e.allowedTools.trim()||e.disabledTools.trim());function Dr(e){let t={description:Cr(e.description),allowedTools:Sr(e.allowedTools),disabledTools:Sr(e.disabledTools)},n=e.authMode===`token`?Cr(e.auth):void 0,r=e.authMode===`oauth`;switch(e.type){case`stdio`:return{type:`stdio`,command:e.command.trim(),args:Sr(e.args,/\n/),cwd:Cr(e.cwd),env:xr(e.env),...t};case`http`:case`sse`:return{type:e.type,url:e.url.trim(),auth:n,headers:xr(e.headers),oauthFlow:r&&e.oauthFlow||void 0,oauthClientId:r?Cr(e.oauthClientId):void 0,oauthClientSecret:r&&e.oauthFlow===`client_credentials`?Cr(e.oauthClientSecret):void 0,oauthCallbackPort:r&&e.oauthCallbackPort.trim()?Number(e.oauthCallbackPort):void 0,...t};case`openapi`:return{type:`openapi`,source:e.source.trim(),baseUrl:Cr(e.baseUrl),auth:n,headers:xr(e.headers),...t};case`graphql`:return{type:`graphql`,source:e.source.trim(),auth:n,headers:xr(e.headers),...t}}}var Or=e=>/auth|token|key|secret|password|passwd|cookie|credential/i.test(e);function kr(e,t){if(!/^[A-Za-z0-9_-]+$/.test(e))return`Name can use only letters, numbers, hyphens and underscores.`;if(t.type===`stdio`)return t.command.trim()?null:`Command is required.`;if(t.type===`http`||t.type===`sse`){if(!t.url.trim())return`URL is required.`}else if(!t.source.trim())return`Spec URL or file is required.`;return t.authMode===`token`&&!t.auth.trim()?`Token is required.`:t.authMode===`oauth`&&t.oauthFlow===`client_credentials`&&!t.oauthClientId.trim()?`Client credentials need a client ID.`:null}var Q=`bg-background border-control-border text-on-surface font-body text-sm`,Ar=`font-label text-sm text-muted-foreground`;function jr({name:e,onClose:t}){let n=St(e);return e===null?(0,J.jsx)(Mr,{initialName:``,initial:yr,onClose:t}):n.data?(0,J.jsx)(Mr,{initialName:e,initial:wr(n.data.source),editing:!0,onClose:t}):(0,J.jsx)(we,{open:!0,dirty:!1,onClose:t,testId:`connection-editor`,children:()=>(0,J.jsx)(`p`,{role:n.error?`alert`:void 0,className:n.error?`text-sm text-error`:`text-sm text-muted-foreground`,children:n.error?n.error.message:`Loading connection…`})})}function Mr({initialName:e,initial:t,editing:n=!1,onClose:r}){let[i,a]=(0,q.useState)(e),[o,s]=(0,q.useState)(t),[c,u]=(0,q.useState)(null),[d,f]=(0,q.useState)(null),p=xt(),m=kt(),h=Dt(),g=pt(),_=e=>s(t=>{let n={...t,...e};return Tr(n.type).some(e=>e.value===n.authMode)||(n.authMode=`none`),n}),v=JSON.stringify([i,o]),y=i!==e||JSON.stringify(o)!==JSON.stringify(t),b=o.type===`http`||o.type===`sse`,x=Tr(o.type),S=d===v?m.data:void 0,C=d===v?m.error:null,w=()=>{let e=kr(i,o);return u(e),!e},T=()=>{w()&&(f(v),m.mutate({name:i,source:Dr(o)}))},E=(e,t)=>{e.preventDefault(),w()&&p.mutate({name:i,source:Dr(o),create:!n},{onSuccess:t})},D=async e=>{if(w())try{(!n||y)&&await p.mutateAsync({name:i,source:Dr(o),create:!n});let t=await h.mutateAsync(i);e(),t.authorizationUrl&&window.location.assign(t.authorizationUrl)}catch{}},O=p.isPending||h.isPending,k=e=>(0,J.jsxs)(l,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`connection-sign-in`,disabled:O,onClick:()=>void D(e),children:[(0,J.jsx)(Ht,{className:`size-4`}),h.isPending?`Signing in…`:n&&!y?`Sign in`:`Save and sign in`]});return(0,J.jsx)(we,{open:!0,dirty:y,busy:O,onClose:r,testId:`connection-editor`,children:(r,s)=>(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ne,{children:(0,J.jsx)(ae,{className:`font-headline text-base text-on-surface`,children:n?`Edit ${e}`:`Add connection`})}),(0,J.jsxs)(`form`,{noValidate:!0,onSubmit:e=>E(e,s),className:`min-h-0`,children:[(0,J.jsxs)(`div`,{className:`work-form-body space-y-5`,children:[(0,J.jsx)(Nr,{value:o.type,onChange:e=>_({type:e})}),(0,J.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,J.jsx)($,{label:`Name *`,hint:n?`Names can't change: OAuth tokens are stored under it.`:void 0,children:e=>(0,J.jsx)(K,{id:e,"data-testid":`connection-name`,value:i,onChange:e=>a(e.target.value),disabled:n,placeholder:`github`,autoFocus:!n,className:Q})}),(0,J.jsx)($,{label:`Description`,children:e=>(0,J.jsx)(K,{id:e,value:o.description,onChange:e=>_({description:e.target.value}),className:Q})})]}),b&&(0,J.jsx)($,{label:`Server URL *`,children:e=>(0,J.jsx)(K,{id:e,"data-testid":`connection-url`,inputMode:`url`,value:o.url,onChange:e=>_({url:e.target.value}),placeholder:`https://mcp.example.com/mcp`,className:Q})}),(o.type===`openapi`||o.type===`graphql`)&&(0,J.jsx)($,{label:o.type===`openapi`?`Spec URL or file *`:`Endpoint URL *`,children:e=>(0,J.jsx)(K,{id:e,"data-testid":`connection-source`,value:o.source,onChange:e=>_({source:e.target.value}),placeholder:o.type===`openapi`?`https://api.example.com/openapi.json`:`https://api.example.com/graphql`,className:Q})}),o.type===`stdio`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($,{label:`Command *`,children:e=>(0,J.jsx)(K,{id:e,"data-testid":`connection-command`,value:o.command,onChange:e=>_({command:e.target.value}),placeholder:`npx`,className:Q})}),(0,J.jsx)($,{label:`Arguments`,hint:`One per line.`,children:e=>(0,J.jsx)(A,{id:e,rows:3,value:o.args,onChange:e=>_({args:e.target.value}),className:`${Q} font-mono`})}),(0,J.jsx)(Lr,{label:`Environment variables`,pairs:o.env,onChange:e=>_({env:e})})]}),x.length>0&&(0,J.jsx)(Pr,{draft:o,editing:n,set:_,account:(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k(s),n&&(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`sm`,"data-testid":`connection-sign-out`,disabled:O||g.isPending,onClick:()=>g.mutate(e),children:`Sign out`}),g.isSuccess&&(0,J.jsx)(`span`,{role:`status`,className:`text-xs text-muted-foreground`,children:`Signed out.`})]})}),(0,J.jsxs)(`details`,{className:`group rounded-md border border-outline-variant`,open:Er(t)||void 0,children:[(0,J.jsx)(`summary`,{className:`flex min-h-11 cursor-pointer items-center px-3 text-sm font-medium`,children:`Advanced`}),(0,J.jsxs)(`div`,{className:`space-y-4 border-t border-outline-variant p-3`,children:[o.type===`openapi`&&(0,J.jsx)($,{label:`Base URL`,hint:`Overrides the servers listed in the spec.`,children:e=>(0,J.jsx)(K,{id:e,value:o.baseUrl,onChange:e=>_({baseUrl:e.target.value}),className:Q})}),o.type===`stdio`?(0,J.jsx)($,{label:`Working folder`,children:e=>(0,J.jsx)(K,{id:e,value:o.cwd,onChange:e=>_({cwd:e.target.value}),className:Q})}):(0,J.jsx)(Lr,{label:`Headers`,pairs:o.headers,onChange:e=>_({headers:e})}),(0,J.jsx)($,{label:`Allowed tools`,hint:`One name or glob per line. Empty allows all.`,children:e=>(0,J.jsx)(A,{id:e,rows:2,value:o.allowedTools,onChange:e=>_({allowedTools:e.target.value}),className:`${Q} font-mono`})}),(0,J.jsx)($,{label:`Disabled tools`,hint:`One name or glob per line.`,children:e=>(0,J.jsx)(A,{id:e,rows:2,value:o.disabledTools,onChange:e=>_({disabledTools:e.target.value}),className:`${Q} font-mono`})})]})]}),(0,J.jsx)(Fr,{pending:m.isPending&&d===v,result:S,error:C,signIn:b?k(s):null}),(c||p.error||h.error||g.error)&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:c??p.error?.message??h.error?.message??g.error?.message})]}),(0,J.jsxs)(re,{className:`work-form-footer`,children:[(0,J.jsx)(l,{type:`button`,variant:`outline`,size:`sm`,"data-testid":`connection-test`,onClick:T,disabled:m.isPending||O,className:`mr-auto`,children:m.isPending?`Testing…`:`Test connection`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`sm`,onClick:r,disabled:O,className:`font-label text-sm text-muted-foreground`,children:`Cancel`}),(0,J.jsx)(l,{type:`submit`,size:`sm`,"data-testid":`connection-save`,disabled:O||n&&!y,children:p.isPending?`Saving…`:n?`Save`:`Add connection`})]})]})]})})}function Nr({value:e,onChange:t}){return(0,J.jsxs)(`fieldset`,{children:[(0,J.jsx)(`legend`,{className:`${Ar} mb-1.5`,children:`Type`}),(0,J.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-5`,"data-testid":`connection-type`,children:mr.map(n=>(0,J.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center justify-center rounded-md border border-outline-variant px-2 text-center text-sm has-checked:border-primary has-checked:bg-primary/10 has-checked:font-medium has-focus-visible:ring-2 has-focus-visible:ring-ring`,children:[(0,J.jsx)(`input`,{type:`radio`,name:`connection-type`,value:n.value,checked:e===n.value,onChange:()=>t(n.value),className:`sr-only`}),n.label]},n.value))})]})}function Pr({draft:e,editing:t,set:n,account:r}){let i=e.oauthFlow===`client_credentials`;return(0,J.jsxs)(`fieldset`,{className:`space-y-4`,children:[(0,J.jsx)(`legend`,{className:`mb-2 text-sm font-medium`,children:`Authentication`}),(0,J.jsx)($,{label:`Method`,children:t=>(0,J.jsxs)(E,{value:e.authMode,onValueChange:e=>n({authMode:e}),children:[(0,J.jsx)(C,{id:t,"data-testid":`connection-auth`,className:Q,children:(0,J.jsx)(S,{})}),(0,J.jsx)(w,{className:`bg-surface border-outline-variant`,children:Tr(e.type).map(e=>(0,J.jsx)(T,{value:e.value,className:`text-sm`,children:e.label},e.value))})]})}),e.authMode===`token`&&(0,J.jsx)($,{label:`Token *`,hint:"A token or full header value. ${VAR} reads an environment variable.",children:t=>(0,J.jsx)(Ir,{id:t,label:`Token`,value:e.auth,onChange:e=>n({auth:e})})}),e.authMode===`oauth`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,J.jsx)($,{label:`Flow`,children:t=>(0,J.jsxs)(E,{value:e.oauthFlow||`browser`,onValueChange:e=>n({oauthFlow:e===`browser`?``:e}),children:[(0,J.jsx)(C,{id:t,className:Q,children:(0,J.jsx)(S,{})}),(0,J.jsx)(w,{className:`bg-surface border-outline-variant`,children:gr.map(e=>(0,J.jsx)(T,{value:e,className:`text-sm`,children:_r[e]},e))})]})}),(0,J.jsx)($,{label:i?`Client ID *`:`Client ID`,hint:i?void 0:`Blank registers a client automatically.`,children:t=>(0,J.jsx)(K,{id:t,value:e.oauthClientId,onChange:e=>n({oauthClientId:e.target.value}),className:Q})})]}),i?(0,J.jsx)($,{label:`Client secret`,hint:t?`Leave blank to keep the stored secret.`:`Stored with the tokens.`,children:t=>(0,J.jsx)(Ir,{id:t,label:`Client secret`,value:e.oauthClientSecret,onChange:e=>n({oauthClientSecret:e})})}):r]})]})}function Fr({pending:e,result:t,error:n,signIn:r}){if(e)return(0,J.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Testing connection…`});if(n)return(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:n.message});if(!t)return null;if(t.status===`connected`)return(0,J.jsxs)(`p`,{role:`status`,"data-testid":`connection-test-result`,className:`flex gap-2 text-sm`,children:[(0,J.jsx)(O,{className:`mt-0.5 size-4 shrink-0 text-success`,"aria-hidden":!0}),(0,J.jsxs)(`span`,{children:[`Connected · `,t.count,` `,t.count===1?`tool`:`tools`]})]});let i=t.status===`auth_required`;return(0,J.jsxs)(`div`,{role:`alert`,"data-testid":`connection-test-result`,className:`flex gap-2 text-sm ${i?``:`text-error`}`,children:[(0,J.jsx)(D,{className:`mt-0.5 size-4 shrink-0 ${i?`text-warning`:``}`,"aria-hidden":!0}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`p`,{children:i?`Reachable — the server needs a sign-in.`:`Couldn't connect.`}),t.message&&(0,J.jsx)(`p`,{className:`wrap-break-word text-xs text-muted-foreground`,children:t.message}),i&&r&&(0,J.jsx)(`div`,{className:`mt-2`,children:r})]})]})}function $({label:e,hint:t,children:n}){let r=(0,q.useId)();return(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:r,className:Ar,children:e}),n(r),t&&(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t})]})}function Ir({id:e,label:t,value:n,onChange:r}){let[i,a]=(0,q.useState)(!1);return(0,J.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(K,{id:e,"aria-label":e?void 0:t,type:i?`text`:`password`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value),className:`${Q} font-mono`}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":i?`Hide ${t}`:`Show ${t}`,"aria-pressed":i,onClick:()=>a(e=>!e),children:i?(0,J.jsx)(Bt,{className:`size-4`}):(0,J.jsx)(Ce,{className:`size-4`})})]})}function Lr({label:e,pairs:t,onChange:n}){let r=(e,r)=>n(t.map((t,n)=>n===e?{...t,...r}:t));return(0,J.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,J.jsx)(`legend`,{className:`${Ar} mb-1.5`,children:e}),t.map((i,a)=>(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 sm:flex-nowrap`,children:[(0,J.jsx)(K,{"aria-label":`${e} name ${a+1}`,value:i.key,onChange:e=>r(a,{key:e.target.value}),placeholder:`Name`,className:`${Q} font-mono sm:w-2/5`}),(0,J.jsx)(`div`,{className:`min-w-0 flex-1`,children:Or(i.key)?(0,J.jsx)(Ir,{label:`${e} value ${a+1}`,value:i.value,onChange:e=>r(a,{value:e})}):(0,J.jsx)(K,{"aria-label":`${e} value ${a+1}`,value:i.value,onChange:e=>r(a,{value:e.target.value}),placeholder:`Value`,className:`${Q} font-mono`})}),(0,J.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove ${i.key||`${e.toLowerCase()} row ${a+1}`}`,onClick:()=>n(t.filter((e,t)=>t!==a)),children:(0,J.jsx)(u,{className:`size-4`})})]},a)),(0,J.jsxs)(l,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>n([...t,{key:``,value:``}]),children:[(0,J.jsx)(ve,{className:`size-4`}),`Add `,e===`Headers`?`header`:`variable`]})]})}var Rr=e=>`resource:${e}`,zr=e=>`prompt:${e}`,Br=e=>e===`http`||e===`sse`||e===`stdio`;function Vr(e){let t=[...e.matchAll(/\{([^}]+)\}/g)].flatMap(e=>(e[1]??``).replace(/^[+#./;?&]/,``).split(`,`).map(e=>e.replace(/\*$|:\d+$/,``).trim()));return[...new Set(t.filter(Boolean))]}function Hr(e,t){let[n,r]=(0,q.useState)(``),i=n.trim().toLowerCase();return{query:n,setQuery:r,shown:(e??[]).filter(e=>!i||t(e).some(e=>e.toLowerCase().includes(i)))}}function Ur({label:e,value:t,onChange:n}){return(0,J.jsx)(K,{"aria-label":e,value:t,onChange:e=>n(e.target.value),placeholder:e,className:`bg-background border-control-border text-sm`})}function Wr({items:e,noun:t}){if(!e)return(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Loading `,t,`…`]});let n=e.filter(e=>e.enabled).length;return(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[n,` of `,e.length,` `,t,` available to agents.`]})}function Gr({children:e}){return e?(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:e}):null}function Kr({testId:e,label:t,description:n,allowed:r,toggling:i,onAllow:a,open:o,onOpen:s,children:c}){return(0,J.jsxs)(`li`,{"data-testid":e,className:`py-1`,children:[(0,J.jsxs)(`div`,{className:`flex min-h-11 items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,className:`size-4 shrink-0 accent-primary`,"aria-label":`Allow ${t}`,checked:r,disabled:i,onChange:e=>a(e.target.checked)}),(0,J.jsxs)(`button`,{type:`button`,"aria-expanded":o,onClick:s,className:`flex min-h-11 min-w-0 flex-1 items-center gap-2 text-left`,children:[(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`span`,{className:`block truncate font-mono text-sm`,children:t}),n&&(0,J.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:n})]}),o?(0,J.jsx)(x,{className:`size-4 shrink-0`,"aria-hidden":!0}):(0,J.jsx)(be,{className:`size-4 shrink-0`,"aria-hidden":!0})]})]}),o&&(0,J.jsx)(`div`,{className:`mb-2 space-y-3 rounded-md border border-border p-3`,children:c})]})}function qr({testId:e,callable:t,pending:n,idle:r,busy:i,onRun:a,blockedHint:o}){return(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(l,{type:`button`,size:`sm`,"data-testid":e,disabled:!t||n,onClick:a,children:n?i:r}),!t&&(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o})]})}function Jr({children:e}){return(0,J.jsx)(`pre`,{className:`max-h-80 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant whitespace-pre-wrap wrap-break-word`,children:e})}function Yr(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function Xr({fields:e,values:t,onChange:n}){let r=(0,q.useId)();return e.length===0?null:(0,J.jsx)(`div`,{className:`grid gap-3`,children:e.map(e=>(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsxs)(P,{htmlFor:`${r}-${e.name}`,className:`font-label text-sm text-muted-foreground`,children:[(0,J.jsx)(`span`,{className:`font-mono`,children:e.name}),e.required&&(0,J.jsx)(`span`,{"aria-hidden":!0,children:` *`})]}),(0,J.jsx)(K,{id:`${r}-${e.name}`,value:t[e.name]??``,required:e.required,placeholder:e.description??void 0,onChange:r=>n({...t,[e.name]:r.target.value}),className:`bg-background border-control-border font-mono text-sm`})]},e.name))})}var Zr=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==``));function Qr({name:e,enabled:t}){let n=yt(e,!0),r=_t(),[i,a]=(0,q.useState)(null),o=n.data&&[...n.data.resources.map(e=>({...e,key:e.uri,target:e.uri,template:!1})),...n.data.templates.map(e=>({...e,key:e.uriTemplate,target:e.uriTemplate,template:!0}))],{query:s,setQuery:c,shown:l}=Hr(o,e=>[e.name,e.target,e.description??``]);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Wr,{items:o,noun:`resources`}),(o?.length??0)>8&&(0,J.jsx)(Ur,{label:`Search resources`,value:s,onChange:c}),(0,J.jsx)(Gr,{children:n.data?.error??(n.error??r.error)?.message}),(0,J.jsxs)(`ul`,{className:`-mx-1 min-h-0 flex-1 divide-y divide-border overflow-y-auto px-1`,children:[l.map(n=>(0,J.jsx)(Kr,{testId:`resource-${n.key}`,label:n.target,description:n.description??n.name,allowed:n.enabled,toggling:r.isPending,onAllow:t=>r.mutate({name:e,tool:Rr(n.target),enabled:t}),open:i===n.key,onOpen:()=>a(i===n.key?null:n.key),children:(0,J.jsx)($r,{name:e,item:n,callable:t&&n.enabled})},n.key)),o&&l.length===0&&(0,J.jsx)(`li`,{className:`py-3 text-sm text-muted-foreground`,children:o.length?`No resources match.`:`This connection has no resources.`})]})]})}function $r({name:e,item:t,callable:n}){let r=ht(),[i,a]=(0,q.useState)({}),o=t.template?Vr(t.target):[];return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs`,children:[(0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`Name`}),(0,J.jsx)(`dd`,{className:`min-w-0 break-all font-mono`,children:t.name}),t.mimeType&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`Type`}),(0,J.jsx)(`dd`,{className:`font-mono`,children:t.mimeType})]})]}),t.description&&(0,J.jsx)(`p`,{className:`whitespace-pre-wrap text-sm`,children:t.description}),(0,J.jsx)(Xr,{fields:o.map(e=>({name:e})),values:i,onChange:a}),(0,J.jsx)(qr,{testId:`resource-read`,callable:n,pending:r.isPending,idle:`Read`,busy:`Reading…`,onRun:()=>r.mutate({name:e,uri:t.target,vars:Zr(i)}),blockedHint:`Allow the resource and enable the connection to read it.`}),(0,J.jsx)(Gr,{children:r.error?.message}),r.data&&(0,J.jsx)(ei,{result:r.data})]})}function ei({result:e}){return(0,J.jsxs)(`section`,{"aria-label":`Contents`,"data-testid":`resource-contents`,className:`space-y-2`,children:[e.contents.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The resource is empty.`}),e.contents.map((e,t)=>{let n=typeof e.mimeType==`string`?e.mimeType:null;return(0,J.jsxs)(`div`,{className:`space-y-1`,children:[typeof e.uri==`string`&&(0,J.jsxs)(`p`,{className:`break-all font-mono text-xs text-muted-foreground`,children:[e.uri,n&&` · ${n}`]}),typeof e.text==`string`?(0,J.jsx)(Jr,{children:Yr(e.text)}):typeof e.blob==`string`&&n?.startsWith(`image/`)?(0,J.jsx)(`img`,{src:`data:${n};base64,${e.blob}`,alt:typeof e.uri==`string`?e.uri:`Resource`,className:`max-h-80 rounded-lg`}):typeof e.blob==`string`?(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Binary content, `,Math.floor(e.blob.length*3/4),` bytes.`]}):(0,J.jsx)(Jr,{children:JSON.stringify(e,null,2)})]},t)})]})}function ti({name:e,enabled:t}){let n=Tt(e,!0),r=_t(),[i,a]=(0,q.useState)(null),o=n.data?.prompts,{query:s,setQuery:c,shown:l}=Hr(o,e=>[e.name,e.description??``]);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Wr,{items:o,noun:`prompts`}),(o?.length??0)>8&&(0,J.jsx)(Ur,{label:`Search prompts`,value:s,onChange:c}),(0,J.jsx)(Gr,{children:n.data?.error??(n.error??r.error)?.message}),(0,J.jsxs)(`ul`,{className:`-mx-1 min-h-0 flex-1 divide-y divide-border overflow-y-auto px-1`,children:[l.map(n=>(0,J.jsx)(Kr,{testId:`prompt-${n.name}`,label:n.name,description:n.description,allowed:n.enabled,toggling:r.isPending,onAllow:t=>r.mutate({name:e,tool:zr(n.name),enabled:t}),open:i===n.name,onOpen:()=>a(i===n.name?null:n.name),children:(0,J.jsx)(ni,{name:e,prompt:n,callable:t&&n.enabled})},n.name)),o&&l.length===0&&(0,J.jsx)(`li`,{className:`py-3 text-sm text-muted-foreground`,children:o.length?`No prompts match.`:`This connection has no prompts.`})]})]})}function ni({name:e,prompt:t,callable:n}){let r=bt(),[i,a]=(0,q.useState)({}),o=t.arguments.filter(e=>e.required&&!i[e.name]);return(0,J.jsxs)(J.Fragment,{children:[t.description&&(0,J.jsx)(`p`,{className:`whitespace-pre-wrap text-sm`,children:t.description}),(0,J.jsx)(Xr,{fields:t.arguments,values:i,onChange:a}),(0,J.jsx)(qr,{testId:`prompt-get`,callable:n&&o.length===0,pending:r.isPending,idle:`Render`,busy:`Rendering…`,onRun:()=>r.mutate({name:e,prompt:t.name,args:Zr(i)}),blockedHint:n?`Fill in ${o.map(e=>e.name).join(`, `)}.`:`Allow the prompt and enable the connection to render it.`}),(0,J.jsx)(Gr,{children:r.error?.message}),r.data&&(0,J.jsx)(ri,{result:r.data})]})}function ri({result:e}){return(0,J.jsxs)(`section`,{"aria-label":`Messages`,"data-testid":`prompt-messages`,className:`space-y-2`,children:[e.description&&(0,J.jsx)(`p`,{className:`text-sm`,children:e.description}),e.messages.map((e,t)=>{let n=e.content;return(0,J.jsxs)(`div`,{className:`space-y-1`,children:[(0,J.jsx)(Pt,{variant:`outline`,children:String(e.role)}),(0,J.jsx)(Jr,{children:n?.type===`text`&&typeof n.text==`string`?n.text:JSON.stringify(n,null,2)})]},t)})]})}var ii=`mt-0 flex min-h-0 flex-1 flex-col gap-3 data-[state=inactive]:hidden`;function ai({name:e,type:t,enabled:n,onClose:r}){let i=Br(t),[a,o]=(0,q.useState)(`tools`);return(0,J.jsx)(se,{open:!0,onOpenChange:e=>!e&&r(),children:(0,J.jsxs)(ie,{"data-testid":`connection-tools`,className:`flex max-h-[min(85dvh,calc(var(--app-height,100dvh)-2rem))] flex-col sm:max-w-2xl`,children:[(0,J.jsxs)(ne,{children:[(0,J.jsx)(ae,{className:`font-headline text-base text-on-surface`,children:i?e:`${e} tools`}),(0,J.jsxs)(oe,{className:`text-xs text-muted-foreground`,children:[`Choose what agents may use, or open an item to try it.`,!n&&` The connection is disabled, so nothing can be called.`]})]}),i?(0,J.jsxs)(N,{value:a,onValueChange:o,className:`flex min-h-0 flex-1 flex-col gap-3`,children:[(0,J.jsxs)(M,{className:`self-start`,children:[(0,J.jsx)(ee,{value:`tools`,children:`Tools`}),(0,J.jsx)(ee,{value:`resources`,children:`Resources`}),(0,J.jsx)(ee,{value:`prompts`,children:`Prompts`})]}),(0,J.jsx)(j,{value:`tools`,className:ii,children:(0,J.jsx)(oi,{name:e,enabled:n})}),(0,J.jsx)(j,{value:`resources`,className:ii,children:a===`resources`&&(0,J.jsx)(Qr,{name:e,enabled:n})}),(0,J.jsx)(j,{value:`prompts`,className:ii,children:a===`prompts`&&(0,J.jsx)(ti,{name:e,enabled:n})})]}):(0,J.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,children:(0,J.jsx)(oi,{name:e,enabled:n})})]})})}function oi({name:e,enabled:t}){let n=Ct(e),r=_t(),[i,a]=(0,q.useState)(null),{query:o,setQuery:s,shown:c}=Hr(n.data,e=>[e.id,e.description]),l=n.data?.length??0;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Wr,{items:n.data,noun:`tools`}),l>8&&(0,J.jsx)(Ur,{label:`Search tools`,value:o,onChange:s}),(0,J.jsx)(Gr,{children:(n.error??r.error)?.message}),(0,J.jsxs)(`ul`,{className:`-mx-1 min-h-0 flex-1 divide-y divide-border overflow-y-auto px-1`,children:[c.map(n=>(0,J.jsx)(Kr,{testId:`tool-${n.id}`,label:n.id,description:n.description,allowed:n.enabled,toggling:r.isPending,onAllow:t=>r.mutate({name:e,tool:n.id,enabled:t}),open:i===n.id,onOpen:()=>a(i===n.id?null:n.id),children:(0,J.jsx)(si,{name:e,tool:n.id,callable:t&&n.enabled})},n.id)),n.data&&c.length===0&&(0,J.jsx)(`li`,{className:`py-3 text-sm text-muted-foreground`,children:l?`No tools match.`:`This connection has no tools.`})]})]})}function si({name:e,tool:t,callable:n}){let r=mt(e,t),i=Ot(),[a,o]=(0,q.useState)(`{}`),[s,c]=(0,q.useState)(null),l=(0,q.useId)();return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Gr,{children:r.error?.message}),r.data&&(0,J.jsxs)(J.Fragment,{children:[r.data.description&&(0,J.jsx)(`p`,{className:`whitespace-pre-wrap text-sm`,children:r.data.description}),(0,J.jsxs)(`details`,{children:[(0,J.jsx)(`summary`,{className:`min-h-11 cursor-pointer content-center text-sm text-muted-foreground`,children:`Input schema`}),(0,J.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded-lg bg-background p-2 font-mono text-xs text-on-surface-variant`,children:JSON.stringify(r.data.inputSchema,null,2)})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:l,className:`font-label text-sm text-muted-foreground`,children:`Arguments (JSON)`}),(0,J.jsx)(A,{id:l,"data-testid":`tool-args`,rows:4,spellCheck:!1,value:a,onChange:e=>o(e.target.value),className:`bg-background border-control-border font-mono text-sm`})]}),(0,J.jsx)(qr,{testId:`tool-run`,callable:n,pending:i.isPending,idle:`Run`,busy:`Running…`,onRun:()=>{let n;try{n=JSON.parse(a||`{}`)}catch(e){c(`Arguments are not valid JSON: ${e.message}`);return}!n||typeof n!=`object`||Array.isArray(n)?c(`Arguments must be a JSON object.`):(c(null),i.mutate({name:e,tool:t,args:n}))},blockedHint:`Allow the tool and enable the connection to run it.`}),(0,J.jsx)(Gr,{children:s??i.error?.message}),i.data&&(0,J.jsx)(ci,{result:i.data})]})}function ci({result:e}){return(0,J.jsxs)(`section`,{"aria-label":`Result`,"data-testid":`tool-result`,className:`space-y-2`,children:[e.isError&&(0,J.jsx)(Pt,{variant:`outline`,children:`Error`}),e.content.map((e,t)=>(0,J.jsx)(Jr,{children:e.type===`text`&&typeof e.text==`string`?Yr(e.text):JSON.stringify(e,null,2)},t))]})}var li=[`url`,`claude-json`,`claude-cli`,`codex`,`spec`],ui={url:`URL`,"claude-json":`Claude Code .mcp.json`,"claude-cli":`Claude Code CLI`,codex:`Codex config.toml`,spec:`spec CLI`},di=/^[A-Za-z0-9_-]{1,64}$/,fi=/^[A-Za-z_][A-Za-z0-9_]*$/;function pi(e,t){return new URL(`/mcp`,new URL(e,t)).href}function mi({baseUrl:e,mode:t,projects:n}){let r=new URL(e);return t===`full`&&r.searchParams.set(`mode`,`full`),n.length===1?r.searchParams.set(`project`,n[0]??``):n.length>1&&r.searchParams.set(`projects`,n.join(`,`)),r.href}function hi(e,t){let n=mi(t),{name:r,secretEnv:i}=t,a=`'${n}'`;switch(e){case`url`:return n;case`claude-json`:return JSON.stringify({mcpServers:{[r]:{type:`http`,url:n,...i?{headers:{Authorization:`Bearer \${${i}}`}}:{}}}},null,2);case`claude-cli`:return`claude mcp add --transport http ${r} ${a}${i?` --header 'Authorization: Bearer \${${i}}'`:``}`;case`codex`:return[`[mcp_servers.${r}]`,`url = ${JSON.stringify(n)}`,...i?[`bearer_token_env_var = ${JSON.stringify(i)}`]:[]].join(`
|
|
9
|
-
`);case`spec`:return`spec add ${r} --mcp-http ${a}${i?` --auth env:${i}`:``}`}}var gi=`grid gap-4 border-b border-border py-5 lg:grid-cols-[minmax(160px,1fr)_minmax(0,2fr)]`;function _i(){let{data:e=[]}=Ge(),[t,n]=(0,q.useState)(()=>pi(m(),window.location.origin)),[r,i]=(0,q.useState)(`meta`),[a,o]=(0,q.useState)([]),[s,c]=(0,q.useState)(`claude-json`),[u,d]=(0,q.useState)(`orc`),[p,h]=(0,q.useState)(!0),[g,_]=(0,q.useState)(`ORC_API_SECRET`),[v,y]=(0,q.useState)(``);(0,q.useEffect)(()=>{f(m()).then(e=>h(e.required)).catch(()=>{})},[]);let b=(0,q.useMemo)(()=>{try{if(!/^https?:$/.test(new URL(t).protocol))return`Use an http(s) endpoint URL.`}catch{return`Enter a full endpoint URL, e.g. http://localhost:7700/mcp.`}return di.test(u)?p&&!fi.test(g)?`Enter a valid environment variable name.`:``:`Server name allows letters, digits, - and _.`},[t,u,p,g]),x=b?``:hi(s,{baseUrl:t,mode:r,projects:a,name:u,secretEnv:p?g:``});async function S(){try{await navigator.clipboard.writeText(x),y(`${ui[s]} copied.`)}catch{y(`Copy failed. Select the text and copy it manually.`)}}function C(e){return t=>{e(t),y(``)}}return(0,J.jsxs)(`section`,{"aria-labelledby":`mcp-server-title`,"data-testid":`settings-mcp`,children:[(0,J.jsx)(`h2`,{id:`mcp-server-title`,className:`mb-1 text-base font-medium`,children:`MCP server`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Build the connection for an agent. Options become query parameters on the ORC endpoint; nothing here changes the server.`}),(0,J.jsxs)(`div`,{className:gi,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(P,{htmlFor:`mcp-base-url`,children:`Endpoint`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Change the host when the agent reaches ORC by another address.`})]}),(0,J.jsx)(K,{id:`mcp-base-url`,"data-testid":`mcp-base-url`,value:t,onChange:e=>C(n)(e.target.value.trim())})]}),(0,J.jsxs)(`div`,{className:gi,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:`Tool surface`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Meta serves search, describe and invoke so agents load schemas on demand.`})]}),(0,J.jsx)(`fieldset`,{"aria-label":`Tool surface`,className:`flex flex-wrap gap-2`,children:[`meta`,`full`].map(e=>(0,J.jsx)(l,{variant:r===e?`secondary`:`outline`,"aria-pressed":r===e,"data-testid":`mcp-mode-${e}`,onClick:()=>C(i)(e),children:e===`meta`?`Meta tools`:`All tools`},e))})]}),(0,J.jsxs)(`div`,{className:gi,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:`Projects`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`No selection serves every project. Selected projects scope project-aware tools.`})]}),(0,J.jsxs)(`details`,{children:[(0,J.jsx)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-sm`,children:a.length?a.join(`, `):`All projects`}),(0,J.jsx)(`div`,{className:`flex flex-wrap gap-x-4`,children:e.map(e=>(0,J.jsxs)(`label`,{className:`inline-flex min-h-11 cursor-pointer items-center gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`mcp-project-${e.name}`,checked:a.includes(e.name),onChange:t=>C(o)(t.target.checked?[...a,e.name]:a.filter(t=>t!==e.name)),className:`size-4 accent-primary`}),e.name]},e.id))})]})]}),(0,J.jsxs)(`div`,{className:gi,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:`Authentication`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`The snippet names an environment variable holding the API secret or an access token from Security; the value itself is never shown.`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsxs)(`label`,{className:`inline-flex min-h-11 cursor-pointer items-center gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`mcp-use-secret`,checked:p,onChange:e=>C(h)(e.target.checked),className:`size-4 accent-primary`}),`Send a bearer token`]}),p&&(0,J.jsx)(K,{"aria-label":`Secret environment variable`,"data-testid":`mcp-secret-env`,value:g,onChange:e=>C(_)(e.target.value.trim())})]})]}),(0,J.jsxs)(`div`,{className:gi,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(P,{htmlFor:`mcp-client`,children:`Client`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Format to copy into the agent.`})]}),(0,J.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]`,children:[(0,J.jsx)(`select`,{id:`mcp-client`,"data-testid":`mcp-client`,className:`form-control form-control-single`,value:s,onChange:e=>C(c)(e.target.value),children:li.map(e=>(0,J.jsx)(`option`,{value:e,children:ui[e]},e))}),(0,J.jsx)(K,{"aria-label":`Server name`,"data-testid":`mcp-server-name`,value:u,disabled:s===`url`,onChange:e=>C(d)(e.target.value.trim())})]})]}),(0,J.jsxs)(`div`,{className:`mt-5 space-y-3`,children:[b?(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:b}):(0,J.jsx)(`pre`,{"data-testid":`mcp-snippet`,className:`overflow-x-auto whitespace-pre-wrap break-all rounded-md border border-border bg-surface p-3 font-mono text-[13px]`,children:x}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,J.jsxs)(l,{"data-testid":`mcp-copy`,disabled:!!b,onClick:()=>void S(),children:[v?(0,J.jsx)(Rt,{size:14}):(0,J.jsx)(Ke,{size:14}),`Copy`]}),v&&(0,J.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:v})]})]})]})}var vi=[`mcp`,`connections`],yi={mcp:`MCP server`,connections:`Connections`};function bi({active:e}){let[t,n]=ft(`integrationsTab`,`mcp`,vi);return(0,J.jsxs)(N,{value:t,onValueChange:e=>n(e),children:[(0,J.jsx)(M,{"aria-label":`Integrations`,className:`mb-5`,children:vi.map(e=>(0,J.jsx)(ee,{value:e,"data-testid":`integrations-tab-${e}`,children:yi[e]},e))}),(0,J.jsx)(j,{value:`mcp`,children:(0,J.jsx)(_i,{})}),(0,J.jsx)(j,{value:`connections`,children:(0,J.jsx)(xi,{enabled:e&&t===`connections`})})]})}function xi({enabled:e}){let{data:t,error:n,isLoading:r}=Et(e),i=vt(),a=gt(),o=wt(),[s,c]=(0,q.useState)(void 0),[u,d]=(0,q.useState)(null),[f,p]=(0,q.useState)(null),m=i.error??a.error;return(0,J.jsxs)(`section`,{"aria-labelledby":`connections-title`,"data-testid":`settings-connections`,children:[(0,J.jsxs)(`div`,{className:`mb-1 flex flex-wrap items-center justify-between gap-2`,children:[(0,J.jsx)(`h2`,{id:`connections-title`,className:`text-base font-medium`,children:`Connections`}),(0,J.jsxs)(l,{size:`sm`,"data-testid":`connection-add`,onClick:()=>c(null),children:[(0,J.jsx)(ve,{className:`size-4`}),`Add connection`]})]}),(0,J.jsxs)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:[`APIs and MCP servers in the `,(0,J.jsx)(`code`,{children:`spec`}),` CLI registry. ORC edits that registry directly, so changes here and from `,(0,J.jsx)(`code`,{children:`spec`}),` stay in step.`]}),r&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading connections…`}),(n??m)&&(0,J.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-error`,children:(n??m)?.message}),a.data&&(0,J.jsxs)(`p`,{role:`status`,className:`mb-3 text-sm text-muted-foreground`,children:[a.data.name,` refreshed: `,a.data.count,` tools.`]}),t&&t.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No connections yet.`}),t&&t.length>0&&(0,J.jsx)(`ul`,{className:`divide-y divide-border border-y border-border`,children:t.map(e=>(0,J.jsxs)(`li`,{"data-testid":`connection-${e.name}`,className:`flex min-h-11 flex-wrap items-center gap-x-3 gap-y-1 py-1`,children:[(0,J.jsx)(`label`,{className:`flex min-h-11 items-center`,children:(0,J.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-primary`,"aria-label":`Enable ${e.name}`,checked:e.enabled,disabled:i.isPending,onChange:t=>i.mutate({name:e.name,enabled:t.target.checked})})}),(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,J.jsx)(`span`,{className:`text-sm font-medium`,children:e.name}),(0,J.jsx)(Pt,{variant:`outline`,children:hr(e.type)}),!e.enabled&&(0,J.jsx)(Pt,{variant:`outline`,children:`Disabled`}),e.description&&(0,J.jsx)(`span`,{className:`min-w-0 basis-full truncate text-xs text-muted-foreground sm:basis-auto`,children:e.description})]}),(0,J.jsxs)(`div`,{className:`ml-auto flex items-center`,children:[(0,J.jsx)(l,{variant:`ghost`,size:`sm`,"data-testid":`connection-tools`,onClick:()=>d(e),children:Br(e.type)?`Browse`:`Tools`}),(0,J.jsx)(l,{variant:`ghost`,size:`icon`,"aria-label":`Refresh ${e.name}`,disabled:!e.enabled||a.isPending,onClick:()=>a.mutate(e.name),children:(0,J.jsx)(fe,{className:a.isPending&&a.variables===e.name?`size-4 animate-spin`:`size-4`})}),(0,J.jsx)(l,{variant:`ghost`,size:`icon`,"aria-label":`Edit ${e.name}`,onClick:()=>c(e.name),children:(0,J.jsx)(Le,{className:`size-4`})}),(0,J.jsx)(l,{variant:`ghost`,size:`icon`,"aria-label":`Delete ${e.name}`,onClick:()=>p(e.name),children:(0,J.jsx)(ct,{className:`size-4`})})]})]},e.name))}),s!==void 0&&(0,J.jsx)(jr,{name:s,onClose:()=>c(void 0)}),u&&(0,J.jsx)(ai,{name:u.name,type:u.type,enabled:u.enabled,onClose:()=>d(null)}),(0,J.jsx)(lt,{open:f!==null,title:`Delete connection`,description:`Delete ${f}? spec-cli also removes its cached spec and revokes its OAuth tokens. This can't be undone.`,isPending:o.isPending,onCancel:()=>p(null),onConfirm:()=>f&&o.mutate(f,{onSettled:()=>p(null)})})]})}var Si=q.forwardRef(({className:e,orientation:t=`horizontal`,decorative:n=!0,...r},i)=>(0,J.jsx)(en,{ref:i,decorative:n,orientation:t,className:c(`shrink-0 bg-surface-bright `,t===`horizontal`?`h-px w-full`:`h-full w-px`,e),...r}));Si.displayName=en.displayName;var Ci=1048576;function wi(e){return e===null?``:e>=1024*Ci?`${(e/1024/Ci).toFixed(1)} GB`:`${Math.round(e/Ci)} MB`}function Ti(e){return{session_embeddings:e.session_embeddings??!1,parser:e.parser,docling_enabled:e.docling_enabled,parser_timeout_secs:String(e.parser_timeout_secs),max_upload_mb:String(Math.round(e.max_upload_bytes/Ci)),usage_retention_days:String(e.usage_retention_days),provider:e.embedding.provider,base_url:e.embedding.base_url??``,model:e.embedding.model??``,dimensions:e.embedding.dimensions?String(e.embedding.dimensions):``,api_key:``,clear_key:!1}}var Ei={none:`Keyword search only. Add an embedding provider for semantic and hybrid search.`,ollama:`Local embeddings from Ollama, for example nomic-embed-text at http://localhost:11434.`,openai:`OpenAI or any OpenAI-compatible endpoint, for example text-embedding-3-small.`};function Di(){let e=Mt(),t=jt(),n=At(),r=Nt(),[i,a]=(0,q.useState)(null),[o,s]=(0,q.useState)(null),[c,u]=(0,q.useState)(!1),[d,f]=(0,q.useState)(!1),[p,m]=(0,q.useState)(!1);if((0,q.useEffect)(()=>{e.data&&a(Ti(e.data))},[e.data]),e.error)return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(`h2`,{className:`mb-1 text-base font-medium`,children:`Knowledge`}),(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:e.error.message})]});if(!i||!e.data)return null;let h=e.data,g=e=>h.env_overrides.includes(`ORC_KNOWLEDGE_${e}`),v=e=>{u(!1),a({...i,...e})},y=t.data?.parsers.find(e=>e.id===`docling`),b=t.data?.docling;async function x(e){f(!0),s(null);try{return await e(),await r(),!0}catch(e){return s(e instanceof Error?e.message:`Request failed`),!1}finally{f(!1)}}async function D(e){if(e.preventDefault(),!i)return;let t={session_embeddings:i.session_embeddings,parser:i.parser,docling_enabled:i.docling_enabled,parser_timeout_secs:Number(i.parser_timeout_secs),max_upload_bytes:Number(i.max_upload_mb)*Ci,usage_retention_days:Number(i.usage_retention_days),embedding:{provider:i.provider,base_url:i.base_url.trim()||null,model:i.model.trim()||null,dimensions:(e=>e.trim()?Number(e):null)(i.dimensions),...i.clear_key?{api_key:null}:i.api_key?{api_key:i.api_key}:{}}};await x(()=>_.kb.updateSettings(t))&&u(!0)}return(0,J.jsxs)(`section`,{"data-testid":`settings-knowledge`,"aria-labelledby":`settings-knowledge-title`,children:[(0,J.jsx)(`h2`,{id:`settings-knowledge-title`,className:`mb-1 text-base font-medium text-on-surface`,children:`Knowledge`}),(0,J.jsxs)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:[`How ORC parses uploads and searches knowledge bases. Saved on the server in`,` `,(0,J.jsx)(`code`,{className:`text-primary`,children:`~/.orc/config.json`}),`; files live in`,` `,(0,J.jsx)(`code`,{className:`break-all text-primary`,children:h.root}),`.`]}),(0,J.jsx)(Si,{className:`mb-4 bg-outline-variant`}),h.env_overrides.length>0&&(0,J.jsxs)(`p`,{className:`mb-4 text-sm text-warning`,"data-testid":`settings-knowledge-env`,children:[`Set by environment, these win over saved values: `,h.env_overrides.join(`, `)]}),(0,J.jsxs)(`form`,{onSubmit:D,className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium`,children:`Parsers`}),t.data?.parsers.map(e=>(0,J.jsxs)(`div`,{"data-testid":`settings-parser-${e.id}`,className:`rounded-md border border-outline-variant p-3 text-sm`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`font-medium`,children:e.label}),(0,J.jsxs)(`span`,{className:`text-xs text-outline`,children:[e.installed?`v${e.version}`:`not installed`,e.size_bytes?` · ${wi(e.size_bytes)}${e.installed?``:` download`}`:``]})]}),(0,J.jsx)(`p`,{className:`mt-1 text-outline`,children:e.description}),(0,J.jsxs)(`p`,{className:`mt-1 text-xs text-outline`,children:[`Formats: `,e.capabilities.formats.join(`, `)]}),e.detail&&(0,J.jsx)(`p`,{className:`mt-1 text-xs text-outline`,children:e.detail}),e.id===`docling`&&(0,J.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[b?.state===`installing`&&(0,J.jsxs)(`div`,{role:`status`,"data-testid":`settings-docling-progress`,className:`text-xs text-outline`,children:[b.step,(0,J.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-y-auto whitespace-pre-wrap font-mono`,children:b.log.slice(-8).join(`
|
|
10
|
-
`)})]}),b?.state===`failed`&&(0,J.jsx)(`p`,{role:`alert`,className:`text-xs text-error`,children:b.error}),e.installed?(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,J.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`settings-docling-enabled`,checked:i.docling_enabled,onChange:e=>v({docling_enabled:e.target.checked})}),`Use automatically for PDFs and images`]}),(0,J.jsxs)(l,{type:`button`,size:`sm`,variant:`ghost`,className:`text-error`,"data-testid":`settings-docling-remove`,onClick:()=>m(!0),children:[(0,J.jsx)(ct,{size:14}),`Remove`]})]}):(0,J.jsxs)(l,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`settings-docling-install`,disabled:d||b?.state===`installing`,onClick:()=>x(()=>_.kb.installDocling()),children:[(0,J.jsx)(k,{size:14}),b?.state===`installing`?`Installing…`:`Install Docling (${wi(y?.size_bytes??null)||`about 2 GB`})`]})]})]},e.id)),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-parser`,className:`text-sm text-muted-foreground`,children:`Default parser`}),(0,J.jsxs)(E,{value:i.parser,onValueChange:e=>v({parser:e}),disabled:g(`PARSER`),children:[(0,J.jsx)(C,{id:`settings-kb-parser`,"data-testid":`settings-kb-parser`,children:(0,J.jsx)(S,{})}),(0,J.jsxs)(w,{children:[(0,J.jsx)(T,{value:`auto`,children:`Automatic: Docling for PDFs and images when enabled`}),t.data?.parsers.map(e=>(0,J.jsx)(T,{value:e.id,disabled:!e.installed,children:e.label},e.id))]})]}),(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:`Knowledge bases can override it. Changing parsers applies to new uploads; reparse a document to apply it to existing ones.`})]}),(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-timeout`,className:`text-sm text-muted-foreground`,children:`Parse timeout (s)`}),(0,J.jsx)(K,{id:`settings-kb-timeout`,type:`number`,min:10,value:i.parser_timeout_secs,onChange:e=>v({parser_timeout_secs:e.target.value})})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-max-upload`,className:`text-sm text-muted-foreground`,children:`Max upload (MB)`}),(0,J.jsx)(K,{id:`settings-kb-max-upload`,type:`number`,min:1,value:i.max_upload_mb,onChange:e=>v({max_upload_mb:e.target.value})})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-retention`,className:`text-sm text-muted-foreground`,children:`Read log (days)`}),(0,J.jsx)(K,{id:`settings-kb-retention`,type:`number`,min:1,value:i.usage_retention_days,onChange:e=>v({usage_retention_days:e.target.value})})]})]})]}),(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium`,children:`Semantic search`}),(0,J.jsxs)(`label`,{className:`flex items-start gap-2 text-sm`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`settings-session-embeddings`,checked:i.session_embeddings,onChange:e=>v({session_embeddings:e.target.checked})}),(0,J.jsxs)(`span`,{children:[`Search coding sessions with embeddings`,(0,J.jsx)(`span`,{className:`block text-xs text-outline`,children:`Uses the provider below for session passages. Keyword search and transcript reading remain available when off. Enabling sends session text to this provider and indexes discovered project sessions.`})]})]}),n.data&&(0,J.jsxs)(`p`,{className:`text-xs text-outline`,"data-testid":`settings-embedding-status`,children:[n.data.embedding.ready?`Ready · ${n.data.embedding.model} · ${n.data.embedding.vector_backend}`:n.data.embedding.detail??`Not configured`,n.data.embedding.pending_chunks?` · ${n.data.embedding.pending_chunks} passages waiting`:``]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-provider`,className:`text-sm text-muted-foreground`,children:`Embedding provider`}),(0,J.jsxs)(E,{value:i.provider,onValueChange:e=>v({provider:e}),disabled:g(`EMBEDDING_PROVIDER`),children:[(0,J.jsx)(C,{id:`settings-kb-provider`,"data-testid":`settings-kb-provider`,children:(0,J.jsx)(S,{})}),(0,J.jsxs)(w,{children:[(0,J.jsx)(T,{value:`none`,children:`None`}),(0,J.jsx)(T,{value:`ollama`,children:`Ollama`}),(0,J.jsx)(T,{value:`openai`,children:`OpenAI-compatible`})]})]}),(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:Ei[i.provider]})]}),i.provider!==`none`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-model`,className:`text-sm text-muted-foreground`,children:`Model`}),(0,J.jsx)(K,{id:`settings-kb-model`,"data-testid":`settings-kb-model`,value:i.model,disabled:g(`EMBEDDING_MODEL`),onChange:e=>v({model:e.target.value}),placeholder:i.provider===`ollama`?`nomic-embed-text`:`text-embedding-3-small`})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-dimensions`,className:`text-sm text-muted-foreground`,children:`Dimensions`}),(0,J.jsx)(K,{id:`settings-kb-dimensions`,type:`number`,value:i.dimensions,onChange:e=>v({dimensions:e.target.value}),placeholder:`Model default`})]})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-base-url`,className:`text-sm text-muted-foreground`,children:`Base URL`}),(0,J.jsx)(K,{id:`settings-kb-base-url`,"data-testid":`settings-kb-base-url`,value:i.base_url,disabled:g(`EMBEDDING_URL`),onChange:e=>v({base_url:e.target.value}),placeholder:i.provider===`ollama`?`http://localhost:11434`:`https://api.openai.com/v1`})]}),(0,J.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,J.jsx)(P,{htmlFor:`settings-kb-api-key`,className:`text-sm text-muted-foreground`,children:i.provider===`ollama`?`Token (hosted or proxied Ollama)`:`API key`}),(0,J.jsx)(K,{id:`settings-kb-api-key`,type:`password`,autoComplete:`off`,"data-testid":`settings-kb-api-key`,value:i.api_key,disabled:i.clear_key||g(`EMBEDDING_API_KEY`),onChange:e=>v({api_key:e.target.value}),placeholder:h.embedding.api_key_set?`Saved. Type to replace`:`Not set`}),h.embedding.api_key_set&&(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-outline`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`settings-kb-api-key-clear`,checked:i.clear_key,onChange:e=>v({clear_key:e.target.checked,api_key:``})}),`Remove the saved key`]}),(0,J.jsxs)(`p`,{className:`text-xs text-outline`,children:[`Stored encrypted with the key in `,(0,J.jsx)(`code`,{children:`~/.orc/secret.key`}),` and never sent back to the browser. Sent as a bearer token to the base URL.`]})]}),(0,J.jsx)(`p`,{className:`text-xs text-outline`,children:`Changing the model re-embeds every passage in the background; keyword search keeps working meanwhile.`})]})]}),o&&(0,J.jsx)(`p`,{role:`alert`,"data-testid":`settings-knowledge-error`,className:`text-sm text-error`,children:o}),(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(l,{type:`submit`,"data-testid":`settings-knowledge-save`,disabled:d,children:`Save knowledge settings`}),c&&(0,J.jsx)(`span`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Saved`})]})]}),(0,J.jsx)(lt,{open:p,title:`Remove Docling`,description:`Deletes the Docling runtime and models from this machine. Documents it parsed keep their text; reparse them to use the basic parser.`,confirmLabel:`Remove`,isPending:d,onCancel:()=>m(!1),onConfirm:async()=>{m(!1),await x(()=>_.kb.uninstallDocling())}})]})}var Oi=R({default_mode:U([`meta`,`full`]).default(`meta`)}).strict(),ki=H().regex(/^[a-z][a-z0-9_-]{0,63}$/),Ai=R({name:ki,title:H().trim().min(1).max(120),description:H().max(1e3).default(``),content:H().trim().min(1).max(3e4)}).strict(),ji=V(Ai).max(50).refine(e=>new Set(e.map(e=>e.name)).size===e.length,{message:`Prompt names must be unique`}),Mi=Oi.extend({prompts:ji});function Ni(){let[e,t]=(0,q.useState)(null),[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(``),[c,u]=(0,q.useState)(!1);(0,q.useEffect)(()=>{let e=!1;return _.settings.mcp.get().then(n=>{e||t(Mi.parse(n))}).catch(t=>{e||(u(!0),s(t.message))}),()=>{e=!0}},[]);async function d(){a(!0),s(``),u(!1);try{let n=await _.settings.mcp.save(Mi.parse(e));t(n),s(`MCP settings saved. New connections use these defaults.`)}catch(e){u(!0),s(e instanceof Error?e.message:`MCP settings could not be saved.`)}finally{a(!1)}}function f(n,r){e&&t({...e,prompts:e.prompts.map((e,t)=>t===n?{...e,...r}:e)})}return(0,J.jsxs)(`section`,{"aria-labelledby":`mcp-settings-title`,"data-testid":`mcp-settings`,className:`space-y-5`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h2`,{id:`mcp-settings-title`,className:`text-base font-medium`,children:`MCP`}),(0,J.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Control how agents connect to this ORC server.`})]}),e&&(0,J.jsxs)(`fieldset`,{disabled:i,className:`min-w-0 space-y-5`,children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`mcp-default-mode`,children:`Default tool mode`}),(0,J.jsxs)(`select`,{id:`mcp-default-mode`,"data-testid":`mcp-default-mode`,className:`form-control form-control-single max-w-sm`,value:e.default_mode,onChange:n=>t({...e,default_mode:n.target.value}),children:[(0,J.jsx)(`option`,{value:`meta`,children:`Meta — discover tools on demand`}),(0,J.jsx)(`option`,{value:`full`,children:`Full — list every tool`})]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`An explicit connection mode overrides this default. Restart existing stdio clients to apply changes.`})]}),(0,J.jsxs)(`div`,{className:`border-y border-border py-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,J.jsxs)(`h3`,{className:`text-sm font-medium`,children:[`Prompts · `,e.prompts.length]}),(0,J.jsx)(l,{variant:`outline`,disabled:i||e.prompts.length>=50,"data-testid":`mcp-add-prompt`,onClick:()=>{let n=new Set(e.prompts.map(e=>e.name)),i=1;for(;n.has(`prompt-${i}`);)i++;r(e.prompts.length),t({...e,prompts:[...e.prompts,{name:`prompt-${i}`,title:`New prompt`,description:``,content:`Answer the user's request.
|
|
11
|
-
|
|
12
|
-
Request: {{request}}`}]})},children:`Add prompt`})]}),(0,J.jsxs)(`p`,{className:`my-2 text-xs text-muted-foreground`,children:[`Agents select these through MCP prompts; in chat, type `,(0,J.jsx)(`code`,{children:`/name`}),`. Use`,` `,(0,J.jsx)(`code`,{children:`{{request}}`}),` for the user's words and `,(0,J.jsx)(`code`,{children:`{{ui_catalog}}`}),` `,`for the current component catalog.`]}),(0,J.jsx)(`ul`,{className:`divide-y divide-border`,children:e.prompts.map((a,o)=>(0,J.jsxs)(`li`,{className:`py-2`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[(0,J.jsxs)(`span`,{className:`min-w-0 truncate text-sm`,children:[a.title,` `,(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a.name})]}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>r(n===o?null:o),"aria-expanded":n===o,children:`Edit`})]}),n===o&&(0,J.jsxs)(`fieldset`,{disabled:i,className:`mt-2 space-y-3`,"data-testid":`mcp-prompt-editor`,children:[(0,J.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,J.jsxs)(`label`,{htmlFor:`mcp-prompt-name-${o}`,className:`space-y-1 text-sm`,children:[`Name`,(0,J.jsx)(K,{id:`mcp-prompt-name-${o}`,"aria-label":`Prompt name`,value:a.name,onChange:e=>f(o,{name:e.target.value})})]}),(0,J.jsxs)(`label`,{htmlFor:`mcp-prompt-title-${o}`,className:`space-y-1 text-sm`,children:[`Title`,(0,J.jsx)(K,{id:`mcp-prompt-title-${o}`,"aria-label":`Prompt title`,value:a.title,onChange:e=>f(o,{title:e.target.value})})]})]}),(0,J.jsxs)(`label`,{htmlFor:`mcp-prompt-description-${o}`,className:`block space-y-1 text-sm`,children:[`Description`,(0,J.jsx)(K,{id:`mcp-prompt-description-${o}`,"aria-label":`Prompt description`,value:a.description,onChange:e=>f(o,{description:e.target.value})})]}),(0,J.jsxs)(`label`,{htmlFor:`mcp-prompt-content-${o}`,className:`block space-y-1 text-sm`,children:[`Instructions`,(0,J.jsx)(A,{id:`mcp-prompt-content-${o}`,"aria-label":`Prompt instructions`,value:a.content,rows:5,onChange:e=>f(o,{content:e.target.value})})]}),(0,J.jsx)(l,{variant:`ghost`,onClick:()=>{t({...e,prompts:e.prompts.filter((e,t)=>t!==o)}),r(null)},children:`Remove prompt`})]})]},o))})]}),(0,J.jsx)(l,{"data-testid":`mcp-save`,disabled:i,onClick:()=>void d(),children:`Save changes`})]}),o&&(0,J.jsx)(`p`,{role:c?`alert`:`status`,className:c?`text-sm text-error`:`text-sm text-muted-foreground`,children:o})]})}var Pi=[`fcm.googleapis.com`,`updates.push.services.mozilla.com`,`web.push.apple.com`],Fi=[`.push.apple.com`,`.notify.windows.com`];function Ii(e){let t;try{t=new URL(e)}catch{return!1}if(t.protocol!==`https:`||t.username||t.password||t.port)return!1;let n=t.hostname.toLowerCase();return Pi.includes(n)||Fi.some(e=>n.endsWith(e))}var Li=H().min(1).max(512).regex(/^[A-Za-z0-9_-]+={0,2}$/,`Expected a base64url key`),Ri=U([`attention`,`chat`,`jobs`]),zi=Ri.options;R({endpoint:H().max(2048).refine(Ii,`Endpoint must be a known browser push service`),keys:R({p256dh:Li,auth:Li}).strict(),label:H().trim().min(1).max(120),topics:V(Ri).max(zi.length).optional()}).strict(),R({topics:V(Ri).max(zi.length)}).strict(),R({id:H(),label:H(),endpoint_host:H(),topics:V(Ri),created_at:W(),last_success_at:W().nullable(),failure_count:W().int()}),R({public_key:H()}),R({title:H().max(200),body:H().max(500),url:H().max(2048),tag:H().max(200)});var Bi={attention:`Human requests (approvals and questions from agents)`,chat:`Chat replies and chat approvals`,jobs:`Job results you asked to be notified about`},Vi={insecure:`Push notifications need HTTPS. Open ORC through an https:// address to enable them.`,"install-required":`On iPhone and iPad, add ORC to the Home Screen (Share → Add to Home Screen), then open it from there.`,unsupported:`This browser does not support push notifications.`};function Hi(...e){return e.find(Boolean)?.message}function Ui(e){return e?new Date(e).toLocaleString():`never`}function Wi({device:e}){let t=Xe(),n=(n,r)=>{let i=r?[...e.topics,n]:e.topics.filter(e=>e!==n);t.mutate({id:e.id,topics:i})};return(0,J.jsxs)(`fieldset`,{className:`space-y-0 sm:space-y-2`,disabled:t.isPending,children:[(0,J.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:`Notify this device about`}),zi.map(t=>(0,J.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm sm:min-h-0 [@media(pointer:coarse)]:min-h-11`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`push-topic-${t}`,checked:e.topics.includes(t),onChange:e=>n(t,e.target.checked)}),Bi[t]]},t))]})}function Gi(){let e=it(),t=Ge({status:`active`}),n=(t,n)=>Me({mutedProjects:n?[...e.mutedProjects,t]:e.mutedProjects.filter(e=>e!==t)});return(0,J.jsxs)(`div`,{className:`mt-6 space-y-3`,"data-testid":`notification-sound-settings`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium`,children:`Sound`}),(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A short chime plays in this browser when work needs you. Completed work stays silent; updates remain in the notification menu.`})]}),(0,J.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm sm:min-h-0 [@media(pointer:coarse)]:min-h-11`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`notification-sound-enabled`,checked:e.sound,onChange:e=>Me({sound:e.target.checked})}),`Play a sound for Needs-you notifications`]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,J.jsx)(`label`,{htmlFor:`notification-volume`,className:`text-sm`,children:`Volume`}),(0,J.jsx)(`input`,{id:`notification-volume`,type:`range`,min:0,max:100,step:5,"data-testid":`notification-sound-volume`,disabled:!e.sound,value:Math.round(e.volume*100),onChange:e=>Me({volume:Number(e.target.value)/100}),className:`w-40 accent-primary`}),(0,J.jsxs)(`span`,{className:`w-10 text-sm tabular-nums text-outline`,children:[Math.round(e.volume*100),`%`]}),(0,J.jsxs)(l,{variant:`outline`,size:`sm`,"data-testid":`notification-sound-test`,disabled:!e.sound||e.volume===0,onClick:()=>{Ee(),window.setTimeout(()=>Ne(e.volume),50)},children:[(0,J.jsx)(Jt,{className:`size-4`}),`Play test sound`]})]}),(t.data?.length??0)>0&&(0,J.jsxs)(`fieldset`,{className:`space-y-0 sm:space-y-1.5`,disabled:!e.sound,children:[(0,J.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:`Mute projects`}),t.data?.map(t=>(0,J.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 text-sm sm:min-h-0 [@media(pointer:coarse)]:min-h-11`,children:[(0,J.jsx)(`input`,{type:`checkbox`,"data-testid":`notification-mute-${t.id}`,checked:e.mutedProjects.includes(t.id),onChange:e=>n(t.id,e.target.checked)}),(0,J.jsx)(`span`,{className:`truncate`,children:t.name})]},t.id))]})]})}function Ki(){let e=Ae(),t=He(),n=qe(),r=ze(),i=$e(),a=Pe(),s=De(),c=t.data??null,u=(n.data??[]).filter(e=>e.id!==c?.id),d=Hi(r.error,i.error,a.error,s.error);return(0,J.jsxs)(`section`,{"aria-labelledby":`notifications-title`,children:[(0,J.jsx)(`h2`,{id:`notifications-title`,className:`mb-1 text-base font-medium`,children:`Notifications`}),(0,J.jsx)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:`Choose alerts and sounds. Push stays quiet while ORC is focused.`}),(0,J.jsx)(o,{to:`/settings?settingsSection=storage`,className:`mb-4 inline-block text-sm underline underline-offset-2`,children:`Notification and audit cleanup settings`}),(0,J.jsx)(Si,{className:`mb-4`}),e===`supported`?(0,J.jsxs)(`div`,{className:`space-y-4`,children:[c?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Wi,{device:c}),(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsxs)(l,{variant:`outline`,"data-testid":`push-test`,disabled:s.isPending,onClick:()=>s.mutate(c.id),children:[(0,J.jsx)(Kt,{className:`mr-2 size-4`}),`Send test notification`]}),(0,J.jsxs)(l,{variant:`outline`,"data-testid":`push-disable`,disabled:i.isPending,onClick:()=>i.mutate(c.id),children:[(0,J.jsx)(It,{className:`mr-2 size-4`}),`Turn off on this device`]})]})]}):(0,J.jsxs)(l,{"data-testid":`push-enable`,disabled:r.isPending||t.isLoading,onClick:()=>r.mutate(),children:[(0,J.jsx)(Be,{className:`mr-2 size-4`}),r.isPending?`Enabling…`:`Enable notifications on this device`]}),s.data&&(0,J.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:s.data.sent?`Test sent. Switch away from ORC to see it.`:`Test not delivered.`})]}):(0,J.jsx)(`p`,{"data-testid":`push-unsupported`,className:`text-sm text-muted-foreground`,children:Vi[e]}),d&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-error`,children:d}),(0,J.jsx)(Gi,{}),u.length>0&&(0,J.jsxs)(`div`,{className:`mt-6`,children:[(0,J.jsx)(`h3`,{className:`mb-2 text-sm font-medium`,children:`Other devices`}),(0,J.jsx)(`ul`,{className:`space-y-2`,"data-testid":`push-devices`,children:u.map(e=>(0,J.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,J.jsxs)(`span`,{className:`min-w-0`,children:[(0,J.jsx)(`span`,{className:`block truncate`,children:e.label}),(0,J.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[`Last delivered `,Ui(e.last_success_at),e.failure_count>0&&` · ${e.failure_count} failed`]})]}),(0,J.jsx)(l,{variant:`ghost`,size:`icon`,"aria-label":`Remove ${e.label}`,disabled:a.isPending,onClick:()=>a.mutate(e.id),children:(0,J.jsx)(ct,{className:`size-4`})})]},e.id))})]})]})}function qi(){let e=r(),t=i({queryKey:[`workspace-preferences`],queryFn:_.settings.get}),[n,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(null),u=n??String(t.data?.notification_retention_days??30),d=s??String(t.data?.audit_retention_days??90),f=a({mutationFn:()=>_.settings.save({notification_retention_days:Number(u),audit_retention_days:Number(d)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:[`workspace-preferences`]}),await e.invalidateQueries({queryKey:[`notifications`]})}});return(0,J.jsxs)(`section`,{className:`mt-6 space-y-3`,"aria-labelledby":`retention-title`,children:[(0,J.jsx)(`h3`,{id:`retention-title`,className:`text-sm font-medium`,children:`Automatic cleanup`}),(0,J.jsx)(`p`,{className:`max-w-2xl text-sm text-outline`,children:`Notifications expire even when unresolved. Their source requests are kept independently. Audit events remain until their own expiry. These settings apply across ORC clients; shorter periods also apply to existing history.`}),(0,J.jsxs)(`form`,{className:`flex flex-wrap items-end gap-3`,onSubmit:e=>{e.preventDefault(),f.mutate()},children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`notification-retention-days`,children:`Notifications (days)`}),(0,J.jsx)(K,{id:`notification-retention-days`,"data-testid":`notification-retention-days`,type:`number`,min:1,max:3650,step:1,required:!0,value:u,onChange:e=>{o(e.target.value),f.reset()},className:`w-32`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`audit-retention-days`,children:`Audit log (days)`}),(0,J.jsx)(K,{id:`audit-retention-days`,"data-testid":`audit-retention-days`,type:`number`,min:1,max:3650,step:1,required:!0,value:d,onChange:e=>{c(e.target.value),f.reset()},className:`w-32`})]}),(0,J.jsx)(l,{type:`submit`,"data-testid":`retention-save`,disabled:t.isPending||!!t.error||f.isPending,children:f.isPending?`Saving…`:`Save retention`})]}),(f.error||t.error)&&(0,J.jsx)(`p`,{role:`alert`,children:f.error?.message??t.error?.message}),f.isSuccess&&(0,J.jsx)(`p`,{role:`status`,children:`Retention saved.`})]})}var Ji=86400,Yi=()=>Math.floor(Date.now()/1e3),Xi=e=>new Date(e*1e3).toLocaleString();function Zi({active:e}){let t=r(),n=i({queryKey:[`browser-session`,m()],queryFn:()=>f(m()),enabled:e}),o=i({queryKey:[`security-settings`],queryFn:_.settings.security.get,enabled:e}),[s,c]=(0,q.useState)(null),[u,p]=(0,q.useState)(null),v=a({mutationFn:()=>_.settings.security.save({session_days:Number(s??o.data?.session_days),cors_origins:(u??o.data?.cors_origins.join(`
|
|
13
|
-
`)??``).split(/[\s,]+/).filter(Boolean)}),onSuccess:async e=>{t.setQueryData([`security-settings`],e),c(null),p(null),await t.invalidateQueries({queryKey:[`browser-session`]})}}),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(()=>g(Yi()+30*Ji)),[w,T]=(0,q.useState)(!1),E=a({mutationFn:()=>d(m(),b,h(S)),onSuccess:()=>{x(``),T(!1)}}),D=o.isPending||!!o.error||v.isPending;return(0,J.jsxs)(`section`,{"aria-label":`Security settings`,className:`space-y-8`,children:[(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsx)(`h2`,{className:`text-base font-medium`,children:`Sign-in`}),n.error&&(0,J.jsx)(`p`,{role:`alert`,children:n.error.message}),n.data&&!n.data.required&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`security-session`,children:`This server has no API secret, so no sign-in is needed.`}),n.data?.required&&(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,J.jsx)(`p`,{className:`text-sm`,"data-testid":`security-session`,children:n.data.expires_at?`This browser is signed in until ${Xi(n.data.expires_at)}.`:`This browser is signed in with a stored credential.`}),(0,J.jsx)(l,{variant:`outline`,"data-testid":`security-sign-out`,onClick:()=>void y(m()),children:`Sign out`})]})]}),(0,J.jsxs)(`form`,{className:`space-y-4 border-t border-border pt-6`,onSubmit:e=>{e.preventDefault(),v.mutate()},children:[(0,J.jsx)(`h2`,{className:`text-base font-medium`,children:`Defaults`}),o.error&&(0,J.jsx)(`p`,{role:`alert`,children:o.error.message}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`security-session-days`,children:`Default sign-in lifetime (days)`}),(0,J.jsx)(K,{id:`security-session-days`,"data-testid":`security-session-days`,type:`number`,min:1,max:365,step:1,required:!0,className:`w-32`,disabled:D,value:s??String(o.data?.session_days??``),onChange:e=>c(e.target.value)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Suggested expiry on the sign-in screen. Anyone signing in can pick a date up to a year ahead.`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`security-cors-origins`,children:`Allowed web UI origins`}),(0,J.jsx)(`textarea`,{id:`security-cors-origins`,"data-testid":`security-cors-origins`,className:`form-control min-h-20 w-full font-mono text-xs`,placeholder:`https://orc.example.com`,disabled:D,value:u??o.data?.cors_origins.join(`
|
|
14
|
-
`)??``,onChange:e=>p(e.target.value)}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`One per line. Leave empty when the web UI and API share an address. Listing an origin lets it call this API with the sign-in cookie, which then requires HTTPS.`})]}),(0,J.jsx)(l,{"data-testid":`security-save`,type:`submit`,disabled:D,children:v.isPending?`Saving…`:`Save security settings`}),v.error&&(0,J.jsx)(`p`,{role:`alert`,children:v.error.message}),v.isSuccess&&(0,J.jsx)(`p`,{role:`status`,children:`Security settings saved.`})]}),(0,J.jsxs)(`form`,{className:`space-y-4 border-t border-border pt-6`,onSubmit:e=>{e.preventDefault(),E.mutate()},children:[(0,J.jsx)(`h2`,{className:`text-base font-medium`,children:`API access token`}),(0,J.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Send it as `,(0,J.jsx)(`code`,{children:`Authorization: Bearer <token>`}),` from scripts and MCP clients instead of the API secret. Changing the API secret revokes every token.`]}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`security-token-secret`,children:`API secret`}),(0,J.jsx)(K,{id:`security-token-secret`,"data-testid":`security-token-secret`,type:`password`,autoComplete:`off`,required:!0,className:`w-64`,value:b,onChange:e=>x(e.target.value)})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`security-token-valid-until`,children:`Valid until`}),(0,J.jsx)(K,{id:`security-token-valid-until`,"data-testid":`security-token-valid-until`,type:`date`,required:!0,min:g(Yi()),max:g(Yi()+364*Ji),value:S,onChange:e=>C(e.target.value)})]}),(0,J.jsx)(l,{"data-testid":`security-token-create`,type:`submit`,disabled:E.isPending,children:E.isPending?`Creating…`:`Create token`})]}),E.error&&(0,J.jsx)(`p`,{role:`alert`,children:E.error.message}),E.data&&(0,J.jsxs)(`div`,{className:`space-y-2`,"data-testid":`security-token-result`,children:[(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Copy it now; it is not shown again. Valid until `,Xi(E.data.expires_at),`.`]}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(K,{readOnly:!0,"aria-label":`Access token`,"data-testid":`security-token-value`,className:`font-mono text-xs`,value:E.data.token,onFocus:e=>e.target.select()}),(0,J.jsxs)(l,{type:`button`,variant:`outline`,"aria-label":`Copy token`,onClick:()=>void navigator.clipboard.writeText(E.data.token).then(()=>T(!0)),children:[(0,J.jsx)(Ke,{size:14}),w?`Copied`:`Copy`]})]})]})]})]})}function Qi(){let e=r();return a({mutationFn:async()=>{let e=await _.system.restart(),t=Date.now()+6e4;for(;Date.now()<t;){await new Promise(e=>setTimeout(e,500));try{if((await _.health.check(AbortSignal.timeout(2e3))).instance_id!==e.instance_id)return}catch(e){if(e instanceof b&&e.status===401)throw e}}throw Error(`ORC has not reconnected yet. Check the server and try again when it is online.`)},onSuccess:()=>e.invalidateQueries()})}function $i(){let{data:e}=Re(),t=Qi();return(0,J.jsxs)(`section`,{"aria-labelledby":`server-title`,children:[(0,J.jsx)(`h2`,{id:`server-title`,className:`mb-1 text-base font-medium`,children:`ORC server`}),(0,J.jsx)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:`Restart ORC to reload server and host information. This closes active terminals and may interrupt running work. Your settings are kept, and this dashboard reconnects automatically. Switching hosts applies to new actions without a restart.`}),(0,J.jsx)(Si,{className:`mb-4`}),(0,J.jsxs)(l,{variant:`outline`,"data-testid":`settings-restart`,disabled:!e?.restart_supported||t.isPending,onClick:()=>t.mutate(),children:[(0,J.jsx)(me,{className:t.isPending?`mr-2 size-4 animate-spin`:`mr-2 size-4`}),t.isPending?`Restarting and reconnecting…`:`Restart ORC server`]}),e&&!e.restart_supported&&(0,J.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:`This server does not support restart from the dashboard.`}),t.isPending&&(0,J.jsx)(`p`,{role:`status`,"data-testid":`settings-restart-status`,className:`mt-2 text-sm text-muted-foreground`,children:`Waiting for ORC to restart…`}),t.isSuccess&&(0,J.jsx)(`p`,{role:`status`,"data-testid":`settings-restart-status`,className:`mt-2 text-sm text-muted-foreground`,children:`ORC restarted. Reconnected.`}),t.isError&&(0,J.jsx)(`p`,{role:`alert`,"data-testid":`settings-restart-error`,className:`mt-2 text-sm text-error`,children:t.error.message})]})}var ea=`__local__`;function ta(e){return e?e instanceof Error?e.message:String(e):null}function na(){let{data:e,error:t,refetch:n}=Ve(),{data:r}=Se(),i=et(),a=Ye(),[o,s]=(0,q.useState)(ea),[c,u]=(0,q.useState)(``);if((0,q.useEffect)(()=>{e&&(s(e.host??ea),u(e.remote_port===null?``:String(e.remote_port)))},[e]),t)return(0,J.jsxs)(`section`,{children:[(0,J.jsx)(`h2`,{className:`mb-3 text-base font-semibold`,children:`Execution host`}),(0,J.jsx)(ut,{message:t.message,onRetry:()=>void n()})]});if(!e)return(0,J.jsx)(`p`,{role:`status`,"data-testid":`page-loading`,className:`text-sm text-muted-foreground`,children:`Loading execution host…`});let d=o===ea?null:o,f=e.host&&!e.hosts.includes(e.host)?[e.host,...e.hosts]:e.hosts,p=Number(c),m=c.trim()===``||Number.isInteger(p)&&p>=1&&p<=65535,h=e.locked||!e.supported,g=r?.backends.find(e=>e.name===`claude`),_=a.data?.host===d?a.data:void 0;return(0,J.jsxs)(`section`,{"data-testid":`ssh-settings`,children:[(0,J.jsx)(`h2`,{className:`font-headline font-semibold text-base text-on-surface mb-1`,children:`Execution host`}),(0,J.jsxs)(`p`,{className:`font-body text-sm text-muted-foreground mb-4`,children:[`Run every agent, terminal, git and file action on a host from`,` `,(0,J.jsx)(`code`,{className:`text-primary`,children:`~/.ssh/config`}),`. Agents there reach orc through a reverse tunnel on the remote port. Terminals already open keep their host.`]}),(0,J.jsx)(Si,{className:`bg-surface-highest mb-4`}),(0,J.jsxs)(`div`,{className:`space-y-4`,children:[e.locked&&(0,J.jsx)(`p`,{"data-testid":`ssh-locked`,className:`font-body text-sm text-tertiary`,children:`Fixed by ORC_SSH_HOST in orc's environment.`}),!e.supported&&(0,J.jsx)(`p`,{"data-testid":`ssh-unsupported`,className:`font-body text-sm text-error`,children:e.unsupported_reason}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`ssh-host`,className:`font-label text-sm text-muted-foreground`,children:`Host`}),(0,J.jsxs)(E,{value:o,onValueChange:s,disabled:h,children:[(0,J.jsx)(C,{id:`ssh-host`,"aria-label":`Execution host`,"data-testid":`ssh-host-picker`,className:`bg-surface-highest border-control-border text-on-surface font-body text-sm`,children:(0,J.jsx)(S,{})}),(0,J.jsxs)(w,{className:`bg-surface-highest border-outline-variant max-h-72`,children:[(0,J.jsx)(T,{value:ea,"data-testid":`ssh-host-option-local`,className:`font-label text-sm`,children:`Local (this machine)`}),f.map(e=>(0,J.jsx)(T,{value:e,"data-testid":`ssh-host-option-${e}`,className:`font-label text-sm`,children:e},e))]})]}),f.length===0&&(0,J.jsx)(`p`,{"data-testid":`page-empty`,className:`font-body text-sm text-muted-foreground`,children:`No Host entries found in ~/.ssh/config on the machine running orc.`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(P,{htmlFor:`ssh-remote-port`,className:`font-label text-sm text-muted-foreground`,children:`Tunnel port override`}),(0,J.jsx)(K,{id:`ssh-remote-port`,"aria-invalid":!(!d||m),"data-testid":`ssh-remote-port`,value:c,placeholder:`Automatic`,onChange:e=>u(e.target.value),disabled:h||!d,inputMode:`numeric`,className:`bg-surface-highest border-outline-variant text-on-surface font-body text-sm`}),d&&!m&&(0,J.jsx)(`p`,{className:`text-sm text-error`,children:`Enter a remote port from 1 to 65535.`}),(0,J.jsx)(`p`,{className:`font-body text-sm text-muted-foreground`,children:`Leave empty to let SSH choose an available port automatically.`})]}),(0,J.jsxs)(`div`,{className:`flex gap-3`,children:[(0,J.jsxs)(l,{"data-testid":`ssh-save`,disabled:h||d!==null&&!m||i.isPending,onClick:()=>i.mutate({host:d,remotePort:d&&c.trim()?p:null}),className:`font-label text-sm bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,J.jsx)(xe,{size:12,className:`mr-1.5`}),` Use Host`]}),(0,J.jsxs)(l,{"data-testid":`ssh-test`,variant:`ghost`,disabled:!d||!e.supported||a.isPending,onClick:()=>d&&a.mutate(d),className:`font-label text-sm text-muted-foreground hover:text-on-surface`,children:[(0,J.jsx)(Wt,{size:12,className:`mr-1.5`}),` `,a.isPending?`Testing…`:`Test`]})]}),ta(i.error??a.error)&&(0,J.jsx)(`p`,{"data-testid":`ssh-error`,className:`font-body text-sm text-error`,children:ta(i.error??a.error)}),_&&(0,J.jsx)(`div`,{"data-testid":`ssh-test-result`,className:`font-body text-sm space-y-1`,children:_.ok?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`p`,{className:`text-secondary`,children:[`Connected to `,_.host,` (`,_.os,`, `,_.shell,`)`]}),(0,J.jsx)(`p`,{className:`text-muted-foreground`,children:Object.entries(_.binaries).map(([e,t])=>`${t?`●`:`○`} ${e}`).join(` `)}),_.binaries.claude&&_.claude_logged_in===!1&&(0,J.jsxs)(`p`,{className:_.api_key_forwarded?`text-muted-foreground`:`text-error`,children:[`claude is not logged in on `,_.host,`.`,` `,_.api_key_forwarded?`ANTHROPIC_API_KEY from orc's environment will be forwarded.`:`Set ANTHROPIC_API_KEY in orc's environment or run claude login there.`]})]}):(0,J.jsx)(`p`,{className:`text-error`,children:_.error})}),e.host&&g&&!g.available&&(0,J.jsxs)(`p`,{"data-testid":`ssh-claude-error`,className:`font-body text-sm text-error`,children:[`claude backend: `,g.error]})]})]})}var ra=new Intl.NumberFormat,ia={codex:`Codex`,claude:`Claude`,cursor:`Cursor`};function aa(){let[e,t]=(0,q.useState)(`30`),n=i({queryKey:[`usage-history`,e],queryFn:()=>_.settings.usageHistory(e)}),r=i({queryKey:[`usage-quotas`],queryFn:_.settings.usageQuotas,staleTime:6e4,refetchInterval:6e4}),a=n.isFetching||r.isFetching,o=n.data;return(0,J.jsxs)(`section`,{"aria-labelledby":`usage-title`,"data-testid":`settings-usage`,className:`space-y-6`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`h2`,{id:`usage-title`,className:`text-base font-medium`,children:`Usage`}),(0,J.jsxs)(l,{variant:`outline`,"data-testid":`usage-refresh`,disabled:a,onClick:()=>{n.refetch(),r.refetch()},children:[(0,J.jsx)(fe,{size:14,"aria-hidden":`true`}),a?`Refreshing…`:`Refresh`]})]}),(0,J.jsxs)(`section`,{"aria-labelledby":`quota-title`,children:[(0,J.jsx)(`h3`,{id:`quota-title`,className:`text-sm font-medium`,children:`Account quotas`}),(0,J.jsx)(`p`,{className:`mt-1 mb-3 text-xs text-muted-foreground`,children:`Local accounts on the API host. SSH accounts are excluded. Refreshes at most once a minute.`}),r.isPending&&(0,J.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Loading account quotas…`}),r.isError&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:`Account quotas could not be loaded. Use Refresh to retry.`}),r.data?.accounts.map(e=>(0,J.jsxs)(`div`,{"data-testid":`usage-quota-${e.provider}`,className:`border-b border-border py-3`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1`,children:[(0,J.jsx)(`h4`,{className:`text-sm font-medium`,children:ia[e.provider]}),(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Checked `,new Date(e.checked_at).toLocaleTimeString()]})]}),e.status!==`available`&&(0,J.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:e.message??`Quota data is unavailable.`}),e.windows.map(t=>(0,J.jsxs)(`div`,{className:`mt-3 grid min-w-0 gap-1.5 sm:grid-cols-[140px_minmax(0,1fr)_80px] sm:items-center sm:gap-x-4`,children:[(0,J.jsx)(`span`,{className:`text-xs`,children:t.label}),(0,J.jsx)(`div`,{role:`progressbar`,"aria-label":`${ia[e.provider]} ${t.label} used`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t.used_percent,className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,J.jsx)(`div`,{className:`h-full bg-foreground`,style:{width:`${t.used_percent}%`}})}),(0,J.jsxs)(`span`,{className:`text-xs tabular-nums sm:text-right`,children:[t.used_percent,`% used`]}),(0,J.jsx)(`span`,{className:`text-xs text-muted-foreground sm:col-span-3`,children:t.resets_at?`Resets ${new Date(t.resets_at).toLocaleString()}`:`Reset time unavailable`})]},t.label))]},e.provider))]}),(0,J.jsxs)(`section`,{"aria-labelledby":`history-title`,children:[(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(`h3`,{id:`history-title`,className:`text-sm font-medium`,children:`Session token history`}),(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[`Sessions started`,(0,J.jsxs)(`select`,{"data-testid":`usage-period`,"aria-label":`Sessions started`,className:`form-control form-control-single min-h-11 w-auto`,value:e,onChange:e=>t(e.target.value),children:[(0,J.jsx)(`option`,{value:`7`,children:`Last 7 days`}),(0,J.jsx)(`option`,{value:`30`,children:`Last 30 days`}),(0,J.jsx)(`option`,{value:`90`,children:`Last 90 days`}),(0,J.jsx)(`option`,{value:`0`,children:`All time`})]})]})]}),(0,J.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`Lifetime token totals for imported sessions started in this period, across all projects. These are not tokens consumed during the period or billed costs.`}),n.isPending&&(0,J.jsx)(`p`,{role:`status`,className:`mt-3 text-sm text-muted-foreground`,children:`Loading session history…`}),n.isError&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-error`,children:`Session history could not be loaded. Use Refresh to retry.`}),o&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`dl`,{className:`my-4 grid grid-cols-2 gap-4 border-y border-border py-3`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:`Recorded tokens`}),(0,J.jsx)(`dd`,{"data-testid":`usage-total-tokens`,className:`mt-1 text-xl tabular-nums`,children:ra.format(o.totals.tokens)})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`dt`,{className:`text-xs text-muted-foreground`,children:`Sessions`}),(0,J.jsx)(`dd`,{className:`mt-1 text-xl tabular-nums`,children:ra.format(o.totals.sessions)})]})]}),o.totals.unknown_sessions>0&&(0,J.jsxs)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:[`Sessions without complete token counts: `,ra.format(o.totals.unknown_sessions),`. Excluded from token totals.`]}),o.totals.estimated_sessions>0&&(0,J.jsxs)(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:[`Cursor sessions with estimated counts:`,` `,ra.format(o.totals.estimated_sessions),`.`]}),!o.totals.sessions&&(0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No imported sessions started in this period. Sessions appear after ORC discovers them.`}),o.agents.map(e=>(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border py-2.5 text-sm`,children:[(0,J.jsx)(`span`,{className:`min-w-0 break-words`,children:ia[e.agent]??e.agent}),(0,J.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[ra.format(e.tokens),` tokens · `,ra.format(e.sessions),` sessions`]})]},e.agent)),o.daily.length>0&&(0,J.jsxs)(`details`,{className:`mt-4`,"data-testid":`usage-daily`,children:[(0,J.jsx)(`summary`,{className:`flex min-h-11 cursor-pointer items-center text-sm focus-visible:outline-2 focus-visible:outline-ring`,children:`By session start date (UTC)`}),o.daily.map(e=>(0,J.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2 border-b border-border py-2 text-xs tabular-nums`,children:[(0,J.jsx)(`span`,{children:e.date}),(0,J.jsxs)(`span`,{className:`text-muted-foreground`,children:[ra.format(e.tokens),` tokens · `,ra.format(e.sessions),` sessions`]})]},e.date))]})]})]})]})}var oa=[`connection`,`security`,`appearance`,`execution`,`server`,`notifications`,`channels`,`agents`,`chat`,`browser`,`mcp`,`integrations`,`knowledge`,`terminals`,`storage`,`usage`,`about`],sa={connection:`Connection`,security:`Security`,appearance:`Appearance`,execution:`Execution host`,server:`Server`,notifications:`Notifications`,channels:`Channels`,agents:`Providers`,chat:`Chat`,browser:`Browser`,mcp:`MCP`,integrations:`Integrations`,knowledge:`Knowledge`,terminals:`Terminals`,storage:`Storage`,usage:`Usage`,about:`About`};function ca(){let e=oa.filter(e=>e!==`browser`||!!st()?.preview),{theme:t}=je(),[n,i]=ft(`settingsSection`,`connection`,e),[a,o]=(0,q.useState)(m),[s,c]=(0,q.useState)(()=>localStorage.getItem(`orc_terminal_font`)??``),[u,d]=(0,q.useState)(!1),[f,p]=(0,q.useState)(``),[h,g]=(0,q.useState)(``),y=r();function b(e){i(e),g(``),p(``)}async function x(e,t=!1){g(``),p(``),d(!0);try{if(e===`connection`){let e=t?`/api`:a.trim()||`/api`;if(!e.startsWith(`/`)&&!/^https?:\/\//i.test(e))throw Error(`Use a relative API path or an http(s) server URL.`);let n=e!==m();localStorage.setItem(`orc_api_url`,e),o(e),n&&window.dispatchEvent(new Event(v)),p(t?`Connection restored to the current server.`:`Connection saved in this browser.`)}else{let e=(await _.settings.save({terminal_font:t?``:s.trim()})).terminal_font??``;c(e),e?localStorage.setItem(le,e):localStorage.removeItem(le),p(t?`Terminal font restored to its default.`:`Terminal font saved. New terminals use this font.`)}await y.invalidateQueries()}catch(e){g(e instanceof Error?e.message:`Settings could not be saved.`)}finally{d(!1)}}async function S(e){g(``),p(``),d(!0);try{let t=await _.settings.save({theme:e});nt(t.theme??e),p(`Appearance saved.`)}catch(e){g(e instanceof Error?e.message:`Appearance could not be saved.`)}finally{d(!1)}}let C=e=>(0,J.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center gap-2`,children:[(0,J.jsxs)(l,{"data-testid":e===`connection`?`settings-save`:`settings-terminal-save`,disabled:u,onClick:()=>void x(e),children:[f?(0,J.jsx)(Rt,{size:14}):(0,J.jsx)(xe,{size:14}),`Save changes`]}),(0,J.jsxs)(l,{variant:`ghost`,disabled:u,onClick:()=>void x(e,!0),children:[`Reset `,e===`connection`?`connection`:`font`]})]});return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(dt,{title:`Settings`}),(0,J.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[160px_minmax(0,1fr)] md:gap-8`,children:[(0,J.jsx)(`nav`,{"aria-label":`Settings sections`,className:`hidden space-y-1 md:block`,children:e.map(e=>(0,J.jsx)(l,{"data-testid":`settings-section-${e}`,variant:n===e?`secondary`:`ghost`,"aria-current":n===e?`page`:void 0,onClick:()=>b(e),className:`w-full justify-start`,children:sa[e]},e))}),(0,J.jsxs)(`label`,{className:`md:hidden`,children:[(0,J.jsx)(`span`,{className:`sr-only`,children:`Settings section`}),(0,J.jsx)(`select`,{"aria-label":`Settings section`,className:`form-control form-control-single`,value:n,onChange:e=>b(e.target.value),children:e.map(e=>(0,J.jsx)(`option`,{value:e,children:sa[e]},e))})]}),(0,J.jsxs)(`div`,{className:`min-w-0 max-w-4xl`,children:[n===`browser`&&st()?.preview&&(0,J.jsx)(wn,{}),n===`usage`&&(0,J.jsx)(aa,{}),(0,J.jsxs)(`section`,{hidden:n!==`connection`,"aria-label":`Connection settings`,children:[(0,J.jsx)(`h2`,{className:`mb-6 text-base font-medium`,children:`Connection`}),(0,J.jsxs)(`div`,{className:`grid gap-4 border-b border-border pb-6 lg:grid-cols-[minmax(160px,1fr)_minmax(0,2fr)]`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(P,{htmlFor:`settings-api-url`,children:`API connection`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Saved in this browser.`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(K,{id:`settings-api-url`,"data-testid":`settings-api-url`,value:a,onChange:e=>o(e.target.value),placeholder:`/api or http://localhost:7700`}),(0,J.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,J.jsx)(`code`,{children:`/api`}),` uses the current server or development proxy.`]})]})]}),C(`connection`)]}),(0,J.jsxs)(`section`,{hidden:n!==`appearance`,"aria-label":`Appearance settings`,children:[(0,J.jsx)(`h2`,{className:`mb-2 text-base font-medium`,children:`Appearance`}),(0,J.jsx)(`p`,{className:`mb-5 text-xs text-muted-foreground`,children:`Changes save immediately.`}),(0,J.jsx)(`fieldset`,{"aria-label":`Theme`,className:`flex gap-2`,children:[`dark`,`light`].map(e=>(0,J.jsx)(l,{variant:t===e?`secondary`:`outline`,"aria-pressed":t===e,"data-testid":`settings-theme-${e}`,disabled:u,onClick:()=>void S(e),children:e===`dark`?`Dark`:`Light`},e))})]}),(0,J.jsx)(`div`,{hidden:n!==`security`,children:(0,J.jsx)(Zi,{active:n===`security`})}),(0,J.jsx)(`div`,{hidden:n!==`execution`,children:(0,J.jsx)(na,{})}),(0,J.jsx)(`div`,{hidden:n!==`mcp`,children:(0,J.jsx)(Ni,{})}),(0,J.jsx)(`div`,{hidden:n!==`server`,children:(0,J.jsx)($i,{})}),(0,J.jsxs)(`div`,{hidden:n!==`notifications`,children:[(0,J.jsx)(Ki,{}),(0,J.jsx)(Sn,{})]}),(0,J.jsx)(`div`,{hidden:n!==`agents`,children:(0,J.jsx)(xn,{})}),(0,J.jsx)(`div`,{hidden:n!==`chat`,children:(0,J.jsx)(pr,{onManageProviders:()=>b(`agents`)})}),(0,J.jsx)(`div`,{hidden:n!==`channels`,children:(0,J.jsx)(fr,{active:n===`channels`})}),(0,J.jsx)(`div`,{hidden:n!==`integrations`,children:(0,J.jsx)(bi,{active:n===`integrations`})}),(0,J.jsx)(`div`,{hidden:n!==`knowledge`,children:(0,J.jsx)(Di,{})}),(0,J.jsxs)(`section`,{hidden:n!==`terminals`,"aria-label":`Terminal settings`,children:[(0,J.jsx)(`h2`,{className:`mb-6 text-base font-medium`,children:`Terminals`}),(0,J.jsxs)(`div`,{className:`grid gap-4 border-b border-border pb-6 lg:grid-cols-[minmax(160px,1fr)_minmax(0,2fr)]`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(P,{htmlFor:`settings-terminal-font`,children:`Terminal font family`}),(0,J.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Applies to newly opened terminals.`})]}),(0,J.jsxs)(`div`,{className:`space-y-2`,children:[(0,J.jsx)(K,{id:`settings-terminal-font`,value:s,onChange:e=>c(e.target.value),placeholder:`e.g. MesloLGS NF`}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Nerd Fonts support prompt and agent icons. Leave blank to choose automatically.`})]})]}),C(`terminals`)]}),(0,J.jsxs)(`section`,{hidden:n!==`storage`,"aria-label":`Settings storage`,children:[(0,J.jsx)(`h2`,{className:`mb-3 text-base font-medium`,children:`Storage`}),(0,J.jsxs)(`p`,{className:`max-w-2xl text-sm leading-relaxed text-muted-foreground`,children:[`Workspace preferences and SSH selection are saved in the server's`,` `,(0,J.jsx)(`code`,{children:`~/.orc/config.json`}),`. The API address is stored in this browser; sign-in uses an HttpOnly cookie, never the API secret.`]}),(0,J.jsx)(qi,{})]}),(0,J.jsx)(`section`,{hidden:n!==`about`,"aria-label":`About ORC`,children:(0,J.jsx)(dn,{})}),h&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-error`,children:h}),f&&!h&&(0,J.jsx)(`p`,{role:`status`,className:`mt-4 text-sm text-muted-foreground`,children:f})]})]})]})}export{ca as default};
|