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.
Files changed (98) hide show
  1. package/README.md +3 -2
  2. package/dist/index.js +897 -803
  3. package/dist/skills/orc-platform/SKILL.md +1 -1
  4. package/dist/skills/orc-platform/references/html-kit.md +154 -0
  5. package/dist/skills/orc-platform/references/scratchpads.md +6 -2
  6. package/dist/web/assets/{Agents-DmrIiUAL.js → Agents-G5dt5_s6.js} +2 -2
  7. package/dist/web/assets/Audit-De9E5Tfd.js +1 -0
  8. package/dist/web/assets/ChatUiRenderer-B1D3eTfy.js +4 -0
  9. package/dist/web/assets/ConfirmDialog-Cp1PcD4R.js +1 -0
  10. package/dist/web/assets/{Dashboard-Dh9P-zTd.js → Dashboard-DWorNfLX.js} +1 -1
  11. package/dist/web/assets/DocumentWorkspace-DZI0NvGD.js +1 -0
  12. package/dist/web/assets/FileEditor-CarhD1G9.js +1 -0
  13. package/dist/web/assets/{IntegrationCallback-CUZ5N-88.js → IntegrationCallback-CuUd_OOy.js} +1 -1
  14. package/dist/web/assets/JobWebhooks-8emXf4c1.js +1 -0
  15. package/dist/web/assets/Jobs-ComQ_dFU.js +3 -0
  16. package/dist/web/assets/Knowledge-Cm2ZVDRs.js +1 -0
  17. package/dist/web/assets/{MarkdownRenderer-fsBqw-wB.js → MarkdownRenderer-CHALCapQ.js} +5 -5
  18. package/dist/web/assets/{NativeFolderField-BuHwey26.js → NativeFolderField-CdaIEZa-.js} +1 -1
  19. package/dist/web/assets/PackageCatalog-CcPUM8f8.js +8 -0
  20. package/dist/web/assets/{PackageRunDialog-C8m43ZhJ.js → PackageRunDialog-DV1E6WX3.js} +19 -19
  21. package/dist/web/assets/{Pager-Dbs7fj3d.js → Pager-DZtibAkl.js} +1 -1
  22. package/dist/web/assets/Projects-BxrWujMD.js +3 -0
  23. package/dist/web/assets/{ResponsiveFilters-HzhzzjyL.js → ResponsiveFilters-C3siPRT-.js} +1 -1
  24. package/dist/web/assets/{ResumeActions-e6YpUhEq.js → ResumeActions-0eJvpGmW.js} +1 -1
  25. package/dist/web/assets/Rules-CHdgAIUd.js +18 -0
  26. package/dist/web/assets/{ScratchpadDiagramEditor-DkW_SmM8.js → ScratchpadDiagramEditor-6R8JsXS3.js} +1 -1
  27. package/dist/web/assets/Scratchpads-uD9R68sw.js +10 -0
  28. package/dist/web/assets/{SessionHomeLink-BAWO86fJ.js → SessionHomeLink-CMCZb7Vy.js} +1 -1
  29. package/dist/web/assets/Sessions-BD9AlzAN.js +4 -0
  30. package/dist/web/assets/Settings-Bt1even4.js +14 -0
  31. package/dist/web/assets/Skills-BSsN8kq-.js +3 -0
  32. package/dist/web/assets/{SourceEditor-B6pT-Rc0.js → SourceEditor-V5vL7Aof.js} +4 -4
  33. package/dist/web/assets/{TagInput-ChFu05vJ.js → TagInput-DU4zMpED.js} +1 -1
  34. package/dist/web/assets/TaskDetailSheet-C8dGHMsb.js +1 -0
  35. package/dist/web/assets/{Tasks-CC92r1kL.js → Tasks-wxRlyx-L.js} +6 -6
  36. package/dist/web/assets/Terminals-BFRG72xa.js +2 -0
  37. package/dist/web/assets/{ViewHeader-D-lhe59Y.js → ViewHeader-CKIR1ZTZ.js} +1 -1
  38. package/dist/web/assets/{Webhooks-BxpA1QBK.js → Webhooks-Bg3pm4rJ.js} +1 -1
  39. package/dist/web/assets/{badge-BqTVr27Z.js → badge-DfvoXiLp.js} +1 -1
  40. package/dist/web/assets/check-DrnDUgkq.js +1 -0
  41. package/dist/web/assets/chevron-down-C1WyGsAA.js +1 -0
  42. package/dist/web/assets/chevron-up-ZnWliPW7.js +1 -0
  43. package/dist/web/assets/{chunk-OB3PAWPO-1IihCzFx.js → chunk-OB3PAWPO-BD6ylT0A.js} +1 -1
  44. package/dist/web/assets/{circle-check-DWP3C_MJ.js → circle-check-CnioupGj.js} +1 -1
  45. package/dist/web/assets/{client-954dj6K2.js → client-DigivyCS.js} +1 -1
  46. package/dist/web/assets/{download-BD7lYc4O.js → download-CNwtbYo1.js} +1 -1
  47. package/dist/web/assets/{highlighted-body-JLMTFACH-CAMR1LA5.js → highlighted-body-JLMTFACH-dpkthrjz.js} +1 -1
  48. package/dist/web/assets/{index-XIDqokJX.js → index-Bc-Nka6Y.js} +50 -49
  49. package/dist/web/assets/index-BrDTqMtQ.css +1 -0
  50. package/dist/web/assets/{live-sessions-C6D_vHcN.js → live-sessions-BG3mNXnQ.js} +1 -1
  51. package/dist/web/assets/{maximize-2-BUxUwGbf.js → maximize-2-CcupqYE8.js} +1 -1
  52. package/dist/web/assets/mermaid-WFAXDIZX-BX9NWlJb.js +1 -0
  53. package/dist/web/assets/orc-kit-BZEVA3Qv.js +317 -0
  54. package/dist/web/assets/{scratchpad-kinds-B0Y6McXL.js → scratchpad-kinds-RGciqVT1.js} +1 -1
  55. package/dist/web/assets/{scratchpad-routes-BtsIfhUW.js → scratchpad-routes-Q2TRGUnx.js} +1 -1
  56. package/dist/web/assets/send-0IpktRLv.js +1 -0
  57. package/dist/web/assets/{upload-CPf6QZHl.js → upload-CaDKCpy5.js} +1 -1
  58. package/dist/web/assets/{useDetailRoute-DOhAbdV7.js → useDetailRoute-B-xjWsyW.js} +1 -1
  59. package/dist/web/assets/{useIntegrations-C0MAVKB4.js → useIntegrations-C6zijOMH.js} +1 -1
  60. package/dist/web/assets/{useJobs-BlWldKP0.js → useJobs-Dly6n-pv.js} +1 -1
  61. package/dist/web/assets/{useMemories-CAf8HcOI.js → useMemories-jakANU6m.js} +1 -1
  62. package/dist/web/assets/useProjectScope-DpgzthH7.js +1 -0
  63. package/dist/web/assets/{useSessions-DiUU2FN8.js → useSessions-tFa1FZ9M.js} +1 -1
  64. package/dist/web/assets/{view-params-DD7i9s5g.js → view-params-YEmeZppw.js} +1 -1
  65. package/dist/web/assets/{x-tY-z3woy.js → x-BayoBYp_.js} +1 -1
  66. package/dist/web/index.html +11 -18
  67. package/dist/web/sw.js +26 -17
  68. package/package.json +1 -1
  69. package/dist/web/assets/Audit-DGSNmToV.js +0 -1
  70. package/dist/web/assets/ChatUiRenderer-Dddr55cW.js +0 -4
  71. package/dist/web/assets/ConfirmDialog-B5es4nUp.js +0 -1
  72. package/dist/web/assets/DocumentWorkspace-I81K42yx.js +0 -1
  73. package/dist/web/assets/FileEditor-wRs221QU.js +0 -1
  74. package/dist/web/assets/JobWebhooks-oaF694Af.js +0 -1
  75. package/dist/web/assets/Jobs-Lmyw5700.js +0 -3
  76. package/dist/web/assets/Knowledge-V4JuZnUZ.js +0 -1
  77. package/dist/web/assets/Markdown-D-AaJ4bU.js +0 -2
  78. package/dist/web/assets/MarkdownEditor-5U4_BhYm.js +0 -2
  79. package/dist/web/assets/PackageCatalog-BC-yAjPQ.js +0 -8
  80. package/dist/web/assets/Projects-C280nbHV.js +0 -3
  81. package/dist/web/assets/Rules-BwsnRQBe.js +0 -18
  82. package/dist/web/assets/Scratchpads-BtUKOhup.js +0 -10
  83. package/dist/web/assets/Sessions-Cn2dIJBt.js +0 -4
  84. package/dist/web/assets/Settings-Bb01CfFw.js +0 -14
  85. package/dist/web/assets/Skills-Vw41zPVg.js +0 -3
  86. package/dist/web/assets/TaskDetailSheet-DuTfo6rZ.js +0 -1
  87. package/dist/web/assets/Terminals-dCbgpRsm.js +0 -2
  88. package/dist/web/assets/check-Cg2_C_4I.js +0 -1
  89. package/dist/web/assets/chevron-down-KBvm_HoX.js +0 -1
  90. package/dist/web/assets/dialog-DNIYhwi4.js +0 -1
  91. package/dist/web/assets/file-kind-BYU1kv95.js +0 -1
  92. package/dist/web/assets/index-hvCYuRJb.css +0 -1
  93. package/dist/web/assets/label-Bm_d0NKL.js +0 -1
  94. package/dist/web/assets/mermaid-WFAXDIZX-Bzg8wVqT.js +0 -1
  95. package/dist/web/assets/select-cyLFVkkB.js +0 -1
  96. package/dist/web/assets/tabs-bEwJLtA0.js +0 -1
  97. package/dist/web/assets/textarea-CovStda2.js +0 -1
  98. package/dist/web/assets/useProjectScope-DtEj9j-P.js +0 -1
