@kimiclaw/cli 1.0.44 → 1.0.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -19
- package/package.json +9 -9
- package/web/dist/assets/{AssistantsView-Y4TXobGE.js → AssistantsView-Y3nFezhd.js} +1 -1
- package/web/dist/assets/AutomationView-bf7_zU_p.js +4 -0
- package/web/dist/assets/Button-B43HsIQ3.js +1 -0
- package/web/dist/assets/{ChannelConfigView-WJ-zUV8p.js → ChannelConfigView---Dwl3Fk.js} +3 -3
- package/web/dist/assets/ChartsView-Dw6G-jf3.js +1 -0
- package/web/dist/assets/{ConnectorsView-DaHmxnGE.js → ConnectorsView-BWvdrpyK.js} +2 -2
- package/web/dist/assets/{DiffPreview-D8tIj_aF.js → DiffPreview-WQihq3bK.js} +57 -56
- package/web/dist/assets/{FileContextMenu-C5WYeBNu.js → FileContextMenu-CyjXlSHp.js} +1 -1
- package/web/dist/assets/FileTreeView-Cafy33nT.js +1 -0
- package/web/dist/assets/HookConfigView-D-lASVju.js +2 -0
- package/web/dist/assets/InboxView-BWajw-Yx.js +1 -0
- package/web/dist/assets/InputArea-CSqaA55j.js +31 -0
- package/web/dist/assets/Install-ClEm4oGX.js +2 -0
- package/web/dist/assets/MemoryView-DLri75dm.js +1 -0
- package/web/dist/assets/ModelsView-BBLUMzR5.js +1 -0
- package/web/dist/assets/PluginsView-C-fnbDGZ.js +1 -0
- package/web/dist/assets/ProjectsView-BruI2W_l.js +1 -0
- package/web/dist/assets/{SessionGrid-BQSrCDqQ.js → SessionGrid-7GLpwn6d.js} +4 -4
- package/web/dist/assets/SettingsModal-cc9Qu2QU.js +4 -0
- package/web/dist/assets/SkillsView-Bf-2-U_q.js +1 -0
- package/web/dist/assets/TemplatesTab-CKul8nbL.js +2 -0
- package/web/dist/assets/{ToolsView-CjdYiaNz.js → ToolsView-D_aluOsK.js} +1 -1
- package/web/dist/assets/WorkspaceDirPicker-Z42YqE4a.js +5 -0
- package/web/dist/assets/{agentIconSet-CDeMxTHf.js → agentIconSet-Cqhm4UOl.js} +1 -1
- package/web/dist/assets/api-BW4-5gtM.js +1 -0
- package/web/dist/assets/chatStore-D8Zzr1hE.js +242 -0
- package/web/dist/assets/cn-CoHJgTJ5.js +1 -0
- package/web/dist/assets/{common-CPZxdYLs.js → common-CP2UB8TN.js} +99 -99
- package/web/dist/assets/icons-CittejKL.js +1 -0
- package/web/dist/assets/imageUrl-BVgcEm7e.js +2 -0
- package/web/dist/assets/index-CEUbTcNL.css +1 -0
- package/web/dist/assets/index-CxrzleFg.js +122 -0
- package/web/dist/assets/{markdown-Cps-36Z5.js → markdown-DZQBOzWk.js} +1 -1
- package/web/dist/assets/{panels-DCwx2Pbu.js → panels-CuDz4aqU.js} +1 -1
- package/web/dist/assets/projectsStore-B7fdKRzl.js +1 -0
- package/web/dist/assets/{react-vendor-CXI113IS.js → react-vendor-BEA-EtI-.js} +1 -1
- package/web/dist/assets/{settingsStore-BSdi9gNd.js → settingsStore-DYqiXodu.js} +1 -1
- package/web/dist/assets/src-55YckF5W.js +2 -0
- package/web/dist/assets/{state-pOTP5BEk.js → state-A4wJ8QgR.js} +1 -1
- package/web/dist/assets/{statusAxesRefresh--2evRuAU.js → statusAxesRefresh-BBqszCp-.js} +1 -1
- package/web/dist/assets/sttLanguages-jnSk4aqg.js +6 -0
- package/web/dist/assets/threadStore-CQi4OzSe.js +1 -0
- package/web/dist/assets/useConfirm-kTv3x0H6.js +1 -0
- package/web/dist/assets/{useTranslation-gGKZZfux.js → useTranslation-2BGEBvJE.js} +1 -1
- package/web/dist/assets/websocket-DCs7f54y.js +1 -0
- package/web/dist/assets/whatsNewStore-DoCQvcMq.js +1 -0
- package/web/dist/index.html +27 -23
- package/web/dist/assets/AutomationView-DfAF2L92.js +0 -3
- package/web/dist/assets/Button-D-g7PgYh.js +0 -1
- package/web/dist/assets/ChartsView-CSAfGqTC.js +0 -1
- package/web/dist/assets/FileTreeView-B7IN0KmE.js +0 -1
- package/web/dist/assets/HookConfigView-9gqvrRhQ.js +0 -2
- package/web/dist/assets/InboxView-BcEfijbj.js +0 -1
- package/web/dist/assets/InputArea-D5F91Uwk.js +0 -14
- package/web/dist/assets/Install-Cuelo0If.js +0 -2
- package/web/dist/assets/MemoryView-BvZSh5-T.js +0 -1
- package/web/dist/assets/ModelsView-BgvMN8xv.js +0 -1
- package/web/dist/assets/PluginsView-C3d6e8vV.js +0 -1
- package/web/dist/assets/ProjectsView-CM7GOsoK.js +0 -1
- package/web/dist/assets/SettingsModal-BvGXq5EE.js +0 -4
- package/web/dist/assets/SkillsView-87kGRliE.js +0 -1
- package/web/dist/assets/TemplatesTab-8MLwVNwV.js +0 -1
- package/web/dist/assets/api-ZQf0Ys8y.js +0 -1
- package/web/dist/assets/icons-B8Ngx6rM.js +0 -1
- package/web/dist/assets/imageUrl-CrQM4gmf.js +0 -74
- package/web/dist/assets/index-Bm7r92T3.css +0 -1
- package/web/dist/assets/index-STsyoFCk.js +0 -145
- package/web/dist/assets/src-BK8SoTFV.js +0 -1
- package/web/dist/assets/sttLanguages-BPcOF0nQ.js +0 -2
- package/web/dist/assets/useConfirm-CQjBnYuP.js +0 -1
- package/web/dist/assets/websocket-CeKJTCdp.js +0 -1
- package/web/dist/assets/whatsNewStore-C0hbStfc.js +0 -1
- package/web/dist/assets/workspaceSemantics-CW8ytHq2.js +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,
|
|
2
|
-
`):e.thinking??``,i=He(e,n),a=e.summary?.durationMs;return{index:t,kind:`message`,text:``,...e.content===``?{}:{previewMarkdown:e.content},sourceSeq:t,inputDetail:e.content,...r===``?{}:{thinkingDetail:r},...i===void 0?{}:{assistantMetrics:i},timeSeconds:a===void 0?null:a/1e3,startedAt:e.timestamp}}function We(e,t){let n=ze(e.args),r=Be(e.result),i=Ve(e);return{index:t,kind:`tool`,text:e.name,...n===``?{}:{previewMarkdown:n},sourceSeq:t,callId:e.id,...n===``?{}:{inputDetail:n},...r===``?{}:{outputDetail:r},...i,isError:e.status===`error`,timeSeconds:e.duration===void 0?null:e.duration/1e3,startedAt:e.timestamp}}function Ge(e,t){return{index:t,kind:`user`,text:``,...e.content===``?{}:{previewMarkdown:e.content},sourceSeq:t,inputDetail:e.content,opensTurn:!0,timeSeconds:0,startedAt:e.timestamp}}function Ke(e,t){let n=[e.originalCount===void 0?``:`original ${e.originalCount} msgs`,e.compressedCount===void 0?``:`compressed ${e.compressedCount} msgs`,e.tokensSaved===void 0?``:`freed ${e.tokensSaved} tokens`].filter(Boolean).join(`, `);return{index:t,kind:`compacted`,text:`Context compressed`,sourceSeq:e.seq,...n===``?{}:{outputDetail:n},timeSeconds:0,startedAt:e.timestamp}}function qe(e){let t=[],n=[];for(let t of e)t.absTime!==null&&Number.isFinite(t.absTime)&&(n.push(t.absTime),t.cell.kind===`tool`&&t.cell.timeSeconds!==null&&Number.isFinite(t.cell.timeSeconds)&&n.push(t.absTime+t.cell.timeSeconds*1e3));if(n.length>=2){let e=Le((Math.max(...n)-Math.min(...n))/1e3);e!==void 0&&t.push(e)}else if(n.length===1){let r=e.find(e=>e.absTime===n[0])?.cell.timeSeconds,i=r==null?void 0:Le(r);i!==void 0&&t.push(i)}let r=new Map;for(let t of e)t.toolName!==void 0&&t.cell.kind===`tool`&&r.set(t.toolName,(r.get(t.toolName)??0)+1);for(let[e,n]of r)t.push(n>1?`${e}×${n}`:e);return t.length===0?void 0:t.join(` `)}function Je(e,t){return{turn:e,groups:t.groups.map(({title:e,laid:t})=>{let n=qe(t);return{title:e,...n===void 0?{}:{description:n},cells:t.map(e=>e.cell)}})}}function Ye(e){return Math.min(...e.groups.flatMap(e=>e.cells.map(e=>e.index)),1/0)}function Xe(e){let{messages:t,compacted:n=[],ttft:r}=e,i=new Map,a=[],o=0,s=0,c=null,l=e=>{let t=i.get(e);return t===void 0&&(t={groups:[]},i.set(e,t)),t},u=(e,t)=>{let n=l(e).groups,r=n[n.length-1];r?.title===`Message`?r.laid.push(t):n.push({title:`Message`,laid:[t]})},d=(e,t,n)=>{if(n.length===0)return;let r=l(e).groups,i=`Step ${t}`,a=r.find(e=>e.title===i);a===void 0?r.push({title:i,laid:[...n]}):a.laid.push(...n)},f=[...t.map(e=>({kind:`message`,message:e})),...n.map(e=>({kind:`compacted`,record:e}))].sort((e,t)=>(e.kind===`message`?e.message.timestamp:e.record.timestamp)-(t.kind===`message`?t.message.timestamp:t.record.timestamp));for(let e of f){if(e.kind===`compacted`){let t=Ke(e.record,++o);a.push({groups:[{title:`Compaction ${e.record.seq}`,laid:[{absTime:Re(e.record.timestamp),cell:t}]}]});continue}let t=e.message;if(z(t)){s+=1;let e=Ge(t,++o);u(s,{absTime:Re(t.timestamp),cell:e});continue}let n=s>0?s:c??1,i=
|
|
3
|
-
`).toLocaleLowerCase()};this.entries.set(i,s),t.add(i)}for(let e of this.entries.keys())t.has(e)||this.entries.delete(e);return!0}search(e){let t=e.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);if(t.length===0)return null;let n=new Set;for(let[e,r]of this.entries)t.every(e=>r.text.includes(e))&&n.add(e);return n}},Q=
|
|
4
|
-
`)}function bt(e,t){return e<=t?{start:e,end:t}:{start:t,end:e}}function xt(e){return Math.min(1,Math.max(0,e))}var St=(0,Z.memo)(function({turns:e,mode:t,range:n,selectedIndex:r=null,searchMatchIndexes:i=null,onRangeChange:a,onRecordSelect:o}){let s=(0,Z.useMemo)(()=>nt(e,t),[t,e]),c=(0,Z.useMemo)(()=>new Map(e.flatMap(e=>e.groups.flatMap(e=>e.cells.map(e=>[e.index,gt(e)])))),[e]),l=(0,Z.useMemo)(()=>new Map(e.flatMap(e=>e.groups.flatMap(e=>e.cells.map(e=>[e.index,Ze(e)])))),[e]),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),[v,y]=(0,Z.useState)(1),b=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{s!==null&&n!==null&&(n.end<s.start||n.start>s.end)&&a(null)},[s,a,n]),(0,Z.useLayoutEffect)(()=>{let e=b.current,t=_.current;b.current=null,e!==null&&t!==null&&(t.scrollLeft=e.fraction*t.scrollWidth-e.contentOffsetPx)},[v]);let x=(0,Z.useRef)(()=>{});if((0,Z.useEffect)(()=>{let e=u.current;if(!e)return;let t=e=>{e.preventDefault(),x.current(e)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[s]),s===null)return(0,Q.jsxs)(`div`,{className:`traj-root`,"data-empty":``,children:[(0,Q.jsxs)(`div`,{className:`traj-labels`,"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{children:`Input`}),(0,Q.jsx)(`span`,{children:`Model`}),(0,Q.jsx)(`span`,{children:`Tools`})]}),(0,Q.jsx)(`div`,{className:`traj-track`})]});let S=Math.max(1,s.end-s.start),C=Math.max(1,s.spans.length)*pt*v,w=e=>{let t=u.current;if(!t)return 0;let n=t.getBoundingClientRect();return xt((e-n.left)/Math.max(1,n.width))},T=e=>s.start+e*S,E=e=>{if(e.button===2){a(null);return}let t=e.target.closest(`[data-timeline-record-index]`),n=t===null?null:Number(t.dataset.timelineRecordIndex);n!==null&&Number.isFinite(n)?o?.(n):(d.current={pointerId:e.pointerId,anchorFraction:w(e.clientX),anchorClientX:e.clientX,recordIndex:null},e.currentTarget.setPointerCapture(e.pointerId))},D=e=>{let t=d.current;if(t!==null&&e.pointerId===t.pointerId){let n=w(e.clientX);if(Math.abs(e.clientX-t.anchorClientX)>=dt){let e=T(t.anchorFraction),r=T(n);p(bt(e,r))}return}let n=w(e.clientX),r=e.target.closest(`[data-timeline-record-index]`),i=r===null?null:Number(r.dataset.timelineRecordIndex);g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{h({fraction:n,recordIndex:Number.isFinite(i)?i:null})},ft)},O=e=>{let t=d.current;t!==null&&e.pointerId===t.pointerId&&(d.current=null,f!==null&&(a(f),p(null)))},k=e=>{d.current?.pointerId===e.pointerId&&(d.current=null,p(null))};x.current=e=>{if(s===null)return;let t=_.current;if(t===null)return;if(e.ctrlKey||e.metaKey||e.altKey){let n=Math.min(mt,Math.max(1,v*(e.deltaY<0?1.25:.8)));if(n===v)return;let r=u.current;if(r!==null){let n=r.getBoundingClientRect();b.current={fraction:xt((e.clientX-n.left)/Math.max(1,n.width)),contentOffsetPx:e.clientX-t.getBoundingClientRect().left}}y(n);return}let n=e.deltaX===0?e.deltaY:e.deltaX;n!==0&&(t.scrollLeft+=n)};let A=f??n,j=m?.recordIndex;return(0,Q.jsxs)(`div`,{ref:_,className:`traj-root`,children:[(0,Q.jsxs)(`div`,{className:`traj-labels`,"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{children:`Input`}),(0,Q.jsx)(`span`,{children:`Model`}),(0,Q.jsx)(`span`,{children:`Tools`})]}),(0,Q.jsxs)(`div`,{ref:u,className:`traj-track`,style:{width:`max(100%, ${C}px)`},role:`slider`,"aria-label":`Trajectory timeline`,tabIndex:0,onKeyDown:e=>{e.key===`Escape`&&a(null)},onPointerDown:E,onPointerMove:D,onPointerUp:O,onPointerCancel:k,onPointerLeave:()=>{g.current&&clearTimeout(g.current),g.current=null,d.current===null&&h(null)},onDoubleClick:e=>{e.preventDefault(),a(null)},onContextMenu:e=>{e.preventDefault(),a(null)},children:[m!==null&&m.recordIndex===null&&f===null&&(0,Q.jsx)(`div`,{className:`traj-hoverLine`,"aria-hidden":`true`,style:{"--trajectory-hover-left":`${m.fraction*100}%`}}),A!==null&&(0,Q.jsx)(`div`,{className:`traj-selection`,"data-dragging":f===null?void 0:`true`,"aria-hidden":`true`,style:{"--trajectory-selection-left":`${(A.start-s.start)/S*100}%`,"--trajectory-selection-width":`${(A.end-A.start)/S*100}%`}}),(0,Q.jsx)(`div`,{className:`traj-turnBoundaries`,"aria-hidden":`true`,children:s.turnBoundaries.filter(e=>e.time>s.start).map(e=>(0,Q.jsx)(`span`,{className:`traj-turnBoundary`,"data-turn":e.turn,style:{"--trajectory-turn-left":`${(e.time-s.start)/S*100}%`}},e.turn))}),(0,Q.jsx)(`div`,{className:`traj-lanes`,"data-timeline-domain":``,children:s.spans.map(e=>{let t=(e.start-s.start)/S,n=(e.end-e.start)/S*100,a=c.get(e.index),o=a?.ttftMs,u=a?.decodingMs,d=o===void 0||u===void 0||o+u<=0?null:o/(o+u),f=l.get(e.index)??e.label;return(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`traj-span`,"data-timeline-span":e.kind,"data-timeline-record-index":e.index,"data-assistant-timing":d===null?void 0:`true`,"data-error":e.isError||void 0,"data-current":e.index===r||void 0,"data-hovered":j===e.index||void 0,"data-search-match":i===null?void 0:i.has(e.index)?`true`:`false`,"data-selected":A===null?void 0:e.start<=A.end&&e.end>=A.start?`true`:`false`,title:yt(e.kind,a),style:{"--trajectory-span-left":`${t*100}%`,"--trajectory-span-width":`${n}%`,"--trajectory-span-lane":e.lane,...d===null?{}:{"--trajectory-assistant-ttft":`${d*100}%`}},children:(0,Q.jsx)(`span`,{className:`traj-spanLabel`,children:f})},e.index)})})]})]})}),Ct=I();function wt(e){return typeof e==`object`?e.key:e}function Tt(e,t){let n=e.length;return new Proxy(e,{get(e,r,i){if(typeof r==`string`){let i=r.charCodeAt(0);if(i>=48&&i<=57){let i=+r;if(Number.isInteger(i)&&i>=0&&i<n){let n=e[i];if(typeof n!=`object`){let r=t[i*2];n=e[i]={index:i,key:n,start:r,size:t[i*2+1],end:r+t[i*2+1],lane:0}}return n}}if(r===`length`)return n}return Reflect.get(e,r,i)}})}function Et(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return(o.length!==r.length||o.some((e,t)=>r[t]!==e))&&(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1),i}return o.updateDeps=e=>{r=e},o}function Dt(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Ot=(e,t)=>Math.abs(e-t)<1.01,kt=(e,t,n)=>{let r;return Object.assign(function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)},{cancel:()=>{e.clearTimeout(r)}})};function At({offset:e,isScrolling:t,elementMax:n,holdOffset:r,scrollOffset:i,pendingWrite:a,clampedMaxAtWrite:o}){return t&&a===null&&e===i?`spurious`:a!==null&&Math.abs(e-a.target)<1.5?`readBack`:a!==null&&!a.smooth&&n!==null&&a.target>n+r+.5&&Math.abs(e-(n+r))<1.5||a!==null&&!a.smooth&&a.lowMaxes?.some(t=>Math.abs(e-t)<1.5)?`clampedReadBack`:o!==null&&Math.abs(e-o)<1.5?`clampedEcho`:`external`}var jt=e=>e===`smooth`||e===`smoothFinishing`;function Mt({kind:e,offset:t,command:n,target:r}){return e!==`spurious`&&e!==`readBack`&&e!==`clampedReadBack`&&n?.index!=null&&n.phase!==`queued`&&!jt(n.phase)&&!Ot(t,n.lastTargetOffset)&&!Ot(t,r())&&e!==`clampedEcho`}var Nt=40;function Pt(e){let t=e[e.length-1];if(t===void 0)return!1;let n=e.length-2;for(;n>=0&&t.t-e[n].t<Nt;)n--;if(n<0)return!1;let r=e[n],i=n-1;for(;i>=0&&r.t-e[i].t<Nt;)i--;if(i<0)return!1;let a=e[i],o=(t.offset-r.offset)/(t.t-r.t),s=(r.offset-a.offset)/(r.t-a.t);return o*s>=0&&Math.abs(o)>=2*Math.abs(s)&&Math.abs(o)-Math.abs(s)>=.8}function Ft(e){let t=e[e.length-1];if(t===void 0)return!1;let n=e.length-2;for(;n>=0&&t.t-e[n].t<Nt;)n--;if(n<0)return!1;let r=e[n];return Math.abs(t.offset-r.offset)/(t.t-r.t)>=.05}var It,Lt=()=>{if(It!==void 0)return It;if(typeof navigator>`u`)return It=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return It=!0;let e=navigator.maxTouchPoints;return It=navigator.platform===`MacIntel`&&e!==void 0&&e>0},Rt,zt=()=>Rt===void 0?Rt=Lt()&&typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`overflow-anchor: auto`):Rt,Bt={capture:!0,passive:!0},Vt=class{constructor(e){this.host=e,this._touch=null,this.inMotion=()=>this._touch!==null&&this._touch.phase!==`lateFling`,this.dragging=()=>this._touch?.phase===`down`&&this._touch.moved,this.tail=()=>this._touch?.phase===`tail`?this._touch.moved?`fling`:`tap`:null,this.onScroll=({isScrolling:e,ownReadBack:t,moved:n,external:r})=>(e&&this._touch?.phase===`tail`?this._openTail(this._touch.moved||!t,!1):this._touch?.phase===`lateFling`&&(this.host.now()>this._touch.until?this._touch=null:r&&e&&n&&this._openTail(!0,!1)),!t&&e&&n&&this._touch?.phase===`down`?(this._touch.moved=!0,!0):!1),this.touchStart=()=>{this.end(),this._touch={phase:`down`,moved:!1}},this.touchEnd=()=>{let e=this._touch?.phase===`down`&&this._touch.moved;this.end(),this._openTail(e,e)},this.end=()=>{let e=this.host.getWindow();this._touch?.phase===`tail`&&e!=null&&e.clearTimeout(this._touch.timerId),this._touch=null},this.listen=e=>{let t=()=>this.touchStart(),n=()=>this.touchEnd();return e.addEventListener(`touchstart`,t,Bt),e.addEventListener(`touchend`,n,Bt),e.addEventListener(`touchcancel`,n,Bt),()=>{e.removeEventListener(`touchstart`,t,Bt),e.removeEventListener(`touchend`,n,Bt),e.removeEventListener(`touchcancel`,n,Bt),this.end()}},this._openTail=(e,t)=>{let n=this.host.getWindow();if(!Lt()||n==null)return;this.end();let r={phase:`tail`,moved:e,awaitingFling:t,timerId:n.setTimeout(()=>{this.host.tailStillMoving()?this._openTail(r.moved,r.awaitingFling):(this._touch=r.awaitingFling?{phase:`lateFling`,until:this.host.now()+1e3}:null,this.host.onTailClosed())},150)};this._touch=r}}get touch(){return this._touch}},Ht=e=>{let{clientWidth:t,clientHeight:n}=e;return{width:t,height:n}},Ut=e=>{let t=new Set;return{schedule:n=>{let r=e.requestAnimationFrame(()=>{t.delete(r),n()});t.add(r)},cancel:()=>{t.forEach(t=>e.cancelAnimationFrame(t)),t.clear()}}},Wt=e=>e,Gt=e=>{let t=e.overscan*Math.max(e.lanes??1,1),n=Math.max(e.startIndex-t,0),r=Math.min(e.endIndex+t,e.count-1)-n+1,i=Array(r);for(let e=0;e<r;e++)i[e]=n+e;return i},Kt=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(Ht(n)),!r.ResizeObserver)return()=>{};let a=Ut(r),o=new r.ResizeObserver(()=>{let t=()=>{i(Ht(n))};e.options.useAnimationFrameWithResizeObserver?a.schedule(t):t()});return o.observe(n,{box:`content-box`}),()=>{o.unobserve(n),a.cancel()}},qt={passive:!0},Jt=typeof window>`u`||`onscrollend`in window,Yt=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Jt,o=0,s=a?null:kt(i,()=>t(n(r),!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,qt),a&&r.addEventListener(`scrollend`,u,qt),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},Xt=(e,t)=>Yt(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),Zt=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},Qt=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},$t=(e,t)=>e===`smooth`?t?`smoothLanded`:`smooth`:`instant`,en=e=>e?.phase===`smooth`||e?.phase===`smoothLanded`;function tn(e,t,n,r){if(t===0)return!1;let i=r(0),a=new Set,o=0;for(;o<e;){let e=n(o);if(e===i)break;a.add(e),o++}let s=e-o;if(s===0||s>=t)return!1;for(let e=0;e<s;e++)if(r(e)!==n(o+e))return!1;for(let e=s;e<t;e++)if(a.has(r(e)))return!1;return!0}var nn=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._iosGesture=new Vt({getWindow:()=>this.targetWindow,now:()=>this.now(),tailStillMoving:()=>{let e=this.scrollState;if(e?.phase!==`queued`||this.pendingWrite!==null)return!1;let t=this._readElementOffset();return t===null||this._lastElementOffset===null||Math.abs(t-this._lastElementOffset)<1?!1:(this._lastElementOffset=t,e.samples=[...e.samples??[],{t:this.now(),offset:t}],!0)},onTailClosed:()=>{let e=this.scrollState;e?.phase===`queued`&&Ft(e.samples??[])&&(this.scrollState=null),this._flushHoldIfReady(!0),this._writeAwaitingCommand()}}),this._lastElementOffset=null,this.pendingWrite=null,this._clampedAdjustment=null,this.elementsCache=new Map,this._resizeBatch=null,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=null,n=()=>{if(e)return e;let n=this.targetWindow;if(!n||!n.ResizeObserver)return null;let i=t=Ut(n);return e=new n.ResizeObserver(e=>{let t=()=>{let t={sync:!1};this._resizeBatch=t;try{e.forEach(r)}finally{this._resizeBatch=null,t.notify&&(this.notify(t.sync),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment())}};this.options.useAnimationFrameWithResizeObserver?i.schedule(t):t()})},r=e=>{let t=e.target,n=this.indexFromElement(t);if(t.isConnected)this.isIndexInRange(n)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this));else{this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}}};return{disconnect:()=>{var r;(r=n())==null||r.disconnect(),t?.cancel(),e=null,t=null},observe:e=>n()?.observe(e,{box:`border-box`}),unobserve:e=>n()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Wt,rangeExtractor:Gt,onChange:()=>{},measureElement:Zt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=this._singleLaneMeasurements?.items??s,l=e=>wt(c[e]),u=e>0?l(0):null,d=e>0?l(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==u||t.getItemKey(o-1)!==d)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>0&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==d)&&(o>e||tn(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=null;if(r&&this.scrollOffset!==null&&!this._awaitingCommandReadBack()){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:s}=this.options,c=0;for(;c<a&&s(c)!==e;)c++;if(c<a){let e=n[c];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(o=n-this.scrollOffset,this.scrollOffset=n)}}}i?this.pendingScrollAnchor={kind:`follow`,behavior:i}:o!==null&&(this._canWriteScroll()?this.pendingScrollAnchor={kind:`anchor`,delta:o}:(this._holdOffset+=o,this._followOffsetTarget(o)))},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=Et(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{var e;this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,(e=this._momentumStop)==null||e.restore(),this._momentumStop=null,this.isScrolling=!1,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._clampedAdjustment=null,this.pendingWrite=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}this.scrollElement=e,this.targetWindow=this.scrollElement&&`ownerDocument`in this.scrollElement?this.scrollElement.ownerDocument.defaultView:this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{let n=t?this._elementMaxScrollOffset():null,r=this._reportedOverscroll;this._reportedOverscroll=e<0||n!==null&&e>n+1;let i=e;this._lastElementOffset=i,e=this._toLayoutOffset(e);let a=this._classifyScrollEvent(e,t,n);if(a===`spurious`)return;a===`readBack`?e=this.pendingWrite.target:a===`clampedReadBack`&&this.scrollState?.index!=null&&e<this.getMaxScrollOffset()-1.5?this.scrollState.lastTargetOffset=e:Mt({kind:a,offset:e,command:this.scrollState,target:()=>this.getScrollStateTarget(this.scrollState)})&&(this.scrollState=null),this.pendingWrite=null,this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null);let o=this.getScrollOffset(),s=this.scrollDirection;this.scrollDirection=t?o===e?this.scrollDirection:o<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t;let c=this.scrollState;if(c?.phase===`queued`&&a===`external`&&t){if(r||this._reportedOverscroll)c.samples=[];else{let e=this.now();c.samples=[...(c.samples??[]).filter(t=>e-t.t<=200),{t:e,offset:i}],(s!==null&&this.scrollDirection!==s||Pt(c.samples))&&(this.scrollState=null)}}this._iosGesture.onScroll({isScrolling:t,ownReadBack:a===`readBack`,moved:e!==o,external:a===`external`&&this.scrollState?.phase!==`smooth`&&this.scrollState?.phase!==`smoothFinishing`})&&this.scrollState?.phase===`queued`&&(this.scrollState=null),this._flushHoldIfReady(!0),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement&&this.unsubs.push(this._iosGesture.listen(this.scrollElement)),this._scrollToOffset(this.getScrollOffset())}this._noteClampMax();let t=this.pendingScrollAnchor;this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled&&(t.kind===`anchor`?this._canWriteScroll()?en(this.scrollState)&&!Ot(this.getScrollOffset()-t.delta,this.scrollState.lastTargetOffset)||(this._followOffsetTarget(t.delta),this._scrollToOffset(this.getScrollOffset())):(this._holdOffset+=t.delta,this._followOffsetTarget(t.delta),this.notify(!1)):this.scrollToEnd({behavior:t.behavior})),this._flushHoldIfReady(!1),this._retryClampedAdjustment()},this._classifyScrollEvent=(e,t,n)=>At({offset:e,isScrolling:t,elementMax:n,holdOffset:this._holdOffset,scrollOffset:this.scrollOffset,pendingWrite:this.pendingWrite,clampedMaxAtWrite:this._clampedAdjustment?.maxAtWrite??null}),this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:e,maxAtWrite:t}=this._clampedAdjustment,n=this.getMaxScrollOffset();n>t+.5&&(this._clampedAdjustment=e>n+.5?{target:e,maxAtWrite:n}:null,this._scrollToOffset(e))},this._writeAwaitingCommand=()=>{let e=this.scrollState;if(e===null||e.phase!==`queued`)return;let{behavior:t}=e;this.getMeasurements();let n=this.getScrollStateTarget(e);e.lastTargetOffset=n,this._clampedAdjustment=null,e.phase=$t(t,e.index!=null&&Ot(n,this.getScrollOffset())),this._scrollToOffset(n,{behavior:t}),this.scheduleScrollReconcile()},this._readElementOffset=()=>{let e=this.scrollElement;if(e==null)return null;let{horizontal:t,isRtl:n}=this.options;return typeof e.scrollTop==`number`?t?e.scrollLeft*(n&&-1||1):e.scrollTop:typeof e.scrollY==`number`?t?e.scrollX:e.scrollY:null},this._canWriteScroll=()=>!(Lt()&&this._iosGesture.inMotion())&&!this._reportedOverscroll,this._flushHoldIfReady=e=>{if(this._holdOffset===0||!this.scrollElement||!this.options.enabled||!this._canWriteScroll()||this.scrollState?.phase===`smooth`)return;this._holdOffset=0,this.scrollOffset!==null&&this.scrollOffset<0&&(this.scrollOffset=0),this.notify(e);let t=this.getCommandWrittenOffset()??this.getScrollOffset();this._clampedAdjustment=this._clampedBy(t),this._scrollToOffset(t)},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Et(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,t,n,r,i,a,o,s)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=Et(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s},c)=>{let l=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=e*2,a=this._singleLaneMeasurements?.flat;if(!a||a.length<i){let e=new Float64Array(i);a&&u>0&&e.set(a.subarray(0,u*2)),a=e}let o=u===0?Array(e):this._singleLaneMeasurements.items.slice(),c;if(u===0)c=t+n;else{let e=u-1;c=a[e*2]+a[e*2+1]+s}for(let t=u;t<e;t++){let e=r(t);o[t]=e;let n=l.get(e),i=typeof n==`number`?n:this.options.estimateSize(t);a[t*2]=c,a[t*2+1]=i,c+=i+s}this._singleLaneMeasurements={flat:a,items:o};let d=Tt(o,a);return this.measurementsCache=d,d}let d=this.measurementsCache.slice(0,u),f=Array(a).fill(void 0),p=new Float64Array(a),m=0;for(let e=0;e<u;e++){let t=d[e];t&&(f[t.lane]===void 0&&m++,f[t.lane]=e,p[t.lane]=t.end)}for(let i=u;i<e;i++){let e=r(i),c=this.laneAssignments.get(i),u,h,g=o===`estimate`||l.has(e);if(c!==void 0&&this.options.lanes>1){u=c;let e=f[u],r=e===void 0?void 0:d[e];h=r?r.end+s:t+n}else if(m===a){let e=0,t=p[0],n=f[0];for(let r=1;r<a;r++){let i=p[r];(i<t||i===t&&f[r]<n)&&(e=r,t=i,n=f[r])}u=e,h=t+s,g&&this.laneAssignments.set(i,u)}else u=i%this.options.lanes,h=t+n,g&&this.laneAssignments.set(i,u);let _=l.get(e),v=typeof _==`number`?_:this.options.estimateSize(i),y=h+v;d[i]={index:i,start:h,size:v,end:y,key:e,lane:u},f[u]===void 0&&m++,f[u]=i,p[u]=y}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Et(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=on(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Et(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t,this.options.lanes]},(e,t,n,r,i,a)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n,lanes:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!en(this.scrollState))return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e);if(!this.isIndexInRange(t))return;let n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),e.isConnected&&(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{var n;if(!this.isIndexInRange(e))return;this._resizeBatch?.sync&&this.getMeasurements();let r,i,a,o=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&o!=null)a=this.options.getItemKey(e),i=o[e*2],r=o[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;a=t.key,i=t.start,r=t.size}let s=this.itemSizeCache.get(a)??r,c=t-s;if(c!==0){let o=this.options.anchorTo===`end`&&!en(this.scrollState)&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,l=o?this._getLayoutTotalSize():0,u=this.getScrollOffset(),d=this.itemSizeCache.has(a)?i+s<=u&&this.scrollDirection!==`backward`:i<u,f=!en(this.scrollState)&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?d:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:a,start:i,size:r,end:i+r,lane:0},c,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(a,t),this.itemSizeCacheVersion++;let p=!1;if(this._awaitingCommandReadBack()||(o?p=this.applyScrollAdjustment(this._getLayoutTotalSize()-l):f&&(p=this.applyScrollAdjustment(c))),this._resizeBatch){this._resizeBatch.notify=!0,(n=this._resizeBatch).sync||(n.sync=p);return}this.notify(p),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment()}},this.getVirtualItems=Et(()=>[this.getVirtualIndexes(),this.getMeasurements(),this._holdOffset],(e,t,n)=>{let r=[];for(let i=0,a=e.length;i<a;i++){let a=t[e[i]];r.push(n===0?a:{...a,start:a.start-n,end:a.end-n})}return r},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._singleLaneMeasurements?.flat,r=this.options.lanes===1&&n!=null;return Dt(t[rn(0,t.length-1,r?e=>n[e*2]:e=>Dt(t[e]).start,e)])},this._noteClampMax=()=>{if(!this._awaitingCommandReadBack())return;let e=this._elementMaxScrollOffset();if(e===null)return;let t=this.pendingWrite,n=Math.max(e,0)+this._holdOffset;if(n>=t.target)return;let r=t.lowMaxes??=[];r[r.length-1]!==n&&r.push(n)},this.getMaxScrollOffset=()=>(this._elementMaxScrollOffset()??0)+this._holdOffset,this._toLayoutOffset=e=>{let t=e+this._holdOffset;return this.pendingScrollAnchor?.kind===`anchor`&&(t+=this.pendingScrollAnchor.delta),t},this._elementMaxScrollOffset=()=>{let e=this.scrollElement;if(e===null)return null;if(`scrollHeight`in e)return this.options.horizontal?e.scrollWidth-e.clientWidth:e.scrollHeight-e.clientHeight;if(`document`in e){let t=e.document.documentElement;return this.options.horizontal?t.scrollWidth-e.innerWidth:t.scrollHeight-e.innerHeight}return null},this._momentumStop=null,this._stopMomentum=e=>{let t=this.scrollElement,n=this.targetWindow;if(t===null||n===null)return;let r=`document`in t?t.document.scrollingElement:t;if(!r?.style)return;if(this._momentumStop){this._momentumStop.done=e;return}let{style:i}=r,a=this.options.horizontal?`overflow-x`:`overflow-y`,o=i.getPropertyValue(a),s=i.getPropertyPriority(a);i.setProperty(a,`hidden`,`important`);let c={restore:()=>i.getPropertyValue(a)!==`hidden`||i.getPropertyPriority(a)!==`important`?!1:(i.setProperty(a,o,s),!0),done:e};this._momentumStop=c,n.requestAnimationFrame(()=>n.requestAnimationFrame(()=>{this._momentumStop===c&&(this._momentumStop=null,c.restore()&&c.done())}))},this._clampedBy=e=>{let t=this._elementMaxScrollOffset();if(t===null)return null;let n=t+this._holdOffset;return e>n+.5?{target:e,maxAtWrite:n}:null},this.getVirtualDistanceFromEnd=()=>Math.max(this._getLayoutTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`){if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t]}if(t===`end`&&e===this.options.count-1){let e=this.getMaxScrollOffset(),n=e-this.options.paddingEnd+this.options.scrollPaddingEnd;return[Math.max(Math.min(n,e),0),t]}let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{this._startScroll({index:null,align:t},this.getOffsetForAlignment(e,t),n,`absolute`)},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r;this._startScroll({index:e,align:a},i,n,`absolute`)},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getOffsetForAlignment((this.getCommandWrittenOffset()??this.getScrollOffset())+e,`start`);this._startScroll({index:null,align:`start`},n,t,`relative`)},this.scrollToEnd=({behavior:e=`auto`}={})=>{this.options.count>0?this._startScroll({index:this.options.count-1,align:`end`,toEnd:!0},Math.max(this.getMaxScrollOffset(),0),e,`absolute`):this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.cancelScroll=()=>{this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null},this.getTotalSize=()=>Math.max(this._getLayoutTotalSize()-this._holdOffset,0),this._getLayoutTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._singleLaneMeasurements?.flat;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n}={})=>{let r={target:e+(t??0),smooth:n===`smooth`};return this.pendingWrite=r,this.options.scrollToFn(e-this._holdOffset,{behavior:n,adjustments:t},this),r},this.getCommandWrittenOffset=()=>this.scrollState!==null&&this.pendingWrite!==null&&!this.pendingWrite.smooth?this.pendingWrite.target:null,this._awaitingCommandReadBack=()=>{let e=this.getCommandWrittenOffset();return!(Lt()&&this._iosGesture.dragging())&&e!==null&&!Ot(e,this.getScrollOffset())},this._followOffsetTarget=e=>{this.scrollState!==null&&this.scrollState.index==null&&(this.scrollState.lastTargetOffset+=e)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}get scrollAdjustments(){return 0}applyScrollAdjustment(e,t){if(e===0)return!1;if(this._followOffsetTarget(e),this._canWriteScroll()){let n=this.getScrollOffset();this._clampedAdjustment=this._clampedBy(n+e);let r=this._scrollToOffset(n,{adjustments:e,behavior:t});return this.scrollOffset!==null&&(this.pendingWrite===r&&(this.scrollOffset+=e),this.scrollOffset<0&&(this.scrollOffset=0)),!0}return this._holdOffset+=e,this.scrollOffset!==null&&(this.scrollOffset+=e),!0}scheduleScrollReconcile(){this.targetWindow?this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}):this.scrollState=null}getScrollStateTarget(e){let t=e.toEnd?[Math.max(this.getMaxScrollOffset(),0)]:e.index==null?void 0:this.getOffsetForIndex(e.index,e.align);return t?t[0]:e.lastTargetOffset}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}if(this.scrollState.phase===`queued`){this.scheduleScrollReconcile();return}this.getMeasurements();let e=this.getScrollStateTarget(this.scrollState),t=this.scrollState.index==null?1:this.options.useAnimationFrameWithResizeObserver?3:2,n=e!==this.scrollState.lastTargetOffset;if(!n&&Ot(e,this.getScrollOffset())){if(this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothLanded`:this.scrollState.phase===`smoothFinishing`&&(this.scrollState.phase=`instant`),this.scrollState.stableFrames++,this.scrollState.stableFrames>=t){this.getScrollOffset()!==e&&this._scrollToOffset(e,{behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let t=this.getSize()||600,n=Math.abs(e-this.getScrollOffset()),r=en(this.scrollState)&&n>t;this.scrollState.lastTargetOffset=e,r?this.scrollState.phase=`smooth`:this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothFinishing`:this.scrollState.phase===`smoothLanded`&&(this.scrollState.phase=`instant`),this._scrollToOffset(e,{behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}_startScroll(e,t,n,r){let i=this._iosGesture.tail();if(r===`absolute`&&i!==null){if(i===`fling`&&zt()){this._stopMomentum(()=>{this.scrollState?.phase!==`queued`||this._iosGesture.tail()!==`fling`||this._reportedOverscroll||(this._iosGesture.end(),this._flushHoldIfReady(!0),this._writeAwaitingCommand())}),this.scrollState={...e,startedAt:this.now(),lastTargetOffset:t,stableFrames:0,phase:`queued`,behavior:n,samples:[]},this.scheduleScrollReconcile();return}this._iosGesture.end()}this.scrollState={...e,startedAt:this.now(),lastTargetOffset:t,stableFrames:0,behavior:n,phase:$t(n,e.index!=null&&Ot(t,this.getScrollOffset()))},this._scrollToOffset(t,{behavior:n}),this.scheduleScrollReconcile()}},rn=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function an(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function on(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=an(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=rn(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var sn=typeof document<`u`?Z.useLayoutEffect:Z.useEffect;function cn({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=Z.useReducer(e=>e+1,0)[1],a=Z.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=Z.useRef(!1),s=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}},c=(e,t,n)=>{let r=a.current,i=!!e.options.horizontal,o=t.start-e.options.scrollMargin;r.lastPositions.get(n)!==o&&(r.lastPositions.set(n,o),r.mode===`transform`?n.style.transform=i?`translate3d(${o}px, 0, 0)`:`translate3d(0, ${o}px, 0)`:n.style[i?`left`:`top`]=`${o}px`)},l=e=>{let t=a.current;if(t.enabled&&t.container){s(e);for(let t of e.getVirtualItems()){let n=e.elementsCache.get(t.key);n&&c(e,t,n)}}},u={...r,onChange:(t,n)=>{var s;let c=a.current,u=!0;if(c.enabled){l(t);let e=t.range,n=c.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,Ct.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[d]=Z.useState(()=>{let e=new nn(u),t=e.measureElement;return e.measureElement=n=>{o.current=!0;try{t(n)}finally{o.current=!1}let r=a.current;if(n!==null&&r.enabled&&r.container){let t=e.measurementsCache[e.indexFromElement(n)];t&&c(e,t,n)}},Object.assign(e,{containerRef:t=>{let n=a.current;n.container=t,n.lastSize=null,t!==null&&l(e)}})});return d.setOptions(u),sn(()=>d._didMount(),[]),sn(()=>(s(d),d._willUpdate())),sn(()=>{l(d)}),d}function ln(e){return cn({observeElementRect:Kt,observeElementOffset:Xt,scrollToFn:Qt,...e})}var un=30,dn=20,fn=26,pn=22,mn=9;function hn(e){let t=encodeURIComponent(je(e.cell));return e.collapsedSummaryKind===void 0?t:`${t}\u0000summary\u0000${e.collapsedSummaryKind}`}function gn(e){if(e.collapsedSummaryKind!==void 0)return dn;let t=un;return e.turnStart===!0&&e.turn!==null&&e.turn!==void 0&&(t+=fn),e.groupStart===!0&&(t+=pn),t}function _n(e){let t=[],n=[];for(let[r,i]of e.entries()){let e={logicalIndex:r,record:i};if(i.cell.requestOnly===!0){n.push(e);continue}let a=[...n,e];n=[],t.push({entries:a,height:a.reduce((e,t)=>e+gn(t.record),0),key:hn(i)})}return n.length>0&&t.push({entries:n,height:mn,key:n.map(e=>hn(e.record)).join(`|`)}),t}var vn=[`Input`,`Output`,`Think`,`Time`],yn=(0,Z.memo)(function({turn:e}){return(0,Q.jsxs)(`div`,{className:`sticky top-0 z-10 flex h-[26px] items-center border-b border-dark-border/40 bg-dark-surface/95 px-2 backdrop-blur`,children:[(0,Q.jsxs)(`span`,{className:`text-meta font-semibold text-dark-text`,children:[`Turn `,e]}),(0,Q.jsx)(`div`,{className:`ms-auto flex items-center gap-3 pe-1 text-badge text-dark-muted/50`,"aria-hidden":`true`,children:vn.map(e=>(0,Q.jsx)(`span`,{className:`w-12 text-end`,children:e},e))})]})}),bn=(0,Z.memo)(function({title:e,description:t}){return(0,Q.jsxs)(`div`,{className:`flex h-[22px] items-center gap-2 px-2 text-meta`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-dark-muted`,children:e}),t!==void 0&&t!==``&&(0,Q.jsx)(`span`,{className:`truncate text-dark-muted/50`,children:t})]})}),xn={system:`System`,user:`User`,context:`Context`,compacted:`Compacted`,message:`Message`,tool:`Tool`,subtool:`Sub`},Sn={system:`bg-dark-surface text-dark-muted border-dark-border/40`,user:`bg-accent-blue/10 text-accent-blue border-accent-blue/30`,context:`bg-dark-surface text-dark-muted border-dark-border/40`,compacted:`bg-accent-yellow/15 text-accent-yellow border-accent-yellow`,message:`bg-accent-green/10 text-accent-green border-accent-green/30`,tool:`bg-accent-purple/10 text-accent-purple border-accent-purple/30`,subtool:`bg-dark-surface text-dark-muted border-dark-border/40`},Cn=(0,Z.memo)(function({cell:e,selected:t=!1,onClick:n}){let{index:r,kind:i,timeSeconds:a,input:o,output:s,think:c}=e,l=Ze(e),u=i===`message`;return(0,Q.jsxs)(`div`,{className:[`flex h-[30px] items-center gap-2 border-b border-dark-border/20 px-2 text-xs cursor-pointer select-none`,t?`bg-accent-blue/10`:`hover:bg-dark-surface/40`].join(` `),"data-kind":i,"data-selected":t||void 0,onClick:()=>n?.(r),children:[(0,Q.jsxs)(`span`,{className:`w-10 shrink-0 text-end tabular-nums text-dark-muted/50`,children:[`#`,r]}),(0,Q.jsx)(`span`,{className:`w-[74px] shrink-0`,children:(0,Q.jsx)(`span`,{className:[`inline-block rounded border px-1 py-px text-badge leading-none`,Sn[i]].join(` `),children:xn[i]})}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-dark-text`,title:l,children:l}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2 tabular-nums text-dark-muted/60`,children:[u&&(0,Q.jsxs)(Q.Fragment,{children:[o!==void 0&&(0,Q.jsx)(`span`,{title:`Input tokens`,children:o}),s!==void 0&&(0,Q.jsx)(`span`,{title:`Output tokens`,children:s}),c!==void 0&&(0,Q.jsx)(`span`,{title:`Reasoning tokens`,children:c})]}),(0,Q.jsx)(`span`,{className:`w-16 text-end`,children:Me(a)})]})]})}),wn=100,Tn=12,En=600,Dn=2;function On(e){let t=(0,Z.useRef)({rows:[],structure:[]});if(t.current.rows===e)return t.current.structure;let n=t.current.structure.length===e.length&&e.every((e,n)=>{let r=t.current.structure[n];return r?.key===e.key&&r.height===e.height})?t.current.structure:e.map(e=>({key:e.key,height:e.height}));return t.current={rows:e,structure:n},n}function kn(e){let t=[];for(let n of e){let e=[];for(let t of n.groups)t.cells.forEach((r,i)=>{e.push({turn:n.turn,group:t.title,groupDescription:t.description,groupStart:i===0,turnStart:e.length===0,cell:r,turnEnd:!1})});if(e.length>0){let t=e[e.length-1];t&&(t.turnEnd=!0)}t.push(...e)}return t}function An(e,t){let n=[],r=[],i=null,a=()=>{if(r.length!==0){if(i!==null&&t.has(i)){let e=r.filter(e=>e.cell.requestOnly!==!0&&e.cell.kind!==`system`),t=r[0];n.push({...t,groupStart:!0,turnStart:!0,turnEnd:!0,collapsedSummary:`Turn ${i} · ${e.length} records`,collapsedSummaryKind:`turn`,cell:{...t.cell,index:t.cell.index}})}else n.push(...r);r=[],i=null}};for(let t of e)t.turnStart&&a(),i=t.turn,r.push(t);return a(),n}function jn(e,t){let n=[],r=0;for(;r<e.length;){let i=e[r],a=e[r+1];if(i.cell.kind===`message`&&a!==void 0&&(a.cell.kind===`tool`||a.cell.kind===`subtool`)&&t.has(je(i.cell))){let t=r+1;for(;t<e.length&&(e[t].cell.kind===`tool`||e[t].cell.kind===`subtool`);)t+=1;let a=t-r-1;n.push({...i,groupStart:!0,turnEnd:e[t-1]?.turnEnd??i.turnEnd,collapsedSummary:`${Ze(i.cell)||`Message`} · ${a} tool call${a>1?`s`:``}`,collapsedSummaryKind:`assistant`}),r=t}else n.push(i),r+=1}return n}function Mn(e,t){let n=[],r=null,i=null;for(let a of e){if(a.turnStart&&(r=a),a.groupStart&&(i=a),!t.has(a.cell.index))continue;let e=a;r!==null&&n.length===0&&(r===a?e={...e,groupStart:!0,turnStart:!0}:n.push({...r,groupStart:!0,turnStart:!0}),r=null),i!==null&&n.length>0&&n[n.length-1].group!==a.group&&(i===a?e={...e,groupStart:!0}:n.push({...i,groupStart:!0,turnStart:!1}),i=null),n.push(e)}return n}function Nn(e){if(e===null||!Number.isFinite(e))return`Not available`;let t=new Date(e),n=e=>String(e).padStart(2,`0`),r=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}.${(e=>String(e).padStart(3,`0`))(t.getMilliseconds())}`;return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`} ${r}`}function Pn(e){let t=[{id:`overview`,label:`Summary`}];return e.inputDetail!==void 0&&e.inputDetail!==``&&t.push({id:`input`,label:`Input`}),e.outputDetail!==void 0&&e.outputDetail!==``&&t.push({id:`output`,label:`Output`}),e.thinkingDetail!==void 0&&e.thinkingDetail!==``&&t.push({id:`thinking`,label:`Thinking`}),e.assistantMetrics!==void 0&&t.push({id:`timing`,label:`Timing`}),(e.input!==void 0||e.output!==void 0||e.think!==void 0)&&t.push({id:`usage`,label:`Usage`}),t}function Fn({cell:e,onClose:t}){let n=Pn(e),[r,i]=(0,Z.useState)(n[0]?.id??`overview`),a=Ze(e);return(0,Q.jsxs)(`div`,{className:`flex h-full w-[360px] shrink-0 flex-col border-s border-dark-border/40 bg-dark-surface/40`,children:[(0,Q.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center justify-between border-b border-dark-border/40 px-3`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-dark-text`,children:[`Record #`,e.index]}),(0,Q.jsx)(`button`,{type:`button`,className:`rounded p-1 text-dark-muted hover:bg-dark-surface/60`,onClick:t,"aria-label":`Close details`,children:(0,Q.jsx)(C,{size:14})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1 border-b border-dark-border/40 px-2 py-1.5`,children:n.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`traj-detailTab`,"data-active":r===e.id||void 0,onClick:()=>i(e.id),children:e.label},e.id))}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(()=>{switch(r){case`overview`:return(0,Q.jsxs)(`dl`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Kind`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.kind})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Index`}),(0,Q.jsxs)(`dd`,{className:`traj-detailValue`,children:[`#`,e.index]})]}),e.callId!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Call ID`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue break-all`,children:e.callId})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Duration`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Me(e.timeSeconds)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Started`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Nn(e.startedAt??null)})]}),e.isError===!0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Status`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue text-accent-red`,children:`error`})]}),a!==``&&(0,Q.jsxs)(`div`,{className:`pt-1`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey mb-1`,children:`Summary`}),(0,Q.jsx)(`dd`,{className:`traj-detailBody`,children:a})]})]});case`input`:return(0,Q.jsx)(`div`,{className:`traj-detailBody`,children:e.inputDetail});case`output`:return(0,Q.jsx)(`div`,{className:`traj-detailBody`,children:e.outputDetail});case`thinking`:return(0,Q.jsx)(`div`,{className:`traj-detailBody`,children:e.thinkingDetail});case`timing`:{let t=e.assistantMetrics;if(!t)return null;let n=t.firstTokenTime!==null&&t.stepStartTime!==null?t.firstTokenTime-t.stepStartTime:null,r=t.completedTime!==null&&t.firstTokenTime!==null?t.completedTime-t.firstTokenTime:null;return(0,Q.jsxs)(`dl`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Step start`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Nn(t.stepStartTime)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`First token`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Nn(t.firstTokenTime)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`TTFT`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:n===null?`—`:`${n} ms`})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Decoding`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:r===null?`—`:`${r} ms`})]})]})}case`usage`:return(0,Q.jsxs)(`dl`,{className:`space-y-1.5`,children:[e.input!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Input`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.input})]}),e.output!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Output`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.output})]}),e.think!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Reasoning`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.think})]}),e.input===void 0&&e.output===void 0&&e.think===void 0&&(0,Q.jsx)(`div`,{className:`traj-detailValue`,children:`Token usage not reported by provider yet.`})]});default:return null}})()})]})}function In({turns:e,searchMatchIndexes:t=null,selectedIndex:n,onSelectIndex:r,onDeselect:i,onClearSelection:a,collapsedTurns:o,onToggleTurn:s,collapsedAssistants:c,onToggleAssistant:l}){let u=(0,Z.useRef)(null),d=(0,Z.useMemo)(()=>kn(e),[e]),f=(0,Z.useMemo)(()=>n===null?void 0:d.find(e=>e.cell.index===n),[d,n]),p=(0,Z.useMemo)(()=>{if(t!==null)return Mn(d,t);let e=o.size===0?d:An(d,o);return c.size===0?e:jn(e,c)},[d,c,o,t]),m=(0,Z.useMemo)(()=>_n(p),[p]),h=On(m),g=p.length>wn,_=(0,Z.useCallback)(e=>h[e]?.height??30,[h]),v=(0,Z.useCallback)(e=>h[e]?.key??e,[h]),y=(0,Z.useCallback)(()=>u.current,[]),b=ln({count:g?h.length:0,enabled:g,estimateSize:_,getItemKey:v,getScrollElement:y,initialRect:{width:0,height:En},overscan:Tn,scrollEndThreshold:Dn}),x=g?b.getVirtualItems():[],S=g?b.getTotalSize():0,C=(0,Z.useRef)(!1);(0,Z.useLayoutEffect)(()=>{if(C.current||t!==null)return;let e=u.current;e!==null&&p.length!==0&&(e.scrollHeight>e.clientHeight&&(e.scrollTop=e.scrollHeight),C.current=!0)},[p.length,t]),(0,Z.useLayoutEffect)(()=>{if(t===null)return;let e=u.current;e!==null&&p.length!==0&&(e.scrollTop=0,C.current=!0)},[t,p.length]);let w=e=>{r(e)},T=e=>e.collapsedSummary===void 0?(0,Q.jsxs)(Q.Fragment,{children:[e.turnStart&&e.turn!==null&&(0,Q.jsx)(yn,{turn:e.turn}),e.groupStart&&(0,Q.jsx)(bn,{title:e.group,description:e.groupDescription}),(0,Q.jsx)(Cn,{cell:e.cell,selected:n===e.cell.index,onClick:w})]}):(0,Q.jsxs)(`div`,{className:`flex h-[20px] cursor-pointer items-center gap-2 px-2 text-xs text-dark-muted hover:bg-dark-surface/40`,onClick:()=>{e.collapsedSummaryKind===`turn`&&e.turn!==null?s(e.turn):e.collapsedSummaryKind===`assistant`&&l(je(e.cell))},children:[(0,Q.jsx)(`span`,{className:`text-dark-muted/50`,children:`▸`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.collapsedSummary})]});return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsx)(`div`,{ref:u,className:`min-w-0 flex-1 overflow-auto`,onClick:e=>{e.target===e.currentTarget&&a?.()},children:g?(0,Q.jsx)(`div`,{style:{height:S,position:`relative`},children:x.map(e=>{let t=m[e.index];return t?(0,Q.jsx)(`div`,{"data-virtual-row-key":t.key,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`,height:t.height},children:t.entries.map(e=>(0,Q.jsx)(`div`,{children:T(e.record)},hn(e.record)))},t.key):null})}):p.map(e=>(0,Q.jsx)(`div`,{children:T(e)},hn(e)))}),f!==void 0&&(0,Q.jsx)(Fn,{cell:f.cell,onClose:i},f.cell.index)]})}function Ln(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}var Rn=(0,Z.memo)(function({errors:e,onOpenLogs:t}){let{t:n}=L(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(null),s=(0,Z.useMemo)(()=>e.filter(e=>e.level===`error`),[e]);if((0,Z.useEffect)(()=>{o(e=>e!==null&&s.length>e?null:e)},[s.length]),s.length===0||a!==null)return null;let u=s[s.length-1];if(u===void 0)return null;let d=s.slice(-20).reverse();return(0,Q.jsxs)(`div`,{"data-trajectory-error-banner":``,className:`mx-2 mt-1 shrink-0 rounded-md border border-accent-red/50 bg-accent-red/10 text-xs`,role:`alert`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 text-accent-red`,children:[(0,Q.jsx)(x,{size:14,className:`shrink-0`,"aria-hidden":`true`}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-start`,onClick:()=>i(e=>!e),title:n(r?`trajectory.errorBanner.collapse`:`trajectory.errorBanner.expand`),children:[(0,Q.jsxs)(`span`,{className:`shrink-0 font-semibold`,children:[n(`trajectory.errorBanner.title`),s.length>1&&(0,Q.jsxs)(`span`,{className:`ms-1.5 rounded bg-accent-red px-1.5 py-0.5 text-badge font-semibold text-accent-fg`,children:[`×`,s.length]})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-dark-text`,children:[Ln(u.timestamp),` · `,u.message]}),r?(0,Q.jsx)(l,{size:14,className:`shrink-0`,"aria-hidden":`true`}):(0,Q.jsx)(c,{size:14,className:`shrink-0`,"aria-hidden":`true`})]}),t&&(0,Q.jsxs)(`button`,{type:`button`,className:`flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-accent-red hover:bg-accent-red/15`,onClick:t,title:n(`trajectory.errorBanner.viewLogs`),children:[(0,Q.jsx)(_,{size:12,"aria-hidden":`true`}),n(`trajectory.errorBanner.viewLogs`)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-0.5 text-dark-muted hover:bg-accent-red/15 hover:text-accent-red`,onClick:()=>{o(s.length),i(!1)},title:n(`trajectory.errorBanner.dismiss`),children:(0,Q.jsx)(C,{size:14,"aria-hidden":`true`})})]}),r&&(0,Q.jsx)(`div`,{className:`max-h-40 overflow-y-auto border-t border-accent-red/30 px-2 py-1.5 font-mono text-meta custom-scrollbar`,children:d.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 py-0.5`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-dark-muted`,children:Ln(e.timestamp)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-accent-red px-1 py-0.5 text-avatar font-semibold uppercase leading-none text-accent-fg`,children:e.source}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-all text-dark-text`,children:e.message})]},e.id))})]})}),zn=new Set,Bn=new Set,Vn=[],Hn=3e3;function Un({sessionId:e,messages:t,errorLogs:n,onOpenLogs:r}){let[i,a]=(0,Z.useState)(zn),[o,s]=(0,Z.useState)(Bn),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(``),[m]=(0,Z.useState)(()=>new lt),[h,g]=(0,Z.useState)(0),_=(0,Z.useRef)(null),v=(0,Z.useRef)(!1),[y,b]=(0,Z.useState)(null),x=Te(t=>t.compactedBySession[e]??Wn),S=Te(t=>t.ttftBySession[e]),C=(0,Z.useMemo)(()=>{if(S!==void 0)return new Map(Object.entries(S))},[S]),w=(0,Z.useMemo)(()=>Xe({messages:t,compacted:x,ttft:C}),[t,x,C]),T=u?`duration`:`sequence`;(0,Z.useEffect)(()=>(_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{m.update([w]),g(e=>e+1),v.current=!0},v.current?Hn:0),()=>{_.current&&clearTimeout(_.current)}),[w,m]);let E=(0,Z.useMemo)(()=>f.trim()===``?null:m.search(f),[f,h]),D=(0,Z.useMemo)(()=>{if(E===null)return null;let e=new Set;for(let t of w)for(let n of t.groups)for(let t of n.cells)E.has(je(t))&&e.add(t.index);return e},[w,E]),O=(0,Z.useMemo)(()=>c===null?null:it(w,c,T),[w,T,c]),k=(0,Z.useMemo)(()=>(n??Vn).filter(t=>t.sessionId===e),[n,e]),A=(0,Z.useMemo)(()=>r?()=>r(e):void 0,[r,e]),j=(0,Z.useMemo)(()=>w.filter(e=>e.turn!==null&&e.groups.reduce((e,t)=>e+t.cells.filter(e=>e.requestOnly!==!0&&e.kind!==`system`).length,0)>1).flatMap(e=>e.turn===null?[]:[e.turn]),[w]),M=j.length>0&&j.every(e=>i.has(e)),N=(0,Z.useMemo)(()=>{let e=[];for(let t of w){let n=t.groups.flatMap(e=>e.cells);for(let t=0;t<n.length;t++){let r=n[t];if(r?.kind!==`message`)continue;let i=n[t+1];(i?.kind===`tool`||i?.kind===`subtool`)&&e.push(je(r))}}return e},[w]),P=N.length>0&&N.every(e=>o.has(e)),F=(0,Z.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),I=(0,Z.useCallback)(()=>{a(e=>{let t=new Set(e);if(M)for(let e of j)t.delete(e);else for(let e of j)t.add(e);return t})},[M,j]),L=(0,Z.useCallback)(e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),R=(0,Z.useCallback)(()=>{s(e=>{let t=new Set(e);if(P)for(let e of N)t.delete(e);else for(let e of N)t.add(e);return t})},[P,N]),z=(0,Z.useCallback)(e=>{l(e)},[]),B=(0,Z.useCallback)(e=>{O!==null&&!O.has(e)&&l(null),b(t=>t===e?null:e)},[O]),V=(0,Z.useCallback)(()=>{b(null)},[]),ee=(0,Z.useCallback)(()=>{l(null),b(null)},[]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,"data-conversation-composer-overlay":``,children:[(0,Q.jsx)(ut,{actualDuration:u,onActualDurationChange:e=>{d(e),l(null)},allTurnsCollapsed:M,onToggleAllTurns:I,allAssistantsCollapsed:P,onToggleAllAssistants:R,searchQuery:f,onSearchQueryChange:p}),(0,Q.jsx)(Rn,{errors:k,onOpenLogs:A}),(0,Q.jsx)(St,{turns:w,mode:T,range:c,selectedIndex:y,searchMatchIndexes:D,onRangeChange:z,onRecordSelect:B}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,Q.jsx)(In,{turns:w,searchMatchIndexes:D,selectedIndex:y,onSelectIndex:B,onDeselect:V,onClearSelection:ee,collapsedTurns:i,onToggleTurn:F,collapsedAssistants:o,onToggleAssistant:L})})]})}var Wn=[],Gn=(0,Z.memo)(function({activeSessionId:e}){let{t}=L(),n=le(e=>e.observed).filter(t=>t.id!==e);return n.length===0?null:(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-col gap-1.5`,children:[n.map(e=>(0,Q.jsx)(Kn,{id:e.id,title:e.title},e.id)),(0,Q.jsx)(`span`,{className:`sr-only`,children:t(`chat.observedTitle`)})]})});function Kn({id:e,title:t}){let{t:n}=L(),r=H(t=>t.generatingSessions?.includes(e)??!1),i=H(t=>{let n=t.messagesBySession[e];return!!(n&&n.length>0?n[n.length-1]:void 0)?.errorCard}),a=H(t=>{let n=t.messagesBySession[e];if(!n||n.length===0)return``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t.type===`user`)continue;let r=t.content||``;if(r.trim())return r.trim().slice(-160)}return``}),o=n(r?`chat.observedRunning`:i?`chat.observedFailed`:`chat.observedDone`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs`,children:[(0,Q.jsx)(v,{size:13,className:`shrink-0 text-accent-blue`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`max-w-[180px] truncate font-medium text-dark-text`,title:t,children:t}),(0,Q.jsx)(`span`,{className:`shrink-0 text-badge text-dark-muted`,children:e.slice(0,8)}),r?(0,Q.jsx)(s,{size:12,className:`shrink-0 animate-spin text-accent-yellow`,"aria-hidden":`true`}):i?(0,Q.jsx)(E,{size:12,className:`shrink-0 text-accent-red`,"aria-hidden":`true`}):(0,Q.jsx)(j,{size:12,className:`shrink-0 text-accent-green`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-badge ${i?`text-accent-red`:r?`text-accent-yellow`:`text-accent-green`}`,children:o}),a&&(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-dark-muted/80`,title:a,children:a})]})}function qn({isOpen:e,onClose:t,title:n,collapsedSummary:r,badge:i,leading:a,children:o,maxHeight:s=`45vh`,onExpandedChange:l,alignToComposer:u=!1,className:d}){let{t:f}=L(),[p,m]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{e&&m(!0)},[e]),(0,Z.useEffect)(()=>{l?.(p)},[p,l]),se({isOpen:e,onClose:t,lockScroll:!1});let h=(0,Z.useCallback)(()=>{m(e=>!e)},[]);return e?(0,Q.jsx)(`div`,{className:G(`shrink-0`,u&&`chat-drawer-col`),children:(0,Q.jsxs)(`div`,{className:G(`bg-dark-overlay/95 ui-surface-overlay backdrop-blur shadow-drawer`,u?`overflow-hidden rounded-xl border border-dark-border`:`border-t border-dark-border`,d),children:[(0,Q.jsxs)(`div`,{role:`button`,"aria-expanded":p,tabIndex:0,onClick:h,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},title:f(p?`commonUi.drawerCollapseTitle`:`commonUi.drawerExpandTitle`),className:G(`flex items-center gap-2 px-4 py-2 cursor-pointer select-none transition-colors`,`hover:bg-dark-hover/60`),children:[a&&(0,Q.jsx)(`span`,{className:`shrink-0 flex items-center`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:a}),(0,Q.jsx)(`span`,{className:G(`shrink-0 text-dark-muted transition-transform duration-200`,!p&&`rotate-180`),children:(0,Q.jsx)(c,{size:16})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-dark-text truncate`,children:n}),i,!p&&r&&(0,Q.jsx)(`span`,{className:`min-w-0 flex items-center gap-1.5 text-xs text-dark-muted truncate`,children:r})]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":f(`common.close`),onClick:e=>{e.stopPropagation(),t()},className:`shrink-0 p-1 rounded-md text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors`,children:(0,Q.jsx)(C,{size:15})})]}),p&&(0,Q.jsx)(`div`,{className:`animate-slide-up border-t border-dark-border/60 overflow-y-auto custom-scrollbar p-4`,style:{maxHeight:s},children:o})]})}):null}function Jn(e,t){if(!e||!t||t.length===0)return;let n=e.find(e=>e.switchMode&&t.includes(e.label));n?.switchMode&&be.getState().setBaseMode(n.switchMode)}var Yn=15e3,Xn=300,Zn=4,Qn=8388608;function $n(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(typeof r.result==`string`?r.result:``),r.onerror=()=>n(r.error instanceof Error?r.error:Error(`image read failed`)),r.readAsDataURL(e)})}function er(e){let t=[];for(let n of Array.from(e.items??[])){if(n.kind!==`file`||!n.type.startsWith(`image/`))continue;let e=n.getAsFile();e&&t.push(e)}if(t.length===0)for(let n of Array.from(e.files??[]))n.type.startsWith(`image/`)&&t.push(n);return t}function tr(e){let{t}=L();return(0,Z.useMemo)(()=>{if(e.secret)return{allItems:[],otherIdx:-1,proceedIdx:-1,displayItems:[]};let n=t(`chat.askOtherLabel`),r=t(`chat.askProceedLabel`),i=e.options||[],a=i.some(e=>e.label===n),o=i.some(e=>e.label===r),s=[...i];return o||s.push({label:r,description:t(`chat.askProceedDesc`)}),a||s.push({label:n,description:t(`chat.askCustomDesc`)}),{allItems:s,otherIdx:a?s.findIndex(e=>e.label===n):s.length-1,proceedIdx:o?s.findIndex(e=>e.label===r):s.length-(a?1:2),displayItems:s}},[e,t])}function nr(e){let t=(0,Z.useRef)(null),[n,r]=(0,Z.useState)({top:!1,bottom:!1}),i=(0,Z.useCallback)(()=>{let e=t.current;if(!e)return;let n=e.scrollHeight-e.clientHeight,i=n>2&&e.scrollTop>2,a=n>2&&e.scrollTop<n-2;r(e=>e.top===i&&e.bottom===a?e:{top:i,bottom:a})},[]);return(0,Z.useEffect)(()=>{i();let e=t.current;if(!e)return;e.addEventListener(`scroll`,i,{passive:!0});let n=typeof ResizeObserver<`u`?new ResizeObserver(i):null;return n?.observe(e),()=>{e.removeEventListener(`scroll`,i),n?.disconnect()}},[i,e]),{ref:t,style:{"--ui-fade-top":n.top?`14px`:`0px`,"--ui-fade-bottom":n.bottom?`14px`:`0px`}}}function rr({ms:e}){let{t}=L();return(0,Q.jsx)(`span`,{className:`inline-flex items-center self-start text-xs leading-relaxed tabular-nums text-accent-yellow`,children:t(`chat.askAutoContinue`,{seconds:Math.max(1,Math.round(e/1e3))})})}function ir({children:e,tone:t}){return(0,Q.jsx)(`span`,{className:G(`shrink-0 rounded-full px-1.5 py-0.5 text-meta leading-none`,t===`green`?`bg-accent-green/10 text-accent-green`:`bg-dark-hover text-dark-muted`),children:e})}function ar({label:e,description:t,index:n,multi:r,active:i,checked:a,tag:o,onSelect:s}){let c=r?a:i;return(0,Q.jsxs)(`button`,{type:`button`,role:r?`checkbox`:`radio`,"aria-checked":c,onClick:s,className:G(`w-full min-h-11 flex items-start gap-3 rounded-lg border px-3 py-2.5 text-start`,`transition duration-snap ease-expo`,c?`border-accent-blue/40 bg-accent-blue/10`:`border-dark-border/60 bg-transparent hover:border-dark-border hover:bg-dark-hover`),children:[(0,Q.jsx)(`span`,{className:G(`shrink-0 w-5 h-5 inline-flex items-center justify-center text-meta font-medium tabular-nums`,`transition duration-snap ease-expo`,r?`rounded-md`:`rounded-full`,c?`border border-accent-blue bg-accent-blue text-accent-fg`:r?`border border-dark-border text-transparent`:`border border-dark-border text-dark-muted`),children:r?(0,Q.jsx)(S,{size:12}):n}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-dark-text`,children:e}),o]}),t&&(0,Q.jsx)(`span`,{className:`block mt-0.5 text-xs leading-snug text-dark-muted`,children:t})]}),!r&&(0,Q.jsx)(S,{size:15,"aria-hidden":`true`,className:G(`shrink-0 mt-0.5 transition-opacity duration-snap ease-expo`,c?`text-accent-blue opacity-100`:`opacity-0`)})]})}function or({value:e,onChange:t,onSubmit:n}){let{t:r}=L(),[i,a]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute start-3 top-1/2 -translate-y-1/2 text-dark-muted`,children:(0,Q.jsx)(p,{size:14})}),(0,Q.jsx)(`input`,{type:i?`text`:`password`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,className:`input ps-9 pe-11 font-mono`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),n())},placeholder:r(`chat.askSecretPlaceholder`),autoFocus:!0}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-label":r(i?`chat.askSecretHide`:`chat.askSecretReveal`),"aria-pressed":i,className:G(`absolute end-1 top-1/2 -translate-y-1/2 inline-flex h-8 w-8 items-center justify-center`,`rounded-md text-dark-muted transition-colors duration-snap ease-expo`,`hover:bg-dark-hover hover:text-dark-text`),children:i?(0,Q.jsx)(f,{size:14,"aria-hidden":`true`}):(0,Q.jsx)(u,{size:14,"aria-hidden":`true`})})]}),(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-dark-muted`,children:r(`chat.askSecretHint`)}),(0,Q.jsx)(K,{variant:`primary`,shape:`pill`,leftIcon:(0,Q.jsx)(D,{size:15}),onClick:n,disabled:!e,className:`w-full min-h-11 sm:w-auto sm:self-start`,children:r(`chat.askSubmit`)})]})}function sr({item:e,answered:t,selectedIdx:n,multiSelected:r,customInput:i,showCustomInput:a,onSelect:o,onToggleMulti:s,onProceed:c,onEnterCustom:l,onCancelCustom:u,onSubmitCustom:d,onCustomChange:f,inputRef:p}){let{t:m}=L(),{otherIdx:h,proceedIdx:g,displayItems:_}=tr(e),v=!!e.multiSelect,{ref:y,style:b}=nr(_.length);if(e.secret)return(0,Q.jsx)(or,{value:i,onChange:f,onSubmit:d});let x=e=>{e===g?c():e===h?l():v?s(e):o(e)};return(0,Q.jsxs)(`div`,{ref:y,style:b,role:v?`group`:`radiogroup`,"aria-label":e.question,className:`fade-mask-y flex flex-col gap-2 pe-1 overflow-y-auto custom-scrollbar sm:max-h-72`,children:[_.map((e,t)=>{let o=n===t,s=t===h;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ar,{label:e.label,description:e.description,index:t+1,multi:v,active:o,checked:r.has(t),tag:t===g?(0,Q.jsx)(ir,{tone:`green`,children:m(`chat.askDirectTag`)}):s?(0,Q.jsx)(ir,{tone:`muted`,children:m(`chat.askCustomTag`)}):null,onSelect:()=>x(t)}),s&&o&&a&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 ps-8`,children:[(0,Q.jsx)(`textarea`,{ref:p,className:`input resize-none`,rows:3,value:i,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),d()),e.key===`Escape`&&u()},placeholder:m(`chat.askAnswerPlaceholder`),autoFocus:!0}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(K,{variant:`primary`,size:`sm`,shape:`pill`,leftIcon:(0,Q.jsx)(D,{size:13}),onClick:d,children:m(`chat.askSubmit`)}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,shape:`pill`,leftIcon:(0,Q.jsx)(C,{size:13}),onClick:u,children:m(`common.cancel`)})]})]})]},`opt-${t}`)}),t&&(0,Q.jsx)(`div`,{className:`text-xs font-medium text-accent-green`,children:m(`chat.askAnswered`)})]})}var cr=(e,t)=>e?.secret===!0||t?.secret===!0;function lr({images:e,notice:t,onRemove:n}){let{t:r}=L();return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-dark-border bg-dark-surface`,children:[(0,Q.jsx)(`img`,{src:e,alt:r(`chat.askImageAlt`,{index:t+1}),className:`h-14 w-14 object-cover`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":r(`chat.askImageRemove`),onClick:()=>n(t),className:`absolute end-0.5 top-0.5 inline-flex h-5 w-5 items-center justify-center rounded-full bg-dark-bg/80 text-dark-muted transition-colors hover:bg-accent-red/80 hover:text-dark-bg`,children:(0,Q.jsx)(C,{size:11})})]},`ask-img-${t}`))}),t?(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 text-meta text-accent-yellow`,children:[(0,Q.jsx)(x,{size:11,className:`shrink-0`}),(0,Q.jsx)(`span`,{children:t})]}):(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 text-meta text-dark-muted`,children:[(0,Q.jsx)(A,{size:11,className:`shrink-0`}),(0,Q.jsx)(`span`,{children:r(`chat.askImagePasteHint`)})]})]})}function ur({isOpen:e,onClose:t}){let{t:r}=L(),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(-1),[l,u]=(0,Z.useState)(new Set),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(0),[T,E]=(0,Z.useState)([]),[O,k]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)([]),[N,P]=(0,Z.useState)(null),F=(0,Z.useRef)(null),I=(0,Z.useRef)(null),R=(0,Z.useMemo)(()=>a?a.questions&&a.questions.length>0?a.questions:[{question:a.question,header:a.header,options:a.options,multiSelect:a.multiSelect,secret:a.secret}]:[],[a]),z=R.length>1,B=(0,Z.useCallback)(e=>{o(e),c(e.multiSelect?-1:0),u(new Set),f(``);let t=e.questions&&e.questions.length>0?e.questions:[e];m(cr(t[0],e)),g(!1),v(!1),b(!1),w(0),k(!1),E(t.map(()=>null)),M([]),P(null)},[]);(0,Z.useEffect)(()=>{I.current=a}),(0,Z.useEffect)(()=>{if(e){let e=window.__pendingQuestion;e&&B(e)}},[e,B]),(0,Z.useEffect)(()=>{let e=e=>{let n=e.detail,r=I.current?.questionId??null;if(n&&r&&n!==r)return;let i=r;g(!0),setTimeout(()=>{let e=I.current?.questionId??null;i&&e&&e!==i||(t(),o(null),g(!1))},Xn)};return window.addEventListener(`ask-question-dismiss`,e),()=>window.removeEventListener(`ask-question-dismiss`,e)},[t]),(0,Z.useEffect)(()=>{if(!h)return;let e=setTimeout(()=>{g(!1),v(!0)},Yn);return()=>clearTimeout(e)},[h]),(0,Z.useEffect)(()=>{let e=()=>{v(!1),b(!1)};return window.addEventListener(`ask-question-dismiss`,e),()=>window.removeEventListener(`ask-question-dismiss`,e)},[]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.detail,n=I.current?.questionId??null;t&&n&&t!==n||(g(!1),v(!0),b(!0))};return window.addEventListener(`ask-question-ack-failed`,e),()=>window.removeEventListener(`ask-question-ack-failed`,e)},[]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.detail,n=ee.getState().activeSessionId;if(t&&n&&t!==n)return;let r=window.__pendingQuestion;r&&B(r)};return window.addEventListener(`ask-question-required`,e),()=>window.removeEventListener(`ask-question-required`,e)},[B]),(0,Z.useEffect)(()=>{c(0),u(new Set),f(``),m(cr(R[C],a))},[C,O,a,R]);let V=R[C]||null,{allItems:H,otherIdx:U}=tr(V||{question:``}),W=cr(V,a),q=j[C]??[],J=(0,Z.useCallback)((e,t)=>{!h&&a&&(v(!1),g(!0),Jn(a.options,t),X.send({type:`question_answer`,sessionId:a.sessionId||X.getSessionId()||void 0,data:JSON.stringify({questionId:a.questionId,answer:e,selectedOptions:t,...q.length>0?{images:q}:{}})}))},[h,a,q]),te=(0,Z.useCallback)(()=>{!h&&a&&(v(!1),g(!0),X.send({type:`question_answer`,sessionId:a.sessionId||X.getSessionId()||void 0,data:JSON.stringify({questionId:a.questionId,answers:R.map((e,t)=>{let n=T[t]||{answer:r(`chat.askUnansweredValue`)},i=j[t]??[];return i.length>0?{...n,images:i}:n})})}))},[h,a,R,T,j,r]),ne=(0,Z.useCallback)(e=>{M(t=>{let n=t.slice();return n[C]=(n[C]??[]).filter((t,n)=>n!==e),n}),P(null)},[C]),re=(0,Z.useCallback)(e=>{if(h||W||O)return;let t=e.clipboardData;if(!t)return;let n=er(t);if(n.length===0)return;e.preventDefault();let i=C,a=j[i]?.length??0;(async()=>{let e=[],t=0,o=0;for(let r of n)if(r.size>Qn)t++;else if(a+e.length>=Zn)o++;else try{let t=await $n(r);t.startsWith(`data:image/`)&&e.push(t)}catch{}e.length>0&&M(t=>{let n=t.slice();return n[i]=[...n[i]??[],...e].slice(0,Zn),n}),t>0?P(r(`chat.askImageTooLarge`)):o>0?P(r(`chat.askImageTooMany`,{count:Zn})):e.length>0&&P(null)})()},[h,W,O,C,j,r]),Y=(0,Z.useCallback)((e,t,n)=>{Jn(R[e]?.options,n),E(r=>{let i=r.slice();return i[e]={answer:t,selectedOptions:n},i}),e<R.length-1?w(e+1):k(!0)},[R]),ie=(0,Z.useCallback)(e=>{if(h||!a)return;let t=H[e];t&&(c(e),J(t.label,[t.label]))},[h,a,H,J]),ae=(0,Z.useCallback)(()=>{if(h||!a||s<0)return;let e=H[s];e&&J(e.label,[e.label])},[h,a,s,H,J]),oe=(0,Z.useCallback)(()=>{if(h||s<0)return;let e=H[s];e&&Y(C,e.label,[e.label])},[h,s,H,Y,C]),se=(0,Z.useCallback)(e=>{if(h)return;let t=H[e];t&&Y(C,t.label,[t.label])},[h,H,Y,C]),ce=(0,Z.useCallback)(e=>{h||u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[h]),le=(0,Z.useCallback)(()=>{if(h)return;let e=[...l].map(e=>H[e]?.label||``);z?Y(C,e.join(`, `),e):J(e.join(`, `),e)},[h,l,H,z,Y,C,J]),ue=(0,Z.useCallback)(()=>{if(h)return;let e=r(`chat.askProceedLabel`);z?Y(C,e,[e]):J(e,[e])},[h,z,Y,C,J,r]),de=(0,Z.useCallback)(()=>{h||(c(U),m(!0),setTimeout(()=>F.current?.focus(),100))},[h,U]),fe=(0,Z.useCallback)(()=>{m(!1),f(``)},[]),pe=(0,Z.useCallback)(()=>{if(h||W&&!d.trim())return;let e=d||r(`chat.askEmptyInputValue`);z?Y(C,e):J(e)},[h,d,z,Y,C,J,r,W]),me=(0,Z.useCallback)(()=>{!h&&a&&(v(!1),g(!0),X.send({type:`question_answer`,sessionId:a.sessionId||X.getSessionId()||void 0,data:JSON.stringify({questionId:a.questionId,answers:R.map(()=>({answer:`(cancelled)`}))})}))},[h,a,R]),he=(0,Z.useCallback)(()=>{if(!h){if(y)t();else if(z){if(p&&!W){m(!1),f(``);return}if(O){k(!1),w(R.length-1);return}me()}else p&&!W?(m(!1),f(``)):J(`(cancelled)`)}},[h,z,p,O,R.length,me,J,y,t,W]);if(!e||!a)return null;let ge=T.filter(e=>!e).length,_e=T.filter(Boolean).length,ve=h||_||p,ye=h?(0,Q.jsx)(`span`,{children:r(`chat.askSubmitting`)}):_?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-accent-yellow`,children:[(0,Q.jsx)(x,{size:12}),r(`chat.askSubmitRetry`)]}):p?W?null:(0,Q.jsx)(`span`,{children:r(`chat.askEnterHint`)}):a.multiSelect?(0,Q.jsx)(`span`,{children:r(`chat.askMultiHintSingle`)}):(0,Q.jsx)(`span`,{children:r(`chat.askSingleHintSingle`)});return(0,Q.jsx)(qn,{isOpen:e,onClose:he,title:a.header||r(z?`chat.askBatchTitle`:`chat.askSingleTitle`),badge:z?(0,Q.jsxs)(`span`,{className:`shrink-0 inline-flex items-center rounded-full bg-dark-hover px-2 py-0.5 text-meta font-medium tabular-nums text-dark-muted`,children:[_e,`/`,R.length]}):void 0,collapsedSummary:(0,Q.jsx)(`span`,{className:`truncate`,children:V?.question||a.question}),maxHeight:`min(85dvh, 40rem)`,alignToComposer:!0,children:z?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,onPaste:re,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[R.map((e,t)=>{let n=!!T[t],r=!O&&C===t;return(0,Q.jsxs)(`button`,{type:`button`,"aria-current":r?`step`:void 0,onClick:()=>{w(t),k(!1)},className:G(`inline-flex items-center gap-1 rounded-full px-3 min-h-9 text-xs font-medium tabular-nums`,`transition duration-snap ease-expo`,r?`bg-dark-text text-dark-bg`:n?`border border-accent-green/40 bg-accent-green/10 text-accent-green`:`border border-dark-border bg-dark-surface text-dark-muted hover:bg-dark-hover`),children:[`Q`,t+1,n&&(0,Q.jsx)(S,{size:11})]},`nav-${t}`)}),(0,Q.jsx)(`button`,{type:`button`,"aria-current":O?`step`:void 0,onClick:()=>k(!0),className:G(`inline-flex items-center rounded-full px-3 min-h-9 text-xs font-medium`,`transition duration-snap ease-expo`,O?`bg-dark-text text-dark-bg`:`border border-dark-border bg-dark-surface text-dark-muted hover:bg-dark-hover`),children:r(`chat.askSubmit`)})]}),a.autoResolutionMs&&a.autoResolutionMs>0&&(0,Q.jsx)(rr,{ms:a.autoResolutionMs}),O?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-dark-text`,children:r(`chat.askReviewTitle`)}),(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-dark-border`,children:R.map((e,t)=>{let n=T[t];return(0,Q.jsxs)(`div`,{className:G(`flex items-start gap-3 px-3 py-2.5`,t>0&&`border-t border-dark-border`),children:[(0,Q.jsx)(`span`,{className:`shrink-0 w-5 h-5 rounded-full border border-dark-border text-meta font-medium tabular-nums text-dark-muted inline-flex items-center justify-center`,children:t+1}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm leading-snug text-dark-text`,children:e.question}),(0,Q.jsxs)(`div`,{className:G(`mt-1 text-xs break-words`,n?`text-accent-green`:`text-accent-yellow`),children:[n?n.answer:r(`chat.askNotAnswered`),(j[t]??[]).length>0&&(0,Q.jsxs)(`span`,{className:`ms-2 inline-flex items-center gap-0.5 text-meta text-dark-muted`,children:[(0,Q.jsx)(A,{size:11}),`${(j[t]??[]).length}`]})]})]})]},`rev-${t}`)})}),ge>0&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-accent-yellow/30 bg-accent-yellow/10 px-3 py-2 text-xs leading-relaxed text-accent-yellow`,children:[(0,Q.jsx)(x,{size:14,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:r(`chat.askUnansweredWarning`,{count:ge})})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[(0,Q.jsx)(K,{variant:`primary`,shape:`pill`,leftIcon:(0,Q.jsx)(D,{size:15}),onClick:te,disabled:h,className:`w-full min-h-11 sm:w-auto`,children:r(`chat.askSubmitAll`)}),(0,Q.jsx)(K,{variant:`secondary`,shape:`pill`,leftIcon:(0,Q.jsx)(n,{size:14}),onClick:()=>{k(!1),w(R.length-1)},disabled:h,className:`w-full min-h-11 sm:w-auto`,children:r(`chat.askBackToEdit`)})]})]}):V?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-3`,children:[(0,Q.jsx)(`p`,{className:`min-w-0 text-base leading-relaxed text-dark-text text-pretty`,children:V.question}),(0,Q.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1.5 shrink-0`,children:[(0,Q.jsx)(K,{variant:`secondary`,size:`sm`,shape:`pill`,leftIcon:(0,Q.jsx)(n,{size:13}),onClick:()=>{w(e=>Math.max(0,e-1)),k(!1)},disabled:C===0,children:r(`chat.askPrevQuestion`)}),C<R.length-1?(0,Q.jsx)(K,{variant:`secondary`,size:`sm`,shape:`pill`,rightIcon:(0,Q.jsx)(i,{size:13}),onClick:()=>{w(e=>Math.min(R.length-1,e+1)),k(!1)},children:r(`chat.askNextQuestion`)}):(0,Q.jsx)(K,{variant:`secondary`,size:`sm`,shape:`pill`,rightIcon:(0,Q.jsx)(i,{size:13}),onClick:()=>k(!0),children:r(`chat.askViewSubmit`)})]})]}),(0,Q.jsx)(sr,{item:V,answered:!!T[C],selectedIdx:s,multiSelected:l,customInput:d,showCustomInput:p,onSelect:se,onToggleMulti:ce,onProceed:ue,onEnterCustom:de,onCancelCustom:fe,onSubmitCustom:pe,onCustomChange:f,inputRef:F}),!W&&(q.length>0||p)&&(0,Q.jsx)(lr,{images:q,notice:N,onRemove:ne}),(0,Q.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsx)(`p`,{className:G(`text-xs leading-relaxed text-dark-muted`,!ve&&`hidden sm:block`),children:p?(0,Q.jsx)(`span`,{children:r(`chat.askEnterHint`)}):V.multiSelect?(0,Q.jsx)(`span`,{children:r(`chat.askMultiHintBatch`)}):(0,Q.jsx)(`span`,{children:r(`chat.askSingleHintBatch`)})}),!p&&(0,Q.jsx)(K,{variant:V.multiSelect?`primary`:`secondary`,shape:`pill`,leftIcon:(0,Q.jsx)(S,{size:15}),onClick:V.multiSelect?le:oe,disabled:h||(V.multiSelect?l.size===0:s<0),className:`w-full min-h-11 sm:w-auto sm:shrink-0`,children:V.multiSelect?r(`chat.askFinishQuestion`,{count:l.size}):r(`chat.askConfirmQuestion`)})]})]}):null]}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,onPaste:re,children:[(0,Q.jsx)(`p`,{className:`text-base leading-relaxed text-dark-text text-pretty`,children:a.question}),a.autoResolutionMs&&a.autoResolutionMs>0&&(0,Q.jsx)(rr,{ms:a.autoResolutionMs}),(0,Q.jsx)(sr,{item:R[0],answered:!1,selectedIdx:s,multiSelected:l,customInput:d,showCustomInput:p,onSelect:ie,onToggleMulti:ce,onProceed:ue,onEnterCustom:de,onCancelCustom:fe,onSubmitCustom:pe,onCustomChange:f,inputRef:F}),!W&&(q.length>0||p)&&(0,Q.jsx)(lr,{images:q,notice:N,onRemove:ne}),(0,Q.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[ye?(0,Q.jsx)(`p`,{className:G(`text-xs leading-relaxed text-dark-muted`,!ve&&`hidden sm:block`),children:ye}):(0,Q.jsx)(`span`,{className:`hidden sm:block`}),!p&&(0,Q.jsx)(K,{variant:a.multiSelect?`primary`:`secondary`,shape:`pill`,leftIcon:(0,Q.jsx)(S,{size:15}),onClick:a.multiSelect?le:ae,disabled:h||(a.multiSelect?l.size===0:s<0),className:`w-full min-h-11 sm:w-auto sm:shrink-0`,children:a.multiSelect?r(`chat.askSubmitSelected`,{count:l.size}):r(`chat.askSubmit`)})]})]})})}var dr=(0,Z.memo)(function({sessionId:e}){let{t:n}=L(),{offer:r,respond:i}=we(e);if(!r)return null;let a=r.fileName||n(`widgets.dwf.offerFallbackTitle`);return(0,Q.jsx)(`div`,{className:`chat-drawer-col shrink-0 pb-1.5`,"data-testid":`dwf-offer-card`,children:(0,Q.jsxs)(`div`,{className:`animate-fade-in-up overflow-hidden rounded-xl border border-accent-purple/40 bg-dark-surface`,style:{boxShadow:`var(--shadow-air-1)`},role:`group`,"aria-label":a,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-dark-border/60 px-3 py-2`,children:[(0,Q.jsx)(t,{size:13,className:`text-accent-purple shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-meta font-semibold text-dark-text`,children:a})]}),(0,Q.jsx)(`div`,{className:`px-3 py-2`,children:(0,Q.jsx)(Oe,{offer:r,onRespond:i,layout:`wide`})})]})})}),fr=15;function pr({isOpen:e,onCloseModal:t}){let{t:n}=L(`hook`),r=ue(),i=r.pendingApprovals,o=r.autoMode,s=r.setAutoMode,[c,l]=(0,Z.useState)(0),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(fr),[m,h]=(0,Z.useState)(!0),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(null),y=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{i.length!==0&&(o?(i.forEach(e=>{X.send({type:`hook_allow`,data:JSON.stringify({approvalId:e.approvalId})})}),r.clearApprovals()):l(e=>Math.min(e,i.length-1)))},[i.length,o]);let b=i[c]??null,S=i.length>0&&b!==null,C=i.length,w=S?C-c-1:0;(0,Z.useEffect)(()=>{if(S&&!u&&e&&b)return p(fr),v.current=setInterval(()=>{p(e=>e<=1?(v.current&&clearInterval(v.current),0):e-1)},1e3),()=>{v.current&&clearInterval(v.current)}},[S,u,e,b?.approvalId]);let T=b?ce(b.toolName,b.askPayload):{level:`MEDIUM`,reasonKey:`risk_default`},E=ke[T.level],D=te[T.level===`CRITICAL`?`critical`:T.level===`HIGH`?`high`:T.level===`LOW`?`low`:`medium`],O=b?de(b.toolName,b.askPayload):null,A=b?fe(b.toolName,b.askPayload):null,j=b?{verb:ye(b.toolName),target:he(b.toolName,b.askPayload)}:null,M=b?Se(b.askPayload)!==null:!1,N=b?pe(b.toolName,b.askPayload):null,P=(O?ve(O.text):A?ve(A):!1)&&!g;(0,Z.useEffect)(()=>{_(!1)},[b?.approvalId]);let I=f/fr*100,R=f<=5,z=q((fr-f)*1e3),B=(0,Z.useCallback)((e,t)=>{let n=ee.getState().activeSessionId;n&&H.getState().updateHookApprovalStatus(n,e,t)},[]),V=(0,Z.useCallback)(e=>{b&&(e&&B(b.approvalId,e),d(!0),setTimeout(()=>{r.removeApproval(b.approvalId),l(0),d(!1),y.current=!1,p(fr)},200))},[b?.approvalId,r,B]),U=(0,Z.useCallback)(()=>{!b||u||y.current||(P?_(!0):(y.current=!0,v.current&&clearInterval(v.current),X.send({type:`hook_allow`,data:JSON.stringify({approvalId:b.approvalId})}),V(`approved`)))},[b,V,u,P]),W=(0,Z.useCallback)(()=>{!b||u||y.current||(y.current=!0,v.current&&clearInterval(v.current),X.send({type:`hook_deny`,data:JSON.stringify({approvalId:b.approvalId})}),V(`denied`))},[b,V,u]),G=(0,Z.useCallback)(()=>{if(!b||u||y.current)return;if(P){_(!0);return}y.current=!0,v.current&&clearInterval(v.current);let e=Se(b.askPayload);e?(r.addToSessionAllowList(b.toolName,e),X.send({type:`hook_allow`,data:JSON.stringify({approvalId:b.approvalId,sessionAllow:!0})})):(r.addToSessionAllowList(b.toolName),X.send({type:`hook_allow`,data:JSON.stringify({approvalId:b.approvalId})})),V(`approved`)},[b,V,r,u,P]),J=(0,Z.useCallback)(()=>{!b||u||y.current||(P?_(!0):(y.current=!0,v.current&&clearInterval(v.current),s(!0),be.getState().setAuto(!0),X.send({type:`hook_allow`,data:JSON.stringify({approvalId:b.approvalId})}),V(`approved`)))},[b,V,u,s,P]),re=(b?.timeoutMs??15e3)>0,Y=b?.timeoutAction===`deny`?W:U;if((0,Z.useEffect)(()=>{f===0&&e&&!u&&b&&re&&Y()},[f,e,u,b,Y,re]),(0,Z.useEffect)(()=>{if(!e||!m)return;let t=e=>{let t=e.target;t&&typeof t.closest==`function`&&t.closest(`input, textarea, select, [contenteditable="true"]`)||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),W()):e.key===`Enter`?(e.preventDefault(),U()):e.key===`1`?U():e.key===`2`?W():e.key===`3`?G():e.key===`4`&&J())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,m,U,W,G,J]),!S||!b)return null;let ie=n(`optionAllowHint`),ae=n(`optionDenyHint`),oe=M?n(`optionAllowPathHint`):n(`optionAllowAlwaysHint`,{tool:b.toolName}),se=n(`optionAutoModeHint`),le=O?.text??A??null,me=le?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Q.jsx)(`code`,{className:`font-mono text-meta bg-dark-surface text-accent-blue px-1 py-0.5 rounded shrink-0`,children:b.toolName}),(0,Q.jsx)(`span`,{className:`truncate`,children:le})]}):null;return(0,Q.jsx)(qn,{isOpen:e,onClose:()=>t?.(),title:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(F,{className:`w-4 h-4 text-accent-yellow`}),(0,Q.jsx)(`span`,{children:n(`hookApproval`)}),(0,Q.jsxs)(`span`,{className:`text-xs text-dark-muted`,children:[`(`,c+1,`/`,C,`)`]})]}),badge:(0,Q.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-badge font-bold border shrink-0 ${E.badge}`,children:[E.icon,` `,T.level]}),collapsedSummary:me,onExpandedChange:h,maxHeight:`50vh`,alignToComposer:!0,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${E.bg} border ${E.border}`,children:[(0,Q.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${E.badge}`,children:[E.icon,` `,T.level]}),(0,Q.jsx)(`span`,{className:`text-xs text-dark-muted truncate`,children:n(T.reasonKey)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 ms-auto shrink-0`,children:[(0,Q.jsx)(k,{size:12,className:R?`text-accent-red`:`text-dark-muted`}),(0,Q.jsx)(`span`,{className:`text-xs font-mono ${R?`text-accent-red animate-pulse`:`text-dark-muted`}`,children:re?`${f}s`:`∞`}),(0,Q.jsx)(`div`,{className:`w-12 h-1.5 bg-dark-border rounded-full overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all duration-700 ${R?`bg-accent-red`:f<=8?`bg-accent-yellow`:`bg-accent-green`}`,style:{width:`${I}%`}})})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`flex-none w-7 h-7 rounded-lg bg-accent-blue/10 text-accent-blue inline-flex items-center justify-center`,children:(0,Q.jsx)(F,{size:15})}),j&&(0,Q.jsx)(_e,{pre:n(j.verb),obj:j.target})]}),N&&(N.external&&N.path?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-meta px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow border border-accent-yellow shrink-0`,title:N.path,children:[(0,Q.jsx)(a,{size:10}),n(`scopeExternal`),`: `,N.path.length>48?`${N.path.slice(0,47)}…`:N.path]}):(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 shrink-0`,children:n(`scopeLocal`)}))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-dark-muted shrink-0`,children:n(`tool`)}),(0,Q.jsx)(`code`,{className:`text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate`,children:b.toolName}),(0,Q.jsx)(`span`,{className:`text-dark-muted/50`,children:z}),(0,Q.jsx)(`span`,{className:`text-dark-muted/50`,children:D.label}),b.timeoutAction&&(0,Q.jsxs)(`span`,{className:`text-xs ${b.timeoutAction===`deny`?`text-accent-red`:`text-accent-green`}`,children:[`timeout: `,re?`${b.timeoutAction===`allow`?`auto-allow`:`auto-deny`}${b.timeoutMs?` (${(b.timeoutMs/1e3).toFixed(0)}s)`:``}`:n(`timeoutWaitUser`)]})]}),O?(0,Q.jsx)(ge,{text:O.text,mono:O.mono,expanded:g,onToggle:()=>_(e=>!e)}):A?(0,Q.jsx)(ge,{text:A,expanded:g,onToggle:()=>_(e=>!e)}):null,P&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>_(!0),className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded bg-accent-red/10 text-accent-red border border-accent-red/30 hover:bg-accent-red/20 transition-colors text-left`,children:[(0,Q.jsx)(x,{size:13}),(0,Q.jsx)(`span`,{children:n(`showAll`)})]}),(T.level===`CRITICAL`||T.level===`HIGH`)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${E.bg} ${E.text}`,children:[(0,Q.jsx)(x,{size:13}),(0,Q.jsx)(`span`,{children:T.level===`CRITICAL`?n(`highRiskWarning`):n(`mediumRiskConfirm`)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(K,{variant:`accent`,onClick:U,disabled:u||P,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono bg-accent-fg/20 rounded px-1`,children:`1`}),(0,Q.jsx)(`span`,{children:ne.allow.label}),(0,Q.jsx)(`span`,{className:`text-meta text-accent-fg/70 hidden sm:inline`,children:ie})]}),(0,Q.jsxs)(`button`,{onClick:G,disabled:u||P,className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono text-dark-muted bg-dark-surface rounded px-1`,children:`3`}),(0,Q.jsx)(`span`,{children:ne.allow_session.label}),(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 hidden sm:inline`,children:oe})]}),(0,Q.jsxs)(`button`,{onClick:J,disabled:u||P,className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono text-dark-muted bg-dark-surface rounded px-1`,children:`4`}),(0,Q.jsx)(`span`,{children:ne.auto.label}),(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 hidden sm:inline`,children:se})]}),(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsxs)(`button`,{onClick:W,disabled:u,className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-dark-muted hover:bg-accent-red/15 hover:text-accent-red text-sm transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono text-dark-muted/60 rounded px-1`,children:`2`}),(0,Q.jsx)(`span`,{children:ne.deny.label}),(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 hidden sm:inline`,children:ae})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-dark-muted/60`,children:[(0,Q.jsx)(`span`,{children:n(`shortcutHint`)}),(0,Q.jsx)(`span`,{children:w>0?n(`morePending`,{n:w}):n(`lastItem`)})]})]})})}var mr=`dsc-auto-access-banner-dismissed`,hr=(0,Z.memo)(function(){let{t:e}=L(),t=be(e=>e.mode),[n,r]=(0,Z.useState)(()=>localStorage.getItem(mr)===`1`);(0,Z.useEffect)(()=>{J(t===`normal`?`act`:t)||localStorage.getItem(mr)===`1`&&r(!1)},[t]);let i=(0,Z.useCallback)(e=>{e&&localStorage.setItem(mr,`1`),r(!0)},[]);return!(t!==`normal`&&J(t))||n?null:(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1 text-meta leading-snug text-accent-yellow/75 bg-accent-yellow/[0.05] border-b border-accent-yellow/10 select-none`,role:`note`,title:e(`autoAccess.desc`),children:[(0,Q.jsx)(d,{size:11,className:`shrink-0 text-accent-yellow/70`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 truncate`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e(`autoAccess.title`)}),(0,Q.jsxs)(`span`,{className:`text-accent-yellow/60`,children:[` · `,e(`autoAccess.desc`)]})]}),(0,Q.jsx)(`button`,{onClick:()=>i(!1),className:`shrink-0 rounded p-0.5 text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors`,title:e(`autoAccess.dismiss`),"aria-label":e(`autoAccess.dismiss`),children:(0,Q.jsx)(C,{size:11})}),(0,Q.jsx)(`button`,{onClick:()=>i(!0),className:`shrink-0 rounded px-1 py-px text-badge text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors whitespace-nowrap`,children:e(`autoAccess.neverShow`)})]})});function gr(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t)}…`:n}function _r(e){return gr(e,12)}function vr(){return`custom-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function yr(e,t){return e.some(e=>e.kind===`scenario`&&e.id===t)}function br(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id!=`string`||t.id===``||typeof t.label!=`string`||t.label===``||typeof t.hint!=`string`?!1:t.kind===`template`?typeof t.templateId==`string`&&t.templateId!==``:t.kind!==void 0&&t.kind!==`prompt`?!1:typeof t.prompt==`string`&&t.prompt!==``}function xr(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&t.id!==``&&typeof t.label==`string`&&t.label!==``&&Array.isArray(t.scenarios)&&t.scenarios.length>0&&t.scenarios.every(br)}function Sr(e){let t=e(`chat.start.categories`,{returnObjects:!0,defaultValue:[]});return Array.isArray(t)?t.filter(xr):[]}var Cr=`tpl:`,wr=`tpl-`;function Tr(e){return e.trim().toLowerCase()}function Er(e){let t=new Map;for(let n of e){let e=(n.category??``).trim();if(!e)continue;let r=(n.name??``).trim();if(!r)continue;let i={id:`${wr}${n.id}`,label:r,hint:n.description??``,prompt:``,kind:`template`,templateId:n.id},a=t.get(e);a?a.push(i):t.set(e,[i])}return[...t].map(([e,t])=>({id:`${Cr}${e}`,label:e,scenarios:t}))}function Dr(e,t){if(t.length===0)return e;let n=e.map(e=>({...e})),r=new Set(n.map(e=>e.id)),i=new Map(n.map((e,t)=>[Tr(e.label),t]));for(let e of t){let t=Tr(e.label),a=i.get(t);if(a!==void 0){let t=n[a];n[a]={...t,scenarios:[...t.scenarios,...e.scenarios]}}else r.has(e.id)||(r.add(e.id),i.set(t,n.length),n.push(e))}return n}function Or(e,t,n){let r=new Map;for(let t of e)for(let e of t.scenarios)r.set(e.id,e);let i=new Set,a=[];for(let e of t){if(i.has(e.id))continue;if(i.add(e.id),e.kind===`custom`){a.push({id:e.id,label:e.label,hint:gr(e.prompt,56),prompt:e.prompt});continue}let t=r.get(e.id);t&&a.push(t)}return jr(a,n).slice(0,6)}function kr(e){return e<5?`chat.start.greetingDawn`:e<11?`chat.start.greetingMorning`:e<13?`chat.start.greetingNoon`:e<18?`chat.start.greetingAfternoon`:`chat.start.greetingEvening`}function Ar(e,t,n){let r=e(kr(t)),i=(n??``).trim();return i?e(`chat.start.withName`,{greeting:r,name:i}):r}function jr(e,t){return e.map((e,n)=>({scenario:e,index:n,count:t[e.id]??0})).sort((e,t)=>t.count-e.count||e.index-t.index).map(e=>e.scenario)}function Mr(e,t){return e.length===0||!t?null:e.find(e=>e.id===t)??null}var $=U()(W((e,t)=>({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0,setCategoryId:t=>e({categoryId:t,suggestionsHidden:!1}),recordUse:t=>e(e=>({clickCounts:{...e.clickCounts,[t]:(e.clickCounts[t]??0)+1},favorites:e.favorites.some(e=>e.id===t)?e.favorites:[{kind:`scenario`,id:t},...e.favorites]})),toggleFavorite:t=>e(e=>({favorites:e.favorites.some(e=>e.kind===`scenario`&&e.id===t)?e.favorites.filter(e=>e.kind!==`scenario`||e.id!==t):[{kind:`scenario`,id:t},...e.favorites]})),removeFavorite:t=>e(e=>({favorites:e.favorites.filter(e=>e.id!==t)})),addCustomFavorite:(n,r)=>{let i=r.trim();if(!i)return null;let a=vr(),o=new Set(t().favorites.map(e=>e.id));for(;o.has(a);)a=vr();let s={kind:`custom`,id:a,label:n.trim()||_r(i),prompt:i};return e(e=>({favorites:[s,...e.favorites]})),s},toggleSuggestions:()=>e(e=>({suggestionsHidden:!e.suggestionsHidden})),requestFocus:()=>e(e=>({prefillNonce:e.prefillNonce+1})),reset:()=>e({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0})}),{name:`deepseekcode-start-page-storage`,partialize:e=>({categoryId:e.categoryId,clickCounts:e.clickCounts,favorites:e.favorites,suggestionsHidden:e.suggestionsHidden}),version:2,migrate:(e,t)=>{let n=t??0;if(n>=2||!e||typeof e!=`object`)return e;let r=e,i=n<1||r.suggestionsHidden,a=n<1?Object.entries(r.clickCounts??{}).sort((e,t)=>t[1]-e[1]).slice(0,6).map(([e])=>e):r.favoriteIds??[];return{categoryId:r.categoryId??null,clickCounts:r.clickCounts??{},suggestionsHidden:i,favorites:a.map(e=>({kind:`scenario`,id:e}))}}}));function Nr(e){return typeof e!=`string`||!e?null:e.split(/[\\/]+/).pop()||null}var Pr={enabled:!0,exists:!1,name:null,file:null};function Fr(){let[e,t]=(0,Z.useState)(Pr);return(0,Z.useEffect)(()=>{let e=!1,n=()=>{ie.profile.get().then(n=>{if(e||!n.success||!n.data)return;let r=n.data,i=r.enabled!==!1,a=r.exists===!0,o={enabled:i,exists:a,name:i&&r.name?r.name:null,file:i&&a?Nr(r.path):null};t(e=>e.enabled===o.enabled&&e.exists===o.exists&&e.name===o.name&&e.file===o.file?e:o)}).catch(()=>{})};return n(),window.addEventListener(Ae,n),()=>{e=!0,window.removeEventListener(Ae,n)}},[]),e}var Ir=(0,Z.memo)(function(){return(0,Q.jsxs)(`div`,{className:`relative isolate flex min-h-[8.5rem] w-full flex-col justify-end pb-1`,children:[(0,Q.jsx)(Lr,{}),(0,Q.jsx)(Br,{})]})}),Lr=(0,Z.memo)(function(){let{t:e}=L(),{enabled:t,exists:n,name:r,file:i}=Fr(),a=(0,Z.useMemo)(()=>Ar(e,new Date().getHours(),r),[e,r]);return(0,Q.jsxs)(`div`,{className:`chat-col px-4 pt-2 sm:px-6`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl font-semibold leading-snug tracking-tight text-dark-text`,children:[(0,Q.jsx)(`span`,{className:`block`,children:a}),(0,Q.jsx)(`span`,{className:`block`,children:e(`chat.start.question`)})]}),(0,Q.jsx)(Rr,{enabled:t,exists:n,name:r,file:i})]})});function Rr({enabled:e,exists:t,name:n,file:r}){let{t:i}=L(),a=e?n?i(`chat.start.profileOn`,{name:n}):t?r?i(`chat.start.profileFile`,{file:r}):i(`chat.start.profileSet`):i(`chat.start.profileAnonymous`):i(`chat.start.profileDisabled`),o=(0,Z.useCallback)(()=>{typeof window<`u`&&window.dispatchEvent(new CustomEvent(`switch-tab`,{detail:{tab:`settings`,section:`profile`}}))},[]);return(0,Q.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:o,title:i(`chat.start.profileHint`),className:`inline-flex min-w-0 items-center gap-1.5 rounded-full border border-dark-border/70 bg-dark-surface/50 px-2.5 py-1 text-meta text-dark-muted transition-colors hover:border-accent-blue/40 hover:text-dark-text`,children:[(0,Q.jsx)(T,{size:11,"aria-hidden":`true`,className:`shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:a}),(0,Q.jsxs)(`span`,{className:`shrink-0 text-dark-muted/70`,children:[`· `,i(`chat.start.profileEdit`)]})]})})}var zr=[{glyph:`/`,labelKey:`shortcuts.slashCommand`},{glyph:`@`,labelKey:`shortcuts.fileRef`},{glyph:`!`,labelKey:`shortcuts.shellCommand`},{glyph:`$`,labelKey:`shortcuts.skillRef`}],Br=(0,Z.memo)(function(){let{t:e}=L();return(0,Q.jsx)(`ul`,{"data-testid":`start-tips`,"aria-label":e(`shortcuts.title`),className:`chat-col mt-3 flex flex-wrap items-center gap-x-4 gap-y-1.5 px-4 sm:px-6`,children:zr.map(t=>(0,Q.jsxs)(`li`,{className:`inline-flex items-center gap-1.5 text-badge text-dark-muted/60`,children:[(0,Q.jsx)(`kbd`,{className:`rounded border border-dark-border bg-dark-bg px-1.5 py-0.5 font-mono text-badge leading-none text-dark-muted`,children:t.glyph}),(0,Q.jsx)(`span`,{children:e(t.labelKey)})]},t.glyph))})}),Vr=(0,Z.memo)(function({sessionId:e,onStartTemplate:t}){let{t:n}=L(),[a,o]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;return ie.templates.list().then(t=>{!e&&t.success&&t.data&&o(t.data)}).catch(()=>{}),()=>{e=!0}},[t]);let s=(0,Z.useMemo)(()=>Dr(Sr(n),Er(a)),[n,a]),c=$(e=>e.categoryId),l=$(e=>e.setCategoryId),d=$(e=>e.clickCounts),p=$(e=>e.favorites),m=$(e=>e.recordUse),h=$(e=>e.toggleFavorite),_=$(e=>e.removeFavorite),v=$(e=>e.addCustomFavorite),b=$(e=>e.suggestionsHidden),x=$(e=>e.toggleSuggestions),S=$(e=>e.requestFocus),w=(0,Z.useMemo)(()=>Mr(s,c),[s,c]),T=(0,Z.useCallback)(()=>l(null),[l]),E=(0,Z.useMemo)(()=>w?jr(w.scenarios,d):Or(s,p,d),[w,s,p,d]),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(``),N=(0,Z.useCallback)(()=>{O(!1),A(``),M(``)},[]),P=(0,Z.useCallback)(()=>{O(!0),b&&x()},[b,x]),F=(0,Z.useCallback)(e=>{e.preventDefault(),v(k,j)&&N()},[v,N,k,j]),I=(0,Z.useCallback)(t=>{e&&(H.getState().setSessionInput(e,t.prompt),m(t.id),S())},[e,m,S]),[R,z]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(``),ee=(0,Z.useCallback)(async e=>{V(``);let t=await ie.templates.get(e);!t.success||!t.data?V(n(`templates.loadFailed`)):(z(t.data),b&&x())},[n,b,x]),U=(0,Z.useCallback)(e=>{e.kind===`template`&&e.templateId?t&&ee(e.templateId):I(e)},[t,ee,I]),W=(0,Z.useRef)([]),[G,K]=(0,Z.useState)(0),q=(0,Z.useCallback)((e,t,n)=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let n=e.key===`ArrowDown`?Math.min(t+1,E.length-1):Math.max(t-1,0);K(n),W.current[n]?.focus()}else e.key===`Tab`&&(e.preventDefault(),U(n))},[U,E.length]);return s.length===0?null:(0,Q.jsxs)(`div`,{className:`start-col max-md:order-3 px-4 pb-4 sm:px-6`,children:[(0,Q.jsxs)(`div`,{role:`tablist`,"aria-label":n(`chat.start.categoriesLabel`),onKeyDown:e=>{e.key===`Escape`&&c&&(e.preventDefault(),T())},className:`snap-row mt-5 flex items-center gap-2 overflow-x-auto pb-1`,children:[s.map(e=>{let t=e.id===c;return(0,Q.jsxs)(`span`,{"data-testid":`start-chip`,"data-category-id":e.id,"data-selected":t?`true`:void 0,className:`inline-flex shrink-0 items-center overflow-hidden rounded-full border transition-colors focus-within:ring-1 focus-within:ring-accent-blue/60 ${t?`border-transparent bg-gradient-to-r rtl:bg-gradient-to-l from-accent-blue to-accent-purple text-accent-fg shadow-sm`:`border-dark-border/70 text-dark-muted hover:border-accent-blue/40 hover:text-dark-text`}`,children:[(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,"data-testid":`start-chip-label`,onClick:()=>l(t?null:e.id),className:`py-1 text-meta transition-colors focus-visible:outline-none ${t?`ps-3 pe-1.5`:`px-3`}`,children:e.label}),t&&(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-chip-clear`,"aria-label":n(`chat.start.clearCategory`,{label:e.label}),title:n(`chat.start.clearCategory`,{label:e.label}),onClick:T,className:`py-1 pl-0 pe-2 text-accent-fg/75 transition-colors hover:text-accent-fg focus-visible:outline-none`,children:(0,Q.jsx)(C,{size:12,"aria-hidden":`true`})})]},e.id)}),(0,Q.jsx)(i,{size:13,"aria-hidden":`true`,className:`shrink-0 text-dark-muted/50`})]}),(0,Q.jsxs)(`div`,{className:`mt-2.5`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0 truncate text-meta text-dark-muted/60`,children:[w?n(`chat.start.categoryTitle`,{label:w.label}):n(`chat.start.frequentTitle`),(0,Q.jsx)(`span`,{className:`ms-2 text-dark-muted/40`,children:n(w?`chat.start.selectedHint`:`chat.start.frequentHint`)})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[!w&&!D&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`start-custom-add`,onClick:P,className:`inline-flex items-center gap-1 text-meta text-dark-muted/60 transition-colors hover:text-dark-text`,children:[(0,Q.jsx)(y,{size:11,"aria-hidden":`true`}),n(`chat.start.customAdd`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:x,className:`inline-flex items-center gap-1 text-meta text-dark-muted/60 transition-colors hover:text-dark-text`,children:b?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(u,{size:11,"aria-hidden":`true`}),n(`chat.start.show`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(f,{size:11,"aria-hidden":`true`}),n(`chat.start.hide`)]})})]})]}),B&&(0,Q.jsx)(`div`,{"data-testid":`start-template-error`,className:`mb-2 text-meta text-accent-red`,children:B}),R&&(0,Q.jsxs)(`div`,{"data-testid":`start-template-form`,className:`mb-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-xs font-medium text-dark-text`,children:R.name}),(0,Q.jsx)(Ee,{template:R,onCancel:()=>z(null),onSubmit:e=>{let n=R;z(null),t?.(n,e)},submitLabel:n(`templates.launch`)})]}),D&&!w&&(0,Q.jsxs)(`form`,{"data-testid":`start-custom-form`,onSubmit:F,className:`mb-2 flex flex-col gap-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3`,children:[(0,Q.jsx)(`input`,{"data-testid":`start-custom-label`,value:k,onChange:e=>A(e.target.value),placeholder:n(`chat.start.customLabelPlaceholder`),maxLength:40,className:`w-full rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-xs text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none`}),(0,Q.jsx)(`textarea`,{"data-testid":`start-custom-prompt`,value:j,onChange:e=>M(e.target.value),placeholder:n(`chat.start.customPromptPlaceholder`),rows:2,autoFocus:!0,className:`w-full resize-none rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-xs leading-snug text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-custom-cancel`,onClick:N,className:`rounded-md px-2.5 py-1 text-meta text-dark-muted transition-colors hover:text-dark-text`,children:n(`chat.start.customCancel`)}),(0,Q.jsx)(`button`,{type:`submit`,"data-testid":`start-custom-save`,disabled:!j.trim(),className:`rounded-md border border-accent-blue/40 bg-accent-blue/10 px-2.5 py-1 text-meta font-medium text-accent-blue transition-colors hover:bg-accent-blue/20 disabled:cursor-not-allowed disabled:border-dark-border/60 disabled:bg-transparent disabled:text-dark-muted/40`,children:n(`chat.start.customSave`)})]})]}),!b&&!R&&(E.length===0?D?null:(0,Q.jsx)(`p`,{"data-testid":`start-frequent-empty`,className:`rounded-xl border border-dashed border-dark-border/60 px-4 py-3 text-xs leading-relaxed text-dark-muted/70`,children:n(`chat.start.frequentEmpty`)}):(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-xl border border-dark-border/60 bg-dark-surface/40`,children:E.map((e,t)=>{let i=yr(p,e.id);return(0,Q.jsxs)(`div`,{"data-testid":`start-row-shell`,className:`group flex items-center transition-colors hover:bg-dark-hover/40 focus-within:bg-dark-hover/40 ${t>0?`border-t border-dark-border/40`:``}`,children:[(0,Q.jsxs)(`button`,{ref:e=>{W.current[t]=e},type:`button`,"data-testid":`start-row`,"data-scenario-id":e.id,tabIndex:t===G?0:-1,onClick:()=>U(e),onKeyDown:n=>q(n,t,e),className:`flex min-w-0 flex-1 items-baseline gap-3 py-2.5 ps-4 pe-2 text-start transition-colors focus-visible:outline-none`,children:[(0,Q.jsx)(`span`,{className:`w-[84px] shrink-0 text-compact font-medium leading-snug text-dark-text`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 border-s border-dark-border/50 ps-3 text-compact leading-snug text-dark-muted`,children:e.hint}),(0,Q.jsx)(g,{size:12,"aria-hidden":`true`,className:`mt-0.5 shrink-0 text-dark-muted/40`})]}),w?(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-row-favorite`,"aria-pressed":i,"aria-label":n(i?`chat.start.removeFavorite`:`chat.start.addFavorite`,{label:e.label}),title:n(i?`chat.start.removeFavorite`:`chat.start.addFavorite`,{label:e.label}),onClick:()=>h(e.id),className:`me-2 shrink-0 rounded-md p-1.5 transition-colors focus-visible:outline-none ${i?`text-accent-yellow`:`text-dark-muted/40 hover:text-dark-text`}`,children:(0,Q.jsx)(r,{size:13,"aria-hidden":`true`,className:i?`fill-current`:``})}):(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-row-remove`,"aria-label":n(`chat.start.removeFavorite`,{label:e.label}),title:n(`chat.start.removeFavorite`,{label:e.label}),onClick:()=>_(e.id),className:`me-2 shrink-0 rounded-md p-1.5 text-dark-muted/40 transition-colors hover:text-dark-text focus-visible:outline-none`,children:(0,Q.jsx)(C,{size:13,"aria-hidden":`true`})})]},e.id)})}))]})]})}),Hr=(0,Z.memo)(function({currentSessionId:e}){let{t}=L(),[n]=(0,Z.useState)(V),r=(0,Z.useCallback)(()=>{if(!n)return;let e=ee.getState();e.sessionTabs.some(e=>e.id===n.id)?e.setActiveSession(n.id):e.historySessions.some(e=>e.id===n.id)?e.restoreHistorySession(n.id):e.addSessionTab(n.title||void 0,n.dir||void 0,n.id),X.setSessionId(n.id)},[n]);if(!n||n.id===e)return null;let i=n.title.trim();return i?(0,Q.jsx)(`div`,{className:`mb-1 flex shrink-0 justify-center px-4 max-md:justify-start`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:r,title:t(`chat.resumeLastTitle`),"data-testid":`resume-last-session`,className:`group flex max-w-full items-center gap-1.5 rounded-full border border-dark-border/70 bg-dark-surface/50 px-2.5 py-1 text-meta leading-none text-dark-muted transition-colors hover:border-accent-blue/40 hover:bg-accent-blue/10 hover:text-dark-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60`,children:[(0,Q.jsx)(O,{size:11,className:`shrink-0 text-dark-muted/70 group-hover:text-accent-blue`}),(0,Q.jsx)(`span`,{className:`truncate`,children:t(`chat.resumeLast`,{title:i})})]})}):null});function Ur(e){let{sessionId:t,isGenerating:n,messages:r}=e,{i18n:i}=L(),a=(0,Z.useRef)(n),o=(0,Z.useRef)(t);(0,Z.useEffect)(()=>{let e=a.current,s=o.current!==t;if(a.current=n,o.current=t,s||!e||n)return;let c=me();if(c.enabled&&c.autoPlay)for(let e=r.length-1;e>=0;e--){let t=r[e];if(!t||t.type!==`assistant`)continue;let n=(t.content||``).trim();if(n){if(!De(n))return;xe(n,ae(i.language));return}}},[n,t,r,i.language]),(0,Z.useEffect)(()=>()=>Ce(),[t])}var Wr=[{mode:`chat`,Icon:o,labelKey:`trajectory.viewChat`},{mode:`trajectory`,Icon:b,labelKey:`trajectory.viewTrajectory`}],Gr=[],Kr=(0,Z.memo)(function({tabs:e,activeSessionId:t,onSend:n,onStop:r,onPause:i,onResume:a,activeTab:o,setActiveTab:s,createNewSession:c,setTheme:l,setThemePreset:u,setLogs:d,setUnreadLogs:f,onRegenerate:p,onRetryTurn:m,onDeleteMessage:h,onUndoLastUser:g,onOpenSidebarView:_,hookDrawerOpen:v,onCloseHookDrawer:y,questionDrawerOpen:b,onCloseQuestionDrawer:x,workspaceDir:S,onWorkspaceSelect:C,onNewSessionInDir:w,errorLogs:T,onOpenLogs:E,onStartTemplate:D}){let O=(0,Z.useMemo)(()=>({setActiveTab:s,createNewSession:c,setTheme:l,setThemePreset:u,setLogs:d,setUnreadLogs:f}),[s,c,l,u,d,f]),[k,A]=(0,Z.useState)(`chat`),{t:j}=L(),M=H(e=>t?e.messagesBySession[t]??Gr:Gr),N=H(e=>t?e.generatingSessions.includes(t):!1),P=H(e=>t?e.pausedSessions.includes(t):!1);Ur({sessionId:t,isGenerating:N,messages:M});let F=e.find(e=>e.id===t)||null,I=(0,Z.useMemo)(()=>M.filter(e=>!e.deleted).length===0,[M]),R=H(e=>!t||e.snapshotLoadedSessions.includes(t)),z=I&&!R;(0,Z.useEffect)(()=>{F&&!I&&B({id:F.id,title:F.title,dir:S})},[F,I,S]);let V=$(e=>e.prefillNonce),ee=(0,Z.useCallback)((e,r,i,a,o,s)=>{t&&n(t,e,r,i,a||s?{...a?{mentions:a,mentionDeliveryMode:o}:{},...s?{display:s}:{}}:void 0)},[n,t]),U=(0,Z.useCallback)(async e=>{let n=t;if(!n)return;let r=`shell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,i=Date.now();H.getState().addMessage(n,{id:r,type:`user`,content:`!${e}`,timestamp:i,noTruncate:!0,shellRun:{command:e,stdout:``,stderr:``,exitCode:null,durationMs:0,running:!0}});let a=await ie.shell.exec(e,S),o=a.success&&a.data?{...a.data,running:!1}:{command:e,stdout:``,stderr:``,exitCode:null,durationMs:Date.now()-i,running:!1,error:a.error||j(`chat.shellRequestFailedGeneric`)};H.getState().updateMessage(n,r,{shellRun:o})},[t,S,j]),W=(0,Z.useCallback)(e=>{t&&p&&p(t,e)},[p,t]),G=(0,Z.useCallback)(e=>{t&&h&&h(t,e)},[h,t]);return(0,Q.jsx)(`div`,{className:`flex-1 flex min-h-0`,children:(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[(0,Q.jsx)(hr,{}),F&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex h-7 shrink-0 items-center justify-end px-3`,children:(0,Q.jsxs)(`div`,{role:`radiogroup`,"aria-label":j(`trajectory.viewToggleTitle`),className:`relative inline-grid grid-cols-2 items-center rounded-full border border-dark-border bg-dark-surface/60 p-0.5 text-meta leading-none`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-y-0.5 left-0.5 w-[calc(50%-2px)] rounded-full ring-1 transition-transform duration-200 ease-out motion-reduce:transition-none ${k===`trajectory`?`translate-x-full bg-accent-blue/20 ring-accent-blue/40`:`translate-x-0 bg-dark-hover ring-dark-border`}`}),Wr.map(({mode:e,Icon:t,labelKey:n})=>{let r=k===e;return(0,Q.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:j(`trajectory.viewToggleTitle`),onClick:()=>A(e),className:`relative z-10 flex items-center justify-center gap-1 whitespace-nowrap rounded-full px-2.5 py-1 transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60 ${r?`text-dark-text`:`text-dark-muted hover:text-dark-text`}`,children:[(0,Q.jsx)(t,{size:11}),j(n)]},e)})]})}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col ${I&&k===`chat`?`justify-center overflow-y-auto custom-scrollbar py-2 max-md:justify-start`:``}`,children:[k===`chat`?(0,Q.jsxs)(Q.Fragment,{children:[z?(0,Q.jsx)(`div`,{className:`animate-session-switch flex items-center justify-center py-10 text-sm text-dark-muted`,role:`status`,children:j(`chat.loading`)},`restoring-${F.id}`):I?(0,Q.jsxs)(`div`,{className:`animate-session-switch`,children:[(0,Q.jsx)(Hr,{currentSessionId:F.id}),(0,Q.jsx)(Ir,{})]},`empty-${F.id}`):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col animate-session-switch`,children:(0,Q.jsx)(re,{messages:M,isGenerating:N,isPaused:P,sessionId:F.id,onRegenerate:p?W:void 0,onRetryTurn:m,onDeleteMessage:h?G:void 0,onUndoLastUser:g,onOpenSidebarView:_})},F.id),(0,Q.jsx)(dr,{sessionId:F.id})]}),(0,Q.jsx)(pr,{isOpen:!!v,onCloseModal:y}),(0,Q.jsx)(ur,{isOpen:!!b,onClose:x??(()=>{})})]}):(0,Q.jsx)(Un,{sessionId:F.id,messages:M,errorLogs:T,onOpenLogs:E}),(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(Gn,{activeSessionId:F.id})}),(0,Q.jsx)(Y,{sessionId:F.id,onSend:ee,onRunShell:U,onStop:()=>r(F.id),onPause:()=>i(F.id),onResume:()=>a(F.id),slashOptions:O,workspaceDir:S,onWorkspaceSelect:C?e=>C(e,F.id):void 0,onNewSessionInDir:w,focusRequest:V}),k===`chat`&&I&&R&&(0,Q.jsx)(Vr,{sessionId:F.id,onStartTemplate:D})]})]})]})})});export{Kr as SessionGrid};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-COiEfhsA.js";import{A as t,Ar as n,Cr as r,Dr as i,E as a,Er as o,Gn as s,Gt as c,Kn as l,Lt as u,Or as d,Qt as f,V as p,Y as m,Z as h,Zr as g,br as _,d as v,dt as y,et as b,fn as x,g as S,hr as C,ii as w,jr as T,kr as E,lr as D,n as O,p as k,q as A,qn as j,qt as M,rt as N,x as P,z as F}from"./icons-CittejKL.js";import{r as I}from"./react-vendor-BEA-EtI-.js";import{t as L}from"./useTranslation-2BGEBvJE.js";import{C as R,R as z,a as B,b as V,c as ee,d as H,f as U,j as W,z as G}from"./chatStore-D8Zzr1hE.js";import{n as K,t as te}from"./state-A4wJ8QgR.js";import{t as q}from"./Button-B43HsIQ3.js";import"./src-55YckF5W.js";import{c as ne}from"./DiffPreview-WQihq3bK.js";import{a as re,c as J,d as ie,i as ae,l as oe,n as se,o as ce,r as le,s as ue,t as de,u as fe}from"./InputArea-CSqaA55j.js";import{h as pe,m as me}from"./sttLanguages-jnSk4aqg.js";import{t as he}from"./api-BW4-5gtM.js";import{j as ge}from"./settingsStore-DYqiXodu.js";import{I as _e}from"./markdown-DZQBOzWk.js";import{n as Y}from"./websocket-DCs7f54y.js";import{t as X}from"./cn-CoHJgTJ5.js";import"./common-CP2UB8TN.js";import{i as ve}from"./useConfirm-kTv3x0H6.js";import{f as ye,ft as be,g as xe,h as Se,it as Ce,lt as we,m as Te,p as Ee,rt as De,ut as Oe,y as ke}from"./index-CxrzleFg.js";import{t as Ae}from"./profileChange-xrd7jkii.js";var Z=e(w(),1);function je(e){return e.recordId===void 0?e.callId===void 0?e.sourceSeq===void 0?`${e.kind}\u0000index\u0000${e.index}`:`${e.kind}\u0000seq\u0000${e.sourceSeq}`:`${e.kind}\u0000call\u0000${e.callId}`:e.recordId}function Me(e){return ne(e===null?null:e*1e3)}var Ne=2048,Pe=512;function Fe(e){return e.replace(/```[^\n]*\n([\s\S]*?)```/g,`$1`).replace(/`([^`]+)`/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/^#{1,6}\s+/gm,``).replace(/^[ \t]*[-*+]\s+/gm,``).replace(/^[ \t]*>\s?/gm,``).replace(/(\*\*|__)(.*?)\1/g,`$2`).replace(/(\*|_)(.*?)\1/g,`$2`).replace(/~~(.*?)~~/g,`$1`)}function Ie(e){let t=e.slice(0,Ne),n=Fe(t).replace(/\s+/g,` `).trim(),r=n.slice(0,Pe).trimEnd();return t.length<e.length||r.length<n.length?`${r}…`:r}function Le(e){if(Number.isFinite(e))return Me(e)}function Re(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function ze(e){if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return``}}function Be(e){if(typeof e==`string`)return e;if(e==null)return``;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Ve(e){if(e.status===`error`)return{result:e.result===void 0?`error`:Be(e.result)};let t=Be(e.result);return t===``?{result:`No output`}:{result:``,resultPreviewMarkdown:t}}function He(e,t){let n=t?.get(e.id)??null,r=e.summary?.durationMs===void 0?null:(n??e.timestamp)+e.summary.durationMs,i=n!==null||r!==null;if(i)return{timingRecorded:i,stepStartTime:e.timestamp,firstTokenTime:n,completedTime:r,usageProvided:!1,outputTokens:null}}function Ue(e,t,n){let r=e.thinkingBlocks?e.thinkingBlocks.map(e=>e.text).join(`
|
|
2
|
+
`):e.thinking??``,i=He(e,n),a=e.summary?.durationMs;return{index:t,kind:`message`,text:``,...e.content===``?{}:{previewMarkdown:e.content},sourceSeq:t,inputDetail:e.content,...r===``?{}:{thinkingDetail:r},...i===void 0?{}:{assistantMetrics:i},timeSeconds:a===void 0?null:a/1e3,startedAt:e.timestamp}}function We(e,t){let n=ze(e.args),r=Be(e.result),i=Ve(e);return{index:t,kind:`tool`,text:e.name,...n===``?{}:{previewMarkdown:n},sourceSeq:t,callId:e.id,...n===``?{}:{inputDetail:n},...r===``?{}:{outputDetail:r},...i,isError:e.status===`error`,timeSeconds:e.duration===void 0?null:e.duration/1e3,startedAt:e.timestamp}}function Ge(e,t){return{index:t,kind:`user`,text:``,...e.content===``?{}:{previewMarkdown:e.content},sourceSeq:t,inputDetail:e.content,opensTurn:!0,timeSeconds:0,startedAt:e.timestamp}}function Ke(e,t){let n=[e.originalCount===void 0?``:`original ${e.originalCount} msgs`,e.compressedCount===void 0?``:`compressed ${e.compressedCount} msgs`,e.tokensSaved===void 0?``:`freed ${e.tokensSaved} tokens`].filter(Boolean).join(`, `);return{index:t,kind:`compacted`,text:`Context compressed`,sourceSeq:e.seq,...n===``?{}:{outputDetail:n},timeSeconds:0,startedAt:e.timestamp}}function qe(e){let t=[],n=[];for(let t of e)t.absTime!==null&&Number.isFinite(t.absTime)&&(n.push(t.absTime),t.cell.kind===`tool`&&t.cell.timeSeconds!==null&&Number.isFinite(t.cell.timeSeconds)&&n.push(t.absTime+t.cell.timeSeconds*1e3));if(n.length>=2){let e=Le((Math.max(...n)-Math.min(...n))/1e3);e!==void 0&&t.push(e)}else if(n.length===1){let r=e.find(e=>e.absTime===n[0])?.cell.timeSeconds,i=r==null?void 0:Le(r);i!==void 0&&t.push(i)}let r=new Map;for(let t of e)t.toolName!==void 0&&t.cell.kind===`tool`&&r.set(t.toolName,(r.get(t.toolName)??0)+1);for(let[e,n]of r)t.push(n>1?`${e}×${n}`:e);return t.length===0?void 0:t.join(` `)}function Je(e,t){return{turn:e,groups:t.groups.map(({title:e,laid:t})=>{let n=qe(t);return{title:e,...n===void 0?{}:{description:n},cells:t.map(e=>e.cell)}})}}function Ye(e){return Math.min(...e.groups.flatMap(e=>e.cells.map(e=>e.index)),1/0)}function Xe(e){let{messages:t,compacted:n=[],ttft:r}=e,i=new Map,a=[],o=0,s=0,c=null,l=e=>{let t=i.get(e);return t===void 0&&(t={groups:[]},i.set(e,t)),t},u=(e,t)=>{let n=l(e).groups,r=n[n.length-1];r?.title===`Message`?r.laid.push(t):n.push({title:`Message`,laid:[t]})},d=(e,t,n)=>{if(n.length===0)return;let r=l(e).groups,i=`Step ${t}`,a=r.find(e=>e.title===i);a===void 0?r.push({title:i,laid:[...n]}):a.laid.push(...n)},f=[...t.map(e=>({kind:`message`,message:e})),...n.map(e=>({kind:`compacted`,record:e}))].sort((e,t)=>(e.kind===`message`?e.message.timestamp:e.record.timestamp)-(t.kind===`message`?t.message.timestamp:t.record.timestamp));for(let e of f){if(e.kind===`compacted`){let t=Ke(e.record,++o);a.push({groups:[{title:`Compaction ${e.record.seq}`,laid:[{absTime:Re(e.record.timestamp),cell:t}]}]});continue}let t=e.message;if(z(t)){s+=1;let e=Ge(t,++o);u(s,{absTime:Re(t.timestamp),cell:e});continue}let n=s>0?s:c??1,i=G(t)?Ge(t,++o):Ue(t,++o,r);u(n,{absTime:Re(t.timestamp),cell:i}),c=n;for(let e of t.toolCalls??[]){let t=We(e,++o);u(n,{absTime:Re(e.timestamp),toolName:e.name,callId:e.id,cell:t})}for(let[e,r]of(t.steps??[]).entries()){let t=(r.toolCalls??[]).map(e=>{let t=We(e,++o);return{absTime:Re(e.timestamp),toolName:e.name,callId:e.id,cell:t}});d(n,e+1,t)}}return[...[...i.entries()].map(([e,t])=>Je(e,t)),...a.map(e=>Je(null,e))].sort((e,t)=>Ye(e)-Ye(t))}function Ze(e){if(e.text!==``)return e.text;if(e.previewMarkdown!==void 0){let t=Ie(e.previewMarkdown);if(t!==``)return t}if(e.result!==void 0&&e.result!==``)return e.result;if(e.resultPreviewMarkdown!==void 0){let t=Ie(e.resultPreviewMarkdown);if(t!==``)return t}return e.kind}function Qe(e){return ne(e)}function $e(e){return e===`tool`||e===`subtool`?2:+(e===`message`||e===`compacted`)}function et(e){return e!=null&&Number.isFinite(e)}function tt(e){if(!et(e.startedAt))return null;let t=et(e.timeSeconds)?Math.max(0,e.timeSeconds*1e3):0;return{start:e.startedAt,end:e.startedAt+t}}function nt(e,t=`sequence`){if(t!==`sequence`)return rt(e,t===`duration`);let n=[],r=[];for(let t of e){let e=t.groups.flatMap(e=>e.cells.filter(e=>e.requestOnly!==!0));e.length!==0&&(t.turn!==null&&r.push({turn:t.turn,time:n.length}),n.push(...e.map((e,t)=>({start:n.length+t,end:n.length+t+1,index:e.index,isError:e.isError===!0,kind:e.kind,label:e.text,lane:$e(e.kind)}))))}return n.length===0?null:{start:0,end:n.length,spans:n,turnBoundaries:r}}function rt(e,t){let n=e.flatMap(e=>{let t=e.groups.flatMap(e=>e.cells.flatMap(e=>{if(e.requestOnly===!0)return[];let t=tt(e);return t===null?[]:[{...t,index:e.index,isError:e.isError===!0,kind:e.kind,label:e.text,lane:$e(e.kind)}]}));return t.length===0?[]:[{turn:e.turn,rawSpans:t}]}),r=n.flatMap(e=>e.rawSpans);if(r.length===0)return null;let i=new Map,a=0,o=null;for(let e of[...r].sort((e,t)=>e.start-t.start||e.end-t.end))t&&o!==null&&e.start>o&&(a+=e.start-o),i.set(e,a),o=o===null?e.end:Math.max(o,e.end);let s=[],c=[];for(let e of n){let t=e.rawSpans.map(e=>{let t=i.get(e)??0;return{...e,start:e.start-t,end:e.end-t}});s.push(...t),e.turn!==null&&c.push({turn:e.turn,time:Math.min(...t.map(e=>e.start))})}return{start:Math.min(...s.map(e=>e.start)),end:Math.max(...s.map(e=>e.end)),spans:s,turnBoundaries:c}}function it(e,t,n=`sequence`){let r=nt(e,n);return new Set(r?.spans.filter(e=>e.start<=t.end&&e.end>=t.start).map(e=>e.index))}function at(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function ot(e){if(e.previewMarkdown===void 0)return``;let t=Ie(e.previewMarkdown);return e.text===``?t:t===``?e.text:`${e.text} · ${t}`}function st(e){return e.resultPreviewMarkdown===void 0?e.result??``:Ie(e.resultPreviewMarkdown)}function ct(e,t,n){let r=[...n.sourceBlocks??[],...n.outputBlocks??[]];return[e===null?`between turns`:`turn ${e}`,t,n.kind,n.kind===`message`?`assistant`:``,n.text,n.previewMarkdown??``,n.inputDetail??``,n.outputDetail??``,n.thinkingDetail??``,n.schemaDetail??``,n.result??``,n.resultPreviewMarkdown??``,n.callId??``,...r.flatMap(e=>[e.type,e.content,e.callId??``,e.toolName??``,e.imageAlt??``])]}var lt=class{entries=new Map;layouts;update(e){if(this.layouts===e)return!1;this.layouts=e;let t=new Set;for(let n of e)for(let e of n)for(let n of e.groups)for(let r of n.cells){if(r.requestOnly===!0)continue;let i=je(r),a=ct(e.turn,n.title,r),o=this.entries.get(i),s=o!==void 0&&at(o.sources,a)?o:{sources:a,text:[...a,ot(r),st(r)].join(`
|
|
3
|
+
`).toLocaleLowerCase()};this.entries.set(i,s),t.add(i)}for(let e of this.entries.keys())t.has(e)||this.entries.delete(e);return!0}search(e){let t=e.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);if(t.length===0)return null;let n=new Set;for(let[e,r]of this.entries)t.every(e=>r.text.includes(e))&&n.add(e);return n}},Q=_e(),ut=(0,Z.memo)(function({actualDuration:e,onActualDurationChange:t,allTurnsCollapsed:n,onToggleAllTurns:i,allAssistantsCollapsed:a,onToggleAllAssistants:s,searchQuery:c,onSearchQueryChange:l}){let{t:u}=L();return(0,Q.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center gap-1 border-b border-dark-border/40 px-2`,role:`toolbar`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60`,"aria-pressed":e,title:u(e?`trajectory.toolbar.equalWidth`:`trajectory.toolbar.actualDuration`),onClick:()=>t(!e),children:[(0,Q.jsx)(P,{size:13}),u(`trajectory.toolbar.duration`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60`,"aria-pressed":n,title:u(n?`trajectory.toolbar.expandTurns`:`trajectory.toolbar.collapseTurns`),onClick:i,children:[n?(0,Q.jsx)(o,{size:13}):(0,Q.jsx)(r,{size:13}),u(`trajectory.toolbar.turns`)]}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60`,"aria-pressed":a,title:u(a?`trajectory.toolbar.expandCalls`:`trajectory.toolbar.collapseCalls`),onClick:s,children:[(0,Q.jsx)(f,{size:13}),u(`trajectory.toolbar.calls`)]}),(0,Q.jsx)(`div`,{className:`ms-auto flex min-w-0 flex-1 items-center justify-end`,children:(0,Q.jsxs)(`div`,{className:`relative flex w-56 items-center`,children:[(0,Q.jsx)(m,{size:12,className:`pointer-events-none absolute start-2 text-dark-muted/50`}),(0,Q.jsx)(`input`,{type:`search`,className:`h-7 w-full rounded border border-dark-border/40 bg-dark-surface/60 ps-7 pe-2 text-xs text-dark-text outline-none placeholder:text-dark-muted/40 focus:border-accent-blue/50`,"aria-label":u(`trajectory.toolbar.search`),placeholder:u(`trajectory.toolbar.searchPlaceholder`),value:c,onChange:e=>l(e.currentTarget.value)})]})})]})}),dt=3,ft=500,pt=8,mt=8;function ht(e){let t=e?.stepStartTime,n=e?.firstTokenTime,r=e?.completedTime;return e?.timingRecorded!==!0||typeof t!=`number`||typeof n!=`number`||typeof r!=`number`||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||n<t||r<n?{}:{ttftMs:n-t,decodingMs:r-n}}function gt(e){let t=e.timeSeconds===null||!Number.isFinite(e.timeSeconds)?void 0:Math.max(0,e.timeSeconds*1e3),n=e.startedAt===null||!Number.isFinite(e.startedAt)?void 0:e.startedAt;return{...t===void 0?{}:{durationMs:t},...n===void 0?{}:{startedAt:n},...ht(e.assistantMetrics)}}function _t(e){switch(e){case`system`:return`SYSTEM`;case`user`:return`USER`;case`context`:return`CONTEXT`;case`compacted`:return`COMPACTED`;case`message`:return`ASSISTANT`;case`tool`:return`TOOL`;case`subtool`:return`SUBTOOL`}}function vt(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}.${(e=>String(e).padStart(3,`0`))(t.getMilliseconds())}`}function yt(e,t){let n=_t(e);if(t===void 0)return n;let r=t.durationMs===void 0?null:`Total ${Qe(t.durationMs)}`;return[n,t.startedAt===void 0?null:t.durationMs===void 0?`Started ${vt(t.startedAt)}`:`${vt(t.startedAt)} → ${vt(t.startedAt+t.durationMs)}`,[r,t.ttftMs===void 0||t.decodingMs===void 0?null:`TTFT ${Qe(t.ttftMs)} · Decoding ${Qe(t.decodingMs)}`].filter(e=>e!==null).join(` · `)].filter(e=>e!==null&&e!==``).join(`
|
|
4
|
+
`)}function bt(e,t){return e<=t?{start:e,end:t}:{start:t,end:e}}function xt(e){return Math.min(1,Math.max(0,e))}var St=(0,Z.memo)(function({turns:e,mode:t,range:n,selectedIndex:r=null,searchMatchIndexes:i=null,onRangeChange:a,onRecordSelect:o}){let s=(0,Z.useMemo)(()=>nt(e,t),[t,e]),c=(0,Z.useMemo)(()=>new Map(e.flatMap(e=>e.groups.flatMap(e=>e.cells.map(e=>[e.index,gt(e)])))),[e]),l=(0,Z.useMemo)(()=>new Map(e.flatMap(e=>e.groups.flatMap(e=>e.cells.map(e=>[e.index,Ze(e)])))),[e]),u=(0,Z.useRef)(null),d=(0,Z.useRef)(null),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),g=(0,Z.useRef)(null),_=(0,Z.useRef)(null),[v,y]=(0,Z.useState)(1),b=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{s!==null&&n!==null&&(n.end<s.start||n.start>s.end)&&a(null)},[s,a,n]),(0,Z.useLayoutEffect)(()=>{let e=b.current,t=_.current;b.current=null,e!==null&&t!==null&&(t.scrollLeft=e.fraction*t.scrollWidth-e.contentOffsetPx)},[v]);let x=(0,Z.useRef)(()=>{});if((0,Z.useEffect)(()=>{let e=u.current;if(!e)return;let t=e=>{e.preventDefault(),x.current(e)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[s]),s===null)return(0,Q.jsxs)(`div`,{className:`traj-root`,"data-empty":``,children:[(0,Q.jsxs)(`div`,{className:`traj-labels`,"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{children:`Input`}),(0,Q.jsx)(`span`,{children:`Model`}),(0,Q.jsx)(`span`,{children:`Tools`})]}),(0,Q.jsx)(`div`,{className:`traj-track`})]});let S=Math.max(1,s.end-s.start),C=Math.max(1,s.spans.length)*pt*v,w=e=>{let t=u.current;if(!t)return 0;let n=t.getBoundingClientRect();return xt((e-n.left)/Math.max(1,n.width))},T=e=>s.start+e*S,E=e=>{if(e.button===2){a(null);return}let t=e.target.closest(`[data-timeline-record-index]`),n=t===null?null:Number(t.dataset.timelineRecordIndex);n!==null&&Number.isFinite(n)?o?.(n):(d.current={pointerId:e.pointerId,anchorFraction:w(e.clientX),anchorClientX:e.clientX,recordIndex:null},e.currentTarget.setPointerCapture(e.pointerId))},D=e=>{let t=d.current;if(t!==null&&e.pointerId===t.pointerId){let n=w(e.clientX);if(Math.abs(e.clientX-t.anchorClientX)>=dt){let e=T(t.anchorFraction),r=T(n);p(bt(e,r))}return}let n=w(e.clientX),r=e.target.closest(`[data-timeline-record-index]`),i=r===null?null:Number(r.dataset.timelineRecordIndex);g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{h({fraction:n,recordIndex:Number.isFinite(i)?i:null})},ft)},O=e=>{let t=d.current;t!==null&&e.pointerId===t.pointerId&&(d.current=null,f!==null&&(a(f),p(null)))},k=e=>{d.current?.pointerId===e.pointerId&&(d.current=null,p(null))};x.current=e=>{if(s===null)return;let t=_.current;if(t===null)return;if(e.ctrlKey||e.metaKey||e.altKey){let n=Math.min(mt,Math.max(1,v*(e.deltaY<0?1.25:.8)));if(n===v)return;let r=u.current;if(r!==null){let n=r.getBoundingClientRect();b.current={fraction:xt((e.clientX-n.left)/Math.max(1,n.width)),contentOffsetPx:e.clientX-t.getBoundingClientRect().left}}y(n);return}let n=e.deltaX===0?e.deltaY:e.deltaX;n!==0&&(t.scrollLeft+=n)};let A=f??n,j=m?.recordIndex;return(0,Q.jsxs)(`div`,{ref:_,className:`traj-root`,children:[(0,Q.jsxs)(`div`,{className:`traj-labels`,"aria-hidden":`true`,children:[(0,Q.jsx)(`span`,{children:`Input`}),(0,Q.jsx)(`span`,{children:`Model`}),(0,Q.jsx)(`span`,{children:`Tools`})]}),(0,Q.jsxs)(`div`,{ref:u,className:`traj-track`,style:{width:`max(100%, ${C}px)`},role:`slider`,"aria-label":`Trajectory timeline`,tabIndex:0,onKeyDown:e=>{e.key===`Escape`&&a(null)},onPointerDown:E,onPointerMove:D,onPointerUp:O,onPointerCancel:k,onPointerLeave:()=>{g.current&&clearTimeout(g.current),g.current=null,d.current===null&&h(null)},onDoubleClick:e=>{e.preventDefault(),a(null)},onContextMenu:e=>{e.preventDefault(),a(null)},children:[m!==null&&m.recordIndex===null&&f===null&&(0,Q.jsx)(`div`,{className:`traj-hoverLine`,"aria-hidden":`true`,style:{"--trajectory-hover-left":`${m.fraction*100}%`}}),A!==null&&(0,Q.jsx)(`div`,{className:`traj-selection`,"data-dragging":f===null?void 0:`true`,"aria-hidden":`true`,style:{"--trajectory-selection-left":`${(A.start-s.start)/S*100}%`,"--trajectory-selection-width":`${(A.end-A.start)/S*100}%`}}),(0,Q.jsx)(`div`,{className:`traj-turnBoundaries`,"aria-hidden":`true`,children:s.turnBoundaries.filter(e=>e.time>s.start).map(e=>(0,Q.jsx)(`span`,{className:`traj-turnBoundary`,"data-turn":e.turn,style:{"--trajectory-turn-left":`${(e.time-s.start)/S*100}%`}},e.turn))}),(0,Q.jsx)(`div`,{className:`traj-lanes`,"data-timeline-domain":``,children:s.spans.map(e=>{let t=(e.start-s.start)/S,n=(e.end-e.start)/S*100,a=c.get(e.index),o=a?.ttftMs,u=a?.decodingMs,d=o===void 0||u===void 0||o+u<=0?null:o/(o+u),f=l.get(e.index)??e.label;return(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`traj-span`,"data-timeline-span":e.kind,"data-timeline-record-index":e.index,"data-assistant-timing":d===null?void 0:`true`,"data-error":e.isError||void 0,"data-current":e.index===r||void 0,"data-hovered":j===e.index||void 0,"data-search-match":i===null?void 0:i.has(e.index)?`true`:`false`,"data-selected":A===null?void 0:e.start<=A.end&&e.end>=A.start?`true`:`false`,title:yt(e.kind,a),style:{"--trajectory-span-left":`${t*100}%`,"--trajectory-span-width":`${n}%`,"--trajectory-span-lane":e.lane,...d===null?{}:{"--trajectory-assistant-ttft":`${d*100}%`}},children:(0,Q.jsx)(`span`,{className:`traj-spanLabel`,children:f})},e.index)})})]})]})}),Ct=I();function wt(e){return typeof e==`object`?e.key:e}function Tt(e,t){let n=e.length;return new Proxy(e,{get(e,r,i){if(typeof r==`string`){let i=r.charCodeAt(0);if(i>=48&&i<=57){let i=+r;if(Number.isInteger(i)&&i>=0&&i<n){let n=e[i];if(typeof n!=`object`){let r=t[i*2];n=e[i]={index:i,key:n,start:r,size:t[i*2+1],end:r+t[i*2+1],lane:0}}return n}}if(r===`length`)return n}return Reflect.get(e,r,i)}})}function Et(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return(o.length!==r.length||o.some((e,t)=>r[t]!==e))&&(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1),i}return o.updateDeps=e=>{r=e},o}function Dt(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var Ot=(e,t)=>Math.abs(e-t)<1.01,kt=(e,t,n)=>{let r;return Object.assign(function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)},{cancel:()=>{e.clearTimeout(r)}})};function At({offset:e,isScrolling:t,elementMax:n,holdOffset:r,scrollOffset:i,pendingWrite:a,clampedMaxAtWrite:o}){return t&&a===null&&e===i?`spurious`:a!==null&&Math.abs(e-a.target)<1.5?`readBack`:a!==null&&!a.smooth&&n!==null&&a.target>n+r+.5&&Math.abs(e-(n+r))<1.5||a!==null&&!a.smooth&&a.lowMaxes?.some(t=>Math.abs(e-t)<1.5)?`clampedReadBack`:o!==null&&Math.abs(e-o)<1.5?`clampedEcho`:`external`}var jt=e=>e===`smooth`||e===`smoothFinishing`;function Mt({kind:e,offset:t,command:n,target:r}){return e!==`spurious`&&e!==`readBack`&&e!==`clampedReadBack`&&n?.index!=null&&n.phase!==`queued`&&!jt(n.phase)&&!Ot(t,n.lastTargetOffset)&&!Ot(t,r())&&e!==`clampedEcho`}var Nt=40;function Pt(e){let t=e[e.length-1];if(t===void 0)return!1;let n=e.length-2;for(;n>=0&&t.t-e[n].t<Nt;)n--;if(n<0)return!1;let r=e[n],i=n-1;for(;i>=0&&r.t-e[i].t<Nt;)i--;if(i<0)return!1;let a=e[i],o=(t.offset-r.offset)/(t.t-r.t),s=(r.offset-a.offset)/(r.t-a.t);return o*s>=0&&Math.abs(o)>=2*Math.abs(s)&&Math.abs(o)-Math.abs(s)>=.8}function Ft(e){let t=e[e.length-1];if(t===void 0)return!1;let n=e.length-2;for(;n>=0&&t.t-e[n].t<Nt;)n--;if(n<0)return!1;let r=e[n];return Math.abs(t.offset-r.offset)/(t.t-r.t)>=.05}var It,Lt=()=>{if(It!==void 0)return It;if(typeof navigator>`u`)return It=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return It=!0;let e=navigator.maxTouchPoints;return It=navigator.platform===`MacIntel`&&e!==void 0&&e>0},Rt,zt=()=>Rt===void 0?Rt=Lt()&&typeof CSS<`u`&&typeof CSS.supports==`function`&&CSS.supports(`overflow-anchor: auto`):Rt,Bt={capture:!0,passive:!0},Vt=class{constructor(e){this.host=e,this._touch=null,this.inMotion=()=>this._touch!==null&&this._touch.phase!==`lateFling`,this.dragging=()=>this._touch?.phase===`down`&&this._touch.moved,this.tail=()=>this._touch?.phase===`tail`?this._touch.moved?`fling`:`tap`:null,this.onScroll=({isScrolling:e,ownReadBack:t,moved:n,external:r})=>(e&&this._touch?.phase===`tail`?this._openTail(this._touch.moved||!t,!1):this._touch?.phase===`lateFling`&&(this.host.now()>this._touch.until?this._touch=null:r&&e&&n&&this._openTail(!0,!1)),!t&&e&&n&&this._touch?.phase===`down`?(this._touch.moved=!0,!0):!1),this.touchStart=()=>{this.end(),this._touch={phase:`down`,moved:!1}},this.touchEnd=()=>{let e=this._touch?.phase===`down`&&this._touch.moved;this.end(),this._openTail(e,e)},this.end=()=>{let e=this.host.getWindow();this._touch?.phase===`tail`&&e!=null&&e.clearTimeout(this._touch.timerId),this._touch=null},this.listen=e=>{let t=()=>this.touchStart(),n=()=>this.touchEnd();return e.addEventListener(`touchstart`,t,Bt),e.addEventListener(`touchend`,n,Bt),e.addEventListener(`touchcancel`,n,Bt),()=>{e.removeEventListener(`touchstart`,t,Bt),e.removeEventListener(`touchend`,n,Bt),e.removeEventListener(`touchcancel`,n,Bt),this.end()}},this._openTail=(e,t)=>{let n=this.host.getWindow();if(!Lt()||n==null)return;this.end();let r={phase:`tail`,moved:e,awaitingFling:t,timerId:n.setTimeout(()=>{this.host.tailStillMoving()?this._openTail(r.moved,r.awaitingFling):(this._touch=r.awaitingFling?{phase:`lateFling`,until:this.host.now()+1e3}:null,this.host.onTailClosed())},150)};this._touch=r}}get touch(){return this._touch}},Ht=e=>{let{clientWidth:t,clientHeight:n}=e;return{width:t,height:n}},Ut=e=>{let t=new Set;return{schedule:n=>{let r=e.requestAnimationFrame(()=>{t.delete(r),n()});t.add(r)},cancel:()=>{t.forEach(t=>e.cancelAnimationFrame(t)),t.clear()}}},Wt=e=>e,Gt=e=>{let t=e.overscan*Math.max(e.lanes??1,1),n=Math.max(e.startIndex-t,0),r=Math.min(e.endIndex+t,e.count-1)-n+1,i=Array(r);for(let e=0;e<r;e++)i[e]=n+e;return i},Kt=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(Ht(n)),!r.ResizeObserver)return()=>{};let a=Ut(r),o=new r.ResizeObserver(()=>{let t=()=>{i(Ht(n))};e.options.useAnimationFrameWithResizeObserver?a.schedule(t):t()});return o.observe(n,{box:`content-box`}),()=>{o.unobserve(n),a.cancel()}},qt={passive:!0},Jt=typeof window>`u`||`onscrollend`in window,Yt=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Jt,o=0,s=a?null:kt(i,()=>t(n(r),!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,qt),a&&r.addEventListener(`scrollend`,u,qt),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u),s?.cancel()}},Xt=(e,t)=>Yt(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),Zt=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},Qt=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},$t=(e,t)=>e===`smooth`?t?`smoothLanded`:`smooth`:`instant`,en=e=>e?.phase===`smooth`||e?.phase===`smoothLanded`;function tn(e,t,n,r){if(t===0)return!1;let i=r(0),a=new Set,o=0;for(;o<e;){let e=n(o);if(e===i)break;a.add(e),o++}let s=e-o;if(s===0||s>=t)return!1;for(let e=0;e<s;e++)if(r(e)!==n(o+e))return!1;for(let e=s;e<t;e++)if(a.has(r(e)))return!1;return!0}var nn=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._iosGesture=new Vt({getWindow:()=>this.targetWindow,now:()=>this.now(),tailStillMoving:()=>{let e=this.scrollState;if(e?.phase!==`queued`||this.pendingWrite!==null)return!1;let t=this._readElementOffset();return t===null||this._lastElementOffset===null||Math.abs(t-this._lastElementOffset)<1?!1:(this._lastElementOffset=t,e.samples=[...e.samples??[],{t:this.now(),offset:t}],!0)},onTailClosed:()=>{let e=this.scrollState;e?.phase===`queued`&&Ft(e.samples??[])&&(this.scrollState=null),this._flushHoldIfReady(!0),this._writeAwaitingCommand()}}),this._lastElementOffset=null,this.pendingWrite=null,this._clampedAdjustment=null,this.elementsCache=new Map,this._resizeBatch=null,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=null,n=()=>{if(e)return e;let n=this.targetWindow;if(!n||!n.ResizeObserver)return null;let i=t=Ut(n);return e=new n.ResizeObserver(e=>{let t=()=>{let t={sync:!1};this._resizeBatch=t;try{e.forEach(r)}finally{this._resizeBatch=null,t.notify&&(this.notify(t.sync),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment())}};this.options.useAnimationFrameWithResizeObserver?i.schedule(t):t()})},r=e=>{let t=e.target,n=this.indexFromElement(t);if(t.isConnected)this.isIndexInRange(n)&&this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this));else{this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}}};return{disconnect:()=>{var r;(r=n())==null||r.disconnect(),t?.cancel(),e=null,t=null},observe:e=>n()?.observe(e,{box:`border-box`}),unobserve:e=>n()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Wt,rangeExtractor:Gt,onChange:()=>{},measureElement:Zt,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=this._singleLaneMeasurements?.items??s,l=e=>wt(c[e]),u=e>0?l(0):null,d=e>0?l(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==u||t.getItemKey(o-1)!==d)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>0&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==d)&&(o>e||tn(e,o,l,t.getItemKey))&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=null;if(r&&this.scrollOffset!==null&&!this._awaitingCommandReadBack()){let[e,t]=r,n=this.getMeasurements(),{count:a,getItemKey:s}=this.options,c=0;for(;c<a&&s(c)!==e;)c++;if(c<a){let e=n[c];if(e){let n=Math.max(0,e.start+t);!i&&n!==this.scrollOffset&&(o=n-this.scrollOffset,this.scrollOffset=n)}}}i?this.pendingScrollAnchor={kind:`follow`,behavior:i}:o!==null&&(this._canWriteScroll()?this.pendingScrollAnchor={kind:`anchor`,delta:o}:(this._holdOffset+=o,this._followOffsetTarget(o)))},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=Et(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{var e;this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,(e=this._momentumStop)==null||e.restore(),this._momentumStop=null,this.isScrolling=!1,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._clampedAdjustment=null,this.pendingWrite=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}this.scrollElement=e,this.targetWindow=this.scrollElement&&`ownerDocument`in this.scrollElement?this.scrollElement.ownerDocument.defaultView:this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{let n=t?this._elementMaxScrollOffset():null,r=this._reportedOverscroll;this._reportedOverscroll=e<0||n!==null&&e>n+1;let i=e;this._lastElementOffset=i,e=this._toLayoutOffset(e);let a=this._classifyScrollEvent(e,t,n);if(a===`spurious`)return;a===`readBack`?e=this.pendingWrite.target:a===`clampedReadBack`&&this.scrollState?.index!=null&&e<this.getMaxScrollOffset()-1.5?this.scrollState.lastTargetOffset=e:Mt({kind:a,offset:e,command:this.scrollState,target:()=>this.getScrollStateTarget(this.scrollState)})&&(this.scrollState=null),this.pendingWrite=null,this._clampedAdjustment!==null&&Math.abs(e-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null);let o=this.getScrollOffset(),s=this.scrollDirection;this.scrollDirection=t?o===e?this.scrollDirection:o<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t;let c=this.scrollState;if(c?.phase===`queued`&&a===`external`&&t){if(r||this._reportedOverscroll)c.samples=[];else{let e=this.now();c.samples=[...(c.samples??[]).filter(t=>e-t.t<=200),{t:e,offset:i}],(s!==null&&this.scrollDirection!==s||Pt(c.samples))&&(this.scrollState=null)}}this._iosGesture.onScroll({isScrolling:t,ownReadBack:a===`readBack`,moved:e!==o,external:a===`external`&&this.scrollState?.phase!==`smooth`&&this.scrollState?.phase!==`smoothFinishing`})&&this.scrollState?.phase===`queued`&&(this.scrollState=null),this._flushHoldIfReady(!0),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement&&this.unsubs.push(this._iosGesture.listen(this.scrollElement)),this._scrollToOffset(this.getScrollOffset())}this._noteClampMax();let t=this.pendingScrollAnchor;this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled&&(t.kind===`anchor`?this._canWriteScroll()?en(this.scrollState)&&!Ot(this.getScrollOffset()-t.delta,this.scrollState.lastTargetOffset)||(this._followOffsetTarget(t.delta),this._scrollToOffset(this.getScrollOffset())):(this._holdOffset+=t.delta,this._followOffsetTarget(t.delta),this.notify(!1)):this.scrollToEnd({behavior:t.behavior})),this._flushHoldIfReady(!1),this._retryClampedAdjustment()},this._classifyScrollEvent=(e,t,n)=>At({offset:e,isScrolling:t,elementMax:n,holdOffset:this._holdOffset,scrollOffset:this.scrollOffset,pendingWrite:this.pendingWrite,clampedMaxAtWrite:this._clampedAdjustment?.maxAtWrite??null}),this._retryClampedAdjustment=()=>{if(this._clampedAdjustment===null||!this.scrollElement||!this.options.enabled)return;let{target:e,maxAtWrite:t}=this._clampedAdjustment,n=this.getMaxScrollOffset();n>t+.5&&(this._clampedAdjustment=e>n+.5?{target:e,maxAtWrite:n}:null,this._scrollToOffset(e))},this._writeAwaitingCommand=()=>{let e=this.scrollState;if(e===null||e.phase!==`queued`)return;let{behavior:t}=e;this.getMeasurements();let n=this.getScrollStateTarget(e);e.lastTargetOffset=n,this._clampedAdjustment=null,e.phase=$t(t,e.index!=null&&Ot(n,this.getScrollOffset())),this._scrollToOffset(n,{behavior:t}),this.scheduleScrollReconcile()},this._readElementOffset=()=>{let e=this.scrollElement;if(e==null)return null;let{horizontal:t,isRtl:n}=this.options;return typeof e.scrollTop==`number`?t?e.scrollLeft*(n&&-1||1):e.scrollTop:typeof e.scrollY==`number`?t?e.scrollX:e.scrollY:null},this._canWriteScroll=()=>!(Lt()&&this._iosGesture.inMotion())&&!this._reportedOverscroll,this._flushHoldIfReady=e=>{if(this._holdOffset===0||!this.scrollElement||!this.options.enabled||!this._canWriteScroll()||this.scrollState?.phase===`smooth`)return;this._holdOffset=0,this.scrollOffset!==null&&this.scrollOffset<0&&(this.scrollOffset=0),this.notify(e);let t=this.getCommandWrittenOffset()??this.getScrollOffset();this._clampedAdjustment=this._clampedBy(t),this._scrollToOffset(t)},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Et(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(e,t,n,r,i,a,o,s)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s}),{key:!1}),this.isIndexInRange=e=>e>=0&&e<this.options.count,this.getMeasurements=Et(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o,gap:s},c)=>{let l=this.itemSizeCache;if(!i)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=e*2,a=this._singleLaneMeasurements?.flat;if(!a||a.length<i){let e=new Float64Array(i);a&&u>0&&e.set(a.subarray(0,u*2)),a=e}let o=u===0?Array(e):this._singleLaneMeasurements.items.slice(),c;if(u===0)c=t+n;else{let e=u-1;c=a[e*2]+a[e*2+1]+s}for(let t=u;t<e;t++){let e=r(t);o[t]=e;let n=l.get(e),i=typeof n==`number`?n:this.options.estimateSize(t);a[t*2]=c,a[t*2+1]=i,c+=i+s}this._singleLaneMeasurements={flat:a,items:o};let d=Tt(o,a);return this.measurementsCache=d,d}let d=this.measurementsCache.slice(0,u),f=Array(a).fill(void 0),p=new Float64Array(a),m=0;for(let e=0;e<u;e++){let t=d[e];t&&(f[t.lane]===void 0&&m++,f[t.lane]=e,p[t.lane]=t.end)}for(let i=u;i<e;i++){let e=r(i),c=this.laneAssignments.get(i),u,h,g=o===`estimate`||l.has(e);if(c!==void 0&&this.options.lanes>1){u=c;let e=f[u],r=e===void 0?void 0:d[e];h=r?r.end+s:t+n}else if(m===a){let e=0,t=p[0],n=f[0];for(let r=1;r<a;r++){let i=p[r];(i<t||i===t&&f[r]<n)&&(e=r,t=i,n=f[r])}u=e,h=t+s,g&&this.laneAssignments.set(i,u)}else u=i%this.options.lanes,h=t+n,g&&this.laneAssignments.set(i,u);let _=l.get(e),v=typeof _==`number`?_:this.options.estimateSize(i),y=h+v;d[i]={index:i,start:h,size:v,end:y,key:e,lane:u},f[u]===void 0&&m++,f[u]=i,p[u]=y}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Et(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=on(e,t,n,r,r===1&&this._singleLaneMeasurements!==null?this._singleLaneMeasurements.flat:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Et(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t,this.options.lanes]},(e,t,n,r,i,a)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n,lanes:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!en(this.scrollState))return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e);if(!this.isIndexInRange(t))return;let n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),e.isConnected&&(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{var n;if(!this.isIndexInRange(e))return;this._resizeBatch?.sync&&this.getMeasurements();let r,i,a,o=this._singleLaneMeasurements?.flat;if(this.options.lanes===1&&o!=null)a=this.options.getItemKey(e),i=o[e*2],r=o[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;a=t.key,i=t.start,r=t.size}let s=this.itemSizeCache.get(a)??r,c=t-s;if(c!==0){let o=this.options.anchorTo===`end`&&!en(this.scrollState)&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,l=o?this._getLayoutTotalSize():0,u=this.getScrollOffset(),d=this.itemSizeCache.has(a)?i+s<=u&&this.scrollDirection!==`backward`:i<u,f=!en(this.scrollState)&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?d:this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:a,start:i,size:r,end:i+r,lane:0},c,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(a,t),this.itemSizeCacheVersion++;let p=!1;if(this._awaitingCommandReadBack()||(o?p=this.applyScrollAdjustment(this._getLayoutTotalSize()-l):f&&(p=this.applyScrollAdjustment(c))),this._resizeBatch){this._resizeBatch.notify=!0,(n=this._resizeBatch).sync||(n.sync=p);return}this.notify(p),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment()}},this.getVirtualItems=Et(()=>[this.getVirtualIndexes(),this.getMeasurements(),this._holdOffset],(e,t,n)=>{let r=[];for(let i=0,a=e.length;i<a;i++){let a=t[e[i]];r.push(n===0?a:{...a,start:a.start-n,end:a.end-n})}return r},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._singleLaneMeasurements?.flat,r=this.options.lanes===1&&n!=null;return Dt(t[rn(0,t.length-1,r?e=>n[e*2]:e=>Dt(t[e]).start,e)])},this._noteClampMax=()=>{if(!this._awaitingCommandReadBack())return;let e=this._elementMaxScrollOffset();if(e===null)return;let t=this.pendingWrite,n=Math.max(e,0)+this._holdOffset;if(n>=t.target)return;let r=t.lowMaxes??=[];r[r.length-1]!==n&&r.push(n)},this.getMaxScrollOffset=()=>(this._elementMaxScrollOffset()??0)+this._holdOffset,this._toLayoutOffset=e=>{let t=e+this._holdOffset;return this.pendingScrollAnchor?.kind===`anchor`&&(t+=this.pendingScrollAnchor.delta),t},this._elementMaxScrollOffset=()=>{let e=this.scrollElement;if(e===null)return null;if(`scrollHeight`in e)return this.options.horizontal?e.scrollWidth-e.clientWidth:e.scrollHeight-e.clientHeight;if(`document`in e){let t=e.document.documentElement;return this.options.horizontal?t.scrollWidth-e.innerWidth:t.scrollHeight-e.innerHeight}return null},this._momentumStop=null,this._stopMomentum=e=>{let t=this.scrollElement,n=this.targetWindow;if(t===null||n===null)return;let r=`document`in t?t.document.scrollingElement:t;if(!r?.style)return;if(this._momentumStop){this._momentumStop.done=e;return}let{style:i}=r,a=this.options.horizontal?`overflow-x`:`overflow-y`,o=i.getPropertyValue(a),s=i.getPropertyPriority(a);i.setProperty(a,`hidden`,`important`);let c={restore:()=>i.getPropertyValue(a)!==`hidden`||i.getPropertyPriority(a)!==`important`?!1:(i.setProperty(a,o,s),!0),done:e};this._momentumStop=c,n.requestAnimationFrame(()=>n.requestAnimationFrame(()=>{this._momentumStop===c&&(this._momentumStop=null,c.restore()&&c.done())}))},this._clampedBy=e=>{let t=this._elementMaxScrollOffset();if(t===null)return null;let n=t+this._holdOffset;return e>n+.5?{target:e,maxAtWrite:n}:null},this.getVirtualDistanceFromEnd=()=>Math.max(this._getLayoutTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`){if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t]}if(t===`end`&&e===this.options.count-1){let e=this.getMaxScrollOffset(),n=e-this.options.paddingEnd+this.options.scrollPaddingEnd;return[Math.max(Math.min(n,e),0),t]}let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{this._startScroll({index:null,align:t},this.getOffsetForAlignment(e,t),n,`absolute`)},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r;this._startScroll({index:e,align:a},i,n,`absolute`)},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getOffsetForAlignment((this.getCommandWrittenOffset()??this.getScrollOffset())+e,`start`);this._startScroll({index:null,align:`start`},n,t,`relative`)},this.scrollToEnd=({behavior:e=`auto`}={})=>{this.options.count>0?this._startScroll({index:this.options.count-1,align:`end`,toEnd:!0},Math.max(this.getMaxScrollOffset(),0),e,`absolute`):this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.cancelScroll=()=>{this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null},this.getTotalSize=()=>Math.max(this._getLayoutTotalSize()-this._holdOffset,0),this._getLayoutTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._singleLaneMeasurements?.flat;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n}={})=>{let r={target:e+(t??0),smooth:n===`smooth`};return this.pendingWrite=r,this.options.scrollToFn(e-this._holdOffset,{behavior:n,adjustments:t},this),r},this.getCommandWrittenOffset=()=>this.scrollState!==null&&this.pendingWrite!==null&&!this.pendingWrite.smooth?this.pendingWrite.target:null,this._awaitingCommandReadBack=()=>{let e=this.getCommandWrittenOffset();return!(Lt()&&this._iosGesture.dragging())&&e!==null&&!Ot(e,this.getScrollOffset())},this._followOffsetTarget=e=>{this.scrollState!==null&&this.scrollState.index==null&&(this.scrollState.lastTargetOffset+=e)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}get scrollAdjustments(){return 0}applyScrollAdjustment(e,t){if(e===0)return!1;if(this._followOffsetTarget(e),this._canWriteScroll()){let n=this.getScrollOffset();this._clampedAdjustment=this._clampedBy(n+e);let r=this._scrollToOffset(n,{adjustments:e,behavior:t});return this.scrollOffset!==null&&(this.pendingWrite===r&&(this.scrollOffset+=e),this.scrollOffset<0&&(this.scrollOffset=0)),!0}return this._holdOffset+=e,this.scrollOffset!==null&&(this.scrollOffset+=e),!0}scheduleScrollReconcile(){this.targetWindow?this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}):this.scrollState=null}getScrollStateTarget(e){let t=e.toEnd?[Math.max(this.getMaxScrollOffset(),0)]:e.index==null?void 0:this.getOffsetForIndex(e.index,e.align);return t?t[0]:e.lastTargetOffset}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}if(this.scrollState.phase===`queued`){this.scheduleScrollReconcile();return}this.getMeasurements();let e=this.getScrollStateTarget(this.scrollState),t=this.scrollState.index==null?1:this.options.useAnimationFrameWithResizeObserver?3:2,n=e!==this.scrollState.lastTargetOffset;if(!n&&Ot(e,this.getScrollOffset())){if(this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothLanded`:this.scrollState.phase===`smoothFinishing`&&(this.scrollState.phase=`instant`),this.scrollState.stableFrames++,this.scrollState.stableFrames>=t){this.getScrollOffset()!==e&&this._scrollToOffset(e,{behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let t=this.getSize()||600,n=Math.abs(e-this.getScrollOffset()),r=en(this.scrollState)&&n>t;this.scrollState.lastTargetOffset=e,r?this.scrollState.phase=`smooth`:this.scrollState.phase===`smooth`?this.scrollState.phase=`smoothFinishing`:this.scrollState.phase===`smoothLanded`&&(this.scrollState.phase=`instant`),this._scrollToOffset(e,{behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}_startScroll(e,t,n,r){let i=this._iosGesture.tail();if(r===`absolute`&&i!==null){if(i===`fling`&&zt()){this._stopMomentum(()=>{this.scrollState?.phase!==`queued`||this._iosGesture.tail()!==`fling`||this._reportedOverscroll||(this._iosGesture.end(),this._flushHoldIfReady(!0),this._writeAwaitingCommand())}),this.scrollState={...e,startedAt:this.now(),lastTargetOffset:t,stableFrames:0,phase:`queued`,behavior:n,samples:[]},this.scheduleScrollReconcile();return}this._iosGesture.end()}this.scrollState={...e,startedAt:this.now(),lastTargetOffset:t,stableFrames:0,behavior:n,phase:$t(n,e.index!=null&&Ot(t,this.getScrollOffset()))},this._scrollToOffset(t,{behavior:n}),this.scheduleScrollReconcile()}},rn=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function an(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function on(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=an(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=rn(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var sn=typeof document<`u`?Z.useLayoutEffect:Z.useEffect;function cn({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=Z.useReducer(e=>e+1,0)[1],a=Z.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=Z.useRef(!1),s=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}},c=(e,t,n)=>{let r=a.current,i=!!e.options.horizontal,o=t.start-e.options.scrollMargin;r.lastPositions.get(n)!==o&&(r.lastPositions.set(n,o),r.mode===`transform`?n.style.transform=i?`translate3d(${o}px, 0, 0)`:`translate3d(0, ${o}px, 0)`:n.style[i?`left`:`top`]=`${o}px`)},l=e=>{let t=a.current;if(t.enabled&&t.container){s(e);for(let t of e.getVirtualItems()){let n=e.elementsCache.get(t.key);n&&c(e,t,n)}}},u={...r,onChange:(t,n)=>{var s;let c=a.current,u=!0;if(c.enabled){l(t);let e=t.range,n=c.prevRange;u=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,u&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}u&&(e&&n&&!o.current?(0,Ct.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[d]=Z.useState(()=>{let e=new nn(u),t=e.measureElement;return e.measureElement=n=>{o.current=!0;try{t(n)}finally{o.current=!1}let r=a.current;if(n!==null&&r.enabled&&r.container){let t=e.measurementsCache[e.indexFromElement(n)];t&&c(e,t,n)}},Object.assign(e,{containerRef:t=>{let n=a.current;n.container=t,n.lastSize=null,t!==null&&l(e)}})});return d.setOptions(u),sn(()=>d._didMount(),[]),sn(()=>(s(d),d._willUpdate())),sn(()=>{l(d)}),d}function ln(e){return cn({observeElementRect:Kt,observeElementOffset:Xt,scrollToFn:Qt,...e})}var un=30,dn=20,fn=26,pn=22,mn=9;function hn(e){let t=encodeURIComponent(je(e.cell));return e.collapsedSummaryKind===void 0?t:`${t}\u0000summary\u0000${e.collapsedSummaryKind}`}function gn(e){if(e.collapsedSummaryKind!==void 0)return dn;let t=un;return e.turnStart===!0&&e.turn!==null&&e.turn!==void 0&&(t+=fn),e.groupStart===!0&&(t+=pn),t}function _n(e){let t=[],n=[];for(let[r,i]of e.entries()){let e={logicalIndex:r,record:i};if(i.cell.requestOnly===!0){n.push(e);continue}let a=[...n,e];n=[],t.push({entries:a,height:a.reduce((e,t)=>e+gn(t.record),0),key:hn(i)})}return n.length>0&&t.push({entries:n,height:mn,key:n.map(e=>hn(e.record)).join(`|`)}),t}var vn=[`Input`,`Output`,`Think`,`Time`],yn=(0,Z.memo)(function({turn:e}){return(0,Q.jsxs)(`div`,{className:`sticky top-0 z-10 flex h-[26px] items-center border-b border-dark-border/40 bg-dark-surface/95 px-2 backdrop-blur`,children:[(0,Q.jsxs)(`span`,{className:`text-meta font-semibold text-dark-text`,children:[`Turn `,e]}),(0,Q.jsx)(`div`,{className:`ms-auto flex items-center gap-3 pe-1 text-badge text-dark-muted/50`,"aria-hidden":`true`,children:vn.map(e=>(0,Q.jsx)(`span`,{className:`w-12 text-end`,children:e},e))})]})}),bn=(0,Z.memo)(function({title:e,description:t}){return(0,Q.jsxs)(`div`,{className:`flex h-[22px] items-center gap-2 px-2 text-meta`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-dark-muted`,children:e}),t!==void 0&&t!==``&&(0,Q.jsx)(`span`,{className:`truncate text-dark-muted/50`,children:t})]})}),xn={system:`System`,user:`User`,context:`Context`,compacted:`Compacted`,message:`Message`,tool:`Tool`,subtool:`Sub`},Sn={system:`bg-dark-surface text-dark-muted border-dark-border/40`,user:`bg-accent-blue/10 text-accent-blue border-accent-blue/30`,context:`bg-dark-surface text-dark-muted border-dark-border/40`,compacted:`bg-accent-yellow/15 text-accent-yellow border-accent-yellow`,message:`bg-accent-green/10 text-accent-green border-accent-green/30`,tool:`bg-accent-purple/10 text-accent-purple border-accent-purple/30`,subtool:`bg-dark-surface text-dark-muted border-dark-border/40`},Cn=(0,Z.memo)(function({cell:e,selected:t=!1,onClick:n}){let{index:r,kind:i,timeSeconds:a,input:o,output:s,think:c}=e,l=Ze(e),u=i===`message`;return(0,Q.jsxs)(`div`,{className:[`flex h-[30px] items-center gap-2 border-b border-dark-border/20 px-2 text-xs cursor-pointer select-none`,t?`bg-accent-blue/10`:`hover:bg-dark-surface/40`].join(` `),"data-kind":i,"data-selected":t||void 0,onClick:()=>n?.(r),children:[(0,Q.jsxs)(`span`,{className:`w-10 shrink-0 text-end tabular-nums text-dark-muted/50`,children:[`#`,r]}),(0,Q.jsx)(`span`,{className:`w-[74px] shrink-0`,children:(0,Q.jsx)(`span`,{className:[`inline-block rounded border px-1 py-px text-badge leading-none`,Sn[i]].join(` `),children:xn[i]})}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-dark-text`,title:l,children:l}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2 tabular-nums text-dark-muted/60`,children:[u&&(0,Q.jsxs)(Q.Fragment,{children:[o!==void 0&&(0,Q.jsx)(`span`,{title:`Input tokens`,children:o}),s!==void 0&&(0,Q.jsx)(`span`,{title:`Output tokens`,children:s}),c!==void 0&&(0,Q.jsx)(`span`,{title:`Reasoning tokens`,children:c})]}),(0,Q.jsx)(`span`,{className:`w-16 text-end`,children:Me(a)})]})]})}),wn=100,Tn=12,En=600,Dn=2;function On(e){let t=(0,Z.useRef)({rows:[],structure:[]});if(t.current.rows===e)return t.current.structure;let n=t.current.structure.length===e.length&&e.every((e,n)=>{let r=t.current.structure[n];return r?.key===e.key&&r.height===e.height})?t.current.structure:e.map(e=>({key:e.key,height:e.height}));return t.current={rows:e,structure:n},n}function kn(e){let t=[];for(let n of e){let e=[];for(let t of n.groups)t.cells.forEach((r,i)=>{e.push({turn:n.turn,group:t.title,groupDescription:t.description,groupStart:i===0,turnStart:e.length===0,cell:r,turnEnd:!1})});if(e.length>0){let t=e[e.length-1];t&&(t.turnEnd=!0)}t.push(...e)}return t}function An(e,t){let n=[],r=[],i=null,a=()=>{if(r.length!==0){if(i!==null&&t.has(i)){let e=r.filter(e=>e.cell.requestOnly!==!0&&e.cell.kind!==`system`),t=r[0];n.push({...t,groupStart:!0,turnStart:!0,turnEnd:!0,collapsedSummary:`Turn ${i} · ${e.length} records`,collapsedSummaryKind:`turn`,cell:{...t.cell,index:t.cell.index}})}else n.push(...r);r=[],i=null}};for(let t of e)t.turnStart&&a(),i=t.turn,r.push(t);return a(),n}function jn(e,t){let n=[],r=0;for(;r<e.length;){let i=e[r],a=e[r+1];if(i.cell.kind===`message`&&a!==void 0&&(a.cell.kind===`tool`||a.cell.kind===`subtool`)&&t.has(je(i.cell))){let t=r+1;for(;t<e.length&&(e[t].cell.kind===`tool`||e[t].cell.kind===`subtool`);)t+=1;let a=t-r-1;n.push({...i,groupStart:!0,turnEnd:e[t-1]?.turnEnd??i.turnEnd,collapsedSummary:`${Ze(i.cell)||`Message`} · ${a} tool call${a>1?`s`:``}`,collapsedSummaryKind:`assistant`}),r=t}else n.push(i),r+=1}return n}function Mn(e,t){let n=[],r=null,i=null;for(let a of e){if(a.turnStart&&(r=a),a.groupStart&&(i=a),!t.has(a.cell.index))continue;let e=a;r!==null&&n.length===0&&(r===a?e={...e,groupStart:!0,turnStart:!0}:n.push({...r,groupStart:!0,turnStart:!0}),r=null),i!==null&&n.length>0&&n[n.length-1].group!==a.group&&(i===a?e={...e,groupStart:!0}:n.push({...i,groupStart:!0,turnStart:!1}),i=null),n.push(e)}return n}function Nn(e){if(e===null||!Number.isFinite(e))return`Not available`;let t=new Date(e),n=e=>String(e).padStart(2,`0`),r=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}.${(e=>String(e).padStart(3,`0`))(t.getMilliseconds())}`;return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`} ${r}`}function Pn(e){let t=[{id:`overview`,label:`Summary`}];return e.inputDetail!==void 0&&e.inputDetail!==``&&t.push({id:`input`,label:`Input`}),e.outputDetail!==void 0&&e.outputDetail!==``&&t.push({id:`output`,label:`Output`}),e.thinkingDetail!==void 0&&e.thinkingDetail!==``&&t.push({id:`thinking`,label:`Thinking`}),e.assistantMetrics!==void 0&&t.push({id:`timing`,label:`Timing`}),(e.input!==void 0||e.output!==void 0||e.think!==void 0)&&t.push({id:`usage`,label:`Usage`}),t}function Fn({cell:e,onClose:t}){let n=Pn(e),[r,i]=(0,Z.useState)(n[0]?.id??`overview`),a=Ze(e);return(0,Q.jsxs)(`div`,{className:`flex h-full w-[360px] shrink-0 flex-col border-s border-dark-border/40 bg-dark-surface/40`,children:[(0,Q.jsxs)(`div`,{className:`flex h-9 shrink-0 items-center justify-between border-b border-dark-border/40 px-3`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-medium text-dark-text`,children:[`Record #`,e.index]}),(0,Q.jsx)(`button`,{type:`button`,className:`rounded p-1 text-dark-muted hover:bg-dark-surface/60`,onClick:t,"aria-label":`Close details`,children:(0,Q.jsx)(O,{size:14})})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-1 border-b border-dark-border/40 px-2 py-1.5`,children:n.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:`traj-detailTab`,"data-active":r===e.id||void 0,onClick:()=>i(e.id),children:e.label},e.id))}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(()=>{switch(r){case`overview`:return(0,Q.jsxs)(`dl`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Kind`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.kind})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Index`}),(0,Q.jsxs)(`dd`,{className:`traj-detailValue`,children:[`#`,e.index]})]}),e.callId!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Call ID`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue break-all`,children:e.callId})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Duration`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Me(e.timeSeconds)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Started`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Nn(e.startedAt??null)})]}),e.isError===!0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-20 shrink-0`,children:`Status`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue text-accent-red`,children:`error`})]}),a!==``&&(0,Q.jsxs)(`div`,{className:`pt-1`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey mb-1`,children:`Summary`}),(0,Q.jsx)(`dd`,{className:`traj-detailBody`,children:a})]})]});case`input`:return(0,Q.jsx)(`div`,{className:`traj-detailBody`,children:e.inputDetail});case`output`:return(0,Q.jsx)(`div`,{className:`traj-detailBody`,children:e.outputDetail});case`thinking`:return(0,Q.jsx)(`div`,{className:`traj-detailBody`,children:e.thinkingDetail});case`timing`:{let t=e.assistantMetrics;if(!t)return null;let n=t.firstTokenTime!==null&&t.stepStartTime!==null?t.firstTokenTime-t.stepStartTime:null,r=t.completedTime!==null&&t.firstTokenTime!==null?t.completedTime-t.firstTokenTime:null;return(0,Q.jsxs)(`dl`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Step start`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Nn(t.stepStartTime)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`First token`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:Nn(t.firstTokenTime)})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`TTFT`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:n===null?`—`:`${n} ms`})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Decoding`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:r===null?`—`:`${r} ms`})]})]})}case`usage`:return(0,Q.jsxs)(`dl`,{className:`space-y-1.5`,children:[e.input!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Input`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.input})]}),e.output!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Output`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.output})]}),e.think!==void 0&&(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`dt`,{className:`traj-detailKey w-24 shrink-0`,children:`Reasoning`}),(0,Q.jsx)(`dd`,{className:`traj-detailValue`,children:e.think})]}),e.input===void 0&&e.output===void 0&&e.think===void 0&&(0,Q.jsx)(`div`,{className:`traj-detailValue`,children:`Token usage not reported by provider yet.`})]});default:return null}})()})]})}function In({turns:e,searchMatchIndexes:t=null,selectedIndex:n,onSelectIndex:r,onDeselect:i,onClearSelection:a,collapsedTurns:o,onToggleTurn:s,collapsedAssistants:c,onToggleAssistant:l}){let u=(0,Z.useRef)(null),d=(0,Z.useMemo)(()=>kn(e),[e]),f=(0,Z.useMemo)(()=>n===null?void 0:d.find(e=>e.cell.index===n),[d,n]),p=(0,Z.useMemo)(()=>{if(t!==null)return Mn(d,t);let e=o.size===0?d:An(d,o);return c.size===0?e:jn(e,c)},[d,c,o,t]),m=(0,Z.useMemo)(()=>_n(p),[p]),h=On(m),g=p.length>wn,_=(0,Z.useCallback)(e=>h[e]?.height??30,[h]),v=(0,Z.useCallback)(e=>h[e]?.key??e,[h]),y=(0,Z.useCallback)(()=>u.current,[]),b=ln({count:g?h.length:0,enabled:g,estimateSize:_,getItemKey:v,getScrollElement:y,initialRect:{width:0,height:En},overscan:Tn,scrollEndThreshold:Dn}),x=g?b.getVirtualItems():[],S=g?b.getTotalSize():0,C=(0,Z.useRef)(!1);(0,Z.useLayoutEffect)(()=>{if(C.current||t!==null)return;let e=u.current;e!==null&&p.length!==0&&(e.scrollHeight>e.clientHeight&&(e.scrollTop=e.scrollHeight),C.current=!0)},[p.length,t]),(0,Z.useLayoutEffect)(()=>{if(t===null)return;let e=u.current;e!==null&&p.length!==0&&(e.scrollTop=0,C.current=!0)},[t,p.length]);let w=e=>{r(e)},T=e=>e.collapsedSummary===void 0?(0,Q.jsxs)(Q.Fragment,{children:[e.turnStart&&e.turn!==null&&(0,Q.jsx)(yn,{turn:e.turn}),e.groupStart&&(0,Q.jsx)(bn,{title:e.group,description:e.groupDescription}),(0,Q.jsx)(Cn,{cell:e.cell,selected:n===e.cell.index,onClick:w})]}):(0,Q.jsxs)(`div`,{className:`flex h-[20px] cursor-pointer items-center gap-2 px-2 text-xs text-dark-muted hover:bg-dark-surface/40`,onClick:()=>{e.collapsedSummaryKind===`turn`&&e.turn!==null?s(e.turn):e.collapsedSummaryKind===`assistant`&&l(je(e.cell))},children:[(0,Q.jsx)(`span`,{className:`text-dark-muted/50`,children:`▸`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.collapsedSummary})]});return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Q.jsx)(`div`,{ref:u,className:`min-w-0 flex-1 overflow-auto`,onClick:e=>{e.target===e.currentTarget&&a?.()},children:g?(0,Q.jsx)(`div`,{style:{height:S,position:`relative`},children:x.map(e=>{let t=m[e.index];return t?(0,Q.jsx)(`div`,{"data-virtual-row-key":t.key,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`,height:t.height},children:t.entries.map(e=>(0,Q.jsx)(`div`,{children:T(e.record)},hn(e.record)))},t.key):null})}):p.map(e=>(0,Q.jsx)(`div`,{children:T(e)},hn(e)))}),f!==void 0&&(0,Q.jsx)(Fn,{cell:f.cell,onClose:i},f.cell.index)]})}function Ln(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}var Rn=(0,Z.memo)(function({errors:e,onOpenLogs:t}){let{t:r}=L(),[a,o]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),l=(0,Z.useMemo)(()=>e.filter(e=>e.level===`error`),[e]);if((0,Z.useEffect)(()=>{c(e=>e!==null&&l.length>e?null:e)},[l.length]),l.length===0||s!==null)return null;let u=l[l.length-1];if(u===void 0)return null;let d=l.slice(-20).reverse();return(0,Q.jsxs)(`div`,{"data-trajectory-error-banner":``,className:`mx-2 mt-1 shrink-0 rounded-md border border-accent-red/50 bg-accent-red/10 text-xs`,role:`alert`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 text-accent-red`,children:[(0,Q.jsx)(S,{size:14,className:`shrink-0`,"aria-hidden":`true`}),(0,Q.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-start`,onClick:()=>o(e=>!e),title:r(a?`trajectory.errorBanner.collapse`:`trajectory.errorBanner.expand`),children:[(0,Q.jsxs)(`span`,{className:`shrink-0 font-semibold`,children:[r(`trajectory.errorBanner.title`),l.length>1&&(0,Q.jsxs)(`span`,{className:`ms-1.5 rounded bg-accent-red px-1.5 py-0.5 text-badge font-semibold text-accent-fg`,children:[`×`,l.length]})]}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-dark-text`,children:[Ln(u.timestamp),` · `,u.message]}),a?(0,Q.jsx)(i,{size:14,className:`shrink-0`,"aria-hidden":`true`}):(0,Q.jsx)(n,{size:14,className:`shrink-0`,"aria-hidden":`true`})]}),t&&(0,Q.jsxs)(`button`,{type:`button`,className:`flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-accent-red hover:bg-accent-red/15`,onClick:t,title:r(`trajectory.errorBanner.viewLogs`),children:[(0,Q.jsx)(h,{size:12,"aria-hidden":`true`}),r(`trajectory.errorBanner.viewLogs`)]}),(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-0.5 text-dark-muted hover:bg-accent-red/15 hover:text-accent-red`,onClick:()=>{c(l.length),o(!1)},title:r(`trajectory.errorBanner.dismiss`),children:(0,Q.jsx)(O,{size:14,"aria-hidden":`true`})})]}),a&&(0,Q.jsx)(`div`,{className:`max-h-40 overflow-y-auto border-t border-accent-red/30 px-2 py-1.5 font-mono text-meta custom-scrollbar`,children:d.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 py-0.5`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 text-dark-muted`,children:Ln(e.timestamp)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-accent-red px-1 py-0.5 text-avatar font-semibold uppercase leading-none text-accent-fg`,children:e.source}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 whitespace-pre-wrap break-all text-dark-text`,children:e.message})]},e.id))})]})}),zn=new Set,Bn=new Set,Vn=[],Hn=3e3;function Un({sessionId:e,messages:t,errorLogs:n,onOpenLogs:r}){let[i,a]=(0,Z.useState)(zn),[o,s]=(0,Z.useState)(Bn),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(``),[m]=(0,Z.useState)(()=>new lt),[h,g]=(0,Z.useState)(0),_=(0,Z.useRef)(null),v=(0,Z.useRef)(!1),[y,b]=(0,Z.useState)(null),x=xe(t=>t.compactedBySession[e]??Wn),S=xe(t=>t.ttftBySession[e]),C=(0,Z.useMemo)(()=>{if(S!==void 0)return new Map(Object.entries(S))},[S]),w=(0,Z.useMemo)(()=>Xe({messages:t,compacted:x,ttft:C}),[t,x,C]),T=u?`duration`:`sequence`;(0,Z.useEffect)(()=>(_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{m.update([w]),g(e=>e+1),v.current=!0},v.current?Hn:0),()=>{_.current&&clearTimeout(_.current)}),[w,m]);let E=(0,Z.useMemo)(()=>f.trim()===``?null:m.search(f),[f,h]),D=(0,Z.useMemo)(()=>{if(E===null)return null;let e=new Set;for(let t of w)for(let n of t.groups)for(let t of n.cells)E.has(je(t))&&e.add(t.index);return e},[w,E]),O=(0,Z.useMemo)(()=>c===null?null:it(w,c,T),[w,T,c]),k=(0,Z.useMemo)(()=>(n??Vn).filter(t=>t.sessionId===e),[n,e]),A=(0,Z.useMemo)(()=>r?()=>r(e):void 0,[r,e]),j=(0,Z.useMemo)(()=>w.filter(e=>e.turn!==null&&e.groups.reduce((e,t)=>e+t.cells.filter(e=>e.requestOnly!==!0&&e.kind!==`system`).length,0)>1).flatMap(e=>e.turn===null?[]:[e.turn]),[w]),M=j.length>0&&j.every(e=>i.has(e)),N=(0,Z.useMemo)(()=>{let e=[];for(let t of w){let n=t.groups.flatMap(e=>e.cells);for(let t=0;t<n.length;t++){let r=n[t];if(r?.kind!==`message`)continue;let i=n[t+1];(i?.kind===`tool`||i?.kind===`subtool`)&&e.push(je(r))}}return e},[w]),P=N.length>0&&N.every(e=>o.has(e)),F=(0,Z.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),I=(0,Z.useCallback)(()=>{a(e=>{let t=new Set(e);if(M)for(let e of j)t.delete(e);else for(let e of j)t.add(e);return t})},[M,j]),L=(0,Z.useCallback)(e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),R=(0,Z.useCallback)(()=>{s(e=>{let t=new Set(e);if(P)for(let e of N)t.delete(e);else for(let e of N)t.add(e);return t})},[P,N]),z=(0,Z.useCallback)(e=>{l(e)},[]),B=(0,Z.useCallback)(e=>{O!==null&&!O.has(e)&&l(null),b(t=>t===e?null:e)},[O]),V=(0,Z.useCallback)(()=>{b(null)},[]),ee=(0,Z.useCallback)(()=>{l(null),b(null)},[]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,"data-conversation-composer-overlay":``,children:[(0,Q.jsx)(ut,{actualDuration:u,onActualDurationChange:e=>{d(e),l(null)},allTurnsCollapsed:M,onToggleAllTurns:I,allAssistantsCollapsed:P,onToggleAllAssistants:R,searchQuery:f,onSearchQueryChange:p}),(0,Q.jsx)(Rn,{errors:k,onOpenLogs:A}),(0,Q.jsx)(St,{turns:w,mode:T,range:c,selectedIndex:y,searchMatchIndexes:D,onRangeChange:z,onRecordSelect:B}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,Q.jsx)(In,{turns:w,searchMatchIndexes:D,selectedIndex:y,onSelectIndex:B,onDeselect:V,onClearSelection:ee,collapsedTurns:i,onToggleTurn:F,collapsedAssistants:o,onToggleAssistant:L})})]})}var Wn=[],Gn=(0,Z.memo)(function({activeSessionId:e}){let{t}=L(),n=be(e=>e.observed).filter(t=>t.id!==e);return n.length===0?null:(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-col gap-1.5`,children:[n.map(e=>(0,Q.jsx)(Kn,{id:e.id,title:e.title},e.id)),(0,Q.jsx)(`span`,{className:`sr-only`,children:t(`chat.observedTitle`)})]})});function Kn({id:e,title:t}){let{t:n}=L(),r=B(t=>t.generatingSessions?.includes(e)??!1),i=B(t=>{let n=t.messagesBySession[e];return!!(n&&n.length>0?n[n.length-1]:void 0)?.errorCard}),a=B(t=>{let n=t.messagesBySession[e];if(!n||n.length===0)return``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t.type===`user`)continue;let r=t.content||``;if(r.trim())return r.trim().slice(-160)}return``}),o=n(r?`chat.observedRunning`:i?`chat.observedFailed`:`chat.observedDone`);return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs`,children:[(0,Q.jsx)(v,{size:13,className:`shrink-0 text-accent-blue`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`max-w-[180px] truncate font-medium text-dark-text`,title:t,children:t}),(0,Q.jsx)(`span`,{className:`shrink-0 text-badge text-dark-muted`,children:e.slice(0,8)}),r?(0,Q.jsx)(M,{size:12,className:`shrink-0 animate-spin text-accent-yellow`,"aria-hidden":`true`}):i?(0,Q.jsx)(C,{size:12,className:`shrink-0 text-accent-red`,"aria-hidden":`true`}):(0,Q.jsx)(_,{size:12,className:`shrink-0 text-accent-green`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`shrink-0 text-badge ${i?`text-accent-red`:r?`text-accent-yellow`:`text-accent-green`}`,children:o}),a&&(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-dark-muted/80`,title:a,children:a})]})}function qn({isOpen:e,onClose:t,title:r,collapsedSummary:i,badge:a,leading:o,children:s,maxHeight:c=`45vh`,onExpandedChange:l,alignToComposer:u=!1,className:d}){let{t:f}=L(),[p,m]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{e&&m(!0)},[e]),(0,Z.useEffect)(()=>{l?.(p)},[p,l]),ve({isOpen:e,onClose:t,lockScroll:!1});let h=(0,Z.useCallback)(()=>{m(e=>!e)},[]);return e?(0,Q.jsx)(`div`,{className:X(`shrink-0`,u&&`chat-drawer-col`),children:(0,Q.jsxs)(`div`,{className:X(`bg-dark-overlay/95 ui-surface-overlay backdrop-blur shadow-drawer`,u?`overflow-hidden rounded-xl border border-dark-border`:`border-t border-dark-border`,d),children:[(0,Q.jsxs)(`div`,{role:`button`,"aria-expanded":p,tabIndex:0,onClick:h,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h())},title:f(p?`commonUi.drawerCollapseTitle`:`commonUi.drawerExpandTitle`),className:X(`flex items-center gap-2 px-4 py-2 cursor-pointer select-none transition-colors`,`hover:bg-dark-hover/60`),children:[o&&(0,Q.jsx)(`span`,{className:`shrink-0 flex items-center`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o}),(0,Q.jsx)(`span`,{className:X(`shrink-0 text-dark-muted transition-transform duration-200`,!p&&`rotate-180`),children:(0,Q.jsx)(n,{size:16})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-dark-text truncate`,children:r}),a,!p&&i&&(0,Q.jsx)(`span`,{className:`min-w-0 flex items-center gap-1.5 text-xs text-dark-muted truncate`,children:i})]}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":f(`common.close`),onClick:e=>{e.stopPropagation(),t()},className:`shrink-0 p-1 rounded-md text-dark-muted hover:text-dark-text hover:bg-dark-hover transition-colors`,children:(0,Q.jsx)(O,{size:15})})]}),p&&(0,Q.jsx)(`div`,{className:`animate-slide-up border-t border-dark-border/60 overflow-y-auto custom-scrollbar p-4`,style:{maxHeight:c},children:s})]})}):null}function Jn(e,t){if(!e||!t||t.length===0)return;let n=e.find(e=>e.switchMode&&t.includes(e.label));n?.switchMode&&we.getState().setBaseMode(n.switchMode)}var Yn=15e3,Xn=300,Zn=4,Qn=8388608;function $n(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(typeof r.result==`string`?r.result:``),r.onerror=()=>n(r.error instanceof Error?r.error:Error(`image read failed`)),r.readAsDataURL(e)})}function er(e){let t=[];for(let n of Array.from(e.items??[])){if(n.kind!==`file`||!n.type.startsWith(`image/`))continue;let e=n.getAsFile();e&&t.push(e)}if(t.length===0)for(let n of Array.from(e.files??[]))n.type.startsWith(`image/`)&&t.push(n);return t}function tr(e){let{t}=L();return(0,Z.useMemo)(()=>{if(e.secret)return{allItems:[],otherIdx:-1,proceedIdx:-1,displayItems:[]};let n=t(`chat.askOtherLabel`),r=t(`chat.askProceedLabel`),i=e.options||[],a=i.some(e=>e.label===n),o=i.some(e=>e.label===r),s=[...i];return o||s.push({label:r,description:t(`chat.askProceedDesc`)}),a||s.push({label:n,description:t(`chat.askCustomDesc`)}),{allItems:s,otherIdx:a?s.findIndex(e=>e.label===n):s.length-1,proceedIdx:o?s.findIndex(e=>e.label===r):s.length-(a?1:2),displayItems:s}},[e,t])}function nr(e){let t=(0,Z.useRef)(null),[n,r]=(0,Z.useState)({top:!1,bottom:!1}),i=(0,Z.useCallback)(()=>{let e=t.current;if(!e)return;let n=e.scrollHeight-e.clientHeight,i=n>2&&e.scrollTop>2,a=n>2&&e.scrollTop<n-2;r(e=>e.top===i&&e.bottom===a?e:{top:i,bottom:a})},[]);return(0,Z.useEffect)(()=>{i();let e=t.current;if(!e)return;e.addEventListener(`scroll`,i,{passive:!0});let n=typeof ResizeObserver<`u`?new ResizeObserver(i):null;return n?.observe(e),()=>{e.removeEventListener(`scroll`,i),n?.disconnect()}},[i,e]),{ref:t,style:{"--ui-fade-top":n.top?`14px`:`0px`,"--ui-fade-bottom":n.bottom?`14px`:`0px`}}}function rr({ms:e}){let{t}=L();return(0,Q.jsx)(`span`,{className:`inline-flex items-center self-start text-xs leading-relaxed tabular-nums text-accent-yellow`,children:t(`chat.askAutoContinue`,{seconds:Math.max(1,Math.round(e/1e3))})})}function ir({children:e,tone:t}){return(0,Q.jsx)(`span`,{className:X(`shrink-0 rounded-full px-1.5 py-0.5 text-meta leading-none`,t===`green`?`bg-accent-green/10 text-accent-green`:`bg-dark-hover text-dark-muted`),children:e})}function ar({label:e,description:t,index:n,multi:r,active:i,checked:a,tag:o,onSelect:s}){let c=r?a:i;return(0,Q.jsxs)(`button`,{type:`button`,role:r?`checkbox`:`radio`,"aria-checked":c,onClick:s,className:X(`w-full min-h-11 flex items-start gap-3 rounded-lg border px-3 py-2.5 text-start`,`transition duration-snap ease-expo`,c?`border-accent-blue/40 bg-accent-blue/10`:`border-dark-border/60 bg-transparent hover:border-dark-border hover:bg-dark-hover`),children:[(0,Q.jsx)(`span`,{className:X(`shrink-0 w-5 h-5 inline-flex items-center justify-center text-meta font-medium tabular-nums`,`transition duration-snap ease-expo`,r?`rounded-md`:`rounded-full`,c?`border border-accent-blue bg-accent-blue text-accent-fg`:r?`border border-dark-border text-transparent`:`border border-dark-border text-dark-muted`),children:r?(0,Q.jsx)(T,{size:12}):n}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-dark-text`,children:e}),o]}),t&&(0,Q.jsx)(`span`,{className:`block mt-0.5 text-xs leading-snug text-dark-muted`,children:t})]}),!r&&(0,Q.jsx)(T,{size:15,"aria-hidden":`true`,className:X(`shrink-0 mt-0.5 transition-opacity duration-snap ease-expo`,c?`text-accent-blue opacity-100`:`opacity-0`)})]})}function or({value:e,onChange:t,onSubmit:n}){let{t:r}=L(),[i,a]=(0,Z.useState)(!1);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute start-3 top-1/2 -translate-y-1/2 text-dark-muted`,children:(0,Q.jsx)(c,{size:14})}),(0,Q.jsx)(`input`,{type:i?`text`:`password`,autoComplete:`off`,autoCorrect:`off`,spellCheck:!1,className:`input ps-9 pe-11 font-mono`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),n())},placeholder:r(`chat.askSecretPlaceholder`),autoFocus:!0}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-label":r(i?`chat.askSecretHide`:`chat.askSecretReveal`),"aria-pressed":i,className:X(`absolute end-1 top-1/2 -translate-y-1/2 inline-flex h-8 w-8 items-center justify-center`,`rounded-md text-dark-muted transition-colors duration-snap ease-expo`,`hover:bg-dark-hover hover:text-dark-text`),children:i?(0,Q.jsx)(l,{size:14,"aria-hidden":`true`}):(0,Q.jsx)(s,{size:14,"aria-hidden":`true`})})]}),(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-dark-muted`,children:r(`chat.askSecretHint`)}),(0,Q.jsx)(q,{variant:`primary`,shape:`pill`,leftIcon:(0,Q.jsx)(A,{size:15}),onClick:n,disabled:!e,className:`w-full min-h-11 sm:w-auto sm:self-start`,children:r(`chat.askSubmit`)})]})}function sr({item:e,answered:t,selectedIdx:n,multiSelected:r,customInput:i,showCustomInput:a,onSelect:o,onToggleMulti:s,onProceed:c,onEnterCustom:l,onCancelCustom:u,onSubmitCustom:d,onCustomChange:f,inputRef:p}){let{t:m}=L(),{otherIdx:h,proceedIdx:g,displayItems:_}=tr(e),v=!!e.multiSelect,{ref:y,style:b}=nr(_.length);if(e.secret)return(0,Q.jsx)(or,{value:i,onChange:f,onSubmit:d});let x=e=>{e===g?c():e===h?l():v?s(e):o(e)};return(0,Q.jsxs)(`div`,{ref:y,style:b,role:v?`group`:`radiogroup`,"aria-label":e.question,className:`fade-mask-y flex flex-col gap-2 pe-1 overflow-y-auto custom-scrollbar sm:max-h-72`,children:[_.map((e,t)=>{let o=n===t,s=t===h;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ar,{label:e.label,description:e.description,index:t+1,multi:v,active:o,checked:r.has(t),tag:t===g?(0,Q.jsx)(ir,{tone:`green`,children:m(`chat.askDirectTag`)}):s?(0,Q.jsx)(ir,{tone:`muted`,children:m(`chat.askCustomTag`)}):null,onSelect:()=>x(t)}),s&&o&&a&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 ps-8`,children:[(0,Q.jsx)(`textarea`,{ref:p,className:`input resize-none`,rows:3,value:i,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),d()),e.key===`Escape`&&u()},placeholder:m(`chat.askAnswerPlaceholder`),autoFocus:!0}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(q,{variant:`primary`,size:`sm`,shape:`pill`,leftIcon:(0,Q.jsx)(A,{size:13}),onClick:d,children:m(`chat.askSubmit`)}),(0,Q.jsx)(q,{variant:`ghost`,size:`sm`,shape:`pill`,leftIcon:(0,Q.jsx)(O,{size:13}),onClick:u,children:m(`common.cancel`)})]})]})]},`opt-${t}`)}),t&&(0,Q.jsx)(`div`,{className:`text-xs font-medium text-accent-green`,children:m(`chat.askAnswered`)})]})}var cr=(e,t)=>e?.secret===!0||t?.secret===!0;function lr({images:e,notice:t,onRemove:n}){let{t:r}=L();return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[e.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative overflow-hidden rounded-lg border border-dark-border bg-dark-surface`,children:[(0,Q.jsx)(`img`,{src:e,alt:r(`chat.askImageAlt`,{index:t+1}),className:`h-14 w-14 object-cover`}),(0,Q.jsx)(`button`,{type:`button`,"aria-label":r(`chat.askImageRemove`),onClick:()=>n(t),className:`absolute end-0.5 top-0.5 inline-flex h-5 w-5 items-center justify-center rounded-full bg-dark-bg/80 text-dark-muted transition-colors hover:bg-accent-red/80 hover:text-dark-bg`,children:(0,Q.jsx)(O,{size:11})})]},`ask-img-${t}`))}),t?(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 text-meta text-accent-yellow`,children:[(0,Q.jsx)(S,{size:11,className:`shrink-0`}),(0,Q.jsx)(`span`,{children:t})]}):(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 text-meta text-dark-muted`,children:[(0,Q.jsx)(x,{size:11,className:`shrink-0`}),(0,Q.jsx)(`span`,{children:r(`chat.askImagePasteHint`)})]})]})}function ur({isOpen:e,onClose:t}){let{t:n}=L(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(-1),[s,c]=(0,Z.useState)(new Set),[l,u]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[b,C]=(0,Z.useState)(0),[w,D]=(0,Z.useState)([]),[O,k]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)([]),[N,P]=(0,Z.useState)(null),F=(0,Z.useRef)(null),I=(0,Z.useRef)(null),R=(0,Z.useMemo)(()=>r?r.questions&&r.questions.length>0?r.questions:[{question:r.question,header:r.header,options:r.options,multiSelect:r.multiSelect,secret:r.secret}]:[],[r]),z=R.length>1,B=(0,Z.useCallback)(e=>{i(e),o(e.multiSelect?-1:0),c(new Set),u(``);let t=e.questions&&e.questions.length>0?e.questions:[e];p(cr(t[0],e)),h(!1),_(!1),y(!1),C(0),k(!1),D(t.map(()=>null)),M([]),P(null)},[]);(0,Z.useEffect)(()=>{I.current=r}),(0,Z.useEffect)(()=>{if(e){let e=window.__pendingQuestion;e&&B(e)}},[e,B]),(0,Z.useEffect)(()=>{let e=e=>{let n=e.detail,r=I.current?.questionId??null;if(n&&r&&n!==r)return;let a=r;h(!0),setTimeout(()=>{let e=I.current?.questionId??null;a&&e&&e!==a||(t(),i(null),h(!1))},Xn)};return window.addEventListener(`ask-question-dismiss`,e),()=>window.removeEventListener(`ask-question-dismiss`,e)},[t]),(0,Z.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>{h(!1),_(!0)},Yn);return()=>clearTimeout(e)},[m]),(0,Z.useEffect)(()=>{let e=()=>{_(!1),y(!1)};return window.addEventListener(`ask-question-dismiss`,e),()=>window.removeEventListener(`ask-question-dismiss`,e)},[]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.detail,n=I.current?.questionId??null;t&&n&&t!==n||(h(!1),_(!0),y(!0))};return window.addEventListener(`ask-question-ack-failed`,e),()=>window.removeEventListener(`ask-question-ack-failed`,e)},[]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.detail,n=ee.getState().activeSessionId;if(t&&n&&t!==n)return;let r=window.__pendingQuestion;r&&B(r)};return window.addEventListener(`ask-question-required`,e),()=>window.removeEventListener(`ask-question-required`,e)},[B]),(0,Z.useEffect)(()=>{o(0),c(new Set),u(``),p(cr(R[b],r))},[b,O,r,R]);let V=R[b]||null,{allItems:H,otherIdx:U}=tr(V||{question:``}),W=cr(V,r),G=j[b]??[],K=(0,Z.useCallback)((e,t)=>{!m&&r&&(_(!1),h(!0),Jn(r.options,t),Y.send({type:`question_answer`,sessionId:r.sessionId||Y.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answer:e,selectedOptions:t,...G.length>0?{images:G}:{}})}))},[m,r,G]),te=(0,Z.useCallback)(()=>{!m&&r&&(_(!1),h(!0),Y.send({type:`question_answer`,sessionId:r.sessionId||Y.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:R.map((e,t)=>{let r=w[t]||{answer:n(`chat.askUnansweredValue`)},i=j[t]??[];return i.length>0?{...r,images:i}:r})})}))},[m,r,R,w,j,n]),ne=(0,Z.useCallback)(e=>{M(t=>{let n=t.slice();return n[b]=(n[b]??[]).filter((t,n)=>n!==e),n}),P(null)},[b]),re=(0,Z.useCallback)(e=>{if(m||W||O)return;let t=e.clipboardData;if(!t)return;let r=er(t);if(r.length===0)return;e.preventDefault();let i=b,a=j[i]?.length??0;(async()=>{let e=[],t=0,o=0;for(let n of r)if(n.size>Qn)t++;else if(a+e.length>=Zn)o++;else try{let t=await $n(n);t.startsWith(`data:image/`)&&e.push(t)}catch{}e.length>0&&M(t=>{let n=t.slice();return n[i]=[...n[i]??[],...e].slice(0,Zn),n}),t>0?P(n(`chat.askImageTooLarge`)):o>0?P(n(`chat.askImageTooMany`,{count:Zn})):e.length>0&&P(null)})()},[m,W,O,b,j,n]),J=(0,Z.useCallback)((e,t,n)=>{Jn(R[e]?.options,n),D(r=>{let i=r.slice();return i[e]={answer:t,selectedOptions:n},i}),e<R.length-1?C(e+1):k(!0)},[R]),ie=(0,Z.useCallback)(e=>{if(m||!r)return;let t=H[e];t&&(o(e),K(t.label,[t.label]))},[m,r,H,K]),ae=(0,Z.useCallback)(()=>{if(m||!r||a<0)return;let e=H[a];e&&K(e.label,[e.label])},[m,r,a,H,K]),oe=(0,Z.useCallback)(()=>{if(m||a<0)return;let e=H[a];e&&J(b,e.label,[e.label])},[m,a,H,J,b]),se=(0,Z.useCallback)(e=>{if(m)return;let t=H[e];t&&J(b,t.label,[t.label])},[m,H,J,b]),ce=(0,Z.useCallback)(e=>{m||c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[m]),le=(0,Z.useCallback)(()=>{if(m)return;let e=[...s].map(e=>H[e]?.label||``);z?J(b,e.join(`, `),e):K(e.join(`, `),e)},[m,s,H,z,J,b,K]),ue=(0,Z.useCallback)(()=>{if(m)return;let e=n(`chat.askProceedLabel`);z?J(b,e,[e]):K(e,[e])},[m,z,J,b,K,n]),de=(0,Z.useCallback)(()=>{m||(o(U),p(!0),setTimeout(()=>F.current?.focus(),100))},[m,U]),fe=(0,Z.useCallback)(()=>{p(!1),u(``)},[]),pe=(0,Z.useCallback)(()=>{if(m||W&&!l.trim())return;let e=l||n(`chat.askEmptyInputValue`);z?J(b,e):K(e)},[m,l,z,J,b,K,n,W]),me=(0,Z.useCallback)(()=>{!m&&r&&(_(!1),h(!0),Y.send({type:`question_answer`,sessionId:r.sessionId||Y.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:R.map(()=>({answer:`(cancelled)`}))})}))},[m,r,R]),he=(0,Z.useCallback)(()=>{if(!m){if(v)t();else if(z){if(f&&!W){p(!1),u(``);return}if(O){k(!1),C(R.length-1);return}me()}else f&&!W?(p(!1),u(``)):K(`(cancelled)`)}},[m,z,f,O,R.length,me,K,v,t,W]);if(!e||!r)return null;let ge=w.filter(e=>!e).length,_e=w.filter(Boolean).length,ve=m||g||f,ye=m?(0,Q.jsx)(`span`,{children:n(`chat.askSubmitting`)}):g?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-accent-yellow`,children:[(0,Q.jsx)(S,{size:12}),n(`chat.askSubmitRetry`)]}):f?W?null:(0,Q.jsx)(`span`,{children:n(`chat.askEnterHint`)}):r.multiSelect?(0,Q.jsx)(`span`,{children:n(`chat.askMultiHintSingle`)}):(0,Q.jsx)(`span`,{children:n(`chat.askSingleHintSingle`)});return(0,Q.jsx)(qn,{isOpen:e,onClose:he,title:r.header||n(z?`chat.askBatchTitle`:`chat.askSingleTitle`),badge:z?(0,Q.jsxs)(`span`,{className:`shrink-0 inline-flex items-center rounded-full bg-dark-hover px-2 py-0.5 text-meta font-medium tabular-nums text-dark-muted`,children:[_e,`/`,R.length]}):void 0,collapsedSummary:(0,Q.jsx)(`span`,{className:`truncate`,children:V?.question||r.question}),maxHeight:`min(85dvh, 40rem)`,alignToComposer:!0,children:z?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,onPaste:re,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[R.map((e,t)=>{let n=!!w[t],r=!O&&b===t;return(0,Q.jsxs)(`button`,{type:`button`,"aria-current":r?`step`:void 0,onClick:()=>{C(t),k(!1)},className:X(`inline-flex items-center gap-1 rounded-full px-3 min-h-9 text-xs font-medium tabular-nums`,`transition duration-snap ease-expo`,r?`bg-dark-text text-dark-bg`:n?`border border-accent-green/40 bg-accent-green/10 text-accent-green`:`border border-dark-border bg-dark-surface text-dark-muted hover:bg-dark-hover`),children:[`Q`,t+1,n&&(0,Q.jsx)(T,{size:11})]},`nav-${t}`)}),(0,Q.jsx)(`button`,{type:`button`,"aria-current":O?`step`:void 0,onClick:()=>k(!0),className:X(`inline-flex items-center rounded-full px-3 min-h-9 text-xs font-medium`,`transition duration-snap ease-expo`,O?`bg-dark-text text-dark-bg`:`border border-dark-border bg-dark-surface text-dark-muted hover:bg-dark-hover`),children:n(`chat.askSubmit`)})]}),r.autoResolutionMs&&r.autoResolutionMs>0&&(0,Q.jsx)(rr,{ms:r.autoResolutionMs}),O?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-dark-text`,children:n(`chat.askReviewTitle`)}),(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-dark-border`,children:R.map((e,t)=>{let r=w[t];return(0,Q.jsxs)(`div`,{className:X(`flex items-start gap-3 px-3 py-2.5`,t>0&&`border-t border-dark-border`),children:[(0,Q.jsx)(`span`,{className:`shrink-0 w-5 h-5 rounded-full border border-dark-border text-meta font-medium tabular-nums text-dark-muted inline-flex items-center justify-center`,children:t+1}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm leading-snug text-dark-text`,children:e.question}),(0,Q.jsxs)(`div`,{className:X(`mt-1 text-xs break-words`,r?`text-accent-green`:`text-accent-yellow`),children:[r?r.answer:n(`chat.askNotAnswered`),(j[t]??[]).length>0&&(0,Q.jsxs)(`span`,{className:`ms-2 inline-flex items-center gap-0.5 text-meta text-dark-muted`,children:[(0,Q.jsx)(x,{size:11}),`${(j[t]??[]).length}`]})]})]})]},`rev-${t}`)})}),ge>0&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-accent-yellow/30 bg-accent-yellow/10 px-3 py-2 text-xs leading-relaxed text-accent-yellow`,children:[(0,Q.jsx)(S,{size:14,className:`shrink-0 mt-0.5`}),(0,Q.jsx)(`span`,{children:n(`chat.askUnansweredWarning`,{count:ge})})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[(0,Q.jsx)(q,{variant:`primary`,shape:`pill`,leftIcon:(0,Q.jsx)(A,{size:15}),onClick:te,disabled:m,className:`w-full min-h-11 sm:w-auto`,children:n(`chat.askSubmitAll`)}),(0,Q.jsx)(q,{variant:`secondary`,shape:`pill`,leftIcon:(0,Q.jsx)(E,{size:14}),onClick:()=>{k(!1),C(R.length-1)},disabled:m,className:`w-full min-h-11 sm:w-auto`,children:n(`chat.askBackToEdit`)})]})]}):V?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between sm:gap-3`,children:[(0,Q.jsx)(`p`,{className:`min-w-0 text-base leading-relaxed text-dark-text text-pretty`,children:V.question}),(0,Q.jsxs)(`div`,{className:`hidden sm:flex items-center gap-1.5 shrink-0`,children:[(0,Q.jsx)(q,{variant:`secondary`,size:`sm`,shape:`pill`,leftIcon:(0,Q.jsx)(E,{size:13}),onClick:()=>{C(e=>Math.max(0,e-1)),k(!1)},disabled:b===0,children:n(`chat.askPrevQuestion`)}),b<R.length-1?(0,Q.jsx)(q,{variant:`secondary`,size:`sm`,shape:`pill`,rightIcon:(0,Q.jsx)(d,{size:13}),onClick:()=>{C(e=>Math.min(R.length-1,e+1)),k(!1)},children:n(`chat.askNextQuestion`)}):(0,Q.jsx)(q,{variant:`secondary`,size:`sm`,shape:`pill`,rightIcon:(0,Q.jsx)(d,{size:13}),onClick:()=>k(!0),children:n(`chat.askViewSubmit`)})]})]}),(0,Q.jsx)(sr,{item:V,answered:!!w[b],selectedIdx:a,multiSelected:s,customInput:l,showCustomInput:f,onSelect:se,onToggleMulti:ce,onProceed:ue,onEnterCustom:de,onCancelCustom:fe,onSubmitCustom:pe,onCustomChange:u,inputRef:F}),!W&&(G.length>0||f)&&(0,Q.jsx)(lr,{images:G,notice:N,onRemove:ne}),(0,Q.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsx)(`p`,{className:X(`text-xs leading-relaxed text-dark-muted`,!ve&&`hidden sm:block`),children:f?(0,Q.jsx)(`span`,{children:n(`chat.askEnterHint`)}):V.multiSelect?(0,Q.jsx)(`span`,{children:n(`chat.askMultiHintBatch`)}):(0,Q.jsx)(`span`,{children:n(`chat.askSingleHintBatch`)})}),!f&&(0,Q.jsx)(q,{variant:V.multiSelect?`primary`:`secondary`,shape:`pill`,leftIcon:(0,Q.jsx)(T,{size:15}),onClick:V.multiSelect?le:oe,disabled:m||(V.multiSelect?s.size===0:a<0),className:`w-full min-h-11 sm:w-auto sm:shrink-0`,children:V.multiSelect?n(`chat.askFinishQuestion`,{count:s.size}):n(`chat.askConfirmQuestion`)})]})]}):null]}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,onPaste:re,children:[(0,Q.jsx)(`p`,{className:`text-base leading-relaxed text-dark-text text-pretty`,children:r.question}),r.autoResolutionMs&&r.autoResolutionMs>0&&(0,Q.jsx)(rr,{ms:r.autoResolutionMs}),(0,Q.jsx)(sr,{item:R[0],answered:!1,selectedIdx:a,multiSelected:s,customInput:l,showCustomInput:f,onSelect:ie,onToggleMulti:ce,onProceed:ue,onEnterCustom:de,onCancelCustom:fe,onSubmitCustom:pe,onCustomChange:u,inputRef:F}),!W&&(G.length>0||f)&&(0,Q.jsx)(lr,{images:G,notice:N,onRemove:ne}),(0,Q.jsxs)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[ye?(0,Q.jsx)(`p`,{className:X(`text-xs leading-relaxed text-dark-muted`,!ve&&`hidden sm:block`),children:ye}):(0,Q.jsx)(`span`,{className:`hidden sm:block`}),!f&&(0,Q.jsx)(q,{variant:r.multiSelect?`primary`:`secondary`,shape:`pill`,leftIcon:(0,Q.jsx)(T,{size:15}),onClick:r.multiSelect?le:ae,disabled:m||(r.multiSelect?s.size===0:a<0),className:`w-full min-h-11 sm:w-auto sm:shrink-0`,children:r.multiSelect?n(`chat.askSubmitSelected`,{count:s.size}):n(`chat.askSubmit`)})]})]})})}var dr=(0,Z.memo)(function({sessionId:e}){let{t:n}=L(),{offer:r,respond:i}=Ce(e);if(!r)return null;let a=r.fileName||n(`widgets.dwf.offerFallbackTitle`);return(0,Q.jsx)(`div`,{className:`chat-drawer-col shrink-0 pb-1.5`,"data-testid":`dwf-offer-card`,children:(0,Q.jsxs)(`div`,{className:`animate-fade-in-up overflow-hidden rounded-xl border border-accent-purple/40 bg-dark-surface`,style:{boxShadow:`var(--shadow-air-1)`},role:`group`,"aria-label":a,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-dark-border/60 px-3 py-2`,children:[(0,Q.jsx)(t,{size:13,className:`text-accent-purple shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-meta font-semibold text-dark-text`,children:a})]}),(0,Q.jsx)(`div`,{className:`px-3 py-2`,children:(0,Q.jsx)(De,{offer:r,onRespond:i,layout:`wide`})})]})})}),fr=15;function pr({isOpen:e,onCloseModal:t}){let{t:n}=L(`hook`),r=Oe(),i=r.pendingApprovals,a=r.autoMode,o=r.setAutoMode,[s,c]=(0,Z.useState)(0),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(fr),[p,m]=(0,Z.useState)(!0),[h,g]=(0,Z.useState)(!1),_=(0,Z.useRef)(null),v=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{i.length!==0&&(a?(i.forEach(e=>{Y.send({type:`hook_allow`,data:JSON.stringify({approvalId:e.approvalId})})}),r.clearApprovals()):c(e=>Math.min(e,i.length-1)))},[i.length,a]);let y=i[s]??null,b=i.length>0&&y!==null,x=i.length,C=b?x-s-1:0;(0,Z.useEffect)(()=>{if(b&&!l&&e&&y)return f(fr),_.current=setInterval(()=>{f(e=>e<=1?(_.current&&clearInterval(_.current),0):e-1)},1e3),()=>{_.current&&clearInterval(_.current)}},[b,l,e,y?.approvalId]);let w=y?Ee(y.toolName,y.askPayload):{level:`MEDIUM`,reasonKey:`risk_default`},T=ye[w.level],E=R[w.level===`CRITICAL`?`critical`:w.level===`HIGH`?`high`:w.level===`LOW`?`low`:`medium`],O=y?ce(y.toolName,y.askPayload):null,k=y?Se(y.toolName,y.askPayload):null,A=y?{verb:oe(y.toolName),target:J(y.toolName,y.askPayload)}:null,M=y?Te(y.askPayload)!==null:!1,N=y?ue(y.toolName,y.askPayload):null,P=(O?re(O.text):k?re(k):!1)&&!h;(0,Z.useEffect)(()=>{g(!1)},[y?.approvalId]);let I=d/fr*100,z=d<=5,H=ne((fr-d)*1e3),U=(0,Z.useCallback)((e,t)=>{let n=ee.getState().activeSessionId;n&&B.getState().updateHookApprovalStatus(n,e,t)},[]),W=(0,Z.useCallback)(e=>{y&&(e&&U(y.approvalId,e),u(!0),setTimeout(()=>{r.removeApproval(y.approvalId),c(0),u(!1),v.current=!1,f(fr)},200))},[y?.approvalId,r,U]),G=(0,Z.useCallback)(()=>{!y||l||v.current||(P?g(!0):(v.current=!0,_.current&&clearInterval(_.current),Y.send({type:`hook_allow`,data:JSON.stringify({approvalId:y.approvalId})}),W(`approved`)))},[y,W,l,P]),K=(0,Z.useCallback)(()=>{!y||l||v.current||(v.current=!0,_.current&&clearInterval(_.current),Y.send({type:`hook_deny`,data:JSON.stringify({approvalId:y.approvalId})}),W(`denied`))},[y,W,l]),te=(0,Z.useCallback)(()=>{if(!y||l||v.current)return;if(P){g(!0);return}v.current=!0,_.current&&clearInterval(_.current);let e=Te(y.askPayload);e?(r.addToSessionAllowList(y.toolName,e),Y.send({type:`hook_allow`,data:JSON.stringify({approvalId:y.approvalId,sessionAllow:!0})})):(r.addToSessionAllowList(y.toolName),Y.send({type:`hook_allow`,data:JSON.stringify({approvalId:y.approvalId})})),W(`approved`)},[y,W,r,l,P]),ie=(0,Z.useCallback)(()=>{!y||l||v.current||(P?g(!0):(v.current=!0,_.current&&clearInterval(_.current),o(!0),we.getState().setAuto(!0),Y.send({type:`hook_allow`,data:JSON.stringify({approvalId:y.approvalId})}),W(`approved`)))},[y,W,l,o,P]),se=(y?.timeoutMs??15e3)>0,de=y?.timeoutAction===`deny`?K:G;if((0,Z.useEffect)(()=>{d===0&&e&&!l&&y&&se&&de()},[d,e,l,y,de,se]),(0,Z.useEffect)(()=>{if(!e||!p)return;let t=e=>{let t=e.target;t&&typeof t.closest==`function`&&t.closest(`input, textarea, select, [contenteditable="true"]`)||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),K()):e.key===`Enter`?(e.preventDefault(),G()):e.key===`1`?G():e.key===`2`?K():e.key===`3`?te():e.key===`4`&&ie())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,p,G,K,te,ie]),!b||!y)return null;let fe=n(`optionAllowHint`),pe=n(`optionDenyHint`),me=M?n(`optionAllowPathHint`):n(`optionAllowAlwaysHint`,{tool:y.toolName}),he=n(`optionAutoModeHint`),ge=O?.text??k??null,_e=ge?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Q.jsx)(`code`,{className:`font-mono text-meta bg-dark-surface text-accent-blue px-1 py-0.5 rounded shrink-0`,children:y.toolName}),(0,Q.jsx)(`span`,{className:`truncate`,children:ge})]}):null;return(0,Q.jsx)(qn,{isOpen:e,onClose:()=>t?.(),title:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(F,{className:`w-4 h-4 text-accent-yellow`}),(0,Q.jsx)(`span`,{children:n(`hookApproval`)}),(0,Q.jsxs)(`span`,{className:`text-xs text-dark-muted`,children:[`(`,s+1,`/`,x,`)`]})]}),badge:(0,Q.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-badge font-bold border shrink-0 ${T.badge}`,children:[T.icon,` `,w.level]}),collapsedSummary:_e,onExpandedChange:m,maxHeight:`50vh`,alignToComposer:!0,children:(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${T.bg} border ${T.border}`,children:[(0,Q.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${T.badge}`,children:[T.icon,` `,w.level]}),(0,Q.jsx)(`span`,{className:`text-xs text-dark-muted truncate`,children:n(w.reasonKey)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 ms-auto shrink-0`,children:[(0,Q.jsx)(D,{size:12,className:z?`text-accent-red`:`text-dark-muted`}),(0,Q.jsx)(`span`,{className:`text-xs font-mono ${z?`text-accent-red animate-pulse`:`text-dark-muted`}`,children:se?`${d}s`:`∞`}),(0,Q.jsx)(`div`,{className:`w-12 h-1.5 bg-dark-border rounded-full overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all duration-700 ${z?`bg-accent-red`:d<=8?`bg-accent-yellow`:`bg-accent-green`}`,style:{width:`${I}%`}})})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[(0,Q.jsx)(`span`,{className:`flex-none w-7 h-7 rounded-lg bg-accent-blue/10 text-accent-blue inline-flex items-center justify-center`,children:(0,Q.jsx)(F,{size:15})}),A&&(0,Q.jsx)(ae,{pre:n(A.verb),obj:A.target})]}),N&&(N.external&&N.path?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-meta px-1.5 py-0.5 rounded bg-accent-yellow/15 text-accent-yellow border border-accent-yellow shrink-0`,title:N.path,children:[(0,Q.jsx)(j,{size:10}),n(`scopeExternal`),`: `,N.path.length>48?`${N.path.slice(0,47)}…`:N.path]}):(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 shrink-0`,children:n(`scopeLocal`)}))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-dark-muted shrink-0`,children:n(`tool`)}),(0,Q.jsx)(`code`,{className:`text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate`,children:y.toolName}),(0,Q.jsx)(`span`,{className:`text-dark-muted/50`,children:H}),(0,Q.jsx)(`span`,{className:`text-dark-muted/50`,children:E.label}),y.timeoutAction&&(0,Q.jsxs)(`span`,{className:`text-xs ${y.timeoutAction===`deny`?`text-accent-red`:`text-accent-green`}`,children:[`timeout: `,se?`${y.timeoutAction===`allow`?`auto-allow`:`auto-deny`}${y.timeoutMs?` (${(y.timeoutMs/1e3).toFixed(0)}s)`:``}`:n(`timeoutWaitUser`)]})]}),O?(0,Q.jsx)(le,{text:O.text,mono:O.mono,expanded:h,onToggle:()=>g(e=>!e)}):k?(0,Q.jsx)(le,{text:k,expanded:h,onToggle:()=>g(e=>!e)}):null,P&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(!0),className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded bg-accent-red/10 text-accent-red border border-accent-red/30 hover:bg-accent-red/20 transition-colors text-left`,children:[(0,Q.jsx)(S,{size:13}),(0,Q.jsx)(`span`,{children:n(`showAll`)})]}),(w.level===`CRITICAL`||w.level===`HIGH`)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${T.bg} ${T.text}`,children:[(0,Q.jsx)(S,{size:13}),(0,Q.jsx)(`span`,{children:w.level===`CRITICAL`?n(`highRiskWarning`):n(`mediumRiskConfirm`)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(q,{variant:`accent`,onClick:G,disabled:l||P,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono bg-accent-fg/20 rounded px-1`,children:`1`}),(0,Q.jsx)(`span`,{children:V.allow.label}),(0,Q.jsx)(`span`,{className:`text-meta text-accent-fg/70 hidden sm:inline`,children:fe})]}),(0,Q.jsxs)(`button`,{onClick:te,disabled:l||P,className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono text-dark-muted bg-dark-surface rounded px-1`,children:`3`}),(0,Q.jsx)(`span`,{children:V.allow_session.label}),(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 hidden sm:inline`,children:me})]}),(0,Q.jsxs)(`button`,{onClick:ie,disabled:l||P,className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono text-dark-muted bg-dark-surface rounded px-1`,children:`4`}),(0,Q.jsx)(`span`,{children:V.auto.label}),(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 hidden sm:inline`,children:he})]}),(0,Q.jsx)(`span`,{className:`flex-1`}),(0,Q.jsxs)(`button`,{onClick:K,disabled:l,className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-dark-muted hover:bg-accent-red/15 hover:text-accent-red text-sm transition-colors disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`text-badge font-mono text-dark-muted/60 rounded px-1`,children:`2`}),(0,Q.jsx)(`span`,{children:V.deny.label}),(0,Q.jsx)(`span`,{className:`text-meta text-dark-muted/60 hidden sm:inline`,children:pe})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-dark-muted/60`,children:[(0,Q.jsx)(`span`,{children:n(`shortcutHint`)}),(0,Q.jsx)(`span`,{children:C>0?n(`morePending`,{n:C}):n(`lastItem`)})]})]})})}var mr=`dsc-auto-access-banner-dismissed`,hr=(0,Z.memo)(function(){let{t:e}=L(),t=we(e=>e.mode),[n,r]=(0,Z.useState)(()=>localStorage.getItem(mr)===`1`);(0,Z.useEffect)(()=>{W(t===`normal`?`act`:t)||localStorage.getItem(mr)===`1`&&r(!1)},[t]);let i=(0,Z.useCallback)(e=>{e&&localStorage.setItem(mr,`1`),r(!0)},[]);return!(t!==`normal`&&W(t))||n?null:(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-4 py-1 text-meta leading-snug text-accent-yellow/75 bg-accent-yellow/[0.05] border-b border-accent-yellow/10 select-none`,role:`note`,title:e(`autoAccess.desc`),children:[(0,Q.jsx)(p,{size:11,className:`shrink-0 text-accent-yellow/70`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 truncate`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e(`autoAccess.title`)}),(0,Q.jsxs)(`span`,{className:`text-accent-yellow/60`,children:[` · `,e(`autoAccess.desc`)]})]}),(0,Q.jsx)(`button`,{onClick:()=>i(!1),className:`shrink-0 rounded p-0.5 text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors`,title:e(`autoAccess.dismiss`),"aria-label":e(`autoAccess.dismiss`),children:(0,Q.jsx)(O,{size:11})}),(0,Q.jsx)(`button`,{onClick:()=>i(!0),className:`shrink-0 rounded px-1 py-px text-badge text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors whitespace-nowrap`,children:e(`autoAccess.neverShow`)})]})});function gr(e,t){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t)}…`:n}function _r(e){return gr(e,12)}function vr(){return`custom-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function yr(e,t){return e.some(e=>e.kind===`scenario`&&e.id===t)}function br(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id!=`string`||t.id===``||typeof t.label!=`string`||t.label===``||typeof t.hint!=`string`?!1:t.kind===`template`?typeof t.templateId==`string`&&t.templateId!==``:t.kind!==void 0&&t.kind!==`prompt`?!1:typeof t.prompt==`string`&&t.prompt!==``}function xr(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&t.id!==``&&typeof t.label==`string`&&t.label!==``&&Array.isArray(t.scenarios)&&t.scenarios.length>0&&t.scenarios.every(br)}function Sr(e){let t=e(`chat.start.categories`,{returnObjects:!0,defaultValue:[]});return Array.isArray(t)?t.filter(xr):[]}var Cr=`tpl:`,wr=`tpl-`;function Tr(e){return e.trim().toLowerCase()}function Er(e){let t=new Map;for(let n of e){let e=(n.category??``).trim();if(!e)continue;let r=(n.name??``).trim();if(!r)continue;let i={id:`${wr}${n.id}`,label:r,hint:n.description??``,prompt:``,kind:`template`,templateId:n.id},a=t.get(e);a?a.push(i):t.set(e,[i])}return[...t].map(([e,t])=>({id:`${Cr}${e}`,label:e,scenarios:t}))}function Dr(e,t){if(t.length===0)return e;let n=e.map(e=>({...e})),r=new Set(n.map(e=>e.id)),i=new Map(n.map((e,t)=>[Tr(e.label),t]));for(let e of t){let t=Tr(e.label),a=i.get(t);if(a!==void 0){let t=n[a];n[a]={...t,scenarios:[...t.scenarios,...e.scenarios]}}else r.has(e.id)||(r.add(e.id),i.set(t,n.length),n.push(e))}return n}function Or(e,t,n){let r=new Map;for(let t of e)for(let e of t.scenarios)r.set(e.id,e);let i=new Set,a=[];for(let e of t){if(i.has(e.id))continue;if(i.add(e.id),e.kind===`custom`){a.push({id:e.id,label:e.label,hint:gr(e.prompt,56),prompt:e.prompt});continue}let t=r.get(e.id);t&&a.push(t)}return jr(a,n).slice(0,6)}function kr(e){return e<5?`chat.start.greetingDawn`:e<11?`chat.start.greetingMorning`:e<13?`chat.start.greetingNoon`:e<18?`chat.start.greetingAfternoon`:`chat.start.greetingEvening`}function Ar(e,t,n){let r=e(kr(t)),i=(n??``).trim();return i?e(`chat.start.withName`,{greeting:r,name:i}):r}function jr(e,t){return e.map((e,n)=>({scenario:e,index:n,count:t[e.id]??0})).sort((e,t)=>t.count-e.count||e.index-t.index).map(e=>e.scenario)}function Mr(e,t){return e.length===0||!t?null:e.find(e=>e.id===t)??null}var $=K()(te((e,t)=>({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0,setCategoryId:t=>e({categoryId:t,suggestionsHidden:!1}),recordUse:t=>e(e=>({clickCounts:{...e.clickCounts,[t]:(e.clickCounts[t]??0)+1},favorites:e.favorites.some(e=>e.id===t)?e.favorites:[{kind:`scenario`,id:t},...e.favorites]})),toggleFavorite:t=>e(e=>({favorites:e.favorites.some(e=>e.kind===`scenario`&&e.id===t)?e.favorites.filter(e=>e.kind!==`scenario`||e.id!==t):[{kind:`scenario`,id:t},...e.favorites]})),removeFavorite:t=>e(e=>({favorites:e.favorites.filter(e=>e.id!==t)})),addCustomFavorite:(n,r)=>{let i=r.trim();if(!i)return null;let a=vr(),o=new Set(t().favorites.map(e=>e.id));for(;o.has(a);)a=vr();let s={kind:`custom`,id:a,label:n.trim()||_r(i),prompt:i};return e(e=>({favorites:[s,...e.favorites]})),s},toggleSuggestions:()=>e(e=>({suggestionsHidden:!e.suggestionsHidden})),requestFocus:()=>e(e=>({prefillNonce:e.prefillNonce+1})),reset:()=>e({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0})}),{name:`deepseekcode-start-page-storage`,partialize:e=>({categoryId:e.categoryId,clickCounts:e.clickCounts,favorites:e.favorites,suggestionsHidden:e.suggestionsHidden}),version:2,migrate:(e,t)=>{let n=t??0;if(n>=2||!e||typeof e!=`object`)return e;let r=e,i=n<1||r.suggestionsHidden,a=n<1?Object.entries(r.clickCounts??{}).sort((e,t)=>t[1]-e[1]).slice(0,6).map(([e])=>e):r.favoriteIds??[];return{categoryId:r.categoryId??null,clickCounts:r.clickCounts??{},suggestionsHidden:i,favorites:a.map(e=>({kind:`scenario`,id:e}))}}}));function Nr(e){return typeof e!=`string`||!e?null:e.split(/[\\/]+/).pop()||null}var Pr={enabled:!0,exists:!1,name:null,file:null};function Fr(){let[e,t]=(0,Z.useState)(Pr);return(0,Z.useEffect)(()=>{let e=!1,n=()=>{he.profile.get().then(n=>{if(e||!n.success||!n.data)return;let r=n.data,i=r.enabled!==!1,a=r.exists===!0,o={enabled:i,exists:a,name:i&&r.name?r.name:null,file:i&&a?Nr(r.path):null};t(e=>e.enabled===o.enabled&&e.exists===o.exists&&e.name===o.name&&e.file===o.file?e:o)}).catch(()=>{})};return n(),window.addEventListener(Ae,n),()=>{e=!0,window.removeEventListener(Ae,n)}},[]),e}var Ir=(0,Z.memo)(function(){return(0,Q.jsxs)(`div`,{className:`relative isolate flex min-h-[8.5rem] w-full flex-col justify-end pb-1`,children:[(0,Q.jsx)(Lr,{}),(0,Q.jsx)(Br,{})]})}),Lr=(0,Z.memo)(function(){let{t:e}=L(),{enabled:t,exists:n,name:r,file:i}=Fr(),a=(0,Z.useMemo)(()=>Ar(e,new Date().getHours(),r),[e,r]);return(0,Q.jsxs)(`div`,{className:`chat-col px-4 pt-2 sm:px-6`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl font-semibold leading-snug tracking-tight text-dark-text`,children:[(0,Q.jsx)(`span`,{className:`block`,children:a}),(0,Q.jsx)(`span`,{className:`block`,children:e(`chat.start.question`)})]}),(0,Q.jsx)(Rr,{enabled:t,exists:n,name:r,file:i})]})});function Rr({enabled:e,exists:t,name:n,file:r}){let{t:i}=L(),a=e?n?i(`chat.start.profileOn`,{name:n}):t?r?i(`chat.start.profileFile`,{file:r}):i(`chat.start.profileSet`):i(`chat.start.profileAnonymous`):i(`chat.start.profileDisabled`),o=(0,Z.useCallback)(()=>{typeof window<`u`&&window.dispatchEvent(new CustomEvent(`switch-tab`,{detail:{tab:`settings`,section:`profile`}}))},[]);return(0,Q.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:o,title:i(`chat.start.profileHint`),className:`inline-flex min-w-0 items-center gap-1.5 rounded-full border border-dark-border/70 bg-dark-surface/50 px-2.5 py-1 text-meta text-dark-muted transition-colors hover:border-accent-blue/40 hover:text-dark-text`,children:[(0,Q.jsx)(k,{size:11,"aria-hidden":`true`,className:`shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:a}),(0,Q.jsxs)(`span`,{className:`shrink-0 text-dark-muted/70`,children:[`· `,i(`chat.start.profileEdit`)]})]})})}var zr=[{glyph:`/`,labelKey:`shortcuts.slashCommand`},{glyph:`@`,labelKey:`shortcuts.fileRef`},{glyph:`!`,labelKey:`shortcuts.shellCommand`},{glyph:`$`,labelKey:`shortcuts.skillRef`}],Br=(0,Z.memo)(function(){let{t:e}=L();return(0,Q.jsx)(`ul`,{"data-testid":`start-tips`,"aria-label":e(`shortcuts.title`),className:`chat-col mt-3 flex flex-wrap items-center gap-x-4 gap-y-1.5 px-4 sm:px-6`,children:zr.map(t=>(0,Q.jsxs)(`li`,{className:`inline-flex items-center gap-1.5 text-badge text-dark-muted/60`,children:[(0,Q.jsx)(`kbd`,{className:`rounded border border-dark-border bg-dark-bg px-1.5 py-0.5 font-mono text-badge leading-none text-dark-muted`,children:t.glyph}),(0,Q.jsx)(`span`,{children:e(t.labelKey)})]},t.glyph))})}),Vr=(0,Z.memo)(function({sessionId:e,onStartTemplate:t}){let{t:n}=L(),[r,i]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{if(!t)return;let e=!1;return he.templates.list().then(t=>{!e&&t.success&&t.data&&i(t.data)}).catch(()=>{}),()=>{e=!0}},[t]);let o=(0,Z.useMemo)(()=>Dr(Sr(n),Er(r)),[n,r]),c=$(e=>e.categoryId),u=$(e=>e.setCategoryId),f=$(e=>e.clickCounts),p=$(e=>e.favorites),m=$(e=>e.recordUse),h=$(e=>e.toggleFavorite),_=$(e=>e.removeFavorite),v=$(e=>e.addCustomFavorite),b=$(e=>e.suggestionsHidden),x=$(e=>e.toggleSuggestions),S=$(e=>e.requestFocus),C=(0,Z.useMemo)(()=>Mr(o,c),[o,c]),w=(0,Z.useCallback)(()=>u(null),[u]),T=(0,Z.useMemo)(()=>C?jr(C.scenarios,f):Or(o,p,f),[C,o,p,f]),[E,D]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(``),[j,M]=(0,Z.useState)(``),N=(0,Z.useCallback)(()=>{D(!1),A(``),M(``)},[]),P=(0,Z.useCallback)(()=>{D(!0),b&&x()},[b,x]),F=(0,Z.useCallback)(e=>{e.preventDefault(),v(k,j)&&N()},[v,N,k,j]),I=(0,Z.useCallback)(t=>{e&&(B.getState().setSessionInput(e,t.prompt),m(t.id),S())},[e,m,S]),[R,z]=(0,Z.useState)(null),[V,ee]=(0,Z.useState)(``),H=(0,Z.useCallback)(async e=>{ee(``);let t=await he.templates.get(e);!t.success||!t.data?ee(n(`templates.loadFailed`)):(z(t.data),b&&x())},[n,b,x]),U=(0,Z.useCallback)(e=>{e.kind===`template`&&e.templateId?t&&H(e.templateId):I(e)},[t,H,I]),W=(0,Z.useRef)([]),[G,K]=(0,Z.useState)(0),te=(0,Z.useCallback)((e,t,n)=>{if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let n=e.key===`ArrowDown`?Math.min(t+1,T.length-1):Math.max(t-1,0);K(n),W.current[n]?.focus()}else e.key===`Tab`&&(e.preventDefault(),U(n))},[U,T.length]);return o.length===0?null:(0,Q.jsxs)(`div`,{className:`start-col max-md:order-3 px-4 pb-4 sm:px-6`,children:[(0,Q.jsxs)(`div`,{role:`tablist`,"aria-label":n(`chat.start.categoriesLabel`),onKeyDown:e=>{e.key===`Escape`&&c&&(e.preventDefault(),w())},className:`snap-row mt-5 flex items-center gap-2 overflow-x-auto pb-1`,children:[o.map(e=>{let t=e.id===c;return(0,Q.jsxs)(`span`,{"data-testid":`start-chip`,"data-category-id":e.id,"data-selected":t?`true`:void 0,className:`inline-flex shrink-0 items-center overflow-hidden rounded-full border transition-colors focus-within:ring-1 focus-within:ring-accent-blue/60 ${t?`border-transparent bg-gradient-to-r rtl:bg-gradient-to-l from-accent-blue to-accent-purple text-accent-fg shadow-sm`:`border-dark-border/70 text-dark-muted hover:border-accent-blue/40 hover:text-dark-text`}`,children:[(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,"data-testid":`start-chip-label`,onClick:()=>u(t?null:e.id),className:`py-1 text-meta transition-colors focus-visible:outline-none ${t?`ps-3 pe-1.5`:`px-3`}`,children:e.label}),t&&(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-chip-clear`,"aria-label":n(`chat.start.clearCategory`,{label:e.label}),title:n(`chat.start.clearCategory`,{label:e.label}),onClick:w,className:`py-1 pl-0 pe-2 text-accent-fg/75 transition-colors hover:text-accent-fg focus-visible:outline-none`,children:(0,Q.jsx)(O,{size:12,"aria-hidden":`true`})})]},e.id)}),(0,Q.jsx)(d,{size:13,"aria-hidden":`true`,className:`shrink-0 text-dark-muted/50`})]}),(0,Q.jsxs)(`div`,{className:`mt-2.5`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0 truncate text-meta text-dark-muted/60`,children:[C?n(`chat.start.categoryTitle`,{label:C.label}):n(`chat.start.frequentTitle`),(0,Q.jsx)(`span`,{className:`ms-2 text-dark-muted/40`,children:n(C?`chat.start.selectedHint`:`chat.start.frequentHint`)})]}),(0,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[!C&&!E&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`start-custom-add`,onClick:P,className:`inline-flex items-center gap-1 text-meta text-dark-muted/60 transition-colors hover:text-dark-text`,children:[(0,Q.jsx)(y,{size:11,"aria-hidden":`true`}),n(`chat.start.customAdd`)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:x,className:`inline-flex items-center gap-1 text-meta text-dark-muted/60 transition-colors hover:text-dark-text`,children:b?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(s,{size:11,"aria-hidden":`true`}),n(`chat.start.show`)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(l,{size:11,"aria-hidden":`true`}),n(`chat.start.hide`)]})})]})]}),V&&(0,Q.jsx)(`div`,{"data-testid":`start-template-error`,className:`mb-2 text-meta text-accent-red`,children:V}),R&&(0,Q.jsxs)(`div`,{"data-testid":`start-template-form`,className:`mb-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-xs font-medium text-dark-text`,children:R.name}),(0,Q.jsx)(ke,{template:R,onCancel:()=>z(null),onSubmit:e=>{let n=R;z(null),t?.(n,e)},submitLabel:n(`templates.launch`)})]}),E&&!C&&(0,Q.jsxs)(`form`,{"data-testid":`start-custom-form`,onSubmit:F,className:`mb-2 flex flex-col gap-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3`,children:[(0,Q.jsx)(`input`,{"data-testid":`start-custom-label`,value:k,onChange:e=>A(e.target.value),placeholder:n(`chat.start.customLabelPlaceholder`),maxLength:40,className:`w-full rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-xs text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none`}),(0,Q.jsx)(`textarea`,{"data-testid":`start-custom-prompt`,value:j,onChange:e=>M(e.target.value),placeholder:n(`chat.start.customPromptPlaceholder`),rows:2,autoFocus:!0,className:`w-full resize-none rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-xs leading-snug text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-custom-cancel`,onClick:N,className:`rounded-md px-2.5 py-1 text-meta text-dark-muted transition-colors hover:text-dark-text`,children:n(`chat.start.customCancel`)}),(0,Q.jsx)(`button`,{type:`submit`,"data-testid":`start-custom-save`,disabled:!j.trim(),className:`rounded-md border border-accent-blue/40 bg-accent-blue/10 px-2.5 py-1 text-meta font-medium text-accent-blue transition-colors hover:bg-accent-blue/20 disabled:cursor-not-allowed disabled:border-dark-border/60 disabled:bg-transparent disabled:text-dark-muted/40`,children:n(`chat.start.customSave`)})]})]}),!b&&!R&&(T.length===0?E?null:(0,Q.jsx)(`p`,{"data-testid":`start-frequent-empty`,className:`rounded-xl border border-dashed border-dark-border/60 px-4 py-3 text-xs leading-relaxed text-dark-muted/70`,children:n(`chat.start.frequentEmpty`)}):(0,Q.jsx)(`div`,{className:`overflow-hidden rounded-xl border border-dark-border/60 bg-dark-surface/40`,children:T.map((e,t)=>{let r=yr(p,e.id);return(0,Q.jsxs)(`div`,{"data-testid":`start-row-shell`,className:`group flex items-center transition-colors hover:bg-dark-hover/40 focus-within:bg-dark-hover/40 ${t>0?`border-t border-dark-border/40`:``}`,children:[(0,Q.jsxs)(`button`,{ref:e=>{W.current[t]=e},type:`button`,"data-testid":`start-row`,"data-scenario-id":e.id,tabIndex:t===G?0:-1,onClick:()=>U(e),onKeyDown:n=>te(n,t,e),className:`flex min-w-0 flex-1 items-baseline gap-3 py-2.5 ps-4 pe-2 text-start transition-colors focus-visible:outline-none`,children:[(0,Q.jsx)(`span`,{className:`w-[84px] shrink-0 text-compact font-medium leading-snug text-dark-text`,children:e.label}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 border-s border-dark-border/50 ps-3 text-compact leading-snug text-dark-muted`,children:e.hint}),(0,Q.jsx)(g,{size:12,"aria-hidden":`true`,className:`mt-0.5 shrink-0 text-dark-muted/40`})]}),C?(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-row-favorite`,"aria-pressed":r,"aria-label":n(r?`chat.start.removeFavorite`:`chat.start.addFavorite`,{label:e.label}),title:n(r?`chat.start.removeFavorite`:`chat.start.addFavorite`,{label:e.label}),onClick:()=>h(e.id),className:`me-2 shrink-0 rounded-md p-1.5 transition-colors focus-visible:outline-none ${r?`text-accent-yellow`:`text-dark-muted/40 hover:text-dark-text`}`,children:(0,Q.jsx)(a,{size:13,"aria-hidden":`true`,className:r?`fill-current`:``})}):(0,Q.jsx)(`button`,{type:`button`,"data-testid":`start-row-remove`,"aria-label":n(`chat.start.removeFavorite`,{label:e.label}),title:n(`chat.start.removeFavorite`,{label:e.label}),onClick:()=>_(e.id),className:`me-2 shrink-0 rounded-md p-1.5 text-dark-muted/40 transition-colors hover:text-dark-text focus-visible:outline-none`,children:(0,Q.jsx)(O,{size:13,"aria-hidden":`true`})})]},e.id)})}))]})]})}),Hr=(0,Z.memo)(function({currentSessionId:e}){let{t}=L(),[n]=(0,Z.useState)(H),r=(0,Z.useCallback)(()=>{if(!n)return;let e=ee.getState();e.sessionTabs.some(e=>e.id===n.id)?e.setActiveSession(n.id):e.historySessions.some(e=>e.id===n.id)?e.restoreHistorySession(n.id):e.addSessionTab(n.title||void 0,n.dir||void 0,n.id),Y.setSessionId(n.id)},[n]);if(!n||n.id===e)return null;let i=n.title.trim();return i?(0,Q.jsx)(`div`,{className:`mb-1 flex shrink-0 justify-center px-4 max-md:justify-start`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:r,title:t(`chat.resumeLastTitle`),"data-testid":`resume-last-session`,className:`group flex max-w-full items-center gap-1.5 rounded-full border border-dark-border/70 bg-dark-surface/50 px-2.5 py-1 text-meta leading-none text-dark-muted transition-colors hover:border-accent-blue/40 hover:bg-accent-blue/10 hover:text-dark-text focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60`,children:[(0,Q.jsx)(N,{size:11,className:`shrink-0 text-dark-muted/70 group-hover:text-accent-blue`}),(0,Q.jsx)(`span`,{className:`truncate`,children:t(`chat.resumeLast`,{title:i})})]})}):null});function Ur(e){let{sessionId:t,isGenerating:n,messages:r}=e,{i18n:i}=L(),a=(0,Z.useRef)(n),o=(0,Z.useRef)(t);(0,Z.useEffect)(()=>{let e=a.current,s=o.current!==t;if(a.current=n,o.current=t,s||!e||n)return;let c=pe();if(c.enabled&&c.autoPlay)for(let e=r.length-1;e>=0;e--){let t=r[e];if(!t||t.type!==`assistant`)continue;let n=(t.content||``).trim();if(n){if(!me(n))return;fe(n,ge(i.language));return}}},[n,t,r,i.language]),(0,Z.useEffect)(()=>()=>ie(),[t])}var Wr=[{mode:`chat`,Icon:u,labelKey:`trajectory.viewChat`},{mode:`trajectory`,Icon:b,labelKey:`trajectory.viewTrajectory`}],Gr=[],Kr=(0,Z.memo)(function({tabs:e,activeSessionId:t,onSend:n,onStop:r,onPause:i,onResume:a,activeTab:o,setActiveTab:s,createNewSession:c,setTheme:l,setThemePreset:u,setLogs:d,setUnreadLogs:f,onRegenerate:p,onRetryTurn:m,onDeleteMessage:h,onUndoLastUser:g,onOpenSidebarView:_,hookDrawerOpen:v,onCloseHookDrawer:y,questionDrawerOpen:b,onCloseQuestionDrawer:x,workspaceDir:S,onWorkspaceSelect:C,onNewSessionInDir:w,errorLogs:T,onOpenLogs:E,onStartTemplate:D}){let O=(0,Z.useMemo)(()=>({setActiveTab:s,createNewSession:c,setTheme:l,setThemePreset:u,setLogs:d,setUnreadLogs:f}),[s,c,l,u,d,f]),[k,A]=(0,Z.useState)(`chat`),{t:j}=L(),M=B(e=>t?e.messagesBySession[t]??Gr:Gr),N=B(e=>t?e.generatingSessions.includes(t):!1),P=B(e=>t?e.pausedSessions.includes(t):!1);Ur({sessionId:t,isGenerating:N,messages:M});let F=e.find(e=>e.id===t)||null,I=(0,Z.useMemo)(()=>M.filter(e=>!e.deleted).length===0,[M]),R=B(e=>!t||e.snapshotLoadedSessions.includes(t)),z=I&&!R;(0,Z.useEffect)(()=>{F&&!I&&U({id:F.id,title:F.title,dir:S})},[F,I,S]);let V=$(e=>e.prefillNonce),ee=(0,Z.useCallback)((e,r,i,a,o,s)=>{t&&n(t,e,r,i,a||s?{...a?{mentions:a,mentionDeliveryMode:o}:{},...s?{display:s}:{}}:void 0)},[n,t]),H=(0,Z.useCallback)(async e=>{let n=t;if(!n)return;let r=`shell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,i=Date.now();B.getState().addMessage(n,{id:r,type:`user`,content:`!${e}`,timestamp:i,noTruncate:!0,shellRun:{command:e,stdout:``,stderr:``,exitCode:null,durationMs:0,running:!0}});let a=await he.shell.exec(e,S),o=a.success&&a.data?{...a.data,running:!1}:{command:e,stdout:``,stderr:``,exitCode:null,durationMs:Date.now()-i,running:!1,error:a.error||j(`chat.shellRequestFailedGeneric`)};B.getState().updateMessage(n,r,{shellRun:o})},[t,S,j]),W=(0,Z.useCallback)(e=>{t&&p&&p(t,e)},[p,t]),G=(0,Z.useCallback)(e=>{t&&h&&h(t,e)},[h,t]);return(0,Q.jsx)(`div`,{className:`flex-1 flex min-h-0`,children:(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[(0,Q.jsx)(hr,{}),F&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex h-7 shrink-0 items-center justify-end px-3`,children:(0,Q.jsxs)(`div`,{role:`radiogroup`,"aria-label":j(`trajectory.viewToggleTitle`),className:`relative inline-grid grid-cols-2 items-center rounded-full border border-dark-border bg-dark-surface/60 p-0.5 text-meta leading-none`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-y-0.5 left-0.5 w-[calc(50%-2px)] rounded-full ring-1 transition-transform duration-200 ease-out motion-reduce:transition-none ${k===`trajectory`?`translate-x-full bg-accent-blue/20 ring-accent-blue/40`:`translate-x-0 bg-dark-hover ring-dark-border`}`}),Wr.map(({mode:e,Icon:t,labelKey:n})=>{let r=k===e;return(0,Q.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":r,title:j(`trajectory.viewToggleTitle`),onClick:()=>A(e),className:`relative z-10 flex items-center justify-center gap-1 whitespace-nowrap rounded-full px-2.5 py-1 transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60 ${r?`text-dark-text`:`text-dark-muted hover:text-dark-text`}`,children:[(0,Q.jsx)(t,{size:11}),j(n)]},e)})]})}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col ${I&&k===`chat`?`justify-center overflow-y-auto custom-scrollbar py-2 max-md:justify-start`:``}`,children:[k===`chat`?(0,Q.jsxs)(Q.Fragment,{children:[z?(0,Q.jsx)(`div`,{className:`animate-session-switch flex items-center justify-center py-10 text-sm text-dark-muted`,role:`status`,children:j(`chat.loading`)},`restoring-${F.id}`):I?(0,Q.jsxs)(`div`,{className:`animate-session-switch`,children:[(0,Q.jsx)(Hr,{currentSessionId:F.id}),(0,Q.jsx)(Ir,{})]},`empty-${F.id}`):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col animate-session-switch`,children:(0,Q.jsx)(se,{messages:M,isGenerating:N,isPaused:P,sessionId:F.id,onRegenerate:p?W:void 0,onRetryTurn:m,onDeleteMessage:h?G:void 0,onUndoLastUser:g,onOpenSidebarView:_})},F.id),(0,Q.jsx)(dr,{sessionId:F.id})]}),(0,Q.jsx)(pr,{isOpen:!!v,onCloseModal:y}),(0,Q.jsx)(ur,{isOpen:!!b,onClose:x??(()=>{})})]}):(0,Q.jsx)(Un,{sessionId:F.id,messages:M,errorLogs:T,onOpenLogs:E}),(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(Gn,{activeSessionId:F.id})}),(0,Q.jsx)(de,{sessionId:F.id,onSend:ee,onRunShell:H,onStop:()=>r(F.id),onPause:()=>i(F.id),onResume:()=>a(F.id),slashOptions:O,workspaceDir:S,onWorkspaceSelect:C?e=>C(e,F.id):void 0,onNewSessionInDir:w,focusRequest:V}),k===`chat`&&I&&R&&(0,Q.jsx)(Vr,{sessionId:F.id,onStartTemplate:D})]})]})]})})});export{Kr as SessionGrid};
|