1import{A as je,y as ye,nb as Ne,ks as Se,r as h,nc as we,j as t,aq as f,au as N,nd as be,ne as Ae,P as ke,b as Te,L as $,cd as Re,c as ne,W as Le,B as G,nf as se,lW as _e,bQ as Ce,q as ae,ng as I,f as V,b0 as Ie,S as Ee}from"./index-_Ci2S7BU.js";import{b as z,A as $e,a as Fe}from"./ActivityRow-CLGkwpXw.js";import"./alertStyles-BHKPp5pv.js";import"./archive-B7iclEQe.js";const A=f("text-[13px] leading-5",N.body),w=f(N.linkSmall,N.focusRing),re=8e3,Oe=4e3,U="Nothing matches your search.",ue={needs_you:"Nothing needs you right now.",running:"Nothing is running right now.",didnt_finish:"Everything you started finished."},De=[["live","Activity could not be refreshed. Showing the last known state."],["agents","Activity could not be refreshed. Showing the last known state."],["history","Older work could not be loaded."],["alerts","Alert updates could not be loaded."],["archive","What you archived could not be loaded, so archived items may show here."]],Q=e=>`â${e}â`,P=e=>`${e} ${e===1?"item":"items"}`,K=e=>e.length===1?Q(e[0].title):P(e.length),Pe=e=>`Couldnât archive ${K(e)}. ${e.length===1?"Itâs":"Theyâre"} back in the list.`,le=e=>`Couldnât restore ${K(e)}. ${e.length===1?"Itâs":"Theyâre"} still archived.`;function Ge(e){const[n,s]=h.useState(()=>Number.isFinite(e)?e:Date.now());return h.useEffect(()=>{if(Number.isFinite(e)){s(e);return}const a=setInterval(()=>s(Date.now()),6e4);return()=>clearInterval(a)},[e]),n}function H({children:e,className:n="",...s}){return t.jsx("p",{...s,className:f("py-12 text-center",A,n),children:e})}function E({title:e,count:n=null,dot:s=!1,children:a,footer:c=null}){const r=h.useId();return t.jsxs("section",{"aria-labelledby":r,className:"flex flex-col gap-3",children:[t.jsxs("h2",{id:r,className:f("flex items-center gap-2 text-[13px] font-medium leading-5",N.body),children:[s?t.jsx("span",{"aria-hidden":"true",className:f("h-1.5 w-1.5 shrink-0 rounded-full",N.goldFill)}):null,e,n!==null?t.jsx("span",{className:"font-normal tabular-nums",children:n}):null]}),a,c]})}const Ue=(e,n)=>new Date(e||0).toDateString()===new Date(n||0).toDateString();function qe({item:e,now:n,Row:s,actions:a}){const[c,r]=h.useState(!1),l=e.sessions||e.repeats;return t.jsxs(t.Fragment,{children:[t.jsx(s,{item:e,now:n,onArchive:a.archiveGroup,onRestore:a.restoreGroup}),t.jsx(Fe,{item:e,open:c,onToggle:()=>r(o=>!o),onArchiveRepeats:e.sessions?null:a.archiveRepeats}),c?l.map(o=>t.jsx(z,{item:o,now:n,onArchive:a.archive,onRestore:a.restore,repeat:!0,grouped:s===z&&Ue(o.at,e.at)},o.id)):null]})}function L({items:e,now:n,dense:s=!1,actions:a={}}){const c=s?z:$e;return t.jsx(V,{as:"ul",theme:"studio",padding:"none",className:"divide-y overflow-hidden",children:e.map(r=>r.repeats?.length?t.jsx(qe,{item:r,now:n,Row:c,actions:a},r.foldId||r.id):t.jsx(c,{item:r,now:n,onArchive:a.archive,onRestore:a.restore},r.foldId||r.id))})}function ie({to:e,children:n}){return t.jsx($,{to:e,className:f("self-start",w),children:n})}function ce({label:e="Loading activityâ¦"}){return t.jsx("div",{className:"py-12 text-center",role:"status",children:t.jsx(Ee,{size:"sm",label:e})})}function Me(e,n){const[s,a]=h.useState(!1);return h.useEffect(()=>{if(a(!1),!e)return;const c=setTimeout(()=>a(!0),_e);return()=>clearTimeout(c)},[e,n]),e&&s}function Be(e){const[n,s]=h.useState(!1),a=e.status.failed.length>0||e.feeds.archive==="failed";return h.useEffect(()=>{if(!n)return;if(!a){s(!1);return}const c=setTimeout(()=>s(!1),Oe);return()=>clearTimeout(c)},[n,a]),{retrying:n&&a,again:()=>{s(!0),e.retry()}}}function F({inbox:e,slow:n,retry:s,children:a}){return e.status.failed.length?s.retrying?t.jsx(ce,{label:"Trying againâ¦"}):t.jsxs(H,{role:"status","data-activity-state":"failed",children:["We couldnât load your activity."," ",t.jsx(G,{unstyled:!0,onClick:s.again,className:f("underline underline-offset-2",w),children:"Try again"})]}):e.status.pending.length?n?t.jsx(H,{role:"status","data-activity-state":"slow",children:"Still loading your activity. This is taking longer than usual."}):t.jsx(ce,{}):t.jsx(H,{"data-activity-state":"empty",children:a})}function q({inbox:e,slow:n}){return e.historyLoading?t.jsx("p",{className:f("mt-4",A),role:"status",children:n?"Older work is taking longer than usual to load.":"Loading older workâ¦"}):null}function J({groups:e,now:n,dense:s,openAll:a,actions:c}){const[r,l]=h.useState(()=>new Set);return e.map(o=>{const m=a||!o.collapsible||r.has(o.key);return t.jsx(E,{title:o.label,count:o.items.length,children:m?t.jsx(L,{items:o.items,now:n,dense:s,actions:c}):t.jsx(V,{as:"div",theme:"studio",padding:"none",className:"overflow-hidden",children:t.jsxs(G,{unstyled:!0,"aria-expanded":"false","aria-label":`Show ${o.items.length} ${o.items.length===1?"item":"items"} from ${o.label}`,"data-activity-group":o.key,onClick:()=>l(v=>new Set(v).add(o.key)),className:"flex min-h-11 w-full items-center gap-3 px-4 text-left sm:px-5",children:[t.jsx(Ie,{size:16,"aria-hidden":"true",className:N.body}),t.jsxs("span",{className:"flex min-w-0 flex-1 items-baseline gap-2.5",children:[t.jsxs("span",{className:f("whitespace-nowrap",N.cardTitle),children:[o.items.length," ",o.items.length===1?"item":"items"]}),t.jsx("span",{className:f("truncate tabular-nums",A),children:o.range})]}),t.jsx("span",{className:N.linkSmall,children:"Show"})]})})},o.key)})}function We({inbox:e,now:n,actions:s,withQuery:a,slow:c,retry:r}){const{buckets:l,counts:o,searching:m}=e,v=e.feeds.history==="ready",u=l.didnt_finish,j=l.done,S=m?j.length>I:o.done===null?j.length>0:o.done>
1I,k=m?`See all ${j.length.toLocaleString("en-US")} done â`:o.done===null?"See all done â":`See all ${o.done.toLocaleString("en-US")} done â`,d=[l.needs_you.length?t.jsx(E,{title:"Needs you",dot:!0,children:t.jsx(L,{items:l.needs_you,now:n,actions:s})},"needs"):null,l.running.length?t.jsx(E,{title:"Running",children:t.jsx(L,{items:l.running,now:n,actions:s})},"running"):null,u.length?t.jsx(E,{title:"Didnât finish",footer:u.length>I?t.jsx(ie,{to:a("didnt-finish"),children:v||m?`See all ${u.length} â`:"See all â"}):null,children:t.jsx(L,{items:u.slice(0,I),now:n,actions:s})},"didnt"):null,j.length?t.jsx(E,{title:"Done",footer:S?t.jsx(ie,{to:a("done"),children:k}):null,children:t.jsx(L,{items:j.slice(0,I),now:n,actions:s})},"done"):null].filter(Boolean);return d.length?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex flex-col gap-10",children:d}),t.jsx(q,{inbox:e,slow:c})]}):t.jsx(F,{inbox:e,slow:c,retry:r,children:m?U:t.jsxs(t.Fragment,{children:["Nothing here yet."," ",t.jsx($,{to:"/research",className:w,children:"Start a chat â"})]})})}function He({inbox:e,bucket:n,now:s,actions:a,slow:c,retry:r}){const l=e.buckets[n];return l.length?t.jsx(L,{items:l,now:s,actions:a}):t.jsx(F,{inbox:e,slow:c,retry:r,children:e.searching?U:ue[n]})}function ze({inbox:e,now:n,actions:s,slow:a,retry:c}){return e.didntFinishGroups.length?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex flex-col gap-7",children:t.jsx(J,{groups:e.didntFinishGroups,now:n,openAll:e.searching,actions:s})}),t.jsx(q,{inbox:e,slow:a})]}):t.jsx(F,{inbox:e,slow:a,retry:c,children:e.searching?U:ue.didnt_finish})}function Qe({inbox:e,now:n,projectsEnabled:s,actions:a,slow:c,retry:r}){return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex flex-col gap-7",children:e.doneGroups.length?t.jsx(J,{groups:e.doneGroups,now:n,dense:!0,openAll:e.filtered,actions:a}):t.jsx(F,{inbox:e,slow:c,retry:r,children:e.filtered?"No done items match.":"Nothing done yet."})}),e.doneGroups.length?t.jsx(q,{inbox:e,slow:c}):null,s?t.jsxs("p",{className:f("mt-7 flex flex-wrap items-center gap-x-3 gap-y-1",A),children:["Older work stays in its project and in search.",t.jsx($,{to:"/projects",className:w,children:"Go to Projects â"})]}):null]})}function Ye({inbox:e,now:n,actions:s,slow:a,retry:c}){return e.archivedGroups.length?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex flex-col gap-7",children:t.jsx(J,{groups:e.archivedGroups,now:n,dense:!0,openAll:e.searching,actions:s})}),t.jsx(q,{inbox:e,slow:a})]}):t.jsx(F,{inbox:e,slow:a,retry:c,children:e.searching?U:"Nothing is archived."})}function Ve({tab:e,inbox:n,q:s,projectId:a,useCase:c,setParam:r}){return t.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center",children:[t.jsx(Ce,{theme:"studio","aria-label":"Search activity",placeholder:"Search activity",value:s,onChange:l=>r("q",l.target.value),className:"min-w-0 flex-1"}),e==="done"?t.jsxs("div",{className:"flex gap-2",children:[t.jsxs(ae,{theme:"studio","aria-label":"Project",value:a,onChange:l=>r("project",l.target.value),className:"min-w-0 flex-1 sm:w-44 sm:flex-none",children:[t.jsx("option",{value:"",children:"All projects"}),n.projectOptions.map(l=>t.jsx("option",{value:l.value,children:l.label},l.value))]}),t.jsxs(ae,{theme:"studio","aria-label":"Use case",value:c,onChange:l=>r("use_case",l.target.value),className:"min-w-0 flex-1 sm:w-44 sm:flex-none",children:[t.jsx("option",{value:"",children:"All use cases"}),n.useCaseOptions.map(l=>t.jsx("option",{value:l.value,children:l.label},l.value))]})]}):null]})}function Ke(){const[e,n]=h.useState(null),s=h.useRef(0),a=h.useRef(null),c=h.useRef(!1);return h.useEffect(()=>{if(!e){c.current=!1;return}let l=0;const o=()=>{c.current||a.current?.contains(document.activeElement)?l=setTimeout(o,re):n(m=>m?.id===e.id?null:m)};return l=setTimeout(o,re),()=>clearTimeout(l)},[e]),{notice:e,show:(l,o=null)=>{s.current+=1,n({id:s.current,text:l,undo:o})},clear:()=>n(null),lineRef:a,hovered:c}}function Je({notice:e,onUndo:n,lineRef:s,hovered:a}){return t.jsx("div",{ref:s,role:"status","aria-live":"polite","data-activity-notice":"",className:"pointer-events-none sticky bottom-4 z-10 flex",children:e?t.jsxs(V,{as:"p",theme:"studio",padding:"none",className:f("pointer-events-auto mt-6 flex max-w-full flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5",A),onMouseEnter:()=>{a.current=!0},onMouseLeave:()=>{a.current=!1},children:[t.jsx("span",{className:"min-w-0",children:e.text}),e.undo?t.jsx(G,{unstyled:!0,onClick:n,className:f("underline underline-offset-2",w),children:"Undo"}):null]}):null})}const de=["data-activity-item","data-activity-repeats","data-activity-group"],Xe=de.map(e=>`[${e}]`).join(","),oe=e=>{const n=de.find(s=>
1e.hasAttribute(s));return{attr:n,value:e.getAttribute(n)}},Ze=(e,{attr:n,value:s})=>[...e.querySelectorAll(`[${n}]`)].find(a=>a.getAttribute(n)===s)||null,et=e=>(e?.matches("button, a[href]")?e:e?.querySelector("button, a[href]"))||null,Y=(e,n=[])=>[...e.map(s=>({attr:"data-activity-item",value:s})),...n.map(s=>({attr:"data-activity-repeats",value:s}))];function tt(e){const n=h.useRef(null),s=h.useRef(null);return h.useLayoutEffect(()=>{const a=n.current,c=e.current;if(!a||!c)return;n.current=null;const r=document.activeElement,l=!r||r===document.body||!r.isConnected||r===s.current;if(a.onlyIfLost&&!l)return;const o=a.anchors.map(m=>et(Ze(c,m))).find(Boolean)||c;o.focus(),s.current=o}),{leave(a,c=[]){const r=e.current,l=document.activeElement;if(!r||!l||!r.contains(l))return;const o=new Set(Y(a,c).map(({attr:d,value:T})=>`${d}=${T}`)),m=d=>{const{attr:T,value:O}=oe(d);return o.has(`${T}=${O}`)},v=[...r.querySelectorAll(Xe)],u=v.find(d=>m(d)&&d.contains(l));if(!u)return;const j=v.filter(d=>!m(d)),S=j.filter(d=>u.compareDocumentPosition(d)&d.DOCUMENT_POSITION_FOLLOWING),k=j.filter(d=>u.compareDocumentPosition(d)&d.DOCUMENT_POSITION_PRECEDING).reverse();n.current={anchors:[...S,...k].map(oe)}},back(a,{onlyIfLost:c=!1}={}){n.current={anchors:a,onlyIfLost:c}}}}function lt({sources:e,now:n}={}){const[s,a]=je(),{hasStudioAgentAccess:c}=ye(),r=Ne(s.get("tab")),l=s.get("q")||"",o=s.get("project")||"",m=s.get("use_case")||"",v=Ge(n),u=Se({tab:r,q:l,projectId:o,useCase:m,now:v,sources:e}),j=!!c,S=r===se,{notice:k,show:d,clear:T,lineRef:O,hovered:he}=Ke(),X=h.useRef(null),R=tt(X),M=i=>{const g=new URLSearchParams;i!=="all"&&g.set("tab",i),l&&g.set("q",l);const y=g.toString();return y?`?${y}`:"/activity"},fe=i=>a(()=>{const g=new URLSearchParams;return i!=="all"&&g.set("tab",i),l&&g.set("q",l),g}),me=(i,g)=>a(y=>{const x=new URLSearchParams(y);return g?x.set(i,g):x.delete(i),x},{replace:!0}),ge=we.map(i=>{const g=i.id==="needs-you"?u.counts.needs_you||null:i.id==="done"?u.counts.done:null;return{id:i.id,label:t.jsxs("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap",children:[i.label,g?t.jsx("span",{className:f("font-normal tabular-nums",N.body),children:g.toLocaleString("en-US")}):null]})}}),Z=be(r),ve=S?u.archivedGroups.length>0:r==="all"?Ae.some(i=>u.buckets[i].length>0):r==="done"?u.doneGroups.length>0:r==="didnt-finish"?u.didntFinishGroups.length>0:u.buckets[Z].length>0,_=Me(u.status.pending.length>0,r),b=Be(u),xe=[...u.status.failed,...u.feeds.archive==="failed"?["archive"]:[]],ee=ve&&De.find(([i])=>xe.includes(i))?.[1]||"",B=(i,g,y=[])=>{const x=i.map(p=>p.id),C=Y(x,y);R.leave(x,y),d(g,p=>{T(),p&&R.back(C),u.unarchive(x).then(W=>{W||d(le(i))})}),u.archive(x).then(p=>{p||(R.back(C,{onlyIfLost:!0}),d(Pe(i)))})},D={archive:i=>B([i],`Archived ${Q(i.title)}.`),archiveGroup:i=>B([i,...i.repeats],`Archived ${P(i.repeats.length+1)}.`,[i.id]),archiveRepeats:i=>B(i.repeats,`Archived ${P(i.repeats.length)}.`,[i.id])},te=(i,g,y=[])=>{const x=i.map(p=>p.id),C=Y(x,y);R.leave(x,y),d(g,p=>{T(),p&&R.back(C),u.archive(x).then(W=>{W||d(`Couldnât archive ${K(i)} again. ${i.length===1?"It stays":"They stay"} on Activity.`)})}),u.unarchive(x).then(p=>{p||(R.back(C,{onlyIfLost:!0}),d(le(i)))})},pe={restore:i=>te([i],`Restored ${Q(i.title)}.`),restoreGroup:i=>te([i,...i.repeats],`Restored ${P(i.repeats.length+1)}.`,[i.id])};return t.jsx(ke,{children:t.jsxs(Te,{children:[S?t.jsxs(t.Fragment,{children:[t.jsxs($,{to:M("all"),className:f("mb-4 inline-flex items-center gap-1",w),children:[t.jsx(Re,{size:14,"aria-hidden":"true"}),"Back to Activity"]}),t.jsx(ne,{title:"Archived",description:"Hidden from Activity. The runs themselves are unchanged.",className:"!mb-0"})]}):t.jsxs(t.Fragment,{children:[t.jsx(ne,{title:"Activity",description:"Everything waiting on you, running, or finished.",className:"!mb-0"}),t.jsx(Le,{variant:"underline",items:ge,activeId:r,onChange:fe,ariaLabel:"Filter activity",className:"mt-7 !flex-nowrap gap-x-3 overflow-x-auto pb-px [scrollbar-width:none] sm:gap-x-6 sm:overflow-visible sm:pb-0"})]}),ee?t.jsxs("p",{role:"status","data-activity-state":"stale",className:f("mt-4",A),children:[ee," ",b.retrying?"Trying againâ¦":t.jsx(G,{unstyled:!0,onClick:b.again,className:f("underline underline-offset-2",w),children:"Try again"})]}):null,t.jsx("div",{className:"mt-6",children:t.jsx(Ve,{tab:r,inbox:u,q:l,projectId:o,useCase:m,setParam:me})}),t.jsxs("div",{className:"mt-7",children:[t.jsx("div",{ref:X,tabIndex:-1,
1className:"outline-none",children:S?t.jsx(Ye,{inbox:u,now:v,actions:pe,slow:_,retry:b}):r==="all"?t.jsx(We,{inbox:u,now:v,actions:D,withQuery:M,slow:_,retry:b}):r==="done"?t.jsx(Qe,{inbox:u,now:v,projectsEnabled:j,actions:D,slow:_,retry:b}):r==="didnt-finish"?t.jsx(ze,{inbox:u,now:v,actions:D,slow:_,retry:b}):t.jsx(He,{inbox:u,bucket:Z,now:v,actions:D,slow:_,retry:b})}),t.jsx(Je,{notice:k,onUndo:()=>k?.undo?.(!!O.current?.contains(document.activeElement)),lineRef:O,hovered:he})]}),!S&&u.archivedCount>0?t.jsx("p",{className:f("mt-10",A),children:t.jsxs($,{to:M(se),className:w,children:["Archived (",u.archivedCount.toLocaleString("en-US"),")"]})}):null]})})}export{lt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.