@@ -0,0 +1,10 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ScratchpadDiagramEditor-6R8JsXS3.js","assets/rolldown-runtime-DSDNlrLa.js","assets/jsx-runtime-CVMpzJz9.js","assets/button-By-NN7c7.js","assets/react-dom-DTbwZiiP.js","assets/floating-ui.react-dom-BDMgcqWu.js","assets/bundle-mjs-CdK3cBzO.js","assets/client-DigivyCS.js","assets/check-DrnDUgkq.js","assets/prod-BxHPuooG.js","assets/es2015-w69PgVrA.js","assets/preload-helper-BLdHbfdN.js","assets/index-Bc-Nka6Y.js","assets/QueryClientProvider-DlPztvhd.js","assets/useMutation-CRAWY7v2.js","assets/chunk-OB3PAWPO-BD6ylT0A.js","assets/dist-bytwC6rk.js","assets/x-BayoBYp_.js","assets/chevron-down-C1WyGsAA.js","assets/chevron-up-ZnWliPW7.js","assets/circle-check-CnioupGj.js","assets/maximize-2-CcupqYE8.js","assets/dist-DScw4RwC.js","assets/dist-Ct6061MC.js","assets/dist-D8Wfxh48.js","assets/schemas-BQZhekae.js","assets/document-display-BQ5dM8QT.js","assets/bulk-actions-C8S1Gt4W.js","assets/index-BrDTqMtQ.css","assets/save-file-3ZpJah8W.js","assets/ScratchpadDiagramEditor-DtRVLazd.css"])))=>i.map(i=>d[i]);
2
+ import{a as e,n as t}from"./rolldown-runtime-DSDNlrLa.js";import{n,t as r}from"./jsx-runtime-CVMpzJz9.js";import{f as i,p as a,t as o,u as s}from"./chunk-OB3PAWPO-BD6ylT0A.js";import{l as c,t as l}from"./button-By-NN7c7.js";import{h as u,i as d,n as f,r as p}from"./client-DigivyCS.js";import{t as m}from"./check-DrnDUgkq.js";import{t as h}from"./scratchpad-kinds-RGciqVT1.js";import{t as g}from"./download-CNwtbYo1.js";import{t as _}from"./maximize-2-CcupqYE8.js";import{t as v}from"./ResponsiveFilters-C3siPRT-.js";import{c as y,d as b,f as x,g as S,i as C,l as w,m as T,t as E,u as D}from"./schemas-BQZhekae.js";import{t as ee}from"./preload-helper-BLdHbfdN.js";import{$r as te,Et as O,Ii as ne,Kr as re,O as k,Rt as ie,Yr as ae,Zr as oe,at as A,bt as se,ct as j,d as ce,ei as le,fi as ue,hn as de,ii as fe,it as M,lt as pe,mn as me,nt as N,ot as P,pn as he,rt as F,si as ge}from"./index-Bc-Nka6Y.js";import{t as _e}from"./ConfirmDialog-Cp1PcD4R.js";import{a as ve,c as ye,i as be,l as xe,n as I,o as Se,r as Ce,s as we,t as Te}from"./scratchpad-routes-Q2TRGUnx.js";import{i as Ee}from"./live-sessions-BG3mNXnQ.js";import{t as De}from"./orc-kit-BZEVA3Qv.js";import{t as Oe}from"./save-file-3ZpJah8W.js";import{t as ke}from"./ErrorState-DB0nWfcc.js";import{t as Ae}from"./ViewHeader-CKIR1ZTZ.js";import{t as L}from"./view-params-YEmeZppw.js";import{t as je}from"./EmptyState-YM4VSLR9.js";import{r as Me}from"./useSessions-tFa1FZ9M.js";import{a as Ne,i as R,n as Pe,o as Fe,r as z,t as Ie}from"./table-COm8Aml-.js";import{t as Le}from"./DocumentWorkspace-DZI0NvGD.js";import{t as Re}from"./TagInput-DU4zMpED.js";var ze={name:`shield`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]};ze.node;var Be=u(ze),B=[`doc`,`diagram`,`html`],Ve=E(B),He={doc:{extension:`.md`,mime:`text/markdown; charset=utf-8`},diagram:{extension:`.excalidraw`,mime:`application/json; charset=utf-8`},html:{extension:`.html`,mime:`text/html; charset=utf-8`}};w({type:y(`excalidraw`),elements:C(x(T(),S())),appState:x(T(),S()).optional(),files:x(T(),S()).optional()});function V(e,t){return`${e.normalize(`NFKD`).replace(/[^\w\s.-]/g,``).trim().replace(/\s+/g,`-`).toLowerCase().slice(0,80)||`scratchpad`}${He[t].extension}`}var Ue=T().trim().min(1).max(200),We=C(T().min(1).max(64)).max(20),Ge=T().min(1).max(200);b({id:T(),kind:Ve,title:T(),content:T(),project_id:T().nullable(),session_id:T().nullable(),tags:C(T()),author:T(),revision:D().int(),created_at:D().int(),updated_at:D().int()}).omit({content:!0}).extend({size_bytes:D().int()}),b({kind:Ve,title:Ue,content:T().optional(),project_id:T().min(1).nullable().optional(),session_id:Ge.nullable().optional(),tags:We.optional(),author:T().min(1).max(200).optional()}).strict(),b({title:Ue.optional(),content:T().optional(),project_id:T().min(1).nullable().optional(),session_id:Ge.nullable().optional(),tags:We.optional(),author:T().min(1).max(200).optional(),if_revision:D().int().min(1).optional()}).strict(),b({download_url:T().url().optional(),upload_url:T().url().optional(),filename:T(),revision:D().int(),expires_at:T().datetime()});var H=e(n(),1),U=r();function Ke({draft:e,children:t}){let n=e.saving?`Saving…`:e.dirty?`Unsaved changes`:`Saved`;return(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1.5`,children:t}),(0,U.jsx)(`span`,{"data-testid":`scratchpad-save-status`,role:`status`,className:`text-xs text-outline`,children:n}),(e.dirty||e.saving)&&(0,U.jsxs)(U.Fragment,{children:[e.stale&&(0,U.jsx)(l,{type:`button`,size:`sm`,variant:`ghost`,"data-testid":`scratchpad-overwrite`,disabled:e.saving,onClick:e.overwrite,children:`Keep mine`}),(0,U.jsx)(l,{type:`button`,size:`sm`,variant:`ghost`,"data-testid":`scratchpad-discard`,disabled:e.saving,onClick:e.discard,children:`Discard`}),(0,U.jsx)(l,{type:`button`,size:`sm`,"data-testid":`scratchpad-save`,disabled:e.saving,onClick:()=>void e.save(),children:`Save`})]})]}),e.error&&(0,U.jsxs)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:[e.error,` Your draft has been kept.`,e.stale&&` Discard loads their version; Keep mine lets you save over it.`]}),e.stale&&!e.error&&(0,U.jsx)(`p`,{role:`status`,className:`text-sm text-outline`,children:`This scratchpad changed elsewhere. Your draft is preserved: Discard loads their version; Keep mine lets you save over it.`})]})}function qe({active:e,onClick:t,children:n,testId:r}){return(0,U.jsx)(`button`,{type:`button`,"data-testid":r,"aria-pressed":e,onClick:t,className:`inline-flex min-h-9 items-center gap-1.5 font-label text-sm px-3 py-1.5 border transition-colors ${e?`bg-surface-highest text-on-surface border-transparent`:`bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface`}`,children:n})}function Je(e){let t=Se(),[n,r]=(0,H.useState)(e.content),[i,a]=(0,H.useState)({content:e.content,revision:e.revision}),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(null),u=(0,H.useRef)(e.content),d=n!==i.content;(0,H.useEffect)(()=>{e.revision<=i.revision||(e.content===i.content?a({content:e.content,revision:e.revision}):u.current===i.content&&(u.current=e.content,r(e.content),a({content:e.content,revision:e.revision})))},[e.content,e.revision,i]),(0,H.useEffect)(()=>{if(!d)return;let e=e=>e.preventDefault();return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[d]);let p=(0,H.useCallback)(e=>{u.current=e,r(e)},[]);async function m(){if(!d||o)return;s(!0),l(null);let n=u.current;try{let t=await f.scratchpads.update(e.id,{content:n,if_revision:i.revision});a({content:t.content,revision:t.revision})}catch(e){l(e instanceof Error?e.message:`Could not save scratchpad`)}finally{s(!1),await t()}}function h(){a({content:e.content,revision:e.revision}),l(null)}function g(){u.current=e.content,r(e.content),a({content:e.content,revision:e.revision}),l(null)}return{draft:n,setDraft:p,dirty:d,stale:d&&e.revision!==i.revision,saving:o,error:c,save:m,overwrite:h,discard:g}}function Ye(e,t,n){if(!/^\/(?![/\\])/.test(e))return!1;let r=new URL(t,n),i=new URL(`${t}${e}`,n),a=r.pathname.replace(/\/$/,``);return i.origin===r.origin&&i.pathname.startsWith(`${a}/`)}var Xe=[`preview`,`code`,`split`],Ze={preview:`Preview`,code:`Code`,split:`Split`},Qe=400,$e=`allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals`,et=`orc:fetch`,W=`orc:fetch:result`,tt=e=>`<script>(()=>{const pending=new Map();let next=0;
3
+ addEventListener("message",(e)=>{const d=e.data;if(e.source!==parent||!d||d.type!=="${W}")return;
4
+ const p=pending.get(d.id);if(!p)return;pending.delete(d.id);
5
+ if(d.error)p.reject(new Error(d.error));
6
+ else p.resolve(new Response(d.body,{status:d.status,statusText:d.statusText,headers:d.headers}));});
7
+ window.orc=Object.freeze({fetch:(path,init={})=>new Promise((resolve,reject)=>{const id=++next;
8
+ pending.set(id,{resolve,reject});
9
+ parent.postMessage({type:"${et}",nonce:"${e}",id,path:String(path),method:init.method,
10
+ headers:[...new Headers(init.headers)],body:init.body},"*");})});})();<\/script>`,nt=()=>Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,`0`)).join(``);function rt(e,t){let n=tt(t),r=/^\s*<!doctype[^>]*>/i.exec(e);return r?`${r[0]}${n}${e.slice(r[0].length)}`:`${n}${e}`}function it(e,t){let n=e;return n?.type===et&&n.nonce===t&&typeof n.id==`number`&&typeof n.path==`string`&&Array.isArray(n.headers)}async function at(e,t){try{if(!Ye(t.path,d(),window.location.href))throw Error(`orc.fetch path must be an ORC API path: ${t.path}`);let n=await p(t.path,{method:t.method,headers:t.headers,body:t.body??null}),r=await n.arrayBuffer();e.postMessage({type:W,id:t.id,status:n.status,statusText:n.statusText,headers:[...n.headers],body:r.byteLength?r:null},`*`,r.byteLength?[r]:[])}catch(n){e.postMessage({type:W,id:t.id,error:n instanceof Error?n.message:`Request failed`},`*`)}}function G({html:e,title:t,trusted:n=!1}){let r=(0,H.useRef)(null),{theme:i}=ce(),a=(0,H.useMemo)(()=>n?nt():``,[n,e]),o=(0,H.useMemo)(()=>{let t=De(e,i);return a?rt(t,a):t},[e,i,a]);return(0,H.useEffect)(()=>{if(!a)return;let e=e=>{let t=r.current?.contentWindow;t&&e.source===t&&it(e.data,a)&&at(t,e.data)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[a]),(0,U.jsx)(`iframe`,{ref:r,"data-testid":`scratchpad-html-preview`,"data-trusted":n||void 0,title:`${t} preview`,sandbox:$e,referrerPolicy:`no-referrer`,srcDoc:o,className:`h-(--pad-height,70vh) w-full border bg-white ${n?`border-destructive`:`border-outline-variant`}`},n?`trusted`:`sandboxed`)}function ot({pad:e}){let t=Je(e),[n,r]=L(`padView`,`preview`,Xe),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(!1),c=(0,H.useRef)(e.revision);(0,H.useEffect)(()=>{e.revision!==c.current&&(c.current=e.revision,e.content!==t.draft&&a(!1))},[e.revision,e.content,t.draft]);let u={...t,discard:()=>{e.content!==t.draft&&a(!1),t.discard()}},[d,f]=(0,H.useState)(t.draft);(0,H.useEffect)(()=>{let e=setTimeout(()=>f(t.draft),Qe);return()=>clearTimeout(e)},[t.draft]);let p=(0,U.jsx)(se,{path:V(e.title,`html`),value:t.draft,onChange:t.setDraft,onSave:()=>void t.save(),readOnly:t.saving,height:`var(--pad-height, 70vh)`,label:`HTML source`,testId:`scratchpad-html-source`});return(0,U.jsxs)(`div`,{className:`space-y-3`,"data-testid":`scratchpad-html`,children:[(0,U.jsxs)(Ke,{draft:u,children:[Xe.map(e=>(0,U.jsx)(qe,{active:n===e,onClick:()=>r(e),testId:`scratchpad-view-${e}`,children:Ze[e]},e)),n!==`code`&&(i?(0,U.jsxs)(l,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`scratchpad-html-sandbox`,onClick:()=>a(!1),children:[(0,U.jsx)(Be,{size:12,className:`mr-1`}),` Back to sandbox`]}):(0,U.jsxs)(l,{type:`button`,size:`sm`,variant:`outline`,"data-testid":`scratchpad-html-trust`,onClick:()=>s(!0),children:[(0,U.jsx)(oe,{size:12,className:`mr-1`}),` Render with ORC access`]}))]}),i&&n!==`code`&&(0,U.jsxs)(`p`,{role:`status`,className:`text-sm text-destructive`,children:[`This page runs with ORC access: its scripts act as you and can call the API through`,` `,(0,U.jsx)(`code`,{className:`font-mono text-xs`,children:`orc.fetch()`}),`.`]}),n===`preview`?(0,U.jsx)(G,{html:d,title:e.title,trusted:i}):n===`code`?p:(0,U.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:[(0,U.jsx)(`div`,{className:`min-w-0`,children:p}),(0,U.jsx)(G,{html:d,title:e.title,trusted:i})]}),(0,U.jsx)(_e,{open:o,title:`Render with ORC access?`,description:`The page's scripts will be able to call the ORC API as you through orc.fetch: read and change anything, including starting agents and terminals. They stay in the sandbox; the dashboard does not hand them your API secret, though API calls such as terminals can reach anything you can. Only do this for a page you trust. Access ends when you go back to the sandbox, leave the page, or someone else edits it.`,confirmLabel:`Render with access`,variant:`destructive`,onCancel:()=>s(!1),onConfirm:()=>{s(!1),a(!0)}})]})}var st=(0,H.lazy)(()=>ee(()=>import(`./ScratchpadDiagramEditor-6R8JsXS3.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30])));function ct({pad:e}){return e.kind===`doc`?(0,U.jsx)(lt,{pad:e}):e.kind===`html`?(0,U.jsx)(ot,{pad:e}):(0,U.jsx)(H.Suspense,{fallback:(0,U.jsx)(`div`,{role:`status`,className:`p-3 text-sm text-outline`,children:`Loading diagram editor…`}),children:(0,U.jsx)(st,{pad:e})})}function lt({pad:e}){let t=Se(),n=(0,H.useRef)(e.revision);return(0,U.jsx)(Le,{documentId:`scratchpad:${e.id}`,path:V(e.title,`doc`),content:e.content,testId:`scratchpad-doc`,layout:`page`,pageTitle:e.title,onSave:async(r,i)=>{try{let t=await f.scratchpads.update(e.id,{content:r,if_revision:i===e.content?e.revision:n.current});return n.current=t.revision,r}finally{await t()}}})}var ut=t({ScratchpadFormDialog:()=>$,default:()=>Y}),K=`all`,q=`unassigned`,dt=200;function ft(e,t){if(e===q)return``;for(let n of[e,t])if(n&&n!==K&&n!==q)return n;return``}function J(e){return new Date(e*1e3).toLocaleString()}function Y({projectId:e}){let{scratchpadId:t}=a();return t?(0,U.jsx)(gt,{id:t},t):(0,U.jsx)(pt,{defaultProjectId:e})}function X({kind:e}){let{label:t,icon:n}=h[e];return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-label text-xs text-muted-foreground`,children:[(0,U.jsx)(n,{size:12,"aria-hidden":!0}),` `,t]})}function pt({defaultProjectId:e}){let t=ie(`lg`),n=i(),r=s(),[a,u]=L(`project`,e);(0,H.useEffect)(()=>{let e=new URLSearchParams(r.search),t=e.get(`padProject`);t&&(e.has(`project`)||e.set(`project`,t),e.delete(`padProject`),n({search:e.toString()},{replace:!0}))},[r.search,n]);let[d,f]=L(`padKind`,K,[K,...B]),[p,m]=L(`padQuery`,``),[g,_]=(0,H.useState)(p);(0,H.useEffect)(()=>_(p),[p]),(0,H.useEffect)(()=>{if(g===p)return;let e=setTimeout(()=>m(g,{replace:!0}),350);return()=>clearTimeout(e)},[g,p,m]);let[y,b]=(0,H.useState)(!1);(0,H.useEffect)(()=>{let e=new URLSearchParams(r.search);e.get(`new`)===`1`&&(b(!0),e.delete(`new`),n({search:e.toString()},{replace:!0}))},[r.search,n]);let{data:x}=O({status:`active`}),S=ye({kind:d===K?void 0:d,project_id:a===K||a===q?void 0:a,include_global:a!==K&&a!==q?`true`:void 0,unassigned:a===q?`true`:void 0,q:p||void 0,limit:dt}),C=S.data?.scratchpads??[],w=e=>e?x?.find(t=>t.id===e)?.name??e:`Global`,T=!!p||d!==K||a!==K;return(0,U.jsxs)(`div`,{children:[(0,U.jsx)(Ae,{title:`Scratchpads`,compact:!0,help:(0,U.jsxs)(U.Fragment,{children:[`Working docs, diagrams and HTML pages you or an agent keep and come back to. Agents create and edit them with the `,(0,U.jsx)(`code`,{className:`font-mono text-xs`,children:`pad_*`}),` tools; share one by copying its link.`]}),meta:S.data?S.data.total:void 0,action:(0,U.jsxs)(l,{"data-testid":`new-scratchpad-button`,size:`sm`,onClick:()=>b(!0),className:`font-label text-sm`,children:[(0,U.jsx)(fe,{size:12,className:`mr-1`}),` New`,(0,U.jsx)(`span`,{className:`sr-only sm:not-sr-only`,children:` scratchpad`})]})}),(0,U.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,U.jsxs)(`div`,{className:`relative min-w-0 flex-1 lg:max-w-md`,children:[(0,U.jsx)(le,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground`}),(0,U.jsx)(re,{type:`search`,"aria-label":`Search scratchpads`,"data-testid":`scratchpad-search-input`,value:g,onChange:e=>_(e.target.value),onKeyDown:e=>e.key===`Enter`&&m(e.currentTarget.value),placeholder:`Search scratchpads…`,className:`h-11 pl-9 text-base lg:h-9 lg:text-sm`})]}),(0,U.jsxs)(v,{activeCount:Number(d!==K)+Number(a!==K),children:[(0,U.jsxs)(N,{value:a,onValueChange:e=>u(e),children:[(0,U.jsx)(A,{"aria-label":`Project`,"data-testid":`scratchpad-project-filter`,className:`h-11 w-48 max-w-full bg-background font-body text-base text-on-surface lg:h-9 lg:text-sm`,children:(0,U.jsx)(P,{})}),(0,U.jsxs)(F,{className:`bg-surface border-outline-variant`,children:[(0,U.jsx)(M,{value:K,className:`font-body text-sm`,children:`All projects`}),(0,U.jsx)(M,{value:q,className:`font-body text-sm`,children:`Global`}),x?.map(e=>(0,U.jsx)(M,{value:e.id,"data-testid":`scratchpad-project-${e.id}`,className:`font-body text-sm`,children:e.name},e.id))]})]}),(0,U.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1.5`,children:[K,...B].map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>f(e),"data-testid":`scratchpad-kind-${e}`,"aria-pressed":d===e,className:`min-h-11 rounded-md font-label text-sm px-3 py-1.5 border transition-colors lg:min-h-9 focus-visible:outline-2 focus-visible:outline-focus ${d===e?`bg-surface-highest text-on-surface border-transparent`:`bg-transparent border-transparent text-muted-foreground hover:bg-surface-low hover:text-on-surface`}`,children:e===K?`All`:h[e].label},e))})]})]}),S.error?(0,U.jsx)(ke,{message:S.error.message,onRetry:()=>void S.refetch()}):S.isLoading?(0,U.jsx)(`div`,{className:`space-y-2`,children:[...[,,,,,]].map((e,t)=>(0,U.jsx)(k,{className:`h-10 w-full bg-surface-highest`},t))}):C.length===0?(0,U.jsx)(je,{message:T?`No scratchpads match`:`No scratchpads yet`}):(0,U.jsx)(`div`,{className:`overflow-hidden`,children:t?(0,U.jsxs)(Ie,{children:[(0,U.jsx)(Ne,{children:(0,U.jsxs)(Fe,{className:`border-b border-outline-variant hover:bg-transparent`,children:[(0,U.jsx)(R,{className:`font-label text-sm text-muted-foreground`,children:`Title`}),(0,U.jsx)(R,{className:`font-label text-sm text-muted-foreground w-28`,children:`Kind`}),(0,U.jsx)(R,{className:`font-label text-sm text-muted-foreground`,children:`Project`}),(0,U.jsx)(R,{className:`font-label text-sm text-muted-foreground hidden md:table-cell`,children:`Author`}),(0,U.jsx)(R,{className:`font-label text-sm text-muted-foreground w-20 hidden md:table-cell`,children:`Size`}),(0,U.jsx)(R,{className:`font-label text-sm text-muted-foreground w-44`,children:`Updated`})]})}),(0,U.jsx)(Pe,{children:C.map(e=>(0,U.jsxs)(Fe,{"data-testid":`scratchpad-row`,"data-scratchpad-id":e.id,className:`border-b border-outline-variant/50 hover:bg-surface-low cursor-pointer`,onClick:()=>n(`${I(e.id)}${r.search}`),children:[(0,U.jsxs)(z,{className:`font-body text-sm font-medium text-on-surface`,children:[(0,U.jsx)(o,{to:`${I(e.id)}${r.search}`,className:`inline-flex min-h-11 items-center hover:text-primary`,onClick:e=>e.stopPropagation(),children:e.title}),e.tags.length>0&&(0,U.jsx)(`span`,{className:`ml-2 font-label text-xs text-outline`,children:e.tags.map(e=>`#${e}`).join(` `)})]}),(0,U.jsx)(z,{children:(0,U.jsx)(X,{kind:e.kind})}),(0,U.jsx)(z,{className:`font-body text-sm text-muted-foreground`,children:w(e.project_id)}),(0,U.jsx)(z,{className:`font-body text-sm text-muted-foreground hidden md:table-cell`,children:e.author}),(0,U.jsx)(z,{className:`font-label text-sm text-muted-foreground hidden md:table-cell`,children:c(e.size_bytes)}),(0,U.jsx)(z,{className:`font-label text-sm text-muted-foreground`,children:J(e.updated_at)})]},e.id))})]}):(0,U.jsx)(`div`,{className:`divide-y divide-border`,children:C.map(e=>(0,U.jsxs)(o,{to:`${I(e.id)}${r.search}`,"data-testid":`scratchpad-row`,"data-scratchpad-id":e.id,className:`block min-h-11 py-3 text-sm hover:bg-surface focus-visible:outline-2 focus-visible:outline-focus`,children:[(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,U.jsx)(`span`,{className:`min-w-0 break-words font-medium`,children:e.title}),(0,U.jsx)(`time`,{className:`shrink-0 text-xs text-outline`,dateTime:new Date(e.updated_at*1e3).toISOString(),title:J(e.updated_at),children:Ee(new Date(e.updated_at*1e3).toISOString())})]}),(0,U.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-outline`,children:[(0,U.jsx)(X,{kind:e.kind}),(0,U.jsx)(`span`,{children:w(e.project_id)}),(0,U.jsx)(`span`,{children:e.author}),e.tags.length>0&&(0,U.jsx)(`span`,{children:e.tags.map(e=>`#${e}`).join(` `)})]})]},e.id))})}),y&&(0,U.jsx)($,{defaultProjectId:ft(a,e),onClose:()=>b(!1),onSaved:e=>n(I(e.id))})]})}var Z=`none`,Q=`none`,mt=50;function ht(e,t,n){let r=(e??[]).filter(e=>e.session_id&&(t===Z||e.project_id===t||e.session_id===n)).sort((e,t)=>(t.last_activity_at??t.created_at).localeCompare(e.last_activity_at??e.created_at)).slice(0,mt),i=e?.find(e=>e.session_id===n);return i&&!r.includes(i)?[i,...r]:r}function $({pad:e,defaultProjectId:t=``,defaultKind:n=`doc`,onClose:r,onSaved:i}){let[a,o]=(0,H.useState)(e?.kind??n),[s,c]=(0,H.useState)(e?.title??``),[u,d]=(0,H.useState)((e?e.project_id:t)||Z),[f,p]=(0,H.useState)(e?.session_id??Q),[m,g]=(0,H.useState)(e?.tags??[]),[_,v]=(0,H.useState)(``),y=(0,H.useRef)(JSON.stringify([a,s,u,f,m])),{data:b}=O({status:`active`}),{data:x}=Me(!1),S=ht(x,u,f),C=be(),w=xe(),T=e?w:C;function E(t){let n={title:s.trim(),project_id:u===Z?null:u,session_id:f===Q?null:f,tags:m},r=e=>{t(),i?.(e)};e?w.mutate({id:e.id,...n},{onSuccess:r}):C.mutate({kind:a,...n},{onSuccess:r})}return(0,U.jsx)(pe,{open:!0,onClose:r,busy:T.isPending,dirty:!!_.trim()||JSON.stringify([a,s,u,f,m])!==y.current,testId:`scratchpad-form`,children:(t,n)=>(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(me,{children:(0,U.jsx)(de,{children:e?`Scratchpad properties`:`New scratchpad`})}),(0,U.jsxs)(`form`,{className:`min-h-0`,onSubmit:e=>{e.preventDefault(),E(n)},children:[(0,U.jsxs)(`div`,{className:`work-form-body grid grid-cols-1 gap-4 md:grid-cols-2`,children:[!e&&(0,U.jsxs)(`fieldset`,{className:`space-y-2 md:col-span-2`,children:[(0,U.jsx)(`legend`,{className:`font-label text-sm`,children:`Kind`}),(0,U.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:B.map(e=>{let{label:t,icon:n}=h[e];return(0,U.jsx)(`button`,{type:`button`,"data-testid":`scratchpad-form-kind-${e}`,"aria-pressed":a===e,onClick:()=>o(e),className:`flex min-h-8 items-center justify-center gap-1 rounded-md border px-2 py-2 transition-colors ${a===e?`border-primary bg-surface-low`:`border-outline-variant hover:bg-surface-low`}`,children:(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-label text-[13px]`,children:[(0,U.jsx)(n,{size:14,"aria-hidden":!0}),` `,t]})},e)})}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`scratchpad-kind-hint`,children:h[a].hint})]}),(0,U.jsxs)(`div`,{className:`space-y-2 md:col-span-2`,children:[(0,U.jsx)(j,{htmlFor:`scratchpad-title`,children:`Title`}),(0,U.jsx)(re,{id:`scratchpad-title`,"data-testid":`scratchpad-form-title`,value:s,maxLength:200,autoFocus:!0,onChange:e=>c(e.target.value)})]}),(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(j,{htmlFor:`scratchpad-project`,children:`Project`}),(0,U.jsxs)(N,{value:u,onValueChange:d,children:[(0,U.jsx)(A,{id:`scratchpad-project`,"data-testid":`scratchpad-form-project`,children:(0,U.jsx)(P,{})}),(0,U.jsxs)(F,{className:`bg-surface border-outline-variant`,children:[(0,U.jsx)(M,{value:Z,children:`No project`}),b?.map(e=>(0,U.jsx)(M,{value:e.id,children:e.name},e.id))]})]})]}),(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(j,{htmlFor:`scratchpad-session`,children:`Session`}),(0,U.jsxs)(N,{value:f,onValueChange:p,children:[(0,U.jsx)(A,{id:`scratchpad-session`,"data-testid":`scratchpad-form-session`,children:(0,U.jsx)(P,{})}),(0,U.jsxs)(F,{className:`bg-surface border-outline-variant`,children:[(0,U.jsx)(M,{value:Q,children:`No session`}),f!==Q&&!S.some(e=>e.session_id===f)&&(0,U.jsx)(M,{value:f,children:f.slice(0,8)}),S.map(e=>(0,U.jsxs)(M,{value:e.session_id,"data-testid":`scratchpad-form-session-option`,children:[e.agent,` · `,e.name??`Untitled session`,` ·`,` `,Ee(e.last_activity_at??e.created_at)]},e.id))]})]})]}),(0,U.jsxs)(`div`,{className:`space-y-2 md:col-span-2`,children:[(0,U.jsx)(j,{children:`Tags`}),(0,U.jsx)(Re,{value:m,onChange:g,onDraftChange:v,placeholder:`Add a tag`,"aria-label":`Tags`,"data-testid":`scratchpad-form-tags`})]}),T.error&&(0,U.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive md:col-span-2`,children:T.error.message})]}),(0,U.jsxs)(he,{className:`work-form-footer`,children:[(0,U.jsx)(l,{type:`button`,variant:`ghost`,onClick:t,disabled:T.isPending,children:`Cancel`}),(0,U.jsx)(l,{type:`submit`,"data-testid":`scratchpad-form-submit`,disabled:!s.trim()||T.isPending,children:e?`Save`:`Create`})]})]})]})})}function gt({id:e}){let t=i(),n=s(),{data:r,isLoading:a,error:c,refetch:u}=we(e),{data:d}=O(),[f,p]=(0,H.useState)(!1),[h,v]=(0,H.useState)(!1),[y,b]=(0,H.useState)(`idle`),[x,S]=(0,H.useState)(!1),C=ve(),w=`${Te}${n.search}`;(0,H.useEffect)(()=>{if(y!==`copied`)return;let e=setTimeout(()=>b(`idle`),2e3);return()=>clearTimeout(e)},[y]),(0,H.useEffect)(()=>{if(!x)return;function e(e){e.key!==`Escape`||e.defaultPrevented||document.querySelector(`[role="dialog"], [role="alertdialog"]`)||S(!1)}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x]);async function T(){try{await navigator.clipboard.writeText(Ce(e)),b(`copied`)}catch{b(`failed`)}}let E=(0,U.jsxs)(o,{to:w,className:`inline-flex min-h-11 items-center gap-1.5 font-label text-sm text-muted-foreground hover:text-on-surface`,children:[(0,U.jsx)(ne,{size:14,"aria-hidden":!0}),` Scratchpads`]});if(c)return(0,U.jsxs)(`div`,{children:[E,(0,U.jsx)(ke,{message:c.message,onRetry:()=>void u()})]});if(a||!r)return(0,U.jsxs)(`div`,{className:`space-y-3`,children:[E,(0,U.jsx)(k,{className:`h-8 w-1/2 bg-surface-highest`}),(0,U.jsx)(k,{className:`h-64 w-full bg-surface-highest`})]});let D=r.project_id?d?.find(e=>e.id===r.project_id):void 0;return(0,U.jsxs)(`div`,{"data-testid":`scratchpad-page`,"data-scratchpad-kind":r.kind,className:`min-w-0`,children:[E,(0,U.jsxs)(`div`,{className:`mt-2 mb-4 flex flex-wrap items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[(0,U.jsx)(`h1`,{"data-testid":`scratchpad-title`,className:`font-headline font-medium text-2xl tracking-tight text-on-surface wrap-break-word`,children:r.title}),(0,U.jsxs)(`div`,{"data-testid":`scratchpad-meta`,className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-outline`,children:[(0,U.jsx)(X,{kind:r.kind}),(0,U.jsxs)(`span`,{children:[`revision `,r.revision]}),(0,U.jsxs)(`span`,{children:[`by `,(0,U.jsx)(`span`,{"data-testid":`scratchpad-author`,children:r.author}),`,`,` `,J(r.updated_at)]}),(0,U.jsx)(`span`,{children:D?.name??(r.project_id?r.project_id:`No project`)}),r.session_id&&(0,U.jsxs)(`span`,{title:`Agent session that created it`,children:[`session `,(0,U.jsx)(`code`,{className:`font-mono text-xs`,children:r.session_id.slice(0,8)})]}),r.tags.length>0&&(0,U.jsx)(`span`,{children:r.tags.map(e=>`#${e}`).join(` `)})]})]}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsxs)(l,{"data-testid":`scratchpad-fullscreen`,size:`sm`,variant:`outline`,onClick:()=>S(!0),children:[(0,U.jsx)(_,{size:12,className:`mr-1`}),` Full screen`]}),(0,U.jsxs)(l,{"data-testid":`scratchpad-copy-link`,size:`sm`,variant:`outline`,onClick:()=>void T(),children:[y===`copied`?(0,U.jsx)(m,{size:12,className:`mr-1`}):(0,U.jsx)(ue,{size:12,className:`mr-1`}),y===`copied`?`Copied`:`Copy link`]}),(0,U.jsxs)(l,{"data-testid":`scratchpad-download`,size:`sm`,variant:`outline`,title:`Download the saved file`,onClick:()=>Oe(new Blob([r.content],{type:He[r.kind].mime}),V(r.title,r.kind)),children:[(0,U.jsx)(g,{size:12,className:`mr-1`}),` Download`]}),(0,U.jsxs)(l,{"data-testid":`scratchpad-properties`,size:`sm`,variant:`outline`,onClick:()=>p(!0),children:[(0,U.jsx)(te,{size:12,className:`mr-1`}),` Properties`]}),(0,U.jsxs)(l,{"data-testid":`scratchpad-delete`,size:`sm`,variant:`outline`,onClick:()=>v(!0),children:[(0,U.jsx)(ae,{size:12,className:`mr-1`}),` Delete`]})]})]}),y===`failed`&&(0,U.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-destructive`,children:`Clipboard access failed. Copy the link from the address bar instead.`}),(0,U.jsxs)(`div`,{"data-testid":`scratchpad-stage`,"data-fullscreen":x||void 0,className:x?`fixed inset-0 z-40 flex flex-col gap-3 overflow-auto bg-background p-3 [--pad-height:calc(100dvh-8.5rem)] sm:p-4`:`min-w-0`,children:[x&&(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(`h2`,{className:`min-w-0 flex-1 truncate font-headline text-lg font-medium text-on-surface`,children:r.title}),(0,U.jsxs)(l,{"data-testid":`scratchpad-exit-fullscreen`,size:`sm`,variant:`outline`,onClick:()=>S(!1),children:[(0,U.jsx)(ge,{size:12,className:`mr-1`}),` Exit full screen`]})]}),(0,U.jsx)(ct,{pad:r})]}),f&&(0,U.jsx)($,{pad:r,onClose:()=>p(!1)}),h&&(0,U.jsx)(_e,{open:!0,title:`Delete scratchpad`,description:`Delete "${r.title}"? This cannot be undone.`,confirmLabel:`Delete`,variant:`destructive`,isPending:C.isPending,onConfirm:()=>C.mutate(r.id,{onSuccess:()=>{v(!1),t(w)}}),onCancel:()=>v(!1)}),C.error&&(0,U.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-destructive`,children:C.error.message})]})}export{$ as ScratchpadFormDialog,Y as default,V as i,Je as n,Ke as r,ut as t};
@@ -1 +1 @@
1
- import{t as e}from"./jsx-runtime-CVMpzJz9.js";import{t,u as n}from"./chunk-OB3PAWPO-1IihCzFx.js";import{t as r}from"./maximize-2-BUxUwGbf.js";import{Vt as i}from"./index-XIDqokJX.js";var a=e();function o({terminalId:e,liveId:o,label:s,testId:c}){let l=n();return(0,a.jsx)(t,{to:{pathname:l.pathname,search:i(l.search,{terminalId:e,liveId:o})},"data-testid":c,"aria-label":s,title:s,className:`inline-flex min-h-11 min-w-11 shrink-0 items-center justify-center rounded-md text-on-surface-variant hover:bg-surface hover:text-on-surface lg:min-h-8 lg:min-w-8`,children:(0,a.jsx)(r,{size:14,"aria-hidden":!0})})}export{o as t};
1
+ import{t as e}from"./jsx-runtime-CVMpzJz9.js";import{t,u as n}from"./chunk-OB3PAWPO-BD6ylT0A.js";import{t as r}from"./maximize-2-CcupqYE8.js";import{cn as i}from"./index-Bc-Nka6Y.js";var a=e();function o({terminalId:e,liveId:o,label:s,testId:c}){let l=n();return(0,a.jsx)(t,{to:{pathname:l.pathname,search:i(l.search,{terminalId:e,liveId:o})},"data-testid":c,"aria-label":s,title:s,className:`inline-flex min-h-11 min-w-11 shrink-0 items-center justify-center rounded-md text-on-surface-variant hover:bg-surface hover:text-on-surface lg:min-h-8 lg:min-w-8`,children:(0,a.jsx)(r,{size:14,"aria-hidden":!0})})}export{o as t};
@@ -0,0 +1,4 @@
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,h as o,t as s,u as c}from"./chunk-OB3PAWPO-BD6ylT0A.js";import{t as l}from"./button-By-NN7c7.js";import{t as u}from"./x-BayoBYp_.js";import{n as d}from"./client-DigivyCS.js";import{t as f}from"./chevron-down-C1WyGsAA.js";import{t as p}from"./chevron-up-ZnWliPW7.js";import{t as m}from"./scratchpad-kinds-RGciqVT1.js";import{t as h}from"./send-0IpktRLv.js";import{t as g}from"./ResponsiveFilters-C3siPRT-.js";import{d as _,m as v,t as y,u as b}from"./schemas-BQZhekae.js";import{$n as x,Ai as S,Br as C,Cn as w,Et as T,Hn as E,Hr as D,It as O,Kr as k,Li as A,Lt as ee,Mt as j,Nt as M,O as N,Rr as te,Sn as ne,Ur as P,Vn as re,Vr as ie,Yn as F,_n as ae,ai as I,an as L,bn as oe,ct as R,dn as se,ei as z,fi as B,fn as V,gn as H,hn as U,in as W,ji as ce,jt as G,mn as le,on as K,qr as ue,ri as q,rn as de,sn as fe,un as pe,vn as me,wn as he,xn as ge,yn as _e}from"./index-Bc-Nka6Y.js";import{t as ve}from"./StatusBadge-CKL0hTFN.js";import{c as ye,n as be}from"./scratchpad-routes-Q2TRGUnx.js";import{i as xe,r as Se,s as Ce,t as we}from"./live-sessions-BG3mNXnQ.js";import{t as Te}from"./ErrorState-DB0nWfcc.js";import{t as Ee}from"./ViewHeader-CKIR1ZTZ.js";import{t as De}from"./EmptyState-YM4VSLR9.js";import{t as Oe}from"./Pager-DZtibAkl.js";import{a as ke,c as Ae,f as je,l as Me,n as Ne,o as Pe,r as Fe,t as Ie,u as Le}from"./useSessions-tFa1FZ9M.js";import{t as Re}from"./useProjectScope-DpgzthH7.js";import{t as ze}from"./ResumeActions-0eJvpGmW.js";import{t as Be}from"./SessionHomeLink-CMCZb7Vy.js";var J=e(t(),1),Y=n();function Ve({projectId:e}){let[t]=o(),n=a(),s=F(),c=r(),u=T(),[p,m]=(0,J.useState)({key:``,offset:0}),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(!1),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(``),[w,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(e),[A,ee]=(0,J.useState)(``),[j,M]=(0,J.useState)(``),[N,ne]=(0,J.useState)(``),[P,ae]=(0,J.useState)(``),[I,L]=(0,J.useState)(0),oe=t.get(`q`)??``,z=t.get(`agent`)??``,B=t.get(`ended`)!==`0`,H=JSON.stringify([e,oe,z]),W=p.key===H?p.offset:0,ce=e=>m({key:H,offset:e}),G=i({queryKey:[`sessions`,`archive`,e,oe,z,W],queryFn:()=>d.sessions.archive({q:oe,...e===`all`?{}:{project_id:e},...[`claude`,`codex`].includes(z)?{agent:z}:{},offset:W,limit:20}),enabled:B,refetchInterval:1e4}),K=i({queryKey:[`sessions`,`archive-transcript`,h?.id,h?.revision,I],queryFn:()=>d.sessions.archiveTranscript(h?.id,{revision:h?.revision,offset:I,limit:50}),enabled:!!h});async function q(e){b(!0),S(``),E(``);try{await e(),await c.invalidateQueries({queryKey:[`sessions`]})}catch(e){S(e instanceof Error?e.message:`Request failed`)}finally{b(!1)}}async function de(e){if(!e?.length)return;let t=u.data?.find(e=>e.id===D)?.name;t?await q(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 d.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`}`)}E(`${r} of ${e.length} sessions synchronized${i.length?`; ${i.length} need attention`:``}.`),i.length&&S(i.join(`
2
+ `))}):S(`Select a project before uploading`)}async function fe(e){await q(async()=>{if(!h)return;let r=await d.sessions.archiveResume(h.id,{revision:h.revision,repository:A,branch:j,commit:N,subdirectory:P});if(r.status!==`ready`||!r.live_session_id)throw Error(r.error||`Session preparation failed`);if(e===`terminal`){let e=await d.terminals.create({kind:h.agent,live_session_id:r.live_session_id});n(`/terminals/${e.id}`)}else{s.openThread(await d.chat.resume(r.live_session_id),{projectId:h.project_id}),g(null);let e=new URLSearchParams(t);e.set(`chat`,`open`),e.delete(`session`),n({search:e.toString()})}})}return B?(0,Y.jsxs)(`section`,{className:`mt-4 space-y-3 border-t border-border pt-2`,"data-testid":`session-archive`,children:[w&&(0,Y.jsx)(`p`,{role:`status`,"data-testid":`archive-feedback`,className:`text-sm`,children:w}),(x||G.error)&&(0,Y.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-error`,children:x||G.error?.message}),G.data?.degraded&&(0,Y.jsx)(`p`,{role:`status`,"data-testid":`archive-degraded`,className:`text-xs text-outline`,children:G.data.degraded}),!!G.data?.pending_chunks&&(0,Y.jsxs)(`p`,{className:`text-xs text-outline`,children:[G.data.pending_chunks,` passages waiting for embeddings`]}),G.data?.sessions.some(e=>e.embedding_error)&&(0,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:`Some archived sessions could not be indexed. Open archived sessions for details.`}),(0,Y.jsxs)(`details`,{"data-testid":`archive-disclosure`,children:[(0,Y.jsxs)(`summary`,{className:`min-h-11 cursor-pointer py-2 text-sm text-outline lg:min-h-8`,children:[`Archived sessions`,G.data?` · ${W+G.data.sessions.length}${G.data.has_more?`+`:``}`:``]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsx)(ue,{label:`Archived sessions`,children:`Uploaded history stays available after the source computer is offline.`}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(l,{variant:`outline`,size:`sm`,"data-testid":`archive-index`,disabled:y,onClick:()=>void q(async()=>{let t=await d.sessions.archiveIndex(e===`all`||e===`unassigned`?void 0:e);E(`${t.indexed} sessions indexed; ${t.failed} failed; ${t.skipped} skipped.`)}),children:`Index discovered sessions`}),(0,Y.jsx)(l,{size:`sm`,"data-testid":`archive-upload-open`,onClick:()=>{O(e),v(!0)},children:`Upload sessions`})]})]}),(0,Y.jsxs)(`div`,{className:`divide-y divide-border`,"data-testid":`archive-records`,children:[G.isLoading&&(0,Y.jsx)(`p`,{className:`p-4 text-sm`,children:`Loading archived sessions…`}),!G.isLoading&&!G.data?.sessions.length&&(0,Y.jsx)(`p`,{className:`p-4 text-sm text-outline`,children:`No archived sessions match this view.`}),G.data?.sessions.map(e=>(0,Y.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:()=>{g(e),L(0),ee(e.metadata.repository??``),M(e.metadata.branch??``),ne(e.metadata.commit??``),ae(e.metadata.subdirectory)},children:[(0,Y.jsx)(`span`,{className:`block text-sm font-medium`,children:e.title}),(0,Y.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,Y.jsx)(`span`,{className:`mt-1 block text-sm text-outline`,children:e.snippet},e.citation)),e.embedding_error&&(0,Y.jsx)(`span`,{className:`block text-xs text-error`,children:e.embedding_error})]},e.id))]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,Y.jsx)(l,{variant:`ghost`,disabled:W===0,onClick:()=>ce(Math.max(0,W-20)),children:`Previous`}),(0,Y.jsx)(l,{variant:`ghost`,disabled:!G.data?.has_more,onClick:()=>ce(W+20),children:`Next`})]})]}),(0,Y.jsx)(pe,{open:_,onOpenChange:v,children:(0,Y.jsxs)(se,{children:[(0,Y.jsxs)(le,{children:[(0,Y.jsx)(U,{children:`Upload session histories`}),(0,Y.jsx)(V,{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,Y.jsx)(R,{htmlFor:`archive-project`,children:`Project`}),(0,Y.jsxs)(`select`,{id:`archive-project`,"data-testid":`archive-project`,value:D,onChange:e=>O(e.target.value),className:`rounded border border-outline-variant bg-surface p-2`,children:[(0,Y.jsx)(`option`,{value:`all`,children:`Select a project`}),u.data?.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,Y.jsx)(k,{"data-testid":`archive-files`,type:`file`,multiple:!0,accept:`.jsonl`,disabled:y||!u.data?.some(e=>e.id===D),onChange:e=>void de(e.target.files)}),y&&(0,Y.jsx)(`p`,{role:`status`,children:`Uploading…`}),w&&(0,Y.jsx)(`p`,{role:`status`,"data-testid":`archive-upload-feedback`,children:w}),x&&(0,Y.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-error`,children:x})]})}),(0,Y.jsx)(pe,{open:!!h,onOpenChange:e=>{e||g(null)},children:(0,Y.jsxs)(se,{className:`max-h-[90vh] max-w-3xl overflow-y-auto`,"data-testid":`archive-detail`,children:[(0,Y.jsxs)(le,{children:[(0,Y.jsx)(U,{children:h?.title}),(0,Y.jsxs)(V,{children:[`Archived history · revision `,h?.revision,`. Prepare a destination checkout to continue in a terminal.`]})]}),K.error&&(0,Y.jsx)(`p`,{role:`alert`,children:K.error.message}),K.data?.turns.map(e=>(0,Y.jsxs)(`div`,{className:`border-b border-outline-variant py-2`,"data-testid":`archive-turn`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-outline`,children:e.role}),(0,Y.jsx)(re,{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,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(l,{variant:`ghost`,disabled:!I,onClick:()=>L(Math.max(0,I-50)),children:`Previous messages`}),(0,Y.jsx)(l,{variant:`ghost`,disabled:I+50>=(K.data?.total??0),onClick:()=>L(I+50),children:`Next messages`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-outline-variant pt-3`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium`,children:`Continue on ORC`}),(0,Y.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,Y.jsx)(R,{htmlFor:`archive-repository`,children:`Repository`}),(0,Y.jsx)(k,{id:`archive-repository`,"data-testid":`archive-repository`,value:A,onChange:e=>ee(e.target.value)}),(0,Y.jsx)(R,{htmlFor:`archive-branch`,children:`Branch`}),(0,Y.jsx)(k,{id:`archive-branch`,"data-testid":`archive-branch`,value:j,onChange:e=>M(e.target.value)}),(0,Y.jsx)(R,{htmlFor:`archive-commit`,children:`Pushed commit`}),(0,Y.jsx)(k,{id:`archive-commit`,"data-testid":`archive-commit`,value:N,onChange:e=>ne(e.target.value)}),(0,Y.jsx)(R,{htmlFor:`archive-subdirectory`,children:`Repository subdirectory`}),(0,Y.jsx)(k,{id:`archive-subdirectory`,"data-testid":`archive-subdirectory`,value:P,onChange:e=>ae(e.target.value),placeholder:`Repository root`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(l,{"data-testid":`archive-resume`,disabled:y||!A||!j||!/^[a-f0-9]{40}$/i.test(N),onClick:()=>void fe(`chat`),children:y?`Preparing…`:`Resume`}),(0,Y.jsxs)(te,{children:[(0,Y.jsx)(ie,{asChild:!0,children:(0,Y.jsx)(l,{variant:`outline`,size:`icon`,"aria-label":`More resume options`,"data-testid":`archive-resume-menu`,children:(0,Y.jsx)(f,{size:14})})}),(0,Y.jsx)(C,{className:`w-40 p-1`,align:`start`,children:(0,Y.jsx)(l,{variant:`ghost`,className:`w-full justify-start`,"data-testid":`archive-resume-terminal`,disabled:y||!A||!j||!/^[a-f0-9]{40}$/i.test(N),onClick:()=>void fe(`terminal`),children:`Terminal`})})]})]}),x&&(0,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:x})]})]})})]}):null}function He({text:e,query:t}){let n=t.trim();if(n.length<2)return(0,Y.jsx)(Y.Fragment,{children:e});let r=e.split(RegExp(`(${we(n)})`,`gi`));return(0,Y.jsx)(Y.Fragment,{children:r.map((e,t)=>e.toLowerCase()===n.toLowerCase()?(0,Y.jsx)(`mark`,{className:`bg-primary/30 text-on-surface rounded-xs`,children:e},t):e)})}function Ue(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 X=new Intl.NumberFormat;function We({sessionId:e,live:t}){let{data:n,isError:r,refetch:a}=i({queryKey:[`session-cache`,e,t],queryFn:()=>d.sessions.cacheUsage(e),staleTime:15e3,refetchInterval:t?15e3:!1,retry:1}),[o,s]=(0,J.useState)(Date.now);if((0,J.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,Y.jsx)(`button`,{type:`button`,className:`min-h-11 text-xs text-muted-foreground underline`,onClick:()=>void a(),children:`Retry cache usage`});let c=Ue(n?.latest??null,o),l=n?.latest;return!c||!l?null:(0,Y.jsxs)(`details`,{"data-testid":`session-cache`,className:`group mt-2 text-xs`,children:[(0,Y.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,Y.jsx)(f,{size:12,"aria-hidden":`true`,className:`group-open:rotate-180`}),c.label]}),(0,Y.jsxs)(`dl`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 pb-2 tabular-nums`,children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:`Last reported input`}),(0,Y.jsxs)(`dd`,{children:[X.format(l.input_tokens),` tokens`]}),(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:`Read from cache`}),(0,Y.jsxs)(`dd`,{children:[X.format(l.cached_input_tokens),` tokens`]}),l.cache_write_tokens!==null&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:`Uncached input`}),(0,Y.jsxs)(`dd`,{children:[X.format(l.input_tokens-l.cached_input_tokens-l.cache_write_tokens),` `,`tokens`]}),(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:`Written to cache`}),(0,Y.jsxs)(`dd`,{children:[X.format(l.cache_write_tokens),` tokens`]})]}),l.recorded_at&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:`Recorded`}),(0,Y.jsx)(`dd`,{children:new Date(l.recorded_at).toLocaleString()})]}),n?.totals&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:`Reported session cached input`}),(0,Y.jsxs)(`dd`,{children:[X.format(n.totals.cached_input_tokens),` /`,` `,X.format(n.totals.input_tokens)]})]})]}),c.cold&&(0,Y.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.`})]})}var Ge=8e3,Ke=y([`session`,`human`,`channel`,`system`]),qe=y([`queued`,`delivering`,`delivered`,`cancelled`,`interrupted`,`failed`]),Je=y([`hook`,`chat`,`resume`]),Z=v().min(1).max(200),Q=v().min(1).max(64),Ye=b().int().nonnegative(),Xe=_({id:Z,project_id:Z.nullable(),target_session_id:Z,target_native_id:Z.nullable(),target_backend:Q,sender_kind:Ke,sender_session_id:Z.nullable(),sender_native_id:Z.nullable(),sender_backend:Q.nullable(),sender_label:v().min(1).max(200),body:v().min(1).max(Ge),position:b().int().nonnegative(),hop:b().int().min(0).max(3),state:qe,delivered_via:Je.nullable(),delivery_error:v().max(2e3).nullable(),request_id:v().min(1).max(128).nullable(),created_at:Ye,updated_at:Ye,delivered_at:Ye.nullable()});_({session_id:Z,backend:Q.optional(),body:v().trim().min(1).max(Ge),request_id:v().trim().min(1).max(128).optional()}).strict(),_({kind:Ke,session_id:Z.nullable().optional(),native_id:Z.nullable().optional(),backend:Q.nullable().optional(),label:v().trim().min(1).max(200)}),_({direction:y([`up`,`down`])}).strict(),_({message:Xe,target:_({session_id:Z,backend:Q,status:v().max(32),delivery:y([`hook`,`resume`,`unsupported`])})});function Ze(e){let t=e.toLowerCase().replace(/-cli$/,``);return t===`claude-code`?`claude`:t}var Qe=[`claude`,`codex`,`gemini`];function $e(e){return Qe.includes(Ze(e))}var et={queued:`queued`,delivering:`delivering`,delivered:`delivered`,cancelled:`cancelled`,interrupted:`interrupted`,failed:`failed`},tt={queued:`text-primary`,delivering:`text-tertiary`,delivered:`text-outline`,cancelled:`text-outline`,interrupted:`text-tertiary`,failed:`text-error`};function nt({session:e,live:t}){let{data:n=[],error:r}=Ae(e.id,t),i=Pe(e.id),a=Ie(e.id),o=ke(e.id),[s,c]=(0,J.useState)(!1),[l,d]=(0,J.useState)(!1),[m,g]=(0,J.useState)(``),_=e.status===`stopped`||$e(e.agent),v=n.filter(e=>e.state===`queued`).length,y=n.filter(e=>e.state===`delivering`).length,b=v?`${v} queued`:y?`delivering`:n.length?`none queued`:`empty`;return(0,Y.jsxs)(`section`,{"data-testid":`session-messages`,className:`mt-2 border-t border-border pt-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`session-messages-toggle`,"aria-expanded":s,onClick:()=>c(e=>!e),className:`inline-flex min-h-11 items-center gap-1.5 font-label text-xs font-medium text-on-surface-variant hover:text-on-surface`,children:[s?(0,Y.jsx)(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}):(0,Y.jsx)(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Messages`,(0,Y.jsx)(`span`,{className:`font-normal text-outline`,children:b})]}),(0,Y.jsx)(ue,{label:`session messages`,testId:`session-messages-help`,children:`A message is delivered to this session at its next safe point: after its current tool call, or when an ended session is resumed. It is not approval, and the agent cannot use it to change configuration.`}),(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`session-message-compose`,disabled:!_,onClick:()=>{d(!0),c(!0)},className:`ml-auto inline-flex min-h-11 items-center gap-1.5 px-2 font-label text-xs font-medium text-primary hover:text-on-surface disabled:text-outline`,children:[(0,Y.jsx)(h,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Send message`]})]}),!_&&(0,Y.jsxs)(`p`,{"data-testid":`session-messages-unsupported`,className:`px-1 pb-2 text-xs text-outline`,children:[e.agent,` has no safe delivery point while it is running. Send a message after this session ends.`]}),s&&(0,Y.jsxs)(`div`,{className:`space-y-2 pb-2`,children:[l&&_&&(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=m.trim();t&&!i.isPending&&i.mutate(t,{onSuccess:()=>{g(``),d(!1),c(!0)}})},className:`space-y-2`,children:[(0,Y.jsx)(`textarea`,{"data-testid":`session-message-input`,"aria-label":`Message to this session`,value:m,maxLength:8e3,onChange:e=>g(e.target.value),placeholder:`Delivered at the session's next safe point`,className:`min-h-[72px] w-full resize-y rounded-lg border border-control-border bg-background px-2 py-2 font-body text-xs text-on-surface`}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`font-label text-[10px] text-outline tabular-nums`,children:[m.length,`/`,8e3]}),(0,Y.jsx)(`button`,{type:`submit`,"data-testid":`session-message-send`,disabled:!m.trim()||i.isPending,className:`min-h-11 rounded-lg border border-control-border px-3 font-label text-xs font-medium text-primary hover:bg-surface-bright disabled:text-outline`,children:i.isPending?`Sending…`:`Send`}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`session-message-compose-cancel`,onClick:()=>{d(!1),g(``),i.reset()},className:`min-h-11 px-2 font-label text-xs font-medium text-outline hover:text-on-surface`,children:`Cancel`})]}),i.error&&(0,Y.jsx)(`p`,{"data-testid":`session-message-error`,className:`text-xs text-error`,children:i.error.message})]}),r?(0,Y.jsxs)(`p`,{"data-testid":`session-messages-error`,className:`text-xs text-error`,children:[`Could not load messages: `,r.message]}):n.length===0?(0,Y.jsx)(`p`,{"data-testid":`session-messages-empty`,className:`px-1 text-xs text-outline`,children:`No messages queued.`}):(0,Y.jsx)(`ul`,{className:`divide-y divide-border/60`,children:n.slice(0,20).map(e=>(0,Y.jsxs)(`li`,{"data-testid":`session-message-row`,"data-state":e.state,className:`flex items-start gap-2 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 font-label text-[10px] uppercase tracking-wide`,children:[(0,Y.jsx)(`span`,{"data-testid":`session-message-state`,className:tt[e.state],children:et[e.state]}),(0,Y.jsx)(`span`,{className:`text-outline`,children:e.sender_label}),e.hop>0&&(0,Y.jsxs)(`span`,{className:`text-outline`,children:[`hop `,e.hop]}),(0,Y.jsx)(`span`,{className:`text-outline normal-case tracking-normal`,children:xe(new Date(e.created_at).toISOString())})]}),(0,Y.jsx)(`p`,{className:`mt-1 line-clamp-2 font-body text-xs text-on-surface-variant wrap-break-word whitespace-pre-wrap`,children:e.body}),e.delivery_error&&(0,Y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-error`,children:e.delivery_error})]}),e.state===`queued`&&(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center`,children:[(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Move message up`,title:`Move up`,disabled:o.isPending,onClick:()=>o.mutate({messageId:e.id,direction:`up`}),className:`min-h-11 min-w-9 text-outline hover:text-on-surface disabled:opacity-50`,children:(0,Y.jsx)(p,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Move message down`,title:`Move down`,disabled:o.isPending,onClick:()=>o.mutate({messageId:e.id,direction:`down`}),className:`min-h-11 min-w-9 text-outline hover:text-on-surface disabled:opacity-50`,children:(0,Y.jsx)(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Cancel message`,title:`Cancel`,disabled:a.isPending,onClick:()=>a.mutate(e.id),className:`min-h-11 min-w-9 text-outline hover:text-error disabled:opacity-50`,children:(0,Y.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":!0})})]})]},e.id))})]})]})}function rt({projectId:e,pending:t,onSelect:n}){let[r,a]=(0,J.useState)(``),[o,s]=(0,J.useState)(!1),[c,u]=(0,J.useState)(null),f=i({queryKey:[`tasks`,`session-picker`,e],queryFn:()=>d.tasks.list({...e?{project_id:e}:{},limit:100})});async function p(e){u(null);try{await n(e)}catch(e){u(e instanceof Error?e.message:`Could not link task`)}}async function m(){s(!0),u(null);try{await p((await d.tasks.get(r.trim())).id)}catch(e){u(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,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsx)(k,{"data-testid":`session-task-search`,"aria-label":`Search tasks or enter a task ID`,value:r,onChange:e=>{a(e.target.value),u(null)},placeholder:`Search recent tasks or paste a task ID`}),(0,Y.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,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:c}),f.error?(0,Y.jsx)(Te,{message:f.error.message,onRetry:()=>f.refetch()}):f.isLoading?(0,Y.jsx)(`p`,{role:`status`,children:`Loading tasks…`}):(0,Y.jsxs)(`div`,{className:`max-h-72 overflow-y-auto divide-y divide-border`,children:[h.map(e=>(0,Y.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,Y.jsx)(`span`,{className:`block text-sm wrap-break-word`,children:e.title}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-xs text-outline`,children:[(0,Y.jsx)(ve,{status:e.status,className:`px-0`}),e.id]})]},e.id)),h.length===0&&(0,Y.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,Y.jsx)(l,{variant:`outline`,disabled:t||o,onClick:()=>void m(),children:o?`Looking up…`:`Link by exact ID`})]})}function it({session:e,linkTestId:t=`open-task`}){let[n]=o(),[r,i]=(0,J.useState)(!1),a=Ne(),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,Y.jsxs)(`div`,{className:`min-w-0 space-y-1`,children:[e.task&&(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(s,{"data-testid":t,to:Ce(`/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,Y.jsx)(ve,{status:e.task.status,className:`px-0`})]}),(0,Y.jsxs)(pe,{open:r,onOpenChange:e=>{i(e),e&&a.reset()},children:[(0,Y.jsx)(H,{asChild:!0,children:(0,Y.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,Y.jsx)(I,{size:12}):(0,Y.jsx)(B,{size:13}),e.task?`Change task`:`Link task`]})}),(0,Y.jsxs)(se,{"data-testid":`session-task-dialog`,className:`max-h-[85dvh] w-[calc(100%-2rem)] overflow-y-auto`,children:[(0,Y.jsxs)(le,{children:[(0,Y.jsx)(U,{children:`Link a task`}),(0,Y.jsxs)(V,{children:[`Choose a recent task for `,e.name??`this session`,`, or paste an exact task ID.`]})]}),a.error&&(0,Y.jsx)(`p`,{role:`alert`,className:`text-sm text-error`,children:a.error.message}),(0,Y.jsx)(rt,{projectId:e.project_id,pending:a.isPending,onSelect:u}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.task&&(0,Y.jsx)(l,{variant:`outline`,"data-testid":`session-task-unlink`,disabled:a.isPending,onClick:()=>void u(null),children:`Unlink task`})})]})]})]})}function at({session:e}){let[t]=o(),{data:n}=ye({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,Y.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,"data-testid":`session-scratchpads`,children:[(0,Y.jsx)(`span`,{className:`text-on-surface-variant`,children:`scratchpads`}),r.map(e=>{let t=m[e.kind].icon;return(0,Y.jsxs)(s,{to:Ce(be(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,Y.jsx)(t,{size:12,"aria-hidden":!0,className:`shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.title})]},e.id)})]})}var ot=`session-search`,st={user:`border-border/65`,assistant:`border-border/65`,tool:`border-border/65 bg-transparent`,system:`border-border/65 bg-transparent`},ct=[`command`,`cmd`,`file_path`,`path`,`pattern`,`query`,`url`,`description`];function lt(e){try{let t=JSON.parse(e);for(let e of ct)if(typeof t[e]==`string`)return t[e]}catch{}return e}function ut(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function dt(e,t,n){(0,J.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(ot),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(ot,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(ot)}},[e,t,n])}function ft({block:e,open:t}){let n=e.result!==void 0;return(0,Y.jsxs)(`details`,{open:t||void 0,"data-testid":`tool-box`,className:`border-l border-border bg-background`,children:[(0,Y.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,Y.jsx)(`span`,{className:`text-secondary shrink-0`,children:e.name}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono normal-case tracking-normal text-on-surface-variant`,children:lt(e.input)}),(0,Y.jsx)(`span`,{className:`shrink-0 ${n?`text-outline`:`text-tertiary`}`,children:n?`done`:`no result`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-border px-2 py-2`,children:[(0,Y.jsx)(`div`,{className:`font-label text-[10px] font-medium text-outline`,children:`input`}),(0,Y.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:ut(e.input)}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`font-label text-[10px] font-medium text-outline`,children:`result`}),(0,Y.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 pt({block:e,matched:t}){if(e.type===`text`)return(0,Y.jsx)(re,{revealContext:t,children:e.text});if(e.type===`tool_use`)return(0,Y.jsx)(ft,{block:e,open:t});let n=e.type===`thinking`?`thinking`:`result`;return(0,Y.jsxs)(`details`,{open:t||void 0,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface`,children:n}),e.type===`thinking`?(0,Y.jsx)(`div`,{className:`mt-1`,children:(0,Y.jsx)(E,{children:e.text})}):(0,Y.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 mt({sessionId:e,initialQuery:t,onClose:n}){let[r,i]=(0,J.useState)(t),[a,o]=(0,J.useState)(0),{data:s}=Fe(!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}=je(e,u),_=(0,J.useRef)(null),v=(0,J.useRef)(null),y=(0,J.useRef)(!0),b=(0,J.useRef)(0),[x,C]=(0,J.useState)(!0),w=(0,J.useCallback)(()=>{let e=_.current;e&&(e.scrollTo({top:e.scrollHeight}),requestAnimationFrame(()=>e.scrollTo({top:e.scrollHeight})))},[]);dt(v,u,d?.turns);let T=d?.matches??[],E=T[a];(0,J.useEffect)(()=>{d&&(E===void 0?y.current&&w():(y.current=!1,document.getElementById(`turn-${E}`)?.scrollIntoView({block:`center`})))},[E,d,w]),(0,J.useEffect)(()=>{d&&x&&(b.current=d.total)},[d,x]);let k=e=>{T.length>0&&o(t=>(t+e+T.length)%T.length)};return(0,Y.jsx)(G,{open:!!e,onOpenChange:e=>!e&&n(),children:(0,Y.jsxs)(M,{side:`right`,defaultWidth:1100,resizeKey:`live-session`,"data-testid":`live-session-detail`,children:[(0,Y.jsxs)(O,{children:[(0,Y.jsx)(ee,{className:`normal-case tracking-normal text-sm pr-8`,children:c?.name??`Session`}),c&&(0,Y.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,Y.jsx)(`span`,{className:`font-medium text-primary`,children:c.agent}),(0,Y.jsx)(D,{state:P(c)}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`text-on-surface-variant`,children:`tokens `}),Se(c)]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:`text-on-surface-variant`,children:`active `}),xe(c.last_activity_at)]}),(0,Y.jsx)(it,{session:c,linkTestId:`detail-open-task`}),(0,Y.jsx)(ze,{session:c}),(0,Y.jsx)(at,{session:c}),(0,Y.jsx)(`span`,{className:`truncate max-w-full text-on-surface-variant`,children:c.cwd})]}),e&&(0,Y.jsx)(We,{sessionId:e,live:l},e),c&&(0,Y.jsx)(nt,{session:c,live:l},c.id),(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-[150px] flex-1`,children:[(0,Y.jsx)(z,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3 w-3 text-outline`}),(0,Y.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,Y.jsx)(`span`,{"data-testid":`transcript-match-count`,className:`font-label text-xs font-medium text-outline`,children:T.length===0?`no matches`:`${a+1} / ${T.length}`}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Previous match`,onClick:()=>k(-1),className:`min-h-11 min-w-11 p-2 text-outline hover:text-on-surface`,children:(0,Y.jsx)(ce,{className:`h-4 w-4`})}),(0,Y.jsx)(`button`,{type:`button`,"aria-label":`Next match`,onClick:()=>k(1),className:`min-h-11 min-w-11 p-2 text-outline hover:text-on-surface`,children:(0,Y.jsx)(S,{className:`h-4 w-4`})}),(0,Y.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,Y.jsx)(q,{className:`h-3 w-3 ${p?`animate-spin`:``}`}),`Refresh`]})]}),d&&(0,Y.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,Y.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[(0,Y.jsx)(j,{ref:_,onScroll:e=>{let t=e.currentTarget,n=t.scrollHeight-t.scrollTop-t.clientHeight<160;y.current=n,C(n)},children:f?(0,Y.jsx)(`div`,{className:`space-y-4`,children:[...[,,,,,]].map((e,t)=>(0,Y.jsx)(N,{className:`h-16 w-full bg-surface-highest`},t))}):m||!d?(0,Y.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,Y.jsx)(`p`,{className:`mt-2`,children:`Resume actions remain available when the native agent session exists.`}),(0,Y.jsx)(`button`,{type:`button`,className:`mt-3 min-h-11 text-primary hover:underline`,onClick:()=>h(),children:`Retry conversation`})]}):(0,Y.jsx)(`div`,{ref:v,className:`space-y-3`,children:d.turns.map(e=>{let t=T.includes(e.index),n=e.blocks.map((e,n)=>(0,Y.jsx)(pt,{block:e,matched:t},n));return(0,Y.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 ${st[e.role]} ${e.index===E?`ring-1 ring-primary`:``}`,children:[(0,Y.jsxs)(`div`,{className:`font-label text-xs font-medium text-outline`,children:[e.role,e.time?` · ${xe(e.time)}`:``]}),e.role===`system`?(0,Y.jsxs)(`details`,{open:t||void 0,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer font-label text-xs font-medium text-outline hover:text-on-surface`,children:`injected context`}),(0,Y.jsx)(`div`,{className:`mt-2 space-y-2`,children:n})]}):n]},e.index)})})}),d&&!x&&(0,Y.jsxs)(`button`,{type:`button`,"data-testid":`jump-to-latest`,onClick:()=>{y.current=!0,w()},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,Y.jsx)(A,{className:`h-3.5 w-3.5`}),`Jump to latest`,d.total>b.current&&` · ${d.total-b.current} new`]})]})]})})}var ht=[...x.flatMap(e=>e.sessionBackends),`cursor`],$=25;function gt({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=he(n.get(`state`)),[p,m]=(0,J.useState)(s),[h,_]=(0,J.useState)({order:u,page:0}),v=h.order===u?h.page:0,y=(0,J.useCallback)(e=>_({order:u,page:e}),[u]),b=(0,J.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,J.useEffect)(()=>m(s),[s]),(0,J.useEffect)(()=>{if(p===s)return;let e=`${t.pathname}${t.search}${t.hash}`,n=setTimeout(()=>{`${window.location.pathname}${window.location.search}${window.location.hash}`===e&&b(`q`,p.trim()||null)},350);return()=>clearTimeout(n)},[p,s,b,t.pathname,t.search,t.hash]);let x=s.trim().length>=2,S=e===`all`?void 0:e,C=Fe(!a,S),E=Me(x?s.trim():``,i,S),{data:D}=T(),O=Le(),k=new Map((D??[]).map(e=>[e.id,e.name])),A=x?E.data?.hits??[]:C.data??[],ee=[...new Set([...ht,...A.map(e=>e.agent)])],j=x?E.isLoading:C.isLoading,M=x?E:C,N=A.filter(e=>(!i||e.agent===i)&&(a||e.status!==`stopped`||e.handoff?.status===`ready`)),te=W();(0,J.useEffect)(()=>{if(!d)return;let e=[`native:${d}`];return K(e),()=>K(e)},[d]);let re=e=>new Date(e.last_activity_at??e.created_at).getTime(),ie=new Map(N.map(e=>[e.id,e.id===d?P(e):fe(P(e),re(e),L(te,[`native:${e.id}`]))])),F=e=>ie.get(e.id)??P(e),I=N.filter(t=>e===`all`?!0:e===`unassigned`?t.project_id===null:t.project_id===e),R=ne(I.map(F)),se=new Map(I.map(e=>[e.id,e])),B=de({items:I.filter(e=>w(F(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(re(e)),lookup:e=>se.get(e),resetKey:[e,f,i,a,s,u].join(`
4
+ `),loading:j}),V=B.items,H=Math.min(v,Math.max(0,Math.ceil(V.length/$)-1))*$,U=e===`unassigned`?`unassigned`:k.get(e)??e;return(0,Y.jsxs)(`section`,{className:`mb-8`,"data-testid":`live-sessions`,children:[(0,Y.jsx)(Ee,{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,Y.jsxs)(Y.Fragment,{children:[V.length,I.length!==N.length&&(0,Y.jsxs)(`span`,{"data-testid":`scope-hint`,className:`normal-case tracking-normal`,children:[` `,`of `,N.length,` · scope: `,U]}),x&&E.data&&(0,Y.jsxs)(`span`,{"data-testid":`search-meta`,className:`normal-case tracking-normal`,children:[` `,`· `,(E.data.ms/1e3).toFixed(1),`s`,E.data.rg?``:` · titles and summaries only (install ripgrep for content)`]})]}),action:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(Be,{label:`Open sessions view`,testId:`live-sessions-open-home`}),(0,Y.jsx)(l,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":O.isPending?`Syncing sessions`:`Refresh sessions`,title:`Refresh sessions`,"data-testid":`sync-sessions`,disabled:O.isPending,className:`lg:size-8`,onClick:()=>O.mutate(),children:(0,Y.jsx)(q,{className:O.isPending?`animate-spin`:``})})]})}),(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1 lg:max-w-md`,children:[(0,Y.jsx)(z,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-outline`}),(0,Y.jsx)(`input`,{type:`search`,"data-testid":`session-search`,"aria-label":`Search agent sessions`,value:p,onChange:e=>m(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,Y.jsxs)(g,{activeCount:Number(!!i)+Number(!a)+Number(u===`asc`),children:[(0,Y.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,Y.jsx)(`option`,{value:`desc`,children:`Last active: newest`}),(0,Y.jsx)(`option`,{value:`asc`,children:`Last active: oldest`})]}),(0,Y.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,Y.jsx)(`option`,{value:``,children:`All agents`}),ee.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`label`,{className:`flex min-h-11 cursor-pointer items-center gap-2 text-[13px] text-outline lg:min-h-8`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,"data-testid":`show-ended`,checked:a,onChange:e=>b(`ended`,e.target.checked?`1`:`0`)}),`Show ended`]})]})]}),(0,Y.jsxs)(`div`,{...B.listProps,children:[x?(0,Y.jsx)(ge,{pending:B.pending,onApply:B.apply}):(0,Y.jsx)(oe,{className:`mb-3`,value:f,counts:R,onChange:e=>b(`state`,e===`all`?null:e),children:(0,Y.jsx)(ge,{pending:B.pending,onApply:B.apply})}),O.error&&(0,Y.jsx)(`p`,{role:`alert`,className:`mb-3 text-sm text-error`,children:O.error.message}),M.error?(0,Y.jsx)(Te,{message:M.error.message,onRetry:()=>M.refetch()}):j?(0,Y.jsx)(`p`,{role:`status`,className:`py-8 text-sm text-outline`,children:`Loading sessions…`}):V.length===0?(0,Y.jsx)(De,{message:x||f!==`all`?`No sessions match`:`No active agent sessions. Enable Show ended to browse previous conversations.`}):(0,Y.jsxs)(`div`,{className:`min-w-0 overflow-hidden`,children:[(0,Y.jsx)(`div`,{className:`divide-y divide-border`,"data-testid":`live-session-list`,children:V.slice(H,H+$).map(e=>(0,Y.jsxs)(`article`,{"data-testid":`live-session-row`,"data-session-id":e.session_id,"data-agent":e.agent,"data-state":F(e),className:`min-w-0 py-1`,children:[(0,Y.jsx)(`div`,{className:`${_e} hover:bg-surface`,children:(0,Y.jsx)(`button`,{type:`button`,className:me,onClick:()=>b(`session`,e.id),children:(0,Y.jsx)(ae,{agent:e.agent,title:(0,Y.jsx)(He,{text:e.name??`Untitled session`,query:x?s:``}),state:F(e),stateTestId:`live-status`,compact:!1})})}),(0,Y.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,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 sm:col-start-1`,children:[(0,Y.jsx)(`span`,{children:e.agent}),(0,Y.jsxs)(`span`,{"data-testid":`live-tokens`,children:[Se(e),` tokens`]}),(0,Y.jsx)(`span`,{children:xe(e.last_activity_at)}),(0,Y.jsx)(`span`,{children:e.project_id?k.get(e.project_id)??`Unknown project`:`Unassigned`}),e.handoff?.status===`ready`&&(0,Y.jsx)(`span`,{"data-testid":`handoff-ready`,children:`Ready to resume`})]}),e.summary&&e.summary!==e.name&&(0,Y.jsx)(`p`,{className:`truncate sm:col-start-1`,title:e.summary,children:(0,Y.jsx)(He,{text:e.summary,query:x?s:``})}),e.snippets?.map(e=>(0,Y.jsx)(`p`,{"data-testid":`search-snippet`,className:`wrap-break-word sm:col-start-1`,children:(0,Y.jsx)(He,{text:e,query:s})},e)),e.cwd&&(0,Y.jsx)(`p`,{className:`truncate sm:col-start-1`,title:e.cwd,children:e.cwd}),(0,Y.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,Y.jsx)(it,{session:e}),(0,Y.jsx)(ze,{session:e}),(0,Y.jsx)(Be,{liveId:e.id,label:`Open in sessions view`,testId:`live-session-open-home`})]})]})]},e.id))}),(0,Y.jsx)(Oe,{page:H/$,pageSize:$,total:V.length,onPage:y})]})]}),(0,Y.jsx)(mt,{sessionId:d,initialQuery:x?s.trim():``,onClose:()=>b(`session`,null)},d??`closed`)]})}function _t({projectId:e}){let t=Re(e);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(Ee,{title:`Sessions`}),(0,Y.jsx)(gt,{projectId:t},t),(0,Y.jsx)(Ve,{projectId:t},`archive-${t}`)]})}export{_t as default};